]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/worm.c
ncurses 5.6 - patch 20080119
[ncurses.git] / test / worm.c
index 61d97a9a404e866a774ee2671b23803d33de9b3a..ea407a0c0606827ff629205bfdde8358677ade63 100644 (file)
@@ -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            *
@@ -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.53 2008/01/19 20:56:38 tom Exp $
 */
 
 #include <test.priv.h>
@@ -93,6 +93,7 @@ typedef struct worm {
 #endif
 } WORM;
 
+static unsigned long sequence = 0;
 static bool quitting = FALSE;
 
 static WORM worm[40];
@@ -306,7 +307,7 @@ draw_worm(WINDOW *win, void *data)
     return done;
 }
 
-#if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915)
+#if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
 static int
 use_window(WINDOW *win, int (*func) (WINDOW *, void *), void *data)
 {
@@ -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;
 }
@@ -357,6 +362,18 @@ draw_all_worms(void)
     return done;
 }
 
+static int
+get_input(void)
+{
+    int ch;
+#ifdef USE_PTHREADS
+    ch = use_window(stdscr, (NCURSES_CALLBACK) wgetch, stdscr);
+#else
+    ch = getch();
+#endif
+    return ch;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -492,22 +509,22 @@ main(int argc, char *argv[])
            }
        }
     }
-    napms(10);
     refresh();
     nodelay(stdscr, TRUE);
 
     while (!done) {
        int ch;
 
-       if ((ch = getch()) > 0) {
+       ++sequence;
+       if ((ch = get_input()) > 0) {
 #ifdef TRACE
            if (trace_start || trace_end) {
                if (generation == trace_start) {
                    trace(TRACE_CALLS);
-                   getch();
+                   get_input();
                } else if (generation == trace_end) {
                    trace(0);
-                   getch();
+                   get_input();
                }
 
                generation++;