Commit graph

101 commits

Author SHA1 Message Date
50cfdcb5a7 Check argument of ef_cadef(), ef_nelem(), ef_flags(), ef_mtime()
This removes any need for calling ef_check() outside of file.c.
Remove its only occurence, from symval(), and give it internal
linkage.
2008-09-03 20:43:13 -04:00
1492845c12 Clean up maintenance of config table sentinels
Xundump had special hackery to maintain configuration tables'
sentinels: xubody() and getobj() added a sentinel element when
initializing or growing a table, which xubody() stripped off again
before returning.  The latter was an unclean hack.

Replace this by building knowledge of sentinels into struct empfile:
new flag EFF_SENTINEL, set for the appropriate members of empfile[],
obeyed by ef_extend() and ef_truncate().
2008-09-03 20:43:13 -04:00
a38625d9a4 Make xundump oops on virtual selectors
Commit da8a1dae (v4.3.12) introduced virtual selectors, but neglected
to update xundump.  Xundump can't work for them, because they don't
provide a setter method.

This didn't actually break anything, because all virtual selectors
have flag NSC_EXTRA set, or are in table EF_VERSION, which xundump
refuses to touch.

Make deffld() oops on virtual selector, just to be safe.
2008-05-12 11:26:41 +02:00
0dd6702df1 Update known contributors comments 2008-03-14 20:25:44 +01:00
726a8e3dae Make xundump catch extraneous fields
Make deffld() reject fields whose selector has flag NSC_EXTRA set.
Since xundump() doesn't provides space for these, the bug could lead
to buffer overruns.
2008-03-14 20:25:43 +01:00
f9e28d0491 Make xundump interpret escapes in identifiers
We need this because we have symbols with spaces, e.g. missions[].
2008-03-14 20:25:42 +01:00
4c746b5e73 Make xdump code available for future use outside the server
Move the bits useful there from src/lib/commands/xdump.c to new
include/xdump.h and src/lib/common/xdump.c.
2008-03-14 20:25:42 +01:00
6af2ad7c56 Implement xundump table truncation 2008-03-14 20:25:10 +01:00
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