2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * xundump.c: Load back xdump output
29 * Known contributors to this file:
30 * Ron Koenderink, 2005
31 * Markus Armbruster, 2005-2011
35 * See doc/xdump! And keep it up-to-date.
37 * Parsing of machine-readable xdump is not precise: it recognizes
38 * comments, accepts whitespace in place of single space, and accepts
39 * the full human-readable field syntax instead of its machine-
43 * - Normalize terminology: table/rows/columns or file/records/fields
44 * - Loading tables with NSC_STRING elements more than once leaks memory
46 * - Symbolic array indexes
47 * - Option to treat missing and unknown fields as warning, not error
48 * TODO, but hardly worth the effort:
49 * - Permit reordering of array elements
66 static char *fname; /* Name of file being read */
67 static int lineno; /* Current line number */
69 static int cur_type; /* Current table's file type */
70 static int partno; /* Counts from 0..#parts-1 */
71 static void *cur_obj; /* The object being read into */
72 static int cur_id; /* and its index in the table */
74 static unsigned char *idgap; /* idgap && idgap[ID] iff part#0 lacks ID */
75 static int idgap_len; /* #elements in idgap[] */
77 static int human; /* Reading human-readable syntax? */
78 static int ellipsis; /* Header ended with ...? */
79 static int nflds; /* #fields in input records */
80 static struct castr **fldca; /* Map field number to selector */
81 static int *fldidx; /* Map field number to index */
82 static int *caflds; /* Map selector number to #fields seen */
83 static int *cafldspp; /* ditto, in previous parts */
84 static int may_omit_id; /* Okay to omit IDs? */
85 static int may_trunc; /* Okay to truncate? */
87 static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
88 static int deffld(int, char *, int);
89 static int defellipsis(void);
90 static int chkflds(void);
91 static int setnum(int, double);
92 static int setstr(int, char *);
93 static int xunsymbol(char *, struct castr *, int);
94 static int setsym(int, char *);
95 static int mtsymset(int, long *);
96 static int add2symset(int, long *, char *);
97 static int xubody(FILE *);
98 static int xutail(FILE *, struct castr *);
101 * Gripe about the current line to stderr, return -1.
104 gripe(char *fmt, ...)
108 fprintf(stderr, "%s:%d: ", fname, lineno);
110 vfprintf(stderr, fmt, ap);
117 /* Make TYPE the current table. */
125 old_nelem = type == EF_BAD ? 0 : ef_nelem(type);
130 /* End the current table. */
139 * Seek to current table's ID-th record.
140 * ID must be acceptable.
141 * Store it in cur_obj, and set cur_id accordingly.
142 * Return 0 on success, -1 on failure.
147 struct empfile *ep = &empfile[cur_type];
149 if (id >= ef_nelem(cur_type)) {
150 if (!ef_ensure_space(cur_type, id, 1))
151 return gripe("Can't put ID %d into table %s", id, ep->name);
154 cur_obj = ef_ptr(cur_type, id);
155 if (CANT_HAPPEN(!cur_obj))
162 * Get the next object.
163 * Must not have a record index.
164 * Store it in cur_obj, and set cur_id accordingly.
165 * Return 0 on success, -1 on failure.
170 int max_id = ef_id_limit(cur_type);
172 if (cur_id >= max_id)
173 return gripe("Too many rows");
174 return tbl_seek(cur_id + 1);
179 * Reset the omitted objects to default state.
182 omit_ids(int id1, int id2)
189 idgap = realloc(idgap, id2 * sizeof(*idgap));
190 for (i = idgap_len; i < id1; i++)
192 for (i = id1; i < id2; i++) {
193 ef_blank(cur_type, i, ef_ptr(cur_type, i));
200 * Return the smallest non-omitted ID in ID1..ID2-1 if any, else -1.
203 expected_id(int id1, int id2)
207 for (i = id1; i < id2; i++) {
208 if (i >= idgap_len || !idgap[i])
215 * Get the next object, it has record index ID.
216 * Store it in cur_obj, and set cur_id accordingly.
217 * Ensure we're omitting the same objects as the previous parts.
218 * Reset any omitted objects to default state.
219 * Return 0 on success, -1 on failure.
222 tbl_skip_to_obj(int id)
224 struct empfile *ep = &empfile[cur_type];
225 int prev_id = cur_id;
229 if (!may_omit_id && id != cur_id + 1)
230 return gripe("Expected %d in field %d", cur_id + 1, 1);
232 return gripe("Field %d must be > %d", 1, cur_id);
233 max_id = ef_id_limit(cur_type);
235 return gripe("Field %d must be <= %d", 1, max_id);
237 exp_id = expected_id(cur_id + 1, ep->fids);
239 return gripe("Table's first part doesn't have this row");
240 else if (id != exp_id)
241 return gripe("Expected %d in field %d,"
242 " like in table's first part",
246 if (tbl_seek(id) < 0)
250 omit_ids(prev_id + 1, id);
256 * If the table has variable length, truncate it.
257 * Else ensure we're omitting the same objects as the previous parts.
258 * Reset any omitted objects to default state.
259 * Return 0 on success, -1 on failure.
264 struct empfile *ep = &empfile[cur_type];
267 if (cur_id + 1 < ep->fids) {
270 if (!ef_truncate(cur_type, cur_id + 1))
274 return gripe("Expected %d more rows",
275 ep->fids - (cur_id + 1));
276 omit_ids(cur_id + 1, ep->fids);
279 exp_id = expected_id(cur_id + 1, ep->fids);
281 return gripe("Expected row with %d in field %d,"
282 " like in table's first part",
294 * Read and ignore field separators from FP.
295 * Return first character that is not a field separator.
304 } while (ch == ' ' || ch == '\t');
309 } while (ch != EOF && ch != '\n');
316 * Decode escape sequences in BUF.
317 * Return BUF on success, null pointer on failure.
329 if (sscanf(++src, "%3o%n", &octal_chr, &n) != 1 || n != 3)
331 *dst++ = (char)octal_chr;
341 * Read an identifier from FP into BUF.
342 * BUF must have space for 1024 characters.
343 * Return number of characters read on success, -1 on failure.
346 getid(FILE *fp, char *buf)
349 if (fscanf(fp, "%1023[^\"#()<>= \t\n]%n", buf, &n) != 1
357 * Try to read a field name from FP.
358 * I is the field number, counting from zero.
359 * If a name is read, set fldca[I] and fldidx[I] for it, and update
361 * Return 1 if a name or ... was read, 0 on end of line, -1 on error.
364 xufldname(FILE *fp, int i)
372 return gripe("Unexpected EOF");
379 if (getc(fp) != '.' || getc(fp) != '.')
380 return gripe("Junk in header field %d", i + 1);
381 if (defellipsis() < 0)
384 if (ch != EOF && ch != '\n')
385 return gripe("Junk after ...");
390 if (getid(fp, buf) < 0)
391 return gripe("Junk in header field %d", i + 1);
395 return deffld(i, buf, -1);
399 if (isdigit(ch) || ch == '-' || ch == '+') {
400 if (fscanf(fp, "%d", &idx) != 1)
401 return gripe("Malformed number in index of header field %d",
404 return gripe("Index must not be negative in header field %d",
407 if (getid(fp, buf) < 0)
408 return gripe("Malformed index in header field %d", i + 1);
409 return gripe("Symbolic index in header field %d not yet implemented",
414 return gripe("Malformed index in header field %d", i + 1);
415 return deffld(i, buf, idx);
420 * Try to read a field value from FP.
421 * I is the field number, counting from zero.
422 * Return 1 if a value was read, 0 on end of line, -1 on error.
425 xufld(FILE *fp, int i)
435 return gripe("Unexpected EOF");
437 CANT_HAPPEN(i > nflds);
439 if (fldca[i]->ca_type != NSC_STRINGY && fldca[i]->ca_len)
440 return gripe("Field %s(%d) missing",
441 fldca[i]->ca_name, fldidx[i]);
442 return gripe("Field %s missing", fldca[i]->ca_name);
446 case '+': case '-': case '.':
447 case '0': case '1': case '2': case '3': case '4':
448 case '5': case '6': case '7': case '8': case '9':
450 if (fscanf(fp, "%lg", &dbl) != 1)
451 return gripe("Malformed number in field %d", i + 1);
452 return setnum(i, dbl);
459 if (fscanf(fp, "%1023[^\"\n]", buf) != 1 || getc(fp) != '"')
460 return gripe("Malformed string in field %d", i + 1);
462 return gripe("Invalid escape sequence in field %d",
465 return setstr(i, buf);
467 if (mtsymset(i, &set) < 0)
471 if (ch == EOF || ch == '\n')
472 return gripe("Unmatched '(' in field %d", i + 1);
476 if (getid(fp, buf) < 0)
477 return gripe("Junk in field %d", i + 1);
478 if (add2symset(i, &set, buf) < 0)
481 return setnum(i, set);
484 if (getid(fp, buf) < 0)
485 return gripe("Junk in field %d", i + 1);
486 if (!strcmp(buf, "nil"))
487 return setstr(i, NULL);
489 return setsym(i, buf);
494 * Read fields from FP.
495 * Use PARSE() to read each field.
496 * Return number of fields read on success, -1 on error.
499 xuflds(FILE *fp, int (*parse)(FILE *, int))
512 else if (ch != ' ' && ch != '\t')
513 return gripe("Bad field separator after field %d", i + 1);
518 * Define the FLDNO-th field.
519 * If IDX is negative, define as selector NAME, else as NAME(IDX).
520 * Set fldca[FLDNO] and fldidx[FLDNO] accordingly.
522 * Return 1 on success, -1 on error.
525 deffld(int fldno, char *name, int idx)
527 struct castr *ca = ef_cadef(cur_type);
530 res = stmtch(name, ca, offsetof(struct castr, ca_name),
531 sizeof(struct castr));
533 return gripe("Header %s of field %d is %s", name, fldno + 1,
534 res == M_NOTUNIQUE ? "ambiguous" : "unknown");
535 if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
536 return gripe("Extraneous header %s in field %d", name, fldno + 1);
537 if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
539 return gripe("Header %s requires an index in field %d",
540 ca[res].ca_name, fldno + 1);
541 if (idx >= ca[res].ca_len)
542 return gripe("Header %s(%d) index out of bounds in field %d",
543 ca[res].ca_name, idx, fldno + 1);
544 if (idx < caflds[res])
545 return gripe("Duplicate header %s(%d) in field %d",
546 ca[res].ca_name, idx, fldno + 1);
547 if (idx > caflds[res])
548 return gripe("Expected header %s(%d) in field %d",
549 ca[res].ca_name, caflds[res], fldno + 1);
552 return gripe("Header %s doesn't take an index in field %d",
553 ca[res].ca_name, fldno + 1);
556 return gripe("Duplicate header %s in field %d",
557 ca[res].ca_name, fldno + 1);
559 fldca[fldno] = &ca[res];
566 * Record that header ends with ...
567 * Set ellipsis and is_partial.
568 * Return 0 on success, -1 on error.
573 struct castr *ca = ef_cadef(cur_type);
575 if (ca[0].ca_table != cur_type || (ca[0].ca_flags & NSC_EXTRA))
576 return gripe("Table %s doesn't support ...", ef_nameof(cur_type));
581 /* Is table split into parts? */
585 return ellipsis || partno;
589 * Check fields in xdump are sane.
590 * Return 0 on success, -1 on error.
595 struct castr *ca = ef_cadef(cur_type);
596 int i, len, cafldsmax, res = 0;
598 /* Record index must come first, to make cur_id work, see setnum() */
599 if (ca[0].ca_table == cur_type && caflds[0] && fldca[0] != &ca[0])
600 res = gripe("Header field %s must come first", ca[0].ca_name);
603 /* Need a join field, use 0-th selector */
605 res = gripe("Header field %s required in each table part",
610 return res; /* table is split, another part expected */
612 /* Check for missing fields */
613 for (i = 0; ca[i].ca_name; i++) {
614 cafldsmax = MAX(caflds[i], cafldspp[i]);
615 if (ca[i].ca_flags & NSC_EXTRA)
617 len = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
618 if (!len && !cafldsmax)
619 res = gripe("Header field %s missing", ca[i].ca_name);
620 else if (len && cafldsmax == len - 1)
621 res = gripe("Header field %s(%d) missing",
622 ca[i].ca_name, len - 1);
623 else if (len && cafldsmax < len - 1)
624 res = gripe("Header fields %s(%d) ... %s(%d) missing",
625 ca[i].ca_name, cafldsmax, ca[i].ca_name, len - 1);
632 * Get selector for field FLDNO.
633 * Assign the field's selector index to *IDX, unless it is null.
634 * Return the selector on success, null pointer on error.
636 static struct castr *
637 getfld(int fldno, int *idx)
639 if (fldno >= nflds) {
640 gripe("Too many fields, expected only %d", nflds);
643 if (CANT_HAPPEN(fldno < 0))
646 *idx = fldidx[fldno];
651 * Is a new value for field FLDNO required to match the old one?
654 fldval_must_match(int fldno)
656 struct castr *ca = ef_cadef(cur_type);
657 int i = fldca[fldno] - ca;
660 * Value must match if:
661 * it's for a const selector, unless the object is still blank, or
662 * it was already given in a previous part of a split table.
664 return (cur_id < old_nelem && (fldca[fldno]->ca_flags & NSC_CONST))
665 || fldidx[fldno] < cafldspp[i];
669 * Set value of field FLDNO in current object to DBL.
670 * Return 1 on success, -1 on error.
673 setnum(int fldno, double dbl)
680 ca = getfld(fldno, &idx);
685 if (ca->ca_table == cur_type) {
686 /* Got record index */
689 return gripe("Field %d can't hold this value", fldno + 1);
690 if (tbl_skip_to_obj(next_id) < 0)
693 if (tbl_next_obj() < 0)
698 memb_ptr += ca->ca_off;
700 switch (ca->ca_type) {
702 old = ((signed char *)memb_ptr)[idx];
703 new = ((signed char *)memb_ptr)[idx] = (signed char)dbl;
707 old = ((unsigned char *)memb_ptr)[idx];
708 new = ((unsigned char *)memb_ptr)[idx] = (unsigned char)dbl;
711 old = ((short *)memb_ptr)[idx];
712 new = ((short *)memb_ptr)[idx] = (short)dbl;
715 old = ((unsigned short *)memb_ptr)[idx];
716 new = ((unsigned short *)memb_ptr)[idx] = (unsigned short)dbl;
719 old = ((int *)memb_ptr)[idx];
720 new = ((int *)memb_ptr)[idx] = (int)dbl;
723 old = ((long *)memb_ptr)[idx];
724 new = ((long *)memb_ptr)[idx] = (long)dbl;
727 old = ((coord *)memb_ptr)[idx];
728 /* FIXME use variant of xrel() that takes orig instead of nation */
729 if (old >= WORLD_X / 2)
731 new = ((coord *)memb_ptr)[idx] = XNORM((coord)dbl);
732 if (new >= WORLD_X / 2)
736 old = ((coord *)memb_ptr)[idx];
737 /* FIXME use variant of yrel() that takes orig instead of nation */
738 if (old >= WORLD_Y / 2)
740 new = ((coord *)memb_ptr)[idx] = YNORM((coord)dbl);
741 if (new >= WORLD_Y / 2)
745 old = ((float *)memb_ptr)[idx];
746 ((float *)memb_ptr)[idx] = (float)dbl;
747 new = dbl; /* suppress new != dbl check */
750 old = ((double *)memb_ptr)[idx];
751 ((double *)memb_ptr)[idx] = dbl;
752 new = dbl; /* suppress new != dbl check */
755 old = ((time_t *)memb_ptr)[idx];
756 new = ((time_t *)memb_ptr)[idx] = (time_t)dbl;
759 return gripe("Field %d doesn't take numbers", fldno + 1);
762 if (fldval_must_match(fldno) && old != dbl)
763 return gripe("Value for field %d must be %g", fldno + 1, old);
765 return gripe("Field %d can't hold this value", fldno + 1);
771 * Set value of field FLDNO in current object to STR.
772 * Return 1 on success, -1 on error.
775 setstr(int fldno, char *str)
780 char *memb_ptr, *old;
782 ca = getfld(fldno, &idx);
787 if (tbl_next_obj() < 0)
791 memb_ptr += ca->ca_off;
792 must_match = fldval_must_match(fldno);
794 switch (ca->ca_type) {
796 old = ((char **)memb_ptr)[idx];
798 /* FIXME may leak old value */
799 ((char **)memb_ptr)[idx] = str ? strdup(str) : NULL;
800 len = 65535; /* really SIZE_MAX, but that's C99 */
803 if (CANT_HAPPEN(idx))
806 return gripe("Field %d doesn't take nil", fldno + 1);
808 if (strlen(str) > len)
809 return gripe("Field %d takes at most %d characters",
810 fldno + 1, (int)len);
813 strncpy(memb_ptr, str, len);
816 return gripe("Field %d doesn't take strings", fldno + 1);
820 if (old && (!str || strncmp(old, str, len)))
821 return gripe("Value for field %d must be \"%.*s\"",
822 fldno + 1, (int)len, old);
824 return gripe("Value for field %d must be nil", fldno + 1);
831 * Resolve symbol name ID in table referred to by CA.
832 * Use field number N for error messages.
833 * Return index in referred table on success, -1 on failure.
836 xunsymbol(char *id, struct castr *ca, int n)
838 int i = ef_elt_byname(ca->ca_table, id);
840 return gripe("%s %s symbol `%s' in field %d",
841 i == M_NOTUNIQUE ? "Ambiguous" : "Unknown",
842 ca->ca_name, id, n + 1);
847 * Map symbol index to symbol value.
848 * CA is the table, and I is the index in it.
851 symval(struct castr *ca, int i)
853 int type = ca->ca_table;
855 if (type != EF_BAD && ef_cadef(type) == symbol_ca)
856 /* symbol table, value is in the table */
857 return ((struct symbol *)ef_ptr(type, i))->value;
858 /* value is the table index */
863 * Set value of field FLDNO in current object to value of symbol SYM.
864 * Return 1 on success, -1 on error.
867 setsym(int fldno, char *sym)
872 ca = getfld(fldno, NULL);
876 if (ca->ca_table == EF_BAD || (ca->ca_flags & NSC_BITS))
877 return gripe("Field %d doesn't take symbols", fldno + 1);
879 i = xunsymbol(sym, ca, fldno);
882 return setnum(fldno, symval(ca, i));
886 * Create an empty symbol set for field FLDNO in *SET.
887 * Return 1 on success, -1 on error.
890 mtsymset(int fldno, long *set)
894 ca = getfld(fldno, NULL);
898 if (ca->ca_table == EF_BAD || ef_cadef(ca->ca_table) != symbol_ca
899 || !(ca->ca_flags & NSC_BITS))
900 return gripe("Field %d doesn't take symbol sets", fldno + 1);
906 * Add a symbol to a symbol set for field FLDNO in *SET.
907 * SYM is the name of the symbol to add.
908 * Return 1 on success, -1 on error.
911 add2symset(int fldno, long *set, char *sym)
916 ca = getfld(fldno, NULL);
920 i = xunsymbol(sym, ca, fldno);
923 *set |= symval(ca, i);
928 * Read an xdump table header line from FP.
929 * Expect header for EXPECTED_TABLE, unless it is EF_BAD.
930 * Recognize header for machine- and human-readable syntax, and set
932 * Return table type on success, -2 on EOF before header, -1 on failure.
935 xuheader(FILE *fp, int expected_table)
941 while ((ch = skipfs(fp)) == '\n')
943 if (ch == EOF && expected_table == EF_BAD)
950 ? fscanf(fp, "config%*[ \t]%63[^ \t#\n]%n", name, &res) != 1
951 : fscanf(fp, "XDUMP%*[ \t]%63[^ \t#\n]%*[ \t]%*[^ \t#\n]%n",
952 name, &res) != 1) || res < 0)
953 return gripe("Expected xdump header");
955 type = ef_byname(name);
957 return gripe("Unknown table `%s'", name);
958 if (expected_table != EF_BAD && expected_table != type)
959 return gripe("Expected table `%s', not `%s'",
960 ef_nameof(expected_table), name);
962 if (!empfile[type].file
963 || !ef_cadef(type) || !(ef_flags(type) & EFF_MEM)) {
964 CANT_HAPPEN(expected_table != EF_BAD);
965 return gripe("Table `%s' is not permitted here", name);
968 if (skipfs(fp) != '\n')
969 return gripe("Junk after xdump header");
976 * Find fields in this xdump.
977 * If reading human-readable syntax, read a field header line from FP.
978 * Else take fields from the table's selectors in CA[].
979 * Set ellipsis, nflds, fldca[], fldidx[] and caflds[] accordingly.
980 * Return 0 on success, -1 on failure.
983 xufldhdr(FILE *fp, struct castr ca[])
989 for (i = 0; ca[i].ca_name; i++)
994 while ((ch = skipfs(fp)) == '\n')
997 nflds = xuflds(fp, xufldname);
1000 nflds -= ellipsis != 0;
1005 for (i = 0; ca[i].ca_name; i++) {
1006 if ((ca[i].ca_flags & NSC_EXTRA))
1008 n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
1016 nflds = fidx - fldidx;
1023 * Read xdump footer from FP.
1024 * CA[] contains the table's selectors.
1025 * The body had RECS records.
1026 * Update cafldspp[] from caflds[].
1027 * Return 0 on success, -1 on failure.
1030 xufooter(FILE *fp, struct castr ca[], int recs)
1036 if (fscanf(fp, "config%n", &res) != 0 || res < 0)
1037 return gripe("Malformed table footer");
1039 if (fscanf(fp, "%d", &n) != 1)
1040 return gripe("Malformed table footer");
1042 return gripe("Read %d rows, which doesn't match footer "
1043 "%d rows", recs, n);
1045 if (skipfs(fp) != '\n')
1046 return gripe("Junk after table footer");
1047 if (tbl_part_done() < 0)
1051 for (i = 0; ca[i].ca_name; i++) {
1052 if (cafldspp[i] < caflds[i])
1053 cafldspp[i] = caflds[i];
1060 * Read an xdump table from FP.
1061 * Both machine- and human-readable xdump syntax are recognized.
1062 * Expect table EXPECTED_TABLE, unless it is EF_BAD.
1063 * Report errors to stderr.
1064 * Messages assume FP starts in the file FILE at line *PLNO.
1065 * Update *PLNO to reflect lines read from FP.
1066 * Return table type on success, -2 on EOF before header, -1 on failure.
1069 xundump(FILE *fp, char *file, int *plno, int expected_table)
1072 int type, nca, nf, i, ch;
1077 if ((type = xuheader(fp, expected_table)) < 0)
1080 ca = ef_cadef(type);
1081 if (CANT_HAPPEN(!ca))
1086 may_trunc = empfile[type].nent < 0;
1087 for (i = 0; ca[i].ca_name; i++) {
1089 if (!(ca[i].ca_flags & NSC_EXTRA)) {
1090 nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0);
1091 if (ca[i].ca_flags & NSC_CONST)
1092 may_omit_id = may_trunc = 0;
1095 fldca = malloc(nf * sizeof(*fldca));
1096 fldidx = malloc(nf * sizeof(*fldidx));
1097 caflds = malloc(nca * sizeof(*caflds));
1098 cafldspp = calloc(nca, sizeof(*cafldspp));
1101 if (xutail(fp, ca) < 0)
1110 /* Skip empty lines so that callers can easily check for EOF */
1111 while ((ch = skipfs(fp)) == '\n')
1120 * Read the remainder of an xdump after the table header line from FP.
1121 * CA[] contains the table's selectors.
1122 * Return 0 on success, -1 on failure.
1125 xutail(FILE *fp, struct castr *ca)
1130 if (xufldhdr(fp, ca) < 0)
1132 if ((recs = xubody(fp)) < 0)
1134 if (xufooter(fp, ca, recs) < 0)
1138 if (xuheader(fp, cur_type) < 0)
1144 * Read the body of an xdump table from FP.
1145 * Return number of rows read on success, -1 on failure.
1153 while ((ch = skipfs(fp)) == '\n')
1158 if (xuflds(fp, xufld) < 0)