X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=0eae1623a25bc4c95539df1825435ff628087f5d;hb=63e971fc4cfc4d7a5638da032326eaf016c62719;hp=4d5dd31cc4eb50d29abde887c9e20d67b56864fa;hpb=bea58f268233184eef62a69fb716a519abee43ca;p=open-adventure.git diff --git a/misc.c b/misc.c index 4d5dd31..0eae162 100644 --- a/misc.c +++ b/misc.c @@ -194,8 +194,7 @@ bool GETIN(FILE *input, for (;;) { if (game.blklin) TYPE0(); - MAPLIN(input); - if (feof(input)) + if (!MAPLIN(input)) return false; *pword1=GETTXT(true,true,true); if (game.blklin && *pword1 < 0) @@ -701,9 +700,10 @@ void BUG(long num) /* Machine dependent routines (MAPLIN, TYPE, SAVEIO) */ -void MAPLIN(FILE *fp) +bool MAPLIN(FILE *fp) { long i, val; + bool eof; /* Read a line of input, from the specified input source, * translate the chars to integers in the range 0-126 and store @@ -730,15 +730,26 @@ void MAPLIN(FILE *fp) * and is not changed thereafter unless the routines on this page choose * to do so. */ - if (!oldstyle && fp == stdin) - fputs("> ", stdout); do { - IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp)); + if (oldstyle) { + IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp)); + eof = (feof(fp)); + } else { + char *cp = linenoise("> "); + eof = (cp == NULL); + if (!eof) { + strncpy(rawbuf, cp, sizeof(rawbuf)-1); + linenoiseHistoryAdd(rawbuf); + strncat(rawbuf, "\n", sizeof(rawbuf)-1); + linenoiseFree(cp); + } + } } while - (!feof(fp) && rawbuf[0] == '#'); - if (feof(fp)) { + (!eof && rawbuf[0] == '#'); + if (eof) { if (logfp && fp == stdin) fclose(logfp); + return false; } else { if (logfp && fp == stdin) IGNORE(fputs(rawbuf, logfp)); @@ -753,6 +764,7 @@ void MAPLIN(FILE *fp) LNLENG=i; } LNPOSN=1; + return true; } }