summaryrefslogtreecommitdiffstats
path: root/contrib/ncurses/progs/infocmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/progs/infocmp.c')
-rw-r--r--contrib/ncurses/progs/infocmp.c161
1 files changed, 99 insertions, 62 deletions
diff --git a/contrib/ncurses/progs/infocmp.c b/contrib/ncurses/progs/infocmp.c
index d3353f2..9b74ba0 100644
--- a/contrib/ncurses/progs/infocmp.c
+++ b/contrib/ncurses/progs/infocmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,18 +35,18 @@
/*
* infocmp.c -- decompile an entry, or compare two entries
* written by Eric S. Raymond
+ * and Thomas E Dickey
*/
#include <progs.priv.h>
#include <dump_entry.h>
-MODULE_ID("$Id: infocmp.c,v 1.85 2006/08/19 21:20:37 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.94 2007/11/17 23:34:26 tom Exp $")
#define L_CURL "{"
#define R_CURL "}"
-#define MAXTERMS 32 /* max # terminal arguments we can handle */
#define MAX_STRING 1024 /* maximum formatted string */
const char *_nc_progname = "infocmp";
@@ -60,8 +60,7 @@ typedef char path[PATH_MAX];
*
***************************************************************************/
-static char *tname[MAXTERMS]; /* terminal type names */
-static ENTRY entries[MAXTERMS]; /* terminfo entries */
+static ENTRY *entries; /* terminfo entries */
static int termcount; /* count of terminal entries */
static bool limited = TRUE; /* "-r" option is not set */
@@ -96,7 +95,8 @@ ExitProgram(int code)
while (termcount-- > 0)
_nc_free_termtype(&entries[termcount].tterm);
_nc_leaks_dump_entry();
- _nc_free_and_exit(code);
+ free(entries);
+ _nc_free_tic(code);
}
#endif
@@ -932,7 +932,8 @@ file_comparison(int argc, char *argv[])
case C_DIFFERENCE:
if (itrace)
(void) fprintf(stderr,
- "infocmp: dumping differences\n");
+ "%s: dumping differences\n",
+ _nc_progname);
(void) printf("comparing %s to %s.\n", name1, name2);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -940,7 +941,8 @@ file_comparison(int argc, char *argv[])
case C_COMMON:
if (itrace)
(void) fprintf(stderr,
- "infocmp: dumping common capabilities\n");
+ "%s: dumping common capabilities\n",
+ _nc_progname);
(void) printf("comparing %s to %s.\n", name1, name2);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -948,7 +950,8 @@ file_comparison(int argc, char *argv[])
case C_NAND:
if (itrace)
(void) fprintf(stderr,
- "infocmp: dumping differences\n");
+ "%s: dumping differences\n",
+ _nc_progname);
(void) printf("comparing %s to %s.\n", name1, name2);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -1083,7 +1086,6 @@ dump_initializers(TERMTYPE *term)
}
*tp++ = '"';
*tp = '\0';
- size += (strlen(term->Strings[n]) + 1);
(void) printf("static char %-20s[] = %s;\n",
string_variable(ExtStrname(term, n, strnames)), buf);
}
@@ -1237,7 +1239,8 @@ terminal_env(void)
if ((terminal = getenv("TERM")) == 0) {
(void) fprintf(stderr,
- "infocmp: environment variable TERM not set\n");
+ "%s: environment variable TERM not set\n",
+ _nc_progname);
exit(EXIT_FAILURE);
}
return terminal;
@@ -1252,10 +1255,15 @@ terminal_env(void)
int
main(int argc, char *argv[])
{
- char *firstdir, *restdir;
/* Avoid "local data >32k" error with mwcc */
/* Also avoid overflowing smaller stacks on systems like AmigaOS */
- path *tfile = (path *) malloc(sizeof(path) * MAXTERMS);
+ path *tfile = 0;
+ char **tname = 0;
+ int maxterms;
+
+ char **myargv;
+
+ char *firstdir, *restdir;
int c, i, len;
bool formatted = FALSE;
bool filecompare = FALSE;
@@ -1270,9 +1278,16 @@ main(int argc, char *argv[])
use_extended_names(FALSE);
#endif
+ _nc_progname = _nc_rootname(argv[0]);
+
+ /* make sure we have enough space to add two terminal entries */
+ myargv = typeCalloc(char *, argc + 3);
+ memcpy(myargv, argv, sizeof(char *) * argc);
+ argv = myargv;
+
while ((c = getopt(argc,
argv,
- "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != EOF) {
+ "1A:aB:CcdEeFfGgIiLlnpqR:rs:TtUuVv:w:x")) != -1) {
switch (c) {
case '1':
mwidth = 0;
@@ -1373,7 +1388,6 @@ main(int argc, char *argv[])
case 'r':
tversion = 0;
- limited = FALSE;
break;
case 's':
@@ -1387,7 +1401,8 @@ main(int argc, char *argv[])
sortmode = S_TERMCAP;
else {
(void) fprintf(stderr,
- "infocmp: unknown sort mode\n");
+ "%s: unknown sort mode\n",
+ _nc_progname);
ExitProgram(EXIT_FAILURE);
}
break;
@@ -1435,6 +1450,18 @@ main(int argc, char *argv[])
}
}
+ maxterms = (argc + 1 - optind);
+ tfile = typeMalloc(path, maxterms);
+ tname = typeCalloc(char *, maxterms);
+ entries = typeCalloc(ENTRY, maxterms);
+
+ if (tfile == 0
+ || tname == 0
+ || entries == 0) {
+ fprintf(stderr, "%s: not enough memory\n", _nc_progname);
+ ExitProgram(EXIT_FAILURE);
+ }
+
/* by default, sort by terminfo name */
if (sortmode == S_DEFAULT)
sortmode = S_TERMINFO;
@@ -1458,53 +1485,56 @@ main(int argc, char *argv[])
/* grab the entries */
termcount = 0;
for (; optind < argc; optind++) {
- if (termcount >= MAXTERMS) {
- (void) fprintf(stderr,
- "infocmp: too many terminal type arguments\n");
- ExitProgram(EXIT_FAILURE);
- } else {
- const char *directory = termcount ? restdir : firstdir;
- int status;
+ const char *directory = termcount ? restdir : firstdir;
+ int status;
- tname[termcount] = argv[optind];
+ tname[termcount] = argv[optind];
- if (directory) {
+ if (directory) {
#if USE_DATABASE
- (void) sprintf(tfile[termcount], "%s/%c/%s",
- directory,
- *argv[optind], argv[optind]);
- if (itrace)
- (void) fprintf(stderr,
- "infocmp: reading entry %s from file %s\n",
- argv[optind], tfile[termcount]);
-
- status = _nc_read_file_entry(tfile[termcount],
- &entries[termcount].tterm);
+#if MIXEDCASE_FILENAMES
+#define LEAF_FMT "%c"
#else
- (void) fprintf(stderr, "terminfo files not supported\n");
- ExitProgram(EXIT_FAILURE);
+#define LEAF_FMT "%02x"
#endif
- } else {
- if (itrace)
- (void) fprintf(stderr,
- "infocmp: reading entry %s from database\n",
- tname[termcount]);
-
- status = _nc_read_entry(tname[termcount],
- tfile[termcount],
- &entries[termcount].tterm);
- directory = TERMINFO; /* for error message */
- }
+ (void) sprintf(tfile[termcount], "%s/" LEAF_FMT "/%s",
+ directory,
+ UChar(*argv[optind]), argv[optind]);
+ if (itrace)
+ (void) fprintf(stderr,
+ "%s: reading entry %s from file %s\n",
+ _nc_progname,
+ argv[optind], tfile[termcount]);
- if (status <= 0) {
+ status = _nc_read_file_entry(tfile[termcount],
+ &entries[termcount].tterm);
+#else
+ (void) fprintf(stderr, "%s: terminfo files not supported\n",
+ _nc_progname);
+ ExitProgram(EXIT_FAILURE);
+#endif
+ } else {
+ if (itrace)
(void) fprintf(stderr,
- "infocmp: couldn't open terminfo file %s.\n",
- tfile[termcount]);
- ExitProgram(EXIT_FAILURE);
- }
- repair_acsc(&entries[termcount].tterm);
- termcount++;
+ "%s: reading entry %s from database\n",
+ _nc_progname,
+ tname[termcount]);
+
+ status = _nc_read_entry(tname[termcount],
+ tfile[termcount],
+ &entries[termcount].tterm);
+ directory = TERMINFO; /* for error message */
+ }
+
+ if (status <= 0) {
+ (void) fprintf(stderr,
+ "%s: couldn't open terminfo file %s.\n",
+ _nc_progname,
+ tfile[termcount]);
+ ExitProgram(EXIT_FAILURE);
}
+ repair_acsc(&entries[termcount].tterm);
+ termcount++;
}
#if NCURSES_XNAMES
@@ -1542,7 +1572,8 @@ main(int argc, char *argv[])
case C_DEFAULT:
if (itrace)
(void) fprintf(stderr,
- "infocmp: about to dump %s\n",
+ "%s: about to dump %s\n",
+ _nc_progname,
tname[0]);
(void) printf("#\tReconstructed via infocmp from file: %s\n",
tfile[0]);
@@ -1553,12 +1584,12 @@ main(int argc, char *argv[])
NULL);
len = show_entry();
if (itrace)
- (void) fprintf(stderr, "infocmp: length %d\n", len);
+ (void) fprintf(stderr, "%s: length %d\n", _nc_progname, len);
break;
case C_DIFFERENCE:
if (itrace)
- (void) fprintf(stderr, "infocmp: dumping differences\n");
+ (void) fprintf(stderr, "%s: dumping differences\n", _nc_progname);
(void) printf("comparing %s to %s.\n", tname[0], tname[1]);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -1566,7 +1597,8 @@ main(int argc, char *argv[])
case C_COMMON:
if (itrace)
(void) fprintf(stderr,
- "infocmp: dumping common capabilities\n");
+ "%s: dumping common capabilities\n",
+ _nc_progname);
(void) printf("comparing %s to %s.\n", tname[0], tname[1]);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
@@ -1574,14 +1606,15 @@ main(int argc, char *argv[])
case C_NAND:
if (itrace)
(void) fprintf(stderr,
- "infocmp: dumping differences\n");
+ "%s: dumping differences\n",
+ _nc_progname);
(void) printf("comparing %s to %s.\n", tname[0], tname[1]);
compare_entry(compare_predicate, &entries->tterm, quiet);
break;
case C_USEALL:
if (itrace)
- (void) fprintf(stderr, "infocmp: dumping use entry\n");
+ (void) fprintf(stderr, "%s: dumping use entry\n", _nc_progname);
dump_entry(&entries[0].tterm,
suppress_untranslatable,
limited,
@@ -1592,7 +1625,7 @@ main(int argc, char *argv[])
|| outform == F_TCONVERR));
len = show_entry();
if (itrace)
- (void) fprintf(stderr, "infocmp: length %d\n", len);
+ (void) fprintf(stderr, "%s: length %d\n", _nc_progname, len);
break;
}
}
@@ -1606,7 +1639,11 @@ main(int argc, char *argv[])
else
file_comparison(argc - optind, argv + optind);
+#if NO_LEAKS
+ free(myargv);
free(tfile);
+ free(tname);
+#endif
ExitProgram(EXIT_SUCCESS);
}
OpenPOWER on IntegriCloud