4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include "curses_inc.h"
45 #include <sys/types.h>
50 * Initialize the screen image to be the image contained
51 * in the given file. This is usually used in a child process
52 * to initialize its idea of the screen image to be that of its
55 * filep: pointer to the output stream
56 * type: 0: <curses> should assume that the physical screen is
57 * EXACTLY as stored in the file. Therefore, we take
58 * special care to make sure that /dev/tty and the terminal
59 * did not change in any way. This information can then
60 * be used in the update optimization of the new program
61 * so that the screen does not have to be cleared. Instead,
62 * curses, by knowing what's on the screen can optimally
63 * update it with the information of the new program.
65 * 1: Tell <curses> that the stored image should be
66 * the physical image. Sort of like a huge waddstr onto
67 * curscr. This can be used when a library wants to save
68 * a screen image and restore it at a later time.
70 * 2: Tell <curses> that the stored image is the physical
71 * image and also it is what the new program wants on the
72 * screen. This can be be thought of as a screen inheritance
77 scr_reset(FILE *filep
, int type
)
79 WINDOW
*win
= NULL
, *win1
= NULL
;
86 if (type
!= 1 && exit_ca_mode
&& *exit_ca_mode
&& non_rev_rmcup
) {
92 fprintf(outf
, "clear it because of "
99 /* check magic number */
100 if (fread((char *) &magic
, sizeof (short), 1, filep
) != 1)
102 if (magic
!= SVR3_DUMP_MAGIC_NUMBER
)
105 /* get modification time of image in file */
106 if (fread((char *) &ttytime
, sizeof (time_t), 1, filep
) != 1)
109 if ((type
!= 1) && ((ttyname(cur_term
->Filedes
) == NULL
) ||
110 (fstat(cur_term
->Filedes
, &statbuf
) < 0) ||
111 (statbuf
.st_mtime
!= ttytime
))) {
117 fprintf(outf
, "Filedes = %hd, "
118 "statbuf.st_mtime = %d, "
119 "ttytime = %d\n", cur_term
->Filedes
,
120 statbuf
.st_mtime
, ttytime
);
126 /* if get here, everything is ok, read the curscr image */
127 if (((win
= getwin(filep
)) == NULL
) ||
128 ((type
== 2) && ((win1
= dupwin(win
)) == NULL
)) ||
129 (win
->_maxy
!= curscr
->_maxy
) || (win
->_maxx
!= curscr
->_maxx
) ||
131 (fread((char *) &magic
, sizeof (int), 1, filep
) != 1))
135 * if soft labels were dumped, we would like either read them
136 * or advance the file pointer pass them
139 short i
, labmax
, lablen
;
140 SLK_MAP
*slk
= SP
->slk
;
142 * Why doesn't the following line and the two below
143 * that access those variables work ?
146 * char **labdis = SP->slk->_ldis, **labval = SP->slk->_lval;
149 if ((fread((char *) &labmax
, sizeof (short), 1, filep
) != 1) ||
150 (fread((char *) &lablen
, sizeof (short), 1, filep
) != 1)) {
155 if ((labmax
!= slk
->_num
) ||
156 (lablen
!= (slk
->_len
+ 1)))
159 for (i
= 0; i
< labmax
; i
++) {
161 * if ((fread(labdis[i], sizeof (char), lablen,
162 * filep) != lablen) ||
163 * (fread(labval[i], sizeof (char), lablen,
166 if ((fread(slk
->_ldis
[i
], sizeof (char),
167 lablen
, filep
) != lablen
) ||
168 (fread(slk
->_lval
[i
],
169 sizeof (char), lablen
, filep
) != lablen
)) {
175 if (fseek(filep
, (long) (2 * labmax
* lablen
*
176 sizeof (char)), 1) != 0)
181 /* read the color information(if any) from the file */
183 if (fread((char *) &magic
, sizeof (int), 1, filep
) != 1)
187 int colors
, color_pairs
;
191 /* if the new terminal doesn't support colors, or it supports */
192 /* less colors (or color_pairs) than the old terminal, or */
193 /* start_color() has not been called, simply advance the file */
194 /* pointer pass the color related info. */
195 /* Note: must to read the first line of color info, even if the */
196 /* new terminal doesn't support color, in order to know how to */
197 /* deal with the rest of the file */
199 if ((fread((char *) &colors
, sizeof (int), 1, filep
) != 1) ||
200 (fread((char *) &color_pairs
, sizeof (int), 1,
201 filep
) != 1) || (fread((char *) &could_change
,
202 sizeof (char), 1, filep
) != 1))
205 if (max_pairs
== -1 || cur_term
->_pairs_tbl
== NULL
||
206 colors
> max_colors
|| color_pairs
> max_pairs
) {
207 if (fseek(filep
, (long) (colors
* sizeof (_Color
) +
208 color_pairs
* sizeof (_Color_pair
)), 1) != 0)
211 _Color_pair
*ptp
, *save_ptp
;
213 /* if both old and new terminals could modify colors, read in */
214 /* color table, and call init_color for each color */
218 _Color
*ctp
, *save_ctp
;
220 if ((save_ctp
= (ctp
= (_Color
*)
222 sizeof (_Color
)))) == NULL
)
225 if (fread(ctp
, sizeof (_Color
),
226 colors
, filep
) != colors
)
229 for (i
= 0; i
< colors
; i
++, ctp
++) {
231 (void) init_color((short)i
,
232 ctp
->r
, ctp
->g
, ctp
->b
);
237 /* the old terminal could modify colors, by the new one */
238 /* cannot skip over color_table info. */
240 if (fseek(filep
, (long) (colors
*
241 sizeof (_Color
)), 1) != 0)
246 /* read color_pairs info. call init_pair for each pair */
248 if ((save_ptp
= (ptp
= (_Color_pair
*)
249 malloc(color_pairs
* sizeof (_Color_pair
)))) ==
252 if (fread(ptp
, sizeof (_Color_pair
), color_pairs
,
253 filep
) != color_pairs
) {
260 curscr
->_clear
= TRUE
;
264 for (i
= 1, ++ptp
; i
<= color_pairs
; i
++, ptp
++) {
267 (void) init_pair((short)i
,
268 ptp
->foreground
, ptp
->background
);
274 /* substitute read in window for the curscr */
278 (void) delwin(_virtscr
);
281 SP
->virt_scr
= _virtscr
= win
;
283 _VIRTBOT
= curscr
->_maxy
- 1;
286 SP
->virt_scr
= _virtscr
= win1
;
287 _VIRTTOP
= curscr
->_maxy
;
289 /* clear the hash table */
290 for (y
= curscr
->_maxy
; y
> 0; --y
)
292 /* LINTED */ /* Known fall-through on case statement. */
295 int saveflag
= curscr
->_flags
& _CANT_BE_IMMED
;
297 (void) delwin(curscr
);
298 SP
->cur_scr
= curscr
= win
;
299 curscr
->_sync
= TRUE
;
300 curscr
->_flags
|= saveflag
;
305 /* clear the hash table */
306 for (y
= curscr
->_maxy
; y
> 0; --y
)
309 curscr
->_clear
= clearit
;