1 /****************************************************************************
2 * Copyright (c) 2013 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_termcap.c,v 1.8 2014/09/25 09:00:56 tom Exp $
34 * A simple demo of the termcap interface.
37 #include <test.priv.h>
39 #if !defined(__MINGW32__)
47 #define valid(s) ((s != 0) && s != (char *)-1)
49 static bool interrupted = FALSE;
50 static long total_chars = 0;
51 static time_t started;
108 if (write(STDOUT_FILENO, &tmp, (size_t) 1) == -1)
111 rc = putc(c, stdout);
135 printf("\n\n%ld total chars, rate %.2f/sec\n",
137 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
141 onsig(int n GCC_UNUSED)
149 long r = (rand() & 077777);
150 return ((double) r / 32768.);
156 #if defined(__MINGW32__) || !HAVE_GETTIMEOFDAY
161 data.tv_usec = ms * 1000;
162 select(0, NULL, NULL, NULL, &data);
167 main(int argc GCC_UNUSED,
168 char *argv[]GCC_UNUSED)
182 srand((unsigned) time(0));
184 if ((name = getenv("TERM")) == 0) {
185 fprintf(stderr, "TERM is not set\n");
186 ExitProgram(EXIT_FAILURE);
187 } else if (tgetent(buffer, name) < 0) {
188 fprintf(stderr, "terminal description not found\n");
189 ExitProgram(EXIT_FAILURE);
193 for (t = 0; t < SIZEOF(my_caps); ++t) {
194 *(my_caps[t].value) = tgetstr((NCURSES_CONST char *)
195 my_caps[t].name, &ap);
199 num_colors = tgetnum("Co");
200 num_lines = tgetnum("li");
201 num_columns = tgetnum("co");
205 if (num_colors > 1) {
208 || (!valid(t_oc) && !valid(t_op)))
212 r = (double) (num_lines - 4);
213 c = (double) (num_columns - 4);
214 started = time((time_t *) 0);
216 while (!interrupted) {
217 x = (int) (c * ranf()) + 2;
218 y = (int) (r * ranf()) + 2;
219 p = (ranf() > 0.9) ? '*' : ' ';
221 tputs(tgoto(t_cm, x, y), 1, outc);
222 if (num_colors > 0) {
223 z = (int) (ranf() * num_colors);
225 tputs(tgoto(t_AF, 0, z), 1, outc);
227 tputs(tgoto(t_AB, 0, z), 1, outc);
230 } else if (valid(t_me)
232 if (ranf() <= 0.01) {
244 ExitProgram(EXIT_SUCCESS);
248 main(int argc GCC_UNUSED,
249 char *argv[]GCC_UNUSED)
251 fprintf(stderr, "This program requires termcap\n");