summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-04-07 22:30:10 +0000
committerglx <glx@openttd.org>2007-04-07 22:30:10 +0000
commit6b35482c8d2cf78bd1092c60002ac29bb2e29e9c (patch)
tree771f0b546ad0d31e62ae9e7b4f04be2685c95802
parentcb431a6a3ea8f08aadf972a76b2e8d5f9d03d93a (diff)
downloadopenttd-6b35482c8d2cf78bd1092c60002ac29bb2e29e9c.tar.xz
(svn r9573) -Fix: enclose settings names containing spaces (like newgrf paths) with quotes
-rw-r--r--src/settings.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 2a758ab22..2836df2d7 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -261,7 +261,13 @@ static IniFile *ini_load(const char *filename)
}
} else if (group) {
/* find end of keyname */
- for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++);
+ if (*s == '\"') {
+ s++;
+ for (t = s; *t != '\0' && *t != '\"'; t++);
+ if (*t == '\"') *t = ' ';
+ } else {
+ for (t = s; *t != '\0' && *t != '=' && *t != '\t' && *t != ' '; t++);
+ }
/* it's an item in an existing group */
item = ini_item_alloc(group, s, t-s);
@@ -349,11 +355,18 @@ static bool ini_save(const char *filename, IniFile *ini)
assert(item->value != NULL);
if (item->comment != NULL) fputs(item->comment, f);
+ /* protect item->name with quotes if needed */
+ if (strchr(item->name, ' ') != NULL) {
+ fprintf(f, "\"%s\"", item->name);
+ } else {
+ fprintf(f, "%s", item->name);
+ }
+
/* Don't give an equal sign to list items that don't have a parameter */
if (group->type == IGT_LIST && *item->value == '\0') {
- fprintf(f, "%s\n", item->name);
+ fprintf(f, "\n");
} else {
- fprintf(f, "%s = %s\n", item->name, item->value);
+ fprintf(f, " = %s\n", item->value);
}
}
}