2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <stdlib.h>
2N/A#include "curses_inc.h"
2N/A
2N/A#ifdef PC6300PLUS
2N/A#include <fcntl.h>
2N/A#include <sys/console.h>
2N/A#endif
2N/A
2N/Aint
2N/Astart_color(void)
2N/A{
2N/A short i, j;
2N/A _Color *color_tbl;
2N/A
2N/A#ifdef PC6300PLUS
2N/A struct console con;
2N/A#endif
2N/A
2N/A /* if not a color terminal, return error */
2N/A
2N/A if ((COLOR_PAIRS = max_pairs) == -1)
2N/A return (ERR);
2N/A
2N/A /* we have only 6 bits to store color-pair info */
2N/A
2N/A if (COLOR_PAIRS > 64)
2N/A COLOR_PAIRS = 64;
2N/A
2N/A#ifdef PC6300PLUS
2N/A ioctl(cur_term->Filedes, CONIOGETDATA, &con);
2N/A if (!con.color)
2N/A return (ERR);
2N/A#endif
2N/A
2N/A /* allocate pairs_tbl */
2N/A
2N/A if ((cur_term->_pairs_tbl =
2N/A (_Color_pair *) malloc((COLOR_PAIRS+1) *
2N/A sizeof (_Color_pair))) == NULL)
2N/A goto err2;
2N/A
2N/A COLORS = max_colors;
2N/A
2N/A/* the following is not required because we assume that color 0 is */
2N/A/* always a default background. if this will change, we may want */
2N/A/* to store the default colors in entry 0 of pairs_tbl. */
2N/A/*
2N/A * cur_term->_pairs_tbl[0].foreground = 0;
2N/A * cur_term->_pairs_tbl[0].background = COLORS;
2N/A */
2N/A
2N/A /* if terminal can change the definition of the color */
2N/A /* allocate color_tbl */
2N/A
2N/A if (can_change)
2N/A if ((color_tbl = (cur_term->_color_tbl =
2N/A (_Color *) malloc(COLORS * sizeof (_Color)))) == NULL)
2N/A goto err1;
2N/A
2N/A /* allocate color mark map for cookie terminals */
2N/A
2N/A if (ceol_standout_glitch || (magic_cookie_glitch >= 0)) {
2N/A int i, nc;
2N/A char **marks;
2N/A
2N/A if ((marks = (char **)calloc((unsigned)LINES,
2N/A sizeof (char *))) == NULL)
2N/A goto err;
2N/A SP->_color_mks = marks;
2N/A nc = (COLS / BITSPERBYTE) + (COLS % BITSPERBYTE ? 1 : 0);
2N/A if ((*marks = (char *)calloc((unsigned)nc * LINES,
2N/A sizeof (char))) == NULL) {
2N/A free(marks);
2N/Aerr: free(color_tbl);
2N/A cur_term->_color_tbl = NULL;
2N/Aerr1: free(cur_term->_pairs_tbl);
2N/A cur_term->_pairs_tbl = NULL;
2N/Aerr2: return (ERR);
2N/A }
2N/A
2N/A for (i = LINES - 1; i-- > 0; ++marks)
2N/A *(marks + 1) = *marks + nc;
2N/A }
2N/A
2N/A if (can_change) {
2N/A /* initialize color_tbl with the following colors: black, blue, */
2N/A /* green, cyan, red, magenta, yellow, black. if table has more */
2N/A /* than 8 entries, use the same 8 colors for the following 8 */
2N/A /* positions, and then again, and again .... If table has less */
2N/A /* then 8 entries, use as many colors as will fit in. */
2N/A
2N/A for (i = 0; i < COLORS; i++) {
2N/A j = i%8;
2N/A
2N/A if (j%2)
2N/A color_tbl[i].b = 1000;
2N/A else
2N/A color_tbl[i].b = 0;
2N/A
2N/A if ((j%4) > 1)
2N/A color_tbl[i].g = 1000;
2N/A else
2N/A color_tbl[i].g = 0;
2N/A
2N/A if (j > 3)
2N/A color_tbl[i].r = 1000;
2N/A else
2N/A color_tbl[i].r = 0;
2N/A }
2N/A
2N/A if (orig_colors)
2N/A (void) tputs(orig_colors, 1, _outch);
2N/A }
2N/A
2N/A if (orig_pair)
2N/A (void) tputs(tparm_p0(orig_pair), 1, _outch);
2N/A
2N/A /* for Tek terminals set the background color to zero */
2N/A
2N/A if (set_background) {
2N/A (void) tputs(tparm_p1(set_background, 0), 1, _outch);
2N/A cur_term->_cur_pair.background = 0;
2N/A cur_term->_cur_pair.foreground = -1;
2N/A }
2N/A return (OK);
2N/A}