aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/tinfo
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/ncurses/tinfo')
-rw-r--r--contrib/ncurses/ncurses/tinfo/add_tries.c131
-rw-r--r--contrib/ncurses/ncurses/tinfo/alloc_entry.c216
-rw-r--r--contrib/ncurses/ncurses/tinfo/alloc_ttype.c188
-rw-r--r--contrib/ncurses/ncurses/tinfo/captoinfo.c604
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_error.c10
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_parse.c423
-rw-r--r--contrib/ncurses/ncurses/tinfo/comp_scan.c904
-rw-r--r--contrib/ncurses/ncurses/tinfo/free_ttype.c3
-rw-r--r--contrib/ncurses/ncurses/tinfo/init_keytry.c6
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_acs.c6
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_cur_term.c6
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_napms.c49
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_options.c286
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_raw.c199
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_setup.c450
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_termcap.c148
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_ti.c94
-rw-r--r--contrib/ncurses/ncurses/tinfo/lib_tputs.c389
-rw-r--r--contrib/ncurses/ncurses/tinfo/make_keys.c4
-rw-r--r--contrib/ncurses/ncurses/tinfo/parse_entry.c481
-rw-r--r--contrib/ncurses/ncurses/tinfo/read_entry.c387
-rw-r--r--contrib/ncurses/ncurses/tinfo/read_termcap.c1424
-rw-r--r--contrib/ncurses/ncurses/tinfo/write_entry.c652
23 files changed, 3582 insertions, 3478 deletions
diff --git a/contrib/ncurses/ncurses/tinfo/add_tries.c b/contrib/ncurses/ncurses/tinfo/add_tries.c
index 95a9e965c5a7..601fb663b7b6 100644
--- a/contrib/ncurses/ncurses/tinfo/add_tries.c
+++ b/contrib/ncurses/ncurses/tinfo/add_tries.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,2000 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 *
@@ -39,86 +39,87 @@
#include <curses.priv.h>
-MODULE_ID("$Id: add_tries.c,v 1.1 1998/11/08 00:04:18 tom Exp $")
+MODULE_ID("$Id: add_tries.c,v 1.2 2000/03/18 22:23:56 tom Exp $")
#define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0'
#define CMP_TRY(a,b) ((a)? (a == b) : (b == 128))
-void _nc_add_to_try(struct tries **tree, char *str, unsigned short code)
+void
+_nc_add_to_try(struct tries **tree, const char *str, unsigned short code)
{
- static bool out_of_memory = FALSE;
- struct tries *ptr, *savedptr;
- unsigned char *txt = (unsigned char *)str;
-
- if (txt == 0 || *txt == '\0' || out_of_memory || code == 0)
- return;
-
- if ((*tree) != 0) {
- ptr = savedptr = (*tree);
-
- for (;;) {
- unsigned char cmp = *txt;
-
- while (!CMP_TRY(ptr->ch, cmp)
- && ptr->sibling != 0)
- ptr = ptr->sibling;
-
- if (CMP_TRY(ptr->ch, cmp)) {
- if (*(++txt) == '\0') {
- ptr->value = code;
- return;
- }
- if (ptr->child != 0)
- ptr = ptr->child;
- else
- break;
- } else {
- if ((ptr->sibling = typeCalloc(struct tries,1)) == 0) {
- out_of_memory = TRUE;
- return;
- }
-
- savedptr = ptr = ptr->sibling;
- SET_TRY(ptr,txt);
- ptr->value = 0;
-
- break;
- }
- } /* end for (;;) */
- } else { /* (*tree) == 0 :: First sequence to be added */
- savedptr = ptr = (*tree) = typeCalloc(struct tries,1);
-
- if (ptr == 0) {
- out_of_memory = TRUE;
- return;
+ static bool out_of_memory = FALSE;
+ struct tries *ptr, *savedptr;
+ unsigned const char *txt = (unsigned const char *) str;
+
+ if (txt == 0 || *txt == '\0' || out_of_memory || code == 0)
+ return;
+
+ if ((*tree) != 0) {
+ ptr = savedptr = (*tree);
+
+ for (;;) {
+ unsigned char cmp = *txt;
+
+ while (!CMP_TRY(ptr->ch, cmp)
+ && ptr->sibling != 0)
+ ptr = ptr->sibling;
+
+ if (CMP_TRY(ptr->ch, cmp)) {
+ if (*(++txt) == '\0') {
+ ptr->value = code;
+ return;
+ }
+ if (ptr->child != 0)
+ ptr = ptr->child;
+ else
+ break;
+ } else {
+ if ((ptr->sibling = typeCalloc(struct tries, 1)) == 0) {
+ out_of_memory = TRUE;
+ return;
}
- SET_TRY(ptr,txt);
+ savedptr = ptr = ptr->sibling;
+ SET_TRY(ptr, txt);
ptr->value = 0;
+
+ break;
+ }
+ } /* end for (;;) */
+ } else { /* (*tree) == 0 :: First sequence to be added */
+ savedptr = ptr = (*tree) = typeCalloc(struct tries, 1);
+
+ if (ptr == 0) {
+ out_of_memory = TRUE;
+ return;
}
- /* at this point, we are adding to the try. ptr->child == 0 */
+ SET_TRY(ptr, txt);
+ ptr->value = 0;
+ }
- while (*txt) {
- ptr->child = typeCalloc(struct tries,1);
+ /* at this point, we are adding to the try. ptr->child == 0 */
- ptr = ptr->child;
+ while (*txt) {
+ ptr->child = typeCalloc(struct tries, 1);
- if (ptr == 0) {
- out_of_memory = TRUE;
+ ptr = ptr->child;
- while ((ptr = savedptr) != 0) {
- savedptr = ptr->child;
- free(ptr);
- }
+ if (ptr == 0) {
+ out_of_memory = TRUE;
- return;
- }
+ while ((ptr = savedptr) != 0) {
+ savedptr = ptr->child;
+ free(ptr);
+ }
- SET_TRY(ptr,txt);
- ptr->value = 0;
+ return;
}
- ptr->value = code;
- return;
+ SET_TRY(ptr, txt);
+ ptr->value = 0;
+ }
+
+ ptr->value = code;
+ return;
}
diff --git a/contrib/ncurses/ncurses/tinfo/alloc_entry.c b/contrib/ncurses/ncurses/tinfo/alloc_entry.c
index 570b48a9af80..17489372e464 100644
--- a/contrib/ncurses/ncurses/tinfo/alloc_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/alloc_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* alloc_entry.c -- allocation functions for terminfo entries
*
@@ -48,149 +47,152 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: alloc_entry.c,v 1.30 1999/03/01 02:03:45 tom Exp $")
+MODULE_ID("$Id: alloc_entry.c,v 1.32 2000/03/12 00:16:31 tom Exp $")
#define ABSENT_OFFSET -1
#define CANCELLED_OFFSET -2
#define MAX_STRTAB 4096 /* documented maximum entry size */
-static char stringbuf[MAX_STRTAB]; /* buffer for string capabilities */
-static size_t next_free; /* next free character in stringbuf */
+static char stringbuf[MAX_STRTAB]; /* buffer for string capabilities */
+static size_t next_free; /* next free character in stringbuf */
-void _nc_init_entry(TERMTYPE *const tp)
+void
+_nc_init_entry(TERMTYPE * const tp)
/* initialize a terminal type data block */
{
-int i;
+ int i;
#if NCURSES_XNAMES
- tp->num_Booleans = BOOLCOUNT;
- tp->num_Numbers = NUMCOUNT;
- tp->num_Strings = STRCOUNT;
- tp->ext_Booleans = 0;
- tp->ext_Numbers = 0;
- tp->ext_Strings = 0;
+ tp->num_Booleans = BOOLCOUNT;
+ tp->num_Numbers = NUMCOUNT;
+ tp->num_Strings = STRCOUNT;
+ tp->ext_Booleans = 0;
+ tp->ext_Numbers = 0;
+ tp->ext_Strings = 0;
#endif
- if (tp->Booleans == 0)
- tp->Booleans = typeMalloc(char,BOOLCOUNT);
- if (tp->Numbers == 0)
- tp->Numbers = typeMalloc(short,NUMCOUNT);
- if (tp->Strings == 0)
- tp->Strings = typeMalloc(char *,STRCOUNT);
+ if (tp->Booleans == 0)
+ tp->Booleans = typeMalloc(char, BOOLCOUNT);
+ if (tp->Numbers == 0)
+ tp->Numbers = typeMalloc(short, NUMCOUNT);
+ if (tp->Strings == 0)
+ tp->Strings = typeMalloc(char *, STRCOUNT);
- for_each_boolean(i,tp)
- tp->Booleans[i] = FALSE;
+ for_each_boolean(i, tp)
+ tp->Booleans[i] = FALSE;
- for_each_number(i,tp)
- tp->Numbers[i] = ABSENT_NUMERIC;
+ for_each_number(i, tp)
+ tp->Numbers[i] = ABSENT_NUMERIC;
- for_each_string(i,tp)
- tp->Strings[i] = ABSENT_STRING;
+ for_each_string(i, tp)
+ tp->Strings[i] = ABSENT_STRING;
- next_free = 0;
+ next_free = 0;
}
-ENTRY *_nc_copy_entry(ENTRY *oldp)
+ENTRY *
+_nc_copy_entry(ENTRY * oldp)
{
- ENTRY *newp = typeCalloc(ENTRY,1);
+ ENTRY *newp = typeCalloc(ENTRY, 1);
- if (newp != 0) {
- *newp = *oldp;
- _nc_copy_termtype(&(newp->tterm), &(oldp->tterm));
- }
- return newp;
+ if (newp != 0) {
+ *newp = *oldp;
+ _nc_copy_termtype(&(newp->tterm), &(oldp->tterm));
+ }
+ return newp;
}
-char *_nc_save_str(const char *const string)
+char *
+_nc_save_str(const char *const string)
/* save a copy of string in the string buffer */
{
-size_t old_next_free = next_free;
-size_t len = strlen(string) + 1;
-
- if (next_free + len < MAX_STRTAB)
- {
- strcpy(&stringbuf[next_free], string);
- DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
- DEBUG(7, ("at location %d", (int) next_free));
- next_free += len;
- }
- return(stringbuf + old_next_free);
+ size_t old_next_free = next_free;
+ size_t len = strlen(string) + 1;
+
+ if (next_free + len < MAX_STRTAB) {
+ strcpy(&stringbuf[next_free], string);
+ DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
+ DEBUG(7, ("at location %d", (int) next_free));
+ next_free += len;
+ }
+ return (stringbuf + old_next_free);
}
-void _nc_wrap_entry(ENTRY *const ep)
+void
+_nc_wrap_entry(ENTRY * const ep)
/* copy the string parts to allocated storage, preserving pointers to it */
{
-int offsets[MAX_ENTRY_SIZE/2], useoffsets[MAX_USES];
-int i, n;
-TERMTYPE *tp = &(ep->tterm);
-
- n = tp->term_names - stringbuf;
- for_each_string(i, &(ep->tterm)) {
- if (tp->Strings[i] == ABSENT_STRING)
- offsets[i] = ABSENT_OFFSET;
- else if (tp->Strings[i] == CANCELLED_STRING)
- offsets[i] = CANCELLED_OFFSET;
- else
- offsets[i] = tp->Strings[i] - stringbuf;
- }
+ int offsets[MAX_ENTRY_SIZE / 2], useoffsets[MAX_USES];
+ int i, n;
+ TERMTYPE *tp = &(ep->tterm);
+
+ n = tp->term_names - stringbuf;
+ for_each_string(i, &(ep->tterm)) {
+ if (tp->Strings[i] == ABSENT_STRING)
+ offsets[i] = ABSENT_OFFSET;
+ else if (tp->Strings[i] == CANCELLED_STRING)
+ offsets[i] = CANCELLED_OFFSET;
+ else
+ offsets[i] = tp->Strings[i] - stringbuf;
+ }
- for (i=0; i < ep->nuses; i++) {
- if (ep->uses[i].parent == (void *)0)
- useoffsets[i] = ABSENT_OFFSET;
- else
- useoffsets[i] = (char *)(ep->uses[i].parent) - stringbuf;
- }
+ for (i = 0; i < ep->nuses; i++) {
+ if (ep->uses[i].name == 0)
+ useoffsets[i] = ABSENT_OFFSET;
+ else
+ useoffsets[i] = ep->uses[i].name - stringbuf;
+ }
- if ((tp->str_table = typeMalloc(char, next_free)) == (char *)0)
- _nc_err_abort("Out of memory");
- (void) memcpy(tp->str_table, stringbuf, next_free);
-
- tp->term_names = tp->str_table + n;
- for_each_string(i, &(ep->tterm)) {
- if (offsets[i] == ABSENT_OFFSET)
- tp->Strings[i] = ABSENT_STRING;
- else if (offsets[i] == CANCELLED_OFFSET)
- tp->Strings[i] = CANCELLED_STRING;
- else
- tp->Strings[i] = tp->str_table + offsets[i];
- }
+ if ((tp->str_table = typeMalloc(char, next_free)) == (char *) 0)
+ _nc_err_abort("Out of memory");
+ (void) memcpy(tp->str_table, stringbuf, next_free);
+
+ tp->term_names = tp->str_table + n;
+ for_each_string(i, &(ep->tterm)) {
+ if (offsets[i] == ABSENT_OFFSET)
+ tp->Strings[i] = ABSENT_STRING;
+ else if (offsets[i] == CANCELLED_OFFSET)
+ tp->Strings[i] = CANCELLED_STRING;
+ else
+ tp->Strings[i] = tp->str_table + offsets[i];
+ }
#if NCURSES_XNAMES
- if ((n = NUM_EXT_NAMES(tp)) != 0) {
- unsigned length = 0;
- for (i = 0; i < n; i++) {
- length += strlen(tp->ext_Names[i]) + 1;
- offsets[i] = tp->ext_Names[i] - stringbuf;
- }
- if ((tp->ext_str_table = typeMalloc(char, length)) == 0)
- _nc_err_abort("Out of memory");
- for (i = 0, length = 0; i < n; i++) {
- tp->ext_Names[i] = tp->ext_str_table + length;
- strcpy(tp->ext_Names[i], stringbuf + offsets[i]);
- length += strlen(tp->ext_Names[i]) + 1;
- }
+ if ((n = NUM_EXT_NAMES(tp)) != 0) {
+ unsigned length = 0;
+ for (i = 0; i < n; i++) {
+ length += strlen(tp->ext_Names[i]) + 1;
+ offsets[i] = tp->ext_Names[i] - stringbuf;
+ }
+ if ((tp->ext_str_table = typeMalloc(char, length)) == 0)
+ _nc_err_abort("Out of memory");
+ for (i = 0, length = 0; i < n; i++) {
+ tp->ext_Names[i] = tp->ext_str_table + length;
+ strcpy(tp->ext_Names[i], stringbuf + offsets[i]);
+ length += strlen(tp->ext_Names[i]) + 1;
}
+ }
#endif
- for (i=0; i < ep->nuses; i++) {
- if (useoffsets[i] == ABSENT_OFFSET)
- ep->uses[i].parent = (void *)0;
- else
- ep->uses[i].parent = (char *)(tp->str_table + useoffsets[i]);
- }
+ for (i = 0; i < ep->nuses; i++) {
+ if (useoffsets[i] == ABSENT_OFFSET)
+ ep->uses[i].name = 0;
+ else
+ ep->uses[i].name = (tp->str_table + useoffsets[i]);
+ }
}
-void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from)
+void
+_nc_merge_entry(TERMTYPE * const to, TERMTYPE * const from)
/* merge capabilities from `from' entry into `to' entry */
{
- int i;
+ int i;
#if NCURSES_XNAMES
_nc_align_termtype(to, from);
#endif
- for_each_boolean(i, from)
- {
- int mergebool = from->Booleans[i];
+ for_each_boolean(i, from) {
+ int mergebool = from->Booleans[i];
if (mergebool == CANCELLED_BOOLEAN)
to->Booleans[i] = FALSE;
@@ -198,9 +200,8 @@ void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from)
to->Booleans[i] = mergebool;
}
- for_each_number(i, from)
- {
- int mergenum = from->Numbers[i];
+ for_each_number(i, from) {
+ int mergenum = from->Numbers[i];
if (mergenum == CANCELLED_NUMERIC)
to->Numbers[i] = ABSENT_NUMERIC;
@@ -213,9 +214,8 @@ void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from)
* storage. This is OK right now, but will be a problem if we
* we ever want to deallocate entries.
*/
- for_each_string(i, from)
- {
- char *mergestring = from->Strings[i];
+ for_each_string(i, from) {
+ char *mergestring = from->Strings[i];
if (mergestring == CANCELLED_STRING)
to->Strings[i] = ABSENT_STRING;
diff --git a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
index a1bf9b0733f0..660381a32b5f 100644
--- a/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
+++ b/contrib/ncurses/ncurses/tinfo/alloc_ttype.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999 Free Software Foundation, Inc. *
+ * Copyright (c) 1999,2000 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 *
@@ -30,7 +30,6 @@
* Author: Thomas E. Dickey <dickey@clark.net> 1999 *
****************************************************************************/
-
/*
* align_ttype.c -- functions for TERMTYPE
*
@@ -44,14 +43,15 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: alloc_ttype.c,v 1.6 1999/03/01 22:10:44 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.8 2000/03/25 17:03:11 tom Exp $")
#if NCURSES_XNAMES
/*
* Merge the a/b lists into dst. Both a/b are sorted (see _nc_extend_names()),
* so we do not have to worry about order dependencies.
*/
-static int merge_names(char **dst, char **a, int na, char **b, int nb)
+static int
+merge_names(char **dst, char **a, int na, char **b, int nb)
{
int n = 0;
while (na && nb) {
@@ -78,7 +78,8 @@ static int merge_names(char **dst, char **a, int na, char **b, int nb)
return n;
}
-static bool find_name(char **table, int length, char *name)
+static bool
+find_name(char **table, int length, char *name)
{
while (length-- > 0) {
if (!strcmp(*table++, name)) {
@@ -90,7 +91,9 @@ static bool find_name(char **table, int length, char *name)
return FALSE;
}
-static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int ext_Numbers, int ext_Strings)
+static void
+realign_data(TERMTYPE * to, char **ext_Names, int ext_Booleans, int
+ ext_Numbers, int ext_Strings)
{
int n, m, base;
int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings);
@@ -98,9 +101,9 @@ static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int e
if (to->ext_Booleans != ext_Booleans) {
to->num_Booleans += (ext_Booleans - to->ext_Booleans);
to->Booleans = typeRealloc(char, to->num_Booleans, to->Booleans);
- for (n = to->ext_Booleans-1,
- m = ext_Booleans-1,
- base = to->num_Booleans - (m+1); m >= 0; m--) {
+ for (n = to->ext_Booleans - 1,
+ m = ext_Booleans - 1,
+ base = to->num_Booleans - (m + 1); m >= 0; m--) {
if (find_name(to->ext_Names, limit, ext_Names[m])) {
to->Booleans[base + m] = to->Booleans[base + n--];
} else {
@@ -112,24 +115,24 @@ static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int e
if (to->ext_Numbers != ext_Numbers) {
to->num_Numbers += (ext_Numbers - to->ext_Numbers);
to->Numbers = typeRealloc(short, to->num_Numbers, to->Numbers);
- for (n = to->ext_Numbers-1,
- m = ext_Numbers-1,
- base = to->num_Numbers - (m+1); m >= 0; m--) {
- if (find_name(to->ext_Names, limit, ext_Names[m+ext_Booleans])) {
+ for (n = to->ext_Numbers - 1,
+ m = ext_Numbers - 1,
+ base = to->num_Numbers - (m + 1); m >= 0; m--) {
+ if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans])) {
to->Numbers[base + m] = to->Numbers[base + n--];
} else {
to->Numbers[base + m] = ABSENT_NUMERIC;
}
}
- to->ext_Numbers = ext_Numbers;
+ to->ext_Numbers = ext_Numbers;
}
if (to->ext_Strings != ext_Strings) {
to->num_Strings += (ext_Strings - to->ext_Strings);
- to->Strings = typeRealloc(char*, to->num_Strings, to->Strings);
- for (n = to->ext_Strings-1,
- m = ext_Strings-1,
- base = to->num_Strings - (m+1); m >= 0; m--) {
- if (find_name(to->ext_Names, limit, ext_Names[m+ext_Booleans+ext_Numbers])) {
+ to->Strings = typeRealloc(char *, to->num_Strings, to->Strings);
+ for (n = to->ext_Strings - 1,
+ m = ext_Strings - 1,
+ base = to->num_Strings - (m + 1); m >= 0; m--) {
+ if (find_name(to->ext_Names, limit, ext_Names[m + ext_Booleans + ext_Numbers])) {
to->Strings[base + m] = to->Strings[base + n--];
} else {
to->Strings[base + m] = ABSENT_STRING;
@@ -142,7 +145,8 @@ static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, int e
/*
* Returns the first index in ext_Names[] for the given token-type
*/
-static int _nc_first_ext_name(TERMTYPE *tp, int token_type)
+static int
+_nc_first_ext_name(TERMTYPE * tp, int token_type)
{
int first;
@@ -166,20 +170,21 @@ static int _nc_first_ext_name(TERMTYPE *tp, int token_type)
/*
* Returns the last index in ext_Names[] for the given token-type
*/
-static int _nc_last_ext_name(TERMTYPE *tp, int token_type)
+static int
+_nc_last_ext_name(TERMTYPE * tp, int token_type)
{
int last;
switch (token_type) {
case BOOLEAN:
- last = tp->ext_Booleans;
+ last = tp->ext_Booleans;
break;
case NUMBER:
- last = tp->ext_Booleans + tp->ext_Numbers;
+ last = tp->ext_Booleans + tp->ext_Numbers;
break;
default:
case STRING:
- last = NUM_EXT_NAMES(tp);
+ last = NUM_EXT_NAMES(tp);
break;
}
return last;
@@ -188,11 +193,12 @@ static int _nc_last_ext_name(TERMTYPE *tp, int token_type)
/*
* Lookup an entry from extended-names, returning -1 if not found
*/
-static int _nc_find_ext_name(TERMTYPE *tp, char *name, int token_type)
+static int
+_nc_find_ext_name(TERMTYPE * tp, char *name, int token_type)
{
unsigned j;
unsigned first = _nc_first_ext_name(tp, token_type);
- unsigned last = _nc_last_ext_name(tp, token_type);
+ unsigned last = _nc_last_ext_name(tp, token_type);
for (j = first; j < last; j++) {
if (!strcmp(name, tp->ext_Names[j])) {
@@ -206,7 +212,8 @@ static int _nc_find_ext_name(TERMTYPE *tp, char *name, int token_type)
* Translate an index into ext_Names[] into the corresponding index into data
* (e.g., Booleans[]).
*/
-static int _nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
+static int
+_nc_ext_data_index(TERMTYPE * tp, int n, int token_type)
{
switch (token_type) {
case BOOLEAN:
@@ -214,12 +221,12 @@ static int _nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
break;
case NUMBER:
n += (tp->num_Numbers - tp->ext_Numbers)
- - (tp->ext_Booleans);
+ - (tp->ext_Booleans);
break;
default:
case STRING:
n += (tp->num_Strings - tp->ext_Strings)
- - (tp->ext_Booleans + tp->ext_Numbers);
+ - (tp->ext_Booleans + tp->ext_Numbers);
}
return n;
}
@@ -228,7 +235,8 @@ static int _nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
* Adjust tables to remove (not free) an extended name and its corresponding
* data.
*/
-static void _nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
+static void
+_nc_del_ext_name(TERMTYPE * tp, char *name, int token_type)
{
int j;
int first, last;
@@ -236,28 +244,28 @@ static void _nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) {
last = NUM_EXT_NAMES(tp) - 1;
for (j = first; j < last; j++) {
- tp->ext_Names[j] = tp->ext_Names[j+1];
+ tp->ext_Names[j] = tp->ext_Names[j + 1];
}
first = _nc_ext_data_index(tp, first, token_type);
switch (token_type) {
case BOOLEAN:
last = tp->num_Booleans - 1;
for (j = first; j < last; j++)
- tp->Booleans[j] = tp->Booleans[j+1];
+ tp->Booleans[j] = tp->Booleans[j + 1];
tp->ext_Booleans -= 1;
tp->num_Booleans -= 1;
break;
case NUMBER:
last = tp->num_Numbers - 1;
for (j = first; j < last; j++)
- tp->Numbers[j] = tp->Numbers[j+1];
+ tp->Numbers[j] = tp->Numbers[j + 1];
tp->ext_Numbers -= 1;
tp->num_Numbers -= 1;
break;
case STRING:
last = tp->num_Strings - 1;
for (j = first; j < last; j++)
- tp->Strings[j] = tp->Strings[j+1];
+ tp->Strings[j] = tp->Strings[j + 1];
tp->ext_Strings -= 1;
tp->num_Strings -= 1;
break;
@@ -269,10 +277,11 @@ static void _nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
* Adjust tables to insert an extended name, making room for new data. The
* index into the corresponding data array is returned.
*/
-static int _nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
+static int
+_nc_ins_ext_name(TERMTYPE * tp, char *name, int token_type)
{
unsigned first = _nc_first_ext_name(tp, token_type);
- unsigned last = _nc_last_ext_name(tp, token_type);
+ unsigned last = _nc_last_ext_name(tp, token_type);
unsigned total = NUM_EXT_NAMES(tp) + 1;
unsigned j, k;
@@ -287,8 +296,8 @@ static int _nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
}
tp->ext_Names = typeRealloc(char *, total, tp->ext_Names);
- for (k = total-1; k > j; k--)
- tp->ext_Names[k] = tp->ext_Names[k-1];
+ for (k = total - 1; k > j; k--)
+ tp->ext_Names[k] = tp->ext_Names[k - 1];
tp->ext_Names[j] = name;
j = _nc_ext_data_index(tp, j, token_type);
@@ -297,22 +306,22 @@ static int _nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
tp->ext_Booleans += 1;
tp->num_Booleans += 1;
tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans);
- for (k = tp->num_Booleans-1; k > j; k--)
- tp->Booleans[k] = tp->Booleans[k-1];
+ for (k = tp->num_Booleans - 1; k > j; k--)
+ tp->Booleans[k] = tp->Booleans[k - 1];
break;
case NUMBER:
tp->ext_Numbers += 1;
tp->num_Numbers += 1;
tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers);
- for (k = tp->num_Numbers-1; k > j; k--)
- tp->Numbers[k] = tp->Numbers[k-1];
+ for (k = tp->num_Numbers - 1; k > j; k--)
+ tp->Numbers[k] = tp->Numbers[k - 1];
break;
case STRING:
tp->ext_Strings += 1;
tp->num_Strings += 1;
tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings);
- for (k = tp->num_Strings-1; k > j; k--)
- tp->Strings[k] = tp->Strings[k-1];
+ for (k = tp->num_Strings - 1; k > j; k--)
+ tp->Strings[k] = tp->Strings[k - 1];
break;
}
return j;
@@ -323,13 +332,14 @@ static int _nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
* as a boolean or number. We'll get this as a special case when we get a
* cancellation of a name that is inherited from another entry.
*/
-static void adjust_cancels(TERMTYPE *to, TERMTYPE *from)
+static void
+adjust_cancels(TERMTYPE * to, TERMTYPE * from)
{
int first = to->ext_Booleans + to->ext_Numbers;
- int last = first + to->ext_Strings;
+ int last = first + to->ext_Strings;
int j, k;
- for (j = first; j < last; ) {
+ for (j = first; j < last;) {
char *name = to->ext_Names[j];
unsigned j_str = to->num_Strings - first - to->ext_Strings;
@@ -338,7 +348,8 @@ static void adjust_cancels(TERMTYPE *to, TERMTYPE *from)
_nc_del_ext_name(to, name, STRING);
k = _nc_ins_ext_name(to, name, BOOLEAN);
to->Booleans[k] = FALSE;
- } else if ((k = _nc_find_ext_name(from, to->ext_Names[j], NUMBER)) >= 0) {
+ } else if ((k = _nc_find_ext_name(from, to->ext_Names[j],
+ NUMBER)) >= 0) {
_nc_del_ext_name(to, name, STRING);
k = _nc_ins_ext_name(to, name, NUMBER);
to->Numbers[k] = CANCELLED_NUMERIC;
@@ -349,7 +360,8 @@ static void adjust_cancels(TERMTYPE *to, TERMTYPE *from)
}
}
-void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
+void
+_nc_align_termtype(TERMTYPE * to, TERMTYPE * from)
{
int na = NUM_EXT_NAMES(to);
int nb = NUM_EXT_NAMES(from);
@@ -358,13 +370,14 @@ void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
char **ext_Names;
int ext_Booleans, ext_Numbers, ext_Strings;
- DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names, nb, from->term_names));
+ DEBUG(2, ("align_termtype to(%d:%s), from(%d:%s)", na, to->term_names,
+ nb, from->term_names));
if (na != 0 || nb != 0) {
if ((na == nb) /* check if the arrays are equivalent */
- && (to->ext_Booleans == from->ext_Booleans)
- && (to->ext_Numbers == from->ext_Numbers)
- && (to->ext_Strings == from->ext_Strings)) {
+ &&(to->ext_Booleans == from->ext_Booleans)
+ && (to->ext_Numbers == from->ext_Numbers)
+ && (to->ext_Strings == from->ext_Strings)) {
for (n = 0, same = TRUE; n < na; n++) {
if (strcmp(to->ext_Names[n], from->ext_Names[n])) {
same = FALSE;
@@ -380,7 +393,7 @@ void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
* into it, updating to's counts for booleans, etc. Fortunately we do
* this only for the terminfo compiler (tic) and comparer (infocmp).
*/
- ext_Names = typeMalloc(char *, na+nb);
+ ext_Names = typeMalloc(char *, na + nb);
if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers))
adjust_cancels(to, from);
@@ -389,62 +402,65 @@ void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
adjust_cancels(from, to);
ext_Booleans = merge_names(ext_Names,
- to->ext_Names,
- to->ext_Booleans,
- from->ext_Names,
- from->ext_Booleans);
- ext_Numbers = merge_names(ext_Names + ext_Booleans,
- to->ext_Names
- + to->ext_Booleans,
- to->ext_Numbers,
- from->ext_Names
- + from->ext_Booleans,
- from->ext_Numbers);
- ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans,
- to->ext_Names
- + to->ext_Booleans
- + to->ext_Numbers,
- to->ext_Strings,
- from->ext_Names
- + from->ext_Booleans
- + from->ext_Numbers,
- from->ext_Strings);
+ to->ext_Names,
+ to->ext_Booleans,
+ from->ext_Names,
+ from->ext_Booleans);
+ ext_Numbers = merge_names(ext_Names + ext_Booleans,
+ to->ext_Names
+ + to->ext_Booleans,
+ to->ext_Numbers,
+ from->ext_Names
+ + from->ext_Booleans,
+ from->ext_Numbers);
+ ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans,
+ to->ext_Names
+ + to->ext_Booleans
+ + to->ext_Numbers,
+ to->ext_Strings,
+ from->ext_Names
+ + from->ext_Booleans
+ + from->ext_Numbers,
+ from->ext_Strings);
/*
* Now we must reallocate the Booleans, etc., to allow the data to be
* overlaid.
*/
if (na != (ext_Booleans + ext_Numbers + ext_Strings)) {
realign_data(to, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
- free(to->ext_Names);
+ FreeIfNeeded(to->ext_Names);
to->ext_Names = ext_Names;
- DEBUG(2, ("realigned %d extended names for '%s' (to)", NUM_EXT_NAMES(to), to->term_names));
+ DEBUG(2, ("realigned %d extended names for '%s' (to)",
+ NUM_EXT_NAMES(to), to->term_names));
}
if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) {
nb = (ext_Booleans + ext_Numbers + ext_Strings);
realign_data(from, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
from->ext_Names = typeRealloc(char *, nb, from->ext_Names);
memcpy(from->ext_Names, ext_Names, sizeof(char *) * nb);
- DEBUG(2, ("realigned %d extended names for '%s' (from)", NUM_EXT_NAMES(from), from->term_names));
+ DEBUG(2, ("realigned %d extended names for '%s' (from)",
+ NUM_EXT_NAMES(from), from->term_names));
}
}
}
#endif
-void _nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src)
+void
+_nc_copy_termtype(TERMTYPE * dst, TERMTYPE * src)
{
int i;
- *dst = *src; /* ...to copy the sizes and string-tables */
- dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst));
- dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst));
- dst->Strings = typeMalloc(char *, NUM_STRINGS(dst));
+ *dst = *src; /* ...to copy the sizes and string-tables */
+ dst->Booleans = typeMalloc(char, NUM_BOOLEANS(dst));
+ dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst));
+ dst->Strings = typeMalloc(char *, NUM_STRINGS(dst));
/* FIXME: use memcpy for these and similar loops */
- for_each_boolean(i,dst)
+ for_each_boolean(i, dst)
dst->Booleans[i] = src->Booleans[i];
- for_each_number(i,dst)
+ for_each_number(i, dst)
dst->Numbers[i] = src->Numbers[i];
- for_each_string(i,dst)
+ for_each_string(i, dst)
dst->Strings[i] = src->Strings[i];
/* FIXME: we probably should also copy str_table and ext_str_table,
@@ -455,6 +471,8 @@ void _nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src)
if ((i = NUM_EXT_NAMES(src)) != 0) {
dst->ext_Names = typeMalloc(char *, i);
memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *));
+ } else {
+ dst->ext_Names = 0;
}
#endif
diff --git a/contrib/ncurses/ncurses/tinfo/captoinfo.c b/contrib/ncurses/ncurses/tinfo/captoinfo.c
index d0881ecd4792..da1382683942 100644
--- a/contrib/ncurses/ncurses/tinfo/captoinfo.c
+++ b/contrib/ncurses/ncurses/tinfo/captoinfo.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,8 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
-
/*
* captoinfo.c --- conversion between termcap and terminfo formats
*
@@ -94,10 +92,9 @@
#include <ctype.h>
#include <tic.h>
-MODULE_ID("$Id: captoinfo.c,v 1.24 1999/07/24 20:06:13 tom Exp $")
+MODULE_ID("$Id: captoinfo.c,v 1.37 2000/04/01 20:07:34 tom Exp $")
#define MAX_PUSHED 16 /* max # args we can push onto the stack */
-#define MAX_ENTRY 2048 /* maximum chars in a translated capability */
static int stack[MAX_PUSHED]; /* the stack */
static int stackptr; /* the next empty place on the stack */
@@ -108,43 +105,47 @@ static int seenr; /* seen a %r */
static int param; /* current parameter */
static char *dp; /* pointer to end of the converted string */
-static char *my_string;
+static char *my_string;
static size_t my_length;
-static char *init_string(void)
+static char *
+init_string(void)
/* initialize 'my_string', 'my_length' */
{
- if (my_string == 0)
- my_string = typeMalloc(char, my_length = 256);
- if (my_string == 0)
- _nc_err_abort("Out of memory");
+ if (my_string == 0)
+ my_string = typeMalloc(char, my_length = 256);
+ if (my_string == 0)
+ _nc_err_abort("Out of memory");
- *my_string = '\0';
- return my_string;
+ *my_string = '\0';
+ return my_string;
}
-static char *save_string(char *d, const char *const s)
+static char *
+save_string(char *d, const char *const s)
{
- size_t have = (d - my_string);
- size_t need = have + strlen(s) + 2;
- if (need > my_length) {
- my_string = (char *)realloc(my_string, my_length = (need + need));
- if (my_string == 0)
- _nc_err_abort("Out of memory");
- d = my_string + have;
- }
- (void) strcpy(d, s);
- return d + strlen(d);
+ size_t have = (d - my_string);
+ size_t need = have + strlen(s) + 2;
+ if (need > my_length) {
+ my_string = (char *) realloc(my_string, my_length = (need + need));
+ if (my_string == 0)
+ _nc_err_abort("Out of memory");
+ d = my_string + have;
+ }
+ (void) strcpy(d, s);
+ return d + strlen(d);
}
-static inline char *save_char(char *s, char c)
+static inline char *
+save_char(char *s, char c)
{
- static char temp[2];
- temp[0] = c;
- return save_string(s, temp);
+ static char temp[2];
+ temp[0] = c;
+ return save_string(s, temp);
}
-static void push(void)
+static void
+push(void)
/* push onstack on to the stack */
{
if (stackptr > MAX_PUSHED)
@@ -153,7 +154,8 @@ static void push(void)
stack[stackptr++] = onstack;
}
-static void pop(void)
+static void
+pop(void)
/* pop the top of the stack into onstack */
{
if (stackptr == 0) {
@@ -161,21 +163,21 @@ static void pop(void)
_nc_warning("I'm confused");
else
onstack = 0;
- }
- else
+ } else
onstack = stack[--stackptr];
param++;
}
-static int cvtchar(register const char *sp)
+static int
+cvtchar(register const char *sp)
/* convert a character to a terminfo push */
{
unsigned char c = 0;
int len;
- switch(*sp) {
+ switch (*sp) {
case '\\':
- switch(*++sp) {
+ switch (*++sp) {
case '\'':
case '$':
case '\\':
@@ -192,8 +194,7 @@ static int cvtchar(register const char *sp)
case '2':
case '3':
len = 1;
- while (isdigit(*sp))
- {
+ while (isdigit(*sp)) {
c = 8 * c + (*sp++ - '0');
len++;
}
@@ -213,65 +214,68 @@ static int cvtchar(register const char *sp)
len = 1;
}
if (isgraph(c) && c != ',' && c != '\'' && c != '\\' && c != ':') {
- *dp++ = '%'; *dp++ = '\''; *dp++ = c; *dp++ = '\'';
+ dp = save_string(dp, "%\'");
+ dp = save_char(dp, c);
+ dp = save_char(dp, '\'');
} else {
- *dp++ = '%'; *dp++ = '{';
+ dp = save_string(dp, "%{");
if (c > 99)
- *dp++ = c / 100 + '0';
+ dp = save_char(dp, c / 100 + '0');
if (c > 9)
- *dp++ = ((int)(c / 10)) % 10 + '0';
- *dp++ = c % 10 + '0';
- *dp++ = '}';
+ dp = save_char(dp, ((int) (c / 10)) % 10 + '0');
+ dp = save_char(dp, c % 10 + '0');
+ dp = save_char(dp, '}');
}
return len;
}
-static void getparm(int parm, int n)
+static void
+getparm(int parm, int n)
/* push n copies of param on the terminfo stack if not already there */
{
- if (seenr) {
- if (parm == 1)
- parm = 2;
- else if (parm == 2)
- parm = 1;
- }
- if (onstack == parm) {
- if (n > 1) {
- _nc_warning("string may not be optimal");
- *dp++ = '%'; *dp++ = 'P'; *dp++ = 'a';
- while(n--) {
- *dp++ = '%'; *dp++ = 'g'; *dp++ = 'a';
- }
- }
- return;
+ if (seenr) {
+ if (parm == 1)
+ parm = 2;
+ else if (parm == 2)
+ parm = 1;
+ }
+ if (onstack == parm) {
+ if (n > 1) {
+ _nc_warning("string may not be optimal");
+ dp = save_string(dp, "%Pa");
+ while (n--) {
+ dp = save_string(dp, "%ga");
+ }
}
- if (onstack != 0)
- push();
+ return;
+ }
+ if (onstack != 0)
+ push();
- onstack = parm;
+ onstack = parm;
- while(n--) { /* %p0 */
- *dp++ = '%'; *dp++ = 'p'; *dp++ = '0' + parm;
- }
+ while (n--) {
+ dp = save_string(dp, "%p");
+ dp = save_char(dp, '0' + parm);
+ }
- if (seenn && parm < 3) { /* %{96}%^ */
- *dp++ = '%'; *dp++ = '{'; *dp++ = '9'; *dp++ = '6'; *dp++ = '}';
- *dp++ = '%'; *dp++ = '^';
- }
+ if (seenn && parm < 3) {
+ dp = save_string(dp, "%{96}%^");
+ }
- if (seenm && parm < 3) { /* %{127}%^ */
- *dp++ = '%'; *dp++ = '{'; *dp++ = '1'; *dp++ = '2'; *dp++ = '7';
- *dp++ = '}'; *dp++ = '%'; *dp++ = '^';
- }
+ if (seenm && parm < 3) {
+ dp = save_string(dp, "%{127}%^");
+ }
}
-char *_nc_captoinfo(
+char *
+_nc_captoinfo(
/* convert a termcap string to terminfo format */
-register const char *cap, /* relevant terminfo capability index */
-register const char *s, /* string value of the capability */
-int const parametrized) /* do % translations if 1, pad translations if >=0 */
+ register const char *cap, /* relevant terminfo capability index */
+ register const char *s, /* string value of the capability */
+ int const parametrized /* do % translations if 1, pad translations if >=0 */
+)
{
- static char line[MAX_ENTRY];
const char *capstart;
stackptr = 0;
@@ -281,27 +285,29 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
seenr = 0;
param = 1;
- dp = line;
+ dp = init_string();
/* skip the initial padding (if we haven't been told not to) */
capstart = 0;
if (s == 0)
s = "";
if (parametrized >= 0 && isdigit(*s))
- for (capstart = s; ; s++)
+ for (capstart = s;; s++)
if (!(isdigit(*s) || *s == '*' || *s == '.'))
break;
- while(*s != '\0') {
- switch(*s) {
+ while (*s != '\0') {
+ switch (*s) {
case '%':
s++;
if (parametrized < 1) {
- *dp++ = '%';
+ dp = save_char(dp, '%');
break;
}
- switch(*s++) {
- case '%': *dp++ = '%'; break;
+ switch (*s++) {
+ case '%':
+ dp = save_char(dp, '%');
+ break;
case 'r':
if (seenr++ == 1) {
_nc_warning("saw %%r twice in %s", cap);
@@ -317,37 +323,33 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
_nc_warning("saw %%n twice in %s", cap);
}
break;
- case 'i': *dp++ = '%'; *dp++ = 'i'; break;
+ case 'i':
+ dp = save_string(dp, "%i");
+ break;
case '6':
case 'B':
- getparm(param, 2);
- /* %{6}%*%+ */
- *dp++ = '%'; *dp++ = '{'; *dp++ = '6';
- *dp++ = '}'; *dp++ = '%'; *dp++ = '*';
- *dp++ = '%'; *dp++ = '+';
+ getparm(param, 1);
+ dp = save_string(dp, "%{10}%/%{16}%*");
+ getparm(param, 1);
+ dp = save_string(dp, "%{10}%m%+");
break;
case '8':
case 'D':
getparm(param, 2);
- /* %{2}%*%- */
- *dp++ = '%'; *dp++ = '{'; *dp++ = '2';
- *dp++ = '}'; *dp++ = '%'; *dp++ = '*';
- *dp++ = '%'; *dp++ = '-';
+ dp = save_string(dp, "%{2}%*%-");
break;
case '>':
getparm(param, 2);
/* %?%{x}%>%t%{y}%+%; */
- *dp++ = '%'; *dp++ = '?';
+ dp = save_string(dp, "%?");
s += cvtchar(s);
- *dp++ = '%'; *dp++ = '>';
- *dp++ = '%'; *dp++ = 't';
+ dp = save_string(dp, "%>%t");
s += cvtchar(s);
- *dp++ = '%'; *dp++ = '+';
- *dp++ = '%'; *dp++ = ';';
+ dp = save_string(dp, "%+%;");
break;
case 'a':
if ((*s == '=' || *s == '+' || *s == '-'
- || *s == '*' || *s == '/')
+ || *s == '*' || *s == '/')
&& (s[1] == 'p' || s[1] == 'c')
&& s[2] != '\0') {
int l;
@@ -363,18 +365,18 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
l++;
} else
l += cvtchar(s + 2);
- switch(*s) {
+ switch (*s) {
case '+':
- *dp++ = '%'; *dp++ = '+';
+ dp = save_string(dp, "%+");
break;
case '-':
- *dp++ = '%'; *dp++ = '-';
+ dp = save_string(dp, "%-");
break;
case '*':
- *dp++ = '%'; *dp++ = '*';
+ dp = save_string(dp, "%*");
break;
case '/':
- *dp++ = '%'; *dp++ = '/';
+ dp = save_string(dp, "%/");
break;
case '=':
if (seenr) {
@@ -384,8 +386,7 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
onstack = 1;
else
onstack = param;
- }
- else
+ } else
onstack = param;
break;
}
@@ -394,39 +395,37 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
}
getparm(param, 1);
s += cvtchar(s);
- *dp++ = '%'; *dp++ = '+';
+ dp = save_string(dp, "%+");
break;
case '+':
getparm(param, 1);
s += cvtchar(s);
- *dp++ = '%'; *dp++ = '+';
- *dp++ = '%'; *dp++ = 'c';
+ dp = save_string(dp, "%+%c");
pop();
break;
case 's':
#ifdef WATERLOO
s += cvtchar(s);
getparm(param, 1);
- *dp++ = '%'; *dp++ = '-';
+ dp = save_string(dp, "%-");
#else
getparm(param, 1);
- *dp++ = '%'; *dp++ = 's';
+ dp = save_string(dp, "%s");
pop();
#endif /* WATERLOO */
break;
case '-':
s += cvtchar(s);
getparm(param, 1);
- *dp++ = '%'; *dp++ = '-';
- *dp++ = '%'; *dp++ = 'c';
+ dp = save_string(dp, "%-%c");
pop();
break;
case '.':
getparm(param, 1);
- *dp++ = '%'; *dp++ = 'c';
+ dp = save_string(dp, "%c");
pop();
break;
- case '0': /* not clear any of the historical termcaps did this */
+ case '0': /* not clear any of the historical termcaps did this */
if (*s == '3')
goto see03;
else if (*s != '2')
@@ -434,19 +433,18 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
/* FALLTHRU */
case '2':
getparm(param, 1);
- *dp++ = '%'; /* *dp++ = '0'; */
- *dp++ = '2'; *dp++ = 'd';
+ dp = save_string(dp, "%2d");
pop();
break;
- case '3': see03:
+ case '3':
+ see03:
getparm(param, 1);
- *dp++ = '%'; /* *dp++ = '0'; */
- *dp++ = '3'; *dp++ = 'd';
+ dp = save_string(dp, "%3d");
pop();
break;
case 'd':
getparm(param, 1);
- *dp++ = '%'; *dp++ = 'd';
+ dp = save_string(dp, "%d");
pop();
break;
case 'f':
@@ -456,61 +454,82 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
param--;
break;
case '\\':
- *dp++ = '%';
- *dp++ = '\\';
+ dp = save_string(dp, "%\\");
break;
- default: invalid:
- *dp++ = '%';
+ default:
+ invalid:
+ dp = save_char(dp, '%');
s--;
- _nc_warning("unknown %% code %s in %s",
- _tracechar(*s), cap);
+ _nc_warning("unknown %% code %s (%#x) in %s",
+ unctrl(*s), (*s) & 0xff, cap);
break;
}
break;
#ifdef REVISIBILIZE
case '\\':
- *dp++ = *s++; *dp++ = *s++; break;
+ dp = save_char(dp, *s++);
+ dp = save_char(dp, *s++);
+ break;
case '\n':
- *dp++ = '\\'; *dp++ = 'n'; s++; break;
+ dp = save_string(dp, "\\n");
+ s++;
+ break;
case '\t':
- *dp++ = '\\'; *dp++ = 't'; s++; break;
+ dp = save_string(dp, "\\t");
+ s++;
+ break;
case '\r':
- *dp++ = '\\'; *dp++ = 'r'; s++; break;
+ dp = save_string(dp, "\\r");
+ s++;
+ break;
case '\200':
- *dp++ = '\\'; *dp++ = '0'; s++; break;
+ dp = save_string(dp, "\\0");
+ s++;
+ break;
case '\f':
- *dp++ = '\\'; *dp++ = 'f'; s++; break;
+ dp = save_string(dp, "\\f");
+ s++;
+ break;
case '\b':
- *dp++ = '\\'; *dp++ = 'b'; s++; break;
+ dp = save_string(dp, "\\b");
+ s++;
+ break;
case ' ':
- *dp++ = '\\'; *dp++ = 's'; s++; break;
+ dp = save_string(dp, "\\s");
+ s++;
+ break;
case '^':
- *dp++ = '\\'; *dp++ = '^'; s++; break;
+ dp = save_string(dp, "\\^");
+ s++;
+ break;
case ':':
- *dp++ = '\\'; *dp++ = ':'; s++; break;
+ dp = save_string(dp, "\\:");
+ s++;
+ break;
case ',':
- *dp++ = '\\'; *dp++ = ','; s++; break;
+ dp = save_string(dp, "\\,");
+ s++;
+ break;
default:
if (*s == '\033') {
- *dp++ = '\\';
- *dp++ = 'E';
+ dp = save_string(dp, "\\E");
s++;
} else if (*s > 0 && *s < 32) {
- *dp++ = '^';
- *dp++ = *s + '@';
+ dp = save_char(dp, '^');
+ dp = save_char(dp, *s + '@');
s++;
} else if (*s <= 0 || *s >= 127) {
- *dp++ = '\\';
- *dp++ = ((*s & 0300) >> 6) + '0';
- *dp++ = ((*s & 0070) >> 3) + '0';
- *dp++ = (*s & 0007) + '0';
+ dp = save_char(dp, '\\');
+ dp = save_char(dp, ((*s & 0300) >> 6) + '0');
+ dp = save_char(dp, ((*s & 0070) >> 3) + '0');
+ dp = save_char(dp, (*s & 0007) + '0');
s++;
} else
- *dp++ = *s++;
+ dp = save_char(dp, *s++);
break;
#else
default:
- *dp++ = *s++;
+ dp = save_char(dp, *s++);
break;
#endif
}
@@ -520,21 +539,76 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
* Now, if we stripped off some leading padding, add it at the end
* of the string as mandatory padding.
*/
- if (capstart)
- {
- *dp++ = '$';
- *dp++ = '<';
- for (s = capstart; ; s++)
+ if (capstart) {
+ dp = save_string(dp, "$<");
+ for (s = capstart;; s++)
if (isdigit(*s) || *s == '*' || *s == '.')
- *dp++ = *s;
+ dp = save_char(dp, *s);
else
break;
- *dp++ = '/';
- *dp++ = '>';
+ dp = save_string(dp, "/>");
+ }
+
+ (void) save_char(dp, '\0');
+ return (my_string);
+}
+
+/*
+ * Check for an expression that corresponds to "%B" (BCD):
+ * (parameter / 10) * 16 + (parameter % 10)
+ */
+static int
+bcd_expression(const char *str)
+{
+ /* leave this non-const for HPUX */
+ static char fmt[] = "%%p%c%%{10}%%/%%{16}%%*%%p%c%%{10}%%m%%+";
+ int len = 0;
+ char ch1, ch2;
+
+ if (sscanf(str, fmt, &ch1, &ch2) == 2
+ && isdigit(ch1)
+ && isdigit(ch2)
+ && (ch1 == ch2)) {
+ len = 28;
+#ifndef NDEBUG
+ {
+ char buffer[80];
+ int tst;
+ sprintf(buffer, fmt, ch1, ch2);
+ tst = strlen(buffer) - 1;
+ assert(len == tst);
+ }
+#endif
}
+ return len;
+}
+
+static char *
+save_tc_char(char *bufptr, int c1)
+{
+ char temp[80];
- *dp = '\0';
- return(line);
+ if (is7bits(c1) && isprint(c1)) {
+ if (c1 == ':' || c1 == '\\')
+ bufptr = save_char(bufptr, '\\');
+ bufptr = save_char(bufptr, c1);
+ } else {
+ if (c1 == (c1 & 0x1f)) /* iscntrl() returns T on 255 */
+ (void) strcpy(temp, unctrl(c1));
+ else
+ (void) sprintf(temp, "\\%03o", c1);
+ bufptr = save_string(bufptr, temp);
+ }
+ return bufptr;
+}
+
+static char *
+save_tc_inequality(char *bufptr, int c1, int c2)
+{
+ bufptr = save_string(bufptr, "%>");
+ bufptr = save_tc_char(bufptr, c1);
+ bufptr = save_tc_char(bufptr, c2);
+ return bufptr;
}
/*
@@ -555,23 +629,25 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
* %m exclusive-or all parameters with 0177 (not in 4.4BSD)
*/
-char *_nc_infotocap(
+char *
+_nc_infotocap(
/* convert a terminfo string to termcap format */
-register const char *cap GCC_UNUSED, /* relevant termcap capability index */
-register const char *str, /* string value of the capability */
-int const parametrized) /* do % translations if 1, pad translations if >=0 */
+ register const char *cap GCC_UNUSED, /* relevant termcap capability index */
+ register const char *str, /* string value of the capability */
+ int const parametrized /* do % translations if 1, pad translations if >=0 */
+)
{
- int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
+ int seenone = 0, seentwo = 0, saw_m = 0, saw_n = 0;
const char *padding;
const char *trimmed = 0;
char ch1 = 0, ch2 = 0;
char *bufptr = init_string();
- char temp[256];
+ int len;
+ bool syntax_error = FALSE;
/* we may have to move some trailing mandatory padding up front */
padding = str + strlen(str) - 1;
- if (*padding == '>' && *--padding == '/')
- {
+ if (*padding == '>' && *--padding == '/') {
--padding;
while (isdigit(*padding) || *padding == '.' || *padding == '*')
padding--;
@@ -583,101 +659,62 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
bufptr = save_char(bufptr, *padding++);
}
- for (; *str && str != trimmed; str++)
- {
- int c1, c2;
- char *cp = 0;
+ for (; *str && str != trimmed; str++) {
+ int c1, c2;
+ char *cp = 0;
- if (str[0] == '\\' && (str[1] == '^' || str[1] == ','))
- {
+ if (str[0] == '\\' && (str[1] == '^' || str[1] == ',')) {
bufptr = save_char(bufptr, *++str);
- }
- else if (str[0] == '$' && str[1] == '<') /* discard padding */
- {
+ } else if (str[0] == '$' && str[1] == '<') { /* discard padding */
str += 2;
- while (isdigit(*str) || *str == '.' || *str == '*' || *str == '/' || *str == '>')
+ while (isdigit(*str) || *str == '.' || *str == '*' || *str ==
+ '/' || *str == '>')
str++;
--str;
- }
- else if (*str != '%' || (parametrized < 1))
+ } else if (str[0] == '%' && str[1] == '%') { /* escaped '%' */
+ bufptr = save_string(bufptr, "%%");
+ } else if (*str != '%' || (parametrized < 1)) {
bufptr = save_char(bufptr, *str);
- else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1,&c2) == 2)
- {
+ } else if (sscanf(str, "%%?%%{%d}%%>%%t%%{%d}%%+%%;", &c1, &c2) == 2) {
str = strchr(str, ';');
- (void) sprintf(temp, "%%>%s%s", unctrl(c1), unctrl(c2));
- bufptr = save_string(bufptr, temp);
- }
- else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1,&ch2) == 2)
- {
+ bufptr = save_tc_inequality(bufptr, c1, c2);
+ } else if (sscanf(str, "%%?%%{%d}%%>%%t%%'%c'%%+%%;", &c1, &ch2) == 2) {
str = strchr(str, ';');
- (void) sprintf(temp, "%%>%s%c", unctrl(c1), ch2);
- bufptr = save_string(bufptr, temp);
- }
- else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1,&c2) == 2)
- {
+ bufptr = save_tc_inequality(bufptr, c1, c2);
+ } else if (sscanf(str, "%%?%%'%c'%%>%%t%%{%d}%%+%%;", &ch1, &c2) == 2) {
str = strchr(str, ';');
- (void) sprintf(temp, "%%>%c%c", ch1, c2);
- bufptr = save_string(bufptr, temp);
- }
- else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2)
- {
+ bufptr = save_tc_inequality(bufptr, c1, c2);
+ } else if (sscanf(str, "%%?%%'%c'%%>%%t%%'%c'%%+%%;", &ch1, &ch2) == 2) {
str = strchr(str, ';');
- (void) sprintf(temp, "%%>%c%c", ch1, ch2);
- bufptr = save_string(bufptr, temp);
- }
- else if (strncmp(str, "%{6}%*%+", 8) == 0)
- {
- str += 7;
- (void) sprintf(temp, "%%B");
- bufptr = save_string(bufptr, temp);
- }
- else if ((sscanf(str, "%%{%d}%%+%%c", &c1) == 1
- || sscanf(str, "%%'%c'%%+%%c", &ch1) == 1)
- && (cp = strchr(str, '+')))
- {
+ bufptr = save_tc_inequality(bufptr, c1, c2);
+ } else if ((len = bcd_expression(str)) != 0) {
+ str += len;
+ bufptr = save_string(bufptr, "%B");
+ } else if ((sscanf(str, "%%{%d}%%+%%c", &c1) == 1
+ || sscanf(str, "%%'%c'%%+%%c", &ch1) == 1)
+ && (cp = strchr(str, '+'))) {
str = cp + 2;
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, '+');
+ bufptr = save_string(bufptr, "%+");
if (ch1)
c1 = ch1;
- if (is7bits(c1) && isprint(c1))
- bufptr = save_char(bufptr, (char)c1);
- else
- {
- if (c1 == (c1 & 0x1f)) /* iscntrl() returns T on 255 */
- (void) strcpy(temp, unctrl(c1));
- else
- (void) sprintf(temp, "\\%03o", c1);
- bufptr = save_string(bufptr, temp);
- }
+ bufptr = save_tc_char(bufptr, c1);
}
- else if (strncmp(str, "%{2}%*%-", 8) == 0)
- {
+ /* FIXME: this "works" for 'delta' */
+ else if (strncmp(str, "%{2}%*%-", 8) == 0) {
str += 7;
- (void) sprintf(temp, "%%D");
- bufptr = save_string(bufptr, temp);
- }
- else if (strncmp(str, "%{96}%^", 7) == 0)
- {
+ bufptr = save_string(bufptr, "%D");
+ } else if (strncmp(str, "%{96}%^", 7) == 0) {
str += 6;
- if (saw_m++ == 0)
- {
- (void) sprintf(temp, "%%n");
- bufptr = save_string(bufptr, temp);
+ if (saw_m++ == 0) {
+ bufptr = save_string(bufptr, "%n");
}
- }
- else if (strncmp(str, "%{127}%^", 8) == 0)
- {
+ } else if (strncmp(str, "%{127}%^", 8) == 0) {
str += 7;
- if (saw_n++ == 0)
- {
- (void) sprintf(temp, "%%m");
- bufptr = save_string(bufptr, temp);
+ if (saw_n++ == 0) {
+ bufptr = save_string(bufptr, "%m");
}
- }
- else
- {
+ } else { /* cm-style format element */
str++;
switch (*str) {
case '%':
@@ -697,90 +734,80 @@ int const parametrized) /* do % translations if 1, pad translations if >=0 */
bufptr = save_char(bufptr, '%');
while (isdigit(*str))
bufptr = save_char(bufptr, *str++);
- if (*str == 'd')
- str++;
- else
- _nc_warning("numeric prefix is missing trailing d in %s",
- cap);
- --str;
+ if (strchr("doxX.", *str)) {
+ if (*str != 'd') /* termcap doesn't have octal, hex */
+ return 0;
+ }
break;
case 'd':
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, 'd');
+ bufptr = save_string(bufptr, "%d");
break;
case 'c':
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, '.');
+ bufptr = save_string(bufptr, "%.");
break;
- /*
- * %s isn't in termcap, but it's convenient to pass it through
- * so we can represent things like terminfo pfkey strings in
- * termcap notation.
- */
+ /*
+ * %s isn't in termcap, but it's convenient to pass it through
+ * so we can represent things like terminfo pfkey strings in
+ * termcap notation.
+ */
case 's':
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, 's');
+ bufptr = save_string(bufptr, "%s");
break;
case 'p':
str++;
if (*str == '1')
seenone = 1;
- else if (*str == '2')
- {
- if (!seenone && !seentwo)
- {
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, 'r');
+ else if (*str == '2') {
+ if (!seenone && !seentwo) {
+ bufptr = save_string(bufptr, "%r");
seentwo++;
}
- }
- else if (*str >= '3')
- return(0);
+ } else if (*str >= '3')
+ return (0);
break;
case 'i':
- bufptr = save_char(bufptr, '%');
- bufptr = save_char(bufptr, 'i');
+ bufptr = save_string(bufptr, "%i");
break;
default:
- return(0);
-
- } /* endswitch (*str) */
- } /* endelse (*str == '%') */
+ bufptr = save_char(bufptr, *str);
+ syntax_error = TRUE;
+ break;
+ } /* endswitch (*str) */
+ } /* endelse (*str == '%') */
if (*str == '\0')
break;
- } /* endwhile (*str) */
+ } /* endwhile (*str) */
- return(my_string);
+ return (syntax_error ? NULL : my_string);
}
#ifdef MAIN
int curr_line;
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
int c, tc = FALSE;
while ((c = getopt(argc, argv, "c")) != EOF)
- switch (c)
- {
+ switch (c) {
case 'c':
tc = TRUE;
break;
}
curr_line = 0;
- for (;;)
- {
- char buf[BUFSIZ];
+ for (;;) {
+ char buf[BUFSIZ];
++curr_line;
if (fgets(buf, sizeof(buf), stdin) == 0)
@@ -788,20 +815,17 @@ int main(int argc, char *argv[])
buf[strlen(buf) - 1] = '\0';
_nc_set_source(buf);
- if (tc)
- {
- char *cp = _nc_infotocap("to termcap", buf, 1);
+ if (tc) {
+ char *cp = _nc_infotocap("to termcap", buf, 1);
if (cp)
(void) fputs(cp, stdout);
- }
- else
+ } else
(void) fputs(_nc_captoinfo("to terminfo", buf, 1), stdout);
(void) putchar('\n');
}
- return(0);
+ return (0);
}
#endif /* MAIN */
/* captoinfo.c ends here */
-
diff --git a/contrib/ncurses/ncurses/tinfo/comp_error.c b/contrib/ncurses/ncurses/tinfo/comp_error.c
index 2b2d503013c0..3767063da0a6 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_error.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_error.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * 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 *
@@ -41,11 +41,11 @@
#include <tic.h>
-MODULE_ID("$Id: comp_error.c,v 1.16 1998/08/01 23:39:51 tom Exp $")
+MODULE_ID("$Id: comp_error.c,v 1.17 1999/10/30 23:00:16 tom Exp $")
-bool _nc_suppress_warnings;
-int _nc_curr_line; /* current line # in input */
-int _nc_curr_col; /* current column # in input */
+bool _nc_suppress_warnings = FALSE;
+int _nc_curr_line = 0; /* current line # in input */
+int _nc_curr_col = 0; /* current column # in input */
static const char *sourcename;
static char termtype[MAX_NAME_SIZE+1];
diff --git a/contrib/ncurses/ncurses/tinfo/comp_parse.c b/contrib/ncurses/ncurses/tinfo/comp_parse.c
index be419ca3e790..ca58bb5746e7 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_parse.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_parse.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,8 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
-
/*
* comp_parse.c -- parser driver loop and use handling.
*
@@ -54,10 +52,10 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: comp_parse.c,v 1.34 1999/02/27 22:13:02 tom Exp $")
+MODULE_ID("$Id: comp_parse.c,v 1.40 2000/04/15 16:57:08 tom Exp $")
static void sanity_check(TERMTYPE *);
-void (*_nc_check_termtype)(TERMTYPE *) = sanity_check;
+void (*_nc_check_termtype) (TERMTYPE *) = sanity_check;
/****************************************************************************
*
@@ -80,31 +78,32 @@ void (*_nc_check_termtype)(TERMTYPE *) = sanity_check;
* _nc_head _nc_tail
*/
-ENTRY *_nc_head, *_nc_tail;
+ENTRY *_nc_head = 0, *_nc_tail = 0;
-static void enqueue(ENTRY *ep)
+static void
+enqueue(ENTRY * ep)
/* add an entry to the in-core list */
{
- ENTRY *newp = _nc_copy_entry(ep);
+ ENTRY *newp = _nc_copy_entry(ep);
- if (newp == NULL)
- _nc_err_abort("Out of memory");
+ if (newp == 0)
+ _nc_err_abort("Out of memory");
- newp->last = _nc_tail;
- _nc_tail = newp;
+ newp->last = _nc_tail;
+ _nc_tail = newp;
- newp->next = (ENTRY *)NULL;
- if (newp->last)
- newp->last->next = newp;
+ newp->next = 0;
+ if (newp->last)
+ newp->last->next = newp;
}
-void _nc_free_entries(ENTRY *head)
+void
+_nc_free_entries(ENTRY * headp)
/* free the allocated storage consumed by list entries */
{
- ENTRY *ep, *next;
+ ENTRY *ep, *next;
- for (ep = head; ep; ep = next)
- {
+ for (ep = headp; ep; ep = next) {
/*
* This conditional lets us disconnect storage from the list.
* To do this, copy an entry out of the list, then null out
@@ -116,27 +115,28 @@ void _nc_free_entries(ENTRY *head)
next = ep->next;
free(ep);
- if (ep == _nc_head) _nc_head = 0;
- if (ep == _nc_tail) _nc_tail = 0;
+ if (ep == _nc_head)
+ _nc_head = 0;
+ if (ep == _nc_tail)
+ _nc_tail = 0;
}
}
-bool _nc_entry_match(char *n1, char *n2)
+bool
+_nc_entry_match(char *n1, char *n2)
/* do any of the aliases in a pair of terminal names match? */
{
- char *pstart, *qstart, *pend, *qend;
- char nc1[MAX_NAME_SIZE+1], nc2[MAX_NAME_SIZE+1];
+ char *pstart, *qstart, *pend, *qend;
+ char nc1[MAX_NAME_SIZE + 1], nc2[MAX_NAME_SIZE + 1];
- if (strchr(n1, '|') == NULL)
- {
+ if (strchr(n1, '|') == 0) {
(void) strncpy(nc1, n1, sizeof(nc1) - 2);
nc1[sizeof(nc1) - 2] = '\0';
(void) strcat(nc1, "|");
n1 = nc1;
}
- if (strchr(n2, '|') == NULL)
- {
+ if (strchr(n2, '|') == 0) {
(void) strncpy(nc2, n2, sizeof(nc2) - 2);
nc2[sizeof(nc2) - 2] = '\0';
(void) strcat(nc2, "|");
@@ -145,11 +145,11 @@ bool _nc_entry_match(char *n1, char *n2)
for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1)
for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1)
- if ((pend-pstart == qend-qstart)
- && memcmp(pstart, qstart, (size_t)(pend-pstart)) == 0)
- return(TRUE);
+ if ((pend - pstart == qend - qstart)
+ && memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0)
+ return (TRUE);
- return(FALSE);
+ return (FALSE);
}
/****************************************************************************
@@ -158,21 +158,24 @@ bool _nc_entry_match(char *n1, char *n2)
*
****************************************************************************/
-void _nc_read_entry_source(FILE *fp, char *buf,
- int literal, bool silent,
- bool (*hook)(ENTRY *))
+void
+_nc_read_entry_source(FILE * fp, char *buf,
+ int literal, bool silent,
+ bool(*hook) (ENTRY *))
/* slurp all entries in the given file into core */
{
- ENTRY thisentry;
- bool oldsuppress = _nc_suppress_warnings;
- int immediate = 0;
+ ENTRY thisentry;
+ bool oldsuppress = _nc_suppress_warnings;
+ int immediate = 0;
if (silent)
_nc_suppress_warnings = TRUE; /* shut the lexer up, too */
- memset(&thisentry, 0, sizeof(thisentry));
- for (_nc_reset_input(fp, buf); _nc_parse_entry(&thisentry, literal, silent) != ERR; )
- {
+ _nc_reset_input(fp, buf);
+ for (;;) {
+ memset(&thisentry, 0, sizeof(thisentry));
+ if (_nc_parse_entry(&thisentry, literal, silent) == ERR)
+ break;
if (!isalnum(thisentry.tterm.term_names[0]))
_nc_err_abort("terminal names must start with letter or digit");
@@ -181,14 +184,13 @@ void _nc_read_entry_source(FILE *fp, char *buf,
* use references to disk, so as to avoid chewing up a lot of
* core when the resolution code could fetch entries off disk.
*/
- if (hook != NULLHOOK && (*hook)(&thisentry))
+ if (hook != NULLHOOK && (*hook) (&thisentry))
immediate++;
else
enqueue(&thisentry);
}
- if (_nc_tail)
- {
+ if (_nc_tail) {
/* set up the head pointer */
for (_nc_head = _nc_tail; _nc_head->last; _nc_head = _nc_head->last)
continue;
@@ -204,12 +206,13 @@ void _nc_read_entry_source(FILE *fp, char *buf,
_nc_suppress_warnings = oldsuppress;
}
-int _nc_resolve_uses(void)
+int
+_nc_resolve_uses(bool fullresolve)
/* try to resolve all use capabilities */
{
- ENTRY *qp, *rp, *lastread = NULL;
- bool keepgoing;
- int i, j, unresolved, total_unresolved, multiples;
+ ENTRY *qp, *rp, *lastread = 0;
+ bool keepgoing;
+ int i, j, unresolved, total_unresolved, multiples;
DEBUG(2, ("RESOLUTION BEGINNING"));
@@ -217,48 +220,41 @@ int _nc_resolve_uses(void)
* Check for multiple occurrences of the same name.
*/
multiples = 0;
- for_entry_list(qp)
- {
+ for_entry_list(qp) {
int matchcount = 0;
for_entry_list(rp)
if (qp > rp
- && _nc_entry_match(qp->tterm.term_names, rp->tterm.term_names))
- {
- matchcount++;
- if (matchcount == 1)
- {
- (void) fprintf(stderr, "Name collision between %s",
- _nc_first_name(qp->tterm.term_names));
- multiples++;
- }
- if (matchcount >= 1)
- (void) fprintf(stderr, " %s", _nc_first_name(rp->tterm.term_names));
+ && _nc_entry_match(qp->tterm.term_names, rp->tterm.term_names)) {
+ matchcount++;
+ if (matchcount == 1) {
+ (void) fprintf(stderr, "Name collision between %s",
+ _nc_first_name(qp->tterm.term_names));
+ multiples++;
}
+ if (matchcount >= 1)
+ (void) fprintf(stderr, " %s", _nc_first_name(rp->tterm.term_names));
+ }
if (matchcount >= 1)
(void) putc('\n', stderr);
}
if (multiples > 0)
- return(FALSE);
+ return (FALSE);
DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES"));
/*
- * First resolution stage: replace names in use arrays with entry
- * pointers. By doing this, we avoid having to do the same name
- * match once for each time a use entry is itself unresolved.
+ * First resolution stage: compute link pointers corresponding to names.
*/
total_unresolved = 0;
_nc_curr_col = -1;
- for_entry_list(qp)
- {
+ for_entry_list(qp) {
unresolved = 0;
- for (i = 0; i < qp->nuses; i++)
- {
- bool foundit;
- char *child = _nc_first_name(qp->tterm.term_names);
- char *lookfor = (char *)(qp->uses[i].parent);
- long lookline = qp->uses[i].line;
+ for (i = 0; i < qp->nuses; i++) {
+ bool foundit;
+ char *child = _nc_first_name(qp->tterm.term_names);
+ char *lookfor = qp->uses[i].name;
+ long lookline = qp->uses[i].line;
foundit = FALSE;
@@ -267,146 +263,142 @@ int _nc_resolve_uses(void)
/* first, try to resolve from in-core records */
for_entry_list(rp)
if (rp != qp
- && _nc_name_match(rp->tterm.term_names, lookfor, "|"))
- {
- DEBUG(2, ("%s: resolving use=%s (in core)",
- child, lookfor));
+ && _nc_name_match(rp->tterm.term_names, lookfor, "|")) {
+ DEBUG(2, ("%s: resolving use=%s (in core)",
+ child, lookfor));
- qp->uses[i].parent = rp;
- foundit = TRUE;
- }
+ qp->uses[i].link = rp;
+ foundit = TRUE;
+ }
/* if that didn't work, try to merge in a compiled entry */
- if (!foundit)
- {
- TERMTYPE thisterm;
- char filename[PATH_MAX];
+ if (!foundit) {
+ TERMTYPE thisterm;
+ char filename[PATH_MAX];
memset(&thisterm, 0, sizeof(thisterm));
- if (_nc_read_entry(lookfor, filename, &thisterm) == 1)
- {
+ if (_nc_read_entry(lookfor, filename, &thisterm) == 1) {
DEBUG(2, ("%s: resolving use=%s (compiled)",
- child, lookfor));
+ child, lookfor));
- rp = typeMalloc(ENTRY,1);
- if (rp == NULL)
+ rp = typeMalloc(ENTRY, 1);
+ if (rp == 0)
_nc_err_abort("Out of memory");
rp->tterm = thisterm;
rp->nuses = 0;
rp->next = lastread;
lastread = rp;
- qp->uses[i].parent = rp;
+ qp->uses[i].link = rp;
foundit = TRUE;
}
}
/* no good, mark this one unresolvable and complain */
- if (!foundit)
- {
+ if (!foundit) {
unresolved++;
total_unresolved++;
_nc_curr_line = lookline;
_nc_warning("resolution of use=%s failed", lookfor);
- qp->uses[i].parent = (ENTRY *)NULL;
+ qp->uses[i].link = 0;
}
}
}
- if (total_unresolved)
- {
+ if (total_unresolved) {
/* free entries read in off disk */
_nc_free_entries(lastread);
- return(FALSE);
+ return (FALSE);
}
DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));
/*
- * OK, at this point all (char *) references have been successfully
- * replaced by (ENTRY *) pointers. Time to do the actual merges.
+ * OK, at this point all (char *) references in `name' mwmbers
+ * have been successfully converred to (ENTRY *) pointers in
+ * `link' members. Time to do the actual merges.
*/
- do {
- TERMTYPE merged;
-
- keepgoing = FALSE;
-
- for_entry_list(qp)
- {
- if (qp->nuses > 0)
- {
- DEBUG(2, ("%s: attempting merge", _nc_first_name(qp->tterm.term_names)));
- /*
- * If any of the use entries we're looking for is
- * incomplete, punt. We'll catch this entry on a
- * subsequent pass.
- */
- for (i = 0; i < qp->nuses; i++)
- if (((ENTRY *)qp->uses[i].parent)->nuses)
- {
- DEBUG(2, ("%s: use entry %d unresolved",
- _nc_first_name(qp->tterm.term_names), i));
- goto incomplete;
- }
-
- /*
- * First, make sure there's no garbage in the merge block.
- * as a side effect, copy into the merged entry the name
- * field and string table pointer.
- */
- _nc_copy_termtype(&merged, &(qp->tterm));
-
- /*
- * Now merge in each use entry in the proper
- * (reverse) order.
- */
- for (; qp->nuses; qp->nuses--)
- _nc_merge_entry(&merged,
- &((ENTRY *)qp->uses[qp->nuses-1].parent)->tterm);
-
- /*
- * Now merge in the original entry.
- */
- _nc_merge_entry(&merged, &qp->tterm);
-
- /*
- * Replace the original entry with the merged one.
- */
- FreeIfNeeded(qp->tterm.Booleans);
- FreeIfNeeded(qp->tterm.Numbers);
- FreeIfNeeded(qp->tterm.Strings);
- qp->tterm = merged;
-
- /*
- * We know every entry is resolvable because name resolution
- * didn't bomb. So go back for another pass.
- */
- /* FALLTHRU */
- incomplete:
- keepgoing = TRUE;
+ if (fullresolve) {
+ do {
+ TERMTYPE merged;
+
+ keepgoing = FALSE;
+
+ for_entry_list(qp) {
+ if (qp->nuses > 0) {
+ DEBUG(2, ("%s: attempting merge",
+ _nc_first_name(qp->tterm.term_names)));
+ /*
+ * If any of the use entries we're looking for is
+ * incomplete, punt. We'll catch this entry on a
+ * subsequent pass.
+ */
+ for (i = 0; i < qp->nuses; i++)
+ if (qp->uses[i].link->nuses) {
+ DEBUG(2, ("%s: use entry %d unresolved",
+ _nc_first_name(qp->tterm.term_names), i));
+ goto incomplete;
+ }
+
+ /*
+ * First, make sure there's no garbage in the
+ * merge block. as a side effect, copy into
+ * the merged entry the name field and string
+ * table pointer.
+ */
+ _nc_copy_termtype(&merged, &(qp->tterm));
+
+ /*
+ * Now merge in each use entry in the proper
+ * (reverse) order.
+ */
+ for (; qp->nuses; qp->nuses--)
+ _nc_merge_entry(&merged,
+ &qp->uses[qp->nuses - 1].link->tterm);
+
+ /*
+ * Now merge in the original entry.
+ */
+ _nc_merge_entry(&merged, &qp->tterm);
+
+ /*
+ * Replace the original entry with the merged one.
+ */
+ FreeIfNeeded(qp->tterm.Booleans);
+ FreeIfNeeded(qp->tterm.Numbers);
+ FreeIfNeeded(qp->tterm.Strings);
+ qp->tterm = merged;
+
+ /*
+ * We know every entry is resolvable because name resolution
+ * didn't bomb. So go back for another pass.
+ */
+ /* FALLTHRU */
+ incomplete:
+ keepgoing = TRUE;
+ }
}
- }
- } while
- (keepgoing);
+ } while
+ (keepgoing);
- DEBUG(2, ("MERGES COMPLETED OK"));
+ DEBUG(2, ("MERGES COMPLETED OK"));
- /*
- * The exit condition of the loop above is such that all entries
- * must now be resolved. Now handle cancellations. In a resolved
- * entry there should be no cancellation markers.
- */
- for_entry_list(qp)
- {
- for_each_boolean(j, &(qp->tterm))
- if (qp->tterm.Booleans[j] == CANCELLED_BOOLEAN)
- qp->tterm.Booleans[j] = FALSE;
- for_each_number(j, &(qp->tterm))
- if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC)
+ /*
+ * The exit condition of the loop above is such that all entries
+ * must now be resolved. Now handle cancellations. In a resolved
+ * entry there should be no cancellation markers.
+ */
+ for_entry_list(qp) {
+ for_each_boolean(j, &(qp->tterm))
+ if (qp->tterm.Booleans[j] == CANCELLED_BOOLEAN)
+ qp->tterm.Booleans[j] = ABSENT_BOOLEAN;
+ for_each_number(j, &(qp->tterm))
+ if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC)
qp->tterm.Numbers[j] = ABSENT_NUMERIC;
- for_each_string(j, &(qp->tterm))
- if (qp->tterm.Strings[j] == CANCELLED_STRING)
+ for_each_string(j, &(qp->tterm))
+ if (qp->tterm.Strings[j] == CANCELLED_STRING)
qp->tterm.Strings[j] = ABSENT_STRING;
+ }
}
/*
@@ -418,19 +410,18 @@ int _nc_resolve_uses(void)
DEBUG(2, ("RESOLUTION FINISHED"));
- if (_nc_check_termtype != 0)
- {
- _nc_curr_col = -1;
- for_entry_list(qp)
- {
- _nc_curr_line = qp->startline;
- _nc_set_type(_nc_first_name(qp->tterm.term_names));
- _nc_check_termtype(&qp->tterm);
+ if (fullresolve)
+ if (_nc_check_termtype != 0) {
+ _nc_curr_col = -1;
+ for_entry_list(qp) {
+ _nc_curr_line = qp->startline;
+ _nc_set_type(_nc_first_name(qp->tterm.term_names));
+ _nc_check_termtype(&qp->tterm);
+ }
+ DEBUG(2, ("SANITY CHECK FINISHED"));
}
- DEBUG(2, ("SANITY CHECK FINISHED"));
- }
- return(TRUE);
+ return (TRUE);
}
/*
@@ -442,14 +433,14 @@ int _nc_resolve_uses(void)
#undef CUR
#define CUR tp->
-static void sanity_check(TERMTYPE *tp)
+static void
+sanity_check(TERMTYPE * tp)
{
- if (!PRESENT(exit_attribute_mode))
- {
-#ifdef __UNUSED__ /* this casts too wide a net */
- bool terminal_entry = !strchr(tp->term_names, '+');
+ if (!PRESENT(exit_attribute_mode)) {
+#ifdef __UNUSED__ /* this casts too wide a net */
+ bool terminal_entry = !strchr(tp->term_names, '+');
if (terminal_entry &&
- (PRESENT(set_attributes)
+ (PRESENT(set_attributes)
|| PRESENT(enter_standout_mode)
|| PRESENT(enter_underline_mode)
|| PRESENT(enter_blink_mode)
@@ -460,31 +451,31 @@ static void sanity_check(TERMTYPE *tp)
|| PRESENT(enter_reverse_mode)))
_nc_warning("no exit_attribute_mode");
#endif /* __UNUSED__ */
- PAIRED(enter_standout_mode, exit_standout_mode)
- PAIRED(enter_underline_mode, exit_underline_mode)
+ PAIRED(enter_standout_mode, exit_standout_mode)
+ PAIRED(enter_underline_mode, exit_underline_mode)
}
- /* listed in structure-member order of first argument */
- PAIRED(enter_alt_charset_mode, exit_alt_charset_mode)
- ANDMISSING(enter_alt_charset_mode, acs_chars)
- ANDMISSING(exit_alt_charset_mode, acs_chars)
- ANDMISSING(enter_blink_mode, exit_attribute_mode)
- ANDMISSING(enter_bold_mode, exit_attribute_mode)
- PAIRED(exit_ca_mode, enter_ca_mode)
- PAIRED(enter_delete_mode, exit_delete_mode)
- ANDMISSING(enter_dim_mode, exit_attribute_mode)
- PAIRED(enter_insert_mode, exit_insert_mode)
- ANDMISSING(enter_secure_mode, exit_attribute_mode)
- ANDMISSING(enter_protected_mode, exit_attribute_mode)
- ANDMISSING(enter_reverse_mode, exit_attribute_mode)
- PAIRED(from_status_line, to_status_line)
- PAIRED(meta_off, meta_on)
-
- PAIRED(prtr_on, prtr_off)
- PAIRED(save_cursor, restore_cursor)
- PAIRED(enter_xon_mode, exit_xon_mode)
- PAIRED(enter_am_mode, exit_am_mode)
- ANDMISSING(label_off, label_on)
- PAIRED(display_clock, remove_clock)
- ANDMISSING(set_color_pair, initialize_pair)
+ /* listed in structure-member order of first argument */
+ PAIRED(enter_alt_charset_mode, exit_alt_charset_mode);
+ ANDMISSING(enter_alt_charset_mode, acs_chars);
+ ANDMISSING(exit_alt_charset_mode, acs_chars);
+ ANDMISSING(enter_blink_mode, exit_attribute_mode);
+ ANDMISSING(enter_bold_mode, exit_attribute_mode);
+ PAIRED(exit_ca_mode, enter_ca_mode);
+ PAIRED(enter_delete_mode, exit_delete_mode);
+ ANDMISSING(enter_dim_mode, exit_attribute_mode);
+ PAIRED(enter_insert_mode, exit_insert_mode);
+ ANDMISSING(enter_secure_mode, exit_attribute_mode);
+ ANDMISSING(enter_protected_mode, exit_attribute_mode);
+ ANDMISSING(enter_reverse_mode, exit_attribute_mode);
+ PAIRED(from_status_line, to_status_line);
+ PAIRED(meta_off, meta_on);
+
+ PAIRED(prtr_on, prtr_off);
+ PAIRED(save_cursor, restore_cursor);
+ PAIRED(enter_xon_mode, exit_xon_mode);
+ PAIRED(enter_am_mode, exit_am_mode);
+ ANDMISSING(label_off, label_on);
+ PAIRED(display_clock, remove_clock);
+ ANDMISSING(set_color_pair, initialize_pair);
}
diff --git a/contrib/ncurses/ncurses/tinfo/comp_scan.c b/contrib/ncurses/ncurses/tinfo/comp_scan.c
index 152930885ab7..8997e417ae57 100644
--- a/contrib/ncurses/ncurses/tinfo/comp_scan.c
+++ b/contrib/ncurses/ncurses/tinfo/comp_scan.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -47,9 +47,10 @@
#include <curses.priv.h>
#include <ctype.h>
+#include <term_entry.h>
#include <tic.h>
-MODULE_ID("$Id: comp_scan.c,v 1.34 1998/11/01 00:56:39 tom Exp $")
+MODULE_ID("$Id: comp_scan.c,v 1.44 2000/06/10 21:59:21 tom Exp $")
/*
* Maximum length of string capability we'll accept before raising an error.
@@ -59,11 +60,14 @@ MODULE_ID("$Id: comp_scan.c,v 1.34 1998/11/01 00:56:39 tom Exp $")
#define iswhite(ch) (ch == ' ' || ch == '\t')
-int _nc_syntax; /* termcap or terminfo? */
-long _nc_curr_file_pos; /* file offset of current line */
-long _nc_comment_start; /* start of comment range before name */
-long _nc_comment_end; /* end of comment range before name */
-long _nc_start_line; /* start line of current entry */
+int _nc_syntax = 0; /* termcap or terminfo? */
+long _nc_curr_file_pos = 0; /* file offset of current line */
+long _nc_comment_start = 0; /* start of comment range before name */
+long _nc_comment_end = 0; /* end of comment range before name */
+long _nc_start_line = 0; /* start line of current entry */
+
+struct token _nc_curr_token =
+{0, 0, 0};
/*****************************************************************************
*
@@ -74,21 +78,22 @@ long _nc_start_line; /* start line of current entry */
static bool first_column; /* See 'next_char()' below */
static char separator; /* capability separator */
static int pushtype; /* type of pushback token */
-static char pushname[MAX_NAME_SIZE+1];
+static char pushname[MAX_NAME_SIZE + 1];
-static int last_char(void);
-static int next_char(void);
+static int last_char(void);
+static int next_char(void);
static long stream_pos(void);
static bool end_of_stream(void);
static void push_back(char c);
/* Assume we may be looking at a termcap-style continuation */
-static inline int eat_escaped_newline(int ch)
+static inline int
+eat_escaped_newline(int ch)
{
- if (ch == '\\')
- while ((ch = next_char()) == '\n' || iswhite(ch))
- continue;
- return ch;
+ if (ch == '\\')
+ while ((ch = next_char()) == '\n' || iswhite(ch))
+ continue;
+ return ch;
}
/*
@@ -124,316 +129,306 @@ static inline int eat_escaped_newline(int ch)
*
*/
-int _nc_get_token(void)
+int
+_nc_get_token(void)
{
-static const char terminfo_punct[] = "@%&*!#";
-long number;
-int type;
-int ch;
-char * numchk;
-char numbuf[80];
-unsigned found;
-static char buffer[MAX_ENTRY_SIZE];
-char *ptr;
-int dot_flag = FALSE;
-long token_start;
-
- if (pushtype != NO_PUSHBACK)
- {
- int retval = pushtype;
-
- _nc_set_type(pushname);
- DEBUG(3, ("pushed-back token: `%s', class %d",
- _nc_curr_token.tk_name, pushtype));
-
- pushtype = NO_PUSHBACK;
- pushname[0] = '\0';
-
- /* currtok wasn't altered by _nc_push_token() */
- return(retval);
- }
+ static const char terminfo_punct[] = "@%&*!#";
+ long number;
+ int type;
+ int ch;
+ char *numchk;
+ char numbuf[80];
+ unsigned found;
+ static char buffer[MAX_ENTRY_SIZE];
+ char *ptr;
+ int dot_flag = FALSE;
+ long token_start;
+
+ if (pushtype != NO_PUSHBACK) {
+ int retval = pushtype;
+
+ _nc_set_type(pushname);
+ DEBUG(3, ("pushed-back token: `%s', class %d",
+ _nc_curr_token.tk_name, pushtype));
- if (end_of_stream())
- return(EOF);
-
-start_token:
- token_start = stream_pos();
- while ((ch = next_char()) == '\n' || iswhite(ch))
- continue;
+ pushtype = NO_PUSHBACK;
+ pushname[0] = '\0';
- ch = eat_escaped_newline(ch);
+ /* currtok wasn't altered by _nc_push_token() */
+ return (retval);
+ }
- if (ch == EOF)
- type = EOF;
- else {
- /* if this is a termcap entry, skip a leading separator */
- if (separator == ':' && ch == ':')
- ch = next_char();
+ if (end_of_stream())
+ return (EOF);
- if (ch == '.') {
- dot_flag = TRUE;
- DEBUG(8, ("dot-flag set"));
+ start_token:
+ token_start = stream_pos();
+ while ((ch = next_char()) == '\n' || iswhite(ch))
+ continue;
- while ((ch = next_char())=='.' || iswhite(ch))
- continue;
- }
+ ch = eat_escaped_newline(ch);
- if (ch == EOF) {
- type = EOF;
- goto end_of_token;
- }
+ if (ch == EOF)
+ type = EOF;
+ else {
+ /* if this is a termcap entry, skip a leading separator */
+ if (separator == ':' && ch == ':')
+ ch = next_char();
- /* have to make some punctuation chars legal for terminfo */
- if (!isalnum(ch) && !strchr(terminfo_punct, (char)ch)) {
- _nc_warning("Illegal character (expected alphanumeric or %s) - %s",
- terminfo_punct, _tracechar((chtype)ch));
- _nc_panic_mode(separator);
- goto start_token;
- }
+ if (ch == '.'
+#ifdef NCURSES_EXT_FUNCS
+ && !_nc_disable_period
+#endif
+ ) {
+ dot_flag = TRUE;
+ DEBUG(8, ("dot-flag set"));
- ptr = buffer;
- *(ptr++) = ch;
-
- if (first_column) {
- char *desc;
-
- _nc_comment_start = token_start;
- _nc_comment_end = _nc_curr_file_pos;
- _nc_start_line = _nc_curr_line;
-
- _nc_syntax = ERR;
- while ((ch = next_char()) != '\n')
- {
- if (ch == EOF)
- _nc_err_abort("premature EOF");
- else if (ch == ':' && last_char() != ',')
- {
- _nc_syntax = SYN_TERMCAP;
- separator = ':';
- break;
- }
- else if (ch == ',')
- {
- _nc_syntax = SYN_TERMINFO;
- separator = ',';
- /*
- * Fall-through here is not an accident.
- * The idea is that if we see a comma, we
- * figure this is terminfo unless we
- * subsequently run into a colon -- but
- * we don't stop looking for that colon until
- * hitting a newline. This allows commas to
- * be embedded in description fields of
- * either syntax.
- */
- /* FALLTHRU */
- }
- else
- ch = eat_escaped_newline(ch);
-
- *ptr++ = ch;
- }
- ptr[0] = '\0';
- if (_nc_syntax == ERR)
- {
- /*
- * Grrr...what we ought to do here is barf,
- * complaining that the entry is malformed.
- * But because a couple of name fields in the
- * 8.2 termcap file end with |\, we just have
- * to assume it's termcap syntax.
- */
- _nc_syntax = SYN_TERMCAP;
- separator = ':';
- }
- else if (_nc_syntax == SYN_TERMINFO)
- {
- /* throw away trailing /, *$/ */
- for (--ptr; iswhite(*ptr) || *ptr == ','; ptr--)
- continue;
- ptr[1] = '\0';
- }
+ while ((ch = next_char()) == '.' || iswhite(ch))
+ continue;
+ }
- /*
- * This is the soonest we have the terminal name
- * fetched. Set up for following warning messages.
- */
- ptr = strchr(buffer, '|');
- if (ptr == (char *)NULL)
- ptr = buffer + strlen(buffer);
- ch = *ptr;
- *ptr = '\0';
- _nc_set_type(buffer);
- *ptr = ch;
-
- /*
- * Compute the boundary between the aliases and the
- * description field for syntax-checking purposes.
- */
- desc = strrchr(buffer, '|');
- if (desc) {
- if (*desc == '\0')
- _nc_warning("empty longname field");
- else if (strchr(desc, ' ') == (char *)NULL)
- _nc_warning("older tic versions may treat the description field as an alias");
- }
- if (!desc)
- desc = buffer + strlen(buffer);
-
- /*
- * Whitespace in a name field other than the long name
- * can confuse rdist and some termcap tools. Slashes
- * are a no-no. Other special characters can be
- * dangerous due to shell expansion.
- */
- for (ptr = buffer; ptr < desc; ptr++)
- {
- if (isspace(*ptr))
- {
- _nc_warning("whitespace in name or alias field");
- break;
- }
- else if (*ptr == '/')
- {
- _nc_warning("slashes aren't allowed in names or aliases");
- break;
- }
- else if (strchr("$[]!*?", *ptr))
- {
- _nc_warning("dubious character `%c' in name or alias field", *ptr);
- break;
- }
- }
+ if (ch == EOF) {
+ type = EOF;
+ goto end_of_token;
+ }
- ptr = buffer;
+ /* have to make some punctuation chars legal for terminfo */
+ if (!isalnum(ch)
+#ifdef NCURSES_EXT_FUNCS
+ && !(ch == '.' && _nc_disable_period)
+#endif
+ && !strchr(terminfo_punct, (char) ch)) {
+ _nc_warning("Illegal character (expected alphanumeric or %s) - %s",
+ terminfo_punct, unctrl(ch));
+ _nc_panic_mode(separator);
+ goto start_token;
+ }
- _nc_curr_token.tk_name = buffer;
- type = NAMES;
- } else {
- while ((ch = next_char()) != EOF) {
- if (!isalnum(ch)) {
- if (_nc_syntax == SYN_TERMINFO) {
- if (ch != '_')
- break;
- } else { /* allow ';' for "k;" */
- if (ch != ';')
- break;
- }
- }
- *(ptr++) = ch;
- }
+ ptr = buffer;
+ *(ptr++) = ch;
- *ptr++ = '\0';
- switch (ch) {
- case ',':
- case ':':
- if (ch != separator)
- _nc_err_abort("Separator inconsistent with syntax");
- _nc_curr_token.tk_name = buffer;
- type = BOOLEAN;
- break;
- case '@':
- if ((ch = next_char()) != separator)
- _nc_warning("Missing separator after `%s', have %s",
- buffer, _tracechar((chtype)ch));
- _nc_curr_token.tk_name = buffer;
- type = CANCEL;
- break;
-
- case '#':
- found = 0;
- while (isalnum(ch = next_char())) {
- numbuf[found++] = ch;
- if (found >= sizeof(numbuf)-1)
- break;
- }
- numbuf[found] = '\0';
- number = strtol(numbuf, &numchk, 0);
- if (numchk == numbuf)
- _nc_warning("no value given for `%s'", buffer);
- if ((*numchk != '\0') || (ch != separator))
- _nc_warning("Missing separator");
- _nc_curr_token.tk_name = buffer;
- _nc_curr_token.tk_valnumber = number;
- type = NUMBER;
- break;
-
- case '=':
- ch = _nc_trans_string(ptr);
- if (ch != separator)
- _nc_warning("Missing separator");
- _nc_curr_token.tk_name = buffer;
- _nc_curr_token.tk_valstring = ptr;
- type = STRING;
- break;
-
- case EOF:
- type = EOF;
- break;
- default:
- /* just to get rid of the compiler warning */
- type = UNDEF;
- _nc_warning("Illegal character - %s",
- _tracechar((chtype)ch));
- }
- } /* end else (first_column == FALSE) */
- } /* end else (ch != EOF) */
+ if (first_column) {
+ char *desc;
-end_of_token:
+ _nc_comment_start = token_start;
+ _nc_comment_end = _nc_curr_file_pos;
+ _nc_start_line = _nc_curr_line;
-#ifdef TRACE
- if (dot_flag == TRUE)
- DEBUG(8, ("Commented out "));
-
- if (_nc_tracing & TRACE_IEVENT)
- {
- fprintf(stderr, "Token: ");
- switch (type)
- {
- case BOOLEAN:
- fprintf(stderr, "Boolean; name='%s'\n",
- _nc_curr_token.tk_name);
+ _nc_syntax = ERR;
+ while ((ch = next_char()) != '\n') {
+ if (ch == EOF)
+ _nc_err_abort("premature EOF");
+ else if (ch == ':' && last_char() != ',') {
+ _nc_syntax = SYN_TERMCAP;
+ separator = ':';
break;
+ } else if (ch == ',') {
+ _nc_syntax = SYN_TERMINFO;
+ separator = ',';
+ /*
+ * Fall-through here is not an accident.
+ * The idea is that if we see a comma, we
+ * figure this is terminfo unless we
+ * subsequently run into a colon -- but
+ * we don't stop looking for that colon until
+ * hitting a newline. This allows commas to
+ * be embedded in description fields of
+ * either syntax.
+ */
+ /* FALLTHRU */
+ } else
+ ch = eat_escaped_newline(ch);
+
+ *ptr++ = ch;
+ }
+ ptr[0] = '\0';
+ if (_nc_syntax == ERR) {
+ /*
+ * Grrr...what we ought to do here is barf,
+ * complaining that the entry is malformed.
+ * But because a couple of name fields in the
+ * 8.2 termcap file end with |\, we just have
+ * to assume it's termcap syntax.
+ */
+ _nc_syntax = SYN_TERMCAP;
+ separator = ':';
+ } else if (_nc_syntax == SYN_TERMINFO) {
+ /* throw away trailing /, *$/ */
+ for (--ptr; iswhite(*ptr) || *ptr == ','; ptr--)
+ continue;
+ ptr[1] = '\0';
+ }
- case NUMBER:
- fprintf(stderr, "Number; name='%s', value=%d\n",
- _nc_curr_token.tk_name,
- _nc_curr_token.tk_valnumber);
+ /*
+ * This is the soonest we have the terminal name
+ * fetched. Set up for following warning messages.
+ */
+ ptr = strchr(buffer, '|');
+ if (ptr == (char *) NULL)
+ ptr = buffer + strlen(buffer);
+ ch = *ptr;
+ *ptr = '\0';
+ _nc_set_type(buffer);
+ *ptr = ch;
+
+ /*
+ * Compute the boundary between the aliases and the
+ * description field for syntax-checking purposes.
+ */
+ desc = strrchr(buffer, '|');
+ if (desc) {
+ if (*desc == '\0')
+ _nc_warning("empty longname field");
+ else if (strchr(desc, ' ') == (char *) NULL)
+ _nc_warning("older tic versions may treat the description field as an alias");
+ }
+ if (!desc)
+ desc = buffer + strlen(buffer);
+
+ /*
+ * Whitespace in a name field other than the long name
+ * can confuse rdist and some termcap tools. Slashes
+ * are a no-no. Other special characters can be
+ * dangerous due to shell expansion.
+ */
+ for (ptr = buffer; ptr < desc; ptr++) {
+ if (isspace(*ptr)) {
+ _nc_warning("whitespace in name or alias field");
break;
-
- case STRING:
- fprintf(stderr, "String; name='%s', value=%s\n",
- _nc_curr_token.tk_name,
- _nc_visbuf(_nc_curr_token.tk_valstring));
+ } else if (*ptr == '/') {
+ _nc_warning("slashes aren't allowed in names or aliases");
break;
-
- case CANCEL:
- fprintf(stderr, "Cancel; name='%s'\n",
- _nc_curr_token.tk_name);
+ } else if (strchr("$[]!*?", *ptr)) {
+ _nc_warning("dubious character `%c' in name or alias field", *ptr);
break;
+ }
+ }
- case NAMES:
+ ptr = buffer;
- fprintf(stderr, "Names; value='%s'\n",
- _nc_curr_token.tk_name);
- break;
+ _nc_curr_token.tk_name = buffer;
+ type = NAMES;
+ } else {
+ while ((ch = next_char()) != EOF) {
+ if (!isalnum(ch)) {
+ if (_nc_syntax == SYN_TERMINFO) {
+ if (ch != '_')
+ break;
+ } else { /* allow ';' for "k;" */
+ if (ch != ';')
+ break;
+ }
+ }
+ *(ptr++) = ch;
+ }
- case EOF:
- fprintf(stderr, "End of file\n");
- break;
+ *ptr++ = '\0';
+ switch (ch) {
+ case ',':
+ case ':':
+ if (ch != separator)
+ _nc_err_abort("Separator inconsistent with syntax");
+ _nc_curr_token.tk_name = buffer;
+ type = BOOLEAN;
+ break;
+ case '@':
+ if ((ch = next_char()) != separator)
+ _nc_warning("Missing separator after `%s', have %s",
+ buffer, unctrl(ch));
+ _nc_curr_token.tk_name = buffer;
+ type = CANCEL;
+ break;
- default:
- _nc_warning("Bad token type");
+ case '#':
+ found = 0;
+ while (isalnum(ch = next_char())) {
+ numbuf[found++] = ch;
+ if (found >= sizeof(numbuf) - 1)
+ break;
+ }
+ numbuf[found] = '\0';
+ number = strtol(numbuf, &numchk, 0);
+ if (numchk == numbuf)
+ _nc_warning("no value given for `%s'", buffer);
+ if ((*numchk != '\0') || (ch != separator))
+ _nc_warning("Missing separator");
+ _nc_curr_token.tk_name = buffer;
+ _nc_curr_token.tk_valnumber = number;
+ type = NUMBER;
+ break;
+
+ case '=':
+ ch = _nc_trans_string(ptr, buffer + sizeof(buffer));
+ if (ch != separator)
+ _nc_warning("Missing separator");
+ _nc_curr_token.tk_name = buffer;
+ _nc_curr_token.tk_valstring = ptr;
+ type = STRING;
+ break;
+
+ case EOF:
+ type = EOF;
+ break;
+ default:
+ /* just to get rid of the compiler warning */
+ type = UNDEF;
+ _nc_warning("Illegal character - %s", unctrl(ch));
}
+ } /* end else (first_column == FALSE) */
+ } /* end else (ch != EOF) */
+
+ end_of_token:
+
+#ifdef TRACE
+ if (dot_flag == TRUE)
+ DEBUG(8, ("Commented out "));
+
+ if (_nc_tracing >= DEBUG_LEVEL(7)) {
+ switch (type) {
+ case BOOLEAN:
+ _tracef("Token: Boolean; name='%s'",
+ _nc_curr_token.tk_name);
+ break;
+
+ case NUMBER:
+ _tracef("Token: Number; name='%s', value=%d",
+ _nc_curr_token.tk_name,
+ _nc_curr_token.tk_valnumber);
+ break;
+
+ case STRING:
+ _tracef("Token: String; name='%s', value=%s",
+ _nc_curr_token.tk_name,
+ _nc_visbuf(_nc_curr_token.tk_valstring));
+ break;
+
+ case CANCEL:
+ _tracef("Token: Cancel; name='%s'",
+ _nc_curr_token.tk_name);
+ break;
+
+ case NAMES:
+
+ _tracef("Token: Names; value='%s'",
+ _nc_curr_token.tk_name);
+ break;
+
+ case EOF:
+ _tracef("Token: End of file");
+ break;
+
+ default:
+ _nc_warning("Bad token type");
}
+ }
#endif
- if (dot_flag == TRUE) /* if commented out, use the next one */
- type = _nc_get_token();
+ if (dot_flag == TRUE) /* if commented out, use the next one */
+ type = _nc_get_token();
- DEBUG(3, ("token: `%s', class %d", _nc_curr_token.tk_name, type));
+ DEBUG(3, ("token: `%s', class %d", _nc_curr_token.tk_name, type));
- return(type);
+ return (type);
}
/*
@@ -456,120 +451,150 @@ end_of_token:
*/
char
-_nc_trans_string(char *ptr)
+_nc_trans_string(char *ptr, char *last)
{
-int count = 0;
-int number;
-int i, c;
-chtype ch, last_ch = '\0';
-bool ignored = FALSE;
-
- while ((ch = c = next_char()) != (chtype)separator && c != EOF) {
- if ((_nc_syntax == SYN_TERMCAP) && c == '\n')
- break;
- if (ch == '^' && last_ch != '%') {
- ch = c = next_char();
- if (c == EOF)
- _nc_err_abort("Premature EOF");
-
- if (! (is7bits(ch) && isprint(ch))) {
- _nc_warning("Illegal ^ character - %s",
- _tracechar((unsigned char)ch));
- }
- if (ch == '?') {
- *(ptr++) = '\177';
- } else {
- if ((ch &= 037) == 0)
- ch = 128;
- *(ptr++) = (char)(ch);
- }
+ int count = 0;
+ int number;
+ int i, c;
+ chtype ch, last_ch = '\0';
+ bool ignored = FALSE;
+ bool long_warning = FALSE;
+
+ while ((ch = c = next_char()) != (chtype) separator && c != EOF) {
+ if (ptr == (last - 1))
+ break;
+ if ((_nc_syntax == SYN_TERMCAP) && c == '\n')
+ break;
+ if (ch == '^' && last_ch != '%') {
+ ch = c = next_char();
+ if (c == EOF)
+ _nc_err_abort("Premature EOF");
+
+ if (!(is7bits(ch) && isprint(ch))) {
+ _nc_warning("Illegal ^ character - %s", unctrl(ch));
}
- else if (ch == '\\') {
- ch = c = next_char();
- if (c == EOF)
- _nc_err_abort("Premature EOF");
-
- if (ch >= '0' && ch <= '7') {
- number = ch - '0';
- for (i=0; i < 2; i++) {
- ch = c = next_char();
- if (c == EOF)
- _nc_err_abort("Premature EOF");
-
- if (c < '0' || c > '7') {
- if (isdigit(c)) {
- _nc_warning("Non-octal digit `%c' in \\ sequence", c);
- /* allow the digit; it'll do less harm */
- } else {
- push_back((char)c);
- break;
- }
+ if (ch == '?') {
+ *(ptr++) = '\177';
+ if (_nc_tracing)
+ _nc_warning("Allow ^? as synonym for \\177");
+ } else {
+ if ((ch &= 037) == 0)
+ ch = 128;
+ *(ptr++) = (char) (ch);
+ }
+ } else if (ch == '\\') {
+ ch = c = next_char();
+ if (c == EOF)
+ _nc_err_abort("Premature EOF");
+
+ if (ch >= '0' && ch <= '7') {
+ number = ch - '0';
+ for (i = 0; i < 2; i++) {
+ ch = c = next_char();
+ if (c == EOF)
+ _nc_err_abort("Premature EOF");
+
+ if (c < '0' || c > '7') {
+ if (isdigit(c)) {
+ _nc_warning("Non-octal digit `%c' in \\ sequence", c);
+ /* allow the digit; it'll do less harm */
+ } else {
+ push_back((char) c);
+ break;
}
-
- number = number * 8 + c - '0';
}
- if (number == 0)
- number = 0200;
- *(ptr++) = (char) number;
- } else {
- switch (c) {
- case 'E':
- case 'e': *(ptr++) = '\033'; break;
+ number = number * 8 + c - '0';
+ }
- case 'a': *(ptr++) = '\007'; break;
+ if (number == 0)
+ number = 0200;
+ *(ptr++) = (char) number;
+ } else {
+ switch (c) {
+ case 'E':
+ case 'e':
+ *(ptr++) = '\033';
+ break;
- case 'l':
- case 'n': *(ptr++) = '\n'; break;
+ case 'a':
+ *(ptr++) = '\007';
+ break;
- case 'r': *(ptr++) = '\r'; break;
+ case 'l':
+ case 'n':
+ *(ptr++) = '\n';
+ break;
- case 'b': *(ptr++) = '\010'; break;
+ case 'r':
+ *(ptr++) = '\r';
+ break;
- case 's': *(ptr++) = ' '; break;
+ case 'b':
+ *(ptr++) = '\010';
+ break;
- case 'f': *(ptr++) = '\014'; break;
+ case 's':
+ *(ptr++) = ' ';
+ break;
- case 't': *(ptr++) = '\t'; break;
+ case 'f':
+ *(ptr++) = '\014';
+ break;
- case '\\': *(ptr++) = '\\'; break;
+ case 't':
+ *(ptr++) = '\t';
+ break;
- case '^': *(ptr++) = '^'; break;
+ case '\\':
+ *(ptr++) = '\\';
+ break;
- case ',': *(ptr++) = ','; break;
+ case '^':
+ *(ptr++) = '^';
+ break;
- case ':': *(ptr++) = ':'; break;
+ case ',':
+ *(ptr++) = ',';
+ break;
- case '\n':
- continue;
+ case ':':
+ *(ptr++) = ':';
+ break;
- default:
- _nc_warning("Illegal character %s in \\ sequence",
- _tracechar((unsigned char)ch));
- *(ptr++) = (char)ch;
- } /* endswitch (ch) */
- } /* endelse (ch < '0' || ch > '7') */
- } /* end else if (ch == '\\') */
- else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) {
- /* newlines embedded in a terminfo string are ignored */
- ignored = TRUE;
- } else {
- *(ptr++) = (char)ch;
- }
+ case '\n':
+ continue;
- if (!ignored) {
- last_ch = ch;
- count ++;
- }
- ignored = FALSE;
+ default:
+ _nc_warning("Illegal character %s in \\ sequence",
+ unctrl(ch));
+ *(ptr++) = (char) ch;
+ } /* endswitch (ch) */
+ } /* endelse (ch < '0' || ch > '7') */
+ }
+ /* end else if (ch == '\\') */
+ else if (ch == '\n' && (_nc_syntax == SYN_TERMINFO)) {
+ /* newlines embedded in a terminfo string are ignored */
+ ignored = TRUE;
+ } else {
+ *(ptr++) = (char) ch;
+ }
- if (count > MAXCAPLEN)
- _nc_warning("Very long string found. Missing separator?");
- } /* end while */
+ if (!ignored) {
+ last_ch = ch;
+ count++;
+ }
+ ignored = FALSE;
- *ptr = '\0';
+ if (count > MAXCAPLEN && !long_warning) {
+ _nc_warning("Very long string found. Missing separator?");
+ long_warning = TRUE;
+ }
+ } /* end while */
+
+ *ptr = '\0';
- return(ch);
+ return (ch);
}
/*
@@ -579,7 +604,8 @@ bool ignored = FALSE;
* get_token() call.
*/
-void _nc_push_token(int tokclass)
+void
+_nc_push_token(int tokclass)
{
/*
* This implementation is kind of bogus, it will fail if we ever do
@@ -591,23 +617,24 @@ void _nc_push_token(int tokclass)
_nc_get_type(pushname);
DEBUG(3, ("pushing token: `%s', class %d",
- _nc_curr_token.tk_name, pushtype));
+ _nc_curr_token.tk_name, pushtype));
}
/*
* Panic mode error recovery - skip everything until a "ch" is found.
*/
-void _nc_panic_mode(char ch)
+void
+_nc_panic_mode(char ch)
{
- int c;
-
- for (;;) {
- c = next_char();
- if (c == ch)
- return;
- if (c == EOF)
- return;
- }
+ int c;
+
+ for (;;) {
+ c = next_char();
+ if (c == ch)
+ return;
+ if (c == EOF)
+ return;
+ }
}
/*****************************************************************************
@@ -630,16 +657,17 @@ static FILE *yyin; /* scanner's input file descriptor */
* non-null.
*/
-void _nc_reset_input(FILE *fp, char *buf)
+void
+_nc_reset_input(FILE * fp, char *buf)
{
- pushtype = NO_PUSHBACK;
- pushname[0] = '\0';
- yyin = fp;
- bufstart = bufptr = buf;
- _nc_curr_file_pos = 0L;
- if (fp != 0)
- _nc_curr_line = 0;
- _nc_curr_col = 0;
+ pushtype = NO_PUSHBACK;
+ pushname[0] = '\0';
+ yyin = fp;
+ bufstart = bufptr = buf;
+ _nc_curr_file_pos = 0L;
+ if (fp != 0)
+ _nc_curr_line = 0;
+ _nc_curr_col = 0;
}
/*
@@ -650,12 +678,12 @@ void _nc_reset_input(FILE *fp, char *buf)
static int
last_char(void)
{
- size_t len = strlen(bufptr);
- while (len--) {
- if (!isspace(bufptr[len]))
- return bufptr[len];
- }
- return 0;
+ size_t len = strlen(bufptr);
+ while (len--) {
+ if (!isspace(bufptr[len]))
+ return bufptr[len];
+ }
+ return 0;
}
/*
@@ -675,17 +703,14 @@ last_char(void)
static int
next_char(void)
{
- if (!yyin)
- {
+ if (!yyin) {
if (*bufptr == '\0')
- return(EOF);
+ return (EOF);
if (*bufptr == '\n') {
_nc_curr_line++;
_nc_curr_col = 0;
}
- }
- else if (!bufptr || !*bufptr)
- {
+ } else if (!bufptr || !*bufptr) {
/*
* In theory this could be recoded to do its I/O one
* character at a time, saving the buffer space. In
@@ -697,15 +722,15 @@ next_char(void)
size_t len;
do {
- _nc_curr_file_pos = ftell(yyin);
+ _nc_curr_file_pos = ftell(yyin);
- if ((bufstart = fgets(line, LEXBUFSIZ, yyin)) != NULL) {
- _nc_curr_line++;
- _nc_curr_col = 0;
- }
- bufptr = bufstart;
- } while
- (bufstart != NULL && line[0] == '#');
+ if ((bufstart = fgets(line, LEXBUFSIZ, yyin)) != NULL) {
+ _nc_curr_line++;
+ _nc_curr_col = 0;
+ }
+ bufptr = bufstart;
+ } while
+ (bufstart != NULL && line[0] == '#');
if (bufstart == NULL)
return (EOF);
@@ -718,10 +743,10 @@ next_char(void)
* files on OS/2, etc.
*/
if ((len = strlen(bufptr)) > 1) {
- if (bufptr[len-1] == '\n'
- && bufptr[len-2] == '\r') {
- bufptr[len-2] = '\n';
- bufptr[len-1] = '\0';
+ if (bufptr[len - 1] == '\n'
+ && bufptr[len - 2] == '\r') {
+ bufptr[len - 2] = '\n';
+ bufptr[len - 1] = '\0';
}
}
}
@@ -729,28 +754,31 @@ next_char(void)
first_column = (bufptr == bufstart);
_nc_curr_col++;
- return(*bufptr++);
+ return (*bufptr++);
}
-static void push_back(char c)
+static void
+push_back(char c)
/* push a character back onto the input stream */
{
if (bufptr == bufstart)
- _nc_syserr_abort("Can't backspace off beginning of line");
+ _nc_syserr_abort("Can't backspace off beginning of line");
*--bufptr = c;
}
-static long stream_pos(void)
+static long
+stream_pos(void)
/* return our current character position in the input stream */
{
return (yyin ? ftell(yyin) : (bufptr ? bufptr - bufstart : 0));
}
-static bool end_of_stream(void)
+static bool
+end_of_stream(void)
/* are we at end of input? */
{
return ((yyin ? feof(yyin) : (bufptr && *bufptr == '\0'))
- ? TRUE : FALSE);
+ ? TRUE : FALSE);
}
/* comp_scan.c ends here */
diff --git a/contrib/ncurses/ncurses/tinfo/free_ttype.c b/contrib/ncurses/ncurses/tinfo/free_ttype.c
index 203ec89ed359..d9d9c0aa52e8 100644
--- a/contrib/ncurses/ncurses/tinfo/free_ttype.c
+++ b/contrib/ncurses/ncurses/tinfo/free_ttype.c
@@ -44,7 +44,7 @@
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: free_ttype.c,v 1.2 1999/03/01 00:30:35 tom Exp $")
+MODULE_ID("$Id: free_ttype.c,v 1.3 2000/03/19 02:03:07 tom Exp $")
void _nc_free_termtype(TERMTYPE *ptr)
{
@@ -62,6 +62,7 @@ void _nc_free_termtype(TERMTYPE *ptr)
#if NCURSES_XNAMES
bool _nc_user_definable = TRUE;
+bool _nc_disable_period = FALSE; /* used by tic -a option */
int use_extended_names(bool flag)
{
diff --git a/contrib/ncurses/ncurses/tinfo/init_keytry.c b/contrib/ncurses/ncurses/tinfo/init_keytry.c
index a720da181e5e..1134480f8def 100644
--- a/contrib/ncurses/ncurses/tinfo/init_keytry.c
+++ b/contrib/ncurses/ncurses/tinfo/init_keytry.c
@@ -32,7 +32,7 @@
/* cursor_visible,cursor_normal,cursor_invisible */
#include <tic.h> /* struct tinfo_fkeys */
-MODULE_ID("$Id: init_keytry.c,v 1.2 1999/09/11 17:32:57 Jeffrey.Honig Exp $")
+MODULE_ID("$Id: init_keytry.c,v 1.3 2000/03/12 02:55:50 Todd.C.Miller Exp $")
/*
** _nc_init_keytry()
@@ -41,7 +41,7 @@ MODULE_ID("$Id: init_keytry.c,v 1.2 1999/09/11 17:32:57 Jeffrey.Honig Exp $")
**
*/
-#ifdef BROKEN_LINKER
+#if BROKEN_LINKER
#undef _nc_tinfo_fkeys
#endif
@@ -51,7 +51,7 @@ MODULE_ID("$Id: init_keytry.c,v 1.2 1999/09/11 17:32:57 Jeffrey.Honig Exp $")
/* LINT_PREPRO
#endif*/
-#ifdef BROKEN_LINKER
+#if BROKEN_LINKER
struct tinfo_fkeys *_nc_tinfo_fkeysf(void)
{
return _nc_tinfo_fkeys;
diff --git a/contrib/ncurses/ncurses/tinfo/lib_acs.c b/contrib/ncurses/ncurses/tinfo/lib_acs.c
index d3c782e8e664..6f0779157413 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_acs.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_acs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * 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 *
@@ -36,9 +36,9 @@
#include <curses.priv.h>
#include <term.h> /* ena_acs, acs_chars */
-MODULE_ID("$Id: lib_acs.c,v 1.15 1999/02/18 11:31:43 tom Exp $")
+MODULE_ID("$Id: lib_acs.c,v 1.16 1999/10/30 23:00:16 tom Exp $")
-chtype acs_map[ACS_LEN];
+chtype acs_map[ACS_LEN] = { 0 };
void _nc_init_acs(void)
{
diff --git a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
index 3250147c8066..7d0aa127d9db 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_cur_term.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * 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 *
@@ -40,9 +40,9 @@
#include <term_entry.h> /* TTY, cur_term */
#include <termcap.h> /* ospeed */
-MODULE_ID("$Id: lib_cur_term.c,v 1.8 1999/07/24 20:08:19 tom Exp $")
+MODULE_ID("$Id: lib_cur_term.c,v 1.9 1999/10/30 23:00:16 tom Exp $")
-TERMINAL *cur_term;
+TERMINAL *cur_term = 0;
TERMINAL *set_curterm(TERMINAL *termp)
{
diff --git a/contrib/ncurses/ncurses/tinfo/lib_napms.c b/contrib/ncurses/ncurses/tinfo/lib_napms.c
index a85304bf1cb6..1bd5c647f029 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_napms.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_napms.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* lib_napms.c
*
@@ -43,9 +42,10 @@
#if HAVE_NANOSLEEP
#include <time.h>
+#if HAVE_SYS_TIME_H
+#include <sys/time.h> /* needed for MacOS X DP3 */
+#endif
#elif USE_FUNC_POLL
-#include <stropts.h>
-#include <poll.h>
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -58,31 +58,32 @@
#endif
#endif
-MODULE_ID("$Id: lib_napms.c,v 1.6 1999/10/21 23:01:41 tom Exp $")
+MODULE_ID("$Id: lib_napms.c,v 1.9 2000/04/29 23:42:56 tom Exp $")
-int napms(int ms)
+int
+napms(int ms)
{
- T((T_CALLED("napms(%d)"), ms));
+ T((T_CALLED("napms(%d)"), ms));
#if HAVE_NANOSLEEP
- {
- struct timespec ts;
- ts.tv_sec = ms / 1000;
- ts.tv_nsec = (ms % 1000) * 1000000;
- nanosleep(&ts, NULL);
- }
+ {
+ struct timespec ts;
+ ts.tv_sec = ms / 1000;
+ ts.tv_nsec = (ms % 1000) * 1000000;
+ nanosleep(&ts, NULL);
+ }
#elif USE_FUNC_POLL
- {
- struct pollfd fds[1];
- poll(fds, 0, ms);
- }
+ {
+ struct pollfd fds[1];
+ poll(fds, 0, ms);
+ }
#elif HAVE_SELECT
- {
- struct timeval tval;
- tval.tv_sec = ms / 1000;
- tval.tv_usec = (ms % 1000) * 1000;
- select(0, NULL, NULL, NULL, &tval);
- }
+ {
+ struct timeval tval;
+ tval.tv_sec = ms / 1000;
+ tval.tv_usec = (ms % 1000) * 1000;
+ select(0, NULL, NULL, NULL, &tval);
+ }
#endif
- returnCode(OK);
+ returnCode(OK);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_options.c b/contrib/ncurses/ncurses/tinfo/lib_options.c
index 0bc14156d674..b58602af72bb 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_options.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_options.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
** lib_options.c
**
@@ -41,168 +40,163 @@
#include <curses.priv.h>
-#include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */
- /* cursor_visible,cursor_normal,cursor_invisible */
+#include <term.h>
-MODULE_ID("$Id: lib_options.c,v 1.36 1999/10/22 21:38:57 tom Exp $")
+MODULE_ID("$Id: lib_options.c,v 1.39 2000/03/12 00:19:11 tom Exp $")
-int idlok(WINDOW *win, bool flag)
+int
+idlok(WINDOW *win, bool flag)
{
- T((T_CALLED("idlok(%p,%d)"), win, flag));
+ T((T_CALLED("idlok(%p,%d)"), win, flag));
- if (win) {
- _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
- returnCode(OK);
- }
- else
- returnCode(ERR);
+ if (win) {
+ _nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-
-void idcok(WINDOW *win, bool flag)
+void
+idcok(WINDOW *win, bool flag)
{
- T((T_CALLED("idcok(%p,%d)"), win, flag));
+ T((T_CALLED("idcok(%p,%d)"), win, flag));
- if (win)
- _nc_idcok = win->_idcok = flag && has_ic();
+ if (win)
+ _nc_idcok = win->_idcok = (flag && has_ic());
- returnVoid;
+ returnVoid;
}
-int halfdelay(int t)
+int
+halfdelay(int t)
{
- T((T_CALLED("halfdelay(%d)"), t));
+ T((T_CALLED("halfdelay(%d)"), t));
- if (t < 1 || t > 255)
- returnCode(ERR);
+ if (t < 1 || t > 255)
+ returnCode(ERR);
- cbreak();
- SP->_cbreak = t+1;
- returnCode(OK);
+ cbreak();
+ SP->_cbreak = t + 1;
+ returnCode(OK);
}
-int nodelay(WINDOW *win, bool flag)
+int
+nodelay(WINDOW *win, bool flag)
{
- T((T_CALLED("nodelay(%p,%d)"), win, flag));
+ T((T_CALLED("nodelay(%p,%d)"), win, flag));
- if (win) {
- if (flag == TRUE)
+ if (win) {
+ if (flag == TRUE)
win->_delay = 0;
- else win->_delay = -1;
- returnCode(OK);
- }
else
- returnCode(ERR);
+ win->_delay = -1;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-int notimeout(WINDOW *win, bool f)
+int
+notimeout(WINDOW *win, bool f)
{
- T((T_CALLED("notimout(%p,%d)"), win, f));
+ T((T_CALLED("notimout(%p,%d)"), win, f));
- if (win) {
- win->_notimeout = f;
- returnCode(OK);
- }
- else
- returnCode(ERR);
+ if (win) {
+ win->_notimeout = f;
+ returnCode(OK);
+ } else
+ returnCode(ERR);
}
-void wtimeout(WINDOW *win, int delay)
+void
+wtimeout(WINDOW *win, int delay)
{
- T((T_CALLED("wtimeout(%p,%d)"), win, delay));
+ T((T_CALLED("wtimeout(%p,%d)"), win, delay));
- if (win) {
- win->_delay = delay;
- }
+ if (win) {
+ win->_delay = delay;
+ }
}
-int keypad(WINDOW *win, bool flag)
+int
+keypad(WINDOW *win, bool flag)
{
- T((T_CALLED("keypad(%p,%d)"), win, flag));
+ T((T_CALLED("keypad(%p,%d)"), win, flag));
- if (win) {
- win->_use_keypad = flag;
- returnCode(_nc_keypad(flag));
- }
- else
- returnCode(ERR);
+ if (win) {
+ win->_use_keypad = flag;
+ returnCode(_nc_keypad(flag));
+ } else
+ returnCode(ERR);
}
-
-int meta(WINDOW *win GCC_UNUSED, bool flag)
+int
+meta(WINDOW *win GCC_UNUSED, bool flag)
{
- /* Ok, we stay relaxed and don't signal an error if win is NULL */
- T((T_CALLED("meta(%p,%d)"), win, flag));
-
- SP->_use_meta = flag;
-
- if (flag && meta_on)
- {
- TPUTS_TRACE("meta_on");
- putp(meta_on);
- }
- else if (! flag && meta_off)
- {
- TPUTS_TRACE("meta_off");
- putp(meta_off);
- }
- returnCode(OK);
+ /* Ok, we stay relaxed and don't signal an error if win is NULL */
+ T((T_CALLED("meta(%p,%d)"), win, flag));
+
+ SP->_use_meta = flag;
+
+ if (flag && meta_on) {
+ TPUTS_TRACE("meta_on");
+ putp(meta_on);
+ } else if (!flag && meta_off) {
+ TPUTS_TRACE("meta_off");
+ putp(meta_off);
+ }
+ returnCode(OK);
}
/* curs_set() moved here to narrow the kernel interface */
-int curs_set(int vis)
+int
+curs_set(int vis)
{
-int cursor = SP->_cursor;
-
- T((T_CALLED("curs_set(%d)"), vis));
-
- if (vis < 0 || vis > 2)
- returnCode(ERR);
-
- if (vis == cursor)
- returnCode(cursor);
-
- switch(vis) {
- case 2:
- if (cursor_visible)
- {
- TPUTS_TRACE("cursor_visible");
- putp(cursor_visible);
- }
- else
- returnCode(ERR);
- break;
- case 1:
- if (cursor_normal)
- {
- TPUTS_TRACE("cursor_normal");
- putp(cursor_normal);
- }
- else
- returnCode(ERR);
- break;
- case 0:
- if (cursor_invisible)
- {
- TPUTS_TRACE("cursor_invisible");
- putp(cursor_invisible);
- }
- else
- returnCode(ERR);
- break;
- }
- SP->_cursor = vis;
- _nc_flush();
-
- returnCode(cursor==-1 ? 1 : cursor);
+ int cursor = SP->_cursor;
+
+ T((T_CALLED("curs_set(%d)"), vis));
+
+ if (vis < 0 || vis > 2)
+ returnCode(ERR);
+
+ if (vis == cursor)
+ returnCode(cursor);
+
+ switch (vis) {
+ case 2:
+ if (cursor_visible) {
+ TPUTS_TRACE("cursor_visible");
+ putp(cursor_visible);
+ } else
+ returnCode(ERR);
+ break;
+ case 1:
+ if (cursor_normal) {
+ TPUTS_TRACE("cursor_normal");
+ putp(cursor_normal);
+ } else
+ returnCode(ERR);
+ break;
+ case 0:
+ if (cursor_invisible) {
+ TPUTS_TRACE("cursor_invisible");
+ putp(cursor_invisible);
+ } else
+ returnCode(ERR);
+ break;
+ }
+ SP->_cursor = vis;
+ _nc_flush();
+
+ returnCode(cursor == -1 ? 1 : cursor);
}
-int typeahead(int fd)
+int
+typeahead(int fd)
{
- T((T_CALLED("typeahead(%d)"), fd));
- SP->_checkfd = fd;
- returnCode(OK);
+ T((T_CALLED("typeahead(%d)"), fd));
+ SP->_checkfd = fd;
+ returnCode(OK);
}
/*
@@ -213,18 +207,20 @@ int typeahead(int fd)
*/
#ifdef NCURSES_EXT_FUNCS
-static int has_key_internal(int keycode, struct tries *tp)
+static int
+has_key_internal(int keycode, struct tries *tp)
{
if (tp == 0)
- return(FALSE);
+ return (FALSE);
else if (tp->value == keycode)
- return(TRUE);
+ return (TRUE);
else
- return(has_key_internal(keycode, tp->child)
- || has_key_internal(keycode, tp->sibling));
+ return (has_key_internal(keycode, tp->child)
+ || has_key_internal(keycode, tp->sibling));
}
-int has_key(int keycode)
+int
+has_key(int keycode)
{
T((T_CALLED("has_key(%d)"), keycode));
returnCode(has_key_internal(keycode, SP->_keytry));
@@ -238,24 +234,22 @@ int has_key(int keycode)
* flush, then the next wgetch may get the escape sequence that corresponds to
* the terminal state _before_ switching modes.
*/
-int _nc_keypad(bool flag)
+int
+_nc_keypad(bool flag)
{
- if (flag && keypad_xmit)
- {
- TPUTS_TRACE("keypad_xmit");
- putp(keypad_xmit);
- _nc_flush();
- }
- else if (! flag && keypad_local)
- {
- TPUTS_TRACE("keypad_local");
- putp(keypad_local);
- _nc_flush();
- }
-
- if (flag && !SP->_tried) {
- _nc_init_keytry();
- SP->_tried = TRUE;
- }
- return(OK);
+ if (flag && keypad_xmit) {
+ TPUTS_TRACE("keypad_xmit");
+ putp(keypad_xmit);
+ _nc_flush();
+ } else if (!flag && keypad_local) {
+ TPUTS_TRACE("keypad_local");
+ putp(keypad_local);
+ _nc_flush();
+ }
+
+ if (flag && !SP->_tried) {
+ _nc_init_keytry();
+ SP->_tried = TRUE;
+ }
+ return (OK);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_raw.c b/contrib/ncurses/ncurses/tinfo/lib_raw.c
index 61b422c1fb88..6033ed9c10c3 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_raw.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_raw.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* raw.c
*
@@ -47,21 +46,20 @@
*/
#include <curses.priv.h>
-#include <term.h> /* cur_term */
+#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_raw.c,v 1.3 1999/03/06 22:28:24 tom Exp $")
+MODULE_ID("$Id: lib_raw.c,v 1.7 2000/02/13 01:01:26 tom Exp $")
#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
#if HAVE_SYS_TERMIO_H
-#include <sys/termio.h> /* needed for ISC */
+#include <sys/termio.h> /* needed for ISC */
#endif
#ifdef __EMX__
#include <io.h>
-#include <fcntl.h>
#endif
#define COOKED_INPUT (IXON|BRKINT|PARMRK)
@@ -74,160 +72,165 @@ MODULE_ID("$Id: lib_raw.c,v 1.3 1999/03/06 22:28:24 tom Exp $")
#define AFTER(s)
#endif /* TRACE */
-int raw(void)
+int
+raw(void)
{
- T((T_CALLED("raw()")));
- if (SP != 0 && cur_term != 0) {
+ T((T_CALLED("raw()")));
+ if (SP != 0 && cur_term != 0) {
- SP->_raw = TRUE;
- SP->_cbreak = 1;
+ SP->_raw = TRUE;
+ SP->_cbreak = 1;
#ifdef __EMX__
- setmode(SP->_ifd, O_BINARY);
+ setmode(SP->_ifd, O_BINARY);
#endif
#ifdef TERMIOS
- BEFORE("raw");
- cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG);
- cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
- cur_term->Nttyb.c_cc[VMIN] = 1;
- cur_term->Nttyb.c_cc[VTIME] = 0;
- AFTER("raw");
+ BEFORE("raw");
+ cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN);
+ cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
+ cur_term->Nttyb.c_cc[VMIN] = 1;
+ cur_term->Nttyb.c_cc[VTIME] = 0;
+ AFTER("raw");
#else
- cur_term->Nttyb.sg_flags |= RAW;
+ cur_term->Nttyb.sg_flags |= RAW;
#endif
- returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
- }
- returnCode(ERR);
+ returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
+ }
+ returnCode(ERR);
}
-int cbreak(void)
+int
+cbreak(void)
{
- T((T_CALLED("cbreak()")));
+ T((T_CALLED("cbreak()")));
- SP->_cbreak = 1;
+ SP->_cbreak = 1;
#ifdef __EMX__
- setmode(SP->_ifd, O_BINARY);
+ setmode(SP->_ifd, O_BINARY);
#endif
#ifdef TERMIOS
- BEFORE("cbreak");
- cur_term->Nttyb.c_lflag &= ~ICANON;
- cur_term->Nttyb.c_iflag &= ~ICRNL;
- cur_term->Nttyb.c_lflag |= ISIG;
- cur_term->Nttyb.c_cc[VMIN] = 1;
- cur_term->Nttyb.c_cc[VTIME] = 0;
- AFTER("cbreak");
+ BEFORE("cbreak");
+ cur_term->Nttyb.c_lflag &= ~ICANON;
+ cur_term->Nttyb.c_iflag &= ~ICRNL;
+ cur_term->Nttyb.c_lflag |= ISIG;
+ cur_term->Nttyb.c_cc[VMIN] = 1;
+ cur_term->Nttyb.c_cc[VTIME] = 0;
+ AFTER("cbreak");
#else
- cur_term->Nttyb.sg_flags |= CBREAK;
+ cur_term->Nttyb.sg_flags |= CBREAK;
#endif
- returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+ returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
}
-void qiflush(void)
+void
+qiflush(void)
{
- T((T_CALLED("qiflush()")));
+ T((T_CALLED("qiflush()")));
- /*
- * Note: this implementation may be wrong. See the comment under
- * intrflush().
- */
+ /*
+ * Note: this implementation may be wrong. See the comment under
+ * intrflush().
+ */
#ifdef TERMIOS
- BEFORE("qiflush");
- cur_term->Nttyb.c_lflag &= ~(NOFLSH);
- AFTER("qiflush");
- (void)_nc_set_tty_mode( &cur_term->Nttyb);
- returnVoid;
+ BEFORE("qiflush");
+ cur_term->Nttyb.c_lflag &= ~(NOFLSH);
+ AFTER("qiflush");
+ (void) _nc_set_tty_mode(&cur_term->Nttyb);
+ returnVoid;
#endif
}
-
-int noraw(void)
+int
+noraw(void)
{
- T((T_CALLED("noraw()")));
+ T((T_CALLED("noraw()")));
- SP->_raw = FALSE;
- SP->_cbreak = 0;
+ SP->_raw = FALSE;
+ SP->_cbreak = 0;
#ifdef __EMX__
- setmode(SP->_ifd, O_TEXT);
+ setmode(SP->_ifd, O_TEXT);
#endif
#ifdef TERMIOS
- BEFORE("noraw");
- cur_term->Nttyb.c_lflag |= ISIG|ICANON;
- cur_term->Nttyb.c_iflag |= COOKED_INPUT;
- AFTER("noraw");
+ BEFORE("noraw");
+ cur_term->Nttyb.c_lflag |= ISIG | ICANON |
+ (cur_term->Ottyb.c_lflag & IEXTEN);
+ cur_term->Nttyb.c_iflag |= COOKED_INPUT;
+ AFTER("noraw");
#else
- cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
+ cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK);
#endif
- returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+ returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
}
-
-int nocbreak(void)
+int
+nocbreak(void)
{
- T((T_CALLED("nocbreak()")));
+ T((T_CALLED("nocbreak()")));
- SP->_cbreak = 0;
+ SP->_cbreak = 0;
#ifdef __EMX__
- setmode(SP->_ifd, O_TEXT);
+ setmode(SP->_ifd, O_TEXT);
#endif
#ifdef TERMIOS
- BEFORE("nocbreak");
- cur_term->Nttyb.c_lflag |= ICANON;
- cur_term->Nttyb.c_iflag |= ICRNL;
- AFTER("nocbreak");
+ BEFORE("nocbreak");
+ cur_term->Nttyb.c_lflag |= ICANON;
+ cur_term->Nttyb.c_iflag |= ICRNL;
+ AFTER("nocbreak");
#else
- cur_term->Nttyb.sg_flags &= ~CBREAK;
+ cur_term->Nttyb.sg_flags &= ~CBREAK;
#endif
- returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+ returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
}
-void noqiflush(void)
+void
+noqiflush(void)
{
- T((T_CALLED("noqiflush()")));
+ T((T_CALLED("noqiflush()")));
- /*
- * Note: this implementation may be wrong. See the comment under
- * intrflush().
- */
+ /*
+ * Note: this implementation may be wrong. See the comment under
+ * intrflush().
+ */
#ifdef TERMIOS
- BEFORE("noqiflush");
- cur_term->Nttyb.c_lflag |= NOFLSH;
- AFTER("noqiflush");
- (void)_nc_set_tty_mode( &cur_term->Nttyb);
- returnVoid;
+ BEFORE("noqiflush");
+ cur_term->Nttyb.c_lflag |= NOFLSH;
+ AFTER("noqiflush");
+ (void) _nc_set_tty_mode(&cur_term->Nttyb);
+ returnVoid;
#endif
}
-int intrflush(WINDOW *win GCC_UNUSED, bool flag)
+int
+intrflush(WINDOW *win GCC_UNUSED, bool flag)
{
- T((T_CALLED("intrflush(%d)"), flag));
+ T((T_CALLED("intrflush(%d)"), flag));
- /*
- * This call does the same thing as the qiflush()/noqiflush()
- * pair. We know for certain that SVr3 intrflush() tweaks the
- * NOFLSH bit; on the other hand, the match (in the SVr4 man
- * pages) between the language describing NOFLSH in termio(7)
- * and the language describing qiflush()/noqiflush() in
- * curs_inopts(3x) is too exact to be coincidence.
- */
+ /*
+ * This call does the same thing as the qiflush()/noqiflush() pair. We
+ * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the
+ * other hand, the match (in the SVr4 man pages) between the language
+ * describing NOFLSH in termio(7) and the language describing
+ * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence.
+ */
#ifdef TERMIOS
- BEFORE("intrflush");
- if (flag)
- cur_term->Nttyb.c_lflag &= ~(NOFLSH);
- else
- cur_term->Nttyb.c_lflag |= (NOFLSH);
- AFTER("intrflush");
- returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
+ BEFORE("intrflush");
+ if (flag)
+ cur_term->Nttyb.c_lflag &= ~(NOFLSH);
+ else
+ cur_term->Nttyb.c_lflag |= (NOFLSH);
+ AFTER("intrflush");
+ returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
#else
- returnCode(ERR);
+ returnCode(ERR);
#endif
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_setup.c b/contrib/ncurses/ncurses/tinfo/lib_setup.c
index 64aa73fa8cf3..50c330eb5739 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_setup.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_setup.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* Terminal setup routines common to termcap and terminfo:
*
@@ -40,16 +39,16 @@
*/
#include <curses.priv.h>
-#include <tic.h> /* for MAX_NAME_SIZE */
+#include <tic.h> /* for MAX_NAME_SIZE */
#include <term_entry.h>
#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
-#include <term.h> /* lines, columns, cur_term */
+#include <term.h> /* lines, columns, cur_term */
-MODULE_ID("$Id: lib_setup.c,v 1.55 1999/08/21 23:06:08 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.59 2000/02/13 01:01:26 tom Exp $")
/****************************************************************************
*
@@ -95,120 +94,116 @@ static int _use_env = TRUE;
static void do_prototype(void);
-void use_env(bool f)
+void
+use_env(bool f)
{
- _use_env = f;
+ _use_env = f;
}
-int LINES, COLS, TABSIZE;
+int LINES = 0, COLS = 0, TABSIZE = 0;
-static void _nc_get_screensize(int *linep, int *colp)
+static void
+_nc_get_screensize(int *linep, int *colp)
/* Obtain lines/columns values from the environment and/or terminfo entry */
{
- /* figure out the size of the screen */
- T(("screen size: terminfo lines = %d columns = %d", lines, columns));
+ /* figure out the size of the screen */
+ T(("screen size: terminfo lines = %d columns = %d", lines, columns));
- if (!_use_env)
- {
- *linep = (int)lines;
- *colp = (int)columns;
- }
- else /* usually want to query LINES and COLUMNS from environment */
- {
- int value;
+ if (!_use_env) {
+ *linep = (int) lines;
+ *colp = (int) columns;
+ } else { /* usually want to query LINES and COLUMNS from environment */
+ int value;
- *linep = *colp = 0;
+ *linep = *colp = 0;
- /* first, look for environment variables */
- if ((value = _nc_getenv_num("LINES")) > 0) {
- *linep = value;
- }
- if ((value = _nc_getenv_num("COLUMNS")) > 0) {
- *colp = value;
- }
- T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
+ /* first, look for environment variables */
+ if ((value = _nc_getenv_num("LINES")) > 0) {
+ *linep = value;
+ }
+ if ((value = _nc_getenv_num("COLUMNS")) > 0) {
+ *colp = value;
+ }
+ T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp));
#ifdef __EMX__
- if (*linep <= 0 || *colp <= 0)
- {
- int screendata[2];
- _scrsize(screendata);
- *colp = screendata[0];
- *linep = screendata[1];
- T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp));
- }
+ if (*linep <= 0 || *colp <= 0) {
+ int screendata[2];
+ _scrsize(screendata);
+ *colp = screendata[0];
+ *linep = screendata[1];
+ T(("EMX screen size: environment LINES = %d COLUMNS = %d",
+ *linep, *colp));
+ }
#endif
#if HAVE_SIZECHANGE
- /* if that didn't work, maybe we can try asking the OS */
- if (*linep <= 0 || *colp <= 0)
- {
- if (isatty(cur_term->Filedes))
- {
- STRUCT_WINSIZE size;
-
- errno = 0;
- do {
- if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
- && errno != EINTR)
- goto failure;
- } while
- (errno == EINTR);
-
- /*
- * Solaris lets users override either dimension with an
- * environment variable.
- */
- if (*linep <= 0)
- *linep = WINSIZE_ROWS(size);
- if (*colp <= 0)
- *colp = WINSIZE_COLS(size);
- }
- /* FALLTHRU */
- failure:;
+ /* if that didn't work, maybe we can try asking the OS */
+ if (*linep <= 0 || *colp <= 0) {
+ if (isatty(cur_term->Filedes)) {
+ STRUCT_WINSIZE size;
+
+ errno = 0;
+ do {
+ if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0
+ && errno != EINTR)
+ goto failure;
+ } while
+ (errno == EINTR);
+
+ /*
+ * Solaris lets users override either dimension with an
+ * environment variable.
+ */
+ if (*linep <= 0)
+ *linep = WINSIZE_ROWS(size);
+ if (*colp <= 0)
+ *colp = WINSIZE_COLS(size);
}
+ /* FALLTHRU */
+ failure:;
+ }
#endif /* HAVE_SIZECHANGE */
- /* if we can't get dynamic info about the size, use static */
- if (*linep <= 0 || *colp <= 0)
- if (lines > 0 && columns > 0)
- {
- *linep = (int)lines;
- *colp = (int)columns;
- }
-
- /* the ultimate fallback, assume fixed 24x80 size */
- if (*linep <= 0 || *colp <= 0)
- {
- *linep = 24;
- *colp = 80;
+ /* if we can't get dynamic info about the size, use static */
+ if (*linep <= 0 || *colp <= 0)
+ if (lines > 0 && columns > 0) {
+ *linep = (int) lines;
+ *colp = (int) columns;
}
- /*
- * Put the derived values back in the screen-size caps, so
- * tigetnum() and tgetnum() will do the right thing.
- */
- lines = (short)(*linep);
- columns = (short)(*colp);
+ /* the ultimate fallback, assume fixed 24x80 size */
+ if (*linep <= 0 || *colp <= 0) {
+ *linep = 24;
+ *colp = 80;
}
- T(("screen size is %dx%d", *linep, *colp));
+ /*
+ * Put the derived values back in the screen-size caps, so
+ * tigetnum() and tgetnum() will do the right thing.
+ */
+ lines = (short) (*linep);
+ columns = (short) (*colp);
+ }
+
+ T(("screen size is %dx%d", *linep, *colp));
- if (init_tabs != -1)
- TABSIZE = (int)init_tabs;
- else
- TABSIZE = 8;
- T(("TABSIZE = %d", TABSIZE));
+ if (VALID_NUMERIC(init_tabs))
+ TABSIZE = (int) init_tabs;
+ else
+ TABSIZE = 8;
+ T(("TABSIZE = %d", TABSIZE));
}
#if USE_SIZECHANGE
-void _nc_update_screensize(void)
+void
+_nc_update_screensize(void)
{
- int my_lines, my_cols;
+ int my_lines, my_cols;
- _nc_get_screensize(&my_lines, &my_cols);
- if (SP != 0 && SP->_resize != 0)
- SP->_resize(my_lines, my_cols);
+ _nc_get_screensize(&my_lines, &my_cols);
+ if (SP != 0 && SP->_resize != 0)
+ SP->_resize(my_lines, my_cols);
}
#endif
@@ -235,52 +230,53 @@ void _nc_update_screensize(void)
}
#if USE_DATABASE
-static int grab_entry(const char *const tn, TERMTYPE *const tp)
+static int
+grab_entry(const char *const tn, TERMTYPE * const tp)
/* return 1 if entry found, 0 if not found, -1 if database not accessible */
{
- char filename[PATH_MAX];
- int status;
+ char filename[PATH_MAX];
+ int status;
- /*
- * $TERM shouldn't contain pathname delimiters.
- */
- if (strchr(tn, '/'))
- return 0;
+ /*
+ * $TERM shouldn't contain pathname delimiters.
+ */
+ if (strchr(tn, '/'))
+ return 0;
- if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
+ if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
#ifndef PURE_TERMINFO
- /*
- * Try falling back on the termcap file.
- * Note: allowing this call links the entire terminfo/termcap
- * compiler into the startup code. It's preferable to build a
- * real terminfo database and use that.
- */
- status = _nc_read_termcap_entry(tn, tp);
-#endif /* PURE_TERMINFO */
-
- }
-
/*
- * If we have an entry, force all of the cancelled strings to null
- * pointers so we don't have to test them in the rest of the library.
- * (The terminfo compiler bypasses this logic, since it must know if
- * a string is cancelled, for merging entries).
+ * Try falling back on the termcap file.
+ * Note: allowing this call links the entire terminfo/termcap
+ * compiler into the startup code. It's preferable to build a
+ * real terminfo database and use that.
*/
- if (status == 1) {
- int n;
- for_each_boolean(n,tp)
- if (!VALID_BOOLEAN(tp->Booleans[n]))
- tp->Booleans[n] = FALSE;
- for_each_string(n,tp)
- if (tp->Strings[n] == CANCELLED_STRING)
- tp->Strings[n] = ABSENT_STRING;
- }
- return(status);
+ status = _nc_read_termcap_entry(tn, tp);
+#endif /* PURE_TERMINFO */
+
+ }
+
+ /*
+ * If we have an entry, force all of the cancelled strings to null
+ * pointers so we don't have to test them in the rest of the library.
+ * (The terminfo compiler bypasses this logic, since it must know if
+ * a string is cancelled, for merging entries).
+ */
+ if (status == 1) {
+ int n;
+ for_each_boolean(n, tp)
+ if (!VALID_BOOLEAN(tp->Booleans[n]))
+ tp->Booleans[n] = FALSE;
+ for_each_string(n, tp)
+ if (tp->Strings[n] == CANCELLED_STRING)
+ tp->Strings[n] = ABSENT_STRING;
+ }
+ return (status);
}
#endif
-char ttytype[NAMESIZE];
+char ttytype[NAMESIZE] = "";
/*
* setupterm(termname, Filedes, errret)
@@ -290,107 +286,103 @@ char ttytype[NAMESIZE];
*
*/
-int setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
+int
+setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
{
-struct term *term_ptr;
-int status;
+ struct term *term_ptr;
+ int status;
- T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
+ T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, errret));
- if (tname == 0) {
- tname = getenv("TERM");
- if (tname == 0 || *tname == '\0') {
- ret_error0(-1, "TERM environment variable not set.\n");
- }
- }
- if (strlen(tname) > MAX_NAME_SIZE) {
- ret_error(-1, "TERM environment must be <= %d characters.\n",
- MAX_NAME_SIZE);
+ if (tname == 0) {
+ tname = getenv("TERM");
+ if (tname == 0 || *tname == '\0') {
+ ret_error0(-1, "TERM environment variable not set.\n");
}
+ }
+ if (strlen(tname) > MAX_NAME_SIZE) {
+ ret_error(-1, "TERM environment must be <= %d characters.\n",
+ MAX_NAME_SIZE);
+ }
- T(("your terminal name is %s", tname));
+ T(("your terminal name is %s", tname));
- term_ptr = typeCalloc(TERMINAL, 1);
+ term_ptr = typeCalloc(TERMINAL, 1);
- if (term_ptr == 0) {
- ret_error0(-1, "Not enough memory to create terminal structure.\n") ;
- }
+ if (term_ptr == 0) {
+ ret_error0(-1, "Not enough memory to create terminal structure.\n");
+ }
#if USE_DATABASE
- status = grab_entry(tname, &term_ptr->type);
+ status = grab_entry(tname, &term_ptr->type);
#else
- status = 0;
+ status = 0;
#endif
- /* try fallback list if entry on disk */
- if (status != 1)
- {
- const TERMTYPE *fallback = _nc_fallback(tname);
-
- if (fallback)
- {
- term_ptr->type = *fallback;
- status = 1;
- }
- }
-
- if (status == -1)
- {
- ret_error0(-1, "terminals database is inaccessible\n");
- }
- else if (status == 0)
- {
- ret_error(0, "'%s': unknown terminal type.\n", tname);
- }
-
- /*
- * Improve on SVr4 curses. If an application mixes curses and termcap
- * calls, it may call both initscr and tgetent. This is not really a
- * good thing to do, but can happen if someone tries using ncurses with
- * the readline library. The problem we are fixing is that when
- * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
- * zeroed. A subsequent call to endwin uses the zeroed terminal
- * settings rather than the ones saved in initscr. So we check if
- * cur_term appears to contain terminal settings for the same output
- * file as our current call - and copy those terminal settings. (SVr4
- * curses does not do this, however applications that are working
- * around the problem will still work properly with this feature).
- */
- if (cur_term != 0) {
- if (cur_term->Filedes == Filedes)
- term_ptr->Ottyb = cur_term->Ottyb;
- }
-
- set_curterm(term_ptr);
-
- if (command_character && getenv("CC"))
- do_prototype();
-
- strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1);
- ttytype[NAMESIZE - 1] = '\0';
-
- /*
- * Allow output redirection. This is what SVr3 does.
- * If stdout is directed to a file, screen updates go
- * to standard error.
- */
- if (Filedes == STDOUT_FILENO && !isatty(Filedes))
- Filedes = STDERR_FILENO;
- cur_term->Filedes = Filedes;
-
- _nc_get_screensize(&LINES, &COLS);
-
- if (errret)
- *errret = 1;
+ /* try fallback list if entry on disk */
+ if (status != 1) {
+ const TERMTYPE *fallback = _nc_fallback(tname);
- T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
-
- if (generic_type) {
- ret_error(0, "'%s': I need something more specific.\n", tname);
- }
- if (hard_copy) {
- ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ if (fallback) {
+ term_ptr->type = *fallback;
+ status = 1;
}
- returnCode(OK);
+ }
+
+ if (status == -1) {
+ ret_error0(-1, "terminals database is inaccessible\n");
+ } else if (status == 0) {
+ ret_error(0, "'%s': unknown terminal type.\n", tname);
+ }
+
+ /*
+ * Improve on SVr4 curses. If an application mixes curses and termcap
+ * calls, it may call both initscr and tgetent. This is not really a
+ * good thing to do, but can happen if someone tries using ncurses with
+ * the readline library. The problem we are fixing is that when
+ * tgetent calls setupterm, the resulting Ottyb struct in cur_term is
+ * zeroed. A subsequent call to endwin uses the zeroed terminal
+ * settings rather than the ones saved in initscr. So we check if
+ * cur_term appears to contain terminal settings for the same output
+ * file as our current call - and copy those terminal settings. (SVr4
+ * curses does not do this, however applications that are working
+ * around the problem will still work properly with this feature).
+ */
+ if (cur_term != 0) {
+ if (cur_term->Filedes == Filedes)
+ term_ptr->Ottyb = cur_term->Ottyb;
+ }
+
+ set_curterm(term_ptr);
+
+ if (command_character && getenv("CC"))
+ do_prototype();
+
+ strncpy(ttytype, cur_term->type.term_names, NAMESIZE - 1);
+ ttytype[NAMESIZE - 1] = '\0';
+
+ /*
+ * Allow output redirection. This is what SVr3 does.
+ * If stdout is directed to a file, screen updates go
+ * to standard error.
+ */
+ if (Filedes == STDOUT_FILENO && !isatty(Filedes))
+ Filedes = STDERR_FILENO;
+ cur_term->Filedes = Filedes;
+
+ _nc_get_screensize(&LINES, &COLS);
+
+ if (errret)
+ *errret = 1;
+
+ T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
+
+ if (generic_type) {
+ ret_error(0, "'%s': I need something more specific.\n", tname);
+ }
+ if (hard_copy) {
+ ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
+ }
+ returnCode(OK);
}
/*
@@ -404,19 +396,19 @@ int status;
static void
do_prototype(void)
{
-int i;
-char CC;
-char proto;
-char *tmp;
-
- tmp = getenv("CC");
- CC = *tmp;
- proto = *command_character;
-
- for_each_string(i, &(cur_term->type)) {
- for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
- if (*tmp == proto)
- *tmp = CC;
- }
+ int i;
+ char CC;
+ char proto;
+ char *tmp;
+
+ tmp = getenv("CC");
+ CC = *tmp;
+ proto = *command_character;
+
+ for_each_string(i, &(cur_term->type)) {
+ for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) {
+ if (*tmp == proto)
+ *tmp = CC;
}
+ }
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_termcap.c b/contrib/ncurses/ncurses/tinfo/lib_termcap.c
index 8238b368eea3..c47400132fa8 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_termcap.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -39,15 +39,15 @@
#define __INTERNAL_CAPS_VISIBLE
#include <term_entry.h>
-MODULE_ID("$Id: lib_termcap.c,v 1.29 1999/09/05 01:06:43 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.36 2000/02/13 01:01:26 tom Exp $")
/*
some of the code in here was contributed by:
Magnus Bengtsson, d6mbeng@dtek.chalmers.se
*/
-char *UP;
-char *BC;
+char *UP = 0;
+char *BC = 0;
/***************************************************************************
*
@@ -64,29 +64,30 @@ char *BC;
*
***************************************************************************/
-int tgetent(char *bufp GCC_UNUSED, const char *name)
+int
+tgetent(char *bufp GCC_UNUSED, const char *name)
{
-int errcode;
+ int errcode;
- T((T_CALLED("tgetent()")));
+ T((T_CALLED("tgetent()")));
- setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode);
+ setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode);
- if (errcode == 1) {
+ if (errcode == 1) {
- if (cursor_left)
- if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
- backspace_if_not_bs = cursor_left;
+ if (cursor_left)
+ if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
+ backspace_if_not_bs = cursor_left;
- /* we're required to export these */
- if (pad_char != NULL)
- PC = pad_char[0];
- if (cursor_up != NULL)
- UP = cursor_up;
- if (backspace_if_not_bs != NULL)
- BC = backspace_if_not_bs;
+ /* we're required to export these */
+ if (pad_char != NULL)
+ PC = pad_char[0];
+ if (cursor_up != NULL)
+ UP = cursor_up;
+ if (backspace_if_not_bs != NULL)
+ BC = backspace_if_not_bs;
- (void) baudrate(); /* sets ospeed as a side-effect */
+ (void) baudrate(); /* sets ospeed as a side-effect */
/* LINT_PREPRO
#if 0*/
@@ -94,8 +95,8 @@ int errcode;
/* LINT_PREPRO
#endif*/
- }
- returnCode(errcode);
+ }
+ returnCode(errcode);
}
/***************************************************************************
@@ -107,22 +108,23 @@ int errcode;
*
***************************************************************************/
-int tgetflag(NCURSES_CONST char *id)
+int
+tgetflag(NCURSES_CONST char *id)
{
-int i;
-
- T((T_CALLED("tgetflag(%s)"), id));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_boolean(i, tp) {
- const char *capname = ExtBoolname(tp, i, boolcodes);
- if (!strncmp(id, capname, 2)) {
- /* setupterm forces invalid booleans to false */
- returnCode(tp->Booleans[i]);
- }
+ int i;
+
+ T((T_CALLED("tgetflag(%s)"), id));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_boolean(i, tp) {
+ const char *capname = ExtBoolname(tp, i, boolcodes);
+ if (!strncmp(id, capname, 2)) {
+ /* setupterm forces invalid booleans to false */
+ returnCode(tp->Booleans[i]);
}
}
- returnCode(0); /* Solaris does this */
+ }
+ returnCode(0); /* Solaris does this */
}
/***************************************************************************
@@ -134,23 +136,24 @@ int i;
*
***************************************************************************/
-int tgetnum(NCURSES_CONST char *id)
+int
+tgetnum(NCURSES_CONST char *id)
{
-int i;
-
- T((T_CALLED("tgetnum(%s)"), id));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_number(i, tp) {
- const char *capname = ExtNumname(tp, i, numcodes);
- if (!strncmp(id, capname, 2)) {
- if (!VALID_NUMERIC(tp->Numbers[i]))
- return -1;
- returnCode(tp->Numbers[i]);
- }
+ int i;
+
+ T((T_CALLED("tgetnum(%s)"), id));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_number(i, tp) {
+ const char *capname = ExtNumname(tp, i, numcodes);
+ if (!strncmp(id, capname, 2)) {
+ if (!VALID_NUMERIC(tp->Numbers[i]))
+ returnCode(ABSENT_NUMERIC);
+ returnCode(tp->Numbers[i]);
}
}
- returnCode(ERR);
+ }
+ returnCode(ABSENT_NUMERIC);
}
/***************************************************************************
@@ -162,30 +165,30 @@ int i;
*
***************************************************************************/
-char *tgetstr(NCURSES_CONST char *id, char **area)
+char *
+tgetstr(NCURSES_CONST char *id, char **area)
{
-int i;
-
- T((T_CALLED("tgetstr(%s,%p)"), id, area));
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_string(i, tp) {
- const char *capname = ExtStrname(tp, i, strcodes);
- T(("trying %s", capname));
- if (!strncmp(id, capname, 2)) {
- T(("found match : %s", _nc_visbuf(tp->Strings[i])));
- /* setupterm forces cancelled strings to null */
- if (area != 0
- && *area != 0
- && VALID_STRING(tp->Strings[i])) {
- (void) strcpy(*area, tp->Strings[i]);
- *area += strlen(*area) + 1;
- }
- returnPtr(tp->Strings[i]);
+ int i;
+
+ T((T_CALLED("tgetstr(%s,%p)"), id, area));
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_string(i, tp) {
+ const char *capname = ExtStrname(tp, i, strcodes);
+ if (!strncmp(id, capname, 2)) {
+ TR(TRACE_DATABASE,("found match : %s", _nc_visbuf(tp->Strings[i])));
+ /* setupterm forces canceled strings to null */
+ if (area != 0
+ && *area != 0
+ && VALID_STRING(tp->Strings[i])) {
+ (void) strcpy(*area, tp->Strings[i]);
+ *area += strlen(*area) + 1;
}
+ returnPtr(tp->Strings[i]);
}
}
- returnPtr(NULL);
+ }
+ returnPtr(NULL);
}
/*
@@ -197,8 +200,9 @@ int i;
*
*/
-char *tgoto(const char *string, int x, int y)
+char *
+tgoto(const char *string, int x, int y)
{
- T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
- returnPtr(tparm((NCURSES_CONST char *)string, y, x));
+ T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
+ returnPtr(tparm((NCURSES_CONST char *) string, y, x));
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_ti.c b/contrib/ncurses/ncurses/tinfo/lib_ti.c
index 7b2b2f910f2d..def5ba6d5ea3 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_ti.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_ti.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,71 +31,73 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
#include <curses.priv.h>
#include <term_entry.h>
#include <tic.h>
-MODULE_ID("$Id: lib_ti.c,v 1.16 1999/02/28 23:11:28 tom Exp $")
+MODULE_ID("$Id: lib_ti.c,v 1.20 2000/02/13 01:01:26 tom Exp $")
-int tigetflag(NCURSES_CONST char *str)
+int
+tigetflag(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetflag(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_boolean(i,tp) {
- const char *capname = ExtBoolname(tp, i, boolnames);
- if (!strcmp(str, capname)) {
- /* setupterm forces invalid booleans to false */
- returnCode(tp->Booleans[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetflag(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_boolean(i, tp) {
+ const char *capname = ExtBoolname(tp, i, boolnames);
+ if (!strcmp(str, capname)) {
+ /* setupterm forces invalid booleans to false */
+ returnCode(tp->Booleans[i]);
}
}
+ }
- returnCode(ABSENT_BOOLEAN);
+ returnCode(ABSENT_BOOLEAN);
}
-int tigetnum(NCURSES_CONST char *str)
+int
+tigetnum(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetnum(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_number(i, tp) {
- const char *capname = ExtNumname(tp, i, numnames);
- if (!strcmp(str, capname)) {
- if (!VALID_NUMERIC(tp->Numbers[i]))
- return -1;
- returnCode(tp->Numbers[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetnum(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_number(i, tp) {
+ const char *capname = ExtNumname(tp, i, numnames);
+ if (!strcmp(str, capname)) {
+ if (!VALID_NUMERIC(tp->Numbers[i]))
+ returnCode(ABSENT_NUMERIC);
+ returnCode(tp->Numbers[i]);
}
}
+ }
- returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */
+ returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */
}
-char *tigetstr(NCURSES_CONST char *str)
+char *
+tigetstr(NCURSES_CONST char *str)
{
-int i;
-
- T((T_CALLED("tigetstr(%s)"), str));
-
- if (cur_term != 0) {
- TERMTYPE *tp = &(cur_term->type);
- for_each_string(i, tp) {
- const char *capname = ExtStrname(tp, i, strnames);
- if (!strcmp(str, capname)) {
- /* setupterm forces cancelled strings to null */
- returnPtr(tp->Strings[i]);
- }
+ int i;
+
+ T((T_CALLED("tigetstr(%s)"), str));
+
+ if (cur_term != 0) {
+ TERMTYPE *tp = &(cur_term->type);
+ for_each_string(i, tp) {
+ const char *capname = ExtStrname(tp, i, strnames);
+ if (!strcmp(str, capname)) {
+ /* setupterm forces cancelled strings to null */
+ returnPtr(tp->Strings[i]);
}
}
+ }
- returnPtr(CANCELLED_STRING);
+ returnPtr(CANCELLED_STRING);
}
diff --git a/contrib/ncurses/ncurses/tinfo/lib_tputs.c b/contrib/ncurses/ncurses/tinfo/lib_tputs.c
index d3fd46276e6e..f17d8382e921 100644
--- a/contrib/ncurses/ncurses/tinfo/lib_tputs.c
+++ b/contrib/ncurses/ncurses/tinfo/lib_tputs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* tputs.c
* delay_output()
@@ -42,210 +41,278 @@
#include <curses.priv.h>
#include <ctype.h>
-#include <term.h> /* padding_baud_rate, xon_xoff */
-#include <termcap.h> /* ospeed */
+#include <term.h> /* padding_baud_rate, xon_xoff */
+#include <termcap.h> /* ospeed */
#include <tic.h>
-MODULE_ID("$Id: lib_tputs.c,v 1.41 1999/10/22 23:31:24 tom Exp $")
+MODULE_ID("$Id: lib_tputs.c,v 1.47 2000/05/27 23:08:41 tom Exp $")
-char PC; /* used by termcap library */
-speed_t ospeed; /* used by termcap library */
+char PC = 0; /* used by termcap library */
+speed_t ospeed = 0; /* used by termcap library */
-int _nc_nulls_sent; /* used by 'tack' program */
+int _nc_nulls_sent = 0; /* used by 'tack' program */
-static int (*my_outch)(int c) = _nc_outch;
+static int (*my_outch) (int c) = _nc_outch;
-int delay_output(int ms)
+int
+delay_output(int ms)
{
- T((T_CALLED("delay_output(%d)"), ms));
+ T((T_CALLED("delay_output(%d)"), ms));
- if (no_pad_char)
- napms(ms);
- else {
- register int nullcount;
+ if (no_pad_char) {
+ _nc_flush();
+ napms(ms);
+ } else {
+ register int nullcount;
- nullcount = (ms * _nc_baudrate(ospeed)) / 10000;
- for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
- my_outch(PC);
- if (my_outch == _nc_outch)
- _nc_flush();
- }
+ nullcount = (ms * _nc_baudrate(ospeed)) / 10000;
+ for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
+ my_outch(PC);
+ if (my_outch == _nc_outch)
+ _nc_flush();
+ }
- returnCode(OK);
+ returnCode(OK);
}
-int _nc_outch(int ch)
+void
+_nc_flush(void)
+{
+ (void)fflush(NC_OUTPUT);
+}
+
+int
+_nc_outch(int ch)
{
#ifdef TRACE
- _nc_outchars++;
+ _nc_outchars++;
#endif /* TRACE */
- if (SP != 0
- && SP->_cleanup) {
- char tmp = ch;
- /*
- * POSIX says write() is safe in a signal handler, but the
- * buffered I/O is not.
- */
- write(fileno(NC_OUTPUT), &tmp, 1);
- } else {
- putc(ch, NC_OUTPUT);
- }
- return OK;
+ if (SP != 0
+ && SP->_cleanup) {
+ char tmp = ch;
+ /*
+ * POSIX says write() is safe in a signal handler, but the
+ * buffered I/O is not.
+ */
+ write(fileno(NC_OUTPUT), &tmp, 1);
+ } else {
+ putc(ch, NC_OUTPUT);
+ }
+ return OK;
}
-int putp(const char *string)
+#ifdef USE_WIDEC_SUPPORT
+/*
+ * Reference: The Unicode Standard 2.0
+ *
+ * No surrogates supported (we're storing only one 16-bit Unicode value per
+ * cell).
+ */
+int
+_nc_utf8_outch(int ch)
{
- return tputs(string, 1, _nc_outch);
+ static const unsigned byteMask = 0xBF;
+ static const unsigned otherMark = 0x80;
+ static const unsigned firstMark[] =
+ {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
+
+ int result[7], *ptr;
+ int count = 0;
+
+ if (ch < 0x80)
+ count = 1;
+ else if (ch < 0x800)
+ count = 2;
+ else if (ch < 0x10000)
+ count = 3;
+ else if (ch < 0x200000)
+ count = 4;
+ else if (ch < 0x4000000)
+ count = 5;
+ else if (ch <= 0x7FFFFFFF)
+ count = 6;
+ else {
+ count = 2;
+ ch = 0xFFFD;
+ }
+ ptr = result + count;
+ switch (count) {
+ case 6:
+ *--ptr = (ch | otherMark) & byteMask;
+ ch >>= 6;
+ case 5:
+ *--ptr = (ch | otherMark) & byteMask;
+ ch >>= 6;
+ case 4:
+ *--ptr = (ch | otherMark) & byteMask;
+ ch >>= 6;
+ case 3:
+ *--ptr = (ch | otherMark) & byteMask;
+ ch >>= 6;
+ case 2:
+ *--ptr = (ch | otherMark) & byteMask;
+ ch >>= 6;
+ case 1:
+ *--ptr = (ch | firstMark[count]);
+ }
+ while (count--)
+ _nc_outch(*ptr++);
+ return OK;
}
+#endif
-int tputs(const char *string, int affcnt, int (*outc)(int))
+int
+putp(const char *string)
{
-bool always_delay;
-bool normal_delay;
-int number;
+ return tputs(string, 1, _nc_outch);
+}
+
+int
+tputs(const char *string, int affcnt, int (*outc) (int))
+{
+ bool always_delay;
+ bool normal_delay;
+ int number;
#ifdef BSD_TPUTS
-int trailpad;
+ int trailpad;
#endif /* BSD_TPUTS */
#ifdef TRACE
-char addrbuf[32];
-
- if (_nc_tracing & TRACE_TPUTS)
- {
- if (outc == _nc_outch)
- (void) strcpy(addrbuf, "_nc_outch");
- else
- (void) sprintf(addrbuf, "%p", outc);
- if (_nc_tputs_trace) {
- TR(TRACE_MAXIMUM, ("tputs(%s = %s, %d, %s) called", _nc_tputs_trace, _nc_visbuf(string), affcnt, addrbuf));
- }
- else {
- TR(TRACE_MAXIMUM, ("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf));
- }
- _nc_tputs_trace = (char *)NULL;
+ char addrbuf[32];
+
+ if (_nc_tracing & TRACE_TPUTS) {
+ if (outc == _nc_outch)
+ (void) strcpy(addrbuf, "_nc_outch");
+ else
+ (void) sprintf(addrbuf, "%p", outc);
+ if (_nc_tputs_trace) {
+ _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
+ _nc_visbuf(string), affcnt, addrbuf);
+ } else {
+ _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf);
}
+ _nc_tputs_trace = (char *) NULL;
+ }
#endif /* TRACE */
-
- if (!VALID_STRING(string))
- return ERR;
- if (cur_term == 0) {
- always_delay = FALSE;
- normal_delay = TRUE;
- } else {
- always_delay = (string == bell) || (string == flash_screen);
- normal_delay =
- !xon_xoff
- && padding_baud_rate
+ if (!VALID_STRING(string))
+ return ERR;
+
+ if (cur_term == 0) {
+ always_delay = FALSE;
+ normal_delay = TRUE;
+ } else {
+ always_delay = (string == bell) || (string == flash_screen);
+ normal_delay =
+ !xon_xoff
+ && padding_baud_rate
#ifdef NCURSES_NO_PADDING
- && (SP == 0 || !(SP->_no_padding))
+ && (SP == 0 || !(SP->_no_padding))
#endif
- && (_nc_baudrate(ospeed) >= padding_baud_rate);
- }
+ && (_nc_baudrate(ospeed) >= padding_baud_rate);
+ }
#ifdef BSD_TPUTS
- /*
- * This ugly kluge deals with the fact that some ancient BSD programs
- * (like nethack) actually do the likes of tputs("50") to get delays.
- */
- trailpad = 0;
- if (isdigit(*string)) {
+ /*
+ * This ugly kluge deals with the fact that some ancient BSD programs
+ * (like nethack) actually do the likes of tputs("50") to get delays.
+ */
+ trailpad = 0;
+ if (isdigit(*string)) {
+ while (isdigit(*string)) {
+ trailpad = trailpad * 10 + (*string - '0');
+ string++;
+ }
+ trailpad *= 10;
+ if (*string == '.') {
+ string++;
+ if (isdigit(*string)) {
+ trailpad += (*string - '0');
+ string++;
+ }
+ while (isdigit(*string))
+ string++;
+ }
+
+ if (*string == '*') {
+ trailpad *= affcnt;
+ string++;
+ }
+ }
+#endif /* BSD_TPUTS */
+
+ my_outch = outc; /* redirect delay_output() */
+ while (*string) {
+ if (*string != '$')
+ (*outc) (*string);
+ else {
+ string++;
+ if (*string != '<') {
+ (*outc) ('$');
+ if (*string)
+ (*outc) (*string);
+ } else {
+ bool mandatory;
+
+ string++;
+ if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) {
+ (*outc) ('$');
+ (*outc) ('<');
+ continue;
+ }
+
+ number = 0;
while (isdigit(*string)) {
- trailpad = trailpad * 10 + (*string - '0');
- string++;
+ number = number * 10 + (*string - '0');
+ string++;
}
- trailpad *= 10;
+ number *= 10;
if (*string == '.') {
+ string++;
+ if (isdigit(*string)) {
+ number += (*string - '0');
+ string++;
+ }
+ while (isdigit(*string))
string++;
- if (isdigit(*string)) {
- trailpad += (*string - '0');
- string++;
- }
- while (isdigit(*string))
- string++;
}
- if (*string == '*') {
- trailpad *= affcnt;
+ mandatory = FALSE;
+ while (*string == '*' || *string == '/') {
+ if (*string == '*') {
+ number *= affcnt;
+ string++;
+ } else { /* if (*string == '/') */
+ mandatory = TRUE;
string++;
+ }
}
- }
-#endif /* BSD_TPUTS */
- my_outch = outc; /* redirect delay_output() */
- while (*string) {
- if (*string != '$')
- (*outc)(*string);
- else {
- string++;
- if (*string != '<') {
- (*outc)('$');
- if (*string)
- (*outc)(*string);
- } else {
- bool mandatory;
-
- string++;
- if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) {
- (*outc)('$');
- (*outc)('<');
- continue;
- }
-
- number = 0;
- while (isdigit(*string)) {
- number = number * 10 + (*string - '0');
- string++;
- }
- number *= 10;
- if (*string == '.') {
- string++;
- if (isdigit(*string)) {
- number += (*string - '0');
- string++;
- }
- while (isdigit(*string))
- string++;
- }
-
- mandatory = FALSE;
- while (*string == '*' || *string == '/')
- {
- if (*string == '*') {
- number *= affcnt;
- string++;
- }
- else /* if (*string == '/') */ {
- mandatory = TRUE;
- string++;
- }
- }
-
- if (number > 0
- && (always_delay
- || normal_delay
- || mandatory))
- delay_output(number/10);
-
- } /* endelse (*string == '<') */
- } /* endelse (*string == '$') */
-
- if (*string == '\0')
- break;
+ if (number > 0
+ && (always_delay
+ || normal_delay
+ || mandatory))
+ delay_output(number / 10);
- string++;
- }
+ } /* endelse (*string == '<') */
+ } /* endelse (*string == '$') */
+
+ if (*string == '\0')
+ break;
+
+ string++;
+ }
#ifdef BSD_TPUTS
- /*
- * Emit any BSD-style prefix padding that we've accumulated now.
- */
- if (trailpad > 0
- && (always_delay || normal_delay))
- delay_output(trailpad/10);
+ /*
+ * Emit any BSD-style prefix padding that we've accumulated now.
+ */
+ if (trailpad > 0
+ && (always_delay || normal_delay))
+ delay_output(trailpad / 10);
#endif /* BSD_TPUTS */
- my_outch = _nc_outch;
- return OK;
+ my_outch = _nc_outch;
+ return OK;
}
diff --git a/contrib/ncurses/ncurses/tinfo/make_keys.c b/contrib/ncurses/ncurses/tinfo/make_keys.c
index a1fd1d0b66f8..703ca5de0fea 100644
--- a/contrib/ncurses/ncurses/tinfo/make_keys.c
+++ b/contrib/ncurses/ncurses/tinfo/make_keys.c
@@ -37,7 +37,7 @@
*/
#include <curses.priv.h>
-MODULE_ID("$Id: make_keys.c,v 1.7 1999/09/11 17:32:57 Jeffrey.Honig Exp $")
+MODULE_ID("$Id: make_keys.c,v 1.8 2000/03/12 02:55:50 Todd.C.Miller Exp $")
#include <names.c>
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
"",
"/* This file was generated by MAKE_KEYS */",
"",
- "#ifdef BROKEN_LINKER",
+ "#if BROKEN_LINKER",
"static",
"#endif",
"struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
diff --git a/contrib/ncurses/ncurses/tinfo/parse_entry.c b/contrib/ncurses/ncurses/tinfo/parse_entry.c
index 07f3868e0b44..1aff562d0dd6 100644
--- a/contrib/ncurses/ncurses/tinfo/parse_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/parse_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* parse_entry.c -- compile one terminfo or termcap entry
*
@@ -48,24 +47,23 @@
#define __INTERNAL_CAPS_VISIBLE
#include <term_entry.h>
-MODULE_ID("$Id: parse_entry.c,v 1.39 1999/03/01 02:28:51 tom Exp $")
+MODULE_ID("$Id: parse_entry.c,v 1.44 2000/04/30 00:17:42 tom Exp $")
#ifdef LINT
-static short const parametrized[] = { 0 };
+static short const parametrized[] =
+{0};
#else
#include <parametrized.h>
#endif
-struct token _nc_curr_token;
-
-static void postprocess_termcap(TERMTYPE *, bool);
-static void postprocess_terminfo(TERMTYPE *);
-static struct name_table_entry const * lookup_fullname(const char *name);
+static void postprocess_termcap(TERMTYPE *, bool);
+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 const *
+_nc_extend_names(ENTRY * entryp, char *name, int token_type)
{
static struct name_table_entry temp;
TERMTYPE *tp = &(entryp->tterm);
@@ -77,20 +75,20 @@ _nc_extend_names(ENTRY *entryp, char *name, int token_type)
switch (token_type) {
case BOOLEAN:
- first = 0;
- last = tp->ext_Booleans;
+ 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;
+ 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;
+ 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;
@@ -98,7 +96,7 @@ _nc_extend_names(ENTRY *entryp, char *name, int token_type)
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)) {
+ if (n > (unsigned) (tp->ext_Booleans + tp->ext_Numbers)) {
token_type = STRING;
} else if (n > tp->ext_Booleans) {
token_type = NUMBER;
@@ -125,9 +123,15 @@ _nc_extend_names(ENTRY *entryp, char *name, int token_type)
offset = n;
tindex = n - first;
switch (token_type) {
- case BOOLEAN: tindex += BOOLCOUNT; break;
- case NUMBER: tindex += NUMCOUNT; break;
- case STRING: tindex += STRCOUNT; break;
+ case BOOLEAN:
+ tindex += BOOLCOUNT;
+ break;
+ case NUMBER:
+ tindex += NUMCOUNT;
+ break;
+ case STRING:
+ tindex += STRCOUNT;
+ break;
}
break;
}
@@ -138,35 +142,35 @@ _nc_extend_names(ENTRY *entryp, char *name, int token_type)
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];
+ 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];
+ 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];
+ 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);
+ tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names);
while (--actual > offset)
- tp->ext_Names[actual] = tp->ext_Names[actual-1];
+ 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_name = tp->ext_Names[offset];
+ temp.nte_type = token_type;
temp.nte_index = tindex;
- temp.nte_link = -1;
+ temp.nte_link = -1;
return &temp;
}
@@ -191,16 +195,17 @@ _nc_extend_names(ENTRY *entryp, char *name, int token_type)
* push back token
*/
-int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
+int
+_nc_parse_entry(struct entry *entryp, int literal, bool silent)
{
- int token_type;
- struct name_table_entry const *entry_ptr;
- char *ptr, namecpy[MAX_NAME_SIZE+1];
+ int token_type;
+ struct name_table_entry const *entry_ptr;
+ char *ptr, namecpy[MAX_NAME_SIZE + 1];
token_type = _nc_get_token();
if (token_type == EOF)
- return(EOF);
+ return (EOF);
if (token_type != NAMES)
_nc_err_abort("Entry does not start with terminal names in column one");
@@ -213,8 +218,7 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
/* junk the 2-character termcap name, if present */
ptr = _nc_curr_token.tk_name;
- if (ptr[2] == '|')
- {
+ if (ptr[2] == '|') {
ptr = _nc_curr_token.tk_name + 3;
_nc_curr_token.tk_name[2] = '\0';
}
@@ -233,30 +237,29 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool 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 *)0)
+ 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 *)0, "|")) != (char *)0)
+ while ((ptr = strtok((char *) 0, "|")) != (char *) 0)
if (strlen(ptr) > MAX_ALIAS)
_nc_warning("alias `%s' may be too long", ptr);
entryp->nuses = 0;
for (token_type = _nc_get_token();
- token_type != EOF && token_type != NAMES;
- token_type = _nc_get_token())
- {
+ token_type != EOF && token_type != NAMES;
+ token_type = _nc_get_token()) {
if (strcmp(_nc_curr_token.tk_name, "use") == 0
|| strcmp(_nc_curr_token.tk_name, "tc") == 0) {
- entryp->uses[entryp->nuses].parent = (void *)_nc_save_str(_nc_curr_token.tk_valstring);
+ entryp->uses[entryp->nuses].name = _nc_save_str(_nc_curr_token.tk_valstring);
entryp->uses[entryp->nuses].line = _nc_curr_line;
entryp->nuses++;
} else {
/* normal token lookup */
entry_ptr = _nc_find_entry(_nc_curr_token.tk_name,
- _nc_syntax ? _nc_cap_hash_table : _nc_info_hash_table);
+ _nc_syntax ? _nc_cap_hash_table : _nc_info_hash_table);
/*
* Our kluge to handle aliasing. The reason it's done
@@ -266,43 +269,37 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
* making this case fast, aliased caps aren't common now
* and will get rarer.
*/
- if (entry_ptr == NOTFOUND)
- {
- const struct alias *ap;
+ if (entry_ptr == NOTFOUND) {
+ const struct alias *ap;
- if (_nc_syntax == SYN_TERMCAP)
- {
+ if (_nc_syntax == SYN_TERMCAP) {
for (ap = _nc_capalias_table; ap->from; ap++)
- if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
- {
- if (ap->to == (char *)0)
- {
+ if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
+ if (ap->to == (char *) 0) {
_nc_warning("%s (%s termcap extension) ignored",
- ap->from, ap->source);
+ ap->from, ap->source);
goto nexttok;
}
entry_ptr = _nc_find_entry(ap->to, _nc_cap_hash_table);
if (entry_ptr && !silent)
- _nc_warning("%s (%s termcap extension) aliased to %s", ap->from, ap->source, ap->to);
+ _nc_warning("%s (%s termcap extension) aliased to %s",
+ ap->from, ap->source, ap->to);
break;
}
- }
- else /* if (_nc_syntax == SYN_TERMINFO) */
- {
+ } else { /* if (_nc_syntax == SYN_TERMINFO) */
for (ap = _nc_infoalias_table; ap->from; ap++)
- if (strcmp(ap->from, _nc_curr_token.tk_name) == 0)
- {
- if (ap->to == (char *)0)
- {
+ if (strcmp(ap->from, _nc_curr_token.tk_name) == 0) {
+ if (ap->to == (char *) 0) {
_nc_warning("%s (%s terminfo extension) ignored",
- ap->from, ap->source);
+ ap->from, ap->source);
goto nexttok;
}
entry_ptr = _nc_find_entry(ap->to, _nc_info_hash_table);
if (entry_ptr && !silent)
- _nc_warning("%s (%s terminfo extension) aliased to %s", ap->from, ap->source, ap->to);
+ _nc_warning("%s (%s terminfo extension) aliased to %s",
+ ap->from, ap->source, ap->to);
break;
}
@@ -311,16 +308,17 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
}
}
}
-
#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);
+ && _nc_user_definable
+ && (entry_ptr = _nc_extend_names(entryp,
+ _nc_curr_token.tk_name, token_type)) != 0) {
+ if (_nc_tracing >= DEBUG_LEVEL(1))
+ _nc_warning("extended capability '%s'", _nc_curr_token.tk_name);
}
#endif /* NCURSES_XNAMES */
@@ -328,13 +326,12 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
if (entry_ptr == NOTFOUND) {
if (!silent)
_nc_warning("unknown capability '%s'",
- _nc_curr_token.tk_name);
+ _nc_curr_token.tk_name);
continue;
}
/* deal with bad type/value combinations. */
- if (token_type != CANCEL && entry_ptr->nte_type != token_type)
- {
+ if (token_type != CANCEL && entry_ptr->nte_type != token_type) {
/*
* Nasty special cases here handle situations in which type
* information can resolve name clashes. Normal lookup
@@ -348,39 +345,36 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
/* tell max_attributes from arrow_key_map */
if (token_type == NUMBER && !strcmp("ma", _nc_curr_token.tk_name))
entry_ptr = _nc_find_type_entry("ma", NUMBER,
- _nc_get_table(_nc_syntax != 0));
+ _nc_get_table(_nc_syntax != 0));
/* map terminfo's string MT to MT */
- else if (token_type==STRING &&!strcmp("MT",_nc_curr_token.tk_name))
+ else if (token_type == STRING && !strcmp("MT", _nc_curr_token.tk_name))
entry_ptr = _nc_find_type_entry("MT", STRING,
- _nc_get_table(_nc_syntax != 0));
+ _nc_get_table(_nc_syntax != 0));
/* treat strings without following "=" as empty strings */
- else if (token_type==BOOLEAN && entry_ptr->nte_type==STRING)
+ else if (token_type == BOOLEAN && entry_ptr->nte_type == STRING)
token_type = STRING;
/* we couldn't recover; skip this token */
- else
- {
- if (!silent)
- {
+ else {
+ if (!silent) {
const char *type_name;
- switch (entry_ptr->nte_type)
- {
+ switch (entry_ptr->nte_type) {
case BOOLEAN:
- type_name = "boolean";
- break;
+ type_name = "boolean";
+ break;
case STRING:
- type_name = "string";
- break;
+ type_name = "string";
+ break;
case NUMBER:
- type_name = "numeric";
- break;
+ type_name = "numeric";
+ break;
default:
- type_name = "unknown";
- break;
+ type_name = "unknown";
+ break;
}
_nc_warning("wrong type used for %s capability '%s'",
- type_name, _nc_curr_token.tk_name);
+ type_name, _nc_curr_token.tk_name);
}
continue;
}
@@ -415,23 +409,23 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
case STRING:
ptr = _nc_curr_token.tk_valstring;
- if (_nc_syntax==SYN_TERMCAP)
+ if (_nc_syntax == SYN_TERMCAP)
ptr = _nc_captoinfo(_nc_curr_token.tk_name,
- ptr,
- parametrized[entry_ptr->nte_index]);
+ ptr,
+ parametrized[entry_ptr->nte_index]);
entryp->tterm.Strings[entry_ptr->nte_index] = _nc_save_str(ptr);
break;
default:
if (!silent)
_nc_warning("unknown token type");
- _nc_panic_mode((_nc_syntax==SYN_TERMCAP) ? ':' : ',');
+ _nc_panic_mode((_nc_syntax == SYN_TERMCAP) ? ':' : ',');
continue;
}
- } /* end else cur_token.name != "use" */
- nexttok:
- continue; /* cannot have a label w/o statement */
- } /* endwhile (not EOF and not NAMES) */
+ } /* end else cur_token.name != "use" */
+ nexttok:
+ continue; /* cannot have a label w/o statement */
+ } /* endwhile (not EOF and not NAMES) */
_nc_push_token(token_type);
_nc_set_type(_nc_first_name(entryp->tterm.term_names));
@@ -443,10 +437,9 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
* to be done before entry allocation is wrapped up.
*/
if (!literal) {
- if (_nc_syntax == SYN_TERMCAP)
- {
- bool has_base_entry = FALSE;
- int i;
+ if (_nc_syntax == SYN_TERMCAP) {
+ bool has_base_entry = FALSE;
+ int i;
/*
* Don't insert defaults if this is a `+' entry meant only
@@ -461,50 +454,49 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent)
* have picked up defaults via translation.
*/
for (i = 0; i < entryp->nuses; i++)
- if (!strchr((char *)entryp->uses[i].parent, '+'))
+ if (!strchr((char *) entryp->uses[i].name, '+'))
has_base_entry = TRUE;
postprocess_termcap(&entryp->tterm, has_base_entry);
- }
- else
+ } else
postprocess_terminfo(&entryp->tterm);
}
_nc_wrap_entry(entryp);
- return(OK);
+ return (OK);
}
-int _nc_capcmp(const char *s, const char *t)
+int
+_nc_capcmp(const char *s, const char *t)
/* compare two string capabilities, stripping out padding */
{
if (!s && !t)
- return(0);
+ return (0);
else if (!s || !t)
- return(1);
-
- for (;;)
- {
- if (s[0] == '$' && s[1] == '<')
- {
- for (s += 2; ; s++)
- if (!(isdigit(*s) || *s=='.' || *s=='*' || *s=='/' || *s=='>'))
+ return (1);
+
+ for (;;) {
+ if (s[0] == '$' && s[1] == '<') {
+ for (s += 2;; s++)
+ if (!(isdigit(*s) || *s == '.' || *s == '*' || *s == '/' ||
+ *s == '>'))
break;
}
- if (t[0] == '$' && t[1] == '<')
- {
- for (t += 2; ; t++)
- if (!(isdigit(*t) || *t=='.' || *t=='*' || *t=='/' || *t=='>'))
+ if (t[0] == '$' && t[1] == '<') {
+ for (t += 2;; t++)
+ if (!(isdigit(*t) || *t == '.' || *t == '*' || *t == '/' ||
+ *t == '>'))
break;
}
/* we've now pushed s and t past any padding they were pointing at */
if (*s == '\0' && *t == '\0')
- return(0);
+ return (0);
if (*s != *t)
- return(*t - *s);
+ return (*t - *s);
/* else *s == *t but one is not NUL, so continue */
s++, t++;
@@ -516,29 +508,32 @@ int _nc_capcmp(const char *s, const char *t)
* list. For each capability, we may assume there is a keycap that sends the
* string which is the value of that capability.
*/
-typedef struct {const char *from; const char *to;} assoc;
+typedef struct {
+ const char *from;
+ const char *to;
+} assoc;
static assoc const ko_xlate[] =
{
- {"al", "kil1"}, /* insert line key -> KEY_IL */
- {"bt", "kcbt"}, /* back tab -> KEY_BTAB */
- {"cd", "ked"}, /* clear-to-eos key -> KEY_EOL */
- {"ce", "kel"}, /* clear-to-eol key -> KEY_EOS */
- {"cl", "kclr"}, /* clear key -> KEY_CLEAR */
- {"ct", "tbc"}, /* clear all tabs -> KEY_CATAB */
- {"dc", "kdch1"}, /* delete char -> KEY_DC */
- {"dl", "kdl1"}, /* delete line -> KEY_DL */
- {"do", "kcud1"}, /* down key -> KEY_DOWN */
- {"ei", "krmir"}, /* exit insert key -> KEY_EIC */
- {"ho", "khome"}, /* home key -> KEY_HOME */
- {"ic", "kich1"}, /* insert char key -> KEY_IC */
- {"im", "kIC"}, /* insert-mode key -> KEY_SIC */
- {"le", "kcub1"}, /* le key -> KEY_LEFT */
- {"nd", "kcuf1"}, /* nd key -> KEY_RIGHT */
- {"nl", "kent"}, /* new line key -> KEY_ENTER */
- {"st", "khts"}, /* set-tab key -> KEY_STAB */
- {"ta", CANCELLED_STRING},
- {"up", "kcuu1"}, /* up-arrow key -> KEY_UP */
- {(char *)0, (char *)0},
+ {"al", "kil1"}, /* insert line key -> KEY_IL */
+ {"bt", "kcbt"}, /* back tab -> KEY_BTAB */
+ {"cd", "ked"}, /* clear-to-eos key -> KEY_EOL */
+ {"ce", "kel"}, /* clear-to-eol key -> KEY_EOS */
+ {"cl", "kclr"}, /* clear key -> KEY_CLEAR */
+ {"ct", "tbc"}, /* clear all tabs -> KEY_CATAB */
+ {"dc", "kdch1"}, /* delete char -> KEY_DC */
+ {"dl", "kdl1"}, /* delete line -> KEY_DL */
+ {"do", "kcud1"}, /* down key -> KEY_DOWN */
+ {"ei", "krmir"}, /* exit insert key -> KEY_EIC */
+ {"ho", "khome"}, /* home key -> KEY_HOME */
+ {"ic", "kich1"}, /* insert char key -> KEY_IC */
+ {"im", "kIC"}, /* insert-mode key -> KEY_SIC */
+ {"le", "kcub1"}, /* le key -> KEY_LEFT */
+ {"nd", "kcuf1"}, /* nd key -> KEY_RIGHT */
+ {"nl", "kent"}, /* new line key -> KEY_ENTER */
+ {"st", "khts"}, /* set-tab key -> KEY_STAB */
+ {"ta", CANCELLED_STRING},
+ {"up", "kcuu1"}, /* up-arrow key -> KEY_UP */
+ {(char *) 0, (char *) 0},
};
/*
@@ -569,7 +564,8 @@ static const char C_HT[] = "\t";
#define CUR tp->
static
-void postprocess_termcap(TERMTYPE *tp, bool has_base)
+void
+postprocess_termcap(TERMTYPE * tp, bool has_base)
{
char buf[MAX_LINE * 2 + 2];
@@ -582,8 +578,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
*/
/* if there was a tc entry, assume we picked up defaults via that */
- if (!has_base)
- {
+ if (!has_base) {
if (WANTED(init_3string) && termcap_init2)
init_3string = _nc_save_str(termcap_init2);
@@ -637,15 +632,15 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
} else
newline = _nc_save_str(C_LF);
} else if (PRESENT(carriage_return) && PRESENT(scroll_forward)) {
- strncpy(buf, carriage_return, MAX_LINE-2);
- buf[MAX_LINE-1] = '\0';
- strncat(buf, scroll_forward, MAX_LINE-strlen(buf)-1);
+ strncpy(buf, carriage_return, MAX_LINE - 2);
+ buf[MAX_LINE - 1] = '\0';
+ strncat(buf, scroll_forward, MAX_LINE - strlen(buf) - 1);
buf[MAX_LINE] = '\0';
newline = _nc_save_str(buf);
} else if (PRESENT(carriage_return) && PRESENT(cursor_down)) {
- strncpy(buf, carriage_return, MAX_LINE-2);
- buf[MAX_LINE-1] = '\0';
- strncat(buf, cursor_down, MAX_LINE-strlen(buf)-1);
+ strncpy(buf, carriage_return, MAX_LINE - 2);
+ buf[MAX_LINE - 1] = '\0';
+ strncat(buf, cursor_down, MAX_LINE - strlen(buf) - 1);
buf[MAX_LINE] = '\0';
newline = _nc_save_str(buf);
}
@@ -661,8 +656,7 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
* These translations will *not* be inverted by tgetent().
*/
- if (!has_base)
- {
+ if (!has_base) {
/*
* We wait until now to decide if we've got a working cr because even
* one that doesn't work can be used for newline. Unfortunately the
@@ -698,13 +692,11 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
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
- {
+ else {
if (tab && _nc_capcmp(tab, C_HT))
_nc_warning("hardware tabs with a non-^I tab string %s",
- _nc_visbuf(tab));
- else
- {
+ _nc_visbuf(tab));
+ else {
if (WANTED(tab))
tab = _nc_save_str(C_HT);
init_tabs = 8;
@@ -715,14 +707,13 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
* Now translate the ko capability, if there is one. This
* isn't from mytinfo...
*/
- if (PRESENT(other_non_function_keys))
- {
- char *dp, *cp = strtok(other_non_function_keys, ",");
- struct name_table_entry const *from_ptr;
- struct name_table_entry const *to_ptr;
- assoc const *ap;
- char buf2[MAX_TERMINFO_LENGTH];
- bool foundim;
+ if (PRESENT(other_non_function_keys)) {
+ char *dp, *cp = strtok(other_non_function_keys, ",");
+ struct name_table_entry const *from_ptr;
+ struct name_table_entry const *to_ptr;
+ assoc const *ap;
+ char buf2[MAX_TERMINFO_LENGTH];
+ bool foundim;
/* we're going to use this for a special case later */
dp = strchr(other_non_function_keys, 'i');
@@ -733,30 +724,26 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
for (ap = ko_xlate; ap->from; ap++)
if (strcmp(ap->from, cp) == 0)
break;
- if (!ap->to)
- {
+ if (!ap->to) {
_nc_warning("unknown capability `%s' in ko string", cp);
continue;
- }
- else if (ap->to == CANCELLED_STRING) /* ignore it */
+ } else if (ap->to == CANCELLED_STRING) /* ignore it */
continue;
/* now we know we found a match in ko_table, so... */
from_ptr = _nc_find_entry(ap->from, _nc_cap_hash_table);
- to_ptr = _nc_find_entry(ap->to, _nc_info_hash_table);
+ to_ptr = _nc_find_entry(ap->to, _nc_info_hash_table);
if (!from_ptr || !to_ptr) /* should never happen! */
_nc_err_abort("ko translation table is invalid, I give up");
- if (WANTED(tp->Strings[from_ptr->nte_index]))
- {
+ if (WANTED(tp->Strings[from_ptr->nte_index])) {
_nc_warning("no value for ko capability %s", ap->from);
continue;
}
- if (tp->Strings[to_ptr->nte_index])
- {
+ if (tp->Strings[to_ptr->nte_index]) {
/* There's no point in warning about it if it's the same
* string; that's just an inefficiency.
*/
@@ -764,8 +751,8 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
tp->Strings[from_ptr->nte_index],
tp->Strings[to_ptr->nte_index]) != 0)
_nc_warning("%s (%s) already has an explicit value %s, ignoring ko",
- ap->to, ap->from,
- _nc_visbuf(tp->Strings[to_ptr->nte_index]) );
+ ap->to, ap->from,
+ _nc_visbuf(tp->Strings[to_ptr->nte_index]));
continue;
}
@@ -774,24 +761,21 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
* stripping out padding.
*/
dp = buf2;
- for (cp = tp->Strings[from_ptr->nte_index]; *cp; cp++)
- {
- if (cp[0] == '$' && cp[1] == '<')
- {
+ for (cp = tp->Strings[from_ptr->nte_index]; *cp; cp++) {
+ if (cp[0] == '$' && cp[1] == '<') {
while (*cp && *cp != '>')
if (!*cp)
break;
- else
+ else
++cp;
- }
- else
+ } else
*dp++ = *cp;
}
*dp++ = '\0';
tp->Strings[to_ptr->nte_index] = _nc_save_str(buf2);
} while
- ((cp = strtok((char *)0, ",")) != 0);
+ ((cp = strtok((char *) 0, ",")) != 0);
/*
* Note: ko=im and ko=ic both want to grab the `Insert'
@@ -799,15 +783,13 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
* got mapped to kich1 and im to kIC to avoid a collision.
* If the description has im but not ic, hack kIC back to kich1.
*/
- if (foundim && WANTED(key_ic) && key_sic)
- {
+ if (foundim && WANTED(key_ic) && key_sic) {
key_ic = key_sic;
key_sic = ABSENT_STRING;
}
}
- if (!hard_copy)
- {
+ if (!hard_copy) {
if (WANTED(key_backspace))
key_backspace = _nc_save_str(C_BS);
if (WANTED(key_left))
@@ -829,90 +811,76 @@ void postprocess_termcap(TERMTYPE *tp, bool has_base)
PRESENT(acs_ttee) ||
PRESENT(acs_hline) ||
PRESENT(acs_vline) ||
- PRESENT(acs_plus))
- {
- char buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
+ PRESENT(acs_plus)) {
+ char buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
- if (acs_chars)
- {
- (void)strcpy(bp, acs_chars);
+ if (acs_chars) {
+ (void) strcpy(bp, acs_chars);
bp += strlen(bp);
}
- if (acs_ulcorner && acs_ulcorner[1] == '\0')
- {
+ if (acs_ulcorner && acs_ulcorner[1] == '\0') {
*bp++ = 'l';
*bp++ = *acs_ulcorner;
}
- if (acs_llcorner && acs_llcorner[1] == '\0')
- {
+ if (acs_llcorner && acs_llcorner[1] == '\0') {
*bp++ = 'm';
*bp++ = *acs_llcorner;
}
- if (acs_urcorner && acs_urcorner[1] == '\0')
- {
+ if (acs_urcorner && acs_urcorner[1] == '\0') {
*bp++ = 'k';
*bp++ = *acs_urcorner;
}
- if (acs_lrcorner && acs_lrcorner[1] == '\0')
- {
+ if (acs_lrcorner && acs_lrcorner[1] == '\0') {
*bp++ = 'j';
*bp++ = *acs_lrcorner;
}
- if (acs_ltee && acs_ltee[1] == '\0')
- {
+ if (acs_ltee && acs_ltee[1] == '\0') {
*bp++ = 't';
*bp++ = *acs_ltee;
}
- if (acs_rtee && acs_rtee[1] == '\0')
- {
+ if (acs_rtee && acs_rtee[1] == '\0') {
*bp++ = 'u';
*bp++ = *acs_rtee;
}
- if (acs_btee && acs_btee[1] == '\0')
- {
+ if (acs_btee && acs_btee[1] == '\0') {
*bp++ = 'v';
*bp++ = *acs_btee;
}
- if (acs_ttee && acs_ttee[1] == '\0')
- {
+ if (acs_ttee && acs_ttee[1] == '\0') {
*bp++ = 'w';
*bp++ = *acs_ttee;
}
- if (acs_hline && acs_hline[1] == '\0')
- {
+ if (acs_hline && acs_hline[1] == '\0') {
*bp++ = 'q';
*bp++ = *acs_hline;
}
- if (acs_vline && acs_vline[1] == '\0')
- {
+ if (acs_vline && acs_vline[1] == '\0') {
*bp++ = 'x';
*bp++ = *acs_vline;
}
- if (acs_plus)
- {
+ if (acs_plus) {
*bp++ = 'n';
strcpy(bp, acs_plus);
bp = buf2 + strlen(buf2);
}
- if (bp != buf2)
- {
+ if (bp != buf2) {
*bp++ = '\0';
acs_chars = _nc_save_str(buf2);
_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{{||}}~~");
+ } else if (acs_chars == 0
+ && enter_alt_charset_mode != 0
+ && exit_alt_charset_mode != 0) {
+ acs_chars =
+ _nc_save_str("``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~");
}
}
static
-void postprocess_terminfo(TERMTYPE *tp)
+void
+postprocess_terminfo(TERMTYPE * tp)
{
/*
* TERMINFO-TO-TERMINFO MAPPINGS FOR SOURCE TRANSLATION
@@ -922,74 +890,60 @@ void postprocess_terminfo(TERMTYPE *tp)
/*
* Translate AIX forms characters.
*/
- if (PRESENT(box_chars_1))
- {
- char buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
+ if (PRESENT(box_chars_1)) {
+ char buf2[MAX_TERMCAP_LENGTH], *bp = buf2;
- if (acs_chars)
- {
- (void)strcpy(bp, acs_chars);
+ if (acs_chars) {
+ (void) strcpy(bp, acs_chars);
bp += strlen(bp);
}
- if (box_chars_1[0]) /* ACS_ULCORNER */
- {
+ if (box_chars_1[0]) { /* ACS_ULCORNER */
*bp++ = 'l';
*bp++ = box_chars_1[0];
}
- if (box_chars_1[1]) /* ACS_HLINE */
- {
+ if (box_chars_1[1]) { /* ACS_HLINE */
*bp++ = 'q';
*bp++ = box_chars_1[1];
}
- if (box_chars_1[2]) /* ACS_URCORNER */
- {
+ if (box_chars_1[2]) { /* ACS_URCORNER */
*bp++ = 'k';
*bp++ = box_chars_1[2];
}
- if (box_chars_1[3]) /* ACS_VLINE */
- {
+ if (box_chars_1[3]) { /* ACS_VLINE */
*bp++ = 'x';
*bp++ = box_chars_1[3];
}
- if (box_chars_1[4]) /* ACS_LRCORNER */
- {
+ if (box_chars_1[4]) { /* ACS_LRCORNER */
*bp++ = 'j';
*bp++ = box_chars_1[4];
}
- if (box_chars_1[5]) /* ACS_LLCORNER */
- {
+ if (box_chars_1[5]) { /* ACS_LLCORNER */
*bp++ = 'm';
*bp++ = box_chars_1[5];
}
- if (box_chars_1[6]) /* ACS_TTEE */
- {
+ if (box_chars_1[6]) { /* ACS_TTEE */
*bp++ = 'w';
*bp++ = box_chars_1[6];
}
- if (box_chars_1[7]) /* ACS_RTEE */
- {
+ if (box_chars_1[7]) { /* ACS_RTEE */
*bp++ = 'u';
*bp++ = box_chars_1[7];
}
- if (box_chars_1[8]) /* ACS_BTEE */
- {
+ if (box_chars_1[8]) { /* ACS_BTEE */
*bp++ = 'v';
*bp++ = box_chars_1[8];
}
- if (box_chars_1[9]) /* ACS_LTEE */
- {
+ if (box_chars_1[9]) { /* ACS_LTEE */
*bp++ = 't';
*bp++ = box_chars_1[9];
}
- if (box_chars_1[10]) /* ACS_PLUS */
- {
+ if (box_chars_1[10]) { /* ACS_PLUS */
*bp++ = 'n';
*bp++ = box_chars_1[10];
}
- if (bp != buf2)
- {
+ if (bp != buf2) {
*bp++ = '\0';
acs_chars = _nc_save_str(buf2);
_nc_warning("acsc string synthesized from AIX capabilities");
@@ -1010,7 +964,8 @@ void postprocess_terminfo(TERMTYPE *tp)
* sorted, but the nte_type fields are not necessarily grouped together.
*/
static
-struct name_table_entry const * lookup_fullname(const char *find)
+struct name_table_entry const *
+lookup_fullname(const char *find)
{
int state = -1;
@@ -1034,10 +989,10 @@ struct name_table_entry const * lookup_fullname(const char *find)
for (count = 0; names[count] != 0; count++) {
if (!strcmp(names[count], find)) {
- struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
- while (entry_ptr->nte_type != state
+ struct name_table_entry const *entry_ptr = _nc_get_table(FALSE);
+ while (entry_ptr->nte_type != state
|| entry_ptr->nte_index != count)
- entry_ptr++;
+ entry_ptr++;
return entry_ptr;
}
}
diff --git a/contrib/ncurses/ncurses/tinfo/read_entry.c b/contrib/ncurses/ncurses/tinfo/read_entry.c
index f60a4863bdf8..85dc3e0bf6e9 100644
--- a/contrib/ncurses/ncurses/tinfo/read_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/read_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,8 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
-
/*
* read_entry.c -- Routine for reading in a compiled terminfo file
*
@@ -40,23 +38,13 @@
#include <curses.priv.h>
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
#include <tic.h>
#include <term_entry.h>
-MODULE_ID("$Id: read_entry.c,v 1.61 1999/07/24 20:07:20 tom Exp $")
+MODULE_ID("$Id: read_entry.c,v 1.67 2000/03/11 12:35:45 tom Exp $")
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-#if 0
-#define TRACE_IN(p) DEBUG(2, p)
-#else
-#define TRACE_IN(p) /*nothing*/
+#if !HAVE_TELL
+#define tell(fd) 0 /* lseek() is POSIX, but not tell() - odd... */
#endif
/*
@@ -82,7 +70,8 @@ static bool keep_tic_directory = FALSE;
* Record the "official" location of the terminfo directory, according to
* the place where we're writing to, or the normal default, if not.
*/
-const char *_nc_tic_dir(const char *path)
+const char *
+_nc_tic_dir(const char *path)
{
static const char *result = TERMINFO;
@@ -104,42 +93,44 @@ const char *_nc_tic_dir(const char *path)
* has chdir'd to it. If we let it be changed, then if $TERMINFO has a
* relative path, we'll lose track of the actual directory.
*/
-void _nc_keep_tic_dir(const char *path)
+void
+_nc_keep_tic_dir(const char *path)
{
_nc_tic_dir(path);
keep_tic_directory = TRUE;
}
-static void convert_shorts(char *buf, short *Numbers, int count)
+static void
+convert_shorts(char *buf, short *Numbers, int count)
{
int i;
- for (i = 0; i < count; i++)
- {
- if (IS_NEG1(buf + 2*i))
+ for (i = 0; i < count; i++) {
+ if (IS_NEG1(buf + 2 * i))
Numbers[i] = ABSENT_NUMERIC;
- else if (IS_NEG2(buf + 2*i))
+ else if (IS_NEG2(buf + 2 * i))
Numbers[i] = CANCELLED_NUMERIC;
else
- Numbers[i] = LOW_MSB(buf + 2*i);
- TRACE_IN(("get Numbers[%d]=%d", i, Numbers[i]));
+ Numbers[i] = LOW_MSB(buf + 2 * i);
+ TR(TRACE_DATABASE, ("get Numbers[%d]=%d", i, Numbers[i]));
}
}
-static void convert_strings(char *buf, char **Strings, int count, int size, char *table)
+static void
+convert_strings(char *buf, char **Strings, int count, int size, char *table)
{
int i;
char *p;
for (i = 0; i < count; i++) {
- if (IS_NEG1(buf + 2*i)) {
+ if (IS_NEG1(buf + 2 * i)) {
Strings[i] = ABSENT_STRING;
- } else if (IS_NEG2(buf + 2*i)) {
+ } else if (IS_NEG2(buf + 2 * i)) {
Strings[i] = CANCELLED_STRING;
- } else if (LOW_MSB(buf + 2*i) > size) {
+ } else if (LOW_MSB(buf + 2 * i) > size) {
Strings[i] = ABSENT_STRING;
} else {
- Strings[i] = (LOW_MSB(buf+2*i) + table);
- TRACE_IN(("Strings[%d] = %s", i, _nc_visbuf(Strings[i])));
+ Strings[i] = (LOW_MSB(buf + 2 * i) + table);
+ TR(TRACE_DATABASE, ("Strings[%d] = %s", i, _nc_visbuf(Strings[i])));
}
/* make sure all strings are NUL terminated */
@@ -159,53 +150,59 @@ static void convert_strings(char *buf, char **Strings, int count, int size, char
#define even_boundary(value) \
if ((value) % 2 != 0) read(fd, buf, 1)
-static int read_termtype(int fd, TERMTYPE *ptr)
+static int
+read_termtype(int fd, TERMTYPE * ptr)
/* return 1 if read, 0 if not found or garbled */
{
- int name_size, bool_count, num_count, str_count, str_size;
- int i;
- char buf[MAX_ENTRY_SIZE];
+ int name_size, bool_count, num_count, str_count, str_size;
+ int i;
+ char buf[MAX_ENTRY_SIZE];
+
+ TR(TRACE_DATABASE, ("READ termtype header @%d", tell(fd)));
- TRACE_IN(("READ termtype header @%d", tell(fd)));
+ memset(ptr, 0, sizeof(*ptr));
/* grab the header */
if (!read_shorts(fd, buf, 6)
- || LOW_MSB(buf) != MAGIC) {
- return(0);
+ || LOW_MSB(buf) != MAGIC) {
+ return (0);
}
_nc_free_termtype(ptr);
- name_size = LOW_MSB(buf + 2);
+ name_size = LOW_MSB(buf + 2);
bool_count = LOW_MSB(buf + 4);
- num_count = LOW_MSB(buf + 6);
- str_count = LOW_MSB(buf + 8);
- str_size = LOW_MSB(buf + 10);
-
- TRACE_IN(("header is %d/%d/%d/%d(%d)", name_size, bool_count, num_count, str_count, str_size));
- if (name_size < 0
- || bool_count < 0
- || num_count < 0
- || str_count < 0
- || str_size < 0) {
- return(0);
+ num_count = LOW_MSB(buf + 6);
+ str_count = LOW_MSB(buf + 8);
+ str_size = LOW_MSB(buf + 10);
+
+ TR(TRACE_DATABASE,
+ ("TERMTYPE name_size=%d, bool=%d/%d, num=%d/%d str=%d/%d(%d)",
+ name_size, bool_count, BOOLCOUNT, num_count, NUMCOUNT,
+ str_count, STRCOUNT, str_size));
+ if (name_size < 0
+ || bool_count < 0
+ || num_count < 0
+ || str_count < 0
+ || str_size < 0) {
+ return (0);
}
if (str_size) {
/* try to allocate space for the string table */
- if (str_count*2 >= (int) sizeof(buf)
- || (ptr->str_table = typeMalloc(char, (unsigned)str_size)) == 0) {
- return(0);
+ if (str_count * 2 >= (int) sizeof(buf)
+ || (ptr->str_table = typeMalloc(char, (unsigned) str_size)) == 0) {
+ return (0);
}
} else {
str_count = 0;
}
/* grab the name (a null-terminate string) */
- read(fd, buf, min(MAX_NAME_SIZE, (unsigned)name_size));
+ read(fd, buf, min(MAX_NAME_SIZE, (unsigned) name_size));
buf[MAX_NAME_SIZE] = '\0';
ptr->term_names = typeCalloc(char, strlen(buf) + 1);
if (ptr->term_names == NULL) {
- return(0);
+ return (0);
}
(void) strcpy(ptr->term_names, buf);
if (name_size > MAX_NAME_SIZE)
@@ -213,8 +210,8 @@ static int read_termtype(int fd, TERMTYPE *ptr)
/* grab the booleans */
if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0
- || read(fd, ptr->Booleans, (unsigned)bool_count) < bool_count) {
- return(0);
+ || read(fd, ptr->Booleans, (unsigned) bool_count) < bool_count) {
+ return (0);
}
/*
@@ -227,128 +224,142 @@ static int read_termtype(int fd, TERMTYPE *ptr)
/* grab the numbers */
if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0
- || !read_shorts(fd, buf, num_count)) {
- return(0);
+ || !read_shorts(fd, buf, num_count)) {
+ return (0);
}
convert_shorts(buf, ptr->Numbers, num_count);
if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0)
- return(0);
+ return (0);
- if (str_count)
- {
+ if (str_count) {
/* grab the string offsets */
if (!read_shorts(fd, buf, str_count)) {
- return(0);
+ return (0);
}
/* finally, grab the string table itself */
- if (read(fd, ptr->str_table, (unsigned)str_size) != str_size)
- return(0);
+ if (read(fd, ptr->str_table, (unsigned) str_size) != str_size)
+ return (0);
convert_strings(buf, ptr->Strings, str_count, str_size, ptr->str_table);
}
-
#if NCURSES_XNAMES
ptr->num_Booleans = BOOLCOUNT;
- ptr->num_Numbers = NUMCOUNT;
- ptr->num_Strings = STRCOUNT;
+ ptr->num_Numbers = NUMCOUNT;
+ ptr->num_Strings = STRCOUNT;
/*
* Read extended entries, if any, after the normal end of terminfo data.
*/
even_boundary(str_size);
- TRACE_IN(("READ extended_header @%d", tell(fd)));
+ TR(TRACE_DATABASE, ("READ extended_header @%d", tell(fd)));
if (_nc_user_definable && read_shorts(fd, buf, 5)) {
int ext_bool_count = LOW_MSB(buf + 0);
- int ext_num_count = LOW_MSB(buf + 2);
- int ext_str_count = LOW_MSB(buf + 4);
- int ext_str_size = LOW_MSB(buf + 6);
- int ext_str_limit = LOW_MSB(buf + 8);
+ int ext_num_count = LOW_MSB(buf + 2);
+ int ext_str_count = LOW_MSB(buf + 4);
+ int ext_str_size = LOW_MSB(buf + 6);
+ int ext_str_limit = LOW_MSB(buf + 8);
int need = (ext_bool_count + ext_num_count + ext_str_count);
int base = 0;
if (need >= (int) sizeof(buf)
- || ext_str_size >= (int) sizeof(buf)
- || ext_str_limit >= (int) sizeof(buf)
- || ext_bool_count < 0
- || ext_num_count < 0
- || ext_str_count < 0
- || ext_str_size < 0
- || ext_str_limit < 0)
- return(0);
+ || ext_str_size >= (int) sizeof(buf)
+ || ext_str_limit >= (int) sizeof(buf)
+ || ext_bool_count < 0
+ || ext_num_count < 0
+ || ext_str_count < 0
+ || ext_str_size < 0
+ || ext_str_limit < 0)
+ return (0);
ptr->num_Booleans = BOOLCOUNT + ext_bool_count;
- ptr->num_Numbers = NUMCOUNT + ext_num_count;
- ptr->num_Strings = STRCOUNT + ext_str_count;
+ ptr->num_Numbers = NUMCOUNT + ext_num_count;
+ ptr->num_Strings = STRCOUNT + ext_str_count;
- ptr->Booleans = typeRealloc(char, ptr->num_Booleans,ptr->Booleans);
+ ptr->Booleans = typeRealloc(char, ptr->num_Booleans, ptr->Booleans);
ptr->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers);
- ptr->Strings = typeRealloc(char*, ptr->num_Strings, ptr->Strings);
+ ptr->Strings = typeRealloc(char *, ptr->num_Strings, ptr->Strings);
- TRACE_IN(("extended header is %d/%d/%d(%d:%d)", ext_bool_count, ext_num_count, ext_str_count, ext_str_size, ext_str_limit));
+ TR(TRACE_DATABASE, ("extended header is %d/%d/%d(%d:%d)",
+ ext_bool_count, ext_num_count, ext_str_count, ext_str_size, ext_str_limit));
- TRACE_IN(("READ %d extended-booleans @%d", ext_bool_count, tell(fd)));
+ TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
+ ext_bool_count, tell(fd)));
if ((ptr->ext_Booleans = ext_bool_count) != 0) {
- if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)ext_bool_count) != ext_bool_count)
- return(0);
+ if (read(fd, ptr->Booleans + BOOLCOUNT, (unsigned)
+ ext_bool_count) != ext_bool_count)
+ return (0);
}
even_boundary(ext_bool_count);
- TRACE_IN(("READ %d extended-numbers @%d", ext_num_count, tell(fd)));
+ TR(TRACE_DATABASE, ("READ %d extended-numbers @%d",
+ ext_num_count, tell(fd)));
if ((ptr->ext_Numbers = ext_num_count) != 0) {
if (!read_shorts(fd, buf, ext_num_count))
- return(0);
- TRACE_IN(("Before converting extended-numbers"));
+ return (0);
+ TR(TRACE_DATABASE, ("Before converting extended-numbers"));
convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count);
}
- TRACE_IN(("READ extended-offsets @%d", tell(fd)));
+ TR(TRACE_DATABASE, ("READ extended-offsets @%d", tell(fd)));
if ((ext_str_count || need)
- && !read_shorts(fd, buf, ext_str_count+need))
- return(0);
+ && !read_shorts(fd, buf, ext_str_count + need))
+ return (0);
+
+ TR(TRACE_DATABASE, ("READ %d bytes of extended-strings @%d",
+ ext_str_limit, tell(fd)));
- TRACE_IN(("READ %d bytes of extended-strings @%d", ext_str_limit, tell(fd)));
if (ext_str_limit) {
if ((ptr->ext_str_table = typeMalloc(char, ext_str_limit)) == 0)
- return(0);
+ return (0);
if (read(fd, ptr->ext_str_table, ext_str_limit) != ext_str_limit)
- return(0);
- TRACE_IN(("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
+ return (0);
+ TR(TRACE_DATABASE, ("first extended-string is %s", _nc_visbuf(ptr->ext_str_table)));
}
if ((ptr->ext_Strings = ext_str_count) != 0) {
- TRACE_IN(("Before computing extended-string capabilities str_count=%d, ext_str_count=%d", str_count, ext_str_count));
- convert_strings(buf, ptr->Strings + str_count, ext_str_count, ext_str_limit, ptr->ext_str_table);
- for (i = ext_str_count-1; i >= 0; i--) {
- TRACE_IN(("MOVE from [%d:%d] %s", i, i+str_count, _nc_visbuf(ptr->Strings[i+str_count])));
- ptr->Strings[i+STRCOUNT] = ptr->Strings[i+str_count];
- if (VALID_STRING(ptr->Strings[i+STRCOUNT]))
- base += (strlen(ptr->Strings[i+STRCOUNT]) + 1);
- TRACE_IN(("... to [%d] %s", i+STRCOUNT, _nc_visbuf(ptr->Strings[i+STRCOUNT])));
+ TR(TRACE_DATABASE,
+ ("Before computing extended-string capabilities str_count=%d, ext_str_count=%d",
+ str_count, ext_str_count));
+ convert_strings(buf, ptr->Strings + str_count, ext_str_count,
+ ext_str_limit, ptr->ext_str_table);
+ for (i = ext_str_count - 1; i >= 0; i--) {
+ TR(TRACE_DATABASE, ("MOVE from [%d:%d] %s",
+ i, i + str_count,
+ _nc_visbuf(ptr->Strings[i + str_count])));
+ ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count];
+ if (VALID_STRING(ptr->Strings[i + STRCOUNT]))
+ base += (strlen(ptr->Strings[i + STRCOUNT]) + 1);
+ TR(TRACE_DATABASE, ("... to [%d] %s",
+ i + STRCOUNT,
+ _nc_visbuf(ptr->Strings[i + STRCOUNT])));
}
}
if (need) {
if ((ptr->ext_Names = typeCalloc(char *, need)) == 0)
- return(0);
- TRACE_IN(("ext_NAMES starting @%d in extended_strings, first = %s", base, _nc_visbuf(ptr->ext_str_table+base)));
- convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need, ext_str_limit, ptr->ext_str_table + base);
+ return (0);
+ TR(TRACE_DATABASE,
+ ("ext_NAMES starting @%d in extended_strings, first = %s",
+ base, _nc_visbuf(ptr->ext_str_table + base)));
+ convert_strings(buf + (2 * ext_str_count), ptr->ext_Names, need,
+ ext_str_limit, ptr->ext_str_table + base);
}
T(("...done reading terminfo bool %d(%d) num %d(%d) str %d(%d)",
- ptr->num_Booleans, ptr->ext_Booleans,
- ptr->num_Numbers, ptr->ext_Numbers,
- ptr->num_Strings, ptr->ext_Strings));
+ ptr->num_Booleans, ptr->ext_Booleans,
+ ptr->num_Numbers, ptr->ext_Numbers,
+ ptr->num_Strings, ptr->ext_Strings));
- TRACE_IN(("extend: num_Booleans:%d", ptr->num_Booleans));
+ TR(TRACE_DATABASE, ("extend: num_Booleans:%d", ptr->num_Booleans));
} else
#endif /* NCURSES_XNAMES */
{
T(("...done reading terminfo bool %d num %d str %d",
- bool_count,
- num_count,
- str_count));
- TRACE_IN(("normal: num_Booleans:%d", ptr->num_Booleans));
+ bool_count, num_count, str_count));
+#if NCURSES_XNAMES
+ TR(TRACE_DATABASE, ("normal: num_Booleans:%d", ptr->num_Booleans));
+#endif
}
for (i = bool_count; i < BOOLCOUNT; i++)
@@ -358,18 +369,19 @@ static int read_termtype(int fd, TERMTYPE *ptr)
for (i = str_count; i < STRCOUNT; i++)
ptr->Strings[i] = ABSENT_STRING;
- return(1);
+ return (1);
}
-int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
+int
+_nc_read_file_entry(const char *const filename, TERMTYPE * ptr)
/* return 1 if read, 0 if not found or garbled */
{
int code, fd = -1;
if (_nc_access(filename, R_OK) < 0
- || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) {
+ || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) {
T(("cannot open terminfo %s (errno=%d)", filename, errno));
- return(0);
+ return (0);
}
T(("read terminfo %s", filename));
@@ -384,51 +396,54 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
* Build a terminfo pathname and try to read the data. Returns 1 on success,
* 0 on failure.
*/
-static int _nc_read_tic_entry(char *const filename,
- const char *const dir, const char *ttn, TERMTYPE *const tp)
+static int
+_nc_read_tic_entry(char *const filename,
+ const char *const dir, const char *ttn, TERMTYPE * const tp)
{
/* maximum safe length of terminfo root directory name */
#define MAX_TPATH (PATH_MAX - MAX_ALIAS - 6)
- if (strlen(dir) > MAX_TPATH)
- return 0;
- (void) sprintf(filename, "%s/%s", dir, ttn);
- return _nc_read_file_entry(filename, tp);
+ if (strlen(dir) > MAX_TPATH)
+ return 0;
+ (void) sprintf(filename, "%s/%s", dir, ttn);
+ return _nc_read_file_entry(filename, tp);
}
/*
* Process the list of :-separated directories, looking for the terminal type.
* We don't use strtok because it does not show us empty tokens.
*/
-static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const ttn, TERMTYPE *const tp)
+static int
+_nc_read_terminfo_dirs(const char *dirs, char *const filename, const char *const
+ ttn, TERMTYPE * const tp)
{
- char *list, *a;
- const char *b;
- int code = 0;
-
- /* we'll modify the argument, so we must copy */
- if ((b = a = list = strdup(dirs)) == NULL)
- return(0);
-
- for (;;) {
- int c = *a;
- if (c == 0 || c == ':') {
- *a = 0;
- if ((b + 1) >= a)
- b = TERMINFO;
- if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) {
- code = 1;
- break;
- }
- b = a + 1;
- if (c == 0)
- break;
- }
- a++;
+ char *list, *a;
+ const char *b;
+ int code = 0;
+
+ /* we'll modify the argument, so we must copy */
+ if ((b = a = list = strdup(dirs)) == NULL)
+ return (0);
+
+ for (;;) {
+ int c = *a;
+ if (c == 0 || c == ':') {
+ *a = 0;
+ if ((b + 1) >= a)
+ b = TERMINFO;
+ if (_nc_read_tic_entry(filename, b, ttn, tp) == 1) {
+ code = 1;
+ break;
+ }
+ b = a + 1;
+ if (c == 0)
+ break;
}
+ a++;
+ }
- free(list);
- return(code);
+ free(list);
+ return (code);
}
/*
@@ -440,43 +455,43 @@ static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const
* overrun the file buffer.
*/
-int _nc_read_entry(const char *const tn, char *const filename, TERMTYPE *const tp)
+int
+_nc_read_entry(const char *const tn, char *const filename, TERMTYPE * const tp)
{
-char *envp;
-char ttn[MAX_ALIAS + 3];
-
- /* truncate the terminal name to prevent dangerous buffer airline */
- (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn);
-
- /* This is System V behavior, in conjunction with our requirements for
- * writing terminfo entries.
- */
- if (have_tic_directory
- && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1)
- return 1;
-
- if ((envp = getenv("TERMINFO")) != 0
- && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1)
- return 1;
-
- if ((envp = _nc_home_terminfo()) != 0) {
- if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) {
- return(1);
- }
+ char *envp;
+ char ttn[MAX_ALIAS + 3];
+
+ /* truncate the terminal name to prevent dangerous buffer airline */
+ (void) sprintf(ttn, "%c/%.*s", *tn, MAX_ALIAS, tn);
+
+ /* This is System V behavior, in conjunction with our requirements for
+ * writing terminfo entries.
+ */
+ if (have_tic_directory
+ && _nc_read_tic_entry(filename, _nc_tic_dir(0), ttn, tp) == 1)
+ return 1;
+
+ if ((envp = getenv("TERMINFO")) != 0
+ && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1)
+ return 1;
+
+ if ((envp = _nc_home_terminfo()) != 0) {
+ if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) {
+ return (1);
}
+ }
- /* this is an ncurses extension */
- if ((envp = getenv("TERMINFO_DIRS")) != 0)
- return _nc_read_terminfo_dirs(envp, filename, ttn, tp);
+ /* this is an ncurses extension */
+ if ((envp = getenv("TERMINFO_DIRS")) != 0)
+ return _nc_read_terminfo_dirs(envp, filename, ttn, tp);
- /* Try the system directory. Note that the TERMINFO_DIRS value, if
- * defined by the configure script, begins with a ":", which will be
- * interpreted as TERMINFO.
- */
+ /* Try the system directory. Note that the TERMINFO_DIRS value, if
+ * defined by the configure script, begins with a ":", which will be
+ * interpreted as TERMINFO.
+ */
#ifdef TERMINFO_DIRS
- return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp);
+ return _nc_read_terminfo_dirs(TERMINFO_DIRS, filename, ttn, tp);
#else
- return _nc_read_tic_entry(filename, TERMINFO, ttn, tp);
+ return _nc_read_tic_entry(filename, TERMINFO, ttn, tp);
#endif
}
-
diff --git a/contrib/ncurses/ncurses/tinfo/read_termcap.c b/contrib/ncurses/ncurses/tinfo/read_termcap.c
index d60a92d63f0a..26e72d403263 100644
--- a/contrib/ncurses/ncurses/tinfo/read_termcap.c
+++ b/contrib/ncurses/ncurses/tinfo/read_termcap.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,7 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
/*
* Termcap compatibility support
*
@@ -56,11 +55,7 @@
#include <tic.h>
#include <term_entry.h>
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-MODULE_ID("$Id: read_termcap.c,v 1.43 1999/04/10 20:52:52 tom Exp $")
+MODULE_ID("$Id: read_termcap.c,v 1.47 2000/04/15 16:53:19 Todd.C.Miller Exp $")
#ifndef PURE_TERMINFO
@@ -86,7 +81,7 @@ MODULE_ID("$Id: read_termcap.c,v 1.43 1999/04/10 20:52:52 tom Exp $")
#define _nc_cgetset cgetset
#else
static int _nc_cgetmatch(char *, const char *);
-static int _nc_getent(char **, unsigned int *, int *, int, char **, int, const char *, int, char *);
+static int _nc_getent(char **, unsigned *, int *, int, char **, int, const char *, int, char *);
static int _nc_nfcmp(const char *, char *);
/*-
@@ -130,16 +125,16 @@ static int _nc_nfcmp(const char *, char *);
#define BFRAG 1024
#define BSIZE 1024
#define ESC ('[' & 037) /* ASCII ESC */
-#define MAX_RECURSION 32 /* maximum getent recursion */
-#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */
+#define MAX_RECURSION 32 /* maximum getent recursion */
+#define SFRAG 100 /* cgetstr mallocs in SFRAG chunks */
#define RECOK (char)0
#define TCERR (char)1
#define SHADOW (char)2
-static size_t topreclen; /* toprec length */
-static char *toprec; /* Additional record specified by cgetset() */
-static int gottoprec; /* Flag indicating retrieval of toprecord */
+static size_t topreclen; /* toprec length */
+static char *toprec; /* Additional record specified by cgetset() */
+static int gottoprec; /* Flag indicating retrieval of toprecord */
/*
* Cgetset() allows the addition of a user specified buffer to be added to the
@@ -149,20 +144,20 @@ static int gottoprec; /* Flag indicating retrieval of toprecord */
static int
_nc_cgetset(const char *ent)
{
- if (ent == 0) {
- FreeIfNeeded(toprec);
- toprec = 0;
- topreclen = 0;
- return (0);
- }
- topreclen = strlen(ent);
- if ((toprec = typeMalloc(char, topreclen + 1)) == 0) {
- errno = ENOMEM;
- return (-1);
- }
- gottoprec = 0;
- (void)strcpy(toprec, ent);
+ if (ent == 0) {
+ FreeIfNeeded(toprec);
+ toprec = 0;
+ topreclen = 0;
return (0);
+ }
+ topreclen = strlen(ent);
+ if ((toprec = typeMalloc(char, topreclen + 1)) == 0) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ gottoprec = 0;
+ (void) strcpy(toprec, ent);
+ return (0);
}
/*
@@ -180,43 +175,43 @@ _nc_cgetset(const char *ent)
static char *
_nc_cgetcap(char *buf, const char *cap, int type)
{
- register const char *cp;
- register char *bp;
+ register const char *cp;
+ register char *bp;
- bp = buf;
+ bp = buf;
+ for (;;) {
+ /*
+ * Skip past the current capability field - it's either the
+ * name field if this is the first time through the loop, or
+ * the remainder of a field whose name failed to match cap.
+ */
for (;;) {
- /*
- * Skip past the current capability field - it's either the
- * name field if this is the first time through the loop, or
- * the remainder of a field whose name failed to match cap.
- */
- for (;;) {
- if (*bp == '\0')
- return (0);
- else if (*bp++ == ':')
- break;
- }
+ if (*bp == '\0')
+ return (0);
+ else if (*bp++ == ':')
+ break;
+ }
- /*
- * Try to match (cap, type) in buf.
- */
- for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++)
- continue;
- if (*cp != '\0')
- continue;
- if (*bp == '@')
- return (0);
- if (type == ':') {
- if (*bp != '\0' && *bp != ':')
- continue;
- return(bp);
- }
- if (*bp != type)
- continue;
- bp++;
- return (*bp == '@' ? 0 : bp);
+ /*
+ * Try to match (cap, type) in buf.
+ */
+ for (cp = cap; *cp == *bp && *bp != '\0'; cp++, bp++)
+ continue;
+ if (*cp != '\0')
+ continue;
+ if (*bp == '@')
+ return (0);
+ if (type == ':') {
+ if (*bp != '\0' && *bp != ':')
+ continue;
+ return (bp);
}
- /* NOTREACHED */
+ if (*bp != type)
+ continue;
+ bp++;
+ return (*bp == '@' ? 0 : bp);
+ }
+ /* NOTREACHED */
}
/*
@@ -236,9 +231,9 @@ _nc_cgetcap(char *buf, const char *cap, int type)
static int
_nc_cgetent(char **buf, int *oline, char **db_array, const char *name)
{
- unsigned int dummy;
+ unsigned dummy;
- return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0));
+ return (_nc_getent(buf, &dummy, oline, 0, db_array, -1, name, 0, 0));
}
/*
@@ -262,327 +257,327 @@ _nc_cgetent(char **buf, int *oline, char **db_array, const char *name)
#define DOALLOC(size) typeRealloc(char, size, record)
static int
_nc_getent(
- char **cap, /* termcap-content */
- unsigned int *len, /* length, needed for recursion */
- int *beginning, /* line-number at match */
- int in_array, /* index in 'db_array[] */
- char **db_array, /* list of files to search */
- int fd,
- const char *name,
- int depth,
- char *nfield)
+ char **cap, /* termcap-content */
+ unsigned *len, /* length, needed for recursion */
+ int *beginning, /* line-number at match */
+ int in_array, /* index in 'db_array[] */
+ char **db_array, /* list of files to search */
+ int fd,
+ const char *name,
+ int depth,
+ char *nfield)
{
- register char *r_end, *rp;
- int myfd = FALSE;
- char *record = 0;
- int tc_not_resolved;
- int current;
- int lineno;
-
- /*
- * Return with ``loop detected'' error if we've recurred more than
- * MAX_RECURSION times.
- */
- if (depth > MAX_RECURSION)
- return (TC_REF_LOOP);
+ register char *r_end, *rp;
+ int myfd = FALSE;
+ char *record = 0;
+ int tc_not_resolved;
+ int current;
+ int lineno;
+
+ /*
+ * Return with ``loop detected'' error if we've recurred more than
+ * MAX_RECURSION times.
+ */
+ if (depth > MAX_RECURSION)
+ return (TC_REF_LOOP);
+
+ /*
+ * Check if we have a top record from cgetset().
+ */
+ if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) {
+ if ((record = DOALLOC(topreclen + BFRAG)) == 0) {
+ errno = ENOMEM;
+ return (TC_SYS_ERR);
+ }
+ (void) strcpy(record, toprec);
+ rp = record + topreclen + 1;
+ r_end = rp + BFRAG;
+ current = in_array;
+ } else {
+ int foundit;
/*
- * Check if we have a top record from cgetset().
+ * Allocate first chunk of memory.
*/
- if (depth == 0 && toprec != 0 && _nc_cgetmatch(toprec, name) == 0) {
- if ((record = DOALLOC(topreclen + BFRAG)) == 0) {
- errno = ENOMEM;
- return (TC_SYS_ERR);
- }
- (void)strcpy(record, toprec);
- rp = record + topreclen + 1;
- r_end = rp + BFRAG;
- current = in_array;
- } else {
- int foundit;
-
- /*
- * Allocate first chunk of memory.
- */
- if ((record = DOALLOC(BFRAG)) == 0) {
- errno = ENOMEM;
- return (TC_SYS_ERR);
- }
- rp = r_end = record + BFRAG;
- foundit = FALSE;
-
- /*
- * Loop through database array until finding the record.
- */
- for (current = in_array; db_array[current] != 0; current++) {
- int eof = FALSE;
-
- /*
- * Open database if not already open.
- */
- if (fd >= 0) {
- (void)lseek(fd, (off_t)0, SEEK_SET);
- } else if ((_nc_access(db_array[current], R_OK) < 0)
- || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
- /* No error on unfound file. */
- if (errno == ENOENT)
- continue;
- free(record);
- return (TC_SYS_ERR);
- } else {
- myfd = TRUE;
- }
- lineno = 0;
-
- /*
- * Find the requested capability record ...
- */
- {
- char buf[2048];
- register char *b_end = buf;
- register char *bp = buf;
- register int c;
-
- /*
- * Loop invariants:
- * There is always room for one more character in record.
- * R_end always points just past end of record.
- * Rp always points just past last character in record.
- * B_end always points just past last character in buf.
- * Bp always points at next character in buf.
- */
-
- for (;;) {
- int first = lineno + 1;
-
- /*
- * Read in a line implementing (\, newline)
- * line continuation.
- */
- rp = record;
- for (;;) {
- if (bp >= b_end) {
- int n;
-
- n = read(fd, buf, sizeof(buf));
- if (n <= 0) {
- if (myfd)
- (void)close(fd);
- if (n < 0) {
- free(record);
- return (TC_SYS_ERR);
- }
- fd = -1;
- eof = TRUE;
- break;
- }
- b_end = buf+n;
- bp = buf;
- }
-
- c = *bp++;
- if (c == '\n') {
- lineno++;
- if (rp == record || *(rp-1) != '\\')
- break;
- }
- *rp++ = c;
-
- /*
- * Enforce loop invariant: if no room
- * left in record buffer, try to get
- * some more.
- */
- if (rp >= r_end) {
- unsigned int pos;
- size_t newsize;
-
- pos = rp - record;
- newsize = r_end - record + BFRAG;
- record = DOALLOC(newsize);
- if (record == 0) {
- if (myfd)
- (void)close(fd);
- errno = ENOMEM;
- return (TC_SYS_ERR);
- }
- r_end = record + newsize;
- rp = record + pos;
- }
- }
- /* loop invariant lets us do this */
- *rp++ = '\0';
-
- /*
- * If encountered eof check next file.
- */
- if (eof)
- break;
-
- /*
- * Toss blank lines and comments.
- */
- if (*record == '\0' || *record == '#')
- continue;
-
- /*
- * See if this is the record we want ...
- */
- if (_nc_cgetmatch(record, name) == 0
- && (nfield == 0
- || !_nc_nfcmp(nfield, record))) {
- foundit = TRUE;
- *beginning = first;
- break; /* found it! */
- }
- }
- }
- if (foundit)
- break;
- }
-
- if (!foundit)
- return (TC_NOT_FOUND);
+ if ((record = DOALLOC(BFRAG)) == 0) {
+ errno = ENOMEM;
+ return (TC_SYS_ERR);
}
+ rp = r_end = record + BFRAG;
+ foundit = FALSE;
/*
- * Got the capability record, but now we have to expand all tc=name
- * references in it ...
+ * Loop through database array until finding the record.
*/
- {
- register char *newicap, *s;
- register int newilen;
- unsigned int ilen;
- int diff, iret, tclen, oline;
- char *icap, *scan, *tc, *tcstart, *tcend;
+ for (current = in_array; db_array[current] != 0; current++) {
+ int eof = FALSE;
+
+ /*
+ * Open database if not already open.
+ */
+ if (fd >= 0) {
+ (void) lseek(fd, (off_t) 0, SEEK_SET);
+ } else if ((_nc_access(db_array[current], R_OK) < 0)
+ || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
+ /* No error on unfound file. */
+ if (errno == ENOENT)
+ continue;
+ free(record);
+ return (TC_SYS_ERR);
+ } else {
+ myfd = TRUE;
+ }
+ lineno = 0;
+
+ /*
+ * Find the requested capability record ...
+ */
+ {
+ char buf[2048];
+ register char *b_end = buf;
+ register char *bp = buf;
+ register int c;
/*
* Loop invariants:
- * There is room for one more character in record.
- * R_end points just past end of record.
- * Rp points just past last character in record.
- * Scan points at remainder of record that needs to be
- * scanned for tc=name constructs.
+ * There is always room for one more character in record.
+ * R_end always points just past end of record.
+ * Rp always points just past last character in record.
+ * B_end always points just past last character in buf.
+ * Bp always points at next character in buf.
*/
- scan = record;
- tc_not_resolved = FALSE;
- for (;;) {
- if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0)
- break;
- /*
- * Find end of tc=name and stomp on the trailing `:'
- * (if present) so we can use it to call ourselves.
- */
- s = tc;
- while (*s != '\0') {
- if (*s++ == ':') {
- *(s - 1) = '\0';
- break;
- }
- }
- tcstart = tc - 3;
- tclen = s - tcstart;
- tcend = s;
-
- iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd, tc, depth+1, 0);
- newicap = icap; /* Put into a register. */
- newilen = ilen;
- if (iret != TC_SUCCESS) {
- /* an error */
- if (iret < TC_NOT_FOUND) {
- if (myfd)
- (void)close(fd);
- free(record);
- return (iret);
- }
- if (iret == TC_UNRESOLVED)
- tc_not_resolved = TRUE;
- /* couldn't resolve tc */
- if (iret == TC_NOT_FOUND) {
- *(s - 1) = ':';
- scan = s - 1;
- tc_not_resolved = TRUE;
- continue;
+ for (;;) {
+ int first = lineno + 1;
+
+ /*
+ * Read in a line implementing (\, newline)
+ * line continuation.
+ */
+ rp = record;
+ for (;;) {
+ if (bp >= b_end) {
+ int n;
+
+ n = read(fd, buf, sizeof(buf));
+ if (n <= 0) {
+ if (myfd)
+ (void) close(fd);
+ if (n < 0) {
+ free(record);
+ return (TC_SYS_ERR);
}
+ fd = -1;
+ eof = TRUE;
+ break;
+ }
+ b_end = buf + n;
+ bp = buf;
}
- /* not interested in name field of tc'ed record */
- s = newicap;
- while (*s != '\0' && *s++ != ':')
- ;
- newilen -= s - newicap;
- newicap = s;
-
- /* make sure interpolated record is `:'-terminated */
- s += newilen;
- if (*(s-1) != ':') {
- *s = ':'; /* overwrite NUL with : */
- newilen++;
+ c = *bp++;
+ if (c == '\n') {
+ lineno++;
+ if (rp == record || *(rp - 1) != '\\')
+ break;
}
+ *rp++ = c;
/*
- * Make sure there's enough room to insert the
- * new record.
+ * Enforce loop invariant: if no room
+ * left in record buffer, try to get
+ * some more.
*/
- diff = newilen - tclen;
- if (diff >= r_end - rp) {
- unsigned int pos, tcpos, tcposend;
- size_t newsize;
-
- pos = rp - record;
- newsize = r_end - record + diff + BFRAG;
- tcpos = tcstart - record;
- tcposend = tcend - record;
- record = DOALLOC(newsize);
- if (record == 0) {
- if (myfd)
- (void)close(fd);
- free(icap);
- errno = ENOMEM;
- return (TC_SYS_ERR);
- }
- r_end = record + newsize;
- rp = record + pos;
- tcstart = record + tcpos;
- tcend = record + tcposend;
+ if (rp >= r_end) {
+ unsigned pos;
+ size_t newsize;
+
+ pos = rp - record;
+ newsize = r_end - record + BFRAG;
+ record = DOALLOC(newsize);
+ if (record == 0) {
+ if (myfd)
+ (void) close(fd);
+ errno = ENOMEM;
+ return (TC_SYS_ERR);
+ }
+ r_end = record + newsize;
+ rp = record + pos;
}
+ }
+ /* loop invariant lets us do this */
+ *rp++ = '\0';
+
+ /*
+ * If encountered eof check next file.
+ */
+ if (eof)
+ break;
- /*
- * Insert tc'ed record into our record.
- */
- s = tcstart + newilen;
- memmove(s, tcend, (size_t)(rp - tcend));
- memmove(tcstart, newicap, (size_t)newilen);
- rp += diff;
- free(icap);
+ /*
+ * Toss blank lines and comments.
+ */
+ if (*record == '\0' || *record == '#')
+ continue;
- /*
- * Start scan on `:' so next cgetcap works properly
- * (cgetcap always skips first field).
- */
- scan = s-1;
+ /*
+ * See if this is the record we want ...
+ */
+ if (_nc_cgetmatch(record, name) == 0
+ && (nfield == 0
+ || !_nc_nfcmp(nfield, record))) {
+ foundit = TRUE;
+ *beginning = first;
+ break; /* found it! */
+ }
}
+ }
+ if (foundit)
+ break;
}
+ if (!foundit)
+ return (TC_NOT_FOUND);
+ }
+
+ /*
+ * Got the capability record, but now we have to expand all tc=name
+ * references in it ...
+ */
+ {
+ register char *newicap, *s;
+ register int newilen;
+ unsigned ilen;
+ int diff, iret, tclen, oline;
+ char *icap, *scan, *tc, *tcstart, *tcend;
+
/*
- * Close file (if we opened it), give back any extra memory, and
- * return capability, length and success.
+ * Loop invariants:
+ * There is room for one more character in record.
+ * R_end points just past end of record.
+ * Rp points just past last character in record.
+ * Scan points at remainder of record that needs to be
+ * scanned for tc=name constructs.
*/
- if (myfd)
- (void)close(fd);
- *len = rp - record - 1; /* don't count NUL */
- if (r_end > rp) {
- if ((record = DOALLOC((size_t)(rp - record))) == 0) {
- errno = ENOMEM;
- return (TC_SYS_ERR);
+ scan = record;
+ tc_not_resolved = FALSE;
+ for (;;) {
+ if ((tc = _nc_cgetcap(scan, "tc", '=')) == 0)
+ break;
+
+ /*
+ * Find end of tc=name and stomp on the trailing `:'
+ * (if present) so we can use it to call ourselves.
+ */
+ s = tc;
+ while (*s != '\0') {
+ if (*s++ == ':') {
+ *(s - 1) = '\0';
+ break;
+ }
+ }
+ tcstart = tc - 3;
+ tclen = s - tcstart;
+ tcend = s;
+
+ iret = _nc_getent(&icap, &ilen, &oline, current, db_array, fd,
+ tc, depth + 1, 0);
+ newicap = icap; /* Put into a register. */
+ newilen = ilen;
+ if (iret != TC_SUCCESS) {
+ /* an error */
+ if (iret < TC_NOT_FOUND) {
+ if (myfd)
+ (void) close(fd);
+ free(record);
+ return (iret);
}
+ if (iret == TC_UNRESOLVED)
+ tc_not_resolved = TRUE;
+ /* couldn't resolve tc */
+ if (iret == TC_NOT_FOUND) {
+ *(s - 1) = ':';
+ scan = s - 1;
+ tc_not_resolved = TRUE;
+ continue;
+ }
+ }
+
+ /* not interested in name field of tc'ed record */
+ s = newicap;
+ while (*s != '\0' && *s++ != ':') ;
+ newilen -= s - newicap;
+ newicap = s;
+
+ /* make sure interpolated record is `:'-terminated */
+ s += newilen;
+ if (*(s - 1) != ':') {
+ *s = ':'; /* overwrite NUL with : */
+ newilen++;
+ }
+
+ /*
+ * Make sure there's enough room to insert the
+ * new record.
+ */
+ diff = newilen - tclen;
+ if (diff >= r_end - rp) {
+ unsigned pos, tcpos, tcposend;
+ size_t newsize;
+
+ pos = rp - record;
+ newsize = r_end - record + diff + BFRAG;
+ tcpos = tcstart - record;
+ tcposend = tcend - record;
+ record = DOALLOC(newsize);
+ if (record == 0) {
+ if (myfd)
+ (void) close(fd);
+ free(icap);
+ errno = ENOMEM;
+ return (TC_SYS_ERR);
+ }
+ r_end = record + newsize;
+ rp = record + pos;
+ tcstart = record + tcpos;
+ tcend = record + tcposend;
+ }
+
+ /*
+ * Insert tc'ed record into our record.
+ */
+ s = tcstart + newilen;
+ memmove(s, tcend, (size_t) (rp - tcend));
+ memmove(tcstart, newicap, (size_t) newilen);
+ rp += diff;
+ free(icap);
+
+ /*
+ * Start scan on `:' so next cgetcap works properly
+ * (cgetcap always skips first field).
+ */
+ scan = s - 1;
+ }
+ }
+
+ /*
+ * Close file (if we opened it), give back any extra memory, and
+ * return capability, length and success.
+ */
+ if (myfd)
+ (void) close(fd);
+ *len = rp - record - 1; /* don't count NUL */
+ if (r_end > rp) {
+ if ((record = DOALLOC((size_t) (rp - record))) == 0) {
+ errno = ENOMEM;
+ return (TC_SYS_ERR);
}
+ }
- *cap = record;
- if (tc_not_resolved)
- return (TC_UNRESOLVED);
- return (current);
+ *cap = record;
+ if (tc_not_resolved)
+ return (TC_UNRESOLVED);
+ return (current);
}
/*
@@ -592,40 +587,40 @@ _nc_getent(
static int
_nc_cgetmatch(char *buf, const char *name)
{
- register const char *np;
- register char *bp;
-
+ register const char *np;
+ register char *bp;
+
+ /*
+ * Start search at beginning of record.
+ */
+ bp = buf;
+ for (;;) {
/*
- * Start search at beginning of record.
+ * Try to match a record name.
*/
- bp = buf;
+ np = name;
for (;;) {
- /*
- * Try to match a record name.
- */
- np = name;
- for (;;) {
- if (*np == '\0') {
- if (*bp == '|' || *bp == ':' || *bp == '\0')
- return (0);
- else
- break;
- } else if (*bp++ != *np++) {
- break;
- }
- }
+ if (*np == '\0') {
+ if (*bp == '|' || *bp == ':' || *bp == '\0')
+ return (0);
+ else
+ break;
+ } else if (*bp++ != *np++) {
+ break;
+ }
+ }
- /*
- * Match failed, skip to next name in record.
- */
- bp--; /* a '|' or ':' may have stopped the match */
- for (;;) {
- if (*bp == '\0' || *bp == ':')
- return (-1); /* match failed totally */
- else if (*bp++ == '|')
- break; /* found next name */
- }
+ /*
+ * Match failed, skip to next name in record.
+ */
+ bp--; /* a '|' or ':' may have stopped the match */
+ for (;;) {
+ if (*bp == '\0' || *bp == ':')
+ return (-1); /* match failed totally */
+ else if (*bp++ == '|')
+ break; /* found next name */
}
+ }
}
/*
@@ -634,18 +629,17 @@ _nc_cgetmatch(char *buf, const char *name)
static int
_nc_nfcmp(const char *nf, char *rec)
{
- char *cp, tmp;
- int ret;
+ char *cp, tmp;
+ int ret;
- for (cp = rec; *cp != ':'; cp++)
- ;
+ for (cp = rec; *cp != ':'; cp++) ;
- tmp = *(cp + 1);
- *(cp + 1) = '\0';
- ret = strcmp(nf, rec);
- *(cp + 1) = tmp;
+ tmp = *(cp + 1);
+ *(cp + 1) = '\0';
+ ret = strcmp(nf, rec);
+ *(cp + 1) = tmp;
- return (ret);
+ return (ret);
}
#endif /* HAVE_BSD_CGETENT */
@@ -706,63 +700,63 @@ static char *tbuf;
static char *
get_tc_token(char **srcp, int *endp)
{
- int ch;
- bool found = FALSE;
- char *s, *base;
- char *tok = 0;
-
- *endp = TRUE;
- for (s = base = *srcp; *s != '\0'; ) {
- ch = *s++;
- if (ch == '\\') {
- if (*s == '\0') {
- break;
- } else if (*s++ == '\n') {
- while (isspace(*s))
- s++;
- } else {
- found = TRUE;
- }
- } else if (ch == ':') {
- if (found) {
- tok = base;
- s[-1] = '\0';
- *srcp = s;
- *endp = FALSE;
- break;
- }
- base = s;
- } else if (isgraph(ch)) {
- found = TRUE;
- }
- }
-
- /* malformed entry may end without a ':' */
- if (tok == 0 && found) {
+ int ch;
+ bool found = FALSE;
+ char *s, *base;
+ char *tok = 0;
+
+ *endp = TRUE;
+ for (s = base = *srcp; *s != '\0';) {
+ ch = *s++;
+ if (ch == '\\') {
+ if (*s == '\0') {
+ break;
+ } else if (*s++ == '\n') {
+ while (isspace(*s))
+ s++;
+ } else {
+ found = TRUE;
+ }
+ } else if (ch == ':') {
+ if (found) {
tok = base;
+ s[-1] = '\0';
+ *srcp = s;
+ *endp = FALSE;
+ break;
+ }
+ base = s;
+ } else if (isgraph(ch)) {
+ found = TRUE;
}
+ }
+
+ /* malformed entry may end without a ':' */
+ if (tok == 0 && found) {
+ tok = base;
+ }
- return tok;
+ return tok;
}
static char *
copy_tc_token(char *dst, const char *src, size_t len)
{
- int ch;
+ int ch;
- while ((ch = *src++) != '\0') {
- if (ch == '\\' && *src == '\n') {
- while (isspace(*src))
- src++;
- continue;
- }
- if (--len == 0) {
- dst = 0;
- break;
- }
- *dst++ = ch;
+ while ((ch = *src++) != '\0') {
+ if (ch == '\\' && *src == '\n') {
+ while (isspace(*src))
+ src++;
+ continue;
+ }
+ if (--len == 0) {
+ dst = 0;
+ break;
}
- return dst;
+ *dst++ = ch;
+ }
+ return dst;
}
/*
@@ -771,127 +765,126 @@ copy_tc_token(char *dst, const char *src, size_t len)
static int
_nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
{
- static char *the_source;
-
- register char *p;
- register char *cp;
- char *dummy;
- char **fname;
- char *home;
- int i;
- char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
- char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
- char **pvec; /* holds usable tail of path vector */
- char *termpath;
-
- fname = pathvec;
- pvec = pathvec;
- tbuf = bp;
- p = pathbuf;
- cp = getenv("TERMCAP");
-
- /*
- * TERMCAP can have one of two things in it. It can be the name of a
- * file to use instead of /etc/termcap. In this case it better start
- * with a "/". Or it can be an entry to use so we don't have to read
- * the file. In this case it has to already have the newlines crunched
- * out. If TERMCAP does not hold a file name then a path of names is
- * searched instead. The path is found in the TERMPATH variable, or
- * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
- */
- if (!is_pathname(cp)) { /* no TERMCAP or it holds an entry */
- if ((termpath = getenv("TERMPATH")) != 0) {
- strncpy(pathbuf, termpath, PBUFSIZ - 1);
- } else {
- if ((home = getenv("HOME")) != 0 &&
- strlen(home) < PBUFSIZ) { /* setup path */
- p += strlen(home); /* path, looking in */
- strcpy(pathbuf, home); /* $HOME first */
- *p++ = '/';
- } /* if no $HOME look in current directory */
+ static char *the_source;
+
+ register char *p;
+ register char *cp;
+ char *dummy;
+ char **fname;
+ char *home;
+ int i;
+ char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
+ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
+ char **pvec; /* holds usable tail of path vector */
+ char *termpath;
+
+ fname = pathvec;
+ pvec = pathvec;
+ tbuf = bp;
+ p = pathbuf;
+ cp = getenv("TERMCAP");
+
+ /*
+ * TERMCAP can have one of two things in it. It can be the name of a file
+ * to use instead of /etc/termcap. In this case it better start with a
+ * "/". Or it can be an entry to use so we don't have to read the file.
+ * In this case it has to already have the newlines crunched out. If
+ * TERMCAP does not hold a file name then a path of names is searched
+ * instead. The path is found in the TERMPATH variable, or becomes
+ * "$HOME/.termcap /etc/termcap" if no TERMPATH exists.
+ */
+ if (!is_pathname(cp)) { /* no TERMCAP or it holds an entry */
+ if ((termpath = getenv("TERMPATH")) != 0) {
+ strncpy(pathbuf, termpath, PBUFSIZ - 1);
+ } else {
+ if ((home = getenv("HOME")) != 0 &&
+ strlen(home) < PBUFSIZ) { /* setup path */
+ p += strlen(home); /* path, looking in */
+ strcpy(pathbuf, home); /* $HOME first */
+ *p++ = '/';
+ } /* if no $HOME look in current directory */
#define MY_PATH_DEF ".termcap /etc/termcap /usr/share/misc/termcap"
- strncpy(p, MY_PATH_DEF, (size_t)(PBUFSIZ - (p - pathbuf) - 1));
- }
+ strncpy(p, MY_PATH_DEF, (size_t) (PBUFSIZ - (p - pathbuf) - 1));
}
- else /* user-defined name in TERMCAP */
- strncpy(pathbuf, cp, PBUFSIZ - 1); /* still can be tokenized */
- pathbuf[PBUFSIZ - 1] = '\0';
-
- *fname++ = pathbuf; /* tokenize path into vector of names */
- while (*++p) {
- if (*p == ' ' || *p == ':') {
- *p = '\0';
- while (*++p)
- if (*p != ' ' && *p != ':')
- break;
- if (*p == '\0')
- break;
- *fname++ = p;
- if (fname >= pathvec + PVECSIZ) {
- fname--;
- break;
- }
- }
+ } else /* user-defined name in TERMCAP */
+ strncpy(pathbuf, cp, PBUFSIZ - 1); /* still can be tokenized */
+ pathbuf[PBUFSIZ - 1] = '\0';
+
+ *fname++ = pathbuf; /* tokenize path into vector of names */
+ while (*++p) {
+ if (*p == ' ' || *p == ':') {
+ *p = '\0';
+ while (*++p)
+ if (*p != ' ' && *p != ':')
+ break;
+ if (*p == '\0')
+ break;
+ *fname++ = p;
+ if (fname >= pathvec + PVECSIZ) {
+ fname--;
+ break;
+ }
}
- *fname = 0; /* mark end of vector */
- if (is_pathname(cp)) {
- if (_nc_cgetset(cp) < 0) {
- return(TC_SYS_ERR);
- }
+ }
+ *fname = 0; /* mark end of vector */
+ if (is_pathname(cp)) {
+ if (_nc_cgetset(cp) < 0) {
+ return (TC_SYS_ERR);
}
-
- i = _nc_cgetent(&dummy, lineno, pathvec, name);
-
- /* ncurses' termcap-parsing routines cannot handle multiple adjacent
- * empty fields, and mistakenly use the last valid cap entry instead of
- * the first (breaks tc= includes)
- */
- if (i >= 0) {
- char *pd, *ps, *tok;
- int endflag = FALSE;
- char *list[1023];
- size_t n, count = 0;
-
- pd = bp;
- ps = dummy;
- while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) {
- bool ignore = FALSE;
-
- for (n = 1; n < count; n++) {
- char *s = list[n];
- if (s[0] == tok[0]
- && s[1] == tok[1]) {
- ignore = TRUE;
- break;
- }
- }
- if (ignore != TRUE) {
- list[count++] = tok;
- pd = copy_tc_token(pd, tok, TBUFSIZ - (2+pd-bp));
- if (pd == 0) {
- i = -1;
- break;
- }
- *pd++ = ':';
- *pd = '\0';
- }
+ }
+
+ i = _nc_cgetent(&dummy, lineno, pathvec, name);
+
+ /* ncurses' termcap-parsing routines cannot handle multiple adjacent
+ * empty fields, and mistakenly use the last valid cap entry instead of
+ * the first (breaks tc= includes)
+ */
+ if (i >= 0) {
+ char *pd, *ps, *tok;
+ int endflag = FALSE;
+ char *list[1023];
+ size_t n, count = 0;
+
+ pd = bp;
+ ps = dummy;
+ while (!endflag && (tok = get_tc_token(&ps, &endflag)) != 0) {
+ bool ignore = FALSE;
+
+ for (n = 1; n < count; n++) {
+ char *s = list[n];
+ if (s[0] == tok[0]
+ && s[1] == tok[1]) {
+ ignore = TRUE;
+ break;
}
+ }
+ if (ignore != TRUE) {
+ list[count++] = tok;
+ pd = copy_tc_token(pd, tok, TBUFSIZ - (2 + pd - bp));
+ if (pd == 0) {
+ i = -1;
+ break;
+ }
+ *pd++ = ':';
+ *pd = '\0';
+ }
}
-
- FreeIfNeeded(dummy);
- FreeIfNeeded(the_source);
- the_source = 0;
-
- /* This is not related to the BSD cgetent(), but to fake up a suitable
- * filename for ncurses' error reporting. (If we are not using BSD
- * cgetent, then it is the actual filename).
- */
- if (i >= 0) {
- if ((the_source = strdup(pathvec[i])) != 0)
- *sourcename = the_source;
- }
-
- return(i);
+ }
+
+ FreeIfNeeded(dummy);
+ FreeIfNeeded(the_source);
+ the_source = 0;
+
+ /* This is not related to the BSD cgetent(), but to fake up a suitable
+ * filename for ncurses' error reporting. (If we are not using BSD
+ * cgetent, then it is the actual filename).
+ */
+ if (i >= 0) {
+ if ((the_source = strdup(pathvec[i])) != 0)
+ *sourcename = the_source;
+ }
+
+ return (i);
}
#endif /* USE_BSD_TGETENT */
#endif /* USE_GETCAP */
@@ -903,214 +896,207 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name)
* a right to open the file.
*/
#if !USE_GETCAP
-static int add_tc(char *termpaths[], char *path, int count)
+static int
+add_tc(char *termpaths[], char *path, int count)
{
- if (count < MAXPATHS
- && _nc_access(path, R_OK) == 0)
- termpaths[count++] = path;
- termpaths[count] = 0;
- return count;
+ if (count < MAXPATHS
+ && _nc_access(path, R_OK) == 0)
+ termpaths[count++] = path;
+ termpaths[count] = 0;
+ return count;
}
#define ADD_TC(path, count) filecount = add_tc(termpaths, path, count)
#endif /* !USE_GETCAP */
-int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp)
+int
+_nc_read_termcap_entry(const char *const tn, TERMTYPE * const tp)
{
- int found = FALSE;
- ENTRY *ep;
+ int found = FALSE;
+ ENTRY *ep;
#if USE_GETCAP_CACHE
- char cwd_buf[PATH_MAX];
+ char cwd_buf[PATH_MAX];
#endif
#if USE_GETCAP
- char tc[TBUFSIZ];
- static char *source;
- static int lineno;
-
+ char *p, tc[TBUFSIZ];
+ static char *source;
+ static int lineno;
+
+ if ((p = getenv("TERMCAP")) != 0
+ && !is_pathname(p) && _nc_name_match(p, tn, "|:")) {
+ /* TERMCAP holds a termcap entry */
+ strncpy(tc, p, sizeof(tc) - 1);
+ tc[sizeof(tc) - 1] = '\0';
+ _nc_set_source("TERMCAP");
+ } else {
/* we're using getcap(3) */
if (_nc_tgetent(tc, &source, &lineno, tn) < 0)
- return (ERR);
+ return (ERR);
_nc_curr_line = lineno;
_nc_set_source(source);
- _nc_read_entry_source((FILE *)0, tc, FALSE, FALSE, NULLHOOK);
+ }
+ _nc_read_entry_source((FILE *) 0, tc, FALSE, FALSE, NULLHOOK);
#else
- /*
- * Here is what the 4.4BSD termcap(3) page prescribes:
- *
- * It will look in the environment for a TERMCAP variable. If found,
- * and the value does not begin with a slash, and the terminal type
- * name is the same as the environment string TERM, the TERMCAP string
- * is used instead of reading a termcap file. If it does begin with a
- * slash, the string is used as a path name of the termcap file to
- * search. If TERMCAP does not begin with a slash and name is
- * different from TERM, tgetent() searches the files $HOME/.termcap and
- * /usr/share/misc/termcap, in that order, unless the environment
- * variable TERMPATH exists, in which case it specifies a list of file
- * pathnames (separated by spaces or colons) to be searched instead.
- *
- * It goes on to state:
- *
- * Whenever multiple files are searched and a tc field occurs in the
- * requested entry, the entry it names must be found in the same file
- * or one of the succeeding files.
- *
- * However, this restriction is relaxed in ncurses; tc references to
- * previous files are permitted.
- *
- * This routine returns 1 if an entry is found, 0 if not found, and -1
- * if the database is not accessible.
- */
- FILE *fp;
- char *tc, *termpaths[MAXPATHS];
- int filecount = 0;
- bool use_buffer = FALSE;
- char tc_buf[1024];
- char pathbuf[PATH_MAX];
-
- termpaths[filecount] = 0;
- if ((tc = getenv("TERMCAP")) != 0)
- {
- if (is_pathname(tc)) /* interpret as a filename */
- {
- ADD_TC(tc, 0);
- }
- else if (_nc_name_match(tc, tn, "|:")) /* treat as a capability file */
- {
- use_buffer = TRUE;
- (void) sprintf(tc_buf, "%.*s\n", (int)sizeof(tc_buf)-2, tc);
- }
- else if ((tc = getenv("TERMPATH")) != 0)
- {
- char *cp;
-
- for (cp = tc; *cp; cp++)
- {
- if (*cp == ':')
- *cp = '\0';
- else if (cp == tc || cp[-1] == '\0')
- {
- ADD_TC(cp, filecount);
- }
- }
+ /*
+ * Here is what the 4.4BSD termcap(3) page prescribes:
+ *
+ * It will look in the environment for a TERMCAP variable. If found, and
+ * the value does not begin with a slash, and the terminal type name is the
+ * same as the environment string TERM, the TERMCAP string is used instead
+ * of reading a termcap file. If it does begin with a slash, the string is
+ * used as a path name of the termcap file to search. If TERMCAP does not
+ * begin with a slash and name is different from TERM, tgetent() searches
+ * the files $HOME/.termcap and /usr/share/misc/termcap, in that order,
+ * unless the environment variable TERMPATH exists, in which case it
+ * specifies a list of file pathnames (separated by spaces or colons) to be
+ * searched instead.
+ *
+ * It goes on to state:
+ *
+ * Whenever multiple files are searched and a tc field occurs in the
+ * requested entry, the entry it names must be found in the same file or
+ * one of the succeeding files.
+ *
+ * However, this restriction is relaxed in ncurses; tc references to
+ * previous files are permitted.
+ *
+ * This routine returns 1 if an entry is found, 0 if not found, and -1 if
+ * the database is not accessible.
+ */
+ FILE *fp;
+ char *tc, *termpaths[MAXPATHS];
+ int filecount = 0;
+ bool use_buffer = FALSE;
+ char tc_buf[1024];
+ char pathbuf[PATH_MAX];
+
+ termpaths[filecount] = 0;
+ if ((tc = getenv("TERMCAP")) != 0) {
+ if (is_pathname(tc)) { /* interpret as a filename */
+ ADD_TC(tc, 0);
+ } else if (_nc_name_match(tc, tn, "|:")) { /* treat as a capability file */
+ use_buffer = TRUE;
+ (void) sprintf(tc_buf, "%.*s\n", (int) sizeof(tc_buf) - 2, tc);
+ } else if ((tc = getenv("TERMPATH")) != 0) {
+ char *cp;
+
+ for (cp = tc; *cp; cp++) {
+ if (*cp == ':')
+ *cp = '\0';
+ else if (cp == tc || cp[-1] == '\0') {
+ ADD_TC(cp, filecount);
}
+ }
}
- else /* normal case */
- {
- char envhome[PATH_MAX], *h;
+ } else { /* normal case */
+ char envhome[PATH_MAX], *h;
- filecount = 0;
+ filecount = 0;
- /*
- * Probably /etc/termcap is a symlink to /usr/share/misc/termcap.
- * Avoid reading the same file twice.
- */
- if (_nc_access("/etc/termcap", F_OK) == 0)
- ADD_TC("/etc/termcap", filecount);
- else
- ADD_TC("/usr/share/misc/termcap", filecount);
+ /*
+ * Probably /etc/termcap is a symlink to /usr/share/misc/termcap.
+ * Avoid reading the same file twice.
+ */
+ if (_nc_access("/etc/termcap", F_OK) == 0)
+ ADD_TC("/etc/termcap", filecount);
+ else
+ ADD_TC("/usr/share/misc/termcap", filecount);
#define PRIVATE_CAP "%s/.termcap"
- if ((h = getenv("HOME")) != NULL
- && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX)
- {
- /* user's .termcap, if any, should override it */
- (void) strcpy(envhome, h);
- (void) sprintf(pathbuf, PRIVATE_CAP, envhome);
- ADD_TC(pathbuf, filecount);
- }
+ if ((h = getenv("HOME")) != NULL
+ && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) {
+ /* user's .termcap, if any, should override it */
+ (void) strcpy(envhome, h);
+ (void) sprintf(pathbuf, PRIVATE_CAP, envhome);
+ ADD_TC(pathbuf, filecount);
}
+ }
- /* parse the sources */
- if (use_buffer)
- {
- _nc_set_source("TERMCAP");
+ /* parse the sources */
+ if (use_buffer) {
+ _nc_set_source("TERMCAP");
- /*
- * We don't suppress warning messages here. The presumption is
- * that since it's just a single entry, they won't be a pain.
- */
- _nc_read_entry_source((FILE *)0, tc_buf, FALSE, FALSE, NULLHOOK);
- } else {
- int i;
+ /*
+ * We don't suppress warning messages here. The presumption is
+ * that since it's just a single entry, they won't be a pain.
+ */
+ _nc_read_entry_source((FILE *) 0, tc_buf, FALSE, FALSE, NULLHOOK);
+ } else {
+ int i;
- for (i = 0; i < filecount; i++) {
+ for (i = 0; i < filecount; i++) {
- T(("Looking for %s in %s", tn, termpaths[i]));
- if ((fp = fopen(termpaths[i], "r")) != (FILE *)0)
- {
- _nc_set_source(termpaths[i]);
+ T(("Looking for %s in %s", tn, termpaths[i]));
+ if ((fp = fopen(termpaths[i], "r")) != (FILE *) 0) {
+ _nc_set_source(termpaths[i]);
- /*
- * Suppress warning messages. Otherwise you
- * get 400 lines of crap from archaic termcap
- * files as ncurses complains about all the
- * obsolete capabilities.
- */
- _nc_read_entry_source(fp, (char*)0, FALSE, TRUE, NULLHOOK);
+ /*
+ * Suppress warning messages. Otherwise you get 400 lines of
+ * crap from archaic termcap files as ncurses complains about
+ * all the obsolete capabilities.
+ */
+ _nc_read_entry_source(fp, (char *) 0, FALSE, TRUE, NULLHOOK);
- (void) fclose(fp);
- }
- }
+ (void) fclose(fp);
+ }
}
+ }
#endif /* USE_GETCAP */
- if (_nc_head == 0)
- return(ERR);
+ if (_nc_head == 0)
+ return (ERR);
- /* resolve all use references */
- _nc_resolve_uses();
+ /* resolve all use references */
+ _nc_resolve_uses(TRUE);
- /* find a terminal matching tn, if we can */
+ /* find a terminal matching tn, if we can */
#if USE_GETCAP_CACHE
- if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0)
- {
- _nc_set_writedir((char *)0); /* note: this does a chdir */
+ if (getcwd(cwd_buf, sizeof(cwd_buf)) != 0) {
+ _nc_set_writedir((char *) 0); /* note: this does a chdir */
#endif
- for_entry_list(ep) {
- if (_nc_name_match(ep->tterm.term_names, tn, "|:"))
- {
- /*
- * Make a local copy of the terminal
- * capabilities. Free all entry storage except
- * the string table for the loaded type (which
- * we disconnected from the list by NULLing out
- * ep->tterm.str_table above).
- */
- *tp = ep->tterm;
- ep->tterm.str_table = (char *)0;
-
- /*
- * OK, now try to write the type to user's
- * terminfo directory. Next time he loads
- * this, it will come through terminfo.
- *
- * Advantage: Second and subsequent fetches of
- * this entry will be very fast.
- *
- * Disadvantage: After the first time a
- * termcap type is loaded by its user, editing
- * it in the /etc/termcap file, or in TERMCAP,
- * or in a local ~/.termcap, will be
- * ineffective unless the terminfo entry is
- * explicitly removed.
- */
+ for_entry_list(ep) {
+ if (_nc_name_match(ep->tterm.term_names, tn, "|:")) {
+ /*
+ * Make a local copy of the terminal capabilities. Free all
+ * entry storage except the string table for the loaded type
+ * (which we disconnected from the list by NULLing out
+ * ep->tterm.str_table above).
+ */
+ *tp = ep->tterm;
+ ep->tterm.str_table = (char *) 0;
+
+ /*
+ * OK, now try to write the type to user's terminfo directory.
+ * Next time he loads this, it will come through terminfo.
+ *
+ * Advantage: Second and subsequent fetches of this entry will
+ * be very fast.
+ *
+ * Disadvantage: After the first time a termcap type is loaded
+ * by its user, editing it in the /etc/termcap file, or in
+ * TERMCAP, or in a local ~/.termcap, will be ineffective
+ * unless the terminfo entry is explicitly removed.
+ */
#if USE_GETCAP_CACHE
- (void) _nc_write_entry(tp);
+ (void) _nc_write_entry(tp);
#endif
- found = TRUE;
- break;
- }
- }
-#if USE_GETCAP_CACHE
- chdir(cwd_buf);
+ found = TRUE;
+ break;
+ }
}
+#if USE_GETCAP_CACHE
+ chdir(cwd_buf);
+ }
#endif
- _nc_free_entries(_nc_head);
- return(found);
+ _nc_free_entries(_nc_head);
+ return (found);
}
#else
-extern void _nc_read_termcap(void);
- void _nc_read_termcap(void) { }
-#endif /* PURE_TERMINFO */
+extern void _nc_read_termcap(void);
+void
+_nc_read_termcap(void)
+{
+}
+#endif /* PURE_TERMINFO */
diff --git a/contrib/ncurses/ncurses/tinfo/write_entry.c b/contrib/ncurses/ncurses/tinfo/write_entry.c
index 4829fa936d01..12aedd6e565c 100644
--- a/contrib/ncurses/ncurses/tinfo/write_entry.c
+++ b/contrib/ncurses/ncurses/tinfo/write_entry.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998,1999,2000 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 *
@@ -31,8 +31,6 @@
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
-
-
/*
* write_entry.c -- write a terminfo structure onto the file system
*/
@@ -51,28 +49,29 @@
#if 0
#define TRACE_OUT(p) DEBUG(2, p)
#else
-#define TRACE_OUT(p) /*nothing*/
+#define TRACE_OUT(p) /*nothing */
#endif
-MODULE_ID("$Id: write_entry.c,v 1.47 1999/07/10 20:29:22 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.52 2000/03/11 12:23:42 tom Exp $")
static int total_written;
static int write_object(FILE *, TERMTYPE *);
-static void write_file(char *filename, TERMTYPE *tp)
+static void
+write_file(char *filename, TERMTYPE * tp)
{
- FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
- if (fp == 0) {
- perror(filename);
- _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename);
- }
- DEBUG(1, ("Created %s", filename));
+ FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0;
+ if (fp == 0) {
+ perror(filename);
+ _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename);
+ }
+ DEBUG(1, ("Created %s", filename));
- if (write_object(fp, tp) == ERR) {
- _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
- }
- fclose(fp);
+ if (write_object(fp, tp) == ERR) {
+ _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename);
+ }
+ fclose(fp);
}
/*
@@ -80,36 +79,38 @@ static void write_file(char *filename, TERMTYPE *tp)
*
* Make a directory if it doesn't exist.
*/
-static int make_directory(const char *path)
+static int
+make_directory(const char *path)
{
-int rc;
-struct stat statbuf;
-char fullpath[PATH_MAX];
-const char *destination = _nc_tic_dir(0);
-
- if (path == destination || *path == '/') {
- if (strlen(path) + 1 > sizeof(fullpath))
- return(-1);
- (void)strcpy(fullpath, path);
- } else {
- if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath))
- return(-1);
- (void)sprintf(fullpath, "%s/%s", destination, path);
- }
+ int rc;
+ struct stat statbuf;
+ char fullpath[PATH_MAX];
+ const char *destination = _nc_tic_dir(0);
+
+ if (path == destination || *path == '/') {
+ if (strlen(path) + 1 > sizeof(fullpath))
+ return (-1);
+ (void) strcpy(fullpath, path);
+ } else {
+ if (strlen(destination) + strlen(path) + 2 > sizeof(fullpath))
+ return (-1);
+ (void) sprintf(fullpath, "%s/%s", destination, path);
+ }
- if ((rc = stat(path, &statbuf)) < 0) {
- rc = mkdir(path, 0777);
- } else {
- if (_nc_access(path, R_OK|W_OK|X_OK) < 0) {
- rc = -1; /* permission denied */
- } else if (!(S_ISDIR(statbuf.st_mode))) {
- rc = -1; /* not a directory */
- }
+ if ((rc = stat(path, &statbuf)) < 0) {
+ rc = mkdir(path, 0777);
+ } else {
+ if (_nc_access(path, R_OK | W_OK | X_OK) < 0) {
+ rc = -1; /* permission denied */
+ } else if (!(S_ISDIR(statbuf.st_mode))) {
+ rc = -1; /* not a directory */
}
- return rc;
+ }
+ return rc;
}
-void _nc_set_writedir(char *dir)
+void
+_nc_set_writedir(char *dir)
/* set the write directory for compiled entries */
{
const char *destination;
@@ -121,15 +122,14 @@ void _nc_set_writedir(char *dir)
(void) _nc_tic_dir(getenv("TERMINFO"));
destination = _nc_tic_dir(0);
- if (make_directory(destination) < 0)
- {
- char *home = _nc_home_terminfo();
+ if (make_directory(destination) < 0) {
+ char *home = _nc_home_terminfo();
if (home != 0) {
destination = home;
if (make_directory(destination) < 0)
_nc_err_abort("%s: permission denied (errno %d)",
- destination, errno);
+ destination, errno);
}
}
@@ -138,7 +138,7 @@ void _nc_set_writedir(char *dir)
* *once only* per run.
*/
if (chdir(_nc_tic_dir(destination)) < 0
- || getcwd(actual, sizeof(actual)) == 0)
+ || getcwd(actual, sizeof(actual)) == 0)
_nc_err_abort("%s: not a directory", destination);
_nc_keep_tic_dir(strdup(actual));
}
@@ -155,27 +155,28 @@ void _nc_set_writedir(char *dir)
*
*/
-static void check_writeable(int code)
+static void
+check_writeable(int code)
{
-static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-static bool verified[sizeof(dirnames)];
+ static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ static bool verified[sizeof(dirnames)];
-char dir[2];
-char *s;
+ char dir[2];
+ char *s;
- if (code == 0 || (s = strchr(dirnames, code)) == 0)
- _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
+ if (code == 0 || (s = strchr(dirnames, code)) == 0)
+ _nc_err_abort("Illegal terminfo subdirectory \"%c\"", code);
- if (verified[s-dirnames])
- return;
+ if (verified[s - dirnames])
+ return;
- dir[0] = code;
- dir[1] = '\0';
- if (make_directory(dir) < 0) {
- _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
- }
+ dir[0] = code;
+ dir[1] = '\0';
+ if (make_directory(dir) < 0) {
+ _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
+ }
- verified[s-dirnames] = TRUE;
+ verified[s - dirnames] = TRUE;
}
/*
@@ -200,163 +201,159 @@ char *s;
* _nc_curr_line is properly set before the write_entry() call.
*/
-void _nc_write_entry(TERMTYPE *const tp)
+void
+_nc_write_entry(TERMTYPE * const tp)
{
-struct stat statbuf;
-char name_list[MAX_TERMINFO_LENGTH];
-char *first_name, *other_names;
-char *ptr;
-char filename[PATH_MAX];
-char linkname[PATH_MAX];
+ struct stat statbuf;
+ char name_list[MAX_TERMINFO_LENGTH];
+ char *first_name, *other_names;
+ char *ptr;
+ char filename[PATH_MAX];
+ char linkname[PATH_MAX];
#if USE_SYMLINKS
-char symlinkname[PATH_MAX];
+ char symlinkname[PATH_MAX];
#endif /* USE_SYMLINKS */
-static int call_count;
-static time_t start_time; /* time at start of writes */
+ static int call_count;
+ static time_t start_time; /* time at start of writes */
- if (call_count++ == 0) {
- start_time = 0;
- }
+ if (call_count++ == 0) {
+ start_time = 0;
+ }
- (void) strcpy(name_list, tp->term_names);
- DEBUG(7, ("Name list = '%s'", name_list));
+ (void) strcpy(name_list, tp->term_names);
+ DEBUG(7, ("Name list = '%s'", name_list));
- first_name = name_list;
+ first_name = name_list;
- ptr = &name_list[strlen(name_list) - 1];
- other_names = ptr + 1;
+ ptr = &name_list[strlen(name_list) - 1];
+ other_names = ptr + 1;
- while (ptr > name_list && *ptr != '|')
- ptr--;
+ while (ptr > name_list && *ptr != '|')
+ ptr--;
- if (ptr != name_list) {
- *ptr = '\0';
+ if (ptr != name_list) {
+ *ptr = '\0';
- for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++)
- continue;
+ for (ptr = name_list; *ptr != '\0' && *ptr != '|'; ptr++)
+ continue;
- if (*ptr == '\0')
- other_names = ptr;
- else {
- *ptr = '\0';
- other_names = ptr + 1;
- }
+ if (*ptr == '\0')
+ other_names = ptr;
+ else {
+ *ptr = '\0';
+ other_names = ptr + 1;
}
+ }
- DEBUG(7, ("First name = '%s'", first_name));
- DEBUG(7, ("Other names = '%s'", other_names));
+ DEBUG(7, ("First name = '%s'", first_name));
+ DEBUG(7, ("Other names = '%s'", other_names));
- _nc_set_type(first_name);
+ _nc_set_type(first_name);
- if (strlen(first_name) > sizeof(filename)-3)
- _nc_warning("terminal name too long.");
+ if (strlen(first_name) > sizeof(filename) - 3)
+ _nc_warning("terminal name too long.");
- sprintf(filename, "%c/%s", first_name[0], first_name);
+ sprintf(filename, "%c/%s", first_name[0], first_name);
- /*
- * Has this primary name been written since the first call to
- * write_entry()? If so, the newer write will step on the older,
- * so warn the user.
- */
- if (start_time > 0 &&
- stat(filename, &statbuf) >= 0
- && statbuf.st_mtime >= start_time)
- {
- _nc_warning("name multiply defined.");
+ /*
+ * Has this primary name been written since the first call to
+ * write_entry()? If so, the newer write will step on the older,
+ * so warn the user.
+ */
+ if (start_time > 0 &&
+ stat(filename, &statbuf) >= 0
+ && statbuf.st_mtime >= start_time) {
+ _nc_warning("name multiply defined.");
+ }
+
+ check_writeable(first_name[0]);
+ write_file(filename, tp);
+
+ if (start_time == 0) {
+ if (stat(filename, &statbuf) < 0
+ || (start_time = statbuf.st_mtime) == 0) {
+ _nc_syserr_abort("error obtaining time from %s/%s",
+ _nc_tic_dir(0), filename);
}
+ }
+ while (*other_names != '\0') {
+ ptr = other_names++;
+ while (*other_names != '|' && *other_names != '\0')
+ other_names++;
- check_writeable(first_name[0]);
- write_file(filename, tp);
+ if (*other_names != '\0')
+ *(other_names++) = '\0';
- if (start_time == 0) {
- if (stat(filename, &statbuf) < 0
- || (start_time = statbuf.st_mtime) == 0) {
- _nc_syserr_abort("error obtaining time from %s/%s",
- _nc_tic_dir(0), filename);
- }
+ if (strlen(ptr) > sizeof(linkname) - 3) {
+ _nc_warning("terminal alias %s too long.", ptr);
+ continue;
}
- while (*other_names != '\0') {
- ptr = other_names++;
- while (*other_names != '|' && *other_names != '\0')
- other_names++;
-
- if (*other_names != '\0')
- *(other_names++) = '\0';
-
- if (strlen(ptr) > sizeof(linkname)-3) {
- _nc_warning("terminal alias %s too long.", ptr);
- continue;
- }
- if (strchr(ptr, '/') != 0) {
- _nc_warning("cannot link alias %s.", ptr);
- continue;
- }
-
- check_writeable(ptr[0]);
- sprintf(linkname, "%c/%s", ptr[0], ptr);
-
- if (strcmp(filename, linkname) == 0) {
- _nc_warning("self-synonym ignored");
- }
- else if (stat(linkname, &statbuf) >= 0 &&
- statbuf.st_mtime < start_time)
- {
- _nc_warning("alias %s multiply defined.", ptr);
- }
- else if (_nc_access(linkname, W_OK) == 0)
+ if (strchr(ptr, '/') != 0) {
+ _nc_warning("cannot link alias %s.", ptr);
+ continue;
+ }
+
+ check_writeable(ptr[0]);
+ sprintf(linkname, "%c/%s", ptr[0], ptr);
+
+ if (strcmp(filename, linkname) == 0) {
+ _nc_warning("self-synonym ignored");
+ } else if (stat(linkname, &statbuf) >= 0 &&
+ statbuf.st_mtime < start_time) {
+ _nc_warning("alias %s multiply defined.", ptr);
+ } else if (_nc_access(linkname, W_OK) == 0)
#if HAVE_LINK
- {
- int code;
+ {
+ int code;
#if USE_SYMLINKS
- strcpy(symlinkname, "../");
- strncat(symlinkname, filename, sizeof(symlinkname) - 4);
- symlinkname[sizeof(symlinkname) - 1] = '\0';
+ strcpy(symlinkname, "../");
+ strncat(symlinkname, filename, sizeof(symlinkname) - 4);
+ symlinkname[sizeof(symlinkname) - 1] = '\0';
#endif /* USE_SYMLINKS */
#if HAVE_REMOVE
- code = remove(linkname);
+ code = remove(linkname);
#else
- code = unlink(linkname);
+ code = unlink(linkname);
#endif
- if (code != 0 && errno == ENOENT)
- code = 0;
+ if (code != 0 && errno == ENOENT)
+ code = 0;
#if USE_SYMLINKS
- if (symlink(symlinkname, linkname) < 0)
+ if (symlink(symlinkname, linkname) < 0)
#else
- if (link(filename, linkname) < 0)
+ if (link(filename, linkname) < 0)
#endif /* USE_SYMLINKS */
- {
- /*
- * If there wasn't anything there, and we cannot
- * link to the target because it is the same as the
- * target, then the source must be on a filesystem
- * that uses caseless filenames, such as Win32, etc.
- */
- if (code == 0 && errno == EEXIST)
- _nc_warning("can't link %s to %s", filename, linkname);
- else if (code == 0 && errno == EPERM)
- write_file(linkname, tp);
- else
- _nc_syserr_abort("can't link %s to %s", filename, linkname);
- }
- else
- {
- DEBUG(1, ("Linked %s", linkname));
- }
- }
+ {
+ /*
+ * If there wasn't anything there, and we cannot
+ * link to the target because it is the same as the
+ * target, then the source must be on a filesystem
+ * that uses caseless filenames, such as Win32, etc.
+ */
+ if (code == 0 && errno == EEXIST)
+ _nc_warning("can't link %s to %s", filename, linkname);
+ else if (code == 0 && errno == EPERM)
+ write_file(linkname, tp);
+ else
+ _nc_syserr_abort("can't link %s to %s", filename, linkname);
+ } else {
+ DEBUG(1, ("Linked %s", linkname));
+ }
+ }
#else /* just make copies */
- write_file(linkname, tp);
+ write_file(linkname, tp);
#endif /* HAVE_LINK */
- }
+ }
}
-#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */
+#undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */
#define HI(x) ((x) / 256)
#define LO(x) ((x) % 256)
#define LITTLE_ENDIAN(p, x) (p)[0] = LO(x), (p)[1] = HI(x)
#define WRITE_STRING(str) (fwrite(str, sizeof(char), strlen(str) + 1, fp) == strlen(str) + 1)
-static int compute_offsets(char **Strings, int strmax, short *offsets)
+static int
+compute_offsets(char **Strings, int strmax, short *offsets)
{
size_t nextfree = 0;
int i;
@@ -375,17 +372,18 @@ static int compute_offsets(char **Strings, int strmax, short *offsets)
return nextfree;
}
-static void convert_shorts(unsigned char *buf, short *Numbers, int count)
+static void
+convert_shorts(unsigned char *buf, short *Numbers, int count)
{
int i;
for (i = 0; i < count; i++) {
- if (Numbers[i] == -1) { /* HI/LO won't work */
- buf[2*i] = buf[2*i + 1] = 0377;
- } else if (Numbers[i] == -2) { /* HI/LO won't work */
- buf[2*i] = 0376;
- buf[2*i + 1] = 0377;
+ if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */
+ buf[2 * i] = buf[2 * i + 1] = 0377;
+ } else if (Numbers[i] == CANCELLED_NUMERIC) { /* HI/LO won't work */
+ buf[2 * i] = 0376;
+ buf[2 * i + 1] = 0377;
} else {
- LITTLE_ENDIAN(buf + 2*i, Numbers[i]);
+ LITTLE_ENDIAN(buf + 2 * i, Numbers[i]);
TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i]));
}
}
@@ -394,164 +392,188 @@ static void convert_shorts(unsigned char *buf, short *Numbers, int count)
#define even_boundary(value) \
((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1)
-static int write_object(FILE *fp, TERMTYPE *tp)
+static int
+write_object(FILE * fp, TERMTYPE * tp)
{
-char *namelist;
-size_t namelen, boolmax, nummax, strmax;
-char zero = '\0';
-size_t i;
-short nextfree;
-short offsets[MAX_ENTRY_SIZE/2];
-unsigned char buf[MAX_ENTRY_SIZE];
+ char *namelist;
+ size_t namelen, boolmax, nummax, strmax;
+ char zero = '\0';
+ size_t i;
+ short nextfree;
+ short offsets[MAX_ENTRY_SIZE / 2];
+ unsigned char buf[MAX_ENTRY_SIZE];
+ unsigned last_bool = BOOLWRITE;
+ unsigned last_num = NUMWRITE;
+ unsigned last_str = STRWRITE;
- namelist = tp->term_names;
- namelen = strlen(namelist) + 1;
+#if NCURSES_XNAMES
+ /*
+ * Normally we limit the list of values to exclude the "obsolete"
+ * capabilities. However, if we are accepting extended names, add
+ * these as well, since they are used for supporting translation
+ * to/from termcap.
+ */
+ if (_nc_user_definable) {
+ last_bool = BOOLCOUNT;
+ last_num = NUMCOUNT;
+ last_str = STRCOUNT;
+ }
+#endif
- /*
- * BOOLWRITE, etc., are less than BOOLCOUNT because we store some
- * values internally.
- */
- boolmax = 0;
- for (i = 0; i < BOOLWRITE; i++) {
- if (tp->Booleans[i])
- boolmax = i+1;
- }
+ namelist = tp->term_names;
+ namelen = strlen(namelist) + 1;
- nummax = 0;
- for (i = 0; i < NUMWRITE; i++) {
- if (tp->Numbers[i] != ABSENT_NUMERIC)
- nummax = i+1;
- }
+ boolmax = 0;
+ for (i = 0; i < last_bool; i++) {
+ if (tp->Booleans[i] == TRUE)
+ boolmax = i + 1;
+ }
- strmax = 0;
- for (i = 0; i < STRWRITE; i++) {
- if (tp->Strings[i] != ABSENT_STRING)
- strmax = i+1;
- }
+ nummax = 0;
+ for (i = 0; i < last_num; i++) {
+ if (tp->Numbers[i] != ABSENT_NUMERIC)
+ nummax = i + 1;
+ }
- nextfree = compute_offsets(tp->Strings, strmax, offsets);
+ strmax = 0;
+ for (i = 0; i < last_str; i++) {
+ if (tp->Strings[i] != ABSENT_STRING)
+ strmax = i + 1;
+ }
- /* fill in the header */
- LITTLE_ENDIAN(buf, MAGIC);
- LITTLE_ENDIAN(buf+2, min(namelen, MAX_NAME_SIZE + 1));
- LITTLE_ENDIAN(buf+4, boolmax);
- LITTLE_ENDIAN(buf+6, nummax);
- LITTLE_ENDIAN(buf+8, strmax);
- LITTLE_ENDIAN(buf+10, nextfree);
+ nextfree = compute_offsets(tp->Strings, strmax, offsets);
- /* write out the header */
- TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp)));
- if (fwrite(buf, 12, 1, fp) != 1
- || fwrite(namelist, sizeof(char), namelen, fp) != namelen
- || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax)
- return(ERR);
+ /* fill in the header */
+ LITTLE_ENDIAN(buf, MAGIC);
+ LITTLE_ENDIAN(buf + 2, min(namelen, MAX_NAME_SIZE + 1));
+ LITTLE_ENDIAN(buf + 4, boolmax);
+ LITTLE_ENDIAN(buf + 6, nummax);
+ LITTLE_ENDIAN(buf + 8, strmax);
+ LITTLE_ENDIAN(buf + 10, nextfree);
- if (even_boundary(namelen+boolmax))
- return(ERR);
+ /* write out the header */
+ TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp)));
+ if (fwrite(buf, 12, 1, fp) != 1
+ || fwrite(namelist, sizeof(char), namelen, fp) != namelen)
+ return (ERR);
- TRACE_OUT(("Numerics begin at %04lx", ftell(fp)));
+ for (i = 0; i < boolmax; i++)
+ if (tp->Booleans[i] == TRUE)
+ buf[i] = TRUE;
+ else
+ buf[i] = FALSE;
+ if (fwrite(buf, sizeof(char), boolmax, fp) != boolmax)
+ return (ERR);
- /* the numerics */
- convert_shorts(buf, tp->Numbers, nummax);
- if (fwrite(buf, 2, nummax, fp) != nummax)
- return(ERR);
+ if (even_boundary(namelen + boolmax))
+ return (ERR);
- TRACE_OUT(("String offsets begin at %04lx", ftell(fp)));
+ TRACE_OUT(("Numerics begin at %04lx", ftell(fp)));
- /* the string offsets */
- convert_shorts(buf, offsets, strmax);
- if (fwrite(buf, 2, strmax, fp) != strmax)
- return(ERR);
+ /* the numerics */
+ convert_shorts(buf, tp->Numbers, nummax);
+ if (fwrite(buf, 2, nummax, fp) != nummax)
+ return (ERR);
- TRACE_OUT(("String table begins at %04lx", ftell(fp)));
+ TRACE_OUT(("String offsets begin at %04lx", ftell(fp)));
- /* the strings */
- for (i = 0; i < strmax; i++)
- if (VALID_STRING(tp->Strings[i]))
- if (!WRITE_STRING(tp->Strings[i]))
- return(ERR);
+ /* the string offsets */
+ convert_shorts(buf, offsets, strmax);
+ if (fwrite(buf, 2, strmax, fp) != strmax)
+ return (ERR);
+
+ TRACE_OUT(("String table begins at %04lx", ftell(fp)));
+
+ /* the strings */
+ for (i = 0; i < strmax; i++)
+ if (VALID_STRING(tp->Strings[i]))
+ if (!WRITE_STRING(tp->Strings[i]))
+ return (ERR);
#if NCURSES_XNAMES
- if (NUM_EXT_NAMES(tp)) {
- unsigned extcnt = NUM_EXT_NAMES(tp);
-
- if (even_boundary(nextfree))
- return(ERR);
-
- nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets);
- TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
- nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings);
- TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
- strmax = tp->ext_Strings + extcnt;
-
- /*
- * Write the extended header
- */
- LITTLE_ENDIAN(buf+0, tp->ext_Booleans);
- LITTLE_ENDIAN(buf+2, tp->ext_Numbers);
- LITTLE_ENDIAN(buf+4, tp->ext_Strings);
- LITTLE_ENDIAN(buf+6, strmax);
- LITTLE_ENDIAN(buf+8, nextfree);
- TRACE_OUT(("WRITE extended-header @%ld", ftell(fp)));
- if (fwrite(buf, 10, 1, fp) != 1)
- return(ERR);
-
- TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp)));
- if (tp->ext_Booleans
- && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char), tp->ext_Booleans, fp) != tp->ext_Booleans)
- return(ERR);
-
- if (even_boundary(tp->ext_Booleans))
- return(ERR);
-
- TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp)));
- if (tp->ext_Numbers) {
- convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
- if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers)
- return(ERR);
- }
+ if (NUM_EXT_NAMES(tp)) {
+ unsigned extcnt = NUM_EXT_NAMES(tp);
- /*
- * Convert the offsets for the ext_Strings and ext_Names tables,
- * in that order.
- */
- convert_shorts(buf, offsets, strmax);
- TRACE_OUT(("WRITE offsets @%ld", ftell(fp)));
- if (fwrite(buf, 2, strmax, fp) != strmax)
- return(ERR);
-
- /*
- * Write the string table after the offset tables so we do not
- * have to do anything about alignment.
- */
- for (i = 0; i < tp->ext_Strings; i++) {
- if (VALID_STRING(tp->Strings[i+STRCOUNT])) {
- TRACE_OUT(("WRITE ext_Strings[%d]=%s", i, _nc_visbuf(tp->Strings[i+STRCOUNT])));
- if (!WRITE_STRING(tp->Strings[i+STRCOUNT]))
- return(ERR);
- }
- }
+ if (even_boundary(nextfree))
+ return (ERR);
- /*
- * Write the extended names
- */
- for (i = 0; i < extcnt; i++) {
- TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i]));
- if (!WRITE_STRING(tp->ext_Names[i]))
- return(ERR);
+ nextfree = compute_offsets(tp->Strings + STRCOUNT, tp->ext_Strings, offsets);
+ TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree));
+ nextfree += compute_offsets(tp->ext_Names, extcnt, offsets + tp->ext_Strings);
+ TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
+ strmax = tp->ext_Strings + extcnt;
+
+ /*
+ * Write the extended header
+ */
+ LITTLE_ENDIAN(buf + 0, tp->ext_Booleans);
+ LITTLE_ENDIAN(buf + 2, tp->ext_Numbers);
+ LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
+ LITTLE_ENDIAN(buf + 6, strmax);
+ LITTLE_ENDIAN(buf + 8, nextfree);
+ TRACE_OUT(("WRITE extended-header @%ld", ftell(fp)));
+ if (fwrite(buf, 10, 1, fp) != 1)
+ return (ERR);
+
+ TRACE_OUT(("WRITE %d booleans @%ld", tp->ext_Booleans, ftell(fp)));
+ if (tp->ext_Booleans
+ && fwrite(tp->Booleans + BOOLCOUNT, sizeof(char),
+ tp->ext_Booleans, fp) != tp->ext_Booleans)
+ return (ERR);
+
+ if (even_boundary(tp->ext_Booleans))
+ return (ERR);
+
+ TRACE_OUT(("WRITE %d numbers @%ld", tp->ext_Numbers, ftell(fp)));
+ if (tp->ext_Numbers) {
+ convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers);
+ if (fwrite(buf, 2, tp->ext_Numbers, fp) != tp->ext_Numbers)
+ return (ERR);
+ }
+
+ /*
+ * Convert the offsets for the ext_Strings and ext_Names tables,
+ * in that order.
+ */
+ convert_shorts(buf, offsets, strmax);
+ TRACE_OUT(("WRITE offsets @%ld", ftell(fp)));
+ if (fwrite(buf, 2, strmax, fp) != strmax)
+ return (ERR);
+
+ /*
+ * Write the string table after the offset tables so we do not
+ * have to do anything about alignment.
+ */
+ for (i = 0; i < tp->ext_Strings; i++) {
+ if (VALID_STRING(tp->Strings[i + STRCOUNT])) {
+ TRACE_OUT(("WRITE ext_Strings[%d]=%s", i,
+ _nc_visbuf(tp->Strings[i + STRCOUNT])));
+ if (!WRITE_STRING(tp->Strings[i + STRCOUNT]))
+ return (ERR);
}
+ }
+ /*
+ * Write the extended names
+ */
+ for (i = 0; i < extcnt; i++) {
+ TRACE_OUT(("WRITE ext_Names[%d]=%s", i, tp->ext_Names[i]));
+ if (!WRITE_STRING(tp->ext_Names[i]))
+ return (ERR);
}
+
+ }
#endif /* NCURSES_XNAMES */
- total_written++;
- return(OK);
+ total_written++;
+ return (OK);
}
/*
* Returns the total number of entries written by this process
*/
-int _nc_tic_written(void)
+int
+_nc_tic_written(void)
{
- return total_written;
+ return total_written;
}