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