mirror of
https://github.com/Aigor44/ncursesw-morphos.git
synced 2025-03-01 16:15:25 +08:00
ncurses 6.0 - patch 20170909
+ improve wide-character implementation of myADDNSTR() in frm_driver.c, which was inconsistent with the normal implementation. + save/restore cursor position in Undo_Justification(), matching behavior of Buffer_To_Window() (report by Leon Winter). + modify test/knight to provide the "slow" solution for small screens using "R", noting that Warnsdorf's method is easily done with "a". + modify several test-programs which call use_default_colors() to consistently do this only if "-d" option is given. + additional changes to test with non-standard variants of curses: + modify a loop limit in firework.c to work around absense of limit checks in some libraries. + fill the last row of a window with "?" in firstlast if waddch does not return ERR on the lower-right corner. + add checks in test/configure for some functions not in 4.3BSD curses. + fix a regression in test/configure (cf: 20170826).
This commit is contained in:
parent
a4dac84af1
commit
5d8dbcdd94
19
NEWS
19
NEWS
@ -25,7 +25,7 @@
|
||||
-- sale, use or other dealings in this Software without prior written --
|
||||
-- authorization. --
|
||||
-------------------------------------------------------------------------------
|
||||
-- $Id: NEWS,v 1.2939 2017/09/02 21:48:17 tom Exp $
|
||||
-- $Id: NEWS,v 1.2949 2017/09/09 22:32:34 tom Exp $
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
This is a log of changes that ncurses has gone through since Zeyd started
|
||||
@ -45,6 +45,23 @@ See the AUTHORS file for the corresponding full names.
|
||||
Changes through 1.9.9e did not credit all contributions;
|
||||
it is not possible to add this information.
|
||||
|
||||
20170909
|
||||
+ improve wide-character implementation of myADDNSTR() in frm_driver.c,
|
||||
which was inconsistent with the normal implementation.
|
||||
+ save/restore cursor position in Undo_Justification(), matching
|
||||
behavior of Buffer_To_Window() (report by Leon Winter).
|
||||
+ modify test/knight to provide the "slow" solution for small screens
|
||||
using "R", noting that Warnsdorf's method is easily done with "a".
|
||||
+ modify several test-programs which call use_default_colors() to
|
||||
consistently do this only if "-d" option is given.
|
||||
+ additional changes to test with non-standard variants of curses:
|
||||
+ modify a loop limit in firework.c to work around absense of limit
|
||||
checks in some libraries.
|
||||
+ fill the last row of a window with "?" in firstlast if waddch does
|
||||
not return ERR on the lower-right corner.
|
||||
+ add checks in test/configure for some functions not in 4.3BSD curses.
|
||||
+ fix a regression in test/configure (cf: 20170826).
|
||||
|
||||
20170902
|
||||
+ amend change for endwin-state for better consistency with the older
|
||||
logic (report/patch by Jeb Rosen, cf: 20170722).
|
||||
|
4
dist.mk
4
dist.mk
@ -25,7 +25,7 @@
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
# $Id: dist.mk,v 1.1181 2017/08/29 22:24:15 tom Exp $
|
||||
# $Id: dist.mk,v 1.1182 2017/09/03 20:54:16 tom Exp $
|
||||
# Makefile for creating ncurses distributions.
|
||||
#
|
||||
# This only needs to be used directly as a makefile by developers, but
|
||||
@ -37,7 +37,7 @@ SHELL = /bin/sh
|
||||
# These define the major/minor/patch versions of ncurses.
|
||||
NCURSES_MAJOR = 6
|
||||
NCURSES_MINOR = 0
|
||||
NCURSES_PATCH = 20170902
|
||||
NCURSES_PATCH = 20170909
|
||||
|
||||
# We don't append the patch to the version, since this only applies to releases
|
||||
VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#include "form.priv.h"
|
||||
|
||||
MODULE_ID("$Id: frm_driver.c,v 1.121 2017/04/08 22:02:15 tom Exp $")
|
||||
MODULE_ID("$Id: frm_driver.c,v 1.123 2017/09/09 22:35:49 tom Exp $")
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
This is the core module of the form library. It contains the majority
|
||||
@ -99,9 +99,9 @@ Perhaps at some time we will make this configurable at runtime.
|
||||
#define GROW_IF_NAVIGATE (1)
|
||||
|
||||
#if USE_WIDEC_SUPPORT
|
||||
#define myADDNSTR(w, s, n) wadd_wchnstr(w, s, n)
|
||||
#define myINSNSTR(w, s, n) wins_wchnstr(w, s, n)
|
||||
#define myINNSTR(w, s, n) fix_wchnstr(w, s, n)
|
||||
#define myADDNSTR(w, s, n) wide_waddnstr(w, s, n)
|
||||
#define myINSNSTR(w, s, n) wide_winsnstr(w, s, n)
|
||||
#define myINNSTR(w, s, n) wide_winnstr(w, s, n)
|
||||
#define myWCWIDTH(w, y, x) cell_width(w, y, x)
|
||||
#else
|
||||
#define myADDNSTR(w, s, n) waddnstr(w, s, n)
|
||||
@ -239,9 +239,29 @@ check_pos(FORM *form, int lineno)
|
||||
Wide-character special functions
|
||||
--------------------------------------------------------------------------*/
|
||||
#if USE_WIDEC_SUPPORT
|
||||
/* like winsnstr */
|
||||
/* add like waddnstr, but using cchar_t* rather than char*
|
||||
*/
|
||||
static int
|
||||
wins_wchnstr(WINDOW *w, cchar_t *s, int n)
|
||||
wide_waddnstr(WINDOW *w, const cchar_t *s, int n)
|
||||
{
|
||||
int rc = OK;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if ((rc = wadd_wch(w, s)) != OK)
|
||||
break;
|
||||
++s;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* insert like winsnstr, but using cchar_t* rather than char*
|
||||
*
|
||||
* X/Open Curses has no close equivalent; inserts are done only with wchar_t
|
||||
* strings.
|
||||
*/
|
||||
static int
|
||||
wide_winsnstr(WINDOW *w, const cchar_t *s, int n)
|
||||
{
|
||||
int code = ERR;
|
||||
int y, x;
|
||||
@ -257,11 +277,13 @@ wins_wchnstr(WINDOW *w, cchar_t *s, int n)
|
||||
return code;
|
||||
}
|
||||
|
||||
/* win_wchnstr is inconsistent with winnstr, since it returns OK rather than
|
||||
* the number of items transferred.
|
||||
/* retrieve like winnstr, but using cchar_t*, rather than char*.
|
||||
*
|
||||
* X/Open Curses' closest equivalent, win_wchnstr(), is inconsistent with
|
||||
* winnstr(), since it returns OK rather than the number of items transferred.
|
||||
*/
|
||||
static int
|
||||
fix_wchnstr(WINDOW *w, cchar_t *s, int n)
|
||||
wide_winnstr(WINDOW *w, cchar_t *s, int n)
|
||||
{
|
||||
int x;
|
||||
|
||||
@ -1023,8 +1045,11 @@ static void
|
||||
Undo_Justification(FIELD *field, WINDOW *win)
|
||||
{
|
||||
FIELD_CELL *bp;
|
||||
int y, x;
|
||||
int len;
|
||||
|
||||
getyx(win, y, x);
|
||||
|
||||
bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
|
||||
? field->buf
|
||||
: Get_Start_Of_Data(field->buf, Buffer_Length(field)));
|
||||
@ -1036,6 +1061,7 @@ Undo_Justification(FIELD *field, WINDOW *win)
|
||||
wmove(win, 0, 0);
|
||||
myADDNSTR(win, bp, len);
|
||||
}
|
||||
wmove(win, y, x);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Id: ncurses_defs,v 1.75 2017/08/20 16:50:04 tom Exp $
|
||||
# $Id: ncurses_defs,v 1.80 2017/09/04 15:01:23 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 2000-2016,2017 Free Software Foundation, Inc. #
|
||||
# #
|
||||
@ -52,8 +52,11 @@ HAVE_BUILTIN_H
|
||||
HAVE_CHGAT 1
|
||||
HAVE_COLOR_CONTENT 1
|
||||
HAVE_COLOR_SET 1
|
||||
HAVE_COPYWIN 1
|
||||
HAVE_CURSCR 1
|
||||
HAVE_DERWIN 1
|
||||
HAVE_DIRENT_H
|
||||
HAVE_DUPWIN 1
|
||||
HAVE_ERRNO
|
||||
HAVE_FCNTL_H
|
||||
HAVE_FILTER 1
|
||||
@ -73,6 +76,7 @@ HAVE_GETWIN 1
|
||||
HAVE_GPM_H
|
||||
HAVE_GPP_BUILTIN_H
|
||||
HAVE_GXX_BUILTIN_H
|
||||
HAVE_HALFDELAY 1
|
||||
HAVE_HAS_KEY
|
||||
HAVE_INIT_EXTENDED_COLOR
|
||||
HAVE_INTTYPES_H
|
||||
@ -105,6 +109,7 @@ HAVE_MVVLINE 1
|
||||
HAVE_MVWVLINE 1
|
||||
HAVE_NANOSLEEP
|
||||
HAVE_NC_ALLOC_H
|
||||
HAVE_NEWPAD 1
|
||||
HAVE_PANEL_H
|
||||
HAVE_POLL
|
||||
HAVE_POLL_H
|
||||
|
@ -26,7 +26,7 @@
|
||||
.\" authorization. *
|
||||
.\"***************************************************************************
|
||||
.\"
|
||||
.\" $Id: user_caps.5,v 1.1 2017/08/12 21:26:12 tom Exp $
|
||||
.\" $Id: user_caps.5,v 1.2 2017/09/04 19:27:24 tom Exp $
|
||||
.TH user_caps 5
|
||||
.ie \n(.g .ds `` \(lq
|
||||
.el .ds `` ``
|
||||
@ -210,7 +210,7 @@ asserts that ncurses must use Unicode values for line-drawing characters,
|
||||
and that it should ignore the alternate character set capabilities
|
||||
when the locale uses UTF-8 encoding.
|
||||
For more information, see the discussion of
|
||||
\fBNCURSES_NO_UTF8_ACS\fP in \fBterminfo\fP(5).
|
||||
\fBNCURSES_NO_UTF8_ACS\fP in \fBncurses\fP(3X).
|
||||
.IP
|
||||
Set this capability to a nonzero value to enable it.
|
||||
.TP 3
|
||||
|
@ -1,8 +1,8 @@
|
||||
ncurses6 (6.0+20170902) unstable; urgency=low
|
||||
ncurses6 (6.0+20170909) unstable; urgency=low
|
||||
|
||||
* latest weekly patch
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Tue, 29 Aug 2017 18:24:15 -0400
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Sun, 03 Sep 2017 16:54:16 -0400
|
||||
|
||||
ncurses6 (5.9-20131005) unstable; urgency=low
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
ncurses6 (6.0+20170902) unstable; urgency=low
|
||||
ncurses6 (6.0+20170909) unstable; urgency=low
|
||||
|
||||
* latest weekly patch
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Tue, 29 Aug 2017 18:24:15 -0400
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Sun, 03 Sep 2017 16:54:16 -0400
|
||||
|
||||
ncurses6 (5.9-20131005) unstable; urgency=low
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
ncurses6 (6.0+20170902) unstable; urgency=low
|
||||
ncurses6 (6.0+20170909) unstable; urgency=low
|
||||
|
||||
* latest weekly patch
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Tue, 29 Aug 2017 18:24:15 -0400
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Sun, 03 Sep 2017 16:54:16 -0400
|
||||
|
||||
ncurses6 (5.9-20120608) unstable; urgency=low
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
; $Id: mingw-ncurses.nsi,v 1.229 2017/08/29 22:24:15 tom Exp $
|
||||
; $Id: mingw-ncurses.nsi,v 1.230 2017/09/03 20:54:16 tom Exp $
|
||||
|
||||
; TODO add examples
|
||||
; TODO bump ABI to 6
|
||||
@ -10,7 +10,7 @@
|
||||
!define VERSION_MAJOR "6"
|
||||
!define VERSION_MINOR "0"
|
||||
!define VERSION_YYYY "2017"
|
||||
!define VERSION_MMDD "0902"
|
||||
!define VERSION_MMDD "0909"
|
||||
!define VERSION_PATCH ${VERSION_YYYY}${VERSION_MMDD}
|
||||
|
||||
!define MY_ABI "5"
|
||||
|
@ -3,7 +3,7 @@
|
||||
Summary: shared libraries for terminal handling
|
||||
Name: mingw32-ncurses6
|
||||
Version: 6.0
|
||||
Release: 20170902
|
||||
Release: 20170909
|
||||
License: X11
|
||||
Group: Development/Libraries
|
||||
Source: ncurses-%{version}-%{release}.tgz
|
||||
|
@ -1,7 +1,7 @@
|
||||
Summary: shared libraries for terminal handling
|
||||
Name: ncurses6
|
||||
Version: 6.0
|
||||
Release: 20170902
|
||||
Release: 20170909
|
||||
License: X11
|
||||
Group: Development/Libraries
|
||||
Source: ncurses-%{version}-%{release}.tgz
|
||||
|
@ -1,6 +1,6 @@
|
||||
# $Id: Makefile.in,v 1.116 2017/08/11 00:13:11 tom Exp $
|
||||
# $Id: Makefile.in,v 1.117 2017/09/04 00:50:06 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. #
|
||||
# Copyright (c) 1998-2015,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 "Software"), #
|
||||
|
6
test/aclocal.m4
vendored
6
test/aclocal.m4
vendored
@ -26,7 +26,7 @@ dnl sale, use or other dealings in this Software without prior written *
|
||||
dnl authorization. *
|
||||
dnl***************************************************************************
|
||||
dnl
|
||||
dnl $Id: aclocal.m4,v 1.142 2017/08/20 18:12:43 tom Exp $
|
||||
dnl $Id: aclocal.m4,v 1.144 2017/09/07 21:08:12 tom Exp $
|
||||
dnl
|
||||
dnl Author: Thomas E. Dickey
|
||||
dnl
|
||||
@ -745,7 +745,7 @@ fi
|
||||
AC_CHECK_HEADERS($cf_cv_ncurses_header)
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_CURSES_LIBS version: 39 updated: 2015/05/10 19:52:14
|
||||
dnl CF_CURSES_LIBS version: 40 updated: 2017/09/07 17:06:24
|
||||
dnl --------------
|
||||
dnl Look for the curses libraries. Older curses implementations may require
|
||||
dnl termcap/termlib to be linked as well. Call CF_CURSES_CPPFLAGS first.
|
||||
@ -839,7 +839,7 @@ if test ".$ac_cv_func_initscr" != .yes ; then
|
||||
for cf_curs_lib in $cf_check_list xcurses jcurses pdcurses unknown
|
||||
do
|
||||
LIBS="-l$cf_curs_lib $cf_save_LIBS"
|
||||
if test "$cf_term_lib" = unknown ; then
|
||||
if test "$cf_term_lib" = unknown || test "$cf_term_lib" = "$cf_curs_lib" ; then
|
||||
AC_MSG_CHECKING(if we can link with $cf_curs_lib library)
|
||||
AC_TRY_LINK([#include <${cf_cv_ncurses_header:-curses.h}>],
|
||||
[initscr()],
|
||||
|
3140
test/configure
vendored
3140
test/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ dnl***************************************************************************
|
||||
dnl
|
||||
dnl Author: Thomas E. Dickey 1996-on
|
||||
dnl
|
||||
dnl $Id: configure.in,v 1.135 2017/08/20 16:38:29 tom Exp $
|
||||
dnl $Id: configure.in,v 1.142 2017/09/09 23:07:56 tom Exp $
|
||||
dnl This is a simple configuration-script for the ncurses test programs that
|
||||
dnl allows the test-directory to be separately configured against a reference
|
||||
dnl system (i.e., sysvr4 curses)
|
||||
@ -52,6 +52,7 @@ AC_ARG_PROGRAM
|
||||
|
||||
AC_PROG_MAKE_SET
|
||||
CF_PROG_CC
|
||||
AC_C_INLINE
|
||||
AC_PROG_CPP
|
||||
AC_PROG_AWK
|
||||
CF_PROG_INSTALL
|
||||
@ -272,6 +273,9 @@ assume_default_colors \
|
||||
chgat \
|
||||
color_content \
|
||||
color_set \
|
||||
copywin \
|
||||
delscreen \
|
||||
dupwin \
|
||||
filter \
|
||||
getbegx \
|
||||
getcurx \
|
||||
@ -279,10 +283,14 @@ getmaxx \
|
||||
getnstr \
|
||||
getparx \
|
||||
getwin \
|
||||
halfdelay \
|
||||
init_extended_color \
|
||||
mvderwin \
|
||||
mvvline \
|
||||
mvwin \
|
||||
mvwvline \
|
||||
napms \
|
||||
newpad \
|
||||
putwin \
|
||||
resize_term \
|
||||
resizeterm \
|
||||
@ -308,6 +316,7 @@ vidputs \
|
||||
vsscanf \
|
||||
vw_printw \
|
||||
wchgat \
|
||||
winsdelln \
|
||||
winsstr \
|
||||
wresize \
|
||||
wsyncdown \
|
||||
@ -453,7 +462,7 @@ do
|
||||
\$(srcdir)/test.priv.h \\
|
||||
ncurses_cfg.h
|
||||
$SHOW_CC
|
||||
$ECHO_CC\$(CC) -c \$(CFLAGS_DEFAULT) \$(srcdir)/$N.c
|
||||
$ECHO_CC\$(CC) -c \$(CFLAGS_DEFAULT) -DMODULE_NAME="$N" \$(srcdir)/$N.c
|
||||
TEST_EOF
|
||||
done
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: demo_new_pair.c,v 1.15 2017/06/26 00:20:23 tom Exp $
|
||||
* $Id: demo_new_pair.c,v 1.16 2017/09/04 11:47:44 tom Exp $
|
||||
*
|
||||
* Demonstrate the alloc_pair() function.
|
||||
*/
|
||||
@ -334,7 +334,7 @@ main(int argc, char *argv[])
|
||||
total_cells += 1 + (use_wide ? 1 : 0);
|
||||
++current;
|
||||
}
|
||||
endwin();
|
||||
exit_curses();
|
||||
fclose(output);
|
||||
|
||||
printf("%.1f cells/second\n",
|
||||
|
@ -29,7 +29,7 @@
|
||||
/*
|
||||
* Author: Thomas E. Dickey
|
||||
*
|
||||
* $Id: demo_termcap.c,v 1.54 2017/04/13 09:12:40 tom Exp $
|
||||
* $Id: demo_termcap.c,v 1.55 2017/09/04 13:28:44 tom Exp $
|
||||
*
|
||||
* A simple demo of the termcap interface.
|
||||
*/
|
||||
@ -74,8 +74,10 @@ static bool b_opt = FALSE;
|
||||
static bool n_opt = FALSE;
|
||||
static bool s_opt = FALSE;
|
||||
static bool q_opt = FALSE;
|
||||
#ifdef NCURSES_VERSION
|
||||
static bool x_opt = FALSE;
|
||||
static bool y_opt = FALSE;
|
||||
#endif
|
||||
|
||||
static char *d_opt;
|
||||
static char *e_opt;
|
||||
@ -768,7 +770,9 @@ main(int argc, char *argv[])
|
||||
int n;
|
||||
char *name;
|
||||
bool a_opt = FALSE;
|
||||
#if defined(NCURSES_VERSION) || defined(HAVE_CURSES_DATA_OSPEED)
|
||||
bool v_opt = FALSE;
|
||||
#endif
|
||||
char *input_name = 0;
|
||||
|
||||
int repeat;
|
||||
@ -804,9 +808,12 @@ main(int argc, char *argv[])
|
||||
case 's':
|
||||
s_opt = TRUE;
|
||||
break;
|
||||
#if defined(NCURSES_VERSION) || defined(HAVE_CURSES_DATA_OSPEED)
|
||||
case 'v':
|
||||
v_opt = TRUE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef NCURSES_VERSION
|
||||
#if NCURSES_XNAMES
|
||||
case 'x':
|
||||
x_opt = TRUE;
|
||||
@ -815,6 +822,7 @@ main(int argc, char *argv[])
|
||||
y_opt = TRUE;
|
||||
x_opt = TRUE;
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
|
14
test/ditto.c
14
test/ditto.c
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2012,2016 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-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 *
|
||||
@ -29,7 +29,7 @@
|
||||
/*
|
||||
* Author: Thomas E. Dickey (1998-on)
|
||||
*
|
||||
* $Id: ditto.c,v 1.44 2016/09/04 20:43:04 tom Exp $
|
||||
* $Id: ditto.c,v 1.46 2017/09/06 09:19:14 tom Exp $
|
||||
*
|
||||
* The program illustrates how to set up multiple screens from a single
|
||||
* program.
|
||||
@ -44,6 +44,8 @@
|
||||
#include <test.priv.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if HAVE_DELSCREEN
|
||||
|
||||
#ifdef USE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@ -450,3 +452,11 @@ main(int argc, char *argv[])
|
||||
}
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("This program requires the curses delscreen function\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: echochar.c,v 1.13 2017/04/15 13:38:37 tom Exp $
|
||||
* $Id: echochar.c,v 1.14 2017/09/04 11:48:15 tom Exp $
|
||||
*
|
||||
* Demonstrate the echochar function (compare to dots.c).
|
||||
* Thomas Dickey - 2006/11/4
|
||||
@ -45,7 +45,7 @@ static time_t started;
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
endwin();
|
||||
exit_curses();
|
||||
|
||||
printf("\n\n%ld total chars, rate %.2f/sec\n",
|
||||
total_chars,
|
||||
|
@ -29,7 +29,7 @@
|
||||
/*
|
||||
* Author: Thomas E. Dickey 1998
|
||||
*
|
||||
* $Id: filter.c,v 1.29 2017/06/17 18:16:39 tom Exp $
|
||||
* $Id: filter.c,v 1.30 2017/09/08 22:34:05 tom Exp $
|
||||
*
|
||||
* An example of the 'filter()' function in ncurses, this program prompts
|
||||
* for commands and executes them (like a command shell). It illustrates
|
||||
@ -308,6 +308,9 @@ usage(void)
|
||||
," -a suppress xterm alternate-screen by amending smcup/rmcup"
|
||||
#endif
|
||||
," -c show current time on prompt line with \"Command\""
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
," -i use initscr() rather than newterm()"
|
||||
," -p poll for individual characters rather than using getnstr"
|
||||
};
|
||||
@ -327,12 +330,15 @@ main(int argc, char *argv[])
|
||||
bool a_option = FALSE;
|
||||
#endif
|
||||
bool c_option = FALSE;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
bool i_option = FALSE;
|
||||
bool p_option = FALSE;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "acip")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "adcip")) != -1) {
|
||||
switch (ch) {
|
||||
#ifdef NCURSES_VERSION
|
||||
case 'a':
|
||||
@ -342,6 +348,11 @@ main(int argc, char *argv[])
|
||||
case 'c':
|
||||
c_option = TRUE;
|
||||
break;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case 'i':
|
||||
i_option = TRUE;
|
||||
break;
|
||||
@ -376,7 +387,7 @@ main(int argc, char *argv[])
|
||||
int background = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() != ERR)
|
||||
if (d_option && (use_default_colors() != ERR))
|
||||
background = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_CYAN, (short) background);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-2014,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 *
|
||||
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: firework.c,v 1.30 2014/08/02 17:24:07 tom Exp $
|
||||
* $Id: firework.c,v 1.34 2017/09/09 00:35:56 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
@ -37,8 +37,7 @@ static short my_bg = COLOR_BLACK;
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -137,13 +136,52 @@ explode(int row, int col)
|
||||
showit();
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
int start, end, row, diff, flag = 0, direction;
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: firework [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors, repeat to use in init_pair"
|
||||
#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[])
|
||||
{
|
||||
int ch;
|
||||
int start, end;
|
||||
int row, diff;
|
||||
int flag = 0;
|
||||
int direction;
|
||||
unsigned seed;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
|
||||
while ((ch = getopt(argc, argv, "d")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
CATCHALL(onsig);
|
||||
|
||||
@ -156,7 +194,7 @@ main(
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
my_bg = -1;
|
||||
#endif
|
||||
}
|
||||
@ -174,7 +212,7 @@ main(
|
||||
diff = abs(start - end);
|
||||
} while (diff < 2 || diff >= LINES - 2);
|
||||
(void) attrset(AttrArg(0, A_NORMAL));
|
||||
for (row = 0; row < diff; row++) {
|
||||
for (row = 1; row < diff; row++) {
|
||||
MvPrintw(LINES - row, start + (row * direction),
|
||||
(direction < 0) ? "\\" : "/");
|
||||
if (flag++) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-2010,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,7 +29,7 @@
|
||||
* This test was written by Alexander V. Lukyanov to demonstrate difference
|
||||
* between ncurses 4.1 and SVR4 curses
|
||||
*
|
||||
* $Id: firstlast.c,v 1.7 2010/05/01 19:11:55 tom Exp $
|
||||
* $Id: firstlast.c,v 1.8 2017/09/06 01:07:39 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -40,6 +40,11 @@ fill(WINDOW *w, const char *str)
|
||||
const char *s;
|
||||
int x0 = -1, y0 = -1;
|
||||
int x1, y1;
|
||||
int maxx, maxy, limit;
|
||||
|
||||
getmaxyx(w, maxy, maxx);
|
||||
wmove(w, 0, 0);
|
||||
limit = maxy * maxx;
|
||||
|
||||
for (;;) {
|
||||
for (s = str; *s; s++) {
|
||||
@ -49,6 +54,16 @@ fill(WINDOW *w, const char *str)
|
||||
wmove(w, 0, 0);
|
||||
return;
|
||||
}
|
||||
/* waddch() should return ERR at the lower-right corner */
|
||||
if (--limit < 0) {
|
||||
beep();
|
||||
if (*str == '?')
|
||||
return;
|
||||
napms(500);
|
||||
wmove(w, maxy - 1, 0);
|
||||
str = "?";
|
||||
limit = maxx + 1;
|
||||
}
|
||||
x0 = x1;
|
||||
y0 = y1;
|
||||
}
|
||||
|
21
test/gdc.6
21
test/gdc.6
@ -1,5 +1,5 @@
|
||||
.\"***************************************************************************
|
||||
.\" Copyright (c) 1998-2003,2006 Free Software Foundation, Inc. *
|
||||
.\" Copyright (c) 1998-2006,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 *
|
||||
@ -26,16 +26,12 @@
|
||||
.\" authorization. *
|
||||
.\"***************************************************************************
|
||||
.\"
|
||||
.\" $Id: gdc.6,v 1.3 2006/04/22 23:02:15 tom Exp $
|
||||
.\" $Id: gdc.6,v 1.4 2017/09/09 20:04:09 tom Exp $
|
||||
.TH GDC 6
|
||||
.SH NAME
|
||||
gdc \- grand digital clock (curses)
|
||||
.SH SYNOPSIS
|
||||
.B gdc
|
||||
[-n] [
|
||||
[-s] [
|
||||
.I n
|
||||
]
|
||||
.B gdc \fP[\fIoptions\fP] [\fIn\fP]
|
||||
.SH DESCRIPTION
|
||||
.I Gdc
|
||||
runs a digital clock made of reverse-video blanks on a terminal screen.
|
||||
@ -44,14 +40,20 @@ You can make the clock stop, pause or resume by pressing a ``q'',
|
||||
``s'' or space, respectively.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -n
|
||||
.B \-d
|
||||
use terminal's default colors for the background.
|
||||
.TP
|
||||
.B \-n
|
||||
redirects input to /dev/null, making it ignore the stop/pause commands.
|
||||
You can still stop it by pressing the interrupt key.
|
||||
.TP
|
||||
.B -s
|
||||
.B \-s
|
||||
makes digits scroll as they change.
|
||||
When running on a fast display, the program breaks up the scrolling into
|
||||
subsecond repaints, making the operation appear smooth.
|
||||
.TP
|
||||
.B \-t \fIhh:mm:ss\fP
|
||||
specify starting time (default is ``now'').
|
||||
.PP
|
||||
With an optional numeric argument
|
||||
.I num
|
||||
@ -61,4 +63,5 @@ seconds.
|
||||
Normally it runs "forever" (counting down from 2 billion seconds).
|
||||
.SH AUTHOR
|
||||
Amos Shapir, modified for curses by John Lupien.
|
||||
.br
|
||||
Improvements for ncurses by Thomas Dickey.
|
||||
|
29
test/gdc.c
29
test/gdc.c
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-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 *
|
||||
@ -33,7 +33,7 @@
|
||||
* modified 10-18-89 for curses (jrl)
|
||||
* 10-18-89 added signal handling
|
||||
*
|
||||
* $Id: gdc.c,v 1.45 2016/09/10 21:47:55 tom Exp $
|
||||
* $Id: gdc.c,v 1.50 2017/09/09 20:23:09 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -66,7 +66,7 @@ sighndl(int signo)
|
||||
signal(signo, sighndl);
|
||||
sigtermed = signo;
|
||||
if (redirected) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ check_term(void)
|
||||
{
|
||||
if (sigtermed) {
|
||||
(void) standend();
|
||||
endwin();
|
||||
exit_curses();
|
||||
fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
@ -156,8 +156,11 @@ usage(void)
|
||||
"Usage: gdc [options] [count]"
|
||||
,""
|
||||
,"Options:"
|
||||
," -n redirect input to /dev/null"
|
||||
," -s scroll each number into place, rather than flipping"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
," -n redirect input to /dev/null"
|
||||
," -s scroll each number into place, rather than flipping"
|
||||
," -t hh:mm:ss specify starting time (default is ``now'')"
|
||||
,""
|
||||
,"If you specify a count, gdc runs for that number of seconds"
|
||||
@ -218,13 +221,21 @@ main(int argc, char *argv[])
|
||||
bool smooth = FALSE;
|
||||
bool stages = FALSE;
|
||||
time_t starts = 0;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
CATCHALL(sighndl);
|
||||
|
||||
while ((k = getopt(argc, argv, "nst:")) != -1) {
|
||||
while ((k = getopt(argc, argv, "dnst:")) != -1) {
|
||||
switch (k) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case 'n':
|
||||
ifp = fopen("/dev/null", "r");
|
||||
redirected = TRUE;
|
||||
@ -268,7 +279,7 @@ main(int argc, char *argv[])
|
||||
short bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
bg = -1;
|
||||
#endif
|
||||
init_pair(PAIR_DIGITS, COLOR_BLACK, COLOR_RED);
|
||||
@ -435,6 +446,6 @@ main(int argc, char *argv[])
|
||||
}
|
||||
} while (--count);
|
||||
(void) standend();
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
230
test/hanoi.c
230
test/hanoi.c
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-2014,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 *
|
||||
@ -41,7 +41,7 @@
|
||||
*
|
||||
* Date: 05.Nov.90
|
||||
*
|
||||
* $Id: hanoi.c,v 1.36 2014/08/02 17:24:07 tom Exp $
|
||||
* $Id: hanoi.c,v 1.39 2017/09/09 00:19:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -89,104 +89,6 @@ static int NTiles = 0;
|
||||
static int NMoves = 0;
|
||||
static bool AutoFlag = FALSE;
|
||||
|
||||
static void InitTiles(void);
|
||||
static void DisplayTiles(void);
|
||||
static void MakeMove(int From, int To);
|
||||
static void AutoMove(int From, int To, int Num);
|
||||
static void Usage(void);
|
||||
static int Solved(int NumTiles);
|
||||
static int GetMove(int *From, int *To);
|
||||
static int InvalidMove(int From, int To);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int FromCol, ToCol;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
NTiles = DEFAULTTILES;
|
||||
break;
|
||||
case 2:
|
||||
NTiles = atoi(argv[1]);
|
||||
if (NTiles > MAXTILES || NTiles < MINTILES) {
|
||||
fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (strcmp(argv[2], "a")) {
|
||||
Usage();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
NTiles = atoi(argv[1]);
|
||||
if (NTiles > MAXTILES || NTiles < MINTILES) {
|
||||
fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
AutoFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
initscr();
|
||||
if (has_colors()) {
|
||||
int i;
|
||||
short bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
bg = -1;
|
||||
#endif
|
||||
for (i = 0; i < 9; i++)
|
||||
init_pair((short) (i + 1), bg, TileColour[i]);
|
||||
}
|
||||
cbreak();
|
||||
if (LINES < 24) {
|
||||
endwin();
|
||||
fprintf(stderr, "Min screen length 24 lines\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
if (AutoFlag) {
|
||||
curs_set(0);
|
||||
leaveok(stdscr, TRUE); /* Attempt to remove cursor */
|
||||
}
|
||||
InitTiles();
|
||||
DisplayTiles();
|
||||
if (AutoFlag) {
|
||||
do {
|
||||
noecho();
|
||||
AutoMove(0, 2, NTiles);
|
||||
} while (!Solved(NTiles));
|
||||
sleep(2);
|
||||
} else {
|
||||
echo();
|
||||
for (;;) {
|
||||
if (GetMove(&FromCol, &ToCol))
|
||||
break;
|
||||
if (InvalidMove(FromCol, ToCol)) {
|
||||
MvAddStr(STATUSLINE, 0, "Invalid Move !!");
|
||||
refresh();
|
||||
beep();
|
||||
continue;
|
||||
}
|
||||
MakeMove(FromCol, ToCol);
|
||||
if (Solved(NTiles)) {
|
||||
MvPrintw(STATUSLINE, 0,
|
||||
"Well Done !! You did it in %d moves", NMoves);
|
||||
refresh();
|
||||
sleep(5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
InvalidMove(int From, int To)
|
||||
{
|
||||
@ -329,9 +231,129 @@ Solved(int NumTiles)
|
||||
}
|
||||
|
||||
static void
|
||||
Usage(void)
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: hanoi [<No Of Tiles>] [a]\n");
|
||||
fprintf(stderr,
|
||||
"The 'a' option causes the tower to be solved automatically\n");
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: hanoi [options] [[<No Of Tiles>] [a]]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
," -n NUM set number of tiles (positional param is deprecated)"
|
||||
," -X solve automatically (positional \"a\" is deprecated)"
|
||||
};
|
||||
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)
|
||||
{
|
||||
int ch, FromCol, ToCol;
|
||||
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
|
||||
NTiles = DEFAULTTILES;
|
||||
while ((ch = getopt(argc, argv, "dn:X")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case 'n':
|
||||
NTiles = atoi(optarg);
|
||||
break;
|
||||
case 'X':
|
||||
AutoFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
switch (ch = (argc - optind)) {
|
||||
case 2:
|
||||
if (strcmp(argv[optind + 1], "a")) {
|
||||
usage();
|
||||
}
|
||||
AutoFlag = TRUE;
|
||||
/* FALLTHRU */
|
||||
case 1:
|
||||
NTiles = atoi(argv[optind]);
|
||||
/* FALLTHRU */
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if (NTiles > MAXTILES || NTiles < MINTILES) {
|
||||
fprintf(stderr, "Range %d to %d\n", MINTILES, MAXTILES);
|
||||
usage();
|
||||
}
|
||||
|
||||
initscr();
|
||||
if (has_colors()) {
|
||||
int i;
|
||||
short bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
bg = -1;
|
||||
#endif
|
||||
for (i = 0; i < 9; i++)
|
||||
init_pair((short) (i + 1), bg, TileColour[i]);
|
||||
}
|
||||
cbreak();
|
||||
if (LINES < 24) {
|
||||
endwin();
|
||||
fprintf(stderr, "Min screen length 24 lines\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
if (AutoFlag) {
|
||||
curs_set(0);
|
||||
leaveok(stdscr, TRUE); /* Attempt to remove cursor */
|
||||
}
|
||||
InitTiles();
|
||||
DisplayTiles();
|
||||
if (AutoFlag) {
|
||||
do {
|
||||
noecho();
|
||||
AutoMove(0, 2, NTiles);
|
||||
} while (!Solved(NTiles));
|
||||
sleep(2);
|
||||
} else {
|
||||
echo();
|
||||
for (;;) {
|
||||
if (GetMove(&FromCol, &ToCol))
|
||||
break;
|
||||
if (InvalidMove(FromCol, ToCol)) {
|
||||
MvAddStr(STATUSLINE, 0, "Invalid Move !!");
|
||||
refresh();
|
||||
beep();
|
||||
continue;
|
||||
}
|
||||
MakeMove(FromCol, ToCol);
|
||||
if (Solved(NTiles)) {
|
||||
MvPrintw(STATUSLINE, 0,
|
||||
"Well Done !! You did it in %d moves", NMoves);
|
||||
refresh();
|
||||
sleep(5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: inchs.c,v 1.14 2017/04/29 22:03:26 tom Exp $
|
||||
* $Id: inchs.c,v 1.16 2017/09/06 09:20:42 tom Exp $
|
||||
*
|
||||
* Author: Thomas E Dickey
|
||||
*/
|
||||
|
@ -26,12 +26,15 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: insdelln.c,v 1.10 2017/04/15 17:40:11 tom Exp $
|
||||
* $Id: insdelln.c,v 1.12 2017/09/07 08:24:24 tom Exp $
|
||||
*
|
||||
* test-driver for deleteln, wdeleteln, insdelln, winsdelln, insertln, winsertln
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#if HAVE_WINSDELLN
|
||||
|
||||
#include <popup_msg.h>
|
||||
|
||||
#define SHOW(n) ((n) == ERR ? "ERR" : "OK")
|
||||
@ -379,3 +382,12 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#else
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("This program requires the curses winsdelln function\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
464
test/knight.c
464
test/knight.c
@ -33,25 +33,26 @@
|
||||
* Eric S. Raymond <esr@snark.thyrsus.com> July 22 1995. Mouse support
|
||||
* added September 20th 1995.
|
||||
*
|
||||
* $Id: knight.c,v 1.38 2017/08/20 16:15:42 tom Exp $
|
||||
* $Id: knight.c,v 1.43 2017/09/10 00:13:02 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
/* board size */
|
||||
#define BDEPTH 8
|
||||
#define BWIDTH 8
|
||||
#define YLIMIT 8
|
||||
#define XLIMIT 8
|
||||
#define MAXMOVES (ylimit * xlimit)
|
||||
|
||||
/* where to start the instructions */
|
||||
#define INSTRY 2
|
||||
#define INSTRX 35
|
||||
#define INSTRY 2
|
||||
#define INSTRX 35
|
||||
|
||||
/* corner of board */
|
||||
#define BOARDY 2
|
||||
#define BOARDX 0
|
||||
#define BOARDY 2
|
||||
#define BOARDX 0
|
||||
|
||||
/* notification line */
|
||||
#define NOTIFYY 21
|
||||
#define NOTIFYY 21
|
||||
|
||||
/* virtual color values */
|
||||
#define TRAIL_COLOR 1
|
||||
@ -65,20 +66,28 @@
|
||||
#define CYINV(y) (((y) - 2) / 2)
|
||||
|
||||
typedef struct {
|
||||
short x, y;
|
||||
} cell;
|
||||
int x, y;
|
||||
} HISTORY;
|
||||
|
||||
typedef int SQUARES[YLIMIT][XLIMIT];
|
||||
|
||||
static WINDOW *boardwin; /* the board window */
|
||||
static WINDOW *helpwin; /* the help window */
|
||||
static WINDOW *msgwin; /* the message window */
|
||||
static cell history[BDEPTH * BWIDTH + 1]; /* choice history */
|
||||
|
||||
static bool d_option;
|
||||
|
||||
static chtype minus = '-'; /* possible-move character */
|
||||
static chtype oldch;
|
||||
static chtype plus = '+'; /* cursor hot-spot character */
|
||||
static chtype trail = '#'; /* trail character */
|
||||
static int movecount; /* count of moves so far */
|
||||
static int trialcount; /* count of trials so far */
|
||||
static short board[BDEPTH][BWIDTH]; /* the squares */
|
||||
|
||||
static int ylimit = YLIMIT;
|
||||
static int xlimit = XLIMIT;
|
||||
static int maxmoves = (YLIMIT * XLIMIT);
|
||||
|
||||
static int count_tries; /* count of trials so far */
|
||||
static int test_test; /* FIXME */
|
||||
/* *INDENT-OFF* */
|
||||
static const struct {
|
||||
int y;
|
||||
@ -93,6 +102,7 @@ static const struct {
|
||||
{ 1, -2 },
|
||||
{ 2, -1 },
|
||||
};
|
||||
#define MAX_OFFSET (unsigned)SIZEOF(offsets)
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
@ -104,9 +114,12 @@ init_program(void)
|
||||
initscr();
|
||||
cbreak(); /* immediate char return */
|
||||
noecho(); /* no immediate echo */
|
||||
boardwin = newwin(BDEPTH * 2 + 1, BWIDTH * 4 + 1, BOARDY, BOARDX);
|
||||
|
||||
maxmoves = MAXMOVES;
|
||||
boardwin = newwin(ylimit * 2 + 1, xlimit * 4 + 1, BOARDY, BOARDX);
|
||||
helpwin = newwin(0, 0, INSTRY, INSTRX);
|
||||
msgwin = newwin(1, INSTRX - 1, NOTIFYY, 0);
|
||||
|
||||
scrollok(msgwin, TRUE);
|
||||
keypad(boardwin, TRUE);
|
||||
|
||||
@ -115,7 +128,7 @@ init_program(void)
|
||||
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
bg = -1;
|
||||
#endif
|
||||
|
||||
@ -178,7 +191,11 @@ help2(void)
|
||||
(void) waddstr(helpwin, "r -- redraw screen \\|/ \\|/ \n");
|
||||
(void) waddstr(helpwin, "bksp -- undo move h-+-l 4-+-6\n");
|
||||
(void) waddstr(helpwin, "a -- autojump /|\\ /|\\ \n");
|
||||
(void) waddstr(helpwin, " b j n 1 2 3\n");
|
||||
if (ylimit <= 6) {
|
||||
(void) waddstr(helpwin, "R -- solve (slow) b j n 1 2 3\n");
|
||||
} else {
|
||||
(void) waddstr(helpwin, " b j n 1 2 3\n");
|
||||
}
|
||||
|
||||
(void) waddstr(helpwin, "\nYou can place your knight on the selected\n");
|
||||
(void) waddstr(helpwin, "square with spacebar, Enter, or the keypad\n");
|
||||
@ -202,30 +219,33 @@ show_help(bool * keyhelp)
|
||||
wrefresh(helpwin);
|
||||
}
|
||||
|
||||
static bool
|
||||
chksqr(int r1, int c1)
|
||||
static inline bool
|
||||
isValidYX(int y, int x)
|
||||
{
|
||||
if ((r1 < 0) || (r1 > BDEPTH - 1))
|
||||
return (FALSE);
|
||||
if ((c1 < 0) || (c1 > BWIDTH - 1))
|
||||
return (FALSE);
|
||||
return ((!board[r1][c1]) ? TRUE : FALSE);
|
||||
return (y >= 0 && y < ylimit && x >= 0 && x < xlimit) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
isUnusedYX(SQUARES squares, int y, int x)
|
||||
{
|
||||
return (isValidYX(y, x) && (!squares[y][x]) ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
static bool
|
||||
chkmoves(int rw, int col)
|
||||
/* check to see if valid moves are available */
|
||||
boardIsFilled(SQUARES squares, int y, int x)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
for (n = 0; n < SIZEOF(offsets); n++)
|
||||
if (chksqr(rw + offsets[n].y, col + offsets[n].x))
|
||||
return (TRUE);
|
||||
return (FALSE);
|
||||
for (n = 0; n < MAX_OFFSET; n++) {
|
||||
if (isUnusedYX(squares, y + offsets[n].y, x + offsets[n].x)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
dosquares(void)
|
||||
drawBoard(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
@ -233,7 +253,7 @@ dosquares(void)
|
||||
|
||||
move(BOARDY, BOARDX);
|
||||
waddch(boardwin, ACS_ULCORNER);
|
||||
for (j = 0; j < 7; j++) {
|
||||
for (j = 0; j < (ylimit - 1); j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
@ -244,10 +264,10 @@ dosquares(void)
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_URCORNER);
|
||||
|
||||
for (i = 1; i < BDEPTH; i++) {
|
||||
for (i = 1; i < ylimit; i++) {
|
||||
move(BOARDY + i * 2 - 1, BOARDX);
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
for (j = 0; j < xlimit; j++) {
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
@ -255,7 +275,7 @@ dosquares(void)
|
||||
}
|
||||
move(BOARDY + i * 2, BOARDX);
|
||||
waddch(boardwin, ACS_LTEE);
|
||||
for (j = 0; j < BWIDTH - 1; j++) {
|
||||
for (j = 0; j < xlimit - 1; j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
@ -269,7 +289,7 @@ dosquares(void)
|
||||
|
||||
move(BOARDY + i * 2 - 1, BOARDX);
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
for (j = 0; j < xlimit; j++) {
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
@ -278,7 +298,7 @@ dosquares(void)
|
||||
|
||||
move(BOARDY + i * 2, BOARDX);
|
||||
waddch(boardwin, ACS_LLCORNER);
|
||||
for (j = 0; j < BWIDTH - 1; j++) {
|
||||
for (j = 0; j < xlimit - 1; j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
@ -291,20 +311,20 @@ dosquares(void)
|
||||
}
|
||||
|
||||
static void
|
||||
mark_possibles(int prow, int pcol, chtype mark)
|
||||
mark_possibles(SQUARES squares, int y, int x, chtype mark)
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
for (n = 0; n < SIZEOF(offsets); n++) {
|
||||
if (chksqr(prow + offsets[n].y, pcol + offsets[n].x)) {
|
||||
cellmove(prow + offsets[n].y, pcol + offsets[n].x);
|
||||
for (n = 0; n < MAX_OFFSET; n++) {
|
||||
if (isUnusedYX(squares, y + offsets[n].y, x + offsets[n].x)) {
|
||||
cellmove(y + offsets[n].y, x + offsets[n].x);
|
||||
waddch(boardwin, mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
find_next_move(int *y, int *x)
|
||||
find_next_move(SQUARES squares, HISTORY * doneData, int doneSize, int *y, int *x)
|
||||
{
|
||||
unsigned j, k;
|
||||
int found = -1;
|
||||
@ -314,14 +334,14 @@ find_next_move(int *y, int *x)
|
||||
int newy, newx;
|
||||
bool result = FALSE;
|
||||
|
||||
if (movecount > 1) {
|
||||
oldy = history[movecount - 1].y;
|
||||
oldx = history[movecount - 1].x;
|
||||
for (j = 0; j < SIZEOF(offsets) * 2; j++) {
|
||||
k = j % SIZEOF(offsets);
|
||||
if (doneSize > 1) {
|
||||
oldy = doneData[doneSize - 1].y;
|
||||
oldx = doneData[doneSize - 1].x;
|
||||
for (j = 0; j < MAX_OFFSET * 2; j++) {
|
||||
k = j % MAX_OFFSET;
|
||||
newy = oldy + offsets[k].y;
|
||||
newx = oldx + offsets[k].x;
|
||||
if (chksqr(newy, newx)) {
|
||||
if (isUnusedYX(squares, newy, newx)) {
|
||||
if (first < 0)
|
||||
first = (int) k;
|
||||
if (newy == *y
|
||||
@ -345,16 +365,16 @@ find_next_move(int *y, int *x)
|
||||
}
|
||||
|
||||
static void
|
||||
count_next_moves(int y, int x)
|
||||
count_next_moves(SQUARES squares, int count_moves, int y, int x)
|
||||
{
|
||||
int count = 0;
|
||||
unsigned j;
|
||||
|
||||
wprintw(msgwin, "\nMove %d", movecount);
|
||||
for (j = 0; j < SIZEOF(offsets); j++) {
|
||||
wprintw(msgwin, "\nMove %d", count_moves);
|
||||
for (j = 0; j < MAX_OFFSET; j++) {
|
||||
int newy = y + offsets[j].y;
|
||||
int newx = x + offsets[j].x;
|
||||
if (chksqr(newy, newx)) {
|
||||
if (isUnusedYX(squares, newy, newx)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
@ -383,37 +403,38 @@ markcell(chtype tchar, int row, int column)
|
||||
}
|
||||
|
||||
static void
|
||||
drawmove(chtype tchar, int oldy, int oldx, int row, int column)
|
||||
drawMove(SQUARES squares, int count_moves, chtype tchar, int oldy, int oldx, int
|
||||
row, int column)
|
||||
/* place the stars, update board & currents */
|
||||
{
|
||||
if (movecount <= 1) {
|
||||
if (count_moves <= 1) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < BDEPTH; i++) {
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
if (movecount == 0) {
|
||||
for (i = 0; i < ylimit; i++) {
|
||||
for (j = 0; j < xlimit; j++) {
|
||||
if (count_moves == 0) {
|
||||
unmarkcell(i, j);
|
||||
} else {
|
||||
cellmove(i, j);
|
||||
if (winch(boardwin) == minus)
|
||||
waddch(boardwin, movecount ? ' ' : minus);
|
||||
waddch(boardwin, count_moves ? ' ' : minus);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
markcell(tchar, oldy, oldx);
|
||||
mark_possibles(oldy, oldx, ' ');
|
||||
mark_possibles(squares, oldy, oldx, ' ');
|
||||
}
|
||||
|
||||
if (row >= 0 && column >= 0) {
|
||||
markcell(trail, row, column);
|
||||
mark_possibles(row, column, minus);
|
||||
board[row][column] = TRUE;
|
||||
mark_possibles(squares, row, column, minus);
|
||||
squares[row][column] = TRUE;
|
||||
}
|
||||
|
||||
wprintw(msgwin, "\nMove %d", movecount);
|
||||
if (trialcount != movecount)
|
||||
wprintw(msgwin, " (%d tries)", trialcount);
|
||||
wprintw(msgwin, "\nMove %d", count_moves);
|
||||
if (count_tries != count_moves)
|
||||
wprintw(msgwin, " (%d tries)", count_tries);
|
||||
wclrtoeol(msgwin);
|
||||
}
|
||||
|
||||
@ -427,17 +448,16 @@ iabs(int num)
|
||||
}
|
||||
|
||||
static bool
|
||||
evalmove(int row, int column)
|
||||
/* evaluate move */
|
||||
evaluate_move(SQUARES squares, HISTORY * doneData, int doneSize, int row, int column)
|
||||
{
|
||||
if (movecount == 1)
|
||||
if (doneSize <= 1)
|
||||
return (TRUE);
|
||||
else if (board[row][column] == TRUE) {
|
||||
else if (squares[row][column] == TRUE) {
|
||||
waddstr(msgwin, "\nYou've already been there.");
|
||||
return (FALSE);
|
||||
} else {
|
||||
int rdif = iabs(row - history[movecount - 1].y);
|
||||
int cdif = iabs(column - history[movecount - 1].x);
|
||||
int rdif = iabs(row - doneData[doneSize - 1].y);
|
||||
int cdif = iabs(column - doneData[doneSize - 1].x);
|
||||
|
||||
if (!((rdif == 1) && (cdif == 2)) && !((rdif == 2) && (cdif == 1))) {
|
||||
waddstr(msgwin, "\nThat's not a legal knight's move.");
|
||||
@ -449,15 +469,18 @@ evalmove(int row, int column)
|
||||
}
|
||||
|
||||
static int
|
||||
completed(void)
|
||||
completed(SQUARES squares)
|
||||
{
|
||||
int i, j, count = 0;
|
||||
|
||||
for (i = 0; i < BDEPTH; i++)
|
||||
for (j = 0; j < BWIDTH; j++)
|
||||
if (board[i][j] != 0)
|
||||
for (i = 0; i < ylimit; i++) {
|
||||
for (j = 0; j < xlimit; j++) {
|
||||
if (squares[i][j] != 0) {
|
||||
count += 1;
|
||||
return (count == (BWIDTH * BDEPTH) ? -1 : count);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ((count == maxmoves) ? -1 : count);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -467,6 +490,104 @@ no_previous_move(void)
|
||||
beep();
|
||||
}
|
||||
|
||||
/* Recursively try all possible moves, starting from (y,x) */
|
||||
static int
|
||||
recurBack(SQUARES squares, int y, int x, int total)
|
||||
{
|
||||
int longest = total;
|
||||
int best_x = x;
|
||||
int best_y = y;
|
||||
int result;
|
||||
|
||||
if (total < maxmoves) {
|
||||
int try_x, try_y;
|
||||
unsigned k;
|
||||
|
||||
for (k = 0; k < MAX_OFFSET; k++) {
|
||||
try_x = x + offsets[k].x;
|
||||
try_y = y + offsets[k].y;
|
||||
if (isUnusedYX(squares, try_y, try_x)) {
|
||||
++test_test;
|
||||
squares[try_y][try_x] = total + 1;
|
||||
result = recurBack(squares, try_y, try_x, total + 1);
|
||||
if (result > longest) {
|
||||
longest = result;
|
||||
best_x = try_x;
|
||||
best_y = try_y;
|
||||
}
|
||||
if (result >= maxmoves)
|
||||
break;
|
||||
squares[try_y][try_x] = 0; /* allow retry... */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = total;
|
||||
if (longest > total) {
|
||||
result = longest;
|
||||
squares[best_y][best_x] = total + 1;
|
||||
(void) recurBack(squares, best_y, best_x, total + 1);
|
||||
if (result < maxmoves)
|
||||
squares[best_y][best_x] = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Solve the Knight Tour problem using backtracking, returning the length of
|
||||
* the resulting solution. If this is invoked from a point where the remaining
|
||||
* choices cannot complete the tour, the result will fall short.
|
||||
*/
|
||||
static int
|
||||
useBacktracking(SQUARES result, HISTORY * doneData, int doneSize)
|
||||
{
|
||||
int y = 0, x = 0, n;
|
||||
SQUARES squares;
|
||||
int total;
|
||||
int actual = doneSize - 1;
|
||||
|
||||
memset(squares, 0, sizeof(squares));
|
||||
for (n = 1; n <= actual; ++n) {
|
||||
y = doneData[n].y;
|
||||
x = doneData[n].x;
|
||||
squares[y][x] = n;
|
||||
}
|
||||
|
||||
total = recurBack(squares, y, x, actual);
|
||||
if (total > actual) {
|
||||
for (y = 0; y < ylimit; ++y) {
|
||||
for (x = 0; x < xlimit; ++x) {
|
||||
result[y][x] = squares[y][x];
|
||||
if ((n = squares[y][x]) != 0) {
|
||||
doneData[n].y = y;
|
||||
doneData[n].x = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static int
|
||||
reviewHistory(HISTORY * history, int count_moves, int review, int *ny, int *nx)
|
||||
{
|
||||
if (review < 0) {
|
||||
beep();
|
||||
review = 0;
|
||||
} else if (review > count_moves - 2) {
|
||||
beep();
|
||||
review = count_moves - 2;
|
||||
} else {
|
||||
*ny = history[count_moves - review - 1].y;
|
||||
*nx = history[count_moves - review - 1].x;
|
||||
wprintw(msgwin, "\nReview %d:%d.", count_moves - review - 1,
|
||||
count_moves - 1);
|
||||
wrefresh(msgwin);
|
||||
}
|
||||
return review;
|
||||
}
|
||||
|
||||
static void
|
||||
play(void)
|
||||
/* play the game */
|
||||
@ -477,14 +598,19 @@ play(void)
|
||||
int lastrow = 0;
|
||||
int ny = 0, nx = 0;
|
||||
int review = 0; /* review history */
|
||||
int test_size;
|
||||
int rw = 0, col = 0; /* current row and column */
|
||||
|
||||
do {
|
||||
SQUARES squares;
|
||||
HISTORY history[(YLIMIT * XLIMIT) + 1];
|
||||
int count_moves = 0; /* count of moves so far */
|
||||
|
||||
/* clear screen and draw board */
|
||||
werase(boardwin);
|
||||
werase(helpwin);
|
||||
werase(msgwin);
|
||||
dosquares();
|
||||
drawBoard();
|
||||
help1();
|
||||
wnoutrefresh(stdscr);
|
||||
wnoutrefresh(helpwin);
|
||||
@ -492,10 +618,9 @@ play(void)
|
||||
wnoutrefresh(boardwin);
|
||||
doupdate();
|
||||
|
||||
movecount = 0;
|
||||
for (i = 0; i < BDEPTH; i++) {
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
board[i][j] = FALSE;
|
||||
for (i = 0; i < ylimit; i++) {
|
||||
for (j = 0; j < xlimit; j++) {
|
||||
squares[i][j] = FALSE;
|
||||
unmarkcell(i, j);
|
||||
}
|
||||
}
|
||||
@ -503,8 +628,8 @@ play(void)
|
||||
history[0].y = history[0].x = -1;
|
||||
history[1].y = history[1].x = -1;
|
||||
lastrow = lastcol = -2;
|
||||
movecount = 1;
|
||||
trialcount = 1;
|
||||
count_moves = 1;
|
||||
count_tries = 1;
|
||||
keyhelp = FALSE;
|
||||
show_help(&keyhelp);
|
||||
|
||||
@ -512,7 +637,7 @@ play(void)
|
||||
if (rw != lastrow || col != lastcol) {
|
||||
if (lastrow >= 0 && lastcol >= 0) {
|
||||
cellmove(lastrow, lastcol);
|
||||
if (board[lastrow][lastcol])
|
||||
if (squares[lastrow][lastcol])
|
||||
waddch(boardwin, trail);
|
||||
else
|
||||
waddch(boardwin, oldch);
|
||||
@ -534,7 +659,7 @@ play(void)
|
||||
case 'k':
|
||||
case '8':
|
||||
case KEY_UP:
|
||||
ny = rw + BDEPTH - 1;
|
||||
ny = rw + ylimit - 1;
|
||||
nx = col;
|
||||
break;
|
||||
case 'j':
|
||||
@ -547,7 +672,7 @@ play(void)
|
||||
case '4':
|
||||
case KEY_LEFT:
|
||||
ny = rw;
|
||||
nx = col + BWIDTH - 1;
|
||||
nx = col + xlimit - 1;
|
||||
break;
|
||||
case 'l':
|
||||
case '6':
|
||||
@ -558,19 +683,19 @@ play(void)
|
||||
case 'y':
|
||||
case '7':
|
||||
case KEY_A1:
|
||||
ny = rw + BDEPTH - 1;
|
||||
nx = col + BWIDTH - 1;
|
||||
ny = rw + ylimit - 1;
|
||||
nx = col + xlimit - 1;
|
||||
break;
|
||||
case 'b':
|
||||
case '1':
|
||||
case KEY_C1:
|
||||
ny = rw + 1;
|
||||
nx = col + BWIDTH - 1;
|
||||
nx = col + xlimit - 1;
|
||||
break;
|
||||
case 'u':
|
||||
case '9':
|
||||
case KEY_A3:
|
||||
ny = rw + BDEPTH - 1;
|
||||
ny = rw + ylimit - 1;
|
||||
nx = col + 1;
|
||||
break;
|
||||
case 'n':
|
||||
@ -587,8 +712,8 @@ play(void)
|
||||
MEVENT myevent;
|
||||
|
||||
getmouse(&myevent);
|
||||
if (myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
|
||||
&& myevent.x >= CX(0) && myevent.x <= CX(BWIDTH)) {
|
||||
if (myevent.y >= CY(0) && myevent.y <= CY(ylimit)
|
||||
&& myevent.x >= CX(0) && myevent.x <= CX(xlimit)) {
|
||||
nx = CXINV(myevent.x);
|
||||
ny = CYINV(myevent.y);
|
||||
ungetch('\n');
|
||||
@ -605,8 +730,8 @@ play(void)
|
||||
request_mouse_pos();
|
||||
test_y = MOUSE_Y_POS + 0;
|
||||
test_x = MOUSE_X_POS + 1;
|
||||
if (test_y >= CY(0) && test_y <= CY(BDEPTH)
|
||||
&& test_x >= CX(0) && test_x <= CX(BWIDTH)) {
|
||||
if (test_y >= CY(0) && test_y <= CY(ylimit)
|
||||
&& test_x >= CX(0) && test_x <= CX(xlimit)) {
|
||||
ny = CYINV(test_y);
|
||||
nx = CXINV(test_x);
|
||||
wmove(helpwin, 0, 0);
|
||||
@ -622,18 +747,20 @@ play(void)
|
||||
case '\n':
|
||||
case ' ':
|
||||
review = 0;
|
||||
if (evalmove(rw, col)) {
|
||||
drawmove(trail,
|
||||
history[movecount - 1].y,
|
||||
history[movecount - 1].x,
|
||||
if (evaluate_move(squares, history, count_moves, rw, col)) {
|
||||
drawMove(squares,
|
||||
count_moves,
|
||||
trail,
|
||||
history[count_moves - 1].y,
|
||||
history[count_moves - 1].x,
|
||||
rw, col);
|
||||
history[movecount].y = (short) rw;
|
||||
history[movecount].x = (short) col;
|
||||
movecount++;
|
||||
trialcount++;
|
||||
history[count_moves].y = (short) rw;
|
||||
history[count_moves].x = (short) col;
|
||||
count_moves++;
|
||||
count_tries++;
|
||||
|
||||
if (!chkmoves(rw, col)) {
|
||||
if (completed() < 0) {
|
||||
if (boardIsFilled(squares, rw, col)) {
|
||||
if (completed(squares) < 0) {
|
||||
waddstr(msgwin, "\nYou won.");
|
||||
} else {
|
||||
waddstr(msgwin,
|
||||
@ -649,40 +776,40 @@ play(void)
|
||||
case KEY_BACKSPACE:
|
||||
case '\b':
|
||||
review = 0;
|
||||
if (movecount <= 0) {
|
||||
if (count_moves <= 0) {
|
||||
no_previous_move();
|
||||
} else if (movecount <= 1) {
|
||||
ny = history[movecount].y;
|
||||
nx = history[movecount].x;
|
||||
} else if (count_moves <= 1) {
|
||||
ny = history[count_moves].y;
|
||||
nx = history[count_moves].x;
|
||||
if (nx < 0 || ny < 0) {
|
||||
ny = (lastrow >= 0) ? lastrow : 0;
|
||||
nx = (lastcol >= 0) ? lastcol : 0;
|
||||
}
|
||||
movecount = 0;
|
||||
board[ny][nx] = FALSE;
|
||||
count_moves = 0;
|
||||
squares[ny][nx] = FALSE;
|
||||
oldch = minus;
|
||||
drawmove(' ', ny, nx, -1, -1);
|
||||
movecount = 1;
|
||||
trialcount = 1;
|
||||
drawMove(squares, count_moves, ' ', ny, nx, -1, -1);
|
||||
count_moves = 1;
|
||||
count_tries = 1;
|
||||
no_previous_move();
|
||||
} else {
|
||||
int oldy = history[movecount - 1].y;
|
||||
int oldx = history[movecount - 1].x;
|
||||
int oldy = history[count_moves - 1].y;
|
||||
int oldx = history[count_moves - 1].x;
|
||||
|
||||
if (!board[rw][col]) {
|
||||
if (!squares[rw][col]) {
|
||||
cellmove(rw, col);
|
||||
waddch(boardwin, ' ');
|
||||
}
|
||||
|
||||
board[oldy][oldx] = FALSE;
|
||||
--movecount;
|
||||
ny = history[movecount - 1].y;
|
||||
nx = history[movecount - 1].x;
|
||||
squares[oldy][oldx] = FALSE;
|
||||
--count_moves;
|
||||
ny = history[count_moves - 1].y;
|
||||
nx = history[count_moves - 1].x;
|
||||
if (nx < 0 || ny < 0) {
|
||||
ny = oldy;
|
||||
nx = oldx;
|
||||
}
|
||||
drawmove(' ', oldy, oldx, ny, nx);
|
||||
drawMove(squares, count_moves, ' ', oldy, oldx, ny, nx);
|
||||
|
||||
/* avoid problems if we just changed the current cell */
|
||||
cellmove(lastrow, lastcol);
|
||||
@ -693,30 +820,41 @@ play(void)
|
||||
case 'a':
|
||||
nx = col;
|
||||
ny = rw;
|
||||
if (find_next_move(&ny, &nx))
|
||||
count_next_moves(ny, nx);
|
||||
if (find_next_move(squares, history, count_moves, &ny, &nx))
|
||||
count_next_moves(squares, count_moves, ny, nx);
|
||||
else
|
||||
beep();
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
if (review > 0) {
|
||||
review--;
|
||||
ny = history[movecount - review - 1].y;
|
||||
nx = history[movecount - review - 1].x;
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
review = reviewHistory(history, count_moves, review - 1,
|
||||
&ny, &nx);
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
if (review < movecount - 2) {
|
||||
review++;
|
||||
ny = history[movecount - review - 1].y;
|
||||
nx = history[movecount - review - 1].x;
|
||||
review = reviewHistory(history, count_moves, review + 1,
|
||||
&ny, &nx);
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
if (ylimit <= 6) {
|
||||
wprintw(msgwin, "\nworking...");
|
||||
wrefresh(msgwin);
|
||||
test_test = 0;
|
||||
test_size = useBacktracking(squares, history, count_moves);
|
||||
wprintw(msgwin, "\nOk %d:%d (%d tests)",
|
||||
test_size, maxmoves, test_test);
|
||||
review = 0;
|
||||
while (count_moves <= test_size) {
|
||||
markcell(trail,
|
||||
ny = history[count_moves].y,
|
||||
nx = history[count_moves].x);
|
||||
count_moves++;
|
||||
}
|
||||
} else {
|
||||
beep();
|
||||
wprintw(msgwin, "\nBoard is too large.");
|
||||
}
|
||||
wrefresh(msgwin);
|
||||
break;
|
||||
|
||||
#if HAVE_CURSCR
|
||||
@ -745,12 +883,12 @@ play(void)
|
||||
break;
|
||||
}
|
||||
|
||||
col = nx % BWIDTH;
|
||||
rw = ny % BDEPTH;
|
||||
col = nx % xlimit;
|
||||
rw = ny % ylimit;
|
||||
}
|
||||
|
||||
dropout:
|
||||
if ((count = completed()) < 0)
|
||||
if ((count = completed(squares)) < 0)
|
||||
wprintw(msgwin, "\nYou won. Care to try again? ");
|
||||
else
|
||||
wprintw(msgwin, "\n%d squares filled. Try again? ", count);
|
||||
@ -759,9 +897,55 @@ play(void)
|
||||
(tolower(wgetch(msgwin)) == 'y');
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: knight [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
," -n NUM set board-size to NUM*NUM (default 8x8)"
|
||||
};
|
||||
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[])
|
||||
{
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "dn:")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case 'n':
|
||||
ch = atoi(optarg);
|
||||
if (ch < 3 || ch > 8) {
|
||||
fprintf(stderr, "board size %d is outside [3..8]\n", ch);
|
||||
usage();
|
||||
}
|
||||
xlimit = ylimit = ch;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
init_program();
|
||||
|
||||
play();
|
||||
@ -769,5 +953,3 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* knight.c ends here */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2005,2010 Free Software Foundation, Inc. *
|
||||
* Copyright (c) 1998-2010,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 *
|
||||
@ -34,7 +34,7 @@
|
||||
* This can't be part of the ncurses test-program, because ncurses rips off the
|
||||
* bottom line to do labels.
|
||||
*
|
||||
* $Id: lrtest.c,v 1.22 2010/05/01 19:11:55 tom Exp $
|
||||
* $Id: lrtest.c,v 1.24 2017/09/04 11:28:19 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -174,8 +174,7 @@ main(
|
||||
refresh();
|
||||
}
|
||||
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# $Id: mk-test.awk,v 1.16 2017/08/11 16:51:10 tom Exp $
|
||||
# $Id: mk-test.awk,v 1.17 2017/09/04 00:50:49 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 2006-2010,2015 Free Software Foundation, Inc. #
|
||||
# Copyright (c) 2006-2015,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 "Software"), #
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: movewindow.c,v 1.43 2017/06/24 20:48:46 tom Exp $
|
||||
* $Id: movewindow.c,v 1.45 2017/09/06 20:08:11 tom Exp $
|
||||
*
|
||||
* Demonstrate move functions for windows and derived windows from the curses
|
||||
* library.
|
||||
@ -45,7 +45,9 @@ TODO:
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#if HAVE_MVDERWIN && HAVE_MVWIN
|
||||
|
||||
#include <popup_msg.h>
|
||||
|
||||
#ifdef HAVE_XCURSES
|
||||
@ -767,3 +769,11 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
#endif
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("This program requires the curses mvderwin and mvwin functions\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
@ -40,7 +40,7 @@ AUTHOR
|
||||
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
|
||||
Thomas E. Dickey (beginning revision 1.27 in 1996).
|
||||
|
||||
$Id: ncurses.c,v 1.453 2017/06/24 20:49:44 tom Exp $
|
||||
$Id: ncurses.c,v 1.460 2017/09/09 22:52:38 tom Exp $
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
@ -155,6 +155,7 @@ static bool use_colors; /* true if we use colors */
|
||||
#undef max_pairs
|
||||
static int max_pairs; /* ...and the number of color pairs */
|
||||
|
||||
#if HAVE_COLOR_CONTENT
|
||||
typedef struct {
|
||||
NCURSES_COLOR_T red;
|
||||
NCURSES_COLOR_T green;
|
||||
@ -162,6 +163,7 @@ typedef struct {
|
||||
} RGB_DATA;
|
||||
|
||||
static RGB_DATA *all_colors;
|
||||
#endif
|
||||
|
||||
static void main_menu(bool);
|
||||
static void failed(const char *s) GCC_NORETURN;
|
||||
@ -174,29 +176,16 @@ failed(const char *s)
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* The behavior of mvhline, mvvline for negative/zero length is unspecified,
|
||||
* though we can rely on negative x/y values to stop the macro.
|
||||
*/
|
||||
static void
|
||||
do_h_line(int y, int x, chtype c, int to)
|
||||
{
|
||||
if ((to) > (x))
|
||||
MvHLine(y, x, c, (to) - (x));
|
||||
}
|
||||
|
||||
static void
|
||||
do_v_line(int y, int x, chtype c, int to)
|
||||
{
|
||||
if ((to) > (y))
|
||||
MvVLine(y, x, c, (to) - (y));
|
||||
}
|
||||
|
||||
static void
|
||||
Repaint(void)
|
||||
{
|
||||
touchwin(stdscr);
|
||||
#if HAVE_CURSCR
|
||||
touchwin(curscr);
|
||||
wrefresh(curscr);
|
||||
#else
|
||||
wrefresh(stdscr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -2644,6 +2633,7 @@ wide_color_test(void)
|
||||
}
|
||||
#endif /* USE_WIDEC_SUPPORT */
|
||||
|
||||
#if HAVE_COLOR_CONTENT
|
||||
static void
|
||||
change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
|
||||
{
|
||||
@ -2990,6 +2980,7 @@ color_edit(void)
|
||||
|
||||
endwin();
|
||||
}
|
||||
#endif /* HAVE_COLOR_CONTENT */
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
@ -5255,6 +5246,25 @@ demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if HAVE_NEWPAD
|
||||
|
||||
/* The behavior of mvhline, mvvline for negative/zero length is unspecified,
|
||||
* though we can rely on negative x/y values to stop the macro.
|
||||
*/
|
||||
static void
|
||||
do_h_line(int y, int x, chtype c, int to)
|
||||
{
|
||||
if ((to) > (x))
|
||||
MvHLine(y, x, c, (to) - (x));
|
||||
}
|
||||
|
||||
static void
|
||||
do_v_line(int y, int x, chtype c, int to)
|
||||
{
|
||||
if ((to) > (y))
|
||||
MvVLine(y, x, c, (to) - (y));
|
||||
}
|
||||
|
||||
#define GRIDSIZE 3
|
||||
|
||||
static bool pending_pan = FALSE;
|
||||
@ -5703,6 +5713,7 @@ demo_pad(bool colored)
|
||||
endwin();
|
||||
erase();
|
||||
}
|
||||
#endif /* HAVE_NEWPAD */
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
@ -6519,6 +6530,7 @@ demo_forms(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if HAVE_COPYWIN /* ...and overlay, overwrite */
|
||||
static void
|
||||
fillwin(WINDOW *win, char ch)
|
||||
{
|
||||
@ -6861,10 +6873,11 @@ overlap_test(void)
|
||||
delwin(win2);
|
||||
delwin(win1);
|
||||
erase();
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
}
|
||||
|
||||
#endif /* HAVE_COPYWIN */
|
||||
|
||||
static void
|
||||
show_setting_name(const char *name)
|
||||
{
|
||||
@ -6944,7 +6957,7 @@ show_settings(void)
|
||||
show_boolean_setting("has_il", has_il());
|
||||
Pause();
|
||||
erase();
|
||||
endwin();
|
||||
exit_curses();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -6994,6 +7007,7 @@ do_single_test(const char c)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if HAVE_COLOR_CONTENT
|
||||
case 'd':
|
||||
if (!use_colors)
|
||||
Cannot("does not support color.");
|
||||
@ -7002,6 +7016,7 @@ do_single_test(const char c)
|
||||
else
|
||||
color_edit();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if USE_SOFTKEYS
|
||||
case 'e':
|
||||
@ -7055,6 +7070,7 @@ do_single_test(const char c)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if HAVE_NEWPAD
|
||||
case 'p':
|
||||
demo_pad(FALSE);
|
||||
break;
|
||||
@ -7062,6 +7078,7 @@ do_single_test(const char c)
|
||||
case 'P':
|
||||
demo_pad(TRUE);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if USE_LIBFORM
|
||||
case 'r':
|
||||
@ -7069,9 +7086,11 @@ do_single_test(const char c)
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if HAVE_COPYWIN
|
||||
case 's':
|
||||
overlap_test();
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if USE_LIBMENU && defined(TRACE)
|
||||
case 't':
|
||||
@ -7116,7 +7135,9 @@ usage(void)
|
||||
," -h rip-off header line (can repeat)"
|
||||
#endif
|
||||
," -m do not use colors"
|
||||
#if HAVE_COLOR_CONTENT
|
||||
," -p file rgb values to use in 'd' rather than ncurses's builtin"
|
||||
#endif
|
||||
#if USE_LIBPANEL
|
||||
," -s msec specify nominal time for panel-demo (default: 1, to hold)"
|
||||
#endif
|
||||
@ -7126,7 +7147,9 @@ usage(void)
|
||||
#ifdef TRACE
|
||||
," -t mask specify default trace-level (may toggle with ^T)"
|
||||
#endif
|
||||
#if HAVE_COLOR_CONTENT
|
||||
," -x use xterm-compatible control for reading color palette"
|
||||
#endif
|
||||
};
|
||||
size_t n;
|
||||
for (n = 0; n < SIZEOF(tbl); n++)
|
||||
@ -7196,8 +7219,10 @@ main_menu(bool top)
|
||||
#if USE_WIDEC_SUPPORT
|
||||
(void) puts("C = color test pattern using wide-character calls");
|
||||
#endif
|
||||
#if HAVE_COLOR_CONTENT
|
||||
if (top)
|
||||
(void) puts("d = edit RGB color values");
|
||||
#endif
|
||||
#if USE_SOFTKEYS
|
||||
(void) puts("e = exercise soft keys");
|
||||
#if USE_WIDEC_SUPPORT
|
||||
@ -7220,13 +7245,17 @@ main_menu(bool top)
|
||||
(void) puts("O = exercise panels with wide-characters");
|
||||
#endif
|
||||
#endif
|
||||
#if HAVE_NEWPAD
|
||||
(void) puts("p = exercise pad features");
|
||||
(void) puts("P = exercise pad features, using color");
|
||||
#endif
|
||||
(void) puts("q = quit");
|
||||
#if USE_LIBFORM
|
||||
(void) puts("r = exercise forms code");
|
||||
#endif
|
||||
#if HAVE_COPYWIN
|
||||
(void) puts("s = overlapping-refresh test");
|
||||
#endif
|
||||
#if USE_LIBMENU && defined(TRACE)
|
||||
(void) puts("t = set trace level");
|
||||
#endif
|
||||
@ -7304,9 +7333,11 @@ main(int argc, char *argv[])
|
||||
bool assumed_colors = FALSE;
|
||||
bool default_colors = FALSE;
|
||||
#endif
|
||||
char *palette_file = 0;
|
||||
bool monochrome = FALSE;
|
||||
#if HAVE_COLOR_CONTENT
|
||||
bool xterm_colors = FALSE;
|
||||
char *palette_file = 0;
|
||||
#endif
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
@ -7354,9 +7385,11 @@ main(int argc, char *argv[])
|
||||
case 'm':
|
||||
monochrome = TRUE;
|
||||
break;
|
||||
#if HAVE_COLOR_CONTENT
|
||||
case 'p':
|
||||
palette_file = optarg;
|
||||
break;
|
||||
#endif
|
||||
#if USE_LIBPANEL
|
||||
case 's':
|
||||
nap_msec = (int) atol(optarg);
|
||||
@ -7372,9 +7405,11 @@ main(int argc, char *argv[])
|
||||
save_trace = (unsigned) strtol(optarg, 0, 0);
|
||||
break;
|
||||
#endif
|
||||
#if HAVE_COLOR_CONTENT
|
||||
case 'x':
|
||||
xterm_colors = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@ -7434,9 +7469,11 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
|
||||
|
||||
#if HAVE_COLOR_CONTENT
|
||||
if (can_change_color()) {
|
||||
init_all_colors(xterm_colors, palette_file);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* newdemo.c - A demo program using PDCurses. The program illustrate
|
||||
* the use of colours for text output.
|
||||
*
|
||||
* $Id: newdemo.c,v 1.43 2016/09/10 21:25:53 tom Exp $
|
||||
* $Id: newdemo.c,v 1.44 2017/09/04 11:49:55 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -50,7 +50,7 @@ static const char *messages[] =
|
||||
static void
|
||||
trap(int sig GCC_UNUSED)
|
||||
{
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
height = 14; /* Create a drawing window */
|
||||
win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
|
||||
if (win == NULL) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -360,6 +360,6 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
if (WaitForUser(win) == 1)
|
||||
break;
|
||||
}
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: picsmap.c,v 1.101 2017/08/20 16:42:13 tom Exp $
|
||||
* $Id: picsmap.c,v 1.103 2017/09/06 09:21:38 tom Exp $
|
||||
*
|
||||
* Author: Thomas E. Dickey
|
||||
*
|
||||
@ -49,7 +49,6 @@
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@ -1703,7 +1702,7 @@ main(int argc, char *argv[])
|
||||
init_palette(palette_path);
|
||||
}
|
||||
scrollok(stdscr, FALSE);
|
||||
endwin();
|
||||
exit_curses();
|
||||
}
|
||||
if (optind >= argc)
|
||||
giveup("expected at least one image filename");
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: popup_msg.c,v 1.7 2017/04/15 19:16:41 tom Exp $
|
||||
* $Id: popup_msg.c,v 1.8 2017/09/03 21:05:01 tom Exp $
|
||||
*
|
||||
* Show a multi-line message in a window which may extend beyond the screen.
|
||||
*
|
||||
@ -37,6 +37,8 @@
|
||||
|
||||
#include <popup_msg.h>
|
||||
|
||||
#if HAVE_NEWPAD
|
||||
|
||||
static WINDOW *old_window;
|
||||
|
||||
static void
|
||||
@ -167,3 +169,13 @@ popup_msg2(WINDOW *parent, char **msg)
|
||||
{
|
||||
popup_msg(parent, (const char *const *) msg);
|
||||
}
|
||||
|
||||
#else
|
||||
void
|
||||
popup_msg(WINDOW *parent, const char *const *msg)
|
||||
{
|
||||
(void) parent;
|
||||
(void) msg;
|
||||
beep();
|
||||
}
|
||||
#endif
|
||||
|
52
test/rain.c
52
test/rain.c
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: rain.c,v 1.43 2017/04/30 01:08:14 tom Exp $
|
||||
* $Id: rain.c,v 1.46 2017/09/09 00:37:51 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
#include <popup_msg.h>
|
||||
@ -70,8 +70,7 @@ static STATS drop_threads[MAX_THREADS];
|
||||
static void
|
||||
onsig(int n GCC_UNUSED)
|
||||
{
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -289,9 +288,28 @@ get_input(void)
|
||||
return USING_WINDOW(stdscr, wgetch);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: rain [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
};
|
||||
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[])
|
||||
{
|
||||
static const char *help[] =
|
||||
{
|
||||
@ -309,6 +327,25 @@ main(int argc GCC_UNUSED,
|
||||
DATA last[MAX_DROP];
|
||||
#endif
|
||||
int j = 0;
|
||||
int ch;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
|
||||
while ((ch = getopt(argc, argv, "d")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
@ -319,7 +356,7 @@ main(int argc GCC_UNUSED,
|
||||
int bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
bg = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_BLUE, (short) bg);
|
||||
@ -394,8 +431,7 @@ main(int argc GCC_UNUSED,
|
||||
}
|
||||
napms(50);
|
||||
}
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
#ifdef USE_PTHREADS
|
||||
printf("Counts per thread:\n");
|
||||
for (j = 0; j < MAX_THREADS; ++j)
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: savescreen.c,v 1.32 2017/04/15 17:33:50 tom Exp $
|
||||
* $Id: savescreen.c,v 1.34 2017/09/04 15:01:45 tom Exp $
|
||||
*
|
||||
* Demonstrate save/restore functions from the curses library.
|
||||
* Thomas Dickey - 2007/7/14
|
||||
@ -313,7 +313,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
move(0, 0);
|
||||
} else {
|
||||
endwin();
|
||||
exit_curses();
|
||||
fprintf(stderr, "Cannot open \"%s\"\n", fill_by);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
@ -325,14 +325,14 @@ main(int argc, char *argv[])
|
||||
* Use the last file as the initial/current screen.
|
||||
*/
|
||||
if (last < 0) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
printf("No screen-dumps given\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
which = last;
|
||||
if (load_screen(files[which]) == ERR) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
printf("Cannot load screen-dump %s\n", files[which]);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
@ -489,7 +489,7 @@ main(int argc, char *argv[])
|
||||
|
||||
#else
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
printf("This program requires the screen-dump functions\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: tclock.c,v 1.35 2016/09/04 23:52:17 tom Exp $ */
|
||||
/* $Id: tclock.c,v 1.38 2017/09/09 00:37:06 tom Exp $ */
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
@ -116,8 +116,28 @@ dline(int pair, int from_x, int from_y, int x2, int y2, int ch)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: tclock [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
};
|
||||
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 i, cx, cy;
|
||||
double cr, mradius, hradius, mangle, hangle;
|
||||
@ -137,6 +157,24 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
struct timeval current;
|
||||
#endif
|
||||
double fraction = 0.0;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool d_option = FALSE;
|
||||
#endif
|
||||
|
||||
while ((ch = getopt(argc, argv, "d")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
d_option = TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
@ -149,7 +187,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (d_option && (use_default_colors() == OK))
|
||||
my_bg = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_RED, my_bg);
|
||||
@ -254,8 +292,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
|
||||
}
|
||||
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
|
@ -29,7 +29,7 @@
|
||||
/****************************************************************************
|
||||
* Author: Thomas E. Dickey 1996-on *
|
||||
****************************************************************************/
|
||||
/* $Id: test.priv.h,v 1.148 2017/08/20 16:51:33 tom Exp $ */
|
||||
/* $Id: test.priv.h,v 1.154 2017/09/06 20:07:40 tom Exp $ */
|
||||
|
||||
#ifndef __TEST_PRIV_H
|
||||
#define __TEST_PRIV_H 1
|
||||
@ -86,10 +86,22 @@
|
||||
#define HAVE_COLOR_CONTENT 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_COPYWIN
|
||||
#define HAVE_COPYWIN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_COLOR_SET
|
||||
#define HAVE_COLOR_SET 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DELSCREEN
|
||||
#define HAVE_DELSCREEN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DUPWIN
|
||||
#define HAVE_DUPWIN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FILTER
|
||||
#define HAVE_FILTER 0
|
||||
#endif
|
||||
@ -122,6 +134,10 @@
|
||||
#define HAVE_GETWIN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_HALFDELAY
|
||||
#define HAVE_HALFDELAY 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_INIT_EXTENDED_COLOR
|
||||
#define HAVE_INIT_EXTENDED_COLOR 0
|
||||
#endif
|
||||
@ -154,10 +170,18 @@
|
||||
#define HAVE_MENU_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MVDERWIN
|
||||
#define HAVE_MVDERWIN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MVVLINE
|
||||
#define HAVE_MVVLINE 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MVWIN
|
||||
#define HAVE_MVWIN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MVWVLINE
|
||||
#define HAVE_MVWVLINE 0
|
||||
#endif
|
||||
@ -170,6 +194,10 @@
|
||||
#define HAVE_NC_ALLOC_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NEWPAD
|
||||
#define HAVE_NEWPAD 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PANEL_H
|
||||
#define HAVE_PANEL_H 0
|
||||
#endif
|
||||
@ -294,6 +322,10 @@
|
||||
#define HAVE_VID_PUTS 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WINSDELLN
|
||||
#define HAVE_WINSDELLN 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WRESIZE
|
||||
#define HAVE_WRESIZE 0
|
||||
#endif
|
||||
@ -695,18 +727,18 @@ extern char *strnames[], *strcodes[], *strfnames[];
|
||||
* These usually are implemented as macros, but may be functions.
|
||||
*/
|
||||
#if !defined(getcurx) && !HAVE_GETCURX
|
||||
#define getcurx(win) ((win)?(win)->_curx:ERR)
|
||||
#define getcury(win) ((win)?(win)->_cury:ERR)
|
||||
#define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
|
||||
#define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
|
||||
#endif
|
||||
|
||||
#if !defined(getbegx) && !HAVE_GETBEGX
|
||||
#define getbegx(win) ((win)?(win)->_begx:ERR)
|
||||
#define getbegy(win) ((win)?(win)->_begy:ERR)
|
||||
#define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
|
||||
#define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
|
||||
#endif
|
||||
|
||||
#if !defined(getmaxx) && !HAVE_GETMAXX
|
||||
#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
|
||||
#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
|
||||
#define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
|
||||
#define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -760,6 +792,15 @@ extern char *strnames[], *strcodes[], *strfnames[];
|
||||
#define NCURSES_XNAMES 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ncurses restores the cursor in endwin(). Other libraries may not.
|
||||
*/
|
||||
#ifdef NCURSES_VERSION
|
||||
#define exit_curses() endwin()
|
||||
#else
|
||||
#define exit_curses() do { endwin(); curs_set(1); } while (0)
|
||||
#endif
|
||||
|
||||
/* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
|
||||
* (which is incompatible with legacy usage, doesn't solve any problems).
|
||||
*/
|
||||
|
@ -26,14 +26,13 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: test_addchstr.c,v 1.21 2017/04/15 14:09:14 tom Exp $
|
||||
* $Id: test_addchstr.c,v 1.23 2017/09/06 09:27:20 tom Exp $
|
||||
*
|
||||
* Demonstrate the waddchstr() and waddch functions.
|
||||
* Thomas Dickey - 2009/9/12
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#include <linedata.h>
|
||||
|
||||
/*
|
||||
|
@ -26,14 +26,13 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: test_addstr.c,v 1.13 2017/04/15 14:56:27 tom Exp $
|
||||
* $Id: test_addstr.c,v 1.15 2017/09/06 09:27:34 tom Exp $
|
||||
*
|
||||
* Demonstrate the waddstr() and waddch functions.
|
||||
* Thomas Dickey - 2009/9/12
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#include <linedata.h>
|
||||
|
||||
/*
|
||||
|
@ -26,7 +26,7 @@
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: test_instr.c,v 1.7 2017/04/15 14:08:40 tom Exp $
|
||||
* $Id: test_instr.c,v 1.9 2017/09/06 09:27:45 tom Exp $
|
||||
*
|
||||
* Author: Thomas E Dickey
|
||||
*
|
||||
|
238
test/testcurs.c
238
test/testcurs.c
@ -6,7 +6,7 @@
|
||||
* wrs(5/28/93) -- modified to be consistent (perform identically) with either
|
||||
* PDCurses or under Unix System V, R4
|
||||
*
|
||||
* $Id: testcurs.c,v 1.50 2015/07/05 00:11:10 tom Exp $
|
||||
* $Id: testcurs.c,v 1.52 2017/09/04 11:49:55 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -20,127 +20,16 @@ static void display_menu(int, int);
|
||||
static void inputTest(WINDOW *);
|
||||
static void introTest(WINDOW *);
|
||||
static void outputTest(WINDOW *);
|
||||
#if HAVE_NEWPAD
|
||||
static void padTest(WINDOW *);
|
||||
#endif
|
||||
static void scrollTest(WINDOW *);
|
||||
#if defined(PDCURSES) && !defined(XCURSES)
|
||||
static void resizeTest(WINDOW *);
|
||||
#endif
|
||||
|
||||
struct commands {
|
||||
NCURSES_CONST char *text;
|
||||
void (*function) (WINDOW *);
|
||||
};
|
||||
typedef struct commands COMMAND;
|
||||
|
||||
static const COMMAND command[] =
|
||||
{
|
||||
{"General Test", introTest},
|
||||
{"Pad Test", padTest},
|
||||
#if defined(PDCURSES) && !defined(XCURSES)
|
||||
{"Resize Test", resizeTest},
|
||||
#endif
|
||||
{"Scroll Test", scrollTest},
|
||||
{"Input Test", inputTest},
|
||||
{"Output Test", outputTest}
|
||||
};
|
||||
#define MAX_OPTIONS (int) SIZEOF(command)
|
||||
|
||||
static int width, height;
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
WINDOW *win;
|
||||
int key;
|
||||
int old_option = (-1);
|
||||
int new_option = 0;
|
||||
bool quit = FALSE;
|
||||
int n;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
PDC_debug("testcurs started\n");
|
||||
#endif
|
||||
if (!initTest(&win))
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
|
||||
erase();
|
||||
display_menu(old_option, new_option);
|
||||
for (;;) {
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
wbkgd(win, (chtype) COLOR_PAIR(1));
|
||||
} else
|
||||
wbkgd(win, A_REVERSE);
|
||||
#else
|
||||
wbkgd(win, A_REVERSE);
|
||||
#endif
|
||||
werase(win);
|
||||
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
raw();
|
||||
key = getch();
|
||||
if (key < KEY_MIN && key > 0 && isalpha(key)) {
|
||||
if (islower(key))
|
||||
key = toupper(key);
|
||||
for (n = 0; n < MAX_OPTIONS; ++n) {
|
||||
if (key == command[n].text[0]) {
|
||||
display_menu(old_option, new_option = n);
|
||||
key = ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (key) {
|
||||
case 10:
|
||||
case 13:
|
||||
case KEY_ENTER:
|
||||
erase();
|
||||
refresh();
|
||||
(*command[new_option].function) (win);
|
||||
erase();
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case KEY_UP:
|
||||
new_option = ((new_option == 0)
|
||||
? new_option
|
||||
: new_option - 1);
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
new_option = ((new_option == (MAX_OPTIONS - 1))
|
||||
? new_option
|
||||
: new_option + 1);
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case 'Q':
|
||||
case 'q':
|
||||
quit = TRUE;
|
||||
break;
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
if (quit == TRUE)
|
||||
break;
|
||||
}
|
||||
|
||||
delwin(win);
|
||||
|
||||
endwin();
|
||||
#ifdef XCURSES
|
||||
XCursesExit();
|
||||
#endif
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
Continue(WINDOW *win)
|
||||
{
|
||||
@ -184,7 +73,7 @@ initTest(WINDOW **win)
|
||||
height = 13; /* Create a drawing window */
|
||||
*win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
|
||||
if (*win == NULL) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -668,7 +557,7 @@ resizeTest(WINDOW *dummy GCC_UNUSED)
|
||||
|
||||
win1 = newwin(10, 50, 14, 25);
|
||||
if (win1 == NULL) {
|
||||
endwin();
|
||||
exit_curses();
|
||||
return;
|
||||
}
|
||||
#ifdef A_COLOR
|
||||
@ -696,6 +585,7 @@ resizeTest(WINDOW *dummy GCC_UNUSED)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HAVE_NEWPAD
|
||||
static void
|
||||
padTest(WINDOW *dummy GCC_UNUSED)
|
||||
{
|
||||
@ -736,6 +626,28 @@ padTest(WINDOW *dummy GCC_UNUSED)
|
||||
delwin(pad);
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_NEWPAD */
|
||||
|
||||
struct commands {
|
||||
NCURSES_CONST char *text;
|
||||
void (*function) (WINDOW *);
|
||||
};
|
||||
typedef struct commands COMMAND;
|
||||
|
||||
static const COMMAND command[] =
|
||||
{
|
||||
{"General Test", introTest},
|
||||
#if HAVE_NEWPAD
|
||||
{"Pad Test", padTest},
|
||||
#endif
|
||||
#if defined(PDCURSES) && !defined(XCURSES)
|
||||
{"Resize Test", resizeTest},
|
||||
#endif
|
||||
{"Scroll Test", scrollTest},
|
||||
{"Input Test", inputTest},
|
||||
{"Output Test", outputTest}
|
||||
};
|
||||
#define MAX_OPTIONS (int) SIZEOF(command)
|
||||
|
||||
static void
|
||||
display_menu(int old_option, int new_option)
|
||||
@ -760,3 +672,97 @@ display_menu(int old_option, int new_option)
|
||||
"Use Up and Down Arrows to select - Enter to run - Q to quit");
|
||||
refresh();
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
WINDOW *win;
|
||||
int key;
|
||||
int old_option = (-1);
|
||||
int new_option = 0;
|
||||
bool quit = FALSE;
|
||||
int n;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
PDC_debug("testcurs started\n");
|
||||
#endif
|
||||
if (!initTest(&win))
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
|
||||
erase();
|
||||
display_menu(old_option, new_option);
|
||||
for (;;) {
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
wbkgd(win, (chtype) COLOR_PAIR(1));
|
||||
} else
|
||||
wbkgd(win, A_REVERSE);
|
||||
#else
|
||||
wbkgd(win, A_REVERSE);
|
||||
#endif
|
||||
werase(win);
|
||||
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
raw();
|
||||
key = getch();
|
||||
if (key < KEY_MIN && key > 0 && isalpha(key)) {
|
||||
if (islower(key))
|
||||
key = toupper(key);
|
||||
for (n = 0; n < MAX_OPTIONS; ++n) {
|
||||
if (key == command[n].text[0]) {
|
||||
display_menu(old_option, new_option = n);
|
||||
key = ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (key) {
|
||||
case 10:
|
||||
case 13:
|
||||
case KEY_ENTER:
|
||||
erase();
|
||||
refresh();
|
||||
(*command[new_option].function) (win);
|
||||
erase();
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case KEY_UP:
|
||||
new_option = ((new_option == 0)
|
||||
? new_option
|
||||
: new_option - 1);
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
new_option = ((new_option == (MAX_OPTIONS - 1))
|
||||
? new_option
|
||||
: new_option + 1);
|
||||
display_menu(old_option, new_option);
|
||||
break;
|
||||
case 'Q':
|
||||
case 'q':
|
||||
quit = TRUE;
|
||||
break;
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
if (quit == TRUE)
|
||||
break;
|
||||
}
|
||||
|
||||
delwin(win);
|
||||
|
||||
exit_curses();
|
||||
#ifdef XCURSES
|
||||
XCursesExit();
|
||||
#endif
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@
|
||||
* scroll operation worked, and the refresh() code only had to do a
|
||||
* partial repaint.
|
||||
*
|
||||
* $Id: view.c,v 1.101 2017/04/15 20:14:01 tom Exp $
|
||||
* $Id: view.c,v 1.102 2017/09/04 00:39:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
@ -506,12 +506,17 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
#endif
|
||||
case 's':
|
||||
#if HAVE_HALFDELAY
|
||||
if (got_number) {
|
||||
halfdelay(my_delay = n);
|
||||
} else {
|
||||
nodelay(stdscr, FALSE);
|
||||
my_delay = -1;
|
||||
}
|
||||
#else
|
||||
nodelay(stdscr, FALSE);
|
||||
my_delay = -1;
|
||||
#endif
|
||||
break;
|
||||
case ' ':
|
||||
nodelay(stdscr, TRUE);
|
||||
|
95
test/worm.c
95
test/worm.c
@ -47,25 +47,20 @@
|
||||
|
||||
July 1995 (esr): worms is now in living color! :-)
|
||||
|
||||
Options:
|
||||
-f fill screen with copies of 'WORM' at start.
|
||||
-l <n> set worm length
|
||||
-n <n> set number of worms
|
||||
-t make worms leave droppings
|
||||
-T <start> <end> set trace interval
|
||||
-S set single-stepping during trace interval
|
||||
-N suppress cursor-movement optimization
|
||||
|
||||
This program makes a good torture-test for the ncurses cursor-optimization
|
||||
code. You can use -T to set the worm move interval over which movement
|
||||
traces will be dumped. The program stops and waits for one character of
|
||||
input at the beginning and end of the interval.
|
||||
|
||||
$Id: worm.c,v 1.68 2017/04/15 14:15:00 tom Exp $
|
||||
$Id: worm.c,v 1.75 2017/09/08 20:00:50 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#ifndef NCURSES_VERSION
|
||||
#undef TRACE
|
||||
#endif
|
||||
|
||||
#ifdef USE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
@ -201,20 +196,21 @@ static const struct options {
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#ifdef KEY_RESIZE
|
||||
static void
|
||||
failed(const char *s)
|
||||
{
|
||||
perror(s);
|
||||
endwin();
|
||||
exit_curses();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
USING_WINDOW(stdscr, wrefresh);
|
||||
curs_set(1);
|
||||
endwin();
|
||||
exit_curses();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -422,41 +418,70 @@ update_refs(WINDOW *win)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: worm [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
," -d invoke use_default_colors"
|
||||
#endif
|
||||
," -f fill screen with copies of \"WORM\" at start"
|
||||
," -l <n> set length of worms"
|
||||
," -n <n> set number of worms"
|
||||
," -t leave trail of \".\""
|
||||
#ifdef TRACE
|
||||
," -T <start>,<end> set trace interval"
|
||||
," -N suppress cursor-movement optimization"
|
||||
#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[])
|
||||
{
|
||||
int ch;
|
||||
int x, y;
|
||||
int n;
|
||||
struct worm *w;
|
||||
int *ip;
|
||||
bool done = FALSE;
|
||||
int max_refs;
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
bool opt_d = FALSE;
|
||||
#endif
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
for (x = 1; x < argc; x++) {
|
||||
char *p;
|
||||
p = argv[x];
|
||||
if (*p == '-')
|
||||
p++;
|
||||
switch (*p) {
|
||||
while ((ch = getopt(argc, argv, "dfl:n:tT:N")) != -1) {
|
||||
switch (ch) {
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
case 'd':
|
||||
opt_d = TRUE;
|
||||
break;
|
||||
#endif
|
||||
case 'f':
|
||||
field = "WORM";
|
||||
break;
|
||||
case 'l':
|
||||
if (++x == argc)
|
||||
goto usage;
|
||||
if ((length = atoi(argv[x])) < 2 || length > MAX_LENGTH) {
|
||||
if ((length = atoi(optarg)) < 2 || length > MAX_LENGTH) {
|
||||
fprintf(stderr, "%s: Invalid length\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (++x == argc)
|
||||
goto usage;
|
||||
if ((number = atoi(argv[x])) < 1 || number > MAX_WORMS) {
|
||||
if ((number = atoi(optarg)) < 1 || number > MAX_WORMS) {
|
||||
fprintf(stderr, "%s: Invalid number of worms\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
@ -464,20 +489,20 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
#ifdef TRACE
|
||||
case 'T':
|
||||
trace_start = atoi(argv[++x]);
|
||||
trace_end = atoi(argv[++x]);
|
||||
if (sscanf(optarg, "%d,%d", &trace_start, &trace_end) != 2)
|
||||
usage();
|
||||
break;
|
||||
case 'N':
|
||||
_nc_optimize_enable ^= OPTIMIZE_ALL; /* declared by ncurses */
|
||||
break;
|
||||
#endif /* TRACE */
|
||||
default:
|
||||
usage:
|
||||
fprintf(stderr,
|
||||
"usage: %s [-field] [-length #] [-number #] [-trail]\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
signal(SIGINT, onsig);
|
||||
initscr();
|
||||
@ -495,7 +520,7 @@ main(int argc, char *argv[])
|
||||
int bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
if (opt_d && (use_default_colors() == OK))
|
||||
bg = -1;
|
||||
#endif
|
||||
|
||||
@ -562,8 +587,6 @@ main(int argc, char *argv[])
|
||||
nodelay(stdscr, TRUE);
|
||||
|
||||
while (!done) {
|
||||
int ch;
|
||||
|
||||
++sequence;
|
||||
if ((ch = get_input()) > 0) {
|
||||
#ifdef TRACE
|
||||
|
1036
test/xmas.c
1036
test/xmas.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user