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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include <sys/types.h>
46 #include "curses_inc.h"
50 #include <sys/console.h>
63 /* if not a color terminal, return error */
65 if ((COLOR_PAIRS
= max_pairs
) == -1)
68 /* we have only 6 bits to store color-pair info */
74 ioctl(cur_term
->Filedes
, CONIOGETDATA
, &con
);
79 /* allocate pairs_tbl */
81 if ((cur_term
->_pairs_tbl
=
82 (_Color_pair
*) malloc((COLOR_PAIRS
+1) *
83 sizeof (_Color_pair
))) == NULL
)
88 /* the following is not required because we assume that color 0 is */
89 /* always a default background. if this will change, we may want */
90 /* to store the default colors in entry 0 of pairs_tbl. */
92 * cur_term->_pairs_tbl[0].foreground = 0;
93 * cur_term->_pairs_tbl[0].background = COLORS;
96 /* if terminal can change the definition of the color */
97 /* allocate color_tbl */
100 if ((color_tbl
= (cur_term
->_color_tbl
=
101 (_Color
*) malloc(COLORS
* sizeof (_Color
)))) == NULL
)
104 /* allocate color mark map for cookie terminals */
106 if (ceol_standout_glitch
|| (magic_cookie_glitch
>= 0)) {
110 if ((marks
= (char **)calloc((unsigned)LINES
,
111 sizeof (char *))) == NULL
)
113 SP
->_color_mks
= marks
;
114 nc
= (COLS
/ BITSPERBYTE
) + (COLS
% BITSPERBYTE
? 1 : 0);
115 if ((*marks
= (char *)calloc((unsigned)nc
* LINES
,
116 sizeof (char))) == NULL
) {
118 err
: free(color_tbl
);
119 cur_term
->_color_tbl
= NULL
;
120 err1
: free(cur_term
->_pairs_tbl
);
121 cur_term
->_pairs_tbl
= NULL
;
125 for (i
= LINES
- 1; i
-- > 0; ++marks
)
126 *(marks
+ 1) = *marks
+ nc
;
130 /* initialize color_tbl with the following colors: black, blue, */
131 /* green, cyan, red, magenta, yellow, black. if table has more */
132 /* than 8 entries, use the same 8 colors for the following 8 */
133 /* positions, and then again, and again .... If table has less */
134 /* then 8 entries, use as many colors as will fit in. */
136 for (i
= 0; i
< COLORS
; i
++) {
140 color_tbl
[i
].b
= 1000;
145 color_tbl
[i
].g
= 1000;
150 color_tbl
[i
].r
= 1000;
156 (void) tputs(orig_colors
, 1, _outch
);
160 (void) tputs(tparm_p0(orig_pair
), 1, _outch
);
162 /* for Tek terminals set the background color to zero */
164 if (set_background
) {
165 (void) tputs(tparm_p1(set_background
, 0), 1, _outch
);
166 cur_term
->_cur_pair
.background
= 0;
167 cur_term
->_cur_pair
.foreground
= -1;