ncurses 6.1 - patch 20181215
[ncurses.git] / ncurses / tinfo / lib_raw.c
index 5d5a53327c3b82ddd74a92d08afd79f6a227c636..173b3a36551a9525eacc67a49e1e001f62d78199 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2007,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            *
  */
 
 #include <curses.priv.h>
-#include <term.h>              /* cur_term */
 
-MODULE_ID("$Id: lib_raw.c,v 1.15 2009/02/15 00:49:02 tom Exp $")
-
-#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
-#define _POSIX_SOURCE
-#endif
+MODULE_ID("$Id: lib_raw.c,v 1.23 2017/04/15 22:24:45 tom Exp $")
 
 #if HAVE_SYS_TERMIO_H
 #include <sys/termio.h>                /* needed for ISC */
@@ -67,6 +62,11 @@ MODULE_ID("$Id: lib_raw.c,v 1.15 2009/02/15 00:49:02 tom Exp $")
 #define _nc_setmode(mode)      /* nothing */
 #endif
 
+#if USE_KLIBC_KBD
+#define INCL_KBD
+#include <os2.h>
+#endif
+
 #define COOKED_INPUT   (IXON|BRKINT|PARMRK)
 
 #ifdef TRACE
@@ -81,28 +81,42 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("raw()")));
-
-    if (SP_PARM != 0 && cur_term != 0) {
+    T((T_CALLED("raw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
 
        BEFORE("raw");
        _nc_setmode(O_BINARY);
 
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
-       buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
-       buf.c_iflag &= ~(COOKED_INPUT);
+       buf.c_lflag &= (unsigned) ~(ICANON | ISIG | IEXTEN);
+       buf.c_iflag &= (unsigned) ~(COOKED_INPUT);
        buf.c_cc[VMIN] = 1;
        buf.c_cc[VTIME] = 0;
 #else
        buf.sg_flags |= RAW;
 #endif
-       if ((result = _nc_set_tty_mode(&buf)) == OK) {
-           SP_PARM->_raw = TRUE;
-           SP_PARM->_cbreak = 1;
-           cur_term->Nttyb = buf;
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+#if USE_KLIBC_KBD
+           KBDINFO kbdinfo;
+
+           kbdinfo.cb = sizeof(kbdinfo);
+           KbdGetStatus(&kbdinfo, 0);
+
+           kbdinfo.cb = sizeof(kbdinfo);
+           kbdinfo.fsMask &= ~KEYBOARD_ASCII_MODE;
+           kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
+           KbdSetStatus(&kbdinfo, 0);
+#endif
+           if (SP_PARM) {
+               SP_PARM->_raw = TRUE;
+               SP_PARM->_cbreak = 1;
+           }
+           termp->Nttyb = buf;
        }
        AFTER("raw");
     }
@@ -121,28 +135,31 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("cbreak()")));
-
-    if (SP_PARM != 0 && cur_term != 0) {
+    T((T_CALLED("cbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
 
        BEFORE("cbreak");
        _nc_setmode(O_BINARY);
 
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
-       buf.c_lflag &= ~ICANON;
-       buf.c_iflag &= ~ICRNL;
+       buf.c_lflag &= (unsigned) ~ICANON;
+       buf.c_iflag &= (unsigned) ~ICRNL;
        buf.c_lflag |= ISIG;
        buf.c_cc[VMIN] = 1;
        buf.c_cc[VTIME] = 0;
 #else
        buf.sg_flags |= CBREAK;
 #endif
-       if ((result = _nc_set_tty_mode(&buf)) == OK) {
-           SP_PARM->_cbreak = 1;
-           cur_term->Nttyb = buf;
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           if (SP_PARM) {
+               SP_PARM->_cbreak = 1;
+           }
+           termp->Nttyb = buf;
        }
        AFTER("cbreak");
     }
@@ -164,23 +181,24 @@ cbreak(void)
 NCURSES_EXPORT(void)
 NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
 {
-    int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("qiflush()")));
-
-    if (cur_term != 0) {
+    T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
+       int result;
 
        BEFORE("qiflush");
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
-       buf.c_lflag &= ~(NOFLSH);
-       result = _nc_set_tty_mode(&buf);
+       buf.c_lflag &= (unsigned) ~(NOFLSH);
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
+       result = ERR;
        /* FIXME */
 #endif
        if (result == OK)
-           cur_term->Nttyb = buf;
+           termp->Nttyb = buf;
        AFTER("qiflush");
     }
     returnVoid;
@@ -198,27 +216,41 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("noraw()")));
-
-    if (SP_PARM != 0 && cur_term != 0) {
+    T((T_CALLED("noraw(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
 
        BEFORE("noraw");
        _nc_setmode(O_TEXT);
 
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
        buf.c_lflag |= ISIG | ICANON |
-           (cur_term->Ottyb.c_lflag & IEXTEN);
+           (termp->Ottyb.c_lflag & IEXTEN);
        buf.c_iflag |= COOKED_INPUT;
 #else
        buf.sg_flags &= ~(RAW | CBREAK);
 #endif
-       if ((result = _nc_set_tty_mode(&buf)) == OK) {
-           SP_PARM->_raw = FALSE;
-           SP_PARM->_cbreak = 0;
-           cur_term->Nttyb = buf;
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+#if USE_KLIBC_KBD
+           KBDINFO kbdinfo;
+
+           kbdinfo.cb = sizeof(kbdinfo);
+           KbdGetStatus(&kbdinfo, 0);
+
+           kbdinfo.cb = sizeof(kbdinfo);
+           kbdinfo.fsMask &= ~KEYBOARD_BINARY_MODE;
+           kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
+           KbdSetStatus(&kbdinfo, 0);
+#endif
+           if (SP_PARM) {
+               SP_PARM->_raw = FALSE;
+               SP_PARM->_cbreak = 0;
+           }
+           termp->Nttyb = buf;
        }
        AFTER("noraw");
     }
@@ -237,25 +269,28 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("nocbreak()")));
-
-    if (SP_PARM != 0 && cur_term != 0) {
+    T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
 
        BEFORE("nocbreak");
        _nc_setmode(O_TEXT);
 
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
        buf.c_lflag |= ICANON;
        buf.c_iflag |= ICRNL;
 #else
        buf.sg_flags &= ~CBREAK;
 #endif
-       if ((result = _nc_set_tty_mode(&buf)) == OK) {
-           SP_PARM->_cbreak = 0;
-           cur_term->Nttyb = buf;
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
+       if (result == OK) {
+           if (SP_PARM) {
+               SP_PARM->_cbreak = 0;
+           }
+           termp->Nttyb = buf;
        }
        AFTER("nocbreak");
     }
@@ -270,31 +305,27 @@ nocbreak(void)
 }
 #endif
 
-/*
- * Note:
- * this implementation may be wrong.  See the comment under intrflush().
- */
 NCURSES_EXPORT(void)
 NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
 {
-    int result = ERR;
-
-    T((T_CALLED("noqiflush()")));
+    TERMINAL *termp;
 
-    if (cur_term != 0) {
+    T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
+       int result;
 
        BEFORE("noqiflush");
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
        buf.c_lflag |= NOFLSH;
-       result = _nc_set_tty_mode(&buf);
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
        /* FIXME */
+       result = ERR;
 #endif
-       if (result == OK) {
-           cur_term->Nttyb = buf;
-       }
+       if (result == OK)
+           termp->Nttyb = buf;
        AFTER("noqiflush");
     }
     returnVoid;
@@ -319,25 +350,28 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
 {
     int result = ERR;
+    TERMINAL *termp;
 
-    T((T_CALLED("intrflush(%d)"), flag));
+    T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag));
+    if (SP_PARM == 0)
+       returnCode(ERR);
 
-    if (cur_term != 0) {
+    if ((termp = TerminalOf(SP_PARM)) != 0) {
        TTY buf;
 
        BEFORE("intrflush");
-       buf = cur_term->Nttyb;
+       buf = termp->Nttyb;
 #ifdef TERMIOS
        if (flag)
-           buf.c_lflag &= ~(NOFLSH);
+           buf.c_lflag &= (unsigned) ~(NOFLSH);
        else
            buf.c_lflag |= (NOFLSH);
-       result = _nc_set_tty_mode(&buf);
+       result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
 #else
        /* FIXME */
 #endif
        if (result == OK) {
-           cur_term->Nttyb = buf;
+           termp->Nttyb = buf;
        }
        AFTER("intrflush");
     }