+ static const char *tbl[] =
+ {
+ "Usage: infocmp [options] [-A directory] [-B directory] [termname...]"
+ ,""
+ ,"Options:"
+ ," -1 print single-column"
+ ," -C use termcap-names"
+ ," -F compare terminfo-files"
+ ," -I use terminfo-names"
+ ," -L use long names"
+ ," -R subset (see manpage)"
+ ," -T eliminate size limits (test)"
+ ," -U eliminate post-processing of entries"
+ ," -V print version"
+#if NCURSES_XNAMES
+ ," -a with -F, list commented-out caps"
+#endif
+ ," -c list common capabilities"
+ ," -d list different capabilities"
+ ," -e format output for C initializer"
+ ," -E format output as C tables"
+ ," -f with -1, format complex strings"
+ ," -G format %{number} to %'char'"
+ ," -g format %'char' to %{number}"
+ ," -i analyze initialization/reset"
+ ," -l output terminfo names"
+ ," -n list capabilities in neither"
+ ," -p ignore padding specifiers"
+ ," -q brief listing, removes headers"
+ ," -r with -C, output in termcap form"
+ ," -r with -F, resolve use-references"
+ ," -s [d|i|l|c] sort fields"
+#if NCURSES_XNAMES
+ ," -t suppress commented-out capabilities"
+#endif
+ ," -u produce source with 'use='"
+ ," -v number (verbose)"
+ ," -w number (width)"
+#if NCURSES_XNAMES
+ ," -x treat unknown capabilities as user-defined"
+#endif
+ };
+ const size_t first = 3;
+ const size_t last = SIZEOF(tbl);
+ const size_t left = (last - first + 1) / 2 + first;
+ size_t n;
+
+ for (n = 0; n < left; n++) {
+ size_t m = (n < first) ? last : n + left - first;
+ if (m < last)
+ fprintf(stderr, "%-40.40s%s\n", tbl[n], tbl[m]);
+ else
+ fprintf(stderr, "%s\n", tbl[n]);
+ }
+ ExitProgram(EXIT_FAILURE);
+}
+
+static char *
+any_initializer(const char *fmt, const char *type)
+{
+ static char *initializer;
+ char *s;
+
+ if (initializer == 0)
+ initializer = (char *) malloc(strlen(entries->tterm.term_names) +
+ strlen(type) + strlen(fmt));
+
+ (void) strcpy(initializer, entries->tterm.term_names);
+ for (s = initializer; *s != 0 && *s != '|'; s++) {
+ if (!isalnum(UChar(*s)))
+ *s = '_';
+ }
+ *s = 0;
+ (void) sprintf(s, fmt, type);
+ return initializer;
+}
+
+static char *
+name_initializer(const char *type)
+{
+ return any_initializer("_%s_data", type);
+}
+
+static char *
+string_variable(const char *type)
+{
+ return any_initializer("_s_%s", type);
+}
+
+/* dump C initializers for the terminal type */
+static void
+dump_initializers(TERMTYPE *term)
+{
+ unsigned n;
+ const char *str = 0;
+
+ printf("\nstatic char %s[] = \"%s\";\n\n",
+ name_initializer("alias"), entries->tterm.term_names);
+
+ for_each_string(n, term) {
+ char buf[MAX_STRING], *sp, *tp;
+
+ if (VALID_STRING(term->Strings[n])) {
+ tp = buf;
+ *tp++ = '"';
+ for (sp = term->Strings[n];
+ *sp != 0 && (tp - buf) < MAX_STRING - 6;
+ sp++) {
+ if (isascii(UChar(*sp))
+ && isprint(UChar(*sp))
+ && *sp != '\\'
+ && *sp != '"')
+ *tp++ = *sp;
+ else {
+ (void) sprintf(tp, "\\%03o", UChar(*sp));
+ tp += 4;
+ }
+ }
+ *tp++ = '"';
+ *tp = '\0';
+ (void) printf("static char %-20s[] = %s;\n",
+ string_variable(ExtStrname(term, n, strnames)), buf);
+ }
+ }
+ printf("\n");
+
+ (void) printf("static char %s[] = %s\n", name_initializer("bool"), L_CURL);
+
+ for_each_boolean(n, term) {
+ switch ((int) (term->Booleans[n])) {
+ case TRUE:
+ str = "TRUE";
+ break;
+
+ case FALSE:
+ str = "FALSE";
+ break;
+
+ case ABSENT_BOOLEAN:
+ str = "ABSENT_BOOLEAN";
+ break;
+
+ case CANCELLED_BOOLEAN:
+ str = "CANCELLED_BOOLEAN";
+ break;
+ }
+ (void) printf("\t/* %3u: %-8s */\t%s,\n",
+ n, ExtBoolname(term, n, boolnames), str);
+ }
+ (void) printf("%s;\n", R_CURL);
+
+ (void) printf("static short %s[] = %s\n", name_initializer("number"), L_CURL);
+
+ for_each_number(n, term) {
+ char buf[BUFSIZ];
+ switch (term->Numbers[n]) {
+ case ABSENT_NUMERIC:
+ str = "ABSENT_NUMERIC";
+ break;
+ case CANCELLED_NUMERIC:
+ str = "CANCELLED_NUMERIC";
+ break;
+ default:
+ sprintf(buf, "%d", term->Numbers[n]);
+ str = buf;
+ break;
+ }
+ (void) printf("\t/* %3u: %-8s */\t%s,\n", n,
+ ExtNumname(term, n, numnames), str);
+ }
+ (void) printf("%s;\n", R_CURL);
+
+ (void) printf("static char * %s[] = %s\n", name_initializer("string"), L_CURL);
+
+ for_each_string(n, term) {
+
+ if (term->Strings[n] == ABSENT_STRING)
+ str = "ABSENT_STRING";
+ else if (term->Strings[n] == CANCELLED_STRING)
+ str = "CANCELLED_STRING";
+ else {
+ str = string_variable(ExtStrname(term, n, strnames));
+ }
+ (void) printf("\t/* %3u: %-8s */\t%s,\n", n,
+ ExtStrname(term, n, strnames), str);
+ }
+ (void) printf("%s;\n", R_CURL);
+
+#if NCURSES_XNAMES
+ if ((NUM_BOOLEANS(term) != BOOLCOUNT)
+ || (NUM_NUMBERS(term) != NUMCOUNT)
+ || (NUM_STRINGS(term) != STRCOUNT)) {
+ (void) printf("static char * %s[] = %s\n",
+ name_initializer("string_ext"), L_CURL);
+ for (n = BOOLCOUNT; n < NUM_BOOLEANS(term); ++n) {
+ (void) printf("\t/* %3u: bool */\t\"%s\",\n",
+ n, ExtBoolname(term, n, boolnames));
+ }
+ for (n = NUMCOUNT; n < NUM_NUMBERS(term); ++n) {
+ (void) printf("\t/* %3u: num */\t\"%s\",\n",
+ n, ExtNumname(term, n, numnames));
+ }
+ for (n = STRCOUNT; n < NUM_STRINGS(term); ++n) {
+ (void) printf("\t/* %3u: str */\t\"%s\",\n",
+ n, ExtStrname(term, n, strnames));
+ }
+ (void) printf("%s;\n", R_CURL);
+ }
+#endif
+}
+
+/* dump C initializers for the terminal type */
+static void
+dump_termtype(TERMTYPE *term)
+{
+ (void) printf("\t%s\n\t\t%s,\n", L_CURL, name_initializer("alias"));
+ (void) printf("\t\t(char *)0,\t/* pointer to string table */\n");
+
+ (void) printf("\t\t%s,\n", name_initializer("bool"));
+ (void) printf("\t\t%s,\n", name_initializer("number"));
+
+ (void) printf("\t\t%s,\n", name_initializer("string"));
+
+#if NCURSES_XNAMES
+ (void) printf("#if NCURSES_XNAMES\n");
+ (void) printf("\t\t(char *)0,\t/* pointer to extended string table */\n");
+ (void) printf("\t\t%s,\t/* ...corresponding names */\n",
+ ((NUM_BOOLEANS(term) != BOOLCOUNT)
+ || (NUM_NUMBERS(term) != NUMCOUNT)
+ || (NUM_STRINGS(term) != STRCOUNT))
+ ? name_initializer("string_ext")
+ : "(char **)0");
+
+ (void) printf("\t\t%d,\t\t/* count total Booleans */\n", NUM_BOOLEANS(term));
+ (void) printf("\t\t%d,\t\t/* count total Numbers */\n", NUM_NUMBERS(term));
+ (void) printf("\t\t%d,\t\t/* count total Strings */\n", NUM_STRINGS(term));
+
+ (void) printf("\t\t%d,\t\t/* count extensions to Booleans */\n",
+ NUM_BOOLEANS(term) - BOOLCOUNT);
+ (void) printf("\t\t%d,\t\t/* count extensions to Numbers */\n",
+ NUM_NUMBERS(term) - NUMCOUNT);
+ (void) printf("\t\t%d,\t\t/* count extensions to Strings */\n",
+ NUM_STRINGS(term) - STRCOUNT);
+
+ (void) printf("#endif /* NCURSES_XNAMES */\n");
+#else
+ (void) term;
+#endif /* NCURSES_XNAMES */
+ (void) printf("\t%s\n", R_CURL);
+}
+
+static int
+optarg_to_number(void)
+{
+ char *temp = 0;
+ long value = strtol(optarg, &temp, 0);
+
+ if (temp == 0 || temp == optarg || *temp != 0) {
+ fprintf(stderr, "Expected a number, not \"%s\"\n", optarg);
+ ExitProgram(EXIT_FAILURE);
+ }
+ return (int) value;
+}
+
+static char *
+terminal_env(void)
+{
+ char *terminal;
+
+ if ((terminal = getenv("TERM")) == 0) {
+ (void) fprintf(stderr,
+ "%s: environment variable TERM not set\n",
+ _nc_progname);