diff options
author | 1998-10-31 06:30:28 +0000 | |
---|---|---|
committer | 1998-10-31 06:30:28 +0000 | |
commit | 8df350bfde7487e9064f4140b11eb7ad96f04536 (patch) | |
tree | 87aa595466265f80e4c4cde6ef98c804c2d7f213 | |
parent | remove all those "black magic" inspired routines, (diff) | |
download | wireguard-openbsd-8df350bfde7487e9064f4140b11eb7ad96f04536.tar.xz wireguard-openbsd-8df350bfde7487e9064f4140b11eb7ad96f04536.zip |
update to ncurses 4.2-981017
34 files changed, 849 insertions, 325 deletions
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 6cb9c099cea..aec0d9437e3 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.28 1998/09/13 19:16:14 millert Exp $ +# $OpenBSD: Makefile,v 1.29 1998/10/31 06:30:28 millert Exp $ # Uncomment this to enable tracing in libcurses #CURSESTRACE=-DTRACE @@ -12,11 +12,11 @@ AWK?= /usr/bin/awk LIB= curses SRCS= access.c alloc_entry.c captoinfo.c codes.c comp_captab.c comp_error.c \ comp_expand.c comp_hash.c comp_parse.c comp_scan.c define_key.c \ - doalloc.c expanded.c fallback.c hardscroll.c hashmap.c keyok.c \ - lib_acs.c lib_adabind.c lib_addch.c lib_addstr.c lib_baudrate.c \ - lib_beep.c lib_bkgd.c lib_box.c lib_chgat.c lib_clear.c \ - lib_clearok.c lib_clrbot.c lib_clreol.c lib_color.c \ - lib_colorset.c lib_cur_term.c lib_data.c lib_delch.c \ + doalloc.c expanded.c fallback.c getenv_num.c hardscroll.c hashmap.c \ + home_terminfo.c keyok.c lib_acs.c lib_adabind.c lib_addch.c \ + lib_addstr.c lib_baudrate.c lib_beep.c lib_bkgd.c lib_box.c \ + lib_chgat.c lib_clear.c lib_clearok.c lib_clrbot.c lib_clreol.c \ + lib_color.c lib_colorset.c lib_cur_term.c lib_data.c lib_delch.c \ lib_delwin.c lib_dft_fgbg.c lib_doupdate.c lib_echo.c \ lib_endwin.c lib_erase.c lib_flash.c lib_freeall.c lib_gen.c \ lib_getch.c lib_getstr.c lib_hline.c lib_immedok.c lib_inchstr.c \ diff --git a/lib/libcurses/comp_expand.c b/lib/libcurses/comp_expand.c index 1543ebe8fc8..b118664a530 100644 --- a/lib/libcurses/comp_expand.c +++ b/lib/libcurses/comp_expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: comp_expand.c,v 1.4 1998/09/13 19:16:15 millert Exp $ */ +/* $OpenBSD: comp_expand.c,v 1.5 1998/10/31 06:30: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.8 1998/08/15 23:01:54 tom Exp $") +MODULE_ID("$From: comp_expand.c,v 1.9 1998/09/26 13:41:40 tom Exp $") static int trailing_spaces(const char *src) { @@ -51,7 +51,7 @@ static int trailing_spaces(const char *src) #define REALCTL(s) (CHAR_OF(s) < 127 && iscntrl(CHAR_OF(s))) #define REALPRINT(s) (CHAR_OF(s) < 127 && isprint(CHAR_OF(s))) -char *_nc_tic_expand(const char *srcp, bool tic_format) +char *_nc_tic_expand(const char *srcp, bool tic_format, bool numbers) { static char * buffer; static size_t length; @@ -72,7 +72,52 @@ int ch; while ((ch = (*str & 0xff)) != 0) { if (ch == '%' && REALPRINT(str+1)) { buffer[bufp++] = *str++; - buffer[bufp++] = *str; + /* + * Though the character literals are more compact, most + * terminal descriptions use numbers and are not easy + * to read in character-literal form. This is the + * default option for tic/infocmp. + */ + if (numbers + && str[0] == S_QUOTE + && str[1] != '\\' + && REALPRINT(str+1) + && str[2] == S_QUOTE) { + sprintf(buffer+bufp, "{%d}", str[1]); + bufp += strlen(buffer+bufp); + str += 2; + } + /* + * If we have a "%{number}", try to translate it into + * a "%'char'" form, since that will run a little faster + * when we're interpreting it. Also, having one form + * for the constant makes it simpler to compare terminal + * descriptions. + */ + else if (!numbers + && str[0] == L_BRACE + && isdigit(str[1])) { + char *dst = 0; + long value = strtol(str+1, &dst, 0); + if (dst != 0 + && *dst == R_BRACE + && value < 127 + && value != '\\' /* FIXME */ + && isprint((int)value)) { + ch = (int)value; + buffer[bufp++] = S_QUOTE; + if (ch == '\\' + || ch == S_QUOTE) + buffer[bufp++] = '\\'; + buffer[bufp++] = ch; + buffer[bufp++] = S_QUOTE; + str = dst; + } else { + buffer[bufp++] = *str; + } + } else { + buffer[bufp++] = *str; + } } else if (ch == 128) { buffer[bufp++] = '\\'; diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 6ff2b1fac4d..2037b6f6c9f 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.h,v 1.12 1998/09/17 04:14:29 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.13 1998/10/31 06:30:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -50,7 +50,7 @@ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 4 #define NCURSES_VERSION_MINOR 2 -#define NCURSES_VERSION_PATCH 980912 +#define NCURSES_VERSION_PATCH 981017 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 4c95727e76f..5b66f2a5308 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.9 1998/09/17 04:14:30 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.10 1998/10/31 06:30:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ /* - * $From: curses.priv.h,v 1.110 1998/09/12 22:50:21 tom Exp $ + * $From: curses.priv.h,v 1.123 1998/10/03 23:35:34 tom Exp $ * * curses.priv.h * @@ -119,6 +119,11 @@ extern int errno; #define USE_QNX_MOUSE 0 #endif +/* EMX mouse support */ +#ifdef __EMX__ +#define USE_EMX_MOUSE +#endif + #define DEFAULT_MAXCLICK 166 #define EV_MAX 8 /* size of mouse circular event queue */ @@ -137,10 +142,21 @@ extern int errno; #endif /* - * As currently coded, hashmap relies on the scroll-hints logic. + * Not all platforms have memmove; some have an equivalent bcopy. (Some may + * have neither). + */ +#if USE_OK_BCOPY +#define memmove(d,s,n) bcopy(s,d,n) +#elif USE_MY_MEMMOVE +#define memmove(d,s,n) _nc_memmove(d,s,n) +extern void * _nc_memmove(void *, const void *, size_t); +#endif + +/* + * Scroll hints are useless when hashmap is used */ #if !USE_SCROLL_HINTS -#if USE_HASHMAP +#if !USE_HASHMAP #define USE_SCROLL_HINTS 1 #else #define USE_SCROLL_HINTS 0 @@ -177,6 +193,13 @@ struct tries { #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK)) /* + * Common/troublesome character definitions + */ +#define L_BRACE '{' +#define R_BRACE '}' +#define S_QUOTE '\'' + +/* * Structure for palette tables */ @@ -225,6 +248,7 @@ struct screen { int _ifd; /* input file ptr for screen */ FILE *_ofp; /* output file ptr for screen */ char *_setbuf; /* buffered I/O for output */ + int _buffered; /* setvbuf uses _setbuf data */ int _checkfd; /* filedesc for typeahead check */ struct term *_term; /* terminal type information */ short _lines; /* screen lines */ @@ -292,6 +316,9 @@ struct screen { int _rep_cost; /* cost of (repeat_char) */ int _hpa_ch_cost; /* cost of (column_address) */ int _cup_ch_cost; /* cost of (cursor_address) */ + int _smir_cost; /* cost of (enter_insert_mode) */ + int _rmir_cost; /* cost of (exit_insert_mode) */ + int _ip_cost; /* cost of (insert_padding) */ /* used in lib_mvcur.c */ char * _address_cursor; int _carriage_return_length; @@ -353,6 +380,9 @@ struct screen { bool _sig_winch; SCREEN *_next_screen; + + /* hashes for old and new lines */ + unsigned long *oldhash, *newhash; }; extern SCREEN *_nc_screen_chain; @@ -468,7 +498,6 @@ typedef struct { #define returnPtr(code) TRACE_RETURN(code,ptr) #define returnVoid T((T_RETURN(""))); return #define returnWin(code) TRACE_RETURN(code,win) -extern unsigned _nc_tracing; extern WINDOW * _nc_retrace_win(WINDOW *); extern attr_t _nc_retrace_attr_t(attr_t); extern char *_nc_retrace_ptr(char *); @@ -487,6 +516,7 @@ extern void _nc_fifo_dump(void); #define returnWin(code) return code #endif +extern unsigned _nc_tracing; extern const char *_nc_visbuf2(int, const char *); #define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch)) @@ -529,9 +559,11 @@ extern const char *_nc_visbuf2(int, const char *); #define InsCharCost(count) \ ((parm_ich != 0) \ ? SP->_ich_cost \ - : ((insert_character != 0) \ - ? (SP->_ich1_cost * count) \ - : INFINITY)) + : ((enter_insert_mode && exit_insert_mode) \ + ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \ + : ((insert_character != 0) \ + ? (SP->_ich1_cost * count) \ + : INFINITY))) #if USE_XMC_SUPPORT #define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) { \ @@ -601,7 +633,7 @@ extern void _nc_do_xmc_glitch(attr_t); #endif /* hardscroll.c */ -#if defined(TRACE) || defined(SCROLLDEBUG) +#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG) extern void _nc_linedump(void); #endif @@ -628,10 +660,6 @@ extern int _nc_has_mouse(void); /* safe_sprintf.c */ extern char * _nc_printf_string(const char *fmt, va_list ap); -/* softscroll.c */ -extern void _nc_setup_scroll(void); -extern void _nc_perform_scroll(void); - /* tries.c */ extern void _nc_add_to_try(struct tries **tree, char *str, unsigned short code); extern char *_nc_expand_try(struct tries *tree, unsigned short code, size_t len); @@ -639,10 +667,12 @@ extern int _nc_remove_key(struct tries **tree, unsigned short code); /* elsewhere ... */ extern WINDOW *_nc_makenew(int, int, int, int, int); +extern char *_nc_home_terminfo(void); extern char *_nc_trace_buf(int, size_t); extern chtype _nc_background(WINDOW *); extern chtype _nc_render(WINDOW *, chtype); extern int _nc_access(const char *, int); +extern int _nc_getenv_num(const char *); extern int _nc_keypad(bool); extern int _nc_outch(int); extern int _nc_setupscreen(short, short const, FILE *); @@ -652,7 +682,9 @@ extern void _nc_do_color(int, bool, int (*)(int)); extern void _nc_freeall(void); extern void _nc_freewin(WINDOW *win); extern void _nc_hash_map(void); +extern void _nc_make_oldhash(int i); extern void _nc_outstr(const char *str); +extern void _nc_scroll_oldhash(int n, int top, int bot); extern void _nc_scroll_optimize(void); extern void _nc_scroll_window(WINDOW *, int const, short const, short const, chtype); extern void _nc_set_buffer(FILE *ofp, bool buffered); @@ -663,8 +695,11 @@ extern void _nc_synchook(WINDOW *win); extern void _nc_update_screensize(void); #endif +/* scroll indices */ +extern int *_nc_oldnums; + #define NC_BUFFERED(flag) \ - if ((SP->_setbuf == 0) != flag) \ + if ((SP->_buffered != 0) != flag) \ _nc_set_buffer(SP->_ofp, flag) /* @@ -699,8 +734,8 @@ extern SCREEN *SP; extern int _nc_slk_format; /* != 0 if slk_init() called */ extern int _nc_slk_initialize(WINDOW *, int); -/* - * Some constants related to SLK's +/* + * Some constants related to SLK's */ #define MAX_SKEY_OLD 8 /* count of soft keys */ #define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */ diff --git a/lib/libcurses/getenv_num.c b/lib/libcurses/getenv_num.c new file mode 100644 index 00000000000..0d561728928 --- /dev/null +++ b/lib/libcurses/getenv_num.c @@ -0,0 +1,58 @@ +/* $OpenBSD: getenv_num.c,v 1.1 1998/10/31 06:30:28 millert Exp $ */ + +/**************************************************************************** + * Copyright (c) 1998 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> 1998 * + ****************************************************************************/ + +/* + * getenv_num.c -- obtain a number from the environment + */ + +#include <curses.priv.h> + +MODULE_ID("$From: getenv_num.c,v 1.1 1998/09/19 21:30:23 tom Exp $") + +int +_nc_getenv_num(const char *name) +{ + char *dst = 0; + char *src = getenv(name); + long value; + + if ((src == 0) + || (value = strtol(src, &dst, 0)) < 0 + || (dst == src) + || (*dst != '\0') + || (int)value < value) + value = -1; + + return (int) value; +} diff --git a/lib/libcurses/hardscroll.c b/lib/libcurses/hardscroll.c index f8bcbb30096..6e136a464b6 100644 --- a/lib/libcurses/hardscroll.c +++ b/lib/libcurses/hardscroll.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hardscroll.c,v 1.7 1998/07/23 21:18:18 millert Exp $ */ +/* $OpenBSD: hardscroll.c,v 1.8 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -148,19 +148,32 @@ AUTHOR #include <curses.priv.h> -MODULE_ID("$From: hardscroll.c,v 1.29 1998/02/11 12:13:57 tom Exp $") +MODULE_ID("$From: hardscroll.c,v 1.32 1998/09/20 02:34:59 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) + +# undef screen_lines +# define screen_lines MAXLINES int oldnums[MAXLINES]; -#define OLDNUM(n) oldnums[n] -#undef T -#define T(x) (void) printf x ; (void) putchar('\n'); -#else -#include <curses.h> -#define OLDNUM(n) newscr->_line[n].oldindex -#ifndef _NEWINDEX -#define _NEWINDEX -1 -#endif /* _NEWINDEX */ +# define OLDNUM(n) oldnums[n] +# define _tracef printf +# undef TR +# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } + +#else /* no debug */ + +/* OLDNUM(n) indicates which line will be shifted to the position n. + if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from + somewhere. */ +# if USE_HASHMAP +int *_nc_oldnums = 0; +static int oldnums_allocated = 0; +# define oldnums _nc_oldnums +# define OLDNUM(n) oldnums[n] +# else /* !USE_HASHMAP */ +# define OLDNUM(n) newscr->_line[n].oldindex +# endif /* !USE_HASHMAP */ + #endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */ @@ -172,6 +185,23 @@ void _nc_scroll_optimize(void) TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins")); +#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) +#if USE_HASHMAP + /* get enough storage */ + if (oldnums_allocated < screen_lines) + { + size_t size = screen_lines * sizeof(*oldnums); + int *new_oldnums = oldnums ? realloc(oldnums, size) : malloc(size); + if (!new_oldnums) + return; + oldnums = new_oldnums; + oldnums_allocated = screen_lines; + } + /* calculate the indices */ + _nc_hash_map(); +#endif +#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + #ifdef TRACE if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) _nc_linedump(); @@ -184,10 +214,10 @@ void _nc_scroll_optimize(void) i++; if (i >= screen_lines) break; - + shift = OLDNUM(i) - i; /* shift > 0 */ start = i; - + i++; while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) i++; @@ -210,10 +240,10 @@ void _nc_scroll_optimize(void) i--; if (i < 0) break; - + shift = OLDNUM(i) - i; /* shift < 0 */ end = i; - + i--; while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) i--; @@ -230,7 +260,7 @@ void _nc_scroll_optimize(void) } } -#if defined(TRACE) || defined(SCROLLDEBUG) +#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG) void _nc_linedump(void) /* dump the state of the real and virtual oldnum fields */ { diff --git a/lib/libcurses/hashmap.c b/lib/libcurses/hashmap.c index 1ca2c4270ba..ef10b1e309e 100644 --- a/lib/libcurses/hashmap.c +++ b/lib/libcurses/hashmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hashmap.c,v 1.3 1998/07/23 21:18:19 millert Exp $ */ +/* $OpenBSD: hashmap.c,v 1.4 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -65,34 +65,42 @@ hashmap: hashmap.c AUTHOR Eric S. Raymond <esr@snark.thyrsus.com>, May 1996 + Bug fixes and improvements by Alexander V. Lukyanov <lav@yars.free.net>, 1997 *****************************************************************************/ #include <curses.priv.h> +#include <term.h> /* for back_color_erase */ -MODULE_ID("$From: hashmap.c,v 1.25 1998/06/06 17:40:06 tom Exp $") +MODULE_ID("$From: hashmap.c,v 1.28 1998/09/20 02:35:15 tom Exp $") #ifdef HASHDEBUG -#define TEXTWIDTH 1 + +# define _tracef printf +# undef TR +# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } +# undef screen_lines +# define screen_lines MAXLINES +# define TEXTWIDTH 1 int oldnums[MAXLINES], reallines[MAXLINES]; static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; -#define OLDNUM(n) oldnums[n] -#define REAL(m) reallines[m] -#define OLDTEXT(n) oldtext[n] -#define NEWTEXT(m) newtext[m] -#undef T -#define T(x) (void) printf x ; (void) putchar('\n'); -#else -#include <curses.h> -#define OLDNUM(n) newscr->_line[n].oldindex -#define REAL(m) curscr->_line[m].oldindex -#define OLDTEXT(n) curscr->_line[n].text -#define NEWTEXT(m) newscr->_line[m].text -#define TEXTWIDTH (curscr->_maxx+1) -#ifndef _NEWINDEX -#define _NEWINDEX -1 -#endif /* _NEWINDEX */ -#endif /* HASHDEBUG */ +# define OLDNUM(n) oldnums[n] +# define OLDTEXT(n) oldtext[n] +# define NEWTEXT(m) newtext[m] +# define PENDING(n) 1 + +#else /* !HASHDEBUG */ + +# define OLDNUM(n) _nc_oldnums[n] +# define OLDTEXT(n) curscr->_line[n].text +# define NEWTEXT(m) newscr->_line[m].text +# define TEXTWIDTH (curscr->_maxx+1) +# define PENDING(n) (newscr->_line[n].firstchar != _NOCHANGE) + +#endif /* !HASHDEBUG */ + +#define oldhash (SP->oldhash) +#define newhash (SP->newhash) static inline unsigned long hash(chtype *text) { @@ -123,10 +131,13 @@ static int update_cost_from_blank(chtype *to) { int cost=0; int i; + chtype blank = BLANK; + + if (back_color_erase) + blank |= (stdscr->_bkgd & A_COLOR); - /* FIXME: ClrBlank should be used */ for (i=TEXTWIDTH; i>0; i--) - if (BLANK != *to++) + if (blank != *to++) cost++; return cost; @@ -147,7 +158,7 @@ static inline bool cost_effective(const int from, const int to, const bool blank if (new_from == _NEWINDEX) new_from = from; - /* + /* * On the left side of >= is the cost before moving; * on the right side -- cost after moving. */ @@ -169,9 +180,7 @@ typedef struct sym; static sym *hashtab=0; -static int lines_alloc=0; -static long *oldhash=0; -static long *newhash=0; +static int lines_alloc=0; static void grow_hunks(void) { @@ -195,7 +204,7 @@ static void grow_hunks(void) { start = i; shift = OLDNUM(i) - i; - + /* get forward limit */ i = start+1; while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) @@ -233,7 +242,7 @@ static void grow_hunks(void) } i--; } - + i = end; /* grow forward */ if (shift > 0) @@ -257,7 +266,7 @@ static void grow_hunks(void) } i++; } - + back_ref_limit = back_limit = i; if (shift > 0) back_ref_limit += shift; @@ -283,21 +292,43 @@ void _nc_hash_map(void) lines_alloc = 0; return; } - - if (oldhash) - free (oldhash); - oldhash = malloc (sizeof(*oldhash)*screen_lines*2); - if (!oldhash) + lines_alloc = screen_lines; + } + + if (oldhash && newhash) + { + /* re-hash only changed lines */ + for (i = 0; i < screen_lines; i++) + { + if (PENDING(i)) + newhash[i] = hash(NEWTEXT(i)); + } + } + else + { + /* re-hash all */ + if (oldhash == 0) + oldhash = typeCalloc (unsigned long, screen_lines); + if (newhash == 0) + newhash = typeCalloc (unsigned long, screen_lines); + if (!oldhash || !newhash) + return; /* malloc failure */ + for (i = 0; i < screen_lines; i++) { - if (hashtab) - FreeAndNull(hashtab); - lines_alloc = 0; - return; + newhash[i] = hash(NEWTEXT(i)); + oldhash[i] = hash(OLDTEXT(i)); } - - lines_alloc = screen_lines; } - newhash = oldhash + screen_lines; /* two arrays in the same memory block */ + +#ifdef HASH_VERIFY + for (i = 0; i < screen_lines; i++) + { + if(newhash[i] != hash(NEWTEXT(i))) + fprintf(stderr,"error in newhash[%d]\n",i); + if(oldhash[i] != hash(OLDTEXT(i))) + fprintf(stderr,"error in oldhash[%d]\n",i); + } +#endif /* * Set up and count line-hash values. @@ -305,34 +336,32 @@ void _nc_hash_map(void) memset(hashtab, '\0', sizeof(*hashtab)*(screen_lines+1)*2); for (i = 0; i < screen_lines; i++) { - unsigned long hashval = hash(OLDTEXT(i)); + unsigned long hashval = oldhash[i]; for (sp = hashtab; sp->hashval; sp++) if (sp->hashval == hashval) break; sp->hashval = hashval; /* in case this is a new entry */ - oldhash[i] = hashval; sp->oldcount++; sp->oldindex = i; } for (i = 0; i < screen_lines; i++) { - unsigned long hashval = hash(NEWTEXT(i)); + unsigned long hashval = newhash[i]; for (sp = hashtab; sp->hashval; sp++) if (sp->hashval == hashval) break; sp->hashval = hashval; /* in case this is a new entry */ - newhash[i] = hashval; sp->newcount++; sp->newindex = i; - - OLDNUM(i) = _NEWINDEX; + + OLDNUM(i) = _NEWINDEX; /* initialize old indices array */ } /* * Mark line pairs corresponding to unique hash pairs. - * + * * We don't mark lines with offset 0, because it can make fail * extending hunks by cost_effective. Otherwise, it does not * have any side effects. @@ -376,18 +405,65 @@ void _nc_hash_map(void) } } } - + /* After clearing invalid hunks, try grow the rest. */ grow_hunks(); #if NO_LEAKS FreeAndNull(hashtab); - FreeAndNull(oldhash); lines_alloc = 0; #endif } +void _nc_make_oldhash(int i) +{ + if (oldhash) + oldhash[i] = hash(OLDTEXT(i)); +} + +void _nc_scroll_oldhash(int n, int top, int bot) +{ + int size; + int i; + + if (!oldhash) + return; + + size = sizeof(*oldhash) * (bot-top+1-abs(n)); + if (n > 0) + { + memmove (oldhash+top, oldhash+top+n, size); + for (i = bot; i > bot-n; i--) + oldhash[i] = hash(OLDTEXT(i)); + } + else + { + memmove (oldhash+top-n, oldhash+top, size); + for (i = top; i < top-n; i++) + oldhash[i] = hash(OLDTEXT(i)); + } +} + + #ifdef HASHDEBUG +static void +usage(void) +{ + static const char *table[] = { + "hashmap test-driver", + "", + "# comment", + "l get initial line number vector", + "n use following letters as text of new lines", + "o use following letters as text of old lines", + "d dump state of test arrays", + "h apply hash mapper and see scroll optimization", + "? this message" + }; + size_t n; + for (n = 0; n < sizeof(table)/sizeof(table[0]); n++) + fprintf(stderr, "%s\n", table[n]); +} int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) @@ -395,6 +471,7 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) char line[BUFSIZ], *st; int n; + SP = typeCalloc(SCREEN,1); for (n = 0; n < screen_lines; n++) { reallines[n] = n; @@ -402,6 +479,9 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) oldtext[n][0] = newtext[n][0] = '.'; } + if (isatty(fileno(stdin))) + usage(); + #ifdef TRACE _nc_tracing = TRACE_MOVE; #endif @@ -476,6 +556,9 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) _nc_scroll_optimize(); (void) fputs("Done.\n", stderr); break; + case '?': + usage(); + break; } } return EXIT_SUCCESS; diff --git a/lib/libcurses/home_terminfo.c b/lib/libcurses/home_terminfo.c new file mode 100644 index 00000000000..95ca64a955f --- /dev/null +++ b/lib/libcurses/home_terminfo.c @@ -0,0 +1,64 @@ +/* $OpenBSD: home_terminfo.c,v 1.1 1998/10/31 06:30:29 millert Exp $ */ + +/**************************************************************************** + * Copyright (c) 1998 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> 1998 * + ****************************************************************************/ + +/* + * home_terminfo.c -- return the $HOME/.terminfo string, expanded + */ + +#include <curses.priv.h> +#include <tic.h> + +MODULE_ID("$From: home_terminfo.c,v 1.1 1998/09/19 21:25:03 tom Exp $") + +#define my_length (strlen(home) + sizeof(PRIVATE_INFO)) + +/* ncurses extension...fall back on user's private directory */ + +char * +_nc_home_terminfo(void) +{ + char *home; + static char *temp = 0; + + if (temp == 0) { + if ((home = getenv("HOME")) != 0 + && my_length <= PATH_MAX) { + temp = malloc(my_length); + if (temp == 0) + _nc_err_abort("Out of memory"); + (void) sprintf(temp, PRIVATE_INFO, home); + } + } + return temp; +} diff --git a/lib/libcurses/lib_baudrate.c b/lib/libcurses/lib_baudrate.c index d39b9084325..1de84561fc7 100644 --- a/lib/libcurses/lib_baudrate.c +++ b/lib/libcurses/lib_baudrate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_baudrate.c,v 1.4 1998/07/23 21:18:27 millert Exp $ */ +/* $OpenBSD: lib_baudrate.c,v 1.5 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -42,7 +42,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term, pad_char */ -MODULE_ID("$From: lib_baudrate.c,v 1.11 1998/02/11 12:13:58 tom Exp $") +MODULE_ID("$From: lib_baudrate.c,v 1.13 1998/09/19 21:34:26 tom Exp $") /* * int @@ -105,9 +105,6 @@ baudrate(void) { size_t i; int ret; -#ifdef TRACE -char *debug_rate; -#endif T((T_CALLED("baudrate()"))); @@ -118,15 +115,10 @@ char *debug_rate; */ #ifdef TRACE if (SP && !isatty(fileno(SP->_ofp)) - && (debug_rate = getenv("BAUDRATE")) != 0) { - long l; - char *p; - - l = strtol(debug_rate, &p, 10); - if (p == debug_rate || *p != '\0' || l == LONG_MIN || - l > INT_MAX) - l = 9600; - returnCode((int)l); + && getenv("BAUDRATE") != 0) { + if ((ret = _nc_getenv_num("BAUDRATE")) <= 0) + ret = 9600; + returnCode(ret); } else #endif diff --git a/lib/libcurses/lib_color.c b/lib/libcurses/lib_color.c index a1a53e02768..bd1b43b6534 100644 --- a/lib/libcurses/lib_color.c +++ b/lib/libcurses/lib_color.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_color.c,v 1.6 1998/08/03 17:02:45 millert Exp $ */ +/* $OpenBSD: lib_color.c,v 1.7 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <term.h> -MODULE_ID("$From: lib_color.c,v 1.31 1998/08/01 22:21:29 tom Exp $") +MODULE_ID("$From: lib_color.c,v 1.33 1998/09/20 00:51:51 tom Exp $") /* * These should be screen structure members. They need to be globals for @@ -257,12 +257,16 @@ int init_pair(short pair, short f, short b) for (y = 0; y <= curscr->_maxy; y++) { struct ldat *ptr = &(curscr->_line[y]); + bool changed = FALSE; for (x = 0; x <= curscr->_maxx; x++) { if ((ptr->text[x] & A_COLOR) == z) { ptr->text[x] &= ~A_COLOR; CHANGED_CELL(ptr,x); + changed = TRUE; } } + if (changed) + _nc_make_oldhash(y); } } SP->_color_pairs[pair] = result; diff --git a/lib/libcurses/lib_cur_term.c b/lib/libcurses/lib_cur_term.c index 321ea1c46a7..541d7fe7523 100644 --- a/lib/libcurses/lib_cur_term.c +++ b/lib/libcurses/lib_cur_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_cur_term.c,v 1.1 1998/07/23 21:18:37 millert Exp $ */ +/* $OpenBSD: lib_cur_term.c,v 1.2 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -41,7 +41,7 @@ #include <curses.priv.h> #include <term.h> /* TTY, cur_term */ -MODULE_ID("$From: lib_cur_term.c,v 1.2 1998/02/11 12:13:55 tom Exp $") +MODULE_ID("$From: lib_cur_term.c,v 1.3 1998/09/19 19:21:05 Alexander.V.Lukyanov Exp $") TERMINAL *cur_term; @@ -77,6 +77,8 @@ int del_curterm(TERMINAL *term) FreeIfNeeded(term->type.str_table); FreeIfNeeded(term->type.term_names); free(term); + if (term == cur_term) + cur_term = 0; returnCode(OK); } returnCode(ERR); diff --git a/lib/libcurses/lib_doupdate.c b/lib/libcurses/lib_doupdate.c index e391e6766e5..d21c815c589 100644 --- a/lib/libcurses/lib_doupdate.c +++ b/lib/libcurses/lib_doupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_doupdate.c,v 1.10 1998/09/17 04:14:30 millert Exp $ */ +/* $OpenBSD: lib_doupdate.c,v 1.11 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -77,7 +77,7 @@ #include <term.h> -MODULE_ID("$From: lib_doupdate.c,v 1.104 1998/09/12 22:50:39 tom Exp $") +MODULE_ID("$From: lib_doupdate.c,v 1.109 1998/10/03 19:08:33 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -223,7 +223,7 @@ static bool check_pending(void) FD_ZERO(&fdset); FD_SET(SP->_checkfd, &fdset); - if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) > 0) + if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) != 0) { have_pending = TRUE; } @@ -521,7 +521,6 @@ struct tms before, after; T(("coming back from shell mode")); reset_prog_mode(); - NC_BUFFERED(TRUE); _nc_mvcur_resume(); _nc_screen_resume(); SP->_mouse_resume(SP); @@ -705,22 +704,7 @@ struct tms before, after; nonempty = min(screen_lines, newscr->_maxy+1); if (SP->_scrolling) { -#if USE_HASHMAP -#if defined(TRACE) || defined(NCURSES_TEST) - if (_nc_optimize_enable & OPTIMIZE_HASHMAP) -#endif /*TRACE */ - _nc_hash_map(); -#elif !USE_SCROLL_HINTS - _nc_setup_scroll(); -#endif -#if defined(TRACE) || defined(NCURSES_TEST) - if (_nc_optimize_enable & OPTIMIZE_SCROLL) -#endif /*TRACE */ -#if USE_SCROLL_HINTS || USE_HASHMAP _nc_scroll_optimize(); -#else - _nc_perform_scroll(); -#endif } nonempty = ClrBottom(nonempty); @@ -931,7 +915,7 @@ int last = min(screen_columns, newscr->_maxx+1); size_t length = sizeof(chtype) * last; chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ - if (!clr_eos || !can_clear_with(blank)) + if(!clr_eos || !can_clear_with(blank)) return total; if (tstLine == 0 || length > lenLine) { @@ -955,6 +939,11 @@ chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ GoTo(top,0); ClrToEOS(blank); total = top; + if (SP->oldhash && SP->newhash) + { + for (row = top; row < screen_lines; row++) + SP->oldhash[row] = SP->newhash[row]; + } } } #if NO_LEAKS @@ -993,6 +982,10 @@ bool attrchanged = FALSE; T(("TransformLine(%d) called", lineno)); + /* copy new hash value to old one */ + if (SP->oldhash && SP->newhash) + SP->oldhash[lineno] = SP->newhash[lineno]; + if(ceol_standout_glitch && clr_eol) { firstChar = 0; while(firstChar < screen_columns) { @@ -1282,25 +1275,33 @@ static int InsStr(chtype *line, int count) { T(("InsStr(%p,%d) called", line, count)); - if (enter_insert_mode && exit_insert_mode) { - TPUTS_TRACE("enter_insert_mode"); - putp(enter_insert_mode); + /* Prefer parm_ich as it has the smallest cost - no need to shift + * the whole line on each character. */ + /* The order must match that of InsCharCost. */ + if (parm_ich) { + TPUTS_TRACE("parm_ich"); + tputs(tparm(parm_ich, count), count, _nc_outch); while (count) { PutAttrChar(*line); line++; count--; } - TPUTS_TRACE("exit_insert_mode"); - putp(exit_insert_mode); return(OK); - } else if (parm_ich) { - TPUTS_TRACE("parm_ich"); - tputs(tparm(parm_ich, count), count, _nc_outch); + } else if (enter_insert_mode && exit_insert_mode) { + TPUTS_TRACE("enter_insert_mode"); + putp(enter_insert_mode); while (count) { PutAttrChar(*line); + if (insert_padding) + { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } line++; count--; } + TPUTS_TRACE("exit_insert_mode"); + putp(exit_insert_mode); return(OK); } else { while (count) { @@ -1694,6 +1695,9 @@ int _nc_scrolln(int n, int top, int bot, int maxy) _nc_scroll_window(curscr, n, top, bot, blank); + /* shift hash values too - they can be reused */ + _nc_scroll_oldhash(n, top, bot); + return(OK); } diff --git a/lib/libcurses/lib_endwin.c b/lib/libcurses/lib_endwin.c index e6b9eb5a29b..b9ff914e93a 100644 --- a/lib/libcurses/lib_endwin.c +++ b/lib/libcurses/lib_endwin.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_endwin.c,v 1.6 1998/09/17 04:14:30 millert Exp $ */ +/* $OpenBSD: lib_endwin.c,v 1.7 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -44,7 +44,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: lib_endwin.c,v 1.15 1998/09/12 22:50:25 tom Exp $") +MODULE_ID("$From: lib_endwin.c,v 1.16 1998/09/20 03:29:17 tom Exp $") int endwin(void) @@ -56,7 +56,6 @@ endwin(void) SP->_mouse_wrap(SP); _nc_screen_wrap(); _nc_mvcur_wrap(); /* wrap up cursor addressing */ - NC_BUFFERED(FALSE); } returnCode(reset_shell_mode()); diff --git a/lib/libcurses/lib_getch.c b/lib/libcurses/lib_getch.c index 2af823b6f8a..920989b3919 100644 --- a/lib/libcurses/lib_getch.c +++ b/lib/libcurses/lib_getch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_getch.c,v 1.6 1998/07/23 21:18:47 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.7 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -42,17 +42,48 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_getch.c,v 1.40 1998/02/11 12:13:58 tom Exp $") +MODULE_ID("$From: lib_getch.c,v 1.41 1998/09/26 23:34:53 tom Exp $") #include <fifo_defs.h> int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ +#ifdef USE_EMX_MOUSE +# include <sys/select.h> +static int +kbd_mouse_read(unsigned char *p) +{ +fd_set fdset; +int nums = SP->_ifd+1; + + for (;;) { + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (SP->_mouse_fd >= 0) { + FD_SET(SP->_mouse_fd, &fdset); + if (SP->_mouse_fd > SP->_checkfd) + nums = SP->_mouse_fd+1; + } + if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + int n; + + if (FD_ISSET(SP->_mouse_fd, &fdset)) /* Prefer mouse */ + n = read(SP->_mouse_fd, p, 1); + else + n = read(SP->_ifd, p, 1); + return n; + } + if (errno != EINTR) + return -1; + } +} +#endif /* USE_EMX_MOUSE */ + static inline int fifo_peek(void) { int ch = SP->_fifo[peek]; T(("peeking at %d", peek)); - + p_inc(); return ch; } @@ -71,7 +102,7 @@ int ch; } else h_inc(); - + #ifdef TRACE if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); #endif @@ -90,8 +121,8 @@ again: errno = 0; #endif -#if USE_GPM_SUPPORT - if ((SP->_mouse_fd >= 0) +#if USE_GPM_SUPPORT + if ((SP->_mouse_fd >= 0) && (_nc_timed_wait(3, -1, (int *)0) & 2)) { SP->_mouse_event(SP); @@ -101,17 +132,21 @@ again: #endif { unsigned char c2=0; +#ifdef USE_EMX_MOUSE + n = kbd_mouse_read(&c2); +#else n = read(SP->_ifd, &c2, 1); - ch = c2; +#endif + ch = c2 & 0xff; } #ifdef HIDE_EINTR /* * Under System V curses with non-restarting signals, getch() returns - * with value ERR when a handled signal keeps it from completing. + * with value ERR when a handled signal keeps it from completing. * If signals restart system calls, OTOH, the signal is invisible * except to its handler. - * + * * We don't want this difference to show. This piece of code * tries to make it look like we always have restarting signals. */ diff --git a/lib/libcurses/lib_initscr.c b/lib/libcurses/lib_initscr.c index 2e09588b491..8f9400788c4 100644 --- a/lib/libcurses/lib_initscr.c +++ b/lib/libcurses/lib_initscr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_initscr.c,v 1.5 1998/09/13 19:16:27 millert Exp $ */ +/* $OpenBSD: lib_initscr.c,v 1.6 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -47,14 +47,13 @@ #include <sys/termio.h> /* needed for ISC */ #endif -MODULE_ID("$From: lib_initscr.c,v 1.23 1998/08/09 00:18:48 tom Exp $") +MODULE_ID("$From: lib_initscr.c,v 1.25 1998/09/19 21:39:25 tom Exp $") WINDOW *initscr(void) { static bool initialized = FALSE; NCURSES_CONST char *name; -char *p; -long l; +int value; T((T_CALLED("initscr()"))); /* Portable applications must not call initscr() more than once */ @@ -70,11 +69,8 @@ long l; } /* allow user to set maximum escape delay from the environment */ - if ((name = getenv("ESCDELAY")) != 0) { - l = strtol(name, &p, 10); - if (p != name && *p == '\0' && l != LONG_MIN && - l <= INT_MAX) - ESCDELAY = (int)l; + if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { + ESCDELAY = value; } /* def_shell_mode - done in newterm/_nc_setupscreen */ diff --git a/lib/libcurses/lib_kernel.c b/lib/libcurses/lib_kernel.c index 7d8edc345f4..1d417ac3e0b 100644 --- a/lib/libcurses/lib_kernel.c +++ b/lib/libcurses/lib_kernel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_kernel.c,v 1.5 1998/07/23 21:18:58 millert Exp $ */ +/* $OpenBSD: lib_kernel.c,v 1.6 1998/10/31 06:30:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -54,7 +54,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_kernel.c,v 1.17 1998/02/11 12:13:57 tom Exp $") +MODULE_ID("$From: lib_kernel.c,v 1.18 1998/09/20 03:34:18 tom Exp $") int reset_prog_mode(void) { @@ -62,8 +62,11 @@ int reset_prog_mode(void) if (cur_term != 0) { _nc_set_curterm(&cur_term->Nttyb); - if (SP && stdscr && stdscr->_use_keypad) - _nc_keypad(TRUE); + if (SP) { + if (stdscr && stdscr->_use_keypad) + _nc_keypad(TRUE); + NC_BUFFERED(TRUE); + } returnCode(OK); } returnCode(ERR); @@ -77,8 +80,9 @@ int reset_shell_mode(void) if (cur_term != 0) { if (SP) { - fflush(SP->_ofp); _nc_keypad(FALSE); + fflush(SP->_ofp); + NC_BUFFERED(FALSE); } returnCode(_nc_set_curterm(&cur_term->Ottyb)); } diff --git a/lib/libcurses/lib_mouse.c b/lib/libcurses/lib_mouse.c index ae2909174e3..608534277d8 100644 --- a/lib/libcurses/lib_mouse.c +++ b/lib/libcurses/lib_mouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_mouse.c,v 1.7 1998/09/17 04:14:30 millert Exp $ */ +/* $OpenBSD: lib_mouse.c,v 1.8 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -65,6 +65,17 @@ * used yet, and a couple of bits open at the high end. */ +#ifdef __EMX__ +# include "io.h" +# include "fcntl.h" +# define INCL_DOS +# define INCL_VIO +# define INCL_KBD +# define INCL_MOU +# define INCL_DOSPROCESS +# include <os2.h> /* Need to include before the others */ +#endif + #include <curses.priv.h> #include <term.h> @@ -75,7 +86,7 @@ #endif #endif -MODULE_ID("$From: lib_mouse.c,v 1.36 1998/08/22 18:09:52 tom Exp $") +MODULE_ID("$From: lib_mouse.c,v 1.38 1998/10/03 19:08:33 tom Exp $") #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT @@ -125,6 +136,77 @@ static void _trace_slot(const char *tag) } #endif +#ifdef USE_EMX_MOUSE + +# define TOP_ROW 0 +# define LEFT_COL 0 + +static int mouse_wfd; +static int mouse_thread; + +# define M_FD(sp) sp->_mouse_fd + +static void +write_event(int down, int button, int x, int y) +{ + char buf[6]; + unsigned long ignore; + + strcpy(buf, key_mouse); + buf[3] = ' ' + (button - 1) + (down ? 0 : 0x40); + buf[4] = ' ' + x - LEFT_COL + 1; + buf[5] = ' ' + y - TOP_ROW + 1; + DosWrite(mouse_wfd, buf, 6, &ignore); +} + +static void +mouse_server(unsigned long ignored GCC_UNUSED) +{ + unsigned short fWait = MOU_WAIT; + /* NOPTRRECT mourt = { 0,0,24,79 }; */ + MOUEVENTINFO mouev; + HMOU hmou; + unsigned short mask = MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN; + int oldstate = 0; + char errmess[] = "Unexpected termination of mouse thread\r\n"; + unsigned long ignore; + + /* open the handle for the mouse */ + if (MouOpen(NULL,&hmou) == 0) { + + if (MouSetEventMask(&mask,hmou) == 0 + && MouDrawPtr(hmou) == 0) { + + for (;;) { + /* sit and wait on the event queue */ + if (MouReadEventQue(&mouev,&fWait,hmou)) + break; + + /* + * OS/2 numbers a 3-button mouse inconsistently from other + * platforms: + * 1 = left + * 2 = right + * 3 = middle. + */ + if ((mouev.fs ^ oldstate) & MOUSE_BN1_DOWN) + write_event(mouev.fs & MOUSE_BN1_DOWN, 1, mouev.col, mouev.row); + if ((mouev.fs ^ oldstate) & MOUSE_BN2_DOWN) + write_event(mouev.fs & MOUSE_BN2_DOWN, 2, mouev.col, mouev.row); + if ((mouev.fs ^ oldstate) & MOUSE_BN3_DOWN) + write_event(mouev.fs & MOUSE_BN3_DOWN, 3, mouev.col, mouev.row); + + oldstate = mouev.fs; + } + } + + DosWrite(2, errmess, strlen(errmess), &ignore); + MouClose(hmou); + } + DosExit(EXIT_THREAD, 0L ); +} +#endif + /* FIXME: The list of names should be configurable */ static int is_xterm(const char *name) { @@ -170,6 +252,30 @@ static void _nc_mouse_init(void) } #endif + /* OS/2 VIO */ +#ifdef USE_EMX_MOUSE + if (!mouse_thread && mousetype != M_XTERM && key_mouse) { + int handles[2]; + if (pipe(handles) < 0) { + perror("mouse pipe error"); + } else { + int rc; + + mouse_wfd = handles[1]; + M_FD(SP) = handles[0]; + /* Needed? */ + setmode(handles[0], O_BINARY); + setmode(handles[1], O_BINARY); + /* Do not use CRT functions, we may single-threaded. */ + rc = DosCreateThread((unsigned long*)&mouse_thread, mouse_server, 0, 0, 8192); + if (rc) + printf("mouse thread error %d=%#x", rc, rc); + else + mousetype = M_XTERM; + } + } +#endif + T(("_nc_mouse_init() set mousetype to %d", mousetype)); } @@ -261,7 +367,13 @@ static bool _nc_mouse_inline(SCREEN *sp) */ for (grabbed = 0; grabbed < 3; grabbed += res) { + + /* For VIO mouse we add extra bit 64 to disambiguate button-up. */ +#ifdef USE_EMX_MOUSE + res = read( M_FD(sp) >= 0 ? M_FD(sp) : sp->_ifd, &kbuf, 3); +#else res = read(sp->_ifd, kbuf + grabbed, 3-grabbed); +#endif if (res == -1) break; } @@ -277,14 +389,26 @@ static bool _nc_mouse_inline(SCREEN *sp) { case 0x0: eventp->bstate = BUTTON1_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON1_RELEASED; +#endif break; case 0x1: eventp->bstate = BUTTON2_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON2_RELEASED; +#endif break; case 0x2: eventp->bstate = BUTTON3_PRESSED; +#ifdef USE_EMX_MOUSE + if (kbuf[0] & 0x40) + eventp->bstate = BUTTON3_RELEASED; +#endif break; case 0x3: diff --git a/lib/libcurses/lib_mvcur.c b/lib/libcurses/lib_mvcur.c index adb0da65e20..718ee1a3382 100644 --- a/lib/libcurses/lib_mvcur.c +++ b/lib/libcurses/lib_mvcur.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_mvcur.c,v 1.11 1998/09/17 04:14:31 millert Exp $ */ +/* $OpenBSD: lib_mvcur.c,v 1.12 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -155,7 +155,7 @@ #include <term.h> #include <ctype.h> -MODULE_ID("$From: lib_mvcur.c,v 1.52 1998/09/12 23:03:26 tom Exp $") +MODULE_ID("$From: lib_mvcur.c,v 1.54 1998/10/03 23:41:21 tom Exp $") #define STRLEN(s) (s != 0) ? strlen(s) : 0 @@ -286,7 +286,7 @@ void _nc_mvcur_resume(void) */ reset_scroll_region(); SP->_cursrow = SP->_curscol = -1; - + /* restore cursor shape */ if (SP->_cursor != -1) { @@ -320,6 +320,13 @@ void _nc_mvcur_init(void) SP->_cud1_cost = CostOf(cursor_down, 0); SP->_cuu1_cost = CostOf(cursor_up, 0); + SP->_smir_cost = CostOf(enter_insert_mode, 0); + SP->_rmir_cost = CostOf(exit_insert_mode, 0); + SP->_ip_cost = 0; + if (insert_padding) { + SP->_ip_cost = CostOf(insert_padding, 0); + } + /* * Assumption: if the terminal has memory_relative addressing, the * initialization strings or smcup will set single-page mode so we @@ -599,7 +606,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) *sp++ = WANT_CHAR(to_y, from_x + i); *sp = '\0'; lhcost += n * SP->_char_padding; - } + } else #endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ { @@ -892,6 +899,10 @@ int mvcur(int yold, int xold, int ynew, int xnew) return(onscreen_mvcur(yold, xold, ynew, xnew, TRUE)); } +#if defined(TRACE) || defined(NCURSES_TEST) +int _nc_optimize_enable = OPTIMIZE_ALL; +#endif + #if defined(MAIN) || defined(NCURSES_TEST) /**************************************************************************** * @@ -1050,7 +1061,7 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) else if (buf[0] == 'i') { dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE); - dump_entry(&cur_term->type, 0, 0); + dump_entry(&cur_term->type, FALSE, TRUE, 0); putchar('\n'); } else if (buf[0] == 'o') diff --git a/lib/libcurses/lib_newterm.c b/lib/libcurses/lib_newterm.c index af7998bc5eb..f3d130c073c 100644 --- a/lib/libcurses/lib_newterm.c +++ b/lib/libcurses/lib_newterm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_newterm.c,v 1.5 1998/07/23 21:19:06 millert Exp $ */ +/* $OpenBSD: lib_newterm.c,v 1.6 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -50,7 +50,7 @@ #include <term.h> /* clear_screen, cup & friends, cur_term */ -MODULE_ID("$From: lib_newterm.c,v 1.34 1998/04/11 22:53:05 tom Exp $") +MODULE_ID("$From: lib_newterm.c,v 1.35 1998/09/19 21:43:22 tom Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -98,10 +98,10 @@ SCREEN * newterm(NCURSES_CONST char *term, FILE *ofp, FILE *ifp) int errret; SCREEN* current; #ifdef TRACE -char *t = getenv("NCURSES_TRACE"); +int t = _nc_getenv_num("NCURSES_TRACE"); - if (t) - trace((unsigned) strtol(t, 0, 0)); + if (t >= 0) + trace(t); #endif T((T_CALLED("newterm(\"%s\",%p,%p)"), term, ofp, ifp)); diff --git a/lib/libcurses/lib_redrawln.c b/lib/libcurses/lib_redrawln.c index 8019c27aaba..9b0e99cdebb 100644 --- a/lib/libcurses/lib_redrawln.c +++ b/lib/libcurses/lib_redrawln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_redrawln.c,v 1.2 1998/07/23 21:19:15 millert Exp $ */ +/* $OpenBSD: lib_redrawln.c,v 1.3 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -41,28 +41,31 @@ #include <curses.priv.h> -MODULE_ID("$From: lib_redrawln.c,v 1.6 1998/03/22 01:40:42 tom Exp $") +MODULE_ID("$From: lib_redrawln.c,v 1.7 1998/09/19 20:09:50 Alexander.V.Lukyanov Exp $") int wredrawln(WINDOW *win, int beg, int num) -{ - int i; - int end; - size_t len = (win->_maxx + 1) * sizeof(chtype); - - T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); - - if (beg < 0) - beg = 0; - - if (touchline (win, beg, num) == ERR) - returnCode(ERR); - +{ + int i; + int end; + size_t len = (win->_maxx + 1) * sizeof(chtype); + + T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); + + if (beg < 0) + beg = 0; + + if (touchline (win, beg, num) == ERR) + returnCode(ERR); + end = beg + num; - if (end > win->_maxy + 1) - end = win->_maxy + 1; - - for (i = beg; i < end; i++) - memset (curscr->_line[i+win->_begy].text+win->_begx, 0, len); - - returnCode(OK); + if (end > win->_maxy + 1) + end = win->_maxy + 1; + + for (i = beg; i < end; i++) + { + memset (curscr->_line[i+win->_begy].text+win->_begx, 0, len); + _nc_make_oldhash(i+win->_begy); + } + + returnCode(OK); } diff --git a/lib/libcurses/lib_set_term.c b/lib/libcurses/lib_set_term.c index 10c913fc3ca..e50e36577ee 100644 --- a/lib/libcurses/lib_set_term.c +++ b/lib/libcurses/lib_set_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_set_term.c,v 1.7 1998/09/17 04:14:31 millert Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.8 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -46,7 +46,7 @@ #include <term.h> /* cur_term */ -MODULE_ID("$From: lib_set_term.c,v 1.40 1998/09/12 23:16:41 tom Exp $") +MODULE_ID("$From: lib_set_term.c,v 1.42 1998/09/20 03:58:06 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -108,10 +108,15 @@ void _nc_set_buffer(FILE *ofp, bool buffered) unsigned buf_len; char *buf_ptr; - if (buffered) { + fflush(ofp); + if ((SP->_buffered = buffered) != 0) { buf_len = min(LINES * (COLS + 6), 2800); - if ((buf_ptr = malloc(buf_len)) == NULL) - return; + if ((buf_ptr = SP->_setbuf) == 0) { + if ((buf_ptr = malloc(buf_len)) == NULL) + return; + SP->_setbuf = buf_ptr; + /* Don't try to free this! */ + } } else { buf_len = 0; buf_ptr = 0; @@ -127,11 +132,6 @@ void _nc_set_buffer(FILE *ofp, bool buffered) (void) setbuffer(ofp, buf_ptr, (int)buf_len); #endif - if (!buffered) { - FreeIfNeeded(SP->_setbuf); - } - SP->_setbuf = buf_ptr; - #endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ } @@ -193,6 +193,11 @@ void delscreen(SCREEN *sp) FreeIfNeeded(sp->_color_table); FreeIfNeeded(sp->_color_pairs); + FreeIfNeeded(sp->oldhash); + FreeIfNeeded(sp->newhash); + + del_curterm(sp->_term); + free(sp); /* @@ -306,6 +311,9 @@ size_t i; _nc_windows = 0; /* no windows yet */ + SP->oldhash = 0; + SP->newhash = 0; + T(("creating newscr")); if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) return ERR; diff --git a/lib/libcurses/lib_setup.c b/lib/libcurses/lib_setup.c index 71cec9dd200..090c63e26c4 100644 --- a/lib/libcurses/lib_setup.c +++ b/lib/libcurses/lib_setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_setup.c,v 1.3 1998/09/13 19:16:28 millert Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.4 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -50,7 +50,7 @@ #include <term.h> /* lines, columns, cur_term */ -MODULE_ID("$From: lib_setup.c,v 1.42 1998/09/05 22:15:14 tom Exp $") +MODULE_ID("$From: lib_setup.c,v 1.46 1998/09/26 12:22:30 tom Exp $") /**************************************************************************** * @@ -106,9 +106,6 @@ int LINES, COLS, TABSIZE; static void _nc_get_screensize(int *linep, int *colp) /* Obtain lines/columns values from the environment and/or terminfo entry */ { -char *rows, *cols, *p; -long l; - /* figure out the size of the screen */ T(("screen size: terminfo lines = %d columns = %d", lines, columns)); @@ -119,18 +116,16 @@ long l; } else /* usually want to query LINES and COLUMNS from environment */ { + int value; + *linep = *colp = 0; /* first, look for environment variables */ - if ((rows = getenv("LINES")) != 0) { - l = strtol(rows, &p, 10); - if (p != rows && *p == '\0' && l != LONG_MIN && l <= INT_MAX) - *linep = (int)l; + if ((value = _nc_getenv_num("LINES")) > 0) { + *linep = value; } - if ((cols = getenv("COLUMNS")) != 0) { - l = strtol(cols, &p, 10); - if (p != cols && *p == '\0' && l != LONG_MIN && l <= INT_MAX) - *colp = (int)l; + if ((value = _nc_getenv_num("COLUMNS")) > 0) { + *colp = value; } T(("screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); @@ -141,7 +136,7 @@ long l; _scrsize(screendata); *colp = screendata[0]; *linep = screendata[1]; - T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); + T(("EMX screen size: environment LINES = %d COLUMNS = %d",*linep,*colp)); } #endif #if HAVE_SIZECHANGE @@ -247,26 +242,42 @@ static int grab_entry(const char *const tn, TERMTYPE *const tp) /* return 1 if entry found, 0 if not found, -1 if database not accessible */ { char filename[PATH_MAX]; - int status; + int status = 0; int _nc_read_bsd_terminfo_entry(const char *, TERMTYPE *); /* XXX */ #ifdef __OpenBSD__ - if ((status = _nc_read_bsd_terminfo_entry(tn, tp)) == 1) - return(1); + status = _nc_read_bsd_terminfo_entry(tn, tp); #endif /* __OpenBSD__ */ - if ((status = _nc_read_entry(tn, filename, tp)) == 1) - return(1); + if (status != 1 && (status = _nc_read_entry(tn, filename, tp)) != 1) { #ifndef PURE_TERMINFO - /* - * Try falling back on the termcap file. Note: allowing this call - * links the entire terminfo/termcap compiler into the startup code. - * It's preferable to build a real terminfo database and use that. - */ - status = _nc_read_termcap_entry(tn, tp); + /* + * Try falling back on the termcap file. + * Note: allowing this call links the entire terminfo/termcap + * compiler into the startup code. It's preferable to build a + * real terminfo database and use that. + */ + status = _nc_read_termcap_entry(tn, tp); #endif /* PURE_TERMINFO */ + } + + /* + * If we have an entry, force all of the cancelled strings to null + * pointers so we don't have to test them in the rest of the library. + * (The terminfo compiler bypasses this logic, since it must know if + * a string is cancelled, for merging entries). + */ + if (status == 1) { + unsigned n; + for (n = 0; n < BOOLCOUNT; n++) + if (!VALID_BOOLEAN(tp->Booleans[n])) + tp->Booleans[n] = FALSE; + for (n = 0; n < STRCOUNT; n++) + if (tp->Strings[n] == CANCELLED_STRING) + tp->Strings[n] = ABSENT_STRING; + } return(status); } #endif diff --git a/lib/libcurses/lib_termcap.c b/lib/libcurses/lib_termcap.c index bfab90e9c0c..7482a87a510 100644 --- a/lib/libcurses/lib_termcap.c +++ b/lib/libcurses/lib_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_termcap.c,v 1.2 1998/07/27 03:37:32 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.3 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -178,8 +178,7 @@ int i; if (cur_term != 0) { for (i = 0; i < BOOLCOUNT; i++) { if (!strncmp(id, boolcodes[i], 2)) { - if (!VALID_BOOLEAN(cur_term->type.Booleans[i])) - return 0; + /* setupterm forces invalid booleans to false */ return cur_term->type.Booleans[i]; } } @@ -232,8 +231,7 @@ int i; T(("trying %s", strcodes[i])); if (!strncmp(id, strcodes[i], 2)) { T(("found match : %s", _nc_visbuf(cur_term->type.Strings[i]))); - if (!VALID_STRING(cur_term->type.Strings[i])) - return 0; + /* setupterm forces cancelled strings to null */ return cur_term->type.Strings[i]; } } diff --git a/lib/libcurses/lib_ti.c b/lib/libcurses/lib_ti.c index da472a9297d..ddb80607aaf 100644 --- a/lib/libcurses/lib_ti.c +++ b/lib/libcurses/lib_ti.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_ti.c,v 1.1 1998/07/23 21:19:37 millert Exp $ */ +/* $OpenBSD: lib_ti.c,v 1.2 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -39,7 +39,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: lib_ti.c,v 1.11 1998/07/18 02:14:05 tom Exp $") +MODULE_ID("$From: lib_ti.c,v 1.12 1998/09/26 12:26:38 tom Exp $") int tigetflag(NCURSES_CONST char *str) { @@ -50,8 +50,7 @@ int i; if (cur_term != 0) { for (i = 0; i < BOOLCOUNT; i++) { if (!strcmp(str, boolnames[i])) { - if (!VALID_BOOLEAN(cur_term->type.Booleans[i])) - return 0; + /* setupterm forces invalid booleans to false */ return cur_term->type.Booleans[i]; } } @@ -88,8 +87,7 @@ int i; if (cur_term != 0) { for (i = 0; i < STRCOUNT; i++) { if (!strcmp(str, strnames[i])) { - if (!VALID_STRING(cur_term->type.Strings[i])) - return 0; + /* setupterm forces cancelled strings to null */ return cur_term->type.Strings[i]; } } diff --git a/lib/libcurses/lib_tparm.c b/lib/libcurses/lib_tparm.c index 4e7386c2c69..f2461c7aaec 100644 --- a/lib/libcurses/lib_tparm.c +++ b/lib/libcurses/lib_tparm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tparm.c,v 1.4 1998/09/13 19:16:28 millert Exp $ */ +/* $OpenBSD: lib_tparm.c,v 1.5 1998/10/31 06:30:30 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.32 1998/08/15 23:37:16 tom Exp $") +MODULE_ID("$From: lib_tparm.c,v 1.36 1998/10/11 00:28:53 tom Exp $") /* * char * @@ -105,9 +105,6 @@ MODULE_ID("$From: lib_tparm.c,v 1.32 1998/08/15 23:37:16 tom Exp $") * resulting in x mod y, not the reverse. */ -#define L_BRACE '{' -#define R_BRACE '}' - #define STACKSIZE 20 typedef union { @@ -136,35 +133,50 @@ void _nc_free_tparm(void) } #endif -static void save_text(size_t limit, char *s) +static void really_get_space(size_t need) { - size_t want = strlen(s) + limit; - size_t need = want + out_used + 1; - - if (need > out_size) { - out_size = need * 2; - out_buff = (char *)_nc_doalloc(out_buff, out_size); - } + out_size = need * 2; + out_buff = (char *)_nc_doalloc(out_buff, out_size); if (out_buff == 0) _nc_err_abort("Out of memory"); - (void)strcpy(out_buff + out_used, s); - out_used += want; } -static void save_number(const char *fmt, int number) +static inline void get_space(size_t need) { - char temp[80]; - (void)sprintf(temp, fmt, number); - save_text(0, temp); + need += out_used; + if (need > out_size) + really_get_space(need); +} + +static inline void save_text(const char *fmt, char *s, int len) +{ + size_t s_len = strlen(s); + if (len > (int)s_len) + s_len = len; + + get_space(s_len + 1); + + (void)sprintf(out_buff+out_used, fmt, s); + out_used += strlen(out_buff+out_used); +} + +static inline void save_number(const char *fmt, int number, int len) +{ + if (len < 30) + len = 30; /* actually log10(MAX_INT)+1 */ + + get_space(len + 1); + + (void)sprintf(out_buff+out_used, fmt, number); + out_used += strlen(out_buff+out_used); } static inline void save_char(int c) { - static char text[2]; if (c == 0) c = 0200; - text[0] = c; - save_text(0, text); + get_space(1); + out_buff[out_used++] = c; } static inline void npush(int x) @@ -191,8 +203,8 @@ static inline const char *parse_format(const char *s, char *format, int *len) bool done = FALSE; bool allowminus = FALSE; bool dot = FALSE; - int maxlen = 0; - int minlen = 0; + int prec = 0; + int width = 0; *len = 0; *format++ = '%'; @@ -231,9 +243,9 @@ static inline const char *parse_format(const char *s, char *format, int *len) default: if (isdigit(*s)) { if (dot) - maxlen = (maxlen * 10) + (*s - '0'); + prec = (prec * 10) + (*s - '0'); else - minlen = (minlen * 10) + (*s - '0'); + width = (width * 10) + (*s - '0'); *format++ = *s++; } else { done = TRUE; @@ -241,7 +253,8 @@ static inline const char *parse_format(const char *s, char *format, int *len) } } *format = '\0'; - *len = (maxlen > minlen) ? maxlen : minlen; + /* return maximum string length in print */ + *len = (prec > width) ? prec : width; return s; } @@ -331,7 +344,7 @@ static int static_vars[NUM_VARS]; #ifdef TRACE if (_nc_tracing & TRACE_CALLS) { for (i = 0; i < popcount; i++) - save_number(", %d", param[i]); + save_number(", %d", param[i], 0); _tracef(T_CALLED("%s(%s%s)"), tname, _nc_visbuf(string), out_buff); out_used = 0; } @@ -355,15 +368,15 @@ static int static_vars[NUM_VARS]; case 'x': /* FALLTHRU */ case 'X': /* FALLTHRU */ case 'c': - save_number(format, npop()); + save_number(format, npop(), len); break; case 'l': - save_number("%d", strlen(spop())); + save_number("%d", strlen(spop()), 0); break; case 's': - save_text(len, spop()); + save_text(format, spop(), len); break; case 'p': @@ -394,7 +407,7 @@ static int static_vars[NUM_VARS]; } break; - case '\'': + case S_QUOTE: string++; npush(*string); string++; @@ -553,8 +566,7 @@ static int static_vars[NUM_VARS]; if (out_buff == 0 && (out_buff = calloc(1,1)) == NULL) return(NULL); - if (out_used == 0) - *out_buff = '\0'; + out_buff[out_used] = '\0'; T((T_RETURN("%s"), _nc_visbuf(out_buff))); return(out_buff); diff --git a/lib/libcurses/lib_tputs.c b/lib/libcurses/lib_tputs.c index c19e326de79..dfe3bcf8878 100644 --- a/lib/libcurses/lib_tputs.c +++ b/lib/libcurses/lib_tputs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_tputs.c,v 1.1 1998/07/23 21:19:38 millert Exp $ */ +/* $OpenBSD: lib_tputs.c,v 1.2 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -47,7 +47,7 @@ #include <term.h> /* padding_baud_rate, xon_xoff */ #include <tic.h> -MODULE_ID("$From: lib_tputs.c,v 1.32 1998/05/09 23:01:25 tom Exp $") +MODULE_ID("$From: lib_tputs.c,v 1.33 1998/09/19 20:35:49 tom Exp $") #define OUTPUT ((SP != 0) ? SP->_ofp : stdout) @@ -111,7 +111,7 @@ int trailpad; #endif /* BSD_TPUTS */ #ifdef TRACE -char addrbuf[17]; +char addrbuf[32]; if (_nc_tracing & TRACE_TPUTS) { diff --git a/lib/libcurses/lib_trace.c b/lib/libcurses/lib_trace.c index f2e4bff596e..a64b90aa7af 100644 --- a/lib/libcurses/lib_trace.c +++ b/lib/libcurses/lib_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_trace.c,v 1.4 1998/07/27 03:37:33 millert Exp $ */ +/* $OpenBSD: lib_trace.c,v 1.5 1998/10/31 06:30:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -40,7 +40,7 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$From: lib_trace.c,v 1.29 1998/07/25 20:11:02 tom Exp $") +MODULE_ID("$From: lib_trace.c,v 1.30 1998/10/03 23:41:42 tom Exp $") #include <ctype.h> #if HAVE_FCNTL_H @@ -52,7 +52,6 @@ unsigned _nc_tracing = 0; /* always define this */ #ifdef TRACE const char *_nc_tputs_trace = ""; long _nc_outchars; -int _nc_optimize_enable = OPTIMIZE_ALL; static FILE * tracefp; /* default to writing to stderr */ #endif diff --git a/lib/libcurses/name_match.c b/lib/libcurses/name_match.c index 77bcc42081c..b86f1b0fadd 100644 --- a/lib/libcurses/name_match.c +++ b/lib/libcurses/name_match.c @@ -1,4 +1,4 @@ -/* $OpenBSD: name_match.c,v 1.1 1998/07/23 21:19:53 millert Exp $ */ +/* $OpenBSD: name_match.c,v 1.2 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -37,7 +37,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: name_match.c,v 1.6 1998/05/31 01:10:13 tom Exp $") +MODULE_ID("$From: name_match.c,v 1.7 1998/09/19 20:27:49 Todd.Miller Exp $") /* * _nc_first_name(char *names) diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index 843d41bddd1..f5535f8d735 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ncurses_cfg.h,v 1.6 1998/09/12 05:47:14 millert Exp $ */ +/* $OpenBSD: ncurses_cfg.h,v 1.7 1998/10/31 06:30:31 millert Exp $ */ /* include/ncurses_cfg.h. Generated automatically by configure. */ /**************************************************************************** @@ -105,7 +105,8 @@ /* #define PURE_TERMINFO 1 */ #define RETSIGTYPE void #define STDC_HEADERS 1 -#define SYSTEM_NAME "openbsd2.3" +#define SYSTEM_NAME "openbsd2.4" +#define TERMINFO_DIRS "/usr/share/terminfo" #define TYPEOF_CHTYPE long #define USE_DATABASE 1 #define USE_HASHMAP 1 diff --git a/lib/libcurses/read_entry.c b/lib/libcurses/read_entry.c index eade3d7e604..db0f9235ac5 100644 --- a/lib/libcurses/read_entry.c +++ b/lib/libcurses/read_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_entry.c,v 1.4 1998/10/08 04:20:00 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.5 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -49,7 +49,7 @@ #include <term.h> #include <tic.h> -MODULE_ID("$From: read_entry.c,v 1.42 1998/08/09 11:59:36 tom Exp $") +MODULE_ID("$From: read_entry.c,v 1.46 1998/10/11 00:30:55 tom Exp $") #ifndef O_BINARY #define O_BINARY 0 @@ -130,6 +130,8 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) return(0); } } + else + str_count = 0; /* grab the name */ read(fd, buf, min(MAX_NAME_SIZE, (unsigned)name_size)); @@ -201,6 +203,8 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) 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); } @@ -223,6 +227,20 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) } } + /* make sure all strings are NUL terminated */ + for (i = str_count; i < STRCOUNT; i++) { + char *p; + + 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; + } + } + close(fd); return(1); } @@ -307,20 +325,10 @@ char ttn[MAX_ALIAS + 3]; && _nc_read_tic_entry(filename, _nc_tic_dir(envp), ttn, tp) == 1) return 1; - /* this is an ncurses extension */ - if (!issetugid() && (envp = getenv("HOME")) != 0 && - strlen(envp) + sizeof(PRIVATE_INFO) <= PATH_MAX) - { - char *home = malloc(strlen(envp) + sizeof(PRIVATE_INFO)); - - if (home == 0) - return(0); - (void) sprintf(home, PRIVATE_INFO, envp); - if (_nc_read_tic_entry(filename, home, ttn, tp) == 1) { - free(home); + if (!issetugid() && (envp = _nc_home_terminfo()) != 0) { + if (_nc_read_tic_entry(filename, envp, ttn, tp) == 1) { return(1); } - free(home); } /* this is an ncurses extension */ diff --git a/lib/libcurses/read_termcap.c b/lib/libcurses/read_termcap.c index bd6da55add1..f2da7081f69 100644 --- a/lib/libcurses/read_termcap.c +++ b/lib/libcurses/read_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_termcap.c,v 1.5 1998/10/08 04:20:00 millert Exp $ */ +/* $OpenBSD: read_termcap.c,v 1.6 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -63,7 +63,7 @@ #include <fcntl.h> #endif -MODULE_ID("$From: read_termcap.c,v 1.35 1998/08/18 01:37:53 tom Exp $") +MODULE_ID("$From: read_termcap.c,v 1.37 1998/09/19 21:42:14 tom Exp $") #ifndef PURE_TERMINFO @@ -1012,11 +1012,14 @@ int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) else ADD_TC("/usr/share/misc/termcap", filecount); - if (!issetugid() && (h = getenv("HOME")) != NULL && strlen(h) + 9 < PATH_MAX) +#define PRIVATE_CAP "%s/.termcap" + + if (!issetugid() && (h = getenv("HOME")) != NULL + && (strlen(h) + sizeof(PRIVATE_CAP)) < PATH_MAX) { /* user's .termcap, if any, should override it */ (void) strcpy(envhome, h); - (void) sprintf(pathbuf, "%s/.termcap", envhome); + (void) sprintf(pathbuf, PRIVATE_CAP, envhome); ADD_TC(pathbuf, filecount); } } diff --git a/lib/libcurses/resizeterm.c b/lib/libcurses/resizeterm.c index a188a61113c..7ecd31ec689 100644 --- a/lib/libcurses/resizeterm.c +++ b/lib/libcurses/resizeterm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resizeterm.c,v 1.3 1998/07/23 21:20:00 millert Exp $ */ +/* $OpenBSD: resizeterm.c,v 1.4 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("$From: resizeterm.c,v 1.6 1998/02/11 12:13:55 tom Exp $") +MODULE_ID("$From: resizeterm.c,v 1.7 1998/09/19 19:27:43 Alexander.V.Lukyanov Exp $") /* * This function reallocates NCURSES window structures. It is invoked in @@ -71,7 +71,7 @@ resizeterm(int ToLines, int ToCols) #if USE_SIGWINCH ungetch(KEY_RESIZE); /* so application can know this */ - clearok(curscr, TRUE); /* screen contents is unknown */ + clearok(curscr, TRUE); /* screen contents are unknown */ #endif for (wp = _nc_windows; wp != 0; wp = wp->next) { @@ -107,6 +107,9 @@ resizeterm(int ToLines, int ToCols) screen_columns = columns = ToCols; SP->_lines_avail = lines - stolen; + + if (SP->oldhash) { FreeAndNull(SP->oldhash); } + if (SP->newhash) { FreeAndNull(SP->newhash); } } /* diff --git a/lib/libcurses/tic.h b/lib/libcurses/tic.h index bbc67e0ad7e..4547129288b 100644 --- a/lib/libcurses/tic.h +++ b/lib/libcurses/tic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tic.h,v 1.1 1998/07/23 21:20:06 millert Exp $ */ +/* $OpenBSD: tic.h,v 1.2 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -226,7 +226,7 @@ extern void _nc_warning(const char *const,...) GCC_PRINTFLIKE(1,2); extern bool _nc_suppress_warnings; /* comp_expand.c: expand string into readable form */ -extern char *_nc_tic_expand(const char *, bool); +extern char *_nc_tic_expand(const char *, bool, bool); /* comp_scan.c: decode string from readable form */ extern char _nc_trans_string(char *); diff --git a/lib/libcurses/write_entry.c b/lib/libcurses/write_entry.c index 4ecda83d004..8bf95fc8dfe 100644 --- a/lib/libcurses/write_entry.c +++ b/lib/libcurses/write_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: write_entry.c,v 1.4 1998/09/13 19:16:31 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.5 1998/10/31 06:30:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -51,7 +51,7 @@ #define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) #endif -MODULE_ID("$From: write_entry.c,v 1.31 1998/08/22 18:02:09 tom Exp $") +MODULE_ID("$From: write_entry.c,v 1.33 1998/09/19 21:24:11 tom Exp $") static int total_written; @@ -119,21 +119,15 @@ void _nc_set_writedir(char *dir) destination = _nc_tic_dir(0); if (make_directory(destination) < 0) { - char *home; + char *home = _nc_home_terminfo(); - /* ncurses extension...fall back on user's private directory */ - if ((home = getenv("HOME")) != (char *)NULL && - strlen(home) + sizeof(PRIVATE_INFO) <= PATH_MAX) - { - char *temp = malloc(sizeof(PRIVATE_INFO) + strlen(home)); - if (temp == NULL) - _nc_err_abort("Out of memory"); - (void) sprintf(temp, PRIVATE_INFO, home); - destination = temp; + if (home != 0) { if (make_directory(destination) < 0) _nc_err_abort("%s: permission denied (errno %d)", destination, errno); + + destination = home; } } |