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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/****************************************************************************
* Copyright (c) 1998-2007,2008 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 *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
* and: Thomas E. Dickey 1996 on *
****************************************************************************/
#include <curses.priv.h>
MODULE_ID("$Id: lib_screen.c,v 1.31 2008/08/16 19:05:37 tom Exp $")
#define MAX_SIZE 0x3fff /* 16k is big enough for a window or pad */
NCURSES_EXPORT(WINDOW *)
getwin(FILE *filep)
{
WINDOW tmp, *nwin;
int n;
T((T_CALLED("getwin(%p)"), filep));
clearerr(filep);
(void) fread(&tmp, sizeof(WINDOW), 1, filep);
if (ferror(filep)
|| tmp._maxy == 0
|| tmp._maxy > MAX_SIZE
|| tmp._maxx == 0
|| tmp._maxx > MAX_SIZE)
returnWin(0);
if (tmp._flags & _ISPAD) {
nwin = newpad(tmp._maxy + 1, tmp._maxx + 1);
} else {
nwin = newwin(tmp._maxy + 1, tmp._maxx + 1, 0, 0);
}
/*
* We deliberately do not restore the _parx, _pary, or _parent
* fields, because the window hierarchy within which they
* made sense is probably gone.
*/
if (nwin != 0) {
nwin->_curx = tmp._curx;
nwin->_cury = tmp._cury;
nwin->_maxy = tmp._maxy;
nwin->_maxx = tmp._maxx;
nwin->_begy = tmp._begy;
nwin->_begx = tmp._begx;
nwin->_yoffset = tmp._yoffset;
nwin->_flags = tmp._flags & ~(_SUBWIN);
WINDOW_ATTRS(nwin) = WINDOW_ATTRS(&tmp);
nwin->_nc_bkgd = tmp._nc_bkgd;
nwin->_notimeout = tmp._notimeout;
nwin->_clear = tmp._clear;
nwin->_leaveok = tmp._leaveok;
nwin->_idlok = tmp._idlok;
nwin->_idcok = tmp._idcok;
nwin->_immed = tmp._immed;
nwin->_scroll = tmp._scroll;
nwin->_sync = tmp._sync;
nwin->_use_keypad = tmp._use_keypad;
nwin->_delay = tmp._delay;
nwin->_regtop = tmp._regtop;
nwin->_regbottom = tmp._regbottom;
if (tmp._flags & _ISPAD)
nwin->_pad = tmp._pad;
for (n = 0; n <= nwin->_maxy; n++) {
clearerr(filep);
(void) fread(nwin->_line[n].text,
sizeof(NCURSES_CH_T),
(size_t) (nwin->_maxx + 1),
filep);
if (ferror(filep)) {
delwin(nwin);
returnWin(0);
}
}
touchwin(nwin);
}
returnWin(nwin);
}
NCURSES_EXPORT(int)
putwin(WINDOW *win, FILE *filep)
{
int code = ERR;
int n;
T((T_CALLED("putwin(%p,%p)"), win, filep));
if (win != 0) {
size_t len = (size_t) (win->_maxx + 1);
clearerr(filep);
if (fwrite(win, sizeof(WINDOW), 1, filep) != 1
|| ferror(filep))
returnCode(code);
for (n = 0; n <= win->_maxy; n++) {
if (fwrite(win->_line[n].text,
sizeof(NCURSES_CH_T), len, filep) != len
|| ferror(filep)) {
returnCode(code);
}
}
code = OK;
}
returnCode(code);
}
NCURSES_EXPORT(int)
scr_restore(const char *file)
{
FILE *fp = 0;
T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file)));
if (_nc_access(file, R_OK) < 0
|| (fp = fopen(file, "rb")) == 0) {
returnCode(ERR);
} else {
delwin(newscr);
SP->_newscr = getwin(fp);
#if !USE_REENTRANT
newscr = SP->_newscr;
#endif
(void) fclose(fp);
returnCode(OK);
}
}
NCURSES_EXPORT(int)
scr_dump(const char *file)
{
FILE *fp = 0;
T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file)));
if (_nc_access(file, W_OK) < 0
|| (fp = fopen(file, "wb")) == 0) {
returnCode(ERR);
} else {
(void) putwin(newscr, fp);
(void) fclose(fp);
returnCode(OK);
}
}
NCURSES_EXPORT(int)
scr_init(const char *file)
{
FILE *fp = 0;
T((T_CALLED("scr_init(%s)"), _nc_visbuf(file)));
if (exit_ca_mode && non_rev_rmcup)
returnCode(ERR);
if (_nc_access(file, R_OK) < 0
|| (fp = fopen(file, "rb")) == 0) {
returnCode(ERR);
} else {
delwin(curscr);
SP->_curscr = getwin(fp);
#if !USE_REENTRANT
curscr = SP->_curscr;
#endif
(void) fclose(fp);
returnCode(OK);
}
}
NCURSES_EXPORT(int)
scr_set(const char *file)
{
T((T_CALLED("scr_set(%s)"), _nc_visbuf(file)));
if (scr_init(file) == ERR) {
returnCode(ERR);
} else {
delwin(newscr);
SP->_newscr = dupwin(curscr);
#if !USE_REENTRANT
newscr = SP->_newscr;
#endif
returnCode(OK);
}
}
|