Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit more tty modes refactoring, no functional change...



details:   https://anonhg.NetBSD.org/src/rev/b5a2e4179b85
branches:  trunk
changeset: 796088:b5a2e4179b85
user:      christos <christos%NetBSD.org@localhost>
date:      Mon May 19 19:54:12 2014 +0000

description:
more tty modes refactoring, no functional change intended.

diffstat:

 lib/libedit/tty.c |  197 +++++++++++++++++++++++------------------------------
 lib/libedit/tty.h |    3 +-
 2 files changed, 88 insertions(+), 112 deletions(-)

diffs (256 lines):

diff -r ae79398f6b31 -r b5a2e4179b85 lib/libedit/tty.c
--- a/lib/libedit/tty.c Mon May 19 18:47:19 2014 +0000
+++ b/lib/libedit/tty.c Mon May 19 19:54:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.c,v 1.43 2014/05/19 17:14:41 christos Exp $        */
+/*     $NetBSD: tty.c,v 1.44 2014/05/19 19:54:12 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.43 2014/05/19 17:14:41 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.44 2014/05/19 19:54:12 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -919,6 +919,58 @@
 }
 
 
+private tcflag_t *
+tty__get_flag(struct termios *t, int kind) {
+       switch (kind) {
+       case MD_INP:
+               return &t->c_iflag;
+       case MD_OUT:
+               return &t->c_oflag;
+       case MD_CTL:
+               return &t->c_cflag;
+       case MD_LIN:
+               return &t->c_lflag;
+       default:
+               abort();
+               /*NOTREACHED*/
+       }
+}
+
+
+private tcflag_t
+tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind)
+{
+       f &= ~el->el_tty.t_t[mode][kind].t_clrmask;
+       f |= el->el_tty.t_t[mode][kind].t_setmask;
+       return f;
+}
+
+
+private void
+tty_update_flags(EditLine *el, int kind)
+{
+       tcflag_t *tt, *ed, *ex;
+       tt = tty__get_flag(&el->el_tty.t_ts, kind);
+       ed = tty__get_flag(&el->el_tty.t_ed, kind);
+       ex = tty__get_flag(&el->el_tty.t_ex, kind);
+
+       if (*tt != *ex && (kind != MD_CTL || *tt != *ed)) {
+               *ed = tty_update_flag(el, *tt, ED_IO, kind);
+               *ex = tty_update_flag(el, *tt, EX_IO, kind);
+       }
+}
+
+
+private void
+tty_update_char(EditLine *el, int mode, int c) {
+       if (!((el->el_tty.t_t[mode][MD_CHAR].t_setmask & C_SH(c)))
+           && (el->el_tty.t_c[TS_IO][c] != el->el_tty.t_c[EX_IO][c]))
+               el->el_tty.t_c[mode][c] = el->el_tty.t_c[TS_IO][c];
+       if (el->el_tty.t_t[mode][MD_CHAR].t_clrmask & C_SH(c))
+               el->el_tty.t_c[mode][c] = el->el_tty.t_vdisable;
+}
+
+
 /* tty_rawmode():
  *     Set terminal into 1 character at a time mode.
  */
@@ -954,112 +1006,42 @@
                (void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed);
        }
        if (tty__cooked_mode(&el->el_tty.t_ts)) {
-               if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) {
-                       el->el_tty.t_ex.c_cflag =
-                           el->el_tty.t_ts.c_cflag;
-                       el->el_tty.t_ex.c_cflag &=
-                           ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask;
-                       el->el_tty.t_ex.c_cflag |=
-                           el->el_tty.t_t[EX_IO][MD_CTL].t_setmask;
-
-                       el->el_tty.t_ed.c_cflag =
-                           el->el_tty.t_ts.c_cflag;
-                       el->el_tty.t_ed.c_cflag &=
-                           ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
-                       el->el_tty.t_ed.c_cflag |=
-                           el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
-               }
-               if ((el->el_tty.t_ts.c_lflag != el->el_tty.t_ex.c_lflag) &&
-                   (el->el_tty.t_ts.c_lflag != el->el_tty.t_ed.c_lflag)) {
-                       el->el_tty.t_ex.c_lflag =
-                           el->el_tty.t_ts.c_lflag;
-                       el->el_tty.t_ex.c_lflag &=
-                           ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask;
-                       el->el_tty.t_ex.c_lflag |=
-                           el->el_tty.t_t[EX_IO][MD_LIN].t_setmask;
+               int i;
 
-                       el->el_tty.t_ed.c_lflag =
-                           el->el_tty.t_ts.c_lflag;
-                       el->el_tty.t_ed.c_lflag &=
-                           ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
-                       el->el_tty.t_ed.c_lflag |=
-                           el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
-               }
-               if ((el->el_tty.t_ts.c_iflag != el->el_tty.t_ex.c_iflag) &&
-                   (el->el_tty.t_ts.c_iflag != el->el_tty.t_ed.c_iflag)) {
-                       el->el_tty.t_ex.c_iflag =
-                           el->el_tty.t_ts.c_iflag;
-                       el->el_tty.t_ex.c_iflag &=
-                           ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask;
-                       el->el_tty.t_ex.c_iflag |=
-                           el->el_tty.t_t[EX_IO][MD_INP].t_setmask;
+               for (i = MD_INP; i <= MD_LIN; i++)
+                       tty_update_flags(el, i);
 
-                       el->el_tty.t_ed.c_iflag =
-                           el->el_tty.t_ts.c_iflag;
-                       el->el_tty.t_ed.c_iflag &=
-                           ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
-                       el->el_tty.t_ed.c_iflag |=
-                           el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
-               }
-               if ((el->el_tty.t_ts.c_oflag != el->el_tty.t_ex.c_oflag) &&
-                   (el->el_tty.t_ts.c_oflag != el->el_tty.t_ed.c_oflag)) {
-                       el->el_tty.t_ex.c_oflag =
-                           el->el_tty.t_ts.c_oflag;
-                       el->el_tty.t_ex.c_oflag &=
-                           ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask;
-                       el->el_tty.t_ex.c_oflag |=
-                           el->el_tty.t_t[EX_IO][MD_OUT].t_setmask;
-
-                       el->el_tty.t_ed.c_oflag =
-                           el->el_tty.t_ts.c_oflag;
-                       el->el_tty.t_ed.c_oflag &=
-                           ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
-                       el->el_tty.t_ed.c_oflag |=
-                           el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
-               }
                if (tty__gettabs(&el->el_tty.t_ex) == 0)
                        el->el_tty.t_tabs = 0;
                else
                        el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
 
