1 /****************************************************************************
2 * Copyright (c) 2013,2014 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey 2013-on *
31 ****************************************************************************/
34 ** Support for obsolete/unusual features.
37 #include <curses.priv.h>
39 MODULE_ID("$Id: obsolete.c,v 1.3 2014/10/11 02:39:35 tom Exp $")
42 * Obsolete entrypoint retained for binary compatbility.
45 NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_DCLx FILE *ofp, int buffered)
56 _nc_set_buffer(FILE *ofp, int buffered)
58 NCURSES_SP_NAME(_nc_set_buffer) (CURRENT_SCREEN, ofp, buffered);
63 NCURSES_EXPORT(char *)
64 _nc_strdup(const char *s)
68 size_t need = strlen(s);
69 result = malloc(need + 1);
79 #define DST ((char *)s1)
80 #define SRC ((const char *)s2)
81 NCURSES_EXPORT(void *)
82 _nc_memmove(void *s1, const void *s2, size_t n)
85 if ((DST + n > SRC) && (SRC + n > DST)) {
91 bfr = typeRealloc(char, length, bfr);
93 for (j = 0; j < n; j++)
102 #endif /* USE_MY_MEMMOVE */
104 #ifdef EXP_XTERM_1005
106 _nc_conv_to_utf8(unsigned char *target, unsigned source, unsigned limit)
108 #define CH(n) UChar((source) >> ((n) * 8))
111 if (source <= 0x0000007f)
113 else if (source <= 0x000007ff)
115 else if (source <= 0x0000ffff)
117 else if (source <= 0x001fffff)
119 else if (source <= 0x03ffffff)
121 else /* (source <= 0x7fffffff) */
124 if ((unsigned) rc > limit) { /* whatever it is, we cannot decode it */
135 target[1] = UChar(0x80 | (CH(0) & 0x3f));
136 target[0] = UChar(0xc0 | (CH(0) >> 6) | ((CH(1) & 0x07) << 2));
140 target[2] = UChar(0x80 | (CH(0) & 0x3f));
141 target[1] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
142 target[0] = UChar(0xe0 | ((int) (CH(1) & 0xf0) >> 4));
146 target[3] = UChar(0x80 | (CH(0) & 0x3f));
147 target[2] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
148 target[1] = UChar(0x80 |
149 ((int) (CH(1) & 0xf0) >> 4) |
150 ((int) (CH(2) & 0x03) << 4));
151 target[0] = UChar(0xf0 | ((int) (CH(2) & 0x1f) >> 2));
155 target[4] = UChar(0x80 | (CH(0) & 0x3f));
156 target[3] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
157 target[2] = UChar(0x80 |
158 ((int) (CH(1) & 0xf0) >> 4) |
159 ((int) (CH(2) & 0x03) << 4));
160 target[1] = UChar(0x80 | (CH(2) >> 2));
161 target[0] = UChar(0xf8 | (CH(3) & 0x03));
165 target[5] = UChar(0x80 | (CH(0) & 0x3f));
166 target[4] = UChar(0x80 | (CH(0) >> 6) | ((CH(1) & 0x0f) << 2));
167 target[3] = UChar(0x80 | (CH(1) >> 4) | ((CH(2) & 0x03) << 4));
168 target[2] = UChar(0x80 | (CH(2) >> 2));
169 target[1] = UChar(0x80 | (CH(3) & 0x3f));
170 target[0] = UChar(0xfc | ((int) (CH(3) & 0x40) >> 6));
175 return rc; /* number of bytes needed in target */
180 _nc_conv_to_utf32(unsigned *target, const char *source, unsigned limit)
182 #define CH(n) UChar((*target) >> ((n) * 8))
188 * Find the number of bytes we will need from the source.
190 if ((*source & 0x80) == 0) {
192 mask = (unsigned) *source;
193 } else if ((*source & 0xe0) == 0xc0) {
195 mask = (unsigned) (*source & 0x1f);
196 } else if ((*source & 0xf0) == 0xe0) {
198 mask = (unsigned) (*source & 0x0f);
199 } else if ((*source & 0xf8) == 0xf0) {
201 mask = (unsigned) (*source & 0x07);
202 } else if ((*source & 0xfc) == 0xf8) {
204 mask = (unsigned) (*source & 0x03);
205 } else if ((*source & 0xfe) == 0xfc) {
207 mask = (unsigned) (*source & 0x01);
210 if ((unsigned) rc > limit) { /* whatever it is, we cannot decode it */
218 for (j = 1; j < rc; j++) {
219 if ((source[j] & 0xc0) != 0x80)
230 for (j = 1; j < rc; j++) {
231 *target |= (unsigned) (source[rc - j] & 0x3f) << shift;
234 *target |= mask << shift;
239 #endif /* EXP_XTERM_1005 */