X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fechochar.c;h=ef649ca4f87246b188b39a8bc5ac6cebe58e8def;hp=8cb0833aa023b1e158dfb41b62ea2d5e143489e5;hb=5d8dbcdd9423bf9821db414fd9ec792ccf1f1027;hpb=b6d0d9ad9e372e856f01a4c283cf784a15993903 diff --git a/test/echochar.c b/test/echochar.c index 8cb0833a..ef649ca4 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-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.9 2012/06/09 20:30:32 tom Exp $ + * $Id: echochar.c,v 1.14 2017/09/04 11:48:15 tom Exp $ * * Demonstrate the echochar function (compare to dots.c). * Thomas Dickey - 2006/11/4 @@ -45,7 +45,7 @@ static time_t started; static void cleanup(void) { - endwin(); + exit_curses(); printf("\n\n%ld total chars, rate %.2f/sec\n", total_chars, @@ -69,12 +69,14 @@ 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 @@ -147,7 +149,7 @@ main(int argc GCC_UNUSED, } } if (opt_r) { - addch(UChar(p)); + AddCh(UChar(p)); refresh(); } else { echochar(UChar(p)); @@ -155,5 +157,6 @@ main(int argc GCC_UNUSED, ++total_chars; } cleanup(); + free(my_pairs); ExitProgram(EXIT_SUCCESS); }