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 1997 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
43*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
44*7c478bd9Sstevel@tonic-gate #include "curses_inc.h"
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #ifdef PC6300PLUS
47*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/console.h>
49*7c478bd9Sstevel@tonic-gate #endif
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #define	NUM_OF_SPECIFIC_TURN_OFFS	3
52*7c478bd9Sstevel@tonic-gate extern	chtype	bit_attributes[];
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate int Oldcolors[] = { COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
55*7c478bd9Sstevel@tonic-gate 		COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE };
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate void
vidupdate(chtype newmode,chtype oldmode,int (* outc)(char))58*7c478bd9Sstevel@tonic-gate vidupdate(chtype newmode, chtype oldmode, int (*outc)(char))
59*7c478bd9Sstevel@tonic-gate {
60*7c478bd9Sstevel@tonic-gate 	bool color_terminal = (cur_term->_pairs_tbl) ? TRUE : FALSE;
61*7c478bd9Sstevel@tonic-gate 	chtype oldvideo = (oldmode & A_ATTRIBUTES) & ~A_COLOR;
62*7c478bd9Sstevel@tonic-gate 	chtype newvideo = (newmode & A_ATTRIBUTES) & ~A_COLOR;
63*7c478bd9Sstevel@tonic-gate 	int  _change_video(chtype, chtype, int (*)(char));
64*7c478bd9Sstevel@tonic-gate 	void _change_color(short, int (*)(char));
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate 	/* if colors are used, extract the color related information from */
67*7c478bd9Sstevel@tonic-gate 	/* the old and new modes and then erase color-pairs fields in	*/
68*7c478bd9Sstevel@tonic-gate 	/* both arguments.						*/
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 	if (color_terminal) {
71*7c478bd9Sstevel@tonic-gate 		/* LINTED */
72*7c478bd9Sstevel@tonic-gate 		short oldcolor = (short) PAIR_NUMBER(oldmode & A_COLOR);
73*7c478bd9Sstevel@tonic-gate 		/* LINTED */
74*7c478bd9Sstevel@tonic-gate 		short newcolor = (short) PAIR_NUMBER(newmode & A_COLOR);
75*7c478bd9Sstevel@tonic-gate 		chtype turn_off = A_COLOR;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 		/* erase information about video attributes that could not */
78*7c478bd9Sstevel@tonic-gate 		/* have been used with colors				   */
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate 		if (oldcolor == 0)
81*7c478bd9Sstevel@tonic-gate 			oldvideo &= ~turn_off;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 		if (no_color_video != -1)
84*7c478bd9Sstevel@tonic-gate 			turn_off |= (((chtype) no_color_video) << 16);
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 		if (oldcolor != 0)
87*7c478bd9Sstevel@tonic-gate 			oldvideo &= ~turn_off;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 		/* if the new mode contains color information, then first  */
91*7c478bd9Sstevel@tonic-gate 		/* deal with video attributes, and then with colors.  This */
92*7c478bd9Sstevel@tonic-gate 		/* way color information will overwrite video information. */
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 		if (newcolor != 0) {
95*7c478bd9Sstevel@tonic-gate 			/* erase information about video attributes that */
96*7c478bd9Sstevel@tonic-gate 			/* should not be used with colors		 */
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 			newvideo &= ~turn_off;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 			/* if the new and the old video modes became 	*/
101*7c478bd9Sstevel@tonic-gate 			/* the same don't bother with them		*/
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 			if (newvideo != oldvideo) {
104*7c478bd9Sstevel@tonic-gate 				if ((_change_video(newvideo, oldvideo,
105*7c478bd9Sstevel@tonic-gate 				    outc)) == -1) {
106*7c478bd9Sstevel@tonic-gate 					_Color_pair *cur_pair =
107*7c478bd9Sstevel@tonic-gate 					    &cur_term->_cur_pair;
108*7c478bd9Sstevel@tonic-gate 					oldcolor = -1;
109*7c478bd9Sstevel@tonic-gate 					cur_pair->background =
110*7c478bd9Sstevel@tonic-gate 					    cur_pair->foreground = -1;
111*7c478bd9Sstevel@tonic-gate 				}
112*7c478bd9Sstevel@tonic-gate 			}
113*7c478bd9Sstevel@tonic-gate 			if (newcolor != oldcolor)
114*7c478bd9Sstevel@tonic-gate 				_change_color(newcolor, outc);
115*7c478bd9Sstevel@tonic-gate 		}
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 		/* new mode doesn't contain any color information.  Deal */
118*7c478bd9Sstevel@tonic-gate 		/* with colors first (possibly turning of the colors that */
119*7c478bd9Sstevel@tonic-gate 		/* were contained in the oldmode, and then deal with video. */
120*7c478bd9Sstevel@tonic-gate 		/* This way video attributes will overwrite colors.	*/
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 		else {
123*7c478bd9Sstevel@tonic-gate 			if (newcolor != oldcolor)
124*7c478bd9Sstevel@tonic-gate 				_change_color(newcolor, outc);
125*7c478bd9Sstevel@tonic-gate 			if (newvideo != oldvideo)
126*7c478bd9Sstevel@tonic-gate 				(void) _change_video(newvideo, oldvideo, outc);
127*7c478bd9Sstevel@tonic-gate 		}
128*7c478bd9Sstevel@tonic-gate 	} else
129*7c478bd9Sstevel@tonic-gate 		(void) _change_video(newvideo, oldvideo, outc);
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate int
_change_video(chtype newmode,chtype oldmode,int (* outc)(char))134*7c478bd9Sstevel@tonic-gate _change_video(chtype newmode, chtype oldmode, int (*outc)(char))
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate 	int rc = 0;
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	/* If you have set_attributes let the terminfo writer */
139*7c478bd9Sstevel@tonic-gate 	/* worry about it. */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	if (!set_attributes) {
142*7c478bd9Sstevel@tonic-gate 	/*
143*7c478bd9Sstevel@tonic-gate 	 * The trick is that we want to pre-process the new and oldmode
144*7c478bd9Sstevel@tonic-gate 	 * so that we now know what they will really translate to on
145*7c478bd9Sstevel@tonic-gate 	 * the physical screen.
146*7c478bd9Sstevel@tonic-gate 	 * In the case where some attributes are being faked
147*7c478bd9Sstevel@tonic-gate 	 * we get rid of the attributes being asked for and just have
148*7c478bd9Sstevel@tonic-gate 	 * STANDOUT mode set.  Therefore, if STANDOUT and UNDERLINE were
149*7c478bd9Sstevel@tonic-gate 	 * on the screen but UNDERLINE was being faked to STANDOUT; and
150*7c478bd9Sstevel@tonic-gate 	 * the new mode is just UNDERLINE, we will get rid of any faked
151*7c478bd9Sstevel@tonic-gate 	 * modes and be left with and oldmode of STANDOUT and a new mode
152*7c478bd9Sstevel@tonic-gate 	 * of STANDOUT, in which case the check for newmode and oldmode
153*7c478bd9Sstevel@tonic-gate 	 * being equal will be true.
154*7c478bd9Sstevel@tonic-gate 	 *
155*7c478bd9Sstevel@tonic-gate 	 *
156*7c478bd9Sstevel@tonic-gate 	 * This test is similar to the concept explained above.
157*7c478bd9Sstevel@tonic-gate 	 * counter is the maximum attributes allowed on a terminal.
158*7c478bd9Sstevel@tonic-gate 	 * For instance, on an hp/tvi950 without set_attributes
159*7c478bd9Sstevel@tonic-gate 	 * the last video sequence sent will be the one the terminal
160*7c478bd9Sstevel@tonic-gate 	 * will be in (on that spot).  Therefore, in setupterm.c
161*7c478bd9Sstevel@tonic-gate 	 * if ceol_standout_glitch or magic_cookie_glitch is set
162*7c478bd9Sstevel@tonic-gate 	 * max_attributes is set to 1.  This is because on those terminals
163*7c478bd9Sstevel@tonic-gate 	 * only one attribute can be on at once.  So, we pre-process the
164*7c478bd9Sstevel@tonic-gate 	 * oldmode and the newmode and only leave the bits that are
165*7c478bd9Sstevel@tonic-gate 	 * significant.  In other words, if on an hp you ask for STANDOUT
166*7c478bd9Sstevel@tonic-gate 	 * and UNDERLINE it will become only STANDOUT since that is the
167*7c478bd9Sstevel@tonic-gate 	 * first bit that is looked at.  If then the user goes from
168*7c478bd9Sstevel@tonic-gate 	 * STANDOUT and UNDERLINE to STANDOUT and REVERSE the oldmode will
169*7c478bd9Sstevel@tonic-gate 	 * become STANDOUT and the newmode will become STANDOUT.
170*7c478bd9Sstevel@tonic-gate 	 *
171*7c478bd9Sstevel@tonic-gate 	 * This also helps the code below in that on a hp or tvi950 only
172*7c478bd9Sstevel@tonic-gate 	 * one bit will ever be set so that no code has to be added to
173*7c478bd9Sstevel@tonic-gate 	 * cut out early in case two attributes were asked for.
174*7c478bd9Sstevel@tonic-gate 	 */
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 		chtype	check_faked, modes[2];
177*7c478bd9Sstevel@tonic-gate 		int	counter = max_attributes, i, j, tempmode;
178*7c478bd9Sstevel@tonic-gate 		int	k = (cur_term->sgr_mode == oldmode) ? 1 : 2;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 		modes[0] = newmode;
181*7c478bd9Sstevel@tonic-gate 		modes[1] = oldmode;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 		while (k-- > 0) {
184*7c478bd9Sstevel@tonic-gate 			if ((check_faked = (modes[k] &
185*7c478bd9Sstevel@tonic-gate 			    cur_term->sgr_faked)) != A_NORMAL) {
186*7c478bd9Sstevel@tonic-gate 				modes[k] &= ~check_faked;
187*7c478bd9Sstevel@tonic-gate 				modes[k] |= A_STANDOUT;
188*7c478bd9Sstevel@tonic-gate 			}
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 			if ((j = counter) >= 0) {
191*7c478bd9Sstevel@tonic-gate 				tempmode = A_NORMAL;
192*7c478bd9Sstevel@tonic-gate 				if (j > 0) {
193*7c478bd9Sstevel@tonic-gate 					for (i = 0; i < NUM_ATTRIBUTES; i++) {
194*7c478bd9Sstevel@tonic-gate 						if (modes[k] &
195*7c478bd9Sstevel@tonic-gate 						    bit_attributes[i]) {
196*7c478bd9Sstevel@tonic-gate 							tempmode |=
197*7c478bd9Sstevel@tonic-gate 							    bit_attributes[i];
198*7c478bd9Sstevel@tonic-gate 							if (--j == 0)
199*7c478bd9Sstevel@tonic-gate 								break;
200*7c478bd9Sstevel@tonic-gate 						}
201*7c478bd9Sstevel@tonic-gate 					}
202*7c478bd9Sstevel@tonic-gate 				}
203*7c478bd9Sstevel@tonic-gate 				modes[k] = tempmode;
204*7c478bd9Sstevel@tonic-gate 			}
205*7c478bd9Sstevel@tonic-gate 		}
206*7c478bd9Sstevel@tonic-gate 		newmode = modes[0];
207*7c478bd9Sstevel@tonic-gate 		oldmode = modes[1];
208*7c478bd9Sstevel@tonic-gate 	}
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	if (newmode == oldmode)
211*7c478bd9Sstevel@tonic-gate 		return (rc);
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
214*7c478bd9Sstevel@tonic-gate 	if (outf)
215*7c478bd9Sstevel@tonic-gate 		fprintf(outf, "vidupdate oldmode=%o, newmode=%o\n",
216*7c478bd9Sstevel@tonic-gate 		    oldmode, newmode);
217*7c478bd9Sstevel@tonic-gate #endif
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	if (set_attributes) {
220*7c478bd9Sstevel@tonic-gate 		(void) tputs(tparm(set_attributes,
221*7c478bd9Sstevel@tonic-gate 			newmode & A_STANDOUT,
222*7c478bd9Sstevel@tonic-gate 			newmode & A_UNDERLINE,
223*7c478bd9Sstevel@tonic-gate 			newmode & A_REVERSE,
224*7c478bd9Sstevel@tonic-gate 			newmode & A_BLINK,
225*7c478bd9Sstevel@tonic-gate 			newmode & A_DIM,
226*7c478bd9Sstevel@tonic-gate 			newmode & A_BOLD,
227*7c478bd9Sstevel@tonic-gate 			newmode & A_INVIS,
228*7c478bd9Sstevel@tonic-gate 			newmode & A_PROTECT,
229*7c478bd9Sstevel@tonic-gate 			newmode & A_ALTCHARSET),
230*7c478bd9Sstevel@tonic-gate 			1, outc);
231*7c478bd9Sstevel@tonic-gate 		rc = -1;
232*7c478bd9Sstevel@tonic-gate 	} else {
233*7c478bd9Sstevel@tonic-gate 		chtype	turn_on, turn_off;
234*7c478bd9Sstevel@tonic-gate 		int			i;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 		/*
237*7c478bd9Sstevel@tonic-gate 		 * If we are going to turn something on anyway and we are
238*7c478bd9Sstevel@tonic-gate 		 * on a glitchy terminal, don't bother turning it off
239*7c478bd9Sstevel@tonic-gate 		 * since by turning something on you turn everything else off.
240*7c478bd9Sstevel@tonic-gate 		 */
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 		if ((ceol_standout_glitch || magic_cookie_glitch >= 0) &&
243*7c478bd9Sstevel@tonic-gate 		    ((turn_on = ((oldmode ^ newmode) & newmode)) !=
244*7c478bd9Sstevel@tonic-gate 		    A_NORMAL)) {
245*7c478bd9Sstevel@tonic-gate 			goto turn_on_code;
246*7c478bd9Sstevel@tonic-gate 	}
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	if ((turn_off = (oldmode & newmode) ^ oldmode) != A_NORMAL) {
249*7c478bd9Sstevel@tonic-gate 		/*
250*7c478bd9Sstevel@tonic-gate 		 * Check for things to turn off.
251*7c478bd9Sstevel@tonic-gate 		 * First see if we are going to turn off something
252*7c478bd9Sstevel@tonic-gate 		 * that doesn't have a specific turn off capability.
253*7c478bd9Sstevel@tonic-gate 		 *
254*7c478bd9Sstevel@tonic-gate 		 * Then check to see if, even though there may be a specific
255*7c478bd9Sstevel@tonic-gate 		 * turn off sequence, this terminal doesn't have one or
256*7c478bd9Sstevel@tonic-gate 		 * the turn off sequence also turns off something else.
257*7c478bd9Sstevel@tonic-gate 		 */
258*7c478bd9Sstevel@tonic-gate 		if ((turn_off & ~(A_ALTCHARSET | A_STANDOUT | A_UNDERLINE)) ||
259*7c478bd9Sstevel@tonic-gate 		    (turn_off != (turn_off & cur_term->check_turn_off))) {
260*7c478bd9Sstevel@tonic-gate 			(void) tputs(tparm_p0(exit_attribute_mode), 1, outc);
261*7c478bd9Sstevel@tonic-gate 			rc = -1;
262*7c478bd9Sstevel@tonic-gate 			oldmode = A_NORMAL;
263*7c478bd9Sstevel@tonic-gate 		} else {
264*7c478bd9Sstevel@tonic-gate 			for (i = 0; i < NUM_OF_SPECIFIC_TURN_OFFS; i++) {
265*7c478bd9Sstevel@tonic-gate 				if (turn_off & bit_attributes[i]) {
266*7c478bd9Sstevel@tonic-gate 					(void) tputs(tparm_p0
267*7c478bd9Sstevel@tonic-gate 					    (cur_term->turn_off_seq[i]),
268*7c478bd9Sstevel@tonic-gate 					    1, outc);
269*7c478bd9Sstevel@tonic-gate 					oldmode &= ~bit_attributes[i];
270*7c478bd9Sstevel@tonic-gate 					rc = -1;
271*7c478bd9Sstevel@tonic-gate 				}
272*7c478bd9Sstevel@tonic-gate 			}
273*7c478bd9Sstevel@tonic-gate 		}
274*7c478bd9Sstevel@tonic-gate 	}
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate 	if ((turn_on = ((oldmode ^ newmode) & newmode)) != A_NORMAL) {
277*7c478bd9Sstevel@tonic-gate turn_on_code:
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 		/* Check for modes to turn on. */
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < NUM_ATTRIBUTES; i++)
282*7c478bd9Sstevel@tonic-gate 			if (turn_on & bit_attributes[i]) {
283*7c478bd9Sstevel@tonic-gate 				(void) tputs(tparm_p0(cur_term->turn_on_seq[i]),
284*7c478bd9Sstevel@tonic-gate 				    1, outc);
285*7c478bd9Sstevel@tonic-gate 				rc = -1;
286*7c478bd9Sstevel@tonic-gate 				/*
287*7c478bd9Sstevel@tonic-gate 				 * Keep turning off the bit(s) that we just
288*7c478bd9Sstevel@tonic-gate 				 * sent to the screen.  As soon as turn_on
289*7c478bd9Sstevel@tonic-gate 				 * reaches A_NORMAL we don't have to turn
290*7c478bd9Sstevel@tonic-gate 				 * anything else on and we can
291*7c478bd9Sstevel@tonic-gate 				 * break out of the loop.
292*7c478bd9Sstevel@tonic-gate 				 */
293*7c478bd9Sstevel@tonic-gate 				if ((turn_on &= ~bit_attributes[i]) ==
294*7c478bd9Sstevel@tonic-gate 				    A_NORMAL)
295*7c478bd9Sstevel@tonic-gate 					break;
296*7c478bd9Sstevel@tonic-gate 			}
297*7c478bd9Sstevel@tonic-gate 		}
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 		if (magic_cookie_glitch > 0)
300*7c478bd9Sstevel@tonic-gate 			(void) tputs(cursor_left, 1, outc);
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate 	cur_term->sgr_mode = newmode;
303*7c478bd9Sstevel@tonic-gate 	return (rc);
304*7c478bd9Sstevel@tonic-gate }
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate void
_change_color(short newcolor,int (* outc)(char))308*7c478bd9Sstevel@tonic-gate _change_color(short newcolor, int (*outc)(char))
309*7c478bd9Sstevel@tonic-gate {
310*7c478bd9Sstevel@tonic-gate #ifndef PC6300PLUS
311*7c478bd9Sstevel@tonic-gate 	{
312*7c478bd9Sstevel@tonic-gate 	_Color_pair *ptp = cur_term->_pairs_tbl;
313*7c478bd9Sstevel@tonic-gate 	/* pairs table pointer */
314*7c478bd9Sstevel@tonic-gate 	_Color_pair *cur_pair = &cur_term->_cur_pair;
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 	/* MORE: we may have to change some stuff, depending on whether */
317*7c478bd9Sstevel@tonic-gate 	/* HP terminals  will be changing the background, or not	*/
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate 	if (newcolor == 0) {
320*7c478bd9Sstevel@tonic-gate 		if (orig_pair)
321*7c478bd9Sstevel@tonic-gate 			(void) tputs(tparm_p0(orig_pair), 1, outc);
322*7c478bd9Sstevel@tonic-gate 		if (set_a_background || set_a_foreground ||
323*7c478bd9Sstevel@tonic-gate 		    set_background || set_foreground) {
324*7c478bd9Sstevel@tonic-gate 			cur_pair->background = -1;
325*7c478bd9Sstevel@tonic-gate 			cur_pair->foreground = -1;
326*7c478bd9Sstevel@tonic-gate 		}
327*7c478bd9Sstevel@tonic-gate 		return;
328*7c478bd9Sstevel@tonic-gate 	}
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	/* if we are on HP type terminal, just send an escape sequence	*/
331*7c478bd9Sstevel@tonic-gate 	/* to use desired color pair (we could have done some optimization: */
332*7c478bd9Sstevel@tonic-gate 	/* check if both the foreground and background of newcolor match    */
333*7c478bd9Sstevel@tonic-gate 	/* the ones of cur_term->_cur_pair.  but that will happen only when */
334*7c478bd9Sstevel@tonic-gate 	/* two color pairs are defined exacly the same, and probably not    */
335*7c478bd9Sstevel@tonic-gate 	/* worth the effort).						    */
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	if (set_color_pair)
338*7c478bd9Sstevel@tonic-gate 		(void) tputs(tparm_p1(set_color_pair, newcolor), 1, outc);
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 		/* on Tek model we can do some optimization.	*/
341*7c478bd9Sstevel@tonic-gate 
342*7c478bd9Sstevel@tonic-gate 	else {
343*7c478bd9Sstevel@tonic-gate 		if (ptp[newcolor].background != cur_pair->background) {
344*7c478bd9Sstevel@tonic-gate 			if (set_a_background)
345*7c478bd9Sstevel@tonic-gate 				(void) tputs(tparm_p1(set_a_background,
346*7c478bd9Sstevel@tonic-gate 				    ptp[newcolor].background), 1, outc);
347*7c478bd9Sstevel@tonic-gate 			else if (set_background)
348*7c478bd9Sstevel@tonic-gate 				(void) tputs(tparm_p1(set_background,
349*7c478bd9Sstevel@tonic-gate 				    Oldcolors[ptp[newcolor].background]),
350*7c478bd9Sstevel@tonic-gate 				    1, outc);
351*7c478bd9Sstevel@tonic-gate 			cur_pair->background = ptp[newcolor].background;
352*7c478bd9Sstevel@tonic-gate 		}
353*7c478bd9Sstevel@tonic-gate 		if (ptp[newcolor].foreground != cur_pair->foreground) {
354*7c478bd9Sstevel@tonic-gate 			if (set_a_foreground)
355*7c478bd9Sstevel@tonic-gate 				(void) tputs(tparm_p1(set_a_foreground,
356*7c478bd9Sstevel@tonic-gate 				    ptp[newcolor].foreground), 1, outc);
357*7c478bd9Sstevel@tonic-gate 			else if (set_foreground)
358*7c478bd9Sstevel@tonic-gate 				(void) tputs(tparm_p1(set_foreground,
359*7c478bd9Sstevel@tonic-gate 				    Oldcolors[ptp[newcolor].foreground]),
360*7c478bd9Sstevel@tonic-gate 				    1, outc);
361*7c478bd9Sstevel@tonic-gate 			cur_pair->foreground = ptp[newcolor].foreground;
362*7c478bd9Sstevel@tonic-gate 		}
363*7c478bd9Sstevel@tonic-gate 	}
364*7c478bd9Sstevel@tonic-gate 	}
365*7c478bd9Sstevel@tonic-gate #else
366*7c478bd9Sstevel@tonic-gate 	{
367*7c478bd9Sstevel@tonic-gate 	/* the following code is for PC6300 PLUS: it uses BOLD terminfo  */
368*7c478bd9Sstevel@tonic-gate 	/* entry for turning on colors, and SGR0 for turning them off.   */
369*7c478bd9Sstevel@tonic-gate 	/* Every time a new color-pair is used, we are forced to do an   */
370*7c478bd9Sstevel@tonic-gate 	/* ioctl read, and the send 'enter_bold_mode' escape sequence.   */
371*7c478bd9Sstevel@tonic-gate 	/* This could be improved  by using   */
372*7c478bd9Sstevel@tonic-gate 	/* DIM, UNDERLINE, and REVERSE in addition to BOLD		 */
373*7c478bd9Sstevel@tonic-gate 
374*7c478bd9Sstevel@tonic-gate 	struct console con;
375*7c478bd9Sstevel@tonic-gate 	_Color_pair *ptp = cur_term->_pairs_tbl;
376*7c478bd9Sstevel@tonic-gate 	/* pairs table pointer */
377*7c478bd9Sstevel@tonic-gate 	back = ptp[newcolor].background;
378*7c478bd9Sstevel@tonic-gate 	fore = ptp[newcolor].foreground;
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate 	(void) fflush(SP->term_file);
381*7c478bd9Sstevel@tonic-gate 	ioctl(cur_term->Filedes, CONIOGETDATA, &con);
382*7c478bd9Sstevel@tonic-gate #define	BOLD	4
383*7c478bd9Sstevel@tonic-gate 	con.l[con.page].colors[BOLD] =
384*7c478bd9Sstevel@tonic-gate 	    ((back + back + (fore > 5)) * 8 + fore) & 0177;
385*7c478bd9Sstevel@tonic-gate 	ioctl(cur_term->Filedes, CONIOSETDATA, &con);
386*7c478bd9Sstevel@tonic-gate 	(void) tputs(enter_bold_mode, 1, outc);
387*7c478bd9Sstevel@tonic-gate 	}
388*7c478bd9Sstevel@tonic-gate #endif
389*7c478bd9Sstevel@tonic-gate }
390