Commit graph

102 commits

Author SHA1 Message Date
c93405f10d nsc: New enum ca_dump member CA_DUMP_ONLY
CA_DUMP_ONLY selectors are like CA_DUMP_NONE, except the xdump command
still has them.  This will permit adding selectors for conditional
selector and xdump command forward compatibility without also adding
them to configuration tables.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +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
80bf4ec34b Provide proper build-time assertions for NSC_SITYPE()
We want to cause a diagnostic when NSC_SITYPE()'s argument isn't
implemented.  Commit aa6ad9d's solution is to have the macro expand
into 1/0 then.  Works with GCC, but Clang always warns "division by
zero is undefined".

The better, portable way to conditionally break the build is an array
type with a size that's negative when the build should fail, else
positive.  Implement that wrapped in a sizeof() to make it an
expression as macro BUILD_ASSERT_ONE(), and use it in NSC_SITYPE().

No more warnings from Clang 3.5.0.  GCC still produces its "may be
used uninitialized" false positives.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:42:40 +01: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
e92a522731 symbol: New symbol_set_fmt() parameter sep, use for show
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
9fc0719e54 symbol: Make actofgod.c's fmtflags() public as symbol_set_fmt()
Move to nstreval.c, rename, external linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
b14f5276ab Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:21:34 +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
143a4e4e6f nsc: Rename nstr_exec_val() to nstr_eval() and tighten contract
nstr_exec_val() can produce three different error values: NSC_NOTYPE
on invalid category, invalid type with zero val_as.lng on invalid type
(this is a bug), and the wanted type with zero val_s when it can't
coerce.  None of these should ever happen.

Fix it to always produce an NSC_NOTYPE error value.  Fix up callers to
check for it.

Specify the result's type is promoted on success.  Ensure it is even
when the argument is NSC_VAL with an unpromoted type, which is
invalid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +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
a109de948b Remove option TREATIES
TREATIES has issues:

* Treaties can cover attack, assault, paradrop, board, lboard, fire,
  build (s|p|l|n) and enlist, but not bomb, launch, torpedo and
  enlistment centers.

* Usability is very poor.  While a treaty is in effect, every player
  action that violates a treaty condition triggers a prompt like this:

    This action is in contravention of  treaty #0 (with Curmudgeon)
    Do you wish to go ahead anyway? [yn]

  If you decline, the action is not executed.  If you accept, it is.
  In both cases, your decision is reported in the news.

  You cannot get rid of these prompts until the treaty expires.

* Virtually nobody uses them.

* Virtually unused code is buggy code.  There is at least one race
  condition: multifire() reads the firing sector, ship or land unit
  before the treaty prompt, and writes it back after, triggering a
  generation oops.  Any updates made by other threads while trechk()
  waits for input are wiped out, triggering a seqno mismatch oops.

* The treaty prompts could confuse smart clients that aren't prepared
  for them.  WinACE isn't, but is reported to work anyway at least
  common usage.  Ron Koenderink (the WinACE maintainer) suspects there
  could be a few situations where it will fail.

This feature is not earning its keep.  Remove it.  Drop command
treaty, consider treaty, offer treaty, xdump treaty, reject treaties.
Output of accept changed, obviously.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:14 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01: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
6e4772b175 A few comment fixes for nsc.[ch] file.[ch] 2011-06-25 16:45:31 +02:00
98cd2a3a70 Update known contributors comments 2011-04-14 20:21:23 +02:00
7de511fb66 Factor snxtsct_use_condarg() out of snxtsct() 2011-04-14 20:21:21 +02:00
84072cff5d Factor snxtitem_use_condarg() out of snxtitem() 2011-04-14 20:21:21 +02:00
d0a6dffa02 Collect nstr_item, nstr_sect function declarations in nsc.h
Moved from prototypes.h.
2011-04-14 20:21:21 +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
7465574195 Break long lines more tastefully 2010-06-20 18:36:44 +02:00
373651359e Coding style fixes, mostly indentation and whitespace 2010-06-20 18:36:38 +02:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
ba2044be18 Store uids as int to support more sectors and units
Before, they were stored as short.  Wider uids use more space, but the
next commit will recover it by narrowing other members.

