Improve slightly on Peje's L12 patch, changing documentation to match.

This commit is contained in:
Eric S. Raymond 2017-06-13 07:36:57 -04:00
parent 804e60ccff
commit 3bdab31a0d
3 changed files with 100 additions and 90 deletions

4
TODO
View file

@ -7,9 +7,7 @@ remain to be cleaned up:
rather promiscuously to pass around information that ought to be function
arguments in a modern language.
* Remaining unstructured gotos in playermove() and do_command(). The goto L12
in playermove() is particularly horrible, jumping backwards into the
middle of a loop.
* Remaining unstructured gotos in do_command().
* The program is still pretty much typeless - full of magic numbers being
sliced and diced in cryptic ways. Some attempt has been made to introduce

16
main.c
View file

@ -399,6 +399,10 @@ static bool dwarfmove(void)
game.dloc[PIRATE]=game.chloc;
game.odloc[PIRATE]=game.chloc;
game.dseen[PIRATE]=false;
/* C doesn't have what the Structured rogramming
* Theorem says we need here - multi-level loop
* breakout. We simulate with a goto. Irreducible, alas.
*/
goto jumpout;
}
if (HERE(j))
@ -606,7 +610,13 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
}
LL=LL/1000;
L12:
do {
/*
* (ESR) This special-travel loop may have to be repeated if it includes
* the plover passage. Same deal for any future cases wgerw we beed to
* block travel and then redo it once the blocking condition has been
* removed.
*/
for (;;) {
game.newloc=LL/1000;
motion=MOD(game.newloc,100);
@ -660,7 +670,7 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
game.newloc=labs(TRAVEL[KK])/1000;
} while
(game.newloc == LL);
goto L12;
continue; /* back to top of do/while loop */
case 3:
/* Travel 303. Troll bridge. Must be done only as special
* motion so that dwarves won't wander across and encounter
@ -696,6 +706,8 @@ static bool playermove(FILE *cmdin, token_t verb, int motion)
}
BUG(20);
}
} while
(false);
RSPEAK(game.newloc-500);
game.newloc=game.loc;
return true;

View file

@ -81,7 +81,7 @@ against a comprehesive test suite that we built first and verified with
coverage tools. This is what you are running when you do "make check".
This move entailed some structural changes. The most important was
the refactoring of 354 gotos into if/loop/break structures. We
the refactoring of 355 gotos into if/loop/break structures. We
also abolished almost all shared globals; the main one left is a
struct holding the game's saveable/restorable state.
@ -108,10 +108,10 @@ ways:
and the choice to refrain will make forward translation into future
languages easier.
* There are 20 gotos left that resist restructuring; all but one of
these are in the principal command interpreter function implementing
its state machine. A 21st, a two-level loop breakout, is not reducible
even in principle.
* There are 19 gotos left that resist restructuring; all of these are
in the principal command interpreter function implementing its state
machine. A 21st, a two-level loop breakout, is not reducible even
in principle.
* Linked lists (for objects at a location) are implemented using an array
of link indices. This is a surviving FORTRANism that is quite unlike