예제 #1
0
        static Error parse_specs(Parser_Hook h, string fmt)
        {
            Misc.assert(h != null);
            Misc.assert(fmt != null);

            string[] split = fmt.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (split.Length == 0)
            {
                return(Error.GENERIC);
            }

            h.dir = split[0];

            int i = 1;

            while (i < split.Length)
            {
                /* Lack of a type is legal; that means we're at the end of the
                 * line. */
                string stype = split[i++];

                /* Lack of a name, on the other hand... */
                if (i >= split.Length)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                string name = split[i++];

                /* Grab a type, check to see if we have a mandatory type
                 * following an optional type. */
                PARSE_T type = parse_type(stype);
                if (type == PARSE_T.NONE)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                if ((type & PARSE_T.OPT) == 0 && h.specs.Count > 0 && (h.specs.Last().type & PARSE_T.OPT) != 0)
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }
                if (h.specs.Count > 0 && ((h.specs.Last().type & ~PARSE_T.OPT) == PARSE_T.STR))
                {
                    clean_specs(h);
                    return(Error.GENERIC);
                }

                /* Save this spec. */
                Hook_Spec hs = new Hook_Spec();
                hs.type = type;
                hs.name = name;
                h.specs.Add(hs);
            }

            return(Error.NONE);
        }
예제 #2
0
        static Error parse_specs(Parser_Hook h, string fmt)
        {
            Misc.assert(h != null);
            Misc.assert(fmt != null);

            string[] split = fmt.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            if (split.Length == 0)
                return Error.GENERIC;

            h.dir = split[0];

            int i = 1;
            while(i < split.Length)
            {
                /* Lack of a type is legal; that means we're at the end of the
                 * line. */
                string stype = split[i++];

                /* Lack of a name, on the other hand... */
                if(i >= split.Length) {
                    clean_specs(h);
                    return Error.GENERIC;
                }
                string name = split[i++];

                /* Grab a type, check to see if we have a mandatory type
                 * following an optional type. */
                PARSE_T type = parse_type(stype);
                if (type == PARSE_T.NONE)
                {
                    clean_specs(h);
                    return Error.GENERIC;
                }
                if ((type & PARSE_T.OPT) == 0 && h.specs.Count > 0 && (h.specs.Last().type & PARSE_T.OPT) != 0)
                {
                    clean_specs(h);
                    return Error.GENERIC;
                }
                if (h.specs.Count > 0 && ((h.specs.Last().type & ~PARSE_T.OPT) == PARSE_T.STR))
                {
                    clean_specs(h);
                    return Error.GENERIC;
                }

                /* Save this spec. */
                Hook_Spec hs = new Hook_Spec();
                hs.type = type;
                hs.name = name;
                h.specs.Add(hs);
            }

            return Error.NONE;
        }