(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".
authordominik
Sat, 18 Dec 2004 16:00:10 +0000
changeset 705 e213445d82ec
parent 704 a526dc96fbfc
child 706 841f24d374ed
(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".
settings.c
settings.h
--- a/settings.c	Sat Dec 18 14:19:21 2004 +0000
+++ b/settings.c	Sat Dec 18 16:00:10 2004 +0000
@@ -93,6 +93,7 @@
 	IniItem *item, **last_item;
 	IniGroup *next;
 	IniFile *ini;
+	IniGroupType type; // type of group
 };
 
 struct IniFile {
@@ -121,6 +122,10 @@
 	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 @@
 				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 @@
 		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 @@
 	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;
 	}
 }
 
--- a/settings.h	Sat Dec 18 14:19:21 2004 +0000
+++ b/settings.h	Sat Dec 18 16:00:10 2004 +0000
@@ -28,6 +28,11 @@
 	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 {
 	const char *name;
 	int flags;