8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libcurses / screen / init_pair.c
blob3c5e28e40af43d73bcebac86db6e8898d48efa1b
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 1997 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 "curses_inc.h"
47 int
48 init_pair(short pair, short f, short b)
50 _Color_pair *ptp; /* pairs table pointer */
52 /* check the validity of arguments */
54 if (pair < 1 || pair >= COLOR_PAIRS ||
55 f < 0 || b < 0 || f >= COLORS || b >= COLORS)
56 return (ERR);
58 ptp = cur_term->_pairs_tbl + pair;
60 /* update the pairs table (if no changes just return) */
62 if (ptp->foreground == f && ptp->background == b)
63 return (OK);
65 ptp->foreground = f;
66 ptp->background = b;
68 /* if we are on terminal that cannot define color pairs (Tek) */
69 /* and "pair" was previously defined, go through the curscr */
70 /* and erase information from the color field at all positions */
71 /* that use that color pair (this way when refresh will be */
72 /* called next time, it will be forced to change the color at */
73 /* these positions */
75 if (!initialize_pair) {
76 if (ptp->init) {
77 short i, j;
78 short lin = curscr->_maxy;
79 chtype **y = curscr->_y;
80 bool change;
81 short top = -1;
82 short bottom = -1;
83 chtype new_pair = COLOR_PAIR(pair);
85 /* must use lin=curscr->_maxy rather then LINES, because */
86 /* LINES could have been decremented by ripoffline() */
88 for (i = 0; i < lin; i++) {
89 change = FALSE;
90 for (j = 0; j < COLS; j++) {
91 if ((y[i][j] & A_COLOR) == new_pair) {
92 y[i][j] &= ~A_COLOR;
93 change = TRUE;
95 if (change) {
96 (void) wtouchln(_virtscr,
97 i, 1, -1);
98 if (top == -1)
99 top = i;
100 bottom = i;
101 curscr->_attrs &= ~A_COLOR;
104 if (top != -1) {
105 _VIRTTOP = top;
106 _VIRTBOT = bottom;
113 /* on terminals that can initialize color pairs (HP) */
114 /* send an escape to initialize the new pair */
116 else
117 _init_HP_pair(pair, f, b);
119 /* if that pair has not been previously initialized, it could not */
120 /* have been used on the screen, so we don't have to do refresh */
122 if (ptp->init)
123 (void) wrefresh(_virtscr);
124 else
125 ptp->init = TRUE;
127 return (OK);
132 void
133 _init_HP_pair(short pair, short f, short b)
135 _Color *ctp = cur_term->_color_tbl; /* color table pointer */
137 if (initialize_pair)
138 (void) tputs(tparm_p7(initialize_pair, (long) pair,
139 (long) ctp[f].r, (long) ctp[f].g, (long) ctp[f].b,
140 (long) ctp[b].r, (long) ctp[b].g, (long) ctp[b].b),
141 1, _outch);