static int gripe(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
static int deffld(int, char *, int);
-static int defellipsis(void);
static int chkflds(void);
static int setnum(int, double);
static int setstr(int, char *);
return 0;
}
-/*
- * Get the next object.
- * Must not have a record index.
- * Store it in cur_obj, and set cur_id accordingly.
- * Return 0 on success, -1 on failure.
- */
-static int
-tbl_next_obj(void)
-{
- int max_id = ef_id_limit(cur_type);
-
- if (cur_id >= max_id)
- return gripe("Too many rows");
- return tbl_seek(cur_id + 1);
-}
-
/*
* Omit ID1..ID2-1.
* Reset the omitted objects to default state.
/*
* Get the next object, it has record index ID.
* Store it in cur_obj, and set cur_id accordingly.
- * Ensure we're omitting the same objects as the previous parts.
* Reset any omitted objects to default state.
* Return 0 on success, -1 on failure.
*/
static int
tbl_skip_to_obj(int id)
{
- struct empfile *ep = &empfile[cur_type];
int prev_id = cur_id;
- int max_id, exp_id;
+ int max_id;
- if (partno == 0) {
- if (!may_omit_id && 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);
- max_id = ef_id_limit(cur_type);
- if (id > max_id)
- return gripe("Field %d must be <= %d", 1, max_id);
- } else {
- exp_id = expected_id(cur_id + 1, ep->fids);
- if (exp_id < 0)
- return gripe("Table's first part doesn't have this row");
- else if (id != exp_id)
- return gripe("Expected %d in field %d,"
- " like in table's first part",
- exp_id, 1);
- }
+ if (CANT_HAPPEN(partno != 0))
+ return -1;
+ if (!may_omit_id && 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);
+ max_id = ef_id_limit(cur_type);
+ if (id > max_id)
+ return gripe("Field %d must be <= %d", 1, max_id);
if (tbl_seek(id) < 0)
return -1;
- if (partno == 0)
- omit_ids(prev_id + 1, id);
+ omit_ids(prev_id + 1, id);
return 0;
}
+/*
+ * Get the next object.
+ * Store it in cur_obj, and set cur_id accordingly.
+ * Return 0 on success, -1 on failure.
+ */
+static int
+tbl_next_obj(void)
+{
+ int next_id;
+
+ if (partno == 0) {
+ if (cur_id >= ef_id_limit(cur_type))
+ return gripe("Too many rows");
+ next_id = cur_id + 1;
+ } else {
+ next_id = expected_id(cur_id + 1, empfile[cur_type].fids);
+ if (next_id < 0)
+ return gripe("Table's first part doesn't have this row");
+ }
+ return tbl_seek(next_id);
+}
+
/*
* Finish table part.
* If the table has variable length, truncate it.
case '.':
if (getc(fp) != '.' || getc(fp) != '.')
return gripe("Junk in header field %d", i + 1);
- if (defellipsis() < 0)
- return -1;
+ if (i == 0)
+ return gripe("Header fields expected");
+ ellipsis = 1;
ch = skipfs(fp);
if (ch != EOF && ch != '\n')
return gripe("Junk after ...");
return 1;
}
-/*
- * Record that header ends with ...
- * Set ellipsis and is_partial.
- * Return 0 on success, -1 on error.
- */
-static int
-defellipsis(void)
-{
- struct castr *ca = ef_cadef(cur_type);
-
- if (ca[0].ca_table != cur_type || (ca[0].ca_flags & NSC_EXTRA))
- return gripe("Table %s doesn't support ...", ef_nameof(cur_type));
- ellipsis = 1;
- return 0;
-}
-
-/* Is table split into parts? */
-static int
-is_partial(void)
-{
- return ellipsis || partno;
-}
-
/*
* Check fields in xdump are sane.
* Return 0 on success, -1 on error.
if (ca[0].ca_table == cur_type && caflds[0] && fldca[0] != &ca[0])
res = gripe("Header field %s must come first", ca[0].ca_name);
- if (is_partial()) {
- /* Need a join field, use 0-th selector */
- if (!caflds[0])
- res = gripe("Header field %s required in each table part",
- ca[0].ca_name);
- }
-
if (ellipsis)
return res; /* table is split, another part expected */
return -1;
if (fldno == 0) {
- if (ca->ca_table == cur_type) {
+ if (partno == 0 && ca->ca_table == cur_type) {
/* Got record index */
next_id = (int)dbl;
if (next_id != dbl)
tests/empdump/xundump-errors/colhdr-dup:2: Duplicate header name in field 2
tests/empdump/xundump-errors/colhdr-dup2:6: Duplicate header name in field 3
tests/empdump/xundump-errors/colhdr-dup3:2: Duplicate header pkg(0) in field 8
-tests/empdump/xundump-errors/colhdr-ellipsis:2: Header field uid required in each table part
+tests/empdump/xundump-errors/colhdr-ellipsis:2: Header fields expected
tests/empdump/xundump-errors/colhdr-ellipsis2:2: Junk after ...
-tests/empdump/xundump-errors/colhdr-ellipsis3:2: Table infrastructure doesn't support ...
-tests/empdump/xundump-errors/colhdr-ellipsis4:2: Header field uid required in each table part
-tests/empdump/xundump-errors/colhdr-ellipsis5:2: Table sect doesn't support ...
tests/empdump/xundump-errors/colhdr-eof:2: Unexpected EOF
tests/empdump/xundump-errors/colhdr-first:2: Header field uid must come first
tests/empdump/xundump-errors/colhdr-idxbig:2: Header pkg(99) index out of bounds in field 7
tests/empdump/xundump-errors/colhdr-miss:2: Header field ctype(2) missing
tests/empdump/xundump-errors/colhdr-miss:2: Header fields camt(0) ... camt(2) missing
tests/empdump/xundump-errors/colhdr-miss:2: Header field nllag missing
-tests/empdump/xundump-errors/colhdr-miss2:21: Header field uid required in each table part
tests/empdump/xundump-errors/colhdr-miss2:21: Header fields ctype(0) ... ctype(2) missing
tests/empdump/xundump-errors/colhdr-miss2:21: Header fields camt(0) ... camt(2) missing
tests/empdump/xundump-errors/colhdr-miss2:21: Header field type missing
tests/empdump/xundump-errors/fld-sep:2: Bad field separator after field 1
tests/empdump/xundump-errors/fld-strbig:3: Field 19 takes at most 9 characters
tests/empdump/xundump-errors/fld-unexpid:6: Table's first part doesn't have this row
-tests/empdump/xundump-errors/fld-unexpid1:7: Expected 2 in field 1, like in table's first part
+tests/empdump/xundump-errors/fld-unexpid1:7: Value for field 1 must be 2
tests/empdump/xundump-errors/fld-unksym:2: Unknown level symbol `xxx' in field 11
tests/empdump/xundump-errors/fld-unparen:2: Unmatched '(' in field 19
tests/empdump/xundump-errors/ftr-fewrows:2: Expected 1024 more rows