Home | History | Annotate | Download | only in worms
History log of /src/games/worms/worms.c
RevisionDateAuthorComments
 1.31  12-May-2023  kre When using -H, make the appearance of the worm head depend upon the body
(more than it did before).
 1.30  26-Apr-2023  kre Add a little optional colour, optionally distinguish worm heads,
and optionally randomise worm lengths. Just exit instead of
continuing with a nonsense display if the window shrinks (and
for consistency if it grows).

Most of the ideas and code from RVP. Bugs and man page mangling
from me.
 1.29  19-Apr-2023  kre Another err message typo! (found this one myself!!)
 1.28  19-Apr-2023  kre Typo in an error message (pointed out by RVP; Thanks)
 1.27  18-Apr-2023  kre Correct some unfortunate behaviour in extreme cases pointed out by RVP.
(Very long worms in a smallish window could result in the max number of
worms being 0...)

While here (also suggested by RVP) seed the random number generator,
also add a -S option to set the seed (note: while this is documented
in the updated man page, it does not appear in the usage message in
case of an error ... not likely to be used often enough to include there).

Also some minor improvements suggested by RVP:
delete the prototype for main()
exit curses mode before abort() (which should not happen, but...)
no need to return (->exit) after abort() as modern abort() can
never return.

In addition, check for extraneous (ignored) (non-option) args.
Check for absurdly small or big screens (the worm placement algorithm
doesn't work well for lines of columns < 3, and the abort() mentioned
above actually happens if one of those is == 1).

More flavours of worms added.

Some minor man page wording improvements.
 1.26  15-Apr-2023  kre When worms default delay was changed from 0, to 20ms (Oct 2020)
it lost the ability to run flat out (no sleeps) - which while not
very useful for actually observing the behaviour of various Nematoda,
can be useful when 'worms' is being used to generate cpu heat - it
turns out to be a simple tool to make all of the app itself, the
xterm it runs in (when running under X) and the X server, all more
or less continuously busy - a trivial perpetual CPU load generator.

Changing that was not a simple matter of just allowing -d 0..1000
rather than -d 1..1000 which had always been the limits on -d, as
previously, simply by excluding 0, common error checking wasn't
essential. -djunk would return 0 which was invalid, and so an error
- that it was invalid because 0 < 1, rather than because "junk" is not
a number wasn't material.

Now we need some slightly more elaborate error checking code for the
-d value, and if we're going to do that, may as well do the same for
the -l and -n options, which also take numeric values. That is, it
will no longer be possible to say:
worms -n "5 worms"
Just the number is allowed (but -d now allows a "ms" or "us" suffix).

While here, place a reasonable upper limit (depending upon the
screen size, and worm length) upon the number of worms, so they
have somewhere to go, rather than just on top of each other.

exit(1) from the errx() rather than 0, in the case that curses
initscr() fails (doesn't seem right that it should appear as a
successful run of worms, if it never managed to start).

A couple more minor 80 column violations are handled, without
further penalty, in this update (one simply vanishes, the other
is wrapped).

Note that this sounds like a lot, but it is really all just minor
internal bookkeeping updates - the only real advertised user visible
change is the ability to use -d0 which just restores that which was
the default (though it could never be set via the option) until Oct 2020
- so really all that's happening is replacing minor functionality lost
then, while leaving the change of the default delay that that change
made, untouched.

No man page update required (that never excluded -d0).
 1.25  15-Apr-2023  kre 80 column police.

If this code were just a few chars over the limit, it might get
let off with a warning, but 214 in an 80 zone is way beyond that.

Six months loss of coding licence, and a 214000 character fine.

NFCI.

(I verified the the code was unchanged by joining the resulting
lines back into one again, and then diff'ing that line against
the original - it is identical).
 1.24  15-Apr-2023  kre Garbage collect "char *mp" - it used to point at memory malloc()'d
to hold the termcap entry, back when worms used termcap rather than
curses, and termcap was termcap, rather that a terminfo wannabe.

This should have been removed when worms was converted to curses in
1999, but wasn't, so worms has been doing a meaningless malloc(1024)
and never using the result, ever since.

While here, since the line needed changing anyway to remove mp,
change a malloc() of a product into calloc() so it can deal with
any possible (admittedly extremely unlikely here) integer overflows.

NFCI
 1.23  14-Oct-2020  nia branches: 1.23.6;
worms(6): Use a reasonable default delay for non-1980s terminals.

This is still fast, but not unreasonably fast.
 1.22  19-Jun-2012  dholland WARNS=5, and make WARNS=5 the default for src/games.
 1.21  31-Aug-2011  plunky branches: 1.21.2;
NULL does not need a cast
 1.20  12-Aug-2009  dholland sprinkle static
 1.19  08-Aug-2008  drochner if initscr() fails, exit with a message rather than crash in the
next curses call
 1.18  20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
 1.17  15-Dec-2007  perry branches: 1.17.6;
convert __attribute__s to applicable cdefs.h macros
 1.16  12-Sep-2004  christos branches: 1.16.16;
Don't try to catch SIGSTOP...
 1.15  29-Mar-2004  hubertf Properly handle -d 1000, OK'd by jsm
 1.14  08-Feb-2004  jsm branches: 1.14.2;
Hide the cursor if possible. From OpenBSD.
 1.13  27-Jan-2004  jsm Remove uses of __P.
 1.12  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22269, verified by myself.
 1.11  30-Jul-1999  hubertf This patch converts worms(6) to use curses, thereby
