]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_raw.c
ncurses 5.7 - patch 20100306
[ncurses.git] / ncurses / tinfo / lib_raw.c
index 6033ed9c10c3a7bb4bea477c9e85958e96488c67..7f67a7525e7da4b372d71f2ca6671e62e28ccf3b 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998,1999,2000 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,6 +29,8 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1998-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
  ****************************************************************************/
 
 /*
  */
 
 #include <curses.priv.h>
  */
 
 #include <curses.priv.h>
-#include <term.h>              /* cur_term */
 
 
-MODULE_ID("$Id: lib_raw.c,v 1.7 2000/02/13 01:01:26 tom Exp $")
+MODULE_ID("$Id: lib_raw.c,v 1.18 2009/10/24 21:56:15 tom Exp $")
 
 
-#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
 #define _POSIX_SOURCE
 #endif
 
 #define _POSIX_SOURCE
 #endif
 
@@ -60,177 +61,294 @@ MODULE_ID("$Id: lib_raw.c,v 1.7 2000/02/13 01:01:26 tom Exp $")
 
 #ifdef __EMX__
 #include <io.h>
 
 #ifdef __EMX__
 #include <io.h>
+#define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode)
+#else
+#define _nc_setmode(mode)      /* nothing */
 #endif
 
 #define COOKED_INPUT   (IXON|BRKINT|PARMRK)
 
 #ifdef TRACE
 #endif
 
 #define COOKED_INPUT   (IXON|BRKINT|PARMRK)
 
 #ifdef TRACE
-#define BEFORE(N)      if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits())
-#define AFTER(N)       if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits())
+#define BEFORE(N)      if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits())
+#define AFTER(N)       if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits())
 #else
 #define BEFORE(s)
 #define AFTER(s)
 #endif /* TRACE */
 
 #else
 #define BEFORE(s)
 #define AFTER(s)
 #endif /* TRACE */
 
-int
-raw(void)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0)
 {
 {
-    T((T_CALLED("raw()")));
-    if (SP != 0 && cur_term != 0) {
+    int result = ERR;
+    TERMINAL *termp;
 
 
-       SP->_raw = TRUE;
-       SP->_cbreak = 1;
+    T((T_CALLED("raw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
-#ifdef __EMX__
-       setmode(SP->_ifd, O_BINARY);
-#endif
+       BEFORE("raw");
+       _nc_setmode(O_BINARY);
 
 
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-       BEFORE("raw");
-       cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN);
-       cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
-       cur_term->Nttyb.c_cc[VMIN] = 1;
-       cur_term->Nttyb.c_cc[VTIME] = 0;
+       buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
+       buf.c_iflag &= ~(COOKED_INPUT);
+       buf.c_cc[VMIN] = 1;
+       buf.c_cc[VTIME] = 0;
+#else
+       buf.sg_flags |= RAW;
+#endif
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           SP_PARM->_raw = TRUE;
+           SP_PARM->_cbreak = 1;
+           termp->Nttyb = buf;
+       }
        AFTER("raw");
        AFTER("raw");
+    }
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+raw(void)
+{
+    return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    TERMINAL *termp;
+
+    T((T_CALLED("cbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
+
+       BEFORE("cbreak");
+       _nc_setmode(O_BINARY);
+
+       buf = termp->Nttyb;
+#ifdef TERMIOS
+       buf.c_lflag &= ~ICANON;
+       buf.c_iflag &= ~ICRNL;
+       buf.c_lflag |= ISIG;
+       buf.c_cc[VMIN] = 1;
+       buf.c_cc[VTIME] = 0;
 #else
 #else
-       cur_term->Nttyb.sg_flags |= RAW;
+       buf.sg_flags |= CBREAK;
 #endif
 #endif
-       returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           SP_PARM->_cbreak = 1;
+           termp->Nttyb = buf;
+       }
+       AFTER("cbreak");
     }
     }
-    returnCode(ERR);
+    returnCode(result);
 }
 
 }
 
-int
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 cbreak(void)
 {
 cbreak(void)
 {
-    T((T_CALLED("cbreak()")));
+    return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
+}
+#endif
 
 
-    SP->_cbreak = 1;
+/*
+ * Note:
+ * this implementation may be wrong.  See the comment under intrflush().
+ */
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    TERMINAL *termp;
 
 
-#ifdef __EMX__
-    setmode(SP->_ifd, O_BINARY);
-#endif
+    T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
+       BEFORE("qiflush");
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-    BEFORE("cbreak");
-    cur_term->Nttyb.c_lflag &= ~ICANON;
-    cur_term->Nttyb.c_iflag &= ~ICRNL;
-    cur_term->Nttyb.c_lflag |= ISIG;
-    cur_term->Nttyb.c_cc[VMIN] = 1;
-    cur_term->Nttyb.c_cc[VTIME] = 0;
-    AFTER("cbreak");
+       buf.c_lflag &= ~(NOFLSH);
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 #else
-    cur_term->Nttyb.sg_flags |= CBREAK;
+       /* FIXME */
 #endif
 #endif
-    returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       if (result == OK)
+           termp->Nttyb = buf;
+       AFTER("qiflush");
+    }
+    returnVoid;
 }
 
 }
 
