X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fechochar.c;h=19ba9acd07e34a20f710d5dd034945af506810ff;hp=a8203821075b8c0b8d53c29b9296355f04acbd1e;hb=58369d647d003dd9d9e1ecfc5ab07982db28f3da;hpb=772f879d17117c5b766022f28099e341ebea825b diff --git a/test/echochar.c b/test/echochar.c index a8203821..19ba9acd 100644 --- a/test/echochar.c +++ b/test/echochar.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2006,2007 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 * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: echochar.c,v 1.5 2007/07/21 17:41:55 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 @@ -36,8 +36,6 @@ #include -#define valid(s) ((s != 0) && s != (char *)-1) - static bool interrupted = FALSE; static long total_chars = 0; static time_t started; @@ -45,11 +43,11 @@ 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) / (time((time_t *) 0) - started))); + ((double) (total_chars) / (double) (time((time_t *) 0) - started))); } static void @@ -58,31 +56,34 @@ onsig(int n GCC_UNUSED) interrupted = TRUE; } -static float +static double ranf(void) { long r = (rand() & 077777); - return ((float) r / 32768.); + return ((double) r / 32768.); } static void set_color(char *my_pairs, int fg, int bg) { int pair = (fg * COLORS) + bg; - if (!my_pairs[pair]) { - init_pair(pair, fg, 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 -main( - int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) +main(int argc GCC_UNUSED, + char *argv[]GCC_UNUSED) { int ch, x, y, z, p; - float r; - float c; + double r; + double c; bool use_colors; bool opt_r = FALSE; char *my_pairs = 0; @@ -95,19 +96,18 @@ main( 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) { start_color(); if (COLOR_PAIRS > 0) { - my_pairs = calloc((unsigned) COLOR_PAIRS, sizeof(*my_pairs)); + my_pairs = typeCalloc(char, (size_t) COLOR_PAIRS); } use_colors = (my_pairs != 0); } @@ -116,8 +116,8 @@ main( curs_set(0); - r = (float) (LINES - 4); - c = (float) (COLS - 4); + r = (double) (LINES - 4); + c = (double) (COLS - 4); started = time((time_t *) 0); while (!interrupted) { @@ -146,7 +146,7 @@ main( } } if (opt_r) { - addch(UChar(p)); + AddCh(UChar(p)); refresh(); } else { echochar(UChar(p)); @@ -154,5 +154,6 @@ main( ++total_chars; } cleanup(); + free(my_pairs); ExitProgram(EXIT_SUCCESS); }