/****************************************************************************
- * Copyright (c) 2017 Free Software Foundation, Inc. *
+ * Copyright (c) 2017-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 *
/*
* 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.17 2019/01/21 14:20:18 tom Exp $
*
* A simple demo of the wide-curses interface used for comparison with termcap.
*/
#include <test.priv.h>
-#if !defined(__MINGW32__)
+#if !defined(_WIN32)
#include <sys/time.h>
#endif
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
{
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
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;
break;
}
}
-#endif
srand((unsigned) time(0));
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);
}
}
- 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;
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);
set_colors(fg = z, bg);
} else {
set_colors(fg, bg = z);
- napms(1);
+ napms(s_option);
}
} else {
if (ranf() <= 0.01) {
} 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;