Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit save and restore the tty settings on entry and e...



details:   https://anonhg.NetBSD.org/src/rev/cbd4e8acc12d
branches:  trunk
changeset: 779277:cbd4e8acc12d
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 15 15:59:01 2012 +0000

description:
save and restore the tty settings on entry and exit respectively.
cleanup debugging printfs.

diffstat:

 lib/libedit/tty.c |  55 ++++++++++++++++++++++++++++++-------------------------
 lib/libedit/tty.h |   4 ++--
 2 files changed, 32 insertions(+), 27 deletions(-)

diffs (172 lines):

diff -r e0c079a5e174 -r cbd4e8acc12d lib/libedit/tty.c
--- a/lib/libedit/tty.c Tue May 15 15:50:58 2012 +0000
+++ b/lib/libedit/tty.c Tue May 15 15:59:01 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.c,v 1.41 2011/10/04 15:27:04 christos Exp $        */
+/*     $NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 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.41 2011/10/04 15:27:04 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -499,19 +499,19 @@
 
        if (!isatty(el->el_outfd)) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile,
-                   "tty_setup: isatty: %s\n", strerror(errno));
+               (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
+                   strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
        }
-       if (tty_getty(el, &el->el_tty.t_ed) == -1) {
+       if (tty_getty(el, &el->el_tty.t_or) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile,
-                   "tty_setup: tty_getty: %s\n", strerror(errno));
+               (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
+                   strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
        }
-       el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed;
+       el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or;
 
        el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
        el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
@@ -555,9 +555,8 @@
                tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
                if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
 #ifdef DEBUG_TTY
-                       (void) fprintf(el->el_errfile,
-                           "tty_setup: tty_setty: %s\n",
-                           strerror(errno));
+                       (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+                           __func__, strerror(errno));
 #endif /* DEBUG_TTY */
                        return -1;
                }
@@ -597,10 +596,14 @@
  */
 protected void
 /*ARGSUSED*/
-tty_end(EditLine *el __attribute__((__unused__)))
+tty_end(EditLine *el)
 {
-
-       /* XXX: Maybe reset to an initial state? */
+       if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) {
+#ifdef DEBUG_TTY
+               (void) fprintf(el->el_errfile,
+                   "%s: tty_setty: %s\n", __func__, strerror(errno));
+#endif /* DEBUG_TTY */
+       }
 }
 
 
@@ -950,7 +953,7 @@
 
        if (tty_getty(el, &el->el_tty.t_ts) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile, "tty_rawmode: tty_getty: %s\n",
+               (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
                    strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
@@ -1080,7 +1083,7 @@
        }
        if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
+               (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
                    strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
@@ -1105,8 +1108,7 @@
 
        if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile,
-                   "tty_cookedmode: tty_setty: %s\n",
+               (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
                    strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
@@ -1141,7 +1143,7 @@
 
        if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
+               (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
                    strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
@@ -1162,7 +1164,7 @@
                return 0;
        if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
 #ifdef DEBUG_TTY
-               (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
+               (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
                    strerror(errno));
 #endif /* DEBUG_TTY */
                return -1;
@@ -1246,7 +1248,8 @@
 
                                cu = strlen(m->m_name) + (x != '\0') + 1;
 
-                               if (len + cu >= (size_t)el->el_terminal.t_size.h) {
+                               if (len + cu >=
+                                   (size_t)el->el_terminal.t_size.h) {
                                        (void) fprintf(el->el_outfile, "\n%*s",
                                            (int)st, "");
                                        len = st + cu;
@@ -1278,8 +1281,10 @@
                d = s;
                p = Strchr(s, '=');
                for (m = ttymodes; m->m_name; m++)
-                       if ((p ? strncmp(m->m_name, ct_encode_string(d, &el->el_scratch), (size_t)(p - d)) :
-                           strcmp(m->m_name, ct_encode_string(d, &el->el_scratch))) == 0 &&
+                       if ((p ? strncmp(m->m_name, ct_encode_string(d,
+                           &el->el_scratch), (size_t)(p - d)) :
+                           strcmp(m->m_name, ct_encode_string(d,
+                           &el->el_scratch))) == 0 &&
                            (p == NULL || m->m_type == MD_CHAR))
                                break;
 
@@ -1318,8 +1323,8 @@
        if (el->el_tty.t_mode == z) {
                if (tty_setty(el, TCSADRAIN, tios) == -1) {
 #ifdef DEBUG_TTY
-                       (void) fprintf(el->el_errfile,
-                           "tty_stty: tty_setty: %s\n", strerror(errno));
+                       (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+                           __func__, strerror(errno));
 #endif /* DEBUG_TTY */
                        return -1;
                }
diff -r e0c079a5e174 -r cbd4e8acc12d lib/libedit/tty.h
--- a/lib/libedit/tty.h Tue May 15 15:50:58 2012 +0000
+++ b/lib/libedit/tty.h Tue May 15 15:59:01 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.h,v 1.13 2011/08/16 16:25:15 christos Exp $        */
+/*     $NetBSD: tty.h,v 1.14 2012/05/15 15:59:01 christos Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -469,7 +469,7 @@
 typedef struct {
     ttyperm_t t_t;
     ttychar_t t_c;
-    struct termios t_ex, t_ed, t_ts;
+    struct termios t_or, t_ex, t_ed, t_ts;
     int t_tabs;
     int t_eight;
     speed_t t_speed;



Home | Main Index | Thread Index | Old Index