]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_restart.c
ncurses 4.1
[ncurses.git] / ncurses / lib_restart.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23  * Terminfo-only terminal setup routines:
24  *
25  *              int restartterm(const char *, int, int *)
26  *              TERMINAL *set_curterm(TERMINAL *)
27  *              int del_curterm(TERMINAL *)
28  */
29
30 #include <curses.priv.h>
31
32 #ifdef SVR4_TERMIO
33 #define _POSIX_SOURCE
34 #endif
35
36 #include <term.h>       /* lines, columns, cur_term */
37
38 MODULE_ID("$Id: lib_restart.c,v 1.11 1997/02/02 01:10:25 tom Exp $")
39
40 #undef tabs
41
42 #ifdef TAB3
43 # define tabs TAB3
44 #else
45 # ifdef XTABS
46 #  define tabs XTABS
47 # else
48 #  ifdef OXTABS
49 #   define tabs OXTABS
50 #  else
51 #   define tabs 0
52 #  endif
53 # endif
54 #endif
55
56 int def_shell_mode(void)
57 {
58         T((T_CALLED("def_shell_mode()")));
59
60         if (cur_term == 0)
61                 returnCode(ERR);
62
63         /*
64          * Turn off the XTABS bit in the tty structure if it was on.  If XTABS
65          * was on, remove the tab and backtab capabilities.
66          */
67
68         if (GET_TTY(cur_term->Filedes, &cur_term->Ottyb) == -1)
69                 returnCode(ERR);
70 #ifdef TERMIOS
71         if (cur_term->Ottyb.c_oflag & tabs)
72                 tab = back_tab = NULL;
73 #else
74         if (cur_term->Ottyb.sg_flags & XTABS)
75                 tab = back_tab = NULL;
76 #endif
77         returnCode(OK);
78 }
79
80 int def_prog_mode(void)
81 {
82         T((T_CALLED("def_prog_mode()")));
83
84         if (cur_term == 0)
85                 returnCode(ERR);
86
87         if (GET_TTY(cur_term->Filedes, &cur_term->Nttyb) == -1)
88                 returnCode(ERR);
89 #ifdef TERMIOS
90         cur_term->Nttyb.c_oflag &= ~tabs;
91 #else
92         cur_term->Nttyb.sg_flags &= ~XTABS;
93 #endif
94         returnCode(OK);
95 }
96
97 int restartterm(const char *term, int filenum, int *errret)
98 {
99 int saveecho = SP->_echo;
100 int savecbreak = SP->_cbreak;
101 int saveraw = SP->_raw;
102 int savenl = SP->_nl;
103
104         T((T_CALLED("restartterm(%s,%d,%p)"), term, filenum, errret));
105
106         setupterm(term, filenum, errret);
107
108         if (saveecho)
109                 echo();
110         else
111                 noecho();
112
113         if (savecbreak) {
114                 cbreak();
115                 noraw();
116         } else if (saveraw) {
117                 nocbreak();
118                 raw();
119         } else {
120                 nocbreak();
121                 noraw();
122         }
123         if (savenl)
124                 nl();
125         else
126                 nonl();
127
128         reset_prog_mode();
129
130         _nc_get_screensize();
131
132         returnCode(OK);
133 }
134
135 TERMINAL *set_curterm(TERMINAL *term)
136 {
137         TERMINAL        *oldterm = cur_term;
138
139         cur_term = term;
140         return oldterm;
141 }
142
143 int del_curterm(TERMINAL *term)
144 {
145         T((T_CALLED("del_curterm(%p)"), term));
146
147         if (term != NULL) {
148                 FreeIfNeeded(term->type.str_table);
149                 FreeIfNeeded(term->type.term_names);
150                 free(term);
151                 returnCode(OK);
152         }
153         returnCode(ERR);
154 }