1 /*
2 * CDDL HEADER START
3 *
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
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 /*LINTLIBRARY*/
41
42 #include "curses_inc.h"
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46
47 int
scr_ll_dump(FILE * filep)48 scr_ll_dump(FILE *filep)
49 {
50 short magic = SVR3_DUMP_MAGIC_NUMBER, rv = ERR;
51 char *thistty;
52 SLK_MAP *slk = SP->slk;
53 struct stat statbuf;
54
55 if (fwrite((char *) &magic, sizeof (short), 1, filep) != 1)
56 goto err;
57
58 /* write term name and modification time */
59 if ((thistty = ttyname(cur_term->Filedes)) == NULL)
60 statbuf.st_mtime = 0;
61 else
62 (void) stat(thistty, &statbuf);
63
64 if (fwrite((char *) &(statbuf.st_mtime), sizeof (time_t),
65 1, filep) != 1)
66 goto err;
67
68 /* write curscr */
69 if (_INPUTPENDING)
70 (void) force_doupdate();
71 if (putwin(curscr, filep) == ERR)
72 goto err;
73
74 /* next output: 0 no slk, 1 hardware slk, 2 simulated slk */
75
76 magic = (!slk) ? 0 : (slk->_win) ? 2 : 1;
77 if (fwrite((char *) &magic, sizeof (int), 1, filep) != 1)
78 goto err;
79 if (magic) {
80 short i, labmax = slk->_num, lablen = slk->_len + 1;
81
82 /* output the soft labels themselves */
83 if ((fwrite((char *) &labmax,
84 sizeof (short), 1, filep) != 1) ||
85 (fwrite((char *) &lablen, sizeof (short),
86 1, filep) != 1)) {
87 goto err;
88 }
89 for (i = 0; i < labmax; i++)
90 if ((fwrite(slk->_ldis[i], sizeof (char), lablen,
91 filep) != lablen) || (fwrite(slk->_lval[i],
92 sizeof (char), lablen, filep) != lablen)) {
93 goto err;
94 }
95 }
96
97 /* now write information about colors. Use the following format. */
98 /* Line 1 is mandatory, the remaining lines are required only if */
99 /* line one is 1. */
100 /* line 1: 0 (no colors) or 1 (colors) */
101 /* line 2: number of colors, number of color pairs, can_change */
102 /* X lines: Contents of colors (r, g, b) */
103 /* Y lines: Contents of color-pairs */
104
105 magic = ((cur_term->_pairs_tbl) ? 1 : 0);
106 if (fwrite((char *) &magic, sizeof (int), 1, filep) != 1)
107 goto err;
108 if (magic) {
109 /* number of colors and color_pairs */
110 if ((fwrite((char *) &COLORS, sizeof (int), 1, filep) != 1) ||
111 (fwrite((char *) &COLOR_PAIRS, sizeof (int), 1, filep) !=
112 1) || (fwrite((char *) &can_change, sizeof (char), 1,
113 filep) != 1))
114 goto err;
115
116 /* contents of color_table */
117
118 if (can_change) {
119 if (fwrite((char *) &(cur_term->_color_tbl->r),
120 sizeof (_Color), COLORS, filep) != COLORS)
121 goto err;
122 }
123
124 /* contents of pairs_table */
125
126 if (fwrite((char *) &(cur_term->_pairs_tbl->foreground),
127 sizeof (_Color_pair), COLOR_PAIRS, filep) != COLOR_PAIRS)
128 goto err;
129 }
130
131 /* success */
132 rv = OK;
133 err :
134 return (rv);
135 }
136