(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"
/* Default econfig file */
extern char dflt_econfig[];
struct option_list {
char *opt_key;
int *opt_valuep;

View file

@ -88,10 +88,14 @@ emp_config(char *file)
int errors = 0;
int i;
if (file == NULL) {
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",
file, strerror(errno));

View 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";

View file

@ -33,10 +33,6 @@
* 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)

View 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)

View 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;

View file

@ -31,18 +31,16 @@
* 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);
}