Merge: Codechange: Use null pointer literal instead of the NULL macro
This commit is contained in:
202
src/settings.cpp
202
src/settings.cpp
@@ -103,7 +103,7 @@ static const char * const _list_group_names[] = {
|
||||
"newgrf",
|
||||
"servers",
|
||||
"server_bind_addresses",
|
||||
NULL
|
||||
nullptr
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ static size_t LookupOneOfMany(const char *many, const char *one, size_t onelen =
|
||||
if (onelen == 0) onelen = strlen(one);
|
||||
|
||||
/* check if it's an integer */
|
||||
if (*one >= '0' && *one <= '9') return strtoul(one, NULL, 0);
|
||||
if (*one >= '0' && *one <= '9') return strtoul(one, nullptr, 0);
|
||||
|
||||
idx = 0;
|
||||
for (;;) {
|
||||
@@ -225,7 +225,7 @@ static bool LoadIntList(const char *str, void *array, int nelems, VarType type)
|
||||
int items[64];
|
||||
int i, nitems;
|
||||
|
||||
if (str == NULL) {
|
||||
if (str == nullptr) {
|
||||
memset(items, 0, sizeof(items));
|
||||
nitems = nelems;
|
||||
} else {
|
||||
@@ -355,7 +355,7 @@ static void MakeManyOfMany(char *buf, const char *last, const char *many, uint32
|
||||
*/
|
||||
static const void *StringToVal(const SettingDescBase *desc, const char *orig_str)
|
||||
{
|
||||
const char *str = orig_str == NULL ? "" : orig_str;
|
||||
const char *str = orig_str == nullptr ? "" : orig_str;
|
||||
|
||||
switch (desc->cmd) {
|
||||
case SDT_NUMX: {
|
||||
@@ -380,7 +380,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
|
||||
size_t r = LookupOneOfMany(desc->many, str);
|
||||
/* if the first attempt of conversion from string to the appropriate value fails,
|
||||
* look if we have defined a converter from old value to new value. */
|
||||
if (r == (size_t)-1 && desc->proc_cnvt != NULL) r = desc->proc_cnvt(str);
|
||||
if (r == (size_t)-1 && desc->proc_cnvt != nullptr) r = desc->proc_cnvt(str);
|
||||
if (r != (size_t)-1) return (void*)r; // and here goes converted value
|
||||
|
||||
ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_VALUE);
|
||||
@@ -416,7 +416,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
|
||||
default: break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +515,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
|
||||
/* For settings.xx.yy load the settings from [xx] yy = ? */
|
||||
s = strchr(sdb->name, '.');
|
||||
if (s != NULL) {
|
||||
if (s != nullptr) {
|
||||
group = ini->GetGroup(sdb->name, s - sdb->name);
|
||||
s++;
|
||||
} else {
|
||||
@@ -524,19 +524,19 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
}
|
||||
|
||||
item = group->GetItem(s, false);
|
||||
if (item == NULL && group != group_def) {
|
||||
if (item == nullptr && group != group_def) {
|
||||
/* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
|
||||
* did not exist (e.g. loading old config files with a [settings] section */
|
||||
item = group_def->GetItem(s, false);
|
||||
}
|
||||
if (item == NULL) {
|
||||
if (item == nullptr) {
|
||||
/* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
|
||||
* did not exist (e.g. loading old config files with a [yapf] section */
|
||||
const char *sc = strchr(s, '.');
|
||||
if (sc != NULL) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
|
||||
if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
|
||||
}
|
||||
|
||||
p = (item == NULL) ? sdb->def : StringToVal(sdb, item->value);
|
||||
p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
|
||||
ptr = GetVariableAddress(object, sld);
|
||||
|
||||
switch (sdb->cmd) {
|
||||
@@ -551,16 +551,16 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
switch (GetVarMemType(sld->conv)) {
|
||||
case SLE_VAR_STRB:
|
||||
case SLE_VAR_STRBQ:
|
||||
if (p != NULL) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
|
||||
if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1);
|
||||
break;
|
||||
|
||||
case SLE_VAR_STR:
|
||||
case SLE_VAR_STRQ:
|
||||
free(*(char**)ptr);
|
||||
*(char**)ptr = p == NULL ? NULL : stredup((const char*)p);
|
||||
*(char**)ptr = p == nullptr ? nullptr : stredup((const char*)p);
|
||||
break;
|
||||
|
||||
case SLE_VAR_CHAR: if (p != NULL) *(char *)ptr = *(const char *)p; break;
|
||||
case SLE_VAR_CHAR: if (p != nullptr) *(char *)ptr = *(const char *)p; break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -574,7 +574,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
|
||||
/* Use default */
|
||||
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
|
||||
} else if (sd->desc.proc_cnvt != NULL) {
|
||||
} else if (sd->desc.proc_cnvt != nullptr) {
|
||||
sd->desc.proc_cnvt((const char*)p);
|
||||
}
|
||||
break;
|
||||
@@ -598,7 +598,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
*/
|
||||
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
|
||||
{
|
||||
IniGroup *group_def = NULL, *group;
|
||||
IniGroup *group_def = nullptr, *group;
|
||||
IniItem *item;
|
||||
char buf[512];
|
||||
const char *s;
|
||||
@@ -615,11 +615,11 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
|
||||
/* XXX - wtf is this?? (group override?) */
|
||||
s = strchr(sdb->name, '.');
|
||||
if (s != NULL) {
|
||||
if (s != nullptr) {
|
||||
group = ini->GetGroup(sdb->name, s - sdb->name);
|
||||
s++;
|
||||
} else {
|
||||
if (group_def == NULL) group_def = ini->GetGroup(grpname);
|
||||
if (group_def == nullptr) group_def = ini->GetGroup(grpname);
|
||||
s = sdb->name;
|
||||
group = group_def;
|
||||
}
|
||||
@@ -627,7 +627,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
item = group->GetItem(s, true);
|
||||
ptr = GetVariableAddress(object, sld);
|
||||
|
||||
if (item->value != NULL) {
|
||||
if (item->value != nullptr) {
|
||||
/* check if the value is the same as the old value */
|
||||
const void *p = StringToVal(sdb, item->value);
|
||||
|
||||
@@ -640,7 +640,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
case SDT_MANYOFMANY:
|
||||
switch (GetVarMemType(sld->conv)) {
|
||||
case SLE_VAR_BL:
|
||||
if (*(bool*)ptr == (p != NULL)) continue;
|
||||
if (*(bool*)ptr == (p != nullptr)) continue;
|
||||
break;
|
||||
|
||||
case SLE_VAR_I8:
|
||||
@@ -691,7 +691,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
case SLE_VAR_STR: strecpy(buf, *(char**)ptr, lastof(buf)); break;
|
||||
|
||||
case SLE_VAR_STRQ:
|
||||
if (*(char**)ptr == NULL) {
|
||||
if (*(char**)ptr == nullptr) {
|
||||
buf[0] = '\0';
|
||||
} else {
|
||||
seprintf(buf, lastof(buf), "\"%s\"", *(char**)ptr);
|
||||
@@ -718,7 +718,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
|
||||
/**
|
||||
* Loads all items from a 'grpname' section into a list
|
||||
* The list parameter can be a NULL pointer, in this case nothing will be
|
||||
* The list parameter can be a nullptr pointer, in this case nothing will be
|
||||
* saved and a callback function should be defined that will take over the
|
||||
* list-handling and store the data itself somewhere.
|
||||
* @param ini IniFile handle to the ini file with the source data
|
||||
@@ -729,18 +729,18 @@ static void IniLoadSettingList(IniFile *ini, const char *grpname, StringList &li
|
||||
{
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
|
||||
list.clear();
|
||||
|
||||
for (const IniItem *item = group->item; item != NULL; item = item->next) {
|
||||
if (item->name != NULL) list.emplace_back(item->name);
|
||||
for (const IniItem *item = group->item; item != nullptr; item = item->next) {
|
||||
if (item->name != nullptr) list.emplace_back(item->name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all items from a list into the 'grpname' section
|
||||
* The list parameter can be a NULL pointer, in this case a callback function
|
||||
* The list parameter can be a nullptr pointer, in this case a callback function
|
||||
* should be defined that will provide the source data to be saved.
|
||||
* @param ini IniFile handle to the ini file where the destination data is saved
|
||||
* @param grpname character string identifying the section-header of the ini file
|
||||
@@ -751,7 +751,7 @@ static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &li
|
||||
{
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
group->Clear();
|
||||
|
||||
for (const auto &iter : list) {
|
||||
@@ -812,7 +812,7 @@ SettingType SettingDesc::GetType() const
|
||||
/** Reposition the main toolbar as the setting changed. */
|
||||
static bool v_PositionMainToolbar(int32 p1)
|
||||
{
|
||||
if (_game_mode != GM_MENU) PositionMainToolbar(NULL);
|
||||
if (_game_mode != GM_MENU) PositionMainToolbar(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -820,9 +820,9 @@ static bool v_PositionMainToolbar(int32 p1)
|
||||
static bool v_PositionStatusbar(int32 p1)
|
||||
{
|
||||
if (_game_mode != GM_MENU) {
|
||||
PositionStatusbar(NULL);
|
||||
PositionNewsMessage(NULL);
|
||||
PositionNetworkChatWindow(NULL);
|
||||
PositionStatusbar(nullptr);
|
||||
PositionNewsMessage(nullptr);
|
||||
PositionNetworkChatWindow(nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1545,14 +1545,14 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
|
||||
|
||||
/* Clean any configured AI */
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(NULL);
|
||||
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(nullptr);
|
||||
}
|
||||
|
||||
/* If no group exists, return */
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
|
||||
CompanyID c = COMPANY_FIRST;
|
||||
for (item = group->item; c < MAX_COMPANIES && item != NULL; c++, item = item->next) {
|
||||
for (item = group->item; c < MAX_COMPANIES && item != nullptr; c++, item = item->next) {
|
||||
AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME);
|
||||
|
||||
config->Change(item->name);
|
||||
@@ -1562,7 +1562,7 @@ static void AILoadConfig(IniFile *ini, const char *grpname)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (item->value != NULL) config->StringToSettings(item->value);
|
||||
if (item->value != nullptr) config->StringToSettings(item->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1572,13 +1572,13 @@ static void GameLoadConfig(IniFile *ini, const char *grpname)
|
||||
IniItem *item;
|
||||
|
||||
/* Clean any configured GameScript */
|
||||
GameConfig::GetConfig(GameConfig::SSS_FORCE_NEWGAME)->Change(NULL);
|
||||
GameConfig::GetConfig(GameConfig::SSS_FORCE_NEWGAME)->Change(nullptr);
|
||||
|
||||
/* If no group exists, return */
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
|
||||
item = group->item;
|
||||
if (item == NULL) return;
|
||||
if (item == nullptr) return;
|
||||
|
||||
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
|
||||
|
||||
@@ -1589,7 +1589,7 @@ static void GameLoadConfig(IniFile *ini, const char *grpname)
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (item->value != NULL) config->StringToSettings(item->value);
|
||||
if (item->value != nullptr) config->StringToSettings(item->value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1636,13 +1636,13 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
{
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
IniItem *item;
|
||||
GRFConfig *first = NULL;
|
||||
GRFConfig *first = nullptr;
|
||||
GRFConfig **curr = &first;
|
||||
|
||||
if (group == NULL) return NULL;
|
||||
if (group == nullptr) return nullptr;
|
||||
|
||||
for (item = group->item; item != NULL; item = item->next) {
|
||||
GRFConfig *c = NULL;
|
||||
for (item = group->item; item != nullptr; item = item->next) {
|
||||
GRFConfig *c = nullptr;
|
||||
|
||||
uint8 grfid_buf[4], md5sum[16];
|
||||
char *filename = item->name;
|
||||
@@ -1659,14 +1659,14 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
uint32 grfid = grfid_buf[0] | (grfid_buf[1] << 8) | (grfid_buf[2] << 16) | (grfid_buf[3] << 24);
|
||||
if (has_md5sum) {
|
||||
const GRFConfig *s = FindGRFConfig(grfid, FGCM_EXACT, md5sum);
|
||||
if (s != NULL) c = new GRFConfig(*s);
|
||||
if (s != nullptr) c = new GRFConfig(*s);
|
||||
}
|
||||
if (c == NULL && !FioCheckFileExists(filename, NEWGRF_DIR)) {
|
||||
if (c == nullptr && !FioCheckFileExists(filename, NEWGRF_DIR)) {
|
||||
const GRFConfig *s = FindGRFConfig(grfid, FGCM_NEWEST_VALID);
|
||||
if (s != NULL) c = new GRFConfig(*s);
|
||||
if (s != nullptr) c = new GRFConfig(*s);
|
||||
}
|
||||
}
|
||||
if (c == NULL) c = new GRFConfig(filename);
|
||||
if (c == nullptr) c = new GRFConfig(filename);
|
||||
|
||||
/* Parse parameters */
|
||||
if (!StrEmpty(item->value)) {
|
||||
@@ -1701,7 +1701,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||
|
||||
/* Check for duplicate GRFID (will also check for duplicate filenames) */
|
||||
bool duplicate = false;
|
||||
for (const GRFConfig *gc = first; gc != NULL; gc = gc->next) {
|
||||
for (const GRFConfig *gc = first; gc != nullptr; gc = gc->next) {
|
||||
if (gc->ident.grfid == c->ident.grfid) {
|
||||
SetDParamStr(0, c->filename);
|
||||
SetDParamStr(1, gc->filename);
|
||||
@@ -1730,7 +1730,7 @@ static void AISaveConfig(IniFile *ini, const char *grpname)
|
||||
{
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
group->Clear();
|
||||
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
@@ -1754,7 +1754,7 @@ static void GameSaveConfig(IniFile *ini, const char *grpname)
|
||||
{
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
|
||||
if (group == NULL) return;
|
||||
if (group == nullptr) return;
|
||||
group->Clear();
|
||||
|
||||
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
|
||||
@@ -1800,7 +1800,7 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
|
||||
IniGroup *group = ini->GetGroup(grpname);
|
||||
const GRFConfig *c;
|
||||
|
||||
for (c = list; c != NULL; c = c->next) {
|
||||
for (c = list; c != nullptr; c = c->next) {
|
||||
/* Hex grfid (4 bytes in nibbles), "|", hex md5sum (16 bytes in nibbles), "|", file system path. */
|
||||
char key[4 * 2 + 1 + 16 * 2 + 1 + MAX_PATH];
|
||||
char params[512];
|
||||
@@ -1817,9 +1817,9 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
|
||||
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
|
||||
{
|
||||
if (basic_settings) {
|
||||
proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL);
|
||||
proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
|
||||
#if defined(_WIN32) && !defined(DEDICATED)
|
||||
proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL);
|
||||
proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
@@ -1868,7 +1868,7 @@ void LoadFromConfig(bool minimal)
|
||||
/* Display sheduled errors */
|
||||
extern void ScheduleErrorMessage(ErrorList &datas);
|
||||
ScheduleErrorMessage(_settings_error_list);
|
||||
if (FindWindowById(WC_ERRMSG, 0) == NULL) ShowFirstError();
|
||||
if (FindWindowById(WC_ERRMSG, 0) == nullptr) ShowFirstError();
|
||||
}
|
||||
|
||||
delete ini;
|
||||
@@ -1903,7 +1903,7 @@ StringList GetGRFPresetList()
|
||||
StringList list;
|
||||
|
||||
std::unique_ptr<IniFile> ini(IniLoadConfig());
|
||||
for (IniGroup *group = ini->group; group != NULL; group = group->next) {
|
||||
for (IniGroup *group = ini->group; group != nullptr; group = group->next) {
|
||||
if (strncmp(group->name, "preset-", 7) == 0) {
|
||||
list.emplace_back(group->name + 7);
|
||||
}
|
||||
@@ -1967,7 +1967,7 @@ void DeleteGRFPresetFromConfig(const char *config_name)
|
||||
|
||||
const SettingDesc *GetSettingDescription(uint index)
|
||||
{
|
||||
if (index >= lengthof(_settings)) return NULL;
|
||||
if (index >= lengthof(_settings)) return nullptr;
|
||||
return &_settings[index];
|
||||
}
|
||||
|
||||
@@ -1986,7 +1986,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||
{
|
||||
const SettingDesc *sd = GetSettingDescription(p1);
|
||||
|
||||
if (sd == NULL) return CMD_ERROR;
|
||||
if (sd == nullptr) return CMD_ERROR;
|
||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) return CMD_ERROR;
|
||||
|
||||
if (!sd->IsEditable(true)) return CMD_ERROR;
|
||||
@@ -2002,7 +2002,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||
|
||||
if (oldval == newval) return CommandCost();
|
||||
|
||||
if (sd->desc.proc != NULL && !sd->desc.proc(newval)) {
|
||||
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
|
||||
WriteValue(var, sd->save.conv, (int64)oldval);
|
||||
return CommandCost();
|
||||
}
|
||||
@@ -2045,7 +2045,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
|
||||
|
||||
if (oldval == newval) return CommandCost();
|
||||
|
||||
if (sd->desc.proc != NULL && !sd->desc.proc(newval)) {
|
||||
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) {
|
||||
WriteValue(var, sd->save.conv, (int64)oldval);
|
||||
return CommandCost();
|
||||
}
|
||||
@@ -2078,7 +2078,7 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame)
|
||||
void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
|
||||
Write_ValidateSetting(var2, sd, value);
|
||||
}
|
||||
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
|
||||
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
|
||||
|
||||
SetWindowClassesDirty(WC_GAME_OPTIONS);
|
||||
|
||||
@@ -2112,7 +2112,7 @@ void SetCompanySetting(uint index, int32 value)
|
||||
} else {
|
||||
void *var = GetVariableAddress(&_settings_client.company, &sd->save);
|
||||
Write_ValidateSetting(var, sd, value);
|
||||
if (sd->desc.proc != NULL) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
|
||||
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2141,7 +2141,7 @@ void SyncCompanySettings()
|
||||
const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
|
||||
uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
|
||||
uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
|
||||
if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, NULL, NULL, _local_company, 0);
|
||||
if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2154,7 +2154,7 @@ uint GetCompanySettingIndex(const char *name)
|
||||
{
|
||||
uint i;
|
||||
const SettingDesc *sd = GetSettingFromName(name, &i);
|
||||
assert(sd != NULL && (sd->desc.flags & SGF_PER_COMPANY) != 0);
|
||||
assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -2173,12 +2173,12 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame)
|
||||
if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ) {
|
||||
char **var = (char**)GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
|
||||
free(*var);
|
||||
*var = strcmp(value, "(null)") == 0 ? NULL : stredup(value);
|
||||
*var = strcmp(value, "(null)") == 0 ? nullptr : stredup(value);
|
||||
} else {
|
||||
char *var = (char*)GetVariableAddress(NULL, &sd->save);
|
||||
char *var = (char*)GetVariableAddress(nullptr, &sd->save);
|
||||
strecpy(var, value, &var[sd->save.length - 1]);
|
||||
}
|
||||
if (sd->desc.proc != NULL) sd->desc.proc(0);
|
||||
if (sd->desc.proc != nullptr) sd->desc.proc(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2189,7 +2189,7 @@ bool SetSettingValue(uint index, const char *value, bool force_newgame)
|
||||
* @param i Pointer to an integer that will contain the index of the setting after the call, if it is successful.
|
||||
* @param ignore_version Return a setting even if it not valid for the current savegame version
|
||||
* @return Pointer to the setting description of setting \a name if it can be found,
|
||||
* \c NULL indicates failure to obtain the description
|
||||
* \c nullptr indicates failure to obtain the description
|
||||
*/
|
||||
const SettingDesc *GetSettingFromName(const char *name, uint *i, bool ignore_version)
|
||||
{
|
||||
@@ -2197,17 +2197,17 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i, bool ignore_ver
|
||||
|
||||
/* First check all full names */
|
||||
for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
|
||||
if (sd->desc.name == NULL) continue;
|
||||
if (sd->desc.name == nullptr) continue;
|
||||
if (!ignore_version && !SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
||||
if (strcmp(sd->desc.name, name) == 0) return sd;
|
||||
}
|
||||
|
||||
/* Then check the shortcut variant of the name. */
|
||||
for (*i = 0, sd = _settings; sd->save.cmd != SL_END; sd++, (*i)++) {
|
||||
if (sd->desc.name == NULL) continue;
|
||||
if (sd->desc.name == nullptr) continue;
|
||||
if (!ignore_version && !SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
||||
const char *short_name = strchr(sd->desc.name, '.');
|
||||
if (short_name != NULL) {
|
||||
if (short_name != nullptr) {
|
||||
short_name++;
|
||||
if (strcmp(short_name, name) == 0) return sd;
|
||||
}
|
||||
@@ -2216,12 +2216,12 @@ const SettingDesc *GetSettingFromName(const char *name, uint *i, bool ignore_ver
|
||||
if (strncmp(name, "company.", 8) == 0) name += 8;
|
||||
/* And finally the company-based settings */
|
||||
for (*i = 0, sd = _company_settings; sd->save.cmd != SL_END; sd++, (*i)++) {
|
||||
if (sd->desc.name == NULL) continue;
|
||||
if (sd->desc.name == nullptr) continue;
|
||||
if (!ignore_version && !SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
||||
if (strcmp(sd->desc.name, name) == 0) return sd;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Those 2 functions need to be here, else we have to make some stuff non-static
|
||||
@@ -2231,7 +2231,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
||||
uint index;
|
||||
const SettingDesc *sd = GetSettingFromName(name, &index);
|
||||
|
||||
if (sd == NULL) {
|
||||
if (sd == nullptr) {
|
||||
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
|
||||
return;
|
||||
}
|
||||
@@ -2264,7 +2264,7 @@ void IConsoleSetSetting(const char *name, int value)
|
||||
{
|
||||
uint index;
|
||||
const SettingDesc *sd = GetSettingFromName(name, &index);
|
||||
assert(sd != NULL);
|
||||
assert(sd != nullptr);
|
||||
SetSettingValue(index, value);
|
||||
}
|
||||
|
||||
@@ -2280,7 +2280,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
|
||||
const SettingDesc *sd = GetSettingFromName(name, &index);
|
||||
const void *ptr;
|
||||
|
||||
if (sd == NULL) {
|
||||
if (sd == nullptr) {
|
||||
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
|
||||
return;
|
||||
}
|
||||
@@ -2304,7 +2304,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
|
||||
/**
|
||||
* List all settings and their value to the console
|
||||
*
|
||||
* @param prefilter If not \c NULL, only list settings with names that begin with \a prefilter prefix
|
||||
* @param prefilter If not \c nullptr, only list settings with names that begin with \a prefilter prefix
|
||||
*/
|
||||
void IConsoleListSettings(const char *prefilter)
|
||||
{
|
||||
@@ -2312,7 +2312,7 @@ void IConsoleListSettings(const char *prefilter)
|
||||
|
||||
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
|
||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
|
||||
if (prefilter != NULL && strstr(sd->desc.name, prefilter) == NULL) continue;
|
||||
if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
|
||||
char value[80];
|
||||
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
|
||||
|
||||
@@ -2332,14 +2332,14 @@ void IConsoleListSettings(const char *prefilter)
|
||||
/**
|
||||
* Load handler for settings, which don't go in the PATX chunk, and which are a cross-reference to another setting
|
||||
* @param osd SettingDesc struct containing all information
|
||||
* @param object can be either NULL in which case we load global variables or
|
||||
* @param object can be either nullptr in which case we load global variables or
|
||||
* a pointer to a struct which is getting saved
|
||||
*/
|
||||
static void LoadSettingsXref(const SettingDesc *osd, void *object) {
|
||||
DEBUG(sl, 3, "PATS chunk: Loading xref setting: '%s'", osd->xref);
|
||||
uint index = 0;
|
||||
const SettingDesc *setting_xref = GetSettingFromName(osd->xref, &index, true);
|
||||
assert(setting_xref != NULL);
|
||||
assert(setting_xref != nullptr);
|
||||
|
||||
// Generate a new SaveLoad from the xref target using the version params from the source
|
||||
SaveLoad sld = setting_xref->save;
|
||||
@@ -2355,7 +2355,7 @@ static void LoadSettingsXref(const SettingDesc *osd, void *object) {
|
||||
/**
|
||||
* Save and load handler for settings, except for those which go in the PATX chunk
|
||||
* @param osd SettingDesc struct containing all information
|
||||
* @param object can be either NULL in which case we load global variables or
|
||||
* @param object can be either nullptr in which case we load global variables or
|
||||
* a pointer to a struct which is getting saved
|
||||
*/
|
||||
static void LoadSettings(const SettingDesc *osd, void *object)
|
||||
@@ -2363,9 +2363,9 @@ static void LoadSettings(const SettingDesc *osd, void *object)
|
||||
extern SaveLoadVersion _sl_version;
|
||||
|
||||
for (; osd->save.cmd != SL_END; osd++) {
|
||||
if (osd->patx_name != NULL) continue;
|
||||
if (osd->patx_name != nullptr) continue;
|
||||
const SaveLoad *sld = &osd->save;
|
||||
if (osd->xref != NULL) {
|
||||
if (osd->xref != nullptr) {
|
||||
if (sld->ext_feature_test.IsFeaturePresent(_sl_version, sld->version_from, sld->version_to)) LoadSettingsXref(osd, object);
|
||||
continue;
|
||||
}
|
||||
@@ -2379,7 +2379,7 @@ static void LoadSettings(const SettingDesc *osd, void *object)
|
||||
/**
|
||||
* Save and load handler for settings, except for those which go in the PATX chunk
|
||||
* @param sd SettingDesc struct containing all information
|
||||
* @param object can be either NULL in which case we load global variables or
|
||||
* @param object can be either nullptr in which case we load global variables or
|
||||
* a pointer to a struct which is getting saved
|
||||
*/
|
||||
static void SaveSettings(const SettingDesc *sd, void *object)
|
||||
@@ -2389,14 +2389,14 @@ static void SaveSettings(const SettingDesc *sd, void *object)
|
||||
const SettingDesc *i;
|
||||
size_t length = 0;
|
||||
for (i = sd; i->save.cmd != SL_END; i++) {
|
||||
if (i->patx_name != NULL) continue;
|
||||
if (i->xref != NULL) continue;
|
||||
if (i->patx_name != nullptr) continue;
|
||||
if (i->xref != nullptr) continue;
|
||||
length += SlCalcObjMemberLength(object, &i->save);
|
||||
}
|
||||
SlSetLength(length);
|
||||
|
||||
for (i = sd; i->save.cmd != SL_END; i++) {
|
||||
if (i->patx_name != NULL) continue;
|
||||
if (i->patx_name != nullptr) continue;
|
||||
void *ptr = GetVariableAddress(object, &i->save);
|
||||
SlObjectMember(ptr, &i->save);
|
||||
}
|
||||
@@ -2429,14 +2429,14 @@ static std::vector<const SettingDesc *> _sorted_patx_settings;
|
||||
*/
|
||||
static void MakeSettingsPatxList(const SettingDesc *sd)
|
||||
{
|
||||
static const SettingDesc *previous = NULL;
|
||||
static const SettingDesc *previous = nullptr;
|
||||
|
||||
if (sd == previous) return;
|
||||
previous = sd;
|
||||
|
||||
_sorted_patx_settings.clear();
|
||||
for (const SettingDesc *desc = sd; desc->save.cmd != SL_END; desc++) {
|
||||
if (desc->patx_name == NULL) continue;
|
||||
if (desc->patx_name == nullptr) continue;
|
||||
_sorted_patx_settings.push_back(desc);
|
||||
}
|
||||
|
||||
@@ -2480,7 +2480,7 @@ static const SaveLoad _settings_ext_save_desc[] = {
|
||||
/**
|
||||
* Load handler for settings which go in the PATX chunk
|
||||
* @param osd SettingDesc struct containing all information
|
||||
* @param object can be either NULL in which case we load global variables or
|
||||
* @param object can be either nullptr in which case we load global variables or
|
||||
* a pointer to a struct which is getting saved
|
||||
*/
|
||||
static void LoadSettingsPatx(const SettingDesc *sd, void *object)
|
||||
@@ -2529,7 +2529,7 @@ static void LoadSettingsPatx(const SettingDesc *sd, void *object)
|
||||
/**
|
||||
* Save handler for settings which go in the PATX chunk
|
||||
* @param sd SettingDesc struct containing all information
|
||||
* @param object can be either NULL in which case we load global variables or
|
||||
* @param object can be either nullptr in which case we load global variables or
|
||||
* a pointer to a struct which is getting saved
|
||||
*/
|
||||
static void SaveSettingsPatx(const SettingDesc *sd, void *object)
|
||||
@@ -2544,7 +2544,7 @@ static void SaveSettingsPatx(const SettingDesc *sd, void *object)
|
||||
|
||||
size_t length = 8;
|
||||
for (const SettingDesc *desc = sd; desc->save.cmd != SL_END; desc++) {
|
||||
if (desc->patx_name == NULL) continue;
|
||||
if (desc->patx_name == nullptr) continue;
|
||||
uint32 setting_length = SlCalcObjMemberLength(object, &desc->save);
|
||||
if (!setting_length) continue;
|
||||
|
||||
@@ -2615,10 +2615,10 @@ void LoadSettingsPlyx(bool skip)
|
||||
uint32 company_id = SlReadUint32();
|
||||
if (company_id >= MAX_COMPANIES) SlErrorCorruptFmt("PLYX chunk: invalid company ID: %u", company_id);
|
||||
|
||||
const Company *c = NULL;
|
||||
const Company *c = nullptr;
|
||||
if (!skip) {
|
||||
c = Company::GetIfValid(company_id);
|
||||
if (c == NULL) SlErrorCorruptFmt("PLYX chunk: non-existant company ID: %u", company_id);
|
||||
if (c == nullptr) SlErrorCorruptFmt("PLYX chunk: non-existant company ID: %u", company_id);
|
||||
}
|
||||
|
||||
uint32 company_flags = SlReadUint32();
|
||||
@@ -2637,17 +2637,17 @@ void LoadSettingsPlyx(bool skip)
|
||||
continue;
|
||||
}
|
||||
|
||||
const SettingDesc *setting = NULL;
|
||||
const SettingDesc *setting = nullptr;
|
||||
|
||||
// not many company settings, so perform a linear scan
|
||||
for (const SettingDesc *desc = _company_settings; desc->save.cmd != SL_END; desc++) {
|
||||
if (desc->patx_name != NULL && strcmp(desc->patx_name, current_setting.name) == 0) {
|
||||
if (desc->patx_name != nullptr && strcmp(desc->patx_name, current_setting.name) == 0) {
|
||||
setting = desc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (setting != NULL) {
|
||||
if (setting != nullptr) {
|
||||
// found setting
|
||||
const SaveLoad *sld = &(setting->save);
|
||||
size_t read = SlGetBytesRead();
|
||||
@@ -2690,7 +2690,7 @@ void SaveSettingsPlyx()
|
||||
companies_count++;
|
||||
uint32 setting_count = 0;
|
||||
for (const SettingDesc *desc = _company_settings; desc->save.cmd != SL_END; desc++) {
|
||||
if (desc->patx_name == NULL) continue;
|
||||
if (desc->patx_name == nullptr) continue;
|
||||
uint32 setting_length = SlCalcObjMemberLength(&(c->settings), &desc->save);
|
||||
if (!setting_length) continue;
|
||||
|
||||
@@ -2721,7 +2721,7 @@ void SaveSettingsPlyx()
|
||||
index++;
|
||||
|
||||
for (const SettingDesc *desc = _company_settings; desc->save.cmd != SL_END; desc++) {
|
||||
if (desc->patx_name == NULL) continue;
|
||||
if (desc->patx_name == nullptr) continue;
|
||||
uint32 setting_length = SlCalcObjMemberLength(&(c->settings), &desc->save);
|
||||
if (!setting_length) continue;
|
||||
|
||||
@@ -2779,9 +2779,9 @@ static void Save_PATX()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _setting_chunk_handlers[] = {
|
||||
{ 'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF},
|
||||
{ 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF},
|
||||
{ 'PATX', Save_PATX, Load_PATX, NULL, Check_PATX, CH_RIFF | CH_LAST},
|
||||
{ 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF},
|
||||
{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF},
|
||||
{ 'PATX', Save_PATX, Load_PATX, nullptr, Check_PATX, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
||||
static bool IsSignedVarMemType(VarType vt)
|
||||
|
Reference in New Issue
Block a user