From 871545024d13b48643f6cc91b03758f347c1486b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Nov 2025 23:15:21 +0100 Subject: [PATCH 1/4] experiment: replace every strcmp with fastcmp did some profiling and in basically every single test fastcmp was twice as fast as strcmp maybe this speeds up some things --- src/blua/lauxlib.c | 6 ++++-- src/blua/lfastcmp.h | 32 ++++++++++++++++++++++++++++++++ src/command.c | 10 +++++----- src/console.c | 2 +- src/d_clisrv.c | 4 ++-- src/d_main.c | 2 +- src/d_netcmd.c | 12 ++++++------ src/d_netfil.c | 28 ++++++++++++++-------------- src/d_protocol.c | 4 ++-- src/dedicated/i_system.c | 4 ++-- src/discord.c | 6 +++--- src/doomdef.h | 2 ++ src/filesrch.c | 10 +++++----- src/g_game.c | 11 +++++++---- src/hardware/hw_main.cpp | 2 +- src/hardware/hw_model.c | 8 ++++---- src/lua_hooklib.c | 6 +++--- src/m_aatree.c | 4 ++-- src/m_menu.c | 22 +++++++++++----------- src/m_perfstats.c | 2 +- src/p_saveg.c | 2 +- src/r_data.c | 15 ++++++++------- src/r_patch.cpp | 8 ++++---- src/sdl/hwsym_sdl.c | 3 --- src/sdl/i_system.cpp | 3 ++- src/sdl/i_video.c | 4 ++-- src/sdl/ogl_sdl.c | 4 ++-- src/v_video.c | 5 ++--- 28 files changed, 129 insertions(+), 92 deletions(-) create mode 100644 src/blua/lfastcmp.h diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index e898e38d6..eacce9b44 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -24,6 +24,8 @@ #include "lauxlib.h" +#include "lfastcmp.h" + #define FREELIST_REF 0 /* free list of references */ @@ -40,7 +42,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); lua_getinfo(L, "n", &ar); - if (strcmp(ar.namewhat, "method") == 0) { + if (fastcmp(ar.namewhat, "method")) { narg--; /* do not count `self' */ if (narg == 0) /* error is in the self argument itself? */ return luaL_error(L, "calling " LUA_QS " on bad self (%s)", @@ -97,7 +99,7 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, luaL_checkstring(L, narg); int i; for (i=0; lst[i]; i++) - if (strcmp(lst[i], name) == 0) + if (fastcmp(lst[i], name)) return i; return luaL_argerror(L, narg, lua_pushfstring(L, "invalid option " LUA_QS, name)); diff --git a/src/blua/lfastcmp.h b/src/blua/lfastcmp.h new file mode 100644 index 000000000..f25c59896 --- /dev/null +++ b/src/blua/lfastcmp.h @@ -0,0 +1,32 @@ +#ifndef __FASTCMP_H__ +#define __FASTCMP_H__ + +#include +#include + +// same as fastcmp but we cant use our fancy macros + +// returns false if s != c +// returns true if s == c +__attribute__((always_inline)) static inline bool fasticmp(const char *s, const char *c) +{ + for (; *s && toupper(*s) == toupper(*c); s++, c++) ; + return (*s == *c); // make sure both strings ended +} + +// case-sensitive of the above +__attribute__((always_inline)) static inline bool fastcmp(const char *s, const char *c) +{ + for (; *s && *s == *c; s++, c++) ; + return (*s == *c); // make sure both strings ended +} + +// length-limited of the above +// only true if both strings are at least l characters long AND match, case-sensitively! +__attribute__((always_inline)) static inline bool fastncmp(const char *s, const char *c, uint16_t l) +{ + for (; *s && *s == *c && --l; s++, c++) ; + return !l; // make sure you reached the end +} + +#endif diff --git a/src/command.c b/src/command.c index e73125649..676212703 100644 --- a/src/command.c +++ b/src/command.c @@ -879,7 +879,7 @@ static void COM_Help_f(void) { for (cmd = com_commands; cmd; cmd = cmd->next) { - if (strcmp(cmd->name, help)) + if (!fastcmp(cmd->name, help)) continue; CONS_Printf("\x82""Command %s:\n", cmd->name); @@ -1610,7 +1610,7 @@ void CV_ResetCheatNetVars(void) // Returns true if the variable's current value is its default value boolean CV_IsSetToDefault(consvar_t *v) { - return (!(strcmp(v->defaultvalue, v->string))); + return (fastcmp(v->defaultvalue, v->string)); } // If any cheats CVars are not at their default settings, return true. @@ -1622,7 +1622,7 @@ UINT8 CV_CheatsEnabled(void) consvar_t *cvar; for (cvar = consvar_vars; cvar; cvar = cvar->next) - if ((cvar->flags & CV_CHEAT) && strcmp(cvar->defaultvalue, cvar->string)) + if ((cvar->flags & CV_CHEAT) && !fastcmp(cvar->defaultvalue, cvar->string)) return 1; return 0; } @@ -1799,7 +1799,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) } #define MINVAL 0 #define MAXVAL 1 - else if (var->PossibleValue[MINVAL].strvalue && !strcmp(var->PossibleValue[MINVAL].strvalue, "MIN")) + else if (var->PossibleValue[MINVAL].strvalue && fastcmp(var->PossibleValue[MINVAL].strvalue, "MIN")) { // SRB2Kart #ifdef PARANOIA if (!var->PossibleValue[MAXVAL].strvalue) @@ -2139,7 +2139,7 @@ void CV_SaveVariables(FILE *f) char stringtowrite[MAXTEXTCMD+1]; // Silly hack for Min/Max vars - if (!strcmp(cvar->string, "MAX") || !strcmp(cvar->string, "MIN")) + if (fastcmp(cvar->string, "MAX") || fastcmp(cvar->string, "MIN")) { if (cvar->flags & CV_FLOAT) sprintf(stringtowrite, "%f", FixedToFloat(cvar->value)); diff --git a/src/console.c b/src/console.c index 3959d9b98..062e6ebf3 100644 --- a/src/console.c +++ b/src/console.c @@ -1010,7 +1010,7 @@ boolean CON_Responder(event_t *ev) Lock_state(); // Only add command to history if it differs from previous one - if (strcmp(input.buffer, inputlines[(inputline-1) & 31])) + if (!fastcmp(input.buffer, inputlines[(inputline-1) & 31])) { inputline = (inputline+1) & 31; M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); diff --git a/src/d_clisrv.c b/src/d_clisrv.c index aed5ee347..2ca42df65 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2174,7 +2174,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) if (info->subversion != SUBVERSION) return; // Close, but no cigar. - if (strcmp(info->application, SRB2APPLICATION)) + if (!fastcmp(info->application, SRB2APPLICATION)) return;/* that's a different mod */ i = serverlistcount++; @@ -2219,7 +2219,7 @@ void CL_QueryServerList (msg_server_t *server_list) // thwart nefarious servers who lie to the MS. /* lol bruh, that version COMES from the servers */ - //if (strcmp(version, server_list[i].version) == 0) + //if (fastcmp(version, server_list[i].version)) { INT32 node = I_NetMakeNodewPort(server_list[i].ip, server_list[i].port); if (node == -1) diff --git a/src/d_main.c b/src/d_main.c index 032a9189e..fd643213c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1288,7 +1288,7 @@ static void IdentifyVersion(void) } #if (1) // reduce the amount of findfile by only using full cwd in this func - if (strcmp(tempsrb2path, srb2waddir)) + if (!fastcmp(tempsrb2path, srb2waddir)) #endif { strlcpy(srb2path, srb2waddir, sizeof (srb2path)); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 86c9b12b1..3a5e0ca7e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1508,9 +1508,9 @@ static void SendNameAndColor(void) CV_StealthSet(&cv_playercolor, cv_playercolor.defaultvalue); } - if (!strcmp(cv_playername.string, player_names[consoleplayer]) + if (fastcmp(cv_playername.string, player_names[consoleplayer]) && cv_playercolor.value == players[consoleplayer].skincolor - && !strcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) + && fastcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) return; // We'll handle it later if we're not playing. @@ -2322,8 +2322,8 @@ static void Command_Playdemo_f(void) CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); - demo.loadfiles = strcmp(COM_Argv(2), "-addfiles") == 0; - demo.ignorefiles = strcmp(COM_Argv(2), "-force") == 0; + demo.loadfiles = fastcmp(COM_Argv(2), "-addfiles"); + demo.ignorefiles = fastcmp(COM_Argv(2), "-force"); // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory @@ -5209,14 +5209,14 @@ static void Ringslinger_OnChange(void) static void Gravity_OnChange(void) { if (!M_SecretUnlocked(SECRET_PANDORA) && !netgame && !cv_debug - && strcmp(cv_gravity.string, cv_gravity.defaultvalue)) + && !fastcmp(cv_gravity.string, cv_gravity.defaultvalue)) { CONS_Printf(M_GetText("You haven't earned this yet.\n")); CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); return; } #ifndef NETGAME_GRAVITY - if(netgame) + if (netgame) { CV_StealthSet(&cv_gravity, cv_gravity.defaultvalue); return; diff --git a/src/d_netfil.c b/src/d_netfil.c index 5a1272172..f279eaee0 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -946,17 +946,17 @@ void Got_Filetxpak(void) char *filename = file->filename; static INT32 filetime = 0; - if (!(strcmp(filename, "srb2.srb") - //&& strcmp(filename, "srb2.wad") - //&& strcmp(filename, "patch.dta") - //&& strcmp(filename, "music.dta") - && strcmp(filename, "gfx.kart") - && strcmp(filename, "textures.kart") - && strcmp(filename, "chars.kart") - && strcmp(filename, "maps.kart") - && strcmp(filename, "sounds.kart") - && strcmp(filename, "music.kart") - && strcmp(filename, "patch.kart") + if ((fastcmp(filename, "srb2.srb") + //|| fastcmp(filename, "srb2.wad") + //|| fastcmp(filename, "patch.dta") + //|| fastcmp(filename, "music.dta") + || fastcmp(filename, "gfx.kart") + || fastcmp(filename, "textures.kart") + || fastcmp(filename, "chars.kart") + || fastcmp(filename, "maps.kart") + || fastcmp(filename, "sounds.kart") + || fastcmp(filename, "music.kart") + || fastcmp(filename, "patch.kart") )) I_Error("Tried to download \"%s\"", filename); @@ -1197,7 +1197,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check SRB2's "home" directory (if non-'.') - if (strcmp(srb2home, ".")) + if (!fastcmp(srb2home, ".")) { homecheck = filesearch(filename, srb2home, wantedmd5sum, completepath, 10); @@ -1209,7 +1209,7 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet } // next, check SRB2's "path" directory (also if non-'.') - if (strcmp(srb2path, ".")) + if (!fastcmp(srb2path, ".")) { homecheck = filesearch(filename, srb2path, wantedmd5sum, completepath, 10); @@ -1554,7 +1554,7 @@ CURLGetLogin (const char *url, HTTP_login ***return_prev_next) ( login = (*prev_next)); prev_next = &login->next ){ - if (strcmp(login->url, url) == 0) + if (fastcmp(login->url, url) != 0) { if (return_prev_next) (*return_prev_next) = prev_next; diff --git a/src/d_protocol.c b/src/d_protocol.c index 6ceb05100..963d8e587 100644 --- a/src/d_protocol.c +++ b/src/d_protocol.c @@ -211,12 +211,12 @@ void D_SetupProtocol(void) if (result) { - if (strcmp(buffer, "no") == 0) + if (!fastcmp(buffer, "no")) { fclose(fp); return; } - else if (strcmp(buffer, exe_path) != 0) + else if (fastcmp(buffer, exe_path)) { // overwrite fclose(fp); diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 78f265e2a..d2ffa12ad 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1709,9 +1709,9 @@ char *I_GetUserName(void) strncpy(username, p, MAXPLAYERNAME); } - - if (strcmp(username, "") != 0) + if (!fastcmp(username, "")) return username; + return NULL; // dummy for platform independent version } diff --git a/src/discord.c b/src/discord.c index f94cd574d..8f937cfc1 100644 --- a/src/discord.c +++ b/src/discord.c @@ -277,7 +277,7 @@ static void DRPC_HandleJoinRequest(const DiscordUser *requestUser) while (append != NULL) { // CHECK FOR DUPES!! Ignore any that already exist from the same user. - if (!strcmp(newRequest->userID, append->userID)) + if (fastcmp(newRequest->userID, append->userID)) { Discord_Respond(newRequest->userID, DISCORD_REPLY_IGNORE); DRPC_RemoveRequest(newRequest); @@ -419,7 +419,7 @@ static const char *DRPC_GetServerIP(void) // If you're connected if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL) { - if (strcmp(address, "self")) + if (!fastcmp(address, "self")) { // We're not the server, so we could successfully get the IP! // No need to do anything else :) @@ -684,7 +684,7 @@ void DRPC_UpdatePresence(void) // Character image while (supportedSkins[checkSkin] != NULL) { - if (!strcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin])) + if (fastcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin])) { snprintf(charimg, 21, "char%s", supportedSkins[checkSkin]); discordPresence.smallImageKey = charimg; diff --git a/src/doomdef.h b/src/doomdef.h index a0c76fa61..0329eb7f8 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -69,6 +69,8 @@ extern "C" { #include #include +#include "fastcmp.h" + #ifdef _WIN32 #include #endif diff --git a/src/filesrch.c b/src/filesrch.c index 628a221c2..b9821d368 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -353,7 +353,7 @@ void searchfilemenu(char *tempname) { for (i = first; i < sizedirmenu; i++) { - if (!strcmp(dirmenu[i]+DIR_STRING, tempname)) + if (fastcmp(dirmenu[i]+DIR_STRING, tempname)) { dir_on[menudepthleft] = i; break; @@ -400,7 +400,7 @@ void searchfilemenu(char *tempname) { if (filemenucmp(coredirmenu[i]+DIR_STRING, localmenusearch)) { - if (tempname && !strcmp(coredirmenu[i]+DIR_STRING, tempname)) + if (tempname && fastcmp(coredirmenu[i]+DIR_STRING, tempname)) { dir_on[menudepthleft] = sizedirmenu; Z_Free(tempname); @@ -587,7 +587,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) nameonly(filenamebuf[i]); } - if (strcmp(dent->d_name, filenamebuf[i])) + if (!fastcmp(dent->d_name, filenamebuf[i])) continue; if (cv_addons_md5.value && !checkfilemd5(menupath, wadfiles[i]->md5sum)) @@ -598,11 +598,11 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) } else if (ext == EXT_TXT) { - if (!strncmp(dent->d_name, "log-", 4) || !strcmp(dent->d_name, "errorlog.txt")) + if (!strncmp(dent->d_name, "log-", 4) || fastcmp(dent->d_name, "errorlog.txt")) ext |= EXT_LOADED; } - if (!strcmp(dent->d_name, configfile)) + if (fastcmp(dent->d_name, configfile)) ext |= EXT_LOADED; } diff --git a/src/g_game.c b/src/g_game.c index 796c154d5..05615df78 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3463,7 +3463,8 @@ void G_LoadGameData(void) if (READUINT32(save.p) != 0xFCAFE211) { const char *gdfolder = "the SRB2Kart folder"; - if (strcmp(srb2home,".")) + + if (!fastcmp(srb2home,".")) gdfolder = srb2home; Z_Free(save.buffer); @@ -3547,7 +3548,8 @@ void G_LoadGameData(void) datacorrupt: { const char *gdfolder = "the SRB2Kart folder"; - if (strcmp(srb2home,".")) + + if (!fastcmp(srb2home,".")) gdfolder = srb2home; Z_Free(save.buffer); @@ -3758,7 +3760,8 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) memset(vcheck, 0, sizeof (vcheck)); sprintf(vcheck, "version %d", VERSION); - if (strcmp((const char *)save.p, (const char *)vcheck)) + + if (!fastcmp((const char *)save.p, (const char *)vcheck)) { #ifdef SAVEGAME_OTHERVERSIONS M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"), @@ -4036,7 +4039,7 @@ char *G_BuildMapTitle(INT32 mapnum) if (!mapheaderinfo[mapnum-1]) P_AllocMapHeader(mapnum-1); - if (strcmp(mapheaderinfo[mapnum-1]->lvlttl, "")) + if (!fastcmp(mapheaderinfo[mapnum-1]->lvlttl, "")) { size_t len = 1; const char *zonetext = NULL; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 45f25c2a6..be96fc901 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5840,7 +5840,7 @@ static void COM_HWR_glinfo(void) { argv = COM_Argv(i); - if (strcmp(argv, "--list-extensions") == 0 || strcmp(argv, "-l") == 0) + if (fastcmp(argv, "--list-extensions")|| fastcmp(argv, "-l")) { list_extensions = 1; } diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 6a9825402..77a995ed0 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -163,22 +163,22 @@ model_t *LoadModel(const char *filename, int ztag) return NULL; } - if (!strcmp(extension, ".md3")) + if (fastcmp(extension, ".md3")) { if (!(model = MD3_LoadModel(filename, ztag, false))) return NULL; } - else if (!strcmp(extension, ".md3s")) // MD3 that will be converted in memory to use full floats + else if (fastcmp(extension, ".md3s")) // MD3 that will be converted in memory to use full floats { if (!(model = MD3_LoadModel(filename, ztag, true))) return NULL; } - else if (!strcmp(extension, ".md2")) + else if (fastcmp(extension, ".md2")) { if (!(model = MD2_LoadModel(filename, ztag, false))) return NULL; } - else if (!strcmp(extension, ".md2s")) + else if (fastcmp(extension, ".md2s")) { if (!(model = MD2_LoadModel(filename, ztag, true))) return NULL; diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 6d04b6154..50dd46c61 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -83,7 +83,7 @@ FUNCINLINE static ATTRINLINE unsigned hook_in_list for (type = 0; list[type] != NULL; ++type) { - if (strcmp(name, list[type]) == 0) + if (fastcmp(name, list[type])) break; } @@ -240,7 +240,7 @@ static int lib_addHook(lua_State *L) { add_hook(&hookIds[type]); } - /*else if (strcmp(name, "HUD") == 0) // ehh this is cool and all, but i dont want modders potentially breaking vanilla clients lol + /*else if (fastcmp(name, "HUD")) // ehh this is cool and all, but i dont want modders potentially breaking vanilla clients lol { add_hud_hook(L, 3); }*/ @@ -818,7 +818,7 @@ typedef struct { FUNCINLINE static ATTRINLINE boolean checkbotkey(const char *field) { - return lua_toboolean(gL, -1) && strcmp(lua_tostring(gL, -2), field) == 0; + return lua_toboolean(gL, -1) && fastcmp(lua_tostring(gL, -2), field); } static void res_botai(Hook_State *hook) diff --git a/src/m_aatree.c b/src/m_aatree.c index 34e8e1d87..f78355eaf 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -183,7 +183,7 @@ static aatree_node_t *M_AATreeSetString_Node(aatree_node_t *node, UINT32 flags, else { aatree_entry_t *entry = node->value; - if (entry != NULL && strcmp(entry->key, key) != 0) + if (entry != NULL && !fastcmp(entry->key, key)) entry = entry->next; if (entry != NULL) { @@ -252,7 +252,7 @@ void *M_AATreeGetString(aatree_t *aatree, const char *key) I_Assert((aatree->flags & AATREE_STRING) == AATREE_STRING); UINT32 hash = FNV1a_HashString(key); aatree_entry_t *entry = M_AATreeGet_Node(aatree->root, hash); - while (entry != NULL && strcmp(entry->key, key) != 0) + while (entry != NULL && !fastcmp(entry->key, key)) entry = entry->next; return entry != NULL ? entry->value : NULL; } diff --git a/src/m_menu.c b/src/m_menu.c index 49398df34..bd79ec80c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3719,10 +3719,10 @@ static void M_HandleAddons(INT32 choice) break; case EXT_TXT: case EXT_CFG: - if ((strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") == 0) - || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg") == 0)) + if (fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") + || fastcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg")) { M_StartMessage(va("%c%s\x80\nYou can't autoload this builds' base console scripts, silly!\n They're already autoloaded on startup! \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); S_StartSound(NULL, sfx_s26d); @@ -3830,7 +3830,7 @@ static void ReplayNamesLoadThread(void* userdata) Lock_search_state(); - if (strcmp(menupath, replaydirpath) == 0) + if (fastcmp(menupath, replaydirpath)) { memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*sizedirmenu); replaynamesloaded = true; @@ -6799,7 +6799,7 @@ static int ServerListEntryComparator_##key(const void *entry1, const void *entry const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sa->info.key != sb->info.key) \ return sa->info.key - sb->info.key; \ - return strcmp(sa->info.servername, sb->info.servername); \ + return !fastcmp(sa->info.servername, sb->info.servername); \ } // This does descending instead of ascending. @@ -6809,7 +6809,7 @@ static int ServerListEntryComparator_##key##_reverse(const void *entry1, const v const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sb->info.key != sa->info.key) \ return sb->info.key - sa->info.key; \ - return strcmp(sb->info.servername, sa->info.servername); \ + return !fastcmp(sb->info.servername, sa->info.servername); \ } SERVER_LIST_ENTRY_COMPARATOR(time) @@ -6830,8 +6830,8 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en if (modstate_a != modstate_b) return modstate_a - modstate_b; - // Default to strcmp. - return strcmp(sa->info.servername, sb->info.servername); + // Default to !fastcmp. + return !fastcmp(sa->info.servername, sb->info.servername); } void M_SortServerList(void) @@ -8808,7 +8808,7 @@ static boolean M_QuitMultiPlayerMenu(void) size_t l; // send name if changed - if (strcmp(setupm_name, setupm_cvname->string)) + if (!fastcmp(setupm_name, setupm_cvname->string)) { // remove trailing whitespaces for (l= strlen(setupm_name)-1; @@ -9469,7 +9469,7 @@ static void M_VideoModeMenu(INT32 choice) // VESA mode, which is always a higher modenum for (j = 0; j < vidm_nummodes; j++) { - if (!strcmp(modedescs[j].desc, desc)) + if (fastcmp(modedescs[j].desc, desc)) { // mode(0): 320x200 is always standard VGA, not vesa if (modedescs[j].modenum) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 7384a6086..75aad72e2 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -916,7 +916,7 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) int len = (int)strlen(str); char* str_ptr; - if (strcmp(".lua", str + len - 4) == 0) + if (fastcmp(".lua", str + len - 4)) { str[len-4] = '\0'; // remove .lua at end } diff --git a/src/p_saveg.c b/src/p_saveg.c index d3a162e2d..570e8e1f0 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3391,7 +3391,7 @@ FUNCINLINE static ATTRINLINE void P_UnArchiveSPGame(savebuffer_t *save, INT16 ma READSTRINGN(save->p, testname, sizeof(testname)); - if (strcmp(testname, timeattackfolder)) + if (!fastcmp(testname, timeattackfolder)) { if (modifiedgame) I_Error("Save game not for this modification."); diff --git a/src/r_data.c b/src/r_data.c index 93ad621fa..893252571 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -867,7 +867,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after \"%s\"'s patch name should be",patchName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after %s's patch name, got \"%s\"",patchName,texturesToken); } @@ -907,7 +907,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after patch \"%s\"'s x coordinate should be",patchName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after patch \"%s\"'s x coordinate, got \"%s\"",patchName,texturesToken); } @@ -996,7 +996,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s name should be",newTextureName); } - else if (strcmp(texturesToken,",")!=0) + else if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s name, got \"%s\"",newTextureName,texturesToken); } @@ -1030,7 +1030,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s width should be",newTextureName); } - if (strcmp(texturesToken,",")!=0) + if (!fastcmp(texturesToken,",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s width, got \"%s\"",newTextureName,texturesToken); } @@ -1066,7 +1066,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) I_Error("Error parsing TEXTURES lump: Unexpected end of file where open curly brace for texture \"%s\" should be",newTextureName); } - if (strcmp(texturesToken,"{")==0) + if (fastcmp(texturesToken,"{")) { if (actuallyLoadTexture) { @@ -1084,7 +1084,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch definition for texture \"%s\" should be",newTextureName); } - while (strcmp(texturesToken,"}")!=0) + while (!fastcmp(texturesToken,"}")) { if (stricmp(texturesToken, "PATCH")==0) { @@ -1334,8 +1334,9 @@ lumpnum_t R_GetFlatNumForName(const char *name) if (lump == LUMPERROR) { - if (strcmp(name, SKYFLATNAME)) + if (!fastcmp(name, SKYFLATNAME)) CONS_Debug(DBG_SETUP, "R_GetFlatNumForName: Could not find flat %.8s\n", name); + lump = W_CheckNumForName("REDFLR"); } diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 09aca078a..1e09ae7bb 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -63,7 +63,7 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) I_Error("Error parsing SPRTINFO lump: Missing sprite info"); else { - if (strcmp(sprinfoToken,"{")==0) + if (fastcmp(sprinfoToken,"{")) { Z_Free(sprinfoToken); sprinfoToken = M_GetToken(NULL); @@ -71,7 +71,7 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); } - while (strcmp(sprinfoToken,"}")!=0) + while (!fastcmp(sprinfoToken,"}")) { if (stricmp(sprinfoToken, "XPIVOT")==0) { @@ -175,7 +175,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where open curly brace for sprite \"%s\" should be",newSpriteName); } - if (strcmp(sprinfoToken,"{")==0) + if (fastcmp(sprinfoToken,"{")) { Z_Free(sprinfoToken); sprinfoToken = M_GetToken(NULL); @@ -183,7 +183,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where definition for sprite \"%s\" should be",newSpriteName); } - while (strcmp(sprinfoToken,"}")!=0) + while (!fastcmp(sprinfoToken,"}")) { if (stricmp(sprinfoToken, "SKIN")==0) { diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index a528796eb..edd685327 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -35,9 +35,6 @@ #define _CREATE_DLL_ // necessary for Unix AND Windows -#define GETFUNC(func) \ - else if (0 == strcmp(#func, funcName)) \ - funcPointer = &func \ // // /** \brief The *hwSym function diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4e9e54d72..5281a7f01 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2288,8 +2288,9 @@ char *I_GetUserName(void) } - if (strcmp(username, "") != 0) + if (!fastcmp(username, "")) return username; + return NULL; // dummy for platform independent version } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 7393d8e4b..5bccceaff 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -905,7 +905,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (!strcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) + if (fastcmp(cv_usejoystick[i].string, "0") || !cv_usejoystick[i].value) cv_usejoystick[i].value = 0; else if (atoi(cv_usejoystick[i].string) <= I_NumJoys() // don't mess if we intentionally set higher than NumJoys && cv_usejoystick[i].value) // update the cvar ONLY if a device exists @@ -977,7 +977,7 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (!strcmp(cv_usejoystick[i].string, "0")) + if (fastcmp(cv_usejoystick[i].string, "0")) { cv_usejoystick[i].value = 0; } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4e60801b3..1b8d54fef 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -170,8 +170,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) } } - if (strcmp((const char*)gl_renderer, "GDI Generic") == 0 && - strcmp((const char*)gl_version, "1.1.0") == 0) + if (fastcmp((const char*)gl_renderer, "GDI Generic") && + fastcmp((const char*)gl_version, "1.1.0")) { // Oh no... Windows gave us the GDI Generic rasterizer, so something is wrong... // The game will crash later on when unsupported OpenGL commands are encountered. diff --git a/src/v_video.c b/src/v_video.c index e7d9a87ca..893a39b20 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -23,7 +23,6 @@ #include "r_main.h" #include "r_fps.h" #include "console.h" - #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h" @@ -134,7 +133,7 @@ static boolean InitCube(void) if (!loaded_config) return false; -#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) +#define diffcons(cv) (!fastcmp(cv.string, cv.defaultvalue)) #define diffconsgamma(cv) (cv.value != 0) #define diffconssat(cv) (cv.value != 10) @@ -596,7 +595,7 @@ void V_ResetPaletteCVars(void) if (!loaded_config) return; -#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) +#define diffcons(cv) (!fastcmp(cv.string, cv.defaultvalue)) if diffcons(cv_palette) CV_StealthSetValue(&cv_palette, atoi(cv_palette.defaultvalue)); if diffcons(cv_palettenum) From dc6bf05f351aca99bb3bf082dca82927c9d29e0f Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Oct 2025 21:50:12 +0200 Subject: [PATCH 2/4] experiment: replace every strcasecmp with fasticmp same as before, tho this is not twice as fast but atleast 1/3 faster --- src/command.c | 2 +- src/d_main.c | 5 +++- src/d_netcmd.c | 66 +++++++++++++++++++++++------------------------ src/doomtype.h | 2 +- src/filesrch.c | 14 +++++----- src/m_argv.c | 2 +- src/s_sound.c | 10 +++---- src/sdl/i_video.c | 8 +++--- 8 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/command.c b/src/command.c index 676212703..d5cbf8041 100644 --- a/src/command.c +++ b/src/command.c @@ -359,7 +359,7 @@ size_t COM_CheckParm(const char *check) size_t i; for (i = 1; i < com_argc; i++) - if (!strcasecmp(check, com_argv[i])) + if (fasticmp(check, com_argv[i])) return i; return 0; } diff --git a/src/d_main.c b/src/d_main.c index fd643213c..ef1855d05 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2156,11 +2156,14 @@ void D_SRB2Main(void) const char *sskill = M_GetNextParm(); for (j = 0; kartspeed_cons_t[j].strvalue; j++) - if (!strcasecmp(kartspeed_cons_t[j].strvalue, sskill)) + { + if (fasticmp(kartspeed_cons_t[j].strvalue, sskill)) { newskill = (INT16)kartspeed_cons_t[j].value; break; } + } + if (!kartspeed_cons_t[j].strvalue) // reached end of the list with no match { j = atoi(sskill); // assume they gave us a skill number, which is okay too diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3a5e0ca7e..4998069c1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1219,7 +1219,7 @@ static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum) for (ix = 0; ix < MAXPLAYERS; ix++) { if (ix != playernum && playeringame[ix] - && strcasecmp(name, player_names[ix]) == 0) + && fasticmp(name, player_names[ix])) { // We shouldn't kick people out just because // they joined the game with the same name @@ -1336,7 +1336,7 @@ static void CleanupPlayerName(INT32 playernum, const char *newname) for (i = 0; i < MAXPLAYERS; i++) { if (i != playernum && playeringame[i] - && strcasecmp(tmpname, player_names[i]) == 0) + && fasticmp(tmpname, player_names[i])) { break; } @@ -1386,7 +1386,7 @@ static void SetPlayerName(INT32 playernum, char *newname) { if (EnsurePlayerNameIsGood(newname, playernum)) { - if (strcasecmp(newname, player_names[playernum]) != 0) + if (fasticmp(newname, player_names[playernum])) { if (netgame) HU_AddChatText(va("\x82*%s renamed to %s", player_names[playernum], newname), false); @@ -1945,7 +1945,7 @@ static void Got_NameAndColor(UINT8 **cp, INT32 playernum) // set name if (player_name_changes[playernum] < MAXNAMECHANGES) { - if (strcasecmp(player_names[playernum], name) != 0) + if (!fasticmp(player_names[playernum], name)) SetPlayerName(playernum, name); } @@ -3194,20 +3194,20 @@ static void Command_Teamchange_f(void) if (G_GametypeHasTeams()) { - if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + if (fasticmp(COM_Argv(1), "red") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + else if (fasticmp(COM_Argv(1), "blue") || fasticmp(COM_Argv(1), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + else if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasSpectators()) { - if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; - else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + else if (fasticmp(COM_Argv(1), "playing") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 3; else error = true; @@ -3284,20 +3284,20 @@ static void Command_Teamchange2_f(void) if (G_GametypeHasTeams()) { - if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + if (fasticmp(COM_Argv(1), "red") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + else if (fasticmp(COM_Argv(1), "blue") || fasticmp(COM_Argv(1), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + else if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasSpectators()) { - if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; - else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + else if (fasticmp(COM_Argv(1), "playing") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 3; else error = true; @@ -3375,20 +3375,20 @@ static void Command_Teamchange3_f(void) if (G_GametypeHasTeams()) { - if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + if (fasticmp(COM_Argv(1), "red") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + else if (fasticmp(COM_Argv(1), "blue") || fasticmp(COM_Argv(1), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + else if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasSpectators()) { - if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; - else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + else if (fasticmp(COM_Argv(1), "playing") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 3; else error = true; @@ -3466,20 +3466,20 @@ static void Command_Teamchange4_f(void) if (G_GametypeHasTeams()) { - if (!strcasecmp(COM_Argv(1), "red") || !strcasecmp(COM_Argv(1), "1")) + if (fasticmp(COM_Argv(1), "red") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(1), "blue") || !strcasecmp(COM_Argv(1), "2")) + else if (fasticmp(COM_Argv(1), "blue") || fasticmp(COM_Argv(1), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + else if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasSpectators()) { - if (!strcasecmp(COM_Argv(1), "spectator") || !strcasecmp(COM_Argv(1), "0")) + if (fasticmp(COM_Argv(1), "spectator") || fasticmp(COM_Argv(1), "0")) NetPacket.packet.newteam = 0; - else if (!strcasecmp(COM_Argv(1), "playing") || !strcasecmp(COM_Argv(1), "1")) + else if (fasticmp(COM_Argv(1), "playing") || fasticmp(COM_Argv(1), "1")) NetPacket.packet.newteam = 3; else error = true; @@ -3565,33 +3565,33 @@ static void Command_ServerTeamChange_f(void) if (G_TagGametype()) { - if (!strcasecmp(COM_Argv(2), "it") || !strcasecmp(COM_Argv(2), "1")) + if (fasticmp(COM_Argv(2), "it") || fasticmp(COM_Argv(2), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(2), "notit") || !strcasecmp(COM_Argv(2), "2")) + else if (fasticmp(COM_Argv(2), "notit") || fasticmp(COM_Argv(2), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(2), "playing") || !strcasecmp(COM_Argv(2), "3")) + else if (fasticmp(COM_Argv(2), "playing") || fasticmp(COM_Argv(2), "3")) NetPacket.packet.newteam = 3; - else if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + else if (fasticmp(COM_Argv(2), "spectator") || fasticmp(COM_Argv(2), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasTeams()) { - if (!strcasecmp(COM_Argv(2), "red") || !strcasecmp(COM_Argv(2), "1")) + if (fasticmp(COM_Argv(2), "red") || fasticmp(COM_Argv(2), "1")) NetPacket.packet.newteam = 1; - else if (!strcasecmp(COM_Argv(2), "blue") || !strcasecmp(COM_Argv(2), "2")) + else if (fasticmp(COM_Argv(2), "blue") || fasticmp(COM_Argv(2), "2")) NetPacket.packet.newteam = 2; - else if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + else if (fasticmp(COM_Argv(2), "spectator") || fasticmp(COM_Argv(2), "0")) NetPacket.packet.newteam = 0; else error = true; } else if (G_GametypeHasSpectators()) { - if (!strcasecmp(COM_Argv(2), "spectator") || !strcasecmp(COM_Argv(2), "0")) + if (fasticmp(COM_Argv(2), "spectator") || fasticmp(COM_Argv(2), "0")) NetPacket.packet.newteam = 0; - else if (!strcasecmp(COM_Argv(2), "playing") || !strcasecmp(COM_Argv(2), "1")) + else if (fasticmp(COM_Argv(2), "playing") || fasticmp(COM_Argv(2), "1")) NetPacket.packet.newteam = 3; else error = true; diff --git a/src/doomtype.h b/src/doomtype.h index 78867ed69..7b0df4841 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -63,7 +63,7 @@ extern "C" { #endif #if defined (__unix__) || defined (__APPLE__) || defined (UNIXCOMMON) #undef stricmp - #define stricmp(x,y) strcasecmp(x,y) + #define stricmp(x,y) !fasticmp(x,y) #undef strnicmp #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif diff --git a/src/filesrch.c b/src/filesrch.c index b9821d368..eb68222e2 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -198,7 +198,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want for (; *path != NULL; path++) { - if (strcasecmp(*path, dent->d_name) == 0) + if (fasticmp(*path, dent->d_name)) { skipfolder = true; break; @@ -212,7 +212,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want } } - if (strcasecmp(".git", dent->d_name) // sanity if you're weird like me + if (!fasticmp(".git", dent->d_name) // sanity if you're weird like me && (dirhandle[depthleft-1] = opendir(searchpath)) != NULL) { // Got read permissions! @@ -227,7 +227,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want // I am a file! - if (strcasecmp(searchname, dent->d_name)) + if (!fasticmp(searchname, dent->d_name)) continue; // Not what we're looking for! switch (checkfilemd5(searchpath, wantedmd5sum)) @@ -478,14 +478,14 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) if (replayhut) { - if (strcasecmp(".lmp", dent->d_name+len-5)) + if (!fasticmp(".lmp", dent->d_name+len-5)) continue; // Not a replay } else if (!cv_addons_showall.value) { UINT8 ext; for (ext = 0; ext < NUM_EXT_TABLE; ext++) - if (!strcasecmp(exttable[ext]+1, dent->d_name+len-(exttable[ext][0]))) + if (fasticmp(exttable[ext]+1, dent->d_name+len-(exttable[ext][0]))) break; // extension comparison if (ext == NUM_EXT_TABLE) @@ -559,7 +559,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) if (replayhut) { - if (strcasecmp(".lmp", dent->d_name+len-5)) + if (!fasticmp(".lmp", dent->d_name+len-5)) continue; // Not a replay ext = EXT_TXT; // This isn't used anywhere but better safe than sorry for messing with this... @@ -567,7 +567,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) else { for (; ext < NUM_EXT_TABLE; ext++) - if (!strcasecmp(exttable[ext]+1, dent->d_name+len-(exttable[ext][0]))) + if (fasticmp(exttable[ext]+1, dent->d_name+len-(exttable[ext][0]))) break; // extension comparison if (ext == NUM_EXT_TABLE && !cv_addons_showall.value) diff --git a/src/m_argv.c b/src/m_argv.c index 2ec1b188a..b62d390d9 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -49,7 +49,7 @@ INT32 M_CheckParm(const char *check) for (i = 1; i < myargc; i++) { - if (!strcasecmp(check, myargv[i])) + if (fasticmp(check, myargv[i])) { found = i; return i; diff --git a/src/s_sound.c b/src/s_sound.c index 1bac40a46..e3e86c5b0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1828,7 +1828,7 @@ void S_StopMusic(void) || demo.title) // SRB2Kart: Demos don't interrupt title screen music return; - mapmusic.resume = (cv_birdmusic.value && (strcasecmp(music.name, mapmusic.name) == 0)) ? I_GetSongPosition() : 0; + mapmusic.resume = (cv_birdmusic.value && fasticmp(music.name, mapmusic.name)) ? I_GetSongPosition() : 0; S_SetKeepMusResume(); @@ -1964,7 +1964,7 @@ static void S_SetKeepMusResume(void) { keepmusic.resume = 0; - if (strcasecmp(music.name, mapmusic.name) == 0) + if (fasticmp(music.name, mapmusic.name)) { keepmusic.resume = I_GetSongPosition(); } @@ -2148,19 +2148,19 @@ static void Command_Tunes_f(void) tunenum = (UINT16)atoi(tunearg); track = 0; - if (!strcasecmp(tunearg, "-show")) + if (fasticmp(tunearg, "-show")) { CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), mapmusic.name, (mapmusic.flags & MUSIC_TRACKMASK)); return; } - if (!strcasecmp(tunearg, "-none")) + if (fasticmp(tunearg, "-none")) { S_StopMusic(); return; } - else if (!strcasecmp(tunearg, "-default")) + else if (fasticmp(tunearg, "-default")) { tunearg = mapheaderinfo[gamemap-1]->musname; track = mapheaderinfo[gamemap-1]->mustrack; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5bccceaff..2ea66dbc2 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1785,11 +1785,11 @@ void I_StartupGraphics(void) if (rendermode == render_none) { - if (strcasecmp(word, "software") == 0) + if (fasticmp(word, "software")) { rendermode = render_soft; } - else if (strcasecmp(word, "opengl") == 0) + else if (fasticmp(word, "opengl")) { rendermode = render_opengl; } @@ -1802,7 +1802,7 @@ void I_StartupGraphics(void) if (!msaa_set) { - if (strcasecmp(word, "msaa") == 0) + if (fasticmp(word, "msaa")) { const char *nextword = strtok(NULL, " \n"); @@ -1819,7 +1819,7 @@ void I_StartupGraphics(void) if (!a2c_set) { - if (strcasecmp(word, "a2c") == 0) + if (fasticmp(word, "a2c")) { a2c = true; CONS_Printf("Using a2c because it was specified to be used earlier\n"); From df1085548399eb2c1e6e023b45cae671a632b953 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 Oct 2025 14:25:30 +0200 Subject: [PATCH 3/4] fix oopsie that broke name change --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4998069c1..f0601d9fa 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1386,7 +1386,7 @@ static void SetPlayerName(INT32 playernum, char *newname) { if (EnsurePlayerNameIsGood(newname, playernum)) { - if (fasticmp(newname, player_names[playernum])) + if (!fasticmp(newname, player_names[playernum])) { if (netgame) HU_AddChatText(va("\x82*%s renamed to %s", player_names[playernum], newname), false); From 467688552184e38c2935a9e7ab3a93ea00d4238d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Nov 2025 23:15:52 +0100 Subject: [PATCH 4/4] fixup: replace stricmp with fasticmp actually replace everything correctly my dumbass forgor about the fast both strcmp and stricmp matter in sort stuff so we cannot use the fastcmp stuff there, which means we should not redifine stricmp as fasticmp in case something relies on that behaviour ugh --- src/blua/lauxlib.c | 2 +- src/blua/lfastcmp.h | 32 ------------ src/blua/liolib.c | 8 +-- src/command.c | 72 +++++++++++++------------- src/d_clisrv.c | 7 +-- src/d_main.c | 14 ++--- src/d_netfil.c | 5 +- src/doomtype.h | 2 +- src/g_demo.c | 20 ++++---- src/g_game.c | 2 +- src/g_input.c | 7 +-- src/hardware/hw_md2.c | 12 +++-- src/hardware/hw_model.c | 2 +- src/hardware/hw_shaders.c | 8 +-- src/k_kart.c | 5 +- src/lua_consolelib.c | 2 +- src/lua_mobjlib.c | 6 +-- src/m_emotes.cpp | 4 +- src/m_menu.c | 8 +-- src/m_misc.c | 2 +- src/p_spec.c | 52 ++++++++++++++----- src/r_data.c | 36 +++++++++---- src/r_patch.cpp | 104 +++++++++++++++++++++----------------- src/r_skins.c | 46 ++++++++--------- src/s_sound.c | 31 +++++++----- src/w_wad.c | 10 ++-- 26 files changed, 267 insertions(+), 232 deletions(-) delete mode 100644 src/blua/lfastcmp.h diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index eacce9b44..e91faa182 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -24,7 +24,7 @@ #include "lauxlib.h" -#include "lfastcmp.h" +#include "../doomdef.h" #define FREELIST_REF 0 /* free list of references */ diff --git a/src/blua/lfastcmp.h b/src/blua/lfastcmp.h deleted file mode 100644 index f25c59896..000000000 --- a/src/blua/lfastcmp.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __FASTCMP_H__ -#define __FASTCMP_H__ - -#include -#include - -// same as fastcmp but we cant use our fancy macros - -// returns false if s != c -// returns true if s == c -__attribute__((always_inline)) static inline bool fasticmp(const char *s, const char *c) -{ - for (; *s && toupper(*s) == toupper(*c); s++, c++) ; - return (*s == *c); // make sure both strings ended -} - -// case-sensitive of the above -__attribute__((always_inline)) static inline bool fastcmp(const char *s, const char *c) -{ - for (; *s && *s == *c; s++, c++) ; - return (*s == *c); // make sure both strings ended -} - -// length-limited of the above -// only true if both strings are at least l characters long AND match, case-sensitively! -__attribute__((always_inline)) static inline bool fastncmp(const char *s, const char *c, uint16_t l) -{ - for (; *s && *s == *c && --l; s++, c++) ; - return !l; // make sure you reached the end -} - -#endif diff --git a/src/blua/liolib.c b/src/blua/liolib.c index 40e3e4582..929937e2e 100644 --- a/src/blua/liolib.c +++ b/src/blua/liolib.c @@ -161,12 +161,13 @@ static int io_tostring (lua_State *L) { static int StartsWith(const char *a, const char *b) // this is wolfs being lazy yet again { - if(strncmp(a, b, strlen(b)) == 0) return 1; + if (strncmp(a, b, strlen(b)) == 0) return 1; return 0; } -static int io_open (lua_State *L) { +static int io_open(lua_State *L) +{ FILE **pf; const char *filename = luaL_checkstring(L, 1); int pass = 0; @@ -178,12 +179,13 @@ static int io_open (lua_State *L) { for (i = 0; i < (sizeof (whitelist) / sizeof(const char *)); i++) { - if (!stricmp(&filename[length - strlen(whitelist[i])], whitelist[i])) + if (fasticmp(&filename[length - strlen(whitelist[i])], whitelist[i])) { pass = 1; break; } } + if (l_unlikely(strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\") || StartsWith(filename, "/") || !pass)) { diff --git a/src/command.c b/src/command.c index d5cbf8041..9f9b39500 100644 --- a/src/command.c +++ b/src/command.c @@ -456,7 +456,7 @@ void COM_AddCommand(const char *name, com_func_t func) // fail if the command already exists for (cmd = com_commands; cmd; cmd = cmd->next) { - if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! + if (fasticmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! { // don't I_Error for Lua commands // Lua commands can replace game commands, and they have priority. @@ -492,7 +492,7 @@ int COM_AddLuaCommand(const char *name) // command already exists for (cmd = com_commands; cmd; cmd = cmd->next) { - if (!stricmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! + if (fasticmp(name, cmd->name)) //case insensitive now that we have lower and uppercase! { // replace the built in command. cmd->function = COM_Lua_f; @@ -519,7 +519,7 @@ static boolean COM_Exists(const char *com_name) xcommand_t *cmd; for (cmd = com_commands; cmd; cmd = cmd->next) - if (!stricmp(com_name, cmd->name)) + if (fasticmp(com_name, cmd->name)) return true; return false; @@ -571,7 +571,7 @@ static void COM_ExecuteString(char *ptext) // check functions for (cmd = com_commands; cmd; cmd = cmd->next) { - if (!stricmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase! + if (fasticmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase! { cmd->function(); return; @@ -581,7 +581,7 @@ static void COM_ExecuteString(char *ptext) // check aliases for (a = com_alias; a; a = a->next) { - if (!stricmp(com_argv[0], a->name)) + if (fasticmp(com_argv[0], a->name)) { if (recursion > MAX_ALIAS_RECURSION) CONS_Alert(CONS_WARNING, M_GetText("Alias recursion cycle detected!\n")); @@ -836,7 +836,7 @@ static void COM_Help_f(void) if (cvar->PossibleValue) { { - if (!stricmp(cvar->PossibleValue[0].strvalue, "MIN") && !stricmp(cvar->PossibleValue[1].strvalue, "MAX")) + if (fasticmp(cvar->PossibleValue[0].strvalue, "MIN") && fasticmp(cvar->PossibleValue[1].strvalue, "MAX")) { if (floatmode) { @@ -1176,7 +1176,7 @@ consvar_t *CV_FindVar(const char *name) consvar_t *cvar; for (cvar = consvar_vars; cvar; cvar = cvar->next) - if (!stricmp(name,cvar->name)) + if (fasticmp(name,cvar->name)) return cvar; return NULL; @@ -1366,7 +1366,7 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth) v = INT32_MIN; // Invalid integer trigger } - if (var->PossibleValue[0].strvalue && !stricmp(var->PossibleValue[0].strvalue, "MIN")) // bounded cvar + if (var->PossibleValue[0].strvalue && fasticmp(var->PossibleValue[0].strvalue, "MIN")) // bounded cvar { #define MINVAL 0 #define MAXVAL 1 @@ -1379,21 +1379,21 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth) // search for other for (i = MAXVAL+1; var->PossibleValue[i].strvalue; i++) - if (v == var->PossibleValue[i].value || !stricmp(var->PossibleValue[i].strvalue, valstr)) + if (v == var->PossibleValue[i].value || fasticmp(var->PossibleValue[i].strvalue, valstr)) { var->value = var->PossibleValue[i].value; var->string = var->PossibleValue[i].strvalue; goto finish; } - if ((v != INT32_MIN && v < var->PossibleValue[MINVAL].value) || !stricmp(valstr, "MIN")) + if ((v != INT32_MIN && v < var->PossibleValue[MINVAL].value) || fasticmp(valstr, "MIN")) { v = var->PossibleValue[MINVAL].value; valstr = var->PossibleValue[MINVAL].strvalue; override = true; overrideval = v; } - else if ((v != INT32_MIN && v > var->PossibleValue[MAXVAL].value) || !stricmp(valstr, "MAX")) + else if ((v != INT32_MIN && v > var->PossibleValue[MAXVAL].value) || fasticmp(valstr, "MAX")) { v = var->PossibleValue[MAXVAL].value; valstr = var->PossibleValue[MAXVAL].strvalue; @@ -1411,7 +1411,7 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth) // check first strings for (i = 0; var->PossibleValue[i].strvalue; i++) - if (!stricmp(var->PossibleValue[i].strvalue, valstr)) + if (fasticmp(var->PossibleValue[i].strvalue, valstr)) goto found; if (v != INT32_MIN) { @@ -1424,9 +1424,9 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth) if (var->PossibleValue == CV_OnOff || var->PossibleValue == CV_YesNo) { overrideval = -1; - if (!stricmp(valstr, "on") || !stricmp(valstr, "yes")) + if (fasticmp(valstr, "on") || fasticmp(valstr, "yes")) overrideval = 1; - else if (!stricmp(valstr, "off") || !stricmp(valstr, "no")) + else if (fasticmp(valstr, "off") || fasticmp(valstr, "no")) overrideval = 0; if (overrideval != -1) @@ -1643,7 +1643,7 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) if (!var->string) I_Error("CV_Set: %s no string set!\n", var->name); #endif - if (!var || !var->string || !value || !stricmp(var->string, value)) + if (!var || !var->string || !value || fasticmp(var->string, value)) return; // no changes if (var->flags & CV_NETVAR) @@ -1665,7 +1665,7 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) if (var == &cv_kartspeed && !M_SecretUnlocked(SECRET_HARDSPEED)) { - if (!stricmp(value, "Hard") || atoi(value) == 2) + if (fasticmp(value, "Hard") || atoi(value) == 2) { CONS_Alert(CONS_NOTICE, "You haven't unlocked this yet!\n"); return; @@ -1971,12 +1971,12 @@ static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) { if (joyaxis_default[i]) { - if (!stricmp(v->name, "joyaxis_fire")) + if (fasticmp(v->name, "joyaxis_fire")) { if (joyaxis_count[i] > 7) return false; else if (joyaxis_count[i] == 7) return true; - if (!stricmp(valstr, "None")) joyaxis_count[i]++; + if (fasticmp(valstr, "None")) joyaxis_count[i]++; else joyaxis_default[i] = false; } // reset all axis settings to defaults @@ -2008,37 +2008,37 @@ static boolean CV_FilterJoyAxisVars(consvar_t *v, const char *valstr) // Block the Xbox DInput default axes and reset to the current defaults static boolean CV_FilterJoyAxisVars2(consvar_t *v, const char *valstr) { - if (!stricmp(v->name, "joyaxis_turn") && !stricmp(valstr, "X-Axis")) + if (fasticmp(v->name, "joyaxis_turn") && fasticmp(valstr, "X-Axis")) return false; - if (!stricmp(v->name, "joyaxis2_turn") && !stricmp(valstr, "X-Axis")) + if (fasticmp(v->name, "joyaxis2_turn") && fasticmp(valstr, "X-Axis")) return false; - if (!stricmp(v->name, "joyaxis3_turn") && !stricmp(valstr, "X-Axis")) + if (fasticmp(v->name, "joyaxis3_turn") && fasticmp(valstr, "X-Axis")) return false; - if (!stricmp(v->name, "joyaxis4_turn") && !stricmp(valstr, "X-Axis")) + if (fasticmp(v->name, "joyaxis4_turn") && fasticmp(valstr, "X-Axis")) return false; - if (!stricmp(v->name, "joyaxis_aim") && !stricmp(valstr, "Y-Axis")) + if (fasticmp(v->name, "joyaxis_aim") && fasticmp(valstr, "Y-Axis")) return false; - if (!stricmp(v->name, "joyaxis2_aim") && !stricmp(valstr, "Y-Axis")) + if (fasticmp(v->name, "joyaxis2_aim") && fasticmp(valstr, "Y-Axis")) return false; - if (!stricmp(v->name, "joyaxis3_aim") && !stricmp(valstr, "Y-Axis")) + if (fasticmp(v->name, "joyaxis3_aim") && fasticmp(valstr, "Y-Axis")) return false; - if (!stricmp(v->name, "joyaxis4_aim") && !stricmp(valstr, "Y-Axis")) + if (fasticmp(v->name, "joyaxis4_aim") && fasticmp(valstr, "Y-Axis")) return false; - if (!stricmp(v->name, "joyaxis_fire") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis_fire") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis2_fire") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis2_fire") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis3_fire") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis3_fire") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis4_fire") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis4_fire") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis_drift") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis_drift") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis2_drift") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis2_drift") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis3_drift") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis3_drift") && fasticmp(valstr, "None")) return false; - if (!stricmp(v->name, "joyaxis4_drift") && !stricmp(valstr, "None")) + if (fasticmp(v->name, "joyaxis4_drift") && fasticmp(valstr, "None")) return false; return true; @@ -2055,8 +2055,8 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr) if (GETMAJOREXECVERSION(cv_execversion.value) < 8) // 8 = 1.4 { - if (!stricmp(v->name, "masterserver") // Replaces a hack in MasterServer_OnChange for the original SRB2 MS. - || !stricmp(v->name, "gamma")) // Too easy to accidentially change in prior versions. + if (fasticmp(v->name, "masterserver") // Replaces a hack in MasterServer_OnChange for the original SRB2 MS. + || fasticmp(v->name, "gamma")) // Too easy to accidentially change in prior versions. return false; } diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 2ca42df65..255e7ce8e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3215,7 +3215,7 @@ static void Command_connect(void) server = false; - if (!stricmp(COM_Argv(1), "self")) + if (fasticmp(COM_Argv(1), "self")) { servernode = 0; server = true; @@ -3225,7 +3225,7 @@ static void Command_connect(void) else { // used in menu to connect to a server in the list - if (netgame && !stricmp(COM_Argv(1), "node")) + if (netgame && fasticmp(COM_Argv(1), "node")) { servernode = (SINT8)atoi(COM_Argv(2)); } @@ -3240,7 +3240,7 @@ static void Command_connect(void) netgame = true; multiplayer = true; - if (!stricmp(COM_Argv(1), "any")) + if (fasticmp(COM_Argv(1), "any")) servernode = BROADCASTADDR; else if (I_NetMakeNodewPort && COM_Argc() >= 3) servernode = I_NetMakeNodewPort(COM_Argv(1), COM_Argv(2)); @@ -3264,6 +3264,7 @@ static void Command_connect(void) splitscreen = cv_splitplayers.value-1; SplitScreen_OnChange(); } + botingame = false; botskin = 0; CL_ConnectToServer(); diff --git a/src/d_main.c b/src/d_main.c index ef1855d05..bafc110e1 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1078,19 +1078,19 @@ static INT32 D_DetectFileType(const char* filename) const size_t len = strlen(filename); - if (!stricmp(&filename[len - 4], ".wad")) + if (fasticmp(&filename[len - 4], ".wad")) return 2; - else if (!stricmp(&filename[len - 4], ".pk3")) + else if (fasticmp(&filename[len - 4], ".pk3")) return 3; - else if (!stricmp(&filename[len - 5], ".kart")) + else if (fasticmp(&filename[len - 5], ".kart")) return 4; - else if (!stricmp(&filename[len - 4], ".lua")) + else if (fasticmp(&filename[len - 4], ".lua")) return 5; - else if (!stricmp(&filename[len - 4], ".soc")) + else if (fasticmp(&filename[len - 4], ".soc")) return 6; - else if (!stricmp(&filename[len - 4], ".cfg")) + else if (fasticmp(&filename[len - 4], ".cfg")) return 7; - else if (!stricmp(&filename[len - 4], ".txt")) + else if (fasticmp(&filename[len - 4], ".txt")) return 8; return 0; diff --git a/src/d_netfil.c b/src/d_netfil.c index f279eaee0..c82165788 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -550,7 +550,8 @@ INT32 CL_CheckFiles(void) for (j = mainwads+1; j < numwadfiles; j++) { nameonly(strcpy(wadfilename, wadfiles[j]->filename)); - if (!stricmp(wadfilename, fileneeded[i].filename) && + + if (fasticmp(wadfilename, fileneeded[i].filename) && !memcmp(wadfiles[j]->md5sum, fileneeded[i].md5sum, 16)) { CONS_Debug(DBG_NETPLAY, "already loaded\n"); @@ -665,7 +666,7 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid) strlcpy(wadfilename, wadfiles[wadnum]->filename, MAX_WADPATH); nameonly(wadfilename); - if (!stricmp(wadfilename, p->id.filename)) + if (fasticmp(wadfilename, p->id.filename)) { // Copy file name with full path strlcpy(p->id.filename, wadfiles[wadnum]->filename, MAX_WADPATH); diff --git a/src/doomtype.h b/src/doomtype.h index 7b0df4841..78867ed69 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -63,7 +63,7 @@ extern "C" { #endif #if defined (__unix__) || defined (__APPLE__) || defined (UNIXCOMMON) #undef stricmp - #define stricmp(x,y) !fasticmp(x,y) + #define stricmp(x,y) strcasecmp(x,y) #undef strnicmp #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif diff --git a/src/g_demo.c b/src/g_demo.c index bd3905160..7ee773b1f 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -264,7 +264,7 @@ void G_ReadDemoExtraData(void) kartspeed = READUINT8(demobuf.p); kartweight = READUINT8(demobuf.p); - if (stricmp(skins[players[p].skin].name, name) != 0) + if (!fasticmp(skins[players[p].skin].name, name)) FindClosestSkinForStats(p, kartspeed, kartweight); players[p].kartspeed = kartspeed; @@ -277,7 +277,7 @@ void G_ReadDemoExtraData(void) M_Memcpy(name, demobuf.p, 16); demobuf.p += 16; for (i = 0; i < MAXSKINCOLORS; i++) - if (!stricmp(KartColor_Names[i], name)) // SRB2kart + if (fasticmp(KartColor_Names[i], name)) // SRB2kart { players[p].skincolor = i; if (players[p].mo) @@ -2289,7 +2289,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo) { for (UINT8 j = 0; kartspeed_cons_t[j].strvalue; j++) { - if (!stricmp(kartspeed_cons_t[j].strvalue, svalue)) + if (fasticmp(kartspeed_cons_t[j].strvalue, svalue)) pdemo->kartspeed = kartspeed_cons_t[j].value; } } @@ -2321,7 +2321,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo) for (i = 0; i < numskins; i++) { - if (stricmp(skins[i].name, temp) == 0) + if (fasticmp(skins[i].name, temp)) { pdemo->standings[count].skin = i; break; @@ -2334,7 +2334,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo) for (i = 0; i < MAXSKINCOLORS; i++) { - if (!stricmp(KartColor_Names[i],temp)) // SRB2kart + if (fasticmp(KartColor_Names[i],temp)) // SRB2kart { pdemo->standings[count].color = i; break; @@ -2807,7 +2807,7 @@ void G_DoPlayDemo(char *defdemoname) // Set color for (i = 0; i < MAXSKINCOLORS; i++) { - if (!stricmp(KartColor_Names[i],color)) // SRB2kart + if (fasticmp(KartColor_Names[i],color)) // SRB2kart { players[0].skincolor = i; break; @@ -2947,7 +2947,7 @@ void G_DoPlayDemo(char *defdemoname) for (i = 0; i < MAXSKINCOLORS; i++) { - if (!stricmp(KartColor_Names[i],color)) // SRB2kart + if (fasticmp(KartColor_Names[i],color)) // SRB2kart { players[p].skincolor = i; break; @@ -2961,7 +2961,7 @@ void G_DoPlayDemo(char *defdemoname) kartspeed[p] = READUINT8(demobuf.p); kartweight[p] = READUINT8(demobuf.p); - if (stricmp(skins[players[p].skin].name, skin) != 0) + if (!fasticmp(skins[players[p].skin].name, skin)) FindClosestSkinForStats(p, kartspeed[p], kartweight[p]); // Look for the next player @@ -3242,7 +3242,7 @@ void G_AddGhost(char *defdemoname) for (i = 0; i < numskins; i++) { - if (!stricmp(skins[i].name,skin)) + if (fasticmp(skins[i].name, skin)) { ghskin = &skins[i]; break; @@ -3317,7 +3317,7 @@ void G_AddGhost(char *defdemoname) for (i = 0; i < MAXSKINCOLORS; i++) { - if (!stricmp(KartColor_Names[i],color)) // SRB2kart + if (fasticmp(KartColor_Names[i],color)) // SRB2kart { gh->mo->color = (UINT8)i; break; diff --git a/src/g_game.c b/src/g_game.c index 05615df78..125c88067 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2768,7 +2768,7 @@ INT32 G_GetGametypeByName(const char *gametypestr) INT32 i; for (i = 0; i < NUMGAMETYPES; i++) - if (!stricmp(gametypestr, Gametype_Names[i])) + if (fasticmp(gametypestr, Gametype_Names[i])) return i; return -1; // unknown gametype diff --git a/src/g_input.c b/src/g_input.c index e8bc8223e..e5cd04668 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -1033,7 +1033,7 @@ INT32 G_KeyStringtoNum(const char *keystr) return atoi(&keystr[3]); for (j = 0; j < NUMKEYNAMES; j++) - if (!stricmp(keynames[j].name, keystr)) + if (fasticmp(keynames[j].name, keystr)) return keynames[j].keynum; return 0; @@ -1333,14 +1333,15 @@ static void setcontrol(INT32 (*gc)[2]) player = 0; namectrl = COM_Argv(1); - for (numctrl = 0; numctrl < num_gamecontrols && stricmp(namectrl, gamecontrolname[numctrl]); - numctrl++) + for (numctrl = 0; numctrl < num_gamecontrols && !fasticmp(namectrl, gamecontrolname[numctrl]); numctrl++) ; + if (numctrl == num_gamecontrols) { CONS_Printf(M_GetText("Control '%s' unknown\n"), namectrl); return; } + keynum1 = G_KeyStringtoNum(COM_Argv(2)); keynum2 = G_KeyStringtoNum(COM_Argv(3)); keynum = G_FilterKeyByVersion(numctrl, 0, player, &keynum1, &keynum2, &nestedoverride); diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f3db532e9..10e5e4e1b 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -549,7 +549,7 @@ void HWR_InitMD2(void) { for (i = 0; i < NUMSPRITES; i++) { - if (stricmp(name, sprnames[i]) == 0) + if (fasticmp(name, sprnames[i])) { md2_models[i].scale = scale; md2_models[i].offset = offset; @@ -561,7 +561,7 @@ void HWR_InitMD2(void) for (s = 0; s < MAXSKINS; s++) { - if (stricmp(name, skins[s].name) == 0) + if (fasticmp(name, skins[s].name)) { md2_playermodels[s].skin = s; md2_playermodels[s].scale = scale; @@ -607,11 +607,12 @@ void HWR_AddPlayerMD2(int skin, boolean local) // For MD2's that were added afte } } - md2s = ( (local) ? md2_localplayermodels : md2_playermodels ); + md2s = (local ? md2_localplayermodels : md2_playermodels); + // Check for any MD2s that match the names of player skins! while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) { - if (stricmp(name, K_GetSkinArray(local)[skin].name) == 0) + if (fasticmp(name, K_GetSkinArray(local)[skin].name)) { md2s[skin].skin = skin; md2s[skin].scale = scale; @@ -650,6 +651,7 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu if (!f) { f = fopen(va("%s"PATHSEP"%s", srb2path, "mdls.dat"), "rt"); + if (!f) { CONS_Printf("%s %s\n", M_GetText("Error while loading mdls.dat:"), strerror(errno)); @@ -661,7 +663,7 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu // Check for any MD2s that match the names of sprite names! while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) { - if (stricmp(name, sprnames[spritenum]) == 0) + if (fasticmp(name, sprnames[spritenum])) { md2_models[spritenum].scale = scale; md2_models[spritenum].offset = offset; diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 77a995ed0..811ac3b67 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -126,7 +126,7 @@ tag_t *GetTagByName(model_t *model, char *name, int frame) int i; for (i = 0; i < model->numTags; i++) { - if (!stricmp(iterator[i].name, name)) + if (fasticmp(iterator[i].name, name)) return &iterator[i]; } } diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 9724378fe..19aea915e 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -586,7 +586,7 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) goto skip_field; } - if (!stricmp(stoken, "GLSL")) + if (fasticmp(stoken, "GLSL")) { value = strtok(NULL, "\r\n "); if (!value) @@ -596,9 +596,9 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) goto skip_lump; } - if (!stricmp(value, "VERTEX")) + if (fasticmp(value, "VERTEX")) shadertype = 1; - else if (!stricmp(value, "FRAGMENT")) + else if (fasticmp(value, "FRAGMENT")) shadertype = 2; skip_lump: @@ -624,7 +624,7 @@ skip_lump: for (i = 0; shaderxlat[i].type; i++) { - if (!stricmp(shaderxlat[i].type, stoken)) + if (fasticmp(shaderxlat[i].type, stoken)) { size_t shader_string_length; char *shader_source; diff --git a/src/k_kart.c b/src/k_kart.c index 7f755e235..3f335a5bb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -637,11 +637,14 @@ void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, bo UINT8 K_GetKartColorByName(const char *name) { UINT8 color = (UINT8)atoi(name); + if (color > 0 && color < MAXSKINCOLORS) return color; + for (color = 1; color < MAXSKINCOLORS; color++) - if (!stricmp(KartColor_Names[color], name)) + if (fasticmp(KartColor_Names[color], name)) return color; + return 0; } diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 36c3a6c45..df45e3e07 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -453,7 +453,7 @@ static int lib_cvRegisterVar(lua_State *L) if (cvar->flags & CV_MODIFIED) return luaL_error(L, "failed to register cvar (probable conflict with internal variable/command names)"); - if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP)) && (cvar->PossibleValue || !(cvar->value == 0 && stricmp(cvar->string, "0")))) + if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP)) && (cvar->PossibleValue || !(cvar->value == 0 && !fasticmp(cvar->string, "0")))) { if (!category) { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 5ffbcb34e..fef27f563 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -455,12 +455,12 @@ int mobj_localskin_setter(lua_State *L) strlcpy(skin, luaL_optstring(L, 2, "none"), sizeof skin); strlwr(skin); // all skin names are lowercase - if (stricmp(skin, "none")) + if (!fasticmp(skin, "none")) { // Try localskins for (i = 0; i < numlocalskins; i++) { - if (stricmp(localskins[i].name, skin) == 0) + if (fasticmp(localskins[i].name, skin)) { mo->localskin = &localskins[i]; mo->skinlocal = true; @@ -471,7 +471,7 @@ int mobj_localskin_setter(lua_State *L) // Try other skins for (i = 0; i < numskins; i++) { - if (stricmp(skins[i].name, skin) == 0) + if (fasticmp(skins[i].name, skin)) { mo->localskin = &skins[i]; mo->skinlocal = false; diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 57058ef23..45fd78804 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -112,7 +112,7 @@ void M_LoadEmotes(UINT16 wadnum) trim(field); trim(value); - if (stricmp(field.c_str(), "frames") == 0) + if (fasticmp(field.c_str(), "frames")) { UINT8 numframes = 0; @@ -158,7 +158,7 @@ void M_LoadEmotes(UINT16 wadnum) emote->numframes = numframes; } - else if (stricmp(field.c_str(), "timeperframe") == 0) + else if (fasticmp(field.c_str(), "timeperframe")) { emote->timeperframe = std::stoi(value); diff --git a/src/m_menu.c b/src/m_menu.c index bd79ec80c..09a0c6350 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6799,7 +6799,7 @@ static int ServerListEntryComparator_##key(const void *entry1, const void *entry const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sa->info.key != sb->info.key) \ return sa->info.key - sb->info.key; \ - return !fastcmp(sa->info.servername, sb->info.servername); \ + return strcmp(sa->info.servername, sb->info.servername); \ } // This does descending instead of ascending. @@ -6809,7 +6809,7 @@ static int ServerListEntryComparator_##key##_reverse(const void *entry1, const v const serverelem_t *sa = (const serverelem_t*)entry1, *sb = (const serverelem_t*)entry2; \ if (sb->info.key != sa->info.key) \ return sb->info.key - sa->info.key; \ - return !fastcmp(sb->info.servername, sa->info.servername); \ + return strcmp(sb->info.servername, sa->info.servername); \ } SERVER_LIST_ENTRY_COMPARATOR(time) @@ -6830,8 +6830,8 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en if (modstate_a != modstate_b) return modstate_a - modstate_b; - // Default to !fastcmp. - return !fastcmp(sa->info.servername, sb->info.servername); + // Default to strcmp. + return strcmp(sa->info.servername, sb->info.servername); } void M_SortServerList(void) diff --git a/src/m_misc.c b/src/m_misc.c index 4a0a163aa..58e4b191e 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -423,7 +423,7 @@ void Command_SaveConfig_f(void) FIL_ForceExtension(tmpstr, ".cfg"); M_SaveConfig(tmpstr); - if (stricmp(COM_Argv(2), "-silent")) + if (!fasticmp(COM_Argv(2), "-silent")) CONS_Printf(M_GetText("config saved as %s\n"), configfile); } diff --git a/src/p_spec.c b/src/p_spec.c index e7b032131..e08030e9e 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -324,6 +324,7 @@ void P_InitPicAnims(void) lastanim->speed = LONG(animdefs[i].speed); lastanim++; } + lastanim->istexture = -1; R_ClearTextureNumCache(false); @@ -331,6 +332,7 @@ void P_InitPicAnims(void) // We'll only be using anims from now on. if (animdefs != harddefs) Z_Free(animdefs); + animdefs = NULL; } @@ -361,20 +363,21 @@ void P_ParseANIMDEFSLump(INT32 wadNum, UINT16 lumpnum) // Now, let's start parsing this thing p = animdefsText; + animdefsToken = M_GetToken(p); while (animdefsToken != NULL) { - if (stricmp(animdefsToken, "TEXTURE") == 0) + if (fasticmp(animdefsToken, "TEXTURE")) { Z_Free(animdefsToken); P_ParseAnimationDefintion(1); } - else if (stricmp(animdefsToken, "FLAT") == 0) + else if (fasticmp(animdefsToken, "FLAT")) { Z_Free(animdefsToken); P_ParseAnimationDefintion(0); } - else if (stricmp(animdefsToken, "OSCILLATE") == 0) + else if (fasticmp(animdefsToken, "OSCILLATE")) { // This probably came off the tail of an earlier definition. It's technically legal syntax, but we don't support it. I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"OSCILLATE\" (the animation plays in reverse when it reaches the end) are not supported by SRB2"); @@ -383,11 +386,17 @@ void P_ParseANIMDEFSLump(INT32 wadNum, UINT16 lumpnum) { I_Error("Error parsing ANIMDEFS lump: Expected \"TEXTURE\" or \"FLAT\", got \"%s\"",animdefsToken); } + // parse next line - while (*p != '\0' && *p != '\n') ++p; - if (*p == '\n') ++p; + while (*p != '\0' && *p != '\n') + ++p; + + if (*p == '\n') + ++p; + animdefsToken = M_GetToken(p); } + Z_Free(animdefsToken); Z_Free((void *)animdefsText); } @@ -406,7 +415,8 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where start texture/flat name should be"); } - if (stricmp(animdefsToken, "OPTIONAL") == 0) + + if (fasticmp(animdefsToken, "OPTIONAL")) { // This is meaningful to ZDoom - it tells the program NOT to bomb out // if the textures can't be found - but it's useless in SRB2, so we'll @@ -418,7 +428,7 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where start texture/flat name should be"); } - else if (stricmp(animdefsToken, "RANGE") == 0) + else if (fasticmp(animdefsToken, "RANGE")) { // Oh. Um. Apparently "OPTIONAL" is a texture name. Naughty. // I should probably handle this more gracefully, but right now @@ -427,15 +437,17 @@ void P_ParseAnimationDefintion(SINT8 istexture) I_Error("Error parsing ANIMDEFS lump: \"OPTIONAL\" is a keyword; you cannot use it as the startname of an animation"); } } + animdefsTokenLength = strlen(animdefsToken); - if (animdefsTokenLength>8) + if (animdefsTokenLength > 8) { I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); } // Search for existing animdef for (i = 0; i < maxanims; i++) - if (stricmp(animdefsToken, animdefs[i].startname) == 0) + { + if (fasticmp(animdefsToken, animdefs[i].startname)) { //CONS_Alert(CONS_NOTICE, "Duplicate animation: %s\n", animdefsToken); @@ -444,6 +456,7 @@ void P_ParseAnimationDefintion(SINT8 istexture) Z_Free(animdefsToken); return; } + } // Not found if (i == maxanims) @@ -467,21 +480,25 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"RANGE\" after \"%s\"'s startname should be", animdefs[i].startname); } - if (stricmp(animdefsToken, "ALLOWDECALS") == 0) + + if (fasticmp(animdefsToken, "ALLOWDECALS")) { // Another ZDoom keyword, ho-hum. Skip it, move on to the next token. Z_Free(animdefsToken); animdefsToken = M_GetToken(NULL); } - if (stricmp(animdefsToken, "PIC") == 0) + + if (fasticmp(animdefsToken, "PIC")) { // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"PIC\" (specific frames instead of a consecutive range) are not supported by SRB2"); } - if (stricmp(animdefsToken, "RANGE") != 0) + + if (!fasticmp(animdefsToken, "RANGE")) { I_Error("Error parsing ANIMDEFS lump: Expected \"RANGE\" after \"%s\"'s startname, got \"%s\"", animdefs[i].startname, animdefsToken); } + Z_Free(animdefsToken); // Endname @@ -490,11 +507,13 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s end texture/flat name should be", animdefs[i].startname); } + animdefsTokenLength = strlen(animdefsToken); if (animdefsTokenLength>8) { I_Error("Error parsing ANIMDEFS lump: lump name \"%s\" exceeds 8 characters", animdefsToken); } + strncpy(animdefs[i].endname, animdefsToken, 9); Z_Free(animdefsToken); @@ -504,15 +523,18 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s \"TICS\" should be", animdefs[i].startname); } - if (stricmp(animdefsToken, "RAND") == 0) + + if (fasticmp(animdefsToken, "RAND")) { // This is technically legitimate ANIMDEFS syntax, but SRB2 doesn't support it. I_Error("Error parsing ANIMDEFS lump: Animation definitions utilizing \"RAND\" (random duration per frame) are not supported by SRB2"); } - if (stricmp(animdefsToken, "TICS") != 0) + + if (!fasticmp(animdefsToken, "TICS")) { I_Error("Error parsing ANIMDEFS lump: Expected \"TICS\" in animation definition for \"%s\", got \"%s\"", animdefs[i].startname, animdefsToken); } + Z_Free(animdefsToken); // Speed @@ -521,6 +543,7 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Unexpected end of file where \"%s\"'s animation speed should be", animdefs[i].startname); } + endPos = NULL; #ifndef AVOID_ERRNO errno = 0; @@ -535,6 +558,7 @@ void P_ParseAnimationDefintion(SINT8 istexture) { I_Error("Error parsing ANIMDEFS lump: Expected a positive integer for \"%s\"'s animation speed, got \"%s\"", animdefs[i].startname, animdefsToken); } + animdefs[i].speed = animSpeed; Z_Free(animdefsToken); } diff --git a/src/r_data.c b/src/r_data.c index 893252571..3077326ad 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -976,8 +976,9 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where texture name should be"); } + texturesTokenLength = strlen(texturesToken); - if (texturesTokenLength>8) + if (texturesTokenLength > 8) { I_Error("Error parsing TEXTURES lump: Texture name \"%s\" exceeds 8 characters",texturesToken); } @@ -988,6 +989,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) // ^^ we've confirmed that the token is <= 8 characters so it will never overflow a 9 byte char buffer strupr(newTextureName); // Just do this now so we don't have to worry about it } + Z_Free(texturesToken); // Comma 1 @@ -996,10 +998,11 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s name should be",newTextureName); } - else if (!fastcmp(texturesToken,",")) + else if (!fastcmp(texturesToken, ",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s name, got \"%s\"",newTextureName,texturesToken); } + Z_Free(texturesToken); // Width @@ -1030,10 +1033,12 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after texture \"%s\"'s width should be",newTextureName); } - if (!fastcmp(texturesToken,",")) + + if (!fastcmp(texturesToken, ",")) { I_Error("Error parsing TEXTURES lump: Expected \",\" after texture \"%s\"'s width, got \"%s\"",newTextureName,texturesToken); } + Z_Free(texturesToken); // Height @@ -1066,7 +1071,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) I_Error("Error parsing TEXTURES lump: Unexpected end of file where open curly brace for texture \"%s\" should be",newTextureName); } - if (fastcmp(texturesToken,"{")) + if (fastcmp(texturesToken, "{")) { if (actuallyLoadTexture) { @@ -1078,15 +1083,18 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) resultTexture->height = newTextureHeight; resultTexture->type = TEXTURETYPE_COMPOSITE; } + Z_Free(texturesToken); + texturesToken = M_GetToken(NULL); if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch definition for texture \"%s\" should be",newTextureName); } - while (!fastcmp(texturesToken,"}")) + + while (!fastcmp(texturesToken, "}")) { - if (stricmp(texturesToken, "PATCH")==0) + if (fasticmp(texturesToken, "PATCH")) { Z_Free(texturesToken); if (resultTexture) @@ -1118,6 +1126,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch declaration or right curly brace for texture \"%s\" should be",newTextureName); } } + if (resultTexture && resultTexture->patchcount == 0) { I_Error("Error parsing TEXTURES lump: Texture \"%s\" must have at least one patch",newTextureName); @@ -1127,10 +1136,13 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture) { I_Error("Error parsing TEXTURES lump: Expected \"{\" for texture \"%s\", got \"%s\"",newTextureName,texturesToken); } + Z_Free(texturesToken); - if (actuallyLoadTexture) return resultTexture; - else return NULL; + if (actuallyLoadTexture) + return resultTexture; + + return NULL; } // Parses the TEXTURES lump... but just to count the number of textures. @@ -1162,7 +1174,7 @@ int R_CountTexturesInTEXTURESLump(UINT16 wadNum, UINT16 lumpNum) texturesToken = M_GetToken(texturesText); while (texturesToken != NULL) { - if (stricmp(texturesToken, "WALLTEXTURE")==0) + if (fasticmp(texturesToken, "WALLTEXTURE")) { numTexturesInLump++; Z_Free(texturesToken); @@ -1172,8 +1184,10 @@ int R_CountTexturesInTEXTURESLump(UINT16 wadNum, UINT16 lumpNum) { I_Error("Error parsing TEXTURES lump: Expected \"WALLTEXTURE\", got \"%s\"",texturesToken); } + texturesToken = M_GetToken(NULL); } + Z_Free(texturesToken); Z_Free((void *)texturesText); @@ -1211,7 +1225,7 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) texturesToken = M_GetToken(texturesText); while (texturesToken != NULL) { - if (stricmp(texturesToken, "WALLTEXTURE")==0) + if (fasticmp(texturesToken, "WALLTEXTURE")) { Z_Free(texturesToken); // Get the new texture @@ -1227,8 +1241,10 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) { I_Error("Error parsing TEXTURES lump: Expected \"WALLTEXTURE\", got \"%s\"",texturesToken); } + texturesToken = M_GetToken(NULL); } + Z_Free(texturesToken); Z_Free((void *)texturesText); } diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 1e09ae7bb..7510520dd 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -46,13 +46,14 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite frame should be"); } + sprinfoTokenLength = strlen(sprinfoToken); if (sprinfoTokenLength != 1) { I_Error("Error parsing SPRTINFO lump: Invalid frame \"%s\"",sprinfoToken); } - else - frameChar = sprinfoToken; + + frameChar = sprinfoToken; frameFrame = R_Char2Frame(frameChar[0]); Z_Free(sprinfoToken); @@ -61,53 +62,53 @@ static void R_ParseSpriteInfoFrame(spriteinfo_t *info) sprinfoToken = M_GetToken(NULL); if (sprinfoToken == NULL) I_Error("Error parsing SPRTINFO lump: Missing sprite info"); - else + + if (fastcmp(sprinfoToken, "{")) { - if (fastcmp(sprinfoToken,"{")) + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); + } + while (!fastcmp(sprinfoToken, "}")) + { + if (fasticmp(sprinfoToken, "XPIVOT")) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + frameXPivot = atoi(sprinfoToken); + } + else if (fasticmp(sprinfoToken, "YPIVOT")) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + frameYPivot = atoi(sprinfoToken); + } + else if (fasticmp(sprinfoToken, "ROTAXIS")) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + if (fasticmp(sprinfoToken, "X") || fasticmp(sprinfoToken, "XAXIS") || fasticmp(sprinfoToken, "ROLL")) + frameRotAxis = ROTAXIS_X; + else if (fasticmp(sprinfoToken, "Y") || fasticmp(sprinfoToken, "YAXIS") || fasticmp(sprinfoToken, "PITCH")) + frameRotAxis = ROTAXIS_Y; + else if (fasticmp(sprinfoToken, "Z") || fasticmp(sprinfoToken, "ZAXIS") || fasticmp(sprinfoToken, "YAW")) + frameRotAxis = ROTAXIS_Z; + } + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); if (sprinfoToken == NULL) { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); - } - while (!fastcmp(sprinfoToken,"}")) - { - if (stricmp(sprinfoToken, "XPIVOT")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - frameXPivot = atoi(sprinfoToken); - } - else if (stricmp(sprinfoToken, "YPIVOT")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - frameYPivot = atoi(sprinfoToken); - } - else if (stricmp(sprinfoToken, "ROTAXIS")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - if ((stricmp(sprinfoToken, "X")==0) || (stricmp(sprinfoToken, "XAXIS")==0) || (stricmp(sprinfoToken, "ROLL")==0)) - frameRotAxis = ROTAXIS_X; - else if ((stricmp(sprinfoToken, "Y")==0) || (stricmp(sprinfoToken, "YAXIS")==0) || (stricmp(sprinfoToken, "PITCH")==0)) - frameRotAxis = ROTAXIS_Y; - else if ((stricmp(sprinfoToken, "Z")==0) || (stricmp(sprinfoToken, "ZAXIS")==0) || (stricmp(sprinfoToken, "YAW")==0)) - frameRotAxis = ROTAXIS_Z; - } - Z_Free(sprinfoToken); - - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace should be"); - } + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace should be"); } } - Z_Free(sprinfoToken); } + Z_Free(sprinfoToken); + // set fields info->pivot[frameFrame].x = frameXPivot; info->pivot[frameFrame].y = frameYPivot; @@ -137,6 +138,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite name should be"); } + sprinfoTokenLength = strlen(sprinfoToken); if (sprinfoTokenLength != 4) { @@ -149,6 +151,7 @@ static void R_ParseSpriteInfo(boolean spr2) // ^^ we've confirmed that the token is == 4 characters so it will never overflow a 5 byte char buffer strupr(newSpriteName); // Just do this now so we don't have to worry about it } + Z_Free(sprinfoToken); if (!spr2) @@ -157,7 +160,8 @@ static void R_ParseSpriteInfo(boolean spr2) { if (i == NUMSPRITES) I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName); - if (!memcmp(newSpriteName,sprnames[i],4)) + + if (!memcmp(newSpriteName,sprnames[i], 4)) { sprnum = static_cast(i); break; @@ -175,17 +179,20 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where open curly brace for sprite \"%s\" should be",newSpriteName); } - if (fastcmp(sprinfoToken,"{")) + + if (fastcmp(sprinfoToken, "{")) { Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); if (sprinfoToken == NULL) { I_Error("Error parsing SPRTINFO lump: Unexpected end of file where definition for sprite \"%s\" should be",newSpriteName); } - while (!fastcmp(sprinfoToken,"}")) + + while (!fastcmp(sprinfoToken, "}")) { - if (stricmp(sprinfoToken, "SKIN")==0) + if (fasticmp(sprinfoToken, "SKIN")) { INT32 skinnum; char *skinName = NULL; @@ -216,10 +223,11 @@ static void R_ParseSpriteInfo(boolean spr2) skinnumbers[foundskins] = skinnum; foundskins++; } - else if (stricmp(sprinfoToken, "FRAME")==0) + else if (fasticmp(sprinfoToken, "FRAME")) { R_ParseSpriteInfoFrame(info); Z_Free(sprinfoToken); + if (spr2) { if (!foundskins) @@ -254,6 +262,7 @@ static void R_ParseSpriteInfo(boolean spr2) { I_Error("Error parsing SPRTINFO lump: Expected \"{\" for sprite \"%s\", got \"%s\"",newSpriteName,sprinfoToken); } + Z_Free(sprinfoToken); Z_Free(info); } @@ -291,15 +300,18 @@ void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum) while (sprinfoToken != NULL) { CONS_Printf("Attempting to parse le SPRTINFO lump for ya..\n"); - if (!stricmp(sprinfoToken, "SPRITE")) + + if (fasticmp(sprinfoToken, "SPRITE")) R_ParseSpriteInfo(false); - else if (!stricmp(sprinfoToken, "SPRITE2")) + else if (fasticmp(sprinfoToken, "SPRITE2")) R_ParseSpriteInfo(true); else I_Error("Error parsing SPRTINFO lump: Unknown keyword \"%s\"", sprinfoToken); + Z_Free(sprinfoToken); sprinfoToken = M_GetToken(NULL); } + Z_Free((void *)sprinfoText); } diff --git a/src/r_skins.c b/src/r_skins.c index bf731f708..53765e269 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -72,7 +72,7 @@ static void Sk_SetDefaultValue(skin_t *skin, boolean local) // // set default skin values // - memset(skin, 0, sizeof (skin_t)); + memset(skin, 0, sizeof(skin_t)); snprintf(skin->name, sizeof skin->name, "skin %u", K_GetMobjSkinNum(skin, local)); skin->name[sizeof skin->name - 1] = '\0'; @@ -188,7 +188,7 @@ INT32 R_SkinAvailable(const char *name) for (i = 0; i < numskins; i++) { - if (stricmp(skins[i].name, name) == 0) + if (fasticmp(skins[i].name, name)) return i; } @@ -203,7 +203,7 @@ INT32 R_AnySkinAvailable(const char *name) for (i = 0; i < numallskins; i++) { - if (stricmp(allskins[i].name, name) == 0) + if (fasticmp(allskins[i].name, name)) return i; } @@ -218,7 +218,7 @@ INT32 R_LocalSkinAvailable(const char *name, boolean local) { for (i = 0; i < numlocalskins; i++) { - if (stricmp(localskins[i].name, name) == 0) + if (fasticmp(localskins[i].name, name)) return i; } @@ -236,7 +236,7 @@ boolean SetPlayerSkin(INT32 playernum, const char *skinname) for (i = 0; i < numskins; i++) { // search in the skin list - if (stricmp(skins[i].name, skinname) == 0) + if (fasticmp(skins[i].name, skinname)) { SetPlayerSkinByNum(playernum, i); return true; @@ -257,12 +257,12 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) INT32 i; player_t *player = &players[playernum]; - if (stricmp(skinname, "none")) + if (!fasticmp(skinname, "none")) { for (i = 0; i < numlocalskins; i++) { // search in the localskin list - if (stricmp(localskins[i].name, skinname) == 0) + if (fasticmp(localskins[i].name, skinname)) { player->localskin = 1 + i; player->skinlocal = true; @@ -280,7 +280,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) for (i = 0; i < numskins; i++) { // search in the skin list - if (stricmp(skins[i].name, skinname) == 0) + if (fasticmp(skins[i].name, skinname)) { player->localskin = 1 + i; player->skinlocal = false; @@ -530,7 +530,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) hudname = realname = false; // parse - stoken = strtok (buf2, "\r\n= "); + stoken = strtok(buf2, "\r\n= "); while (stoken) { if ((stoken[0] == '/' && stoken[1] == '/') @@ -546,7 +546,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (!value) I_Error("R_AddSkins: syntax error in S_SKIN lump# %d(%s) in WAD %s\n", lump, W_CheckNameForNumPwad(wadnum,lump), wadfiles[wadnum]->filename); - if (!stricmp(stoken, "name")) + if (fasticmp(stoken, "name")) { // the skin name must uniquely identify a single skin // I'm lazy so if name is already used I leave the 'skin x' @@ -592,7 +592,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (*value == '_') *value = ' '; // turn _ into spaces. } } - else if (!stricmp(stoken, "realname")) + else if (fasticmp(stoken, "realname")) { // Display name (eg. "Knuckles") realname = true; STRBUFCPY(skin->realname, value); @@ -603,7 +603,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (!hudname) STRBUFCPY(skin->hudname, skin->realname); } - else if (!stricmp(stoken, "hudname")) + else if (fasticmp(stoken, "hudname")) { // Life icon name (eg. "K.T.E") hudname = true; STRBUFCPY(skin->hudname, value); @@ -614,34 +614,34 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (!realname) STRBUFCPY(skin->realname, skin->hudname); } - else if (!stricmp(stoken, "sprite")) + else if (fasticmp(stoken, "sprite")) { strupr(value); memcpy(skin->sprite, value, sizeof skin->sprite); } - else if (!stricmp(stoken, "facerank")) + else if (fasticmp(stoken, "facerank")) { strupr(value); memcpy(skin->facerank, value, sizeof(skin->facerank)-1); skin->facerank[sizeof(skin->facerank)-1] = '\0'; } - else if (!stricmp(stoken, "facewant")) + else if (fasticmp(stoken, "facewant")) { strupr(value); memcpy(skin->facewant, value, sizeof(skin->facewant)-1); skin->facewant[sizeof(skin->facewant)-1] = '\0'; } - else if (!stricmp(stoken, "facemmap")) + else if (fasticmp(stoken, "facemmap")) { strupr(value); strncpy(skin->facemmap, value, sizeof(skin->facemmap)-1); skin->facemmap[sizeof(skin->facemmap)-1] = '\0'; } - else if (!stricmp(stoken, "flags")) // character type identification + else if (fasticmp(stoken, "flags")) // character type identification { skin->flags = get_number(value); } - else if (!stricmp(stoken, "kartspeed")) + else if (fasticmp(stoken, "kartspeed")) { skin->kartspeed = atoi(value); @@ -650,7 +650,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (skin->kartspeed > 9) skin->kartspeed = 9; } - else if (!stricmp(stoken, "kartweight")) + else if (fasticmp(stoken, "kartweight")) { skin->kartweight = atoi(value); @@ -660,15 +660,15 @@ void R_AddSkins(UINT16 wadnum, boolean local) skin->kartweight = 9; } // custom translation table - else if (!stricmp(stoken, "startcolor")) + else if (fasticmp(stoken, "startcolor")) { skin->starttranscolor = atoi(value); } - else if (!stricmp(stoken, "prefcolor")) + else if (fasticmp(stoken, "prefcolor")) { skin->prefcolor = K_GetKartColorByName(value); } - else if (!stricmp(stoken, "highresscale")) + else if (fasticmp(stoken, "highresscale")) { skin->highresscale = FLOAT_TO_FIXED(atof(value)); } @@ -687,7 +687,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) continue; if (sfx->skinsound != -1 - && !stricmp(sfx->name, stoken + 2)) + && fasticmp(sfx->name, stoken + 2)) { skin->soundsid[sfx->skinsound] = S_AddSoundFx(value+2, sfx->singularity, sfx->pitch, true); found = true; diff --git a/src/s_sound.c b/src/s_sound.c index e3e86c5b0..1e3f8bf7a 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1095,9 +1095,12 @@ void S_StartSoundName(void *mo, const char *soundname) // Search existing sounds... for (i = sfx_None + 1; i < NUMSFX; i++) { - if (!S_sfx[i].name) + const sfxinfo_t *sfx = &S_sfx[i]; + + if (!sfx->name) continue; - if (!stricmp(S_sfx[i].name, soundname)) + + if (fasticmp(sfx->name, soundname)) { soundnum = i; break; @@ -1110,6 +1113,7 @@ void S_StartSoundName(void *mo, const char *soundname) { if (newsounds[i] == 0) break; + if (!S_IdPlaying(newsounds[i])) { S_RemoveSoundFx(newsounds[i]); @@ -1266,7 +1270,7 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) char *value; char *textline; - if (!stricmp(stoken, "lump")) + if (fasticmp(stoken, "lump")) { value = strtok(NULL, " "); @@ -1341,24 +1345,24 @@ skip_lump: for (textline = def->field; *textline; textline++)\ if (*textline == '_') *textline = ' '; - if (!stricmp(stoken, "usage")) + if (fasticmp(stoken, "usage")) { ADDDEF(usage); } - else if (!stricmp(stoken, "source")) + else if (fasticmp(stoken, "source")) { ADDDEF(source); } - else if (!stricmp(stoken, "title")) + else if (fasticmp(stoken, "title")) { def->use_info = true; ADDDEF(title); } - else if (!stricmp(stoken, "alttitle")) + else if (fasticmp(stoken, "alttitle")) { ADDDEF(alttitle); } - else if (!stricmp(stoken, "authors")) + else if (fasticmp(stoken, "authors")) { ADDDEF(authors); } @@ -1479,7 +1483,8 @@ musicdef_t *S_FindMusicCredit(const char *musname) if (hash != def->hash) continue; - if (stricmp(def->name, musname)) + + if (!fasticmp(def->name, musname)) continue; return def; @@ -1934,7 +1939,7 @@ static const char *musicexception_list[] = { // check if the current music is smth we dont want to keep (vote music, etc) static boolean S_CheckMusicException(void) { - if (stricmp(music.name, mapmusic.name)) + if (!fasticmp(music.name, mapmusic.name)) return true; // dumb hack but dont keepmusic music that is supposed to reset @@ -1944,7 +1949,7 @@ static boolean S_CheckMusicException(void) // in case somehow the mapmusic was replaced with smth we dont want to keep for (size_t i = 0; i < sizeof(musicexception_list)/sizeof(musicexception_list[0]); i++) { - if (!stricmp(music.name, musicexception_list[i]) || !stricmp(checkmusic, musicexception_list[i])) + if (fasticmp(music.name, musicexception_list[i]) || fasticmp(checkmusic, musicexception_list[i])) { return true; } @@ -2030,12 +2035,12 @@ static boolean S_SkipIntroMusic(void) return false; // check if menu music is playing, otherwise it may continue playing - if (!stricmp(music.name, "titles")) + if (fasticmp(music.name, "titles")) return false; char *maptitle = G_BuildMapTitle(gamemap); // Zzz... - if (maptitle && !stricmp(maptitle, "Wandering Falls")) // wandering balls changes its song when the race starts Zzz... + if (maptitle && fasticmp(maptitle, "Wandering Falls")) // wandering balls changes its song when the race starts Zzz... { Z_Free(maptitle); return false; diff --git a/src/w_wad.c b/src/w_wad.c index f9eb9b361..96fe56303 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -375,11 +375,11 @@ static restype_t ResourceFileDetect(const char* filename) { size_t len = strlen(filename) - 4; - if (!stricmp(&filename[len], ".pk3")) + if (fasticmp(&filename[len], ".pk3")) return RET_PK3; - if (!stricmp(&filename[len], ".soc")) + if (fasticmp(&filename[len], ".soc")) return RET_SOC; - if (!stricmp(&filename[len], ".lua")) + if (fasticmp(&filename[len], ".lua")) return RET_LUA; return RET_WAD; @@ -1130,7 +1130,7 @@ UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) { if (lump_p->longnamelength == namelen && lump_p->hash.longname == hash - && !stricmp(lump_p->longname, name)) + && fasticmp(lump_p->longname, name)) return i; } } @@ -1230,7 +1230,7 @@ static lumpnum_t CheckLumpInCache(const char *name, boolean longname) for (INT32 i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--) { if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].hash == hash - && stricmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0) + && fasticmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name)) { lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); return lumpnumcache[lumpnumcacheindex].lumpnum;