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 * wacs.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[] = 41 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/" 42 "libxcurses/src/libc/xcurses/rcs/wacs.c 1.6 1998/05/04 21:16:22 " 43 "cbates Exp $"; 44 #endif 45 #endif 46 47 #include <private.h> 48 #include <limits.h> 49 50 /* 51 * Mapping defined in Xcurses Section 6.2.12 (p260). 52 */ 53 const cchar_t __WACS_VLINE = 54 { 1, 1, 0, WA_ALTCHARSET, L"x" }; 55 const cchar_t __WACS_HLINE = 56 { 1, 1, 0, WA_ALTCHARSET, L"q" }; 57 const cchar_t __WACS_ULCORNER = 58 { 1, 1, 0, WA_ALTCHARSET, L"l" }; 59 const cchar_t __WACS_URCORNER = 60 { 1, 1, 0, WA_ALTCHARSET, L"k" }; 61 const cchar_t __WACS_LLCORNER = 62 { 1, 1, 0, WA_ALTCHARSET, L"m" }; 63 const cchar_t __WACS_LRCORNER = 64 { 1, 1, 0, WA_ALTCHARSET, L"j" }; 65 const cchar_t __WACS_RTEE = 66 { 1, 1, 0, WA_ALTCHARSET, L"u" }; 67 const cchar_t __WACS_LTEE = 68 { 1, 1, 0, WA_ALTCHARSET, L"t" }; 69 const cchar_t __WACS_BTEE = 70 { 1, 1, 0, WA_ALTCHARSET, L"v" }; 71 const cchar_t __WACS_TTEE = 72 { 1, 1, 0, WA_ALTCHARSET, L"w" }; 73 const cchar_t __WACS_PLUS = 74 { 1, 1, 0, WA_ALTCHARSET, L"n" }; 75 const cchar_t __WACS_S1 = 76 { 1, 1, 0, WA_ALTCHARSET, L"o" }; 77 const cchar_t __WACS_S9 = 78 { 1, 1, 0, WA_ALTCHARSET, L"s" }; 79 const cchar_t __WACS_DIAMOND = 80 { 1, 1, 0, WA_ALTCHARSET, L"`" }; 81 const cchar_t __WACS_CKBOARD = 82 { 1, 1, 0, WA_ALTCHARSET, L"a" }; 83 const cchar_t __WACS_DEGREE = 84 { 1, 1, 0, WA_ALTCHARSET, L"f" }; 85 const cchar_t __WACS_PLMINUS = 86 { 1, 1, 0, WA_ALTCHARSET, L"g" }; 87 const cchar_t __WACS_BULLET = 88 { 1, 1, 0, WA_ALTCHARSET, L"~" }; 89 const cchar_t __WACS_LARROW = 90 { 1, 1, 0, WA_ALTCHARSET, L"," }; 91 const cchar_t __WACS_RARROW = 92 { 1, 1, 0, WA_ALTCHARSET, L"+" }; 93 const cchar_t __WACS_DARROW = 94 { 1, 1, 0, WA_ALTCHARSET, L"." }; 95 const cchar_t __WACS_UARROW = 96 { 1, 1, 0, WA_ALTCHARSET, L"-" }; 97 const cchar_t __WACS_BOARD = 98 { 1, 1, 0, WA_ALTCHARSET, L"h" }; 99 const cchar_t __WACS_LANTERN = 100 { 1, 1, 0, WA_ALTCHARSET, L"i" }; 101 const cchar_t __WACS_BLOCK = 102 { 1, 1, 0, WA_ALTCHARSET, L"0" }; 103 104 /* The default characters are from the _primary_ character set. */ 105 static const unsigned char acs_defaults[] = 106 "x|q-l+k+m+j+u+t+v+w+n+o-s_`+a:f\'g#~o,<+>.v-^h#i#0#"; 107 108 int 109 __m_acs_cc(chtype acs, cchar_t *cc) 110 { 111 int i; 112 unsigned char *acsc; 113 chtype vacs; 114 115 vacs = acs & A_CHARTEXT; 116 117 /* Is it a single-byte character? */ 118 if (UCHAR_MAX < vacs || 119 __m_chtype_cc(acs, cc) == ERR) 120 return (-1); 121 122 if (!(acs & A_ALTCHARSET)) 123 return (0); 124 125 /* Pick the acs mapping string to use. */ 126 if (acs_chars == NULL) { 127 /* Use primary character set. */ 128 acsc = (unsigned char *) acs_defaults; 129 acs &= ~A_ALTCHARSET; 130 } else { 131 acsc = (unsigned char *) acs_chars; 132 } 133 134 /* Assume that acsc is even in length. */ 135 for (i = 0; acsc[i] != '\0'; i += 2) { 136 if (acsc[i] == vacs) { 137 (void) __m_chtype_cc((chtype) 138 ((acs & A_ATTRIBUTES) | acsc[i+1]), cc); 139 break; 140 } 141 } 142 143 return (0); 144 } 145 146 /* Returns 1 if ALTCHARSET is to be cleared (override). 0 Otherwise. */ 147 int 148 __m_wacs_cc(const cchar_t *acs, cchar_t *cc) 149 { 150 int i; 151 unsigned char *acsc, mb[MB_LEN_MAX]; 152 int clearit = 0; 153 154 *cc = *acs; 155 cc->_f = 1; 156 157 /* Is it a single-byte character? */ 158 if (!(acs->_at & WA_ALTCHARSET) || 159 acs->_n != 1 || wctomb((char *) mb, acs->_wc[0]) != 1) 160 /* No, just return the original character. */ 161 return (0); 162 163 /* Pick the acs mapping string to use. */ 164 if (acs_chars == NULL) { 165 /* Use primary character set. */ 166 acsc = (unsigned char *) acs_defaults; 167 clearit = 1; 168 } else { 169 acsc = (unsigned char *) acs_chars; 170 } 171 172 /* Assume that acsc is even in length. */ 173 for (i = 0; acsc[i] != '\0'; i += 2) { 174 if (acsc[i] == *mb) { 175 (void) mbtowc(cc->_wc, (char *) &acsc[i+1], 1); 176 break; 177 } 178 } 179 180 return (clearit); 181 } 182