1998-03-01 12:21:12 +08:00
|
|
|
/****************************************************************************
|
2009-02-15 10:14:18 +08:00
|
|
|
* Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
|
1998-03-01 12:21:12 +08:00
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
/*
|
1999-10-24 12:32:42 +08:00
|
|
|
* def_prog_mode()
|
|
|
|
* def_shell_mode()
|
|
|
|
* reset_prog_mode()
|
|
|
|
* reset_shell_mode()
|
|
|
|
* savetty()
|
|
|
|
* resetty()
|
1997-05-15 12:00:00 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <curses.priv.h>
|
|
|
|
|
2009-05-11 07:36:12 +08:00
|
|
|
#ifndef CUR
|
2009-06-07 08:51:13 +08:00
|
|
|
#define CUR SP_TERMTYPE
|
2009-05-11 07:36:12 +08:00
|
|
|
#endif
|
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
MODULE_ID("$Id: lib_ttyflags.c,v 1.25 2009/06/06 19:10:05 tom Exp $")
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-05-11 07:36:12 +08:00
|
|
|
NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
|
1999-10-24 12:32:42 +08:00
|
|
|
{
|
2006-12-18 12:32:42 +08:00
|
|
|
int result = OK;
|
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
if (buf == 0 || SP_PARM == 0) {
|
2006-12-18 12:32:42 +08:00
|
|
|
result = ERR;
|
|
|
|
} else {
|
2009-06-07 08:51:13 +08:00
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
|
|
|
|
|
|
|
if (0 == termp) {
|
2007-05-27 07:44:27 +08:00
|
|
|
result = ERR;
|
|
|
|
} else {
|
2009-06-07 08:51:13 +08:00
|
|
|
#ifdef USE_TERM_DRIVER
|
|
|
|
result = CallDriver_2(SP_PARM, sgmode, FALSE, buf);
|
|
|
|
#else
|
2007-05-27 07:44:27 +08:00
|
|
|
for (;;) {
|
2009-06-07 08:51:13 +08:00
|
|
|
if (GET_TTY(termp->Filedes, buf) != 0) {
|
2007-05-27 07:44:27 +08:00
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
result = ERR;
|
|
|
|
}
|
|
|
|
break;
|
2006-12-18 12:32:42 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|
2006-12-18 12:32:42 +08:00
|
|
|
}
|
|
|
|
|
2007-05-27 07:44:27 +08:00
|
|
|
if (result == ERR)
|
|
|
|
memset(buf, 0, sizeof(*buf));
|
2006-12-18 12:32:42 +08:00
|
|
|
|
2007-05-27 07:44:27 +08:00
|
|
|
TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
|
2009-06-07 08:51:13 +08:00
|
|
|
termp ? termp->Filedes : -1,
|
2008-08-05 09:06:16 +08:00
|
|
|
_nc_trace_ttymode(buf)));
|
2007-05-27 07:44:27 +08:00
|
|
|
}
|
2006-12-18 12:32:42 +08:00
|
|
|
return (result);
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 07:36:12 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-05-11 07:36:12 +08:00
|
|
|
_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)
|
1999-10-24 12:32:42 +08:00
|
|
|
{
|
2006-12-18 12:32:42 +08:00
|
|
|
int result = OK;
|
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
if (buf == 0 || SP_PARM == 0) {
|
2006-12-18 12:32:42 +08:00
|
|
|
result = ERR;
|
|
|
|
} else {
|
2009-06-07 08:51:13 +08:00
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
|
|
|
|
|
|
|
if (0 == termp) {
|
2007-05-27 07:44:27 +08:00
|
|
|
result = ERR;
|
|
|
|
} else {
|
2009-06-07 08:51:13 +08:00
|
|
|
#ifdef USE_TERM_DRIVER
|
|
|
|
result = CallDriver_2(SP_PARM, sgmode, TRUE, buf);
|
|
|
|
#else
|
2007-05-27 07:44:27 +08:00
|
|
|
for (;;) {
|
2009-06-07 08:51:13 +08:00
|
|
|
if (SET_TTY(termp->Filedes, buf) != 0) {
|
2007-05-27 07:44:27 +08:00
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
2009-05-11 07:36:12 +08:00
|
|
|
if ((errno == ENOTTY) && (SP_PARM != 0))
|
|
|
|
SP_PARM->_notty = TRUE;
|
2007-05-27 07:44:27 +08:00
|
|
|
result = ERR;
|
|
|
|
}
|
|
|
|
break;
|
2006-12-18 12:32:42 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|
2006-12-18 12:32:42 +08:00
|
|
|
}
|
2007-05-27 07:44:27 +08:00
|
|
|
TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
|
2009-06-07 08:51:13 +08:00
|
|
|
termp ? termp->Filedes : -1,
|
2008-08-05 09:06:16 +08:00
|
|
|
_nc_trace_ttymode(buf)));
|
2004-02-09 10:15:26 +08:00
|
|
|
}
|
2006-12-18 12:32:42 +08:00
|
|
|
return (result);
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
|
|
|
|
2009-05-11 07:36:12 +08:00
|
|
|
#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
|
|
|
|
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-02-15 10:14:18 +08:00
|
|
|
NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
2008-06-22 08:16:39 +08:00
|
|
|
int rc = ERR;
|
2009-06-07 08:51:13 +08:00
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
T((T_CALLED("def_shell_mode(%p)"), SP_PARM));
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
if (termp != 0) {
|
|
|
|
#ifdef USE_TERM_DRIVER
|
|
|
|
rc = CallDriver_2(SP_PARM, mode, FALSE, TRUE);
|
|
|
|
#else
|
2008-06-22 08:16:39 +08:00
|
|
|
/*
|
|
|
|
* If XTABS was on, remove the tab and backtab capabilities.
|
|
|
|
*/
|
2009-06-07 08:51:13 +08:00
|
|
|
if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
|
1997-05-15 12:00:00 +08:00
|
|
|
#ifdef TERMIOS
|
2009-06-07 08:51:13 +08:00
|
|
|
if (termp->Ottyb.c_oflag & OFLAGS_TABS)
|
2008-06-22 08:16:39 +08:00
|
|
|
tab = back_tab = NULL;
|
1997-05-15 12:00:00 +08:00
|
|
|
#else
|
2009-06-07 08:51:13 +08:00
|
|
|
if (termp->Ottyb.sg_flags & XTABS)
|
2008-06-22 08:16:39 +08:00
|
|
|
tab = back_tab = NULL;
|
1997-05-15 12:00:00 +08:00
|
|
|
#endif
|
2008-06-22 08:16:39 +08:00
|
|
|
rc = OK;
|
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|
2008-06-22 08:16:39 +08:00
|
|
|
}
|
|
|
|
returnCode(rc);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
2009-02-15 10:14:18 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-02-15 10:14:18 +08:00
|
|
|
def_shell_mode(void)
|
|
|
|
{
|
|
|
|
return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
2008-06-22 08:16:39 +08:00
|
|
|
int rc = ERR;
|
2009-06-07 08:51:13 +08:00
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
T((T_CALLED("def_prog_mode(%p)"), SP_PARM));
|
2006-12-18 12:32:42 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
if (termp != 0) {
|
|
|
|
#ifdef USE_TERM_DRIVER
|
|
|
|
rc = CallDriver_2(SP_PARM, mode, TRUE, TRUE);
|
|
|
|
#else
|
2008-06-22 08:16:39 +08:00
|
|
|
/*
|
|
|
|
* Turn off the XTABS bit in the tty structure if it was on.
|
|
|
|
*/
|
2009-06-07 08:51:13 +08:00
|
|
|
if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
|
1997-05-15 12:00:00 +08:00
|
|
|
#ifdef TERMIOS
|
2009-06-07 08:51:13 +08:00
|
|
|
termp->Nttyb.c_oflag &= ~OFLAGS_TABS;
|
1997-05-15 12:00:00 +08:00
|
|
|
#else
|
2009-06-07 08:51:13 +08:00
|
|
|
termp->Nttyb.sg_flags &= ~XTABS;
|
1997-05-15 12:00:00 +08:00
|
|
|
#endif
|
2008-06-22 08:16:39 +08:00
|
|
|
rc = OK;
|
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|
2008-06-22 08:16:39 +08:00
|
|
|
}
|
|
|
|
returnCode(rc);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
2009-02-15 10:14:18 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-02-15 10:14:18 +08:00
|
|
|
def_prog_mode(void)
|
|
|
|
{
|
|
|
|
return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
|
1999-10-24 12:32:42 +08:00
|
|
|
{
|
2009-06-07 08:51:13 +08:00
|
|
|
int rc = ERR;
|
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
2002-10-13 11:35:53 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
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
|
|
|
|
if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
|
2009-02-15 10:14:18 +08:00
|
|
|
if (SP_PARM) {
|
|
|
|
if (SP_PARM->_keypad_on)
|
|
|
|
_nc_keypad(SP_PARM, TRUE);
|
2009-05-11 07:36:12 +08:00
|
|
|
NC_BUFFERED(SP_PARM, TRUE);
|
2002-10-13 11:35:53 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
rc = OK;
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|
2002-10-13 11:35:53 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
returnCode(rc);
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
|
|
|
|
2009-02-15 10:14:18 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2009-02-15 10:14:18 +08:00
|
|
|
reset_prog_mode(void)
|
|
|
|
{
|
|
|
|
return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
2009-06-07 08:51:13 +08:00
|
|
|
int rc = ERR;
|
|
|
|
TERMINAL *termp = TerminalOf(SP_PARM);
|
2002-10-13 11:35:53 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
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
|
2009-02-15 10:14:18 +08:00
|
|
|
if (SP_PARM) {
|
|
|
|
_nc_keypad(SP_PARM, FALSE);
|
2002-10-13 11:35:53 +08:00
|
|
|
_nc_flush();
|
2009-05-11 07:36:12 +08:00
|
|
|
NC_BUFFERED(SP_PARM, FALSE);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
rc = _nc_set_tty_mode(&termp->Ottyb);
|
|
|
|
#endif
|
2002-10-13 11:35:53 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
returnCode(rc);
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2009-02-15 10:14:18 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
reset_shell_mode(void)
|
|
|
|
{
|
|
|
|
return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-27 07:44:27 +08:00
|
|
|
static TTY *
|
2009-06-07 08:51:13 +08:00
|
|
|
saved_tty(NCURSES_SP_DCL0)
|
2007-05-27 07:44:27 +08:00
|
|
|
{
|
|
|
|
TTY *result = 0;
|
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
if (SP_PARM != 0) {
|
|
|
|
result = (TTY *) & (SP_PARM->_saved_tty);
|
2007-05-27 07:44:27 +08:00
|
|
|
} else {
|
|
|
|
if (_nc_prescreen.saved_tty == 0) {
|
|
|
|
_nc_prescreen.saved_tty = typeCalloc(TTY, 1);
|
|
|
|
}
|
|
|
|
result = _nc_prescreen.saved_tty;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-10-24 12:32:42 +08:00
|
|
|
/*
|
|
|
|
** savetty() and resetty()
|
|
|
|
**
|
|
|
|
*/
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
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
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
savetty(void)
|
1999-10-24 12:32:42 +08:00
|
|
|
{
|
2009-06-07 08:51:13 +08:00
|
|
|
return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-24 12:32:42 +08:00
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
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)));
|
1999-10-24 12:32:42 +08:00
|
|
|
}
|
|
|
|
|
2009-06-07 08:51:13 +08:00
|
|
|
#if NCURSES_SP_FUNCS
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
|
|
|
resetty(void)
|
1999-10-24 12:32:42 +08:00
|
|
|
{
|
2009-06-07 08:51:13 +08:00
|
|
|
return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
2009-06-07 08:51:13 +08:00
|
|
|
#endif
|