From: DeaDDooMER Date: Sun, 31 Jan 2021 13:47:19 +0000 (+0300) Subject: portability: remove dependency on str(n)casemp X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=1e058b808ddb343442012f01d6fd5692920a3018;p=flatwaifu.git portability: remove dependency on str(n)casemp --- diff --git a/src/config.c b/src/config.c index dccf37c..6ebb425 100644 --- a/src/config.c +++ b/src/config.c @@ -22,6 +22,7 @@ #include "system.h" #include "files.h" #include "input.h" +#include "cp866.h" static FILE *f; static int ch; @@ -30,7 +31,7 @@ const cfg_t *CFG_find_entry (const char *key, const cfg_t *cfg) { assert(key != NULL); if (cfg != NULL) { int i = 0; - while (cfg[i].cfg && strcasecmp(cfg[i].cfg, key) != 0) { + while (cfg[i].cfg && cp866_strcasecmp(cfg[i].cfg, key) != 0) { i++; } return cfg[i].cfg ? &cfg[i] : NULL; @@ -50,8 +51,8 @@ int CFG_update_key (const char *key, const char *value, const cfg_t *cfg) { case Y_WORD: *(word*)p = atoi(value); break; case Y_DWORD: *(dword*)p = atoi(value); break; case Y_STRING: strcpy(p, value); break; // TODO fix this security problem - case Y_SW_ON: *(byte*)p = strcasecmp(value, "on") == 0 ? 1 : 0; break; - case Y_SW_OFF: *(byte*)p = strcasecmp(value, "off") == 0 ? 1 : 0; break; + case Y_SW_ON: *(byte*)p = cp866_strcasecmp(value, "on") == 0 ? 1 : 0; break; + case Y_SW_OFF: *(byte*)p = cp866_strcasecmp(value, "off") == 0 ? 1 : 0; break; case Y_FILES: F_addwad(value); break; case Y_KEY: *(int*)p = I_string_to_key(value); break; default: assert(0); // unknown type -> something broken diff --git a/src/gl/render.c b/src/gl/render.c index b7b5c24..948a7b5 100644 --- a/src/gl/render.c +++ b/src/gl/render.c @@ -2007,7 +2007,7 @@ void R_get_name (int n, char s[8]) { static short getani (char n[8]) { short i = 0; - while (i < ANIT - 1 && strncasecmp(n, anm[i][0], 8) != 0) { + while (i < ANIT - 1 && cp866_strncasecmp(n, anm[i][0], 8) != 0) { i++; } return i < ANIT - 1 ? i + 1 : 0; @@ -2060,7 +2060,7 @@ void R_load (char s[8]) { .h = 0, .res = -1, }; - } else if (strncasecmp(s, "_WATER_", 7) == 0) { + } else if (cp866_strncasecmp(s, "_WATER_", 7) == 0) { walp[max_textures] = (image) { .n = (void*)((intptr_t)s[7] - '0' + 1), .x = 0, diff --git a/src/input.c b/src/input.c index bd23877..0a74043 100644 --- a/src/input.c +++ b/src/input.c @@ -14,7 +14,7 @@ */ #include "input.h" -#include +#include "cp866.h" #include static char keystate[KEY__LAST + 1]; @@ -130,110 +130,110 @@ const char *I_key_to_string (int key) { } int I_string_to_key (const char *str) { - if (strcasecmp(str, "0") == 0) return KEY_0; - else if (strcasecmp(str, "1") == 0) return KEY_1; - else if (strcasecmp(str, "2") == 0) return KEY_2; - else if (strcasecmp(str, "3") == 0) return KEY_3; - else if (strcasecmp(str, "4") == 0) return KEY_4; - else if (strcasecmp(str, "5") == 0) return KEY_5; - else if (strcasecmp(str, "6") == 0) return KEY_6; - else if (strcasecmp(str, "7") == 0) return KEY_7; - else if (strcasecmp(str, "8") == 0) return KEY_8; - else if (strcasecmp(str, "9") == 0) return KEY_9; - else if (strcasecmp(str, "A") == 0) return KEY_A; - else if (strcasecmp(str, "B") == 0) return KEY_B; - else if (strcasecmp(str, "C") == 0) return KEY_C; - else if (strcasecmp(str, "D") == 0) return KEY_D; - else if (strcasecmp(str, "E") == 0) return KEY_E; - else if (strcasecmp(str, "F") == 0) return KEY_F; - else if (strcasecmp(str, "G") == 0) return KEY_G; - else if (strcasecmp(str, "H") == 0) return KEY_H; - else if (strcasecmp(str, "I") == 0) return KEY_I; - else if (strcasecmp(str, "J") == 0) return KEY_J; - else if (strcasecmp(str, "K") == 0) return KEY_K; - else if (strcasecmp(str, "L") == 0) return KEY_L; - else if (strcasecmp(str, "M") == 0) return KEY_M; - else if (strcasecmp(str, "N") == 0) return KEY_N; - else if (strcasecmp(str, "O") == 0) return KEY_O; - else if (strcasecmp(str, "P") == 0) return KEY_P; - else if (strcasecmp(str, "Q") == 0) return KEY_Q; - else if (strcasecmp(str, "R") == 0) return KEY_R; - else if (strcasecmp(str, "S") == 0) return KEY_S; - else if (strcasecmp(str, "T") == 0) return KEY_T; - else if (strcasecmp(str, "U") == 0) return KEY_U; - else if (strcasecmp(str, "V") == 0) return KEY_V; - else if (strcasecmp(str, "W") == 0) return KEY_W; - else if (strcasecmp(str, "X") == 0) return KEY_X; - else if (strcasecmp(str, "Y") == 0) return KEY_Y; - else if (strcasecmp(str, "Z") == 0) return KEY_Z; - else if (strcasecmp(str, "RETURN") == 0) return KEY_RETURN; - else if (strcasecmp(str, "ESCAPE") == 0) return KEY_ESCAPE; - else if (strcasecmp(str, "BACKSPACE") == 0) return KEY_BACKSPACE; - else if (strcasecmp(str, "TAB") == 0) return KEY_TAB; - else if (strcasecmp(str, "SPACE") == 0) return KEY_SPACE; - else if (strcasecmp(str, "MINUS") == 0) return KEY_MINUS; - else if (strcasecmp(str, "EQUALS") == 0) return KEY_EQUALS; - else if (strcasecmp(str, "LEFTBRACKET") == 0) return KEY_LEFTBRACKET; - else if (strcasecmp(str, "RIGHTBRACKET") == 0) return KEY_RIGHTBRACKET; - else if (strcasecmp(str, "BACKSLASH") == 0) return KEY_BACKSLASH; - else if (strcasecmp(str, "SEMICOLON") == 0) return KEY_SEMICOLON; - else if (strcasecmp(str, "APOSTROPHE") == 0) return KEY_APOSTROPHE; - else if (strcasecmp(str, "GRAVE") == 0) return KEY_GRAVE; - else if (strcasecmp(str, "COMMA") == 0) return KEY_COMMA; - else if (strcasecmp(str, "PERIOD") == 0) return KEY_PERIOD; - else if (strcasecmp(str, "SLASH") == 0) return KEY_SLASH; - else if (strcasecmp(str, "CAPSLOCK") == 0) return KEY_CAPSLOCK; - else if (strcasecmp(str, "F1") == 0) return KEY_F1; - else if (strcasecmp(str, "F2") == 0) return KEY_F2; - else if (strcasecmp(str, "F3") == 0) return KEY_F3; - else if (strcasecmp(str, "F4") == 0) return KEY_F4; - else if (strcasecmp(str, "F5") == 0) return KEY_F5; - else if (strcasecmp(str, "F6") == 0) return KEY_F6; - else if (strcasecmp(str, "F7") == 0) return KEY_F7; - else if (strcasecmp(str, "F8") == 0) return KEY_F8; - else if (strcasecmp(str, "F9") == 0) return KEY_F9; - else if (strcasecmp(str, "F10") == 0) return KEY_F10; - else if (strcasecmp(str, "F11") == 0) return KEY_F11; - else if (strcasecmp(str, "F12") == 0) return KEY_F12; - else if (strcasecmp(str, "PRINTSCREEN") == 0) return KEY_PRINTSCREEN; - else if (strcasecmp(str, "SCROLLLOCK") == 0) return KEY_SCROLLLOCK; - else if (strcasecmp(str, "PAUSE") == 0) return KEY_PAUSE; - else if (strcasecmp(str, "INSERT") == 0) return KEY_INSERT; - else if (strcasecmp(str, "HOME") == 0) return KEY_HOME; - else if (strcasecmp(str, "PAGEUP") == 0) return KEY_PAGEUP; - else if (strcasecmp(str, "DELETE") == 0) return KEY_DELETE; - else if (strcasecmp(str, "END") == 0) return KEY_END; - else if (strcasecmp(str, "PAGEDOWN") == 0) return KEY_PAGEDOWN; - else if (strcasecmp(str, "RIGHT") == 0) return KEY_RIGHT; - else if (strcasecmp(str, "LEFT") == 0) return KEY_LEFT; - else if (strcasecmp(str, "DOWN") == 0) return KEY_DOWN; - else if (strcasecmp(str, "UP") == 0) return KEY_UP; - else if (strcasecmp(str, "NUMLOCK") == 0) return KEY_NUMLOCK; - else if (strcasecmp(str, "KP_DIVIDE") == 0) return KEY_KP_DIVIDE; - else if (strcasecmp(str, "KP_MULTIPLY") == 0) return KEY_KP_MULTIPLY; - else if (strcasecmp(str, "KP_MINUS") == 0) return KEY_KP_MINUS; - else if (strcasecmp(str, "KP_PLUS") == 0) return KEY_KP_PLUS; - else if (strcasecmp(str, "KP_ENTER") == 0) return KEY_KP_ENTER; - else if (strcasecmp(str, "KP_0") == 0) return KEY_KP_0; - else if (strcasecmp(str, "KP_1") == 0) return KEY_KP_1; - else if (strcasecmp(str, "KP_2") == 0) return KEY_KP_2; - else if (strcasecmp(str, "KP_3") == 0) return KEY_KP_3; - else if (strcasecmp(str, "KP_4") == 0) return KEY_KP_4; - else if (strcasecmp(str, "KP_5") == 0) return KEY_KP_5; - else if (strcasecmp(str, "KP_6") == 0) return KEY_KP_6; - else if (strcasecmp(str, "KP_7") == 0) return KEY_KP_7; - else if (strcasecmp(str, "KP_8") == 0) return KEY_KP_8; - else if (strcasecmp(str, "KP_9") == 0) return KEY_KP_9; - else if (strcasecmp(str, "KP_PERIOD") == 0) return KEY_KP_PERIOD; - else if (strcasecmp(str, "SYSREQ") == 0) return KEY_SYSREQ; - else if (strcasecmp(str, "LCTRL") == 0) return KEY_LCTRL; - else if (strcasecmp(str, "LSHIFT") == 0) return KEY_LSHIFT; - else if (strcasecmp(str, "LALT") == 0) return KEY_LALT; - else if (strcasecmp(str, "LSUPER") == 0) return KEY_LSUPER; - else if (strcasecmp(str, "RCTRL") == 0) return KEY_RCTRL; - else if (strcasecmp(str, "RSHIFT") == 0) return KEY_RSHIFT; - else if (strcasecmp(str, "RALT") == 0) return KEY_RALT; - else if (strcasecmp(str, "RSUPER") == 0) return KEY_RSUPER; + if (cp866_strcasecmp(str, "0") == 0) return KEY_0; + else if (cp866_strcasecmp(str, "1") == 0) return KEY_1; + else if (cp866_strcasecmp(str, "2") == 0) return KEY_2; + else if (cp866_strcasecmp(str, "3") == 0) return KEY_3; + else if (cp866_strcasecmp(str, "4") == 0) return KEY_4; + else if (cp866_strcasecmp(str, "5") == 0) return KEY_5; + else if (cp866_strcasecmp(str, "6") == 0) return KEY_6; + else if (cp866_strcasecmp(str, "7") == 0) return KEY_7; + else if (cp866_strcasecmp(str, "8") == 0) return KEY_8; + else if (cp866_strcasecmp(str, "9") == 0) return KEY_9; + else if (cp866_strcasecmp(str, "A") == 0) return KEY_A; + else if (cp866_strcasecmp(str, "B") == 0) return KEY_B; + else if (cp866_strcasecmp(str, "C") == 0) return KEY_C; + else if (cp866_strcasecmp(str, "D") == 0) return KEY_D; + else if (cp866_strcasecmp(str, "E") == 0) return KEY_E; + else if (cp866_strcasecmp(str, "F") == 0) return KEY_F; + else if (cp866_strcasecmp(str, "G") == 0) return KEY_G; + else if (cp866_strcasecmp(str, "H") == 0) return KEY_H; + else if (cp866_strcasecmp(str, "I") == 0) return KEY_I; + else if (cp866_strcasecmp(str, "J") == 0) return KEY_J; + else if (cp866_strcasecmp(str, "K") == 0) return KEY_K; + else if (cp866_strcasecmp(str, "L") == 0) return KEY_L; + else if (cp866_strcasecmp(str, "M") == 0) return KEY_M; + else if (cp866_strcasecmp(str, "N") == 0) return KEY_N; + else if (cp866_strcasecmp(str, "O") == 0) return KEY_O; + else if (cp866_strcasecmp(str, "P") == 0) return KEY_P; + else if (cp866_strcasecmp(str, "Q") == 0) return KEY_Q; + else if (cp866_strcasecmp(str, "R") == 0) return KEY_R; + else if (cp866_strcasecmp(str, "S") == 0) return KEY_S; + else if (cp866_strcasecmp(str, "T") == 0) return KEY_T; + else if (cp866_strcasecmp(str, "U") == 0) return KEY_U; + else if (cp866_strcasecmp(str, "V") == 0) return KEY_V; + else if (cp866_strcasecmp(str, "W") == 0) return KEY_W; + else if (cp866_strcasecmp(str, "X") == 0) return KEY_X; + else if (cp866_strcasecmp(str, "Y") == 0) return KEY_Y; + else if (cp866_strcasecmp(str, "Z") == 0) return KEY_Z; + else if (cp866_strcasecmp(str, "RETURN") == 0) return KEY_RETURN; + else if (cp866_strcasecmp(str, "ESCAPE") == 0) return KEY_ESCAPE; + else if (cp866_strcasecmp(str, "BACKSPACE") == 0) return KEY_BACKSPACE; + else if (cp866_strcasecmp(str, "TAB") == 0) return KEY_TAB; + else if (cp866_strcasecmp(str, "SPACE") == 0) return KEY_SPACE; + else if (cp866_strcasecmp(str, "MINUS") == 0) return KEY_MINUS; + else if (cp866_strcasecmp(str, "EQUALS") == 0) return KEY_EQUALS; + else if (cp866_strcasecmp(str, "LEFTBRACKET") == 0) return KEY_LEFTBRACKET; + else if (cp866_strcasecmp(str, "RIGHTBRACKET") == 0) return KEY_RIGHTBRACKET; + else if (cp866_strcasecmp(str, "BACKSLASH") == 0) return KEY_BACKSLASH; + else if (cp866_strcasecmp(str, "SEMICOLON") == 0) return KEY_SEMICOLON; + else if (cp866_strcasecmp(str, "APOSTROPHE") == 0) return KEY_APOSTROPHE; + else if (cp866_strcasecmp(str, "GRAVE") == 0) return KEY_GRAVE; + else if (cp866_strcasecmp(str, "COMMA") == 0) return KEY_COMMA; + else if (cp866_strcasecmp(str, "PERIOD") == 0) return KEY_PERIOD; + else if (cp866_strcasecmp(str, "SLASH") == 0) return KEY_SLASH; + else if (cp866_strcasecmp(str, "CAPSLOCK") == 0) return KEY_CAPSLOCK; + else if (cp866_strcasecmp(str, "F1") == 0) return KEY_F1; + else if (cp866_strcasecmp(str, "F2") == 0) return KEY_F2; + else if (cp866_strcasecmp(str, "F3") == 0) return KEY_F3; + else if (cp866_strcasecmp(str, "F4") == 0) return KEY_F4; + else if (cp866_strcasecmp(str, "F5") == 0) return KEY_F5; + else if (cp866_strcasecmp(str, "F6") == 0) return KEY_F6; + else if (cp866_strcasecmp(str, "F7") == 0) return KEY_F7; + else if (cp866_strcasecmp(str, "F8") == 0) return KEY_F8; + else if (cp866_strcasecmp(str, "F9") == 0) return KEY_F9; + else if (cp866_strcasecmp(str, "F10") == 0) return KEY_F10; + else if (cp866_strcasecmp(str, "F11") == 0) return KEY_F11; + else if (cp866_strcasecmp(str, "F12") == 0) return KEY_F12; + else if (cp866_strcasecmp(str, "PRINTSCREEN") == 0) return KEY_PRINTSCREEN; + else if (cp866_strcasecmp(str, "SCROLLLOCK") == 0) return KEY_SCROLLLOCK; + else if (cp866_strcasecmp(str, "PAUSE") == 0) return KEY_PAUSE; + else if (cp866_strcasecmp(str, "INSERT") == 0) return KEY_INSERT; + else if (cp866_strcasecmp(str, "HOME") == 0) return KEY_HOME; + else if (cp866_strcasecmp(str, "PAGEUP") == 0) return KEY_PAGEUP; + else if (cp866_strcasecmp(str, "DELETE") == 0) return KEY_DELETE; + else if (cp866_strcasecmp(str, "END") == 0) return KEY_END; + else if (cp866_strcasecmp(str, "PAGEDOWN") == 0) return KEY_PAGEDOWN; + else if (cp866_strcasecmp(str, "RIGHT") == 0) return KEY_RIGHT; + else if (cp866_strcasecmp(str, "LEFT") == 0) return KEY_LEFT; + else if (cp866_strcasecmp(str, "DOWN") == 0) return KEY_DOWN; + else if (cp866_strcasecmp(str, "UP") == 0) return KEY_UP; + else if (cp866_strcasecmp(str, "NUMLOCK") == 0) return KEY_NUMLOCK; + else if (cp866_strcasecmp(str, "KP_DIVIDE") == 0) return KEY_KP_DIVIDE; + else if (cp866_strcasecmp(str, "KP_MULTIPLY") == 0) return KEY_KP_MULTIPLY; + else if (cp866_strcasecmp(str, "KP_MINUS") == 0) return KEY_KP_MINUS; + else if (cp866_strcasecmp(str, "KP_PLUS") == 0) return KEY_KP_PLUS; + else if (cp866_strcasecmp(str, "KP_ENTER") == 0) return KEY_KP_ENTER; + else if (cp866_strcasecmp(str, "KP_0") == 0) return KEY_KP_0; + else if (cp866_strcasecmp(str, "KP_1") == 0) return KEY_KP_1; + else if (cp866_strcasecmp(str, "KP_2") == 0) return KEY_KP_2; + else if (cp866_strcasecmp(str, "KP_3") == 0) return KEY_KP_3; + else if (cp866_strcasecmp(str, "KP_4") == 0) return KEY_KP_4; + else if (cp866_strcasecmp(str, "KP_5") == 0) return KEY_KP_5; + else if (cp866_strcasecmp(str, "KP_6") == 0) return KEY_KP_6; + else if (cp866_strcasecmp(str, "KP_7") == 0) return KEY_KP_7; + else if (cp866_strcasecmp(str, "KP_8") == 0) return KEY_KP_8; + else if (cp866_strcasecmp(str, "KP_9") == 0) return KEY_KP_9; + else if (cp866_strcasecmp(str, "KP_PERIOD") == 0) return KEY_KP_PERIOD; + else if (cp866_strcasecmp(str, "SYSREQ") == 0) return KEY_SYSREQ; + else if (cp866_strcasecmp(str, "LCTRL") == 0) return KEY_LCTRL; + else if (cp866_strcasecmp(str, "LSHIFT") == 0) return KEY_LSHIFT; + else if (cp866_strcasecmp(str, "LALT") == 0) return KEY_LALT; + else if (cp866_strcasecmp(str, "LSUPER") == 0) return KEY_LSUPER; + else if (cp866_strcasecmp(str, "RCTRL") == 0) return KEY_RCTRL; + else if (cp866_strcasecmp(str, "RSHIFT") == 0) return KEY_RSHIFT; + else if (cp866_strcasecmp(str, "RALT") == 0) return KEY_RALT; + else if (cp866_strcasecmp(str, "RSUPER") == 0) return KEY_RSUPER; else return KEY_UNKNOWN; } diff --git a/src/map.c b/src/map.c index d090227..ab154e2 100644 --- a/src/map.c +++ b/src/map.c @@ -32,6 +32,7 @@ #include #include "my.h" #include "error.h" +#include "cp866.h" enum { MB_COMMENT = -1, MB_END = 0, @@ -244,7 +245,7 @@ static int W_load (FILE *h) { myfread(s, 8, 1, h); walf[i] = myfread8(h) ? 1 : 0; // ??? R_load(s); - if (strncasecmp(s, "VTRAP01", 8) == 0) { + if (cp866_strncasecmp(s, "VTRAP01", 8) == 0) { walf[i] |= 2; } } diff --git a/src/soft/render.c b/src/soft/render.c index c77709c..7fbfc8f 100644 --- a/src/soft/render.c +++ b/src/soft/render.c @@ -1393,13 +1393,13 @@ void R_get_name (int n, char s[8]) { } static short getani (char n[8]) { - if (strncasecmp(n, "WALL22_1", 8) == 0) { + if (cp866_strncasecmp(n, "WALL22_1", 8) == 0) { return 1; - } else if (strncasecmp(n, "WALL58_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "WALL58_1", 8) == 0) { return 2; - } else if (strncasecmp(n, "W73A_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "W73A_1", 8) == 0) { return 3; - } else if (strncasecmp(n, "RP2_1", 8) == 0) { + } else if (cp866_strncasecmp(n, "RP2_1", 8) == 0) { return 4; } else { return 0; @@ -1433,7 +1433,7 @@ void R_load (char s[8]) { walh[max_textures] = -1; walp[max_textures] = NULL; } else { - if (strncasecmp(s, "_WATER_", 7) == 0) { + if (cp866_strncasecmp(s, "_WATER_", 7) == 0) { walh[max_textures] = -2; walp[max_textures] = (void*)((intptr_t)s[7] - '0' + 1); } else {