X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=misc.c;h=0eae1623a25bc4c95539df1825435ff628087f5d;hp=b991117222a3ccd9e4dd4263ae7b1ec8610aad2e;hb=63e971fc4cfc4d7a5638da032326eaf016c62719;hpb=037f1df7dd8faf29622654ec4a79c2437b927b28 diff --git a/misc.c b/misc.c index b991117..0eae162 100644 --- a/misc.c +++ b/misc.c @@ -703,6 +703,7 @@ void BUG(long num) 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 @@ -729,13 +730,23 @@ bool 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;