mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-02 04:13:26 +00:00
(svn r16128) -Change: allow loading (and storing) NULL values for STRQ in openttd.cfg.
This commit is contained in:
parent
e2a7732151
commit
208234a7a0
@ -237,7 +237,7 @@ void IniFile::LoadFromDisk(const char *filename)
|
||||
/* find start of parameter */
|
||||
while (*t == '=' || *t == ' ' || *t == '\t') t++;
|
||||
|
||||
|
||||
bool quoted = (*t == '\"');
|
||||
/* remove starting quotation marks */
|
||||
if (*t == '\"') t++;
|
||||
/* remove ending quotation marks */
|
||||
@ -245,7 +245,8 @@ void IniFile::LoadFromDisk(const char *filename)
|
||||
if (e > t && e[-1] == '\"') e--;
|
||||
*e = '\0';
|
||||
|
||||
item->value = strndup(t, e - t);
|
||||
/* If the value was not quoted and empty, it must be NULL */
|
||||
item->value = (!quoted && e == t) ? NULL : strndup(t, e - t);
|
||||
} else {
|
||||
/* it's an orphan item */
|
||||
ShowInfoF("ini: '%s' outside of group", buffer);
|
||||
@ -279,7 +280,6 @@ bool IniFile::SaveToDisk(const char *filename)
|
||||
if (group->comment) fputs(group->comment, f);
|
||||
fprintf(f, "[%s]\n", group->name);
|
||||
for (const IniItem *item = group->item; item != NULL; item = item->next) {
|
||||
assert(item->value != NULL);
|
||||
if (item->comment != NULL) fputs(item->comment, f);
|
||||
|
||||
/* protect item->name with quotes if needed */
|
||||
@ -290,7 +290,7 @@ bool IniFile::SaveToDisk(const char *filename)
|
||||
fprintf(f, "%s", item->name);
|
||||
}
|
||||
|
||||
fprintf(f, " = %s\n", item->value);
|
||||
fprintf(f, " = %s\n", item->value == NULL ? "" : item->value);
|
||||
}
|
||||
}
|
||||
if (this->comment) fputs(this->comment, f);
|
||||
|
@ -293,8 +293,9 @@ static void make_manyofmany(char *buf, const char *last, const char *many, uint3
|
||||
* @param desc SettingDesc struct that holds all information about the variable
|
||||
* @param str input string that will be parsed based on the type of desc
|
||||
* @return return the parsed value of the setting */
|
||||
static const void *string_to_val(const SettingDescBase *desc, const char *str)
|
||||
static const void *string_to_val(const SettingDescBase *desc, const char *orig_str)
|
||||
{
|
||||
const char *str = orig_str == NULL ? "" : orig_str;
|
||||
switch (desc->cmd) {
|
||||
case SDT_NUMX: {
|
||||
char *end;
|
||||
@ -325,7 +326,7 @@ static const void *string_to_val(const SettingDescBase *desc, const char *str)
|
||||
ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name);
|
||||
break;
|
||||
|
||||
case SDT_STRING:
|
||||
case SDT_STRING: return orig_str;
|
||||
case SDT_INTLIST: return str;
|
||||
default: break;
|
||||
}
|
||||
@ -446,12 +447,10 @@ static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *g
|
||||
break;
|
||||
case SLE_VAR_STR:
|
||||
case SLE_VAR_STRQ:
|
||||
if (p != NULL) {
|
||||
free(*(char**)ptr);
|
||||
*(char**)ptr = strdup((const char*)p);
|
||||
}
|
||||
free(*(char**)ptr);
|
||||
*(char**)ptr = p == NULL ? NULL : strdup((const char*)p);
|
||||
break;
|
||||
case SLE_VAR_CHAR: *(char*)ptr = *(char*)p; break;
|
||||
case SLE_VAR_CHAR: if (p != NULL) *(char*)ptr = *(char*)p; break;
|
||||
default: NOT_REACHED(); break;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user