]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/worm.c
ncurses 5.7 - patch 20101023
[ncurses.git] / test / worm.c
index 23b0ef4ae85c70792dae3b0ee12d7298942bbba5..0bcd8d3dddc8e2c86f0cfa406a9972f57bb8dd75 100644 (file)
@@ -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.
 
   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.55 2008/01/26 22:07:57 tom Exp $
+  $Id: worm.c,v 1.59 2008/11/16 00:19:59 juergen Exp $
 */
 
 #include <test.priv.h>
 */
 
 #include <test.priv.h>
@@ -109,6 +109,7 @@ static const char *field;
 static int length = 16, number = 3;
 static chtype trail = ' ';
 
 static int length = 16, number = 3;
 static chtype trail = ' ';
 
+static unsigned pending;
 #ifdef TRACE
 static int generation, trace_start, trace_end;
 #endif /* TRACE */
 #ifdef TRACE
 static int generation, trace_start, trace_end;
 #endif /* TRACE */
@@ -227,6 +228,8 @@ draw_worm(WINDOW *win, void *data)
 {
     WORM *w = (WORM *) data;
     const struct options *op;
 {
     WORM *w = (WORM *) data;
     const struct options *op;
+    unsigned mask = ~(1 << (w - worm));
+    chtype attrs = w->attrs | ((mask & pending) ? A_REVERSE : 0);
 
     int x;
     int y;
 
     int x;
     int y;
@@ -236,7 +239,7 @@ draw_worm(WINDOW *win, void *data)
 
     if ((x = w->xpos[h = w->head]) < 0) {
        wmove(win, y = w->ypos[h] = last_y, x = w->xpos[h] = 0);
 
     if ((x = w->xpos[h = w->head]) < 0) {
        wmove(win, y = w->ypos[h] = last_y, x = w->xpos[h] = 0);
-       waddch(win, w->attrs);
+       waddch(win, attrs);
        refs[y][x]++;
     } else {
        y = w->ypos[h];
        refs[y][x]++;
     } else {
        y = w->ypos[h];
@@ -299,7 +302,7 @@ draw_worm(WINDOW *win, void *data)
 
        if (y < 0)
            y = 0;
 
        if (y < 0)
            y = 0;
-       waddch(win, w->attrs);
+       waddch(win, attrs);
 
        w->ypos[h] = y;
        w->xpos[h] = x;
 
        w->ypos[h] = y;
        w->xpos[h] = x;
@@ -311,9 +314,11 @@ draw_worm(WINDOW *win, void *data)
 
 #ifdef USE_PTHREADS
 static bool
 
 #ifdef USE_PTHREADS
 static bool
-quit_worm(void)
+quit_worm(int bitnum)
 {
 {
+    pending |= (1 << bitnum);
     napms(10);                 /* let the other thread(s) have a chance */
     napms(10);                 /* let the other thread(s) have a chance */
+    pending &= ~(1 << bitnum);
     return quitting;
 }
 
     return quitting;
 }
 
@@ -321,12 +326,18 @@ static void *
 start_worm(void *arg)
 {
     unsigned long compare = 0;
 start_worm(void *arg)
 {
     unsigned long compare = 0;
-    while (!quit_worm()) {
+    Trace(("start_worm"));
+    while (!quit_worm(((struct worm *) arg) - worm)) {
        while (compare < sequence) {
            ++compare;
        while (compare < sequence) {
            ++compare;
+#if HAVE_USE_WINDOW
            use_window(stdscr, draw_worm, arg);
            use_window(stdscr, draw_worm, arg);
+#else
+           draw_worm(stdscr, arg);
+#endif
        }
     }
        }
     }
+    Trace(("...start_worm (done)"));
     return NULL;
 }
 #endif
     return NULL;
 }
 #endif
@@ -349,7 +360,13 @@ draw_all_worms(void)
     }
 #else
     for (n = 0, w = &worm[0]; n < number; n++, w++) {
     }
 #else
     for (n = 0, w = &worm[0]; n < number; n++, w++) {
-       if (use_window(stdscr, draw_worm, w))
+       if (
+#if HAVE_USE_WINDOW
+              USING_WINDOW2(stdscr, draw_worm, w)
+#else
+              draw_worm(stdscr, w)
+#endif
+           )
            done = TRUE;
     }
 #endif
            done = TRUE;
     }
 #endif
@@ -576,6 +593,7 @@ main(int argc, char *argv[])
        USING_WINDOW(stdscr, wrefresh);
     }
 
        USING_WINDOW(stdscr, wrefresh);
     }
 
+    Trace(("Cleanup"));
     cleanup();
 #ifdef NO_LEAKS
     for (y = 0; y < LINES; y++) {
     cleanup();
 #ifdef NO_LEAKS
     for (y = 0; y < LINES; y++) {
@@ -591,6 +609,7 @@ main(int argc, char *argv[])
     /*
      * Do this just in case one of the threads did not really exit.
      */
     /*
      * Do this just in case one of the threads did not really exit.
      */
+    Trace(("join all threads"));
     for (n = 0; n < number; n++) {
        pthread_join(worm[n].thread, NULL);
     }
     for (n = 0; n < number; n++) {
        pthread_join(worm[n].thread, NULL);
     }