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