The use of short has always limited the number of ships, planes, land
units and nukes to SHRT_MAX (commonly 32768).  Only the most extreme
games ever came close.

Commit 49780e2c (v4.3.12) added struct sctstr member sct_uid to make
struct empobj member uid work for sectors.  This made the limit apply
to sectors as well.  We've had games with more than 32768 sectors.
2010-01-19 08:26:42 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
9115c03949 Simplify type coercion in condition evaluation
Change nstr_mkselval() to generate values with promoted types only,
and replace nstr_coerce_val() by new and simpler nstr_optype() in
nstr_comp().

Replace the only remaining use of nstr_coerce_val() in surv() by
nstr_promote(), and remove nstr_coerce_val().

This loses one half of the unimplemented sketch of coercions to
NSC_STRING.  Drop the other half from nstr_exec_val().
2008-12-27 16:59:53 +01:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
e7f5b517a0 Make the item iterator capable of iterating over a cargo list
New snxtitem_cargo() initializes an iterator for a cargo list, with
new enum ns_seltype member NS_GROUP and new struct nstr_item member
next.  Extend nxtitem() and nxtitemp() to step through the list.
2008-09-12 18:46:54 -04:00
7a4b7f75a0 Clean up struct nstr_sect and struct nstr_item a bit
Members read were always set to ef_read, remove and call directly.

Member flag was only assigned to, never used, remove.

Change member group to char to match struct empobj.
2008-09-12 18:41:55 -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
e5ef3d4840 Pass struct natstr * instead of natid to virtual selectors
This is because we want to define them in src/lib/global/, and code
there can't use getnatp(), because that requires
src/lib/common/file.c.  Which renders a cnum parameter pretty useless.

Virtual selectors requiring code from common/ could well come up again
in the future, but let's not worry about that now.
2008-03-26 22:13:21 +01:00
0dd6702df1 Update known contributors comments 2008-03-14 20:25:44 +01:00
06a0036c63 Replace some typedef names by enum tags.
Also get rid of some mildly silly manual packing of enum types.
2008-03-14 20:25:42 +01:00
d1a193ff07 New nstr_mksymval() to create symbolic values 2008-03-14 20:25:41 +01:00
da8a1daeef Virtual selectors
Where ordinary selectors specify a value stored in some object,
virtual selectors specify a function to call to compute a value
associated with some object.

Use them to replace the special case xdump ver by new table
EF_VERSION.

Move configkeys[] to lib/common because nsc_init() needs it to
initialize empfile[EF_VERSION].cadef.
2008-03-14 20:25:41 +01:00
38047a62f7 Reorder members of struct castr to make nsc.c easier to read 2008-03-14 20:25:40 +01:00
93a5779e66 Make nstr_exec_val() return its first argument 2008-03-14 20:25:40 +01:00
0bcb047806 Make nstr_exec_val() more robust
Oops on bad argument, and make a better error value then.
2008-03-14 20:25:40 +01:00
422cd52209 Move nstr_promote() to src/lib/common/, external linkage 2008-03-14 20:25:40 +01:00
9eab865c38 Document nsc.h more completely 2008-03-14 20:25:40 +01:00
400df7be82 Clean up initialization of nat_ca[]
Factor it out of ef_init_srv() and put it into new nsc_init(), next to
nat_ca[].
2008-02-10 11:40:57 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
7dd8b8a305 New xdump updates:
(EF_UPDATES, update_ca): New.
(empfile): Add it.
(update_time): Move to src/lib/global/updtime.c.
2007-07-18 06:16:33 +00:00
654335c621 New Empire table game, to be used for global stuff:
(gamestr, EF_GAME, game_ca): New.
(empfile): Declare the table.
(ef_open_srv, ef_close_srv): Open and close it.
(main): Create it.
(empobj_storage): New member game.

(EF_DYNMAX): New.
(EF_IS_GAME_STATE): Use it.
2007-07-14 14:49:58 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +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
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