aboutsummaryrefslogtreecommitdiff
path: root/test/echochar.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/echochar.c')
-rw-r--r--test/echochar.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/test/echochar.c b/test/echochar.c
index 8cb0833aa023..93a4644213af 100644
--- a/test/echochar.c
+++ b/test/echochar.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2006-2010,2012 Free Software Foundation, Inc. *
+ * Copyright (c) 2006-2017,2019 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
- * $Id: echochar.c,v 1.9 2012/06/09 20:30:32 tom Exp $
+ * $Id: echochar.c,v 1.20 2019/12/14 23:25:29 tom Exp $
*
* Demonstrate the echochar function (compare to dots.c).
* Thomas Dickey - 2006/11/4
@@ -36,8 +36,6 @@
#include <time.h>
-#define valid(s) ((s != 0) && s != (char *)-1)
-
static bool interrupted = FALSE;
static long total_chars = 0;
static time_t started;
@@ -45,9 +43,9 @@ static time_t started;
static void
cleanup(void)
{
- endwin();
+ stop_curses();
- printf("\n\n%ld total chars, rate %.2f/sec\n",
+ printf("\n\n%ld total cells, rate %.2f/sec\n",
total_chars,
((double) (total_chars) / (double) (time((time_t *) 0) - started)));
}
@@ -69,19 +67,21 @@ static void
set_color(char *my_pairs, int fg, int bg)
{
int pair = (fg * COLORS) + bg;
- if (!my_pairs[pair]) {
- init_pair((short) pair,
- (short) fg,
- (short) bg);
+ if (pair < COLOR_PAIRS) {
+ if (!my_pairs[pair]) {
+ init_pair((short) pair,
+ (short) fg,
+ (short) bg);
+ }
+ attron(COLOR_PAIR(pair));
}
- attron((attr_t) COLOR_PAIR(pair));
}
int
main(int argc GCC_UNUSED,
char *argv[]GCC_UNUSED)
{
- int ch, x, y, z, p;
+ int ch;
double r;
double c;
bool use_colors;
@@ -96,13 +96,12 @@ main(int argc GCC_UNUSED,
opt_r = TRUE;
break;
default:
- fprintf(stderr, "usage: echochar [-r]\n");
+ fprintf(stderr, "Usage: echochar [-r]\n");
ExitProgram(EXIT_FAILURE);
}
}
- CATCHALL(onsig);
- initscr();
+ InitAndCatch(initscr(), onsig);
use_colors = has_colors();
if (use_colors) {
@@ -122,13 +121,13 @@ main(int argc GCC_UNUSED,
started = time((time_t *) 0);
while (!interrupted) {
- x = (int) (c * ranf()) + 2;
- y = (int) (r * ranf()) + 2;
- p = (ranf() > 0.9) ? '*' : ' ';
+ int x = (int) (c * ranf()) + 2;
+ int y = (int) (r * ranf()) + 2;
+ int p = (ranf() > 0.9) ? '*' : ' ';
move(y, x);
if (use_colors > 0) {
- z = (int) (ranf() * COLORS);
+ int z = (int) (ranf() * COLORS);
if (ranf() > 0.01) {
set_color(my_pairs, z, last_bg);
last_fg = z;
@@ -147,7 +146,7 @@ main(int argc GCC_UNUSED,
}
}
if (opt_r) {
- addch(UChar(p));
+ AddCh(UChar(p));
refresh();
} else {
echochar(UChar(p));
@@ -155,5 +154,6 @@ main(int argc GCC_UNUSED,
++total_chars;
}
cleanup();
+ free(my_pairs);
ExitProgram(EXIT_SUCCESS);
}