2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, 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 * - Check EFF_CFG tables are dense
47 * - Symbolic array indexes
48 * - Option to treat missing and unknown fields as warning, not error
49 * TODO, but hardly worth the effort:
50 * - Permit reordering of array elements
67 static char *fname; /* Name of file being read */
68 static int lineno; /* Current line number */
70 static int cur_type; /* Current table's file type */
71 static int partno; /* Counts from 0..#parts-1 */
72 static void *cur_obj; /* The object being read into */
73 static int cur_id; /* and its index in the table */
74 static int cur_obj_is_blank;
75 static unsigned char *idgap; /* idgap && idgap[ID] iff part#0 lacks ID */
76 static int idgap_max; /* FIXME */
78 static int human; /* Reading human-readable syntax? */
79 static int ellipsis; /* Header ended with ...? */
80 static int nflds; /* #fields in input records */
81 static struct castr **fldca; /* Map field number to selector */
82 static int *fldidx; /* Map field number to index */
83 static int *caflds; /* Map selector number to #fields seen */
84 static int *cafldspp; /* ditto, in previous parts */
85 static int may_omit_id; /* Okay to omit IDs? */
86 static int may_trunc; /* Okay to truncate? */
88 static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
89 static int deffld(int, char *, int);
90 static int defellipsis(void);
91 static int chkflds(void);
92 static int setnum(int, double);
93 static int setstr(int, char *);
94 static int xunsymbol(char *, struct castr *, int);
95 static int setsym(int, char *);
96 static int mtsymset(int, long *);
97 static int add2symset(int, long *, char *);
98 static int xubody(FILE *);
99 static int xutail(FILE *, struct castr *);
102 * Gripe about the current line to stderr, return -1.
105 gripe(char *fmt, ...)
109 fprintf(stderr, "%s:%d: ", fname, lineno);
111 vfprintf(stderr, fmt, ap);
118 /* Make TYPE the current table. */
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 and cur_obj_is_blank accordingly.
142 * Return 0 on success, -1 on failure.
147 struct empfile *ep = &empfile[cur_type];
149 cur_obj_is_blank = id >= ep->fids;
151 if (id >= ef_nelem(cur_type)) {
152 if (!ef_ensure_space(cur_type, id, 1))
153 return gripe("Can't put ID %d into table %s", id, ep->name);
156 cur_obj = ef_ptr(cur_type, id);
157 if (CANT_HAPPEN(!cur_obj))
164 * Get the next object.
165 * Must not have a record index.
166 * Store it in cur_obj, and set cur_id and cur_obj_is_blank accordingly.
167 * Return 0 on success, -1 on failure.
172 int max_id = ef_id_limit(cur_type);
174 if (cur_id >= max_id)
175 return gripe("Too many rows");
176 return tbl_seek(cur_id + 1);
183 omit_ids(int id1, int id2)
190 idgap = realloc(idgap, (id2 + 1) * sizeof(*idgap));
191 for (i = idgap_max; i < id1; i++)
193 for (i = id1; i < id2; 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_max || !idgap[i])
215 * Get the next object, it has record index ID.
216 * Store it in cur_obj, and set cur_id and cur_obj_is_blank accordingly.
217 * Ensure we're omitting the same objects as the previous parts.
218 * Return 0 on success, -1 on failure.
221 tbl_skip_to_obj(int id)
223 struct empfile *ep = &empfile[cur_type];
224 int prev_id = cur_id;
228 if (!may_omit_id && id != cur_id + 1)
229 return gripe("Expected %d in field %d", cur_id + 1, 1);
231 return gripe("Field %d must be > %d", 1, cur_id);
232 max_id = ef_id_limit(cur_type);
234 return gripe("Field %d must be <= %d", 1, max_id);
236 exp_id = expected_id(cur_id + 1, ep->fids);
238 return gripe("Table's first part doesn't have this row");
239 else if (id != exp_id)
240 return gripe("Expected %d in field %d,"
241 " like in table's first part",
245 if (tbl_seek(id) < 0)
249 omit_ids(prev_id + 1, id);
255 * If the table has variable length, truncate it.
256 * Else ensure we're omitting the same objects as the previous parts.
257 * Return 0 on success, -1 on failure.
262 struct empfile *ep = &empfile[cur_type];
265 if (cur_id + 1 < ep->fids) {
268 if (!ef_truncate(cur_type, cur_id + 1))
271 return gripe("Expected %d more rows",
272 ep->fids - (cur_id + 1));
275 exp_id = expected_id(cur_id + 1, ep->fids);
277 return gripe("Expected row with %d in field %d,"
278 " like in table's first part",
290 * Read and ignore field separators from FP.
291 * Return first character that is not a field separator.
300 } while (ch == ' ' || ch == '\t');
305 } while (ch != EOF && ch != '\n');
312 * Decode escape sequences in BUF.
313 * Return BUF on success, null pointer on failure.
325 if (sscanf(++src, "%3o%n", &octal_chr, &n) != 1 || n != 3)
327 *dst++ = (char)octal_chr;
337 * Read an identifier from FP into BUF.
338 * BUF must have space for 1024 characters.
339 * Return number of characters read on success, -1 on failure.
342 getid(FILE *fp, char *buf)
345 if (fscanf(fp, "%1023[^\"#()<>= \t\n]%n", buf, &n) != 1
353 * Try to read a field name from FP.
354 * I is the field number, counting from zero.
355 * If a name is read, set fldca[I] and fldidx[I] for it, and update
357 * Return 1 if a name or ... was read, 0 on end of line, -1 on error.
360 xufldname(FILE *fp, int i)
368 return gripe("Unexpected EOF");
375 if (getc(fp) != '.' || getc(fp) != '.')
376 return gripe("Junk in header field %d", i + 1);
377 if (defellipsis() < 0)
380 if (ch != EOF && ch != '\n')
381 return gripe("Junk after ...");
386 if (getid(fp, buf) < 0)
387 return gripe("Junk in header field %d", i + 1);
391 return deffld(i, buf, -1);
395 if (isdigit(ch) || ch == '-' || ch == '+') {
396 if (fscanf(fp, "%d", &idx) != 1)
397 return gripe("Malformed number in index of header field %d",
400 return gripe("Index must not be negative in header field %d",
403 if (getid(fp, buf) < 0)
404 return gripe("Malformed index in header field %d", i + 1);
405 return gripe("Symbolic index in header field %d not yet implemented",
410 return gripe("Malformed index in header field %d", i + 1);
411 return deffld(i, buf, idx);
416 * Try to read a field value from FP.
417 * I is the field number, counting from zero.
418 * Return 1 if a value was read, 0 on end of line, -1 on error.
421 xufld(FILE *fp, int i)
431 return gripe("Unexpected EOF");
433 CANT_HAPPEN(i > nflds);
435 if (fldca[i]->ca_type != NSC_STRINGY && fldca[i]->ca_len)
436 return gripe("Field %s(%d) missing",
437 fldca[i]->ca_name, fldidx[i]);
438 return gripe("Field %s missing", fldca[i]->ca_name);
442 case '+': case '-': case '.':
443 case '0': case '1': case '2': case '3': case '4':
444 case '5': case '6': case '7': case '8': case '9':
446 if (fscanf(fp, "%lg", &dbl) != 1)
447 return gripe("Malformed number in field %d", i + 1);
448 return setnum(i, dbl);
455 if (fscanf(fp, "%1023[^\"\n]", buf) != 1 || getc(fp) != '"')
456 return gripe("Malformed string in field %d", i + 1);
458 return gripe("Invalid escape sequence in field %d",
461 return setstr(i, buf);
463 if (mtsymset(i, &set) < 0)
467 if (ch == EOF || ch == '\n')
468 return gripe("Unmatched '(' in field %d", i + 1);
472 if (getid(fp, buf) < 0)
473 return gripe("Junk in field %d", i + 1);
474 if (add2symset(i, &set, buf) < 0)
477 return setnum(i, set);
480 if (getid(fp, buf) < 0)
481 return gripe("Junk in field %d", i + 1);
482 if (!strcmp(buf, "nil"))
483 return setstr(i, NULL);
485 return setsym(i, buf);
490 * Read fields from FP.
491 * Use PARSE() to read each field.
492 * Return number of fields read on success, -1 on error.
495 xuflds(FILE *fp, int (*parse)(FILE *, int))
508 else if (ch != ' ' && ch != '\t')
509 return gripe("Bad field separator after field %d", i + 1);
514 * Define the FLDNO-th field.
515 * If IDX is negative, define as selector NAME, else as NAME(IDX).
516 * Set fldca[FLDNO] and fldidx[FLDNO] accordingly.
518 * Return 1 on success, -1 on error.
521 deffld(int fldno, char *name, int idx)
523 struct castr *ca = ef_cadef(cur_type);
526 res = stmtch(name, ca, offsetof(struct castr, ca_name),
527 sizeof(struct castr));
529 return gripe("Header %s of field %d is %s", name, fldno + 1,
530 res == M_NOTUNIQUE ? "ambiguous" : "unknown");
531 if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
532 return gripe("Extraneous header %s in field %d", name, fldno + 1);
533 if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
535 return gripe("Header %s requires an index in field %d",
536 ca[res].ca_name, fldno + 1);
537 if (idx >= ca[res].ca_len)
538 return gripe("Header %s(%d) index out of bounds in field %d",
539 ca[res].ca_name, idx, fldno + 1);
540 if (idx < caflds[res])
541 return gripe("Duplicate header %s(%d) in field %d",
542 ca[res].ca_name, idx, fldno + 1);
543 if (idx > caflds[res])
544 return gripe("Expected header %s(%d) in field %d",
545 ca[res].ca_name, caflds[res], fldno + 1);
548 return gripe("Header %s doesn't take an index in field %d",
549 ca[res].ca_name, fldno + 1);
552 return gripe("Duplicate header %s in field %d",
553 ca[res].ca_name, fldno + 1);
555 fldca[fldno] = &ca[res];
562 * Record that header ends with ...
563 * Set ellipsis and is_partial.
564 * Return 0 on success, -1 on error.
569 struct castr *ca = ef_cadef(cur_type);
571 if (ca[0].ca_table != cur_type || (ca[0].ca_flags & NSC_EXTRA))
572 return gripe("Table %s doesn't support ...", ef_nameof(cur_type));
577 /* Is table split into parts? */
581 return ellipsis || partno;
585 * Check fields in xdump are sane.
586 * Return 0 on success, -1 on error.
591 struct castr *ca = ef_cadef(cur_type);
592 int i, len, cafldsmax, res = 0;
594 /* Record index must come first, to make cur_id work, see setnum() */
595 if (ca[0].ca_table == cur_type && caflds[0] && fldca[0] != &ca[0])
596 res = gripe("Header field %s must come first", ca[0].ca_name);
599 /* Need a join field, use 0-th selector */
601 res = gripe("Header field %s required in each table part",
606 return res; /* table is split, another part expected */
608 /* Check for missing fields */
609 for (i = 0; ca[i].ca_name; i++) {
610 cafldsmax = MAX(caflds[i], cafldspp[i]);
611 if (ca[i].ca_flags & NSC_EXTRA)
613 len = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
614 if (!len && !cafldsmax)
615 res = gripe("Header field %s missing", ca[i].ca_name);
616 else if (len && cafldsmax == len - 1)
617 res = gripe("Header field %s(%d) missing",
618 ca[i].ca_name, len - 1);
619 else if (len && cafldsmax < len - 1)
620 res = gripe("Header fields %s(%d) ... %s(%d) missing",
621 ca[i].ca_name, cafldsmax, ca[i].ca_name, len - 1);
628 * Get selector for field FLDNO.
629 * Assign the field's selector index to *IDX, unless it is null.
630 * Return the selector on success, null pointer on error.
632 static struct castr *
633 getfld(int fldno, int *idx)
635 if (fldno >= nflds) {
636 gripe("Too many fields, expected only %d", nflds);
639 if (CANT_HAPPEN(fldno < 0))
642 *idx = fldidx[fldno];
647 * Is a new value for field FLDNO required to match the old one?
650 fldval_must_match(int fldno)
652 struct castr *ca = ef_cadef(cur_type);
653 int i = fldca[fldno] - ca;
656 * Value must match if:
657 * it's for a const selector, unless the object is still blank, or
658 * it was already given in a previous part of a split table.
660 return (!cur_obj_is_blank && (fldca[fldno]->ca_flags & NSC_CONST))
661 || fldidx[fldno] < cafldspp[i];
665 * Set value of field FLDNO in current object to DBL.
666 * Return 1 on success, -1 on error.
669 setnum(int fldno, double dbl)
676 ca = getfld(fldno, &idx);
681 if (ca->ca_table == cur_type) {
682 /* Got record index */
685 return gripe("Field %d can't hold this value", fldno + 1);
686 if (tbl_skip_to_obj(next_id) < 0)
689 if (tbl_next_obj() < 0)
694 memb_ptr += ca->ca_off;
696 switch (ca->ca_type) {
698 old = ((signed char *)memb_ptr)[idx];
699 new = ((signed char *)memb_ptr)[idx] = (signed char)dbl;
703 old = ((unsigned char *)memb_ptr)[idx];
704 new = ((unsigned char *)memb_ptr)[idx] = (unsigned char)dbl;
707 old = ((short *)memb_ptr)[idx];
708 new = ((short *)memb_ptr)[idx] = (short)dbl;
711 old = ((unsigned short *)memb_ptr)[idx];
712 new = ((unsigned short *)memb_ptr)[idx] = (unsigned short)dbl;
715 old = ((int *)memb_ptr)[idx];
716 new = ((int *)memb_ptr)[idx] = (int)dbl;
719 old = ((long *)memb_ptr)[idx];
720 new = ((long *)memb_ptr)[idx] = (long)dbl;
723 old = ((coord *)memb_ptr)[idx];
724 /* FIXME use variant of xrel() that takes orig instead of nation */
725 if (old >= WORLD_X / 2)
727 new = ((coord *)memb_ptr)[idx] = XNORM((coord)dbl);
728 if (new >= WORLD_X / 2)
732 old = ((coord *)memb_ptr)[idx];
733 /* FIXME use variant of yrel() that takes orig instead of nation */
734 if (old >= WORLD_Y / 2)
736 new = ((coord *)memb_ptr)[idx] = YNORM((coord)dbl);
737 if (new >= WORLD_Y / 2)
741 old = ((float *)memb_ptr)[idx];
742 ((float *)memb_ptr)[idx] = (float)dbl;
743 new = dbl; /* suppress new != dbl check */
746 old = ((double *)memb_ptr)[idx];
747 ((double *)memb_ptr)[idx] = dbl;
748 new = dbl; /* suppress new != dbl check */
751 old = ((time_t *)memb_ptr)[idx];
752 new = ((time_t *)memb_ptr)[idx] = (time_t)dbl;
755 return gripe("Field %d doesn't take numbers", fldno + 1);
758 if (fldval_must_match(fldno) && old != dbl)
759 return gripe("Value for field %d must be %g", fldno + 1, old);
761 return gripe("Field %d can't hold this value", fldno + 1);
767 * Set value of field FLDNO in current object to STR.
768 * Return 1 on success, -1 on error.
771 setstr(int fldno, char *str)
776 char *memb_ptr, *old;
778 ca = getfld(fldno, &idx);
783 if (tbl_next_obj() < 0)
787 memb_ptr += ca->ca_off;
788 must_match = fldval_must_match(fldno);
790 switch (ca->ca_type) {
792 old = ((char **)memb_ptr)[idx];
794 /* FIXME may leak old value */
795 ((char **)memb_ptr)[idx] = str ? strdup(str) : NULL;
796 len = 65535; /* really SIZE_MAX, but that's C99 */
799 if (CANT_HAPPEN(idx))
802 return gripe("Field %d doesn't take nil", fldno + 1);
804 if (strlen(str) > len)
805 return gripe("Field %d takes at most %d characters",
806 fldno + 1, (int)len);
809 strncpy(memb_ptr, str, len);
812 return gripe("Field %d doesn't take strings", fldno + 1);
816 if (old && (!str || strncmp(old, str, len)))
817 return gripe("Value for field %d must be \"%.*s\"",
818 fldno + 1, (int)len, old);
820 return gripe("Value for field %d must be nil", fldno + 1);
827 * Resolve symbol name ID in table referred to by CA.
828 * Use field number N for error messages.
829 * Return index in referred table on success, -1 on failure.
832 xunsymbol(char *id, struct castr *ca, int n)
834 int i = ef_elt_byname(ca->ca_table, id);
836 return gripe("%s %s symbol `%s' in field %d",
837 i == M_NOTUNIQUE ? "Ambiguous" : "Unknown",
838 ca->ca_name, id, n + 1);
843 * Map symbol index to symbol value.
844 * CA is the table, and I is the index in it.
847 symval(struct castr *ca, int i)
849 int type = ca->ca_table;
851 if (type != EF_BAD && ef_cadef(type) == symbol_ca)
852 /* symbol table, value is in the table */
853 return ((struct symbol *)ef_ptr(type, i))->value;
854 /* value is the table index */
859 * Set value of field FLDNO in current object to value of symbol SYM.
860 * Return 1 on success, -1 on error.
863 setsym(int fldno, char *sym)
868 ca = getfld(fldno, NULL);
872 if (ca->ca_table == EF_BAD || (ca->ca_flags & NSC_BITS))
873 return gripe("Field %d doesn't take symbols", fldno + 1);
875 i = xunsymbol(sym, ca, fldno);
878 return setnum(fldno, symval(ca, i));
882 * Create an empty symbol set for field FLDNO in *SET.
883 * Return 1 on success, -1 on error.
886 mtsymset(int fldno, long *set)
890 ca = getfld(fldno, NULL);
894 if (ca->ca_table == EF_BAD || ef_cadef(ca->ca_table) != symbol_ca
895 || !(ca->ca_flags & NSC_BITS))
896 return gripe("Field %d doesn't take symbol sets", fldno + 1);
902 * Add a symbol to a symbol set for field FLDNO in *SET.
903 * SYM is the name of the symbol to add.
904 * Return 1 on success, -1 on error.
907 add2symset(int fldno, long *set, char *sym)
912 ca = getfld(fldno, NULL);
916 i = xunsymbol(sym, ca, fldno);
919 *set |= symval(ca, i);
924 * Read an xdump table header line from FP.
925 * Expect header for EXPECTED_TABLE, unless it is EF_BAD.
926 * Recognize header for machine- and human-readable syntax, and set
928 * Return table type on success, -2 on EOF before header, -1 on failure.
931 xuheader(FILE *fp, int expected_table)
937 while ((ch = skipfs(fp)) == '\n')
939 if (ch == EOF && expected_table == EF_BAD)
946 ? fscanf(fp, "config%*[ \t]%63[^ \t#\n]%n", name, &res) != 1
947 : fscanf(fp, "XDUMP%*[ \t]%63[^ \t#\n]%*[ \t]%*[^ \t#\n]%n",
948 name, &res) != 1) || res < 0)
949 return gripe("Expected xdump header");
951 type = ef_byname(name);
953 return gripe("Unknown table `%s'", name);
954 if (expected_table != EF_BAD && expected_table != type)
955 return gripe("Expected table `%s', not `%s'",
956 ef_nameof(expected_table), name);
958 if (!empfile[type].file
959 || !ef_cadef(type) || !(ef_flags(type) & EFF_MEM)) {
960 CANT_HAPPEN(expected_table != EF_BAD);
961 return gripe("Table `%s' is not permitted here", name);
964 if (skipfs(fp) != '\n')
965 return gripe("Junk after xdump header");
972 * Find fields in this xdump.
973 * If reading human-readable syntax, read a field header line from FP.
974 * Else take fields from the table's selectors in CA[].
975 * Set ellipsis, nflds, fldca[], fldidx[] and caflds[] accordingly.
976 * Return 0 on success, -1 on failure.
979 xufldhdr(FILE *fp, struct castr ca[])
985 for (i = 0; ca[i].ca_name; i++)
990 while ((ch = skipfs(fp)) == '\n')
993 nflds = xuflds(fp, xufldname);
996 nflds -= ellipsis != 0;
1001 for (i = 0; ca[i].ca_name; i++) {
1002 if ((ca[i].ca_flags & NSC_EXTRA))
1004 n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
1012 nflds = fidx - fldidx;
1019 * Read xdump footer from FP.
1020 * CA[] contains the table's selectors.
1021 * The body had RECS records.
1022 * Update cafldspp[] from caflds[].
1023 * Return 0 on success, -1 on failure.
1026 xufooter(FILE *fp, struct castr ca[], int recs)
1032 if (fscanf(fp, "config%n", &res) != 0 || res < 0)
1033 return gripe("Malformed table footer");
1035 if (fscanf(fp, "%d", &n) != 1)
1036 return gripe("Malformed table footer");
1038 return gripe("Read %d rows, which doesn't match footer "
1039 "%d rows", recs, n);
1041 if (skipfs(fp) != '\n')
1042 return gripe("Junk after table footer");
1043 if (tbl_part_done() < 0)
1047 for (i = 0; ca[i].ca_name; i++) {
1048 if (cafldspp[i] < caflds[i])
1049 cafldspp[i] = caflds[i];
1056 * Read an xdump table from FP.
1057 * Both machine- and human-readable xdump syntax are recognized.
1058 * Expect table EXPECTED_TABLE, unless it is EF_BAD.
1059 * Report errors to stderr.
1060 * Messages assume FP starts in the file FILE at line *PLNO.
1061 * Update *PLNO to reflect lines read from FP.
1062 * Return table type on success, -2 on EOF before header, -1 on failure.
1065 xundump(FILE *fp, char *file, int *plno, int expected_table)
1068 int type, nca, nf, i, ch;
1073 if ((type = xuheader(fp, expected_table)) < 0)
1076 ca = ef_cadef(type);
1077 if (CANT_HAPPEN(!ca))
1082 may_trunc = empfile[type].nent < 0;
1083 for (i = 0; ca[i].ca_name; i++) {
1085 if (!(ca[i].ca_flags & NSC_EXTRA)) {
1086 nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0);
1087 if (ca[i].ca_flags & NSC_CONST)
1088 may_omit_id = may_trunc = 0;
1091 fldca = malloc(nf * sizeof(*fldca));
1092 fldidx = malloc(nf * sizeof(*fldidx));
1093 caflds = malloc(nca * sizeof(*caflds));
1094 cafldspp = calloc(nca, sizeof(*cafldspp));
1097 if (xutail(fp, ca) < 0)
1106 /* Skip empty lines so that callers can easily check for EOF */
1107 while ((ch = skipfs(fp)) == '\n')
1116 * Read the remainder of an xdump after the table header line from FP.
1117 * CA[] contains the table's selectors.
1118 * Return 0 on success, -1 on failure.
1121 xutail(FILE *fp, struct castr *ca)
1126 if (xufldhdr(fp, ca) < 0)
1128 if ((recs = xubody(fp)) < 0)
1130 if (xufooter(fp, ca, recs) < 0)
1134 if (xuheader(fp, cur_type) < 0)
1140 * Read the body of an xdump table from FP.
1141 * Return number of rows read on success, -1 on failure.
1149 while ((ch = skipfs(fp)) == '\n')
1154 if (xuflds(fp, xufld) < 0)