X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdots_curses.c;h=215351815e03d11d1217ba95d76b326d1e6e8afe;hp=477c4a14ef116b60854324901ce83b86c725d7be;hb=eccca377f55c70b12e3e92621d94d1e1c1fcfb7d;hpb=7fa7badf32c514211478cf9f79c70f20d435c2f2 diff --git a/test/dots_curses.c b/test/dots_curses.c index 477c4a14..21535181 100644 --- a/test/dots_curses.c +++ b/test/dots_curses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2014,2017 Free Software Foundation, Inc. * + * Copyright (c) 2014-2018,2019 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 +29,13 @@ /* * Author: Thomas E. Dickey * - * $Id: dots_curses.c,v 1.7 2017/10/11 08:16:33 tom Exp $ + * $Id: dots_curses.c,v 1.14 2019/01/21 14:20:18 tom Exp $ * * A simple demo of the curses interface used for comparison with termcap. */ #include -#if !defined(__MINGW32__) +#if !defined(_WIN32) #include #endif @@ -84,38 +84,109 @@ set_colors(int fg, int bg) } } +static void +usage(void) +{ + static const char *msg[] = + { + "Usage: dots_curses [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)" + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(EXIT_FAILURE); +} + int -main(int argc GCC_UNUSED, - char *argv[]GCC_UNUSED) +main(int argc, char *argv[]) { int x, y, z, p; int fg, bg; 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; + + while ((x = getopt(argc, argv, "T:dem:s:")) != -1) { + switch (x) { + 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; + default: + usage(); + break; + } + } srand((unsigned) time(0)); InitAndCatch(initscr(), onsig); if (has_colors()) { start_color(); +#if HAVE_USE_DEFAULT_COLORS + if (d_option) + use_default_colors(); +#endif for (fg = 0; fg < COLORS; fg++) { for (bg = 0; bg < COLORS; bg++) { - int pair = mypair(fg, bg); + int pair; + if (interrupted) { + cleanup(); + ExitProgram(EXIT_FAILURE); + } + pair = mypair(fg, bg); if (pair > 0) init_pair((short) pair, (short) fg, (short) bg); } } } - r = (double) (LINES - 4); - c = (double) (COLS - 4); + r = (double) (LINES - (m_option * 2)); + c = (double) (COLS - (m_option * 2)); started = time((time_t *) 0); fg = COLOR_WHITE; bg = COLOR_BLACK; while (!interrupted) { - x = (int) (c * ranf()) + 2; - y = (int) (r * ranf()) + 2; + x = (int) (c * ranf()) + m_option; + y = (int) (r * ranf()) + m_option; p = (ranf() > 0.9) ? '*' : ' '; move(y, x); @@ -126,7 +197,7 @@ main(int argc GCC_UNUSED, attron(COLOR_PAIR(mypair(fg, bg))); } else { set_colors(fg, bg = z); - napms(1); + napms(s_option); } } else { if (ranf() <= 0.01) { @@ -135,7 +206,7 @@ main(int argc GCC_UNUSED, } else { attroff(A_REVERSE); } - napms(1); + napms(s_option); } } AddCh(p);