]> ncurses.scripts.mit.edu Git - ncurses.git/blob - progs/infocmp.c
ncurses 5.1
[ncurses.git] / progs / infocmp.c
1 /****************************************************************************
2  * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
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  *      infocmp.c -- decompile an entry, or compare two entries
36  *              written by Eric S. Raymond
37  */
38
39 #include <progs.priv.h>
40
41 #include <term_entry.h>
42 #include <dump_entry.h>
43
44 MODULE_ID("$Id: infocmp.c,v 1.54 2000/03/19 02:56:14 tom Exp $")
45
46 #define L_CURL "{"
47 #define R_CURL "}"
48
49 #define MAXTERMS        32      /* max # terminal arguments we can handle */
50 #define MAX_STRING      1024    /* maximum formatted string */
51
52 const char *_nc_progname = "infocmp";
53
54 typedef char path[PATH_MAX];
55
56 /***************************************************************************
57  *
58  * The following control variables, together with the contents of the
59  * terminfo entries, completely determine the actions of the program.
60  *
61  ***************************************************************************/
62
63 static char *tname[MAXTERMS];   /* terminal type names */
64 static ENTRY entries[MAXTERMS]; /* terminfo entries */
65 static int termcount;           /* count of terminal entries */
66
67 static bool limited = TRUE;     /* "-r" option is not set */
68 static bool quiet = FALSE;
69 static const char *bool_sep = ":";
70 static const char *s_absent = "NULL";
71 static const char *s_cancel = "NULL";
72 static const char *tversion;    /* terminfo version selected */
73 static int itrace;              /* trace flag for debugging */
74 static int mwidth = 60;
75 static int numbers = 0;         /* format "%'char'" to/from "%{number}" */
76 static int outform = F_TERMINFO;/* output format */
77 static int sortmode;            /* sort_mode */
78
79 /* main comparison mode */
80 static int compare;
81 #define C_DEFAULT       0       /* don't force comparison mode */
82 #define C_DIFFERENCE    1       /* list differences between two terminals */
83 #define C_COMMON        2       /* list common capabilities */
84 #define C_NAND          3       /* list capabilities in neither terminal */
85 #define C_USEALL        4       /* generate relative use-form entry */
86 static bool ignorepads;         /* ignore pad prefixes when diffing */
87
88 #if NO_LEAKS
89 #undef ExitProgram
90 static void
91 ExitProgram(int code) GCC_NORETURN;
92 /* prototype is to get gcc to accept the noreturn attribute */
93 static void
94 ExitProgram(int code)
95 {
96     while (termcount-- > 0)
97         _nc_free_termtype(&entries[termcount].tterm);
98     _nc_leaks_dump_entry();
99     _nc_free_and_exit(code);
100 }
101 #endif
102
103 static char *
104 canonical_name(char *ptr, char *buf)
105 /* extract the terminal type's primary name */
106 {
107     char *bp;
108
109     (void) strcpy(buf, ptr);
110     if ((bp = strchr(buf, '|')) != 0)
111         *bp = '\0';
112
113     return (buf);
114 }
115
116 /***************************************************************************
117  *
118  * Predicates for dump function
119  *
120  ***************************************************************************/
121
122 static int
123 capcmp(int idx, const char *s, const char *t)
124 /* capability comparison function */
125 {
126     if (!VALID_STRING(s) && !VALID_STRING(t))
127         return (s != t);
128     else if (!VALID_STRING(s) || !VALID_STRING(t))
129         return (1);
130
131     if ((idx == acs_chars_index) || !ignorepads)
132         return (strcmp(s, t));
133     else
134         return (_nc_capcmp(s, t));
135 }
136
137 static int
138 use_predicate(int type, int idx)
139 /* predicate function to use for use decompilation */
140 {
141     ENTRY *ep;
142
143     switch (type) {
144     case BOOLEAN:
145         {
146             int is_set = FALSE;
147
148             /*
149              * This assumes that multiple use entries are supposed
150              * to contribute the logical or of their boolean capabilities.
151              * This is true if we take the semantics of multiple uses to
152              * be 'each capability gets the first non-default value found
153              * in the sequence of use entries'.
154              *
155              * Note that cancelled or absent booleans are stored as FALSE,
156              * unlike numbers and strings, whose cancelled/absent state is
157              * recorded in the terminfo database.
158              */
159             for (ep = &entries[1]; ep < entries + termcount; ep++)
160                 if (ep->tterm.Booleans[idx] == TRUE) {
161                     is_set = entries[0].tterm.Booleans[idx];
162                     break;
163                 }
164             if (is_set != entries[0].tterm.Booleans[idx])
165                 return (!is_set);
166             else
167                 return (FAIL);
168         }
169
170     case NUMBER:
171         {
172             int value = ABSENT_NUMERIC;
173
174             /*
175              * We take the semantics of multiple uses to be 'each
176              * capability gets the first non-default value found
177              * in the sequence of use entries'.
178              */
179             for (ep = &entries[1]; ep < entries + termcount; ep++)
180                 if (VALID_NUMERIC(ep->tterm.Numbers[idx])) {
181                     value = ep->tterm.Numbers[idx];
182                     break;
183                 }
184
185             if (value != entries[0].tterm.Numbers[idx])
186                 return (value != ABSENT_NUMERIC);
187             else
188                 return (FAIL);
189         }
190
191     case STRING:
192         {
193             char *termstr, *usestr = ABSENT_STRING;
194
195             termstr = entries[0].tterm.Strings[idx];
196
197             /*
198              * We take the semantics of multiple uses to be 'each
199              * capability gets the first non-default value found
200              * in the sequence of use entries'.
201              */
202             for (ep = &entries[1]; ep < entries + termcount; ep++)
203                 if (ep->tterm.Strings[idx]) {
204                     usestr = ep->tterm.Strings[idx];
205                     break;
206                 }
207
208             if (usestr == ABSENT_STRING && termstr == ABSENT_STRING)
209                 return (FAIL);
210             else if (!usestr || !termstr || capcmp(idx, usestr, termstr))
211                 return (TRUE);
212             else
213                 return (FAIL);
214         }
215     }
216
217     return (FALSE);             /* pacify compiler */
218 }
219
220 static bool
221 useeq(ENTRY * e1, ENTRY * e2)
222 /* are the use references in two entries equivalent? */
223 {
224     int i, j;
225
226     if (e1->nuses != e2->nuses)
227         return (FALSE);
228
229     /* Ugh...this is quadratic again */
230     for (i = 0; i < e1->nuses; i++) {
231         bool foundmatch = FALSE;
232
233         /* search second entry for given use reference */
234         for (j = 0; j < e2->nuses; j++)
235             if (!strcmp(e1->uses[i].name, e2->uses[j].name)) {
236                 foundmatch = TRUE;
237                 break;
238             }
239
240         if (!foundmatch)
241             return (FALSE);
242     }
243
244     return (TRUE);
245 }
246
247 static bool
248 entryeq(TERMTYPE * t1, TERMTYPE * t2)
249 /* are two entries equivalent? */
250 {
251     int i;
252
253     for (i = 0; i < NUM_BOOLEANS(t1); i++)
254         if (t1->Booleans[i] != t2->Booleans[i])
255             return (FALSE);
256
257     for (i = 0; i < NUM_NUMBERS(t1); i++)
258         if (t1->Numbers[i] != t2->Numbers[i])
259             return (FALSE);
260
261     for (i = 0; i < NUM_STRINGS(t1); i++)
262         if (capcmp(i, t1->Strings[i], t2->Strings[i]))
263             return (FALSE);
264
265     return (TRUE);
266 }
267
268 #define TIC_EXPAND(result) _nc_tic_expand(result, outform==F_TERMINFO, numbers)
269
270 static void
271 print_uses(ENTRY * ep, FILE * fp)
272 /* print an entry's use references */
273 {
274     int i;
275
276     if (!ep->nuses)
277         fputs("NULL", fp);
278     else
279         for (i = 0; i < ep->nuses; i++) {
280             fputs(ep->uses[i].name, fp);
281             if (i < ep->nuses - 1)
282                 fputs(" ", fp);
283         }
284 }
285
286 static const char *
287 dump_boolean(int val)
288 /* display the value of a boolean capability */
289 {
290     switch (val) {
291     case ABSENT_BOOLEAN:
292         return (s_absent);
293     case CANCELLED_BOOLEAN:
294         return (s_cancel);
295     case FALSE:
296         return ("F");
297     case TRUE:
298         return ("T");
299     default:
300         return ("?");
301     }
302 }
303
304 static void
305 dump_numeric(int val, char *buf)
306 /* display the value of a boolean capability */
307 {
308     switch (val) {
309     case ABSENT_NUMERIC:
310         strcpy(buf, s_absent);
311         break;
312     case CANCELLED_NUMERIC:
313         strcpy(buf, s_cancel);
314         break;
315     default:
316         sprintf(buf, "%d", val);
317         break;
318     }
319 }
320
321 static void
322 dump_string(char *val, char *buf)
323 /* display the value of a string capability */
324 {
325     if (val == ABSENT_STRING)
326         strcpy(buf, s_absent);
327     else if (val == CANCELLED_STRING)
328         strcpy(buf, s_cancel);
329     else {
330         sprintf(buf, "'%.*s'", MAX_STRING - 3, TIC_EXPAND(val));
331     }
332 }
333
334 static void
335 compare_predicate(int type, int idx, const char *name)
336 /* predicate function to use for entry difference reports */
337 {
338     register ENTRY *e1 = &entries[0];
339     register ENTRY *e2 = &entries[1];
340     char buf1[MAX_STRING], buf2[MAX_STRING];
341     int b1, b2;
342     int n1, n2;
343     char *s1, *s2;
344
345     switch (type) {
346     case CMP_BOOLEAN:
347         b1 = e1->tterm.Booleans[idx];
348         b2 = e2->tterm.Booleans[idx];
349         switch (compare) {
350         case C_DIFFERENCE:
351             if (!(b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN) && b1 != b2)
352                 (void) printf("\t%s: %s%s%s.\n",
353                     name,
354                     dump_boolean(b1),
355                     bool_sep,
356                     dump_boolean(b2));
357             break;
358
359         case C_COMMON:
360             if (b1 == b2 && b1 != ABSENT_BOOLEAN)
361                 (void) printf("\t%s= %s.\n", name, dump_boolean(b1));
362             break;
363
364         case C_NAND:
365             if (b1 == ABSENT_BOOLEAN && b2 == ABSENT_BOOLEAN)
366                 (void) printf("\t!%s.\n", name);
367             break;
368         }
369         break;
370
371     case CMP_NUMBER:
372         n1 = e1->tterm.Numbers[idx];
373         n2 = e2->tterm.Numbers[idx];
374         dump_numeric(n1, buf1);
375         dump_numeric(n2, buf2);
376         switch (compare) {
377         case C_DIFFERENCE:
378             if (!((n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)) && n1 != n2)
379                 (void) printf("\t%s: %s, %s.\n", name, buf1, buf2);
380             break;
381
382         case C_COMMON:
383             if (n1 != ABSENT_NUMERIC && n2 != ABSENT_NUMERIC && n1 == n2)
384                 (void) printf("\t%s= %s.\n", name, buf1);
385             break;
386
387         case C_NAND:
388             if (n1 == ABSENT_NUMERIC && n2 == ABSENT_NUMERIC)
389                 (void) printf("\t!%s.\n", name);
390             break;
391         }
392         break;
393
394     case CMP_STRING:
395         s1 = e1->tterm.Strings[idx];
396         s2 = e2->tterm.Strings[idx];
397         switch (compare) {
398         case C_DIFFERENCE:
399             if (capcmp(idx, s1, s2)) {
400                 dump_string(s1, buf1);
401                 dump_string(s2, buf2);
402                 if (strcmp(buf1, buf2))
403                     (void) printf("\t%s: %s, %s.\n", name, buf1, buf2);
404             }
405             break;
406
407         case C_COMMON:
408             if (s1 && s2 && !capcmp(idx, s1, s2))
409                 (void) printf("\t%s= '%s'.\n", name, TIC_EXPAND(s1));
410             break;
411
412         case C_NAND:
413             if (!s1 && !s2)
414                 (void) printf("\t!%s.\n", name);
415             break;
416         }
417         break;
418
419     case CMP_USE:
420         /* unlike the other modes, this compares *all* use entries */
421         switch (compare) {
422         case C_DIFFERENCE:
423             if (!useeq(e1, e2)) {
424                 (void) fputs("\tuse: ", stdout);
425                 print_uses(e1, stdout);
426                 fputs(", ", stdout);
427                 print_uses(e2, stdout);
428                 fputs(".\n", stdout);
429             }
430             break;
431
432         case C_COMMON:
433             if (e1->nuses && e2->nuses && useeq(e1, e2)) {
434                 (void) fputs("\tuse: ", stdout);
435                 print_uses(e1, stdout);
436                 fputs(".\n", stdout);
437             }
438             break;
439
440         case C_NAND:
441             if (!e1->nuses && !e2->nuses)
442                 (void) printf("\t!use.\n");
443             break;
444         }
445     }
446 }
447
448 /***************************************************************************
449  *
450  * Init string analysis
451  *
452  ***************************************************************************/
453
454 typedef struct {
455     const char *from;
456     const char *to;
457 } assoc;
458
459 static const assoc std_caps[] =
460 {
461     /* these are specified by X.364 and iBCS2 */
462     {"\033c", "RIS"},           /* full reset */
463     {"\0337", "SC"},            /* save cursor */
464     {"\0338", "RC"},            /* restore cursor */
465     {"\033[r", "RSR"},          /* not an X.364 mnemonic */
466     {"\033[m", "SGR0"},         /* not an X.364 mnemonic */
467     {"\033[2J", "ED2"},         /* clear page */
468
469     /* this group is specified by ISO 2022 */
470     {"\033(0", "ISO DEC G0"},   /* enable DEC graphics for G0 */
471     {"\033(A", "ISO UK G0"},    /* enable UK chars for G0 */
472     {"\033(B", "ISO US G0"},    /* enable US chars for G0 */
473     {"\033)0", "ISO DEC G1"},   /* enable DEC graphics for G1 */
474     {"\033)A", "ISO UK G1"},    /* enable UK chars for G1 */
475     {"\033)B", "ISO US G1"},    /* enable US chars for G1 */
476
477     /* these are DEC private modes widely supported by emulators */
478     {"\033=", "DECPAM"},        /* application keypad mode */
479     {"\033>", "DECPNM"},        /* normal keypad mode */
480     {"\033<", "DECANSI"},       /* enter ANSI mode */
481
482     {(char *) 0, (char *) 0}
483 };
484
485 static const assoc private_modes[] =
486 /* DEC \E[ ... [hl] modes recognized by many emulators */
487 {
488     {"1", "CKM"},               /* application cursor keys */
489     {"2", "ANM"},               /* set VT52 mode */
490     {"3", "COLM"},              /* 132-column mode */
491     {"4", "SCLM"},              /* smooth scroll */
492     {"5", "SCNM"},              /* reverse video mode */
493     {"6", "OM"},                /* origin mode */
494     {"7", "AWM"},               /* wraparound mode */
495     {"8", "ARM"},               /* auto-repeat mode */
496     {(char *) 0, (char *) 0}
497 };
498
499 static const assoc ecma_highlights[] =
500 /* recognize ECMA attribute sequences */
501 {
502     {"0", "NORMAL"},            /* normal */
503     {"1", "+BOLD"},             /* bold on */
504     {"2", "+DIM"},              /* dim on */
505     {"3", "+ITALIC"},           /* italic on */
506     {"4", "+UNDERLINE"},        /* underline on */
507     {"5", "+BLINK"},            /* blink on */
508     {"6", "+FASTBLINK"},        /* fastblink on */
509     {"7", "+REVERSE"},          /* reverse on */
510     {"8", "+INVISIBLE"},        /* invisible on */
511     {"9", "+DELETED"},          /* deleted on */
512     {"10", "MAIN-FONT"},        /* select primary font */
513     {"11", "ALT-FONT-1"},       /* select alternate font 1 */
514     {"12", "ALT-FONT-2"},       /* select alternate font 2 */
515     {"13", "ALT-FONT-3"},       /* select alternate font 3 */
516     {"14", "ALT-FONT-4"},       /* select alternate font 4 */
517     {"15", "ALT-FONT-5"},       /* select alternate font 5 */
518     {"16", "ALT-FONT-6"},       /* select alternate font 6 */
519     {"17", "ALT-FONT-7"},       /* select alternate font 7 */
520     {"18", "ALT-FONT-1"},       /* select alternate font 1 */
521     {"19", "ALT-FONT-1"},       /* select alternate font 1 */
522     {"20", "FRAKTUR"},          /* Fraktur font */
523     {"21", "DOUBLEUNDER"},      /* double underline */
524     {"22", "-DIM"},             /* dim off */
525     {"23", "-ITALIC"},          /* italic off */
526     {"24", "-UNDERLINE"},       /* underline off */
527     {"25", "-BLINK"},           /* blink off */
528     {"26", "-FASTBLINK"},       /* fastblink off */
529     {"27", "-REVERSE"},         /* reverse off */
530     {"28", "-INVISIBLE"},       /* invisible off */
531     {"29", "-DELETED"},         /* deleted off */
532     {(char *) 0, (char *) 0}
533 };
534
535 static void
536 analyze_string(const char *name, const char *cap, TERMTYPE * tp)
537 {
538     char buf[MAX_TERMINFO_LENGTH];
539     char buf2[MAX_TERMINFO_LENGTH];
540     const char *sp, *ep;
541     const assoc *ap;
542
543     if (cap == ABSENT_STRING || cap == CANCELLED_STRING)
544         return;
545     (void) printf("%s: ", name);
546
547     buf[0] = '\0';
548     for (sp = cap; *sp; sp++) {
549         int i;
550         size_t len = 0;
551         const char *expansion = 0;
552
553         /* first, check other capabilities in this entry */
554         for (i = 0; i < STRCOUNT; i++) {
555             char *cp = tp->Strings[i];
556
557             /* don't use soft-key capabilities */
558             if (strnames[i][0] == 'k' && strnames[i][0] == 'f')
559                 continue;
560
561             if (cp != ABSENT_STRING && cp != CANCELLED_STRING && cp[0] && cp
562                 != cap) {
563                 len = strlen(cp);
564                 (void) strncpy(buf2, sp, len);
565                 buf2[len] = '\0';
566
567                 if (_nc_capcmp(cp, buf2))
568                     continue;
569
570 #define ISRS(s) (!strncmp((s), "is", 2) || !strncmp((s), "rs", 2))
571                 /*
572                  * Theoretically we just passed the test for translation
573                  * (equality once the padding is stripped).  However, there
574                  * are a few more hoops that need to be jumped so that
575                  * identical pairs of initialization and reset strings
576                  * don't just refer to each other.
577                  */
578                 if (ISRS(name) || ISRS(strnames[i]))
579                     if (cap < cp)
580                         continue;
581 #undef ISRS
582
583                 expansion = strnames[i];
584                 break;
585             }
586         }
587
588         /* now check the standard capabilities */
589         if (!expansion)
590             for (ap = std_caps; ap->from; ap++) {
591                 len = strlen(ap->from);
592
593                 if (strncmp(ap->from, sp, len) == 0) {
594                     expansion = ap->to;
595                     break;
596                 }
597             }
598
599         /* now check for private-mode sequences */
600         if (!expansion
601             && sp[0] == '\033' && sp[1] == '[' && sp[2] == '?'
602             && (len = strspn(sp + 3, "0123456789;"))
603             && ((sp[3 + len] == 'h') || (sp[3 + len] == 'l'))) {
604             char buf3[MAX_TERMINFO_LENGTH];
605
606             (void) strcpy(buf2, (sp[3 + len] == 'h') ? "DEC+" : "DEC-");
607             (void) strncpy(buf3, sp + 3, len);
608             len += 4;
609             buf3[len] = '\0';
610
611             ep = strtok(buf3, ";");
612             do {
613                 bool found = FALSE;
614
615                 for (ap = private_modes; ap->from; ap++) {
616                     size_t tlen = strlen(ap->from);
617
618                     if (strncmp(ap->from, ep, tlen) == 0) {
619                         (void) strcat(buf2, ap->to);
620                         found = TRUE;
621                         break;
622                     }
623                 }
624
625                 if (!found)
626                     (void) strcat(buf2, ep);
627                 (void) strcat(buf2, ";");
628             } while
629                 ((ep = strtok((char *) 0, ";")));
630             buf2[strlen(buf2) - 1] = '\0';
631             expansion = buf2;
632         }
633
634         /* now check for ECMA highlight sequences */
635         if (!expansion
636             && sp[0] == '\033' && sp[1] == '['
637             && (len = strspn(sp + 2, "0123456789;"))
638             && sp[2 + len] == 'm') {
639             char buf3[MAX_TERMINFO_LENGTH];
640
641             (void) strcpy(buf2, "SGR:");
642             (void) strncpy(buf3, sp + 2, len);
643             len += 3;
644             buf3[len] = '\0';
645
646             ep = strtok(buf3, ";");
647             do {
648                 bool found = FALSE;
649
650                 for (ap = ecma_highlights; ap->from; ap++) {
651                     size_t tlen = strlen(ap->from);
652
653                     if (strncmp(ap->from, ep, tlen) == 0) {
654                         (void) strcat(buf2, ap->to);
655                         found = TRUE;
656                         break;
657                     }
658                 }
659
660                 if (!found)
661                     (void) strcat(buf2, ep);
662                 (void) strcat(buf2, ";");
663             } while
664                 ((ep = strtok((char *) 0, ";")));
665
666             buf2[strlen(buf2) - 1] = '\0';
667             expansion = buf2;
668         }
669         /* now check for scroll region reset */
670         if (!expansion) {
671             (void) sprintf(buf2, "\033[1;%dr", tp->Numbers[2]);
672             len = strlen(buf2);
673             if (strncmp(buf2, sp, len) == 0)
674                 expansion = "RSR";
675         }
676
677         /* now check for home-down */
678         if (!expansion) {
679             (void) sprintf(buf2, "\033[%d;1H", tp->Numbers[2]);
680             len = strlen(buf2);
681             if (strncmp(buf2, sp, len) == 0)
682                 expansion = "LL";
683         }
684
685         /* now look at the expansion we got, if any */
686         if (expansion) {
687             (void) sprintf(buf + strlen(buf), "{%s}", expansion);
688             sp += len - 1;
689             continue;
690         } else {
691             /* couldn't match anything */
692             buf2[0] = *sp;
693             buf2[1] = '\0';
694             (void) strcat(buf, TIC_EXPAND(buf2));
695         }
696     }
697     (void) printf("%s\n", buf);
698 }
699
700 /***************************************************************************
701  *
702  * File comparison
703  *
704  ***************************************************************************/
705
706 static void
707 file_comparison(int argc, char *argv[])
708 {
709 #define MAXCOMPARE      2
710     /* someday we may allow comparisons on more files */
711     int filecount = 0;
712     ENTRY *heads[MAXCOMPARE];
713     ENTRY *tails[MAXCOMPARE];
714     ENTRY *qp, *rp;
715     int i, n;
716
717     dump_init((char *) 0, F_LITERAL, S_TERMINFO, 0, itrace, FALSE);
718
719     for (n = 0; n < argc && n < MAXCOMPARE; n++) {
720         if (freopen(argv[n], "r", stdin) == 0)
721             _nc_err_abort("Can't open %s", argv[n]);
722
723         _nc_head = _nc_tail = 0;
724
725         /* parse entries out of the source file */
726         _nc_set_source(argv[n]);
727         _nc_read_entry_source(stdin, NULL, TRUE, FALSE, NULLHOOK);
728
729         if (itrace)
730             (void) fprintf(stderr, "Resolving file %d...\n", n - 0);
731
732         /* maybe do use resolution */
733         if (!_nc_resolve_uses(!limited)) {
734             (void) fprintf(stderr,
735                 "There are unresolved use entries in %s:\n",
736                 argv[n]);
737             for_entry_list(qp) {
738                 if (qp->nuses) {
739                     (void) fputs(qp->tterm.term_names, stderr);
740                     (void) fputc('\n', stderr);
741                 }
742             }
743             exit(EXIT_FAILURE);
744         }
745
746         heads[filecount] = _nc_head;
747         tails[filecount] = _nc_tail;
748         filecount++;
749     }
750
751     /* OK, all entries are in core.  Ready to do the comparison */
752     if (itrace)
753         (void) fprintf(stderr, "Entries are now in core...\n");
754
755     /* The entry-matching loop. Sigh, this is intrinsically quadratic. */
756     for (qp = heads[0]; qp; qp = qp->next) {
757         for (rp = heads[1]; rp; rp = rp->next)
758             if (_nc_entry_match(qp->tterm.term_names, rp->tterm.term_names)) {
759                 if (qp->ncrosslinks < MAX_CROSSLINKS)
760                     qp->crosslinks[qp->ncrosslinks] = rp;
761                 qp->ncrosslinks++;
762
763                 if (rp->ncrosslinks < MAX_CROSSLINKS)
764                     rp->crosslinks[rp->ncrosslinks] = qp;
765                 rp->ncrosslinks++;
766             }
767     }
768
769     /* now we have two circular lists with crosslinks */
770     if (itrace)
771         (void) fprintf(stderr, "Name matches are done...\n");
772
773     for (qp = heads[0]; qp; qp = qp->next) {
774         if (qp->ncrosslinks > 1) {
775             (void) fprintf(stderr,
776                 "%s in file 1 (%s) has %d matches in file 2 (%s):\n",
777                 _nc_first_name(qp->tterm.term_names),
778                 argv[0],
779                 qp->ncrosslinks,
780                 argv[1]);
781             for (i = 0; i < qp->ncrosslinks; i++)
782                 (void) fprintf(stderr,
783                     "\t%s\n",
784                     _nc_first_name((qp->crosslinks[i])->tterm.term_names));
785         }
786     }
787
788     for (rp = heads[1]; rp; rp = rp->next) {
789         if (rp->ncrosslinks > 1) {
790             (void) fprintf(stderr,
791                 "%s in file 2 (%s) has %d matches in file 1 (%s):\n",
792                 _nc_first_name(rp->tterm.term_names),
793                 argv[1],
794                 rp->ncrosslinks,
795                 argv[0]);
796             for (i = 0; i < rp->ncrosslinks; i++)
797                 (void) fprintf(stderr,
798                     "\t%s\n",
799                     _nc_first_name((rp->crosslinks[i])->tterm.term_names));
800         }
801     }
802
803     (void) printf("In file 1 (%s) only:\n", argv[0]);
804     for (qp = heads[0]; qp; qp = qp->next)
805         if (qp->ncrosslinks == 0)
806             (void) printf("\t%s\n",
807                 _nc_first_name(qp->tterm.term_names));
808
809     (void) printf("In file 2 (%s) only:\n", argv[1]);
810     for (rp = heads[1]; rp; rp = rp->next)
811         if (rp->ncrosslinks == 0)
812             (void) printf("\t%s\n",
813                 _nc_first_name(rp->tterm.term_names));
814
815     (void) printf("The following entries are equivalent:\n");
816     for (qp = heads[0]; qp; qp = qp->next) {
817         rp = qp->crosslinks[0];
818
819         if (qp->ncrosslinks == 1) {
820             rp = qp->crosslinks[0];
821
822             repair_acsc(&qp->tterm);
823             repair_acsc(&rp->tterm);
824 #if NCURSES_XNAMES
825             _nc_align_termtype(&qp->tterm, &rp->tterm);
826 #endif
827             if (entryeq(&qp->tterm, &rp->tterm) && useeq(qp, rp)) {
828                 char name1[NAMESIZE], name2[NAMESIZE];
829
830                 (void) canonical_name(qp->tterm.term_names, name1);
831                 (void) canonical_name(rp->tterm.term_names, name2);
832
833                 (void) printf("%s = %s\n", name1, name2);
834             }
835         }
836     }
837
838     (void) printf("Differing entries:\n");
839     termcount = 2;
840     for (qp = heads[0]; qp; qp = qp->next) {
841
842         if (qp->ncrosslinks == 1) {
843             rp = qp->crosslinks[0];
844 #if NCURSES_XNAMES
845             /* sorry - we have to do this on each pass */
846             _nc_align_termtype(&qp->tterm, &rp->tterm);
847 #endif
848             if (!(entryeq(&qp->tterm, &rp->tterm) && useeq(qp, rp))) {
849                 char name1[NAMESIZE], name2[NAMESIZE];
850
851                 entries[0] = *qp;
852                 entries[1] = *rp;
853
854                 (void) canonical_name(qp->tterm.term_names, name1);
855                 (void) canonical_name(rp->tterm.term_names, name2);
856
857                 switch (compare) {
858                 case C_DIFFERENCE:
859                     if (itrace)
860                         (void) fprintf(stderr,
861                             "infocmp: dumping differences\n");
862                     (void) printf("comparing %s to %s.\n", name1, name2);
863                     compare_entry(compare_predicate, &entries->tterm, quiet);
864                     break;
865
866                 case C_COMMON:
867                     if (itrace)
868                         (void) fprintf(stderr,
869                             "infocmp: dumping common capabilities\n");
870                     (void) printf("comparing %s to %s.\n", name1, name2);
871                     compare_entry(compare_predicate, &entries->tterm, quiet);
872                     break;
873
874                 case C_NAND:
875                     if (itrace)
876                         (void) fprintf(stderr,
877                             "infocmp: dumping differences\n");
878                     (void) printf("comparing %s to %s.\n", name1, name2);
879                     compare_entry(compare_predicate, &entries->tterm, quiet);
880                     break;
881
882                 }
883             }
884         }
885     }
886 }
887
888 static void
889 usage(void)
890 {
891     static const char *tbl[] =
892     {
893         "Usage: infocmp [options] [-A directory] [-B directory] [termname...]"
894         ,""
895         ,"Options:"
896         ,"  -1    print single-column"
897         ,"  -C    use termcap-names"
898         ,"  -F    compare terminfo-files"
899         ,"  -I    use terminfo-names"
900         ,"  -L    use long names"
901         ,"  -R subset (see manpage)"
902         ,"  -T    eliminate size limits (test)"
903         ,"  -V    print version"
904 #if NCURSES_XNAMES
905         ,"  -a    with -F, list commented-out caps"
906 #endif
907         ,"  -c    list common capabilities"
908         ,"  -d    list different capabilities"
909         ,"  -e    format output for C initializer"
910         ,"  -E    format output as C tables"
911         ,"  -f    with -1, format complex strings"
912         ,"  -G    format %{number} to %'char'"
913         ,"  -g    format %'char' to %{number}"
914         ,"  -i    analyze initialization/reset"
915         ,"  -l    output terminfo names"
916         ,"  -n    list capabilities in neither"
917         ,"  -p    ignore padding specifiers"
918         ,"  -q    brief listing, removes headers"
919         ,"  -r    with -C, output in termcap form"
920         ,"  -r    with -F, resolve use-references"
921         ,"  -s [d|i|l|c] sort fields"
922         ,"  -u    produce source with 'use='"
923         ,"  -v number  (verbose)"
924         ,"  -w number  (width)"
925     };
926     const size_t first = 3;
927     const size_t last = sizeof(tbl) / sizeof(tbl[0]);
928     const size_t left = (last - first + 1) / 2 + first;
929     size_t n;
930
931     for (n = 0; n < left; n++) {
932         size_t m = (n < first) ? last : n + left - first;
933         if (m < last)
934             fprintf(stderr, "%-40.40s%s\n", tbl[n], tbl[m]);
935         else
936             fprintf(stderr, "%s\n", tbl[n]);
937     }
938     exit(EXIT_FAILURE);
939 }
940
941 static char *
942 name_initializer(const char *type)
943 {
944     static char *initializer;
945     char *s;
946
947     if (initializer == 0)
948         initializer = (char *) malloc(strlen(entries->tterm.term_names) + 20);
949
950     (void) sprintf(initializer, "%s_data_%s", type, entries->tterm.term_names);
951     for (s = initializer; *s != 0 && *s != '|'; s++) {
952         if (!isalnum(*s))
953             *s = '_';
954     }
955     *s = 0;
956     return initializer;
957 }
958
959 /* dump C initializers for the terminal type */
960 static void
961 dump_initializers(TERMTYPE * term)
962 {
963     int n;
964     const char *str = 0;
965     int size;
966
967     (void) printf("static char %s[] = %s\n", name_initializer("bool"), L_CURL);
968
969     for_each_boolean(n, term) {
970         switch ((int) (term->Booleans[n])) {
971         case TRUE:
972             str = "TRUE";
973             break;
974
975         case FALSE:
976             str = "FALSE";
977             break;
978
979         case ABSENT_BOOLEAN:
980             str = "ABSENT_BOOLEAN";
981             break;
982
983         case CANCELLED_BOOLEAN:
984             str = "CANCELLED_BOOLEAN";
985             break;
986         }
987         (void) printf("\t/* %3d: %-8s */\t%s,\n",
988             n, ExtBoolname(term, n, boolnames), str);
989     }
990     (void) printf("%s;\n", R_CURL);
991
992     (void) printf("static short %s[] = %s\n", name_initializer("number"), L_CURL);
993
994     for_each_number(n, term) {
995         char buf[BUFSIZ];
996         switch (term->Numbers[n]) {
997         case ABSENT_NUMERIC:
998             str = "ABSENT_NUMERIC";
999             break;
1000         case CANCELLED_NUMERIC:
1001             str = "CANCELLED_NUMERIC";
1002             break;
1003         default:
1004             sprintf(buf, "%d", term->Numbers[n]);
1005             str = buf;
1006             break;
1007         }
1008         (void) printf("\t/* %3d: %-8s */\t%s,\n", n, ExtNumname(term, n,
1009                 numnames), str);
1010     }
1011     (void) printf("%s;\n", R_CURL);
1012
1013     size = sizeof(TERMTYPE)
1014         + (NUM_BOOLEANS(term) * sizeof(term->Booleans[0]))
1015         + (NUM_NUMBERS(term) * sizeof(term->Numbers[0]));
1016
1017     (void) printf("static char * %s[] = %s\n", name_initializer("string"), L_CURL);
1018
1019     for_each_string(n, term) {
1020         char buf[MAX_STRING], *sp, *tp;
1021
1022         if (term->Strings[n] == ABSENT_STRING)
1023             str = "ABSENT_STRING";
1024         else if (term->Strings[n] == CANCELLED_STRING)
1025             str = "CANCELLED_STRING";
1026         else {
1027             tp = buf;
1028             *tp++ = '"';
1029             for (sp = term->Strings[n];
1030                 *sp != 0 && (tp - buf) < MAX_STRING - 6;
1031                 sp++) {
1032                 if (isascii(*sp) && isprint(*sp) && *sp != '\\' && *sp != '"')
1033                     *tp++ = *sp;
1034                 else {
1035                     (void) sprintf(tp, "\\%03o", *sp & 0xff);
1036                     tp += 4;
1037                 }
1038             }
1039             *tp++ = '"';
1040             *tp = '\0';
1041             size += (strlen(term->Strings[n]) + 1);
1042             str = buf;
1043         }
1044 #if NCURSES_XNAMES
1045         if (n == STRCOUNT) {
1046             (void) printf("%s;\n", R_CURL);
1047
1048             (void) printf("static char * %s[] = %s\n",
1049                 name_initializer("string_ext"), L_CURL);
1050         }
1051 #endif
1052         (void) printf("\t/* %3d: %-8s */\t%s,\n", n, ExtStrname(term, n,
1053                 strnames), str);
1054     }
1055     (void) printf("%s;\n", R_CURL);
1056 }
1057
1058 /* dump C initializers for the terminal type */
1059 static void
1060 dump_termtype(TERMTYPE * term)
1061 {
1062     (void) printf("\t%s\n\t\t\"%s\",\n", L_CURL, term->term_names);
1063     (void) printf("\t\t(char *)0,\t/* pointer to string table */\n");
1064
1065     (void) printf("\t\t%s,\n", name_initializer("bool"));
1066     (void) printf("\t\t%s,\n", name_initializer("number"));
1067
1068     (void) printf("\t\t%s,\n", name_initializer("string"));
1069
1070 #if NCURSES_XNAMES
1071     (void) printf("#if NCURSES_XNAMES\n");
1072     (void) printf("\t\t(char *)0,\t/* pointer to extended string table */\n");
1073     (void) printf("\t\t%s,\t/* ...corresponding names */\n",
1074         (NUM_STRINGS(term) != STRCOUNT)
1075         ? name_initializer("string_ext")
1076         : "(char **)0");
1077
1078     (void) printf("\t\t%d,\t\t/* count total Booleans */\n", NUM_BOOLEANS(term));
1079     (void) printf("\t\t%d,\t\t/* count total Numbers */\n", NUM_NUMBERS(term));
1080     (void) printf("\t\t%d,\t\t/* count total Strings */\n", NUM_STRINGS(term));
1081
1082     (void) printf("\t\t%d,\t\t/* count extensions to Booleans */\n",
1083         NUM_BOOLEANS(term) - BOOLCOUNT);
1084     (void) printf("\t\t%d,\t\t/* count extensions to Numbers */\n",
1085         NUM_NUMBERS(term) - NUMCOUNT);
1086     (void) printf("\t\t%d,\t\t/* count extensions to Strings */\n",
1087         NUM_STRINGS(term) - STRCOUNT);
1088
1089     (void) printf("#endif /* NCURSES_XNAMES */\n");
1090 #endif /* NCURSES_XNAMES */
1091     (void) printf("\t%s\n", R_CURL);
1092 }
1093
1094 /***************************************************************************
1095  *
1096  * Main sequence
1097  *
1098  ***************************************************************************/
1099
1100 int
1101 main(int argc, char *argv[])
1102 {
1103     char *terminal, *firstdir, *restdir;
1104     /* Avoid "local data >32k" error with mwcc */
1105     /* Also avoid overflowing smaller stacks on systems like AmigaOS */
1106     path *tfile = (path *) malloc(sizeof(path) * MAXTERMS);
1107     int c, i, len;
1108     bool formatted = FALSE;
1109     bool filecompare = FALSE;
1110     int initdump = 0;
1111     bool init_analyze = FALSE;
1112
1113     if ((terminal = getenv("TERM")) == 0) {
1114         (void) fprintf(stderr,
1115             "infocmp: environment variable TERM not set\n");
1116         return EXIT_FAILURE;
1117     }
1118
1119     /* where is the terminfo database location going to default to? */
1120     restdir = firstdir = 0;
1121
1122     while ((c = getopt(argc, argv, "adeEcCfFGgIinlLpqrR:s:uv:Vw:A:B:1T")) != EOF)
1123         switch (c) {
1124 #if NCURSES_XNAMES
1125         case 'a':
1126             _nc_disable_period = TRUE;
1127             use_extended_names(TRUE);
1128             break;
1129 #endif
1130         case 'd':
1131             compare = C_DIFFERENCE;
1132             break;
1133
1134         case 'e':
1135             initdump |= 1;
1136             break;
1137
1138         case 'E':
1139             initdump |= 2;
1140             break;
1141
1142         case 'c':
1143             compare = C_COMMON;
1144             break;
1145
1146         case 'C':
1147             outform = F_TERMCAP;
1148             tversion = "BSD";
1149             if (sortmode == S_DEFAULT)
1150                 sortmode = S_TERMCAP;
1151             break;
1152
1153         case 'f':
1154             formatted = TRUE;
1155             break;
1156
1157         case 'G':
1158             numbers = 1;
1159             break;
1160
1161         case 'g':
1162             numbers = -1;
1163             break;
1164
1165         case 'F':
1166             filecompare = TRUE;
1167             break;
1168
1169         case 'I':
1170             outform = F_TERMINFO;
1171             if (sortmode == S_DEFAULT)
1172                 sortmode = S_VARIABLE;
1173             tversion = 0;
1174             break;
1175
1176         case 'i':
1177             init_analyze = TRUE;
1178             break;
1179
1180         case 'l':
1181             outform = F_TERMINFO;
1182             break;
1183
1184         case 'L':
1185             outform = F_VARIABLE;
1186             if (sortmode == S_DEFAULT)
1187                 sortmode = S_VARIABLE;
1188             break;
1189
1190         case 'n':
1191             compare = C_NAND;
1192             break;
1193
1194         case 'p':
1195             ignorepads = TRUE;
1196             break;
1197
1198         case 'q':
1199             quiet = TRUE;
1200             s_absent = "-";
1201             s_cancel = "@";
1202             bool_sep = ", ";
1203             break;
1204
1205         case 'r':
1206             tversion = 0;
1207             limited = FALSE;
1208             break;
1209
1210         case 'R':
1211             tversion = optarg;
1212             break;
1213
1214         case 's':
1215             if (*optarg == 'd')
1216                 sortmode = S_NOSORT;
1217             else if (*optarg == 'i')
1218                 sortmode = S_TERMINFO;
1219             else if (*optarg == 'l')
1220                 sortmode = S_VARIABLE;
1221             else if (*optarg == 'c')
1222                 sortmode = S_TERMCAP;
1223             else {
1224                 (void) fprintf(stderr,
1225                     "infocmp: unknown sort mode\n");
1226                 return EXIT_FAILURE;
1227             }
1228             break;
1229
1230         case 'u':
1231             compare = C_USEALL;
1232             break;
1233
1234         case 'v':
1235             itrace = atoi(optarg);
1236             set_trace_level(itrace);
1237             break;
1238
1239         case 'V':
1240             (void) fputs(NCURSES_VERSION, stdout);
1241             putchar('\n');
1242             ExitProgram(EXIT_SUCCESS);
1243
1244         case 'w':
1245             mwidth = atoi(optarg);
1246             break;
1247
1248         case 'A':
1249             firstdir = optarg;
1250             break;
1251
1252         case 'B':
1253             restdir = optarg;
1254             break;
1255
1256         case '1':
1257             mwidth = 0;
1258             break;
1259
1260         case 'T':
1261             limited = FALSE;
1262             break;
1263         default:
1264             usage();
1265         }
1266
1267     /* by default, sort by terminfo name */
1268     if (sortmode == S_DEFAULT)
1269         sortmode = S_TERMINFO;
1270
1271     /* set up for display */
1272     dump_init(tversion, outform, sortmode, mwidth, itrace, formatted);
1273
1274     /* make sure we have at least one terminal name to work with */
1275     if (optind >= argc)
1276         argv[argc++] = terminal;
1277
1278     /* if user is after a comparison, make sure we have two entries */
1279     if (compare != C_DEFAULT && optind >= argc - 1)
1280         argv[argc++] = terminal;
1281
1282     /* exactly two terminal names with no options means do -d */
1283     if (argc - optind == 2 && compare == C_DEFAULT)
1284         compare = C_DIFFERENCE;
1285
1286     if (!filecompare) {
1287         /* grab the entries */
1288         termcount = 0;
1289         for (; optind < argc; optind++) {
1290             if (termcount >= MAXTERMS) {
1291                 (void) fprintf(stderr,
1292                     "infocmp: too many terminal type arguments\n");
1293                 return EXIT_FAILURE;
1294             } else {
1295                 const char *directory = termcount ? restdir : firstdir;
1296                 int status;
1297
1298                 tname[termcount] = argv[optind];
1299
1300                 if (directory) {
1301                     (void) sprintf(tfile[termcount], "%s/%c/%s",
1302                         directory,
1303                         *argv[optind], argv[optind]);
1304                     if (itrace)
1305                         (void) fprintf(stderr,
1306                             "infocmp: reading entry %s from file %s\n",
1307                             argv[optind], tfile[termcount]);
1308
1309                     status = _nc_read_file_entry(tfile[termcount],
1310                         &entries[termcount].tterm);
1311                 } else {
1312                     if (itrace)
1313                         (void) fprintf(stderr,
1314                             "infocmp: reading entry %s from system directories %s\n",
1315                             argv[optind], tname[termcount]);
1316
1317                     status = _nc_read_entry(tname[termcount],
1318                         tfile[termcount],
1319                         &entries[termcount].tterm);
1320                     directory = TERMINFO;       /* for error message */
1321                 }
1322
1323                 if (status <= 0) {
1324                     (void) fprintf(stderr,
1325                         "infocmp: couldn't open terminfo file %s.\n",
1326                         tfile[termcount]);
1327                     return EXIT_FAILURE;
1328                 }
1329                 repair_acsc(&entries[termcount].tterm);
1330                 termcount++;
1331             }
1332         }
1333
1334 #if NCURSES_XNAMES
1335         if (termcount > 1)
1336             _nc_align_termtype(&entries[0].tterm, &entries[1].tterm);
1337 #endif
1338
1339         /* dump as C initializer for the terminal type */
1340         if (initdump) {
1341             if (initdump & 1)
1342                 dump_termtype(&entries[0].tterm);
1343             if (initdump & 2)
1344                 dump_initializers(&entries[0].tterm);
1345             ExitProgram(EXIT_SUCCESS);
1346         }
1347
1348         /* analyze the init strings */
1349         if (init_analyze) {
1350 #undef CUR
1351 #define CUR     entries[0].tterm.
1352             analyze_string("is1", init_1string, &entries[0].tterm);
1353             analyze_string("is2", init_2string, &entries[0].tterm);
1354             analyze_string("is3", init_3string, &entries[0].tterm);
1355             analyze_string("rs1", reset_1string, &entries[0].tterm);
1356             analyze_string("rs2", reset_2string, &entries[0].tterm);
1357             analyze_string("rs3", reset_3string, &entries[0].tterm);
1358             analyze_string("smcup", enter_ca_mode, &entries[0].tterm);
1359             analyze_string("rmcup", exit_ca_mode, &entries[0].tterm);
1360 #undef CUR
1361             ExitProgram(EXIT_SUCCESS);
1362         }
1363
1364         /*
1365          * Here's where the real work gets done
1366          */
1367         switch (compare) {
1368         case C_DEFAULT:
1369             if (itrace)
1370                 (void) fprintf(stderr,
1371                     "infocmp: about to dump %s\n",
1372                     tname[0]);
1373             (void) printf("#\tReconstructed via infocmp from file: %s\n",
1374                 tfile[0]);
1375             len = dump_entry(&entries[0].tterm, limited, numbers, NULL);
1376             putchar('\n');
1377             if (itrace)
1378                 (void) fprintf(stderr, "infocmp: length %d\n", len);
1379             break;
1380
1381         case C_DIFFERENCE:
1382             if (itrace)
1383                 (void) fprintf(stderr, "infocmp: dumping differences\n");
1384             (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1385             compare_entry(compare_predicate, &entries->tterm, quiet);
1386             break;
1387
1388         case C_COMMON:
1389             if (itrace)
1390                 (void) fprintf(stderr,
1391                     "infocmp: dumping common capabilities\n");
1392             (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1393             compare_entry(compare_predicate, &entries->tterm, quiet);
1394             break;
1395
1396         case C_NAND:
1397             if (itrace)
1398                 (void) fprintf(stderr,
1399                     "infocmp: dumping differences\n");
1400             (void) printf("comparing %s to %s.\n", tname[0], tname[1]);
1401             compare_entry(compare_predicate, &entries->tterm, quiet);
1402             break;
1403
1404         case C_USEALL:
1405             if (itrace)
1406                 (void) fprintf(stderr, "infocmp: dumping use entry\n");
1407             len = dump_entry(&entries[0].tterm, limited, numbers, use_predicate);
1408             for (i = 1; i < termcount; i++)
1409                 len += dump_uses(tname[i], !(outform == F_TERMCAP || outform
1410                         == F_TCONVERR));
1411             putchar('\n');
1412             if (itrace)
1413                 (void) fprintf(stderr, "infocmp: length %d\n", len);
1414             break;
1415         }
1416     } else if (compare == C_USEALL)
1417         (void) fprintf(stderr, "Sorry, -u doesn't work with -F\n");
1418     else if (compare == C_DEFAULT)
1419         (void) fprintf(stderr, "Use `tic -[CI] <file>' for this.\n");
1420     else if (argc - optind != 2)
1421         (void) fprintf(stderr,
1422             "File comparison needs exactly two file arguments.\n");
1423     else
1424         file_comparison(argc - optind, argv + optind);
1425
1426     ExitProgram(EXIT_SUCCESS);
1427 }
1428
1429 /* infocmp.c ends here */