]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/xundump.c
Update copyright notice.
[empserver] / src / lib / common / xundump.c
index 58eb36091f72501b85a96f3cbc5bbb7918fa6c5a..44590591bf803942538710866b996417c9dbbaf1 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-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -29,7 +29,7 @@
  * 
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005
+ *     Markus Armbruster, 2005-2006
  */
 
 /*
 
 #include <config.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #include <ctype.h>
-#include <string.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <time.h>
-
 #include "file.h"
 #include "match.h"
 #include "nsc.h"
 #include "optlist.h"
 #include "prototypes.h"
 
-static unsigned char initialized[EF_MAX];
 static char *fname;
 static int lineno;
 static int human;
 static int ellipsis, is_partial;
 static int cur_type, cur_id;
 static void *cur_obj;
+static int cur_obj_is_blank;
 static int nflds;
 static struct castr **fldca;
 static int *fldidx;
@@ -401,7 +397,7 @@ fldval_must_match(int fldno)
     struct castr *ca = ef_cadef(cur_type);
     int i = fldca[fldno] - ca;
 
-    return (initialized[cur_type] && (fldca[fldno]->ca_flags & NSC_CONST))
+    return (!cur_obj_is_blank && (fldca[fldno]->ca_flags & NSC_CONST))
        || caseen[i];
 }
 
@@ -414,7 +410,8 @@ getobj(struct castr *ca, int altid)
     if (!cur_obj) {
        if (ca->ca_table == cur_type)
            cur_id = altid;
-       if (cur_id >= ep->fids) {
+       cur_obj_is_blank = cur_id >= ep->fids;
+       if (cur_obj_is_blank) {
            /* TODO grow cache (and posssibly file) unless EFF_STATIC */
            if (cur_id < ep->csize - !!need_sentinel)
                ep->cids = ep->fids = cur_id + 1;
@@ -520,12 +517,12 @@ setstr(int fldno, char *str)
     ca = getfld(fldno, &idx);
     if (!ca)
        return -1;
-    must_match = fldval_must_match(fldno);
 
     memb_ptr = getobj(ca, cur_id);
     if (!memb_ptr)
        return -1;
     memb_ptr += ca->ca_off;
+    must_match = fldval_must_match(fldno);
 
     switch (ca->ca_type) {
     case NSC_STRING:
@@ -542,7 +539,7 @@ setstr(int fldno, char *str)
        len = ca->ca_len;
        if (strlen(str) > len)
            return gripe("Field %d takes at most %d characters",
-                        fldno + 1, len);
+                        fldno + 1, (int)len);
        old = memb_ptr;
        if (!must_match)
            strncpy(memb_ptr, str, len);
@@ -554,7 +551,7 @@ setstr(int fldno, char *str)
     if (must_match) {
        if (old && (!str || strncmp(old, str, len)))
            return gripe("Value for field %d must be \"%.*s\"",
-                        fldno + 1, len, old);
+                        fldno + 1, (int)len, old);
        if (!old && str)
            return gripe("Value for field %d must be nil", fldno + 1);
     }
@@ -610,7 +607,6 @@ static int
 mtsymset(int fldno, long *set)
 {
     struct castr *ca;
-    struct symbol *symtab;
 
     ca = getfld(fldno, NULL);
     if (!ca)
@@ -627,7 +623,6 @@ static int
 add2symset(int fldno, long *set, char *sym)
 {
     struct castr *ca;
-    struct symbol *symtab;
     int i;
 
     ca = getfld(fldno, NULL);
@@ -784,7 +779,6 @@ xundump(FILE *fp, char *file, int expected_table)
        lineno++;
     ungetc(ch, fp);
 
-    initialized[type] = 1;
     return type;
 }