X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdots_xcurses.c;h=ba65dab2564aee86d5f696507b7f33a8790e50d4;hp=abf0a00ae030b4dfc03b3522290f0f1162f34c7a;hb=3e91848cbe3dad23fdb60962fa9b678592591c34;hpb=7fa7badf32c514211478cf9f79c70f20d435c2f2;ds=sidebyside diff --git a/test/dots_xcurses.c b/test/dots_xcurses.c index abf0a00a..ba65dab2 100644 --- a/test/dots_xcurses.c +++ b/test/dots_xcurses.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2017 Free Software Foundation, Inc. * + * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 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 * @@ -29,13 +30,13 @@ /* * 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.19 2020/02/02 23:34:34 tom Exp $ * * A simple demo of the wide-curses interface used for comparison with termcap. */ #include -#if !defined(__MINGW32__) +#if !defined(_WIN32) #include #endif @@ -55,8 +56,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 @@ -104,22 +104,27 @@ set_colors(int fg, int bg) { int pair = mypair(fg, bg); if (pair > 0) { - color_set((short) pair, NewPair(pair)); + (void) color_set((short) pair, NewPair(pair)); } } -#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 +136,46 @@ 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; + size_t need; + char *my_env; -#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': + need = 6 + strlen(optarg); + my_env = malloc(need); + _nc_SPRINTF(my_env, _nc_SLIMIT(need) "TERM=%s", optarg); + putenv(my_env); + 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 +186,6 @@ main(int argc GCC_UNUSED, break; } } -#endif srand((unsigned) time(0)); @@ -172,11 +196,19 @@ 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++) { + int pair; + if (interrupted) { + cleanup(); + ExitProgram(EXIT_FAILURE); + } pair = mypair(fg, bg); if (pair > 0) { InitPair(pair, fg, bg); @@ -186,27 +218,26 @@ 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; bg = COLOR_BLACK; - pair = 0; wch[1] = 0; while (!interrupted) { - x = (int) (c * ranf()) + margin; - y = (int) (r * ranf()) + margin; - p = (ranf() > 0.9) ? '*' : ' '; + int x = (int) (c * ranf()) + m_option; + int y = (int) (r * ranf()) + m_option; + int p = (ranf() > 0.9) ? '*' : ' '; move(y, x); if (has_colors()) { - z = (int) (ranf() * COLORS); + int z = (int) (ranf() * COLORS); if (ranf() > 0.01) { set_colors(fg = z, bg); } else { set_colors(fg, bg = z); - napms(1); + napms(s_option); } } else { if (ranf() <= 0.01) { @@ -215,10 +246,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;