1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for *
* details. If they are missing then this copy is in violation of *
* the copyright conditions. */
/*
** lib_newterm.c
**
** The newterm() function.
**
*/
#include <stdlib.h>
#include "curses.priv.h"
#include "terminfo.h"
#ifdef SVR4_ACTION
#define _POSIX_SOURCE
#endif
#include <signal.h>
#ifdef MYTINFO
int LINES, COLS;
#endif
static void cleanup(int sig)
{
if (sig == SIGSEGV)
fprintf(stderr, "Got a segmentation violation signal, cleaning up and exiting\n");
endwin();
exit(1);
}
static void
size_change(int sig)
{
struct ttysize ws;
if (ioctl(0, TIOCGSIZE, &ws) == -1)
return;
LINES = ws.ts_lines;
COLS = ws.ts_cols;
}
WINDOW *stdscr, *curscr, *newscr;
SCREEN *SP;
struct ripoff_t
{
int line;
int (*hook)();
}
rippedoff[5], *rsp = rippedoff;
SCREEN * newterm(char *term, FILE *ofp, FILE *ifp)
{
sigaction_t act;
int errret;
int stolen, topstolen;
extern char _ncurses_copyright[];
char *use_it = _ncurses_copyright;
use_it = use_it; /* shut up compiler */
#ifdef TRACE
_init_trace();
T(("newterm(\"%s\",%x,%x) called", term, ofp, ifp));
#endif
#ifdef MYTINFO
if (setupterm(term, fileno(ofp), &errret) != OK)
return NULL;
COLS = columns;
LINES = lines;
#else
if (setupterm(term, fileno(ofp), &errret) != 1)
return NULL;
#endif
if ((SP = (SCREEN *) malloc(sizeof *SP)) == NULL)
return NULL;
if (ofp == stdout && ifp == stdin) {
SP->_ofp = stdout;
SP->_ifp = stdin;
} else {
SP->_ofp = ofp;
SP->_ifp = ofp;
}
SP->_term = cur_term;
SP->_cursrow = -1;
SP->_curscol = -1;
SP->_keytry = UNINITIALISED;
SP->_nl = TRUE;
SP->_raw = FALSE;
SP->_cbreak = FALSE;
SP->_echo = TRUE;
SP->_nlmapping = TRUE;
SP->_fifohead = -1;
SP->_fifotail = 0;
SP->_fifopeek = 0;
SP->_endwin = FALSE;
SP->_checkfd = fileno(ifp);
typeahead(fileno(ifp));
if (enter_ca_mode)
putp(enter_ca_mode);
init_acs();
T(("creating newscr"));
if ((newscr = newwin(lines, columns, 0, 0)) == (WINDOW *)NULL)
return(NULL);
T(("creating curscr"));
if ((curscr = newwin(lines, columns, 0, 0)) == (WINDOW *)NULL)
return(NULL);
SP->_newscr = newscr;
SP->_curscr = curscr;
newscr->_clear = TRUE;
curscr->_clear = FALSE;
stolen = topstolen = 0;
for (rsp = rippedoff; rsp->line; rsp++) {
if (rsp->hook)
if (rsp->line < 0)
rsp->hook(newwin(1,COLS, LINES-1,0), COLS);
else
rsp->hook(newwin(1,COLS, topstolen++,0), COLS);
--LINES;
stolen++;
}
act.sa_handler = tstp;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGTSTP, &act, NULL);
act.sa_handler = cleanup;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
act.sa_handler = size_change;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGWINCH, &act, NULL);
#if 0
sigaction(SIGSEGV, &act, NULL);
#endif
if ((stdscr = newwin(lines - stolen, columns, topstolen, 0)) == NULL)
return(NULL);
SP->_stdscr = stdscr;
def_shell_mode();
def_prog_mode();
T(("newterm returns %x", SP));
return(SP);
}
int
ripoffline(int line, int (*init)(WINDOW *, int))
{
if (line == 0)
return(OK);
if (rsp >= rippedoff + sizeof(rippedoff)/sizeof(rippedoff[0]))
return(ERR);
rsp->line = line;
rsp->hook = init;
rsp++;
return(OK);
}
|