Commit graph

93 commits

Author SHA1 Message Date
c36cae7a64 Make xundump capable of extending tables
Use ef_ensure_space() in getobj().  This also makes sure objects are
properly initialized before undumping writes to them.

Clean up how sentinels are appended: instead of keeping its slot
reserved while undumping, keep it in the table, and strip it off when
done.
2008-02-26 21:07:57 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
fe602d00d6 Comments. 2007-09-02 18:01:15 +00:00
4b2afc1e95 (xufooter, xubody): Rename some variables. No functional change. 2007-08-05 18:58:36 +00:00
9394ca0630 (xundump): Use malloc() instead of calloc() for fldca and fldidx,
because the used part of these arrays is explicitely initialized by
deffld().
2007-08-05 18:52:16 +00:00
5e65a9dd3c (xufld): Clarify. 2007-08-05 18:47:51 +00:00
b72068a49b (xufldname): Don't bother to catch ... in field 1, because the check
for the required join field catches that.
2007-08-05 18:46:04 +00:00
7d88a783de (defellipsis): Set ellipsis to 1 instead of field number, because all
uses just compare to 0.  Parameter now unused, remove.  Caller
changed.
2007-08-05 18:42:24 +00:00
bfee6962fc Fix fields checks for split tables:
(caseen): Remove.
(xufldhdr, deffld): Record only fields in this part in caflds[].  This
fixes the check for duplicate fields in parts other than the first.
(cafldspp): New, to record fields in previous parts.
(xundump): Initialize and finalize it.
(xufooter): Update it.  Requires new parameter ca.  Caller changed.
(fldval_must_match): Use it to do the right thing for split arrays.
(chkflds): Adapt for changed caflds[].
(chkflds): The check for missing fields was skipped for all parts of a
split table instead of for all but the final part.
2007-08-05 18:38:37 +00:00
26d45adf8a (xufldhdr): ellipsis wasn't cleared for machine-readable input. This
broke reading machine-readable input after reading a split table
failed before seeing the last part.  Luckily, callers never tried
that.
2007-08-05 18:23:09 +00:00
6e2a666882 (xutail): Remove parameter type. Use cur_type instead. Caller
changed.
2007-08-05 17:36:01 +00:00
b8b231be42 (getobj, setnum): Move override of cur_id from getobj() to setnum().
Remove the now unused parameters of getobj().  Callers changed.
2007-08-05 17:34:24 +00:00
94324f7966 (xuheader1, xufldhdr, xutrailer, xufooter, xundump2, xutail)
(xundump1, xubody): Rename.
2007-08-05 17:25:01 +00:00
8fead20ac4 (xundump1, xundump2): Move call of xutrailer() from xundump1() to its
caller xundump2().  Make xundump1() return number of records read for
that.
2007-08-05 17:19:52 +00:00
5a8aea24f4 (xundump1): Remove parameter type. Use cur_type instead. Caller
changed.
2007-08-05 17:05:22 +00:00
b031e34738 (xuheader1, xutrailer, xundump1): Remove unused parameters. Callers
changed.
2007-08-05 17:03:07 +00:00
971515ccc9 (xundump): Count lines in a saner way: pass line number in and out.
Callers changed.
2007-08-05 16:22:41 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
aafb4fdf8a (setstr): Fix type error in variadic argument. 2006-12-31 17:21:11 +00:00
2119e557dc (setstr): Supply missing cast. 2006-07-11 18:45:29 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
2cb2c59ac6 Rewrite rev. 1.69 to suppress immutable field match check when
extending any table, empty or not:
(cur_obj_is_blank): New.
(fldval_must_match): Use it instead of initialized[].
(getobj): Set it along with cur_obj.
(setstr): Move fldval_must_match() down, so that cur_obj_is_blank is
defined.
(initialized): Remove.
2006-06-22 19:42:10 +00:00
Ron Koenderink
a21b4a0e72 (mtsymset, add2symset): Remove unused local variables. 2006-06-09 00:26:59 +00:00
a835a4b4d3 Fix the previous revision. 2006-06-04 09:01:51 +00:00
8fa0dcbe17 Don't check values for immutable fields match when initializing an
empty table:
(initialized): New.
(xundump): Set it.
(fldval_must_match): Ignore NSC_CONST when it's clear.
2006-06-04 08:37:37 +00:00
568b9d6639 Allow symbolic references not just to symbol tables:
(xunsymbol1): Use ef_elt_byname().
(setsym): Accept any table reference, not just to symbol table.
(symval): New.
(setsym, add2symset): Use it.
(mtsymset): Last remaining user of getsymtab(); inline and simplify.
(getsymtab): Remove.

