From 6a6d9ca14e39d8d8ee4414d1573e2c039be179bc Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 13 Jun 2017 08:03:27 -0400 Subject: [PATCH] Address GitLab issue #10: Spurious '>' characters appearing in console output The prompt logic has become unpleasantly complicated. --- misc.c | 17 ++++++++++++----- tests/breakvase.chk | 2 +- tests/pirate.chk | 2 +- tests/trident.chk | 2 +- tests/weirdbird.chk | 2 +- tests/weirddwarf.chk | 2 +- tests/wittsend.chk | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/misc.c b/misc.c index 3960347..752bc8e 100644 --- a/misc.c +++ b/misc.c @@ -640,14 +640,14 @@ bool MAPLIN(FILE *fp) * and is not changed thereafter unless the routines on this page choose * to do so. */ - if (prompt) - fputs("> ", stdout); do { if (!editline) { + if (prompt) + fputs("> ", stdout); IGNORE(fgets(rawbuf,sizeof(rawbuf)-1,fp)); eof = (feof(fp)); } else { - char *cp = linenoise(prompt ? "> ": ""); + char *cp = linenoise("> "); eof = (cp == NULL); if (!eof) { strncpy(rawbuf, cp, sizeof(rawbuf)-1); @@ -663,10 +663,17 @@ bool MAPLIN(FILE *fp) fclose(logfp); return false; } else { + FILE *efp = NULL; if (logfp && fp == stdin) - IGNORE(fputs(rawbuf, logfp)); + efp = logfp; else if (!isatty(0)) - IGNORE(fputs(rawbuf, stdout)); + efp = stdout; + if (efp != NULL) + { + if (prompt) + fputs("> ", efp); + IGNORE(fputs(rawbuf, efp)); + } strcpy(INLINE+1, rawbuf); LNLENG=0; for (i=1; i<=(long)sizeof(INLINE) && INLINE[i]!=0; i++) { diff --git a/tests/breakvase.chk b/tests/breakvase.chk index 306a902..012d7f3 100644 --- a/tests/breakvase.chk +++ b/tests/breakvase.chk @@ -1298,7 +1298,7 @@ OK You have taken the vase and hurled it delicately to the ground. -> + You scored 139 out of a possible 430, using 210 turns. You have achieved the rating: "Experienced Adventurer". diff --git a/tests/pirate.chk b/tests/pirate.chk index 116d922..9600c7a 100644 --- a/tests/pirate.chk +++ b/tests/pirate.chk @@ -1772,7 +1772,7 @@ There is a large nest here, full of golden eggs! OK -> + You scored 219 out of a possible 430, using 293 turns. You may now consider yourself a "Seasoned Adventurer". diff --git a/tests/trident.chk b/tests/trident.chk index fb0fa87..d8bf747 100644 --- a/tests/trident.chk +++ b/tests/trident.chk @@ -1415,7 +1415,7 @@ Your lamp is now on. You're at "Y2". -> + You scored 167 out of a possible 430, using 230 turns. You have achieved the rating: "Experienced Adventurer". diff --git a/tests/weirdbird.chk b/tests/weirdbird.chk index e9f8077..01b1168 100644 --- a/tests/weirdbird.chk +++ b/tests/weirdbird.chk @@ -132,7 +132,7 @@ have no bird seed. The little bird is now dead. Its body disappears. -> + You scored 32 out of a possible 430, using 22 turns. You are obviously a rank amateur. Better luck next time. diff --git a/tests/weirddwarf.chk b/tests/weirddwarf.chk index d2d93d3..23adae3 100644 --- a/tests/weirddwarf.chk +++ b/tests/weirddwarf.chk @@ -505,7 +505,7 @@ With what? Your bare hands? Feed what? -> + You scored 103 out of a possible 430, using 86 turns. Your score qualifies you as a novice class adventurer. diff --git a/tests/wittsend.chk b/tests/wittsend.chk index f5d90fe..597eed9 100644 --- a/tests/wittsend.chk +++ b/tests/wittsend.chk @@ -2627,7 +2627,7 @@ It is now pitch dark. If you proceed you will likely fall into a pit. You're in Plover Room. -> + You scored 342 out of a possible 430, using 423 turns. Your score puts you in Master Adventurer Class C. -- 2.31.1