Commit graph

156 commits

Author SHA1 Message Date
549561ff03 Include "file.h" where it's needed
Several headers define macros that use ef_ptr() without including
"file.h".  Fix that.  Drop redundant inclusions elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
dc58018cd7 nsc: Replace NSC_EXTRA, NSC_CONST by enum ca_dump
struct castr ca_flag NSC_EXTRA was introduced in commit 3e5c064
(v4.2.18) to permit selectors that aren't in xdump.

Flag NSC_CONST was introduced in commit 445dfec, and put to use in
commit d8422ca (both v4.3.0) to protect certain table elements that
should not be changed in customized tables.

Both flags apply only to xdump, not to other uses of struct castr,
such as conditionals.

Combining NSC_EXTRA | NSC_CONST makes no sense.

I'll shortly need a way to keep selectors out of configuration tables
for conditional selector and xdump command forward compatibility.
Doing it as a third flag would add more nonsensical combinations.

Convert the flags to a separate enum ca_dump instead:

    neither   -> CA_DUMP
    NSC_CONST -> CA_DUMP_CONST
    NSC_EXTRA -> CA_DUMP_NONE

Bonus: unlike the flags it replaces, ca_dump is not visible in xdump.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +02:00
bae3f5447e Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-07-02 17:45:44 +02:00
eba87789ab Fix and clean up some comments
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:31:08 +01:00
9f25de3dce Change comment style to use @foo rather than FOO
... when referring to a function's parameter or a struct/union's
member.

The idea of using FOO comes from the GNU coding standards:

    The comment on a function is much clearer if you use the argument
    names to speak about the argument values.  The variable name
    itself should be lower case, but write it in upper case when you
    are speaking about the value rather than the variable itself.
    Thus, "the inode number NODE_NUM" rather than "an inode".

Upcasing names is problematic for a case-sensitive language like C,
because it can create ambiguity.  Moreover, it's too much shouting for
my taste.

GTK-Doc's convention to prefix the identifier with @ makes references
to variables stand out nicely.  The rest of the GTK-Doc conventions
make no sense for us, however.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:13:17 +01:00
7f68f37433 xundump: Pass unsigned * for scanf directive %3o, not int *
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-05-14 09:48:57 +02:00
b14f5276ab Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:21:34 +01:00
a4131805d9 xundump: Polish error messages
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
f4f048234c empdump: Omit redundant data from export, new -c includes it
Cuts size of export files in test suite by a factor of four.  Not a
big deal for disk usage, as export files compress very well, and disk
space is cheap anyway.  Export files are simply easier to work with
when they aren't full of redundant crap.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
8afb9c8cb7 xundump: Permit omitting non-trailing realms
This involves computing the realm ID from fields cnum, realm.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
1c2860c8f6 xundump: Permit omitting non-trailing sectors
This involves computing the sector ID from fields xloc, yloc.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
708b8d49d0 xundump: Eliminate global cur_obj
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
d81c8c9463 xundump: Code motion to clean up after previous commit
The previous commit avoided code motion to ease review.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
13e3ce4e59 xundump: Don't require ID field to come first
The code needs it first so it can store field values into the object
right away.  Save the values instead, and store them when the row is
complete.

The improvement is hardly worth the trouble by itself, but it'll
simplify supporting keys consisting of multiple fields, like sector
xloc, yloc or realm cnum, realm, so we can omit rows in those tables,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
33d80e9f7f xundump: Eliminate global may_trunc, may_omit_id
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
cfa0eac32a 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 <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
515beef12e xundump: Support splitting any table
Each part of a split table needs to supply rows for the same objects.
We currently require each part to name its objects explicitly, with an
object ID field, and don't support splitting tables that don't have
such IDs.  These restrictions became arbitrary when commit 4e23c45
implemented checking each partial table supplies the same rows.  Relax
them.

