1 /****************************************************************************
2 * Copyright (c) 2007-2013,2017 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 - 2007
32 * $Id: dots_mvcur.c,v 1.19 2017/11/24 19:26:31 tom Exp $
34 * A simple demo of the terminfo interface, and mvcur.
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)
57 if (putc(c, stdout) == EOF)
66 if (VALID_STRING(s)) {
76 outs(exit_attribute_mode);
77 if (!outs(orig_colors))
82 printf("\n\n%ld total cells, rate %.2f/sec\n",
84 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
88 onsig(int n GCC_UNUSED)
96 long r = (rand() & 077777);
97 return ((double) r / 32768.);
101 get_number(NCURSES_CONST char *cap, int map)
105 int check = tigetnum(cap);
115 static const char *msg[] =
117 "Usage: dots_termcap [options]"
120 ," -T TERM override $TERM"
122 ," -e allow environment $LINES / $COLUMNS"
124 ," -f use tigetnum rather than <term.h> mapping"
125 ," -m SIZE set margin (default: 2)"
126 ," -s MSECS delay 1% of the time (default: 1 msecs)"
130 for (n = 0; n < SIZEOF(msg); n++)
131 fprintf(stderr, "%s\n", msg[n]);
133 ExitProgram(EXIT_FAILURE);
137 main(int argc GCC_UNUSED,
138 char *argv[]GCC_UNUSED)
150 while ((x = getopt(argc, argv, "T:efm:s:")) != -1) {
153 putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg));
164 m_option = atoi(optarg);
167 s_option = atoi(optarg);
175 InitAndCatch((sp = newterm((char *) 0, stdout, stdin)), onsig);
176 refresh(); /* needed with Solaris curses to cancel endwin */
179 fprintf(stderr, "Cannot initialize terminal\n");
180 ExitProgram(EXIT_FAILURE);
183 srand((unsigned) time(0));
187 outs(cursor_invisible);
189 #define GetNumber(ln,sn) get_number(f_option ? #sn : 0, ln)
190 my_colors = GetNumber(max_colors, colors);
192 if (!VALID_STRING(set_a_foreground)
193 || !VALID_STRING(set_a_background)
194 || (!VALID_STRING(orig_colors) && !VALID_STRING(orig_pair)))
198 r = (double) (GetNumber(lines, lines) - (m_option * 2));
199 c = (double) (GetNumber(columns, cols) - (m_option * 2));
200 started = time((time_t *) 0);
202 while (!interrupted) {
203 x = (int) (c * ranf()) + m_option;
204 y = (int) (r * ranf()) + m_option;
205 p = (ranf() > 0.9) ? '*' : ' ';
207 if (mvcur(y0, x0, y, x) != ERR) {
213 z = (int) (ranf() * my_colors);
215 tputs(tparm2(set_a_foreground, z), 1, outc);
217 tputs(tparm2(set_a_background, z), 1, outc);
220 } else if (VALID_STRING(exit_attribute_mode)
221 && VALID_STRING(enter_reverse_mode)) {
222 if (ranf() <= 0.01) {
225 : exit_attribute_mode);
237 ExitProgram(EXIT_SUCCESS);
241 main(int argc GCC_UNUSED,
242 char *argv[]GCC_UNUSED)
244 fprintf(stderr, "This program requires terminfo\n");