(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
authorDarkvater
Thu, 10 Mar 2005 21:44:17 +0000
changeset 1482 46a8146adecf
parent 1481 940e7ce8116f
child 1483 0e6f39e00daf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
- Feature (small): new command-line option -c <config_file>. You can have OpenTTD load alternative config files with this setup, handy for servers, or for saves from other players if you don't want to rename your own config. This will have to do until all game-related settings are saved ingame. Couldn't find the SF patch, so credits to the guy that wrote it.
os2.c
ttd.c
unix.c
win32.c
--- a/os2.c	Thu Mar 10 16:09:51 2005 +0000
+++ b/os2.c	Thu Mar 10 21:44:17 2005 +0000
@@ -582,7 +582,9 @@
 	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
 	_path.gm_dir = str_fmt("%sgm\\", _path.game_data_dir);
 	_path.data_dir = str_fmt("%sdata\\", _path.game_data_dir);
-	_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+
+	if (_config_file == NULL)
+		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
 
 #if defined CUSTOM_LANG_DIR
 	// sets the search path for lng files to the custom one
--- a/ttd.c	Thu Mar 10 16:09:51 2005 +0000
+++ b/ttd.c	Thu Mar 10 21:44:17 2005 +0000
@@ -302,7 +302,8 @@
 		"  -f                  = Fork into the background (dedicated only)\n"
 		#endif
 		"  -i                  = Force to use the DOS palette (use this if you see a lot of pink)\n"
-		"  -p #player          = Player as #player (deprecated) (network only)\n",
+		"  -p #player          = Player as #player (deprecated) (network only)\n"
+		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n",
 		lastof(buf)
 	);
 
@@ -451,6 +452,8 @@
 {
 	UnInitWindowSystem();
 	UnInitNewgrEngines();
+
+	free(_config_file);
 }
 
 static void LoadIntroGame(void)
@@ -509,15 +512,16 @@
 	_switch_mode_errorstr = INVALID_STRING_ID;
 	_dedicated_forks = false;
 	dedicated = false;
+	_config_file = NULL;
 
 	// The last param of the following function means this:
 	//   a letter means: it accepts that param (e.g.: -h)
 	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
 	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
 	#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
-		optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:";
+		optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:c:";
 	#else
-		optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:"; // no fork option
+		optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:c:"; // no fork option
 	#endif
 
 	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
@@ -575,6 +579,9 @@
 			if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i;
 			break;
 		}
+		case 'c':
+			_config_file = strdup(mgo.opt);
+			break;
 		case -2:
  		case 'h':
 			showhelp();
--- a/unix.c	Thu Mar 10 16:09:51 2005 +0000
+++ b/unix.c	Thu Mar 10 21:44:17 2005 +0000
@@ -515,7 +515,10 @@
 	_path.scenario_dir = str_fmt("%sscenario", _path.personal_dir);
 	_path.gm_dir = str_fmt("%sgm/", _path.game_data_dir);
 	_path.data_dir = str_fmt("%sdata/", _path.game_data_dir);
-	_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+
+	if (_config_file == NULL)
+		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+
 	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
 	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);
 
--- a/win32.c	Thu Mar 10 16:09:51 2005 +0000
+++ b/win32.c	Thu Mar 10 21:44:17 2005 +0000
@@ -2131,7 +2131,9 @@
 	_path.data_dir = str_fmt("%sdata\\", cfg);
 	_path.lang_dir = str_fmt("%slang\\", cfg);
 
-	_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+	if (_config_file == NULL)
+		_config_file = str_fmt("%sopenttd.cfg", _path.personal_dir);
+
 	_highscore_file = str_fmt("%shs.dat", _path.personal_dir);
 	_log_file = str_fmt("%sopenttd.log", _path.personal_dir);