]> git.pond.sub.org Git - empserver/commitdiff
(xuheader1): New, factored out of xundump().
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Feb 2006 15:52:10 +0000 (15:52 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Feb 2006 15:52:10 +0000 (15:52 +0000)
src/lib/common/xundump.c

index 02697e8de31fc5cebfacfeeacf755b006ad14ff5..5154aa3880be8c2a43034f30d6a5bac0d36aba3b 100644 (file)
@@ -566,6 +566,40 @@ xuheader(FILE *fp, int expected_table)
     return type;
 }
 
+static int
+xuheader1(FILE *fp, int type, struct castr ca[])
+{
+    struct castr **fca;
+    int *fidx;
+    int ch, i, j, n;
+
+    cur_type = type;
+
+    if (human) {
+       while ((ch = skipfs(fp)) == '\n')
+           lineno++;
+       ungetc(ch, fp);
+       if (xuflds(fp, xufldname) < 0)
+           return -1;
+    } else {
+       fca = fldca;
+       fidx = fldidx;
+
+       for (i = 0; ca[i].ca_name; i++) {
+           if ((ca[i].ca_flags & NSC_EXTRA))
+               continue;
+           n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
+           j = 0;
+           do {
+               *fca++ = &ca[i];
+               *fidx++ = j;
+           } while (++j < n);
+       }
+    }
+
+    return 0;
+}
+
 static int
 xutrailer(FILE *fp, int type, int row)
 {
@@ -617,30 +651,7 @@ xundump(FILE *fp, char *file, int expected_table)
     fldidx = calloc(nflds, sizeof(*fldidx));
     caflds = calloc(nca, sizeof(*caflds));
 
-    cur_type = type;
-    if (human) {
-       while ((ch = skipfs(fp)) == '\n')
-           lineno++;
-       ungetc(ch, fp);
-       if (xuflds(fp, xufldname) < 0)
-           type = EF_BAD;
-    } else {
-       struct castr **fca = fldca;
-       int *fidx = fldidx;
-       int i, j, n;
-       for (i = 0; ca[i].ca_name; i++) {
-           if ((ca[i].ca_flags & NSC_EXTRA))
-               continue;
-           n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
-           j = 0;
-           do {
-               *fca++ = &ca[i];
-               *fidx++ = j;
-           } while (++j < n);
-       }
-    }
-
-    if (type >= 0 && xundump1(fp, type, ca) < 0)
+    if (xuheader1(fp, type, ca) < 0 || xundump1(fp, type, ca) < 0)
        type = EF_BAD;
 
     free(caflds);
@@ -663,6 +674,8 @@ xundump1(FILE *fp, int type, struct castr *ca)
     int need_sentinel = !EF_IS_GAME_STATE(type);
     int row, ch;
 
+    cur_type = type;
+
     for (row = 0;; ++row) {
        while ((ch = skipfs(fp)) == '\n')
            lineno++;
@@ -684,6 +697,7 @@ xundump1(FILE *fp, int type, struct castr *ca)
        if (xuflds(fp, xufld) < 0)
            return -1;
     }
+
     if (row != ep->fids) {
        if (fixed_rows)
            return gripe("Table %s requires %d rows, got %d",