Skip to contentSkip to conversation

parser: Do not print prompt if input buffer is not empty

PATCH New Herbert Xu 1 participant 1 message Jun 10 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Herbert Xu

author
#1 lore raw

PATCH 1/1 parser: Do not print prompt if input buffer is not empty

Quoted 5 lines · Jilles Tjoelker

I expect that the extra ugliness caused by this incomplete check will not be worth it. It would be better to enable libedit or to use a version of linenoise (link it statically to avoid the impact on fork() performance).

I'm feeling generous so this patch works for me.

Quoted 5 lines

By the way, you can also have a "spurious" "$ ":

$ echo a^Jecho b
a
$ b
$ 

It fixes this problem too.

Thanks,

---8<---
Do not print a prompt if there is still input left over in the input buffer.

Add a noinline attribute to setprompt while doing this as otherwise gcc will produce horrendous output.

src/parser.c +2 -3
index 412e876..4e8daf7 100644
@@ -1705,8 +1705,7 @@ synerror(const char *msg)
 	/* NOTREACHED */
 }
 
-STATIC void
-setprompt(int which)
+static void __attribute__((noinline)) setprompt(int which)
 {
 	struct stackmark smark;
 	int show;
@@ -1719,7 +1718,7 @@ setprompt(int which)
 #else
 	show = !el;
 #endif
-	if (show) {
+	if (show && !parsefile->nleft) {
 		pushstackmark(&smark, stackblocksize());
 		out2str(getprompt(NULL));
 		popstackmark(&smark);
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt