X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_ttyflags.c;h=6363a805be9c44a038aa20b87f1d414b1e487c30;hp=0e57c512b20f3e0b107cd7f85f87288743c01eb6;hb=c2650100f80134924eda8f22cd7cc1d1d919ee3d;hpb=0eb88fc5281804773e2a0c7a488a4452463535ce diff --git a/ncurses/tinfo/lib_ttyflags.c b/ncurses/tinfo/lib_ttyflags.c index 0e57c512..6363a805 100644 --- a/ncurses/tinfo/lib_ttyflags.c +++ b/ncurses/tinfo/lib_ttyflags.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 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 * @@ -36,109 +37,261 @@ */ #include -#include /* cur_term */ -MODULE_ID("$Id: lib_ttyflags.c,v 1.3 1999/10/22 21:38:55 tom Exp $") +#ifndef CUR +#define CUR SP_TERMTYPE +#endif + +MODULE_ID("$Id: lib_ttyflags.c,v 1.36 2020/09/05 22:54:47 tom Exp $") -#undef tabs +NCURSES_EXPORT(int) +NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf) +{ + TERMINAL *termp = TerminalOf(SP_PARM); + int result = OK; -#ifdef TAB3 -# define tabs TAB3 + if (buf == 0 || termp == 0) { + result = ERR; + } else { + +#ifdef USE_TERM_DRIVER + if (SP_PARM != 0) { + result = CallDriver_2(SP_PARM, td_sgmode, FALSE, buf); + } else { + result = ERR; + } #else -# ifdef XTABS -# define tabs XTABS -# else -# ifdef OXTABS -# define tabs OXTABS -# else -# define tabs 0 -# endif -# endif + for (;;) { + if (GET_TTY(termp->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + result = ERR; + } + break; + } #endif -int _nc_get_tty_mode(TTY *buf) + TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", + termp ? termp->Filedes : -1, + _nc_trace_ttymode(buf))); + } + if (result == ERR && buf != 0) + memset(buf, 0, sizeof(*buf)); + + return (result); +} + +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +_nc_get_tty_mode(TTY * buf) { - if (cur_term == 0 - || GET_TTY(cur_term->Filedes, buf) != 0) - return(ERR); - TR(TRACE_BITS,("_nc_get_tty_mode: %s", _nc_tracebits())); - return (OK); + 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 (buf == 0 || SP_PARM == 0) { + result = ERR; + } else { + TERMINAL *termp = TerminalOf(SP_PARM); + + if (0 == termp) { + result = ERR; + } else { +#ifdef USE_TERM_DRIVER + result = CallDriver_2(SP_PARM, td_sgmode, TRUE, buf); +#else + for (;;) { + if ((SET_TTY(termp->Filedes, buf) != 0) +#if USE_KLIBC_KBD + && !NC_ISATTY(termp->Filedes) +#endif + ) { + if (errno == EINTR) + continue; + if ((errno == ENOTTY) && (SP_PARM != 0)) + SP_PARM->_notty = TRUE; + result = ERR; + } + break; + } +#endif + } + TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", + termp ? termp->Filedes : -1, + _nc_trace_ttymode(buf))); + } + return (result); } -int _nc_set_tty_mode(TTY *buf) +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +_nc_set_tty_mode(TTY * buf) { - if (cur_term == 0 - || SET_TTY(cur_term->Filedes, buf) != 0) - return(ERR); - TR(TRACE_BITS,("_nc_set_tty_mode: %s", _nc_tracebits())); - return (OK); + return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf); } +#endif -int def_shell_mode(void) +NCURSES_EXPORT(int) +NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0) { - T((T_CALLED("def_shell_mode()"))); + int rc = ERR; + TERMINAL *termp = TerminalOf(SP_PARM); + + T((T_CALLED("def_shell_mode(%p) ->term %p"), + (void *) SP_PARM, (void *) termp)); + if (termp != 0) { +#ifdef USE_TERM_DRIVER + rc = CallDriver_2(SP_PARM, td_mode, FALSE, TRUE); +#else /* - * Turn off the XTABS bit in the tty structure if it was on. If XTABS - * was on, remove the tab and backtab capabilities. + * If XTABS was on, remove the tab and backtab capabilities. */ - - if (_nc_get_tty_mode(&cur_term->Ottyb) != OK) - returnCode(ERR); + if (_nc_get_tty_mode(&termp->Ottyb) == OK) { #ifdef TERMIOS - if (cur_term->Ottyb.c_oflag & tabs) + if (termp->Ottyb.c_oflag & OFLAGS_TABS) tab = back_tab = NULL; +#elif defined(EXP_WIN32_DRIVER) + /* noop */ #else - if (cur_term->Ottyb.sg_flags & XTABS) + if (termp->Ottyb.sg_flags & XTABS) tab = back_tab = NULL; #endif - returnCode(OK); + rc = OK; + } +#endif + } + returnCode(rc); } -int def_prog_mode(void) +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +def_shell_mode(void) { - T((T_CALLED("def_prog_mode()"))); + return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN); +} +#endif + +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->Nttyb) != OK) - returnCode(ERR); + T((T_CALLED("def_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp)); + + if (termp != 0) { +#ifdef USE_TERM_DRIVER + rc = CallDriver_2(SP_PARM, td_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 - cur_term->Nttyb.c_oflag &= ~tabs; + termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS); +#elif defined(EXP_WIN32_DRIVER) + /* noop */ #else - cur_term->Nttyb.sg_flags &= ~XTABS; + termp->Nttyb.sg_flags &= (unsigned) (~XTABS); #endif - returnCode(OK); + rc = OK; + } +#endif + } + returnCode(rc); } -int reset_prog_mode(void) +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +def_prog_mode(void) { - T((T_CALLED("reset_prog_mode()"))); + return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN); +} +#endif - if (cur_term != 0) { - _nc_set_tty_mode(&cur_term->Nttyb); - if (SP) { - if (stdscr && stdscr->_use_keypad) - _nc_keypad(TRUE); - NC_BUFFERED(TRUE); - } - returnCode(OK); +NCURSES_EXPORT(int) +NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0) +{ + int rc = ERR; + TERMINAL *termp = TerminalOf(SP_PARM); + + T((T_CALLED("reset_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp)); + + if (termp != 0) { +#ifdef USE_TERM_DRIVER + rc = CallDriver_2(SP_PARM, td_mode, TRUE, FALSE); +#else + if (_nc_set_tty_mode(&termp->Nttyb) == OK) { + if (SP_PARM) { + if (SP_PARM->_keypad_on) + _nc_keypad(SP_PARM, TRUE); + } + rc = OK; } - returnCode(ERR); +#endif + } + returnCode(rc); } -int reset_shell_mode(void) +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +reset_prog_mode(void) { - T((T_CALLED("reset_shell_mode()"))); + return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN); +} +#endif - if (cur_term != 0) { - if (SP) - { - _nc_keypad(FALSE); - _nc_flush(); - NC_BUFFERED(FALSE); - } - returnCode(_nc_set_tty_mode(&cur_term->Ottyb)); +NCURSES_EXPORT(int) +NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0) +{ + int rc = ERR; + TERMINAL *termp = TerminalOf(SP_PARM); + + T((T_CALLED("reset_shell_mode(%p) ->term %p"), + (void *) SP_PARM, (void *) termp)); + + if (termp != 0) { +#ifdef USE_TERM_DRIVER + rc = CallDriver_2(SP_PARM, td_mode, FALSE, FALSE); +#else + if (SP_PARM) { + _nc_keypad(SP_PARM, FALSE); + _nc_flush(); } - returnCode(ERR); + rc = _nc_set_tty_mode(&termp->Ottyb); +#endif + } + returnCode(rc); +} + +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +reset_shell_mode(void) +{ + return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN); +} +#endif + +static TTY * +saved_tty(NCURSES_SP_DCL0) +{ + TTY *result = 0; + + if (SP_PARM != 0) { + result = (TTY *) & (SP_PARM->_saved_tty); + } else { + if (_nc_prescreen.saved_tty == 0) { + _nc_prescreen.saved_tty = typeCalloc(TTY, 1); + } + result = _nc_prescreen.saved_tty; + } + return result; } /* @@ -146,18 +299,32 @@ int reset_shell_mode(void) ** */ -static TTY buf; - -int savetty(void) +NCURSES_EXPORT(int) +NCURSES_SP_NAME(savetty) (NCURSES_SP_DCL0) { - T((T_CALLED("savetty()"))); + T((T_CALLED("savetty(%p)"), (void *) SP_PARM)); + returnCode(NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG))); +} - returnCode(_nc_get_tty_mode(&buf)); +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +savetty(void) +{ + return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN); } +#endif -int resetty(void) +NCURSES_EXPORT(int) +NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0) { - T((T_CALLED("resetty()"))); + T((T_CALLED("resetty(%p)"), (void *) SP_PARM)); + returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG))); +} - returnCode(_nc_set_tty_mode(&buf)); +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +resetty(void) +{ + return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN); } +#endif