/****************************************************************************
- * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2004,2005 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 "termsort.c" /* this C file is generated */
#include <parametrized.h> /* so is this */
-MODULE_ID("$Id: dump_entry.c,v 1.66 2003/05/24 22:43:59 tom Exp $")
+MODULE_ID("$Id: dump_entry.c,v 1.70 2005/07/23 20:03:30 tom Exp $")
#define INDENT 8
#define DISCARD(string) string = ABSENT_STRING
static int oldcol; /* last value of column before wrap */
static bool pretty; /* true if we format if-then-else strings */
+static char *save_sgr;
+static char *save_acsc;
+
static DYNBUF outbuf;
static DYNBUF tmpbuf;
/* indirection pointers for implementing sort and display modes */
-static const int *bool_indirect, *num_indirect, *str_indirect;
+static const PredIdx *bool_indirect, *num_indirect, *str_indirect;
static NCURSES_CONST char *const *bool_names;
static NCURSES_CONST char *const *num_names;
static NCURSES_CONST char *const *str_names;
static TERMTYPE *cur_type;
static int
-dump_predicate(int type, int idx)
+dump_predicate(PredType type, PredIdx idx)
/* predicate function to use for ordinary decompilation */
{
switch (type) {
return (FALSE); /* pacify compiler */
}
-static void set_obsolete_termcaps(TERMTYPE * tp);
+static void set_obsolete_termcaps(TERMTYPE *tp);
/* is this the index of a function key string? */
#define FNKEY(i) (((i)<= 65 && (i)>= 75) || ((i)<= 216 && (i)>= 268))
#define STR_IDX(name) (&(name) - &(CUR Strings[0]))
static bool
-version_filter(int type, int idx)
+version_filter(PredType type, PredIdx idx)
/* filter out capabilities we may want to suppress */
{
switch (tversion) {
return src;
}
+#define SAME_CAP(n,cap) (&tterm->Strings[n] == &cap)
+
int
-fmt_entry(TERMTYPE * tterm,
- int (*pred) (int type, int idx),
+fmt_entry(TERMTYPE *tterm,
+ PredFunc pred,
bool content_only,
bool suppress_untranslatable,
bool infodump,
int numbers)
{
- int i, j;
+ PredIdx i, j;
char buffer[MAX_TERMINFO_LENGTH];
+ char *capability;
NCURSES_CONST char *name;
int predval, len;
- int num_bools = 0;
- int num_values = 0;
- int num_strings = 0;
+ PredIdx num_bools = 0;
+ PredIdx num_values = 0;
+ PredIdx num_strings = 0;
bool outcount = 0;
#define WRAP_CONCAT \
for_each_string(j, tterm) {
i = StrIndirect(j);
name = ExtStrname(tterm, i, str_names);
+ capability = tterm->Strings[i];
if (!version_filter(STRING, i))
continue;
else if (isObsolete(outform, name))
continue;
+#if NCURSES_XNAMES
/*
- * Some older versions of vi want rmir/smir to be defined
- * for ich/ich1 to work. If they're not defined, force
- * them to be output as defined and empty.
+ * Extended names can be longer than 2 characters, but termcap programs
+ * cannot read those (filter them out).
*/
+ if (outform == F_TERMCAP && (strlen(name) > 2))
+ continue;
+#endif
+
if (outform == F_TERMCAP) {
- if (insert_character || parm_ich) {
- if (&tterm->Strings[i] == &enter_insert_mode
+ /*
+ * Some older versions of vi want rmir/smir to be defined
+ * for ich/ich1 to work. If they're not defined, force
+ * them to be output as defined and empty.
+ */
+ if (PRESENT(insert_character) || PRESENT(parm_ich)) {
+ if (SAME_CAP(i, enter_insert_mode)
&& enter_insert_mode == ABSENT_STRING) {
(void) strcpy(buffer, "im=");
WRAP_CONCAT;
continue;
}
- if (&tterm->Strings[i] == &exit_insert_mode
+ if (SAME_CAP(i, exit_insert_mode)
&& exit_insert_mode == ABSENT_STRING) {
(void) strcpy(buffer, "ei=");
WRAP_CONCAT;
continue;
}
}
+ /*
+ * termcap applications such as screen will be confused if sgr0
+ * is translated to a string containing rmacs. Filter that out.
+ */
+ if (PRESENT(exit_attribute_mode)) {
+ if (SAME_CAP(i, exit_attribute_mode)) {
+ char *trimmed_sgr0;
+ char *my_sgr = set_attributes;
+
+ set_attributes = save_sgr;
+
+ trimmed_sgr0 = _nc_trim_sgr0(tterm);
+ if (strcmp(capability, trimmed_sgr0))
+ capability = trimmed_sgr0;
+
+ set_attributes = my_sgr;
+ }
+ }
}
predval = pred(STRING, i);
buffer[0] = '\0';
if (predval != FAIL) {
- if (tterm->Strings[i] != ABSENT_STRING
+ if (capability != ABSENT_STRING
&& i + 1 > num_strings)
num_strings = i + 1;
- if (!VALID_STRING(tterm->Strings[i])) {
+ if (!VALID_STRING(capability)) {
sprintf(buffer, "%s@", name);
WRAP_CONCAT;
} else if (outform == F_TERMCAP || outform == F_TCONVERR) {
int params = ((i < (int) SIZEOF(parametrized))
? parametrized[i]
: 0);
- char *srccap = _nc_tic_expand(tterm->Strings[i], TRUE, numbers);
+ char *srccap = _nc_tic_expand(capability, TRUE, numbers);
char *cv = _nc_infotocap(name, srccap, params);
if (cv == 0) {
} else {
sprintf(buffer, "%s=%s", name, cv);
}
- len += strlen(tterm->Strings[i]) + 1;
+ len += strlen(capability) + 1;
WRAP_CONCAT;
} else {
- char *src = _nc_tic_expand(tterm->Strings[i],
+ char *src = _nc_tic_expand(capability,
outform == F_TERMINFO, numbers);
strcpy_DYN(&tmpbuf, 0);
} else {
strcpy_DYN(&tmpbuf, src);
}
- len += strlen(tterm->Strings[i]) + 1;
+ len += strlen(capability) + 1;
wrap_concat(tmpbuf.text);
outcount = TRUE;
}
}
+ /* e.g., trimmed_sgr0 */
+ if (capability != tterm->Strings[i])
+ free(capability);
}
len += num_strings * 2;
}
static bool
-kill_string(TERMTYPE * tterm, char *cap)
+kill_string(TERMTYPE *tterm, char *cap)
{
int n;
for (n = 0; n < NUM_STRINGS(tterm); ++n) {
}
static char *
-find_string(TERMTYPE * tterm, char *name)
+find_string(TERMTYPE *tterm, char *name)
{
- int n;
+ PredIdx n;
for (n = 0; n < NUM_STRINGS(tterm); ++n) {
if (version_filter(STRING, n)
&& !strcmp(name, strnames[n])) {
* make it smaller.
*/
static int
-kill_labels(TERMTYPE * tterm, int target)
+kill_labels(TERMTYPE *tterm, int target)
{
int n;
int result = 0;
* make it smaller.
*/
static int
-kill_fkeys(TERMTYPE * tterm, int target)
+kill_fkeys(TERMTYPE *tterm, int target)
{
int n;
int result = 0;
#define SHOW_WHY if (!already_used) PRINTF
int
-dump_entry(TERMTYPE * tterm,
+dump_entry(TERMTYPE *tterm,
bool suppress_untranslatable,
bool limited,
int already_used,
int numbers,
- int (*pred) (int type, int idx))
+ PredFunc pred)
/* dump a single entry */
{
int len, critlen;
}
critlen -= already_used;
+ save_sgr = set_attributes;
+ save_acsc = acs_chars;
+
if (((len = FMT_ENTRY()) > critlen)
&& limited) {
if (!suppress_untranslatable) {
* is really just an optimization hack. Another good candidate is
* acsc since it is both long and unused by BSD termcap.
*/
- char *oldsgr = set_attributes;
- char *oldacsc = acs_chars;
bool changed = FALSE;
+#if NCURSES_XNAMES
+ /*
+ * Extended names are most likely function-key definitions. Drop
+ * those first.
+ */
+ int n;
+ for (n = STRCOUNT; n < NUM_STRINGS(tterm); n++) {
+ char *name = ExtStrname(tterm, n, strnames);
+
+ if (VALID_STRING(tterm->Strings[n])) {
+ set_attributes = ABSENT_STRING;
+ /* we remove long names anyway - only report the short */
+ if (strlen(name) <= 2) {
+ SHOW_WHY("# (%s removed to fit entry within %d bytes)\n",
+ name,
+ critlen);
+ }
+ changed = TRUE;
+ if ((len = FMT_ENTRY()) <= critlen)
+ break;
+ }
+ }
+#endif
if (VALID_STRING(set_attributes)) {
set_attributes = ABSENT_STRING;
SHOW_WHY("# (sgr removed to fit entry within %d bytes)\n",
}
tversion = oldversion;
}
- set_attributes = oldsgr;
- acs_chars = oldacsc;
+ set_attributes = save_sgr;
+ acs_chars = save_acsc;
}
}
}
void
-compare_entry(void (*hook) (int t, int i, const char *name), TERMTYPE * tp
- GCC_UNUSED, bool quiet)
+compare_entry(void (*hook) (PredType t, PredIdx i, const char *name),
+ TERMTYPE *tp GCC_UNUSED,
+ bool quiet)
/* compare two entries */
{
- int i, j;
+ PredIdx i, j;
NCURSES_CONST char *name;
if (!quiet)
#define CUR tp->
static void
-set_obsolete_termcaps(TERMTYPE * tp)
+set_obsolete_termcaps(TERMTYPE *tp)
{
#include "capdefaults.c"
}
* unique.
*/
void
-repair_acsc(TERMTYPE * tp)
+repair_acsc(TERMTYPE *tp)
{
if (VALID_STRING(acs_chars)) {
size_t n, m;