lib_ttyflags.c revision 1.2
1/* $OpenBSD: lib_ttyflags.c,v 1.2 1999/08/15 11:40:55 millert Exp $ */ 2 3/**************************************************************************** 4 * Copyright (c) 1998 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31/* 32 * def_prog_mode() 33 * def_shell_mode() 34 * reset_prog_mode() 35 * reset_shell_mode() 36 * savetty() 37 * resetty() 38 */ 39 40#include <curses.priv.h> 41#include <term.h> /* cur_term */ 42 43MODULE_ID("$From: lib_ttyflags.c,v 1.2 1999/07/24 22:36:12 tom Exp $") 44 45#undef tabs 46 47#ifdef TAB3 48# define tabs TAB3 49#else 50# ifdef XTABS 51# define tabs XTABS 52# else 53# ifdef OXTABS 54# define tabs OXTABS 55# else 56# define tabs 0 57# endif 58# endif 59#endif 60 61int _nc_get_tty_mode(TTY *buf) 62{ 63 if (cur_term == 0 64 || GET_TTY(cur_term->Filedes, buf) != 0) 65 return(ERR); 66 TR(TRACE_BITS,("_nc_get_tty_mode: %s", _nc_tracebits())); 67 return (OK); 68} 69 70int _nc_set_tty_mode(TTY *buf) 71{ 72 if (cur_term == 0 73 || SET_TTY(cur_term->Filedes, buf) != 0) 74 return(ERR); 75 TR(TRACE_BITS,("_nc_set_tty_mode: %s", _nc_tracebits())); 76 return (OK); 77} 78 79int def_shell_mode(void) 80{ 81 T((T_CALLED("def_shell_mode()"))); 82 83 /* 84 * Turn off the XTABS bit in the tty structure if it was on. If XTABS 85 * was on, remove the tab and backtab capabilities. 86 */ 87 88 if (_nc_get_tty_mode(&cur_term->Ottyb) != OK) 89 returnCode(ERR); 90#ifdef TERMIOS 91 if (cur_term->Ottyb.c_oflag & tabs) 92 tab = back_tab = NULL; 93#else 94 if (cur_term->Ottyb.sg_flags & XTABS) 95 tab = back_tab = NULL; 96#endif 97 returnCode(OK); 98} 99 100int def_prog_mode(void) 101{ 102 T((T_CALLED("def_prog_mode()"))); 103 104 if (_nc_get_tty_mode(&cur_term->Nttyb) != OK) 105 returnCode(ERR); 106#ifdef TERMIOS 107 cur_term->Nttyb.c_oflag &= ~tabs; 108#else 109 cur_term->Nttyb.sg_flags &= ~XTABS; 110#endif 111 returnCode(OK); 112} 113 114int reset_prog_mode(void) 115{ 116 T((T_CALLED("reset_prog_mode()"))); 117 118 if (cur_term != 0) { 119 _nc_set_tty_mode(&cur_term->Nttyb); 120 if (SP) { 121 if (stdscr && stdscr->_use_keypad) 122 _nc_keypad(TRUE); 123 NC_BUFFERED(TRUE); 124 } 125 returnCode(OK); 126 } 127 returnCode(ERR); 128} 129 130int reset_shell_mode(void) 131{ 132 T((T_CALLED("reset_shell_mode()"))); 133 134 if (cur_term != 0) { 135 if (SP) 136 { 137 _nc_keypad(FALSE); 138 fflush(SP->_ofp); 139 NC_BUFFERED(FALSE); 140 } 141 returnCode(_nc_set_tty_mode(&cur_term->Ottyb)); 142 } 143 returnCode(ERR); 144} 145 146/* 147** savetty() and resetty() 148** 149*/ 150 151static TTY buf; 152 153int savetty(void) 154{ 155 T((T_CALLED("savetty()"))); 156 157 returnCode(_nc_get_tty_mode(&buf)); 158} 159 160int resetty(void) 161{ 162 T((T_CALLED("resetty()"))); 163 164 returnCode(_nc_set_tty_mode(&buf)); 165} 166