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