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 != ' '))
{
if (!dehfgets(inbuffer, sizeof(inbuffer), fpin)) break;
M_ForceLowercase(inbuffer); // lowercase it
M_StringToLower(inbuffer); // lowercase it
lfstrip(inbuffer);
if (!*inbuffer) break; // killough 11/98
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;
lower = M_StringDuplicate(iwadname);
M_ForceLowercase(lower);
M_StringToLower(lower);
result = M_StringJoin(base, DIR_SEPARATOR_S, lower, NULL);
free(lower);
@ -1482,7 +1482,7 @@ static int GuessFileType(const char *name)
base = M_BaseName(name);
lower = M_StringDuplicate(base);
M_ForceLowercase(lower);
M_StringToLower(lower);
// only ever add one argument to the -iwad parameter

View File

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

View File

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

View File

@ -25,6 +25,7 @@
#include "doomstat.h"
#include "hu_lib.h"
#include "hu_stuff.h"
#include "m_misc.h"
#include "m_swap.h"
#include "r_defs.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)
{
c = toupper(*s++);
c = M_ToUpper(*s++);
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
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 (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)
{
n = tolower(n);
g = tolower(g);
n = M_ToLower(n);
g = M_ToLower(g);
}
if (g == '*')

View File

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

View File

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

View File

@ -98,7 +98,7 @@ char *M_FileCaseExists(const char *path)
filename = (char *)M_BaseName(path_dup);
// 1: lowercase filename, e.g. doom2.wad
M_ForceLowercase(filename);
M_StringToLower(filename);
if (M_FileExists(path_dup))
{
@ -106,7 +106,7 @@ char *M_FileCaseExists(const char *path)
}
// 2: uppercase filename, e.g. DOOM2.WAD
M_ForceUppercase(filename);
M_StringToUpper(filename);
if (M_FileExists(path_dup))
{
@ -117,7 +117,7 @@ char *M_FileCaseExists(const char *path)
ext = strrchr(path_dup, '.');
if (ext != NULL && ext > filename)
{
M_ForceLowercase(ext + 1);
M_StringToLower(ext + 1);
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
if (strlen(filename) > 1)
{
M_ForceLowercase(filename + 1);
M_StringToLower(filename + 1);
if (M_FileExists(path_dup))
{
@ -210,25 +210,41 @@ const char *M_BaseName(const char *path)
// 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;
for (p = text; *p != '\0'; ++p)
{
*p = toupper(*p);
*p = M_ToUpper(*p);
}
}
// 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;
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);
char *M_DirName(const char *path);
const char *M_BaseName(const char *path);
void M_ForceUppercase(char *text);
void M_ForceLowercase(char *text);
char M_ToUpper(const char c);
void M_StringToUpper(char *text);
char M_ToLower(const char c);
void M_StringToLower(char *text);
char *M_StringDuplicate(const char *orig);
boolean M_StringCopy(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 "i_video.h"
#include "m_misc.h"
#include "m_swap.h"
#include "r_defs.h"
#include "v_video.h"
@ -179,7 +180,7 @@ boolean MN_DrawFon2String(int x, int y, byte *cr, const char *str)
{
c = *str++;
c = (upper ? toupper(c) : c) - firstc;
c = (upper ? M_ToUpper(c) : c) - firstc;
if (c < 0 || c >= numchars)
{
cx += FON2_SPACE;
@ -214,7 +215,7 @@ int MN_GetFon2PixelWidth(const char *str)
{
c = *str++;
c = (upper ? toupper(c) : c) - firstc;
c = (upper ? M_ToUpper(c) : c) - firstc;
if (c < 0 || c > numchars)
{
len += FON2_SPACE; // space

View File

@ -1147,20 +1147,20 @@ static void SetDefaultSaveName(int slot)
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
boolean MN_StartsWithMapIdentifier(char *str)
{
if (strnlen(str, 8) >= 4 && toupper(str[0]) == 'E' && isdigit(str[1])
&& toupper(str[2]) == 'M' && isdigit(str[3]))
if (strnlen(str, 8) >= 4 && M_ToUpper(str[0]) == 'E' && isdigit(str[1])
&& M_ToUpper(str[2]) == 'M' && isdigit(str[3]))
{
return true;
}
if (strnlen(str, 8) >= 5 && toupper(str[0]) == 'M' && toupper(str[1]) == 'A'
&& toupper(str[2]) == 'P' && isdigit(str[3]) && isdigit(str[4]))
if (strnlen(str, 8) >= 5 && M_ToUpper(str[0]) == 'M' && M_ToUpper(str[1]) == 'A'
&& M_ToUpper(str[2]) == 'P' && isdigit(str[3]) && isdigit(str[4]))
{
return true;
}
@ -2381,13 +2381,13 @@ static boolean SaveLoadResponder(menu_action_t action, int ch)
if (delete_verify)
{
if (toupper(ch) == 'Y')
if (M_ToUpper(ch) == 'Y')
{
M_DeleteGame(itemOn);
S_StartSound(NULL, sfx_itemup);
delete_verify = false;
}
else if (toupper(ch) == 'N')
else if (M_ToUpper(ch) == 'N')
{
S_StartSound(NULL, sfx_itemup);
delete_verify = false;
@ -2678,7 +2678,7 @@ boolean M_Responder(event_t *ev)
}
else
{
ch = toupper(ch);
ch = M_ToUpper(ch);
if (ch >= 32 && ch <= 127 && saveCharIndex < SAVESTRINGSIZE - 1
&& MN_StringWidth(savegamestrings[saveSlot])
@ -3261,7 +3261,7 @@ static void WriteText(int x, int y, const char *string)
continue;
}
c = toupper(c) - HU_FONTSTART;
c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c >= HU_FONTSIZE)
{
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)
{
cx += SPACEWIDTH; // space
@ -2764,7 +2764,7 @@ int MN_GetPixelWidth(const char *ch)
continue;
}
c = toupper(c) - HU_FONTSTART;
c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c > HU_FONTSIZE)
{
len += SPACEWIDTH; // space
@ -3288,13 +3288,13 @@ boolean MN_SetupResponder(menu_action_t action, int ch)
if (default_verify)
{
if (toupper(ch) == 'Y')
if (M_ToUpper(ch) == 'Y')
{
ResetDefaults();
default_verify = false;
SelectDone(current_item);
}
else if (toupper(ch) == 'N')
else if (M_ToUpper(ch) == 'N')
{
default_verify = false;
SelectDone(current_item);
@ -3688,7 +3688,7 @@ int MN_StringWidth(const char *string)
}
continue;
}
c = toupper(c) - HU_FONTSTART;
c = M_ToUpper(c) - HU_FONTSTART;
if (c < 0 || c > HU_FONTSIZE)
{
w += SPACEWIDTH;

View File

@ -181,7 +181,7 @@ void P_InitPicAnims (void)
int j;
startname = M_StringDuplicate(animdefs[i].startname);
M_ForceUppercase(startname);
M_StringToUpper(startname);
// [FG] play sound when hitting animated floor
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);
buffer[8] = 0;
M_ForceUppercase(buffer);
M_StringToUpper(buffer);
return 1;
}
@ -461,7 +461,7 @@ static int ParseStandardProperty(u_scanner_t *s, mapentry_t *mape)
if (U_MustGetToken(s, TK_StringConst))
{
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;
while (*p)
{
*p = tolower(*p);
*p = M_ToLower(*p);
p++;
}
// Check for a boolean constant.

View File

@ -69,7 +69,7 @@ void ExtractFileBase(const char *path, char *dest)
break;
}
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 hash;
(void) ((hash = toupper(s[0]), s[1]) &&
(hash = hash*3+toupper(s[1]), s[2]) &&
(hash = hash*2+toupper(s[2]), s[3]) &&
(hash = hash*2+toupper(s[3]), s[4]) &&
(hash = hash*2+toupper(s[4]), s[5]) &&
(hash = hash*2+toupper(s[5]), s[6]) &&
(hash = hash*2+toupper(s[6]),
hash = hash*2+toupper(s[7]))
(void) ((hash = M_ToUpper(s[0]), s[1]) &&
(hash = hash*3+M_ToUpper(s[1]), s[2]) &&
(hash = hash*2+M_ToUpper(s[2]), s[3]) &&
(hash = hash*2+M_ToUpper(s[3]), s[4]) &&
(hash = hash*2+M_ToUpper(s[4]), s[5]) &&
(hash = hash*2+M_ToUpper(s[5]), s[6]) &&
(hash = hash*2+M_ToUpper(s[6]),
hash = hash*2+M_ToUpper(s[7]))
);
return hash;
}