git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3686
d7cf8633-e32d-0410-b094-
e92efae38249
if (cmd_argc == 1)
cmd_args = text;
- if (!COM_ParseToken(&text, false))
+ if (!COM_ParseTokenConsole(&text))
return;
if (cmd_argc < MAX_ARGS)
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;
+}
+
/*
================
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;