-void
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 qiflush(void)
 {
 qiflush(void)
 {
-    T((T_CALLED("qiflush()")));
+    NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
+}
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    TERMINAL *termp;
 
 
-    /*
-     * Note: this implementation may be wrong.  See the comment under
-     * intrflush().
-     */
+    T((T_CALLED("noraw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
+       BEFORE("noraw");
+       _nc_setmode(O_TEXT);
+
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-    BEFORE("qiflush");
-    cur_term->Nttyb.c_lflag &= ~(NOFLSH);
-    AFTER("qiflush");
-    (void) _nc_set_tty_mode(&cur_term->Nttyb);
-    returnVoid;
+       buf.c_lflag |= ISIG | ICANON |
+           (termp->Ottyb.c_lflag & IEXTEN);
+       buf.c_iflag |= COOKED_INPUT;
+#else
+       buf.sg_flags &= ~(RAW | CBREAK);
 #endif
 #endif
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           SP_PARM->_raw = FALSE;
+           SP_PARM->_cbreak = 0;
+           termp->Nttyb = buf;
+       }
+       AFTER("noraw");
+    }
+    returnCode(result);
 }
 
 }
 
-int
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 noraw(void)
 {
 noraw(void)
 {
-    T((T_CALLED("noraw()")));
+    return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
+}
+#endif
 
 
-    SP->_raw = FALSE;
-    SP->_cbreak = 0;
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    TERMINAL *termp;
 
 
-#ifdef __EMX__
-    setmode(SP->_ifd, O_TEXT);
-#endif
+    T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
+       BEFORE("nocbreak");
+       _nc_setmode(O_TEXT);
+
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-    BEFORE("noraw");
-    cur_term->Nttyb.c_lflag |= ISIG | ICANON |
-       (cur_term->Ottyb.c_lflag & IEXTEN);
-    cur_term->Nttyb.c_iflag |= COOKED_INPUT;
-    AFTER("noraw");
+       buf.c_lflag |= ICANON;
+       buf.c_iflag |= ICRNL;
 #else
 #else
-    cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK);
+       buf.sg_flags &= ~CBREAK;
 #endif
 #endif
-    returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           SP_PARM->_cbreak = 0;
+           termp->Nttyb = buf;
+       }
+       AFTER("nocbreak");
+    }
+    returnCode(result);
 }
 
 }
 
-int
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 nocbreak(void)
 {
 nocbreak(void)
 {
-    T((T_CALLED("nocbreak()")));
+    return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
+}
+#endif
 
 
-    SP->_cbreak = 0;
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
+    TERMINAL *termp;
 
 
-#ifdef __EMX__
-    setmode(SP->_ifd, O_TEXT);
-#endif
+    T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
+       BEFORE("noqiflush");
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-    BEFORE("nocbreak");
-    cur_term->Nttyb.c_lflag |= ICANON;
-    cur_term->Nttyb.c_iflag |= ICRNL;
-    AFTER("nocbreak");
+       buf.c_lflag |= NOFLSH;
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 #else
-    cur_term->Nttyb.sg_flags &= ~CBREAK;
+       /* FIXME */
 #endif
 #endif
-    returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       if (result == OK)
+           termp->Nttyb = buf;
+       AFTER("noqiflush");
+    }
+    returnVoid;
 }
 
 }
 
-void
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
 noqiflush(void)
 {
 noqiflush(void)
 {
-    T((T_CALLED("noqiflush()")));
-
-    /*
-     * Note: this implementation may be wrong.  See the comment under
-     * intrflush().
-     */
-
-#ifdef TERMIOS
-    BEFORE("noqiflush");
-    cur_term->Nttyb.c_lflag |= NOFLSH;
-    AFTER("noqiflush");
-    (void) _nc_set_tty_mode(&cur_term->Nttyb);
-    returnVoid;
-#endif
+    NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
 }
 }
+#endif
 
 
-int
-intrflush(WINDOW *win GCC_UNUSED, bool flag)
+/*
+ * This call does the same thing as the qiflush()/noqiflush() pair.  We know
+ * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
+ * the match (in the SVr4 man pages) between the language describing NOFLSH in
+ * termio(7) and the language describing qiflush()/noqiflush() in
+ * curs_inopts(3x) is too exact to be coincidence.
+ */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
 {
 {
-    T((T_CALLED("intrflush(%d)"), flag));
+    int result = ERR;
+    TERMINAL *termp;
+
+    T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag));
+    if (SP_PARM == 0)
+       returnCode(ERR);
 
 
-    /*
-     * This call does the same thing as the qiflush()/noqiflush() pair.  We
-     * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the
-     * other hand, the match (in the SVr4 man pages) between the language
-     * describing NOFLSH in termio(7) and the language describing
-     * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence.
-     */
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
+       TTY buf;
 
 
+       BEFORE("intrflush");
+       buf = termp->Nttyb;
 #ifdef TERMIOS
 #ifdef TERMIOS
-    BEFORE("intrflush");
-    if (flag)
-       cur_term->Nttyb.c_lflag &= ~(NOFLSH);
-    else
-       cur_term->Nttyb.c_lflag |= (NOFLSH);
-    AFTER("intrflush");
-    returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       if (flag)
+           buf.c_lflag &= ~(NOFLSH);
+       else
+           buf.c_lflag |= (NOFLSH);
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
 #else
-    returnCode(ERR);
+       /* FIXME */
 #endif
 #endif
+       if (result == OK) {
+           termp->Nttyb = buf;
+       }
+       AFTER("intrflush");
+    }
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+intrflush(WINDOW *win GCC_UNUSED, bool flag)
+{
+    return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);
 }
 }
+#endif