]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/comp_parse.c
ncurses 6.3 - patch 20220430
[ncurses.git] / ncurses / tinfo / comp_parse.c
1 /****************************************************************************
2  * Copyright 2018-2021,2022 Thomas E. Dickey                                *
3  * Copyright 1998-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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
32  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
33  *     and: Thomas E. Dickey                        1996-on                 *
34  ****************************************************************************/
35
36 /*
37  *      comp_parse.c -- parser driver loop and use handling.
38  *
39  *      Use this code by calling _nc_read_entry_source() on as many source
40  *      files as you like (either terminfo or termcap syntax).  If you
41  *      want use-resolution, call _nc_resolve_uses2().  To free the list
42  *      storage, do _nc_free_entries().
43  */
44
45 #include <curses.priv.h>
46
47 #include <ctype.h>
48
49 #include <tic.h>
50
51 MODULE_ID("$Id: comp_parse.c,v 1.117 2022/04/30 15:57:27 tom Exp $")
52
53 static void sanity_check2(TERMTYPE2 *, bool);
54 NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype2) (TERMTYPE2 *, bool) = sanity_check2;
55
56 static void fixup_acsc(TERMTYPE2 *, int);
57
58 static void
59 enqueue(ENTRY * ep)
60 /* add an entry to the in-core list */
61 {
62     ENTRY *newp;
63
64     DEBUG(1, (T_CALLED("enqueue(ep=%p)"), ep));
65
66     newp = _nc_copy_entry(ep);
67     if (newp == 0)
68         _nc_err_abort(MSG_NO_MEMORY);
69
70     newp->last = _nc_tail;
71     _nc_tail = newp;
72
73     newp->next = 0;
74     if (newp->last)
75         newp->last->next = newp;
76 }
77
78 #define NAMEBUFFER_SIZE (MAX_NAME_SIZE + 2)
79
80 static char *
81 force_bar(char *dst, char *src)
82 {
83     if (strchr(src, '|') == 0) {
84         size_t len = strlen(src);
85         if (len > MAX_NAME_SIZE)
86             len = MAX_NAME_SIZE;
87         _nc_STRNCPY(dst, src, MAX_NAME_SIZE);
88         _nc_STRCPY(dst + len, "|", NAMEBUFFER_SIZE - len);
89         src = dst;
90     }
91     return src;
92 }
93 #define ForceBar(dst, src) ((strchr(src, '|') == 0) ? force_bar(dst, src) : src)
94
95 #if NCURSES_USE_TERMCAP && NCURSES_XNAMES
96 static char *
97 skip_index(char *name)
98 {
99     char *bar = strchr(name, '|');
100
101     if (bar != 0 && (bar - name) == 2)
102         name = bar + 1;
103
104     return name;
105 }
106 #endif
107
108 static bool
109 check_collisions(char *n1, char *n2, int counter)
110 {
111     char *pstart, *qstart, *pend, *qend;
112     char nc1[NAMEBUFFER_SIZE];
113     char nc2[NAMEBUFFER_SIZE];
114
115     n1 = ForceBar(nc1, n1);
116     n2 = ForceBar(nc2, n2);
117
118 #if NCURSES_USE_TERMCAP && NCURSES_XNAMES
119     if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
120         n1 = skip_index(n1);
121         n2 = skip_index(n2);
122     }
123 #endif
124
125     for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1) {
126         for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1) {
127             if ((pend - pstart == qend - qstart)
128                 && memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
129                 if (counter > 0)
130                     (void) fprintf(stderr, "Name collision '%.*s' between\n",
131                                    (int) (pend - pstart), pstart);
132                 return (TRUE);
133             }
134         }
135     }
136
137     return (FALSE);
138 }
139
140 static char *
141 next_name(char *name)
142 {
143     if (*name != '\0')
144         ++name;
145     return name;
146 }
147
148 static char *
149 name_ending(char *name)
150 {
151     if (*name == '\0') {
152         name = 0;
153     } else {
154         while (*name != '\0' && *name != '|')
155             ++name;
156     }
157     return name;
158 }
159
160 /*
161  * Essentially, find the conflict reported in check_collisions() and remove
162  * it from the second name, unless that happens to be the last alias.
163  */
164 static bool
165 remove_collision(char *n1, char *n2)
166 {
167     char *p2 = n2;
168     char *pstart, *qstart, *pend, *qend;
169     bool removed = FALSE;
170
171 #if NCURSES_USE_TERMCAP && NCURSES_XNAMES
172     if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
173         n1 = skip_index(n1);
174         p2 = n2 = skip_index(n2);
175     }
176 #endif
177
178     for (pstart = n1; (pend = name_ending(pstart)); pstart = next_name(pend)) {
179         for (qstart = n2; (qend = name_ending(qstart)); qstart = next_name(qend)) {
180             if ((pend - pstart == qend - qstart)
181                 && memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
182                 if (qstart != p2 || *qend == '|') {
183                     if (*qend == '|')
184                         ++qend;
185                     while ((*qstart++ = *qend++) != '\0') ;
186                     fprintf(stderr, "...now\t%s\n", p2);
187                     removed = TRUE;
188                 } else {
189                     fprintf(stderr, "Cannot remove alias '%.*s'\n",
190                             (int) (qend - qstart), qstart);
191                 }
192                 break;
193             }
194         }
195     }
196
197     return removed;
198 }
199
200 /* do any of the aliases in a pair of terminal names match? */
201 NCURSES_EXPORT(bool)
202 _nc_entry_match(char *n1, char *n2)
203 {
204     return check_collisions(n1, n2, 0);
205 }
206
207 /****************************************************************************
208  *
209  * Entry compiler and resolution logic
210  *
211  ****************************************************************************/
212
213 NCURSES_EXPORT(void)
214 _nc_read_entry_source(FILE *fp, char *buf,
215                       int literal, bool silent,
216                       bool(*hook) (ENTRY *))
217 /* slurp all entries in the given file into core */
218 {
219     ENTRY thisentry;
220     bool oldsuppress = _nc_suppress_warnings;
221     int immediate = 0;
222
223     DEBUG(1,
224           (T_CALLED("_nc_read_entry_source(file=%p, buf=%p, literal=%d, silent=%d, hook=%p)"),
225            fp, buf, literal, silent, hook));
226
227     if (silent)
228         _nc_suppress_warnings = TRUE;   /* shut the lexer up, too */
229
230     _nc_reset_input(fp, buf);
231     for (;;) {
232         memset(&thisentry, 0, sizeof(thisentry));
233         if (_nc_parse_entry(&thisentry, literal, silent) == ERR)
234             break;
235         if (!isalnum(UChar(thisentry.tterm.term_names[0])))
236             _nc_err_abort("terminal names must start with letter or digit");
237
238         /*
239          * This can be used for immediate compilation of entries with no "use="
240          * references to disk.  That avoids consuming a lot of memory when the
241          * resolution code could fetch entries off disk.
242          */
243         if (hook != NULLHOOK && (*hook) (&thisentry)) {
244             immediate++;
245         } else {
246             enqueue(&thisentry);
247             /*
248              * The enqueued entry is copied with _nc_copy_termtype(), so we can
249              * free some of the data from thisentry, i.e., the arrays.
250              */
251             FreeIfNeeded(thisentry.tterm.Booleans);
252             FreeIfNeeded(thisentry.tterm.Numbers);
253             FreeIfNeeded(thisentry.tterm.Strings);
254 #if NCURSES_XNAMES
255             FreeIfNeeded(thisentry.tterm.ext_Names);
256 #endif
257         }
258     }
259
260     if (_nc_tail) {
261         /* set up the head pointer */
262         for (_nc_head = _nc_tail; _nc_head->last; _nc_head = _nc_head->last)
263             continue;
264
265         DEBUG(2, ("head = %s", _nc_head->tterm.term_names));
266         DEBUG(2, ("tail = %s", _nc_tail->tterm.term_names));
267     }
268 #ifdef TRACE
269     else if (!immediate)
270         DEBUG(2, ("no entries parsed"));
271 #endif
272
273     _nc_suppress_warnings = oldsuppress;
274 }
275
276 #if 0 && NCURSES_XNAMES
277 static unsigned
278 find_capname(TERMTYPE2 *p, const char *name)
279 {
280     unsigned num_names = NUM_EXT_NAMES(p);
281     unsigned n;
282     if (name != 0) {
283         for (n = 0; n < num_names; ++n) {
284             if (!strcmp(p->ext_Names[n], name))
285                 break;
286         }
287     } else {
288         n = num_names + 1;
289     }
290     return n;
291 }
292
293 static int
294 extended_captype(TERMTYPE2 *p, unsigned which)
295 {
296     int result = UNDEF;
297     unsigned limit = 0;
298     limit += p->ext_Booleans;
299     if (limit != 0 && which < limit) {
300         result = BOOLEAN;
301     } else {
302         limit += p->ext_Numbers;
303         if (limit != 0 && which < limit) {
304             result = NUMBER;
305         } else {
306             limit += p->ext_Strings;
307             if (limit != 0 && which < limit) {
308                 result = ((p->Strings[STRCOUNT + which] != CANCELLED_STRING)
309                           ? STRING
310                           : CANCEL);
311             } else if (which >= limit) {
312                 result = CANCEL;
313             }
314         }
315     }
316     return result;
317 }
318
319 static const char *
320 name_of_captype(int which)
321 {
322     const char *result = "?";
323     switch (which) {
324     case BOOLEAN:
325         result = "boolean";
326         break;
327     case NUMBER:
328         result = "number";
329         break;
330     case STRING:
331         result = "string";
332         break;
333     }
334     return result;
335 }
336
337 #define valid_TERMTYPE2(p) \
338         ((p) != 0 && \
339          (p)->term_names != 0 && \
340          (p)->ext_Names != 0)
341
342 /*
343  * Disallow changing the type of an extended capability when doing a "use"
344  * if one or the other is a string.
345  */
346 static int
347 invalid_merge(TERMTYPE2 *to, TERMTYPE2 *from)
348 {
349     int rc = FALSE;
350     if (valid_TERMTYPE2(to)
351         && valid_TERMTYPE2(from)) {
352         char *to_name = _nc_first_name(to->term_names);
353         char *from_name = strdup(_nc_first_name(from->term_names));
354         unsigned num_names = NUM_EXT_NAMES(from);
355         unsigned n;
356
357         for (n = 0; n < num_names; ++n) {
358             const char *capname = from->ext_Names[n];
359             int tt = extended_captype(to, find_capname(to, capname));
360             int tf = extended_captype(from, n);
361
362             if (tt <= STRING
363                 && tf <= STRING
364                 && (tt == STRING) != (tf == STRING)) {
365                 if (from_name != 0 && strcmp(to_name, from_name)) {
366                     _nc_warning("merge of %s to %s changes type of %s from %s to %s",
367                                 from_name,
368                                 to_name,
369                                 from->ext_Names[n],
370                                 name_of_captype(tf),
371                                 name_of_captype(tt));
372                 } else {
373                     _nc_warning("merge of %s changes type of %s from %s to %s",
374                                 to_name,
375                                 from->ext_Names[n],
376                                 name_of_captype(tf),
377                                 name_of_captype(tt));
378                 }
379                 rc = TRUE;
380             }
381         }
382         free(from_name);
383     }
384     return rc;
385 }
386 #define validate_merge(p, q) \
387         if (invalid_merge(&((p)->tterm), &((q)->tterm))) \
388                 return FALSE
389 #else
390 #define validate_merge(p, q)    /* nothing */
391 #endif
392
393 NCURSES_EXPORT(int)
394 _nc_resolve_uses2(bool fullresolve, bool literal)
395 /* try to resolve all use capabilities */
396 {
397     ENTRY *qp, *rp, *lastread = 0;
398     bool keepgoing;
399     unsigned i, j;
400     int unresolved, total_unresolved, multiples;
401
402     DEBUG(2, (T_CALLED("_nc_resolve_uses2")));
403
404     /*
405      * Check for multiple occurrences of the same name.
406      */
407     multiples = 0;
408     for_entry_list(qp) {
409         int matchcount = 0;
410
411         for_entry_list(rp) {
412             if (qp > rp
413                 && check_collisions(qp->tterm.term_names,
414                                     rp->tterm.term_names,
415                                     matchcount + 1)) {
416                 if (!matchcount++) {
417                     (void) fprintf(stderr, "\t%s\n", rp->tterm.term_names);
418                 }
419                 (void) fprintf(stderr, "and\t%s\n", qp->tterm.term_names);
420                 if (!remove_collision(rp->tterm.term_names,
421                                       qp->tterm.term_names)) {
422                     ++multiples;
423                 }
424             }
425         }
426     }
427     if (multiples > 0) {
428         DEBUG(2, (T_RETURN("false")));
429         return (FALSE);
430     }
431
432     DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES"));
433
434     /*
435      * First resolution stage: compute link pointers corresponding to names.
436      */
437     total_unresolved = 0;
438     _nc_curr_col = -1;
439     for_entry_list(qp) {
440         unresolved = 0;
441         for (i = 0; i < qp->nuses; i++) {
442             bool foundit;
443             char *child = _nc_first_name(qp->tterm.term_names);
444             char *lookfor = qp->uses[i].name;
445             long lookline = qp->uses[i].line;
446
447             if (lookfor == 0)
448                 continue;
449
450             foundit = FALSE;
451
452             _nc_set_type(child);
453
454             /* first, try to resolve from in-core records */
455             for_entry_list(rp) {
456                 if (rp != qp
457                     && _nc_name_match(rp->tterm.term_names, lookfor, "|")) {
458                     DEBUG(2, ("%s: resolving use=%s (in core)",
459                               child, lookfor));
460
461                     qp->uses[i].link = rp;
462                     foundit = TRUE;
463
464                     /* verify that there are no earlier uses */
465                     for (j = 0; j < i; ++j) {
466                         if (qp->uses[j].link != NULL
467                             && !strcmp(qp->uses[j].link->tterm.term_names,
468                                        rp->tterm.term_names)) {
469                             _nc_warning("duplicate use=%s", lookfor);
470                             break;
471                         }
472                     }
473                 }
474             }
475
476             /* if that didn't work, try to merge in a compiled entry */
477             if (!foundit) {
478                 TERMTYPE2 thisterm;
479                 char filename[PATH_MAX];
480
481                 memset(&thisterm, 0, sizeof(thisterm));
482                 if (_nc_read_entry2(lookfor, filename, &thisterm) == 1) {
483                     DEBUG(2, ("%s: resolving use=%s (compiled)",
484                               child, lookfor));
485
486                     TYPE_MALLOC(ENTRY, 1, rp);
487                     rp->tterm = thisterm;
488                     rp->nuses = 0;
489                     rp->next = lastread;
490                     lastread = rp;
491
492                     qp->uses[i].link = rp;
493                     foundit = TRUE;
494
495                     /* verify that there are no earlier uses */
496                     for (j = 0; j < i; ++j) {
497                         if (qp->uses[j].link != NULL
498                             && !strcmp(qp->uses[j].link->tterm.term_names,
499                                        rp->tterm.term_names)) {
500                             _nc_warning("duplicate use=%s", lookfor);
501                             break;
502                         }
503                     }
504                 }
505             }
506
507             /* no good, mark this one unresolvable and complain */
508             if (!foundit) {
509                 unresolved++;
510                 total_unresolved++;
511
512                 _nc_curr_line = (int) lookline;
513                 _nc_warning("resolution of use=%s failed", lookfor);
514                 qp->uses[i].link = 0;
515             }
516         }
517     }
518     if (total_unresolved) {
519         /* free entries read in off disk */
520         _nc_free_entries(lastread);
521         DEBUG(2, (T_RETURN("false")));
522         return (FALSE);
523     }
524
525     DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));
526
527     /*
528      * OK, at this point all (char *) references in `name' members
529      * have been successfully converted to (ENTRY *) pointers in
530      * `link' members.  Time to do the actual merges.
531      */
532     if (fullresolve) {
533         do {
534             ENTRY merged;
535
536             keepgoing = FALSE;
537
538             for_entry_list(qp) {
539                 if (qp->nuses > 0) {
540                     DEBUG(2, ("%s: attempting merge",
541                               _nc_first_name(qp->tterm.term_names)));
542                     /*
543                      * If any of the use entries we're looking for is
544                      * incomplete, punt.  We'll catch this entry on a
545                      * subsequent pass.
546                      */
547                     for (i = 0; i < qp->nuses; i++)
548                         if (qp->uses[i].link
549                             && qp->uses[i].link->nuses) {
550                             DEBUG(2, ("%s: use entry %d unresolved",
551                                       _nc_first_name(qp->tterm.term_names), i));
552                             goto incomplete;
553                         }
554
555                     /*
556                      * First, make sure there is no garbage in the
557                      * merge block.  As a side effect, copy into
558                      * the merged entry the name field and string
559                      * table pointer.
560                      */
561                     _nc_copy_termtype2(&(merged.tterm), &(qp->tterm));
562
563                     /*
564                      * Now merge in each use entry in the proper
565                      * (reverse) order.
566                      */
567                     for (; qp->nuses; qp->nuses--) {
568                         validate_merge(&merged,
569                                        qp->uses[qp->nuses - 1].link);
570                         _nc_merge_entry(&merged,
571                                         qp->uses[qp->nuses - 1].link);
572                     }
573
574                     /*
575                      * Now merge in the original entry.
576                      */
577                     validate_merge(&merged, qp);
578                     _nc_merge_entry(&merged, qp);
579
580                     /*
581                      * Replace the original entry with the merged one.
582                      */
583                     FreeIfNeeded(qp->tterm.Booleans);
584                     FreeIfNeeded(qp->tterm.Numbers);
585                     FreeIfNeeded(qp->tterm.Strings);
586 #if NCURSES_XNAMES
587                     FreeIfNeeded(qp->tterm.ext_Names);
588 #endif
589                     qp->tterm = merged.tterm;
590                     _nc_wrap_entry(qp, TRUE);
591
592                     /*
593                      * We know every entry is resolvable because name resolution
594                      * didn't bomb.  So go back for another pass.
595                      */
596                     /* FALLTHRU */
597                   incomplete:
598                     keepgoing = TRUE;
599                 }
600             }
601         } while
602             (keepgoing);
603
604         DEBUG(2, ("MERGES COMPLETED OK"));
605     }
606
607     /*
608      * We'd like to free entries read in off disk at this point, but can't.
609      * The merge_entry() code doesn't copy the strings in the use entries,
610      * it just aliases them.  If this ever changes, do a
611      * free_entries(lastread) here.
612      */
613
614     DEBUG(2, ("RESOLUTION FINISHED"));
615
616     if (fullresolve) {
617         _nc_curr_col = -1;
618         for_entry_list(qp) {
619             _nc_curr_line = (int) qp->startline;
620             _nc_set_type(_nc_first_name(qp->tterm.term_names));
621             /*
622              * tic overrides this function pointer to provide more verbose
623              * checking.
624              */
625             if (_nc_check_termtype2 != sanity_check2) {
626                 SCREEN *save_SP = SP;
627                 SCREEN fake_sp;
628                 TERMINAL fake_tm;
629                 TERMINAL *save_tm = cur_term;
630
631                 /*
632                  * Setup so that tic can use ordinary terminfo interface to
633                  * obtain capability information.
634                  */
635                 memset(&fake_sp, 0, sizeof(fake_sp));
636                 memset(&fake_tm, 0, sizeof(fake_tm));
637                 fake_sp._term = &fake_tm;
638                 TerminalType(&fake_tm) = qp->tterm;
639                 _nc_set_screen(&fake_sp);
640                 set_curterm(&fake_tm);
641
642                 _nc_check_termtype2(&qp->tterm, literal);
643
644                 /*
645                  * Checking calls tparm, which can allocate memory.  Fix leaks.
646                  */
647 #define TPS(name) fake_tm.tparm_state.name
648                 FreeAndNull(TPS(out_buff));
649                 FreeAndNull(TPS(fmt_buff));
650 #undef TPS
651
652                 _nc_set_screen(save_SP);
653                 set_curterm(save_tm);
654             } else {
655                 fixup_acsc(&qp->tterm, literal);
656             }
657         }
658         DEBUG(2, ("SANITY CHECK FINISHED"));
659     }
660
661     DEBUG(2, (T_RETURN("true")));
662     return (TRUE);
663 }
664
665 /*
666  * This bit of legerdemain turns all the terminfo variable names into
667  * references to locations in the arrays Booleans, Numbers, and Strings ---
668  * precisely what's needed.
669  */
670
671 #undef CUR
672 #define CUR tp->
673
674 static void
675 fixup_acsc(TERMTYPE2 *tp, int literal)
676 {
677     if (!literal) {
678         if (acs_chars == ABSENT_STRING
679             && PRESENT(enter_alt_charset_mode)
680             && PRESENT(exit_alt_charset_mode))
681             acs_chars = strdup(VT_ACSC);
682     }
683 }
684
685 static void
686 sanity_check2(TERMTYPE2 *tp, bool literal)
687 {
688     if (!PRESENT(exit_attribute_mode)) {
689 #ifdef __UNUSED__               /* this casts too wide a net */
690         bool terminal_entry = !strchr(tp->term_names, '+');
691         if (terminal_entry &&
692             (PRESENT(set_attributes)
693              || PRESENT(enter_standout_mode)
694              || PRESENT(enter_underline_mode)
695              || PRESENT(enter_blink_mode)
696              || PRESENT(enter_bold_mode)
697              || PRESENT(enter_dim_mode)
698              || PRESENT(enter_secure_mode)
699              || PRESENT(enter_protected_mode)
700              || PRESENT(enter_reverse_mode)))
701             _nc_warning("no exit_attribute_mode");
702 #endif /* __UNUSED__ */
703         PAIRED(enter_standout_mode, exit_standout_mode);
704         PAIRED(enter_underline_mode, exit_underline_mode);
705 #if defined(enter_italics_mode) && defined(exit_italics_mode)
706         PAIRED(enter_italics_mode, exit_italics_mode);
707 #endif
708     }
709
710     /* we do this check/fix in postprocess_termcap(), but some packagers
711      * prefer to bypass it...
712      */
713     if (!literal) {
714         fixup_acsc(tp, literal);
715         ANDMISSING(enter_alt_charset_mode, acs_chars);
716         ANDMISSING(exit_alt_charset_mode, acs_chars);
717     }
718
719     /* listed in structure-member order of first argument */
720     PAIRED(enter_alt_charset_mode, exit_alt_charset_mode);
721     ANDMISSING(enter_blink_mode, exit_attribute_mode);
722     ANDMISSING(enter_bold_mode, exit_attribute_mode);
723     PAIRED(exit_ca_mode, enter_ca_mode);
724     PAIRED(enter_delete_mode, exit_delete_mode);
725     ANDMISSING(enter_dim_mode, exit_attribute_mode);
726     PAIRED(enter_insert_mode, exit_insert_mode);
727     ANDMISSING(enter_secure_mode, exit_attribute_mode);
728     ANDMISSING(enter_protected_mode, exit_attribute_mode);
729     ANDMISSING(enter_reverse_mode, exit_attribute_mode);
730     PAIRED(from_status_line, to_status_line);
731     PAIRED(meta_off, meta_on);
732
733     PAIRED(prtr_on, prtr_off);
734     PAIRED(save_cursor, restore_cursor);
735     PAIRED(enter_xon_mode, exit_xon_mode);
736     PAIRED(enter_am_mode, exit_am_mode);
737     ANDMISSING(label_off, label_on);
738 #if defined(display_clock) && defined(remove_clock)
739     PAIRED(display_clock, remove_clock);
740 #endif
741     ANDMISSING(set_color_pair, initialize_pair);
742 }
743
744 #if NO_LEAKS
745 NCURSES_EXPORT(void)
746 _nc_leaks_tic(void)
747 {
748     T((T_CALLED("_nc_free_tic()")));
749     _nc_globals.leak_checking = TRUE;
750     _nc_alloc_entry_leaks();
751     _nc_captoinfo_leaks();
752     _nc_comp_scan_leaks();
753 #if BROKEN_LINKER || USE_REENTRANT
754     _nc_names_leaks();
755     _nc_codes_leaks();
756 #endif
757     _nc_tic_expand(0, FALSE, 0);
758 }
759
760 NCURSES_EXPORT(void)
761 _nc_free_tic(int code)
762 {
763     _nc_leaks_tic();
764     exit_terminfo(code);
765 }
766 #endif