Annotation of src/usr.bin/tic/tic.c, Revision 1.16
1.1 millert 1: /****************************************************************************
1.16 ! millert 2: * Copyright (c) 1998-2000 Free Software Foundation, Inc. *
1.1 millert 3: * *
4: * Permission is hereby granted, free of charge, to any person obtaining a *
5: * copy of this software and associated documentation files (the *
6: * "Software"), to deal in the Software without restriction, including *
7: * without limitation the rights to use, copy, modify, merge, publish, *
8: * distribute, distribute with modifications, sublicense, and/or sell *
9: * copies of the Software, and to permit persons to whom the Software is *
10: * furnished to do so, subject to the following conditions: *
11: * *
12: * The above copyright notice and this permission notice shall be included *
13: * in all copies or substantial portions of the Software. *
14: * *
15: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18: * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20: * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21: * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
22: * *
23: * Except as contained in this notice, the name(s) of the above copyright *
24: * holders shall not be used in advertising or otherwise to promote the *
25: * sale, use or other dealings in this Software without prior written *
26: * authorization. *
27: ****************************************************************************/
28:
29: /****************************************************************************
30: * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31: * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32: ****************************************************************************/
33:
34: /*
35: * tic.c --- Main program for terminfo compiler
36: * by Eric S. Raymond
37: *
38: */
39:
40: #include <progs.priv.h>
41:
42: #include <dump_entry.h>
43: #include <term_entry.h>
44:
1.16 ! millert 45: MODULE_ID("$From: tic.c,v 1.57 2000/01/15 21:44:28 tom Exp $")
1.1 millert 46:
47: const char *_nc_progname = "tic";
48:
1.14 millert 49: static FILE *log_fp;
50: static FILE *tmp_fp;
51: static bool showsummary = FALSE;
52: static const char *to_remove;
53:
54: static void (*save_check_termtype) (TERMTYPE *);
55: static void check_termtype(TERMTYPE * tt);
56:
57: static const char usage_string[] = "[-h] [-v[n]] [-e names] [-CILNRTcfrswx1] source-file\n";
58:
59: static void
60: cleanup(void)
61: {
62: if (tmp_fp != 0)
63: fclose(tmp_fp);
64: if (to_remove != 0) {
1.11 millert 65: #if HAVE_REMOVE
1.14 millert 66: remove(to_remove);
1.11 millert 67: #else
1.14 millert 68: unlink(to_remove);
1.11 millert 69: #endif
1.14 millert 70: }
1.2 millert 71: }
72:
1.14 millert 73: static void
74: failed(const char *msg)
1.2 millert 75: {
1.14 millert 76: perror(msg);
77: cleanup();
78: exit(EXIT_FAILURE);
1.2 millert 79: }
80:
1.14 millert 81: static void
82: usage(void)
1.1 millert 83: {
1.14 millert 84: static const char *const tbl[] =
85: {
1.1 millert 86: "Options:",
87: " -1 format translation output one capability per line",
88: " -C translate entries to termcap source form",
89: " -I translate entries to terminfo source form",
90: " -L translate entries to full terminfo source form",
91: " -N disable smart defaults for source translation",
92: " -R restrict translation to given terminfo/termcap version",
93: " -T remove size-restrictions on compiled description",
94: " -c check only, validate input without compiling or translating",
95: " -f format complex strings for readability",
1.8 millert 96: " -G format %{number} to %'char'",
1.2 millert 97: " -g format %'char' to %{number}",
1.1 millert 98: " -e<names> translate/compile only entries named by comma-separated list",
99: " -o<dir> set output directory for compiled entry writes",
100: " -r force resolution of all use entries in source translation",
101: " -s print summary statistics",
102: " -v[n] set verbosity level",
103: " -w[n] set format width for translation output",
1.7 millert 104: #if NCURSES_XNAMES
105: " -x treat unknown capabilities as user-defined",
106: #endif
1.1 millert 107: "",
108: "Parameters:",
109: " <file> file to translate or compile"
1.14 millert 110: };
111: size_t j;
1.1 millert 112:
1.15 millert 113: fprintf(stderr, "Usage: %s %s\n", _nc_progname, usage_string);
114: for (j = 0; j < sizeof(tbl) / sizeof(tbl[0]); j++) {
115: fputs(tbl[j], stderr);
116: putc('\n', stderr);
117: }
1.14 millert 118: exit(EXIT_FAILURE);
1.1 millert 119: }
120:
1.2 millert 121: #define L_BRACE '{'
122: #define R_BRACE '}'
123: #define S_QUOTE '\'';
124:
1.14 millert 125: static void
126: write_it(ENTRY * ep)
1.2 millert 127: {
1.14 millert 128: unsigned n;
129: int ch;
130: char *s, *d, *t;
131: char result[MAX_ENTRY_SIZE];
132:
133: /*
134: * Look for strings that contain %{number}, convert them to %'char',
135: * which is shorter and runs a little faster.
136: */
137: for (n = 0; n < STRCOUNT; n++) {
138: s = ep->tterm.Strings[n];
139: if (VALID_STRING(s)
140: && strchr(s, L_BRACE) != 0) {
141: d = result;
142: t = s;
143: while ((ch = *t++) != 0) {
144: *d++ = ch;
145: if (ch == '\\') {
146: *d++ = *t++;
147: } else if ((ch == '%')
148: && (*t == L_BRACE)) {
149: char *v = 0;
150: long value = strtol(t + 1, &v, 0);
151: if (v != 0
152: && *v == R_BRACE
153: && value > 0
154: && value != '\\' /* FIXME */
155: && value < 127
156: && isprint((int) value)) {
157: *d++ = S_QUOTE;
158: *d++ = (int) value;
159: *d++ = S_QUOTE;
160: t = (v + 1);
161: }
1.2 millert 162: }
1.14 millert 163: }
164: *d = 0;
165: if (strlen(result) < strlen(s))
166: strcpy(s, result);
1.2 millert 167: }
1.14 millert 168: }
1.2 millert 169:
1.14 millert 170: _nc_set_type(_nc_first_name(ep->tterm.term_names));
171: _nc_curr_line = ep->startline;
172: _nc_write_entry(&ep->tterm);
1.2 millert 173: }
174:
1.14 millert 175: static bool
176: immedhook(ENTRY * ep GCC_UNUSED)
1.1 millert 177: /* write out entries with no use capabilities immediately to save storage */
178: {
179: #ifndef HAVE_BIG_CORE
180: /*
181: * This is strictly a core-economy kluge. The really clean way to handle
182: * compilation is to slurp the whole file into core and then do all the
183: * name-collision checks and entry writes in one swell foop. But the
184: * terminfo master file is large enough that some core-poor systems swap
185: * like crazy when you compile it this way...there have been reports of
186: * this process taking *three hours*, rather than the twenty seconds or
187: * less typical on my development box.
188: *
189: * So. This hook *immediately* writes out the referenced entry if it
190: * has no use capabilities. The compiler main loop refrains from
191: * adding the entry to the in-core list when this hook fires. If some
192: * other entry later needs to reference an entry that got written
193: * immediately, that's OK; the resolution code will fetch it off disk
194: * when it can't find it in core.
195: *
196: * Name collisions will still be detected, just not as cleanly. The
197: * write_entry() code complains before overwriting an entry that
198: * postdates the time of tic's first call to write_entry(). Thus
199: * it will complain about overwriting entries newly made during the
200: * tic run, but not about overwriting ones that predate it.
201: *
202: * The reason this is a hook, and not in line with the rest of the
203: * compiler code, is that the support for termcap fallback cannot assume
204: * it has anywhere to spool out these entries!
205: *
206: * The _nc_set_type() call here requires a compensating one in
207: * _nc_parse_entry().
208: *
209: * If you define HAVE_BIG_CORE, you'll disable this kluge. This will
210: * make tic a bit faster (because the resolution code won't have to do
211: * disk I/O nearly as often).
212: */
1.14 millert 213: if (ep->nuses == 0) {
214: int oldline = _nc_curr_line;
1.1 millert 215:
1.2 millert 216: write_it(ep);
1.1 millert 217: _nc_curr_line = oldline;
218: free(ep->tterm.str_table);
1.14 millert 219: return (TRUE);
1.1 millert 220: }
221: #endif /* HAVE_BIG_CORE */
1.14 millert 222: return (FALSE);
1.1 millert 223: }
224:
1.14 millert 225: static void
226: put_translate(int c)
1.1 millert 227: /* emit a comment char, translating terminfo names to termcap names */
228: {
229: static bool in_name = FALSE;
1.14 millert 230: static size_t have, used;
231: static char *namebuf, *suffix;
1.1 millert 232:
1.14 millert 233: if (in_name) {
234: if (used + 1 >= have) {
235: have += 132;
236: namebuf = (namebuf != 0) ? realloc(namebuf, have) : malloc(have);
237: suffix = (suffix != 0) ? realloc(suffix, have) : malloc(have);
1.1 millert 238: }
1.14 millert 239: if (c == '\n' || c == '@') {
240: namebuf[used++] = '\0';
241: (void) putchar('<');
242: (void) fputs(namebuf, stdout);
1.1 millert 243: putchar(c);
1.14 millert 244: in_name = FALSE;
245: } else if (c != '>') {
246: namebuf[used++] = c;
247: } else { /* ah! candidate name! */
248: char *up;
249: NCURSES_CONST char *tp;
250:
251: namebuf[used++] = '\0';
252: in_name = FALSE;
253:
254: suffix[0] = '\0';
255: if ((up = strchr(namebuf, '#')) != 0
256: || (up = strchr(namebuf, '=')) != 0
257: || ((up = strchr(namebuf, '@')) != 0 && up[1] == '>')) {
258: (void) strcpy(suffix, up);
259: *up = '\0';
260: }
1.1 millert 261:
1.14 millert 262: if ((tp = nametrans(namebuf)) != 0) {
263: (void) putchar(':');
264: (void) fputs(tp, stdout);
265: (void) fputs(suffix, stdout);
266: (void) putchar(':');
267: } else {
268: /* couldn't find a translation, just dump the name */
269: (void) putchar('<');
270: (void) fputs(namebuf, stdout);
271: (void) fputs(suffix, stdout);
272: (void) putchar('>');
273: }
1.1 millert 274: }
1.14 millert 275: } else {
276: used = 0;
277: if (c == '<') {
278: in_name = TRUE;
279: } else {
280: putchar(c);
1.1 millert 281: }
282: }
283: }
284:
285: /* Returns a string, stripped of leading/trailing whitespace */
1.14 millert 286: static char *
287: stripped(char *src)
1.1 millert 288: {
1.14 millert 289: while (isspace(*src))
290: src++;
291: if (*src != '\0') {
292: char *dst = strcpy(malloc(strlen(src) + 1), src);
293: size_t len = strlen(dst);
294: while (--len != 0 && isspace(dst[len]))
295: dst[len] = '\0';
296: return dst;
297: }
298: return 0;
1.1 millert 299: }
300:
301: /* Parse the "-e" option-value into a list of names */
1.14 millert 302: static const char **
303: make_namelist(char *src)
1.1 millert 304: {
1.14 millert 305: const char **dst = 0;
1.1 millert 306:
1.14 millert 307: char *s, *base;
308: unsigned pass, n, nn;
309: char buffer[BUFSIZ];
310:
311: if (src == 0) {
312: /* EMPTY */ ;
313: } else if (strchr(src, '/') != 0) { /* a filename */
314: FILE *fp = fopen(src, "r");
315: if (fp == 0)
316: failed(src);
317:
318: for (pass = 1; pass <= 2; pass++) {
319: nn = 0;
320: while (fgets(buffer, sizeof(buffer), fp) != 0) {
321: if ((s = stripped(buffer)) != 0) {
322: if (dst != 0)
323: dst[nn] = s;
324: nn++;
1.1 millert 325: }
1.14 millert 326: }
327: if (pass == 1) {
328: dst = (const char **) calloc(nn + 1, sizeof(*dst));
329: rewind(fp);
330: }
331: }
332: fclose(fp);
333: } else { /* literal list of names */
334: for (pass = 1; pass <= 2; pass++) {
335: for (n = nn = 0, base = src;; n++) {
336: int mark = src[n];
337: if (mark == ',' || mark == '\0') {
338: if (pass == 1) {
339: nn++;
340: } else {
341: src[n] = '\0';
342: if ((s = stripped(base)) != 0)
343: dst[nn++] = s;
344: base = &src[n + 1];
345: }
1.1 millert 346: }
1.14 millert 347: if (mark == '\0')
348: break;
349: }
350: if (pass == 1)
351: dst = (const char **) calloc(nn + 1, sizeof(*dst));
1.1 millert 352: }
1.14 millert 353: }
354: if (showsummary) {
355: fprintf(log_fp, "Entries that will be compiled:\n");
356: for (n = 0; dst[n] != 0; n++)
357: fprintf(log_fp, "%d:%s\n", n + 1, dst[n]);
358: }
359: return dst;
1.1 millert 360: }
361:
1.14 millert 362: static bool
363: matches(const char **needle, const char *haystack)
1.1 millert 364: /* does entry in needle list match |-separated field in haystack? */
365: {
1.14 millert 366: bool code = FALSE;
367: size_t n;
1.1 millert 368:
1.14 millert 369: if (needle != 0) {
370: for (n = 0; needle[n] != 0; n++) {
371: if (_nc_name_match(haystack, needle[n], "|")) {
372: code = TRUE;
373: break;
374: }
1.1 millert 375: }
1.14 millert 376: } else
377: code = TRUE;
378: return (code);
1.1 millert 379: }
380:
1.14 millert 381: int
382: main(int argc, char *argv[])
1.1 millert 383: {
1.14 millert 384: char my_tmpname[PATH_MAX];
385: int v_opt = -1, debug_level;
386: int smart_defaults = TRUE;
387: char *termcap;
388: ENTRY *qp;
389:
390: int this_opt, last_opt = '?';
391:
392: int outform = F_TERMINFO; /* output format */
393: int sortmode = S_TERMINFO; /* sort_mode */
394:
395: int fd;
396: int width = 60;
397: bool formatted = FALSE; /* reformat complex strings? */
398: int numbers = 0; /* format "%'char'" to/from "%{number}" */
399: bool infodump = FALSE; /* running as captoinfo? */
400: bool capdump = FALSE; /* running as infotocap? */
401: bool forceresolve = FALSE; /* force resolution */
402: bool limited = TRUE;
403: char *tversion = (char *) NULL;
404: const char *source_file = "terminfo";
405: const char **namelst = 0;
406: char *outdir = (char *) NULL;
407: bool check_only = FALSE;
408:
409: log_fp = stderr;
410:
411: if ((_nc_progname = strrchr(argv[0], '/')) == NULL)
412: _nc_progname = argv[0];
413: else
414: _nc_progname++;
415:
416: if ((infodump = (strcmp(_nc_progname, "captoinfo") == 0)) != FALSE) {
417: outform = F_TERMINFO;
418: sortmode = S_TERMINFO;
419: }
420: if ((capdump = (strcmp(_nc_progname, "infotocap") == 0)) != FALSE) {
421: outform = F_TERMCAP;
422: sortmode = S_TERMCAP;
423: }
1.7 millert 424: #if NCURSES_XNAMES
1.14 millert 425: use_extended_names(FALSE);
1.7 millert 426: #endif
1.1 millert 427:
1.14 millert 428: /*
429: * Processing arguments is a little complicated, since someone made a
430: * design decision to allow the numeric values for -w, -v options to
431: * be optional.
432: */
433: while ((this_opt = getopt(argc, argv,
434: "0123456789CILNR:TVce:fGgo:rsvwx")) != -1) {
435: if (isdigit(this_opt)) {
436: switch (last_opt) {
437: case 'v':
438: v_opt = (v_opt * 10) + (this_opt - '0');
439: break;
440: case 'w':
441: width = (width * 10) + (this_opt - '0');
442: break;
443: default:
444: if (this_opt != '1')
445: usage();
446: last_opt = this_opt;
447: width = 0;
448: }
449: continue;
450: }
451: switch (this_opt) {
452: case 'C':
453: capdump = TRUE;
454: outform = F_TERMCAP;
455: sortmode = S_TERMCAP;
456: break;
457: case 'I':
458: infodump = TRUE;
459: outform = F_TERMINFO;
460: sortmode = S_TERMINFO;
461: break;
462: case 'L':
463: infodump = TRUE;
464: outform = F_VARIABLE;
465: sortmode = S_VARIABLE;
466: break;
467: case 'N':
468: smart_defaults = FALSE;
469: break;
470: case 'R':
471: tversion = optarg;
472: break;
473: case 'T':
474: limited = FALSE;
475: break;
476: case 'V':
477: puts(NCURSES_VERSION);
478: return EXIT_SUCCESS;
479: case 'c':
480: check_only = TRUE;
481: break;
482: case 'e':
483: namelst = make_namelist(optarg);
484: break;
485: case 'f':
486: formatted = TRUE;
487: break;
488: case 'G':
489: numbers = 1;
490: break;
491: case 'g':
492: numbers = -1;
493: break;
494: case 'o':
495: outdir = optarg;
496: break;
497: case 'r':
498: forceresolve = TRUE;
499: break;
500: case 's':
501: showsummary = TRUE;
502: break;
503: case 'v':
504: v_opt = 0;
505: break;
506: case 'w':
507: width = 0;
508: break;
1.7 millert 509: #if NCURSES_XNAMES
1.14 millert 510: case 'x':
511: use_extended_names(TRUE);
512: break;
1.7 millert 513: #endif
1.14 millert 514: default:
515: usage();
1.1 millert 516: }
1.14 millert 517: last_opt = this_opt;
518: }
1.1 millert 519:
1.14 millert 520: debug_level = (v_opt > 0) ? v_opt : (v_opt == 0);
1.16 ! millert 521: set_trace_level(debug_level);
1.6 millert 522:
1.14 millert 523: if (_nc_tracing) {
524: save_check_termtype = _nc_check_termtype;
525: _nc_check_termtype = check_termtype;
526: }
1.4 millert 527: #ifndef HAVE_BIG_CORE
1.14 millert 528: /*
529: * Aaargh! immedhook seriously hoses us!
530: *
531: * One problem with immedhook is it means we can't do -e. Problem
532: * is that we can't guarantee that for each terminal listed, all the
533: * terminals it depends on will have been kept in core for reference
534: * resolution -- in fact it's certain the primitive types at the end
535: * of reference chains *won't* be in core unless they were explicitly
536: * in the select list themselves.
537: */
538: if (namelst && (!infodump && !capdump)) {
539: (void) fprintf(stderr,
540: "Sorry, -e can't be used without -I or -C\n");
541: cleanup();
542: return EXIT_FAILURE;
543: }
1.4 millert 544: #endif /* HAVE_BIG_CORE */
545:
1.14 millert 546: if (optind < argc) {
547: source_file = argv[optind++];
1.1 millert 548: if (optind < argc) {
1.14 millert 549: fprintf(stderr,
550: "%s: Too many file names. Usage:\n\t%s %s",
551: _nc_progname,
552: _nc_progname,
553: usage_string);
554: return EXIT_FAILURE;
555: }
556: } else {
557: if (infodump == TRUE) {
558: /* captoinfo's no-argument case */
559: source_file = "/usr/share/misc/termcap";
560: if ((termcap = getenv("TERMCAP")) != 0
561: && (namelst = make_namelist(getenv("TERM"))) != 0) {
562: if (access(termcap, F_OK) == 0) {
563: /* file exists */
564: source_file = termcap;
565: } else if (strcpy(my_tmpname, "/tmp/tic.XXXXXXXX")
566: && (fd = mkstemp(my_tmpname)) != -1
567: && (tmp_fp = fdopen(fd, "w")) != 0) {
568: fprintf(tmp_fp, "%s\n", termcap);
569: fclose(tmp_fp);
570: tmp_fp = fopen(source_file, "r");
571: to_remove = source_file;
572: } else {
573: failed("mkstemp");
1.1 millert 574: }
1.14 millert 575: }
1.1 millert 576: } else {
1.14 millert 577: /* tic */
578: fprintf(stderr,
579: "%s: File name needed. Usage:\n\t%s %s",
580: _nc_progname,
581: _nc_progname,
582: usage_string);
583: cleanup();
584: return EXIT_FAILURE;
1.1 millert 585: }
1.14 millert 586: }
587:
588: if (tmp_fp == 0
589: && (tmp_fp = fopen(source_file, "r")) == 0) {
590: fprintf(stderr, "%s: Can't open %s\n", _nc_progname, source_file);
591: return EXIT_FAILURE;
592: }
1.1 millert 593:
1.14 millert 594: if (infodump)
595: dump_init(tversion,
596: smart_defaults
597: ? outform
598: : F_LITERAL,
599: sortmode, width, debug_level, formatted);
600: else if (capdump)
601: dump_init(tversion,
602: outform,
603: sortmode, width, debug_level, FALSE);
1.1 millert 604:
1.14 millert 605: /* parse entries out of the source file */
606: _nc_set_source(source_file);
1.1 millert 607: #ifndef HAVE_BIG_CORE
1.14 millert 608: if (!(check_only || infodump || capdump))
609: _nc_set_writedir(outdir);
1.1 millert 610: #endif /* HAVE_BIG_CORE */
1.14 millert 611: _nc_read_entry_source(tmp_fp, (char *) NULL,
612: !smart_defaults, FALSE,
613: (check_only || infodump || capdump) ? NULLHOOK : immedhook);
614:
615: /* do use resolution */
616: if (check_only || (!infodump && !capdump) || forceresolve) {
617: if (!_nc_resolve_uses() && !check_only) {
618: cleanup();
619: return EXIT_FAILURE;
620: }
621: }
1.1 millert 622:
1.14 millert 623: /* length check */
624: if (check_only && (capdump || infodump)) {
625: for_entry_list(qp) {
626: if (matches(namelst, qp->tterm.term_names)) {
627: int len = fmt_entry(&qp->tterm, NULL, TRUE, infodump, numbers);
628:
629: if (len > (infodump ? MAX_TERMINFO_LENGTH : MAX_TERMCAP_LENGTH))
630: (void) fprintf(stderr,
631: "warning: resolved %s entry is %d bytes long\n",
632: _nc_first_name(qp->tterm.term_names),
633: len);
1.2 millert 634: }
635: }
1.14 millert 636: }
1.1 millert 637:
1.14 millert 638: /* write or dump all entries */
639: if (!check_only) {
640: if (!infodump && !capdump) {
641: _nc_set_writedir(outdir);
1.1 millert 642: for_entry_list(qp)
643: if (matches(namelst, qp->tterm.term_names))
1.14 millert 644: write_it(qp);
645: } else {
646: /* this is in case infotocap() generates warnings */
647: _nc_curr_col = _nc_curr_line = -1;
1.1 millert 648:
1.14 millert 649: for_entry_list(qp) {
650: if (matches(namelst, qp->tterm.term_names)) {
651: int j = qp->cend - qp->cstart;
652: int len = 0;
653:
654: /* this is in case infotocap() generates warnings */
655: _nc_set_type(_nc_first_name(qp->tterm.term_names));
656:
657: (void) fseek(tmp_fp, qp->cstart, SEEK_SET);
658: while (j--) {
659: if (infodump)
660: (void) putchar(fgetc(tmp_fp));
661: else
662: put_translate(fgetc(tmp_fp));
663: }
664:
665: len = dump_entry(&qp->tterm, limited, numbers, NULL);
666: for (j = 0; j < qp->nuses; j++)
667: len += dump_uses((char *) (qp->uses[j].parent), !capdump);
668: (void) putchar('\n');
669: if (debug_level != 0 && !limited)
670: printf("# length=%d\n", len);
1.1 millert 671: }
672: }
1.14 millert 673: if (!namelst) {
674: int c, oldc = '\0';
675: bool in_comment = FALSE;
676: bool trailing_comment = FALSE;
677:
678: (void) fseek(tmp_fp, _nc_tail->cend, SEEK_SET);
679: while ((c = fgetc(tmp_fp)) != EOF) {
680: if (oldc == '\n') {
681: if (c == '#') {
682: trailing_comment = TRUE;
683: in_comment = TRUE;
684: } else {
685: in_comment = FALSE;
1.1 millert 686: }
687: }
1.14 millert 688: if (trailing_comment
689: && (in_comment || (oldc == '\n' && c == '\n')))
690: putchar(c);
691: oldc = c;
1.1 millert 692: }
693: }
694: }
1.14 millert 695: }
1.1 millert 696:
1.14 millert 697: /* Show the directory into which entries were written, and the total
698: * number of entries
699: */
700: if (showsummary
701: && (!(check_only || infodump || capdump))) {
702: int total = _nc_tic_written();
703: if (total != 0)
704: fprintf(log_fp, "%d entries written to %s\n",
705: total,
706: _nc_tic_dir((char *) 0));
707: else
708: fprintf(log_fp, "No entries written\n");
709: }
710: cleanup();
711: return (EXIT_SUCCESS);
1.6 millert 712: }
713:
714: /*
715: * This bit of legerdemain turns all the terminfo variable names into
716: * references to locations in the arrays Booleans, Numbers, and Strings ---
717: * precisely what's needed (see comp_parse.c).
718: */
1.9 millert 719:
1.14 millert 720: TERMINAL *cur_term; /* tweak to avoid linking lib_cur_term.c */
1.6 millert 721:
722: #undef CUR
723: #define CUR tp->
724:
725: /* other sanity-checks (things that we don't want in the normal
726: * logic that reads a terminfo entry)
727: */
1.14 millert 728: static void
729: check_termtype(TERMTYPE * tp)
1.6 millert 730: {
1.14 millert 731: bool conflict = FALSE;
732: unsigned j, k;
733: char fkeys[STRCOUNT];
734:
735: /*
736: * A terminal entry may contain more than one keycode assigned to
737: * a given string (e.g., KEY_END and KEY_LL). But curses will only
738: * return one (the last one assigned).
739: */
740: memset(fkeys, 0, sizeof(fkeys));
741: for (j = 0; _nc_tinfo_fkeys[j].code; j++) {
742: char *a = tp->Strings[_nc_tinfo_fkeys[j].offset];
743: bool first = TRUE;
744: if (!VALID_STRING(a))
745: continue;
746: for (k = j + 1; _nc_tinfo_fkeys[k].code; k++) {
747: char *b = tp->Strings[_nc_tinfo_fkeys[k].offset];
748: if (!VALID_STRING(b)
749: || fkeys[k])
1.6 millert 750: continue;
1.14 millert 751: if (!strcmp(a, b)) {
752: fkeys[j] = 1;
753: fkeys[k] = 1;
754: if (first) {
755: if (!conflict) {
756: _nc_warning("Conflicting key definitions (using the last)");
757: conflict = TRUE;
1.6 millert 758: }
1.14 millert 759: fprintf(stderr, "... %s is the same as %s",
760: keyname(_nc_tinfo_fkeys[j].code),
761: keyname(_nc_tinfo_fkeys[k].code));
762: first = FALSE;
763: } else {
764: fprintf(stderr, ", %s",
765: keyname(_nc_tinfo_fkeys[k].code));
1.6 millert 766: }
767: }
768: }
1.14 millert 769: if (!first)
770: fprintf(stderr, "\n");
771: }
772:
773: /*
774: * Quick check for color. We could also check if the ANSI versus
775: * non-ANSI strings are misused.
776: */
777: if ((max_colors > 0) != (max_pairs > 0)
778: || (max_colors > max_pairs))
779: _nc_warning("inconsistent values for max_colors and max_pairs");
780:
781: PAIRED(set_foreground, set_background)
782: PAIRED(set_a_foreground, set_a_background)
1.6 millert 783:
1.14 millert 784: /*
785: * These may be mismatched because the terminal description relies on
786: * restoring the cursor visibility by resetting it.
787: */
788: ANDMISSING(cursor_invisible, cursor_normal)
789: ANDMISSING(cursor_visible, cursor_normal)
790:
791: /*
792: * From XSI & O'Reilly, we gather that sc/rc are required if csr is
793: * given, because the cursor position after the scrolling operation is
794: * performed is undefined.
795: */
796: ANDMISSING(change_scroll_region, save_cursor)
797: ANDMISSING(change_scroll_region, restore_cursor)
798:
799: /*
800: * Some standard applications (e.g., vi) and some non-curses
801: * applications (e.g., jove) get confused if we have both ich/ich1 and
802: * smir/rmir. Let's be nice and warn about that, too, even though
803: * ncurses handles it.
804: */
1.6 millert 805: if ((PRESENT(enter_insert_mode) || PRESENT(exit_insert_mode))
1.14 millert 806: && (PRESENT(insert_character) || PRESENT(parm_ich))) {
807: _nc_warning("non-curses applications may be confused by ich/ich1 with smir/rmir");
808: }
1.6 millert 809:
1.14 millert 810: /*
811: * Finally, do the non-verbose checks
812: */
813: if (save_check_termtype != 0)
814: save_check_termtype(tp);
1.1 millert 815: }