1 /* 2 * CDDL HEADER START 3 * 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 7 * with the License. 8 * 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. 13 * 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] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1988 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #pragma ident "%Z%%M% %I% %E% SMI" 41 42 /*LINTLIBRARY*/ 43 44 #include <sys/types.h> 45 #include <stdlib.h> 46 #include "curses_inc.h" 47 48 #ifdef PC6300PLUS 49 #include <fcntl.h> 50 #include <sys/console.h> 51 #endif 52 53 int 54 start_color(void) 55 { 56 short i, j; 57 _Color *color_tbl; 58 59 #ifdef PC6300PLUS 60 struct console con; 61 #endif 62 63 /* if not a color terminal, return error */ 64 65 if ((COLOR_PAIRS = max_pairs) == -1) 66 return (ERR); 67 68 /* we have only 6 bits to store color-pair info */ 69 70 if (COLOR_PAIRS > 64) 71 COLOR_PAIRS = 64; 72 73 #ifdef PC6300PLUS 74 ioctl(cur_term->Filedes, CONIOGETDATA, &con); 75 if (!con.color) 76 return (ERR); 77 #endif 78 79 /* allocate pairs_tbl */ 80 81 if ((cur_term->_pairs_tbl = 82 (_Color_pair *) malloc((COLOR_PAIRS+1) * 83 sizeof (_Color_pair))) == NULL) 84 goto err2; 85 86 COLORS = max_colors; 87 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. */ 91 /* 92 * cur_term->_pairs_tbl[0].foreground = 0; 93 * cur_term->_pairs_tbl[0].background = COLORS; 94 */ 95 96 /* if terminal can change the definition of the color */ 97 /* allocate color_tbl */ 98 99 if (can_change) 100 if ((color_tbl = (cur_term->_color_tbl = 101 (_Color *) malloc(COLORS * sizeof (_Color)))) == NULL) 102 goto err1; 103 104 /* allocate color mark map for cookie terminals */ 105 106 if (ceol_standout_glitch || (magic_cookie_glitch >= 0)) { 107 int i, nc; 108 char **marks; 109 110 if ((marks = (char **) calloc((unsigned) LINES, 111 sizeof (char *))) == NULL) 112 goto err; 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) { 117 free(marks); 118 err: free(color_tbl); 119 err1: free(cur_term->_pairs_tbl); 120 err2: return (ERR); 121 } 122 123 for (i = LINES - 1; i-- > 0; ++marks) 124 *(marks + 1) = *marks + nc; 125 } 126 127 if (can_change) { 128 /* initialize color_tbl with the following colors: black, blue, */ 129 /* green, cyan, red, magenta, yellow, black. if table has more */ 130 /* than 8 entries, use the same 8 colors for the following 8 */ 131 /* positions, and then again, and again .... If table has less */ 132 /* then 8 entries, use as many colors as will fit in. */ 133 134 for (i = 0; i < COLORS; i++) { 135 j = i%8; 136 137 if (j%2) 138 color_tbl[i].b = 1000; 139 else 140 color_tbl[i].b = 0; 141 142 if ((j%4) > 1) 143 color_tbl[i].g = 1000; 144 else 145 color_tbl[i].g = 0; 146 147 if (j > 3) 148 color_tbl[i].r = 1000; 149 else 150 color_tbl[i].r = 0; 151 } 152 153 if (orig_colors) 154 (void) tputs(orig_colors, 1, _outch); 155 } 156 157 if (orig_pair) 158 (void) tputs(tparm_p0(orig_pair), 1, _outch); 159 160 /* for Tek terminals set the background color to zero */ 161 162 if (set_background) { 163 (void) tputs(tparm_p1(set_background, 0), 1, _outch); 164 cur_term->_cur_pair.background = 0; 165 cur_term->_cur_pair.foreground = -1; 166 } 167 return (OK); 168 } 169