1 /****************************************************************************
2 * Copyright (c) 2013-2014,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
32 * $Id: dots_termcap.c,v 1.12 2017/10/11 08:15:07 tom Exp $
34 * A simple demo of the termcap interface.
37 #include <test.priv.h>
39 #if !defined(__MINGW32__)
47 static bool interrupted = FALSE;
48 static long total_chars = 0;
49 static time_t started;
106 if (write(STDOUT_FILENO, &tmp, (size_t) 1) == -1)
109 rc = putc(c, stdout);
117 if (VALID_STRING(s)) {
133 printf("\n\n%ld total cells, rate %.2f/sec\n",
135 ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
139 onsig(int n GCC_UNUSED)
147 long r = (rand() & 077777);
148 return ((double) r / 32768.);
154 #if defined(__MINGW32__) || !HAVE_GETTIMEOFDAY
159 data.tv_usec = ms * 1000;
160 select(0, NULL, NULL, NULL, &data);
165 main(int argc GCC_UNUSED,
166 char *argv[]GCC_UNUSED)
178 srand((unsigned) time(0));
180 if ((name = getenv("TERM")) == 0) {
181 fprintf(stderr, "TERM is not set\n");
182 ExitProgram(EXIT_FAILURE);
184 InitAndCatch(z = tgetent(buffer, name), onsig);
186 fprintf(stderr, "terminal description not found\n");
187 ExitProgram(EXIT_FAILURE);
191 for (t = 0; t < SIZEOF(my_caps); ++t) {
192 *(my_caps[t].value) = tgetstr((NCURSES_CONST char *)
193 my_caps[t].name, &ap);
197 num_colors = tgetnum("Co");
198 num_lines = tgetnum("li");
199 num_columns = tgetnum("co");
203 if (num_colors > 1) {
204 if (!VALID_STRING(t_AF)
205 || !VALID_STRING(t_AB)
206 || (!VALID_STRING(t_oc) && !VALID_STRING(t_op)))
210 r = (double) (num_lines - 4);
211 c = (double) (num_columns - 4);
212 started = time((time_t *) 0);
214 while (!interrupted) {
215 x = (int) (c * ranf()) + 2;
216 y = (int) (r * ranf()) + 2;
217 p = (ranf() > 0.9) ? '*' : ' ';
219 tputs(tgoto(t_cm, x, y), 1, outc);
220 if (num_colors > 0) {
221 z = (int) (ranf() * num_colors);
223 tputs(tgoto(t_AF, 0, z), 1, outc);
225 tputs(tgoto(t_AB, 0, z), 1, outc);
228 } else if (VALID_STRING(t_me)
229 && VALID_STRING(t_mr)) {
230 if (ranf() <= 0.01) {
242 ExitProgram(EXIT_SUCCESS);
246 main(int argc GCC_UNUSED,
247 char *argv[]GCC_UNUSED)
249 fprintf(stderr, "This program requires termcap\n");