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#pragma ident	"%Z%%M%	%I%	%E% SMI"
41
42/*LINTLIBRARY*/
43
44#include	"curses_inc.h"
45#include	<sys/types.h>
46#include	<sys/stat.h>
47#include	<unistd.h>
48
49int
50scr_ll_dump(FILE *filep)
51{
52	short	magic = SVR3_DUMP_MAGIC_NUMBER, rv = ERR;
53	char	*thistty;
54	SLK_MAP	*slk = SP->slk;
55	struct	stat	statbuf;
56
57	if (fwrite((char *) &magic, sizeof (short), 1, filep) != 1)
58		goto err;
59
60	/* write term name and modification time */
61	if ((thistty = ttyname(cur_term->Filedes)) == NULL)
62		statbuf.st_mtime = 0;
63	else
64		(void) stat(thistty, &statbuf);
65
66	if (fwrite((char *) &(statbuf.st_mtime), sizeof (time_t),
67	    1, filep) != 1)
68		goto err;
69
70	/* write curscr */
71	if (_INPUTPENDING)
72		(void) force_doupdate();
73	if (putwin(curscr, filep) == ERR)
74		goto err;
75
76	/* next output: 0 no slk, 1 hardware slk, 2 simulated slk */
77
78	magic = (!slk) ? 0 : (slk->_win) ? 2 : 1;
79	if (fwrite((char *) &magic, sizeof (int), 1, filep) != 1)
80		goto err;
81	if (magic) {
82		short	i, labmax = slk->_num, lablen = slk->_len + 1;
83
84		/* output the soft labels themselves */
85		if ((fwrite((char *) &labmax,
86		    sizeof (short), 1, filep) != 1) ||
87		    (fwrite((char *) &lablen, sizeof (short),
88		    1, filep) != 1)) {
89			goto err;
90		}
91		for (i = 0; i < labmax; i++)
92			if ((fwrite(slk->_ldis[i], sizeof (char), lablen,
93			    filep) != lablen) || (fwrite(slk->_lval[i],
94			    sizeof (char), lablen, filep) != lablen)) {
95				goto err;
96			}
97	}
98
99	/* now write information about colors.  Use the following format. */
100	/* Line 1 is mandatory, the remaining lines are required only if  */
101	/* line one is 1.						  */
102	/* line 1: 0 (no colors) or 1 (colors)				  */
103	/* line 2: number of colors, number of color pairs, can_change	  */
104	/* X lines: Contents of colors (r, g, b)			  */
105	/* Y lines: Contents of color-pairs				  */
106
107	magic = ((cur_term->_pairs_tbl) ? 1 : 0);
108	if (fwrite((char *) &magic, sizeof (int), 1, filep) != 1)
109		goto err;
110	if (magic) {
111		/* number of colors and color_pairs	*/
112		if ((fwrite((char *) &COLORS, sizeof (int), 1, filep) != 1) ||
113		    (fwrite((char *) &COLOR_PAIRS, sizeof (int), 1, filep) !=
114		    1) || (fwrite((char *) &can_change, sizeof (char), 1,
115		    filep) != 1))
116			goto err;
117
118		/* contents of color_table		*/
119
120		if (can_change) {
121			if (fwrite((char *) &(cur_term->_color_tbl->r),
122			    sizeof (_Color), COLORS, filep) != COLORS)
123				goto err;
124		}
125
126		/* contents of pairs_table		*/
127
128		if (fwrite((char *) &(cur_term->_pairs_tbl->foreground),
129		    sizeof (_Color_pair), COLOR_PAIRS, filep) != COLOR_PAIRS)
130			goto err;
131	}
132
133	/* success */
134	rv = OK;
135err :
136	return (rv);
137}
138