diff options
author | rubidium42 <rubidium@openttd.org> | 2021-04-28 17:38:02 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-13 23:13:17 +0200 |
commit | 0f062b38826efbfa3b250da3943a6927346bc18c (patch) | |
tree | d0a028ac976b69b6d360979fc0c869f500543e60 /src/settings.cpp | |
parent | a032714dc4ca2b620af1ba9a444840d46ec9326f (diff) | |
download | openttd-0f062b38826efbfa3b250da3943a6927346bc18c.tar.xz |
Codechange: clean up C-string support from settings
Diffstat (limited to 'src/settings.cpp')
-rw-r--r-- | src/settings.cpp | 68 |
1 files changed, 4 insertions, 64 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index d47c120f0..6882179eb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -415,8 +415,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str return desc->def; } - case SDT_STDSTRING: - case SDT_STRING: return orig_str; + case SDT_STDSTRING: return orig_str; case SDT_INTLIST: return str; default: break; } @@ -497,35 +496,6 @@ static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val) /** * Set the string value of a setting. - * @param ptr Pointer to the storage location (might be a pointer to a pointer). - * @param sld Pointer to the information for the conversions and limitations to apply. - * @param p The string to save. - */ -static void Write_ValidateString(void *ptr, const SaveLoad *sld, const char *p) -{ - switch (GetVarMemType(sld->conv)) { - case SLE_VAR_STRB: - case SLE_VAR_STRBQ: - if (p != nullptr) { - char *begin = (char*)ptr; - char *end = begin + sld->length - 1; - strecpy(begin, p, end); - str_validate(begin, end, SVS_NONE); - } - break; - - case SLE_VAR_STR: - case SLE_VAR_STRQ: - free(*(char**)ptr); - *(char**)ptr = p == nullptr ? nullptr : stredup(p); - break; - - default: NOT_REACHED(); - } -} - -/** - * Set the string value of a setting. * @param ptr Pointer to the std::string. * @param sd Pointer to the information for the conversions and limitations to apply. * @param p The string to save. @@ -611,10 +581,6 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp Write_ValidateSetting(ptr, sd, (int32)(size_t)p); break; - case SDT_STRING: - Write_ValidateString(ptr, sld, (const char *)p); - break; - case SDT_STDSTRING: Write_ValidateStdString(ptr, sd, (const char *)p); break; @@ -736,24 +702,6 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp break; } - case SDT_STRING: - switch (GetVarMemType(sld->conv)) { - case SLE_VAR_STRB: strecpy(buf, (char*)ptr, lastof(buf)); break; - case SLE_VAR_STRBQ:seprintf(buf, lastof(buf), "\"%s\"", (char*)ptr); break; - case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break; - - case SLE_VAR_STRQ: - if (*(char**)ptr == nullptr) { - buf[0] = '\0'; - } else { - seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr); - } - break; - - default: NOT_REACHED(); - } - break; - case SDT_STDSTRING: switch (GetVarMemType(sld->conv)) { case SLE_VAR_STR: strecpy(buf, reinterpret_cast<std::string *>(ptr)->c_str(), lastof(buf)); break; @@ -2123,11 +2071,7 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame) } void *ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); - if (sd->desc.cmd == SDT_STRING) { - Write_ValidateString(ptr, &sd->save, value); - } else { - Write_ValidateStdString(ptr, sd, value); - } + Write_ValidateStdString(ptr, sd, value); if (sd->desc.proc != nullptr) sd->desc.proc(0); if (_save_config) SaveToConfig(); @@ -2184,7 +2128,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame) } bool success; - if (sd->desc.cmd == SDT_STRING || sd->desc.cmd == SDT_STDSTRING) { + if (sd->desc.cmd == SDT_STDSTRING) { success = SetSettingValue(index, value, force_newgame); } else { uint32 val; @@ -2235,9 +2179,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame) ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); - if (sd->desc.cmd == SDT_STRING) { - IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr); - } else if (sd->desc.cmd == SDT_STDSTRING) { + if (sd->desc.cmd == SDT_STDSTRING) { IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str()); } else { if (sd->desc.cmd == SDT_BOOLX) { @@ -2268,8 +2210,6 @@ void IConsoleListSettings(const char *prefilter) if (sd->desc.cmd == SDT_BOOLX) { seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off"); - } else if (sd->desc.cmd == SDT_STRING) { - seprintf(value, lastof(value), "%s", (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) ? *(const char * const *)ptr : (const char *)ptr); } else if (sd->desc.cmd == SDT_STDSTRING) { seprintf(value, lastof(value), "%s", reinterpret_cast<const std::string *>(ptr)->c_str()); } else { |