X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fhashtest.c;h=be79c0e10372de14c74e53e0c5729fc8f979533b;hb=9e084820c3f396f861b2cb74fbd5fc15aa10b6bc;hp=06f29098911763b6eb7584185f3e2762d6a59492;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01;p=ncurses.git diff --git a/test/hashtest.c b/test/hashtest.c index 06f29098..be79c0e1 100644 --- a/test/hashtest.c +++ b/test/hashtest.c @@ -1,21 +1,39 @@ +/**************************************************************************** + * Copyright 2019-2020,2022 Thomas E. Dickey * + * Copyright 1998-2013,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 * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ /* * hashtest.c -- test hash mapping * * Generate timing statistics for vertical-motion optimization. * - * $Id: hashtest.c,v 1.22 2002/06/29 23:32:18 tom Exp $ + * $Id: hashtest.c,v 1.39 2022/12/04 00:40:11 tom Exp $ */ -#ifdef TRACE -#define Trace(p) _tracef p -#define USE_TRACE 1 -#else -#define Trace(p) /* nothing */ -#define USE_TRACE 0 -#endif - -#include - #include #define LO_CHAR ' ' @@ -37,7 +55,7 @@ cleanup(void) endwin(); } -static RETSIGTYPE +static void finish(int sig GCC_UNUSED) { cleanup(); @@ -65,20 +83,21 @@ genlines(int base) move(0, 0); for (i = 0; i < head_lines; i++) for (j = 0; j < COLS; j++) - addch((j % 8 == 0) ? ('A' + j / 8) : '-'); + AddCh(UChar((j % 8 == 0) ? ('A' + j / 8) : '-')); move(head_lines, 0); for (i = head_lines; i < LINES - foot_lines; i++) { - int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR; + chtype c = (chtype) ((base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + + LO_CHAR); int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1; for (j = 0; j < hi; j++) - addch(c); + AddCh(c); } for (i = LINES - foot_lines; i < LINES; i++) { move(i, 0); for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++) - addch((j % 8 == 0) ? ('A' + j / 8) : '-'); + AddCh(UChar((j % 8 == 0) ? ('A' + j / 8) : '-')); } scrollok(stdscr, TRUE); @@ -123,61 +142,66 @@ run_test(bool optimized GCC_UNUSED) #endif if (reverse_loops) - for (ch = hi; ch >= lo; ch--) + for (ch = (char) hi; ch >= lo; ch--) one_cycle(ch); else - for (ch = lo; ch <= hi; ch++) + for (ch = (char) lo; ch <= hi; ch++) one_cycle(ch); } static void -usage(void) +usage(int ok) { static const char *const tbl[] = { "Usage: hashtest [options]" ,"" + ,USAGE_COMMON ,"Options:" - ," -c continuous (don't reset between refresh's)" - ," -f num leave 'num' lines constant for footer" - ," -h num leave 'num' lines constant for header" - ," -l num repeat test 'num' times" - ," -n test the normal optimizer" - ," -o test the hashed optimizer" - ," -r reverse the loops" - ," -s single-step" - ," -x assume lower-right corner extension" + ," -c continuous (don't reset between refresh's)" + ," -F num leave 'num' lines constant for footer" + ," -H num leave 'num' lines constant for header" + ," -l num repeat test 'num' times" + ," -n test the normal optimizer" + ," -o test the hashed optimizer" + ," -r reverse the loops" + ," -s single-step" + ," -x assume lower-right corner extension" }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) fprintf(stderr, "%s\n", tbl[n]); - ExitProgram(EXIT_FAILURE); + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { - int c; + int ch; int test_loops = 1; int test_normal = FALSE; int test_optimize = FALSE; setlocale(LC_ALL, ""); - while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) { - switch (c) { + while ((ch = getopt(argc, argv, OPTS_COMMON "cF:H:l:norsx")) != -1) { + switch (ch) { case 'c': continuous = TRUE; break; - case 'f': + case 'F': foot_lines = atoi(optarg); break; - case 'h': + case 'H': head_lines = atoi(optarg); break; case 'l': test_loops = atoi(optarg); + assert(test_loops >= 0); break; case 'n': test_normal = TRUE; @@ -194,8 +218,12 @@ main(int argc, char *argv[]) case 'x': extend_corner = TRUE; break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (!test_normal && !test_optimize) { @@ -203,12 +231,10 @@ main(int argc, char *argv[]) test_optimize = TRUE; } #if USE_TRACE - trace(TRACE_TIMES); + curses_trace(TRACE_TIMES); #endif - (void) signal(SIGINT, finish); /* arrange interrupts to terminate */ - - (void) initscr(); /* initialize the curses library */ + InitAndCatch(initscr(), finish); keypad(stdscr, TRUE); /* enable keyboard mapping */ (void) nonl(); /* tell curses not to do NL->CR/NL on output */ (void) cbreak(); /* take input chars one at a time, no wait for \n */