1
/****************************************************************************
2
* Copyright (c) 2006 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
****************************************************************************/
29
* $Id: echochar.c,v 1.3 2006/12/03 00:14:29 tom Exp $
31
* Demonstrate the echochar function (compare to dots.c).
32
* Thomas Dickey - 2006/11/4
35
#include <test.priv.h>
39
#define valid(s) ((s != 0) && s != (char *)-1)
41
static bool interrupted = FALSE;
42
static long total_chars = 0;
43
static time_t started;
50
printf("\n\n%ld total chars, rate %.2f/sec\n",
52
((double) (total_chars) / (time((time_t *) 0) - started)));
56
onsig(int n GCC_UNUSED)
64
long r = (rand() & 077777);
65
return ((float) r / 32768.);
69
set_color(char *my_pairs, int fg, int bg)
71
int pair = (fg * COLORS) + bg;
72
if (!my_pairs[pair]) {
73
init_pair(pair, fg, bg);
75
attron(COLOR_PAIR(pair));
81
char *argv[]GCC_UNUSED)
92
while ((ch = getopt(argc, argv, "r")) != EOF) {
98
fprintf(stderr, "usage: echochar [-r]\n");
99
ExitProgram(EXIT_FAILURE);
106
use_colors = has_colors();
109
if (COLOR_PAIRS > 0) {
110
my_pairs = calloc(COLOR_PAIRS, sizeof(*my_pairs));
112
use_colors = (my_pairs != 0);
115
srand((unsigned) time(0));
119
r = (float) (LINES - 4);
120
c = (float) (COLS - 4);
121
started = time((time_t *) 0);
123
while (!interrupted) {
124
x = (int) (c * ranf()) + 2;
125
y = (int) (r * ranf()) + 2;
126
p = (ranf() > 0.9) ? '*' : ' ';
129
if (use_colors > 0) {
130
z = (int) (ranf() * COLORS);
132
set_color(my_pairs, z, last_bg);
135
set_color(my_pairs, last_fg, z);
140
if (ranf() <= 0.01) {
157
ExitProgram(EXIT_SUCCESS);