From cfa0eac32aabd0d44786172bfe2ecdac9a6a41bf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 8 Feb 2014 15:11:51 +0100 Subject: [PATCH] xundump: Permit omitting trailing sectors and realms We currently require all rows to be present for tables item, sect-chr, infrastructure, sect, realm. The first three make sense: the code hard-codes indexes for them, and malfunctions when entries are blank, so we want to make it hard to leave any blank by accident. The last two don't: blank sectors and realms work fine. There, the restriction is arbitrary. Drop it. Sectors and realms still can't be omitted "in the middle" (can do that only with an ID selector), but that's coming soon. See also commit 4a4ec91. Signed-off-by: Markus Armbruster --- src/lib/common/xundump.c | 24 ++++++++++++++++++------ tests/empdump/errors.err | 2 +- tests/empdump/xundump-errors/ftr-fewrows | 4 ++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lib/common/xundump.c b/src/lib/common/xundump.c index cd903ade..b9b8de26 100644 --- a/src/lib/common/xundump.c +++ b/src/lib/common/xundump.c @@ -96,6 +96,16 @@ static int add2symset(int, long *, char *); static int xubody(FILE *); static int xutail(FILE *, struct castr *); +/* + * Does the code hardcode indexes for table TYPE? + */ +static int +have_hardcoded_indexes(int type) +{ + return type == EF_ITEM || type == EF_SECTOR_CHR + || type == EF_INFRASTRUCTURE; +} + /* * Gripe about the current line to stderr, return -1. */ @@ -1053,16 +1063,18 @@ xundump(FILE *fp, char *file, int *plno, int expected_table) if (CANT_HAPPEN(!ca)) return -1; + if (have_hardcoded_indexes(type)) { + may_omit_id = may_trunc = 0; + } else { + may_omit_id = 1; + may_trunc = empfile[type].nent < 0; + } + nca = nf = 0; - may_omit_id = 1; - may_trunc = empfile[type].nent < 0; for (i = 0; ca[i].ca_name; i++) { nca++; - if (!(ca[i].ca_flags & NSC_EXTRA)) { + if (!(ca[i].ca_flags & NSC_EXTRA)) nf += MAX(1, CA_ARRAY_LEN(&ca[i])); - if (ca[i].ca_flags & NSC_CONST) - may_omit_id = may_trunc = 0; - } } fldca = malloc(nf * sizeof(*fldca)); fldidx = malloc(nf * sizeof(*fldidx)); diff --git a/tests/empdump/errors.err b/tests/empdump/errors.err index 54258d3a..abc4e324 100644 --- a/tests/empdump/errors.err +++ b/tests/empdump/errors.err @@ -74,7 +74,7 @@ tests/empdump/xundump-errors/fld-unexpid:6: Table's first part doesn't have this 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 +tests/empdump/xundump-errors/ftr-fewrows:2: Expected 34 more rows tests/empdump/xundump-errors/ftr-fewrows2:4: Expected 13 more rows tests/empdump/xundump-errors/ftr-fewrows3:4: Expected 1 more rows tests/empdump/xundump-errors/ftr-fewrows4:7: Expected row with 2 in field 1, like in table's first part diff --git a/tests/empdump/xundump-errors/ftr-fewrows b/tests/empdump/xundump-errors/ftr-fewrows index 0be2020f..b1fbff52 100644 --- a/tests/empdump/xundump-errors/ftr-fewrows +++ b/tests/empdump/xundump-errors/ftr-fewrows @@ -1,3 +1,3 @@ -XDUMP sect 0 +XDUMP sect-chr 0 /0 -# Expected 1024 more rows +# Expected 34 more rows