(xunsymbol1, xunsymbol): Rename.
2006-06-01 19:15:30 +00:00
a1546476bf (xunsymbol1): Fix diagnostics. 2006-06-01 19:06:56 +00:00
c432e3107d Symbolic names for table entries in conditionals, closes #928376:
(ef_elt_byname): New.
(nstr_match_val): Use it to generalize to arbitrary table with
uniquely named elements.  Use ca_type to find table, remove parameter
type.  Callers changed.
(nstr_mkselval): Adapt sanity check accordingly.
(NSC_TYPEID): No longer needed, remove, users changed to use
appropriate integer type instead.  This fixes signedness of sector
selectors des and newdes.
(meta_type): Remove entry for NSC_TYPEID.
(nstr_coerce_val): Can't detect typeid - integer mismatch anymore.
Was nice to have; perhaps revive it later.
2006-06-01 18:48:42 +00:00
15635c25ae (getid): Restrict identifier syntax: outlaw conditional operators <>=#
and meta-character ".
2006-06-01 18:09:40 +00:00
2faa68c6e3 (xufld, setstr): Improve diagnostics. 2006-06-01 18:06:03 +00:00
75604d817c (nsc_type): New member NSC_HIDDEN.
(meta_type): Add its entry.
(setnum, nstr_promote, nstr_exec_val): Deal with it.  nstr_exec_val()
implements opt_HIDDEN by mapping unknown values to -1.
(natstr, nat_ca): Use it for member nat_relate.  This also halves its
size.  Fixes very minor leak: before, player could see relations to
all countries, regardless of contact.
(nation_relations): Add entry for -1.
2006-05-18 19:02:04 +00:00
fe53057977 (xuheader): Fix misleading diagnostics.
(xundump1): Fix table shrinking.
2006-02-19 17:03:33 +00:00
3a73dce58e Permit field repetition in each part of vertically split tables,
provided the values all match:
(caseen): New.
(xundump): Initialize and finalize it.
(xundump2): Update it.
(deffld): Deal with repetition.
(fldval_must_match): New, considers repetition as well as NSC_CONST.
(setnum, setstr): Use it.
2006-02-19 15:25:35 +00:00
c12cc62875 (need_uid, is_partial): Rename.
(xuheader1, chkflds): Collect all code dealing with index field of
vertically split tables in chkflds().
2006-02-19 15:15:40 +00:00
c73613ea26 (defellipsis, chkflds, xundump2, need_uid): Use new need_uid to
require index field in all parts of a split table.
2006-02-14 18:04:44 +00:00
fc676cb53a Support vertically split configuration tables (human-readable only):
(ellipsis): New.
(xuheader1): Initialize it.  Compute nflds.  Allow repetition of index
field in continued tables.
(xundump): Don't set nflds.
(xufldname, defellipsis): Accept ... and call new defellipsis().
(xufldname, chkflds): Update and elaborate check for missing fields,
move it to new chkflds().  Require repetition of index field in
continued tables.
(xundump2): New, factored out of xundump().  Parse continued tables.
2006-02-14 07:30:06 +00:00
46fcc27c6f Xdumps don't contain records not in use, cope with that:
(xundump1, setnum, setstr, getobj, cur_id): Delay table lookup until
first field is about to be assigned.
(xundump1): Record largest ID, because it's no longer given by final
value of row.

