]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/xundump.c
Update copyright notice
[empserver] / src / lib / common / xundump.c
index ff551d9840d3fc66e6f279696b9318b34c89405b..82e08b9b43e8dd02e9f7097f410881d1d7f9841d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2014
+ *     Markus Armbruster, 2005-2016
  */
 
 /*
@@ -58,7 +58,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "file.h"
 #include "match.h"
 #include "nat.h"
 #include "nsc.h"
@@ -122,7 +121,7 @@ ca0_is_id(int type)
 {
     struct castr *ca = ef_cadef(type);
 
-    return ca[0].ca_table == type && !(ca[0].ca_flags & NSC_EXTRA);
+    return ca[0].ca_table == type && ca[0].ca_dump <= CA_DUMP_CONST;
 }
 
 /*
@@ -136,7 +135,7 @@ can_fill_gaps(int type)
 }
 
 /*
- * Is table @type's @id-th record @obj redundant for xundump()
+ * Is table @type's @id-th record @obj redundant for xundump()?
  */
 int
 xundump_redundant(int type, int id, void *obj)
@@ -173,7 +172,7 @@ gripe(char *fmt, ...)
     return -1;
 }
 
-/* Make TYPE the current table.  */
+/* Make TYPE the current table. */
 static void
 tbl_start(int type)
 {
@@ -185,7 +184,7 @@ tbl_start(int type)
     idgap_len = 0;
 }
 
-/* End the current table.  */
+/* End the current table. */
 static void
 tbl_end(void)
 {
@@ -196,7 +195,7 @@ tbl_end(void)
 /*
  * Seek to current table's @id-th object.
  * Extend the table if necessary.
- * Save @id in cur_id.
+ * Save @id in @cur_id.
  * Return the object on success, NULL on failure.
  */
 static void *
@@ -451,7 +450,7 @@ rowid_realm(void)
 /*
  * Get the current row's object.
  * Extend the table if necessary.
- * Save ID in cur_id.
+ * Save ID in @cur_id.
  * Return the object on success, NULL on failure.
  */
 static void *
@@ -506,7 +505,7 @@ fldval_must_match(int fldno)
      * it's for a const selector, unless the object is still blank, or
      * it was already given in a previous part of a split table.
      */
-    return (cur_id < old_nelem && (fldca[fldno]->ca_flags & NSC_CONST))
+    return (cur_id < old_nelem && (fldca[fldno]->ca_dump == CA_DUMP_CONST))
        || fldidx[fldno] < cafldspp[i];
 }
 
@@ -933,7 +932,7 @@ deffld(int fldno, char *name, int idx)
        return gripe("%s header '%s' in field %d",
                     res == M_NOTUNIQUE ? "ambiguous" : "unknown",
                     name, fldno + 1);
-    if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
+    if (ca[res].ca_dump > CA_DUMP_CONST || CANT_HAPPEN(ca[res].ca_get))
        return gripe("extraneous header '%s' in field %d", name, fldno + 1);
     if (CA_IS_ARRAY(&ca[res])) {
        if (idx < 0)
@@ -976,7 +975,7 @@ chkflds(void)
     /* Check for missing fields */
     for (i = 0; ca[i].ca_name; i++) {
        cafldsmax = MAX(caflds[i], cafldspp[i]);
-       if (ca[i].ca_flags & NSC_EXTRA)
+       if (ca[i].ca_dump > CA_DUMP_CONST)
            continue;
        len = CA_ARRAY_LEN(&ca[i]);
        if (!len && !cafldsmax)
@@ -1156,8 +1155,7 @@ xuheader(FILE *fp, int expected_table)
        return gripe("expected table '%s', not '%s'",
                     ef_nameof(expected_table), name);
 
-    if (!empfile[type].file
-       || !ef_cadef(type) || !(ef_flags(type) & EFF_MEM)) {
+    if (!xundumpable(type)) {
        CANT_HAPPEN(expected_table != EF_BAD);
        return gripe("table '%s' is not permitted here", name);
     }
@@ -1169,6 +1167,16 @@ xuheader(FILE *fp, int expected_table)
     return type;
 }
 
+/*
+ * Can table @type be xundumped?
+ */
+int
+xundumpable(int type)
+{
+    return empfile[type].file && ef_cadef(type)
+       && (ef_flags(type) & EFF_MEM);
+}
+
 /*
  * Find fields in this xdump.
  * If reading human-readable syntax, read a field header line from @fp.
@@ -1198,7 +1206,7 @@ xufldhdr(FILE *fp, struct castr ca[])
        fidx = fldidx;
 
        for (i = 0; ca[i].ca_name; i++) {
-           if ((ca[i].ca_flags & NSC_EXTRA))
+           if (ca[i].ca_dump > CA_DUMP_CONST)
                continue;
            n = CA_ARRAY_LEN(&ca[i]);
            j = 0;
@@ -1278,7 +1286,7 @@ xundump(FILE *fp, char *file, int *plno, int expected_table)
     nca = nf = 0;
     for (i = 0; ca[i].ca_name; i++) {
        nca++;
-       if (!(ca[i].ca_flags & NSC_EXTRA))
+       if (ca[i].ca_dump <= CA_DUMP_CONST)
            nf += MAX(1, CA_ARRAY_LEN(&ca[i]));
     }
     fldca = malloc(nf * sizeof(*fldca));