示例#1
0
        public static void TokenizeString(Char[] text, Boolean macroExpand)
        {
            String com_token;

            cmd_argc = 0;
            cmd_args = "";
            var len = Lib.Strlen(text);

            if (macroExpand)
            {
                text = MacroExpandString(text, len);
            }
            if (text == null)
            {
                return;
            }
            len = Lib.Strlen(text);
            Com.ParseHelp ph = new ParseHelp(text);
            while (true)
            {
                var c = ph.Skipwhitestoeol();
                if (c == '\\')
                {
                    c = ph.Nextchar();
                    break;
                }

                if (c == 0)
                {
                    return;
                }
                if (cmd_argc == 1)
                {
                    cmd_args = new String(text, ph.index, len - ph.index);
                    cmd_args.Trim();
                }

                com_token = Com.Parse(ph);
                if (ph.data == null)
                {
                    return;
                }
                if (cmd_argc < Defines.MAX_STRING_TOKENS)
                {
                    cmd_argv[cmd_argc] = com_token;
                    cmd_argc++;
                }
            }
        }
示例#2
0
        public static String Parse(ParseHelp hlp)
        {
            Int32 c;
            var   len = 0;

            if (hlp.data == null)
            {
                return("");
            }

            while (true)
            {
                hlp.Skipwhites();
                if (hlp.IsEof())
                {
                    hlp.data = null;
                    return("");
                }

                if (hlp.Getchar() == '/')
                {
                    if (hlp.Nextchar() == '/')
                    {
                        hlp.Skiptoeol();
                        continue;
                    }
                    else
                    {
                        hlp.Prevchar();
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            if (hlp.Getchar() == '\\')
            {
                hlp.Nextchar();
                while (true)
                {
                    c = hlp.Getchar();
                    hlp.Nextchar();
                    if (c == '\\' || c == 0)
                    {
                        return(new String(com_token, 0, len));
                    }

                    if (len < Defines.MAX_TOKEN_CHARS)
                    {
                        com_token[len] = ( Char )c;
                        len++;
                    }
                }
            }

            c = hlp.Getchar();
            do
            {
                if (len < Defines.MAX_TOKEN_CHARS)
                {
                    com_token[len] = ( Char )c;
                    len++;
                }

                c = hlp.Nextchar();
            }while (c > 32);
            if (len == Defines.MAX_TOKEN_CHARS)
            {
                Com.Printf("Token exceeded " + Defines.MAX_TOKEN_CHARS + " chars, discarded.\\n");
                len = 0;
            }

            return(new String(com_token, 0, len));
        }