(xuheader1, xundump1, xundump): Move initialization of cur_type to
xundump().
2006-02-13 21:22:05 +00:00
eae1e590cc (xundump1): Don't suppress table growth just because it has NSC_CONST
selectors.  That's wrong for EF_SECTOR_CHR and EF_PRODUCT.  Don't
allow table shrinking just because it has no NSC_CONST selectors.
That's wrong for EF_NEWS_CHR.  Allow it for game state and unit
characteristics.
(has_const): Unused, remove.
2006-02-13 21:16:41 +00:00
1a4deb9fde (setnum): Fix computation of old for cases NSC_XCOORD, NSC_YCOORD. 2006-02-13 20:44:18 +00:00
9e362de34f (xuheader, xundump): Return -2 for empty input, so it can be
distinguished from bad input.
2006-02-13 19:07:31 +00:00
6ed05a024c (setstr): Fix for NSC_STRINGY without terminating zero. 2006-02-13 07:06:47 +00:00
86a0a43960 (xuheader1): New, factored out of xundump(). 2006-02-12 15:52:10 +00:00
10096cbf98 (xundump): Rev. 1.44 broke ef_load(). Fix. 2006-02-09 18:34:57 +00:00
66669be655 (xundump, xundump1): Fix treatment of empty lines. 2006-02-09 07:10:18 +00:00
Ron Koenderink
f76a128f5c (mtsymset, xutrailer, xundump1): Remove unused variables. 2006-02-09 00:28:28 +00:00
f5621c5a49 Accept fields out of order in human-readable syntax (indexes must
still be in order), support abbreviated field names:
(nxt_sel, nxt_idx, nxtfld, ca4fld): Remove.
(nflds, fldca, fldidx, caflds, getfld): New.
(xundump): Initialize and finalize them.
(xundump1): New, factored out of xundump().
(deffld): Match names, record field order in fldca[], fldidx[] for
getfld().  Use caflds[] to detect duplicates.
(xufldname): Catch negative index.  Used to pass it to deffld(), which
now interprets it as no index.
(setnum, setstr, setsym, mtsymset, add2symset): Use getfld().

(xufld): Improve error message.

(setstr): Fix for NULL strings.

(xuheader): Catch null ef_cadef().

(xuheader): Don't oops when an unexpected table can't be undumped.
2006-02-08 23:23:48 +00:00
28787caa95 Improve error messages. 2006-02-08 22:44:22 +00:00
b11aa718ce The separation between parsing and semantic actions is awkward and
leaks memory; rework it:
(deffld): New; semantic action for field headers.
(xufldname): Use it instead of storing a value for xucolumnheader().
(xucolumnheader): Remove, use xuflds() directly instead.
(setnum, setstr, setsym): New; semantic actions for field values.
(xufld): Use it instead of storing a value for xuloadrow().
(xuloadrow): Remove.  Was incomplete.
(xufldname, xufld, xuflds): Remove parameter values.  Callers
changed.
(cur_type, cur_obj, nxt_sel, nxt_idx, nxtfld, ca4fld, getsymtab): New
helpers.
(xundump): Initialize them.
(enum_value, value, freeflds, xunsymbol): Remove.

(mtsymset, add2symset): New.
(xufld): Use them to build a symbol set along the parse.

(xufldname, xufld, xuheader, xutrailer, xundump): Increment lineno
when and only when a linefeed is consumed, to make sure it is correct.
Move some semantic checks so that errors get reported for the correct
line.

(xundump): Use compare filenames as pointers, not strings, when
checking whether to reset lineno.

(xundump): Keep empfile[type] consistent during parse, to make
ef_ptr() usable.

(xundump): Don't call ep->init() on sentinels.
(xuinitrow): Unused, remove.
2006-02-08 22:32:53 +00:00
054d59b323 (xundump): Precise value for need_sentinel. 2006-02-08 22:02:13 +00:00
d329c4f8e6 (xutrailer): Fix parsing of /config. Change human-readable syntax not
to accept number of records.  Don't skip empty lines after trailer.
2006-02-08 21:53:04 +00:00