mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(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".
This commit is contained in:
parent
17a613546c
commit
74a0d26d0e
19
settings.c
19
settings.c
@ -93,6 +93,7 @@ struct IniGroup {
|
|||||||
IniItem *item, **last_item;
|
IniItem *item, **last_item;
|
||||||
IniGroup *next;
|
IniGroup *next;
|
||||||
IniFile *ini;
|
IniFile *ini;
|
||||||
|
IniGroupType type; // type of group
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IniFile {
|
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));
|
IniGroup *grp = pool_alloc(&ini->pool, sizeof(IniGroup));
|
||||||
grp->ini = ini;
|
grp->ini = ini;
|
||||||
grp->name = pool_strdup(&ini->pool, grpt, len);
|
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->next = NULL;
|
||||||
grp->item = NULL;
|
grp->item = NULL;
|
||||||
grp->comment = NULL;
|
grp->comment = NULL;
|
||||||
@ -212,6 +217,12 @@ static IniFile *ini_load(const char *filename)
|
|||||||
comment_size = 0;
|
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
|
// find start of parameter
|
||||||
while (*t == '=' || *t == ' ' || *t == '\t') t++;
|
while (*t == '=' || *t == ' ' || *t == '\t') t++;
|
||||||
item->value = pool_strdup(&ini->pool, t, e - t);
|
item->value = pool_strdup(&ini->pool, t, e - t);
|
||||||
@ -282,6 +293,9 @@ static bool ini_save(const char *filename, IniFile *ini)
|
|||||||
fprintf(f, "[%s]\n", group->name);
|
fprintf(f, "[%s]\n", group->name);
|
||||||
for(item = group->item; item; item = item->next) {
|
for(item = group->item; item; item = item->next) {
|
||||||
if (item->comment) fputs(item->comment, f);
|
if (item->comment) fputs(item->comment, f);
|
||||||
|
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 : "");
|
fprintf(f, "%s = %s\n", item->name, item->value ? item->value : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -901,13 +915,12 @@ static void LoadGrfSettings(IniFile *ini)
|
|||||||
if (!group)
|
if (!group)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
item = group->item;
|
||||||
for(i=0; i!=lengthof(_newgrf_files); i++) {
|
for(i=0; i!=lengthof(_newgrf_files); i++) {
|
||||||
char buf[3];
|
|
||||||
sprintf(buf, "%d", i);
|
|
||||||
item = ini_getitem(group, buf, false);
|
|
||||||
if (!item)
|
if (!item)
|
||||||
break;
|
break;
|
||||||
_newgrf_files[i] = strdup(item->value);
|
_newgrf_files[i] = strdup(item->value);
|
||||||
|
item = item->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,11 @@ enum SettingDescType {
|
|||||||
SDT_BOOL = SDT_BOOLX | SDT_UINT8,
|
SDT_BOOL = SDT_BOOLX | SDT_UINT8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
IGT_VARIABLES = 0, // values of the form "landscape = hilly"
|
||||||
|
IGT_LIST = 1, // a list of values, seperated by \n and terminated by the next group block
|
||||||
|
} IniGroupType;
|
||||||
|
|
||||||
typedef struct SettingDesc {
|
typedef struct SettingDesc {
|
||||||
const char *name;
|
const char *name;
|
||||||
int flags;
|
int flags;
|
||||||
|
Loading…
Reference in New Issue
Block a user