ACS: User properties can tell bool from string
This commit is contained in:
parent
061e6e727c
commit
6c026f59cb
3 changed files with 44 additions and 25 deletions
|
|
@ -519,6 +519,7 @@ void M_TokenizerClose(void);
|
|||
const char *M_TokenizerRead(UINT32 i);
|
||||
UINT32 M_TokenizerGetEndPos(void);
|
||||
void M_TokenizerSetEndPos(UINT32 newPos);
|
||||
boolean M_TokenizerJustReadString(void);
|
||||
|
||||
char *sizeu1(size_t num);
|
||||
char *sizeu2(size_t num);
|
||||
|
|
|
|||
16
src/m_misc.c
16
src/m_misc.c
|
|
@ -2003,6 +2003,7 @@ static UINT32 tokenizerStartPos = 0;
|
|||
static UINT32 tokenizerEndPos = 0;
|
||||
static UINT32 tokenizerInputLength = 0;
|
||||
static UINT8 tokenizerInComment = 0; // 0 = not in comment, 1 = // Single-line, 2 = /* Multi-line */
|
||||
static boolean tokenizerIsString = false; // did we strip quotes from this token?
|
||||
|
||||
void M_TokenizerOpen(const char *inputString, size_t inputLength)
|
||||
{
|
||||
|
|
@ -2027,6 +2028,7 @@ void M_TokenizerClose(void)
|
|||
tokenizerStartPos = 0;
|
||||
tokenizerEndPos = 0;
|
||||
tokenizerInComment = 0;
|
||||
tokenizerIsString = false;
|
||||
}
|
||||
|
||||
static void M_DetectComment(UINT32 *pos)
|
||||
|
|
@ -2057,8 +2059,10 @@ static void M_ReadTokenString(UINT32 i)
|
|||
// Assign the memory. Don't forget an extra byte for the end of the string!
|
||||
tokenizerToken[i] = (char *)Z_Malloc(tokenCapacity[i] * sizeof(char), PU_STATIC, NULL);
|
||||
}
|
||||
|
||||
// Copy the string.
|
||||
M_Memcpy(tokenizerToken[i], tokenizerInput + tokenizerStartPos, (size_t)tokenLength);
|
||||
|
||||
// Make the final character NUL.
|
||||
tokenizerToken[i][tokenLength] = '\0';
|
||||
}
|
||||
|
|
@ -2070,6 +2074,9 @@ const char *M_TokenizerRead(UINT32 i)
|
|||
|
||||
tokenizerStartPos = tokenizerEndPos;
|
||||
|
||||
// Reset string flag
|
||||
tokenizerIsString = false;
|
||||
|
||||
// Try to detect comments now, in case we're pointing right at one
|
||||
M_DetectComment(&tokenizerStartPos);
|
||||
|
||||
|
|
@ -2124,6 +2131,10 @@ const char *M_TokenizerRead(UINT32 i)
|
|||
|
||||
M_ReadTokenString(i);
|
||||
tokenizerEndPos++;
|
||||
|
||||
// Tell us the the token was a string.
|
||||
tokenizerIsString = true;
|
||||
|
||||
return tokenizerToken[i];
|
||||
}
|
||||
|
||||
|
|
@ -2159,6 +2170,11 @@ void M_TokenizerSetEndPos(UINT32 newPos)
|
|||
tokenizerEndPos = newPos;
|
||||
}
|
||||
|
||||
boolean M_TokenizerJustReadString(void)
|
||||
{
|
||||
return tokenizerIsString;
|
||||
}
|
||||
|
||||
/** Count bits in a number.
|
||||
*/
|
||||
UINT8 M_CountBits(UINT32 num, UINT8 size)
|
||||
|
|
|
|||
|
|
@ -1607,11 +1607,19 @@ static void ParseUserProperty(mapUserProperties_t *user, const char *param, cons
|
|||
{
|
||||
if (fastncmp(param, "user_", 5) && strlen(param) > 5)
|
||||
{
|
||||
const boolean valIsString = M_TokenizerJustReadString();
|
||||
const char *key = param + 5;
|
||||
const size_t valLen = strlen(val);
|
||||
UINT8 numberType = PROP_NUM_TYPE_INT;
|
||||
size_t i = 0;
|
||||
|
||||
if (valIsString == true)
|
||||
{
|
||||
// Value is a string. Upload directly!
|
||||
K_UserPropertyPush(user, key, USER_PROP_STR, &val);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < valLen; i++)
|
||||
{
|
||||
if (val[i] == '.')
|
||||
|
|
@ -1627,30 +1635,6 @@ static void ParseUserProperty(mapUserProperties_t *user, const char *param, cons
|
|||
|
||||
switch (numberType)
|
||||
{
|
||||
case PROP_NUM_TYPE_NA:
|
||||
default:
|
||||
{
|
||||
// Value is a boolean or a string.
|
||||
|
||||
// Unfortunately, our UDMF parser discards the quotation marks,
|
||||
// so we can't differentiate strings from booleans properly.
|
||||
// Don't feel like tearing it apart to fix that, so we just
|
||||
// turn true & false into booleans, even if they were actually
|
||||
// supposed to be text.
|
||||
|
||||
boolean vBool = fastcmp("true", val);
|
||||
if (vBool == true || fastcmp("false", val))
|
||||
{
|
||||
// Value is *probably* a boolean.
|
||||
K_UserPropertyPush(user, key, USER_PROP_BOOL, &vBool);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Value is a string.
|
||||
K_UserPropertyPush(user, key, USER_PROP_STR, &val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROP_NUM_TYPE_INT:
|
||||
{
|
||||
// Value is an integer.
|
||||
|
|
@ -1665,7 +1649,25 @@ static void ParseUserProperty(mapUserProperties_t *user, const char *param, cons
|
|||
K_UserPropertyPush(user, key, USER_PROP_FIXED, &vFixed);
|
||||
break;
|
||||
}
|
||||
|
||||
case PROP_NUM_TYPE_NA:
|
||||
default:
|
||||
{
|
||||
// Value is some other kind of type.
|
||||
// Currently we just support bool.
|
||||
|
||||
boolean vBool = fastcmp("true", val);
|
||||
if (vBool == true || fastcmp("false", val))
|
||||
{
|
||||
// Value is a boolean.
|
||||
K_UserPropertyPush(user, key, USER_PROP_BOOL, &vBool);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Value is invalid.
|
||||
CONS_Alert(CONS_WARNING, "Could not interpret user property \"%s\" value (%s)\n", param, val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue