xref: /titanic_53/usr/src/lib/libxcurses2/src/libc/xcurses/slk.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1995-1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  * slk.c
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * XCurses Library
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #if M_RCSID
41*7c478bd9Sstevel@tonic-gate #ifndef lint
42*7c478bd9Sstevel@tonic-gate static char rcsID[] =
43*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/slk.c 1.9 1998/05/20 17:26:23 "
45*7c478bd9Sstevel@tonic-gate "cbates Exp $";
46*7c478bd9Sstevel@tonic-gate #endif
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #include <private.h>
50*7c478bd9Sstevel@tonic-gate #include <string.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate int	__m_slk_labels_on;
53*7c478bd9Sstevel@tonic-gate int	__m_slk_touched = 0;
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  * Flag for initialisation soft label keys once setupterm() has been called.
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate int
slk_init(int fmt)58*7c478bd9Sstevel@tonic-gate slk_init(int fmt)
59*7c478bd9Sstevel@tonic-gate {
60*7c478bd9Sstevel@tonic-gate 	int	code = ERR;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 	if (0 <= fmt && fmt <= 1) {
63*7c478bd9Sstevel@tonic-gate 		__m_slk_format = fmt;
64*7c478bd9Sstevel@tonic-gate 		__m_slk_labels_on = 1;
65*7c478bd9Sstevel@tonic-gate 		code = OK;
66*7c478bd9Sstevel@tonic-gate 	}
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	return (code);
69*7c478bd9Sstevel@tonic-gate }
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate int
slk_attron(const chtype at)72*7c478bd9Sstevel@tonic-gate slk_attron(const chtype at)
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate 	int	code = OK;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
77*7c478bd9Sstevel@tonic-gate 		code = wattron(__m_screen->_slk._w, (int) at);
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 	return (code);
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate int
slk_attroff(const chtype at)83*7c478bd9Sstevel@tonic-gate slk_attroff(const chtype at)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate 	int	code = OK;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
88*7c478bd9Sstevel@tonic-gate 		code = wattroff(__m_screen->_slk._w, (int) at);
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	return (code);
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate int
slk_attrset(const chtype at)94*7c478bd9Sstevel@tonic-gate slk_attrset(const chtype at)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 	int	code = OK;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
99*7c478bd9Sstevel@tonic-gate 		code = wattrset(__m_screen->_slk._w, (int) at);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	return (code);
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate int
slk_attr_off(const attr_t at,void * opts)105*7c478bd9Sstevel@tonic-gate slk_attr_off(const attr_t at, void *opts)
106*7c478bd9Sstevel@tonic-gate {
107*7c478bd9Sstevel@tonic-gate 	int	code = OK;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
110*7c478bd9Sstevel@tonic-gate 		code = wattr_off(__m_screen->_slk._w, at, opts);
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	return (code);
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate int
slk_attr_on(const attr_t at,void * opts)116*7c478bd9Sstevel@tonic-gate slk_attr_on(const attr_t at, void *opts)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate 	int	code = OK;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
121*7c478bd9Sstevel@tonic-gate 		code = wattr_on(__m_screen->_slk._w, at, opts);
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate 	return (code);
124*7c478bd9Sstevel@tonic-gate }
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate int
slk_attr_set(const attr_t at,short co,void * opts)127*7c478bd9Sstevel@tonic-gate slk_attr_set(const attr_t at, short co, void *opts)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate 	int	code = OK;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
132*7c478bd9Sstevel@tonic-gate 		code = wattr_set(__m_screen->_slk._w, at, co, opts);
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	return (code);
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate int
slk_color(short co)138*7c478bd9Sstevel@tonic-gate slk_color(short co)
139*7c478bd9Sstevel@tonic-gate {
140*7c478bd9Sstevel@tonic-gate 	int	code = OK;
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
143*7c478bd9Sstevel@tonic-gate 		code = wcolor_set(__m_screen->_slk._w, co, (void *) 0);
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	return (code);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate int
slk_touch(void)149*7c478bd9Sstevel@tonic-gate slk_touch(void)
150*7c478bd9Sstevel@tonic-gate {
151*7c478bd9Sstevel@tonic-gate 	int	code = OK;
152*7c478bd9Sstevel@tonic-gate 	WINDOW	*w = __m_screen->_slk._w;
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	if (w != NULL) {
155*7c478bd9Sstevel@tonic-gate 		code = wtouchln(w, 0, 1, 1);
156*7c478bd9Sstevel@tonic-gate 		wtouchln_hard(w, 0, 1);
157*7c478bd9Sstevel@tonic-gate 	} else
158*7c478bd9Sstevel@tonic-gate 		__m_slk_touched = 1;
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate 	return (code);
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate /*
164*7c478bd9Sstevel@tonic-gate  * These label start columns assume 80 columns in order to
165*7c478bd9Sstevel@tonic-gate  * fit 8 _slk._labels of 8 columns.
166*7c478bd9Sstevel@tonic-gate  */
167*7c478bd9Sstevel@tonic-gate static const int	format[][8] = {
168*7c478bd9Sstevel@tonic-gate 	{ 0, 9, 18, 31, 40, 53, 62, 71 },
169*7c478bd9Sstevel@tonic-gate 	{ 0, 9, 18, 27, 44, 53, 62, 71 },
170*7c478bd9Sstevel@tonic-gate };
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate #define	_LABEL_LENGTH_MALLOC	\
173*7c478bd9Sstevel@tonic-gate 	(MB_LEN_MAX * ((1 + _M_CCHAR_MAX) * 8) + 1)
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate void
__m_slk_set_all(void)176*7c478bd9Sstevel@tonic-gate __m_slk_set_all(void)
177*7c478bd9Sstevel@tonic-gate {
178*7c478bd9Sstevel@tonic-gate 	int	i;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < 8; ++i) {
181*7c478bd9Sstevel@tonic-gate 		if (__m_screen->_slk._labels[i] != NULL) {
182*7c478bd9Sstevel@tonic-gate 			(void) slk_set(i + 1, __m_screen->_slk._labels[i],
183*7c478bd9Sstevel@tonic-gate 				__m_screen->_slk._justify[i]);
184*7c478bd9Sstevel@tonic-gate 		}
185*7c478bd9Sstevel@tonic-gate 	}
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate int
__m_slk_clear(int kluge)189*7c478bd9Sstevel@tonic-gate __m_slk_clear(int kluge)
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	int	i;
192*7c478bd9Sstevel@tonic-gate 	int	index;
193*7c478bd9Sstevel@tonic-gate 	int	code = ERR;
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL) {
196*7c478bd9Sstevel@tonic-gate 		cchar_t	_bg = __m_screen->_slk._w->_bg;
197*7c478bd9Sstevel@tonic-gate 		if (kluge) {
198*7c478bd9Sstevel@tonic-gate 			/* Test suite expects spaces to have FG attributes */
199*7c478bd9Sstevel@tonic-gate 			__m_screen->_slk._w->_bg = __m_screen->_slk._w->_fg;
200*7c478bd9Sstevel@tonic-gate 		}
201*7c478bd9Sstevel@tonic-gate 		for (index = 0; index < 8; ++index) {
202*7c478bd9Sstevel@tonic-gate 			i = format[__m_slk_format][index];
203*7c478bd9Sstevel@tonic-gate 			(void) __m_cc_erase(__m_screen->_slk._w,
204*7c478bd9Sstevel@tonic-gate 				0, i, 0, i + 7);
205*7c478bd9Sstevel@tonic-gate 		}
206*7c478bd9Sstevel@tonic-gate 		__m_screen->_slk._w->_bg = _bg;		/* Restore ... */
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	} else if (plab_norm != NULL) {
209*7c478bd9Sstevel@tonic-gate 		for (index = 0; index < 8; ++index) {
210*7c478bd9Sstevel@tonic-gate 			char	*p;
211*7c478bd9Sstevel@tonic-gate 			p = __m_screen->_slk._saved[index];
212*7c478bd9Sstevel@tonic-gate 			if (!p) {
213*7c478bd9Sstevel@tonic-gate 				p = (char *)malloc(_LABEL_LENGTH_MALLOC);
214*7c478bd9Sstevel@tonic-gate 				if (p == NULL)
215*7c478bd9Sstevel@tonic-gate 					goto error;
216*7c478bd9Sstevel@tonic-gate 				__m_screen->_slk._saved[index] = p;
217*7c478bd9Sstevel@tonic-gate 			}
218*7c478bd9Sstevel@tonic-gate 			(void) strcpy(p, (kluge) ? "" : "        ");
219*7c478bd9Sstevel@tonic-gate 		}
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL) {
222*7c478bd9Sstevel@tonic-gate 		code = wrefresh(__m_screen->_slk._w);
223*7c478bd9Sstevel@tonic-gate 	} else {
224*7c478bd9Sstevel@tonic-gate 		__m_slk_labels_on = 0;
225*7c478bd9Sstevel@tonic-gate 		code = slk_refresh();
226*7c478bd9Sstevel@tonic-gate 	}
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate error:
229*7c478bd9Sstevel@tonic-gate 	return (code);
230*7c478bd9Sstevel@tonic-gate }
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate int
slk_clear(void)233*7c478bd9Sstevel@tonic-gate slk_clear(void)
234*7c478bd9Sstevel@tonic-gate {
235*7c478bd9Sstevel@tonic-gate 	return (__m_slk_clear(0));
236*7c478bd9Sstevel@tonic-gate }
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate int
slk_restore(void)239*7c478bd9Sstevel@tonic-gate slk_restore(void)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate 	int	code;
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate 	__m_slk_set_all();
244*7c478bd9Sstevel@tonic-gate 	__m_slk_labels_on = 1;
245*7c478bd9Sstevel@tonic-gate 	code = slk_refresh();
246*7c478bd9Sstevel@tonic-gate 	return (code);
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate int
slk_noutrefresh(void)250*7c478bd9Sstevel@tonic-gate slk_noutrefresh(void)
251*7c478bd9Sstevel@tonic-gate {
252*7c478bd9Sstevel@tonic-gate 	int	code;
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL)
255*7c478bd9Sstevel@tonic-gate 		code = wnoutrefresh(__m_screen->_slk._w);
256*7c478bd9Sstevel@tonic-gate 	else {
257*7c478bd9Sstevel@tonic-gate 		if (__m_slk_touched) {
258*7c478bd9Sstevel@tonic-gate 			__m_slk_set_all();
259*7c478bd9Sstevel@tonic-gate 			__m_slk_touched = 0;
260*7c478bd9Sstevel@tonic-gate 		}
261*7c478bd9Sstevel@tonic-gate 		if (__m_slk_labels_on) {
262*7c478bd9Sstevel@tonic-gate 			if (label_on != NULL) {
263*7c478bd9Sstevel@tonic-gate 				(void) TPUTS(label_on, 1, __m_outc);
264*7c478bd9Sstevel@tonic-gate 			}
265*7c478bd9Sstevel@tonic-gate 		} else {
266*7c478bd9Sstevel@tonic-gate 			if (label_off != NULL) {
267*7c478bd9Sstevel@tonic-gate 				(void) TPUTS(label_off, 1, __m_outc);
268*7c478bd9Sstevel@tonic-gate 			}
269*7c478bd9Sstevel@tonic-gate 		}
270*7c478bd9Sstevel@tonic-gate 		(void) fflush(__m_screen->_of);
271*7c478bd9Sstevel@tonic-gate 		code = OK;
272*7c478bd9Sstevel@tonic-gate 	}
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate 	return (code);
275*7c478bd9Sstevel@tonic-gate }
276*7c478bd9Sstevel@tonic-gate 
277*7c478bd9Sstevel@tonic-gate int
slk_refresh(void)278*7c478bd9Sstevel@tonic-gate slk_refresh(void)
279*7c478bd9Sstevel@tonic-gate {
280*7c478bd9Sstevel@tonic-gate 	int	code;
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	if ((code = slk_noutrefresh()) == OK)
283*7c478bd9Sstevel@tonic-gate 		code = doupdate();
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 	return (code);
286*7c478bd9Sstevel@tonic-gate }
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate void
__m_slk_doupdate(void)289*7c478bd9Sstevel@tonic-gate __m_slk_doupdate(void)
290*7c478bd9Sstevel@tonic-gate {
291*7c478bd9Sstevel@tonic-gate 	if ((__m_screen->_slk._w == NULL) && plab_norm) {
292*7c478bd9Sstevel@tonic-gate 		int	index;
293*7c478bd9Sstevel@tonic-gate 		for (index = 0; index < 8; index++) {
294*7c478bd9Sstevel@tonic-gate 			char	*s = __m_screen->_slk._saved[index];
295*7c478bd9Sstevel@tonic-gate 			if (s) {
296*7c478bd9Sstevel@tonic-gate 				(void) TPUTS(tparm(plab_norm, (long) index+1,
297*7c478bd9Sstevel@tonic-gate 					(long) s, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
298*7c478bd9Sstevel@tonic-gate 					1, __m_outc);
299*7c478bd9Sstevel@tonic-gate 			}
300*7c478bd9Sstevel@tonic-gate 		}
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate }
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate char *
slk_label(int index)305*7c478bd9Sstevel@tonic-gate slk_label(int index)
306*7c478bd9Sstevel@tonic-gate {
307*7c478bd9Sstevel@tonic-gate 	char	*label;
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 	if (index < 1 || 8 < index) {
310*7c478bd9Sstevel@tonic-gate 		label = NULL;
311*7c478bd9Sstevel@tonic-gate 	} else {
312*7c478bd9Sstevel@tonic-gate 		label = __m_screen->_slk._labels[index-1];
313*7c478bd9Sstevel@tonic-gate 	}
314*7c478bd9Sstevel@tonic-gate 	return (label);
315*7c478bd9Sstevel@tonic-gate }
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate int
slk_set(int index,const char * label,int justify)318*7c478bd9Sstevel@tonic-gate slk_set(int index, const char *label, int justify)
319*7c478bd9Sstevel@tonic-gate {
320*7c478bd9Sstevel@tonic-gate 	int	code = ERR;
321*7c478bd9Sstevel@tonic-gate 	wchar_t	wcs[_M_CCHAR_MAX * 8 + 1];
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 	if ((label == NULL) || *label == '\0')
324*7c478bd9Sstevel@tonic-gate 		label = "        ";
325*7c478bd9Sstevel@tonic-gate 	if (mbstowcs(wcs, label, sizeof (wcs)) != (size_t)-1)
326*7c478bd9Sstevel@tonic-gate 		code = slk_wset(index, wcs, justify);
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	return (code);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate int
slk_wset(int index,const wchar_t * label,int justify)332*7c478bd9Sstevel@tonic-gate slk_wset(int index, const wchar_t *label, int justify)
333*7c478bd9Sstevel@tonic-gate {
334*7c478bd9Sstevel@tonic-gate 	cchar_t	cc;
335*7c478bd9Sstevel@tonic-gate 	int	i, width, code = ERR;
336*7c478bd9Sstevel@tonic-gate 	wchar_t	wcs[_M_CCHAR_MAX * 8 + 1], *wp;
337*7c478bd9Sstevel@tonic-gate 	char	mbs[_LABEL_LENGTH_MALLOC];
338*7c478bd9Sstevel@tonic-gate 	char	tmbs[_LABEL_LENGTH_MALLOC];
339*7c478bd9Sstevel@tonic-gate 	int	ww = 0;
340*7c478bd9Sstevel@tonic-gate 	int	left1, left2;
341*7c478bd9Sstevel@tonic-gate 	static const char	*spcs = "        ";
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	if (index < 1 || 8 < index || justify < 0 || 2 < justify)
344*7c478bd9Sstevel@tonic-gate 		goto error1;
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	index--;	/* Shift from {1..8} to {0..7} */
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	if (label == NULL)
349*7c478bd9Sstevel@tonic-gate 		label = L"";
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	/* Copy the characters that fill the first 8 columns of the label. */
352*7c478bd9Sstevel@tonic-gate 	for (wp = wcs, width = 0; *label != '\0'; label += i, wp += cc._n) {
353*7c478bd9Sstevel@tonic-gate 		if ((i = __m_wcs_cc(label, A_NORMAL, 0, &cc)) < 0)
354*7c478bd9Sstevel@tonic-gate 			goto error1;
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate 		ww += __m_cc_width(&cc);
357*7c478bd9Sstevel@tonic-gate 		if (ww > 8)
358*7c478bd9Sstevel@tonic-gate 			break;
359*7c478bd9Sstevel@tonic-gate 		else
360*7c478bd9Sstevel@tonic-gate 			width = ww;
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 		(void) wcsncpy(wp, cc._wc, cc._n);
363*7c478bd9Sstevel@tonic-gate 	}
364*7c478bd9Sstevel@tonic-gate 	*wp = '\0';
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate 	if (wcstombs(tmbs, wcs, sizeof (mbs)) == (size_t) -1)
367*7c478bd9Sstevel@tonic-gate 		goto error1;
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	if (width == 8) {
370*7c478bd9Sstevel@tonic-gate 		(void) strcpy(mbs, tmbs);
371*7c478bd9Sstevel@tonic-gate 	} else {
372*7c478bd9Sstevel@tonic-gate 		switch (justify) {
373*7c478bd9Sstevel@tonic-gate 		case 0:
374*7c478bd9Sstevel@tonic-gate 			(void) strcpy(mbs, tmbs);
375*7c478bd9Sstevel@tonic-gate 			(void) strncat(mbs, spcs, (8 - width));
376*7c478bd9Sstevel@tonic-gate 			*(mbs + strlen(tmbs) + (8 - width)) = '\0';
377*7c478bd9Sstevel@tonic-gate 			break;
378*7c478bd9Sstevel@tonic-gate 		case 1:
379*7c478bd9Sstevel@tonic-gate 			left1 = (8 - width) / 2;
380*7c478bd9Sstevel@tonic-gate 			(void) strncpy(mbs, spcs, left1);
381*7c478bd9Sstevel@tonic-gate 			(void) strcpy(mbs + left1, tmbs);
382*7c478bd9Sstevel@tonic-gate 			left2 = 8 - width - left1;
383*7c478bd9Sstevel@tonic-gate 			(void) strncat(mbs, spcs, left2);
384*7c478bd9Sstevel@tonic-gate 			*(mbs + left1 + strlen(tmbs) + left2) = '\0';
385*7c478bd9Sstevel@tonic-gate 			break;
386*7c478bd9Sstevel@tonic-gate 		case 2:
387*7c478bd9Sstevel@tonic-gate 			left1 = 8 - width;
388*7c478bd9Sstevel@tonic-gate 			(void) strncpy(mbs, spcs, left1);
389*7c478bd9Sstevel@tonic-gate 			(void) strcpy(mbs + left1, tmbs);
390*7c478bd9Sstevel@tonic-gate 			break;
391*7c478bd9Sstevel@tonic-gate 		}
392*7c478bd9Sstevel@tonic-gate 	}
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	/* Remember the new label. */
395*7c478bd9Sstevel@tonic-gate 	__m_screen->_slk._justify[index] = (short) justify;
396*7c478bd9Sstevel@tonic-gate 
397*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._labels[index] != NULL)
398*7c478bd9Sstevel@tonic-gate 		free(__m_screen->_slk._labels[index]);
399*7c478bd9Sstevel@tonic-gate 	if ((__m_screen->_slk._labels[index] = strdup(tmbs)) == NULL)
400*7c478bd9Sstevel@tonic-gate 		goto error1;
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate 	if (plab_norm != NULL) {
403*7c478bd9Sstevel@tonic-gate 		char	*p;
404*7c478bd9Sstevel@tonic-gate 		p = __m_screen->_slk._saved[index];
405*7c478bd9Sstevel@tonic-gate 		if (!p) {
406*7c478bd9Sstevel@tonic-gate 			p = (char *)malloc(_LABEL_LENGTH_MALLOC);
407*7c478bd9Sstevel@tonic-gate 			if (p == NULL)
408*7c478bd9Sstevel@tonic-gate 				goto error1;
409*7c478bd9Sstevel@tonic-gate 			__m_screen->_slk._saved[index] = p;
410*7c478bd9Sstevel@tonic-gate 		}
411*7c478bd9Sstevel@tonic-gate 		(void) strcpy(p, mbs);
412*7c478bd9Sstevel@tonic-gate 	}
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate 	__m_slk_labels_on = 1;
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate 	if (__m_screen->_slk._w != NULL) {
417*7c478bd9Sstevel@tonic-gate 		cchar_t	_bg = __m_screen->_slk._w->_bg;
418*7c478bd9Sstevel@tonic-gate 		/* Write the justified label into the slk window. */
419*7c478bd9Sstevel@tonic-gate 		i = format[__m_slk_format][index];
420*7c478bd9Sstevel@tonic-gate 		__m_screen->_slk._w->_bg = __m_screen->_slk._w->_fg;
421*7c478bd9Sstevel@tonic-gate 		(void) __m_cc_erase(__m_screen->_slk._w, 0, i, 0, i + 7);
422*7c478bd9Sstevel@tonic-gate 		__m_screen->_slk._w->_bg = _bg;		/* Restore ... */
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate 		(void) mvwaddstr(__m_screen->_slk._w, 0, i, mbs);
425*7c478bd9Sstevel@tonic-gate 	}
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate 	code = OK;
428*7c478bd9Sstevel@tonic-gate error1:
429*7c478bd9Sstevel@tonic-gate 	return (code);
430*7c478bd9Sstevel@tonic-gate }
431