]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_ttyflags.c
ncurses 5.7 - patch 20090728
[ncurses.git] / ncurses / tinfo / lib_ttyflags.c
index 66f08ec9fc1897772c522ffa8568d0727ceab7b0..17b13b2d0c6324f2e3a7d91c86570ad7a852b85e 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 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            *
  */
 
 #include <curses.priv.h>
-#include <term.h>              /* cur_term */
 
-MODULE_ID("$Id: lib_ttyflags.c,v 1.14 2006/12/30 21:37:20 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_ttyflags.c,v 1.25 2009/06/06 19:10:05 tom Exp $")
 
 NCURSES_EXPORT(int)
-_nc_get_tty_mode(TTY * buf)
+NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
 {
     int result = OK;
 
-    if (cur_term == 0) {
+    if (buf == 0 || SP_PARM == 0) {
        result = ERR;
     } else {
-       for (;;) {
-           if (GET_TTY(cur_term->Filedes, buf) != 0) {
-               if (errno == EINTR)
-                   continue;
-               result = ERR;
+       TERMINAL *termp = TerminalOf(SP_PARM);
+
+       if (0 == termp) {
+           result = ERR;
+       } else {
+#ifdef USE_TERM_DRIVER
+           result = CallDriver_2(SP_PARM, sgmode, FALSE, buf);
+#else
+           for (;;) {
+               if (GET_TTY(termp->Filedes, buf) != 0) {
+                   if (errno == EINTR)
+                       continue;
+                   result = ERR;
+               }
+               break;
            }
-           break;
+#endif
        }
-    }
 
-    if (result == ERR)
-       memset(buf, 0, sizeof(*buf));
+       if (result == ERR)
+           memset(buf, 0, sizeof(*buf));
 
-    TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
-                   cur_term->Filedes, _nc_trace_ttymode(buf)));
+       TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
+                       termp ? termp->Filedes : -1,
+                       _nc_trace_ttymode(buf)));
+    }
     return (result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
-_nc_set_tty_mode(TTY * buf)
+_nc_get_tty_mode(TTY * buf)
+{
+    return NCURSES_SP_NAME(_nc_get_tty_mode) (CURRENT_SCREEN, buf);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
 {
     int result = OK;
 
-    if (cur_term == 0) {
+    if (buf == 0 || SP_PARM == 0) {
        result = ERR;
     } else {
-       for (;;) {
-           if (SET_TTY(cur_term->Filedes, buf) != 0) {
-               if (errno == EINTR)
-                   continue;
-               if ((errno == ENOTTY) && (SP != 0))
-                   SP->_notty = TRUE;
-               result = ERR;
+       TERMINAL *termp = TerminalOf(SP_PARM);
+
+       if (0 == termp) {
+           result = ERR;
+       } else {
+#ifdef USE_TERM_DRIVER
+           result = CallDriver_2(SP_PARM, sgmode, TRUE, buf);
+#else
+           for (;;) {
+               if (SET_TTY(termp->Filedes, buf) != 0) {
+                   if (errno == EINTR)
+                       continue;
+                   if ((errno == ENOTTY) && (SP_PARM != 0))
+                       SP_PARM->_notty = TRUE;
+                   result = ERR;
+               }
+               break;
            }
-           break;
+#endif
        }
+       TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
+                       termp ? termp->Filedes : -1,
+                       _nc_trace_ttymode(buf)));
     }
-    TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
-                   cur_term->Filedes, _nc_trace_ttymode(buf)));
     return (result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+_nc_set_tty_mode(TTY * buf)
+{
+    return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
+
+    T((T_CALLED("def_shell_mode(%p)"), SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+       rc = CallDriver_2(SP_PARM, mode, FALSE, TRUE);
+#else
+       /*
+        * If XTABS was on, remove the tab and backtab capabilities.
+        */
+       if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
+#ifdef TERMIOS
+           if (termp->Ottyb.c_oflag & OFLAGS_TABS)
+               tab = back_tab = NULL;
+#else
+           if (termp->Ottyb.sg_flags & XTABS)
+               tab = back_tab = NULL;
+#endif
+           rc = OK;
+       }
+#endif
+    }
+    returnCode(rc);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 def_shell_mode(void)
 {
-    T((T_CALLED("def_shell_mode()")));
+    return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
+}
+#endif
 
-    /*
-     * If XTABS was on, remove the tab and backtab capabilities.
-     */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
-       returnCode(ERR);
+    T((T_CALLED("def_prog_mode(%p)"), SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+       rc = CallDriver_2(SP_PARM, 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
-    if (cur_term->Ottyb.c_oflag & OFLAGS_TABS)
-       tab = back_tab = NULL;
+           termp->Nttyb.c_oflag &= ~OFLAGS_TABS;
 #else
-    if (cur_term->Ottyb.sg_flags & XTABS)
-       tab = back_tab = NULL;
+           termp->Nttyb.sg_flags &= ~XTABS;
 #endif
-    returnCode(OK);
+           rc = OK;
+       }
+#endif
+    }
+    returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 def_prog_mode(void)
 {
-    T((T_CALLED("def_prog_mode()")));
+    return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
+}
+#endif
 
-    /*
-     * Turn off the XTABS bit in the tty structure if it was on.
-     */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
-       returnCode(ERR);
-#ifdef TERMIOS
-    cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS;
+    T((T_CALLED("reset_prog_mode(%p)"), SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+       rc = CallDriver_2(SP_PARM, mode, TRUE, FALSE);
 #else
-    cur_term->Nttyb.sg_flags &= ~XTABS;
+       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;
+       }
 #endif
-    returnCode(OK);
+    }
+    returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 reset_prog_mode(void)
 {
-    T((T_CALLED("reset_prog_mode()")));
+    return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
+{
+    int rc = ERR;
+    TERMINAL *termp = TerminalOf(SP_PARM);
 
-    if (cur_term != 0) {
-       if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
-           if (SP) {
-               if (SP->_keypad_on)
-                   _nc_keypad(TRUE);
-               NC_BUFFERED(TRUE);
-           }
-           returnCode(OK);
+    T((T_CALLED("reset_shell_mode(%p)"), SP_PARM));
+
+    if (termp != 0) {
+#ifdef USE_TERM_DRIVER
+       rc = CallDriver_2(SP_PARM, 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
     }
-    returnCode(ERR);
+    returnCode(rc);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 reset_shell_mode(void)
 {
-    T((T_CALLED("reset_shell_mode()")));
+    return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
+}
+#endif
+
+static TTY *
+saved_tty(NCURSES_SP_DCL0)
+{
+    TTY *result = 0;
 
-    if (cur_term != 0) {
-       if (SP) {
-           _nc_keypad(FALSE);
-           _nc_flush();
-           NC_BUFFERED(FALSE);
+    if (SP_PARM != 0) {
+       result = (TTY *) & (SP_PARM->_saved_tty);
+    } else {
+       if (_nc_prescreen.saved_tty == 0) {
+           _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
        }
-       returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
+       result = _nc_prescreen.saved_tty;
     }
-    returnCode(ERR);
+    return result;
 }
 
 /*
@@ -169,18 +290,32 @@ reset_shell_mode(void)
 **
 */
 
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(savetty) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("savetty(%p)"), SP_PARM));
+    returnCode(NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 savetty(void)
 {
-    T((T_CALLED("savetty()")));
+    return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
+}
+#endif
 
-    returnCode(_nc_get_tty_mode(&(SP->_saved_tty)));
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0)
+{
+    T((T_CALLED("resetty(%p)"), SP_PARM));
+    returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 resetty(void)
 {
-    T((T_CALLED("resetty()")));
-
-    returnCode(_nc_set_tty_mode(&(SP->_saved_tty)));
+    return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);
 }
+#endif