data = entdata;
if (!data)
return;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] != '{')
return; // error
while (1)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] == '}')
break; // end of worldspawn
strlcpy (key, com_token, sizeof (key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
strlcpy (value, com_token, sizeof (value));
if (!strcmp("sky", key))
argv[arrayindex][0] = 0;
for (;;)
{
- if (!COM_ParseToken(&text, true))
+ if (!COM_ParseToken_Simple(&text, true))
return;
if (!strcmp(com_token, "\n"))
break;
cvar_t *cvar;
const char *tempin = in;
- COM_ParseTokenConsole( &tempin );
+ COM_ParseToken_Console( &tempin );
// don't expand rcon_password or similar cvars (CVAR_PRIVATE flag)
if ((cvar = Cvar_FindVar(&com_token[0])) && !(cvar->flags & CVAR_PRIVATE)) {
const char *cvarcontent = cvar->string;
if (cmd_argc == 1)
cmd_args = text;
- if (!COM_ParseTokenConsole(&text))
+ if (!COM_ParseToken_Console(&text))
return;
if (cmd_argc < MAX_ARGS)
/*
==============
-COM_ParseToken
+COM_ParseToken_Simple
Parse a token out of a string
==============
*/
-int COM_ParseToken(const char **datapointer, int returnnewline)
+int COM_ParseToken_Simple(const char **datapointer, int returnnewline)
{
int len;
int c;
data++;
while (*data && (data[0] != '*' || data[1] != '/'))
data++;
- data += 2;
+ if (*data)
+ data++;
+ if (*data)
+ data++;
goto skipwhite;
}
else if (*data == '\"')
c = *data;
if (*data == '\\')
{
- if (data[1] == '"')
- {
- data++;
- c = *data;
- }
- else if (data[1] == '\'')
- {
- data++;
- c = *data;
- }
- else if (data[1] == 'n')
- {
- data++;
+ data++;
+ c = *data;
+ if (c == 'n')
c = '\n';
- }
- else if (data[1] == '\\')
- data++;
+ else if (c == 't')
+ c = '\t';
}
com_token[len++] = c;
}
*datapointer = data+1;
return true;
}
- else if (*data == '\'')
+ else if (*data == '\r')
+ {
+ // translate Mac line ending to UNIX
+ com_token[len++] = '\n';data++;
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+ else if (*data == '\n')
+ {
+ // single character
+ com_token[len++] = *data++;
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+ else
+ {
+ // regular word
+ for (;*data > ' ';data++)
+ {
+ if (len >= (int)sizeof(com_token) - 1)
+ {
+ com_token[0] = 0;
+ *datapointer = NULL;
+ return false;
+ }
+ com_token[len++] = *data;
+ }
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+}
+
+/*
+==============
+COM_ParseToken_QuakeC
+
+Parse a token out of a string
+==============
+*/
+int COM_ParseToken_QuakeC(const char **datapointer, int returnnewline)
+{
+ int len;
+ int c;
+ const char *data = *datapointer;
+
+ len = 0;
+ com_token[0] = 0;
+
+ if (!data)
+ {
+ *datapointer = NULL;
+ return false;
+ }
+
+// skip whitespace
+skipwhite:
+ // line endings:
+ // UNIX: \n
+ // Mac: \r
+ // Windows: \r\n
+ for (;*data <= ' ' && ((*data != '\n' && *data != '\r') || !returnnewline);data++)
+ {
+ if (*data == 0)
+ {
+ // end of file
+ *datapointer = NULL;
+ return false;
+ }
+ }
+
+ // handle Windows line ending
+ if (data[0] == '\r' && data[1] == '\n')
+ data++;
+
+ if (data[0] == '/' && data[1] == '/')
+ {
+ // comment
+ while (*data && *data != '\n' && *data != '\r')
+ data++;
+ goto skipwhite;
+ }
+ else if (data[0] == '/' && data[1] == '*')
+ {
+ // comment
+ data++;
+ while (*data && (data[0] != '*' || data[1] != '/'))
+ data++;
+ if (*data)
+ data++;
+ if (*data)
+ data++;
+ goto skipwhite;
+ }
+ else if (*data == '\"' || *data == '\'')
{
// quoted string
- for (data++;*data != '\'';data++)
+ char quote = *data;
+ for (data++;*data != quote;data++)
{
if (!*data || len >= (int)sizeof(com_token) - 1)
{
c = *data;
if (*data == '\\')
{
- if (data[1] == '"')
- {
- data++;
- c = *data;
- }
- else if (data[1] == '\'')
- {
- data++;
- c = *data;
- }
- else if (data[1] == 'n')
- {
- data++;
+ data++;
+ c = *data;
+ if (c == 'n')
c = '\n';
- }
- else if (data[1] == '\\')
- data++;
+ else if (c == 't')
+ c = '\t';
}
com_token[len++] = c;
}
else if (*data == '\r')
{
// translate Mac line ending to UNIX
- com_token[len++] = '\n';
+ com_token[len++] = '\n';data++;
com_token[len] = 0;
*datapointer = data;
return true;
}
- else if (*data == '\n' || *data == '{' || *data == '}' || *data == ')' || *data == '(' || *data == ']' || *data == '[' || *data == '\'' || *data == ':' || *data == ',' || *data == ';')
+ else if (*data == '\n' || *data == '{' || *data == '}' || *data == ')' || *data == '(' || *data == ']' || *data == '[' || *data == ':' || *data == ',' || *data == ';')
{
// single character
com_token[len++] = *data++;
else
{
// regular word
- for (;*data > ' ' && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != '\'' && *data != ':' && *data != ',' && *data != ';' && *data != '\'' && *data != '"';data++)
+ for (;*data > ' ' && *data != '{' && *data != '}' && *data != ')' && *data != '(' && *data != ']' && *data != '[' && *data != ':' && *data != ',' && *data != ';';data++)
{
if (len >= (int)sizeof(com_token) - 1)
{
*datapointer = NULL;
return false;
}
+ com_token[len++] = *data;
+ }
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+}
+
+/*
+==============
+COM_ParseToken_VM_Tokenize
+
+Parse a token out of a string
+==============
+*/
+int COM_ParseToken_VM_Tokenize(const char **datapointer, int returnnewline)
+{
+ int len;
+ int c;
+ const char *data = *datapointer;
+
+ len = 0;
+ com_token[0] = 0;
+
+ if (!data)
+ {
+ *datapointer = NULL;
+ return false;
+ }
+
+// skip whitespace
+skipwhite:
+ // line endings:
+ // UNIX: \n
+ // Mac: \r
+ // Windows: \r\n
+ for (;*data <= ' ' && ((*data != '\n' && *data != '\r') || !returnnewline);data++)
+ {
+ if (*data == 0)
+ {
+ // end of file
+ *datapointer = NULL;
+ return false;
+ }
+ }
+
+ // handle Windows line ending
+ if (data[0] == '\r' && data[1] == '\n')
+ data++;
+
+ if (data[0] == '/' && data[1] == '/')
+ {
+ // comment
+ while (*data && *data != '\n' && *data != '\r')
+ data++;
+ goto skipwhite;
+ }
+ else if (data[0] == '/' && data[1] == '*')
+ {
+ // comment
+ data++;
+ while (*data && (data[0] != '*' || data[1] != '/'))
+ data++;
+ if (*data)
+ data++;
+ if (*data)
+ data++;
+ goto skipwhite;
+ }
+ else if (*data == '\"' || *data == '\'')
+ {
+ char quote = *data;
+ // quoted string
+ for (data++;*data != quote;data++)
+ {
+ if (!*data || len >= (int)sizeof(com_token) - 1)
+ {
+ com_token[0] = 0;
+ *datapointer = NULL;
+ return false;
+ }
c = *data;
if (*data == '\\')
{
- if (data[1] == '"')
- {
- data++;
- c = *data;
- }
- else if (data[1] == '\'')
- {
- data++;
- c = *data;
- }
- else if (data[1] == 'n')
- {
- data++;
+ data++;
+ c = *data;
+ if (c == 'n')
c = '\n';
- }
- else if (data[1] == '\\')
- data++;
+ else if (c == 't')
+ c = '\t';
}
com_token[len++] = c;
}
com_token[len] = 0;
+ *datapointer = data+1;
+ return true;
+ }
+ else if (*data == '\r')
+ {
+ // translate Mac line ending to UNIX
+ com_token[len++] = '\n';data++;
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+ else if (*data == '\n' || *data == ',' || *data == ';')
+ {
+ // single character
+ com_token[len++] = *data++;
+ com_token[len] = 0;
+ *datapointer = data;
+ return true;
+ }
+ else
+ {
+ // regular word
+ for (;*data > ' ' && *data != ',' && *data != ';';data++)
+ {
+ if (len >= (int)sizeof(com_token) - 1)
+ {
+ com_token[0] = 0;
+ *datapointer = NULL;
+ return false;
+ }
+ com_token[len++] = *data;
+ }
+ com_token[len] = 0;
*datapointer = data;
return true;
}
/*
==============
-COM_ParseTokenConsole
+COM_ParseToken_Console
Parse a token out of a string, behaving like the qwcl console
==============
*/
-int COM_ParseTokenConsole(const char **datapointer)
+int COM_ParseToken_Console(const char **datapointer)
{
int len;
const char *data = *datapointer;
extern char com_token[MAX_INPUTLINE];
-int COM_ParseToken(const char **datapointer, int returnnewline);
-int COM_ParseTokenConsole(const char **datapointer);
+int COM_ParseToken_Simple(const char **datapointer, int returnnewline);
+int COM_ParseToken_QuakeC(const char **datapointer, int returnnewline);
+int COM_ParseToken_VM_Tokenize(const char **datapointer, int returnnewline);
+int COM_ParseToken_Console(const char **datapointer);
extern int com_argc;
extern const char **com_argv;
for (;;)
{
int l;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break;
if (com_token[0] == '{')
continue;
for (l = 0;l < (int)sizeof(keyname) - 1 && com_token[k+l] && com_token[k+l] > ' ';l++)
keyname[l] = com_token[k+l];
keyname[l] = 0;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break;
if (developer.integer >= 100)
Con_Printf("key: %s %s\n", keyname, com_token);
}
// version
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
version = atoi(com_token);
if (version != SAVEGAME_VERSION)
{
}
// description
- // this is a little hard to parse, as : is a separator in COM_ParseToken,
- // so use the console parser instead
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
for (i = 0;i < NUM_SPAWN_PARMS;i++)
{
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
spawn_parms[i] = atof(com_token);
}
// skill
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
// this silliness is so we can load 1.06 save files, which have float skill values
current_skill = (int)(atof(com_token) + 0.5);
Cvar_SetValue ("skill", (float)current_skill);
// mapname
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
strlcpy (mapname, com_token, sizeof(mapname));
// time
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
time = atof(com_token);
allowcheats = sv_cheats.integer != 0;
{
// light style
oldt = t;
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
// if this is a 64 lightstyle savegame produced by Quake, stop now
// we have to check this because darkplaces saves 256 lightstyle savegames
if (com_token[0] == '{')
for(;;)
{
oldt = t;
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
if (com_token[0] == '{')
{
t = oldt;
for (;;)
{
start = t;
- while (COM_ParseTokenConsole(&t))
+ while (COM_ParseToken_Simple(&t, false))
if (!strcmp(com_token, "}"))
break;
- if (!COM_ParseTokenConsole(&start))
+ if (!COM_ParseToken_Simple(&start, false))
{
// end of file
break;
if (Cmd_Argc() > 2)
{
message = Cmd_Args();
- COM_ParseTokenConsole(&message);
+ COM_ParseToken_Simple(&message, false);
if (byNumber)
{
message++; // skip the #
}
p = sv_curl_serverpackages.string;
Con_DPrintf("Require all of: %s\n", p);
- while(COM_ParseTokenConsole(&p))
+ while(COM_ParseToken_Simple(&p, false))
{
Con_DPrintf("Require: %s\n", com_token);
Curl_RequireFile(com_token);
buf[sizeof(buf) - 1] = 0;
t = buf;
// version
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
version = atoi(com_token);
// description
- COM_ParseTokenConsole(&t);
+ COM_ParseToken_Simple(&t, false);
strlcpy (m_filenames[i], com_token, sizeof (m_filenames[i]));
// change _ back to space
int i, j, k;
if (!data)
return;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] != '{')
return; // error
while (1)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] == '}')
break; // end of worldspawn
strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
dpsnprintf(value, sizeof(value), "%s", com_token);
if (!strcmp("wad", key)) // for HalfLife maps
if (!maptext)
return;
text = maptext;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
submodel = 0;
for (;;)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break;
if (com_token[0] != '{')
return; // error
brushes = Mem_Alloc(loadmodel->mempool, maxbrushes * sizeof(mbrush_t));
for (;;)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] == '}')
break; // end of entity
}
for (;;)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
return; // error
if (com_token[0] == '}')
break; // end of brush
// FIXME: support hl .map format
for (pointnum = 0;pointnum < 3;pointnum++)
{
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
for (componentnum = 0;componentnum < 3;componentnum++)
{
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
point[pointnum][componentnum] = atof(com_token);
}
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
}
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
strlcpy(facetexture, com_token, sizeof(facetexture));
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
//scroll_s = atof(com_token);
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
//scroll_t = atof(com_token);
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
//rotate = atof(com_token);
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
//scale_s = atof(com_token);
- COM_ParseTokenConsole(&data);
+ COM_ParseToken_Simple(&data, false);
//scale_t = atof(com_token);
TriangleNormal(point[0], point[1], point[2], planenormal);
VectorNormalizeDouble(planenormal);
memcpy(loadmodel->brush.entities, mod_base + l->fileofs, l->filelen);
data = loadmodel->brush.entities;
// some Q3 maps override the lightgrid_cellsize with a worldspawn key
- if (data && COM_ParseTokenConsole(&data) && com_token[0] == '{')
+ if (data && COM_ParseToken_Simple(&data, false) && com_token[0] == '{')
{
while (1)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break; // error
if (com_token[0] == '}')
break; // end of worldspawn
strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break; // error
strlcpy(value, com_token, sizeof(value));
if (!strcmp("gridsize", key))
text = f = (char *)FS_LoadFile(search->filenames[fileindex], tempmempool, false, NULL);
if (!f)
continue;
- while (COM_ParseToken(&text, false))
+ while (COM_ParseToken_QuakeC(&text, false))
{
if (q3shaders_numshaders >= Q3SHADER_MAXSHADERS)
{
shader = q3shaders_shaders + q3shaders_numshaders++;
memset(shader, 0, sizeof(*shader));
strlcpy(shader->name, com_token, sizeof(shader->name));
- if (!COM_ParseToken(&text, false) || strcasecmp(com_token, "{"))
+ if (!COM_ParseToken_QuakeC(&text, false) || strcasecmp(com_token, "{"))
{
Con_Printf("%s parsing error - expected \"{\", found \"%s\"\n", search->filenames[fileindex], com_token);
break;
}
- while (COM_ParseToken(&text, false))
+ while (COM_ParseToken_QuakeC(&text, false))
{
if (!strcasecmp(com_token, "}"))
break;
}
else
layer = NULL;
- while (COM_ParseToken(&text, false))
+ while (COM_ParseToken_QuakeC(&text, false))
{
if (!strcasecmp(com_token, "}"))
break;
strlcpy(parameter[j], com_token, sizeof(parameter[j]));
numparameters = j + 1;
}
- if (!COM_ParseToken(&text, true))
+ if (!COM_ParseToken_QuakeC(&text, true))
break;
}
if (developer.integer >= 100)
strlcpy(parameter[j], com_token, sizeof(parameter[j]));
numparameters = j + 1;
}
- if (!COM_ParseToken(&text, true))
+ if (!COM_ParseToken_QuakeC(&text, true))
break;
}
if (fileindex == 0 && !strcasecmp(com_token, "}"))
for(line = 0;;line++)
{
// parse line
- if (!COM_ParseToken(&data, true))
+ if (!COM_ParseToken_QuakeC(&data, true))
break;
if (!strcmp(com_token, "\n"))
continue;
else
wordsoverflow = true;
}
- while (COM_ParseToken(&data, true) && strcmp(com_token, "\n"));
+ while (COM_ParseToken_QuakeC(&data, true) && strcmp(com_token, "\n"));
if (wordsoverflow)
{
Con_Printf("Mod_LoadSkinFiles: parsing error in file \"%s_%i.skin\" on line #%i: line with too many statements, skipping\n", loadmodel->name, i, line);
p = PRVM_G_STRING(OFS_PARM0);
num_tokens = 0;
- while(COM_ParseToken(&p, false))
+ while(COM_ParseToken_VM_Tokenize(&p, false))
{
if (num_tokens >= (int)(sizeof(tokens)/sizeof(tokens[0])))
break;
VM_SAFEPARMCOUNT(2, VM_parseentitydata);
- // get edict and test it
+ // get edict and test it
ent = PRVM_G_EDICT(OFS_PARM0);
if (ent->priv.required->free)
PRVM_ERROR ("VM_parseentitydata: %s: Can only set already spawned entities (entity %i is free)!", PRVM_NAME, PRVM_NUM_FOR_EDICT(ent));
data = PRVM_G_STRING(OFS_PARM1);
- // parse the opening brace
- if (!COM_ParseTokenConsole(&data) || com_token[0] != '{' )
+ // parse the opening brace
+ if (!COM_ParseToken_Simple(&data, false) || com_token[0] != '{' )
PRVM_ERROR ("VM_parseentitydata: %s: Couldn't parse entity data:\n%s", PRVM_NAME, data );
PRVM_ED_ParseEdict (data, ent);
while (1)
{
// parse key
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
if (com_token[0] == '}')
break;
strlcpy (keyname, com_token, sizeof(keyname));
// parse value
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
if (com_token[0] == '}')
while (1)
{
// parse key
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
if (developer_entityparsing.integer)
Con_Printf("Key: \"%s\"", com_token);
}
// parse value
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
if (developer_entityparsing.integer)
Con_Printf(" \"%s\"\n", com_token);
while (1)
{
// parse the opening brace
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break;
if (com_token[0] != '{')
PRVM_ERROR ("PRVM_ED_LoadFromFile: %s: found %s when expecting {", PRVM_NAME, com_token);
data = r_refdef.worldmodel->brush.entities;
if (!data)
return;
- for (entnum = 0;COM_ParseTokenConsole(&data) && com_token[0] == '{';entnum++)
+ for (entnum = 0;COM_ParseToken_Simple(&data, false) && com_token[0] == '{';entnum++)
{
type = LIGHTTYPE_MINUSX;
origin[0] = origin[1] = origin[2] = 0;
islight = false;
while (1)
{
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break; // error
if (com_token[0] == '}')
break; // end of entity
strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
- if (!COM_ParseTokenConsole(&data))
+ if (!COM_ParseToken_Simple(&data, false))
break; // error
strlcpy(value, com_token, sizeof(value));
argc = 0;
for (;;)
{
- if (!COM_ParseToken(&text, true) || !strcmp(com_token, "\n"))
+ if (!COM_ParseToken_Simple(&text, true) || !strcmp(com_token, "\n"))
break;
if (argc < 16)
{