X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fgdc.c;h=deecdf7e49f3f1619ccf024072c696ecae5730ef;hp=0c48ffbedfa78292b7979dda6ff90c75ac059cd4;hb=22a4b929f47f85588dc07fddf98b09776cec658f;hpb=e2e9c09c48b19b24979cafb2d4864f538b5ddd1c diff --git a/test/gdc.c b/test/gdc.c index 0c48ffbe..deecdf7e 100644 --- a/test/gdc.c +++ b/test/gdc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * + * Copyright (c) 1998-2016,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 * @@ -33,7 +33,7 @@ * modified 10-18-89 for curses (jrl) * 10-18-89 added signal handling * - * $Id: gdc.c,v 1.45 2016/09/10 21:47:55 tom Exp $ + * $Id: gdc.c,v 1.51 2017/09/30 18:10:05 tom Exp $ */ #include @@ -66,7 +66,7 @@ sighndl(int signo) signal(signo, sighndl); sigtermed = signo; if (redirected) { - endwin(); + exit_curses(); ExitProgram(EXIT_FAILURE); } } @@ -76,7 +76,7 @@ check_term(void) { if (sigtermed) { (void) standend(); - endwin(); + exit_curses(); fprintf(stderr, "gdc terminated by signal %d\n", sigtermed); ExitProgram(EXIT_FAILURE); } @@ -156,8 +156,11 @@ usage(void) "Usage: gdc [options] [count]" ,"" ,"Options:" - ," -n redirect input to /dev/null" - ," -s scroll each number into place, rather than flipping" +#if HAVE_USE_DEFAULT_COLORS + ," -d invoke use_default_colors" +#endif + ," -n redirect input to /dev/null" + ," -s scroll each number into place, rather than flipping" ," -t hh:mm:ss specify starting time (default is ``now'')" ,"" ,"If you specify a count, gdc runs for that number of seconds" @@ -218,13 +221,19 @@ main(int argc, char *argv[]) bool smooth = FALSE; bool stages = FALSE; time_t starts = 0; +#if HAVE_USE_DEFAULT_COLORS + bool d_option = FALSE; +#endif setlocale(LC_ALL, ""); - CATCHALL(sighndl); - - while ((k = getopt(argc, argv, "nst:")) != -1) { + while ((k = getopt(argc, argv, "dnst:")) != -1) { switch (k) { +#if HAVE_USE_DEFAULT_COLORS + case 'd': + d_option = TRUE; + break; +#endif case 'n': ifp = fopen("/dev/null", "r"); redirected = TRUE; @@ -246,17 +255,20 @@ main(int argc, char *argv[]) if (optind < argc) usage(); - if (redirected) { - char *name = getenv("TERM"); - if (name == 0 - || newterm(name, ofp, ifp) == 0) { - fprintf(stderr, "cannot open terminal\n"); - ExitProgram(EXIT_FAILURE); + InitAndCatch({ + if (redirected) { + char *name = getenv("TERM"); + if (name == 0 + || newterm(name, ofp, ifp) == 0) { + fprintf(stderr, "cannot open terminal\n"); + ExitProgram(EXIT_FAILURE); + } + } else { + initscr(); } - - } else { - initscr(); } + ,sighndl); + cbreak(); noecho(); nodelay(stdscr, 1); @@ -268,7 +280,7 @@ main(int argc, char *argv[]) short bg = COLOR_BLACK; start_color(); #if HAVE_USE_DEFAULT_COLORS - if (use_default_colors() == OK) + if (d_option && (use_default_colors() == OK)) bg = -1; #endif init_pair(PAIR_DIGITS, COLOR_BLACK, COLOR_RED); @@ -435,6 +447,6 @@ main(int argc, char *argv[]) } } while (--count); (void) standend(); - endwin(); + exit_curses(); ExitProgram(EXIT_SUCCESS); }