1 /****************************************************************************
2 * Copyright (c) 1999-2007,2008 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.2 2008/02/09 18:08:57 tom Exp $
34 * A simple demo of the terminfo interface, and mvcur.
37 #include <test.priv.h>
43 #define valid(s) ((s != 0) && s != (char *)-1)
45 static bool interrupted = FALSE;
46 static long total_chars = 0;
47 static time_t started;
54 write(STDOUT_FILENO, &tmp, 1);
74 outs(exit_attribute_mode);
75 if (!outs(orig_colors))
80 printf("\n\n%ld total chars, rate %.2f/sec\n",
82 ((double) (total_chars) / (time((time_t *) 0) - started)));
86 onsig(int n GCC_UNUSED)
94 long r = (rand() & 077777);
95 return ((float) r / 32768.);
101 char *argv[]GCC_UNUSED)
111 srand((unsigned) time(0));
112 sp = newterm((char *) 0, stdout, stdin);
115 outs(cursor_invisible);
116 if (max_colors > 1) {
117 if (!valid(set_a_foreground)
118 || !valid(set_a_background)
119 || (!valid(orig_colors) && !valid(orig_pair)))
123 r = (float) (lines - 4);
124 c = (float) (columns - 4);
125 started = time((time_t *) 0);
127 while (!interrupted) {
128 x = (int) (c * ranf()) + 2;
129 y = (int) (r * ranf()) + 2;
130 p = (ranf() > 0.9) ? '*' : ' ';
132 if (mvcur(y0, x0, y, x) != ERR) {
137 if (max_colors > 0) {
138 z = (int) (ranf() * max_colors);
140 tputs(tparm2(set_a_foreground, z), 1, outc);
142 tputs(tparm2(set_a_background, z), 1, outc);
145 } else if (valid(exit_attribute_mode)
146 && valid(enter_reverse_mode)) {
147 if (ranf() <= 0.01) {
150 : exit_attribute_mode);
161 ExitProgram(EXIT_SUCCESS);
165 main(int argc GCC_UNUSED,
166 char *argv[]GCC_UNUSED)
168 fprintf(stderr, "This program requires terminfo\n");