Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit For readline emulation, don't reset the tty to "...



details:   https://anonhg.NetBSD.org/src/rev/f24323c05be5
branches:  trunk
changeset: 826445:f24323c05be5
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Sep 05 18:07:59 2017 +0000

description:
For readline emulation, don't reset the tty to "sane" (cooked) mode if we
did not start this way. Also set and reset the tty on entry and exit from
readline() since this is what readline does.

diffstat:

 lib/libedit/el.c       |  18 ++++++++++++------
 lib/libedit/el.h       |   5 ++++-
 lib/libedit/readline.c |  18 +++++++++++++-----
 lib/libedit/tty.c      |   6 +++---
 4 files changed, 32 insertions(+), 15 deletions(-)

diffs (181 lines):

diff -r f1058d191496 -r f24323c05be5 lib/libedit/el.c
--- a/lib/libedit/el.c  Tue Sep 05 17:21:09 2017 +0000
+++ b/lib/libedit/el.c  Tue Sep 05 18:07:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $ */
+/*     $NetBSD: el.c,v 1.95 2017/09/05 18:07:59 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)el.c       8.2 (Berkeley) 1/3/94";
 #else
-__RCSID("$NetBSD: el.c,v 1.94 2017/06/27 23:25:13 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.95 2017/09/05 18:07:59 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -67,9 +67,9 @@
        fileno(ferr));
 }
 
-EditLine *
-el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
-    int fdin, int fdout, int fderr)
+libedit_private EditLine *
+el_init_internal(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
+    int fdin, int fdout, int fderr, int flags)
 {
        EditLine *el = el_malloc(sizeof(*el));
 
@@ -95,7 +95,7 @@
        /*
          * Initialize all the modules. Order is important!!!
          */
-       el->el_flags = 0;
+       el->el_flags = flags;
        if (setlocale(LC_CTYPE, NULL) != NULL){
                if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
                        el->el_flags |= CHARSET_IS_UTF8;
@@ -123,6 +123,12 @@
        return el;
 }
 
+EditLine *
+el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr,
+    int fdin, int fdout, int fderr)
+{
+       return el_init_internal(prog, fin, fout, ferr, fdin, fdout, fderr, 0);
+}
 
 /* el_end():
  *     Clean up.
diff -r f1058d191496 -r f24323c05be5 lib/libedit/el.h
--- a/lib/libedit/el.h  Tue Sep 05 17:21:09 2017 +0000
+++ b/lib/libedit/el.h  Tue Sep 05 18:07:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.h,v 1.42 2017/06/27 23:25:13 christos Exp $ */
+/*     $NetBSD: el.h,v 1.43 2017/09/05 18:07:59 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -57,6 +57,7 @@
 #define        UNBUFFERED      0x08
 #define        CHARSET_IS_UTF8 0x10
 #define        NARROW_HISTORY  0x40
+#define        NO_RESET        0x80
 
 typedef unsigned char el_action_t;     /* Index to command array       */
 
@@ -141,6 +142,8 @@
 };
 
 libedit_private int    el_editmode(EditLine *, int, const wchar_t **);
+libedit_private EditLine *el_init_internal(const char *, FILE *, FILE *,
+    FILE *, int, int, int, int);
 
 #ifdef DEBUG
 #define        EL_ABORT(a)     do { \
diff -r f1058d191496 -r f24323c05be5 lib/libedit/readline.c
--- a/lib/libedit/readline.c    Tue Sep 05 17:21:09 2017 +0000
+++ b/lib/libedit/readline.c    Tue Sep 05 18:07:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: readline.c,v 1.142 2017/09/01 10:19:10 christos Exp $  */
+/*     $NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $  */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.142 2017/09/01 10:19:10 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.143 2017/09/05 18:07:59 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -290,7 +290,9 @@
        if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0)
                editmode = 0;
 
-       e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
+       e = el_init_internal(rl_readline_name, rl_instream, rl_outstream,
+           stderr, fileno(rl_instream), fileno(rl_outstream), fileno(stderr),
+           NO_RESET);
 
        if (!editmode)
                el_set(e, EL_EDITMODE, 0);
@@ -386,6 +388,8 @@
        _resize_fun(e, &rl_line_buffer);
        _rl_update_pos();
 
+       tty_end(e);
+
        return 0;
 }
 
@@ -410,15 +414,17 @@
                rl_did_startup_hook = 1;
                (*rl_startup_hook)(NULL, 0);
        }
+       tty_init(e);
 
 
        rl_done = 0;
 
        (void)setjmp(topbuf);
+       buf = NULL;
 
        /* update prompt accordingly to what has been passed */
        if (rl_set_prompt(prompt) == -1)
-               return NULL;
+               goto out;
 
        if (rl_pre_input_hook)
                (*rl_pre_input_hook)(NULL, 0);
@@ -443,7 +449,7 @@
 
                buf = strdup(ret);
                if (buf == NULL)
-                       return NULL;
+                       goto out;
                lastidx = count - 1;
                if (buf[lastidx] == '\n')
                        buf[lastidx] = '\0';
@@ -453,6 +459,8 @@
        history(h, &ev, H_GETSIZE);
        history_length = ev.num;
 
+out:
+       tty_end(e);
        return buf;
 }
 
diff -r f1058d191496 -r f24323c05be5 lib/libedit/tty.c
--- a/lib/libedit/tty.c Tue Sep 05 17:21:09 2017 +0000
+++ b/lib/libedit/tty.c Tue Sep 05 18:07:59 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $        */
+/*     $NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)tty.c      8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -497,7 +497,7 @@
 static int
 tty_setup(EditLine *el)
 {
-       int rst = 1;
+       int rst = (el->el_flags & NO_RESET) == 0;
 
        if (el->el_flags & EDIT_DISABLED)
                return 0;



Home | Main Index | Thread Index | Old Index