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