Back to index

tetex-bin  3.0
lib_ttyflags.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /*
00030  *            def_prog_mode()
00031  *            def_shell_mode()
00032  *            reset_prog_mode()
00033  *            reset_shell_mode()
00034  *            savetty()
00035  *            resetty()
00036  */
00037 
00038 #include <curses.priv.h>
00039 #include <term.h>           /* cur_term */
00040 
00041 MODULE_ID("$Id: lib_ttyflags.c,v 1.11 2003/05/17 23:50:37 tom Exp $")
00042 
00043 #undef tabs
00044 
00045 #ifdef TAB3
00046 # define tabs TAB3
00047 #else
00048 # ifdef XTABS
00049 #  define tabs XTABS
00050 # else
00051 #  ifdef OXTABS
00052 #   define tabs OXTABS
00053 #  else
00054 #   define tabs 0
00055 #  endif
00056 # endif
00057 #endif
00058 
00059 NCURSES_EXPORT(int)
00060 _nc_get_tty_mode(TTY * buf)
00061 {
00062     if (cur_term == 0
00063        || GET_TTY(cur_term->Filedes, buf) != 0) {
00064        memset(buf, 0, sizeof(*buf));
00065        return (ERR);
00066     }
00067     TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
00068                   cur_term->Filedes, _nc_trace_ttymode(buf)));
00069     return (OK);
00070 }
00071 
00072 NCURSES_EXPORT(int)
00073 _nc_set_tty_mode(TTY * buf)
00074 {
00075     if (cur_term == 0
00076        || SET_TTY(cur_term->Filedes, buf) != 0) {
00077        if ((errno == ENOTTY) && (SP != 0))
00078            SP->_notty = TRUE;
00079        return (ERR);
00080     }
00081     TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
00082                   cur_term->Filedes, _nc_trace_ttymode(buf)));
00083     return (OK);
00084 }
00085 
00086 NCURSES_EXPORT(int)
00087 def_shell_mode(void)
00088 {
00089     T((T_CALLED("def_shell_mode()")));
00090 
00091     /*
00092      * Turn off the XTABS bit in the tty structure if it was on.  If XTABS
00093      * was on, remove the tab and backtab capabilities.
00094      */
00095 
00096     if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
00097        returnCode(ERR);
00098 #ifdef TERMIOS
00099     if (cur_term->Ottyb.c_oflag & tabs)
00100        tab = back_tab = NULL;
00101 #else
00102     if (cur_term->Ottyb.sg_flags & XTABS)
00103        tab = back_tab = NULL;
00104 #endif
00105     returnCode(OK);
00106 }
00107 
00108 NCURSES_EXPORT(int)
00109 def_prog_mode(void)
00110 {
00111     T((T_CALLED("def_prog_mode()")));
00112 
00113     if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
00114        returnCode(ERR);
00115 #ifdef TERMIOS
00116     cur_term->Nttyb.c_oflag &= ~tabs;
00117 #else
00118     cur_term->Nttyb.sg_flags &= ~XTABS;
00119 #endif
00120     returnCode(OK);
00121 }
00122 
00123 NCURSES_EXPORT(int)
00124 reset_prog_mode(void)
00125 {
00126     T((T_CALLED("reset_prog_mode()")));
00127 
00128     if (cur_term != 0) {
00129        if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
00130            if (SP) {
00131               if (SP->_keypad_on)
00132                   _nc_keypad(TRUE);
00133               NC_BUFFERED(TRUE);
00134            }
00135            returnCode(OK);
00136        }
00137     }
00138     returnCode(ERR);
00139 }
00140 
00141 NCURSES_EXPORT(int)
00142 reset_shell_mode(void)
00143 {
00144     T((T_CALLED("reset_shell_mode()")));
00145 
00146     if (cur_term != 0) {
00147        if (SP) {
00148            _nc_keypad(FALSE);
00149            _nc_flush();
00150            NC_BUFFERED(FALSE);
00151        }
00152        returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
00153     }
00154     returnCode(ERR);
00155 }
00156 
00157 /*
00158 **     savetty()  and  resetty()
00159 **
00160 */
00161 
00162 static TTY buf;
00163 
00164 NCURSES_EXPORT(int)
00165 savetty(void)
00166 {
00167     T((T_CALLED("savetty()")));
00168 
00169     returnCode(_nc_get_tty_mode(&buf));
00170 }
00171 
00172 NCURSES_EXPORT(int)
00173 resetty(void)
00174 {
00175     T((T_CALLED("resetty()")));
00176 
00177     returnCode(_nc_set_tty_mode(&buf));
00178 }