]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/conftab.c
Update copyright notice
[empserver] / src / lib / common / conftab.c
index 82c6ba7a66c957638cef702185b3682f0b5a5aa3..629ce694482805283b7467e3ecc70ecd390163b7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  conftab.c: Load game configuration files
- * 
+ *
  *  Known contributors to this file:
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2008
  */
 
 #include <config.h>
 
 #include <errno.h>
 #include <stdio.h>
-#include <time.h>
 #include "file.h"
 #include "optlist.h"
 #include "product.h"
 #include "prototypes.h"
+#include "xdump.h"
 
 static int read_custom_table_file(char *);
 
+/*
+ * Read builtin configuration tables.
+ * Return 0 on success, -1 on failure.
+ */
 int
 read_builtin_tables(void)
 {
     struct empfile *ep;
     FILE *fp;
-    int res;
+    int lineno, res;
 
     /*
      * Need to read config files for tables referenced through
@@ -57,12 +61,13 @@ read_builtin_tables(void)
      */
     for (ep = empfile; ep->name; ep++) {
        if (!EF_IS_GAME_STATE(ep->uid) && ep->file) {
-           if ((fp = fopen(ep->file, "r")) == NULL) {
+           if ((fp = fopenat(ep->file, "r", builtindir)) == NULL) {
                fprintf(stderr, "Can't open %s for reading (%s)\n",
                        ep->file, strerror(errno));
                return -1;
            }
-           res = xundump(fp, ep->file, ep->uid);
+           lineno = 1;
+           res = xundump(fp, ep->file, &lineno, ep->uid);
            if (res >= 0 && getc(fp) != EOF) {
                fprintf(stderr, "%s: Junk after the table\n",
                        ep->file);
@@ -98,22 +103,23 @@ read_custom_tables(void)
 }
 
 /*
- * Read configuaration table file FNAME.
+ * Read configuration table file FNAME.
  * Return 0 on success, -1 on error.
  */
 static int
 read_custom_table_file(char *fname)
 {
-    int res, n;
+    int lineno, res, n;
     FILE *fp;
 
-    if (!(fp = fopen(fname, "r"))) {
+    if (!(fp = fopenat(fname, "r", configdir))) {
        fprintf(stderr, "Can't open config table %s for reading (%s)\n",
                fname, strerror(errno));
        return -1;
     }
 
-    for (n = 0; (res = xundump(fp, fname, EF_BAD)) >= 0; n++)
+    lineno = 1;
+    for (n = 0; (res = xundump(fp, fname, &lineno, EF_BAD)) >= 0; n++)
        empfile[res].flags |= EFF_CUSTOM;
     if (res != EF_BAD && n == 0)
        fprintf(stderr, "Warning: configuration file %s is empty\n", fname);