1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /* LINTLIBRARY */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate /*
32*0Sstevel@tonic-gate * getwin.c
33*0Sstevel@tonic-gate *
34*0Sstevel@tonic-gate * XCurses Library
35*0Sstevel@tonic-gate *
36*0Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
37*0Sstevel@tonic-gate *
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate #if M_RCSID
41*0Sstevel@tonic-gate #ifndef lint
42*0Sstevel@tonic-gate static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/getwin.c 1.2 "
43*0Sstevel@tonic-gate "1995/06/12 17:48:38 ant Exp $";
44*0Sstevel@tonic-gate #endif
45*0Sstevel@tonic-gate #endif
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate #include <private.h>
48*0Sstevel@tonic-gate #include <limits.h>
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate #undef mvwaddstr
51*0Sstevel@tonic-gate #undef wstandend
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate static int
get_cc(WINDOW * w,char * mbs,FILE * fp)54*0Sstevel@tonic-gate get_cc(WINDOW *w, char *mbs, FILE *fp)
55*0Sstevel@tonic-gate {
56*0Sstevel@tonic-gate short co;
57*0Sstevel@tonic-gate attr_t at;
58*0Sstevel@tonic-gate int n, y, x;
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate if (fscanf(fp, "%d,%d,%hx,%hd,", &y, &x, &at, &co) < 4)
61*0Sstevel@tonic-gate return (0);
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate if (fscanf(fp, "%[^\n]%n ", mbs, &n) < 1)
64*0Sstevel@tonic-gate return (0);
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate if (wattr_set(w, at, co, (void *) 0) == ERR)
67*0Sstevel@tonic-gate return (0);
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate if (mvwaddstr(w, y, x, mbs) == ERR)
70*0Sstevel@tonic-gate return (0);
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate (void) wstandend(w);
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate return (n);
75*0Sstevel@tonic-gate }
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate WINDOW *
getwin(FILE * fp)78*0Sstevel@tonic-gate getwin(FILE *fp)
79*0Sstevel@tonic-gate {
80*0Sstevel@tonic-gate char *mbs;
81*0Sstevel@tonic-gate WINDOW *w;
82*0Sstevel@tonic-gate unsigned short flags;
83*0Sstevel@tonic-gate int by, bx, my, mx;
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate /* Get window dimensions and location to create a new window. */
86*0Sstevel@tonic-gate if (fscanf(fp, "MAX=%d,%d BEG=%d,%d ", &my, &mx, &by, &bx) < 4)
87*0Sstevel@tonic-gate goto error1;
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate if ((mbs = (char *) malloc((size_t) (LINE_MAX+1))) == NULL)
90*0Sstevel@tonic-gate goto error1;
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate if ((w = newwin(my, mx, by, bx)) == NULL)
93*0Sstevel@tonic-gate goto error2;
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate /* Read other window attributes. */
96*0Sstevel@tonic-gate by = fscanf(fp,
97*0Sstevel@tonic-gate "SCROLL=%hd,%hd VMIN=%hd VTIME=%hd FLAGS=%hx FG=%hx,%hd ",
98*0Sstevel@tonic-gate &w->_top, &w->_bottom, &w->_vmin, &w->_vtime, &flags,
99*0Sstevel@tonic-gate &w->_fg._at, &w->_fg._co);
100*0Sstevel@tonic-gate if (by < 7)
101*0Sstevel@tonic-gate goto error3;
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate w->_flags &= ~W_CONFIG_MASK;
104*0Sstevel@tonic-gate w->_flags |= flags;
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate by = fscanf(fp, "BG=%hx,%hd,%[^\n] ", &w->_bg._at, &w->_bg._co, mbs);
107*0Sstevel@tonic-gate if (by < 3)
108*0Sstevel@tonic-gate goto error3;
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate while (get_cc(w, mbs, fp))
111*0Sstevel@tonic-gate ;
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate if (fscanf(fp, "CUR=%hd,%hd", &w->_cury, &w->_curx) < 2)
114*0Sstevel@tonic-gate goto error3;
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate free(mbs);
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate return (w);
119*0Sstevel@tonic-gate error3:
120*0Sstevel@tonic-gate (void) delwin(w);
121*0Sstevel@tonic-gate error2:
122*0Sstevel@tonic-gate free(mbs);
123*0Sstevel@tonic-gate error1:
124*0Sstevel@tonic-gate rewind(fp);
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate return (NULL);
127*0Sstevel@tonic-gate }
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate static int
put_cc(WINDOW * w,int y,int x,char * mbs,int len,FILE * fp)130*0Sstevel@tonic-gate put_cc(WINDOW *w, int y, int x,
131*0Sstevel@tonic-gate char *mbs, int len, FILE *fp)
132*0Sstevel@tonic-gate {
133*0Sstevel@tonic-gate int i;
134*0Sstevel@tonic-gate short co;
135*0Sstevel@tonic-gate attr_t at;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate at = w->_line[y][x]._at;
138*0Sstevel@tonic-gate co = w->_line[y][x]._co;
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate /* Write first character as a multibyte string. */
141*0Sstevel@tonic-gate (void) __m_cc_mbs(&w->_line[y][x], mbs, len);
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /* Write additional characters with same colour and attributes. */
144*0Sstevel@tonic-gate for (i = x; ; ) {
145*0Sstevel@tonic-gate i = __m_cc_next(w, y, i);
146*0Sstevel@tonic-gate if (w->_maxx <= i)
147*0Sstevel@tonic-gate break;
148*0Sstevel@tonic-gate if (w->_line[y][i]._at != at || w->_line[y][i]._co != co)
149*0Sstevel@tonic-gate break;
150*0Sstevel@tonic-gate (void) __m_cc_mbs(&w->_line[y][i], mbs, 0);
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate /* Terminate string. */
154*0Sstevel@tonic-gate (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0);
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate (void) fprintf(fp, "%d,%d,%#x,%d,%s\n", y, x, at, co, mbs);
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate /* Return index of next unprocessed column. */
159*0Sstevel@tonic-gate return (i);
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate int
putwin(WINDOW * w,FILE * fp)163*0Sstevel@tonic-gate putwin(WINDOW *w, FILE *fp)
164*0Sstevel@tonic-gate {
165*0Sstevel@tonic-gate char *mbs;
166*0Sstevel@tonic-gate size_t mbs_len;
167*0Sstevel@tonic-gate int y, x;
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate mbs_len = columns * _M_CCHAR_MAX * MB_LEN_MAX * sizeof (*mbs) + 1;
170*0Sstevel@tonic-gate if ((mbs = (char *) malloc((size_t) mbs_len)) == (char *) 0)
171*0Sstevel@tonic-gate return (ERR);
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate (void) fprintf(fp,
174*0Sstevel@tonic-gate "MAX=%d,%d\nBEG=%d,%d\nSCROLL=%d,%d\n",
175*0Sstevel@tonic-gate w->_maxy, w->_maxx, w->_begy, w->_begx, w->_top, w->_bottom);
176*0Sstevel@tonic-gate (void) fprintf(fp,
177*0Sstevel@tonic-gate "VMIN=%d\nVTIME=%d\nFLAGS=%#x\nFG=%#x,%d\n",
178*0Sstevel@tonic-gate w->_vmin, w->_vtime, w->_flags & W_CONFIG_MASK,
179*0Sstevel@tonic-gate w->_fg._at, w->_fg._co);
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate (void) __m_cc_mbs(&w->_bg, mbs, (int)mbs_len);
182*0Sstevel@tonic-gate (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0);
183*0Sstevel@tonic-gate (void) fprintf(fp, "BG=%#x,%d,%s\n", w->_bg._at, w->_bg._co, mbs);
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate for (y = 0; y < w->_maxy; ++y) {
186*0Sstevel@tonic-gate for (x = 0; x < w->_maxx; )
187*0Sstevel@tonic-gate x = put_cc(w, y, x, mbs, (int)mbs_len, fp);
188*0Sstevel@tonic-gate }
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate (void) fprintf(fp, "CUR=%d,%d\n", w->_curx, w->_cury);
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate free(mbs);
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate return (OK);
195*0Sstevel@tonic-gate }
196