summaryrefslogtreecommitdiff
path: root/settings.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-18 16:00:10 +0000
committerdominik <dominik@openttd.org>2004-12-18 16:00:10 +0000
commit74a0d26d0ec77d9861daab5233e231de47f154f8 (patch)
tree4e7895f4c3392096e2351852fb14ade12f0061f4 /settings.c
parent17a613546cfce5f963d47575f6847830f40cd053 (diff)
downloadopenttd-74a0d26d0ec77d9861daab5233e231de47f154f8.tar.xz
(svn r1157) Enhanced the config file (openttd.cfg) to use another section type. "List sections" as opposed to "variable sections" contain a list of values, separated by a new line. This is now used for the [newgrf] group. You have to edit each line in this section from e.g. "0 = firstset.grf" to only "firstset.grf".
Diffstat (limited to 'settings.c')
-rw-r--r--settings.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/settings.c b/settings.c
index 2b6ffe644..fa1c7d69d 100644
--- a/settings.c
+++ b/settings.c
@@ -93,6 +93,7 @@ struct IniGroup {
IniItem *item, **last_item;
IniGroup *next;
IniFile *ini;
+ IniGroupType type; // type of group
};
struct IniFile {
@@ -121,6 +122,10 @@ static IniGroup *ini_group_alloc(IniFile *ini, const char *grpt, int len)
IniGroup *grp = pool_alloc(&ini->pool, sizeof(IniGroup));
grp->ini = ini;
grp->name = pool_strdup(&ini->pool, grpt, len);
+ if(!strcmp(grp->name, "newgrf"))
+ grp->type = IGT_LIST;
+ else
+ grp->type = IGT_VARIABLES;
grp->next = NULL;
grp->item = NULL;
grp->comment = NULL;
@@ -212,6 +217,12 @@ static IniFile *ini_load(const char *filename)
comment_size = 0;
}
+ // for list items, the name and value are the same:
+ if( group->type == IGT_LIST ) {
+ item->value = item->name;
+ continue;
+ }
+
// find start of parameter
while (*t == '=' || *t == ' ' || *t == '\t') t++;
item->value = pool_strdup(&ini->pool, t, e - t);
@@ -282,7 +293,10 @@ static bool ini_save(const char *filename, IniFile *ini)
fprintf(f, "[%s]\n", group->name);
for(item = group->item; item; item = item->next) {
if (item->comment) fputs(item->comment, f);
- fprintf(f, "%s = %s\n", item->name, item->value ? item->value : "");
+ if(group->type==IGT_LIST)
+ fprintf(f, "%s\n", item->value ? item->value : "");
+ else
+ fprintf(f, "%s = %s\n", item->name, item->value ? item->value : "");
}
}
if (ini->comment) fputs(ini->comment, f);
@@ -901,13 +915,12 @@ static void LoadGrfSettings(IniFile *ini)
if (!group)
return;
+ item = group->item;
for(i=0; i!=lengthof(_newgrf_files); i++) {
- char buf[3];
- sprintf(buf, "%d", i);
- item = ini_getitem(group, buf, false);
if (!item)
break;
_newgrf_files[i] = strdup(item->value);
+ item = item->next;
}
}