]> git.pond.sub.org Git - empserver/commitdiff
(dflt_econfig): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 9 Mar 2005 17:11:58 +0000 (17:11 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 9 Mar 2005 17:11:58 +0000 (17:11 +0000)
(emp_config): Use it when argument is NULL.  This simplifies callers
except pconfig's main(), which now has to suppress reading the default
file.  Also fix callers to check the return value.  Previously, a typo
could easily start a grossly misconfigured program, with potentially
disastrous results.

include/optlist.h
src/lib/gen/emp_config.c
src/lib/global/path.c
src/server/main.c
src/util/fairland.c
src/util/files.c
src/util/pconfig.c

index 96bead32ebc1485d73d749e61bc8324e28f8ee12..74bd6939c315e716f6ea75b77b389c07466cf25f 100644 (file)
@@ -37,6 +37,9 @@
 
 #include "nsc.h"
 
+/* Default econfig file */
+extern char dflt_econfig[];
+
 struct option_list {
     char *opt_key;
     int *opt_valuep;
index 4def08f38181c6a99d29139d21294ba401e041cb..da1be7b2da90d8c289ffc48291622421f8a4fe0f 100644 (file)
@@ -88,9 +88,13 @@ emp_config(char *file)
     int errors = 0;
     int i;
 
-    if (file == NULL) {
-       fixup_files();
-       return 0;
+    if (!file) {
+       if (!*dflt_econfig) {
+           /* No default econfig, use compiled in configuration */
+           fixup_files();
+           return 0;
+       }
+       file = dflt_econfig;
     }
     if ((fp = fopen(file, "r")) == NULL) {
        fprintf(stderr, "Can't open %s for reading (%s)\n",
index cf2e515dc711e1420738cff695ae2e6734fefa0c..a52d21d3c3646f07ba135ed79c6147a499578deb 100644 (file)
@@ -33,7 +33,8 @@
  */
 
 #include "gamesdef.h"
-#include "misc.h"
+
+char dflt_econfig[] = EMPDIR "/data/econfig";
 
 char *infodir  = EMPDIR "/info.nr";
 char *datadir  = EMPDIR "/data";
index 1e6bc7050f392212444284c19fb8ff7f586b24ef..837707c7260fd3ab70f400a0a372efdc773ed449 100644 (file)
  *     Doug Hay, 1998
  */
 
-#if defined(aix) || defined(linux)
-#include <unistd.h>
-#endif /* aix or linux */
-
 #include <signal.h>
 #if !defined(_WIN32)
 #include <sys/ioctl.h>
@@ -189,11 +185,8 @@ main(int argc, char **argv)
         return remove_service(service_name);
 #endif /* _WIN32 */
 
-    if (config_file == NULL) {
-       sprintf(tbuf, "%s/econfig", datadir);
-       config_file = tbuf;
-    }
-    emp_config(config_file);
+    if (emp_config(config_file) < 0)
+       exit(EXIT_FAILURE);
 
 #if defined(_WIN32)
     if (install_service_set)
index 72faccbac7a8101c61e443548760a9c1242a41af..e03da7fbd34a101dfe5b257b7eead4516b2408d1 100644 (file)
@@ -191,7 +191,6 @@ main(int argc, char *argv[])
 {
     int opt;
     char *config_file = NULL;
-    char tbuf[512];
     int i = 0;
 
     rnd_seed = time(NULL);
@@ -222,11 +221,8 @@ main(int argc, char *argv[])
        }
     }
     srandom(rnd_seed);
-    if (config_file == NULL) {
-       sprintf(tbuf, "%s/econfig", datadir);
-       config_file = tbuf;
-    }
-    emp_config(config_file);
+    if (emp_config(config_file))
+       exit(1);
 
     parse_args(argc - optind, argv + optind);
     if (allocate_memory() == -1)
index 6acee2fba9eacfcf6d89c04d4001b1e3d79cf4a9..82e42d8b2dc0eb3f5b0186370b8f2e702dea6b32 100644 (file)
@@ -77,7 +77,6 @@ int
 main(int argc, char *argv[])
 {
     s_char buf[255];
-    s_char tbuf[512];
     s_char *filename;
     int x, y;
     struct natstr nat;
@@ -102,12 +101,9 @@ main(int argc, char *argv[])
        }
     }
 
-    /* Try to use the existing data directory */
-    if (config_file == NULL) {
-       sprintf(tbuf, "%s/econfig", datadir);
-       config_file = tbuf;
-    }
-    emp_config(config_file);
+    if (emp_config(config_file) < 0)
+       exit(1);
+
     empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2;
     empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;
 
index f8009817e8fc970190bb73b03fbd79563eda6edc..e9fcb0e25238e60884568f60c23ccb07107aa9a3 100644 (file)
  *     Julian Onions
  */
 
-#include <gamesdef.h>
 #include <stdio.h>
+#include "optlist.h"
 #include "prototypes.h"
 
 int
 main(int argc, char **argv)
 {
-    if (argc > 1)
-       emp_config(argv[1]);
-    else
-       emp_config(NULL);
-
+    *dflt_econfig = 0;         /* don't read default econfig */
+    if (emp_config(argc > 1 ? argv[1] : NULL) < 0)
+       exit(1);
     print_config(stdout);
     exit(0);
 }