X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_ttyflags.c;h=4cbbf504a0c7e1c085d5de1783954bf0c338e393;hp=ab9c004536ac29ed7789bfdc561120f06d77b35b;hb=d44d7f381ba0173521cb788ba3adb12e261e5c96;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/ncurses/tinfo/lib_ttyflags.c b/ncurses/tinfo/lib_ttyflags.c index ab9c0045..4cbbf504 100644 --- a/ncurses/tinfo/lib_ttyflags.c +++ b/ncurses/tinfo/lib_ttyflags.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -38,49 +38,64 @@ #include #include /* cur_term */ -MODULE_ID("$Id: lib_ttyflags.c,v 1.11 2003/05/17 23:50:37 tom Exp $") - -#undef tabs - -#ifdef TAB3 -# define tabs TAB3 -#else -# ifdef XTABS -# define tabs XTABS -# else -# ifdef OXTABS -# define tabs OXTABS -# else -# define tabs 0 -# endif -# endif -#endif +MODULE_ID("$Id: lib_ttyflags.c,v 1.15 2007/05/26 18:54:25 tom Exp $") NCURSES_EXPORT(int) _nc_get_tty_mode(TTY * buf) { - if (cur_term == 0 - || GET_TTY(cur_term->Filedes, buf) != 0) { - memset(buf, 0, sizeof(*buf)); - return (ERR); + int result = OK; + + if (buf == 0) { + result = ERR; + } else { + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (GET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + result = ERR; + } + break; + } + } + + if (result == ERR) + memset(buf, 0, sizeof(*buf)); + + TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", + cur_term->Filedes, _nc_trace_ttymode(buf))); } - TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s", - cur_term->Filedes, _nc_trace_ttymode(buf))); - return (OK); + return (result); } NCURSES_EXPORT(int) _nc_set_tty_mode(TTY * buf) { - if (cur_term == 0 - || SET_TTY(cur_term->Filedes, buf) != 0) { - if ((errno == ENOTTY) && (SP != 0)) - SP->_notty = TRUE; - return (ERR); + int result = OK; + + if (buf == 0) { + result = ERR; + } else { + if (cur_term == 0) { + result = ERR; + } else { + for (;;) { + if (SET_TTY(cur_term->Filedes, buf) != 0) { + if (errno == EINTR) + continue; + if ((errno == ENOTTY) && (SP != 0)) + SP->_notty = TRUE; + result = ERR; + } + break; + } + } + TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", + cur_term->Filedes, _nc_trace_ttymode(buf))); } - TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s", - cur_term->Filedes, _nc_trace_ttymode(buf))); - return (OK); + return (result); } NCURSES_EXPORT(int) @@ -89,14 +104,13 @@ def_shell_mode(void) T((T_CALLED("def_shell_mode()"))); /* - * 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); #ifdef TERMIOS - if (cur_term->Ottyb.c_oflag & tabs) + if (cur_term->Ottyb.c_oflag & OFLAGS_TABS) tab = back_tab = NULL; #else if (cur_term->Ottyb.sg_flags & XTABS) @@ -110,10 +124,14 @@ def_prog_mode(void) { T((T_CALLED("def_prog_mode()"))); + /* + * Turn off the XTABS bit in the tty structure if it was on. + */ + if (_nc_get_tty_mode(&cur_term->Nttyb) != OK) returnCode(ERR); #ifdef TERMIOS - cur_term->Nttyb.c_oflag &= ~tabs; + cur_term->Nttyb.c_oflag &= ~OFLAGS_TABS; #else cur_term->Nttyb.sg_flags &= ~XTABS; #endif @@ -154,19 +172,33 @@ reset_shell_mode(void) returnCode(ERR); } +static TTY * +saved_tty(void) +{ + TTY *result = 0; + + if (SP != 0) { + result = &(SP->_saved_tty); + } else { + if (_nc_prescreen.saved_tty == 0) { + _nc_prescreen.saved_tty = typeCalloc(TTY, 1); + } + result = _nc_prescreen.saved_tty; + } + return result; +} + /* ** savetty() and resetty() ** */ -static TTY buf; - NCURSES_EXPORT(int) savetty(void) { T((T_CALLED("savetty()"))); - returnCode(_nc_get_tty_mode(&buf)); + returnCode(_nc_get_tty_mode(saved_tty())); } NCURSES_EXPORT(int) @@ -174,5 +206,5 @@ resetty(void) { T((T_CALLED("resetty()"))); - returnCode(_nc_set_tty_mode(&buf)); + returnCode(_nc_set_tty_mode(saved_tty())); }