]> git.pond.sub.org Git - empserver/commitdiff
(empfile, teldir, motdfil, downfil, disablefil, telfil, annfil)
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 9 Mar 2005 18:44:50 +0000 (18:44 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 9 Mar 2005 18:44:50 +0000 (18:44 +0000)
(banfil, authfil, timestampfil): Make file names relative to DATADIR.
(main): emp_server and files change to the data directory.  fairland
has to write newcap_script to the initial current directory, so it
keeps it and makes file names relative to DATADIR absolute.
(fixup_files): Nothing to do, remove.  This fixes the following bug:
fixup_files() formed file names by appending ep->name instead of the
base name of ep->file to datadir.  Thus, fixup_files() changed file
names even when datadir had the compiled-in value.  When emp_config()
couldn't open econfig, it failed to call fixup_files(), and different
file names got used.  Note that with this revision the file names
revert to the names used before fixup_files() was introduced.  Closes
#1146080.
(print_config): Printing file names as comments is not really useful,
remove.
(otherfiles, ofiles): Unused, remove.
(emp_config, main): Previously, pconfig had to call emp_config() even
when it didn't want to read econfig, just to run fixup_files().  This
is no longer necessary.  Simplify.

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

index a74bb6e5b42ffdb9329702113f28f062f8092f06..dec56c7a61da0af0948b16e318c1f111b5b845d3 100644 (file)
@@ -37,8 +37,8 @@
 #include <stddef.h>
 
 struct empfile {
-    char *name;                        /* file name (e.g., "treaty") */
-    char *file;                        /* file path */
+    char *name;                        /* Empire name (e.g., "treaty") */
+    char *file;                        /* file name (relative to data directory) */
     int flags;                 /* misc stuff */
     int mode;                  /* O_flags */
     int size;                  /* size of object */
index da1be7b2da90d8c289ffc48291622421f8a4fe0f..b7c8c2e1133ec4e943e6f4e637d8714f5345f8bb 100644 (file)
@@ -88,14 +88,8 @@ emp_config(char *file)
     int errors = 0;
     int i;
 
-    if (!file) {
-       if (!*dflt_econfig) {
-           /* No default econfig, use compiled in configuration */
-           fixup_files();
-           return 0;
-       }
+    if (!file)
        file = dflt_econfig;
-    }
     if ((fp = fopen(file, "r")) == NULL) {
        fprintf(stderr, "Can't open %s for reading (%s)\n",
                file, strerror(errno));
@@ -163,51 +157,11 @@ emp_config(char *file)
        }
     }
     fclose(fp);
-    fixup_files();
     WORLD_X &= ~1;             /* make even */
 
     return -errors;
 }
 
-struct otherfiles {
-    char **files;
-    char *name;
-};
-
-/* list of other well known files... -maybe tailor these oneday
- * anyway - meantime they are all relative to datadir */
-static struct otherfiles ofiles[] = {
-    {&motdfil, "motd"},
-    {&downfil, "down"},
-    {&disablefil, "disable"},
-    {&banfil, "ban"},
-    {&authfil, "auth"},
-    {&annfil, "ann"},
-    {&timestampfil, "timestamp"},
-    {&teldir, "tel"},
-    {&telfil, "tel/tel"},
-    {NULL, NULL}
-};
-
-/* fix up the empfile struct to reference full path names */
-static void
-fixup_files(void)
-{
-    struct empfile *ep;
-    struct otherfiles *op;
-    s_char buf[1024];
-
-    for (ep = empfile; ep < &empfile[EF_MAX]; ep++) {
-       sprintf(buf, "%s/%s", datadir, ep->name);
-       ep->file = strdup(buf);
-    }
-
-    for (op = ofiles; op->files; op++) {
-       sprintf(buf, "%s/%s", datadir, op->name);
-       *op->files = strdup(buf);
-    }
-}
-
 /* find the key in the table */
 static struct keymatch *
 keylookup(register s_char *command, struct keymatch *tbl)
@@ -226,9 +180,7 @@ keylookup(register s_char *command, struct keymatch *tbl)
 void
 print_config(FILE *fp)
 {
-    struct empfile *ep;
     struct option_list *op;
-    struct otherfiles *ofp;
     struct keymatch *kp;
 
     fprintf(fp, "# Empire Configuration File:\n");
@@ -267,11 +219,6 @@ print_config(FILE *fp)
     }
 
     fprintf(fp, "\n");
