console parsing now behaves like qwcl, thanks to Fuh for pointing out the problems...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Dec 2003 09:47:38 +0000 (09:47 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Dec 2003 09:47:38 +0000 (09:47 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3686 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c
common.c
common.h

diff --git a/cmd.c b/cmd.c
index b6436b3..d2b0b11 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -552,7 +552,7 @@ static void Cmd_TokenizeString (const char *text)
                if (cmd_argc == 1)
                         cmd_args = text;
 
-               if (!COM_ParseToken(&text, false))
+               if (!COM_ParseTokenConsole(&text))
                        return;
 
                if (cmd_argc < MAX_ARGS)
index c94ef45..518ad5b 100644 (file)
--- a/common.c
+++ b/common.c
@@ -598,6 +598,81 @@ skipwhite:
        return true;
 }
 
+/*
+==============
+COM_ParseTokenConsole
+
+Parse a token out of a string, behaving like the qwcl console
+==============
+*/
+int COM_ParseTokenConsole(const char **datapointer)
+{
+       int c;
+       int len;
+       const char *data = *datapointer;
+
+       len = 0;
+       com_token[0] = 0;
+
+       if (!data)
+       {
+               *datapointer = NULL;
+               return false;
+       }
+
+// skip whitespace
+skipwhite:
+       while ((c = *data) <= ' ')
+       {
+               if (c == 0)
+               {
+                       // end of file
+                       *datapointer = NULL;
+                       return false;
+               }
+               data++;
+       }
+
+       // skip // comments
+       if (c == '/' && data[1] == '/')
+       {
+               while (*data && *data != '\n')
+                       data++;
+               goto skipwhite;
+       }
+
+// handle quoted strings specially
+       if (c == '\"')
+       {
+               data++;
+               while (1)
+               {
+                       c = *data++;
+                       if (c == '\"' || !c)
+                       {
+                               com_token[len] = 0;
+                               *datapointer = data;
+                               return true;
+                       }
+                       com_token[len] = c;
+                       len++;
+               }
+       }
+
+// parse a regular word
+       do
+       {
+               com_token[len] = c;
+               data++;
+               len++;
+               c = *data;
+       } while (c>32);
+
+       com_token[len] = 0;
+       *datapointer = data;
+       return true;
+}
+
 
 /*
 ================
index e30c140..1ba72a8 100644 (file)
--- a/common.h
+++ b/common.h
@@ -143,6 +143,7 @@ float MSG_ReadDPCoord (void);
 extern char com_token[1024];
 
 int COM_ParseToken(const char **datapointer, int returnnewline);
+int COM_ParseTokenConsole(const char **datapointer);
 
 extern int com_argc;
 extern const char **com_argv;