1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 2013-2014,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey 2013-on *
32 ****************************************************************************/
35 ** Support for obsolete/unusual features.
38 #include <curses.priv.h>
40 MODULE_ID("$Id: obsolete.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
43 * Obsolete entrypoint retained for binary compatibility.
46 NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_DCLx FILE *ofp, int buffered)
57 _nc_set_buffer(FILE *ofp, int buffered)
59 NCURSES_SP_NAME(_nc_set_buffer) (CURRENT_SCREEN, ofp, buffered);
64 NCURSES_EXPORT(char *)
65 _nc_strdup(const char *s)
69 size_t need = strlen(s);
70 result = malloc(need + 1);
72 _nc_STRCPY(result, s, need);
80 #define DST ((char *)s1)
81 #define SRC ((const char *)s2)
82 NCURSES_EXPORT(void *)
83 _nc_memmove(void *s1, const void *s2, size_t n)
86 if ((DST + n > SRC) && (SRC + n > DST)) {
92 bfr = typeRealloc(char, length, bfr);
94 for (j = 0; j < n; j++)
103 #endif /* USE_MY_MEMMOVE */
105 #ifdef EXP_XTERM_1005
107 _nc_conv_to_utf8(unsigned char *target, unsigned source, unsigned limit)
109 #define CH(n) UChar((source) >> ((n) * 8))
112 if (source <= 0x0000007f)
114 else if (source <= 0x000007ff)
116 else if (source <= 0x0000ffff)
118 else if (source <= 0x001fffff)
120 else if (source <= 0x03ffffff)
122 else /* (source <= 0x7fffffff) */
125 if ((unsigned) rc > limit) { /* whatever it is, we cannot decode it */
136 target[1] = UChar(0x80 | (CH(0) & 0x3f));
137 target[0] = UChar(0xc0 | (CH(0) >> 6) | ((CH(1) & 0x07) << 2));
141 target[2] = UChar(0x80 | (CH(0) & 0x3f));
142 target[1] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
143 target[0] = UChar(0xe0 | ((int) (CH(1) & 0xf0) >> 4));
147 target[3] = UChar(0x80 | (CH(0) & 0x3f));
148 target[2] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
149 target[1] = UChar(0x80 |
150 ((int) (CH(1) & 0xf0) >> 4) |
151 ((int) (CH(2) & 0x03) << 4));
152 target[0] = UChar(0xf0 | ((int) (CH(2) & 0x1f) >> 2));
156 target[4] = UChar(0x80 | (CH(0) & 0x3f));
157 target[3] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
158 target[2] = UChar(0x80 |
159 ((int) (CH(1) & 0xf0) >> 4) |
160 ((int) (CH(2) & 0x03) << 4));
161 target[1] = UChar(0x80 | (CH(2) >> 2));
162 target[0] = UChar(0xf8 | (CH(3) & 0x03));
166 target[5] = UChar(0x80 | (CH(0) & 0x3f));
167 target[4] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
168 target[3] = UChar(0x80 | (CH(1) >> 4) | ((CH(2) & 0x03) << 4));
169 target[2] = UChar(0x80 | (CH(2) >> 2));
170 target[1] = UChar(0x80 | (CH(3) & 0x3f));
171 target[0] = UChar(0xfc | ((int) (CH(3) & 0x40) >> 6));
176 return rc; /* number of bytes needed in target */
181 _nc_conv_to_utf32(unsigned *target, const char *source, unsigned limit)
183 #define CH(n) UChar((*target) >> ((n) * 8))
189 * Find the number of bytes we will need from the source.
191 if ((*source & 0x80) == 0) {
193 mask = (unsigned) *source;
194 } else if ((*source & 0xe0) == 0xc0) {
196 mask = (unsigned) (*source & 0x1f);
197 } else if ((*source & 0xf0) == 0xe0) {
199 mask = (unsigned) (*source & 0x0f);
200 } else if ((*source & 0xf8) == 0xf0) {
202 mask = (unsigned) (*source & 0x07);
203 } else if ((*source & 0xfc) == 0xf8) {
205 mask = (unsigned) (*source & 0x03);
206 } else if ((*source & 0xfe) == 0xfc) {
208 mask = (unsigned) (*source & 0x01);
211 if ((unsigned) rc > limit) { /* whatever it is, we cannot decode it */
219 for (j = 1; j < rc; j++) {
220 if ((source[j] & 0xc0) != 0x80)
231 for (j = 1; j < rc; j++) {
232 *target |= (unsigned) (source[rc - j] & 0x3f) << shift;
235 *target |= mask << shift;
240 #endif /* EXP_XTERM_1005 */