Parse a token out of a string
==============
*/
-int COM_ParseToken (const char **datapointer)
+int COM_ParseToken(const char **datapointer, int returnnewline)
{
int c;
int len;
// skip whitespace
skipwhite:
- while ((c = *data) <= ' ')
+ while ((c = *data) <= ' ' && (c != '\n' || !returnnewline))
{
if (c == 0)
{
data++;
}
-// skip // comments
- if (c=='/' && data[1] == '/')
+ // check if it's a comment
+ if (c == '/')
{
- while (*data && *data != '\n')
- data++;
- goto skipwhite;
+ // skip // comments
+ if (data[1] == '/')
+ {
+ while (*data && *data != '\n')
+ data++;
+ goto skipwhite;
+ }
+ // skip /* comments
+ if (data[1] == '*')
+ {
+ while (*data && *data != '*' && data[1] != '/')
+ data++;
+ goto skipwhite;
+ }
}
-
// handle quoted strings specially
if (c == '\"')
{
while (1)
{
c = *data++;
- if (c=='\"' || !c)
+ if (c == '\"' || !c)
{
com_token[len] = 0;
*datapointer = data;
}
// parse single characters
- if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
+ if (c == '{' || c == '}' || c == ')' || c == '(' || c == ']' || c == '[' || c == '\'' || c == ':' || c == ',' || c == ';' || c == '\n')
{
com_token[len] = c;
len++;
data++;
len++;
c = *data;
- if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
+ if (c == '{' || c == '}' || c == ')' || c == '(' || c == ']' || c == '[' || c == '\'' || c == ':' || c == ',' || c == ';')
break;
} while (c>32);