1 /****************************************************************************
2 * Copyright (c) 1999-2017,2019 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 <dickey@clark.net> 1999
32 * $Id: dots.c,v 1.34 2019/01/21 14:20:18 tom Exp $
34 * A simple demo of the terminfo interface.
37 #include <test.priv.h>
43 static bool interrupted = FALSE;
44 static long total_chars = 0;
45 static time_t started;
54 if (write(STDOUT_FILENO, &tmp, (size_t) 1) == -1)
65 if (VALID_STRING(s)) {
75 outs(exit_attribute_mode);
76 if (!outs(orig_colors))
81 printf("\n\n%ld total cells, rate %.2f/sec\n",
83 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
87 onsig(int n GCC_UNUSED)
95 long r = (rand() & 077777);
96 return ((double) r / 32768.);
100 get_number(NCURSES_CONST char *cap, int map)
104 int check = tigetnum(cap);
114 static const char *msg[] =
116 "Usage: dots [options]"
119 ," -T TERM override $TERM"
121 ," -e allow environment $LINES / $COLUMNS"
123 ," -f use tigetnum rather than <term.h> mapping"
124 ," -m SIZE set margin (default: 2)"
125 ," -s MSECS delay 1% of the time (default: 1 msecs)"
129 for (n = 0; n < SIZEOF(msg); n++)
130 fprintf(stderr, "%s\n", msg[n]);
132 ExitProgram(EXIT_FAILURE);
149 while ((x = getopt(argc, argv, "T:efm:s:")) != -1) {
152 need = 6 + strlen(optarg);
153 my_env = malloc(need);
154 _nc_SPRINTF(my_env, _nc_SLIMIT(need) "TERM=%s", optarg);
166 m_option = atoi(optarg);
169 s_option = atoi(optarg);
177 InitAndCatch(setupterm((char *) 0, 1, (int *) 0), onsig);
179 srand((unsigned) time(0));
182 outs(cursor_invisible);
184 #define GetNumber(ln,sn) get_number(f_option ? #sn : 0, ln)
185 my_colors = GetNumber(max_colors, colors);
187 if (!VALID_STRING(set_a_foreground)
188 || !VALID_STRING(set_a_background)
189 || (!VALID_STRING(orig_colors) && !VALID_STRING(orig_pair)))
193 r = (double) (GetNumber(lines, lines) - (m_option * 2));
194 c = (double) (GetNumber(columns, cols) - (m_option * 2));
195 started = time((time_t *) 0);
197 while (!interrupted) {
198 x = (int) (c * ranf()) + m_option;
199 y = (int) (r * ranf()) + m_option;
200 p = (ranf() > 0.9) ? '*' : ' ';
202 tputs(tparm3(cursor_address, y, x), 1, outc);
204 z = (int) (ranf() * my_colors);
206 tputs(tparm2(set_a_foreground, z), 1, outc);
208 tputs(tparm2(set_a_background, z), 1, outc);
211 } else if (VALID_STRING(exit_attribute_mode)
212 && VALID_STRING(enter_reverse_mode)) {
213 if (ranf() <= 0.01) {
216 : exit_attribute_mode);
225 ExitProgram(EXIT_SUCCESS);
229 main(int argc GCC_UNUSED,
230 char *argv[]GCC_UNUSED)
232 fprintf(stderr, "This program requires terminfo\n");