/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 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 <ctype.h>
#include <tic.h>
#define __INTERNAL_CAPS_VISIBLE
-#include <term.h>
#include <term_entry.h>
-MODULE_ID("$Id: parse_entry.c,v 1.22 1998/02/11 12:13:59 tom Exp $")
+MODULE_ID("$Id: parse_entry.c,v 1.39 1999/03/01 02:28:51 tom Exp $")
#ifdef LINT
static short const parametrized[] = { 0 };
static void postprocess_terminfo(TERMTYPE *);
static struct name_table_entry const * lookup_fullname(const char *name);
+#if NCURSES_XNAMES
+
+static struct name_table_entry const *
+_nc_extend_names(ENTRY *entryp, char *name, int token_type)
+{
+ static struct name_table_entry temp;
+ TERMTYPE *tp = &(entryp->tterm);
+ unsigned offset = 0;
+ unsigned actual;
+ unsigned tindex;
+ unsigned first, last, n;
+ bool found;
+
+ switch (token_type) {
+ case BOOLEAN:
+ first = 0;
+ last = tp->ext_Booleans;
+ offset = tp->ext_Booleans;
+ tindex = tp->num_Booleans;
+ break;
+ case NUMBER:
+ first = tp->ext_Booleans;
+ last = tp->ext_Numbers + first;
+ offset = tp->ext_Booleans + tp->ext_Numbers;
+ tindex = tp->num_Numbers;
+ break;
+ case STRING:
+ first = tp->ext_Booleans + tp->ext_Numbers;
+ last = tp->ext_Strings + first;
+ offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+ tindex = tp->num_Strings;
+ break;
+ case CANCEL:
+ actual = NUM_EXT_NAMES(tp);
+ for (n = 0; n < actual; n++) {
+ if (!strcmp(name, tp->ext_Names[n])) {
+ if (n > (unsigned)(tp->ext_Booleans + tp->ext_Numbers)) {
+ token_type = STRING;
+ } else if (n > tp->ext_Booleans) {
+ token_type = NUMBER;
+ } else {
+ token_type = BOOLEAN;
+ }
+ return _nc_extend_names(entryp, name, token_type);
+ }
+ }
+ /* Well, we are given a cancel for a name that we don't recognize */
+ return _nc_extend_names(entryp, name, STRING);
+ default:
+ return 0;
+ }
+
+ /* Adjust the 'offset' (insertion-point) to keep the lists of extended
+ * names sorted.
+ */
+ for (n = first, found = FALSE; n < last; n++) {
+ int cmp = strcmp(tp->ext_Names[n], name);
+ if (cmp == 0)
+ found = TRUE;
+ if (cmp >= 0) {
+ offset = n;
+ tindex = n - first;
+ switch (token_type) {
+ case BOOLEAN: tindex += BOOLCOUNT; break;
+ case NUMBER: tindex += NUMCOUNT; break;
+ case STRING: tindex += STRCOUNT; break;
+ }
+ break;
+ }
+ }
+ if (!found) {
+ switch (token_type) {
+ case BOOLEAN:
+ tp->ext_Booleans += 1;
+ tp->num_Booleans += 1;
+ tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans);
+ for (last = tp->num_Booleans-1; last > tindex; last--)
+ tp->Booleans[last] = tp->Booleans[last-1];
+ break;
+ case NUMBER:
+ tp->ext_Numbers += 1;
+ tp->num_Numbers += 1;
+ tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers);
+ for (last = tp->num_Numbers-1; last > tindex; last--)
+ tp->Numbers[last] = tp->Numbers[last-1];
+ break;
+ case STRING:
+ tp->ext_Strings += 1;
+ tp->num_Strings += 1;
+ tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings);
+ for (last = tp->num_Strings-1; last > tindex; last--)
+ tp->Strings[last] = tp->Strings[last-1];
+ break;
+ }
+ actual = NUM_EXT_NAMES(tp);
+ tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names);
+ while (--actual > offset)
+ tp->ext_Names[actual] = tp->ext_Names[actual-1];
+ tp->ext_Names[offset] = _nc_save_str(name);
+ }
+
+ temp.nte_name = tp->ext_Names[offset];
+ temp.nte_type = token_type;
+ temp.nte_index = tindex;
+ temp.nte_link = -1;
+
+ return &temp;
+}
+#endif /* NCURSES_XNAMES */
+
/*
* int
* _nc_parse_entry(entry, literal, silent)
/* check for overly-long names and aliases */
(void) strncpy(namecpy, entryp->tterm.term_names, MAX_NAME_SIZE);
namecpy[MAX_NAME_SIZE] = '\0';
- if ((ptr = strrchr(namecpy, '|')) != (char *)NULL)
+ if ((ptr = strrchr(namecpy, '|')) != (char *)0)
*ptr = '\0';
ptr = strtok(namecpy, "|");
if (strlen(ptr) > MAX_ALIAS)
_nc_warning("primary name may be too long");
- while ((ptr = strtok((char *)NULL, "|")) != (char *)NULL)
+ while ((ptr = strtok((char *)0, "|")) != (char *)0)
if (strlen(ptr) > MAX_ALIAS)
_nc_warning("alias `%s' may be too long", ptr);
for (ap = _nc_capalias_table; ap->from; ap++)
if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
{
- if (ap->to == (char *)NULL)
+ if (ap->to == (char *)0)
{
_nc_warning("%s (%s termcap extension) ignored",
ap->from, ap->source);
for (ap = _nc_infoalias_table; ap->from; ap++)
if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
{
- if (ap->to == (char *)NULL)
+ if (ap->to == (char *)0)
{
_nc_warning("%s (%s terminfo extension) ignored",
ap->from, ap->source);
break;
}
- /* last chance: a full-name */
if (entry_ptr == NOTFOUND) {
entry_ptr = lookup_fullname(_nc_curr_token.tk_name);
}
}
}
+#if NCURSES_XNAMES
+ /*
+ * If we have extended-names active, we will automatically
+ * define a name based on its context.
+ */
+ if (entry_ptr == NOTFOUND
+ && _nc_user_definable
+ && (entry_ptr = _nc_extend_names(entryp, _nc_curr_token.tk_name, token_type)) != 0) {
+ _nc_warning("extended capability '%s'", _nc_curr_token.tk_name);
+ }
+#endif /* NCURSES_XNAMES */
+
/* can't find this cap name, not even as an alias */
if (entry_ptr == NOTFOUND) {
if (!silent)
* space-efficient to call this after use resolution, but it has
* to be done before entry allocation is wrapped up.
*/
- if (!literal)
+ if (!literal) {
if (_nc_syntax == SYN_TERMCAP)
{
bool has_base_entry = FALSE;
* have picked up defaults via translation.
*/
for (i = 0; i < entryp->nuses; i++)
- if (!strchr(entryp->uses[i].parent, '+'))
+ if (!strchr((char *)entryp->uses[i].parent, '+'))
has_base_entry = TRUE;
postprocess_termcap(&entryp->tterm, has_base_entry);
}
else
postprocess_terminfo(&entryp->tterm);
-
+ }
_nc_wrap_entry(entryp);
return(OK);
{"st", "khts"}, /* set-tab key -> KEY_STAB */
{"ta", CANCELLED_STRING},
{"up", "kcuu1"}, /* up-arrow key -> KEY_UP */
- {(char *)NULL, (char *)NULL},
+ {(char *)0, (char *)0},
};
/*
* Note that WANTED and PRESENT are not simple inverses! If a capability
* has been explicitly cancelled, it's not considered WANTED.
*/
-#define WANTED(s) ((s) == (char *)NULL)
-#define PRESENT(s) (((s) != (char *)NULL) && ((s) != CANCELLED_STRING))
+#define WANTED(s) ((s) == ABSENT_STRING)
+#define PRESENT(s) (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
/*
* This bit of legerdemain turns all the terminfo variable names into
if (WANTED(init_3string) && termcap_init2)
init_3string = _nc_save_str(termcap_init2);
- if (WANTED(reset_1string) && termcap_reset)
- reset_1string = _nc_save_str(termcap_reset);
+ if (WANTED(reset_2string) && termcap_reset)
+ reset_2string = _nc_save_str(termcap_reset);
if (WANTED(carriage_return)) {
if (carriage_return_delay > 0) {
* space allocated for it is wasted.
*/
if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
- carriage_return = NULL;
+ carriage_return = ABSENT_STRING;
/*
* Supposedly most termcap entries have ta now and '\t' is no longer a
/*
* Translate the old termcap :pt: capability to it#8 + ht=\t
*/
- if (has_hardware_tabs == TRUE)
+ if (has_hardware_tabs == TRUE) {
if (init_tabs != 8 && init_tabs != ABSENT_NUMERIC)
_nc_warning("hardware tabs with a width other than 8: %d", init_tabs);
else
init_tabs = 8;
}
}
-
+ }
/*
* Now translate the ko capability, if there is one. This
* isn't from mytinfo...
tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
} while
- ((cp = strtok((char *)NULL, ",")) != 0);
+ ((cp = strtok((char *)0, ",")) != 0);
/*
* Note: ko=im and ko=ic both want to grab the `Insert'
_nc_warning("acsc string synthesized from XENIX capabilities");
}
}
+ else if (acs_chars == 0
+ && enter_alt_charset_mode != 0
+ && exit_alt_charset_mode != 0)
+ {
+ acs_chars = _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~");
+ }
}
static