Mostly confine assumptions about what token_t is to misc.c

The token_t things like WD* are presently longs and will someday be
char[6].  By introducing some trivial functions - wordeq(),
wordempty(), and wordclear() - we mostly hide the difference.

All runtime knowledge about packing now lives only in misc.c and the
list of magic WORD_* defines in advent.h.  Outside this, literals are
now accessed through #define names that could expand to either longs
or strings.

Still to be done: WD* values are sometiimes compated to zero in
ways implying they can be negative. Must figure out wat thus means.
This commit is contained in:
Eric S. Raymond 2017-06-19 17:21:45 -04:00
parent 87961483a2
commit a678b68b39
5 changed files with 28 additions and 6 deletions

17
misc.c
View file

@ -50,6 +50,23 @@ void packed_to_token(long packed, char token[6])
}
}
/* Hide the fact that wods are corrently packed longs */
bool wordeq(token_t a, token_t b)
{
return a == b;
}
bool wordempty(token_t a)
{
return a == 0;
}
void wordclear(token_t *v)
{
*v = 0;
}
/* I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */
void speak(const char* msg)