]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/xundump.c
Clean up maintenance of config table sentinels
[empserver] / src / lib / common / xundump.c
index d1d6f7e8178fd756a3afe39fa64acbfceb26dfb3..abef9c27e664d1a6b73198938a3d44de72e2c9e8 100644 (file)
@@ -29,7 +29,7 @@
  * 
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2007
+ *     Markus Armbruster, 2005-2008
  */
 
 /*
@@ -47,6 +47,7 @@
  * - Check each partial table supplies the same rows
  * - Check EFF_CFG tables are dense
  * - Symbolic array indexes
+ * - Option to treat missing and unknown fields as warning, not error
  * TODO, but hardly worth the effort:
  * - Permit reordering of array elements
  */
@@ -352,7 +353,7 @@ deffld(int fldno, char *name, int idx)
     if (res < 0)
        return gripe("Header %s of field %d is %s", name, fldno + 1,
                     res == M_NOTUNIQUE ? "ambiguous" : "unknown");
-    if (ca[res].ca_flags == NSC_EXTRA)
+    if (ca[res].ca_flags == NSC_EXTRA || CANT_HAPPEN(ca[res].ca_get))
        return gripe("Extraneous header %s in field %d", name, fldno + 1);
     if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
        if (idx < 0)
@@ -481,17 +482,16 @@ static void *
 getobj(void)
 {
     struct empfile *ep = &empfile[cur_type];
-    int need_sentinel = !EF_IS_GAME_STATE(cur_type);
 
     if (!cur_obj) {
-       cur_obj_is_blank = cur_id >= ep->fids - !!need_sentinel;
+       cur_obj_is_blank = cur_id >= ep->fids;
        if (cur_obj_is_blank) {
-           if (ef_ensure_space(cur_type, cur_id + !!need_sentinel, 1))
+           if (ef_ensure_space(cur_type, cur_id, 1))
                cur_obj = ef_ptr(cur_type, cur_id);
            /* FIXME diagnose out of dynamic memory vs. static table full */
            if (!cur_obj)
                gripe("Can't put ID %d into table %s, it holds only 0..%d.",
-                     cur_id, ep->name, ep->fids - !!need_sentinel - 1);
+                     cur_id, ep->name, ep->fids - 1);
        } else
            cur_obj = ef_ptr(cur_type, cur_id);
     }
@@ -961,13 +961,8 @@ static int
 xubody(FILE *fp)
 {
     struct empfile *ep = &empfile[cur_type];
-    int need_sentinel = !EF_IS_GAME_STATE(cur_type);
-    int old_maxid = ep->fids;
     int i, maxid, ch;
 
-    if (old_maxid == 0 && need_sentinel)
-       ef_ensure_space(cur_type, 0, 1);
-
     maxid = 0;
     for (i = 0;; ++i) {
        while ((ch = skipfs(fp)) == '\n')
@@ -982,12 +977,6 @@ xubody(FILE *fp)
        maxid = MAX(maxid, cur_id + 1);
     }
 
-    if (maxid >= old_maxid && need_sentinel) {
-       /* appended a sentinel, strip it off */
-       ep->fids--;
-       ep->cids--;
-    }
-
     if (CANT_HAPPEN(maxid > ep->fids))
        maxid = ep->fids;
     if (maxid < ep->fids) {