]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_ttyflags.c
ncurses 6.1 - patch 20191102
[ncurses.git] / ncurses / tinfo / lib_ttyflags.c
index d0d582513806dd9deb6fa9a59a403504df84ad6f..cf065cb68a8bd1807d3296ed03c459532d03d89e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_ttyflags.c,v 1.26 2009/10/24 22:15:47 tom Exp $")
+MODULE_ID("$Id: lib_ttyflags.c,v 1.33 2017/04/02 14:30:26 tom Exp $")
 
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
 {
+    TERMINAL *termp = TerminalOf(SP_PARM);
     int result = OK;
 
-    if (buf == 0 || SP_PARM == 0) {
+    if (buf == 0 || termp == 0) {
        result = ERR;
     } else {
-       TERMINAL *termp = TerminalOf(SP_PARM);
 
-       if (0 == termp) {
-           result = ERR;
-       } else {
 #ifdef USE_TERM_DRIVER
-           result = CallDriver_2(SP_PARM, sgmode, FALSE, buf);
+       if (SP_PARM != 0) {
+           result = CallDriver_2(SP_PARM, td_sgmode, FALSE, buf);
+       } else {
+           result = ERR;
+       }
 #else
-           for (;;) {
-               if (GET_TTY(termp->Filedes, buf) != 0) {
-                   if (errno == EINTR)
-                       continue;
-                   result = ERR;
-               }
-               break;
+       for (;;) {
+           if (GET_TTY(termp->Filedes, buf) != 0) {
+               if (errno == EINTR)
+                   continue;
+               result = ERR;
            }
-#endif
+           break;
        }
-
-       if (result == ERR)
-           memset(buf, 0, sizeof(*buf));
+#endif
 
        TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
                        termp ? termp->Filedes : -1,
                        _nc_trace_ttymode(buf)));
     }
+    if (result == ERR && buf != 0)
+       memset(buf, 0, sizeof(*buf));
+
     return (result);
 }
 
@@ -102,10 +102,14 @@ NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
            result = ERR;
        } else {
 #ifdef USE_TERM_DRIVER
-           result = CallDriver_2(SP_PARM, sgmode, TRUE, buf);
+           result = CallDriver_2(SP_PARM, td_sgmode, TRUE, buf);
 #else
            for (;;) {
-               if (SET_TTY(termp->Filedes, buf) != 0) {
+               if ((SET_TTY(termp->Filedes, buf) != 0)
+#if USE_KLIBC_KBD
+                   && !NC_ISATTY(termp->Filedes)
+#endif
+                   ) {
                    if (errno == EINTR)
                        continue;
                    if ((errno == ENOTTY) && (SP_PARM != 0))
@@ -137,11 +141,12 @@ NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
     int rc = ERR;
     TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("def_shell_mode(%p)"), (void *) SP_PARM));
+    T((T_CALLED("def_shell_mode(%p) ->term %p"),
+       (void *) SP_PARM, (void *) termp));
 
     if (termp != 0) {
 #ifdef USE_TERM_DRIVER
-       rc = CallDriver_2(SP_PARM, mode, FALSE, TRUE);
+       rc = CallDriver_2(SP_PARM, td_mode, FALSE, TRUE);
 #else
        /*
         * If XTABS was on, remove the tab and backtab capabilities.
@@ -175,20 +180,20 @@ NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
     int rc = ERR;
     TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("def_prog_mode(%p)"), (void *) SP_PARM));
+    T((T_CALLED("def_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
 
     if (termp != 0) {
 #ifdef USE_TERM_DRIVER
-       rc = CallDriver_2(SP_PARM, mode, TRUE, TRUE);
+       rc = CallDriver_2(SP_PARM, td_mode, TRUE, TRUE);
 #else
        /*
         * Turn off the XTABS bit in the tty structure if it was on.
         */
        if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
 #ifdef TERMIOS
-           termp->Nttyb.c_oflag &= ~OFLAGS_TABS;
+           termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
 #else
-           termp->Nttyb.sg_flags &= ~XTABS;
+           termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
 #endif
            rc = OK;
        }
@@ -211,17 +216,16 @@ NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
     int rc = ERR;
     TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("reset_prog_mode(%p)"), (void *) SP_PARM));
+    T((T_CALLED("reset_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
 
     if (termp != 0) {
 #ifdef USE_TERM_DRIVER
-       rc = CallDriver_2(SP_PARM, mode, TRUE, FALSE);
+       rc = CallDriver_2(SP_PARM, td_mode, TRUE, FALSE);
 #else
        if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
            if (SP_PARM) {
                if (SP_PARM->_keypad_on)
                    _nc_keypad(SP_PARM, TRUE);
-               NC_BUFFERED(SP_PARM, TRUE);
            }
            rc = OK;
        }
@@ -244,16 +248,16 @@ NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
     int rc = ERR;
     TERMINAL *termp = TerminalOf(SP_PARM);
 
-    T((T_CALLED("reset_shell_mode(%p)"), (void *) SP_PARM));
+    T((T_CALLED("reset_shell_mode(%p) ->term %p"),
+       (void *) SP_PARM, (void *) termp));
 
     if (termp != 0) {
 #ifdef USE_TERM_DRIVER
-       rc = CallDriver_2(SP_PARM, mode, FALSE, FALSE);
+       rc = CallDriver_2(SP_PARM, td_mode, FALSE, FALSE);
 #else
        if (SP_PARM) {
            _nc_keypad(SP_PARM, FALSE);
            _nc_flush();
-           NC_BUFFERED(SP_PARM, FALSE);
        }
        rc = _nc_set_tty_mode(&termp->Ottyb);
 #endif