./test/blue.c
./test/bs.6
./test/bs.c
+./test/bulgarian-utf8-tabs.txt
./test/bulgarian-utf8.txt
./test/cardfile.c
./test/cardfile.dat
./test/tput-initc
./test/tracemunch
./test/view.c
+./test/widechars-utf8-tabs.txt
./test/widechars-utf8.txt
./test/widechars.h
./test/worm.c
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
--- $Id: NEWS,v 1.2975 2017/10/14 23:49:52 tom Exp $
+-- $Id: NEWS,v 1.2979 2017/10/21 20:29:16 tom Exp $
-------------------------------------------------------------------------------
This is a log of changes that ncurses has gone through since Zeyd started
Changes through 1.9.9e did not credit all contributions;
it is not possible to add this information.
+20171021
+ + modify test/view.c to expand tabs using the ncurses library rather
+ than in the test-program.
+ + remove very old SIGWINCH example in test/view.c, just use KEY_RESIZE.
+ + add -T, -e, -f -m options to "dots" test-programs.
+ + fix a few typos in usage-messages for test-programs.
+
20171014
+ minor cleanup to test/view.c:
+ eliminate "-n" option by simply reading the whole file.
-5:0:9 6.0 20171014
+5:0:9 6.0 20171021
# use or other dealings in this Software without prior written #
# authorization. #
##############################################################################
-# $Id: dist.mk,v 1.1187 2017/10/08 23:38:02 tom Exp $
+# $Id: dist.mk,v 1.1188 2017/10/15 14:51:52 tom Exp $
# Makefile for creating ncurses distributions.
#
# This only needs to be used directly as a makefile by developers, but
# These define the major/minor/patch versions of ncurses.
NCURSES_MAJOR = 6
NCURSES_MINOR = 0
-NCURSES_PATCH = 20171014
+NCURSES_PATCH = 20171021
# We don't append the patch to the version, since this only applies to releases
VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_traceatr.c,v 1.88 2017/03/01 00:04:04 tom Exp $")
+MODULE_ID("$Id: lib_traceatr.c,v 1.89 2017/10/21 23:12:09 tom Exp $")
#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
} else if (ch->chars[PUTC_i] > 255) {
char temp[80];
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
- "{%d:\\u%x}",
+ "{%d:\\u%lx}",
wcwidth(ch->chars[PUTC_i]),
- ch->chars[PUTC_i]);
+ (unsigned long) ch->chars[PUTC_i]);
(void) _nc_trace_bufcat(bufnum, temp);
break;
}
/****************************************************************************
- * Copyright (c) 2001-2014,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2016,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 *
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.48 2016/09/05 00:43:08 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.49 2017/10/21 23:34:20 tom Exp $")
#define NUM_VISBUFS 4
buf[j].chars[PUTC_i], &PUT_st);
if (PUTC_n <= 0 || buf[j].chars[PUTC_i] > 255) {
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
- "{%d:\\u%x}",
+ "{%d:\\u%lx}",
wcwidth(buf[j].chars[PUTC_i]),
- buf[j].chars[PUTC_i]);
+ (unsigned long) buf[j].chars[PUTC_i]);
(void) _nc_trace_bufcat(bufnum, temp);
break;
}
-ncurses6 (6.0+20171014) unstable; urgency=low
+ncurses6 (6.0+20171021) unstable; urgency=low
* latest weekly patch
- -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 08 Oct 2017 19:38:02 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 15 Oct 2017 10:51:52 -0400
ncurses6 (5.9-20131005) unstable; urgency=low
-ncurses6 (6.0+20171014) unstable; urgency=low
+ncurses6 (6.0+20171021) unstable; urgency=low
* latest weekly patch
- -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 08 Oct 2017 19:38:02 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 15 Oct 2017 10:51:52 -0400
ncurses6 (5.9-20131005) unstable; urgency=low
-ncurses6 (6.0+20171014) unstable; urgency=low
+ncurses6 (6.0+20171021) unstable; urgency=low
* latest weekly patch
- -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 08 Oct 2017 19:38:02 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net> Sun, 15 Oct 2017 10:51:52 -0400
ncurses6 (5.9-20120608) unstable; urgency=low
-; $Id: mingw-ncurses.nsi,v 1.235 2017/10/08 23:38:02 tom Exp $\r
+; $Id: mingw-ncurses.nsi,v 1.236 2017/10/15 14:51:52 tom Exp $\r
\r
; TODO add examples\r
; TODO bump ABI to 6\r
!define VERSION_MAJOR "6"\r
!define VERSION_MINOR "0"\r
!define VERSION_YYYY "2017"\r
-!define VERSION_MMDD "1014"\r
+!define VERSION_MMDD "1021"\r
!define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD}\r
\r
!define MY_ABI "5"\r
Summary: shared libraries for terminal handling
Name: mingw32-ncurses6
Version: 6.0
-Release: 20171014
+Release: 20171021
License: X11
Group: Development/Libraries
Source: ncurses-%{version}-%{release}.tgz
Summary: shared libraries for terminal handling
Name: ncurses6
Version: 6.0
-Release: 20171014
+Release: 20171021
License: X11
Group: Development/Libraries
Source: ncurses-%{version}-%{release}.tgz
* v2.0 featuring strict ANSI/POSIX conformance, November 1993.
* v2.1 with ncurses mouse support, September 1995
*
- * $Id: bs.c,v 1.70 2017/09/30 15:40:39 tom Exp $
+ * $Id: bs.c,v 1.71 2017/10/18 23:03:07 tom Exp $
*/
#include <test.priv.h>
switch (op[i][0]) {
default:
case '?':
- (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
+ (void) fprintf(stderr, "Usage: bs [-s | -b] [-c]\n");
(void) fprintf(stderr, "\tWhere the options are:\n");
(void) fprintf(stderr, "\t-s : play a salvo game\n");
(void) fprintf(stderr, "\t-b : play a blitz game\n");
--- /dev/null
+Показване на помощна информация -- 1
+Създаване на дялове -- 2
+Избор на дял и форматиране -- 3
+Записване в избрания дял -- 4
+Инсталиране на LILO -- 5
+Изход от програмата -- 6
/****************************************************************************
- * Copyright (c) 1999-2013,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2016,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 *
/*
* Author: Thomas E. Dickey
*
- * $Id: cardfile.c,v 1.43 2016/09/10 21:36:46 tom Exp $
+ * $Id: cardfile.c,v 1.45 2017/10/19 21:14:25 tom Exp $
*
* File format: text beginning in column 1 is a title; other text is content.
*/
{
static const char *msg[] =
{
- "Usage: view [options] file"
+ "Usage: cardfile [options] file"
,""
,"Options:"
," -c use color if terminal supports it"
/*
* Author: Thomas E. Dickey (1998-on)
*
- * $Id: ditto.c,v 1.46 2017/09/06 09:19:14 tom Exp $
+ * $Id: ditto.c,v 1.47 2017/10/18 23:04:42 tom Exp $
*
* The program illustrates how to set up multiple screens from a single
* program.
static void
usage(void)
{
- fprintf(stderr, "usage: ditto [terminal1 ...]\n");
+ fprintf(stderr, "Usage: ditto [terminal1 ...]\n");
ExitProgram(EXIT_FAILURE);
}
/*
* Author: Thomas E. Dickey <dickey@clark.net> 1999
*
- * $Id: dots.c,v 1.28 2017/10/11 08:15:27 tom Exp $
+ * $Id: dots.c,v 1.31 2017/10/22 00:44:06 tom Exp $
*
* A simple demo of the terminfo interface.
*/
return ((double) r / 32768.);
}
+static int
+get_number(const char *cap, int map)
+{
+ int result = map;
+ if (cap != 0) {
+ int check = tigetnum(cap);
+ if (check > 0)
+ result = check;
+ }
+ return result;
+}
+
+static void
+usage(void)
+{
+ static const char *msg[] =
+ {
+ "Usage: dots [options]"
+ ,""
+ ,"Options:"
+ ," -T TERM override $TERM"
+ ," -e allow environment $LINES / $COLUMNS"
+ ," -f use tigetnum rather than <term.h> mapping"
+ ," -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;
double r;
double c;
int my_colors;
+ int f_option = 0;
+ int m_option = 2;
+ int s_option = 1;
+
+ while ((x = getopt(argc, argv, "T:efm:s:")) != -1) {
+ switch (x) {
+ case 'T':
+ putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg));
+ break;
+ case 'e':
+ use_env(TRUE);
+ break;
+ case 'f':
+ f_option = 1;
+ break;
+ case 'm':
+ m_option = atoi(optarg);
+ break;
+ case 's':
+ s_option = atoi(optarg);
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
- srand((unsigned) time(0));
InitAndCatch(setupterm((char *) 0, 1, (int *) 0), onsig);
+
+ srand((unsigned) time(0));
+
outs(clear_screen);
outs(cursor_invisible);
- my_colors = max_colors;
+
+#define GetNumber(ln,sn) get_number(f_option ? #sn : 0, ln)
+ my_colors = GetNumber(max_colors, colors);
if (my_colors > 1) {
if (!VALID_STRING(set_a_foreground)
|| !VALID_STRING(set_a_background)
my_colors = -1;
}
- r = (double) (lines - 4);
- c = (double) (columns - 4);
+ r = (double) (GetNumber(lines, lines) - (m_option * 2));
+ c = (double) (GetNumber(columns, cols) - (m_option * 2));
started = time((time_t *) 0);
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) ? '*' : ' ';
tputs(tparm3(cursor_address, y, x), 1, outc);
tputs(tparm2(set_a_foreground, z), 1, outc);
} else {
tputs(tparm2(set_a_background, z), 1, outc);
- napms(1);
+ napms(s_option);
}
} else if (VALID_STRING(exit_attribute_mode)
&& VALID_STRING(enter_reverse_mode)) {
outs((ranf() > 0.6)
? enter_reverse_mode
: exit_attribute_mode);
- napms(1);
+ napms(s_option);
}
}
outc(p);
/*
* 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.9 2017/10/22 00:44:39 tom Exp $
*
* A simple demo of the curses interface used for comparison with termcap.
*/
}
}
+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
+ ," -e allow environment $LINES / $COLUMNS"
+ ," -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;
+
+ while ((x = getopt(argc, argv, "T:dem:s:")) != -1) {
+ switch (x) {
+ case 'T':
+ putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg));
+ break;
+#if HAVE_USE_DEFAULT_COLORS
+ case 'd':
+ d_option = TRUE;
+ break;
+#endif
+ case 'e':
+ use_env(TRUE);
+ break;
+ 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);
}
}
- 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);
attron(COLOR_PAIR(mypair(fg, bg)));
} else {
set_colors(fg, bg = z);
- napms(1);
+ napms(s_option);
}
} else {
if (ranf() <= 0.01) {
} else {
attroff(A_REVERSE);
}
- napms(1);
+ napms(s_option);
}
}
AddCh(p);
/*
* Author: Thomas E. Dickey - 2007
*
- * $Id: dots_mvcur.c,v 1.15 2017/10/11 08:15:46 tom Exp $
+ * $Id: dots_mvcur.c,v 1.17 2017/10/22 00:44:39 tom Exp $
*
* A simple demo of the terminfo interface, and mvcur.
*/
return ((double) r / 32768.);
}
+static int
+get_number(const char *cap, int map)
+{
+ int result = map;
+ if (cap != 0) {
+ int check = tigetnum(cap);
+ if (check > 0)
+ result = check;
+ }
+ return result;
+}
+
+static void
+usage(void)
+{
+ static const char *msg[] =
+ {
+ "Usage: dots_termcap [options]"
+ ,""
+ ,"Options:"
+ ," -T TERM override $TERM"
+ ," -e allow environment $LINES / $COLUMNS"
+ ," -f use tigetnum rather than <term.h> mapping"
+ ," -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)
double c;
SCREEN *sp;
int my_colors;
+ int f_option = 0;
+ int m_option = 2;
+ int s_option = 1;
+
+ while ((x = getopt(argc, argv, "T:efm:s:")) != -1) {
+ switch (x) {
+ case 'T':
+ putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg));
+ break;
+ case 'e':
+ use_env(TRUE);
+ break;
+ case 'f':
+ f_option = 1;
+ break;
+ case 'm':
+ m_option = atoi(optarg);
+ break;
+ case 's':
+ s_option = atoi(optarg);
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
InitAndCatch((sp = newterm((char *) 0, stdout, stdin)), onsig);
refresh(); /* needed with Solaris curses to cancel endwin */
outs(clear_screen);
outs(cursor_home);
outs(cursor_invisible);
- my_colors = max_colors;
+
+#define GetNumber(ln,sn) get_number(f_option ? #sn : 0, ln)
+ my_colors = GetNumber(max_colors, colors);
if (my_colors > 1) {
if (!VALID_STRING(set_a_foreground)
|| !VALID_STRING(set_a_background)
my_colors = -1;
}
- r = (double) (lines - 4);
- c = (double) (columns - 4);
+ r = (double) (GetNumber(lines, lines) - (m_option * 2));
+ c = (double) (GetNumber(columns, cols) - (m_option * 2));
started = time((time_t *) 0);
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) ? '*' : ' ';
if (mvcur(y0, x0, y, x) != ERR) {
tputs(tparm2(set_a_foreground, z), 1, outc);
} else {
tputs(tparm2(set_a_background, z), 1, outc);
- napms(1);
+ napms(s_option);
}
} else if (VALID_STRING(exit_attribute_mode)
&& VALID_STRING(enter_reverse_mode)) {
outs((ranf() > 0.6)
? enter_reverse_mode
: exit_attribute_mode);
- napms(1);
+ napms(s_option);
}
}
outc(p);
/*
* Author: Thomas E. Dickey
*
- * $Id: dots_termcap.c,v 1.12 2017/10/11 08:15:07 tom Exp $
+ * $Id: dots_termcap.c,v 1.15 2017/10/22 00:49:45 tom Exp $
*
* A simple demo of the termcap interface.
*/
static void
my_napms(int ms)
{
+ if (ms > 0) {
#if defined(__MINGW32__) || !HAVE_GETTIMEOFDAY
- Sleep((DWORD) ms);
+ Sleep((DWORD) ms);
#else
- struct timeval data;
- data.tv_sec = 0;
- data.tv_usec = ms * 1000;
- select(0, NULL, NULL, NULL, &data);
+ struct timeval data;
+ data.tv_sec = 0;
+ data.tv_usec = ms * 1000;
+ select(0, NULL, NULL, NULL, &data);
#endif
+ }
+}
+
+static int
+get_number(const char *cap, const char *env)
+{
+ int result = tgetnum(cap);
+ char *value = env ? getenv(env) : 0;
+ if (value != 0 && *value != 0) {
+ char *next = 0;
+ long check = strtol(value, &next, 10);
+ if (check > 0 && *next == '\0')
+ result = (int) check;
+ }
+ return result;
+}
+
+static void
+usage(void)
+{
+ static const char *msg[] =
+ {
+ "Usage: dots_termcap [options]"
+ ,""
+ ,"Options:"
+ ," -T TERM override $TERM"
+ ," -e allow environment $LINES / $COLUMNS"
+ ," -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 num_colors;
int num_lines;
int num_columns;
+ int e_option = 0;
+ int m_option = 2;
+ int s_option = 1;
double r;
double c;
char buffer[1024];
char area[1024];
char *name;
- srand((unsigned) time(0));
+ while ((x = getopt(argc, argv, "T:em:s:")) != -1) {
+ switch (x) {
+ case 'T':
+ putenv(strcat(strcpy(malloc(6 + strlen(optarg)), "TERM="), optarg));
+ break;
+ case 'e':
+ e_option = 1;
+ break;
+ case 'm':
+ m_option = atoi(optarg);
+ break;
+ case 's':
+ s_option = atoi(optarg);
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
if ((name = getenv("TERM")) == 0) {
fprintf(stderr, "TERM is not set\n");
ExitProgram(EXIT_FAILURE);
}
+
+ srand((unsigned) time(0));
+
InitAndCatch(z = tgetent(buffer, name), onsig);
if (z < 0) {
fprintf(stderr, "terminal description not found\n");
}
num_colors = tgetnum("Co");
- num_lines = tgetnum("li");
- num_columns = tgetnum("co");
+#define GetNumber(cap,env) get_number(cap, e_option ? env : 0)
+ num_lines = GetNumber("li", "LINES");
+ num_columns = GetNumber("co", "COLUMNS");
outs(t_cl);
outs(t_vi);
num_colors = -1;
}
- r = (double) (num_lines - 4);
- c = (double) (num_columns - 4);
+ r = (double) (num_lines - (2 * m_option));
+ c = (double) (num_columns - (2 * m_option));
started = time((time_t *) 0);
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) ? '*' : ' ';
tputs(tgoto(t_cm, x, y), 1, outc);
tputs(tgoto(t_AF, 0, z), 1, outc);
} else {
tputs(tgoto(t_AB, 0, z), 1, outc);
- my_napms(1);
+ my_napms(s_option);
}
} else if (VALID_STRING(t_me)
&& VALID_STRING(t_mr)) {
outs((ranf() > 0.6)
? t_mr
: t_me);
- my_napms(1);
+ my_napms(s_option);
}
}
outc(p);
/*
* 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.11 2017/10/22 00:44:39 tom Exp $
*
* A simple demo of the wide-curses interface used for comparison with termcap.
*/
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
}
}
-#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
+ ," -e allow environment $LINES / $COLUMNS"
+ ," -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;
-#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
+ case 'e':
+ use_env(TRUE);
+ break;
+ 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++) {
pair = mypair(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;
* authorization. *
****************************************************************************/
/*
- * $Id: echochar.c,v 1.17 2017/10/11 08:16:12 tom Exp $
+ * $Id: echochar.c,v 1.18 2017/10/18 23:04:52 tom Exp $
*
* Demonstrate the echochar function (compare to dots.c).
* Thomas Dickey - 2006/11/4
opt_r = TRUE;
break;
default:
- fprintf(stderr, "usage: echochar [-r]\n");
+ fprintf(stderr, "Usage: echochar [-r]\n");
ExitProgram(EXIT_FAILURE);
}
}
* authorization. *
****************************************************************************/
/*
- * $Id: ins_wide.c,v 1.23 2017/04/08 22:14:03 tom Exp $
+ * $Id: ins_wide.c,v 1.24 2017/10/18 23:03:57 tom Exp $
*
* Demonstrate the wins_wstr() and wins_wch functions.
* Thomas Dickey - 2002/11/23
{
static const char *tbl[] =
{
- "Usage: inserts [options]"
+ "Usage: ins_wide [options]"
,""
,"Options:"
," -f FILE read data from given file"
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.469 2017/10/01 18:22:48 tom Exp $
+$Id: ncurses.c,v 1.470 2017/10/20 21:20:47 tom Exp $
***************************************************************************/
attr_t attr;
cchar_t ch;
NCURSES_PAIRS_T pair;
- wchar_t wch[10];
+ wchar_t wch[CCHARW_MAX];
memset(&ch, 0, sizeof(ch));
if (getbkgrnd(&ch) != ERR) {
* authorization. *
****************************************************************************/
/*
- * $Id: savescreen.c,v 1.35 2017/09/29 23:42:22 tom Exp $
+ * $Id: savescreen.c,v 1.36 2017/10/20 21:20:34 tom Exp $
*
* Demonstrate save/restore functions from the curses library.
* Thomas Dickey - 2007/7/14
static wchar_t
BaseChar(cchar_t data)
{
- wchar_t my_wchar[sizeof(cchar_t)];
+ wchar_t my_wchar[CCHARW_MAX];
attr_t my_attr;
short my_pair;
getcchar(&data, my_wchar, &my_attr, &my_pair, NULL);
*
* modified by Thomas Dickey <dickey@clark.net> July 1995 to demonstrate
* the use of 'resizeterm()', and May 2000 to illustrate wide-character
- * handling.
+ * handling. This program intentionally does not use pads, to allow testing
+ * with less-capable implementations of curses.
*
* Takes a filename argument. It's a simple file-viewer with various
* scroll-up and scroll-down commands.
* scroll operation worked, and the refresh() code only had to do a
* partial repaint.
*
- * $Id: view.c,v 1.111 2017/10/15 00:56:58 tom Exp $
+ * $Id: view.c,v 1.129 2017/10/22 00:49:23 tom Exp $
*/
#include <test.priv.h>
static void finish(int sig) GCC_NORETURN;
-#if HAVE_TERMIOS_H
-# include <termios.h>
-#else
-#if !defined(__MINGW32__)
-# include <sgtty.h>
-#endif
-#endif
-
-#if !defined(sun) || !HAVE_TERMIOS_H
-# if HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-# endif
-#endif
-
#define my_pair 1
-/* This is needed to compile 'struct winsize' */
-#if NEED_PTEM_H
-#include <sys/stream.h>
-#include <sys/ptem.h>
-#endif
-
#undef CTRL
#define CTRL(x) ((x) & 0x1f)
-#if defined(SIGWINCH) && defined(TIOCGWINSZ) && HAVE_RESIZE_TERM
-#define CAN_RESIZE 1
-#else
-#define CAN_RESIZE 0
-#endif
-
-#if CAN_RESIZE
-static int interrupted;
-static bool waiting = FALSE;
-#endif
-
static int shift = 0;
static bool try_color = FALSE;
static NCURSES_CH_T **lptr;
static int num_lines;
+#if USE_WIDEC_SUPPORT
+static bool n_option = FALSE;
+#endif
+
static void usage(void) GCC_NORETURN;
static void
failed(const char *msg)
{
+ endwin();
fprintf(stderr, "%s\n", msg);
ExitProgram(EXIT_FAILURE);
}
-static void
-usage(void)
-{
- static const char *msg[] =
- {
- "Usage: view [options] file"
- ,""
- ,"Options:"
- ," -c use color if terminal supports it"
- ," -i ignore INT, QUIT, TERM signals"
-#if defined(KEY_RESIZE)
- ," -r use old-style sigwinch handler rather than KEY_RESIZE"
-#endif
- ," -s start in single-step mode, waiting for input"
-#ifdef TRACE
- ," -t trace screen updates"
- ," -T NUM specify trace mask"
-#endif
- };
- size_t n;
- for (n = 0; n < SIZEOF(msg); n++)
- fprintf(stderr, "%s\n", msg[n]);
- ExitProgram(EXIT_FAILURE);
-}
-
static int
ch_len(NCURSES_CH_T * src)
{
#if USE_WIDEC_SUPPORT
for (;;) {
TEST_CCHAR(src, count, {
- ++result;
+ int len = wcwidth(test_wch[0]);
+ result += (len > 0) ? len : 1;
++src;
}
, {
return result;
}
-/*
- * Allocate a string into an array of chtype's. If UTF-8 mode is
- * active, translate the string accordingly.
- */
-static NCURSES_CH_T *
-ch_dup(char *src)
-{
- unsigned len = (unsigned) strlen(src);
- NCURSES_CH_T *dst = typeMalloc(NCURSES_CH_T, len + 1);
- size_t j, k;
-#if USE_WIDEC_SUPPORT
- wchar_t wstr[CCHARW_MAX + 1];
- wchar_t wch;
- int l = 0;
- size_t rc;
- int width;
-#ifndef state_unused
- mbstate_t state;
-#endif
-#endif /* USE_WIDEC_SUPPORT */
-
-#if USE_WIDEC_SUPPORT
- reset_mbytes(state);
-#endif
- for (j = k = 0; j < len; j++) {
-#if USE_WIDEC_SUPPORT
- rc = (size_t) check_mbytes(wch, src + j, len - j, state);
- if (rc == (size_t) -1 || rc == (size_t) -2) {
- break;
- }
- j += rc - 1;
- width = wcwidth(wch);
- if (width == 0) {
- if (l == 0) {
- wstr[l++] = L' ';
- }
- } else if ((l > 0) || (l == CCHARW_MAX)) {
- wstr[l] = L'\0';
- l = 0;
- if (setcchar(dst + k, wstr, 0, 0, NULL) != OK) {
- break;
- }
- ++k;
- }
- wstr[l++] = wch;
-#else
- dst[k++] = (chtype) UChar(src[j]);
-#endif
- }
-#if USE_WIDEC_SUPPORT
- if (l > 0) {
- wstr[l] = L'\0';
- if (setcchar(dst + k, wstr, 0, 0, NULL) == OK)
- ++k;
- }
- wstr[0] = L'\0';
- setcchar(dst + k, wstr, 0, 0, NULL);
-#else
- dst[k] = 0;
-#endif
- return dst;
-}
-
static void
finish(int sig)
{
NCURSES_CH_T *s;
time_t this_time;
-#if CAN_RESIZE
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
- "%.20s (%3dx%3d) col %d ", tag, LINES, COLS, shift);
+ "view %.*s", (int) strlen(tag), tag);
i = (int) strlen(temp);
- if ((i + 7) < (int) sizeof(temp)) {
- _nc_SPRINTF(temp + i, _nc_SLIMIT(sizeof(temp) - (size_t) i)
- "view %.*s",
- (int) (sizeof(temp) - 7 - (size_t) i),
- fname);
- }
-#else
- (void) tag;
- _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
- "view %.*s", (int) sizeof(temp) - 7, fname);
-#endif
+ _nc_SPRINTF(temp + i, _nc_SLIMIT(sizeof(temp) - i)
+ " %.*s", (int) sizeof(temp) - i - 2, fname);
move(0, 0);
printw("%.*s", COLS, temp);
clrtoeol();
for (i = 1; i < LINES; i++) {
int len;
int actual = (int) (lptr + i - vec_lines);
- if (actual >= num_lines) {
- clrtobot();
+ if (actual > num_lines) {
+ if (i < LINES - 1) {
+ int y, x;
+ getyx(stdscr, y, x);
+ move(i, 0);
+ clrtobot();
+ move(y, x);
+ }
break;
}
move(i, 0);
len = ch_len(s);
if (len > shift) {
#if USE_WIDEC_SUPPORT
- add_wchstr(s + shift);
+ /*
+ * An index into an array of cchar_t's is not necessarily the same
+ * as the column-offset. A pad would do this directly. Here we
+ * must translate (or compute a table of offsets).
+ */
+ {
+ int j;
+ int width = 1, count;
+ for (j = actual = 0; j < shift; ++j) {
+ TEST_CCHAR(s + j, count, {
+ width = wcwidth(test_wch[0]);
+ }
+ , {
+ width = 1;
+ });
+ actual += width;
+ if (actual > shift) {
+ break;
+ } else if (actual == shift) {
+ ++j;
+ break;
+ }
+ }
+ if (actual < len) {
+ if (actual > shift)
+ addch('<');
+ add_wchstr(s + j + (actual > shift));
+ }
+ }
#else
addchstr(s + shift);
#endif
refresh();
}
-#if CAN_RESIZE
-/*
- * This uses functions that are "unsafe", but it seems to work on SunOS.
- * Usually: the "unsafe" refers to the functions that POSIX lists which may be
- * called from a signal handler. Those do not include buffered I/O, which is
- * used for instance in wrefresh(). To be really portable, you should use the
- * KEY_RESIZE return (which relies on ncurses' sigwinch handler).
- *
- * The 'wrefresh(curscr)' is needed to force the refresh to start from the top
- * of the screen -- some xterms mangle the bitmap while resizing.
- */
-static void
-adjust(int sig)
-{
- if (waiting || sig == 0) {
- struct winsize size;
-
- if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) {
- resize_term(size.ws_row, size.ws_col);
- wrefresh(curscr);
- show_all(sig ? "SIGWINCH" : "interrupt");
- }
- interrupted = FALSE;
- } else {
- interrupted = TRUE;
- }
- (void) signal(SIGWINCH, adjust); /* some systems need this */
-}
-#endif /* CAN_RESIZE */
-
static void
read_file(const char *filename)
{
FILE *fp;
int pass;
int k;
+ int width;
size_t j;
size_t len;
struct stat sb;
char *my_blob;
char **my_vec = 0;
+ WINDOW *my_win;
if (stat(filename, &sb) != 0
|| (sb.st_mode & S_IFMT) != S_IFREG) {
failed("cannot allocate line-vector #1");
}
}
+
+#if USE_WIDEC_SUPPORT
+ if (!memcmp("", my_blob, 3)) {
+ char *s = my_blob + 3;
+ char *d = my_blob;
+ Trace(("trim BOM"));
+ do {
+ } while ((*d++ = *s++) != '\0');
+ }
+#endif
+
+ width = (int) strlen(my_vec[0]);
+ for (k = 1; my_vec[k]; ++k) {
+ int check = (int) (my_vec[k] - my_vec[k - 1]);
+ if (width < check)
+ width = check;
+ }
+ width = (width + 1) * 5;
+ my_win = newwin(2, width, 0, 0);
+ if (my_win == 0)
+ failed("cannot allocate temporary window");
+
if ((vec_lines = typeCalloc(NCURSES_CH_T *, (size_t) num_lines + 2)) == 0)
failed("cannot allocate line-vector #2");
+ /*
+ * Use the curses library for rendering, including tab-conversion. This
+ * will not make the resulting array's indices correspond to column for
+ * lines containing double-width cells because the "in_wch" functions will
+ * ignore the skipped cells. Use pads for that sort of thing.
+ */
Trace(("slurp the file"));
- for (k = 0; k < num_lines; ++k) {
- char *buf = my_vec[k];
- char temp[BUFSIZ], *s, *d;
- int col;
-
- lptr = &vec_lines[k];
-
+ for (k = 0; my_vec[k]; ++k) {
+ char *s;
+ int y, x;
#if USE_WIDEC_SUPPORT
- if (lptr == vec_lines) {
- if (!memcmp("", buf, 3)) {
- Trace(("trim BOM"));
- s = buf + 3;
- d = buf;
- do {
- } while ((*d++ = *s++) != '\0');
- }
- }
+ char *last = my_vec[k] + (int) strlen(my_vec[k]);
+ wchar_t wch[2];
+ size_t rc;
+#ifndef state_unused
+ mbstate_t state;
#endif
+#endif /* USE_WIDEC_SUPPORT */
- /* convert tabs and nonprinting chars so that shift will work properly */
- for (s = buf, d = temp, col = 0; (*d = *s) != '\0'; s++) {
- if (*d == '\r') {
- if (s[1] == '\n') {
- continue;
- } else {
+ werase(my_win);
+ wmove(my_win, 0, 0);
+#if USE_WIDEC_SUPPORT
+ wch[1] = 0;
+ reset_mbytes(state);
+#endif
+ for (s = my_vec[k]; *s != '\0'; ++s) {
+#if USE_WIDEC_SUPPORT
+ if (!n_option) {
+ rc = (size_t) check_mbytes(wch[0], s, (size_t) (last - s), state);
+ if ((long) rc == -1 || (long) rc == -2) {
break;
}
- }
- if (*d == '\n') {
- *d = '\0';
- break;
- } else if (*d == '\t') {
- col = (col | 7) + 1;
- while ((d - temp) != col)
- *d++ = ' ';
+ s += rc - 1;
+ waddwstr(my_win, wch);
} else
+#endif
+ waddch(my_win, *s & 0xff);
+ }
+ getyx(my_win, y, x);
+ if (y)
+ x = width - 1;
+ wmove(my_win, 0, 0);
+ if ((vec_lines[k] = typeCalloc(NCURSES_CH_T, (size_t) x + 1)) == 0)
+ failed("cannot allocate line-vector #3");
#if USE_WIDEC_SUPPORT
- col++, d++;
+ win_wchnstr(my_win, vec_lines[k], x);
#else
- if (isprint(UChar(*d))) {
- col++;
- d++;
- } else {
- _nc_SPRINTF(d, _nc_SLIMIT(sizeof(temp) - (d - buf))
- "\\%03o", UChar(*s));
- d += strlen(d);
- col = (int) (d - temp);
- }
+ winchnstr(my_win, vec_lines[k], x);
#endif
- }
- *lptr = ch_dup(temp);
}
+ delwin(my_win);
free(my_vec);
free(my_blob);
}
+static void
+usage(void)
+{
+ static const char *msg[] =
+ {
+ "Usage: view [options] file"
+ ,""
+ ,"Options:"
+ ," -c use color if terminal supports it"
+ ," -i ignore INT, QUIT, TERM signals"
+#if USE_WIDEC_SUPPORT
+ ," -n use waddch (bytes) rather then wadd_wch (wide-chars)"
+#endif
+ ," -s start in single-step mode, waiting for input"
+#ifdef TRACE
+ ," -t trace screen updates"
+ ," -T NUM specify trace mask"
+#endif
+ };
+ size_t n;
+ for (n = 0; n < SIZEOF(msg); n++)
+ fprintf(stderr, "%s\n", msg[n]);
+ ExitProgram(EXIT_FAILURE);
+}
+
int
main(int argc, char *argv[])
{
bool got_number = FALSE;
bool ignore_sigs = FALSE;
bool single_step = FALSE;
-#if CAN_RESIZE
- bool nonposix_resize = FALSE;
-#endif
const char *my_label = "Input";
setlocale(LC_ALL, "");
case 'i':
ignore_sigs = TRUE;
break;
-#if CAN_RESIZE
- case 'r':
- nonposix_resize = TRUE;
- break;
-#endif
case 's':
single_step = TRUE;
break;
if (optind + 1 != argc)
usage();
- read_file(fname = argv[optind]);
-
-#if CAN_RESIZE
- if (nonposix_resize)
- (void) signal(SIGWINCH, adjust); /* arrange interrupts to resize */
-#endif
-
InitAndCatch(initscr(), ignore_sigs ? SIG_IGN : finish);
keypad(stdscr, TRUE); /* enable keyboard mapping */
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
nodelay(stdscr, TRUE);
idlok(stdscr, TRUE); /* allow use of insert/delete line */
+ read_file(fname = argv[optind]);
+
if (try_color) {
if (has_colors()) {
start_color();
show_all(my_label);
for (;;) {
-#if CAN_RESIZE
- if (interrupted) {
- adjust(0);
- my_label = "interrupt";
- }
- waiting = TRUE;
c = getch();
- waiting = FALSE;
-#else
- c = getch();
-#endif
if ((c < 127) && isdigit(c)) {
if (!got_number) {
MvPrintw(0, 0, "Count: ");
case CTRL('F'):
/* FALLTHRU */
case KEY_NPAGE:
- if ((lptr - vec_lines) < (num_lines - 5))
- lptr += (LINES - 1);
- else
- lptr = (vec_lines + num_lines - 2);
+ for (i = 0; i < n; i++) {
+ if ((lptr - vec_lines) < (num_lines - 5))
+ lptr += (LINES - 1);
+ else
+ lptr = (vec_lines + num_lines - 2);
+ }
break;
case CTRL('B'):
/* FALLTHRU */
case KEY_PPAGE:
- if ((lptr - vec_lines) >= LINES)
- lptr -= (LINES - 1);
- else
- lptr = vec_lines;
+ for (i = 0; i < n; i++) {
+ if ((lptr - vec_lines) >= LINES)
+ lptr -= (LINES - 1);
+ else
+ lptr = vec_lines;
+ }
break;
case 'r':
--- /dev/null
+APPLE -- It's an APPLE.
+DOG -- No, that's not my DOG.
+ORANGE -- Yeah, that's JUICY.
+CHICKEN -- Normally not a PET.
+CAT -- No, never put a DOG and a CAT together!
+FISH -- Cats like FISH.
+LEMON -- You KNOW how it TASTES.
+----+----1----+----2----+----3----+----4
+APPLE -- It's an APPLE.
+ APPLE -- It's an APPLE.
+ APPLE -- It's an APPLE.
+ APPLE -- It's an APPLE.
+ APPLE -- It's an APPLE.
+ APPLE -- It's an APPLE.
+----+----1----+----2----+----3----+----4