Affects tables sect, news, lost, realm, game, infrastructure.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
67425a06d9 xundump: Report all missing fields, not just first one
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
41f00fdd33 nsc: Turn NSC_HIDDEN into a flag
More general, and fewer places need to know about it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
b6775d1c9b nsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
a06cea24c1 xundump: Clean up lazy coding limiting string length to 65536
Can't just replace the literal 65536 by INT_MAX, because my system's
vfprintf() rejects that with EOVERFLOW.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
002a3a3f1e xundump: Refuse to undump strings too long for terminating null
We're dealing with three kinds of string storage: char * pointing to a
null-terminated string, char[] holding a null-terminated string, and
char holding a string of length 0 or 1.

Unfortunately, xdump meta data doesn't distinguish the latter two:
both are NSC_STRINGY.  Because of that, xundump happily fills char[]
to the limit, producing strings that aren't null-terminated, resulting
in read beyond buffer and possibly worse.

Affects struct shpstr members shp_path, shp_name, shp_rpath, struct
lndstr member lnd_rpath, and struct natstr members nat_cnam, nat_pnam,
nat_hostaddr, nat_hostname, nat_userid.  Since these are all in game
state, only the empdump utility program is affected, not the
configuration table reader.

We clearly need to require null-termination for char[] values.  Since
using char[1] for null-terminated strings makes no sense, we can still
make NSC_STRINGY with length 1 serve char values as before, by
permitting non-null-terminated strings only when length is 1.  Ugly
wart, but it fixes the bug without a possibly awkward change xdump
meta-data.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
199ea0cb39 Clean up redundant forward declarations 2013-05-08 06:55:21 +02:00
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
513352f50c Clean up omit_ids() not to set an extra element in idgap[] 2011-07-16 15:30:10 +02:00
2bbe648d78 Fix xundump's "value must match" check for split tables
The check applies to selectors with flag NSC_CONST set.  It permits
initializing them in new objects, but prevents changing them in
existing objects.  For split tables, initialization worked only in the
first part, because new objects were considered old in later parts.

For instance, in a custom config sect-chr with mnem in the second
part's field 2, new sector types were rejected with `Value for field 2
must be ""'.
2011-06-25 17:12:40 +02:00
7457573a50 Fix how configuration tables and empdump treat omitted entries
Change xundump to blank out omitted rows.  Before, they were left
alone.  Impact:

* No change for reading builtin tables.

* Reading custom tables now replaces the builtin tables instead of
  sort-of-merging them.  Wasn't a real merge, because it dropped
  builtin entries after the last custom entry, except for
  non-truncatable tables item, sect-chr and infrastructure.

* empdump -i now replaces the old state instead of sort-of-merging the
  dump into the old state.  Wasn't a real merge, because it dropped
  old state entries after the last entry in the dump, except for the
  fixed-size tables sect, nat, realm and game.
2011-06-25 16:51:56 +02:00
84d88442b3 Don't misinterpret blank configuration entries as sentinels
Configuration table entries not defined by builtin and custom
configuration files remain blank.  They get misinterpreted as sentinel
in tables that use one.  Affected are tables product, ship-chr,
plane-chr, land-chr and nuke-chr.  Tables item, sect-chr and
infrastructure are immune despite using a sentinel, because omitting
entries is not permitted there.

Code relying on the sentinel fails to pick up entries after the first
blank one.  They don't get set up correctly, they're invisible to
build and show, and not recognized as symbolic selector values (the
frg in ship ?type=frg).  xdump is fine, because it doesn't rely on
sentinels.  It dumps blank entries normally.

The bugs don't bite in the stock game, because the builtin
configuration files are all dense.

The sentinels are all null strings.  Set them to "" in the affected
tables' oninit callback.  Fix up code iterating over the tables to
ignore such entries.  This is precisely the code relying on sentinels,
plus xdump's xdvisible().
2011-06-25 16:51:56 +02:00
29d7b30b2f Permit omitting rows at the end of tables nat and game
When not enough rows are supplied for a table with fixed size, treat
the rows missing at the end just like rows omitted elsewhere: make
them blank if the omission is permitted (tables nat and game), else
fail (tables sect and realm; no change).
2011-06-25 16:51:56 +02:00
4a4ec917f6 Forbid omitting rows in config item and sect-chr
Forbid omitting rows for tables with const fields: item and sect-chr.
This is consistent with the rule for truncation.

