1 /****************************************************************************
2 * Copyright 2019,2020 Thomas E. Dickey *
3 * Copyright 2007-2013,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
31 * Author: Thomas E. Dickey - 2007
33 * $Id: dots_mvcur.c,v 1.22 2020/02/02 23:34:34 tom Exp $
35 * A simple demo of the terminfo interface, and mvcur.
38 #include <test.priv.h>
44 static bool interrupted = FALSE;
45 static long total_chars = 0;
46 static time_t started;
55 if (write(STDOUT_FILENO, &tmp, (size_t) 1) == -1)
58 if (putc(c, stdout) == EOF)
67 if (VALID_STRING(s)) {
77 outs(exit_attribute_mode);
78 if (!outs(orig_colors))
83 printf("\n\n%ld total cells, rate %.2f/sec\n",
85 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
89 onsig(int n GCC_UNUSED)
97 long r = (rand() & 077777);
98 return ((double) r / 32768.);
102 get_number(NCURSES_CONST char *cap, int map)
106 int check = tigetnum(cap);
116 static const char *msg[] =
118 "Usage: dots_termcap [options]"
121 ," -T TERM override $TERM"
123 ," -e allow environment $LINES / $COLUMNS"
125 ," -f use tigetnum rather than <term.h> mapping"
126 ," -m SIZE set margin (default: 2)"
127 ," -s MSECS delay 1% of the time (default: 1 msecs)"
131 for (n = 0; n < SIZEOF(msg); n++)
132 fprintf(stderr, "%s\n", msg[n]);
134 ExitProgram(EXIT_FAILURE);
138 main(int argc GCC_UNUSED,
139 char *argv[]GCC_UNUSED)
153 while ((ch = getopt(argc, argv, "T:efm:s:")) != -1) {
156 need = 6 + strlen(optarg);
157 my_env = malloc(need);
158 _nc_SPRINTF(my_env, _nc_SLIMIT(need) "TERM=%s", optarg);
170 m_option = atoi(optarg);
173 s_option = atoi(optarg);
181 InitAndCatch((sp = newterm((char *) 0, stdout, stdin)), onsig);
182 refresh(); /* needed with Solaris curses to cancel endwin */
185 fprintf(stderr, "Cannot initialize terminal\n");
186 ExitProgram(EXIT_FAILURE);
189 srand((unsigned) time(0));
193 outs(cursor_invisible);
195 #define GetNumber(ln,sn) get_number(f_option ? #sn : 0, ln)
196 my_colors = GetNumber(max_colors, colors);
198 if (!VALID_STRING(set_a_foreground)
199 || !VALID_STRING(set_a_background)
200 || (!VALID_STRING(orig_colors) && !VALID_STRING(orig_pair)))
204 r = (double) (GetNumber(lines, lines) - (m_option * 2));
205 c = (double) (GetNumber(columns, cols) - (m_option * 2));
206 started = time((time_t *) 0);
208 while (!interrupted) {
209 int x = (int) (c * ranf()) + m_option;
210 int y = (int) (r * ranf()) + m_option;
211 int p = (ranf() > 0.9) ? '*' : ' ';
213 if (mvcur(y0, x0, y, x) != ERR) {
219 int z = (int) (ranf() * my_colors);
221 tputs(tparm2(set_a_foreground, z), 1, outc);
223 tputs(tparm2(set_a_background, z), 1, outc);
226 } else if (VALID_STRING(exit_attribute_mode)
227 && VALID_STRING(enter_reverse_mode)) {
228 if (ranf() <= 0.01) {
231 : exit_attribute_mode);
243 ExitProgram(EXIT_SUCCESS);
247 main(int argc GCC_UNUSED,
248 char *argv[]GCC_UNUSED)
250 fprintf(stderr, "This program requires terminfo\n");