8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libcurses / screen / start_col.c
blob7a18ef6c947cd14f0ca9bfe585b600092d5570ec
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
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
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 /*LINTLIBRARY*/
44 #include <sys/types.h>
45 #include <stdlib.h>
46 #include "curses_inc.h"
48 #ifdef PC6300PLUS
49 #include <fcntl.h>
50 #include <sys/console.h>
51 #endif
53 int
54 start_color(void)
56 short i, j;
57 _Color *color_tbl;
59 #ifdef PC6300PLUS
60 struct console con;
61 #endif
63 /* if not a color terminal, return error */
65 if ((COLOR_PAIRS = max_pairs) == -1)
66 return (ERR);
68 /* we have only 6 bits to store color-pair info */
70 if (COLOR_PAIRS > 64)
71 COLOR_PAIRS = 64;
73 #ifdef PC6300PLUS
74 ioctl(cur_term->Filedes, CONIOGETDATA, &con);
75 if (!con.color)
76 return (ERR);
77 #endif
79 /* allocate pairs_tbl */
81 if ((cur_term->_pairs_tbl =
82 (_Color_pair *) malloc((COLOR_PAIRS+1) *
83 sizeof (_Color_pair))) == NULL)
84 goto err2;
86 COLORS = max_colors;
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 */
99 if (can_change)
100 if ((color_tbl = (cur_term->_color_tbl =
101 (_Color *) malloc(COLORS * sizeof (_Color)))) == NULL)
102 goto err1;
104 /* allocate color mark map for cookie terminals */
106 if (ceol_standout_glitch || (magic_cookie_glitch >= 0)) {
107 int i, nc;
108 char **marks;
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 cur_term->_color_tbl = NULL;
120 err1: free(cur_term->_pairs_tbl);
121 cur_term->_pairs_tbl = NULL;
122 err2: return (ERR);
125 for (i = LINES - 1; i-- > 0; ++marks)
126 *(marks + 1) = *marks + nc;
129 if (can_change) {
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++) {
137 j = i%8;
139 if (j%2)
140 color_tbl[i].b = 1000;
141 else
142 color_tbl[i].b = 0;
144 if ((j%4) > 1)
145 color_tbl[i].g = 1000;
146 else
147 color_tbl[i].g = 0;
149 if (j > 3)
150 color_tbl[i].r = 1000;
151 else
152 color_tbl[i].r = 0;
155 if (orig_colors)
156 (void) tputs(orig_colors, 1, _outch);
159 if (orig_pair)
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;
169 return (OK);