From 9a30f30107a16202c16672f0c3e67684130c284a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 19 Feb 2006 07:04:30 +0000 Subject: [PATCH] (builtindir): New econfig key, variable and make variable. (subst.in): Substitute it. Fix prerequisites. (read_builtin_tables): New. (main): Call it. This doesn't do anything, because no builtin tables have been defined. --- Make.mk | 9 ++++++--- include/econfig-spec.h | 4 ++++ include/prototypes.h | 1 + src/lib/common/conftab.c | 29 +++++++++++++++++++++++++++++ src/lib/global/path.c.in | 3 +++ src/server/main.c | 6 ++++++ 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Make.mk b/Make.mk index 5576e47c..2a91357b 100644 --- a/Make.mk +++ b/Make.mk @@ -66,6 +66,7 @@ depcomp = $(SHELL) $(srcdir)/depcomp tarball = $(SHELL) $(scripts)/tarball econfig := $(sysconfdir)/empire/econfig gamedir := $(localstatedir)/empire +builtindir := $(datadir)/empire/builtin einfodir := $(datadir)/empire/info.nr ehtmldir := $(datadir)/empire/info.html @@ -73,9 +74,10 @@ ehtmldir := $(datadir)/empire/info.html # Recursively expanded so that $@ and $< work. subst.in = sed \ -e 's?@configure_input\@?$(notdir $@). Generated from $(notdir $<) by GNUmakefile.?g' \ + -e 's?@builtindir\@?$(builtindir)?g' \ -e 's?@econfig\@?$(econfig)?g' \ - -e 's?@gamedir\@?$(gamedir)?g' \ -e 's?@einfodir\@?$(einfodir)?g' \ + -e 's?@gamedir\@?$(gamedir)?g' \ -e 's/@EMPIREHOST\@/$(EMPIREHOST)/g' \ -e 's/@EMPIREPORT\@/$(EMPIREPORT)/g' @@ -291,7 +293,8 @@ sources.mk: $(srcdir)/sources.mk cp -f $^ $@ endif -# +# Distributing + .PHONY: dist-source dist-source: $(src_distgen) $(bld_distgen) $(tarball) $(TARNAME)-$(VERSION) $(bld_distgen) -C $(srcdir) $(src_distgen) $(src) @@ -342,7 +345,7 @@ GNUmakefile: GNUmakefile.in config.status config.status: configure ./config.status --recheck -src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile +src/lib/global/path.c src/client/ipglob.c: %: %.in GNUmakefile Make.mk $(subst.in) <$< >$@ diff --git a/include/econfig-spec.h b/include/econfig-spec.h index c9ce1c08..63bbaa5c 100644 --- a/include/econfig-spec.h +++ b/include/econfig-spec.h @@ -73,6 +73,10 @@ EMPCFBOTH("data", gamedir, char *, NSC_STRING, KM_INTERNAL, "Directory where this game's data is stored") EMPCFBOTH("info", infodir, char *, NSC_STRING, KM_INTERNAL, "Directory where info pages are stored, can be shared among games") +EMPCFBOTH("builtin", builtindir, char *, NSC_STRING, KM_INTERNAL, + "Directory where builtin files are stored") +EMPCF_COMMENT("# Set this to your source tree's src/lib/global to run the server\n" + "# without installing it, else leave it alone.") EMPCFBOTH("listen_addr", listen_addr, char *, NSC_STRING, KM_INTERNAL, "Local IP address the server should listen on. \"\" listens on all.") EMPCFBOTH("port", loginport, char *, NSC_STRING, KM_INTERNAL, diff --git a/include/prototypes.h b/include/prototypes.h index f936b040..7a5bf818 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -284,6 +284,7 @@ extern int check_comm_ok(struct comstr *); extern int check_loan_ok(struct lonstr *); extern int check_trade_ok(struct trdstr *); /* conftab.c */ +extern int read_builtin_tables(void); extern int read_config_tables(void); /* ef_verify.c */ /* in file.h */ diff --git a/src/lib/common/conftab.c b/src/lib/common/conftab.c index 813d5a30..9339bc77 100644 --- a/src/lib/common/conftab.c +++ b/src/lib/common/conftab.c @@ -44,6 +44,35 @@ static int read_config_table_file(char *); +int +read_builtin_tables(void) +{ + struct empfile *ep; + FILE *fp; + int res; + + for (ep = empfile; ep->name; ep++) { + if (!EF_IS_GAME_STATE(ep->uid) && ep->file) { + if ((fp = fopen(ep->file, "r")) == NULL) { + fprintf(stderr, "Can't open %s for reading (%s)\n", + ep->file, strerror(errno)); + return -1; + } + res = xundump(fp, ep->name, ep->uid); + if (res >= 0 && getc(fp) != EOF) { + fprintf(stderr, "%s: Junk after the table\n", + ep->file); + res = EF_BAD; + } + fclose(fp); + if (res < 0) + return -1; + } + } + + return 0; +} + /* * Read user configuration tables. * Return 0 on success, -1 on failure. diff --git a/src/lib/global/path.c.in b/src/lib/global/path.c.in index d13395ba..33781811 100644 --- a/src/lib/global/path.c.in +++ b/src/lib/global/path.c.in @@ -46,6 +46,9 @@ char *configdir; /* User configuration tables to load, relative to configdir */ char *config_tables = ""; +/* Where to find built-in configuration tables */ +char *builtindir = "@builtindir@"; + /* Where to find info pages */ char *infodir = "@einfodir@"; diff --git a/src/server/main.c b/src/server/main.c index 4c10614d..8f71d3d6 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -203,6 +203,12 @@ main(int argc, char **argv) if (emp_config(config_file) < 0) exit(EXIT_FAILURE); ef_init(); + if (chdir(builtindir)) { + fprintf(stderr, "Can't chdir to %s (%s)\n", builtindir, strerror(errno)); + exit(EXIT_FAILURE); + } + if (read_builtin_tables() < 0) + exit(EXIT_FAILURE); if (chdir(configdir)) { fprintf(stderr, "Can't chdir to %s (%s)\n", configdir, strerror(errno)); exit(EXIT_FAILURE);