]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/alloc_ttype.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / tinfo / alloc_ttype.c
1 /****************************************************************************
2  * Copyright 2018-2021,2022 Thomas E. Dickey                                *
3  * Copyright 1999-2016,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
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:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
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.                               *
23  *                                                                          *
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       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *  Author: Thomas E. Dickey <dickey@clark.net> 1999-on                     *
32  ****************************************************************************/
33
34 /*
35  * align_ttype.c --  functions for TERMTYPE
36  *
37  *      _nc_align_termtype()
38  *      _nc_copy_termtype()
39  *
40  */
41
42 #include <curses.priv.h>
43
44 #include <tic.h>
45
46 MODULE_ID("$Id: alloc_ttype.c,v 1.40 2022/05/08 00:11:44 tom Exp $")
47
48 #if NCURSES_XNAMES
49 /*
50  * Merge the a/b lists into dst.  Both a/b are sorted (see _nc_extend_names()),
51  * so we do not have to worry about order dependencies.
52  */
53 static int
54 merge_names(char **dst, char **a, int na, char **b, int nb)
55 {
56     int n = 0;
57     while (na > 0 && nb > 0) {
58         int cmp = strcmp(*a, *b);
59         if (cmp < 0) {
60             dst[n++] = *a++;
61             na--;
62         } else if (cmp > 0) {
63             dst[n++] = *b++;
64             nb--;
65         } else {
66             dst[n++] = *a;
67             a++, b++;
68             na--, nb--;
69         }
70     }
71     while (na-- > 0) {
72         dst[n++] = *a++;
73     }
74     while (nb-- > 0) {
75         dst[n++] = *b++;
76     }
77     DEBUG(4, ("merge_names -> %d", n));
78     return n;
79 }
80
81 static bool
82 find_name(char **table, int item, int length, const char *name)
83 {
84     int n;
85     int result = -1;
86
87     for (n = item; n < length; ++n) {
88         if (!strcmp(table[n], name)) {
89             DEBUG(4, ("found name '%s' @%d", name, n));
90             result = n;
91             break;
92         }
93     }
94     if (result < 0) {
95         DEBUG(4, ("did not find name '%s'", name));
96     }
97     return (result >= 0);
98 }
99
100 #define EXTEND_NUM(num, ext) \
101         DEBUG(4, ("extending " #num " from %d to %d", \
102          to->num, (unsigned short) (to->num + (ext - to->ext)))); \
103         to->num = (unsigned short) (to->num + (ext - to->ext))
104
105 static void
106 realign_data(TERMTYPE2 *to, char **ext_Names,
107              int ext_Booleans,
108              int ext_Numbers,
109              int ext_Strings)
110 {
111     int n, m, base;
112     int to_Booleans = to->ext_Booleans;
113     int to_Numbers = to->ext_Numbers;
114     int to_Strings = to->ext_Strings;
115     int to1, to2, from;
116
117     DEBUG(4, ("realign_data %d/%d/%d vs %d/%d/%d",
118               ext_Booleans,
119               ext_Numbers,
120               ext_Strings,
121               to->ext_Booleans,
122               to->ext_Numbers,
123               to->ext_Strings));
124
125     if (to->ext_Booleans != ext_Booleans) {
126         to1 = 0;
127         to2 = to_Booleans + to1;
128         from = 0;
129         EXTEND_NUM(num_Booleans, ext_Booleans);
130         TYPE_REALLOC(NCURSES_SBOOL, to->num_Booleans, to->Booleans);
131         for (n = to->ext_Booleans - 1,
132              m = ext_Booleans - 1,
133              base = to->num_Booleans - (m + 1); m >= 0; m--) {
134             if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
135                 to->Booleans[base + m] = to->Booleans[base + n--];
136             } else {
137                 to->Booleans[base + m] = FALSE;
138             }
139         }
140         to->ext_Booleans = UShort(ext_Booleans);
141     }
142
143     if (to->ext_Numbers != ext_Numbers) {
144         to1 = to_Booleans;
145         to2 = to_Numbers + to1;
146         from = ext_Booleans;
147         EXTEND_NUM(num_Numbers, ext_Numbers);
148         TYPE_REALLOC(NCURSES_INT2, to->num_Numbers, to->Numbers);
149         for (n = to->ext_Numbers - 1,
150              m = ext_Numbers - 1,
151              base = to->num_Numbers - (m + 1); m >= 0; m--) {
152             if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
153                 to->Numbers[base + m] = to->Numbers[base + n--];
154             } else {
155                 to->Numbers[base + m] = ABSENT_NUMERIC;
156             }
157         }
158         to->ext_Numbers = UShort(ext_Numbers);
159     }
160
161     if (to->ext_Strings != ext_Strings) {
162         to1 = to_Booleans + to_Numbers;
163         to2 = to_Strings + to1;
164         from = ext_Booleans + ext_Numbers;
165         EXTEND_NUM(num_Strings, ext_Strings);
166         TYPE_REALLOC(char *, to->num_Strings, to->Strings);
167         for (n = to->ext_Strings - 1,
168              m = ext_Strings - 1,
169              base = to->num_Strings - (m + 1); m >= 0; m--) {
170             if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
171                 to->Strings[base + m] = to->Strings[base + n--];
172             } else {
173                 to->Strings[base + m] = ABSENT_STRING;
174             }
175         }
176         to->ext_Strings = UShort(ext_Strings);
177     }
178 }
179
180 /*
181  * Returns the first index in ext_Names[] for the given token-type
182  */
183 static unsigned
184 _nc_first_ext_name(TERMTYPE2 *tp, int token_type)
185 {
186     unsigned first;
187
188     switch (token_type) {
189     case BOOLEAN:
190         first = 0;
191         break;
192     case NUMBER:
193         first = tp->ext_Booleans;
194         break;
195     case STRING:
196         first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
197         break;
198     default:
199         first = 0;
200         break;
201     }
202     return first;
203 }
204
205 /*
206  * Returns the last index in ext_Names[] for the given token-type
207  */
208 static unsigned
209 _nc_last_ext_name(TERMTYPE2 *tp, int token_type)
210 {
211     unsigned last;
212
213     switch (token_type) {
214     case BOOLEAN:
215         last = tp->ext_Booleans;
216         break;
217     case NUMBER:
218         last = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
219         break;
220     default:
221     case STRING:
222         last = NUM_EXT_NAMES(tp);
223         break;
224     }
225     return last;
226 }
227
228 /*
229  * Lookup an entry from extended-names, returning -1 if not found
230  */
231 static int
232 _nc_find_ext_name(TERMTYPE2 *tp, char *name, int token_type)
233 {
234     unsigned j;
235     unsigned first = _nc_first_ext_name(tp, token_type);
236     unsigned last = _nc_last_ext_name(tp, token_type);
237
238     for (j = first; j < last; j++) {
239         if (!strcmp(name, tp->ext_Names[j])) {
240             return (int) j;
241         }
242     }
243     return -1;
244 }
245
246 /*
247  * Translate an index into ext_Names[] into the corresponding index into data
248  * (e.g., Booleans[]).
249  */
250 static int
251 _nc_ext_data_index(TERMTYPE2 *tp, int n, int token_type)
252 {
253     switch (token_type) {
254     case BOOLEAN:
255         n += (tp->num_Booleans - tp->ext_Booleans);
256         break;
257     case NUMBER:
258         n += (tp->num_Numbers - tp->ext_Numbers)
259             - (tp->ext_Booleans);
260         break;
261     default:
262     case STRING:
263         n += (tp->num_Strings - tp->ext_Strings)
264             - (tp->ext_Booleans + tp->ext_Numbers);
265     }
266     return n;
267 }
268
269 /*
270  * Adjust tables to remove (not free) an extended name and its corresponding
271  * data.
272  */
273 static bool
274 _nc_del_ext_name(TERMTYPE2 *tp, char *name, int token_type)
275 {
276     int first;
277
278     if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) {
279         int j;
280         int last = (int) NUM_EXT_NAMES(tp) - 1;
281
282         for (j = first; j < last; j++) {
283             tp->ext_Names[j] = tp->ext_Names[j + 1];
284         }
285         first = _nc_ext_data_index(tp, first, token_type);
286         switch (token_type) {
287         case BOOLEAN:
288             last = tp->num_Booleans - 1;
289             for (j = first; j < last; j++)
290                 tp->Booleans[j] = tp->Booleans[j + 1];
291             tp->ext_Booleans--;
292             tp->num_Booleans--;
293             break;
294         case NUMBER:
295             last = tp->num_Numbers - 1;
296             for (j = first; j < last; j++)
297                 tp->Numbers[j] = tp->Numbers[j + 1];
298             tp->ext_Numbers--;
299             tp->num_Numbers--;
300             break;
301         case STRING:
302             last = tp->num_Strings - 1;
303             for (j = first; j < last; j++)
304                 tp->Strings[j] = tp->Strings[j + 1];
305             tp->ext_Strings--;
306             tp->num_Strings--;
307             break;
308         }
309         return TRUE;
310     }
311     return FALSE;
312 }
313
314 /*
315  * Adjust tables to insert an extended name, making room for new data.  The
316  * index into the corresponding data array is returned.
317  */
318 static int
319 _nc_ins_ext_name(TERMTYPE2 *tp, char *name, int token_type)
320 {
321     unsigned first = _nc_first_ext_name(tp, token_type);
322     unsigned last = _nc_last_ext_name(tp, token_type);
323     unsigned total = NUM_EXT_NAMES(tp) + 1;
324     unsigned j, k;
325
326     for (j = first; j < last; j++) {
327         int cmp = strcmp(name, tp->ext_Names[j]);
328         if (cmp == 0)
329             /* already present */
330             return _nc_ext_data_index(tp, (int) j, token_type);
331         if (cmp < 0) {
332             break;
333         }
334     }
335
336     TYPE_REALLOC(char *, total, tp->ext_Names);
337     for (k = total - 1; k > j; k--)
338         tp->ext_Names[k] = tp->ext_Names[k - 1];
339     tp->ext_Names[j] = name;
340     j = (unsigned) _nc_ext_data_index(tp, (int) j, token_type);
341
342     switch (token_type) {
343     case BOOLEAN:
344         tp->ext_Booleans++;
345         tp->num_Booleans++;
346         TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
347         for (k = (unsigned) (tp->num_Booleans - 1); k > j; k--)
348             tp->Booleans[k] = tp->Booleans[k - 1];
349         break;
350     case NUMBER:
351         tp->ext_Numbers++;
352         tp->num_Numbers++;
353         TYPE_REALLOC(NCURSES_INT2, tp->num_Numbers, tp->Numbers);
354         for (k = (unsigned) (tp->num_Numbers - 1); k > j; k--)
355             tp->Numbers[k] = tp->Numbers[k - 1];
356         break;
357     case STRING:
358         tp->ext_Strings++;
359         tp->num_Strings++;
360         TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
361         for (k = (unsigned) (tp->num_Strings - 1); k > j; k--)
362             tp->Strings[k] = tp->Strings[k - 1];
363         break;
364     }
365     return (int) j;
366 }
367
368 /*
369  * Look for strings that are marked cancelled, which happen to be the same name
370  * as a boolean or number.  We'll get this as a special case when we get a
371  * cancellation of a name that is inherited from another entry.
372  */
373 static void
374 adjust_cancels(TERMTYPE2 *to, TERMTYPE2 *from)
375 {
376     int first = to->ext_Booleans + to->ext_Numbers;
377     int last = first + to->ext_Strings;
378     int j, k;
379
380     DEBUG(3, (T_CALLED("adjust_cancels(%s), from(%s)"),
381               to ? NonNull(to->term_names) : "?",
382               from ? NonNull(from->term_names) : "?"));
383     for (j = first; j < last;) {
384         char *name = to->ext_Names[j];
385         int j_str = to->num_Strings - first - to->ext_Strings;
386
387         if (to->Strings[j + j_str] == CANCELLED_STRING) {
388             if (_nc_find_ext_name(from, to->ext_Names[j], BOOLEAN) >= 0) {
389                 if (_nc_del_ext_name(to, name, STRING)
390                     || _nc_del_ext_name(to, name, NUMBER)) {
391                     k = _nc_ins_ext_name(to, name, BOOLEAN);
392                     to->Booleans[k] = FALSE;
393                 } else {
394                     j++;
395                 }
396             } else if (_nc_find_ext_name(from, to->ext_Names[j], NUMBER) >= 0) {
397                 if (_nc_del_ext_name(to, name, STRING)
398                     || _nc_del_ext_name(to, name, BOOLEAN)) {
399                     k = _nc_ins_ext_name(to, name, NUMBER);
400                     to->Numbers[k] = CANCELLED_NUMERIC;
401                 } else {
402                     j++;
403                 }
404             } else if (_nc_find_ext_name(from, to->ext_Names[j], STRING) >= 0) {
405                 if (_nc_del_ext_name(to, name, NUMBER)
406                     || _nc_del_ext_name(to, name, BOOLEAN)) {
407                     k = _nc_ins_ext_name(to, name, STRING);
408                     to->Strings[k] = CANCELLED_STRING;
409                 } else {
410                     j++;
411                 }
412             } else {
413                 j++;
414             }
415         } else {
416             j++;
417         }
418     }
419     DEBUG(3, (T_RETURN("")));
420 }
421
422 NCURSES_EXPORT(void)
423 _nc_align_termtype(TERMTYPE2 *to, TERMTYPE2 *from)
424 {
425     int na;
426     int nb;
427     char **ext_Names;
428
429     na = to ? ((int) NUM_EXT_NAMES(to)) : 0;
430     nb = from ? ((int) NUM_EXT_NAMES(from)) : 0;
431
432     DEBUG(2, (T_CALLED("_nc_align_termtype to(%d:%s), from(%d:%s)"),
433               na, to ? NonNull(to->term_names) : "?",
434               nb, from ? NonNull(from->term_names) : "?"));
435
436     if (to != NULL && from != NULL && (na != 0 || nb != 0)) {
437         int ext_Booleans, ext_Numbers, ext_Strings;
438         bool used_ext_Names = FALSE;
439
440         if ((na == nb)          /* check if the arrays are equivalent */
441             &&(to->ext_Booleans == from->ext_Booleans)
442             && (to->ext_Numbers == from->ext_Numbers)
443             && (to->ext_Strings == from->ext_Strings)) {
444             int n;
445             bool same;
446
447             for (n = 0, same = TRUE; n < na; n++) {
448                 if (strcmp(to->ext_Names[n], from->ext_Names[n])) {
449                     same = FALSE;
450                     break;
451                 }
452             }
453             if (same) {
454                 DEBUG(2, (T_RETURN("")));
455                 return;
456             }
457         }
458         /*
459          * This is where we pay for having a simple extension representation.
460          * Allocate a new ext_Names array and merge the two ext_Names arrays
461          * into it, updating to's counts for booleans, etc.  Fortunately we do
462          * this only for the terminfo compiler (tic) and comparer (infocmp).
463          */
464         TYPE_MALLOC(char *, (size_t)(na + nb), ext_Names);
465
466         if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers))
467             adjust_cancels(to, from);
468
469         if (from->ext_Strings && (to->ext_Booleans + to->ext_Numbers))
470             adjust_cancels(from, to);
471
472         ext_Booleans = merge_names(ext_Names,
473                                    to->ext_Names,
474                                    to->ext_Booleans,
475                                    from->ext_Names,
476                                    from->ext_Booleans);
477         ext_Numbers = merge_names(ext_Names + ext_Booleans,
478                                   to->ext_Names
479                                   + to->ext_Booleans,
480                                   to->ext_Numbers,
481                                   from->ext_Names
482                                   + from->ext_Booleans,
483                                   from->ext_Numbers);
484         ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans,
485                                   to->ext_Names
486                                   + to->ext_Booleans
487                                   + to->ext_Numbers,
488                                   to->ext_Strings,
489                                   from->ext_Names
490                                   + from->ext_Booleans
491                                   + from->ext_Numbers,
492                                   from->ext_Strings);
493         /*
494          * Now we must reallocate the Booleans, etc., to allow the data to be
495          * overlaid.
496          */
497         if (na != (ext_Booleans + ext_Numbers + ext_Strings)) {
498             realign_data(to, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
499             FreeIfNeeded(to->ext_Names);
500             to->ext_Names = ext_Names;
501             DEBUG(2, ("realigned %d extended names for '%s' (to)",
502                       NUM_EXT_NAMES(to), to->term_names));
503             used_ext_Names = TRUE;
504         }
505         if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) {
506             nb = (ext_Booleans + ext_Numbers + ext_Strings);
507             realign_data(from, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
508             TYPE_REALLOC(char *, (size_t) nb, from->ext_Names);
509             memcpy(from->ext_Names, ext_Names, sizeof(char *) * (size_t) nb);
510             DEBUG(2, ("realigned %d extended names for '%s' (from)",
511                       NUM_EXT_NAMES(from), from->term_names));
512         }
513         if (!used_ext_Names)
514             free(ext_Names);
515     }
516     DEBUG(2, (T_RETURN("")));
517 }
518 #endif
519
520 #define srcINT 1
521 #define dstINT 2
522
523 /*
524  * TERMTYPE and TERMTYPE2 differ only with regard to the values in Numbers.
525  * Use 'mode' to decide which to use.
526  */
527 static void
528 copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
529 {
530     unsigned i;
531     int pass;
532     char *new_table;
533 #if NCURSES_EXT_NUMBERS
534     short *oldptr = 0;
535     int *newptr = 0;
536 #endif
537
538     DEBUG(2, (T_CALLED("copy_termtype(dst=%p, src=%p, mode=%d)"), (void *)
539               dst, (const void *) src, mode));
540     *dst = *src;                /* ...to copy the sizes and string-tables */
541
542     TYPE_MALLOC(NCURSES_SBOOL, NUM_BOOLEANS(dst), dst->Booleans);
543     TYPE_MALLOC(char *, NUM_STRINGS(dst), dst->Strings);
544
545     memcpy(dst->Booleans,
546            src->Booleans,
547            NUM_BOOLEANS(dst) * sizeof(dst->Booleans[0]));
548     memcpy(dst->Strings,
549            src->Strings,
550            NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
551
552     new_table = NULL;
553     for (pass = 0; pass < 2; ++pass) {
554         size_t str_size = 0;
555         if (pass) {
556             dst->term_names = new_table + str_size;
557             strcpy(dst->term_names + str_size, src->term_names);
558         }
559         str_size += strlen(src->term_names) + 1;
560         for (i = 0; i < NUM_STRINGS(dst); ++i) {
561             if (VALID_STRING(src->Strings[i])) {
562                 if (pass) {
563                     strcpy(new_table + str_size, src->Strings[i]);
564                     dst->Strings[i] = new_table + str_size;
565                 }
566                 str_size += strlen(src->Strings[i]) + 1;
567             }
568         }
569         if (pass) {
570             dst->str_table = new_table;
571         } else {
572             ++str_size;
573             new_table = malloc(str_size);
574         }
575     }
576
577 #if NCURSES_EXT_NUMBERS
578     if ((mode & dstINT) == 0) {
579         DEBUG(2, ("...convert int ->short"));
580         TYPE_MALLOC(short, NUM_NUMBERS(dst), oldptr);
581         ((TERMTYPE *) dst)->Numbers = oldptr;
582     } else {
583         DEBUG(2, ("...copy without changing size"));
584         TYPE_MALLOC(int, NUM_NUMBERS(dst), newptr);
585         dst->Numbers = newptr;
586     }
587     if ((mode == srcINT) && (oldptr != 0)) {
588         DEBUG(2, ("...copy int ->short"));
589         for (i = 0; i < NUM_NUMBERS(dst); ++i) {
590             if (src->Numbers[i] > MAX_OF_TYPE(short)) {
591                 oldptr[i] = MAX_OF_TYPE(short);
592             } else {
593                 oldptr[i] = (short) src->Numbers[i];
594             }
595         }
596     } else if ((mode == dstINT) && (newptr != 0)) {
597         DEBUG(2, ("...copy short ->int"));
598         for (i = 0; i < NUM_NUMBERS(dst); ++i) {
599             newptr[i] = ((const short *) (src->Numbers))[i];
600         }
601     } else {
602         DEBUG(2, ("...copy %s without change",
603                   (mode & dstINT)
604                   ? "int"
605                   : "short"));
606         memcpy(dst->Numbers,
607                src->Numbers,
608                NUM_NUMBERS(dst) * ((mode & dstINT)
609                                    ? sizeof(int)
610                                    : sizeof(short)));
611     }
612 #else
613     (void) mode;
614     TYPE_MALLOC(short, NUM_NUMBERS(dst), dst->Numbers);
615     memcpy(dst->Numbers,
616            src->Numbers,
617            NUM_NUMBERS(dst) * sizeof(dst->Numbers[0]));
618 #endif
619
620 #if NCURSES_XNAMES
621     if ((i = NUM_EXT_NAMES(src)) != 0) {
622         TYPE_MALLOC(char *, i, dst->ext_Names);
623         memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *));
624
625         new_table = NULL;
626         for (pass = 0; pass < 2; ++pass) {
627             size_t str_size = 0;
628             for (i = 0; i < NUM_EXT_NAMES(dst); ++i) {
629                 if (VALID_STRING(src->ext_Names[i])) {
630                     if (pass) {
631                         strcpy(new_table + str_size, src->ext_Names[i]);
632                         dst->ext_Names[i] = new_table + str_size;
633                     }
634                     str_size += strlen(src->ext_Names[i]) + 1;
635                 }
636             }
637             if (pass) {
638                 dst->ext_str_table = new_table;
639             } else {
640                 ++str_size;
641                 new_table = malloc(str_size);
642             }
643         }
644     } else {
645         dst->ext_Names = 0;
646     }
647 #endif
648     DEBUG(2, (T_RETURN("")));
649 }
650
651 /*
652  * This entrypoint is used by tack 1.07
653  */
654 NCURSES_EXPORT(void)
655 _nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
656 {
657     DEBUG(2, (T_CALLED("_nc_copy_termtype(dst=%p, src=%p)"), (void *) dst,
658               (const void *) src));
659     copy_termtype((TERMTYPE2 *) dst, (const TERMTYPE2 *) src, 0);
660     DEBUG(2, (T_RETURN("")));
661 }
662
663 #if NCURSES_EXT_NUMBERS
664 NCURSES_EXPORT(void)
665 _nc_copy_termtype2(TERMTYPE2 *dst, const TERMTYPE2 *src)
666 {
667     DEBUG(2, (T_CALLED("_nc_copy_termtype2(dst=%p, src=%p)"), (void *) dst,
668               (const void *) src));
669     copy_termtype(dst, src, srcINT | dstINT);
670     DEBUG(2, (T_RETURN("")));
671 }
672
673 /*
674  * Use this for exporting the internal TERMTYPE2 to the legacy format used via
675  * the CUR macro by applications.
676  */
677 NCURSES_EXPORT(void)
678 _nc_export_termtype2(TERMTYPE *dst, const TERMTYPE2 *src)
679 {
680     DEBUG(2, (T_CALLED("_nc_export_termtype2(dst=%p, src=%p)"), (void *)
681               dst, (const void *) src));
682     copy_termtype((TERMTYPE2 *) dst, src, srcINT);
683     DEBUG(2, (T_RETURN("")));
684 }
685 #endif /* NCURSES_EXT_NUMBERS */