xref: /titanic_44/usr/src/lib/libxcurses2/src/libc/xcurses/termattr.c (revision 4a6ec905b96eb96a398c346f59e034a90ce8ad37)
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 (c) 1995-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /* LINTLIBRARY */
30 
31 /*
32  * termattr.c
33  *
34  * XCurses Library
35  *
36  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
37  *
38  */
39 
40 #if M_RCSID
41 #ifndef lint
42 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/termattr.c 1.1 "
43 "1995/07/10 16:09:34 ant Exp $";
44 #endif
45 #endif
46 
47 #include <private.h>
48 #include <ctype.h>
49 
50 chtype
51 termattrs(void)
52 {
53 	chtype	ch;
54 	cchar_t	cc;
55 
56 	cc = __m_screen->_newscr->_bg;
57 	cc._at = term_attrs();
58 	ch = __m_cc_chtype(&cc) & A_ATTRIBUTES & ~A_COLOR;
59 
60 	return (ch);
61 }
62 
63 attr_t
64 term_attrs(void)
65 {
66 	char	*p;
67 	attr_t	at = 0;
68 
69 	if (set_attributes) {
70 		for (p = set_attributes; *p != '\0'; ++p) {
71 			if (p[0] != '%' || p[1] != 'p' || !isdigit(p[2]))
72 				continue;
73 
74 			p += 2;
75 			switch (*p) {
76 			case 1:
77 				at |= WA_STANDOUT;
78 				break;
79 			case 2:
80 				at |= WA_UNDERLINE;
81 				break;
82 			case 3:
83 				at |= WA_REVERSE;
84 				break;
85 			case 4:
86 				at |= WA_BLINK;
87 				break;
88 			case 5:
89 				at |= WA_DIM;
90 				break;
91 			case 6:
92 				at |= WA_BOLD;
93 				break;
94 			case 7:
95 				at |= WA_INVIS;
96 				break;
97 			case 8:
98 				at |= WA_PROTECT;
99 				break;
100 			case 9:
101 				at |= WA_ALTCHARSET;
102 				break;
103 			}
104 		}
105 	}
106 
107 	if (set_a_attributes) {
108 		for (p = set_a_attributes; *p != '\0'; ++p) {
109 			if (p[0] != '%' || p[1] != 'p' || !isdigit(p[2]))
110 				continue;
111 
112 			p += 2;
113 			switch (*p) {
114 			case 1:
115 				at |= WA_HORIZONTAL;
116 				break;
117 			case 2:
118 				at |= WA_LEFT;
119 				break;
120 			case 3:
121 				at |= WA_LOW;
122 				break;
123 			case 4:
124 				at |= WA_RIGHT;
125 				break;
126 			case 5:
127 				at |= WA_TOP;
128 				break;
129 			case 6:
130 				at |= WA_VERTICAL;
131 				break;
132 			}
133 		}
134 	}
135 
136 	if (enter_alt_charset_mode != NULL)
137 		at |= WA_ALTCHARSET;
138 
139 	if (enter_blink_mode != NULL)
140 		at |= WA_BLINK;
141 
142 	if (enter_bold_mode != NULL)
143 		at |= WA_BOLD;
144 
145 	if (enter_secure_mode != NULL)
146 		at |= WA_INVIS;
147 
148 	if (enter_dim_mode != NULL)
149 		at |= WA_DIM;
150 
151 	if (enter_protected_mode != NULL)
152 		at |= WA_PROTECT;
153 
154 	if (enter_reverse_mode != NULL)
155 		at |= WA_REVERSE;
156 
157 	if (enter_standout_mode != NULL)
158 		at |= WA_STANDOUT;
159 
160 	if (enter_underline_mode != NULL)
161 		at |= WA_UNDERLINE;
162 
163 	if (enter_horizontal_hl_mode != NULL)
164 		at |= WA_HORIZONTAL;
165 
166 	if (enter_left_hl_mode != NULL)
167 		at |= WA_LEFT;
168 
169 	if (enter_low_hl_mode != NULL)
170 		at |= WA_LOW;
171 
172 	if (enter_right_hl_mode != NULL)
173 		at |= WA_RIGHT;
174 
175 	if (enter_top_hl_mode != NULL)
176 		at |= WA_TOP;
177 
178 	if (enter_vertical_hl_mode != NULL)
179 		at |= WA_VERTICAL;
180 
181 	return (at);
182 }
183