]> git.pond.sub.org Git - empserver/commitdiff
(xundump): Add the ability to support the parsing of the human
authorRon Koenderink <rkoenderink@yahoo.ca>
Sun, 1 Jan 2006 03:44:41 +0000 (03:44 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Sun, 1 Jan 2006 03:44:41 +0000 (03:44 +0000)
readable form.

(xucolumnheader): New function.

src/lib/common/xundump.c

index 97295fcc91fee3052b284726d78bcd8a95b53708..1a4d16933fa3066127261a5accb49fb104d978f4 100644 (file)
@@ -53,6 +53,7 @@
 
 static char *fname = "";
 static int lineno = 0;
+static int human;
 
 /*
  * TODO
@@ -488,13 +489,16 @@ xuheader(FILE *fp, int expected_table, struct value values[])
        return -1;
     ungetc(ch, fp);
 
+    human = ch == 'c';
     res = -1;
-    if (fscanf(fp, "XDUMP%*[ \t]%63[^ \t#\n]%*[ \t]%*[^ \t#\n]%n",
-              name, &res) != 1
-       || res < 0)
-       return gripe("Expected XDUMP header");
+    if ((human
+         ? fscanf(fp, "config%*[ \t]%63[^ \t#\n]%n", name, &res) != 1
+         : fscanf(fp, "XDUMP%*[ \t]%63[^ \t#\n]%*[ \t]%*[^ \t#\n]%n",
+                  name, &res) != 1) || res < 0)
+       return gripe("Expected xdump header");
+
     if (skipfs(fp) != '\n')
-       return gripe("Junk after XDUMP header");
+       return gripe("Junk after xdump header");
 
     type = ef_byname(name);
     if (type < 0)
@@ -509,14 +513,40 @@ xuheader(FILE *fp, int expected_table, struct value values[])
     return type;
 }
 
+static int
+xucolumnheader(FILE *fp, int type)
+{
+    char ch;
+
+    if (!human)
+       return 0;
+
+    while ((ch = skipfs(fp)) == '\n');
+    ungetc(ch, fp);
+
+    /* FIXME parse column header */
+    if (fscanf(fp, "%*[^\n]\n") == -1)
+       return gripe("Invalid Column Header for table %s",
+           ef_nameof(type));
+    lineno++;
+
+    return 0;
+}
+
 static int
 xutrailer(FILE *fp, int type, int row)
 {
-    int rows, ch;
+    int rows, ch, res;
 
+    res = -1;
+    if (human) {
+       if (fscanf(fp, "config%n",  &res) != 0) {
+           return gripe("Malformed table footer");
+       }
+    }
     ch = skipfs(fp);
     if (!isdigit(ch)) {
-        if (ch != '\n')
+        if (ch != '\n' || !human)
            return gripe("Malformed table footer");
     } else {
         ungetc(ch, fp);
@@ -558,6 +588,9 @@ xundump(FILE *fp, char *file, int expected_table)
     fixed_rows = has_const(ef_cadef(type));
     need_sentinel = !fixed_rows; /* FIXME only approximation */
 
+    if (xucolumnheader(fp, type) == -1)
+       return -1;
+
     row = 0;
     for (;;) {
        lineno++;