Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh PR bin/52458



details:   https://anonhg.NetBSD.org/src/rev/2f34c237be71
branches:  trunk
changeset: 825899:2f34c237be71
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Aug 05 11:33:05 2017 +0000

description:
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.

diffstat:

 bin/sh/input.c  |  9 +++++----
 bin/sh/parser.c |  8 +++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diffs (74 lines):

diff -r fcf542f5645f -r 2f34c237be71 bin/sh/input.c
--- a/bin/sh/input.c    Sat Aug 05 06:05:37 2017 +0000
+++ b/bin/sh/input.c    Sat Aug 05 11:33:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.60 2017/07/05 19:54:21 kre Exp $   */
+/*     $NetBSD: input.c,v 1.61 2017/08/05 11:33:05 kre 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.60 2017/07/05 19:54:21 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.61 2017/08/05 11:33:05 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -310,10 +310,11 @@
        *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;
        }
diff -r fcf542f5645f -r 2f34c237be71 bin/sh/parser.c
--- a/bin/sh/parser.c   Sat Aug 05 06:05:37 2017 +0000
+++ b/bin/sh/parser.c   Sat Aug 05 11:33:05 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parser.c,v 1.142 2017/07/26 23:09:41 kre Exp $ */
+/*     $NetBSD: parser.c,v 1.143 2017/08/05 11:33:05 kre 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.142 2017/07/26 23:09:41 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.143 2017/08/05 11:33:05 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -2192,13 +2192,14 @@
 {
        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:
@@ -2216,6 +2217,7 @@
        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));
 



Home | Main Index | Thread Index | Old Index