# ncurses 5.6 - patch 20080112 - Thomas E. Dickey
#
# ------------------------------------------------------------------------------
#
# Ncurses 5.6 is at
# 	ftp.gnu.org:/pub/gnu
#
# Patches for ncurses 5.6 are in the subdirectory
# 	ftp://invisible-island.net/ncurses/5.6
#
# ------------------------------------------------------------------------------
# patch by Thomas E. Dickey <dickey@invisible-island.net>
# created  Sun Jan 13 02:05:47 UTC 2008
# ------------------------------------------------------------------------------
# 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(-)
# ------------------------------------------------------------------------------
Index: NEWS
Prereq:  1.1195 
--- ncurses-5.6-20080105+/NEWS	2008-01-06 00:01:08.000000000 +0000
+++ ncurses-5.6-20080112/NEWS	2008-01-13 01:05:34.000000000 +0000
@@ -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 @@
 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
Index: dist.mk
Prereq:  1.622 
--- ncurses-5.6-20080105+/dist.mk	2008-01-05 19:49:50.000000000 +0000
+++ ncurses-5.6-20080112/dist.mk	2008-01-12 16:01:48.000000000 +0000
@@ -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 @@
 # 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)
Index: ncurses/base/lib_newterm.c
Prereq:  1.67 
--- ncurses-5.6-20080105+/ncurses/base/lib_newterm.c	2007-04-21 20:47:32.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/lib_newterm.c	2008-01-12 20:24:40.000000000 +0000
@@ -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 <term.h>		/* clear_screen, cup & friends, cur_term */
 #include <tic.h>
 
-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 @@
 {
     int value;
     int errret;
-    int slk_format = _nc_slk_format;
+    int slk_format = _nc_globals.slk_format;
     SCREEN *current;
     SCREEN *result = 0;
 
Index: ncurses/base/lib_newwin.c
Prereq:  1.42 
--- ncurses-5.6-20080105+/ncurses/base/lib_newwin.c	2007-12-22 23:20:18.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/lib_newwin.c	2008-01-13 00:28:13.000000000 +0000
@@ -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 <curses.priv.h>
 
-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 @@
     {
 	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
Index: ncurses/base/lib_slk.c
Prereq:  1.30 
--- ncurses-5.6-20080105+/ncurses/base/lib_slk.c	2005-01-08 21:56:36.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/lib_slk.c	2008-01-12 20:21:00.000000000 +0000
@@ -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 <ctype.h>
 #include <term.h>		/* 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 @@
 
 /*
  * Paint the info line for the PC style SLK emulation.
- *
  */
 static void
 slk_paint_info(WINDOW *win)
@@ -119,12 +118,12 @@
 
     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 @@
 	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 @@
 	}
 	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 @@
 		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 @@
      * 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);
 }
 
Index: ncurses/base/lib_slkinit.c
Prereq:  1.6 
--- ncurses-5.6-20080105+/ncurses/base/lib_slkinit.c	2007-05-12 18:14:21.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/lib_slkinit.c	2008-01-12 20:23:39.000000000 +0000
@@ -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 <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
 /*
@@ -38,7 +39,7 @@
  */
 #include <curses.priv.h>
 
-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 @@
     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);
 }
Index: ncurses/base/resizeterm.c
Prereq:  1.28 
--- ncurses-5.6-20080105+/ncurses/base/resizeterm.c	2008-01-06 01:23:36.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/resizeterm.c	2008-01-12 22:26:56.000000000 +0000
@@ -41,7 +41,7 @@
 #include <curses.priv.h>
 #include <term.h>
 
-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 @@
 	 */
 	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 @@
 
 	    /* 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
Index: ncurses/base/use_window.c
Prereq:  1.2 
--- ncurses-5.6-20080105+/ncurses/base/use_window.c	2007-10-20 19:57:55.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/base/use_window.c	2008-01-13 00:36:22.000000000 +0000
@@ -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 <curses.priv.h>
 
-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_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_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;
 	}
     }
Index: ncurses/curses.priv.h
Prereq:  1.355 
--- ncurses-5.6-20080105+/ncurses/curses.priv.h	2007-12-29 20:32:54.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/curses.priv.h	2008-01-13 00:33:10.000000000 +0000
@@ -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 @@
 #ifdef USE_PTHREADS
 #if USE_REENTRANT
 #include <pthread.h>
-#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 @@
 	char		*first_name;
 	char		**keyname_table;
 
+	int		slk_format;
+
 	char		*safeprint_buf;
 	size_t		safeprint_used;
 
@@ -1607,7 +1612,6 @@
 #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);
 
 /*
Index: ncurses/tinfo/lib_data.c
Prereq:  1.35 
--- ncurses-5.6-20080105+/ncurses/tinfo/lib_data.c	2007-12-29 20:29:27.000000000 +0000
+++ ncurses-5.6-20080112/ncurses/tinfo/lib_data.c	2008-01-13 01:21:59.000000000 +0000
@@ -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 <curses.priv.h>
 
-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 @@
     NULL,			/* first_name */
     NULL,			/* keyname_table */
 
+    0,				/* slk_format */
+
     NULL,			/* safeprint_buf */
     0,				/* safeprint_used */
 
@@ -177,10 +179,10 @@
 
 #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 @@
 #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 */
Index: test/ncurses.c
Prereq:  1.296 
--- ncurses-5.6-20080105+/test/ncurses.c	2007-12-29 21:05:43.000000000 +0000
+++ ncurses-5.6-20080112/test/ncurses.c	2008-01-12 23:06:58.000000000 +0000
@@ -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: Eric S. Raymond <esr@snark.thyrsus.com> 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 @@
 #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 @@
 #endif
 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
 	case KEY_RESIZE:
+	    wnoutrefresh(stdscr);
 	    break;
 #endif
 
@@ -2655,6 +2656,7 @@
 	    break;
 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
 	case KEY_RESIZE:
+	    wnoutrefresh(stdscr);
 	    break;
 #endif
 	default:
Index: test/worm.c
Prereq:  1.50 
--- ncurses-5.6-20080105+/test/worm.c	2007-12-22 23:55:13.000000000 +0000
+++ ncurses-5.6-20080112/test/worm.c	2008-01-13 01:03:23.000000000 +0000
@@ -61,7 +61,7 @@
   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 <test.priv.h>
@@ -93,6 +93,7 @@
 #endif
 } WORM;
 
+static unsigned long sequence = 0;
 static bool quitting = FALSE;
 
 static WORM worm[40];
@@ -318,15 +319,19 @@
 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 @@
 	    }
 	}
     }
-    napms(10);
     refresh();
     nodelay(stdscr, TRUE);
 
     while (!done) {
 	int ch;
 
+	++sequence;
 	if ((ch = getch()) > 0) {
 #ifdef TRACE
 	    if (trace_start || trace_end) {
