#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "main.h"
#include "share.h" /* for SETUP */
#include "misc.h"
#define WORD1X (*wORD1X)
#define WORD2 (*wORD2)
#define WORD2X (*wORD2X)
-void fGETIN(FILE *input, long *wORD1, long *wORD1X, long *wORD2, long *wORD2X) {
+bool fGETIN(FILE *input, long *wORD1, long *wORD1X, long *wORD2, long *wORD2X) {
long JUNK;
/* Get a command from the adventurer. Snarf out the first word, pad it with
L10: if(BLKLIN)TYPE0();
MAPLIN(input);
- if(input == stdin && feof(stdin)) score(1);
+ if (feof(input))
+ return false;
WORD1=GETTXT(true,true,true,0);
if(BLKLIN && WORD1 < 0) goto L10;
WORD1X=GETTXT(false,true,true,0);
WORD2X=GETTXT(false,true,true,0);
L22: JUNK=GETTXT(false,true,true,0);
if(JUNK > 0) goto L22;
- if(GETTXT(true,true,true,0) <= 0)return;
+ if(GETTXT(true,true,true,0) <= 0)return true;
RSPEAK(53);
goto L10;
}
-/* Utility routines (SETBIT, TSTBIT, set_seed_from_time, get_next_lcg_value, randrange, RNDVOC, BUG) */
+/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
+ * randrange, RNDVOC, BUG) */
#undef SETBIT
long fSETBIT(long BIT) {
#define TSTBIT(MASK,BIT) fTSTBIT(MASK,BIT)
-void set_seed_from_time(void)
+void set_seed(long seedval)
{
- /* Use the current system time to get seed the ISO rand() function, from which we get a seed for the LCG. */
- srand(time(NULL));
- lcgstate.x = (unsigned long) rand() % lcgstate.m;
+ lcgstate.x = (unsigned long) seedval % lcgstate.m;
}
unsigned long get_next_lcg_value(void)
if(MAP2[1] == 0)MPINIT();
- if (!oldstyle && SETUP)
- fputs("> ", stdout);
- IGNORE(fgets(INLINE+1,sizeof(INLINE)-1,OPENED));
+ if (!oldstyle && SETUP && OPENED == stdin)
+ fputs("> ", stdout);
+ do {
+ IGNORE(fgets(rawbuf,sizeof(INLINE)-1,OPENED));
+ } while
+ (!feof(OPENED) && INLINE[1] == '#');
if (feof(OPENED)) {
- if (logfp)
+ if (logfp && OPENED == stdin)
fclose(logfp);
} else {
- if (logfp)
- IGNORE(fputs(INLINE+1, logfp));
+ if (logfp && OPENED == stdin)
+ IGNORE(fputs(rawbuf, logfp));
else if (!isatty(0))
- IGNORE(fputs(INLINE+1, stdout));
+ IGNORE(fputs(rawbuf, stdout));
+ strcpy(INLINE+1, rawbuf);
LNLENG=0;
for (I=1; I<=sizeof(INLINE) && INLINE[I]!=0; I++) {
VAL=INLINE[I]+1;