(dflt_econfig): New.

(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.
This commit is contained in:
Markus Armbruster 2005-03-09 17:11:58 +00:00
parent 12518b82dd
commit 1583d0c6a2
7 changed files with 23 additions and 32 deletions

View file

@ -37,6 +37,9 @@
#include "nsc.h" #include "nsc.h"
/* Default econfig file */
extern char dflt_econfig[];
struct option_list { struct option_list {
char *opt_key; char *opt_key;
int *opt_valuep; int *opt_valuep;

View file

@ -88,9 +88,13 @@ emp_config(char *file)
int errors = 0; int errors = 0;
int i; int i;
if (file == NULL) { if (!file) {
fixup_files(); if (!*dflt_econfig) {
return 0; /* No default econfig, use compiled in configuration */
fixup_files();
return 0;
}
file = dflt_econfig;
} }
if ((fp = fopen(file, "r")) == NULL) { if ((fp = fopen(file, "r")) == NULL) {
fprintf(stderr, "Can't open %s for reading (%s)\n", fprintf(stderr, "Can't open %s for reading (%s)\n",

View file

@ -33,7 +33,8 @@
*/ */
#include "gamesdef.h" #include "gamesdef.h"
#include "misc.h"
char dflt_econfig[] = EMPDIR "/data/econfig";
char *infodir = EMPDIR "/info.nr"; char *infodir = EMPDIR "/info.nr";
char *datadir = EMPDIR "/data"; char *datadir = EMPDIR "/data";

View file

@ -33,10 +33,6 @@
* Doug Hay, 1998 * Doug Hay, 1998
*/ */
#if defined(aix) || defined(linux)
#include <unistd.h>
#endif /* aix or linux */
#include <signal.h> #include <signal.h>
#if !defined(_WIN32) #if !defined(_WIN32)
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -189,11 +185,8 @@ main(int argc, char **argv)
return remove_service(service_name); return remove_service(service_name);
#endif /* _WIN32 */ #endif /* _WIN32 */
if (config_file == NULL) { if (emp_config(config_file) < 0)
sprintf(tbuf, "%s/econfig", datadir); exit(EXIT_FAILURE);
config_file = tbuf;
}
emp_config(config_file);
#if defined(_WIN32) #if defined(_WIN32)
if (install_service_set) if (install_service_set)

View file

@ -191,7 +191,6 @@ main(int argc, char *argv[])
{ {
int opt; int opt;
char *config_file = NULL; char *config_file = NULL;
char tbuf[512];
int i = 0; int i = 0;
rnd_seed = time(NULL); rnd_seed = time(NULL);
@ -222,11 +221,8 @@ main(int argc, char *argv[])
} }
} }
srandom(rnd_seed); srandom(rnd_seed);
if (config_file == NULL) { if (emp_config(config_file))
sprintf(tbuf, "%s/econfig", datadir); exit(1);
config_file = tbuf;
}
emp_config(config_file);
parse_args(argc - optind, argv + optind); parse_args(argc - optind, argv + optind);
if (allocate_memory() == -1) if (allocate_memory() == -1)

View file

@ -77,7 +77,6 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
s_char buf[255]; s_char buf[255];
s_char tbuf[512];
s_char *filename; s_char *filename;
int x, y; int x, y;
struct natstr nat; struct natstr nat;
@ -102,12 +101,9 @@ main(int argc, char *argv[])
} }
} }
/* Try to use the existing data directory */ if (emp_config(config_file) < 0)
if (config_file == NULL) { exit(1);
sprintf(tbuf, "%s/econfig", datadir);
config_file = tbuf;
}
emp_config(config_file);
empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2; empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2;
empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2; empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;

View file

@ -31,18 +31,16 @@
* Julian Onions * Julian Onions
*/ */
#include <gamesdef.h>
#include <stdio.h> #include <stdio.h>
#include "optlist.h"
#include "prototypes.h" #include "prototypes.h"
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
if (argc > 1) *dflt_econfig = 0; /* don't read default econfig */
emp_config(argv[1]); if (emp_config(argc > 1 ? argv[1] : NULL) < 0)
else exit(1);
emp_config(NULL);
print_config(stdout); print_config(stdout);
exit(0); exit(0);
} }