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-1998 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * color.c
31*7c478bd9Sstevel@tonic-gate *
32*7c478bd9Sstevel@tonic-gate * XCurses Library
33*7c478bd9Sstevel@tonic-gate *
34*7c478bd9Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #ifdef M_RCSID
39*7c478bd9Sstevel@tonic-gate #ifndef lint
40*7c478bd9Sstevel@tonic-gate static char rcsID[] =
41*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/color.c 1.6 1998/05/28 17:10:14 "
43*7c478bd9Sstevel@tonic-gate "cbates Exp $";
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate #include <private.h>
48*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate int
start_color(void)51*7c478bd9Sstevel@tonic-gate start_color(void)
52*7c478bd9Sstevel@tonic-gate {
53*7c478bd9Sstevel@tonic-gate COLORS = max_colors;
54*7c478bd9Sstevel@tonic-gate COLOR_PAIRS = max_pairs;
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate if (orig_colors != (char *) 0)
57*7c478bd9Sstevel@tonic-gate (void) TPUTS(orig_colors, 1, __m_outc);
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate if (orig_pair != (char *) 0)
60*7c478bd9Sstevel@tonic-gate (void) TPUTS(orig_pair, 1, __m_outc);
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate if (0 < max_colors) {
63*7c478bd9Sstevel@tonic-gate cur_term->_color = calloc(max_colors,
64*7c478bd9Sstevel@tonic-gate sizeof (*cur_term->_color));
65*7c478bd9Sstevel@tonic-gate if (cur_term->_color == (short (*)[3]) 0)
66*7c478bd9Sstevel@tonic-gate goto error1;
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate if (0 < max_pairs) {
70*7c478bd9Sstevel@tonic-gate cur_term->_pair = calloc(max_pairs, sizeof (*cur_term->_pair));
71*7c478bd9Sstevel@tonic-gate if (cur_term->_pair == (short (*)[2]) 0)
72*7c478bd9Sstevel@tonic-gate goto error2;
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_BLACK, 0, 0, 0);
76*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_RED, 1000, 0, 0);
77*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_GREEN, 0, 1000, 0);
78*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_BLUE, 0, 0, 1000);
79*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_YELLOW, 1000, 1000, 0);
80*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_MAGENTA, 1000, 0, 1000);
81*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_CYAN, 0, 1000, 1000);
82*7c478bd9Sstevel@tonic-gate (void) init_color(COLOR_WHITE, 1000, 1000, 1000);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate return (OK);
85*7c478bd9Sstevel@tonic-gate error2:
86*7c478bd9Sstevel@tonic-gate if (cur_term->_color != (short (*)[3]) 0)
87*7c478bd9Sstevel@tonic-gate free(cur_term->_color);
88*7c478bd9Sstevel@tonic-gate error1:
89*7c478bd9Sstevel@tonic-gate return (ERR);
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate int
init_color(short color,short r,short g,short b)93*7c478bd9Sstevel@tonic-gate init_color(short color, short r, short g, short b)
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate int code = ERR;
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate if (!can_change || color < 0 || max_colors <= color ||
98*7c478bd9Sstevel@tonic-gate r < 0 || 1000 < r ||
99*7c478bd9Sstevel@tonic-gate g < 0 || 1000 < g ||
100*7c478bd9Sstevel@tonic-gate b < 0 || 1000 < b)
101*7c478bd9Sstevel@tonic-gate goto error;
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate /* Remember color settings for future queries. */
104*7c478bd9Sstevel@tonic-gate cur_term->_color[color][0] = r;
105*7c478bd9Sstevel@tonic-gate cur_term->_color[color][1] = g;
106*7c478bd9Sstevel@tonic-gate cur_term->_color[color][2] = b;
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate code = OK;
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate /* Set the color. */
111*7c478bd9Sstevel@tonic-gate if (initialize_color != (char *) 0) {
112*7c478bd9Sstevel@tonic-gate code = tputs(tparm(initialize_color, (long) color,
113*7c478bd9Sstevel@tonic-gate (long) r, (long) g, (long) b, 0L, 0L, 0L, 0L, 0L),
114*7c478bd9Sstevel@tonic-gate 1, __m_outc);
115*7c478bd9Sstevel@tonic-gate }
116*7c478bd9Sstevel@tonic-gate error:
117*7c478bd9Sstevel@tonic-gate return (code);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate int
init_pair(short pair,short f,short b)121*7c478bd9Sstevel@tonic-gate init_pair(short pair, short f, short b)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate int code = ERR;
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate if (pair < 0 || max_pairs <= pair ||
126*7c478bd9Sstevel@tonic-gate f < 0 || max_colors <= f ||
127*7c478bd9Sstevel@tonic-gate b < 0 || max_colors <= b)
128*7c478bd9Sstevel@tonic-gate goto error;
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate /* Remember color-pair settings for future queries. */
131*7c478bd9Sstevel@tonic-gate cur_term->_pair[pair][0] = f;
132*7c478bd9Sstevel@tonic-gate cur_term->_pair[pair][1] = b;
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate code = OK;
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate /* Set color-pair (foreground-background). */
137*7c478bd9Sstevel@tonic-gate if (initialize_pair != (char *) 0) {
138*7c478bd9Sstevel@tonic-gate code = tputs(tparm(initialize_pair,
139*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[f][0],
140*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[f][1],
141*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[f][2],
142*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[b][0],
143*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[b][1],
144*7c478bd9Sstevel@tonic-gate (long) cur_term->_color[b][2],
145*7c478bd9Sstevel@tonic-gate 0L, 0L, 0L), 1, __m_outc);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate error:
148*7c478bd9Sstevel@tonic-gate return (code);
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate int
color_content(short color,short * r,short * g,short * b)152*7c478bd9Sstevel@tonic-gate color_content(short color, short *r, short *g, short *b)
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate if (color < 0 || max_colors <= color)
155*7c478bd9Sstevel@tonic-gate return (ERR);
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate * There does not appear to be a terminfo entry to query the
159*7c478bd9Sstevel@tonic-gate * color settings, so we retain them in an array for quick
160*7c478bd9Sstevel@tonic-gate * access.
161*7c478bd9Sstevel@tonic-gate */
162*7c478bd9Sstevel@tonic-gate *r = cur_term->_color[color][0];
163*7c478bd9Sstevel@tonic-gate *g = cur_term->_color[color][1];
164*7c478bd9Sstevel@tonic-gate *b = cur_term->_color[color][2];
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate return (OK);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate int
pair_content(short pair,short * f,short * b)170*7c478bd9Sstevel@tonic-gate pair_content(short pair, short *f, short *b)
171*7c478bd9Sstevel@tonic-gate {
172*7c478bd9Sstevel@tonic-gate if (pair < 0 || max_pairs <= pair)
173*7c478bd9Sstevel@tonic-gate return (ERR);
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate /*
176*7c478bd9Sstevel@tonic-gate * There does not appear to be a terminfo entry to query the
177*7c478bd9Sstevel@tonic-gate * color-pair settings, so we retain them in an array for quick
178*7c478bd9Sstevel@tonic-gate * access.
179*7c478bd9Sstevel@tonic-gate */
180*7c478bd9Sstevel@tonic-gate *f = cur_term->_pair[pair][0];
181*7c478bd9Sstevel@tonic-gate *b = cur_term->_pair[pair][1];
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate return (OK);
184*7c478bd9Sstevel@tonic-gate }
185