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 * - 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 */
73 static int cur_obj_is_blank;
74 static unsigned char *idgap; /* idgap && idgap[ID] iff part#0 lacks ID */
75 static int idgap_max; /* FIXME */
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. */
129 /* End the current table. */
138 * Seek to current table's ID-th record.
139 * ID must be acceptable.
140 * Store it in cur_obj, and set cur_id and cur_obj_is_blank accordingly.
141 * Return 0 on success, -1 on failure.
146 struct empfile *ep = &empfile[cur_type];
148 cur_obj_is_blank = id >= ep->fids;
150 if (id >= ef_nelem(cur_type)) {
151 if (!ef_ensure_space(cur_type, id, 1))
152 return gripe("Can't put ID %d into table %s", id, ep->name);
155 cur_obj = ef_ptr(cur_type, id);
156 if (CANT_HAPPEN(!cur_obj))
163 * Get the next object.
164 * Must not have a record index.
165 * Store it in cur_obj, and set cur_id and cur_obj_is_blank accordingly.
166 * Return 0 on success, -1 on failure.
171 int max_id = ef_id_limit(cur_type);
173 if (cur_id >= max_id)
174 return gripe("Too many rows");
175 return tbl_seek(cur_id + 1);
182 omit_ids(int id1, int id2)
189 idgap = realloc(idgap, (id2 + 1) * sizeof(*idgap));
190 for (i = idgap_max; i < id1; i++)
192 for (i = id1; i < id2; i++)
199 * Return the smallest non-omitted ID in ID1..ID2-1 if any, else -1.
202 expected_id(int id1, int id2)
206 for (i = id1; i < id2; i++) {
207 if (i >= idgap_max || !idgap[i])
214 * Get the next object, it has record index ID.
215 * Store it in cur_obj, and set cur_id and cur_obj_is_blank accordingly.
216 * Ensure we're omitting the same objects as the previous parts.
217 * Return 0 on success, -1 on failure.
220 tbl_skip_to_obj(int id)
222 struct empfile *ep = &empfile[cur_type];
223 int prev_id = cur_id;
227 if (!may_omit_id && id != cur_id + 1)
228 return gripe("Expected %d in field %d", cur_id + 1, 1);
230 return gripe("Field %d must be > %d", 1, cur_id);
231 max_id = ef_id_limit(cur_type);
233 return gripe("Field %d must be <= %d", 1, max_id);
235 exp_id = expected_id(cur_id + 1, ep->fids);
237 return gripe("Table's first part doesn't have this row");
238 else if (id != exp_id)
239 return gripe("Expected %d in field %d,"
240 " like in table's first part",
244 if (tbl_seek(id) < 0)
248 omit_ids(prev_id + 1, id);
254 * If the table has variable length, truncate it.
255 * Else ensure we're omitting the same objects as the previous parts.
256 * Return 0 on success, -1 on failure.
261 struct empfile *ep = &empfile[cur_type];
264 if (cur_id + 1 < ep->fids) {
267 if (!ef_truncate(cur_type, cur_id + 1))
271 return gripe("Expected %d more rows",
272 ep->fids - (cur_id + 1));
273 omit_ids(cur_id + 1, ep->fids);
276 exp_id = expected_id(cur_id + 1, ep->fids);
278 return gripe("Expected row with %d in field %d,"
279 " like in table's first part",
291 * Read and ignore field separators from FP.
292 * Return first character that is not a field separator.
301 } while (ch == ' ' || ch == '\t');
306 } while (ch != EOF && ch != '\n');
313 * Decode escape sequences in BUF.
314 * Return BUF on success, null pointer on failure.
326 if (sscanf(++src, "%3o%n", &octal_chr, &n) != 1 || n != 3)
328 *dst++ = (char)octal_chr;
338 * Read an identifier from FP into BUF.
339 * BUF must have space for 1024 characters.
340 * Return number of characters read on success, -1 on failure.
343 getid(FILE *fp, char *buf)
346 if (fscanf(fp, "%1023[^\"#()<>= \t\n]%n", buf, &n) != 1
354 * Try to read a field name from FP.
355 * I is the field number, counting from zero.
356 * If a name is read, set fldca[I] and fldidx[I] for it, and update
358 * Return 1 if a name or ... was read, 0 on end of line, -1 on error.
361 xufldname(FILE *fp, int i)
369 return gripe("Unexpected EOF");
376 if (getc(fp) != '.' || getc(fp) != '.')
377 return gripe("Junk in header field %d", i + 1);
378 if (defellipsis() < 0)
381 if (ch != EOF && ch != '\n')
382 return gripe("Junk after ...");
387 if (getid(fp, buf) < 0)
388 return gripe("Junk in header field %d", i + 1);
392 return deffld(i, buf, -1);
396 if (isdigit(ch) || ch == '-' || ch == '+') {
397 if (fscanf(fp, "%d", &idx) != 1)
398 return gripe("Malformed number in index of header field %d",
401 return gripe("Index must not be negative in header field %d",
404 if (getid(fp, buf) < 0)
405 return gripe("Malformed index in header field %d", i + 1);
406 return gripe("Symbolic index in header field %d not yet implemented",
411 return gripe("Malformed index in header field %d", i + 1);
412 return deffld(i, buf, idx);
417 * Try to read a field value from FP.
418 * I is the field number, counting from zero.
419 * Return 1 if a value was read, 0 on end of line, -1 on error.
422 xufld(FILE *fp, int i)
432 return gripe("Unexpected EOF");
434 CANT_HAPPEN(i > nflds);
436 if (fldca[i]->ca_type != NSC_STRINGY && fldca[i]->ca_len)
437 return gripe("Field %s(%d) missing",
438 fldca[i]->ca_name, fldidx[i]);
439 return gripe("Field %s missing", fldca[i]->ca_name);
443 case '+': case '-': case '.':
444 case '0': case '1': case '2': case '3': case '4':
445 case '5': case '6': case '7': case '8': case '9':
447 if (fscanf(fp, "%lg", &dbl) != 1)
448 return gripe("Malformed number in field %d", i + 1);
449 return setnum(i, dbl);
456 if (fscanf(fp, "%1023[^\"\n]", buf) != 1 || getc(fp) != '"')
457 return gripe("Malformed string in field %d", i + 1);
459 return gripe("Invalid escape sequence in field %d",
462 return setstr(i, buf);
464 if (mtsymset(i, &set) < 0)
468 if (ch == EOF || ch == '\n')
469 return gripe("Unmatched '(' in field %d", i + 1);
473 if (getid(fp, buf) < 0)
474 return gripe("Junk in field %d", i + 1);
475 if (add2symset(i, &set, buf) < 0)
478 return setnum(i, set);
481 if (getid(fp, buf) < 0)
482 return gripe("Junk in field %d", i + 1);
483 if (!strcmp(buf, "nil"))
484 return setstr(i, NULL);
486 return setsym(i, buf);
491 * Read fields from FP.
492 * Use PARSE() to read each field.
493 * Return number of fields read on success, -1 on error.
496 xuflds(FILE *fp, int (*parse)(FILE *, int))
509 else if (ch != ' ' && ch != '\t')
510 return gripe("Bad field separator after field %d", i + 1);
515 * Define the FLDNO-th field.
516 * If IDX is negative, define as selector NAME, else as NAME(IDX).
517 * Set fldca[FLDNO] and fldidx[FLDNO] accordingly.
519 * Return 1 on success, -1 on error.
522 deffld(int fldno, char *name, int idx)
524 struct castr *ca = ef_cadef(cur_type);
527 res = stmtch(name, ca, offsetof(struct castr, ca_name),
528 sizeof(struct castr));
530 return gripe("Header %s of field %d is %s", name, fldno + 1,
531 res == M_NOTUNIQUE ? "ambiguous" : "unknown");
532 if ((ca[res].ca_flags & NSC_EXTRA) || CANT_HAPPEN(ca[res].ca_get))
533 return gripe("Extraneous header %s in field %d", name, fldno + 1);
534 if (ca[res].ca_type != NSC_STRINGY && ca[res].ca_len != 0) {
536 return gripe("Header %s requires an index in field %d",
537 ca[res].ca_name, fldno + 1);
538 if (idx >= ca[res].ca_len)
539 return gripe("Header %s(%d) index out of bounds in field %d",
540 ca[res].ca_name, idx, fldno + 1);
541 if (idx < caflds[res])
542 return gripe("Duplicate header %s(%d) in field %d",
543 ca[res].ca_name, idx, fldno + 1);
544 if (idx > caflds[res])
545 return gripe("Expected header %s(%d) in field %d",
546 ca[res].ca_name, caflds[res], fldno + 1);
549 return gripe("Header %s doesn't take an index in field %d",
550 ca[res].ca_name, fldno + 1);
553 return gripe("Duplicate header %s in field %d",
554 ca[res].ca_name, fldno + 1);
556 fldca[fldno] = &ca[res];
563 * Record that header ends with ...
564 * Set ellipsis and is_partial.
565 * Return 0 on success, -1 on error.
570 struct castr *ca = ef_cadef(cur_type);
572 if (ca[0].ca_table != cur_type || (ca[0].ca_flags & NSC_EXTRA))
573 return gripe("Table %s doesn't support ...", ef_nameof(cur_type));
578 /* Is table split into parts? */
582 return ellipsis || partno;
586 * Check fields in xdump are sane.
587 * Return 0 on success, -1 on error.
592 struct castr *ca = ef_cadef(cur_type);
593 int i, len, cafldsmax, res = 0;
595 /* Record index must come first, to make cur_id work, see setnum() */
596 if (ca[0].ca_table == cur_type && caflds[0] && fldca[0] != &ca[0])
597 res = gripe("Header field %s must come first", ca[0].ca_name);
600 /* Need a join field, use 0-th selector */
602 res = gripe("Header field %s required in each table part",
607 return res; /* table is split, another part expected */
609 /* Check for missing fields */
610 for (i = 0; ca[i].ca_name; i++) {
611 cafldsmax = MAX(caflds[i], cafldspp[i]);
612 if (ca[i].ca_flags & NSC_EXTRA)
614 len = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
615 if (!len && !cafldsmax)
616 res = gripe("Header field %s missing", ca[i].ca_name);
617 else if (len && cafldsmax == len - 1)
618 res = gripe("Header field %s(%d) missing",
619 ca[i].ca_name, len - 1);
620 else if (len && cafldsmax < len - 1)
621 res = gripe("Header fields %s(%d) ... %s(%d) missing",
622 ca[i].ca_name, cafldsmax, ca[i].ca_name, len - 1);
629 * Get selector for field FLDNO.
630 * Assign the field's selector index to *IDX, unless it is null.
631 * Return the selector on success, null pointer on error.
633 static struct castr *
634 getfld(int fldno, int *idx)
636 if (fldno >= nflds) {
637 gripe("Too many fields, expected only %d", nflds);
640 if (CANT_HAPPEN(fldno < 0))
643 *idx = fldidx[fldno];
648 * Is a new value for field FLDNO required to match the old one?
651 fldval_must_match(int fldno)
653 struct castr *ca = ef_cadef(cur_type);
654 int i = fldca[fldno] - ca;
657 * Value must match if:
658 * it's for a const selector, unless the object is still blank, or
659 * it was already given in a previous part of a split table.
661 return (!cur_obj_is_blank && (fldca[fldno]->ca_flags & NSC_CONST))
662 || fldidx[fldno] < cafldspp[i];
666 * Set value of field FLDNO in current object to DBL.
667 * Return 1 on success, -1 on error.
670 setnum(int fldno, double dbl)
677 ca = getfld(fldno, &idx);
682 if (ca->ca_table == cur_type) {
683 /* Got record index */
686 return gripe("Field %d can't hold this value", fldno + 1);
687 if (tbl_skip_to_obj(next_id) < 0)
690 if (tbl_next_obj() < 0)
695 memb_ptr += ca->ca_off;
697 switch (ca->ca_type) {
699 old = ((signed char *)memb_ptr)[idx];
700 new = ((signed char *)memb_ptr)[idx] = (signed char)dbl;
704 old = ((unsigned char *)memb_ptr)[idx];
705 new = ((unsigned char *)memb_ptr)[idx] = (unsigned char)dbl;
708 old = ((short *)memb_ptr)[idx];
709 new = ((short *)memb_ptr)[idx] = (short)dbl;
712 old = ((unsigned short *)memb_ptr)[idx];
713 new = ((unsigned short *)memb_ptr)[idx] = (unsigned short)dbl;
716 old = ((int *)memb_ptr)[idx];
717 new = ((int *)memb_ptr)[idx] = (int)dbl;
720 old = ((long *)memb_ptr)[idx];
721 new = ((long *)memb_ptr)[idx] = (long)dbl;
724 old = ((coord *)memb_ptr)[idx];
725 /* FIXME use variant of xrel() that takes orig instead of nation */
726 if (old >= WORLD_X / 2)
728 new = ((coord *)memb_ptr)[idx] = XNORM((coord)dbl);
729 if (new >= WORLD_X / 2)
733 old = ((coord *)memb_ptr)[idx];
734 /* FIXME use variant of yrel() that takes orig instead of nation */
735 if (old >= WORLD_Y / 2)
737 new = ((coord *)memb_ptr)[idx] = YNORM((coord)dbl);
738 if (new >= WORLD_Y / 2)
742 old = ((float *)memb_ptr)[idx];
743 ((float *)memb_ptr)[idx] = (float)dbl;
744 new = dbl; /* suppress new != dbl check */
747 old = ((double *)memb_ptr)[idx];
748 ((double *)memb_ptr)[idx] = dbl;
749 new = dbl; /* suppress new != dbl check */
752 old = ((time_t *)memb_ptr)[idx];
753 new = ((time_t *)memb_ptr)[idx] = (time_t)dbl;
756 return gripe("Field %d doesn't take numbers", fldno + 1);
759 if (fldval_must_match(fldno) && old != dbl)
760 return gripe("Value for field %d must be %g", fldno + 1, old);
762 return gripe("Field %d can't hold this value", fldno + 1);
768 * Set value of field FLDNO in current object to STR.
769 * Return 1 on success, -1 on error.
772 setstr(int fldno, char *str)
777 char *memb_ptr, *old;
779 ca = getfld(fldno, &idx);
784 if (tbl_next_obj() < 0)
788 memb_ptr += ca->ca_off;
789 must_match = fldval_must_match(fldno);
791 switch (ca->ca_type) {
793 old = ((char **)memb_ptr)[idx];
795 /* FIXME may leak old value */
796 ((char **)memb_ptr)[idx] = str ? strdup(str) : NULL;
797 len = 65535; /* really SIZE_MAX, but that's C99 */
800 if (CANT_HAPPEN(idx))
803 return gripe("Field %d doesn't take nil", fldno + 1);
805 if (strlen(str) > len)
806 return gripe("Field %d takes at most %d characters",
807 fldno + 1, (int)len);
810 strncpy(memb_ptr, str, len);
813 return gripe("Field %d doesn't take strings", fldno + 1);
817 if (old && (!str || strncmp(old, str, len)))
818 return gripe("Value for field %d must be \"%.*s\"",
819 fldno + 1, (int)len, old);
821 return gripe("Value for field %d must be nil", fldno + 1);
828 * Resolve symbol name ID in table referred to by CA.
829 * Use field number N for error messages.
830 * Return index in referred table on success, -1 on failure.
833 xunsymbol(char *id, struct castr *ca, int n)
835 int i = ef_elt_byname(ca->ca_table, id);
837 return gripe("%s %s symbol `%s' in field %d",
838 i == M_NOTUNIQUE ? "Ambiguous" : "Unknown",
839 ca->ca_name, id, n + 1);
844 * Map symbol index to symbol value.
845 * CA is the table, and I is the index in it.
848 symval(struct castr *ca, int i)
850 int type = ca->ca_table;
852 if (type != EF_BAD && ef_cadef(type) == symbol_ca)
853 /* symbol table, value is in the table */
854 return ((struct symbol *)ef_ptr(type, i))->value;
855 /* value is the table index */
860 * Set value of field FLDNO in current object to value of symbol SYM.
861 * Return 1 on success, -1 on error.
864 setsym(int fldno, char *sym)
869 ca = getfld(fldno, NULL);
873 if (ca->ca_table == EF_BAD || (ca->ca_flags & NSC_BITS))
874 return gripe("Field %d doesn't take symbols", fldno + 1);
876 i = xunsymbol(sym, ca, fldno);
879 return setnum(fldno, symval(ca, i));
883 * Create an empty symbol set for field FLDNO in *SET.
884 * Return 1 on success, -1 on error.
887 mtsymset(int fldno, long *set)
891 ca = getfld(fldno, NULL);
895 if (ca->ca_table == EF_BAD || ef_cadef(ca->ca_table) != symbol_ca
896 || !(ca->ca_flags & NSC_BITS))
897 return gripe("Field %d doesn't take symbol sets", fldno + 1);
903 * Add a symbol to a symbol set for field FLDNO in *SET.
904 * SYM is the name of the symbol to add.
905 * Return 1 on success, -1 on error.
908 add2symset(int fldno, long *set, char *sym)
913 ca = getfld(fldno, NULL);
917 i = xunsymbol(sym, ca, fldno);
920 *set |= symval(ca, i);
925 * Read an xdump table header line from FP.
926 * Expect header for EXPECTED_TABLE, unless it is EF_BAD.
927 * Recognize header for machine- and human-readable syntax, and set
929 * Return table type on success, -2 on EOF before header, -1 on failure.
932 xuheader(FILE *fp, int expected_table)
938 while ((ch = skipfs(fp)) == '\n')
940 if (ch == EOF && expected_table == EF_BAD)
947 ? fscanf(fp, "config%*[ \t]%63[^ \t#\n]%n", name, &res) != 1
948 : fscanf(fp, "XDUMP%*[ \t]%63[^ \t#\n]%*[ \t]%*[^ \t#\n]%n",
949 name, &res) != 1) || res < 0)
950 return gripe("Expected xdump header");
952 type = ef_byname(name);
954 return gripe("Unknown table `%s'", name);
955 if (expected_table != EF_BAD && expected_table != type)
956 return gripe("Expected table `%s', not `%s'",
957 ef_nameof(expected_table), name);
959 if (!empfile[type].file
960 || !ef_cadef(type) || !(ef_flags(type) & EFF_MEM)) {
961 CANT_HAPPEN(expected_table != EF_BAD);
962 return gripe("Table `%s' is not permitted here", name);
965 if (skipfs(fp) != '\n')
966 return gripe("Junk after xdump header");
973 * Find fields in this xdump.
974 * If reading human-readable syntax, read a field header line from FP.
975 * Else take fields from the table's selectors in CA[].
976 * Set ellipsis, nflds, fldca[], fldidx[] and caflds[] accordingly.
977 * Return 0 on success, -1 on failure.
980 xufldhdr(FILE *fp, struct castr ca[])
986 for (i = 0; ca[i].ca_name; i++)
991 while ((ch = skipfs(fp)) == '\n')
994 nflds = xuflds(fp, xufldname);
997 nflds -= ellipsis != 0;
1002 for (i = 0; ca[i].ca_name; i++) {
1003 if ((ca[i].ca_flags & NSC_EXTRA))
1005 n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
1013 nflds = fidx - fldidx;
1020 * Read xdump footer from FP.
1021 * CA[] contains the table's selectors.
1022 * The body had RECS records.
1023 * Update cafldspp[] from caflds[].
1024 * Return 0 on success, -1 on failure.
1027 xufooter(FILE *fp, struct castr ca[], int recs)
1033 if (fscanf(fp, "config%n", &res) != 0 || res < 0)
1034 return gripe("Malformed table footer");
1036 if (fscanf(fp, "%d", &n) != 1)
1037 return gripe("Malformed table footer");
1039 return gripe("Read %d rows, which doesn't match footer "
1040 "%d rows", recs, n);
1042 if (skipfs(fp) != '\n')
1043 return gripe("Junk after table footer");
1044 if (tbl_part_done() < 0)
1048 for (i = 0; ca[i].ca_name; i++) {
1049 if (cafldspp[i] < caflds[i])
1050 cafldspp[i] = caflds[i];
1057 * Read an xdump table from FP.
1058 * Both machine- and human-readable xdump syntax are recognized.
1059 * Expect table EXPECTED_TABLE, unless it is EF_BAD.
1060 * Report errors to stderr.
1061 * Messages assume FP starts in the file FILE at line *PLNO.
1062 * Update *PLNO to reflect lines read from FP.
1063 * Return table type on success, -2 on EOF before header, -1 on failure.
1066 xundump(FILE *fp, char *file, int *plno, int expected_table)
1069 int type, nca, nf, i, ch;
1074 if ((type = xuheader(fp, expected_table)) < 0)
1077 ca = ef_cadef(type);
1078 if (CANT_HAPPEN(!ca))
1083 may_trunc = empfile[type].nent < 0;
1084 for (i = 0; ca[i].ca_name; i++) {
1086 if (!(ca[i].ca_flags & NSC_EXTRA)) {
1087 nf += MAX(1, ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0);
1088 if (ca[i].ca_flags & NSC_CONST)
1089 may_omit_id = may_trunc = 0;
1092 fldca = malloc(nf * sizeof(*fldca));
1093 fldidx = malloc(nf * sizeof(*fldidx));
1094 caflds = malloc(nca * sizeof(*caflds));
1095 cafldspp = calloc(nca, sizeof(*cafldspp));
1098 if (xutail(fp, ca) < 0)
1107 /* Skip empty lines so that callers can easily check for EOF */
1108 while ((ch = skipfs(fp)) == '\n')
1117 * Read the remainder of an xdump after the table header line from FP.
1118 * CA[] contains the table's selectors.
1119 * Return 0 on success, -1 on failure.
1122 xutail(FILE *fp, struct castr *ca)
1127 if (xufldhdr(fp, ca) < 0)
1129 if ((recs = xubody(fp)) < 0)
1131 if (xufooter(fp, ca, recs) < 0)
1135 if (xuheader(fp, cur_type) < 0)
1141 * Read the body of an xdump table from FP.
1142 * Return number of rows read on success, -1 on failure.
1150 while ((ch = skipfs(fp)) == '\n')
1155 if (xuflds(fp, xufld) < 0)