/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999 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 *
#include "dump_entry.h"
#include "termsort.c" /* this C file is generated */
-#include "parametrized.h" /* so is this */
+#include <parametrized.h> /* so is this */
-MODULE_ID("$Id: dump_entry.c,v 1.25 1998/02/11 12:14:02 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.37 1999/03/14 12:29:30 tom Exp $")
#define INDENT 8
+#define DISCARD(string) string = ABSENT_STRING
+
static int tversion; /* terminfo version */
static int outform; /* output format to use */
static int sortmode; /* sort mode to use */
static int column; /* current column, limited by 'width' */
static int oldcol; /* last value of column before wrap */
static int tracelevel; /* level of debug output */
+static bool pretty; /* true if we format if-then-else strings */
static char *outbuf; /* the output-buffer */
static size_t out_used; /* ...its current length */
#define OBSOLETE(n) (n[0] == 'O' && n[1] == 'T')
+#if NCURSES_XNAMES
+#define BoolIndirect(j) ((j >= BOOLCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : bool_indirect[j]))
+#define NumIndirect(j) ((j >= NUMCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : num_indirect[j]))
+#define StrIndirect(j) ((j >= STRCOUNT) ? (j) : ((sortmode == S_NOSORT) ? j : str_indirect[j]))
+#else
+#define BoolIndirect(j) ((sortmode == S_NOSORT) ? (j) : bool_indirect[j])
+#define NumIndirect(j) ((sortmode == S_NOSORT) ? (j) : num_indirect[j])
+#define StrIndirect(j) ((sortmode == S_NOSORT) ? (j) : str_indirect[j])
+#endif
+
#if NO_LEAKS
void _nc_leaks_dump_entry(void)
{
{
const struct name_table_entry *np;
- if ((np = _nc_find_entry(name, _nc_info_hash_table)) != NULL)
+ if ((np = _nc_find_entry(name, _nc_get_hash_table(0))) != 0)
switch(np->nte_type)
{
case BOOLEAN:
break;
}
- return((char *)NULL);
+ return(0);
}
-void dump_init(const char *version, int mode, int sort, int twidth, int traceval)
+void dump_init(const char *version, int mode, int sort, int twidth, int traceval, bool formatted)
/* set up for entry display */
{
width = twidth;
+ pretty = formatted;
tracelevel = traceval;
/* versions */
- if (version == (char *)NULL)
+ if (version == 0)
tversion = V_ALLCAPS;
else if (!strcmp(version, "SVr1") || !strcmp(version, "SVR1")
|| !strcmp(version, "Ultrix"))
/* implement sort modes */
switch(sortmode = sort)
- {
+ {
case S_NOSORT:
if (traceval)
(void) fprintf(stderr,
#define termcap_length(src) strlen(src)
#endif
+static char * fmt_complex(char *dst, char *src, int level)
+{
+ int percent = 0;
+ int n;
+
+ dst += strlen(dst);
+ while (*src != '\0') {
+ switch (*src) {
+ case '\\':
+ percent = 0;
+ *dst++ = *src++;
+ break;
+ case '%':
+ percent = 1;
+ break;
+ case '?': /* "if" */
+ case 't': /* "then" */
+ case 'e': /* "else" */
+ if (percent) {
+ percent = 0;
+ dst[-1] = '\n';
+ for (n = 0; n <= level; n++)
+ *dst++ = '\t';
+ *dst++ = '%';
+ *dst++ = *src;
+ *dst = '\0';
+ if (*src++ == '?') {
+ src = fmt_complex(dst, src, level+1);
+ dst += strlen(dst);
+ } else if (level == 1) {
+ _nc_warning("%%%c without %%?", *src);
+ }
+ continue;
+ }
+ break;
+ case ';': /* "endif" */
+ if (percent) {
+ percent = 0;
+ if (level > 1) {
+ dst[-1] = '\n';
+ for (n = 0; n < level; n++)
+ *dst++ = '\t';
+ *dst++ = '%';
+ *dst++ = *src++;
+ *dst = '\0';
+ return src;
+ }
+ _nc_warning("%%; without %%?");
+ }
+ break;
+ default:
+ percent = 0;
+ break;
+ }
+ *dst++ = *src++;
+ }
+ *dst = '\0';
+ return src;
+}
+
int fmt_entry(TERMTYPE *tterm,
int (*pred)(int type, int idx),
bool suppress_untranslatable,
- bool infodump)
+ bool infodump,
+ int numbers)
{
int i, j;
char buffer[MAX_TERMINFO_LENGTH];
+NCURSES_CONST char *name;
int predval, len;
int num_bools = 0;
int num_values = 0;
len = 12; /* terminfo file-header */
- if (pred == NULL) {
+ if (pred == 0) {
cur_type = tterm;
pred = dump_predicate;
}
- append_output(NULL);
+ append_output(0);
append_output(tterm->term_names);
append_output(separator);
column = out_used;
force_wrap();
- for (j=0; j < BOOLCOUNT; j++) {
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = bool_indirect[j];
+ for_each_boolean(j,tterm) {
+ i = BoolIndirect(j);
+ name = ExtBoolname(tterm,i,bool_names);
if (!version_filter(BOOLEAN, i))
continue;
else if ((outform == F_LITERAL || outform == F_TERMINFO || outform == F_VARIABLE)
- && (OBSOLETE(bool_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
predval = pred(BOOLEAN, i);
if (predval != FAIL) {
- (void) strcpy(buffer, bool_names[i]);
+ (void) strcpy(buffer, name);
if (predval <= 0)
(void) strcat(buffer, "@");
else if (i + 1 > num_bools)
if (column != INDENT)
force_wrap();
- for (j=0; j < NUMCOUNT; j++) {
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = num_indirect[j];
+ for_each_number(j,tterm) {
+ i = NumIndirect(j);
+ name = ExtNumname(tterm,i,num_names);
if (!version_filter(NUMBER, i))
continue;
else if ((outform == F_LITERAL || outform == F_TERMINFO || outform == F_VARIABLE)
- && (OBSOLETE(num_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
predval = pred(NUMBER, i);
if (predval != FAIL) {
if (tterm->Numbers[i] < 0) {
- sprintf(buffer, "%s@", num_names[i]);
+ sprintf(buffer, "%s@", name);
} else {
- sprintf(buffer, "%s#%d", num_names[i], tterm->Numbers[i]);
+ sprintf(buffer, "%s#%d", name, tterm->Numbers[i]);
if (i + 1 > num_values)
num_values = i + 1;
}
len++;
repair_acsc(tterm);
- for (j=0; j < STRCOUNT; j++) {
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = str_indirect[j];
+ for_each_string(j, tterm) {
+ i = StrIndirect(j);
+ name = ExtStrname(tterm,i,str_names);
if (!version_filter(STRING, i))
continue;
else if ((outform == F_LITERAL || outform == F_TERMINFO || outform == F_VARIABLE)
- && (OBSOLETE(str_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
/*
* them to be output as defined and empty.
*/
if (outform==F_TERMCAP)
+ {
#undef CUR
#define CUR tterm->
if (insert_character || parm_ich)
}
}
+ if (init_3string != 0
+ && termcap_reset != 0
+ && !strcmp(init_3string, termcap_reset))
+ DISCARD(init_3string);
+
+ if (reset_2string != 0
+ && termcap_reset != 0
+ && !strcmp(reset_2string, termcap_reset))
+ DISCARD(reset_2string);
+ }
+
predval = pred(STRING, i);
buffer[0] = '\0';
if (predval != FAIL) {
&& i + 1 > num_strings)
num_strings = i + 1;
if (!VALID_STRING(tterm->Strings[i]))
- sprintf(buffer, "%s@", str_names[i]);
+ sprintf(buffer, "%s@", name);
else if (outform == F_TERMCAP || outform == F_TCONVERR)
{
- char *srccap = _nc_tic_expand(tterm->Strings[i], FALSE);
- char *cv = _nc_infotocap(str_names[i], srccap, parametrized[i]);
+ char *srccap = _nc_tic_expand(tterm->Strings[i], FALSE, numbers);
+ char *cv = _nc_infotocap(name, srccap, parametrized[i]);
- if (cv == (char *)NULL)
+ if (cv == 0)
{
if (outform == F_TCONVERR)
- sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!", str_names[i], srccap);
+ sprintf(buffer, "%s=!!! %s WILL NOT CONVERT !!!", name, srccap);
else if (suppress_untranslatable)
continue;
else
- sprintf(buffer, "..%s=%s", str_names[i], srccap);
+ sprintf(buffer, "..%s=%s", name, srccap);
}
else
- sprintf(buffer, "%s=%s", str_names[i], cv);
+ sprintf(buffer, "%s=%s", name, cv);
len += strlen(tterm->Strings[i]) + 1;
}
else
{
- sprintf(buffer, "%s=%s", str_names[i], _nc_tic_expand(tterm->Strings[i], outform==F_TERMINFO));
+ char *src = _nc_tic_expand(tterm->Strings[i], outform==F_TERMINFO, numbers);
+ sprintf(buffer, "%s=", name);
+ if (pretty && outform==F_TERMINFO)
+ fmt_complex(buffer + strlen(buffer), src, 1);
+ else
+ strcat(buffer, src);
len += strlen(tterm->Strings[i]) + 1;
}
if (box_ok)
{
(void) strcpy(buffer, "box1=");
- (void) strcat(buffer, _nc_tic_expand(boxchars, outform==F_TERMINFO));
+ (void) strcat(buffer, _nc_tic_expand(boxchars, outform==F_TERMINFO, numbers));
WRAP_CONCAT;
}
}
return(infodump ? len : termcap_length(outbuf));
}
-int dump_entry(TERMTYPE *tterm, bool limited, int (*pred)(int type, int idx))
+int dump_entry(TERMTYPE *tterm, bool limited, int numbers, int (*pred)(int type, int idx))
/* dump a single entry */
{
int len, critlen;
infodump = TRUE;
}
- if (((len = fmt_entry(tterm, pred, FALSE, infodump)) > critlen) && limited)
+ if (((len = fmt_entry(tterm, pred, FALSE, infodump, numbers)) > critlen) && limited)
{
(void) printf("# (untranslatable capabilities removed to fit entry within %d bytes)\n",
critlen);
- if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen)
+ if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen)
{
/*
* We pick on sgr because it's a nice long string capability that
* is really just an optimization hack.
*/
char *oldsgr = set_attributes;
- set_attributes = ABSENT_STRING;
+ set_attributes = ABSENT_STRING;
(void) printf("# (sgr removed to fit entry within %d bytes)\n",
critlen);
- if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen)
+ if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen)
{
int oldversion = tversion;
(void) printf("# (terminfo-only capabilities suppressed to fit entry within %d bytes)\n",
critlen);
- if ((len = fmt_entry(tterm, pred, TRUE, infodump)) > critlen)
+ if ((len = fmt_entry(tterm, pred, TRUE, infodump, numbers)) > critlen)
{
(void) fprintf(stderr,
"warning: %s entry is %d bytes long\n",
{
char buffer[MAX_TERMINFO_LENGTH];
- append_output(NULL);
+ append_output(0);
(void)sprintf(buffer, "%s%s", infodump ? "use=" : "tc=", name);
wrap_concat(buffer);
(void) fputs(outbuf, stdout);
return out_used;
}
-void compare_entry(void (*hook)(int t, int i, const char *name))
+void compare_entry(void (*hook)(int t, int i, const char *name), TERMTYPE *tp GCC_UNUSED)
/* compare two entries */
{
int i, j;
+ NCURSES_CONST char * name;
(void) fputs(" comparing booleans.\n", stdout);
- for (j=0; j < BOOLCOUNT; j++)
+ for_each_boolean(j,tp)
{
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = bool_indirect[j];
+ i = BoolIndirect(j);
+ name = ExtBoolname(tp,i,bool_names);
if ((outform == F_LITERAL || outform == F_TERMINFO || outform == F_VARIABLE)
- && (OBSOLETE(bool_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
- (*hook)(BOOLEAN, i, bool_names[i]);
+ (*hook)(BOOLEAN, i, name);
}
(void) fputs(" comparing numbers.\n", stdout);
- for (j=0; j < NUMCOUNT; j++)
+ for_each_number(j,tp)
{
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = num_indirect[j];
+ i = NumIndirect(j);
+ name = ExtNumname(tp,i,num_names);
if ((outform==F_LITERAL || outform==F_TERMINFO || outform==F_VARIABLE)
- && (OBSOLETE(num_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
- (*hook)(NUMBER, i, num_names[i]);
+ (*hook)(NUMBER, i, name);
}
(void) fputs(" comparing strings.\n", stdout);
- for (j=0; j < STRCOUNT; j++)
+ for_each_string(j,tp)
{
- if (sortmode == S_NOSORT)
- i = j;
- else
- i = str_indirect[j];
+ i = StrIndirect(j);
+ name = ExtStrname(tp,i,str_names);
if ((outform==F_LITERAL || outform==F_TERMINFO || outform==F_VARIABLE)
- && (OBSOLETE(str_names[i]) && outform != F_LITERAL))
+ && (OBSOLETE(name) && outform != F_LITERAL))
continue;
- (*hook)(STRING, i, str_names[i]);
+ (*hook)(STRING, i, name);
}
}
-#define NOTSET(s) ((s) == (char *)NULL)
+#define NOTSET(s) ((s) == 0)
/*
* This bit of legerdemain turns all the terminfo variable names into