only convert lower case ASCII chars to upper case (#1630)

* only convert toupper() chars >= HU_FONTSIZE

Probably fixes #1627

* only convert lowercase ASCII chars

* move ascii_toupper() to m_misc.c:M_ToUpper()

* use M_ToUpper()/M_ToLower() throughout the code

* rename M_ForceUppercase() -> M_StringToUpper()
This commit is contained in:
Fabian Greffrath 2024-04-01 16:38:59 +02:00 committed by GitHub
parent d2c8914adb
commit 38b0fa3852
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 74 additions and 54 deletions

View File

@ -2601,7 +2601,7 @@ void deh_procPars(DEHFILE *fpin, FILE* fpout, char *line) // extension
while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' ')) while (!dehfeof(fpin) && *inbuffer && (*inbuffer != ' '))
{ {
if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break; if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
M_ForceLowercase(inbuffer); // lowercase it M_StringToLower(inbuffer); // lowercase it
lfstrip(inbuffer); lfstrip(inbuffer);
if (!*inbuffer) break; // killough 11/98 if (!*inbuffer) break; // killough 11/98
if (3 != sscanf(inbuffer,"par %i %i %i",&episode, &level, &partime)) if (3 != sscanf(inbuffer,"par %i %i %i",&episode, &level, &partime))

View File

@ -856,7 +856,7 @@ static char *GetAutoloadDir(const char *base, const char *iwadname, boolean crea
char *lower; char *lower;
lower = M_StringDuplicate(iwadname); lower = M_StringDuplicate(iwadname);
M_ForceLowercase(lower); M_StringToLower(lower);
result = M_StringJoin(base, DIR_SEPARATOR_S, lower, NULL); result = M_StringJoin(base, DIR_SEPARATOR_S, lower, NULL);
free(lower); free(lower);
@ -1482,7 +1482,7 @@ static int GuessFileType(const char *name)
base = M_BaseName(name); base = M_BaseName(name);
lower = M_StringDuplicate(base); lower = M_StringDuplicate(base);
M_ForceLowercase(lower); M_StringToLower(lower);
// only ever add one argument to the -iwad parameter // only ever add one argument to the -iwad parameter

View File

@ -417,7 +417,7 @@ void F_TextWrite (void)
continue; continue;
} }
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c> HU_FONTSIZE) if (c < 0 || c> HU_FONTSIZE)
{ {
cx += 4; cx += 4;
@ -650,7 +650,7 @@ void F_CastPrint (char* text)
c = *ch++; c = *ch++;
if (!c) if (!c)
break; break;
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c> HU_FONTSIZE) if (c < 0 || c> HU_FONTSIZE)
{ {
width += 4; width += 4;
@ -669,7 +669,7 @@ void F_CastPrint (char* text)
c = *ch++; c = *ch++;
if (!c) if (!c)
break; break;
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c> HU_FONTSIZE) if (c < 0 || c> HU_FONTSIZE)
{ {
cx += 4; cx += 4;

View File

@ -3646,7 +3646,7 @@ int G_ValidateMapName(const char *mapname, int *pEpi, int *pMap)
return 0; return 0;
strncpy(mapuname, mapname, 8); strncpy(mapuname, mapname, 8);
mapuname[8] = 0; mapuname[8] = 0;
M_ForceUppercase(mapuname); M_StringToUpper(mapuname);
if (gamemode != commercial) if (gamemode != commercial)
{ {

View File

@ -25,6 +25,7 @@
#include "doomstat.h" #include "doomstat.h"
#include "hu_lib.h" #include "hu_lib.h"
#include "hu_stuff.h" #include "hu_stuff.h"
#include "m_misc.h"
#include "m_swap.h" #include "m_swap.h"
#include "r_defs.h" #include "r_defs.h"
#include "r_draw.h" #include "r_draw.h"
@ -170,7 +171,7 @@ static void add_string_to_line (hu_line_t *const l, const hu_font_t *const f, co
while (*s) while (*s)
{ {
c = toupper(*s++); c = M_ToUpper(*s++);
if (c == '\x1b') if (c == '\x1b')
{ {
@ -324,7 +325,7 @@ static void draw_line_aligned (const hu_multiline_t *m, const hu_line_t *l, cons
// draw the new stuff // draw the new stuff
for (i = 0; i < l->len; i++) for (i = 0; i < l->len; i++)
{ {
c = toupper(l->line[i]); //jff insure were not getting a cheap toupper conv. c = M_ToUpper(l->line[i]);
#if 0 #if 0
if (c == '\n') if (c == '\n')

View File

@ -196,8 +196,8 @@ static boolean MatchesGlob(const char *name, const char *glob, int flags)
if ((flags & GLOB_FLAG_NOCASE) != 0) if ((flags & GLOB_FLAG_NOCASE) != 0)
{ {
n = tolower(n); n = M_ToLower(n);
g = tolower(g); g = M_ToLower(g);
} }
if (g == '*') if (g == '*')

View File

@ -1203,13 +1203,13 @@ boolean M_FindCheats(int key)
if (argsleft) if (argsleft)
{ {
*arg++ = tolower(key); // store key in arg buffer *arg++ = M_ToLower(key); // store key in arg buffer
if (!--argsleft) // if last key in arg list, if (!--argsleft) // if last key in arg list,
cheat[cht].func.s(argbuf); // process the arg buffer cheat[cht].func.s(argbuf); // process the arg buffer
return 1; // affirmative response return 1; // affirmative response
} }
key = tolower(key) - 'a'; key = M_ToLower(key) - 'a';
if (key < 0 || key >= 32) // ignore most non-alpha cheat letters if (key < 0 || key >= 32) // ignore most non-alpha cheat letters
{ {
sr = 0; // clear shift register sr = 0; // clear shift register
@ -1225,7 +1225,7 @@ boolean M_FindCheats(int key)
const char *p; // [FG] char! const char *p; // [FG] char!
for (p=cheat[i].cheat; *p; p++) for (p=cheat[i].cheat; *p; p++)
{ {
unsigned key = tolower(*p)-'a'; // convert to 0-31 unsigned key = M_ToLower(*p)-'a'; // convert to 0-31
if (key >= 32) // ignore most non-alpha cheat letters if (key >= 32) // ignore most non-alpha cheat letters
continue; continue;
c = (c<<5) + key; // shift key into code c = (c<<5) + key; // shift key into code

View File

@ -2850,7 +2850,7 @@ static unsigned default_hash(const char *name)
unsigned hash = 0; unsigned hash = 0;
while (*name) while (*name)
{ {
hash = hash * 2 + toupper(*name++); hash = hash * 2 + M_ToUpper(*name++);
} }
return hash % NUMDEFAULTS; return hash % NUMDEFAULTS;
} }

View File

@ -98,7 +98,7 @@ char *M_FileCaseExists(const char *path)
filename = (char *)M_BaseName(path_dup); filename = (char *)M_BaseName(path_dup);
// 1: lowercase filename, e.g. doom2.wad // 1: lowercase filename, e.g. doom2.wad
M_ForceLowercase(filename); M_StringToLower(filename);
if (M_FileExists(path_dup)) if (M_FileExists(path_dup))
{ {
@ -106,7 +106,7 @@ char *M_FileCaseExists(const char *path)
} }
// 2: uppercase filename, e.g. DOOM2.WAD // 2: uppercase filename, e.g. DOOM2.WAD
M_ForceUppercase(filename); M_StringToUpper(filename);
if (M_FileExists(path_dup)) if (M_FileExists(path_dup))
{ {
@ -117,7 +117,7 @@ char *M_FileCaseExists(const char *path)
ext = strrchr(path_dup, '.'); ext = strrchr(path_dup, '.');
if (ext != NULL && ext > filename) if (ext != NULL && ext > filename)
{ {
M_ForceLowercase(ext + 1); M_StringToLower(ext + 1);
if (M_FileExists(path_dup)) if (M_FileExists(path_dup))
{ {
@ -128,7 +128,7 @@ char *M_FileCaseExists(const char *path)
// 4. lowercase filename with uppercase first letter, e.g. Doom2.wad // 4. lowercase filename with uppercase first letter, e.g. Doom2.wad
if (strlen(filename) > 1) if (strlen(filename) > 1)
{ {
M_ForceLowercase(filename + 1); M_StringToLower(filename + 1);
if (M_FileExists(path_dup)) if (M_FileExists(path_dup))
{ {
@ -210,25 +210,41 @@ const char *M_BaseName(const char *path)
// Change string to uppercase. // Change string to uppercase.
void M_ForceUppercase(char *text) char M_ToUpper(const char c)
{
if (c >= 'a' && c <= 'z')
return c + 'A' - 'a';
else
return c;
}
void M_StringToUpper(char *text)
{ {
char *p; char *p;
for (p = text; *p != '\0'; ++p) for (p = text; *p != '\0'; ++p)
{ {
*p = toupper(*p); *p = M_ToUpper(*p);
} }
} }
// Change string to lowercase. // Change string to lowercase.
void M_ForceLowercase(char *text) char M_ToLower(const char c)
{
if (c >= 'A' && c <= 'Z')
return c - 'A' + 'a';
else
return c;
}
void M_StringToLower(char *text)
{ {
char *p; char *p;
for (p = text; *p != '\0'; ++p) for (p = text; *p != '\0'; ++p)
{ {
*p = tolower(*p); *p = M_ToLower(*p);
} }
} }

View File

@ -29,8 +29,10 @@ char *M_FileCaseExists(const char *file);
boolean M_StrToInt(const char *str, int *result); boolean M_StrToInt(const char *str, int *result);
char *M_DirName(const char *path); char *M_DirName(const char *path);
const char *M_BaseName(const char *path); const char *M_BaseName(const char *path);
void M_ForceUppercase(char *text); char M_ToUpper(const char c);
void M_ForceLowercase(char *text); void M_StringToUpper(char *text);
char M_ToLower(const char c);
void M_StringToLower(char *text);
char *M_StringDuplicate(const char *orig); char *M_StringDuplicate(const char *orig);
boolean M_StringCopy(char *dest, const char *src, size_t dest_size); boolean M_StringCopy(char *dest, const char *src, size_t dest_size);
boolean M_StringConcat(char *dest, const char *src, size_t dest_size); boolean M_StringConcat(char *dest, const char *src, size_t dest_size);

View File

@ -22,6 +22,7 @@
#include "doomtype.h" #include "doomtype.h"
#include "i_video.h" #include "i_video.h"
#include "m_misc.h"
#include "m_swap.h" #include "m_swap.h"
#include "r_defs.h" #include "r_defs.h"
#include "v_video.h" #include "v_video.h"
@ -179,7 +180,7 @@ boolean MN_DrawFon2String(int x, int y, byte *cr, const char *str)
{ {
c = *str++; c = *str++;
c = (upper ? toupper(c) : c) - firstc; c = (upper ? M_ToUpper(c) : c) - firstc;
if (c < 0 || c >= numchars) if (c < 0 || c >= numchars)
{ {
cx += FON2_SPACE; cx += FON2_SPACE;
@ -214,7 +215,7 @@ int MN_GetFon2PixelWidth(const char *str)
{ {
c = *str++; c = *str++;
c = (upper ? toupper(c) : c) - firstc; c = (upper ? M_ToUpper(c) : c) - firstc;
if (c < 0 || c > numchars) if (c < 0 || c > numchars)
{ {
len += FON2_SPACE; // space len += FON2_SPACE; // space

View File

@ -1147,20 +1147,20 @@ static void SetDefaultSaveName(int slot)
M_snprintf(savegamestrings[slot], SAVESTRINGSIZE, "%s", maplump); M_snprintf(savegamestrings[slot], SAVESTRINGSIZE, "%s", maplump);
} }
M_ForceUppercase(savegamestrings[slot]); M_StringToUpper(savegamestrings[slot]);
} }
// [FG] override savegame name if it already starts with a map identifier // [FG] override savegame name if it already starts with a map identifier
boolean MN_StartsWithMapIdentifier(char *str) boolean MN_StartsWithMapIdentifier(char *str)
{ {
if (strnlen(str, 8) >= 4 && toupper(str[0]) == 'E' && isdigit(str[1]) if (strnlen(str, 8) >= 4 && M_ToUpper(str[0]) == 'E' && isdigit(str[1])
&& toupper(str[2]) == 'M' && isdigit(str[3])) && M_ToUpper(str[2]) == 'M' && isdigit(str[3]))
{ {
return true; return true;
} }
if (strnlen(str, 8) >= 5 && toupper(str[0]) == 'M' && toupper(str[1]) == 'A' if (strnlen(str, 8) >= 5 && M_ToUpper(str[0]) == 'M' && M_ToUpper(str[1]) == 'A'
&& toupper(str[2]) == 'P' && isdigit(str[3]) && isdigit(str[4])) && M_ToUpper(str[2]) == 'P' && isdigit(str[3]) && isdigit(str[4]))
{ {
return true; return true;
} }
@ -2381,13 +2381,13 @@ static boolean SaveLoadResponder(menu_action_t action, int ch)
if (delete_verify) if (delete_verify)
{ {
if (toupper(ch) == 'Y') if (M_ToUpper(ch) == 'Y')
{ {
M_DeleteGame(itemOn); M_DeleteGame(itemOn);
S_StartSound(NULL, sfx_itemup); S_StartSound(NULL, sfx_itemup);
delete_verify = false; delete_verify = false;
} }
else if (toupper(ch) == 'N') else if (M_ToUpper(ch) == 'N')
{ {
S_StartSound(NULL, sfx_itemup); S_StartSound(NULL, sfx_itemup);
delete_verify = false; delete_verify = false;
@ -2678,7 +2678,7 @@ boolean M_Responder(event_t *ev)
} }
else else
{ {
ch = toupper(ch); ch = M_ToUpper(ch);
if (ch >= 32 && ch <= 127 && saveCharIndex < SAVESTRINGSIZE - 1 if (ch >= 32 && ch <= 127 && saveCharIndex < SAVESTRINGSIZE - 1
&& MN_StringWidth(savegamestrings[saveSlot]) && MN_StringWidth(savegamestrings[saveSlot])
@ -3261,7 +3261,7 @@ static void WriteText(int x, int y, const char *string)
continue; continue;
} }
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c >= HU_FONTSIZE) if (c < 0 || c >= HU_FONTSIZE)
{ {
cx += 4; cx += 4;

View File

@ -2677,7 +2677,7 @@ void MN_DrawStringCR(int cx, int cy, byte *cr1, byte *cr2, const char *ch)
} }
} }
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c > HU_FONTSIZE) if (c < 0 || c > HU_FONTSIZE)
{ {
cx += SPACEWIDTH; // space cx += SPACEWIDTH; // space
@ -2764,7 +2764,7 @@ int MN_GetPixelWidth(const char *ch)
continue; continue;
} }
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c > HU_FONTSIZE) if (c < 0 || c > HU_FONTSIZE)
{ {
len += SPACEWIDTH; // space len += SPACEWIDTH; // space
@ -3288,13 +3288,13 @@ boolean MN_SetupResponder(menu_action_t action, int ch)
if (default_verify) if (default_verify)
{ {
if (toupper(ch) == 'Y') if (M_ToUpper(ch) == 'Y')
{ {
ResetDefaults(); ResetDefaults();
default_verify = false; default_verify = false;
SelectDone(current_item); SelectDone(current_item);
} }
else if (toupper(ch) == 'N') else if (M_ToUpper(ch) == 'N')
{ {
default_verify = false; default_verify = false;
SelectDone(current_item); SelectDone(current_item);
@ -3688,7 +3688,7 @@ int MN_StringWidth(const char *string)
} }
continue; continue;
} }
c = toupper(c) - HU_FONTSTART; c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c > HU_FONTSIZE) if (c < 0 || c > HU_FONTSIZE)
{ {
w += SPACEWIDTH; w += SPACEWIDTH;

View File

@ -181,7 +181,7 @@ void P_InitPicAnims (void)
int j; int j;
startname = M_StringDuplicate(animdefs[i].startname); startname = M_StringDuplicate(animdefs[i].startname);
M_ForceUppercase(startname); M_StringToUpper(startname);
// [FG] play sound when hitting animated floor // [FG] play sound when hitting animated floor
if (strstr(startname, "WATER") || strstr(startname, "BLOOD")) if (strstr(startname, "WATER") || strstr(startname, "BLOOD"))

View File

@ -374,7 +374,7 @@ static int ParseLumpName(u_scanner_t *s, char *buffer)
} }
strncpy(buffer, s->string, 8); strncpy(buffer, s->string, 8);
buffer[8] = 0; buffer[8] = 0;
M_ForceUppercase(buffer); M_StringToUpper(buffer);
return 1; return 1;
} }
@ -461,7 +461,7 @@ static int ParseStandardProperty(u_scanner_t *s, mapentry_t *mape)
if (U_MustGetToken(s, TK_StringConst)) if (U_MustGetToken(s, TK_StringConst))
{ {
key = strdup(s->string); key = strdup(s->string);
key[0] = tolower(key[0]); key[0] = M_ToLower(key[0]);
} }
} }
} }

View File

@ -541,7 +541,7 @@ boolean U_GetNextToken(u_scanner_t *s, boolean expandState)
char *p = nextState->string; char *p = nextState->string;
while (*p) while (*p)
{ {
*p = tolower(*p); *p = M_ToLower(*p);
p++; p++;
} }
// Check for a boolean constant. // Check for a boolean constant.

View File

@ -69,7 +69,7 @@ void ExtractFileBase(const char *path, char *dest)
break; break;
} }
else else
*dest++ = toupper(*src++); *dest++ = M_ToUpper(*src++);
} }
// //
@ -279,14 +279,14 @@ static void W_CoalesceMarkedResource(const char *start_marker,
unsigned W_LumpNameHash(const char *s) unsigned W_LumpNameHash(const char *s)
{ {
unsigned hash; unsigned hash;
(void) ((hash = toupper(s[0]), s[1]) && (void) ((hash = M_ToUpper(s[0]), s[1]) &&
(hash = hash*3+toupper(s[1]), s[2]) && (hash = hash*3+M_ToUpper(s[1]), s[2]) &&
(hash = hash*2+toupper(s[2]), s[3]) && (hash = hash*2+M_ToUpper(s[2]), s[3]) &&
(hash = hash*2+toupper(s[3]), s[4]) && (hash = hash*2+M_ToUpper(s[3]), s[4]) &&
(hash = hash*2+toupper(s[4]), s[5]) && (hash = hash*2+M_ToUpper(s[4]), s[5]) &&
(hash = hash*2+toupper(s[5]), s[6]) && (hash = hash*2+M_ToUpper(s[5]), s[6]) &&
(hash = hash*2+toupper(s[6]), (hash = hash*2+M_ToUpper(s[6]),
hash = hash*2+toupper(s[7])) hash = hash*2+M_ToUpper(s[7]))
); );
return hash; return hash;
} }