X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdots_xcurses.c;h=f86cd8d16b3318c9fbf096c02e517720e4b60a26;hp=abf0a00ae030b4dfc03b3522290f0f1162f34c7a;hb=aed072e27e60c2abc5ac0ab8113aacf9b4908d50;hpb=7fa7badf32c514211478cf9f79c70f20d435c2f2 diff --git a/test/dots_xcurses.c b/test/dots_xcurses.c index abf0a00a..f86cd8d1 100644 --- a/test/dots_xcurses.c +++ b/test/dots_xcurses.c @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey * - * $Id: dots_xcurses.c,v 1.8 2017/10/12 00:20:41 tom Exp $ + * $Id: dots_xcurses.c,v 1.14 2017/12/09 21:04:41 tom Exp $ * * A simple demo of the wide-curses interface used for comparison with termcap. */ @@ -55,8 +55,7 @@ static bool interrupted = FALSE; static long total_chars = 0; static time_t started; -#ifdef NCURSES_VERSION -static bool d_option = FALSE; +#if HAVE_ALLOC_PAIR static bool x_option = FALSE; #endif @@ -108,18 +107,23 @@ set_colors(int fg, int bg) } } -#if defined(NCURSES_VERSION) static void usage(void) { static const char *msg[] = { - "Usage: firework [options]" + "Usage: dots_xcurses [options]" ,"" ,"Options:" + ," -T TERM override $TERM" #if HAVE_USE_DEFAULT_COLORS ," -d invoke use_default_colors()" #endif +#if HAVE_USE_ENV + ," -e allow environment $LINES / $COLUMNS" +#endif + ," -m SIZE set margin (default: 2)" + ," -s MSECS delay 1% of the time (default: 1 msecs)" #if HAVE_ALLOC_PAIR ," -x use alloc_pair() rather than init_pair()" #endif @@ -131,26 +135,43 @@ usage(void) ExitProgram(EXIT_FAILURE); } -#endif int -main(int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) +main(int argc, char *argv[]) { - int margin = 2; int x, y, z, p; int fg, bg, ch; wchar_t wch[2]; int pair; double r; double c; +#if HAVE_USE_DEFAULT_COLORS + bool d_option = FALSE; +#endif + int m_option = 2; + int s_option = 1; -#if defined(NCURSES_VERSION) - while ((ch = getopt(argc, argv, "dx")) != -1) { + while ((ch = getopt(argc, argv, "T:dem:s:x")) != -1) { switch (ch) { + case 'T': + putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg)); + break; +#if HAVE_USE_DEFAULT_COLORS case 'd': d_option = TRUE; break; +#endif +#if HAVE_USE_ENV + case 'e': + use_env(TRUE); + break; +#endif + case 'm': + m_option = atoi(optarg); + break; + case 's': + s_option = atoi(optarg); + break; #if HAVE_ALLOC_PAIR case 'x': x_option = TRUE; @@ -161,7 +182,6 @@ main(int argc GCC_UNUSED, break; } } -#endif srand((unsigned) time(0)); @@ -172,11 +192,18 @@ main(int argc GCC_UNUSED, if (d_option) use_default_colors(); #endif +#if HAVE_ALLOC_PAIR if (x_option) { ; /* nothing */ - } else { + } else +#endif + { for (fg = 0; fg < COLORS; fg++) { for (bg = 0; bg < COLORS; bg++) { + if (interrupted) { + cleanup(); + ExitProgram(EXIT_FAILURE); + } pair = mypair(fg, bg); if (pair > 0) { InitPair(pair, fg, bg); @@ -186,8 +213,8 @@ main(int argc GCC_UNUSED, } } - r = (double) (LINES - (2 * margin)); - c = (double) (COLS - (2 * margin)); + r = (double) (LINES - (2 * m_option)); + c = (double) (COLS - (2 * m_option)); started = time((time_t *) 0); fg = COLOR_WHITE; @@ -195,8 +222,8 @@ main(int argc GCC_UNUSED, pair = 0; wch[1] = 0; while (!interrupted) { - x = (int) (c * ranf()) + margin; - y = (int) (r * ranf()) + margin; + x = (int) (c * ranf()) + m_option; + y = (int) (r * ranf()) + m_option; p = (ranf() > 0.9) ? '*' : ' '; move(y, x); @@ -206,7 +233,7 @@ main(int argc GCC_UNUSED, set_colors(fg = z, bg); } else { set_colors(fg, bg = z); - napms(1); + napms(s_option); } } else { if (ranf() <= 0.01) { @@ -215,10 +242,10 @@ main(int argc GCC_UNUSED, } else { attr_off(WA_REVERSE, NULL); } - napms(1); + napms(s_option); } } - wch[0] = p; + wch[0] = (wchar_t) p; addnwstr(wch, 1); refresh(); ++total_chars;