1 /****************************************************************************
2 * Copyright (c) 2014 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
30 * Author: Thomas E. Dickey
32 * $Id: dots_curses.c,v 1.3 2014/08/09 22:28:42 tom Exp $
34 * A simple demo of the curses interface used for comparison with termcap.
36 #include <test.priv.h>
38 #if !defined(__MINGW32__)
44 #define valid(s) ((s != 0) && s != (char *)-1)
46 static bool interrupted = FALSE;
47 static long total_chars = 0;
48 static time_t started;
55 printf("\n\n%ld total chars, rate %.2f/sec\n",
57 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
61 onsig(int n GCC_UNUSED)
69 long r = (rand() & 077777);
70 return ((double) r / 32768.);
74 mypair(int fg, int bg)
76 int pair = (fg * COLORS) + bg;
77 return (pair >= COLOR_PAIRS) ? -1 : pair;
81 set_colors(int fg, int bg)
83 int pair = mypair(fg, bg);
85 attron(COLOR_PAIR(mypair(fg, bg)));
90 main(int argc GCC_UNUSED,
91 char *argv[]GCC_UNUSED)
100 srand((unsigned) time(0));
105 for (fg = 0; fg < COLORS; fg++) {
106 for (bg = 0; bg < COLORS; bg++) {
107 int pair = mypair(fg, bg);
109 init_pair((short) pair, (short) fg, (short) bg);
114 r = (double) (LINES - 4);
115 c = (double) (COLS - 4);
116 started = time((time_t *) 0);
120 while (!interrupted) {
121 x = (int) (c * ranf()) + 2;
122 y = (int) (r * ranf()) + 2;
123 p = (ranf() > 0.9) ? '*' : ' ';
127 z = (int) (ranf() * COLORS);
129 set_colors(fg = z, bg);
130 attron(COLOR_PAIR(mypair(fg, bg)));
132 set_colors(fg, bg = z);
136 if (ranf() <= 0.01) {
150 ExitProgram(EXIT_SUCCESS);