From c4d90db4f4e50bb8a971955ce4812262da4a50bc Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 13 Jan 2008 02:05:47 +0000 Subject: [PATCH 1/1] ncurses 5.6 - patch 20080112 + remove recursive-mutex definitions, finish threading demo for worm.c + remove a redundant adjustment of lines in resizeterm.c's adjust_window() which caused occasional misadjustment of stdscr when softkeys were used. --- NEWS | 8 +++++++- dist.mk | 6 +++--- ncurses/base/lib_newterm.c | 6 +++--- ncurses/base/lib_newwin.c | 6 +++--- ncurses/base/lib_slk.c | 23 +++++++++++------------ ncurses/base/lib_slkinit.c | 11 ++++++----- ncurses/base/resizeterm.c | 22 ++++++++++++---------- ncurses/base/use_window.c | 8 ++++---- ncurses/curses.priv.h | 16 ++++++++++------ ncurses/tinfo/lib_data.c | 35 +++++++++++++++++++++++++++++------ test/ncurses.c | 8 +++++--- test/worm.c | 13 +++++++++---- 12 files changed, 102 insertions(+), 60 deletions(-) diff --git a/NEWS b/NEWS index 4778fc2f..72b0b8df 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.1195 2008/01/06 00:01:08 tom Exp $ +-- $Id: NEWS,v 1.1197 2008/01/13 01:05:34 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,12 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20080112 + + remove recursive-mutex definitions, finish threading demo for worm.c + + remove a redundant adjustment of lines in resizeterm.c's + adjust_window() which caused occasional misadjustment of stdscr when + softkeys were used. + 20080105 + several improvements to terminfo entries based on xterm #230 -TD + modify MKlib_gen.sh to handle keyname/key_name prototypes, so the diff --git a/dist.mk b/dist.mk index 58497df5..bde9e4fa 100644 --- a/dist.mk +++ b/dist.mk @@ -1,5 +1,5 @@ ############################################################################## -# Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. # +# Copyright (c) 1998-2007,2008 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"), # @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.622 2008/01/05 19:49:50 tom Exp $ +# $Id: dist.mk,v 1.624 2008/01/12 16:01:48 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 5 NCURSES_MINOR = 6 -NCURSES_PATCH = 20080105 +NCURSES_PATCH = 20080112 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/base/lib_newterm.c b/ncurses/base/lib_newterm.c index 05cd9b8a..f52562ce 100644 --- a/ncurses/base/lib_newterm.c +++ b/ncurses/base/lib_newterm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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,7 +48,7 @@ #include /* clear_screen, cup & friends, cur_term */ #include -MODULE_ID("$Id: lib_newterm.c,v 1.67 2007/04/21 20:47:32 tom Exp $") +MODULE_ID("$Id: lib_newterm.c,v 1.68 2008/01/12 20:24:40 tom Exp $") #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ #define ONLCR 0 @@ -123,7 +123,7 @@ newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { int value; int errret; - int slk_format = _nc_slk_format; + int slk_format = _nc_globals.slk_format; SCREEN *current; SCREEN *result = 0; diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c index b0f4603a..21ba95f3 100644 --- a/ncurses/base/lib_newwin.c +++ b/ncurses/base/lib_newwin.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_newwin.c,v 1.42 2007/12/22 23:20:18 tom Exp $") +MODULE_ID("$Id: lib_newwin.c,v 1.44 2008/01/13 00:28:13 tom Exp $") static WINDOW * remove_window_from_screen(WINDOW *win) @@ -234,7 +234,7 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) { pthread_mutexattr_t recattr; memset(&recattr, 0, sizeof(recattr)); - pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_NORMAL); pthread_mutex_init(&(wp->mutex_use_window), &recattr); } #endif diff --git a/ncurses/base/lib_slk.c b/ncurses/base/lib_slk.c index 5609e3b5..27b21b08 100644 --- a/ncurses/base/lib_slk.c +++ b/ncurses/base/lib_slk.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2008 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 * @@ -45,7 +45,7 @@ #include #include /* num_labels, label_*, plab_norm */ -MODULE_ID("$Id: lib_slk.c,v 1.30 2005/01/08 21:56:36 tom Exp $") +MODULE_ID("$Id: lib_slk.c,v 1.31 2008/01/12 20:21:00 tom Exp $") /* * We'd like to move these into the screen context structure, but cannot, @@ -56,7 +56,6 @@ _nc_slk_format = 0; /* one more than format specified in slk_init() */ /* * Paint the info line for the PC style SLK emulation. - * */ static void slk_paint_info(WINDOW *win) @@ -119,12 +118,12 @@ _nc_slk_initialize(WINDOW *stwin, int cols) SP->_slk->maxlab = ((num_labels > 0) ? num_labels - : MAX_SKEY(_nc_slk_format)); + : MAX_SKEY(_nc_globals.slk_format)); SP->_slk->maxlen = ((num_labels > 0) ? label_width * label_height - : MAX_SKEY_LEN(_nc_slk_format)); - SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) - ? MAX_SKEY(_nc_slk_format) + : MAX_SKEY_LEN(_nc_globals.slk_format)); + SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_globals.slk_format)) + ? MAX_SKEY(_nc_globals.slk_format) : SP->_slk->maxlab); if (SP->_slk->maxlen <= 0 @@ -148,7 +147,7 @@ _nc_slk_initialize(WINDOW *stwin, int cols) memset(SP->_slk->ent[i].form_text, ' ', max_length); SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); } - if (_nc_slk_format >= 3) { /* PC style */ + if (_nc_globals.slk_format >= 3) { /* PC style */ int gap = (cols - 3 * (3 + 4 * max_length)) / 2; if (gap < 1) @@ -161,7 +160,7 @@ _nc_slk_initialize(WINDOW *stwin, int cols) } slk_paint_info(stwin); } else { - if (_nc_slk_format == 2) { /* 4-4 */ + if (_nc_globals.slk_format == 2) { /* 4-4 */ int gap = cols - (SP->_slk->maxlab * max_length) - 6; if (gap < 1) @@ -172,7 +171,7 @@ _nc_slk_initialize(WINDOW *stwin, int cols) x += (i == 3) ? gap : 1; } } else { - if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ + if (_nc_globals.slk_format == 1) { /* 1 -> 3-2-3 */ int gap = (cols - (SP->_slk->maxlab * max_length) - 5) / 2; @@ -196,8 +195,8 @@ _nc_slk_initialize(WINDOW *stwin, int cols) * per default no SLK keys and may call slk_init again to * define a new layout. (juergen 03-Mar-1999) */ - SP->slk_format = _nc_slk_format; - _nc_slk_format = 0; + SP->slk_format = _nc_globals.slk_format; + _nc_globals.slk_format = 0; returnCode(res); } diff --git a/ncurses/base/lib_slkinit.c b/ncurses/base/lib_slkinit.c index 20c0baa5..c440109b 100644 --- a/ncurses/base/lib_slkinit.c +++ b/ncurses/base/lib_slkinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -38,7 +39,7 @@ */ #include -MODULE_ID("$Id: lib_slkinit.c,v 1.6 2007/05/12 18:14:21 tom Exp $") +MODULE_ID("$Id: lib_slkinit.c,v 1.7 2008/01/12 20:23:39 tom Exp $") NCURSES_EXPORT(int) slk_init(int format) @@ -46,9 +47,9 @@ slk_init(int format) int code = ERR; T((T_CALLED("slk_init(%d)"), format)); - if (format >= 0 && format <= 3 && !_nc_slk_format) { - _nc_slk_format = 1 + format; - code = _nc_ripoffline(-SLK_LINES(_nc_slk_format), _nc_slk_initialize); + if (format >= 0 && format <= 3 && !_nc_globals.slk_format) { + _nc_globals.slk_format = 1 + format; + code = _nc_ripoffline(-SLK_LINES(_nc_globals.slk_format), _nc_slk_initialize); } returnCode(code); } diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c index b2cff216..eb2dd737 100644 --- a/ncurses/base/resizeterm.c +++ b/ncurses/base/resizeterm.c @@ -41,7 +41,7 @@ #include #include -MODULE_ID("$Id: resizeterm.c,v 1.28 2008/01/06 01:23:36 tom Exp $") +MODULE_ID("$Id: resizeterm.c,v 1.30 2008/01/12 22:26:56 tom Exp $") #define stolen_lines (screen_lines - SP->_lines_avail) @@ -210,24 +210,22 @@ adjust_window(WINDOW *win, int ToLines, int ToCols, int stolen EXTRA_DCLS) */ win->_begy += (ToLines - CurLines); } else { - if (myLines == CurLines - stolen - && ToLines != CurLines) + if (myLines == (CurLines - stolen) + && ToLines != CurLines) { myLines = ToLines - stolen; - else if (myLines == CurLines - && ToLines != CurLines) + } else if (myLines == CurLines + && ToLines != CurLines) { myLines = ToLines; + } } - if (myLines > ToLines) + if (myLines > ToLines) { myLines = ToLines; + } if (myCols > ToCols) myCols = ToCols; - if (myLines == CurLines - && ToLines != CurLines) - myLines = ToLines; - if (myCols == CurCols && ToCols != CurCols) myCols = ToCols; @@ -425,6 +423,10 @@ resizeterm(int ToLines, int ToCols) /* ripped-off lines are a special case: if we did not lengthen * them, we haven't moved them either. repaint them, too. + * + * for the rest - stdscr and other windows - the client has to + * decide which to repaint, since without panels, ncurses does + * not know which are really on top. */ for (rop = ripoff_stack; (rop - ripoff_stack) < N_RIPS; rop++) { if (rop->win != stdscr diff --git a/ncurses/base/use_window.c b/ncurses/base/use_window.c index 8792cb47..4c9b1375 100644 --- a/ncurses/base/use_window.c +++ b/ncurses/base/use_window.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2007 Free Software Foundation, Inc. * + * Copyright (c) 2007,2008 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 * @@ -32,7 +32,7 @@ #include -MODULE_ID("$Id: use_window.c,v 1.2 2007/10/20 19:57:55 tom Exp $") +MODULE_ID("$Id: use_window.c,v 1.3 2008/01/13 00:36:22 tom Exp $") #ifdef USE_PTHREADS NCURSES_EXPORT(void) @@ -43,7 +43,7 @@ _nc_lock_window(WINDOW *win) _nc_lock_global(windowlist); for (p = _nc_windows; p != 0; p = p->next) { if (&(p->win) == win) { - pthread_mutex_lock(&(p->mutex_use_window)); + _nc_mutex_lock(&(p->mutex_use_window)); break; } } @@ -58,7 +58,7 @@ _nc_unlock_window(WINDOW *win) _nc_lock_global(windowlist); for (p = _nc_windows; p != 0; p = p->next) { if (&(p->win) == win) { - pthread_mutex_unlock(&(p->mutex_use_window)); + _nc_mutex_unlock(&(p->mutex_use_window)); break; } } diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index 484fd193..1e748eec 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 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 * @@ -34,7 +34,7 @@ /* - * $Id: curses.priv.h,v 1.355 2007/12/29 20:32:54 tom Exp $ + * $Id: curses.priv.h,v 1.357 2008/01/13 00:33:10 tom Exp $ * * curses.priv.h * @@ -314,9 +314,12 @@ color_t; #ifdef USE_PTHREADS #if USE_REENTRANT #include -#define _nc_lock_global(name) pthread_mutex_lock(&_nc_globals.mutex_##name) -#define _nc_try_global(name) pthread_mutex_trylock(&_nc_globals.mutex_##name) -#define _nc_unlock_global(name) pthread_mutex_unlock(&_nc_globals.mutex_##name) +extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *); +extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *); +extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *); +#define _nc_lock_global(name) _nc_mutex_lock(&_nc_globals.mutex_##name) +#define _nc_try_global(name) _nc_mutex_trylock(&_nc_globals.mutex_##name) +#define _nc_unlock_global(name) _nc_mutex_unlock(&_nc_globals.mutex_##name) extern NCURSES_EXPORT(void) _nc_lock_window(WINDOW *); extern NCURSES_EXPORT(void) _nc_unlock_window(WINDOW *); @@ -540,6 +543,8 @@ typedef struct { char *first_name; char **keyname_table; + int slk_format; + char *safeprint_buf; size_t safeprint_used; @@ -1607,7 +1612,6 @@ extern NCURSES_EXPORT_VAR(SCREEN *) SP; #define screen_lines SP->_lines #define screen_columns SP->_columns -extern NCURSES_EXPORT_VAR(int) _nc_slk_format; /* != 0 if slk_init() called */ extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int); /* diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c index d7f3b59a..21b854b9 100644 --- a/ncurses/tinfo/lib_data.c +++ b/ncurses/tinfo/lib_data.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_data.c,v 1.35 2007/12/29 20:29:27 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.39 2008/01/13 01:21:59 tom Exp $") /* * OS/2's native linker complains if we don't initialize public data when @@ -131,6 +131,8 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { NULL, /* first_name */ NULL, /* keyname_table */ + 0, /* slk_format */ + NULL, /* safeprint_buf */ 0, /* safeprint_used */ @@ -177,10 +179,10 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { #endif /* TRACE */ #ifdef USE_PTHREADS - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, /* mutex_set_SP */ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, /* mutex_use_screen */ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, /* mutex_use_window */ - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, /* mutex_windowlist */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_set_SP */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_use_screen */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_use_window */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_windowlist */ PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */ PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */ 0, /* nested_tracef */ @@ -231,3 +233,24 @@ NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { #endif }; /* *INDENT-ON* */ + +/******************************************************************************/ +#ifdef USE_PTHREADS +NCURSES_EXPORT(int) +_nc_mutex_lock(pthread_mutex_t *obj) +{ + return pthread_mutex_lock(obj); +} + +NCURSES_EXPORT(int) +_nc_mutex_trylock(pthread_mutex_t *obj) +{ + return pthread_mutex_trylock(obj); +} + +NCURSES_EXPORT(int) +_nc_mutex_unlock(pthread_mutex_t *obj) +{ + return pthread_mutex_unlock(obj); +} +#endif /* USE_PTHREADS */ diff --git a/test/ncurses.c b/test/ncurses.c index 91acade3..50f24947 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.296 2007/12/29 21:05:43 tom Exp $ +$Id: ncurses.c,v 1.298 2008/01/12 23:06:58 tom Exp $ ***************************************************************************/ @@ -76,7 +76,7 @@ $Id: ncurses.c,v 1.296 2007/12/29 21:05:43 tom Exp $ #define NCURSES_CONST_PARAM const void #ifdef TRACE -static unsigned save_trace = TRACE_ORDINARY | TRACE_CALLS; +static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS; extern unsigned _nc_tracing; #endif @@ -2525,6 +2525,7 @@ slk_test(void) #endif #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE case KEY_RESIZE: + wnoutrefresh(stdscr); break; #endif @@ -2655,6 +2656,7 @@ wide_slk_test(void) break; #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE case KEY_RESIZE: + wnoutrefresh(stdscr); break; #endif default: diff --git a/test/worm.c b/test/worm.c index 61d97a9a..172b1dd8 100644 --- a/test/worm.c +++ b/test/worm.c @@ -61,7 +61,7 @@ Options: traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.50 2007/12/22 23:55:13 tom Exp $ + $Id: worm.c,v 1.51 2008/01/13 01:03:23 tom Exp $ */ #include @@ -93,6 +93,7 @@ typedef struct worm { #endif } WORM; +static unsigned long sequence = 0; static bool quitting = FALSE; static WORM worm[40]; @@ -318,15 +319,19 @@ use_window(WINDOW *win, int (*func) (WINDOW *, void *), void *data) static bool quit_worm(void) { - napms(20); /* let the other thread(s) have a chance */ + napms(10); /* let the other thread(s) have a chance */ return quitting; } static void * start_worm(void *arg) { + unsigned long compare = 0; while (!quit_worm()) { - use_window(stdscr, draw_worm, arg); + while (compare < sequence) { + ++compare; + use_window(stdscr, draw_worm, arg); + } } return NULL; } @@ -492,13 +497,13 @@ main(int argc, char *argv[]) } } } - napms(10); refresh(); nodelay(stdscr, TRUE); while (!done) { int ch; + ++sequence; if ((ch = getch()) > 0) { #ifdef TRACE if (trace_start || trace_end) { -- 2.44.0