]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/dots.c
ncurses 6.2 - patch 20200531
[ncurses.git] / test / dots.c
index bd3c30bb71d48358b8281a5e458d08e19eed16cf..94d90a13ff90d6474deebe303b6e37f114795491 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1999-2017,2019 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 1999-2013,2017 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -29,7 +30,7 @@
 /*
  * Author: Thomas E. Dickey <dickey@clark.net> 1999
  *
 /*
  * Author: Thomas E. Dickey <dickey@clark.net> 1999
  *
- * $Id: dots.c,v 1.35 2019/08/24 21:49:50 tom Exp $
+ * $Id: dots.c,v 1.40 2020/05/29 23:04:02 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
  *
  * A simple demo of the terminfo interface.
  */
@@ -78,9 +79,10 @@ cleanup(void)
     outs(clear_screen);
     outs(cursor_normal);
 
     outs(clear_screen);
     outs(cursor_normal);
 
-    printf("\n\n%ld total cells, rate %.2f/sec\n",
-          total_chars,
-          ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
+    fflush(stdout);
+    fprintf(stderr, "\n\n%ld total cells, rate %.2f/sec\n",
+           total_chars,
+           ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
 }
 
 static void
 }
 
 static void
@@ -122,6 +124,7 @@ usage(void)
 #endif
        ," -f       use tigetnum rather than <term.h> mapping"
        ," -m SIZE  set margin (default: 2)"
 #endif
        ," -f       use tigetnum rather than <term.h> mapping"
        ," -m SIZE  set margin (default: 2)"
+       ," -r SECS  self-interrupt/exit after specified number of seconds"
        ," -s MSECS delay 1% of the time (default: 1 msecs)"
     };
     size_t n;
        ," -s MSECS delay 1% of the time (default: 1 msecs)"
     };
     size_t n;
@@ -142,11 +145,12 @@ main(int argc,
     int my_colors;
     int f_option = 0;
     int m_option = 2;
     int my_colors;
     int f_option = 0;
     int m_option = 2;
+    int r_option = 0;
     int s_option = 1;
     size_t need;
     char *my_env;
 
     int s_option = 1;
     size_t need;
     char *my_env;
 
-    while ((ch = getopt(argc, argv, "T:efm:s:")) != -1) {
+    while ((ch = getopt(argc, argv, "T:efm:r:s:")) != -1) {
        switch (ch) {
        case 'T':
            need = 6 + strlen(optarg);
        switch (ch) {
        case 'T':
            need = 6 + strlen(optarg);
@@ -165,6 +169,9 @@ main(int argc,
        case 'm':
            m_option = atoi(optarg);
            break;
        case 'm':
            m_option = atoi(optarg);
            break;
+       case 'r':
+           r_option = atoi(optarg);
+           break;
        case 's':
            s_option = atoi(optarg);
            break;
        case 's':
            s_option = atoi(optarg);
            break;
@@ -174,6 +181,7 @@ main(int argc,
        }
     }
 
        }
     }
 
+    SetupAlarm(r_option);
     InitAndCatch(setupterm((char *) 0, 1, (int *) 0), onsig);
 
     srand((unsigned) time(0));
     InitAndCatch(setupterm((char *) 0, 1, (int *) 0), onsig);
 
     srand((unsigned) time(0));
@@ -206,7 +214,8 @@ main(int argc,
                tputs(tparm2(set_a_foreground, z), 1, outc);
            } else {
                tputs(tparm2(set_a_background, z), 1, outc);
                tputs(tparm2(set_a_foreground, z), 1, outc);
            } else {
                tputs(tparm2(set_a_background, z), 1, outc);
-               napms(s_option);
+               if (s_option)
+                   napms(s_option);
            }
        } else if (VALID_STRING(exit_attribute_mode)
                   && VALID_STRING(enter_reverse_mode)) {
            }
        } else if (VALID_STRING(exit_attribute_mode)
                   && VALID_STRING(enter_reverse_mode)) {
@@ -214,7 +223,8 @@ main(int argc,
                outs((ranf() > 0.6)
                     ? enter_reverse_mode
                     : exit_attribute_mode);
                outs((ranf() > 0.6)
                     ? enter_reverse_mode
                     : exit_attribute_mode);
-               napms(s_option);
+               if (s_option)
+                   napms(s_option);
            }
        }
        outc(p);
            }
        }
        outc(p);