-    for (ep = empfile; ep < &empfile[EF_MAX]; ep++)
-       fprintf(fp, "# File %s -> %s\n", ep->name, ep->file);
-    for (ofp = ofiles; ofp->files; ofp++)
-       fprintf(fp, "# File %s -> %s\n", ofp->name, *(ofp->files));
-
 }
 
 
index 30a9a2df15a5bf5c670748776c5b06fb22f51485..051de27cc068660e3163e0f6993443bd6aab8c15 100644 (file)
 #include "commodity.h"
 
 struct empfile empfile[] = {
-    {"sect", EMPDIR "/data/sector", EFF_XY | EFF_OWNER,
+    {"sect", "sector", EFF_XY | EFF_OWNER,
      0, sizeof(struct sctstr), 0, 0, 0, offsetof(struct sctstr, sct_item),
      -1, -1, 0, 0, 0, 0, 0},
-    {"ship", EMPDIR "/data/ship", EFF_XY | EFF_OWNER | EFF_GROUP,
+    {"ship", "ship", EFF_XY | EFF_OWNER | EFF_GROUP,
      0, sizeof(struct shpstr), 0, 0, 0, offsetof(struct shpstr, shp_item),
      -1, -1, 0, 0, 0, 0, 0},
-    {"plane", EMPDIR "/data/plane", EFF_XY | EFF_OWNER | EFF_GROUP,
+    {"plane", "plane", EFF_XY | EFF_OWNER | EFF_GROUP,
      0, sizeof(struct plnstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"land", EMPDIR "/data/land", EFF_XY | EFF_OWNER | EFF_GROUP,
+    {"land", "land", EFF_XY | EFF_OWNER | EFF_GROUP,
      0, sizeof(struct lndstr), 0, 0, 0, offsetof(struct lndstr, lnd_item),
      -1, -1, 0, 0, 0, 0, 0},
-    {"nuke", EMPDIR "/data/nuke", EFF_XY | EFF_OWNER,
+    {"nuke", "nuke", EFF_XY | EFF_OWNER,
      0, sizeof(struct nukstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"news", EMPDIR "/data/news", 0,
+    {"news", "news", 0,
      0, sizeof(struct nwsstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"treaty", EMPDIR "/data/treaty", 0,
+    {"treaty", "treaty", 0,
      0, sizeof(struct trtstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"trade", EMPDIR "/data/trade", 0,
+    {"trade", "trade", 0,
      0, sizeof(struct trdstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"pow", EMPDIR "/data/power", 0,
+    {"pow", "power", 0,
      0, sizeof(struct powstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"nat", EMPDIR "/data/nation", 0,
+    {"nat", "nation", 0,
      0, sizeof(struct natstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"loan", EMPDIR "/data/loan", 0,
+    {"loan", "loan", 0,
      0, sizeof(struct lonstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"map", EMPDIR "/data/map", 0,
+    {"map", "map", 0,
      0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"bmap", EMPDIR "/data/bmap", 0,
+    {"bmap", "bmap", 0,
      0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"commodity", EMPDIR "/data/commodity", 0,
+    {"commodity", "commodity", 0,
      0, sizeof(struct comstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"lost", EMPDIR "/data/lostitems", 0, 0,
+    {"lost", "lostitems", 0, 0,
      sizeof(struct loststr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0}
 };
index a52d21d3c3646f07ba135ed79c6147a499578deb..ed0e52b6df169f2b05acfb99b54a3f234e4f5bc7 100644 (file)
@@ -38,15 +38,16 @@ char dflt_econfig[] = EMPDIR "/data/econfig";
 
 char *infodir  = EMPDIR "/info.nr";
 char *datadir  = EMPDIR "/data";
-char *teldir   = EMPDIR "/data/tel";
 
-char *motdfil  = EMPDIR "/data/motd";
-char *downfil  = EMPDIR "/data/down";
-char *disablefil = EMPDIR "/data/disable";
-char *telfil   = EMPDIR "/data/tel/tel";
-char *annfil   = EMPDIR "/data/ann";
-char *banfil   = EMPDIR "/data/ban";
-char *authfil  = EMPDIR "/data/auth";
-char *timestampfil = EMPDIR "/data/timestamp";
+/* relative to DATADIR */
+char *teldir   = "tel";
+char *motdfil  = "motd";
+char *downfil  = "down";
+char *disablefil = "disable";
+char *telfil   = "tel/tel";
+char *annfil   = "ann";
+char *banfil   = "ban";
+char *authfil  = "auth";
+char *timestampfil = "timestamp";
 
 char *loginport = EMP_PORT;
index 837707c7260fd3ab70f400a0a372efdc773ed449..69db0c589aec2316874760a843b3750de8064f09 100644 (file)
@@ -37,6 +37,7 @@
 #if !defined(_WIN32)
 #include <sys/ioctl.h>
 #endif
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
@@ -187,6 +188,10 @@ main(int argc, char **argv)
 
     if (emp_config(config_file) < 0)
        exit(EXIT_FAILURE);
+    if (chdir(datadir)) {
+       fprintf(stderr, "Can't chdir to %s (%s)\n", datadir, strerror(errno));
+       exit(EXIT_FAILURE);
+    }
 
 #if defined(_WIN32)
     if (install_service_set)
index e03da7fbd34a101dfe5b257b7eead4516b2408d1..94e3d19112e21a9f30d75f99573ede406f558b53 100644 (file)
@@ -64,13 +64,11 @@ static int quiet = 0;
 /* lower URAN_MIN for more uranium */
 #define URAN_MIN   56
 
-#if defined(aix) || defined(linux) || defined(solaris)
-#include <unistd.h>
-#endif /* aix or linux */
 #if defined(_WIN32)
 #include "../lib/gen/getopt.h"
 #endif
 
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -402,12 +400,16 @@ static int
 allocate_memory(void)
 {
     int i;
+    char *fname;
 
-    sect_fptr = fopen(empfile[EF_SECTOR].file, "wb");
+    fname = malloc(strlen(datadir) + 1 + strlen(empfile[EF_SECTOR].file) + 1);
+    sprintf(fname, "%s/%s", datadir, empfile[EF_SECTOR].file);
+    sect_fptr = fopen(fname, "wb");
     if (sect_fptr == NULL) {
-       perror(empfile[EF_SECTOR].file);
+       perror(fname);
        return -1;
     }
+    free(fname);
     sectsbuf =
        (struct sctstr *)calloc((YSIZE * XSIZE), sizeof(struct sctstr));
     sects = (struct sctstr **)calloc(YSIZE, sizeof(struct sctstr *));
index 82e42d8b2dc0eb3f5b0186370b8f2e702dea6b32..ceeac41d789e3356ba7862458f7ec24cc266c71c 100644 (file)
  *     Steve McClure, 1998
  */
 
-#if defined(aix) || defined(linux) || defined(solaris)
-#include <unistd.h>
-#endif /* aix or linux */
-
 #include <sys/types.h>
 #include <fcntl.h>
 #if !defined(_WIN32)
@@ -46,6 +42,7 @@
 #include <direct.h>
 #include "../lib/gen/getopt.h"
 #endif
+#include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -112,6 +109,11 @@ main(int argc, char *argv[])
        printf("Can't make game directory\n");
        exit(1);
     }
+    if (chdir(datadir)) {
+       fprintf(stderr, "Can't chdir to %s (%s)\n", datadir, strerror(errno));
+       exit(EXIT_FAILURE);
+    }
+
     if (!force) {
        printf("WARNING: this blasts the existing game in %s (if any)\n",
           datadir);
index e9fcb0e25238e60884568f60c23ccb07107aa9a3..d4db5fdd7087cb4d6283ce5134727e9e74ead645 100644 (file)
@@ -38,9 +38,9 @@
 int
 main(int argc, char **argv)
 {
-    *dflt_econfig = 0;         /* don't read default econfig */
-    if (emp_config(argc > 1 ? argv[1] : NULL) < 0)
-       exit(1);
+    if (argc > 1)
+       if (emp_config(argv[1]) < 0)
+           exit(1);
     print_config(stdout);
     exit(0);
 }