diff --git a/src/doomdef.h b/src/doomdef.h index 99b79c03a..890ace89a 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -540,6 +540,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); diff --git a/src/m_misc.cpp b/src/m_misc.cpp index f5b1594ba..226128fc1 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -2295,6 +2295,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) { @@ -2319,6 +2320,7 @@ void M_TokenizerClose(void) tokenizerStartPos = 0; tokenizerEndPos = 0; tokenizerInComment = 0; + tokenizerIsString = false; } static void M_DetectComment(UINT32 *pos) @@ -2349,8 +2351,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'; } @@ -2362,6 +2366,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); @@ -2416,6 +2423,10 @@ const char *M_TokenizerRead(UINT32 i) M_ReadTokenString(i); tokenizerEndPos++; + + // Tell us the the token was a string. + tokenizerIsString = true; + return tokenizerToken[i]; } @@ -2451,6 +2462,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) diff --git a/src/p_setup.c b/src/p_setup.c index 7d07e7c18..4153f889a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1400,11 +1400,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] == '.') @@ -1420,30 +1428,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. @@ -1458,7 +1442,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; + } } } }