projects
/
ncurses.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ncurses 6.2 - patch 20200418
[ncurses.git]
/
test
/
dots_xcurses.c
diff --git
a/test/dots_xcurses.c
b/test/dots_xcurses.c
index abf0a00ae030b4dfc03b3522290f0f1162f34c7a..ba65dab2564aee86d5f696507b7f33a8790e50d4 100644
(file)
--- 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 *
* *
* 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
*
/*
* 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 <test.priv.h>
*
* 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
#include <sys/time.h>
#endif
@@
-55,8
+56,7
@@
static bool interrupted = FALSE;
static long total_chars = 0;
static time_t started;
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
static bool x_option = FALSE;
#endif
@@
-104,22
+104,27
@@
set_colors(int fg, int bg)
{
int pair = mypair(fg, bg);
if (pair > 0) {
{
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[] =
{
static void
usage(void)
{
static const char *msg[] =
{
- "Usage:
firework
[options]"
+ "Usage:
dots_xcurses
[options]"
,""
,"Options:"
,""
,"Options:"
+ ," -T TERM override $TERM"
#if HAVE_USE_DEFAULT_COLORS
," -d invoke use_default_colors()"
#endif
#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
#if HAVE_ALLOC_PAIR
," -x use alloc_pair() rather than init_pair()"
#endif
@@
-131,26
+136,46
@@
usage(void)
ExitProgram(EXIT_FAILURE);
}
ExitProgram(EXIT_FAILURE);
}
-#endif
int
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 fg, bg, ch;
wchar_t wch[2];
- int pair;
double r;
double c;
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) {
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;
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;
#if HAVE_ALLOC_PAIR
case 'x':
x_option = TRUE;
@@
-161,7
+186,6
@@
main(int argc GCC_UNUSED,
break;
}
}
break;
}
}
-#endif
srand((unsigned) time(0));
srand((unsigned) time(0));
@@
-172,11
+196,19
@@
main(int argc GCC_UNUSED,
if (d_option)
use_default_colors();
#endif
if (d_option)
use_default_colors();
#endif
+#if HAVE_ALLOC_PAIR
if (x_option) {
; /* nothing */
if (x_option) {
; /* nothing */
- } else {
+ } else
+#endif
+ {
for (fg = 0; fg < COLORS; fg++) {
for (bg = 0; bg < COLORS; bg++) {
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);
pair = mypair(fg, bg);
if (pair > 0) {
InitPair(pair, fg, bg);
@@
-186,27
+218,26
@@
main(int argc GCC_UNUSED,
}
}
}
}
- r = (double) (LINES - (2 * m
argi
n));
- c = (double) (COLS - (2 * m
argi
n));
+ r = (double) (LINES - (2 * m
_optio
n));
+ c = (double) (COLS - (2 * m
_optio
n));
started = time((time_t *) 0);
fg = COLOR_WHITE;
bg = COLOR_BLACK;
started = time((time_t *) 0);
fg = COLOR_WHITE;
bg = COLOR_BLACK;
- pair = 0;
wch[1] = 0;
while (!interrupted) {
wch[1] = 0;
while (!interrupted) {
-
x = (int) (c * ranf()) + margi
n;
-
y = (int) (r * ranf()) + margi
n;
- p = (ranf() > 0.9) ? '*' : ' ';
+
int x = (int) (c * ranf()) + m_optio
n;
+
int y = (int) (r * ranf()) + m_optio
n;
+
int
p = (ranf() > 0.9) ? '*' : ' ';
move(y, x);
if (has_colors()) {
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);
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) {
}
} else {
if (ranf() <= 0.01) {
@@
-215,10
+246,10
@@
main(int argc GCC_UNUSED,
} else {
attr_off(WA_REVERSE, NULL);
}
} 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;
addnwstr(wch, 1);
refresh();
++total_chars;