]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_raw.c
ncurses 5.7 - patch 20090510
[ncurses.git] / ncurses / tinfo / lib_raw.c
index 61b422c1fb885a1c366e184a9e62f7ba3e89afa4..5d5a53327c3b82ddd74a92d08afd79f6a227c636 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1998-2007,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            *
 /****************************************************************************
  *  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                    *
  ****************************************************************************/
 
-
 /*
  *     raw.c
  *
  */
 
 #include <curses.priv.h>
-#include <term.h>      /* cur_term */
+#include <term.h>              /* cur_term */
 
-MODULE_ID("$Id: lib_raw.c,v 1.3 1999/03/06 22:28:24 tom Exp $")
+MODULE_ID("$Id: lib_raw.c,v 1.15 2009/02/15 00:49:02 tom Exp $")
 
-#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
 #define _POSIX_SOURCE
 #endif
 
 #if HAVE_SYS_TERMIO_H
-#include <sys/termio.h>        /* needed for ISC */
+#include <sys/termio.h>                /* needed for ISC */
 #endif
 
 #ifdef __EMX__
 #include <io.h>
-#include <fcntl.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
-#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 */
 
-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;
 
-               SP->_raw = TRUE;
-               SP->_cbreak = 1;
+    T((T_CALLED("raw()")));
 
-#ifdef __EMX__
-               setmode(SP->_ifd, O_BINARY);
-#endif
+    if (SP_PARM != 0 && cur_term != 0) {
+       TTY buf;
+
+       BEFORE("raw");
+       _nc_setmode(O_BINARY);
 
+       buf = cur_term->Nttyb;
 #ifdef TERMIOS
-               BEFORE("raw");
-               cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG);
-               cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
-               cur_term->Nttyb.c_cc[VMIN] = 1;
-               cur_term->Nttyb.c_cc[VTIME] = 0;
-               AFTER("raw");
+       buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
+       buf.c_iflag &= ~(COOKED_INPUT);
+       buf.c_cc[VMIN] = 1;
+       buf.c_cc[VTIME] = 0;
 #else
-               cur_term->Nttyb.sg_flags |= RAW;
+       buf.sg_flags |= RAW;
 #endif
-               returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+       if ((result = _nc_set_tty_mode(&buf)) == OK) {
+           SP_PARM->_raw = TRUE;
+           SP_PARM->_cbreak = 1;
+           cur_term->Nttyb = buf;
        }
-       returnCode(ERR);
+       AFTER("raw");
+    }
+    returnCode(result);
 }
 
-int cbreak(void)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+raw(void)
 {
-       T((T_CALLED("cbreak()")));
+    return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
+}
+#endif
 
