]> git.pond.sub.org Git - empserver/commitdiff
xundump: Eliminate global may_trunc, may_omit_id
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 8 Feb 2014 15:52:14 +0000 (16:52 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Feb 2015 15:53:00 +0000 (16:53 +0100)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/common/xundump.c

index b9b8de26c5f71a3f9ce5c756df5b15ffd22b8a5a..d579dd8a6db0090777f86eac6f065d54ab226894 100644 (file)
@@ -82,8 +82,6 @@ static struct castr **fldca;  /* Map field number to selector */
 static int *fldidx;            /* Map field number to index */
 static int *caflds;            /* Map selector number to #fields seen */
 static int *cafldspp;          /* ditto, in previous parts */
-static int may_omit_id;                /* Okay to omit IDs? */
-static int may_trunc;          /* Okay to truncate? */
 
 static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
 static int deffld(int, char *, int);
@@ -106,6 +104,27 @@ have_hardcoded_indexes(int type)
        || type == EF_INFRASTRUCTURE;
 }
 
+/*
+ * Okay to truncate table TYPE?
+ */
+static int
+may_truncate(int type)
+{
+    return empfile[type].nent < 0 && !have_hardcoded_indexes(type);
+}
+
+/*
+ * Can we fill in gaps in table TYPE?
+ */
+static int
+can_fill_gaps(int type)
+{
+    struct castr *ca = ef_cadef(type);
+
+    return ca[0].ca_table == type && !(ca[0].ca_flags & NSC_EXTRA)
+       && !have_hardcoded_indexes(type);
+}
+
 /*
  * Gripe about the current line to stderr, return -1.
  */
@@ -218,7 +237,7 @@ tbl_skip_to_obj(int id)
 
     if (CANT_HAPPEN(partno != 0))
        return -1;
-    if (!may_omit_id && id != cur_id + 1)
+    if (!can_fill_gaps(cur_type) && id != cur_id + 1)
        return gripe("Expected %d in field %d", cur_id + 1, 1);
     if (id <= cur_id)
        return gripe("Field %d must be > %d", 1, cur_id);
@@ -270,11 +289,11 @@ tbl_part_done(void)
 
     if (cur_id + 1 < ep->fids) {
        if (partno == 0) {
-           if (may_trunc) {
+           if (may_truncate(cur_type)) {
                if (!ef_truncate(cur_type, cur_id + 1))
                    return -1;
            } else {
-               if (!may_omit_id)
+               if (!can_fill_gaps(cur_type))
                    return gripe("Expected %d more rows",
                                 ep->fids - (cur_id + 1));
                omit_ids(cur_id + 1, ep->fids);
@@ -1063,13 +1082,6 @@ xundump(FILE *fp, char *file, int *plno, int expected_table)
     if (CANT_HAPPEN(!ca))
        return -1;
 
-    if (have_hardcoded_indexes(type)) {
-       may_omit_id = may_trunc = 0;
-    } else {
-       may_omit_id = 1;
-       may_trunc = empfile[type].nent < 0;
-    }
-
     nca = nf = 0;
     for (i = 0; ca[i].ca_name; i++) {
        nca++;