From afe24bd4f0bf7a2db722d5d7c255676251f8c70a Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 29 Apr 2017 16:40:07 +0100 Subject: [PATCH] Get rid of stack overflow code because filesystem case insensitivity is Windows exlcusive, so we can just create a wrapper function for there instead of rolling our own. --- src/doomtype.h | 4 ---- src/filesrch.c | 25 +++++++++++++++++++++++-- src/string.c | 38 -------------------------------------- 3 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 6ef847cfc..a711b466d 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -170,10 +170,6 @@ size_t strlcat(char *dst, const char *src, size_t siz); size_t strlcpy(char *dst, const char *src, size_t siz); #endif -#if 1 // don't know what systems don't have this -char* stristr(char* haystack, const char* needle); -#endif - // Macro for use with char foo[FOOSIZE+1] type buffers. // Never use this with a buffer that is a "char *" or passed // into the function as an argument. diff --git a/src/filesrch.c b/src/filesrch.c index d0c97c498..a0c9b8231 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -510,7 +510,19 @@ char exttable[NUM_EXT_TABLE][5] = { char filenamebuf[MAX_WADFILES][MAX_WADPATH]; -#define searchdir if (menusearch[0] && !stristr(dent->d_name, menusearch+1))\ +#ifdef _WIN32 +static char *strsystemstr(char *haystack, char *needle) +{ + char uprhaystack[128]; + strlcpy(uprhaystack, haystack, 128); + strupr(uprhaystack); + return strstr(uprhaystack, needle); +} +#else +#define strsystemstr(haystack, needle) strstr(haystack, needle) +#endif + +#define searchdir if (menusearch[0] && !strsystemstr(dent->d_name, localmenusearch))\ {\ rejected++;\ continue;\ @@ -524,6 +536,7 @@ boolean preparefilemenu(boolean samedepth) size_t pos = 0, folderpos = 0, numfolders = 0, rejected = 0; char *tempname = NULL; boolean noresults = false; + char localmenusearch[MAXSTRINGLENGTH] = ""; if (samedepth) { @@ -544,6 +557,14 @@ boolean preparefilemenu(boolean samedepth) if (dirhandle == NULL) return false; + if (menusearch[0]) + { + strcpy(localmenusearch, menusearch+1); +#ifdef _WIN32 + strupr(localmenusearch); +#endif + } + while (true) { menupath[menupathindex[menudepthleft]] = 0; @@ -651,7 +672,7 @@ boolean preparefilemenu(boolean samedepth) filenamebuf[i][MAX_WADPATH - 1] = '\0'; nameonly(filenamebuf[i]); } - if (strcasecmp(dent->d_name, filenamebuf[i])) + if (strcmp(dent->d_name, filenamebuf[i])) continue; if (checkfilemd5(menupath, wadfiles[i]->md5sum)) ext |= EXT_LOADED; diff --git a/src/string.c b/src/string.c index 1e2c14ac2..5dcd9183c 100644 --- a/src/string.c +++ b/src/string.c @@ -49,42 +49,4 @@ size_t strlcpy(char *dst, const char *src, size_t siz) return strlcat(dst, src, siz); } -#endif - -#if 1 // i don't know what specific OSes are missing this, oh well - -// stack overflow, eep... -char* stristr(char* haystack, const char* needle) -{ - char* p1 = haystack; - const char* p2 = needle; - char* r = ((*p2 == 0) ? haystack : 0); - - while (*p1 != 0 && *p2 != 0) - { - if (tolower(*p1) == tolower(*p2)) - { - if (r == 0) - r = p1; - - p2++; - } - else - { - p2 = needle; - if (tolower(*p1) == tolower(*p2)) - { - r = p1; - p2++; - } - else - r = 0; - } - - p1++; - } - - return ((*p2 == 0) ? r : 0); -} - #endif \ No newline at end of file