Remove characters that will not be allowed in the constant string.
This commit is contained in:
parent
2166571920
commit
5b1b556946
96
src/g_game.c
96
src/g_game.c
|
@ -3251,50 +3251,64 @@ INT16 G_AddGametype(UINT32 rules)
|
||||||
//
|
//
|
||||||
void G_AddGametypeConstant(INT16 gtype, const char *newgtconst)
|
void G_AddGametypeConstant(INT16 gtype, const char *newgtconst)
|
||||||
{
|
{
|
||||||
char *gtconst = Z_Malloc(strlen(newgtconst) + 3, PU_STATIC, NULL);
|
size_t r = 0; // read
|
||||||
// Copy GT_ and the gametype name.
|
size_t w = 0; // write
|
||||||
strcpy(gtconst, "GT_");
|
char *gtconst = Z_Calloc(strlen(newgtconst) + 3, PU_STATIC, NULL);
|
||||||
strcat(gtconst, newgtconst);
|
char *tmpconst = Z_Calloc(strlen(newgtconst), PU_STATIC, NULL);
|
||||||
|
|
||||||
|
// Copy the gametype name.
|
||||||
|
strcpy(tmpconst, newgtconst);
|
||||||
|
|
||||||
// Make uppercase.
|
// Make uppercase.
|
||||||
strupr(gtconst);
|
strupr(tmpconst);
|
||||||
// Remove characters.
|
|
||||||
#define REMOVECHAR(chr) \
|
// Prepare to write the new constant string now.
|
||||||
{ \
|
strcpy(gtconst, "GT_");
|
||||||
char *chrfind = strchr(gtconst, chr); \
|
|
||||||
while (chrfind) \
|
// Remove characters that will not be allowed in the constant string.
|
||||||
{ \
|
for (; r < strlen(tmpconst); r++)
|
||||||
*chrfind = '_'; \
|
{
|
||||||
chrfind = strchr(chrfind, chr); \
|
boolean writechar = true;
|
||||||
} \
|
char rc = tmpconst[r];
|
||||||
|
switch (rc)
|
||||||
|
{
|
||||||
|
// Space
|
||||||
|
case ' ':
|
||||||
|
// Used for operations
|
||||||
|
case '+':
|
||||||
|
case '-':
|
||||||
|
case '*':
|
||||||
|
case '/':
|
||||||
|
case '%':
|
||||||
|
case '^':
|
||||||
|
// Part of Lua's syntax
|
||||||
|
case '#':
|
||||||
|
case '=':
|
||||||
|
case '~':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case '{':
|
||||||
|
case '}':
|
||||||
|
case '[':
|
||||||
|
case ']':
|
||||||
|
case ':':
|
||||||
|
case ';':
|
||||||
|
case ',':
|
||||||
|
case '.':
|
||||||
|
writechar = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (writechar)
|
||||||
|
{
|
||||||
|
gtconst[3 + w] = rc;
|
||||||
|
w++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Space
|
// Free the temporary string.
|
||||||
REMOVECHAR(' ')
|
Z_Free(tmpconst);
|
||||||
// Used for operations
|
|
||||||
REMOVECHAR('+')
|
|
||||||
REMOVECHAR('-')
|
|
||||||
REMOVECHAR('*')
|
|
||||||
REMOVECHAR('/')
|
|
||||||
REMOVECHAR('%')
|
|
||||||
REMOVECHAR('^')
|
|
||||||
// Part of Lua's syntax
|
|
||||||
REMOVECHAR('#')
|
|
||||||
REMOVECHAR('=')
|
|
||||||
REMOVECHAR('~')
|
|
||||||
REMOVECHAR('<')
|
|
||||||
REMOVECHAR('>')
|
|
||||||
REMOVECHAR('(')
|
|
||||||
REMOVECHAR(')')
|
|
||||||
REMOVECHAR('{')
|
|
||||||
REMOVECHAR('}')
|
|
||||||
REMOVECHAR('[')
|
|
||||||
REMOVECHAR(']')
|
|
||||||
REMOVECHAR(':')
|
|
||||||
REMOVECHAR(';')
|
|
||||||
REMOVECHAR(',')
|
|
||||||
REMOVECHAR('.')
|
|
||||||
|
|
||||||
#undef REMOVECHAR
|
|
||||||
|
|
||||||
// Finally, set the constant string.
|
// Finally, set the constant string.
|
||||||
Gametype_ConstantNames[gtype] = gtconst;
|
Gametype_ConstantNames[gtype] = gtconst;
|
||||||
|
|
Loading…
Reference in a new issue