-               {
-                       int i;
-
-                       tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
-                       /*
-                        * Check if the user made any changes.
-                        * If he did, then propagate the changes to the
-                        * edit and execute data structures.
-                        */
-                       for (i = 0; i < C_NCC; i++)
-                               if (el->el_tty.t_c[TS_IO][i] !=
-                                   el->el_tty.t_c[EX_IO][i])
-                                       break;
+               tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
+               /*
+                * Check if the user made any changes.
+                * If he did, then propagate the changes to the
+                * edit and execute data structures.
+                */
+               for (i = 0; i < C_NCC; i++)
+                       if (el->el_tty.t_c[TS_IO][i] !=
+                           el->el_tty.t_c[EX_IO][i])
+                               break;
 
-                       if (i != C_NCC) {
-                               /*
-                                * Propagate changes only to the unprotected
-                                * chars that have been modified just now.
-                                */
-                               for (i = 0; i < C_NCC; i++) {
-                                       if (!((el->el_tty.t_t[ED_IO][MD_CHAR].t_setmask & C_SH(i)))
-                                           && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
-                                               el->el_tty.t_c[ED_IO][i] = el->el_tty.t_c[TS_IO][i];
-                                       if (el->el_tty.t_t[ED_IO][MD_CHAR].t_clrmask & C_SH(i))
-                                               el->el_tty.t_c[ED_IO][i] = el->el_tty.t_vdisable;
-                               }
-                               tty_bind_char(el, 0);
-                               tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
+               if (i != C_NCC) {
+                       /*
+                        * Propagate changes only to the unprotected
+                        * chars that have been modified just now.
+                        */
+                       for (i = 0; i < C_NCC; i++)
+                               tty_update_char(el, ED_IO, i);
 
-                               for (i = 0; i < C_NCC; i++) {
-                                       if (!((el->el_tty.t_t[EX_IO][MD_CHAR].t_setmask & C_SH(i)))
-                                           && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i]))
-                                               el->el_tty.t_c[EX_IO][i] = el->el_tty.t_c[TS_IO][i];
-                                       if (el->el_tty.t_t[EX_IO][MD_CHAR].t_clrmask & C_SH(i))
-                                               el->el_tty.t_c[EX_IO][i] = el->el_tty.t_vdisable;
-                               }
-                               tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
-                       }
+                       tty_bind_char(el, 0);
+                       tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
+
+                       for (i = 0; i < C_NCC; i++)
+                               tty_update_char(el, EX_IO, i);
+
+                       tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
                }
        }
        if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
@@ -1333,16 +1315,9 @@
 private void
 tty_setup_flags(EditLine *el, struct termios *tios, int mode)
 {
-       tios->c_iflag &= ~el->el_tty.t_t[mode][MD_INP].t_clrmask;
-       tios->c_iflag |= el->el_tty.t_t[mode][MD_INP].t_setmask;
-
-       tios->c_oflag &= ~el->el_tty.t_t[mode][MD_OUT].t_clrmask;
-       tios->c_oflag |= el->el_tty.t_t[mode][MD_OUT].t_setmask;
-
-       tios->c_cflag &= ~el->el_tty.t_t[mode][MD_CTL].t_clrmask;
-       tios->c_cflag |= el->el_tty.t_t[mode][MD_CTL].t_setmask;
-
-       tios->c_lflag &= ~el->el_tty.t_t[mode][MD_LIN].t_clrmask;
-       tios->c_lflag |= el->el_tty.t_t[mode][MD_LIN].t_setmask;
+       int kind;
+       for (kind = MD_INP; kind <= MD_LIN; kind++) {
+               tcflag_t *f = tty__get_flag(tios, kind);
+               *f = tty_update_flag(el, *f, mode, kind);
+       }
 }
-
diff -r ae79398f6b31 -r b5a2e4179b85 lib/libedit/tty.h
--- a/lib/libedit/tty.h Mon May 19 18:47:19 2014 +0000
+++ b/lib/libedit/tty.h Mon May 19 19:54:12 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty.h,v 1.14 2012/05/15 15:59:01 christos Exp $        */
+/*     $NetBSD: tty.h,v 1.15 2014/05/19 19:54:12 christos Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -442,6 +442,7 @@
 #define        QU_IO   2       /* used only for quoted chars   */
 #define        NN_IO   3       /* The number of entries        */
 
+/* Don't re-order */
 #define        MD_INP  0
 #define        MD_OUT  1
 #define        MD_CTL  2



Home | Main Index | Thread Index | Old Index