-       SP->_cbreak = 1;
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
+{
+    int result = ERR;
 
-#ifdef __EMX__
-       setmode(SP->_ifd, O_BINARY);
-#endif
+    T((T_CALLED("cbreak()")));
+
+    if (SP_PARM != 0 && cur_term != 0) {
+       TTY buf;
 
-#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");
+       _nc_setmode(O_BINARY);
+
+       buf = cur_term->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
-       cur_term->Nttyb.sg_flags |= CBREAK;
+       buf.sg_flags |= CBREAK;
 #endif
-       returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+       if ((result = _nc_set_tty_mode(&buf)) == OK) {
+           SP_PARM->_cbreak = 1;
+           cur_term->Nttyb = buf;
+       }
+       AFTER("cbreak");
+    }
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+cbreak(void)
+{
+    return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
 }
+#endif
 
-void qiflush(void)
+/*
+ * Note:
+ * this implementation may be wrong.  See the comment under intrflush().
+ */
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
 {
-       T((T_CALLED("qiflush()")));
+    int result = ERR;
 
-       /*
-        * Note: this implementation may be wrong.  See the comment under
-        * intrflush().
-        */
+    T((T_CALLED("qiflush()")));
+
+    if (cur_term != 0) {
+       TTY buf;
 
-#ifdef TERMIOS
        BEFORE("qiflush");
-       cur_term->Nttyb.c_lflag &= ~(NOFLSH);
-       AFTER("qiflush");
-       (void)_nc_set_tty_mode( &cur_term->Nttyb);
-       returnVoid;
+       buf = cur_term->Nttyb;
+#ifdef TERMIOS
+       buf.c_lflag &= ~(NOFLSH);
+       result = _nc_set_tty_mode(&buf);
+#else
+       /* FIXME */
 #endif
+       if (result == OK)
+           cur_term->Nttyb = buf;
+       AFTER("qiflush");
+    }
+    returnVoid;
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+qiflush(void)
+{
+    NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
+}
+#endif
 
-int noraw(void)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
 {
-       T((T_CALLED("noraw()")));
+    int result = ERR;
 
-       SP->_raw = FALSE;
-       SP->_cbreak = 0;
+    T((T_CALLED("noraw()")));
 
-#ifdef __EMX__
-       setmode(SP->_ifd, O_TEXT);
-#endif
+    if (SP_PARM != 0 && cur_term != 0) {
+       TTY buf;
 
-#ifdef TERMIOS
        BEFORE("noraw");
-       cur_term->Nttyb.c_lflag |= ISIG|ICANON;
-       cur_term->Nttyb.c_iflag |= COOKED_INPUT;
-       AFTER("noraw");
+       _nc_setmode(O_TEXT);
+
+       buf = cur_term->Nttyb;
+#ifdef TERMIOS
+       buf.c_lflag |= ISIG | ICANON |
+           (cur_term->Ottyb.c_lflag & IEXTEN);
+       buf.c_iflag |= COOKED_INPUT;
 #else
-       cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
+       buf.sg_flags &= ~(RAW | CBREAK);
 #endif
-       returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+       if ((result = _nc_set_tty_mode(&buf)) == OK) {
+           SP_PARM->_raw = FALSE;
+           SP_PARM->_cbreak = 0;
+           cur_term->Nttyb = buf;
+       }
+       AFTER("noraw");
+    }
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+noraw(void)
+{
+    return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
+}
+#endif
 
-int nocbreak(void)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
 {
-       T((T_CALLED("nocbreak()")));
+    int result = ERR;
 
-       SP->_cbreak = 0;
+    T((T_CALLED("nocbreak()")));
 
-#ifdef __EMX__
-       setmode(SP->_ifd, O_TEXT);
-#endif
+    if (SP_PARM != 0 && cur_term != 0) {
+       TTY buf;
 
-#ifdef TERMIOS
        BEFORE("nocbreak");
-       cur_term->Nttyb.c_lflag |= ICANON;
-       cur_term->Nttyb.c_iflag |= ICRNL;
-       AFTER("nocbreak");
+       _nc_setmode(O_TEXT);
+
+       buf = cur_term->Nttyb;
+#ifdef TERMIOS
+       buf.c_lflag |= ICANON;
+       buf.c_iflag |= ICRNL;
 #else
-       cur_term->Nttyb.sg_flags &= ~CBREAK;
+       buf.sg_flags &= ~CBREAK;
 #endif
-       returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+       if ((result = _nc_set_tty_mode(&buf)) == OK) {
+           SP_PARM->_cbreak = 0;
+           cur_term->Nttyb = buf;
+       }
+       AFTER("nocbreak");
+    }
+    returnCode(result);
 }
 
-void noqiflush(void)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+nocbreak(void)
+{
+    return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
+}
+#endif
+
+/*
+ * Note:
+ * this implementation may be wrong.  See the comment under intrflush().
+ */
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
 {
-       T((T_CALLED("noqiflush()")));
+    int result = ERR;
 
-       /*
-        * Note: this implementation may be wrong.  See the comment under
-        * intrflush().
-        */
+    T((T_CALLED("noqiflush()")));
+
+    if (cur_term != 0) {
+       TTY buf;
 
-#ifdef TERMIOS
        BEFORE("noqiflush");
-       cur_term->Nttyb.c_lflag |= NOFLSH;
-       AFTER("noqiflush");
-       (void)_nc_set_tty_mode( &cur_term->Nttyb);
-       returnVoid;
+       buf = cur_term->Nttyb;
+#ifdef TERMIOS
+       buf.c_lflag |= NOFLSH;
+       result = _nc_set_tty_mode(&buf);
+#else
+       /* FIXME */
 #endif
+       if (result == OK) {
+           cur_term->Nttyb = buf;
+       }
+       AFTER("noqiflush");
+    }
+    returnVoid;
 }
 
-int intrflush(WINDOW *win GCC_UNUSED, bool flag)
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+noqiflush(void)
 {
-       T((T_CALLED("intrflush(%d)"), flag));
+    NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
+}
+#endif
 
-       /*
-        * 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.
-        */
+/*
+ * 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)
+{
+    int result = ERR;
+
+    T((T_CALLED("intrflush(%d)"), flag));
+
+    if (cur_term != 0) {
+       TTY buf;
 
-#ifdef TERMIOS
        BEFORE("intrflush");
+       buf = cur_term->Nttyb;
+#ifdef TERMIOS
        if (flag)
-               cur_term->Nttyb.c_lflag &= ~(NOFLSH);
+           buf.c_lflag &= ~(NOFLSH);
        else
-               cur_term->Nttyb.c_lflag |= (NOFLSH);
-       AFTER("intrflush");
-       returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+           buf.c_lflag |= (NOFLSH);
+       result = _nc_set_tty_mode(&buf);
 #else
-       returnCode(ERR);
+       /* FIXME */
 #endif
+       if (result == OK) {
+           cur_term->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