Add string functions compatibility layer

See #17
This commit is contained in:
Alexander Batalov 2022-05-28 11:57:32 +03:00
parent e1cf71eac7
commit 4bac829739
28 changed files with 164 additions and 94 deletions

View File

@ -235,6 +235,8 @@ add_executable(${EXECUTABLE_NAME} WIN32
target_sources(${EXECUTABLE_NAME} PUBLIC
"src/fps_limiter.cc"
"src/fps_limiter.h"
"src/platform_compat.cc"
"src/platform_compat.h"
"src/sfall_config.cc"
"src/sfall_config.h"
)

View File

@ -6,6 +6,7 @@
#include "game_config.h"
#include "memory.h"
#include "object.h"
#include "platform_compat.h"
#include "proto.h"
#include <stdio.h>
@ -108,7 +109,7 @@ int artInit()
}
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && stricmp(language, ENGLISH) != 0) {
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && compat_stricmp(language, ENGLISH) != 0) {
strcpy(gArtLanguage, language);
gArtLanguageInitialized = true;
}
@ -155,16 +156,16 @@ int artInit()
ptr = gArtListDescriptions[1].fileNames;
for (i = 0; i < gArtListDescriptions[1].fileNamesLength; i++) {
if (stricmp(ptr, "hmjmps") == 0) {
if (compat_stricmp(ptr, "hmjmps") == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_JUMPSUIT][GENDER_MALE] = i;
} else if (stricmp(ptr, "hfjmps") == 0) {
} else if (compat_stricmp(ptr, "hfjmps") == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_JUMPSUIT][GENDER_FEMALE] = i;
}
if (stricmp(ptr, "hmwarr") == 0) {
if (compat_stricmp(ptr, "hmwarr") == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_TRIBAL][GENDER_MALE] = i;
_art_vault_guy_num = i;
} else if (stricmp(ptr, "hfprim") == 0) {
} else if (compat_stricmp(ptr, "hfprim") == 0) {
_art_vault_person_nums[DUDE_NATIVE_LOOK_TRIBAL][GENDER_FEMALE] = i;
}
@ -202,7 +203,7 @@ int artInit()
ptr = gArtListDescriptions[4].fileNames;
for (i = 0; i < gArtListDescriptions[4].fileNamesLength; i++) {
if (stricmp(ptr, "grid001.frm") == 0) {
if (compat_stricmp(ptr, "grid001.frm") == 0) {
_art_mapper_blank_tile = i;
}
}

View File

@ -20,6 +20,7 @@
#include "object.h"
#include "palette.h"
#include "perk.h"
#include "platform_compat.h"
#include "proto.h"
#include "scripts.h"
#include "skill.h"
@ -679,7 +680,7 @@ int _editor_design(bool isCreationMode)
continue;
}
if (stricmp(critterGetName(gDude), "None") == 0) {
if (compat_stricmp(critterGetName(gDude), "None") == 0) {
soundPlayFile("iisxxxx1");
// Warning: You haven't changed your player
@ -1946,7 +1947,7 @@ void editorRenderPerks()
// 0x434498
int _kills_list_comp(const KillInfo* a, const KillInfo* b)
{
return stricmp(a->name, b->name);
return compat_stricmp(a->name, b->name);
}
// 0x4344A4
@ -2520,7 +2521,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_ARMOR_CLASS), t, 10);
compat_itoa(critterGetStat(gDude, STAT_ARMOR_CLASS), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, color);
// Action Points
@ -2536,7 +2537,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_MAXIMUM_ACTION_POINTS), t, 10);
compat_itoa(critterGetStat(gDude, STAT_MAXIMUM_ACTION_POINTS), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, color);
// Carry Weight
@ -2552,7 +2553,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_CARRY_WEIGHT), t, 10);
compat_itoa(critterGetStat(gDude, STAT_CARRY_WEIGHT), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, critterIsEncumbered(gDude) ? _colorTable[31744] : color);
// Melee Damage
@ -2568,7 +2569,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_MELEE_DAMAGE), t, 10);
compat_itoa(critterGetStat(gDude, STAT_MELEE_DAMAGE), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, color);
// Damage Resistance
@ -2632,7 +2633,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_SEQUENCE), t, 10);
compat_itoa(critterGetStat(gDude, STAT_SEQUENCE), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, color);
// Healing Rate
@ -2648,7 +2649,7 @@ void editorRenderSecondaryStats()
sprintf(t, "%s", messageListItemText);
fontDrawText(characterEditorWindowBuf + 640 * y + 194, t, 640, 640, color);
itoa(critterGetStat(gDude, STAT_HEALING_RATE), t, 10);
compat_itoa(critterGetStat(gDude, STAT_HEALING_RATE), t, 10);
fontDrawText(characterEditorWindowBuf + 640 * y + 288, t, 640, 640, color);
// Critical Chance
@ -3694,7 +3695,7 @@ int _OptionWindow()
// already exists
sprintf(dest,
"%s %s",
strupr(v236),
compat_strupr(v236),
getmsg(&editorMessageList, &editorMessageListItem, 609));
char v240[512];
@ -3717,7 +3718,7 @@ int _OptionWindow()
if (characterPrintToFile(dest) == 0) {
sprintf(dest,
"%s%s",
strupr(v236),
compat_strupr(v236),
getmsg(&editorMessageList, &editorMessageListItem, 607));
showDialogBox(dest, NULL, 0, 169, 126, _colorTable[992], NULL, _colorTable[992], 0);
} else {
@ -3726,7 +3727,7 @@ int _OptionWindow()
sprintf(dest,
"%s%s%s",
getmsg(&editorMessageList, &editorMessageListItem, 611),
strupr(v236),
compat_strupr(v236),
"!");
showDialogBox(dest, NULL, 0, 169, 126, _colorTable[32328], NULL, _colorTable[992], 0x01);
}
@ -3813,7 +3814,7 @@ int _OptionWindow()
if (characterFileExists(title)) {
sprintf(title,
"%s %s",
strupr(fileName),
compat_strupr(fileName),
getmsg(&editorMessageList, &editorMessageListItem, 609));
char line2[512];
@ -3838,7 +3839,7 @@ int _OptionWindow()
sprintf(title,
"%s%s%s",
getmsg(&editorMessageList, &editorMessageListItem, 611),
strupr(fileName),
compat_strupr(fileName),
"!");
showDialogBox(title, NULL, 0, 169, 126, _colorTable[32328], NULL, _colorTable[32328], 1);
}
@ -4131,7 +4132,7 @@ int characterPrintToFile(const char* fileName)
sprintf(title1,
" %s: %s (%s)",
getmsg(&editorMessageList, &editorMessageListItem, 125),
itoa(gGameGlobalVars[GVAR_PLAYER_REPUTATION], title2, 10),
compat_itoa(gGameGlobalVars[GVAR_PLAYER_REPUTATION], title2, 10),
getmsg(&editorMessageList, &editorMessageListItem, reputationDescription->name));
fileWriteString(title1, stream);
fileWriteString("\n", stream);
@ -4489,7 +4490,7 @@ char* _itostndn(int value, char* dest)
int v18 = value / v16[index];
if (v18 > 0 || v3) {
char temp[64]; // TODO: Size is probably wrong.
itoa(v18, temp, 10);
compat_itoa(v18, temp, 10);
strcat(dest, temp);
v3 = true;
@ -5102,7 +5103,7 @@ void editorRenderKarma()
GenericReputationEntry* reputationDescription = &(gGenericReputationEntries[reputation]);
char reputationValue[32];
itoa(gGameGlobalVars[GVAR_PLAYER_REPUTATION], reputationValue, 10);
compat_itoa(gGameGlobalVars[GVAR_PLAYER_REPUTATION], reputationValue, 10);
sprintf(formattedText,
"%s: %s (%s)",
@ -6490,7 +6491,7 @@ bool editorDrawKillsEntry(const char* name, int kills)
color = _colorTable[992];
}
itoa(kills, killsString, 10);
compat_itoa(kills, killsString, 10);
int v6 = fontGetStringWidth(killsString);
// TODO: Check.

View File

@ -17,6 +17,7 @@
#include "map.h"
#include "memory.h"
#include "object.h"
#include "platform_compat.h"
#include "proto.h"
#include "proto_instance.h"
#include "random.h"
@ -199,7 +200,7 @@ void _parse_hurt_str(char* str, int* valuePtr)
*valuePtr = 0;
str = strlwr(str);
str = compat_strlwr(str);
while (*str) {
v5 = strspn(str, " ");
str += v5;
@ -234,7 +235,7 @@ int _cai_match_str_to_list(const char* str, const char** list, int count, int* v
{
*valuePtr = -1;
for (int index = 0; index < count; index++) {
if (stricmp(str, list[index]) == 0) {
if (compat_stricmp(str, list[index]) == 0) {
*valuePtr = index;
}
}

View File

@ -2,6 +2,7 @@
#include "db.h"
#include "memory.h"
#include "platform_compat.h"
#include <ctype.h>
#include <stdio.h>
@ -243,7 +244,7 @@ bool configGetIntList(Config* config, const char* sectionKey, const char* key, i
bool configSetInt(Config* config, const char* sectionKey, const char* key, int value)
{
char stringValue[20];
itoa(value, stringValue, 10);
compat_itoa(value, stringValue, 10);
return configSetString(config, sectionKey, key, stringValue);
}

View File

@ -1,5 +1,6 @@
#include "db.h"
#include "platform_compat.h"
#include "xfile.h"
#include <assert.h>
@ -620,7 +621,7 @@ int fileNameListInit(const char* pattern, char*** fileNameListPtr, int a3, int a
int fileNamesLength = xlist->fileNamesLength;
for (int index = 0; index < fileNamesLength - 1; index++) {
if (stricmp(xlist->fileNames[index], xlist->fileNames[index + 1]) == 0) {
if (compat_stricmp(xlist->fileNames[index], xlist->fileNames[index + 1]) == 0) {
char* temp = xlist->fileNames[index + 1];
memmove(&(xlist->fileNames[index + 1]), &(xlist->fileNames[index + 2]), sizeof(*xlist->fileNames) * (xlist->fileNamesLength - index - 1));
xlist->fileNames[xlist->fileNamesLength - 1] = temp;
@ -730,5 +731,5 @@ void _db_enable_hash_table_()
// 0x4C68E8
int _db_list_compare(const void* p1, const void* p2)
{
return stricmp(*(const char**)p1, *(const char**)p2);
return compat_stricmp(*(const char**)p1, *(const char**)p2);
}

View File

@ -1,6 +1,7 @@
#include "debug.h"
#include "memory.h"
#include "platform_compat.h"
#include "window_manager_private.h"
#include <stdarg.h>
@ -82,7 +83,7 @@ void _debug_register_env()
}
strcpy(copy, type);
strlwr(copy);
compat_strlwr(copy);
if (strcmp(copy, "mono") == 0) {
// NOTE: Uninline.

View File

@ -1,5 +1,7 @@
#include "dfile.h"
#include "platform_compat.h"
#include <fpattern.h>
#include <assert.h>
@ -591,7 +593,7 @@ int dbaseFindEntryByFilePath(const void* a1, const void* a2)
const char* filePath = (const char*)a1;
DBaseEntry* entry = (DBaseEntry*)a2;
return stricmp(filePath, entry->path);
return compat_stricmp(filePath, entry->path);
}
// 0x4E5D9C

View File

@ -3,6 +3,7 @@
#include "core.h"
#include "memory_manager.h"
#include "movie.h"
#include "platform_compat.h"
#include "text_font.h"
#include "widget.h"
#include "window_manager.h"
@ -450,7 +451,7 @@ int _dialogGotoReply(const char* a1)
ptr = &(_dialog[_tods]);
for (i = 0; i < ptr->field_8; i++) {
v5 = &(ptr->field_4[i]);
if (v5->field_4 != NULL && stricmp(v5->field_4, a1) == 0) {
if (v5->field_4 != NULL && compat_stricmp(v5->field_4, a1) == 0) {
ptr->field_10 = i;
return 0;
}

View File

@ -1,5 +1,7 @@
#include "dictionary.h"
#include "platform_compat.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@ -143,7 +145,7 @@ int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* inde
while (r >= l) {
mid = (l + r) / 2;
cmp = stricmp(key, dictionary->entries[mid].key);
cmp = compat_stricmp(key, dictionary->entries[mid].key);
if (cmp == 0) {
break;
}

View File

@ -2,6 +2,7 @@
#include "interpreter_lib.h"
#include "memory_manager.h"
#include "platform_compat.h"
#include <ctype.h>
#include <string.h>
@ -38,7 +39,7 @@ ExternalProcedure* externalProcedureFind(const char* identifier)
ExternalProcedure* externalProcedure = &(gExternalProcedures[v1]);
if (externalProcedure->program != NULL) {
if (stricmp(externalProcedure->name, identifier) == 0) {
if (compat_stricmp(externalProcedure->name, identifier) == 0) {
return externalProcedure;
}
}
@ -51,7 +52,7 @@ ExternalProcedure* externalProcedureFind(const char* identifier)
externalProcedure = &(gExternalProcedures[v1]);
if (externalProcedure->program != NULL) {
if (stricmp(externalProcedure->name, identifier) == 0) {
if (compat_stricmp(externalProcedure->name, identifier) == 0) {
return externalProcedure;
}
}
@ -95,7 +96,7 @@ ExternalVariable* externalVariableFind(const char* identifier)
unsigned int v2 = v1;
ExternalVariable* exportedVariable = &(gExternalVariables[v1]);
if (stricmp(exportedVariable->name, identifier) == 0) {
if (compat_stricmp(exportedVariable->name, identifier) == 0) {
return exportedVariable;
}
@ -111,7 +112,7 @@ ExternalVariable* externalVariableFind(const char* identifier)
}
exportedVariable = &(gExternalVariables[v1]);
if (stricmp(exportedVariable->name, identifier) == 0) {
if (compat_stricmp(exportedVariable->name, identifier) == 0) {
return exportedVariable;
}
} while (v1 != v2);
@ -200,7 +201,7 @@ int externalVariableCreate(Program* program, const char* identifier)
ExternalVariable* exportedVariable = externalVariableFind(identifier);
if (exportedVariable != NULL) {
if (stricmp(exportedVariable->programName, programName) != 0) {
if (compat_stricmp(exportedVariable->programName, programName) != 0) {
return 1;
}

View File

@ -39,6 +39,7 @@
#include "party_member.h"
#include "perk.h"
#include "pipboy.h"
#include "platform_compat.h"
#include "proto.h"
#include "queue.h"
#include "random.h"
@ -137,13 +138,13 @@ int gameInitWithOptions(const char* windowTitle, bool isMapper, int font, int a4
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language)) {
if (stricmp(language, FRENCH) == 0) {
if (compat_stricmp(language, FRENCH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_FRENCH);
} else if (stricmp(language, GERMAN) == 0) {
} else if (compat_stricmp(language, GERMAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_GERMAN);
} else if (stricmp(language, ITALIAN) == 0) {
} else if (compat_stricmp(language, ITALIAN) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_ITALIAN);
} else if (stricmp(language, SPANISH) == 0) {
} else if (compat_stricmp(language, SPANISH) == 0) {
keyboardSetLayout(KEYBOARD_LAYOUT_SPANISH);
}
}
@ -1222,7 +1223,7 @@ void showSplash()
char path[64];
char* language;
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && stricmp(language, ENGLISH) != 0) {
if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_LANGUAGE_KEY, &language) && compat_stricmp(language, ENGLISH) != 0) {
sprintf(path, "art\\%s\\splash\\", language);
} else {
sprintf(path, "art\\splash\\");

View File

@ -13,6 +13,7 @@
#include "item.h"
#include "map.h"
#include "object.h"
#include "platform_compat.h"
#include "proto.h"
#include "proto_instance.h"
#include "skilldex.h"
@ -2193,7 +2194,7 @@ int _gmouse_3d_move_to(int x, int y, int elevation, Rect* a4)
char* executable;
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, &executable);
if (stricmp(executable, "mapper") == 0) {
if (compat_stricmp(executable, "mapper") == 0) {
if (tileRoofIsVisible()) {
if ((gDude->flags & OBJECT_HIDDEN) == 0) {
y1 = -83;

View File

@ -11,6 +11,7 @@
#include "movie.h"
#include "movie_effect.h"
#include "palette.h"
#include "platform_compat.h"
#include "text_font.h"
#include "widget.h"
#include "window_manager.h"
@ -148,7 +149,7 @@ int gameMoviePlay(int movie, int flags)
int movieFileSize;
bool movieFound = false;
if (stricmp(language, ENGLISH) != 0) {
if (compat_stricmp(language, ENGLISH) != 0) {
sprintf(movieFilePath, "art\\%s\\cuts\\%s", language, gMovieFileNames[movie]);
movieFound = dbGetFileSize(movieFilePath, &movieFileSize) == 0;
}

View File

@ -13,6 +13,7 @@
#include "memory.h"
#include "movie.h"
#include "object.h"
#include "platform_compat.h"
#include "proto.h"
#include "queue.h"
#include "random.h"
@ -1308,7 +1309,7 @@ char* sfxBuildCharName(Object* a1, int anim, int extra)
}
sprintf(_sfx_file_name, "%s%c%c", v7, v8, v9);
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}
@ -1317,7 +1318,7 @@ char* sfxBuildCharName(Object* a1, int anim, int extra)
char* gameSoundBuildAmbientSoundEffectName(const char* a1)
{
sprintf(_sfx_file_name, "A%6s%1d", a1, 1);
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}
@ -1326,7 +1327,7 @@ char* gameSoundBuildAmbientSoundEffectName(const char* a1)
char* gameSoundBuildInterfaceName(const char* a1)
{
sprintf(_sfx_file_name, "N%6s%1d", a1, 1);
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}
@ -1402,7 +1403,7 @@ char* sfxBuildWeaponName(int effectType, Object* weapon, int hitMode, Object* ta
}
sprintf(_sfx_file_name, "W%c%c%1d%cXX%1d", effectTypeCode, weaponSoundCode, v6, materialCode, 1);
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}
@ -1414,7 +1415,7 @@ char* sfxBuildSceneryName(int actionType, int action, const char* name)
char actionCode = _snd_lookup_scenery_action[action];
sprintf(_sfx_file_name, "S%c%c%4s%1d", actionTypeCode, actionCode, name, 1);
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}
@ -1437,7 +1438,7 @@ char* sfxBuildOpenName(Object* object, int action)
protoGetProto(object->pid, &proto);
sprintf(_sfx_file_name, "I%cCNTNR%c", _snd_lookup_scenery_action[action], proto->item.field_80);
}
strupr(_sfx_file_name);
compat_strupr(_sfx_file_name);
return _sfx_file_name;
}

View File

@ -6,6 +6,7 @@
#include "export.h"
#include "interpreter_lib.h"
#include "memory_manager.h"
#include "platform_compat.h"
#include <assert.h>
#include <stdarg.h>
@ -2967,7 +2968,7 @@ void opLookupStringProc(Program* program)
for (int index = 1; index < procedureCount; index++) {
int offset = stackReadInt32(procedurePtr, 0);
const char* procedureName = programGetIdentifier(program, offset);
if (stricmp(procedureName, procedureNameToLookup) == 0) {
if (compat_stricmp(procedureName, procedureNameToLookup) == 0) {
programStackPushInt32(program, index);
programStackPushInt16(program, VALUE_TYPE_INT);
return;
@ -3309,7 +3310,7 @@ int programFindProcedure(Program* program, const char* name)
unsigned char* ptr = program->procedures + 4;
for (int index = 0; index < procedureCount; index++) {
int identifierOffset = stackReadInt32(ptr, offsetof(Procedure, field_0));
if (stricmp((char*)(program->identifiers + identifierOffset), name) == 0) {
if (compat_stricmp((char*)(program->identifiers + identifierOffset), name) == 0) {
return index;
}

View File

@ -23,6 +23,7 @@
#include "object.h"
#include "palette.h"
#include "pipboy.h"
#include "platform_compat.h"
#include "proto.h"
#include "proto_instance.h"
#include "queue.h"
@ -255,7 +256,7 @@ void _map_init()
{
char* executable;
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, "executable", &executable);
if (stricmp(executable, "mapper") == 0) {
if (compat_stricmp(executable, "mapper") == 0) {
_map_scroll_refresh = isoWindowRefreshRectMapper;
}
@ -696,7 +697,7 @@ int mapLoadByName(char* fileName)
{
int rc;
strupr(fileName);
compat_strupr(fileName);
rc = -1;

View File

@ -3,6 +3,7 @@
#include "debug.h"
#include "game_config.h"
#include "memory.h"
#include "platform_compat.h"
#include "random.h"
#include <ctype.h>
@ -82,7 +83,7 @@ int badwordsInit()
break;
}
strupr(gBadwords[index]);
compat_strupr(gBadwords[index]);
gBadwordsLengths[index] = len;
}
@ -523,7 +524,7 @@ bool messageListFilterBadwords(MessageList* messageList)
for (int index = 0; index < messageList->entries_num; index++) {
MessageListItem* item = &(messageList->entries[index]);
strcpy(_bad_copy, item->text);
strupr(_bad_copy);
compat_strupr(_bad_copy);
for (int badwordIndex = 0; badwordIndex < gBadwordsCount; badwordIndex++) {
// I don't quite understand the loop below. It has no stop

View File

@ -5,6 +5,7 @@
#include "memory.h"
#include "movie.h"
#include "palette.h"
#include "platform_compat.h"
#include <stdio.h>
#include <stdlib.h>
@ -127,7 +128,7 @@ int movieEffectsLoad(const char* filePath)
int movieEffectsCreated = 0;
for (int index = 0; index < movieEffectsLength; index++) {
char section[20];
itoa(movieEffectFrameList[index], section, 10);
compat_itoa(movieEffectFrameList[index], section, 10);
char* fadeTypeString;
if (!configGetString(&config, section, "fade_type", &fadeTypeString)) {
@ -135,9 +136,9 @@ int movieEffectsLoad(const char* filePath)
}
int fadeType = MOVIE_EFFECT_TYPE_NONE;
if (stricmp(fadeTypeString, "in") == 0) {
if (compat_stricmp(fadeTypeString, "in") == 0) {
fadeType = MOVIE_EFFECT_TYPE_FADE_IN;
} else if (stricmp(fadeTypeString, "out") == 0) {
} else if (compat_stricmp(fadeTypeString, "out") == 0) {
fadeType = MOVIE_EFFECT_TYPE_FADE_OUT;
}

View File

@ -2,6 +2,7 @@
#include "debug.h"
#include "memory_manager.h"
#include "platform_compat.h"
#include <stdlib.h>
#include <string.h>
@ -81,7 +82,7 @@ Nevs* _nevs_find(const char* a1)
for (int index = 0; index < NEVS_COUNT; index++) {
Nevs* nevs = &(_nevs[index]);
if (nevs->field_0 != 0 && stricmp(nevs->field_4, a1) == 0) {
if (nevs->field_0 != 0 && compat_stricmp(nevs->field_4, a1) == 0) {
return nevs;
}
}

28
src/platform_compat.cc Normal file
View File

@ -0,0 +1,28 @@
#include "platform_compat.h"
#include <SDL.h>
int compat_stricmp(const char* string1, const char* string2)
{
return SDL_strcasecmp(string1, string2);
}
int compat_strnicmp(const char* string1, const char* string2, size_t size)
{
return SDL_strncasecmp(string1, string2, size);
}
char* compat_strupr(char* string)
{
return SDL_strupr(string);
}
char* compat_strlwr(char* string)
{
return SDL_strlwr(string);
}
char* compat_itoa(int value, char* buffer, int radix)
{
return SDL_itoa(value, buffer, radix);
}

13
src/platform_compat.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef PLATFORM_COMPAT_H
#define PLATFORM_COMPAT_H
// TODO: This is compatibility cross-platform layer. Designed to have minimal
// impact on the codebase. Remove once it's no longer needed.
int compat_stricmp(const char* string1, const char* string2);
int compat_strnicmp(const char* string1, const char* string2, size_t size);
char* compat_strupr(char* string);
char* compat_strlwr(char* string);
char* compat_itoa(int value, char* buffer, int radix);
#endif /* PLATFORM_COMPAT_H */

View File

@ -3,6 +3,7 @@
#include "db.h"
#include "debug.h"
#include "memory.h"
#include "platform_compat.h"
#include "sound_decoder.h"
#include <limits.h>
@ -164,7 +165,7 @@ void soundEffectsListExit()
// 0x4A9C28
int soundEffectsListGetTag(char* name, int* tagPtr)
{
if (strnicmp(gSoundEffectsListPath, name, gSoundEffectsListPathLength) != 0) {
if (compat_strnicmp(gSoundEffectsListPath, name, gSoundEffectsListPathLength) != 0) {
return SFXL_ERR;
}
@ -441,7 +442,7 @@ int soundEffectsListCompareByName(const void* a1, const void* a2)
SoundEffectsListEntry* v1 = (SoundEffectsListEntry*)a1;
SoundEffectsListEntry* v2 = (SoundEffectsListEntry*)a2;
return stricmp(v1->name, v2->name);
return compat_stricmp(v1->name, v2->name);
}
// read via xfile

View File

@ -1,6 +1,7 @@
#include "string_parsers.h"
#include "debug.h"
#include "platform_compat.h"
#include <stdlib.h>
#include <string.h>
@ -19,7 +20,7 @@ int strParseInt(char** stringPtr, int* valuePtr)
str = *stringPtr;
strlwr(str);
compat_strlwr(str);
v1 = strspn(str, " ");
str += v1;
@ -63,7 +64,7 @@ int strParseStrFromList(char** stringPtr, int* valuePtr, const char** stringList
str = *stringPtr;
strlwr(str);
compat_strlwr(str);
v1 = strspn(str, " ");
str += v1;
@ -84,7 +85,7 @@ int strParseStrFromList(char** stringPtr, int* valuePtr, const char** stringList
}
for (i = 0; i < stringListLength; i++) {
if (stricmp(str, stringList[i]) == 0) {
if (compat_stricmp(str, stringList[i]) == 0) {
break;
}
}
@ -119,7 +120,7 @@ int strParseStrFromFunc(char** stringPtr, int* valuePtr, StringParserCallback* c
str = *stringPtr;
strlwr(str);
compat_strlwr(str);
v1 = strspn(str, " ");
str += v1;
@ -174,7 +175,7 @@ int strParseIntWithKey(char** stringPtr, const char* key, int* valuePtr, const c
return -1;
}
strlwr(str);
compat_strlwr(str);
if (*str == ',') {
str++;
@ -225,7 +226,7 @@ int strParseKeyValue(char** stringPtr, char* key, int* valuePtr, const char* del
return -1;
}
strlwr(str);
compat_strlwr(str);
if (*str == ',') {
str++;

View File

@ -10,6 +10,7 @@
#include "light.h"
#include "map.h"
#include "object.h"
#include "platform_compat.h"
#include <assert.h>
#include <string.h>
@ -391,7 +392,7 @@ int tileInit(TileData** a1, int squareGridWidth, int squareGridHeight, int hexGr
char* executable;
configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_EXECUTABLE_KEY, &executable);
if (stricmp(executable, "mapper") == 0) {
if (compat_stricmp(executable, "mapper") == 0) {
gTileWindowRefreshElevationProc = tileRefreshMapper;
}

View File

@ -6,6 +6,7 @@
#include "memory_manager.h"
#include "mouse_manager.h"
#include "movie.h"
#include "platform_compat.h"
#include "text_font.h"
#include "widget.h"
#include "window_manager.h"
@ -162,7 +163,7 @@ int _selectWindow(const char* windowName)
{
if (gCurrentManagedWindowIndex != -1) {
ManagedWindow* managedWindow = &(gManagedWindows[gCurrentManagedWindowIndex]);
if (stricmp(managedWindow->name, windowName) == 0) {
if (compat_stricmp(managedWindow->name, windowName) == 0) {
return gCurrentManagedWindowIndex;
}
}
@ -171,7 +172,7 @@ int _selectWindow(const char* windowName)
for (index = 0; index < MANAGED_WINDOW_COUNT; index++) {
ManagedWindow* managedWindow = &(gManagedWindows[index]);
if (managedWindow->window != -1) {
if (stricmp(managedWindow->name, windowName) == 0) {
if (compat_stricmp(managedWindow->name, windowName) == 0) {
break;
}
}
@ -666,7 +667,7 @@ bool _windowDeleteButton(const char* buttonName)
for (int index = 0; index < managedWindow->buttonsLength; index++) {
ManagedButton* managedButton = &(managedWindow->buttons[index]);
if (stricmp(managedButton->name, buttonName) == 0) {
if (compat_stricmp(managedButton->name, buttonName) == 0) {
buttonDestroy(managedButton->btn);
if (managedButton->field_48 != NULL) {
@ -724,7 +725,7 @@ bool _windowSetButtonFlag(const char* buttonName, int value)
for (int index = 0; index < managedWindow->buttonsLength; index++) {
ManagedButton* managedButton = &(managedWindow->buttons[index]);
if (stricmp(managedButton->name, buttonName) == 0) {
if (compat_stricmp(managedButton->name, buttonName) == 0) {
managedButton->flags |= value;
return true;
}
@ -747,7 +748,7 @@ bool _windowAddButtonProc(const char* buttonName, Program* program, int a3, int
for (int index = 0; index < managedWindow->buttonsLength; index++) {
ManagedButton* managedButton = &(managedWindow->buttons[index]);
if (stricmp(managedButton->name, buttonName) == 0) {
if (compat_stricmp(managedButton->name, buttonName) == 0) {
managedButton->field_5C = a3;
managedButton->field_60 = a4;
managedButton->field_54 = a5;
@ -774,7 +775,7 @@ bool _windowAddButtonRightProc(const char* buttonName, Program* program, int a3,
for (int index = 0; index < managedWindow->buttonsLength; index++) {
ManagedButton* managedButton = &(managedWindow->buttons[index]);
if (stricmp(managedButton->name, buttonName) == 0) {
if (compat_stricmp(managedButton->name, buttonName) == 0) {
managedButton->field_68 = a4;
managedButton->field_64 = a3;
managedButton->program = program;
@ -814,7 +815,7 @@ bool _windowCheckRegionExists(const char* regionName)
for (int index = 0; index < managedWindow->regionsLength; index++) {
Region* region = managedWindow->regions[index];
if (region != NULL) {
if (stricmp(regionGetName(region), regionName) == 0) {
if (compat_stricmp(regionGetName(region), regionName) == 0) {
return true;
}
}
@ -898,7 +899,7 @@ bool _windowAddRegionProc(const char* regionName, Program* program, int a3, int
for (int index = 0; index < managedWindow->regionsLength; index++) {
Region* region = managedWindow->regions[index];
if (region != NULL) {
if (stricmp(region->name, regionName) == 0) {
if (compat_stricmp(region->name, regionName) == 0) {
region->field_50 = a3;
region->field_54 = a4;
region->field_48 = a5;
@ -923,7 +924,7 @@ bool _windowAddRegionRightProc(const char* regionName, Program* program, int a3,
for (int index = 0; index < managedWindow->regionsLength; index++) {
Region* region = managedWindow->regions[index];
if (region != NULL) {
if (stricmp(region->name, regionName) == 0) {
if (compat_stricmp(region->name, regionName) == 0) {
region->field_58 = a3;
region->field_5C = a4;
region->program = program;
@ -943,7 +944,7 @@ bool _windowSetRegionFlag(const char* regionName, int value)
for (int index = 0; index < managedWindow->regionsLength; index++) {
Region* region = managedWindow->regions[index];
if (region != NULL) {
if (stricmp(region->name, regionName) == 0) {
if (compat_stricmp(region->name, regionName) == 0) {
regionAddFlag(region, value);
return true;
}
@ -971,7 +972,7 @@ bool _windowAddRegionName(const char* regionName)
if (index != managedWindow->currentRegionIndex) {
Region* other = managedWindow->regions[index];
if (other != NULL) {
if (stricmp(regionGetName(other), regionName) == 0) {
if (compat_stricmp(regionGetName(other), regionName) == 0) {
regionDelete(other);
managedWindow->regions[index] = NULL;
break;
@ -1003,7 +1004,7 @@ bool _windowDeleteRegion(const char* regionName)
for (int index = 0; index < managedWindow->regionsLength; index++) {
Region* region = managedWindow->regions[index];
if (region != NULL) {
if (stricmp(regionGetName(region), regionName) == 0) {
if (compat_stricmp(regionGetName(region), regionName) == 0) {
regionDelete(region);
managedWindow->regions[index] = NULL;
managedWindow->field_38++;

View File

@ -22,6 +22,7 @@
#include "object.h"
#include "party_member.h"
#include "perk.h"
#include "platform_compat.h"
#include "proto_instance.h"
#include "queue.h"
#include "random.h"
@ -1306,7 +1307,7 @@ int worldmapConfigLoadEncounterEntry(EncounterEntry* entry, char* string)
int _wmParseEncounterSubEncStr(EncounterEntry* encounterEntry, char** stringPtr)
{
char* string = *stringPtr;
if (strnicmp(string, "enc:", 4) != 0) {
if (compat_strnicmp(string, "enc:", 4) != 0) {
return -1;
}
@ -1411,7 +1412,7 @@ int _wmParseFindSubEncTypeMatch(char* str, int* valuePtr)
{
*valuePtr = 0;
if (stricmp(str, "player") == 0) {
if (compat_stricmp(str, "player") == 0) {
*valuePtr = -1;
return 0;
}
@ -1431,7 +1432,7 @@ int _wmParseFindSubEncTypeMatch(char* str, int* valuePtr)
int _wmFindEncBaseTypeMatch(char* str, int* valuePtr)
{
for (int index = 0; index < _wmMaxEncBaseTypes; index++) {
if (stricmp(_wmEncBaseTypeList[index].name, str) == 0) {
if (compat_stricmp(_wmEncBaseTypeList[index].name, str) == 0) {
*valuePtr = index;
return 0;
}
@ -1700,7 +1701,7 @@ int _wmParseTerrainTypes(Config* config, char* string)
worldmapTerrainInfoInit(terrain);
}
strlwr(string);
compat_strlwr(string);
pch = string;
for (int index = 0; index < gTerrainsLength; index++) {
@ -1794,7 +1795,7 @@ int worldmapConfigLoadSubtile(TileInfo* tile, int row, int column, char* string)
int worldmapFindEncounterTableByLookupName(char* string, int* valuePtr)
{
for (int index = 0; index < gEncounterTablesLength; index++) {
if (stricmp(string, gEncounterTables[index].lookupName) == 0) {
if (compat_stricmp(string, gEncounterTables[index].lookupName) == 0) {
*valuePtr = index;
return 0;
}
@ -1812,7 +1813,7 @@ int worldmapFindTerrainByLookupName(char* string, int* valuePtr)
{
for (int index = 0; index < gTerrainsLength; index++) {
Terrain* terrain = &(gTerrains[index]);
if (stricmp(string, terrain->field_0) == 0) {
if (compat_stricmp(string, terrain->field_0) == 0) {
*valuePtr = index;
return 0;
}
@ -1840,7 +1841,7 @@ int _wmParseEncounterItemType(char** stringPtr, ENC_BASE_TYPE_38_48* a2, int* a3
return -1;
}
strlwr(string);
compat_strlwr(string);
if (*string == ',') {
string++;
@ -1983,7 +1984,7 @@ int worldmapConfigParseConditionEntry(char** stringPtr, const char* a2, int* typ
return -1;
}
strlwr(string);
compat_strlwr(string);
if (*string == ',') {
string++;
@ -2383,7 +2384,7 @@ int worldmapFindMapByLookupName(char* string, int* valuePtr)
{
for (int index = 0; index < gMapsLength; index++) {
MapInfo* map = &(gMaps[index]);
if (stricmp(string, map->lookupName) == 0) {
if (compat_stricmp(string, map->lookupName) == 0) {
*valuePtr = index;
return 0;
}
@ -2471,7 +2472,7 @@ int _wmMapInit()
exit(1);
}
strlwr(str);
compat_strlwr(str);
strncpy(map->mapFileName, str, 40);
if (configGetString(&config, section, "music", &str)) {
@ -2636,7 +2637,7 @@ int mapGetFileName(int map, char* dest)
// 0x4BF9BC
int mapGetIndexByFileName(char* name)
{
strlwr(name);
compat_strlwr(name);
char* pch = name;
while (*pch != '\0' && *pch != '.') {
@ -6323,7 +6324,7 @@ int worldmapCompareCitiesByName(const void* a1, const void* a2)
CityInfo* city1 = &(gCities[v1]);
CityInfo* city2 = &(gCities[v2]);
return stricmp(city1->name, city2->name);
return compat_stricmp(city1->name, city2->name);
}
// 0x4C5734

View File

@ -1,6 +1,7 @@
#include "xfile.h"
#include "file_find.h"
#include "platform_compat.h"
#include <assert.h>
#include <direct.h>
@ -464,7 +465,7 @@ bool xbaseOpen(const char* path)
XBase* curr = gXbaseHead;
XBase* prev = NULL;
while (curr != NULL) {
if (stricmp(path, curr->path) == 0) {
if (compat_stricmp(path, curr->path) == 0) {
break;
}