X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=main.c;h=d84e4f2ad85a9aa54a1d624162e273b91a401251;hb=f9eca41f3a8415a8463f754c72518c556f7d869b;hp=27130aac1d8735421025b912fafaf9d9915a8782;hpb=c703bd78d9db22fbaef43efb798e2ae2e2cd0d9e;p=open-adventure.git diff --git a/main.c b/main.c index 27130aa..d84e4f2 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "main.h" #include "misc.h" @@ -17,8 +17,7 @@ long ABB[186], ATAB[331], ATLOC[186], BLKLIN = true, DFLAG, KTAB[331], *LINES, LINK[201], LNLENG, LNPOSN, PARMS[26], PLACE[101], PTEXT[101], RTEXT[278], SETUP = 0, TABSIZ = 330; -signed char INLINE[LINESIZE+1], MAP1[129], MAP2[129]; -signed char raw_input[LINESIZE+1]; +signed char rawbuf[LINESIZE], INLINE[LINESIZE+1], MAP1[129], MAP2[129]; long ABBNUM, ACTSPK[36], AMBER, ATTACK, AXE, BACK, BATTER, BEAR, BIRD, BLOOD, BONUS, BOTTLE, CAGE, CAVE, CAVITY, CHAIN, CHASM, CHEST, CHLOC, CHLOC2, @@ -50,6 +49,14 @@ extern void initialise(); extern void score(long); extern int action(FILE *, long); +void sig_handler(int signo) +{ + if (signo == SIGINT) + if (logfp != NULL) + fflush(logfp); + exit(0); +} + /* * MAIN PROGRAM */ @@ -58,7 +65,6 @@ static bool do_command(FILE *); int main(int argc, char *argv[]) { int ch; - time_t starttime = time(NULL); /* Adventure (rev 2: 20 treasures) */ @@ -78,6 +84,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "advent: can't open logfile %s for write\n", optarg); + signal(SIGINT, sig_handler); break; case 'o': oldstyle = true; @@ -102,7 +109,8 @@ int main(int argc, char *argv[]) { lcgstate.a = 1093; lcgstate.c = 221587; lcgstate.m = 1048576; - set_seed((long)starttime); + long seedval = (long)time(NULL); + set_seed(seedval); /* Read the database if we have not yet done so */ @@ -136,7 +144,8 @@ L1: SETUP= -1; if(NOVICE)LIMIT=1000; if (logfp) - fprintf(logfp, "seed %ld\n", starttime); + fprintf(logfp, "seed %ld\n", seedval); + for (;;) { if (!do_command(stdin)) break; @@ -144,11 +153,25 @@ L1: SETUP= -1; score(1); } +static bool fallback_handler(signed char *buf) +/* fallback handler for commands not handled by FORTRANish parser */ +{ + long sv; + if (sscanf(buf, "seed %ld", &sv) == 1) { + set_seed(sv); + printf("Seed set to %ld\n", sv); + // here we reconfigure any global game state that uses random numbers + ZZWORD=RNDVOC(3,0)+MESH*2; + return true; + } + return false; +} + static bool do_command(FILE *cmdin) { /* Can't leave cave once it's closing (except by main office). */ -L2: if(!OUTSID(NEWLOC) || NEWLOC == 0 || !CLOSNG) goto L71; + if(!OUTSID(NEWLOC) || NEWLOC == 0 || !CLOSNG) goto L71; RSPEAK(130); NEWLOC=LOC; if(!PANIC)CLOCK2=15; @@ -456,19 +479,10 @@ L2800: WD1=WD2; /* Gee, I don't understand. */ L3000: SETPRM(1,WD1,WD1X); - /* This is a kludge. The command parser we inherited from the base 2.5 - * barfs on numeric tokens. It will fall through to here when it sees - * seed NNNN. Instead of barfing, go straight to the action processor - * where it will examine the raw input. This will fo away when we get - * rid of the obfuscated FORTRANoid input processing. - */ - if (strncmp(raw_input, "seed", 4) == 0) { - I=4090; K=34; - goto Laction; - } else { - RSPEAK(254); - goto L2600; - } + if (fallback_handler(rawbuf)) + return true; + RSPEAK(254); + goto L2600; /* Verb and object analysis moved to separate module. */