/****************************************************************************
- * Copyright (c) 2006-2008,2010 Free Software Foundation, Inc. *
+ * Copyright (c) 2006-2014,2017 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 *
* authorization. *
****************************************************************************/
/*
- * $Id: echochar.c,v 1.8 2010/11/14 01:00:44 tom Exp $
+ * $Id: echochar.c,v 1.18 2017/10/18 23:04:52 tom Exp $
*
* Demonstrate the echochar function (compare to dots.c).
* Thomas Dickey - 2006/11/4
#include <time.h>
-#define valid(s) ((s != 0) && s != (char *)-1)
-
static bool interrupted = FALSE;
static long total_chars = 0;
static time_t started;
static void
cleanup(void)
{
- endwin();
+ exit_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)));
}
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(COLOR_PAIR(pair));
}
int
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) {
}
}
if (opt_r) {
- addch(UChar(p));
+ AddCh(UChar(p));
refresh();
} else {
echochar(UChar(p));
++total_chars;
}
cleanup();
+ free(my_pairs);
ExitProgram(EXIT_SUCCESS);
}