diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-02 06:23:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-02 06:23:57 +0000 |
commit | e52ae7d7cb3b9267a450ee786b056b14391f2f50 (patch) | |
tree | 852bbb003a1438d75ce8016c9feef856d56fd2fd /lib/libcurses | |
parent | aedffcef562be3c46e9a21641c0a65c968b1d889 (diff) |
ncurses-4.2-990301
Diffstat (limited to 'lib/libcurses')
40 files changed, 1499 insertions, 428 deletions
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 8e7e1426958..b291542bfec 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.36 1999/02/24 06:31:06 millert Exp $ +# $OpenBSD: Makefile,v 1.37 1999/03/02 06:23:26 millert Exp $ # Uncomment this to enable tracing in libcurses #CURSESTRACE=-DTRACE @@ -35,18 +35,18 @@ SRCS+= define_key.c keybound.c keyok.c lib_adabind.c lib_addch.c lib_addstr.c \ lib_winch.c lib_window.c nc_panel.c resizeterm.c safe_sprintf.c \ sigaction.c tries.c wresize.c # tinfo -SRCS+= access.c add_tries.c alloc_entry.c captoinfo.c comp_error.c \ - comp_expand.c comp_hash.c comp_parse.c comp_scan.c doalloc.c \ - getenv_num.c home_terminfo.c init_keytry.c lib_acs.c lib_baudrate.c \ - lib_cur_term.c lib_data.c lib_has_cap.c lib_kernel.c \ - lib_longname.c lib_napms.c lib_options.c lib_print.c lib_raw.c \ - lib_setup.c lib_termcap.c lib_termname.c lib_ti.c lib_tparm.c \ - lib_tputs.c lib_ttyflags.c name_match.c \ +SRCS+= access.c add_tries.c alloc_entry.c alloc_ttype.c captoinfo.c \ + comp_error.c comp_expand.c comp_hash.c comp_parse.c comp_scan.c \ + doalloc.c free_ttype.c getenv_num.c home_terminfo.c init_keytry.c \ + lib_acs.c lib_baudrate.c lib_cur_term.c lib_data.c lib_has_cap.c \ + lib_kernel.c lib_longname.c lib_napms.c lib_options.c lib_print.c \ + lib_raw.c lib_setup.c lib_termcap.c lib_termname.c lib_ti.c \ + lib_tparm.c lib_tputs.c lib_ttyflags.c name_match.c \ parse_entry.c read_bsd_terminfo.c read_entry.c read_termcap.c \ setbuf.c write_entry.c # trace SRCS+= lib_trace.c lib_traceatr.c lib_tracebits.c lib_tracechr.c \ - lib_tracedmp.c lib_tracemse.c trace_buf.c trace_tries.c + lib_tracedmp.c lib_tracemse.c trace_buf.c trace_tries.c trace_xnames.c # tty SRCS+= hardscroll.c hashmap.c lib_mvcur.c lib_tstp.c lib_twait.c \ lib_vidattr.c tty_update.c diff --git a/lib/libcurses/base/define_key.c b/lib/libcurses/base/define_key.c index 81578027796..97d2b6e9558 100644 --- a/lib/libcurses/base/define_key.c +++ b/lib/libcurses/base/define_key.c @@ -1,4 +1,4 @@ -/* $OpenBSD: define_key.c,v 1.2 1999/02/24 06:31:07 millert Exp $ */ +/* $OpenBSD: define_key.c,v 1.3 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -34,7 +34,7 @@ #include <curses.priv.h> -MODULE_ID("$From: define_key.c,v 1.3 1999/02/19 11:53:02 tom Exp $") +MODULE_ID("$From: define_key.c,v 1.4 1999/02/21 13:03:55 tom Exp $") int define_key(char *str, int keycode) @@ -43,7 +43,9 @@ define_key(char *str, int keycode) T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); if (keycode > 0) { - if (has_key(keycode)) { + if (str != 0) { + define_key(str, 0); + } else if (has_key(keycode)) { while (_nc_remove_key(&(SP->_keytry), keycode)) code = OK; } diff --git a/lib/libcurses/base/lib_color.c b/lib/libcurses/base/lib_color.c index 1aa3602c853..8ed06319de7 100644 --- a/lib/libcurses/base/lib_color.c +++ b/lib/libcurses/base/lib_color.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_color.c,v 1.1 1999/01/18 19:09:39 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.2 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <term.h> -MODULE_ID("$From: lib_color.c,v 1.33 1998/09/20 00:51:51 tom Exp $") +MODULE_ID("$From: lib_color.c,v 1.34 1999/02/27 19:54:51 tom Exp $") /* * These should be screen structure members. They need to be globals for @@ -168,7 +168,7 @@ int start_color(void) returnCode(ERR); SP->_coloron = 1; - if ((SP->_color_table = malloc(sizeof(color_t) * COLORS)) == 0) + if ((SP->_color_table = typeMalloc(color_t, COLORS)) == 0) returnCode(ERR); if (hue_lightness_saturation) memcpy(SP->_color_table, hls_palette, sizeof(color_t) * COLORS); diff --git a/lib/libcurses/base/safe_sprintf.c b/lib/libcurses/base/safe_sprintf.c index 3e01e47bf16..a5dd7c4a8e1 100644 --- a/lib/libcurses/base/safe_sprintf.c +++ b/lib/libcurses/base/safe_sprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: safe_sprintf.c,v 1.1 1999/01/18 19:10:07 millert Exp $ */ +/* $OpenBSD: safe_sprintf.c,v 1.2 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("$From: safe_sprintf.c,v 1.9 1998/08/15 23:58:49 tom Exp $") +MODULE_ID("$From: safe_sprintf.c,v 1.10 1999/02/27 19:56:37 tom Exp $") #if USE_SAFE_SPRINTF @@ -59,9 +59,9 @@ _nc_printf_length(const char *fmt, va_list ap) if (fmt == 0 || *fmt == '\0') return -1; - if ((format = malloc(strlen(fmt)+1)) == 0) + if ((format = typeMalloc(char, strlen(fmt)+1)) == 0) return -1; - if ((buffer = malloc(length)) == 0) { + if ((buffer = typeMalloc(char, length)) == 0) { free(format); return -1; } @@ -152,7 +152,7 @@ _nc_printf_length(const char *fmt, va_list ap) prec = strlen(pval); if (prec > (int)length) { length = length + prec; - buffer = (char *)_nc_doalloc(buffer, length); + buffer = typeRealloc(char, length, buffer); if (buffer == 0) { free(format); return -1; @@ -214,7 +214,7 @@ _nc_printf_string(const char *fmt, va_list ap) int len = _nc_printf_length(fmt, ap); if (len > 0) { - if ((buf = malloc(len+1)) == 0) + if ((buf = typeMalloc(char, len+1)) == 0) return(0); vsprintf(buf, fmt, ap); } @@ -227,7 +227,7 @@ _nc_printf_string(const char *fmt, va_list ap) if (screen_lines > rows) rows = screen_lines; if (screen_columns > cols) cols = screen_columns; len = (rows * (cols + 1)) + 1; - buf = (char *)_nc_doalloc(buf, len); + buf = typeRealloc(char, len, buf); if (buf == 0) { return(0); } diff --git a/lib/libcurses/base/tries.c b/lib/libcurses/base/tries.c index 245446b3599..11c57829141 100644 --- a/lib/libcurses/base/tries.c +++ b/lib/libcurses/base/tries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tries.c,v 1.2 1999/02/24 06:31:08 millert Exp $ */ +/* $OpenBSD: tries.c,v 1.3 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -41,7 +41,7 @@ #include <curses.priv.h> -MODULE_ID("$From: tries.c,v 1.10 1999/02/19 11:52:11 tom Exp $") +MODULE_ID("$From: tries.c,v 1.12 1999/03/01 23:23:59 tom Exp $") /* * Expand a keycode into the string that it corresponds to, returning null if @@ -84,12 +84,14 @@ char *_nc_expand_try(struct tries *tree, unsigned short code, int *count, size_t */ int _nc_remove_key(struct tries **tree, unsigned short code) { + T((T_CALLED("_nc_remove_key(%p,%d)"), tree, code)); + if (code == 0) - return FALSE; + returnCode(FALSE); while (*tree != 0) { if (_nc_remove_key(&(*tree)->child, code)) { - return TRUE; + returnCode(TRUE); } if ((*tree)->value == code) { if((*tree)->child) { @@ -100,11 +102,11 @@ int _nc_remove_key(struct tries **tree, unsigned short code) *tree = (*tree)->sibling; free(to_free); } - return TRUE; + returnCode(TRUE); } tree = &(*tree)->sibling; } - return FALSE; + returnCode(FALSE); } /* @@ -113,14 +115,15 @@ int _nc_remove_key(struct tries **tree, unsigned short code) */ int _nc_remove_string(struct tries **tree, char *string) { + T((T_CALLED("_nc_remove_string(%p,%s)"), tree, _nc_visbuf(string))); + if (string == 0 || *string == 0) - return FALSE; + returnCode(FALSE); while (*tree != 0) { - if (_nc_remove_string(&(*tree)->child, string+1)) { - return TRUE; - } if ((unsigned char)(*tree)->ch == (unsigned char)*string) { + if (string[1] != 0) + returnCode(_nc_remove_string(&(*tree)->child, string+1)); if((*tree)->child) { /* don't cut the whole sub-tree */ (*tree)->value = 0; @@ -129,9 +132,9 @@ int _nc_remove_string(struct tries **tree, char *string) *tree = (*tree)->sibling; free(to_free); } - return TRUE; + returnCode(TRUE); } tree = &(*tree)->sibling; } - return FALSE; + returnCode(FALSE); } diff --git a/lib/libcurses/base/wresize.c b/lib/libcurses/base/wresize.c index 47ed197ca62..b70f5678231 100644 --- a/lib/libcurses/base/wresize.c +++ b/lib/libcurses/base/wresize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wresize.c,v 1.1 1999/01/18 19:10:08 millert Exp $ */ +/* $OpenBSD: wresize.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -34,7 +34,7 @@ #include <curses.priv.h> -MODULE_ID("$From: wresize.c,v 1.11 1998/10/12 12:24:40 Alexander.V.Lukyanov Exp $") +MODULE_ID("$From: wresize.c,v 1.12 1999/02/27 18:57:31 tom Exp $") /* * Reallocate a curses WINDOW struct to either shrink or grow to the specified @@ -42,7 +42,7 @@ MODULE_ID("$From: wresize.c,v 1.11 1998/10/12 12:24:40 Alexander.V.Lukyanov Exp * blanks. The application is responsible for repainting the blank area. */ -#define DOALLOC(p,t,n) (t *)_nc_doalloc(p, sizeof(t)*(n)) +#define DOALLOC(p,t,n) typeRealloc(t, n, p) #define ld_ALLOC(p,n) DOALLOC(p,struct ldat,n) #define c_ALLOC(p,n) DOALLOC(p,chtype,n) diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index f6f29be9006..abad4d7cb58 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.h,v 1.21 1999/02/24 06:33:14 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.22 1999/03/02 06:23:26 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -33,7 +33,7 @@ * and: Eric S. Raymond <esr@snark.thyrsus.com> * ****************************************************************************/ -/* $From: curses.h.in,v 1.79 1999/02/19 12:03:06 tom Exp $ */ +/* $From: curses.h.in,v 1.81 1999/02/28 23:38:22 tom Exp $ */ #ifndef __NCURSES_H #define __NCURSES_H @@ -50,7 +50,7 @@ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 5 #define NCURSES_VERSION_MINOR 0 -#define NCURSES_VERSION_PATCH 990220 +#define NCURSES_VERSION_PATCH 990301 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION @@ -79,24 +79,16 @@ typedef unsigned long chtype; /* XSI and SVr4 specify that curses implements 'bool'. However, C++ may also * implement it. If so, we must use the C++ compiler's type to avoid conflict * with other interfaces. - * - * To simplify use with/without the configuration script, we define the symbols - * CXX_BUILTIN_BOOL and CXX_TYPE_OF_BOOL; they're edited by the configure - * script. */ #undef TRUE +#define TRUE 1 + #undef FALSE -#define CXX_BUILTIN_BOOL 1 -#define CXX_TYPE_OF_BOOL char +#define FALSE 0 -#if defined(__cplusplus) && CXX_BUILTIN_BOOL -#define TRUE ((CXX_TYPE_OF_BOOL)true) -#define FALSE ((CXX_TYPE_OF_BOOL)false) -#else -typedef CXX_TYPE_OF_BOOL bool; -#define TRUE ((bool)1) -#define FALSE ((bool)0) +#if !defined(__cplusplus) || !1 +typedef char bool; #endif #ifdef __cplusplus @@ -325,6 +317,7 @@ extern int define_key (char *, int); extern int keyok (int, bool); extern int resizeterm (int, int); extern int use_default_colors (void); +extern int use_extended_names (bool); extern int wresize (WINDOW *, int, int); extern char ttytype[]; /* needed for backward compatibility */ diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 1dbb0781336..25ed50023ca 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.13 1999/02/24 06:31:07 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.14 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ /* - * $From: curses.priv.h,v 1.131 1999/02/19 11:38:48 tom Exp $ + * $From: curses.priv.h,v 1.136 1999/02/28 01:50:50 tom Exp $ * * curses.priv.h * @@ -476,7 +476,9 @@ typedef struct { line->lastchar = end #define SIZEOF(v) (sizeof(v)/sizeof(v[0])) -#define typeCalloc(type,elts) (type *)calloc(elts,sizeof(type)) +#define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type)) +#define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type)) +#define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type)) #define FreeIfNeeded(p) if(p != 0) free(p) #define FreeAndNull(p) free(p); p = 0 @@ -629,6 +631,10 @@ extern void _nc_expanded(void); /* doalloc.c */ extern void *_nc_doalloc(void *, size_t); +#if !HAVE_STRDUP +#define strdup _nc_strdup +extern char *_nc_strdup(char *); +#endif /* doupdate.c */ #if USE_XMC_SUPPORT diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index 04960fd5396..22795ed7b79 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ncurses_cfg.h,v 1.10 1999/01/31 20:25:38 millert Exp $ */ +/* $OpenBSD: ncurses_cfg.h,v 1.11 1999/03/02 06:23:27 millert Exp $ */ /* include/ncurses_cfg.h. Generated automatically by configure. */ /**************************************************************************** @@ -115,6 +115,7 @@ #define USE_DATABASE 1 #define USE_GETCAP 1 #define USE_HASHMAP 1 +/* #define USE_SIGWINCH 1 */ /* The C compiler may not treat these properly but C++ has to */ #ifdef __cplusplus diff --git a/lib/libcurses/term.h b/lib/libcurses/term.h index 39154bc0b68..936cbe23ee8 100644 --- a/lib/libcurses/term.h +++ b/lib/libcurses/term.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term.h,v 1.5 1999/01/18 19:09:16 millert Exp $ */ +/* $OpenBSD: term.h,v 1.6 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -33,7 +33,7 @@ /* and: Eric S. Raymond <esr@snark.thyrsus.com> */ /****************************************************************************/ -/* $From: MKterm.h.awk.in,v 1.32 1999/01/09 22:01:45 tom Exp $ */ +/* $From: MKterm.h.awk.in,v 1.35 1999/02/24 01:04:55 tom Exp $ */ /* ** term.h -- Definition of struct term @@ -47,7 +47,7 @@ #endif #undef NCURSES_VERSION -#define NCURSES_VERSION "4.2" +#define NCURSES_VERSION "5.0" #ifdef __cplusplus extern "C" { @@ -83,6 +83,9 @@ extern "C" { #undef NCURSES_CONST #define NCURSES_CONST /*nothing*/ +#undef NCURSES_XNAMES +#define NCURSES_XNAMES 0 + /* We will use these symbols to hide differences between * termios/termio/sgttyb interfaces. */ @@ -680,6 +683,9 @@ extern "C" { #endif /* __INTERNAL_CAPS_VISIBLE */ +/* + * Predefined terminfo array sizes + */ #define BOOLCOUNT 44 #define NUMCOUNT 39 #define STRCOUNT 414 @@ -687,22 +693,35 @@ extern "C" { typedef struct termtype { /* in-core form of terminfo data */ char *term_names; /* str_table offset of term names */ char *str_table; /* pointer to string table */ - char Booleans[BOOLCOUNT]; /* array of values */ - short Numbers[NUMCOUNT]; /* array of values */ - char *Strings[STRCOUNT]; /* array of string offsets */ + char *Booleans; /* array of boolean values */ + short *Numbers; /* array of integer values */ + char **Strings; /* array of string offsets */ + +#if NCURSES_XNAMES + char *ext_str_table; /* pointer to extended string table */ + char **ext_Names; /* corresponding names */ + + unsigned short num_Booleans;/* count total Booleans */ + unsigned short num_Numbers; /* count total Numbers */ + unsigned short num_Strings; /* count total Strings */ + + unsigned short ext_Booleans;/* count extensions to Booleans */ + unsigned short ext_Numbers; /* count extensions to Numbers */ + unsigned short ext_Strings; /* count extensions to Strings */ +#endif /* NCURSES_XNAMES */ + } TERMTYPE; typedef struct term { /* describe an actual terminal */ TERMTYPE type; /* terminal type description */ short Filedes; /* file description being written to */ - TTY Ottyb, /* original state of the terminal */ - Nttyb; /* current state of the terminal */ - int _baudrate; /* used to compute padding */ + TTY Ottyb, /* original state of the terminal */ + Nttyb; /* current state of the terminal */ + int _baudrate; /* used to compute padding */ } TERMINAL; extern TERMINAL *cur_term; - #if BROKEN_LINKER #define boolnames _nc_boolnames() #define boolcodes _nc_boolcodes() diff --git a/lib/libcurses/term_entry.h b/lib/libcurses/term_entry.h index e949c429a8c..9c5e50e6b78 100644 --- a/lib/libcurses/term_entry.h +++ b/lib/libcurses/term_entry.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term_entry.h,v 1.6 1999/02/24 06:31:07 millert Exp $ */ +/* $OpenBSD: term_entry.h,v 1.7 1999/03/02 06:23:27 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -45,6 +45,8 @@ extern "C" { #endif +#include <term.h> + #define MAX_USES 32 typedef struct entry { @@ -63,6 +65,28 @@ typedef struct entry { } ENTRY; +#if NCURSES_XNAMES +#define NUM_BOOLEANS(tp) (tp)->num_Booleans +#define NUM_NUMBERS(tp) (tp)->num_Numbers +#define NUM_STRINGS(tp) (tp)->num_Strings +#define EXT_NAMES(tp,i,limit,index,table) (i >= limit) ? tp->ext_Names[index] : table[i] +#else +#define NUM_BOOLEANS(tp) BOOLCOUNT +#define NUM_NUMBERS(tp) NUMCOUNT +#define NUM_STRINGS(tp) STRCOUNT +#define EXT_NAMES(tp,i,limit,index,table) table[i] +#endif + +#define NUM_EXT_NAMES(tp) ((tp)->ext_Booleans + (tp)->ext_Numbers + (tp)->ext_Strings) + +#define for_each_boolean(n,tp) for(n = 0; n < NUM_BOOLEANS(tp); n++) +#define for_each_number(n,tp) for(n = 0; n < NUM_NUMBERS(tp); n++) +#define for_each_string(n,tp) for(n = 0; n < NUM_STRINGS(tp); n++) + +#define ExtBoolname(tp,i,names) EXT_NAMES(tp, i, BOOLCOUNT, (i - (tp->num_Booleans - tp->ext_Booleans)), names) +#define ExtNumname(tp,i,names) EXT_NAMES(tp, i, NUMCOUNT, (i - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans, names) +#define ExtStrname(tp,i,names) EXT_NAMES(tp, i, STRCOUNT, (i - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans), names) + extern ENTRY *_nc_head, *_nc_tail; #define for_entry_list(qp) for (qp = _nc_head; qp; qp = qp->next) @@ -89,12 +113,23 @@ extern ENTRY *_nc_head, *_nc_tail; } /* alloc_entry.c: elementary allocation code */ -extern void _nc_init_entry(TERMTYPE *const); +extern ENTRY *_nc_copy_entry(ENTRY *oldp); extern char *_nc_save_str(const char *const); +extern void _nc_init_entry(TERMTYPE *const); extern void _nc_merge_entry(TERMTYPE *const, TERMTYPE *const); extern void _nc_wrap_entry(ENTRY *const); +/* alloc_ttype.c: elementary allocation code */ +extern void _nc_align_termtype(TERMTYPE *, TERMTYPE *); +extern void _nc_copy_termtype(TERMTYPE *, TERMTYPE *); + +/* free_ttype.c: elementary allocation code */ +extern void _nc_free_termtype(TERMTYPE *); + /* parse_entry.c: entry-parsing code */ +#if NCURSES_XNAMES +extern bool _nc_user_definable; +#endif extern int _nc_parse_entry(ENTRY *, int, bool); extern int _nc_capcmp(const char *, const char *); @@ -109,6 +144,8 @@ extern int _nc_resolve_uses(void); extern void _nc_free_entries(ENTRY *); extern void (*_nc_check_termtype)(TERMTYPE *); +/* trace_xnames.c */ +extern void _nc_trace_xnames(TERMTYPE *); #ifdef __OpenBSD__ /* read_bsd_terminfo.c: terminfo.db reading */ diff --git a/lib/libcurses/tinfo/alloc_entry.c b/lib/libcurses/tinfo/alloc_entry.c index 49bb255f9a6..3f94b109c31 100644 --- a/lib/libcurses/tinfo/alloc_entry.c +++ b/lib/libcurses/tinfo/alloc_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc_entry.c,v 1.1 1999/01/18 19:10:13 millert Exp $ */ +/* $OpenBSD: alloc_entry.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -37,20 +37,20 @@ /* * alloc_entry.c -- allocation functions for terminfo entries * + * _nc_copy_entry() * _nc_init_entry() + * _nc_merge_entry() * _nc_save_str() - * _nc_merge_entry(); - * _nc_wrap_entry(); + * _nc_wrap_entry() * */ #include <curses.priv.h> #include <tic.h> -#include <term.h> #include <term_entry.h> -MODULE_ID("$From: alloc_entry.c,v 1.14 1998/07/04 23:17:42 tom Exp $") +MODULE_ID("$From: alloc_entry.c,v 1.30 1999/03/01 02:03:45 tom Exp $") #define ABSENT_OFFSET -1 #define CANCELLED_OFFSET -2 @@ -65,18 +65,44 @@ void _nc_init_entry(TERMTYPE *const tp) { int i; - for (i=0; i < BOOLCOUNT; i++) - tp->Booleans[i] = FALSE; /* FIXME: why not ABSENT_BOOLEAN? */ - - for (i=0; i < NUMCOUNT; 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; +#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); + + for_each_boolean(i,tp) + tp->Booleans[i] = FALSE; + + for_each_number(i,tp) tp->Numbers[i] = ABSENT_NUMERIC; - for (i=0; i < STRCOUNT; i++) + for_each_string(i,tp) tp->Strings[i] = ABSENT_STRING; next_free = 0; } +ENTRY *_nc_copy_entry(ENTRY *oldp) +{ + ENTRY *newp = typeCalloc(ENTRY,1); + + if (newp != 0) { + *newp = *oldp; + _nc_copy_termtype(&(newp->tterm), &(oldp->tterm)); + } + return newp; +} + char *_nc_save_str(const char *const string) /* save a copy of string in the string buffer */ { @@ -96,42 +122,64 @@ size_t len = strlen(string) + 1; void _nc_wrap_entry(ENTRY *const ep) /* copy the string parts to allocated storage, preserving pointers to it */ { -int offsets[STRCOUNT], useoffsets[MAX_USES]; +int offsets[MAX_ENTRY_SIZE/2], useoffsets[MAX_USES]; int i, n; +TERMTYPE *tp = &(ep->tterm); - n = ep->tterm.term_names - stringbuf; - for (i=0; i < STRCOUNT; i++) - if (ep->tterm.Strings[i] == ABSENT_STRING) + n = tp->term_names - stringbuf; + for_each_string(i, &(ep->tterm)) { + if (tp->Strings[i] == ABSENT_STRING) offsets[i] = ABSENT_OFFSET; - else if (ep->tterm.Strings[i] == CANCELLED_STRING) + else if (tp->Strings[i] == CANCELLED_STRING) offsets[i] = CANCELLED_OFFSET; else - offsets[i] = ep->tterm.Strings[i] - stringbuf; + offsets[i] = tp->Strings[i] - stringbuf; + } - for (i=0; i < ep->nuses; i++) + 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; + } - if ((ep->tterm.str_table = (char *)malloc(next_free)) == (char *)0) + if ((tp->str_table = typeMalloc(char, next_free)) == (char *)0) _nc_err_abort("Out of memory"); - (void) memcpy(ep->tterm.str_table, stringbuf, next_free); + (void) memcpy(tp->str_table, stringbuf, next_free); - ep->tterm.term_names = ep->tterm.str_table + n; - for (i=0; i < STRCOUNT; i++) + tp->term_names = tp->str_table + n; + for_each_string(i, &(ep->tterm)) { if (offsets[i] == ABSENT_OFFSET) - ep->tterm.Strings[i] = ABSENT_STRING; + tp->Strings[i] = ABSENT_STRING; else if (offsets[i] == CANCELLED_OFFSET) - ep->tterm.Strings[i] = CANCELLED_STRING; + tp->Strings[i] = CANCELLED_STRING; else - ep->tterm.Strings[i] = ep->tterm.str_table + offsets[i]; + 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; + } + } +#endif - for (i=0; i < ep->nuses; i++) + for (i=0; i < ep->nuses; i++) { if (useoffsets[i] == ABSENT_OFFSET) ep->uses[i].parent = (void *)0; else - ep->uses[i].parent = (char *)(ep->tterm.str_table + useoffsets[i]); + ep->uses[i].parent = (char *)(tp->str_table + useoffsets[i]); + } } void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) @@ -139,7 +187,10 @@ void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) { int i; - for (i=0; i < BOOLCOUNT; i++) +#if NCURSES_XNAMES + _nc_align_termtype(to, from); +#endif + for_each_boolean(i, from) { int mergebool = from->Booleans[i]; @@ -149,7 +200,7 @@ void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) to->Booleans[i] = mergebool; } - for (i=0; i < NUMCOUNT; i++) + for_each_number(i, from) { int mergenum = from->Numbers[i]; @@ -164,7 +215,7 @@ 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 (i=0; i < STRCOUNT; i++) + for_each_string(i, from) { char *mergestring = from->Strings[i]; @@ -174,4 +225,3 @@ void _nc_merge_entry(TERMTYPE *const to, TERMTYPE *const from) to->Strings[i] = mergestring; } } - diff --git a/lib/libcurses/tinfo/alloc_ttype.c b/lib/libcurses/tinfo/alloc_ttype.c new file mode 100644 index 00000000000..b243b2dfc7f --- /dev/null +++ b/lib/libcurses/tinfo/alloc_ttype.c @@ -0,0 +1,463 @@ +/* $OpenBSD: alloc_ttype.c,v 1.1 1999/03/02 06:23:28 millert Exp $ */ + +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + + +/* + * align_ttype.c -- functions for TERMTYPE + * + * _nc_align_termtype() + * _nc_copy_termtype() + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: alloc_ttype.c,v 1.1 1999/03/02 06:23:28 millert 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) +{ + int n = 0; + while (na && nb) { + int cmp = strcmp(*a, *b); + if (cmp < 0) { + dst[n++] = *a++; + na--; + } else if (cmp > 0) { + dst[n++] = *b++; + nb--; + } else if (cmp == 0) { + dst[n++] = *a; + a++, b++; + na--, nb--; + } + } + while (na-- > 0) { + dst[n++] = *a++; + } + while (nb-- > 0) { + dst[n++] = *b++; + } + DEBUG(4, ("merge_names -> %d", n)); + return n; +} + +static bool find_name(char **table, int length, char *name) +{ + while (length-- > 0) { + if (!strcmp(*table++, name)) { + DEBUG(4, ("found name '%s'", name)); + return TRUE; + } + } + DEBUG(4, ("did not find name '%s'", name)); + return FALSE; +} + +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); + + 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--) { + if (find_name(to->ext_Names, limit, ext_Names[m])) { + to->Booleans[base + m] = to->Booleans[base + n--]; + } else { + to->Booleans[base + m] = FALSE; + } + } + to->ext_Booleans = ext_Booleans; + } + 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])) { + to->Numbers[base + m] = to->Numbers[base + n--]; + } else { + to->Numbers[base + m] = ABSENT_NUMERIC; + } + } + 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[base + m] = to->Strings[base + n--]; + } else { + to->Strings[base + m] = ABSENT_STRING; + } + } + to->ext_Strings = ext_Strings; + } +} + +/* + * Returns the first index in ext_Names[] for the given token-type + */ +static int _nc_first_ext_name(TERMTYPE *tp, int token_type) +{ + int first; + + switch (token_type) { + case BOOLEAN: + first = 0; + break; + case NUMBER: + first = tp->ext_Booleans; + break; + case STRING: + first = tp->ext_Booleans + tp->ext_Numbers; + break; + default: + first = 0; + break; + } + return first; +} + +/* + * Returns the last index in ext_Names[] for the given token-type + */ +static int _nc_last_ext_name(TERMTYPE *tp, int token_type) +{ + int last; + + switch (token_type) { + case BOOLEAN: + last = tp->ext_Booleans; + break; + case NUMBER: + last = tp->ext_Booleans + tp->ext_Numbers; + break; + default: + case STRING: + last = NUM_EXT_NAMES(tp); + break; + } + return last; +} + +/* + * Lookup an entry from extended-names, returning -1 if not found + */ +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); + + for (j = first; j < last; j++) { + if (!strcmp(name, tp->ext_Names[j])) { + return j; + } + } + return -1; +} + +/* + * 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) +{ + switch (token_type) { + case BOOLEAN: + n += (tp->num_Booleans - tp->ext_Booleans); + break; + case NUMBER: + n += (tp->num_Numbers - tp->ext_Numbers) + - (tp->ext_Booleans); + break; + default: + case STRING: + n += (tp->num_Strings - tp->ext_Strings) + - (tp->ext_Booleans + tp->ext_Numbers); + } + return n; +} + +/* + * 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) +{ + int j; + int first, last; + + 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]; + } + 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->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->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->ext_Strings -= 1; + tp->num_Strings -= 1; + break; + } + } +} + +/* + * 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) +{ + unsigned first = _nc_first_ext_name(tp, token_type); + unsigned last = _nc_last_ext_name(tp, token_type); + unsigned total = NUM_EXT_NAMES(tp) + 1; + unsigned j, k; + + for (j = first; j < last; j++) { + int cmp = strcmp(name, tp->ext_Names[j]); + if (cmp == 0) + /* already present */ + return _nc_ext_data_index(tp, j, token_type); + if (cmp < 0) { + break; + } + } + + 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]; + tp->ext_Names[j] = name; + j = _nc_ext_data_index(tp, j, token_type); + + switch (token_type) { + case BOOLEAN: + 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]; + 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]; + 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]; + break; + } + return j; +} + +/* + * Look for strings that are marked cancelled, which happen to be the same name + * 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) +{ + int first = to->ext_Booleans + to->ext_Numbers; + int last = first + to->ext_Strings; + int j, k; + + for (j = first; j < last; ) { + char *name = to->ext_Names[j]; + unsigned j_str = to->num_Strings - first - to->ext_Strings; + + if (to->Strings[j + j_str] == CANCELLED_STRING) { + if ((k = _nc_find_ext_name(from, to->ext_Names[j], BOOLEAN)) >= 0) { + _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) { + _nc_del_ext_name(to, name, STRING); + k = _nc_ins_ext_name(to, name, NUMBER); + to->Numbers[k] = CANCELLED_NUMERIC; + } + } else { + j++; + } + } +} + +void _nc_align_termtype(TERMTYPE *to, TERMTYPE *from) +{ + int na = NUM_EXT_NAMES(to); + int nb = NUM_EXT_NAMES(from); + int n; + bool same; + 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)); + + 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)) { + for (n = 0, same = TRUE; n < na; n++) { + if (strcmp(to->ext_Names[n], from->ext_Names[n])) { + same = FALSE; + break; + } + } + if (same) + return; + } + /* + * This is where we pay for having a simple extension representation. + * Allocate a new ext_Names array and merge the two ext_Names arrays + * 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); + + if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers)) + adjust_cancels(to, from); + + if (from->ext_Strings && (to->ext_Booleans + to->ext_Numbers)) + 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); + /* + * 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); + to->ext_Names = ext_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)); + } + } +} +#endif + +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)); + + /* FIXME: use memcpy for these and similar loops */ + for_each_boolean(i,dst) + dst->Booleans[i] = src->Booleans[i]; + for_each_number(i,dst) + dst->Numbers[i] = src->Numbers[i]; + for_each_string(i,dst) + dst->Strings[i] = src->Strings[i]; + + /* FIXME: we probably should also copy str_table and ext_str_table, + * but tic and infocmp are not written to exploit that (yet). + */ + +#if NCURSES_XNAMES + if ((i = NUM_EXT_NAMES(src)) != 0) { + dst->ext_Names = typeMalloc(char *, i); + memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *)); + } +#endif + +} diff --git a/lib/libcurses/tinfo/captoinfo.c b/lib/libcurses/tinfo/captoinfo.c index dcdc4c4ca62..11b7d07e929 100644 --- a/lib/libcurses/tinfo/captoinfo.c +++ b/lib/libcurses/tinfo/captoinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: captoinfo.c,v 1.1 1999/01/18 19:10:13 millert Exp $ */ +/* $OpenBSD: captoinfo.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -96,7 +96,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$From: captoinfo.c,v 1.21 1998/05/30 23:32:15 Todd.Miller Exp $") +MODULE_ID("$From: captoinfo.c,v 1.23 1999/02/28 23:42:20 tom Exp $") #define MAX_PUSHED 16 /* max # args we can push onto the stack */ #define MAX_ENTRY 2048 /* maximum chars in a translated capability */ @@ -117,7 +117,7 @@ static char *init_string(void) /* initialize 'my_string', 'my_length' */ { if (my_string == 0) - my_string = malloc(my_length = 256); + my_string = typeMalloc(char, my_length = 256); if (my_string == 0) _nc_err_abort("Out of memory"); @@ -130,7 +130,7 @@ 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 = realloc(my_string, my_length = (need + need)); + my_string = (char *)realloc(my_string, my_length = (need + need)); if (my_string == 0) _nc_err_abort("Out of memory"); d = my_string + have; diff --git a/lib/libcurses/tinfo/comp_expand.c b/lib/libcurses/tinfo/comp_expand.c index 12c7113fb9d..c78ec3c117e 100644 --- a/lib/libcurses/tinfo/comp_expand.c +++ b/lib/libcurses/tinfo/comp_expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_expand.c,v 1.1 1999/01/18 19:10:13 millert Exp $ */ +/* $OpenBSD: comp_expand.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -37,7 +37,7 @@ #include <ctype.h> #include <tic.h> -MODULE_ID("$From: comp_expand.c,v 1.9 1998/09/26 13:41:40 tom Exp $") +MODULE_ID("$From: comp_expand.c,v 1.10 1999/02/23 23:14:59 tom Exp $") static int trailing_spaces(const char *src) { @@ -63,7 +63,7 @@ size_t need = (2 + strlen(str)) * 4; int ch; if (buffer == 0 || need > length) { - if ((buffer = (char *)_nc_doalloc(buffer, length = need)) == 0) + if ((buffer = typeRealloc(char, length = need, buffer)) == 0) return 0; } diff --git a/lib/libcurses/tinfo/comp_hash.c b/lib/libcurses/tinfo/comp_hash.c index a2d7de5866c..95d9caf0e56 100644 --- a/lib/libcurses/tinfo/comp_hash.c +++ b/lib/libcurses/tinfo/comp_hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_hash.c,v 1.1 1999/01/18 19:10:14 millert Exp $ */ +/* $OpenBSD: comp_hash.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -51,7 +51,7 @@ #define DEBUG(level, params) /*nothing*/ #endif -MODULE_ID("$From: comp_hash.c,v 1.18 1998/08/22 18:01:18 tom Exp $") +MODULE_ID("$From: comp_hash.c,v 1.19 1999/02/22 22:49:43 tom Exp $") static int hash_function(const char *); @@ -182,18 +182,6 @@ struct name_table_entry const *ptr; * performance enhancement). */ -#if !HAVE_STRDUP -static char *strdup (char *s) -{ - char *p; - - p = malloc(strlen(s)+1); - if (p) - strcpy(p,s); - return(p); -} -#endif /* not HAVE_STRDUP */ - #define MAX_COLUMNS BUFSIZ /* this _has_ to be worst-case */ static char **parse_columns(char *buffer) diff --git a/lib/libcurses/tinfo/comp_parse.c b/lib/libcurses/tinfo/comp_parse.c index 954f8e10d37..b5cb6716e83 100644 --- a/lib/libcurses/tinfo/comp_parse.c +++ b/lib/libcurses/tinfo/comp_parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_parse.c,v 1.2 1999/02/24 06:31:10 millert Exp $ */ +/* $OpenBSD: comp_parse.c,v 1.3 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -54,10 +54,9 @@ #include <ctype.h> #include <tic.h> -#include <term.h> #include <term_entry.h> -MODULE_ID("$From: comp_parse.c,v 1.26 1999/02/19 10:38:13 tom Exp $") +MODULE_ID("$From: comp_parse.c,v 1.34 1999/02/27 22:13:02 tom Exp $") static void sanity_check(TERMTYPE *); void (*_nc_check_termtype)(TERMTYPE *) = sanity_check; @@ -88,13 +87,11 @@ ENTRY *_nc_head, *_nc_tail; static void enqueue(ENTRY *ep) /* add an entry to the in-core list */ { - ENTRY *newp = (ENTRY *)malloc(sizeof(ENTRY)); + ENTRY *newp = _nc_copy_entry(ep); if (newp == NULL) _nc_err_abort("Out of memory"); - (void) memcpy(newp, ep, sizeof(ENTRY)); - newp->last = _nc_tail; _nc_tail = newp; @@ -178,6 +175,7 @@ void _nc_read_entry_source(FILE *fp, char *buf, 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; ) { if (!isalnum(thisentry.tterm.term_names[0])) @@ -289,15 +287,16 @@ int _nc_resolve_uses(void) TERMTYPE thisterm; char filename[PATH_MAX]; + memset(&thisterm, 0, sizeof(thisterm)); if (_nc_read_entry(lookfor, filename, &thisterm) == 1) { DEBUG(2, ("%s: resolving use=%s (compiled)", child, lookfor)); - rp = (ENTRY *)malloc(sizeof(ENTRY)); + rp = typeMalloc(ENTRY,1); if (rp == NULL) _nc_err_abort("Out of memory"); - memcpy(&rp->tterm, &thisterm, sizeof(TERMTYPE)); + rp->tterm = thisterm; rp->nuses = 0; rp->next = lastread; lastread = rp; @@ -338,6 +337,7 @@ int _nc_resolve_uses(void) keepgoing = FALSE; for_entry_list(qp) + { if (qp->nuses > 0) { DEBUG(2, ("%s: attempting merge", _nc_first_name(qp->tterm.term_names))); @@ -359,7 +359,7 @@ int _nc_resolve_uses(void) * as a side effect, copy into the merged entry the name * field and string table pointer. */ - memcpy(&merged, &qp->tterm, sizeof(TERMTYPE)); + _nc_copy_termtype(&merged, &(qp->tterm)); /* * Now merge in each use entry in the proper @@ -377,7 +377,10 @@ int _nc_resolve_uses(void) /* * Replace the original entry with the merged one. */ - memcpy(&qp->tterm, &merged, sizeof(TERMTYPE)); + FreeIfNeeded(qp->tterm.Booleans); + FreeIfNeeded(qp->tterm.Numbers); + FreeIfNeeded(qp->tterm.Strings); + qp->tterm = merged; /* * We know every entry is resolvable because name resolution @@ -387,6 +390,7 @@ int _nc_resolve_uses(void) incomplete: keepgoing = TRUE; } + } } while (keepgoing); @@ -399,13 +403,13 @@ int _nc_resolve_uses(void) */ for_entry_list(qp) { - for (j = 0; j < BOOLCOUNT; j++) + for_each_boolean(j, &(qp->tterm)) if (qp->tterm.Booleans[j] == CANCELLED_BOOLEAN) qp->tterm.Booleans[j] = FALSE; - for (j = 0; j < NUMCOUNT; j++) + for_each_number(j, &(qp->tterm)) if (qp->tterm.Numbers[j] == CANCELLED_NUMERIC) qp->tterm.Numbers[j] = ABSENT_NUMERIC; - for (j = 0; j < STRCOUNT; j++) + for_each_string(j, &(qp->tterm)) if (qp->tterm.Strings[j] == CANCELLED_STRING) qp->tterm.Strings[j] = ABSENT_STRING; } diff --git a/lib/libcurses/tinfo/doalloc.c b/lib/libcurses/tinfo/doalloc.c index a4d293e77ec..43b6017e35c 100644 --- a/lib/libcurses/tinfo/doalloc.c +++ b/lib/libcurses/tinfo/doalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doalloc.c,v 1.1 1999/01/18 19:10:15 millert Exp $ */ +/* $OpenBSD: doalloc.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> -MODULE_ID("$From: doalloc.c,v 1.2 1998/08/18 22:52:39 Hans-Joachim.Widmaier Exp $") +MODULE_ID("$From: doalloc.c,v 1.4 1999/02/27 19:58:33 tom Exp $") void *_nc_doalloc(void *oldp, size_t amount) { @@ -54,7 +54,23 @@ void *_nc_doalloc(void *oldp, size_t amount) errno = ENOMEM; /* just in case 'free' reset */ } } else { - newp = malloc(amount); + newp = typeMalloc(char, amount); } return newp; } + +#if !HAVE_STRDUP +char *_nc_strdup(char *src) +{ + char *dst; + if (src != 0) { + char *dst = typeMalloc(char, strlen(src) + 1); + if (dst != 0) { + (void)strcpy(dst, src): + } + } else { + dst = 0; + } + return dst; +} +#endif diff --git a/lib/libcurses/tinfo/free_ttype.c b/lib/libcurses/tinfo/free_ttype.c new file mode 100644 index 00000000000..68fc4cff683 --- /dev/null +++ b/lib/libcurses/tinfo/free_ttype.c @@ -0,0 +1,74 @@ +/* $OpenBSD: free_ttype.c,v 1.1 1999/03/02 06:23:28 millert Exp $ */ + +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ + + +/* + * free_ttype.c -- allocation functions for TERMTYPE + * + * _nc_free_termtype() + * use_extended_names() + * + */ + +#include <curses.priv.h> + +#include <tic.h> +#include <term_entry.h> + +MODULE_ID("$Id: free_ttype.c,v 1.1 1999/03/02 06:23:28 millert Exp $") + +void _nc_free_termtype(TERMTYPE *ptr) +{ + FreeIfNeeded(ptr->str_table); + FreeIfNeeded(ptr->term_names); +#if NCURSES_XNAMES + FreeIfNeeded(ptr->ext_str_table); + FreeIfNeeded(ptr->Booleans); + FreeIfNeeded(ptr->Numbers); + FreeIfNeeded(ptr->Strings); + FreeIfNeeded(ptr->ext_Names); +#endif + memset(ptr, 0, sizeof(TERMTYPE)); +} + +#if NCURSES_XNAMES +bool _nc_user_definable = TRUE; + +int use_extended_names(bool flag) +{ + int oldflag = _nc_user_definable; + _nc_user_definable = flag; + return oldflag; +} +#endif diff --git a/lib/libcurses/tinfo/home_terminfo.c b/lib/libcurses/tinfo/home_terminfo.c index be4feaf927f..4b72613f134 100644 --- a/lib/libcurses/tinfo/home_terminfo.c +++ b/lib/libcurses/tinfo/home_terminfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: home_terminfo.c,v 1.1 1999/01/18 19:10:15 millert Exp $ */ +/* $OpenBSD: home_terminfo.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -39,7 +39,7 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$From: home_terminfo.c,v 1.1 1998/09/19 21:25:03 tom Exp $") +MODULE_ID("$From: home_terminfo.c,v 1.2 1999/02/27 19:58:46 tom Exp $") #define my_length (strlen(home) + sizeof(PRIVATE_INFO)) @@ -54,7 +54,7 @@ _nc_home_terminfo(void) if (temp == 0) { if ((home = getenv("HOME")) != 0 && my_length <= PATH_MAX) { - temp = malloc(my_length); + temp = typeMalloc(char, my_length); if (temp == 0) _nc_err_abort("Out of memory"); (void) sprintf(temp, PRIVATE_INFO, home); diff --git a/lib/libcurses/tinfo/lib_cur_term.c b/lib/libcurses/tinfo/lib_cur_term.c index 0429da48316..782c1fff767 100644 --- a/lib/libcurses/tinfo/lib_cur_term.c +++ b/lib/libcurses/tinfo/lib_cur_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_cur_term.c,v 1.1 1999/01/18 19:10:17 millert Exp $ */ +/* $OpenBSD: lib_cur_term.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -39,10 +39,10 @@ */ #include <curses.priv.h> -#include <term.h> /* TTY, cur_term */ +#include <term_entry.h> /* TTY, cur_term */ #include <termcap.h> /* ospeed */ -MODULE_ID("$From: lib_cur_term.c,v 1.6 1999/01/10 00:48:44 tom Exp $") +MODULE_ID("$From: lib_cur_term.c,v 1.7 1999/02/22 18:41:09 tom Exp $") TERMINAL *cur_term; @@ -62,8 +62,7 @@ int del_curterm(TERMINAL *term) T((T_CALLED("del_curterm(%p)"), term)); if (term != 0) { - FreeIfNeeded(term->type.str_table); - FreeIfNeeded(term->type.term_names); + _nc_free_termtype(&(term->type)); free(term); if (term == cur_term) cur_term = 0; diff --git a/lib/libcurses/tinfo/lib_print.c b/lib/libcurses/tinfo/lib_print.c index 2d872a665ed..a42bccf6f21 100644 --- a/lib/libcurses/tinfo/lib_print.c +++ b/lib/libcurses/tinfo/lib_print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_print.c,v 1.1 1999/01/18 19:10:19 millert Exp $ */ +/* $OpenBSD: lib_print.c,v 1.2 1999/03/02 06:23:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -38,7 +38,7 @@ #include <term.h> -MODULE_ID("$From: lib_print.c,v 1.10 1998/10/13 14:47:53 Alexander.V.Lukyanov Exp $") +MODULE_ID("$From: lib_print.c,v 1.11 1999/02/27 19:59:05 tom Exp $") int mcprint(char *data, int len) /* ship binary character data to the printer via mc4/mc5/mc5p */ @@ -66,7 +66,7 @@ int mcprint(char *data, int len) offsize = strlen(prtr_off); } - if ((mybuf = malloc(onsize + len + offsize + 1)) == (char *)NULL) + if ((mybuf = typeMalloc(char, onsize + len + offsize + 1)) == (char *)0) { errno = ENOMEM; return(ERR); diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c index 7ff479cca77..f496c05f992 100644 --- a/lib/libcurses/tinfo/lib_setup.c +++ b/lib/libcurses/tinfo/lib_setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_setup.c,v 1.2 1999/01/22 04:50:43 millert Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.3 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -43,6 +43,7 @@ #include <curses.priv.h> #include <tic.h> /* for MAX_NAME_SIZE */ +#include <term_entry.h> #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -50,7 +51,7 @@ #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$From: lib_setup.c,v 1.48 1999/01/02 23:11:56 tom Exp $") +MODULE_ID("$From: lib_setup.c,v 1.51 1999/02/27 22:13:00 tom Exp $") /**************************************************************************** * @@ -263,11 +264,11 @@ static int grab_entry(const char *const tn, TERMTYPE *const tp) * a string is cancelled, for merging entries). */ if (status == 1) { - unsigned n; - for (n = 0; n < BOOLCOUNT; n++) + int n; + for_each_boolean(n,tp) if (!VALID_BOOLEAN(tp->Booleans[n])) tp->Booleans[n] = FALSE; - for (n = 0; n < STRCOUNT; n++) + for_each_string(n,tp) if (tp->Strings[n] == CANCELLED_STRING) tp->Strings[n] = ABSENT_STRING; } @@ -323,7 +324,7 @@ int status; if (fallback) { - memcpy(&term_ptr->type, fallback, sizeof(TERMTYPE)); + term_ptr->type = *fallback; status = 1; } } @@ -380,7 +381,7 @@ int status; static void do_prototype(void) { -int i, j; +int i; char CC; char proto; char *tmp; @@ -389,12 +390,10 @@ char *tmp; CC = *tmp; proto = *command_character; - for (i=0; i < STRCOUNT; i++) { - j = 0; - while (cur_term->type.Strings[i][j]) { - if (cur_term->type.Strings[i][j] == proto) - cur_term->type.Strings[i][j] = CC; - j++; - } + for_each_string(i, &(cur_term->type)) { + for (tmp = cur_term->type.Strings[i]; *tmp; tmp++) { + if (*tmp == proto) + *tmp = CC; + } } } diff --git a/lib/libcurses/tinfo/lib_termcap.c b/lib/libcurses/tinfo/lib_termcap.c index e50b4a622da..e7e76cd5b5c 100644 --- a/lib/libcurses/tinfo/lib_termcap.c +++ b/lib/libcurses/tinfo/lib_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_termcap.c,v 1.1 1999/01/18 19:10:19 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -39,9 +39,9 @@ #include <tic.h> #define __INTERNAL_CAPS_VISIBLE -#include <term.h> +#include <term_entry.h> -MODULE_ID("$From: lib_termcap.c,v 1.25 1999/01/10 00:48:11 tom Exp $") +MODULE_ID("$From: lib_termcap.c,v 1.28 1999/02/27 22:12:58 tom Exp $") /* some of the code in here was contributed by: @@ -115,12 +115,14 @@ int i; T((T_CALLED("tgetflag(%s)"), id)); if (cur_term != 0) { - for (i = 0; i < BOOLCOUNT; i++) { - if (!strncmp(id, boolcodes[i], 2)) { - /* setupterm forces invalid booleans to false */ - returnCode(cur_term->type.Booleans[i]); - } + 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 */ } @@ -140,13 +142,15 @@ int i; T((T_CALLED("tgetnum(%s)"), id)); if (cur_term != 0) { - for (i = 0; i < NUMCOUNT; i++) { - if (!strncmp(id, numcodes[i], 2)) { - if (!VALID_NUMERIC(cur_term->type.Numbers[i])) - return -1; - returnCode(cur_term->type.Numbers[i]); - } + 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]); } + } } returnCode(ERR); } @@ -166,14 +170,16 @@ int i; T((T_CALLED("tgetstr(%s,%p)"), id, area)); if (cur_term != 0) { - for (i = 0; i < STRCOUNT; i++) { - T(("trying %s", strcodes[i])); - if (!strncmp(id, strcodes[i], 2)) { - T(("found match : %s", _nc_visbuf(cur_term->type.Strings[i]))); - /* setupterm forces cancelled strings to null */ - returnPtr(cur_term->type.Strings[i]); - } + 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 */ + returnPtr(tp->Strings[i]); } + } } returnPtr(NULL); } diff --git a/lib/libcurses/tinfo/lib_ti.c b/lib/libcurses/tinfo/lib_ti.c index 6d2d792df6e..bfa484cfd95 100644 --- a/lib/libcurses/tinfo/lib_ti.c +++ b/lib/libcurses/tinfo/lib_ti.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_ti.c,v 1.1 1999/01/18 19:10:20 millert Exp $ */ +/* $OpenBSD: lib_ti.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -36,10 +36,10 @@ #include <curses.priv.h> -#include <term.h> +#include <term_entry.h> #include <tic.h> -MODULE_ID("$From: lib_ti.c,v 1.13 1999/01/03 01:44:27 tom Exp $") +MODULE_ID("$From: lib_ti.c,v 1.16 1999/02/28 23:11:28 tom Exp $") int tigetflag(NCURSES_CONST char *str) { @@ -48,12 +48,14 @@ int i; T((T_CALLED("tigetflag(%s)"), str)); if (cur_term != 0) { - for (i = 0; i < BOOLCOUNT; i++) { - if (!strcmp(str, boolnames[i])) { - /* setupterm forces invalid booleans to false */ - returnCode(cur_term->type.Booleans[i]); - } + 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); @@ -66,13 +68,15 @@ int i; T((T_CALLED("tigetnum(%s)"), str)); if (cur_term != 0) { - for (i = 0; i < NUMCOUNT; i++) { - if (!strcmp(str, numnames[i])) { - if (!VALID_NUMERIC(cur_term->type.Numbers[i])) - return -1; - returnCode(cur_term->type.Numbers[i]); - } + 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]); } + } } returnCode(CANCELLED_NUMERIC); /* Solaris returns a -1 instead */ @@ -85,12 +89,14 @@ int i; T((T_CALLED("tigetstr(%s)"), str)); if (cur_term != 0) { - for (i = 0; i < STRCOUNT; i++) { - if (!strcmp(str, strnames[i])) { - /* setupterm forces cancelled strings to null */ - returnPtr(cur_term->type.Strings[i]); - } + 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); diff --git a/lib/libcurses/tinfo/lib_tparm.c b/lib/libcurses/tinfo/lib_tparm.c index 87fad7291c7..709d11e009e 100644 --- a/lib/libcurses/tinfo/lib_tparm.c +++ b/lib/libcurses/tinfo/lib_tparm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tparm.c,v 1.1 1999/01/18 19:10:20 millert Exp $ */ +/* $OpenBSD: lib_tparm.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -45,7 +45,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: lib_tparm.c,v 1.37 1999/01/02 22:38:25 tom Exp $") +MODULE_ID("$From: lib_tparm.c,v 1.38 1999/02/27 20:08:22 tom Exp $") /* * char * @@ -136,7 +136,7 @@ void _nc_free_tparm(void) static void really_get_space(size_t need) { out_size = need * 2; - out_buff = (char *)_nc_doalloc(out_buff, out_size); + out_buff = typeRealloc(char, out_size, out_buff); if (out_buff == 0) _nc_err_abort("Out of memory"); } @@ -314,7 +314,7 @@ static int static_vars[NUM_VARS]; } if ((size_t)(cp - string) > len_fmt) { len_fmt = (cp - string) + len_fmt + 2; - if ((format = _nc_doalloc(format, len_fmt)) == 0) + if ((format = typeRealloc(char, len_fmt, format)) == 0) return 0; } @@ -564,7 +564,7 @@ static int static_vars[NUM_VARS]; string++; } /* endwhile (*string) */ - if (out_buff == 0 && (out_buff = calloc(1,1)) == NULL) + if (out_buff == 0 && (out_buff = typeCalloc(char,1)) == NULL) return(NULL); out_buff[out_used] = '\0'; diff --git a/lib/libcurses/tinfo/lib_tputs.c b/lib/libcurses/tinfo/lib_tputs.c index e4c778332df..19a1339033b 100644 --- a/lib/libcurses/tinfo/lib_tputs.c +++ b/lib/libcurses/tinfo/lib_tputs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tputs.c,v 1.1 1999/01/18 19:10:20 millert Exp $ */ +/* $OpenBSD: lib_tputs.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -48,7 +48,7 @@ #include <termcap.h> /* ospeed */ #include <tic.h> -MODULE_ID("$From: lib_tputs.c,v 1.38 1999/01/10 00:57:41 tom Exp $") +MODULE_ID("$From: lib_tputs.c,v 1.39 1999/02/25 10:44:29 tom Exp $") #define OUTPUT ((SP != 0) ? SP->_ofp : stdout) @@ -121,7 +121,7 @@ char addrbuf[32]; } #endif /* TRACE */ - if (string == ABSENT_STRING || string == CANCELLED_STRING) + if (!VALID_STRING(string)) return ERR; if (cur_term == 0) { diff --git a/lib/libcurses/tinfo/make_keys.c b/lib/libcurses/tinfo/make_keys.c index 876b942cb09..afc60725e3a 100644 --- a/lib/libcurses/tinfo/make_keys.c +++ b/lib/libcurses/tinfo/make_keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: make_keys.c,v 1.2 1999/02/24 06:31:11 millert Exp $ */ +/* $OpenBSD: make_keys.c,v 1.3 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -39,7 +39,7 @@ */ #include <curses.priv.h> -MODULE_ID("$From: make_keys.c,v 1.5 1999/02/18 22:38:41 tom Exp $") +MODULE_ID("$From: make_keys.c,v 1.6 1999/02/22 16:55:20 tom Exp $") #include <names.c> @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) 0 }; static const char *suffix[] = { - " { 0, 0} };", + "\t{ 0, 0} };", "", "#endif /* NCU_KEYS_H */", 0 diff --git a/lib/libcurses/tinfo/parse_entry.c b/lib/libcurses/tinfo/parse_entry.c index ed44a9840d7..e75680138d9 100644 --- a/lib/libcurses/tinfo/parse_entry.c +++ b/lib/libcurses/tinfo/parse_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: parse_entry.c,v 1.1 1999/01/18 19:10:21 millert Exp $ */ +/* $OpenBSD: parse_entry.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1999 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -48,10 +48,9 @@ #include <ctype.h> #include <tic.h> #define __INTERNAL_CAPS_VISIBLE -#include <term.h> #include <term_entry.h> -MODULE_ID("$From: parse_entry.c,v 1.24 1998/07/04 23:08:38 tom Exp $") +MODULE_ID("$From: parse_entry.c,v 1.39 1999/03/01 02:28:51 tom Exp $") #ifdef LINT static short const parametrized[] = { 0 }; @@ -65,6 +64,116 @@ 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 temp; + TERMTYPE *tp = &(entryp->tterm); + unsigned offset = 0; + unsigned actual; + unsigned tindex; + unsigned first, last, n; + bool found; + + switch (token_type) { + case BOOLEAN: + first = 0; + last = tp->ext_Booleans; + offset = tp->ext_Booleans; + tindex = tp->num_Booleans; + break; + case NUMBER: + first = tp->ext_Booleans; + last = tp->ext_Numbers + first; + offset = tp->ext_Booleans + tp->ext_Numbers; + tindex = tp->num_Numbers; + break; + case STRING: + first = tp->ext_Booleans + tp->ext_Numbers; + last = tp->ext_Strings + first; + offset = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings; + tindex = tp->num_Strings; + break; + case CANCEL: + actual = NUM_EXT_NAMES(tp); + for (n = 0; n < actual; n++) { + if (!strcmp(name, tp->ext_Names[n])) { + if (n > (unsigned)(tp->ext_Booleans + tp->ext_Numbers)) { + token_type = STRING; + } else if (n > tp->ext_Booleans) { + token_type = NUMBER; + } else { + token_type = BOOLEAN; + } + return _nc_extend_names(entryp, name, token_type); + } + } + /* Well, we are given a cancel for a name that we don't recognize */ + return _nc_extend_names(entryp, name, STRING); + default: + return 0; + } + + /* Adjust the 'offset' (insertion-point) to keep the lists of extended + * names sorted. + */ + for (n = first, found = FALSE; n < last; n++) { + int cmp = strcmp(tp->ext_Names[n], name); + if (cmp == 0) + found = TRUE; + if (cmp >= 0) { + offset = n; + tindex = n - first; + switch (token_type) { + case BOOLEAN: tindex += BOOLCOUNT; break; + case NUMBER: tindex += NUMCOUNT; break; + case STRING: tindex += STRCOUNT; break; + } + break; + } + } + if (!found) { + switch (token_type) { + case BOOLEAN: + tp->ext_Booleans += 1; + tp->num_Booleans += 1; + tp->Booleans = typeRealloc(char, tp->num_Booleans, tp->Booleans); + for (last = tp->num_Booleans-1; last > tindex; last--) + tp->Booleans[last] = tp->Booleans[last-1]; + break; + case NUMBER: + tp->ext_Numbers += 1; + tp->num_Numbers += 1; + tp->Numbers = typeRealloc(short, tp->num_Numbers, tp->Numbers); + for (last = tp->num_Numbers-1; last > tindex; last--) + tp->Numbers[last] = tp->Numbers[last-1]; + break; + case STRING: + tp->ext_Strings += 1; + tp->num_Strings += 1; + tp->Strings = typeRealloc(char *, tp->num_Strings, tp->Strings); + for (last = tp->num_Strings-1; last > tindex; last--) + tp->Strings[last] = tp->Strings[last-1]; + break; + } + actual = NUM_EXT_NAMES(tp); + tp->ext_Names = typeRealloc(char *, actual, tp->ext_Names); + while (--actual > offset) + tp->ext_Names[actual] = tp->ext_Names[actual-1]; + tp->ext_Names[offset] = _nc_save_str(name); + } + + temp.nte_name = tp->ext_Names[offset]; + temp.nte_type = token_type; + temp.nte_index = tindex; + temp.nte_link = -1; + + return &temp; +} +#endif /* NCURSES_XNAMES */ + /* * int * _nc_parse_entry(entry, literal, silent) @@ -198,13 +307,24 @@ int _nc_parse_entry(struct entry *entryp, int literal, bool silent) break; } - /* last chance: a full-name */ if (entry_ptr == NOTFOUND) { entry_ptr = lookup_fullname(_nc_curr_token.tk_name); } } } +#if NCURSES_XNAMES + /* + * If we have extended-names active, we will automatically + * define a name based on its context. + */ + if (entry_ptr == NOTFOUND + && _nc_user_definable + && (entry_ptr = _nc_extend_names(entryp, _nc_curr_token.tk_name, token_type)) != 0) { + _nc_warning("extended capability '%s'", _nc_curr_token.tk_name); + } +#endif /* NCURSES_XNAMES */ + /* can't find this cap name, not even as an alias */ if (entry_ptr == NOTFOUND) { if (!silent) @@ -342,7 +462,7 @@ 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(entryp->uses[i].parent, '+')) + if (!strchr((char *)entryp->uses[i].parent, '+')) has_base_entry = TRUE; postprocess_termcap(&entryp->tterm, has_base_entry); diff --git a/lib/libcurses/tinfo/read_bsd_terminfo.c b/lib/libcurses/tinfo/read_bsd_terminfo.c index 211e4c3e052..ef57727825c 100644 --- a/lib/libcurses/tinfo/read_bsd_terminfo.c +++ b/lib/libcurses/tinfo/read_bsd_terminfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_bsd_terminfo.c,v 1.4 1999/02/01 20:55:41 millert Exp $ */ +/* $OpenBSD: read_bsd_terminfo.c,v 1.5 1999/03/02 06:23:29 millert Exp $ */ /* * Copyright (c) 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com> @@ -32,7 +32,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: read_bsd_terminfo.c,v 1.4 1999/02/01 20:55:41 millert Exp $"; +static char rcsid[] = "$OpenBSD: read_bsd_terminfo.c,v 1.5 1999/03/02 06:23:29 millert Exp $"; #endif #include <curses.priv.h> @@ -175,19 +175,19 @@ _nc_lookup_bsd_terminfo_entry(tn, filename, tp) _nc_warning("alias `%s' may be too long", p); /* Copy capabilities */ - for (i = 0 ; i < BOOLCOUNT ; i++) { + for_each_boolean(i, tp) { if (cgetcap(capbuf, (char *)boolnames[i], ':') == NULL) tp->Booleans[i] = FALSE; else tp->Booleans[i] = TRUE; } - for (i = 0 ; i < NUMCOUNT ; i++) { + for_each_number(i, tp) { if (cgetnum(capbuf, (char *)numnames[i], &num) < 0) tp->Numbers[i] = 0; else tp->Numbers[i] = (int)num; } - for (i = 0 ; i < STRCOUNT ; i++) { + for_each_string(i, tp) { if (cgetstr(capbuf, (char *)strnames[i], &p) < 0) tp->Strings[i] = NULL; else diff --git a/lib/libcurses/tinfo/read_entry.c b/lib/libcurses/tinfo/read_entry.c index 133152bbaef..09902edc114 100644 --- a/lib/libcurses/tinfo/read_entry.c +++ b/lib/libcurses/tinfo/read_entry.c @@ -1,7 +1,7 @@ -/* $OpenBSD: read_entry.c,v 1.3 1999/01/23 18:31:02 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.4 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1999 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -46,16 +46,21 @@ #include <fcntl.h> #endif -#include <term.h> #include <tic.h> #include <term_entry.h> -MODULE_ID("$From: read_entry.c,v 1.47 1998/12/20 02:51:50 tom Exp $") +MODULE_ID("$From: read_entry.c,v 1.60 1999/03/01 23:59:28 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*/ +#endif + /* * int * _nc_read_file_entry(filename, ptr) @@ -107,60 +112,101 @@ void _nc_keep_tic_dir(const char *path) keep_tic_directory = TRUE; } -int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) -/* return 1 if read, 0 if not found or garbled */ +static void convert_shorts(char *buf, short *Numbers, int count) { - int name_size, bool_count, num_count, str_count, str_size; - int i, fd, numread; - char buf[MAX_ENTRY_SIZE]; + int i; + for (i = 0; i < count; i++) + { + if (IS_NEG1(buf + 2*i)) + Numbers[i] = ABSENT_NUMERIC; + 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])); + } +} -#ifdef __OpenBSD__ - if (_nc_read_bsd_terminfo_file(filename, ptr) == 1) - return(1); -#endif /* __OpenBSD__ */ +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)) { + Strings[i] = ABSENT_STRING; + } else if (IS_NEG2(buf + 2*i)) { + Strings[i] = CANCELLED_STRING; + } 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]))); + } - if (_nc_access(filename, R_OK) < 0 - || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) { - T(("cannot open terminfo %s (errno=%d)", filename, errno)); - return(0); + /* make sure all strings are NUL terminated */ + if (VALID_STRING(Strings[i])) { + for (p = Strings[i]; p <= table + size; p++) + if (*p == '\0') + break; + /* if there is no NUL, ignore the string */ + if (p > table + size) + Strings[i] = ABSENT_STRING; + } } +} - T(("read terminfo %s", filename)); +#define read_shorts(fd, buf, count) (read(fd, buf, (count)*2) == (count)*2) + +#define even_boundary(value) \ + if ((value) % 2 != 0) read(fd, buf, 1) + +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]; + + TRACE_IN(("READ termtype header @%d", tell(fd))); /* grab the header */ - (void) read(fd, buf, 12); - if (LOW_MSB(buf) != MAGIC) - { - close(fd); + if (!read_shorts(fd, buf, 6) + || LOW_MSB(buf) != MAGIC) { return(0); } + + _nc_free_termtype(ptr); 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); - if (str_size) - { + 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); + } + + if (str_size) { /* try to allocate space for the string table */ - ptr->str_table = malloc((unsigned)str_size); - if (ptr->str_table == 0) - { - close(fd); + if (str_count*2 >= (int) sizeof(buf) + || (ptr->str_table = typeMalloc(char, (unsigned)str_size)) == 0) { return(0); } - } - else + } else { str_count = 0; + } - /* grab the name */ + /* grab the name (a null-terminate string) */ read(fd, buf, min(MAX_NAME_SIZE, (unsigned)name_size)); buf[MAX_NAME_SIZE] = '\0'; - ptr->term_names = calloc(strlen(buf) + 1, sizeof(char)); + ptr->term_names = typeCalloc(char, strlen(buf) + 1); if (ptr->term_names == NULL) { - if (str_size) - free(ptr->str_table); - close(fd); return(0); } (void) strcpy(ptr->term_names, buf); @@ -168,12 +214,10 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) lseek(fd, (off_t) (name_size - MAX_NAME_SIZE), 1); /* grab the booleans */ - read(fd, ptr->Booleans, min(BOOLCOUNT, (unsigned)bool_count)); - if (bool_count > BOOLCOUNT) - lseek(fd, (off_t) (bool_count - BOOLCOUNT), 1); - else - for (i=bool_count; i < BOOLCOUNT; i++) - ptr->Booleans[i] = 0; + if ((ptr->Booleans = typeCalloc(char, max(BOOLCOUNT, bool_count))) == 0 + || read(fd, ptr->Booleans, (unsigned)bool_count) < bool_count) { + return(0); + } /* * If booleans end on an odd byte, skip it. The machine they @@ -181,90 +225,168 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) * word-oriented machine that would trap out if you tried a * word access off a 2-byte boundary. */ - if ((name_size + bool_count) % 2 != 0) - read(fd, buf, 1); + even_boundary(name_size + bool_count); /* grab the numbers */ - (void) read(fd, buf, min(NUMCOUNT*2, (unsigned)num_count*2)); - for (i = 0; i < min(num_count, NUMCOUNT); i++) - { - if (IS_NEG1(buf + 2*i)) - ptr->Numbers[i] = ABSENT_NUMERIC; - else if (IS_NEG2(buf + 2*i)) - ptr->Numbers[i] = CANCELLED_NUMERIC; - else - ptr->Numbers[i] = LOW_MSB(buf + 2*i); + if ((ptr->Numbers = typeCalloc(short, max(NUMCOUNT, num_count))) == 0 + || !read_shorts(fd, buf, num_count)) { + return(0); } - if (num_count > NUMCOUNT) - lseek(fd, (off_t) (2 * (num_count - NUMCOUNT)), 1); - else - for (i=num_count; i < NUMCOUNT; i++) - ptr->Numbers[i] = ABSENT_NUMERIC; + convert_shorts(buf, ptr->Numbers, num_count); + + if ((ptr->Strings = typeCalloc(char *, max(STRCOUNT, str_count))) == 0) + return(0); if (str_count) { - if (str_count*2 >= MAX_ENTRY_SIZE) - { - close(fd); - return(0); - } /* grab the string offsets */ - numread = read(fd, buf, (unsigned)(str_count*2)); - if (numread < str_count*2) - { - close(fd); + if (!read_shorts(fd, buf, str_count)) { return(0); } - for (i = 0; i < numread/2; i++) - { - if (i >= STRCOUNT) - break; - if (IS_NEG1(buf + 2*i)) - ptr->Strings[i] = ABSENT_STRING; - else if (IS_NEG2(buf + 2*i)) - ptr->Strings[i] = CANCELLED_STRING; - else if (LOW_MSB(buf + 2*i) > str_size) - ptr->Strings[i] = ABSENT_STRING; - else - ptr->Strings[i] = (LOW_MSB(buf+2*i) + ptr->str_table); - } + /* finally, grab the string table itself */ + 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 (str_count > STRCOUNT) - lseek(fd, (off_t) (2 * (str_count - STRCOUNT)), 1); - else - for (i = str_count; i < STRCOUNT; i++) - ptr->Strings[i] = ABSENT_STRING; +#if NCURSES_XNAMES - if (str_size) - { - /* finally, grab the string table itself */ - numread = read(fd, ptr->str_table, (unsigned)str_size); - if (numread != str_size) - { - close(fd); + ptr->num_Booleans = BOOLCOUNT; + 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))); + 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 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); + + ptr->num_Booleans = BOOLCOUNT + ext_bool_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->Numbers = typeRealloc(short, ptr->num_Numbers, ptr->Numbers); + 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)); + + TRACE_IN(("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); } - } + even_boundary(ext_bool_count); - /* make sure all strings are NUL terminated */ - for (i = str_count; i < STRCOUNT; i++) { - char *p; + TRACE_IN(("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")); + convert_shorts(buf, ptr->Numbers + NUMCOUNT, ext_num_count); + } - if (VALID_STRING(ptr->Strings[i])) { - for (p = ptr->Strings[i]; p <= ptr->str_table + str_size; p++) - if (*p == '\0') - break; - /* if there is no NUL, ignore the string */ - if (p > ptr->str_table + str_size) - ptr->Strings[i] = ABSENT_STRING; + TRACE_IN(("READ extended-offsets @%d", tell(fd))); + if ((ext_str_count || need) + && !read_shorts(fd, buf, ext_str_count+need)) + return(0); + + 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); + 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))); + } + + 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]))); + } + } + + 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); } + + 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)); + + TRACE_IN(("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)); } - close(fd); + for (i = bool_count; i < BOOLCOUNT; i++) + ptr->Booleans[i] = FALSE; + for (i = num_count; i < NUMCOUNT; i++) + ptr->Numbers[i] = ABSENT_NUMERIC; + for (i = str_count; i < STRCOUNT; i++) + ptr->Strings[i] = ABSENT_STRING; + return(1); } +int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) +/* return 1 if read, 0 if not found or garbled */ +{ + int code, fd; + +#ifdef __OpenBSD__ + if (_nc_read_bsd_terminfo_file(filename, ptr) == 1) + return(1); +#endif /* __OpenBSD__ */ + + if (_nc_access(filename, R_OK) < 0 + || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) { + T(("cannot open terminfo %s (errno=%d)", filename, errno)); + return(0); + } + + T(("read terminfo %s", filename)); + if ((code = read_termtype(fd, ptr)) == 0) + _nc_free_termtype(ptr); + close(fd); + + return (code); +} + /* * Build a terminfo pathname and try to read the data. Returns 1 on success, * 0 on failure. @@ -292,9 +414,8 @@ static int _nc_read_terminfo_dirs(const char *dirs, char *const filename, const int code = 0; /* we'll modify the argument, so we must copy */ - if ((b = a = list = malloc(strlen(dirs) + 1)) == NULL) + if ((b = a = list = strdup(dirs)) == NULL) return(0); - (void) strcpy(list, dirs); for (;;) { int c = *a; @@ -351,7 +472,7 @@ char ttn[MAX_ALIAS + 3]; && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) return 1; - if (!issetugid() && (envp = _nc_home_terminfo()) != 0) { + if ((envp = _nc_home_terminfo()) != 0) { if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { return(1); } diff --git a/lib/libcurses/tinfo/read_termcap.c b/lib/libcurses/tinfo/read_termcap.c index de240b648f3..5f0a542132f 100644 --- a/lib/libcurses/tinfo/read_termcap.c +++ b/lib/libcurses/tinfo/read_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_termcap.c,v 1.1 1999/01/18 19:10:22 millert Exp $ */ +/* $OpenBSD: read_termcap.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -55,7 +55,6 @@ #include <curses.priv.h> #include <ctype.h> -#include <term.h> #include <tic.h> #include <term_entry.h> @@ -63,7 +62,7 @@ #include <fcntl.h> #endif -MODULE_ID("$From: read_termcap.c,v 1.37 1998/09/19 21:42:14 tom Exp $") +MODULE_ID("$From: read_termcap.c,v 1.41 1999/02/27 22:12:54 tom Exp $") #ifndef PURE_TERMINFO @@ -159,7 +158,7 @@ _nc_cgetset(const char *ent) return (0); } topreclen = strlen(ent); - if ((toprec = malloc (topreclen + 1)) == 0) { + if ((toprec = typeMalloc(char, topreclen + 1)) == 0) { errno = ENOMEM; return (-1); } @@ -262,7 +261,7 @@ _nc_cgetent(char **buf, int *oline, char **db_array, const char *name) * names interpolated, a name can't be found, or depth exceeds * MAX_RECURSION. */ -#define DOALLOC(size) (char *)_nc_doalloc(record, size) +#define DOALLOC(size) typeRealloc(char, size, record) static int _nc_getent( char **cap, /* termcap-content */ @@ -892,9 +891,8 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) * cgetent, then it is the actual filename). */ if (i >= 0) { - the_source = malloc(strlen(pathvec[i]) + 1); - if (the_source != 0) - *sourcename = strcpy(the_source, pathvec[i]); + if ((the_source = strdup(pathvec[i])) != 0) + *sourcename = the_source; } return(i); @@ -1083,7 +1081,7 @@ int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) * we disconnected from the list by NULLing out * ep->tterm.str_table above). */ - memcpy(tp, &ep->tterm, sizeof(TERMTYPE)); + *tp = ep->tterm; ep->tterm.str_table = (char *)0; /* diff --git a/lib/libcurses/tinfo/setbuf.c b/lib/libcurses/tinfo/setbuf.c index 677873b6da2..d798cce9611 100644 --- a/lib/libcurses/tinfo/setbuf.c +++ b/lib/libcurses/tinfo/setbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setbuf.c,v 1.2 1999/02/24 05:36:11 millert Exp $ */ +/* $OpenBSD: setbuf.c,v 1.3 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -44,7 +44,7 @@ #include <curses.priv.h> -MODULE_ID("$From: setbuf.c,v 1.4 1999/02/10 03:15:09 tom Exp $") +MODULE_ID("$From: setbuf.c,v 1.5 1999/02/27 20:00:15 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -115,7 +115,7 @@ void _nc_set_buffer(FILE *ofp, bool buffered) if ((SP->_buffered = buffered) != 0) { buf_len = min(LINES * (COLS + 6), 2800); if ((buf_ptr = SP->_setbuf) == 0) { - if ((buf_ptr = malloc(buf_len)) == NULL) + if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) return; SP->_setbuf = buf_ptr; /* Don't try to free this! */ diff --git a/lib/libcurses/tinfo/write_entry.c b/lib/libcurses/tinfo/write_entry.c index 22c20151790..a085849b491 100644 --- a/lib/libcurses/tinfo/write_entry.c +++ b/lib/libcurses/tinfo/write_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: write_entry.c,v 1.1 1999/01/18 19:10:23 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -44,14 +44,19 @@ #include <sys/stat.h> #include <tic.h> -#include <term.h> #include <term_entry.h> #ifndef S_ISDIR #define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) #endif -MODULE_ID("$From: write_entry.c,v 1.34 1998/12/20 02:49:27 tom Exp $") +#if 0 +#define TRACE_OUT(p) DEBUG(2, p) +#else +#define TRACE_OUT(p) /*nothing*/ +#endif + +MODULE_ID("$From: write_entry.c,v 1.45 1999/02/28 22:26:33 tom Exp $") static int total_written; @@ -139,7 +144,7 @@ void _nc_set_writedir(char *dir) if (chdir(_nc_tic_dir(destination)) < 0 || getcwd(actual, sizeof(actual)) == 0) _nc_err_abort("%s: not a directory", destination); - _nc_keep_tic_dir(strcpy(malloc(strlen(actual)+1), actual)); + _nc_keep_tic_dir(strdup(actual)); } /* @@ -353,6 +358,46 @@ static time_t start_time; /* time at start of writes */ #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) +{ + size_t nextfree = 0; + int i; + + for (i = 0; i < strmax; i++) { + if (Strings[i] == ABSENT_STRING) { + offsets[i] = -1; + } else if (Strings[i] == CANCELLED_STRING) { + offsets[i] = -2; + } else { + offsets[i] = nextfree; + nextfree += strlen(Strings[i]) + 1; + TRACE_OUT(("put Strings[%d]=%s(%d)", i, _nc_visbuf(Strings[i]), nextfree)); + } + } + return nextfree; +} + +static void convert_shorts(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; + } else { + LITTLE_ENDIAN(buf + 2*i, Numbers[i]); + TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i])); + } + } +} + +#define even_boundary(value) \ + ((value) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) + static int write_object(FILE *fp, TERMTYPE *tp) { char *namelist; @@ -360,38 +405,35 @@ size_t namelen, boolmax, nummax, strmax; char zero = '\0'; size_t i; short nextfree; -short offsets[STRCOUNT]; +short offsets[MAX_ENTRY_SIZE/2]; unsigned char buf[MAX_ENTRY_SIZE]; namelist = tp->term_names; namelen = strlen(namelist) + 1; + /* + * 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; + for (i = 0; i < BOOLWRITE; i++) { + if (tp->Booleans[i]) + boolmax = i+1; + } nummax = 0; - for (i = 0; i < NUMWRITE; i++) - if (tp->Numbers[i] != ABSENT_NUMERIC) - nummax = i+1; + for (i = 0; i < NUMWRITE; i++) { + if (tp->Numbers[i] != ABSENT_NUMERIC) + nummax = i+1; + } strmax = 0; - for (i = 0; i < STRWRITE; i++) - if (tp->Strings[i] != ABSENT_STRING) - strmax = i+1; + for (i = 0; i < STRWRITE; i++) { + if (tp->Strings[i] != ABSENT_STRING) + strmax = i+1; + } - nextfree = 0; - for (i = 0; i < strmax; i++) - if (tp->Strings[i] == ABSENT_STRING) - offsets[i] = -1; - else if (tp->Strings[i] == CANCELLED_STRING) - offsets[i] = -2; - else - { - offsets[i] = nextfree; - nextfree += strlen(tp->Strings[i]) + 1; - } + nextfree = compute_offsets(tp->Strings, strmax, offsets); /* fill in the header */ LITTLE_ENDIAN(buf, MAGIC); @@ -402,60 +444,110 @@ unsigned char buf[MAX_ENTRY_SIZE]; LITTLE_ENDIAN(buf+10, nextfree); /* write out the header */ + TRACE_OUT(("Header of %s @%ld", namelist, ftell(fp))); if (fwrite(buf, 12, 1, fp) != 1 - || fwrite(namelist, sizeof(char), (size_t)namelen, fp) != namelen - || fwrite(tp->Booleans, sizeof(char), (size_t)boolmax, fp) != boolmax) - return(ERR); + || fwrite(namelist, sizeof(char), namelen, fp) != namelen + || fwrite(tp->Booleans, sizeof(char), boolmax, fp) != boolmax) + return(ERR); - /* the even-boundary padding byte */ - if ((namelen+boolmax) % 2 != 0 && fwrite(&zero, sizeof(char), 1, fp) != 1) - return(ERR); + if (even_boundary(namelen+boolmax)) + return(ERR); -#ifdef SHOWOFFSET - (void) fprintf(stderr, "Numerics begin at %04lx\n", ftell(fp)); -#endif /* SHOWOFFSET */ + TRACE_OUT(("Numerics begin at %04lx", ftell(fp))); /* the numerics */ - for (i = 0; i < nummax; i++) - { - if (tp->Numbers[i] == -1) /* HI/LO won't work */ - buf[2*i] = buf[2*i + 1] = 0377; - else if (tp->Numbers[i] == -2) /* HI/LO won't work */ - buf[2*i] = 0376, buf[2*i + 1] = 0377; - else - LITTLE_ENDIAN(buf + 2*i, tp->Numbers[i]); - } - if (fwrite(buf, 2, (size_t)nummax, fp) != nummax) - return(ERR); + convert_shorts(buf, tp->Numbers, nummax); + if (fwrite(buf, 2, nummax, fp) != nummax) + return(ERR); -#ifdef SHOWOFFSET - (void) fprintf(stderr, "String offets begin at %04lx\n", ftell(fp)); -#endif /* SHOWOFFSET */ + TRACE_OUT(("String offsets begin at %04lx", ftell(fp))); /* the string offsets */ - for (i = 0; i < strmax; i++) - if (offsets[i] == -1) /* HI/LO won't work */ - buf[2*i] = buf[2*i + 1] = 0377; - else if (offsets[i] == -2) /* HI/LO won't work */ - { - buf[2*i] = 0376; - buf[2*i + 1] = 0377; - } - else - LITTLE_ENDIAN(buf + 2*i, offsets[i]); - if (fwrite(buf, 2, (size_t)strmax, fp) != strmax) - return(ERR); + convert_shorts(buf, offsets, strmax); + if (fwrite(buf, 2, strmax, fp) != strmax) + return(ERR); -#ifdef SHOWOFFSET - (void) fprintf(stderr, "String table begins at %04lx\n", ftell(fp)); -#endif /* SHOWOFFSET */ + TRACE_OUT(("String table begins at %04lx", ftell(fp))); /* the strings */ for (i = 0; i < strmax; i++) - if (tp->Strings[i] != ABSENT_STRING && tp->Strings[i] != CANCELLED_STRING) - if (fwrite(tp->Strings[i], sizeof(char), strlen(tp->Strings[i]) + 1, fp) != strlen(tp->Strings[i]) + 1) + 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); + } + + /* + * 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); } diff --git a/lib/libcurses/trace/trace_buf.c b/lib/libcurses/trace/trace_buf.c index 11117c5326b..4e0ed6ce21e 100644 --- a/lib/libcurses/trace/trace_buf.c +++ b/lib/libcurses/trace/trace_buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace_buf.c,v 1.1 1999/01/18 19:10:25 millert Exp $ */ +/* $OpenBSD: trace_buf.c,v 1.2 1999/03/02 06:23:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -37,7 +37,7 @@ #include <curses.priv.h> -MODULE_ID("$From: trace_buf.c,v 1.6 1998/08/15 23:37:25 tom Exp $") +MODULE_ID("$From: trace_buf.c,v 1.7 1999/02/27 19:50:58 tom Exp $") typedef struct { char *text; @@ -63,8 +63,7 @@ char * _nc_trace_buf(int bufnum, size_t want) if ((size_t)(bufnum+1) > have) { size_t need = (bufnum + 1) * 2; - size_t used = sizeof(*list) * need; - if ((list = (LIST *)_nc_doalloc(list, used)) == 0) + if ((list = typeRealloc(LIST, need, list)) == 0) return(0); while (need > have) list[have++].text = 0; @@ -73,7 +72,7 @@ char * _nc_trace_buf(int bufnum, size_t want) if (list[bufnum].text == 0 || want > list[bufnum].size) { - if ((list[bufnum].text = (char *)_nc_doalloc(list[bufnum].text, want)) != 0) + if ((list[bufnum].text = typeRealloc(char, want, list[bufnum].text)) != 0) list[bufnum].size = want; } diff --git a/lib/libcurses/trace/trace_tries.c b/lib/libcurses/trace/trace_tries.c index 27acd6d4ab7..2951c3ba0d3 100644 --- a/lib/libcurses/trace/trace_tries.c +++ b/lib/libcurses/trace/trace_tries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace_tries.c,v 1.1 1999/02/24 06:31:11 millert Exp $ */ +/* $OpenBSD: trace_tries.c,v 1.2 1999/03/02 06:23:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1999 Free Software Foundation, Inc. * @@ -37,7 +37,7 @@ #include <curses.priv.h> -MODULE_ID("$From: trace_tries.c,v 1.3 1999/02/19 04:05:26 tom Exp $") +MODULE_ID("$From: trace_tries.c,v 1.5 1999/02/28 23:42:28 tom Exp $") #ifdef TRACE static char *buffer; @@ -46,7 +46,7 @@ static unsigned len; static void recur_tries(struct tries *tree, unsigned level) { if (level > len) - buffer = realloc(buffer, len = (level + 1) * 4); + buffer = (char *)realloc(buffer, len = (level + 1) * 4); while (tree != 0) { if ((buffer[level] = tree->ch) == 0) @@ -63,7 +63,7 @@ static void recur_tries(struct tries *tree, unsigned level) void _nc_trace_tries(struct tries *tree) { - buffer = malloc(len = 80); + buffer = typeMalloc(char, len = 80); _tracef("BEGIN tries %p", tree); recur_tries(tree, 0); _tracef(". . . tries %p", tree); diff --git a/lib/libcurses/trace/trace_xnames.c b/lib/libcurses/trace/trace_xnames.c new file mode 100644 index 00000000000..6a761ee1cc1 --- /dev/null +++ b/lib/libcurses/trace/trace_xnames.c @@ -0,0 +1,76 @@ +/* $OpenBSD: trace_xnames.c,v 1.1 1999/03/02 06:23:30 millert Exp $ */ + +/**************************************************************************** + * Copyright (c) 1999 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1999 * + ****************************************************************************/ +/* + * trace_xnames.c - Tracing/Debugging buffers (TERMTYPE extended names) + */ + +#include <curses.priv.h> +#include <term_entry.h> + +MODULE_ID("$Id: trace_xnames.c,v 1.1 1999/03/02 06:23:30 millert Exp $") + +void _nc_trace_xnames(TERMTYPE *tp GCC_UNUSED) +{ +#ifdef TRACE +#if NCURSES_XNAMES + int limit = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings; + int n, m; + if (limit) { + int begin_num = tp->ext_Booleans; + int begin_str = tp->ext_Booleans + tp->ext_Numbers; + + _tracef("extended names (%s) %d = %d+%d+%d of %d+%d+%d", + tp->term_names, + limit, + tp->ext_Booleans, tp->ext_Numbers, tp->ext_Strings, + tp->num_Booleans, tp->num_Numbers, tp->num_Strings); + for (n = 0; n < limit; n++) { + if ((m = n - begin_str) >= 0) { + _tracef("[%d] %s = %s", n, + tp->ext_Names[n], + _nc_visbuf(tp->Strings[tp->num_Strings + m - tp->ext_Strings])); + } else if ((m = n - begin_num) >= 0) { + _tracef("[%d] %s = %d (num)", n, + tp->ext_Names[n], + tp->Numbers[tp->num_Numbers + m - tp->ext_Numbers]); + } else { + _tracef("[%d] %s = %d (bool)", n, + tp->ext_Names[n], + tp->Booleans[tp->num_Booleans + n - tp->ext_Booleans]); + } + } + } +#endif +#endif +} diff --git a/lib/libcurses/tty/hardscroll.c b/lib/libcurses/tty/hardscroll.c index f27ece1915b..2c88ed1f829 100644 --- a/lib/libcurses/tty/hardscroll.c +++ b/lib/libcurses/tty/hardscroll.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hardscroll.c,v 1.1 1999/01/18 19:10:25 millert Exp $ */ +/* $OpenBSD: hardscroll.c,v 1.2 1999/03/02 06:23:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -148,7 +148,7 @@ AUTHOR #include <curses.priv.h> -MODULE_ID("$From: hardscroll.c,v 1.32 1998/09/20 02:34:59 tom Exp $") +MODULE_ID("$From: hardscroll.c,v 1.33 1999/02/27 20:01:29 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -190,8 +190,7 @@ void _nc_scroll_optimize(void) /* get enough storage */ if (oldnums_allocated < screen_lines) { - size_t size = screen_lines * sizeof(*oldnums); - int *new_oldnums = oldnums ? realloc(oldnums, size) : malloc(size); + int *new_oldnums = typeRealloc(int, screen_lines, oldnums); if (!new_oldnums) return; oldnums = new_oldnums; @@ -271,7 +270,7 @@ void _nc_linedump(void) size_t want = (screen_lines + 1) * 4; if (have < want) - buf = malloc(have = want); + buf = typeMalloc(char, have = want); (void) strcpy(buf, "virt"); for (n = 0; n < screen_lines; n++) diff --git a/lib/libcurses/tty/hashmap.c b/lib/libcurses/tty/hashmap.c index 77cb0e19158..ec5617456a1 100644 --- a/lib/libcurses/tty/hashmap.c +++ b/lib/libcurses/tty/hashmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hashmap.c,v 1.1 1999/01/18 19:10:26 millert Exp $ */ +/* $OpenBSD: hashmap.c,v 1.2 1999/03/02 06:23:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -72,7 +72,7 @@ AUTHOR #include <curses.priv.h> #include <term.h> /* for back_color_erase */ -MODULE_ID("$From: hashmap.c,v 1.28 1998/09/20 02:35:15 tom Exp $") +MODULE_ID("$From: hashmap.c,v 1.29 1999/02/27 20:02:24 tom Exp $") #ifdef HASHDEBUG @@ -284,7 +284,7 @@ void _nc_hash_map(void) { if (hashtab) free (hashtab); - hashtab = malloc (sizeof(*hashtab)*(screen_lines+1)*2); + hashtab = typeMalloc(sym, (screen_lines+1)*2); if (!hashtab) { if (oldhash) diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c index 503b63c654d..6389748139b 100644 --- a/lib/libcurses/tty/tty_update.c +++ b/lib/libcurses/tty/tty_update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_update.c,v 1.2 1999/01/31 20:17:10 millert Exp $ */ +/* $OpenBSD: tty_update.c,v 1.3 1999/03/02 06:23:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -77,7 +77,7 @@ #include <term.h> -MODULE_ID("$From: tty_update.c,v 1.110 1999/01/31 01:45:37 Alexander.V.Lukyanov Exp $") +MODULE_ID("$From: tty_update.c,v 1.111 1999/02/27 20:07:56 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -901,12 +901,12 @@ chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ if(!clr_eos || !can_clear_with(blank)) return total; - if (tstLine == 0 || length > lenLine) { - tstLine = (chtype *)_nc_doalloc(tstLine, length); + if ((tstLine == 0) || (last > (int)lenLine)) { + tstLine = typeRealloc(chtype, last, tstLine); } if (tstLine != 0) { - lenLine = length; + lenLine = last; for (col = 0; col < last; col++) tstLine[col] = blank; |