X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fnewdemo.c;h=78761534d7c5efdac70f6ea19b6f8d2fc5066bdf;hb=c11444e368f1d5964bd0f81e6e3b0f8c8ccd09cc;hp=462e340bc8a42493e813ddc550e620f2fcfbe503;hpb=5d8dbcdd9423bf9821db414fd9ec792ccf1f1027;p=ncurses.git diff --git a/test/newdemo.c b/test/newdemo.c index 462e340b..78761534 100644 --- a/test/newdemo.c +++ b/test/newdemo.c @@ -2,7 +2,7 @@ * newdemo.c - A demo program using PDCurses. The program illustrate * the use of colours for text output. * - * $Id: newdemo.c,v 1.44 2017/09/04 11:49:55 tom Exp $ + * $Id: newdemo.c,v 1.48 2022/12/10 23:36:05 tom Exp $ */ #include @@ -50,7 +50,7 @@ static const char *messages[] = static void trap(int sig GCC_UNUSED) { - exit_curses(); + stop_curses(); ExitProgram(EXIT_FAILURE); } @@ -61,11 +61,12 @@ static int WaitForUser(WINDOW *win) { time_t t; - chtype key; nodelay(win, TRUE); t = time((time_t *) 0); + while (1) { + chtype key; if ((int) (key = (chtype) wgetch(win)) != ERR) { if (key == 'q' || key == 'Q') return 1; @@ -214,25 +215,55 @@ BouncingBalls(WINDOW *win) return 0; } +static void +usage(int ok) +{ + static const char *msg[] = + { + "Usage: newdemo [options]" + ,"" + ,USAGE_COMMON + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); +} +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ + /* * Main driver */ int -main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) +main(int argc, char *argv[]) { WINDOW *win; - int w, x, y, i, j, k; + int x, y, i, k; char buffer[SIZEOF(messages) * 80]; - const char *message; int width, height; chtype save[80]; - chtype c; + int ch; + + while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) { + switch (ch) { + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); + default: + usage(ch == OPTS_USAGE); + /* NOTREACHED */ + } + } + if (optind < argc) + usage(FALSE); setlocale(LC_ALL, ""); - CATCHALL(trap); - - initscr(); + InitAndCatch(initscr(), trap); if (has_colors()) start_color(); cbreak(); @@ -241,11 +272,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) height = 14; /* Create a drawing window */ win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); if (win == NULL) { - exit_curses(); + stop_curses(); ExitProgram(EXIT_FAILURE); } while (1) { + int w; + int j; + chtype c; + const char *message; + set_colors(win, 1, COLOR_WHITE, COLOR_BLUE); werase(win); @@ -360,6 +396,6 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) if (WaitForUser(win) == 1) break; } - exit_curses(); + stop_curses(); ExitProgram(EXIT_SUCCESS); }