The server expects certain entries in these two tables, and
malfunctions when they're blank.  Omitting them in the builtin tables
has always left them blank, but deities are not supposed to edit them,
and maintainers are supposed to know what they're doing, so the issue
was deemed unimportant and ignored.  However, I plan to blank out
omitted rows in custom tables as well, and then the issue isn't
unimportant anymore.
2011-06-25 16:51:44 +02:00
4e23c45e61 Make xundump check each partial table supplies the same rows
Also streamline the error message for missing rows at end of table.
2011-06-25 16:51:44 +02:00
4c731905cf Make xundump reject out-of-order rows
This also catches duplicate rows.  Will make blanking out gaps easier.
2011-06-25 16:51:44 +02:00
3a3b9409b2 Clean up xundump's test whether table may be truncated
A table may be truncated when its size is variable and it doesn't have
const fields.  The old code tested table IDs instead.
2011-06-25 16:50:41 +02:00
63f972d31c Overhaul how xundump keeps track of current object
Factor tracking of cur_type, cur_obj, cur_id and cur_is_blank into a
set of functions.  They replace getobj().  While there, improve some
error messages.
2011-06-25 16:50:41 +02:00
58ed1d1b9e Fix empdump not to grow game state files with fixed size
empdump -i now complains about extra rows instead of silently growing
the file to a size the server will reject.  Affects tables sector,
nation, realms, game.

Bonus fix: better error message on I/O error or insufficient memory.
2011-06-25 16:50:06 +02:00
73bd5d6aa3 Fix empdump not to truncate game state files with fixed size
empdump -i now complains about missing rows instead of silently
truncating the file to a size the server will reject.  Affects tables
sector, nation, realms, game.
2011-06-25 16:50:06 +02:00
bd453cd821 Fix how empdump rejects attempt to split table sect
Split tables require the record index in the leftmost column.
defellipsis() correctly rejects "..." when the table doesn't have one.
It fails to reject it when it has one that is NSC_EXTRA, and thus not
permitted in a dump.  This is the case for table sect.  defellipsis()
happily succeeds, then chkflds() demands column "uid" if it's missing,
and rejects it if its present.
2011-06-25 16:50:05 +02:00
b40741dc5f empdump failed to catch some invalid column names
It missed those with more flags than just NSC_EXTRA set: table sect
name uid, table nat names passwd, xorg, yorg, contacts, rejects.
Since xundump() doesn't provide space for these, the bug could lead to
buffer overruns.  Fixes flawed commit 726a8e3d, v4.3.12.
2011-06-25 16:50:05 +02:00
7e95b52bce Fix empdump to check for truncation failure
xubody() neglected to check ef_truncate()'s return value.  Two failure
modes: invalid arguments, and ftruncate() failure.  The former
shouldn't happen, and the latter can happen only for file-backed
tables, hence only in empdump -i.
2011-06-25 16:49:58 +02:00
5cedc533f8 Make xundump report invalid record IDs
It failed silently before.
2011-06-25 16:49:57 +02:00
50070a8f9a Make xundump reject numbers that don't fit into integral field
Numbers are read into a double, then cast to the field type.  The cast
may change the value.  Flag that as error, except for floating-point
fields.
2011-06-25 16:49:57 +02:00
029d929b1b Restrict xundump to tables with a file name
Tables with a file name are: any game state, and any table that's
initialized from a .config file.

Tables that are no longer customizable: "updates" (customization had
no effect, because update_get_schedule() overwrote it), "table",
"meta" and the symbol tables (customization couldn't change them
anyway), and news-chr (customizing r_newsstory[] was kind of neat, but
unsafe because they are format strings for sprintf()).
2011-06-25 16:47:57 +02:00
5b9d31a4b3 Check record uid comes first in split config tables
setnum() requires the record uid to come first, so we better ensure it
does.
2011-06-25 16:45:31 +02:00
cb3e35cb3a Don't stop checking xdump field headers when join field is missing
Also improve the error message a bit.
2011-06-25 16:45:31 +02:00
98cd2a3a70 Update known contributors comments 2011-04-14 20:21:23 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
25115f4997 Document xundump() memory leak more clearly 2010-07-25 18:24:00 +02:00
243a15052f Convert spaces to tabs 2010-06-20 18:36:44 +02:00