mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 10:19:57 -04:00
Quote a settings value on save when reading it back would change it.
cfg_load trims blanks around a value and takes one pair of quotes off it, so a mods_order list whose first mod's folder name starts with a space, or a value that is itself quoted, came back different at the next start and the mod lost its place and switch. Such values are now written in quotes; others are written as before. --probe-cfg checks it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -547,6 +547,17 @@ static const char *section_of(const char *key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// A value as cfg_load reads it back: quoted when it starts or ends with a blank (cfg_load trims those) or is itself
|
||||
// quoted (cfg_load takes one pair of quotes off). A mod's folder name in mods_order can start with a space.
|
||||
static void put_value(Out *o, const char *v) {
|
||||
size_t n = strlen(v);
|
||||
int quote = n && (v[0] == ' ' || v[0] == '\t' || v[n - 1] == ' ' || v[n - 1] == '\t' ||
|
||||
(n >= 2 && v[0] == '"' && v[n - 1] == '"'));
|
||||
if (quote) puts_(o, "\"");
|
||||
puts_(o, v);
|
||||
if (quote) puts_(o, "\"");
|
||||
}
|
||||
|
||||
// "key = value" + eol for entry e (key lower-case)
|
||||
static void put_entry(Out *o, const CfgEntry *e, const char *eol) {
|
||||
char k[64];
|
||||
@@ -554,7 +565,7 @@ static void put_entry(Out *o, const CfgEntry *e, const char *eol) {
|
||||
for (char *p = k; *p; p++) *p = (char)tolower((unsigned char)*p);
|
||||
puts_(o, k);
|
||||
puts_(o, " = ");
|
||||
puts_(o, e->value);
|
||||
put_value(o, e->value);
|
||||
puts_(o, eol);
|
||||
}
|
||||
|
||||
@@ -639,7 +650,7 @@ int cfg_save_to(const char *path) {
|
||||
while (kn && (s[kn - 1] == ' ' || s[kn - 1] == '\t')) kn--;
|
||||
put(&o, s, kn);
|
||||
puts_(&o, " = ");
|
||||
puts_(&o, entries[replace[i]].value);
|
||||
put_value(&o, entries[replace[i]].value);
|
||||
int had_eol = len && s[len - 1] == '\n';
|
||||
if (had_eol) puts_(&o, eol);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user