Module Name:    src
Committed By:   snj
Date:           Wed Aug  9 05:35:19 UTC 2017

Modified Files:
        src/bin/sh [netbsd-8]: input.c parser.c

Log Message:
Pull up following revision(s) (requested by kre in ticket #199):
        bin/sh/input.c: revision 1.61
        bin/sh/parser.c: revision 1.143
PR bin/52458
Avoid mangling history when editing is enabled, and the prompt contains a \n
Also, allow empty input lines into history when they are being appended to
a previous (partial) command (but not when they would just make an empty entry)
.
For all the gory details, see the PR.
Note nothing here actually makes prompts containing \n work correctly
when editing is enabled, that's a libedit issue, which will be addressed
some other time.


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.1 -r1.56.2.2 src/bin/sh/input.c
cvs rdiff -u -r1.132.2.1 -r1.132.2.2 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/input.c
diff -u src/bin/sh/input.c:1.56.2.1 src/bin/sh/input.c:1.56.2.2
--- src/bin/sh/input.c:1.56.2.1	Sun Jul 23 14:58:14 2017
+++ src/bin/sh/input.c	Wed Aug  9 05:35:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: input.c,v 1.56.2.1 2017/07/23 14:58:14 snj Exp $	*/
+/*	$NetBSD: input.c,v 1.56.2.2 2017/08/09 05:35:18 snj Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c	8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.56.2.1 2017/07/23 14:58:14 snj Exp $");
+__RCSID("$NetBSD: input.c,v 1.56.2.2 2017/08/09 05:35:18 snj Exp $");
 #endif
 #endif /* not lint */
 
@@ -310,10 +310,11 @@ preadbuffer(void)
 	*q = '\0';
 
 #ifndef SMALL
-	if (parsefile->fd == 0 && hist && something) {
+	if (parsefile->fd == 0 && hist && (something || whichprompt == 2)) {
 		HistEvent he;
+
 		INTOFF;
-		history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,
+		history(hist, &he, whichprompt != 2 ? H_ENTER : H_APPEND,
 		    parsenextc);
 		INTON;
 	}

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.132.2.1 src/bin/sh/parser.c:1.132.2.2
--- src/bin/sh/parser.c:1.132.2.1	Sun Jul 23 14:58:14 2017
+++ src/bin/sh/parser.c	Wed Aug  9 05:35:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.132.2.1 2017/07/23 14:58:14 snj Exp $	*/
+/*	$NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.132.2.1 2017/07/23 14:58:14 snj Exp $");
+__RCSID("$NetBSD: parser.c,v 1.132.2.2 2017/08/09 05:35:18 snj Exp $");
 #endif
 #endif /* not lint */
 
@@ -2191,13 +2191,14 @@ getprompt(void *unused)
 {
 	char *p;
 	const char *cp;
+	int wp;
 
 	if (!doprompt)
 		return "";
 
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("getprompt %d\n", whichprompt));
 
-	switch (whichprompt) {
+	switch (wp = whichprompt) {
 	case 0:
 		return "";
 	case 1:
@@ -2215,6 +2216,7 @@ getprompt(void *unused)
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt <<%s>>\n", p));
 
 	cp = expandstr(p, plinno);
+	whichprompt = wp;	/* history depends on it not changing */
 
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt -> <<%s>>\n", cp));
 

Reply via email to