10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*375Smuffin * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate * The Regents of the University of California
330Sstevel@tonic-gate * All Rights Reserved
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate * contributors.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*LINTLIBRARY*/
430Sstevel@tonic-gate
440Sstevel@tonic-gate #include <sys/types.h>
450Sstevel@tonic-gate #include <stdlib.h>
460Sstevel@tonic-gate #include "curses_inc.h"
470Sstevel@tonic-gate
480Sstevel@tonic-gate #ifdef PC6300PLUS
490Sstevel@tonic-gate #include <fcntl.h>
500Sstevel@tonic-gate #include <sys/console.h>
510Sstevel@tonic-gate #endif
520Sstevel@tonic-gate
530Sstevel@tonic-gate int
start_color(void)540Sstevel@tonic-gate start_color(void)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate short i, j;
570Sstevel@tonic-gate _Color *color_tbl;
580Sstevel@tonic-gate
590Sstevel@tonic-gate #ifdef PC6300PLUS
600Sstevel@tonic-gate struct console con;
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate
630Sstevel@tonic-gate /* if not a color terminal, return error */
640Sstevel@tonic-gate
650Sstevel@tonic-gate if ((COLOR_PAIRS = max_pairs) == -1)
660Sstevel@tonic-gate return (ERR);
670Sstevel@tonic-gate
680Sstevel@tonic-gate /* we have only 6 bits to store color-pair info */
690Sstevel@tonic-gate
700Sstevel@tonic-gate if (COLOR_PAIRS > 64)
710Sstevel@tonic-gate COLOR_PAIRS = 64;
720Sstevel@tonic-gate
730Sstevel@tonic-gate #ifdef PC6300PLUS
740Sstevel@tonic-gate ioctl(cur_term->Filedes, CONIOGETDATA, &con);
750Sstevel@tonic-gate if (!con.color)
760Sstevel@tonic-gate return (ERR);
770Sstevel@tonic-gate #endif
780Sstevel@tonic-gate
790Sstevel@tonic-gate /* allocate pairs_tbl */
800Sstevel@tonic-gate
810Sstevel@tonic-gate if ((cur_term->_pairs_tbl =
820Sstevel@tonic-gate (_Color_pair *) malloc((COLOR_PAIRS+1) *
830Sstevel@tonic-gate sizeof (_Color_pair))) == NULL)
840Sstevel@tonic-gate goto err2;
850Sstevel@tonic-gate
860Sstevel@tonic-gate COLORS = max_colors;
870Sstevel@tonic-gate
880Sstevel@tonic-gate /* the following is not required because we assume that color 0 is */
890Sstevel@tonic-gate /* always a default background. if this will change, we may want */
900Sstevel@tonic-gate /* to store the default colors in entry 0 of pairs_tbl. */
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate * cur_term->_pairs_tbl[0].foreground = 0;
930Sstevel@tonic-gate * cur_term->_pairs_tbl[0].background = COLORS;
940Sstevel@tonic-gate */
950Sstevel@tonic-gate
960Sstevel@tonic-gate /* if terminal can change the definition of the color */
970Sstevel@tonic-gate /* allocate color_tbl */
980Sstevel@tonic-gate
990Sstevel@tonic-gate if (can_change)
1000Sstevel@tonic-gate if ((color_tbl = (cur_term->_color_tbl =
1010Sstevel@tonic-gate (_Color *) malloc(COLORS * sizeof (_Color)))) == NULL)
1020Sstevel@tonic-gate goto err1;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /* allocate color mark map for cookie terminals */
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate if (ceol_standout_glitch || (magic_cookie_glitch >= 0)) {
1070Sstevel@tonic-gate int i, nc;
1080Sstevel@tonic-gate char **marks;
1090Sstevel@tonic-gate
110*375Smuffin if ((marks = (char **)calloc((unsigned)LINES,
1110Sstevel@tonic-gate sizeof (char *))) == NULL)
1120Sstevel@tonic-gate goto err;
1130Sstevel@tonic-gate SP->_color_mks = marks;
1140Sstevel@tonic-gate nc = (COLS / BITSPERBYTE) + (COLS % BITSPERBYTE ? 1 : 0);
115*375Smuffin if ((*marks = (char *)calloc((unsigned)nc * LINES,
1160Sstevel@tonic-gate sizeof (char))) == NULL) {
1170Sstevel@tonic-gate free(marks);
1180Sstevel@tonic-gate err: free(color_tbl);
119*375Smuffin cur_term->_color_tbl = NULL;
1200Sstevel@tonic-gate err1: free(cur_term->_pairs_tbl);
121*375Smuffin cur_term->_pairs_tbl = NULL;
1220Sstevel@tonic-gate err2: return (ERR);
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate for (i = LINES - 1; i-- > 0; ++marks)
1260Sstevel@tonic-gate *(marks + 1) = *marks + nc;
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate if (can_change) {
1300Sstevel@tonic-gate /* initialize color_tbl with the following colors: black, blue, */
1310Sstevel@tonic-gate /* green, cyan, red, magenta, yellow, black. if table has more */
1320Sstevel@tonic-gate /* than 8 entries, use the same 8 colors for the following 8 */
1330Sstevel@tonic-gate /* positions, and then again, and again .... If table has less */
1340Sstevel@tonic-gate /* then 8 entries, use as many colors as will fit in. */
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate for (i = 0; i < COLORS; i++) {
1370Sstevel@tonic-gate j = i%8;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if (j%2)
1400Sstevel@tonic-gate color_tbl[i].b = 1000;
1410Sstevel@tonic-gate else
1420Sstevel@tonic-gate color_tbl[i].b = 0;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate if ((j%4) > 1)
1450Sstevel@tonic-gate color_tbl[i].g = 1000;
1460Sstevel@tonic-gate else
1470Sstevel@tonic-gate color_tbl[i].g = 0;
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate if (j > 3)
1500Sstevel@tonic-gate color_tbl[i].r = 1000;
1510Sstevel@tonic-gate else
1520Sstevel@tonic-gate color_tbl[i].r = 0;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate if (orig_colors)
1560Sstevel@tonic-gate (void) tputs(orig_colors, 1, _outch);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate if (orig_pair)
1600Sstevel@tonic-gate (void) tputs(tparm_p0(orig_pair), 1, _outch);
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate /* for Tek terminals set the background color to zero */
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate if (set_background) {
1650Sstevel@tonic-gate (void) tputs(tparm_p1(set_background, 0), 1, _outch);
1660Sstevel@tonic-gate cur_term->_cur_pair.background = 0;
1670Sstevel@tonic-gate cur_term->_cur_pair.foreground = -1;
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate return (OK);
1700Sstevel@tonic-gate }
171