simplifying the code and improving its portability. It also adds a
delay option from OpenBSD, to allow reasonable speed display on fast
terminals, adds use of const, and fixes signal handling and use of
errx() where appropriate.

Patch supplied in PR 6661 by Joseph Myers <jsm28@cam.ac.uk>.
 1.10  13-Sep-1998  hubertf mark non-returning functions (PR#6144 by Joseph Myers <jsm28@cam.ac.uk>)
 1.9  12-Oct-1997  lukem WARNSify
 1.8  22-Apr-1995  cgd fix window size update code.
 1.7  22-Apr-1995  cgd un-munge import; it apparently didn't import properly.
 1.6  22-Apr-1995  cgd rough cleanup of import. RCS Ids
 1.5  31-Jan-1995  jtc Make man page and usage message agree with the code.
Fix from Hubert Feyrer.
 1.4  05-Apr-1994  mycroft Clean this up a little, and use TOCGWINSW.
 1.3  01-Aug-1993  mycroft Add RCS identifiers.
 1.2  18-Apr-1993  mycroft Cleanup for GCC 2.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2  22-Apr-1995  cgd src/games/worms from Lite
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.2.1  30-Mar-2004  jmc Pullup rev 1.15 (requested by hubertf in ticket #13)

Properly handle -d 1000.
 1.16.16.1  09-Jan-2008  matt sync with HEAD
 1.17.6.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.2.1  30-Oct-2012  yamt sync with head
 1.23.6.1  25-Apr-2023  martin Pull up following revision(s) (requested by kre in ticket #148):

games/worms/worms.c: revision 1.24
games/worms/worms.c: revision 1.25
games/worms/worms.c: revision 1.26
games/worms/worms.c: revision 1.27
games/worms/worms.c: revision 1.28
games/worms/worms.c: revision 1.29
games/worms/worms.6: revision 1.17

Garbage collect "char *mp" - it used to point at memory malloc()'d
to hold the termcap entry, back when worms used termcap rather than
curses, and termcap was termcap, rather that a terminfo wannabe.

This should have been removed when worms was converted to curses in
1999, but wasn't, so worms has been doing a meaningless malloc(1024)
and never using the result, ever since.

While here, since the line needed changing anyway to remove mp,
change a malloc() of a product into calloc() so it can deal with
any possible (admittedly extremely unlikely here) integer overflows.

NFCI

80 column police.

If this code were just a few chars over the limit, it might get
let off with a warning, but 214 in an 80 zone is way beyond that.
Six months loss of coding licence, and a 214000 character fine.

NFCI.

(I verified the the code was unchanged by joining the resulting
lines back into one again, and then diff'ing that line against
the original - it is identical).

When worms default delay was changed from 0, to 20ms (Oct 2020)
it lost the ability to run flat out (no sleeps) - which while not
very useful for actually observing the behaviour of various Nematoda,
can be useful when 'worms' is being used to generate cpu heat - it
turns out to be a simple tool to make all of the app itself, the
xterm it runs in (when running under X) and the X server, all more
or less continuously busy - a trivial perpetual CPU load generator.

Changing that was not a simple matter of just allowing -d 0..1000
rather than -d 1..1000 which had always been the limits on -d, as
previously, simply by excluding 0, common error checking wasn't
essential. -djunk would return 0 which was invalid, and so an error
- - that it was invalid because 0 < 1, rather than because "junk" is not
a number wasn't material.

Now we need some slightly more elaborate error checking code for the
- -d value, and if we're going to do that, may as well do the same for
the -l and -n options, which also take numeric values. That is, it
will no longer be possible to say:

worms -n "5 worms"

Just the number is allowed (but -d now allows a "ms" or "us" suffix).

While here, place a reasonable upper limit (depending upon the
screen size, and worm length) upon the number of worms, so they
have somewhere to go, rather than just on top of each other.

exit(1) from the errx() rather than 0, in the case that curses
initscr() fails (doesn't seem right that it should appear as a
successful run of worms, if it never managed to start).

A couple more minor 80 column violations are handled, without
further penalty, in this update (one simply vanishes, the other
is wrapped).

Note that this sounds like a lot, but it is really all just minor
internal bookkeeping updates - the only real advertised user visible
change is the ability to use -d0 which just restores that which was
the default (though it could never be set via the option) until Oct 2020
- - so really all that's happening is replacing minor functionality lost
then, while leaving the change of the default delay that that change
made, untouched.

No man page update required (that never excluded -d0).

Correct some unfortunate behaviour in extreme cases pointed out by RVP.
(Very long worms in a smallish window could result in the max number of
worms being 0...)

While here (also suggested by RVP) seed the random number generator,
also add a -S option to set the seed (note: while this is documented
in the updated man page, it does not appear in the usage message in
case of an error ... not likely to be used often enough to include there).

Also some minor improvements suggested by RVP:
delete the prototype for main()
exit curses mode before abort() (which should not happen, but...)
no need to return (->exit) after abort() as modern abort() can
never return.

In addition, check for extraneous (ignored) (non-option) args.

Check for absurdly small or big screens (the worm placement algorithm
doesn't work well for lines of columns < 3, and the abort() mentioned
above actually happens if one of those is == 1).

More flavours of worms added.

Some minor man page wording improvements.

Typo in an error message (pointed out by RVP; Thanks)

Another err message typo! (found this one myself!!)

RSS XML Feed