mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-05 03:39:02 +00:00
Remove files that are no longer exist.
Approved by: delphij
This commit is contained in:
parent
4a1a95108d
commit
01b82453a3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/vendor/ncurses/dist/; revision=166133 svn path=/vendor/ncurses/5.6-20061217/; revision=166126; tag=vendor/ncurses/5.6-20061217
@ -1,405 +0,0 @@
|
||||
# Copyright (C) 1997,1998 Free Software Foundation, Inc.
|
||||
# This file is part of the GNU C Library.
|
||||
|
||||
# The GNU C Library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or (at your option) any later version.
|
||||
|
||||
# The GNU C Library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with the GNU C Library; see the file COPYING.LIB. If not,
|
||||
# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
#
|
||||
# Makefile for ncurses part.
|
||||
#
|
||||
subdir := ncurses
|
||||
|
||||
ncurses-version = 4.2
|
||||
form-version = $(ncurses-version)
|
||||
menu-version = $(ncurses-version)
|
||||
panel-version = $(ncurses-version)
|
||||
|
||||
extras := form menu ncurses panel
|
||||
|
||||
extra-libs = $(extras:%=lib%)
|
||||
# These libraries will be built in the `others' pass rather than
|
||||
# the `lib' pass, because they depend on libc.so being built already.
|
||||
extra-libs-others = $(extra-libs)
|
||||
|
||||
# The sources are found in the appropriate subdir.
|
||||
subdir-dirs = $(extras) progs test
|
||||
vpath %.c $(subdir-dirs)
|
||||
vpath %.h $(subdir-dirs)
|
||||
|
||||
libform-routines = \
|
||||
fld_arg \
|
||||
fld_attr \
|
||||
fld_current \
|
||||
fld_def \
|
||||
fld_dup \
|
||||
fld_ftchoice \
|
||||
fld_ftlink \
|
||||
fld_info \
|
||||
fld_just \
|
||||
fld_link \
|
||||
fld_max \
|
||||
fld_move \
|
||||
fld_newftyp \
|
||||
fld_opts \
|
||||
fld_pad \
|
||||
fld_page \
|
||||
fld_stat \
|
||||
fld_type \
|
||||
fld_user \
|
||||
frm_cursor \
|
||||
frm_data \
|
||||
frm_def \
|
||||
frm_driver \
|
||||
frm_hook \
|
||||
frm_opts \
|
||||
frm_page \
|
||||
frm_post \
|
||||
frm_req_name \
|
||||
frm_scale \
|
||||
frm_sub \
|
||||
frm_user \
|
||||
frm_win \
|
||||
fty_alnum \
|
||||
fty_alpha \
|
||||
fty_enum \
|
||||
fty_int \
|
||||
fty_ipv4 \
|
||||
fty_num \
|
||||
fty_regex
|
||||
|
||||
libncurses-routines = \
|
||||
base/define_key \
|
||||
base/keybound \
|
||||
base/keyok \
|
||||
base/lib_addch \
|
||||
base/lib_addstr \
|
||||
base/lib_beep \
|
||||
base/lib_bkgd \
|
||||
base/lib_box \
|
||||
base/lib_chgat \
|
||||
base/lib_clear \
|
||||
base/lib_clearok \
|
||||
base/lib_clrbot \
|
||||
base/lib_clreol \
|
||||
base/lib_color \
|
||||
base/lib_colorset \
|
||||
base/lib_delch \
|
||||
base/lib_delwin \
|
||||
base/lib_dft_fgbg \
|
||||
base/lib_echo \
|
||||
base/lib_endwin \
|
||||
base/lib_erase \
|
||||
base/lib_flash \
|
||||
base/lib_freeall \
|
||||
base/lib_getch \
|
||||
base/lib_getstr \
|
||||
base/lib_hline \
|
||||
base/lib_immedok \
|
||||
base/lib_inchstr \
|
||||
base/lib_initscr \
|
||||
base/lib_insch \
|
||||
base/lib_insdel \
|
||||
base/lib_insstr \
|
||||
base/lib_instr \
|
||||
base/lib_isendwin \
|
||||
base/lib_leaveok \
|
||||
base/lib_mouse \
|
||||
base/lib_move \
|
||||
base/lib_mvwin \
|
||||
base/lib_newterm \
|
||||
base/lib_newwin \
|
||||
base/lib_nl \
|
||||
base/lib_overlay \
|
||||
base/lib_pad \
|
||||
base/lib_printw \
|
||||
base/lib_redrawln \
|
||||
base/lib_refresh \
|
||||
base/lib_restart \
|
||||
base/lib_scanw \
|
||||
base/lib_screen \
|
||||
base/lib_scroll \
|
||||
base/lib_scrollok \
|
||||
base/lib_scrreg \
|
||||
base/lib_set_term \
|
||||
base/lib_slk \
|
||||
base/lib_slkatr_set \
|
||||
base/lib_slkatrof \
|
||||
base/lib_slkatron \
|
||||
base/lib_slkatrset \
|
||||
base/lib_slkattr \
|
||||
base/lib_slkclear \
|
||||
base/lib_slkcolor \
|
||||
base/lib_slkinit \
|
||||
base/lib_slklab \
|
||||
base/lib_slkrefr \
|
||||
base/lib_slkset \
|
||||
base/lib_slktouch \
|
||||
base/lib_touch \
|
||||
base/lib_ungetch \
|
||||
base/lib_vline \
|
||||
base/lib_wattroff \
|
||||
base/lib_wattron \
|
||||
base/lib_winch \
|
||||
base/lib_window \
|
||||
base/memmove \
|
||||
base/nc_panel \
|
||||
base/resizeterm \
|
||||
base/safe_sprintf \
|
||||
base/sigaction \
|
||||
base/tries \
|
||||
base/version \
|
||||
base/vsscanf \
|
||||
base/wresize \
|
||||
codes \
|
||||
comp_captab \
|
||||
expanded \
|
||||
fallback \
|
||||
lib_gen \
|
||||
lib_keyname \
|
||||
names \
|
||||
tinfo/access \
|
||||
tinfo/add_tries \
|
||||
tinfo/alloc_entry \
|
||||
tinfo/alloc_ttype \
|
||||
tinfo/captoinfo \
|
||||
tinfo/comp_error \
|
||||
tinfo/comp_expand \
|
||||
tinfo/comp_hash \
|
||||
tinfo/comp_parse \
|
||||
tinfo/comp_scan \
|
||||
tinfo/doalloc \
|
||||
tinfo/free_ttype \
|
||||
tinfo/getenv_num \
|
||||
tinfo/home_terminfo \
|
||||
tinfo/init_keytry \
|
||||
tinfo/lib_acs \
|
||||
tinfo/lib_baudrate \
|
||||
tinfo/lib_cur_term \
|
||||
tinfo/lib_data \
|
||||
tinfo/lib_has_cap \
|
||||
tinfo/lib_kernel \
|
||||
tinfo/lib_longname \
|
||||
tinfo/lib_napms \
|
||||
tinfo/lib_options \
|
||||
tinfo/lib_print \
|
||||
tinfo/lib_raw \
|
||||
tinfo/lib_setup \
|
||||
tinfo/lib_termcap \
|
||||
tinfo/lib_termname \
|
||||
tinfo/lib_tgoto \
|
||||
tinfo/lib_ti \
|
||||
tinfo/lib_tparm \
|
||||
tinfo/lib_tputs \
|
||||
tinfo/lib_ttyflags \
|
||||
tinfo/name_match \
|
||||
tinfo/parse_entry \
|
||||
tinfo/read_entry \
|
||||
tinfo/read_termcap \
|
||||
tinfo/setbuf \
|
||||
tinfo/strings \
|
||||
tinfo/write_entry \
|
||||
trace/lib_trace \
|
||||
trace/lib_traceatr \
|
||||
trace/lib_tracebits \
|
||||
trace/lib_tracechr \
|
||||
trace/lib_tracedmp \
|
||||
trace/lib_tracemse \
|
||||
trace/trace_buf \
|
||||
trace/trace_tries \
|
||||
trace/trace_xnames \
|
||||
trace/varargs \
|
||||
trace/visbuf \
|
||||
tty/hardscroll \
|
||||
tty/hashmap \
|
||||
tty/lib_mvcur \
|
||||
tty/lib_tstp \
|
||||
tty/lib_twait \
|
||||
tty/lib_vidattr \
|
||||
tty/tty_update \
|
||||
unctrl
|
||||
|
||||
libmenu-routines = \
|
||||
m_attribs \
|
||||
m_cursor \
|
||||
m_driver \
|
||||
m_format \
|
||||
m_global \
|
||||
m_hook \
|
||||
m_item_cur \
|
||||
m_item_nam \
|
||||
m_item_new \
|
||||
m_item_opt \
|
||||
m_item_top \
|
||||
m_item_use \
|
||||
m_item_val \
|
||||
m_item_vis \
|
||||
m_items \
|
||||
m_new \
|
||||
m_opts \
|
||||
m_pad \
|
||||
m_pattern \
|
||||
m_post \
|
||||
m_req_name \
|
||||
m_scale \
|
||||
m_spacing \
|
||||
m_sub \
|
||||
m_userptr \
|
||||
m_win
|
||||
|
||||
libpanel-routines = \
|
||||
panel \
|
||||
p_above \
|
||||
p_below \
|
||||
p_bottom \
|
||||
p_delete \
|
||||
p_hide \
|
||||
p_hidden \
|
||||
p_move \
|
||||
p_new \
|
||||
p_replace \
|
||||
p_show \
|
||||
p_top \
|
||||
p_update \
|
||||
p_user \
|
||||
p_win
|
||||
|
||||
headers = curses.h eti.h form.h menu.h panel.h term.h termcap.h \
|
||||
unctrl.h
|
||||
others = clear infocmp tic toe tput tset
|
||||
install-bin = $(others)
|
||||
|
||||
clear-objs = clear.o
|
||||
infocmp-objs = infocmp.o dump_entry.o
|
||||
tic-objs = tic.o dump_entry.o
|
||||
toe-objs = toe.o dump_entry.o
|
||||
tput-objs = tput.o
|
||||
tset-objs = tset.o dump_entry.o
|
||||
extra-objs = $(tic-objs) $(toe-objs) $(infocmp-objs) $(clear-objs) \
|
||||
$(tput-objs) $(tset-objs)
|
||||
|
||||
test-srcs = blue bs cardfile ditto firework firstlast gdc hanoi hashtest knight \
|
||||
lrtest ncurses newdemo rain tclock testaddch testcurs \
|
||||
testscanw view worm xmas
|
||||
|
||||
include ../Rules
|
||||
|
||||
ifndef tabsetdir
|
||||
tabsetdir = $(datadir)/tabset
|
||||
endif
|
||||
ifndef inst_tabsetdir
|
||||
inst_tabsetdir = $(install_root)/$(tabsetdir)
|
||||
endif
|
||||
|
||||
ifndef terminfodir
|
||||
terminfodir = $(datadir)/terminfo
|
||||
endif
|
||||
ifndef inst_terminfodir
|
||||
inst_terminfodir = $(install_root)/$(terminfodir)
|
||||
endif
|
||||
|
||||
ifndef mandir
|
||||
mandir = $(prefix)/man
|
||||
endif
|
||||
|
||||
ifndef inst_mandir
|
||||
inst_mandir = $(install_root)/$(mandir)
|
||||
endif
|
||||
|
||||
CPPFLAGS += -DTERMINFO='"$(terminfodir)"' -Iinclude -Iform -Incurses \
|
||||
-Imenu -Ipanel -Iprogs -Itest
|
||||
|
||||
ifneq ($(strip $(objpfx)),)
|
||||
CPPFLAGS += -I$(objpfx)
|
||||
endif
|
||||
|
||||
LDLIBS-tclock = math/libm
|
||||
|
||||
tests: $(test-srcs:%=$(objpfx)%)
|
||||
|
||||
$(objpfx)clear: $(addprefix $(objpfx),$(clear-objs))
|
||||
$(objpfx)infocmp: $(addprefix $(objpfx),$(infocmp-objs))
|
||||
$(objpfx)tic: $(addprefix $(objpfx),$(tic-objs))
|
||||
$(objpfx)toe: $(addprefix $(objpfx),$(toe-objs))
|
||||
$(objpfx)tput: $(addprefix $(objpfx),$(tput-objs))
|
||||
$(objpfx)tset: $(addprefix $(objpfx),$(tset-objs))
|
||||
|
||||
ifeq ($(build-shared),yes)
|
||||
$(others:%=$(objpfx)%): $(objpfx)libncurses.so
|
||||
else
|
||||
$(others:%=$(objpfx)%): $(objpfx)libncurses.a
|
||||
endif
|
||||
|
||||
$(test-srcs:%=$(objpfx)%): $(objpfx)libform.a $(objpfx)libmenu.a \
|
||||
$(objpfx)libpanel.a $(objpfx)libncurses.a
|
||||
|
||||
# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
|
||||
# This ensures they will load libc.so for needed symbols if loaded by
|
||||
# a statically-linked program that hasn't already loaded it.
|
||||
$(extras:%=$(objpfx)lib%.so): $(common-objpfx)libc.so
|
||||
|
||||
subdir_install: $(inst_libdir)/libtermcap.a $(inst_libdir)/libcurses.a \
|
||||
$(inst_bindir)/reset $(inst_bindir)/captoinfo
|
||||
|
||||
$(inst_libdir)/libtermcap.a $(inst_libdir)/libcurses.a: \
|
||||
$(inst_libdir)/libncurses.a
|
||||
$(make-link)
|
||||
|
||||
$(inst_bindir)/reset: $(inst_bindir)/tset
|
||||
$(make-link)
|
||||
|
||||
$(inst_bindir)/captoinfo: $(inst_bindir)/tic
|
||||
$(make-link)
|
||||
|
||||
ifeq (yes,$(build-shared))
|
||||
subdir_install: $(inst_libdir)/libtermcap.so $(inst_libdir)/libcurses.so
|
||||
|
||||
$(inst_libdir)/libtermcap.so $(inst_libdir)/libcurses.so: \
|
||||
$(inst_libdir)/libncurses.so
|
||||
$(make-link)
|
||||
endif
|
||||
|
||||
subdir_install: $(inst_mandir)/man5/terminfo.5
|
||||
|
||||
$(inst_mandir)/man5/terminfo.5: $(objpfx)terminfo.5 $(wildcard man/*.[0-9]*)
|
||||
$(make-target-directory)
|
||||
sh $(edit_man-sh) $(prefix) $(inst_mandir) $(edit_man-sed) $^
|
||||
|
||||
subdir_install: $(inst_tabsetdir)/std
|
||||
|
||||
$(inst_tabsetdir)/std: \
|
||||
$(filter-out misc/tabset/CVS, $(wildcard misc/tabset/*))
|
||||
$(make-target-directory)
|
||||
for f in $^; do \
|
||||
echo installing $$f; \
|
||||
$(INSTALL_DATA) $$f $(inst_tabsetdir); \
|
||||
done
|
||||
|
||||
|
||||
ifeq (no,$(cross-compiling))
|
||||
subdir_install: $(inst_terminfodir)/v/vt100
|
||||
|
||||
$(inst_terminfodir)/v/vt100: misc/terminfo.src $(objpfx)tic
|
||||
$(make-target-directory)
|
||||
sh $(run_tic-sh) $(common-objpfx) misc $(terminfodir) \
|
||||
$(install_root)
|
||||
endif
|
||||
|
||||
subdir_distclean subdir_realclean:
|
||||
-rm -f $(addprefix $(objpfx), MKterm.h.awk codes.c \
|
||||
comp_captab.c confdefs.h config.log curses.h \
|
||||
expanded.c fallback.c hashsize.h keys.tries \
|
||||
lib_gen.c lib_keyname.c names.c ncurses_cfg.h \
|
||||
nomacros.h parametrized.h term.h termcap.h \
|
||||
terminfo.5 termsort.c unctrl.c unctrl.h)
|
@ -1,5 +0,0 @@
|
||||
To compile this as an add-on for glibc, unpack it in the glibc source
|
||||
tree and put ncurses on the add-on list when you do configure.
|
||||
|
||||
hjl@gnu.ai.mit.edu
|
||||
03/21/1997
|
@ -1,220 +0,0 @@
|
||||
# $Id: Makefile.in,v 1.64 2002/01/19 20:25:31 NIIBE.Yutaka Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998,1999,2000,2001,2002 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997
|
||||
#
|
||||
# Simple makefile for c++ window class demo
|
||||
|
||||
# turn off _all_ suffix rules; we'll generate our own
|
||||
.SUFFIXES:
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
CF_MFLAGS = @cf_cv_makeflags@
|
||||
@SET_MAKE@
|
||||
x = @PROG_EXT@
|
||||
|
||||
MODEL = ../@DFT_OBJ_SUBDIR@
|
||||
DESTDIR = @DESTDIR@
|
||||
srcdir = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
libdir = @libdir@
|
||||
includedir = @includedir@
|
||||
|
||||
LIBTOOL = @LIBTOOL@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
||||
AR = @AR@
|
||||
AR_OPTS = @AR_OPTS@
|
||||
|
||||
CXX_AR = @CXX_AR@
|
||||
CXX_AR_OPTS = @CXX_AR_OPTS@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
CXX = @CXX@
|
||||
CPP = @CPP@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CXXLIBS = @CXXLIBS@
|
||||
|
||||
INCDIR = ../include
|
||||
CPPFLAGS = -I../c++ -I$(INCDIR) -I$(srcdir) -DHAVE_CONFIG_H @CPPFLAGS@
|
||||
|
||||
CCFLAGS = $(CPPFLAGS) $(CXXFLAGS)
|
||||
|
||||
CFLAGS_LIBTOOL = $(CCFLAGS)
|
||||
CFLAGS_NORMAL = $(CCFLAGS)
|
||||
CFLAGS_DEBUG = $(CCFLAGS) @CXX_G_OPT@ -DTRACE
|
||||
CFLAGS_PROFILE = $(CCFLAGS) -pg
|
||||
CFLAGS_SHARED = $(CCFLAGS) @CC_SHARED_OPTS@
|
||||
|
||||
CFLAGS_DEFAULT = $(CFLAGS_@DFT_UPR_MODEL@)
|
||||
|
||||
NCURSES_MAJOR = @NCURSES_MAJOR@
|
||||
NCURSES_MINOR = @NCURSES_MINOR@
|
||||
REL_VERSION = @cf_cv_rel_version@
|
||||
ABI_VERSION = @cf_cv_abi_version@
|
||||
|
||||
LINK = @LINK_PROGS@ $(LIBTOOL) $(CXX) @CXXLDFLAGS@
|
||||
|
||||
LIBROOT = ncurses++
|
||||
|
||||
LIBNAME_LIBTOOL = @LIB_PREFIX@$(LIBROOT)@LIB_SUFFIX@.la
|
||||
LIBNAME_NORMAL = @LIB_PREFIX@$(LIBROOT)@LIB_SUFFIX@.a
|
||||
LIBNAME = @LIB_PREFIX@$(LIBROOT)@CXX_LIB_SUFFIX@
|
||||
|
||||
LINK_FLAGS = @EXTRA_LDFLAGS@ -L../lib -l$(LIBROOT)@LIB_SUFFIX@
|
||||
|
||||
LINK_LIBTOOL = @EXTRA_LDFLAGS@ -L../lib ../lib/$(LIBNAME)
|
||||
LINK_NORMAL = $(LINK_FLAGS)
|
||||
LINK_DEBUG = $(LINK_FLAGS)
|
||||
LINK_PROFILE = $(LINK_FLAGS)
|
||||
LINK_SHARED = $(LINK_FLAGS)
|
||||
|
||||
LDFLAGS = @TEST_ARGS@ @LDFLAGS@ \
|
||||
@LD_MODEL@ @LIBS@ @EXTRA_LIBS@ @LOCAL_LDFLAGS@ $(CXXLIBS)
|
||||
|
||||
LDFLAGS_LIBTOOL = $(LDFLAGS)
|
||||
LDFLAGS_NORMAL = $(LDFLAGS)
|
||||
LDFLAGS_DEBUG = $(LDFLAGS) @CC_G_OPT@
|
||||
LDFLAGS_PROFILE = $(LDFLAGS) -pg
|
||||
LDFLAGS_SHARED = $(LDFLAGS) @LD_SHARED_OPTS@
|
||||
|
||||
LDFLAGS_DEFAULT = $(LINK_@DFT_UPR_MODEL@) $(LDFLAGS_@DFT_UPR_MODEL@)
|
||||
|
||||
AUTO_SRC = \
|
||||
etip.h
|
||||
|
||||
all \
|
||||
libs :: $(AUTO_SRC) ../lib/$(LIBNAME)
|
||||
|
||||
all :: demo$x
|
||||
|
||||
sources : $(AUTO_SRC)
|
||||
|
||||
depend :
|
||||
|
||||
# Build a conventional library for installing, since a shared library would
|
||||
# pull in all of the ncurses libraries (panel, menu, form, ncurses) as direct
|
||||
# dependencies.
|
||||
LIB_OBJS = \
|
||||
$(MODEL)/cursesf.o \
|
||||
$(MODEL)/cursesm.o \
|
||||
$(MODEL)/cursesw.o \
|
||||
$(MODEL)/cursespad.o \
|
||||
$(MODEL)/cursesp.o \
|
||||
$(MODEL)/cursslk.o \
|
||||
$(MODEL)/cursesapp.o \
|
||||
$(MODEL)/cursesmain.o
|
||||
|
||||
../lib/$(LIBNAME_NORMAL) : $(LIB_OBJS)
|
||||
$(CXX_AR) $(CXX_AR_OPTS) $@ $?
|
||||
$(RANLIB) $@
|
||||
|
||||
../lib/$(LIBNAME_LIBTOOL) : $(LIB_OBJS)
|
||||
cd ../lib && $(LIBTOOL) $(CXX) -o $(LIBNAME) $(LIB_OBJS:.o=.lo) \
|
||||
-rpath $(INSTALL_PREFIX)$(libdir) \
|
||||
-version-info $(NCURSES_MAJOR):$(NCURSES_MINOR)
|
||||
|
||||
OBJS_DEMO = $(MODEL)/demo.o
|
||||
|
||||
$(MODEL)/demo.o : $(srcdir)/demo.cc \
|
||||
$(cursesf_h) $(cursesm_h) $(cursesapp_h)
|
||||
|
||||
demo$x: $(OBJS_DEMO) \
|
||||
../lib/$(LIBNAME) \
|
||||
@TEST_DEPS@
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(OBJS_DEMO) $(LDFLAGS_DEFAULT)
|
||||
|
||||
etip.h: $(srcdir)/etip.h.in $(srcdir)/edit_cfg.sh
|
||||
cp $(srcdir)/etip.h.in $@
|
||||
sh $(srcdir)/edit_cfg.sh ../include/ncurses_cfg.h $@
|
||||
|
||||
$(DESTDIR)$(libdir) :
|
||||
sh $(srcdir)/../mkinstalldirs $@
|
||||
|
||||
install \
|
||||
install.libs:: ../lib/$(LIBNAME) $(DESTDIR)$(libdir)
|
||||
$(LIBTOOL) $(INSTALL) ../lib/$(LIBNAME) $(DESTDIR)$(libdir)/$(LIBNAME)
|
||||
|
||||
uninstall \
|
||||
uninstall.libs::
|
||||
-$(LIBTOOL) rm -f $(DESTDIR)$(libdir)/$(LIBNAME)
|
||||
|
||||
mostlyclean ::
|
||||
-rm -f core tags TAGS *~ *.bak *.i *.ii *.ln *.atac trace
|
||||
|
||||
clean :: mostlyclean
|
||||
-rm -rf $(MODEL)/SunWS_cache
|
||||
-$(LIBTOOL) rm -f demo$x $(AUTO_SRC) ../lib/$(LIBNAME) $(LIB_OBJS) $(LIB_OBJS:.o=.lo) $(OBJS_DEMO)
|
||||
-rm -rf .libs
|
||||
|
||||
distclean :: clean
|
||||
-rm -f Makefile
|
||||
|
||||
realclean :: distclean
|
||||
|
||||
###############################################################################
|
||||
|
||||
cursesw_h = $(srcdir)/cursesw.h \
|
||||
etip.h \
|
||||
$(INCDIR)/curses.h
|
||||
|
||||
cursesp_h = $(srcdir)/cursesp.h \
|
||||
$(cursesw_h) \
|
||||
$(INCDIR)/panel.h
|
||||
|
||||
cursesf_h = $(srcdir)/cursesf.h \
|
||||
$(cursesp_h) \
|
||||
$(INCDIR)/form.h
|
||||
|
||||
cursesm_h = $(srcdir)/cursesm.h \
|
||||
$(cursesp_h) \
|
||||
$(INCDIR)/menu.h
|
||||
|
||||
cursslk_h = $(srcdir)/cursslk.h \
|
||||
$(cursesw_h)
|
||||
|
||||
cursesapp_h = $(srcdir)/cursesapp.h \
|
||||
$(cursslk_h)
|
||||
|
||||
$(INCDIR)/form.h :
|
||||
cd ../form && $(MAKE) $@
|
||||
|
||||
$(INCDIR)/menu.h :
|
||||
cd ../menu && $(MAKE) $@
|
||||
|
||||
$(INCDIR)/panel.h :
|
||||
cd ../panel && $(MAKE) $@
|
||||
|
||||
###############################################################################
|
||||
# The remainder of this file is automatically generated during configuration
|
||||
###############################################################################
|
@ -1,42 +0,0 @@
|
||||
This is a log of changes that the ncurses C++ binding has gone
|
||||
through starting with the integration of menu and forms integration
|
||||
into the binding.
|
||||
|
||||
990731 + Improve support for pads. A viewport window may now be added to
|
||||
a pad. It will then be possible to use a builtin panning mechanism
|
||||
to view the pad.
|
||||
|
||||
970908 + Improve NCursesWindow class: added additional methods to
|
||||
cover more ncurses functionality. Make refresh() and
|
||||
noutrefresh() virtual members to allow different implementation
|
||||
in the NCursesPanel class.
|
||||
+ CAUTION: changed order of parameters in vline() and hline() of
|
||||
NCursesWindow class.
|
||||
+ Make refresh() in NCursesPanel non-static, it is now a
|
||||
reimplementation of refresh() in the base class. Added
|
||||
noutrefresh() to NCursesPanel.
|
||||
+ Added NCursesForm and related classes to support libform
|
||||
functionality.
|
||||
+ Moved most of configuration related stuff from cursesw.h to
|
||||
etip.h
|
||||
+ Added NCursesApplication class to support easy configuration
|
||||
of menu and forms related attributes as well as ripped of
|
||||
title lines and Soft-Label-Keys for an application.
|
||||
+ Support of Auto-Cleanup for a menus fieldlist.
|
||||
+ Change of return type for current_item() and operator[] for
|
||||
menus.
|
||||
+ Enhanced demo.
|
||||
970502
|
||||
+ Introduced the THROW and THROWS functions/macros to prepare
|
||||
a smoother transition to real exception handling.
|
||||
+ Exception classes provided in etip.h
|
||||
+ Added the NCursesMenu class to support libmenu functionality.
|
||||
+ The inheritace relation between NCursesWindow and NCursesColorWindow
|
||||
was kind of brain damage. Monochrome is a special case of colored, so
|
||||
the relation should be just the opposite. This would allow all
|
||||
derived classes like NCursesPanel, NCursesMenu or NCursesForm to
|
||||
have colors.
|
||||
To resolve that design flaw I put the color functionality into the
|
||||
NCursesWindow class and it can be switched on by the static member
|
||||
useColors(). NCursesColorWindow is still there for compatibility
|
||||
reasons.
|
@ -1,5 +0,0 @@
|
||||
This is a list of open problems. This mainly lists known missing pieces
|
||||
and design flaws.
|
||||
|
||||
1. Testing!!!
|
||||
2. Better demo program
|
@ -1,58 +0,0 @@
|
||||
C++ interface to ncurses routines
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
This directory contains the source code for several C++ classes which
|
||||
ease the use of writing ncurses-based programs. The code is derived
|
||||
from the libg++ CursesWindow class but enhanced for ncurses.
|
||||
|
||||
The classes simplify the use of window specific functions by
|
||||
encapsulating them in the window object. Function overloading is
|
||||
used in order to narrow the interface. E.g. you don't have the
|
||||
distinction between `printw' and `mvprintw' anymore.
|
||||
|
||||
A second benefit is the removal of all #defines which are included in
|
||||
the curses.h file. This is a steady cause of trouble because many
|
||||
common identifiers are used. Instead now all #defines are inline
|
||||
functions which also allows strict type checking of arguments.
|
||||
|
||||
The next enhancement is color support. It was originally provided by a
|
||||
derived class. This caused some trouble if you think about Panels or
|
||||
Menus and Forms with colors. We decided to put color support into the
|
||||
base class so that any derived class may use color support also.
|
||||
The implementation chosen here is directed to unrestricted use
|
||||
of mixes of color and monochrome windows. The original NCursesColorWindow
|
||||
class is maintained for compatibility reasons.
|
||||
|
||||
The last point to mention is the support of other packages that are
|
||||
distributed with the ncurses package: the panels library, the menu library
|
||||
and the form library. This support is provided by the NCursesPanel class,
|
||||
which is also derived from the NCursesWindow class and the NCursesMenu
|
||||
and NCursesForm classes which are derived from NCursesPanel. This allows
|
||||
building interfaces with windows.
|
||||
|
||||
Please see the example program for a quick introduction.
|
||||
|
||||
Note that at this point, there is no documentation for these classes.
|
||||
Hopefully some will be written in the not too distant future. For now,
|
||||
to find out how to use the classes, read the code and the example program.
|
||||
|
||||
Suggestions for enhancements and contributions of code (and docs) are
|
||||
welcome. Please let us know which functionality you miss.
|
||||
|
||||
ATTENTION LINUX USERS: There is currently some discussion of
|
||||
replacing the BSD curses in the Linux libc with ncurses. If
|
||||
this is done we could perhaps include these classes in the Linux
|
||||
libg++ replacing the original CursesWindow class (and renaming it
|
||||
to CursesWindow). This could be done because NCursesWindow can
|
||||
be made easily to a superset of the CursesWindow class.
|
||||
|
||||
|
||||
Original author:
|
||||
Eric Newton <newton@rocky.oswego.edu> for FSF's libg++
|
||||
|
||||
Authors of first ncurses based release (NCursesWindow, NCursesPanel):
|
||||
Ulrich Drepper <drepper@ira.uka.de>
|
||||
and Anatoly Ivasyuk <anatoly@nick.csh.rit.edu>
|
||||
|
||||
Author of this release:
|
||||
Juergen Pfeifer <juergen.pfeifer@gmx.net>
|
@ -1,146 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesapp.h"
|
||||
|
||||
MODULE_ID("$Id: cursesapp.cc,v 1.8 2001/03/24 21:25:36 tom Exp $")
|
||||
|
||||
void
|
||||
NCursesApplication::init(bool bColors) {
|
||||
if (bColors)
|
||||
NCursesWindow::useColors();
|
||||
|
||||
if (Root_Window->colors() > 1) {
|
||||
b_Colors = TRUE;
|
||||
Root_Window->setcolor(1);
|
||||
Root_Window->setpalette(COLOR_YELLOW,COLOR_BLUE);
|
||||
Root_Window->setcolor(2);
|
||||
Root_Window->setpalette(COLOR_CYAN,COLOR_BLUE);
|
||||
Root_Window->setcolor(3);
|
||||
Root_Window->setpalette(COLOR_BLACK,COLOR_BLUE);
|
||||
Root_Window->setcolor(4);
|
||||
Root_Window->setpalette(COLOR_BLACK,COLOR_CYAN);
|
||||
Root_Window->setcolor(5);
|
||||
Root_Window->setpalette(COLOR_BLUE,COLOR_YELLOW);
|
||||
Root_Window->setcolor(6);
|
||||
Root_Window->setpalette(COLOR_BLACK,COLOR_GREEN);
|
||||
}
|
||||
else
|
||||
b_Colors = FALSE;
|
||||
|
||||
Root_Window->bkgd(' '|window_backgrounds());
|
||||
}
|
||||
|
||||
NCursesApplication* NCursesApplication::theApp = 0;
|
||||
NCursesWindow* NCursesApplication::titleWindow = 0;
|
||||
NCursesApplication::SLK_Link* NCursesApplication::slk_stack = 0;
|
||||
|
||||
NCursesApplication::~NCursesApplication() {
|
||||
Soft_Label_Key_Set* S;
|
||||
|
||||
delete titleWindow;
|
||||
while( (S=top()) ) {
|
||||
pop();
|
||||
delete S;
|
||||
}
|
||||
delete Root_Window;
|
||||
::endwin();
|
||||
}
|
||||
|
||||
int NCursesApplication::rinit(NCursesWindow& w) {
|
||||
titleWindow = &w;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void NCursesApplication::push(Soft_Label_Key_Set& S) {
|
||||
SLK_Link* L = new SLK_Link;
|
||||
assert(L != 0);
|
||||
L->prev = slk_stack;
|
||||
L->SLKs = &S;
|
||||
slk_stack = L;
|
||||
if (Root_Window)
|
||||
S.show();
|
||||
}
|
||||
|
||||
bool NCursesApplication::pop() {
|
||||
if (slk_stack) {
|
||||
SLK_Link* L = slk_stack;
|
||||
slk_stack = slk_stack->prev;
|
||||
delete L;
|
||||
if (Root_Window && top())
|
||||
top()->show();
|
||||
}
|
||||
return (slk_stack ? FALSE : TRUE);
|
||||
}
|
||||
|
||||
Soft_Label_Key_Set* NCursesApplication::top() const {
|
||||
if (slk_stack)
|
||||
return slk_stack->SLKs;
|
||||
else
|
||||
return (Soft_Label_Key_Set*)0;
|
||||
}
|
||||
|
||||
int NCursesApplication::operator()(void) {
|
||||
bool bColors = b_Colors;
|
||||
Soft_Label_Key_Set* S;
|
||||
|
||||
int ts = titlesize();
|
||||
if (ts>0)
|
||||
NCursesWindow::ripoffline(ts,rinit);
|
||||
Soft_Label_Key_Set::Label_Layout fmt = useSLKs();
|
||||
if (fmt!=Soft_Label_Key_Set::None) {
|
||||
S = new Soft_Label_Key_Set(fmt);
|
||||
assert(S != 0);
|
||||
init_labels(*S);
|
||||
}
|
||||
|
||||
Root_Window = new NCursesWindow(::stdscr);
|
||||
init(bColors);
|
||||
|
||||
if (ts>0)
|
||||
title();
|
||||
if (fmt!=Soft_Label_Key_Set::None) {
|
||||
push(*S);
|
||||
}
|
||||
|
||||
return run();
|
||||
}
|
||||
|
||||
NCursesApplication::NCursesApplication(bool bColors) {
|
||||
b_Colors = bColors;
|
||||
if (theApp)
|
||||
THROW(new NCursesException("Application object already created."));
|
||||
else
|
||||
theApp = this;
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2000 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: cursesapp.h,v 1.7 2001/03/24 21:41:18 tom Exp $
|
||||
|
||||
#ifndef NCURSES_CURSESAPP_H_incl
|
||||
#define NCURSES_CURSESAPP_H_incl
|
||||
|
||||
#include <cursslk.h>
|
||||
|
||||
class NCURSES_IMPEXP NCursesApplication {
|
||||
public:
|
||||
typedef struct _slk_link { // This structure is used to maintain
|
||||
struct _slk_link* prev; // a stack of SLKs
|
||||
Soft_Label_Key_Set* SLKs;
|
||||
} SLK_Link;
|
||||
private:
|
||||
static int rinit(NCursesWindow& w); // Internal Init function for title
|
||||
static NCursesApplication* theApp; // Global ref. to the application
|
||||
|
||||
static SLK_Link* slk_stack;
|
||||
|
||||
protected:
|
||||
static NCursesWindow* titleWindow; // The Title Window (if any)
|
||||
|
||||
bool b_Colors; // Is this a color application?
|
||||
NCursesWindow* Root_Window; // This is the stdscr equiv.
|
||||
|
||||
// Initialization of attributes;
|
||||
// Rewrite this in your derived class if you prefer other settings
|
||||
virtual void init(bool bColors);
|
||||
|
||||
// The number of lines for the title window. Default is no title window
|
||||
// You may rewrite this in your derived class
|
||||
virtual int titlesize() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This method is called to put something into the title window initially
|
||||
// You may rewrite this in your derived class
|
||||
virtual void title() {
|
||||
}
|
||||
|
||||
// The layout used for the Soft Label Keys. Default is to have no SLKs.
|
||||
// You may rewrite this in your derived class
|
||||
virtual Soft_Label_Key_Set::Label_Layout useSLKs() const {
|
||||
return Soft_Label_Key_Set::None;
|
||||
}
|
||||
|
||||
// This method is called to initialize the SLKs. Default is nothing.
|
||||
// You may rewrite this in your derived class
|
||||
virtual void init_labels(Soft_Label_Key_Set& S) const {
|
||||
}
|
||||
|
||||
// Your derived class must implement this method. The return value must
|
||||
// be the exit value of your application.
|
||||
virtual int run() = 0;
|
||||
|
||||
|
||||
// The constructor is protected, so you may use it in your derived
|
||||
// class constructor. The argument tells whether or not you want colors.
|
||||
NCursesApplication(bool wantColors = FALSE);
|
||||
|
||||
public:
|
||||
virtual ~NCursesApplication();
|
||||
|
||||
// Get a pointer to the current application object
|
||||
static NCursesApplication* getApplication() {
|
||||
return theApp;
|
||||
}
|
||||
|
||||
// This method runs the application and returns its exit value
|
||||
int operator()(void);
|
||||
|
||||
// Process the commandline arguments. The default implementation simply
|
||||
// ignores them. Your derived class may rewrite this.
|
||||
virtual void handleArgs(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Does this application use colors?
|
||||
inline bool useColors() const {
|
||||
return b_Colors;
|
||||
}
|
||||
|
||||
// Push the Key Set S onto the SLK Stack. S then becomes the current set
|
||||
// of Soft Labelled Keys.
|
||||
void push(Soft_Label_Key_Set& S);
|
||||
|
||||
// Throw away the current set of SLKs and make the previous one the
|
||||
// new current set.
|
||||
bool pop();
|
||||
|
||||
// Retrieve the current set of Soft Labelled Keys.
|
||||
Soft_Label_Key_Set* top() const;
|
||||
|
||||
// Attributes to use for menu and forms foregrounds
|
||||
virtual chtype foregrounds() const {
|
||||
return b_Colors ? COLOR_PAIR(1) : A_BOLD;
|
||||
}
|
||||
|
||||
// Attributes to use for menu and forms backgrounds
|
||||
virtual chtype backgrounds() const {
|
||||
return b_Colors ? COLOR_PAIR(2) : A_NORMAL;
|
||||
}
|
||||
|
||||
// Attributes to use for inactive (menu) elements
|
||||
virtual chtype inactives() const {
|
||||
return b_Colors ? (COLOR_PAIR(3)|A_DIM) : A_DIM;
|
||||
}
|
||||
|
||||
// Attributes to use for (form) labels and SLKs
|
||||
virtual chtype labels() const {
|
||||
return b_Colors ? COLOR_PAIR(4) : A_NORMAL;
|
||||
}
|
||||
|
||||
// Attributes to use for form backgrounds
|
||||
virtual chtype dialog_backgrounds() const {
|
||||
return b_Colors ? COLOR_PAIR(4) : A_NORMAL;
|
||||
}
|
||||
|
||||
// Attributes to use as default for (form) window backgrounds
|
||||
virtual chtype window_backgrounds() const {
|
||||
return b_Colors ? COLOR_PAIR(5) : A_NORMAL;
|
||||
}
|
||||
|
||||
// Attributes to use for the title window
|
||||
virtual chtype screen_titles() const {
|
||||
return b_Colors ? COLOR_PAIR(6) : A_BOLD;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // NCURSES_CURSESAPP_H_incl
|
@ -1,426 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesf.h"
|
||||
#include "cursesapp.h"
|
||||
|
||||
MODULE_ID("$Id: cursesf.cc,v 1.14 2001/07/14 20:54:43 juergen Exp $")
|
||||
|
||||
NCursesFormField::~NCursesFormField () {
|
||||
if (field)
|
||||
OnError(::free_field (field));
|
||||
}
|
||||
|
||||
/* Construct a FIELD* array from an array of NCursesFormField
|
||||
* objects.
|
||||
*/
|
||||
FIELD**
|
||||
NCursesForm::mapFields(NCursesFormField* nfields[]) {
|
||||
int fieldCount = 0,lcv;
|
||||
FIELD** old_fields;
|
||||
|
||||
assert(nfields != 0);
|
||||
|
||||
for (lcv=0; nfields[lcv]->field; ++lcv)
|
||||
++fieldCount;
|
||||
|
||||
FIELD** fields = new FIELD*[fieldCount + 1];
|
||||
|
||||
for (lcv=0;nfields[lcv]->field;++lcv) {
|
||||
fields[lcv] = nfields[lcv]->field;
|
||||
}
|
||||
fields[lcv] = NULL;
|
||||
|
||||
my_fields = nfields;
|
||||
|
||||
if (form && (old_fields = ::form_fields(form))) {
|
||||
::set_form_fields(form,(FIELD**)0);
|
||||
delete[] old_fields;
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
void NCursesForm::setDefaultAttributes() {
|
||||
NCursesApplication* S = NCursesApplication::getApplication();
|
||||
|
||||
int n = count();
|
||||
if (n > 0) {
|
||||
for(int i=0; i<n; i++) {
|
||||
NCursesFormField* f = (*this)[i];
|
||||
if ((f->options() & (O_EDIT|O_ACTIVE))==(O_EDIT|O_ACTIVE)) {
|
||||
if (S) {
|
||||
f->set_foreground(S->foregrounds());
|
||||
f->set_background(S->backgrounds());
|
||||
}
|
||||
f->set_pad_character('_');
|
||||
}
|
||||
else {
|
||||
if (S)
|
||||
f->set_background(S->labels());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (S) {
|
||||
bkgd(' '|S->dialog_backgrounds());
|
||||
if (sub)
|
||||
sub->bkgd(' '|S->dialog_backgrounds());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::InitForm(NCursesFormField* nfields[],
|
||||
bool with_frame,
|
||||
bool autoDelete_Fields) {
|
||||
int mrows, mcols;
|
||||
|
||||
keypad(TRUE);
|
||||
meta(TRUE);
|
||||
|
||||
b_framed = with_frame;
|
||||
b_autoDelete = autoDelete_Fields;
|
||||
|
||||
form = (FORM*)0;
|
||||
form = ::new_form(mapFields(nfields));
|
||||
if (!form)
|
||||
OnError (E_SYSTEM_ERROR);
|
||||
|
||||
UserHook* hook = new UserHook;
|
||||
hook->m_user = NULL;
|
||||
hook->m_back = this;
|
||||
hook->m_owner = form;
|
||||
::set_form_userptr(form,(void*)hook);
|
||||
|
||||
::set_form_init (form, NCursesForm::frm_init);
|
||||
::set_form_term (form, NCursesForm::frm_term);
|
||||
::set_field_init (form, NCursesForm::fld_init);
|
||||
::set_field_term (form, NCursesForm::fld_term);
|
||||
|
||||
scale(mrows, mcols);
|
||||
::set_form_win(form, w);
|
||||
|
||||
if (with_frame) {
|
||||
if ((mrows > height()-2) || (mcols > width()-2))
|
||||
OnError(E_NO_ROOM);
|
||||
sub = new NCursesWindow(*this,mrows,mcols,1,1,'r');
|
||||
::set_form_sub(form, sub->w);
|
||||
b_sub_owner = TRUE;
|
||||
}
|
||||
else {
|
||||
sub = (NCursesWindow*)0;
|
||||
b_sub_owner = FALSE;
|
||||
}
|
||||
options_on(O_NL_OVERLOAD);
|
||||
setDefaultAttributes();
|
||||
}
|
||||
|
||||
NCursesForm::~NCursesForm() {
|
||||
UserHook* hook = (UserHook*)::form_userptr(form);
|
||||
delete hook;
|
||||
if (b_sub_owner) {
|
||||
delete sub;
|
||||
::set_form_sub(form,(WINDOW *)0);
|
||||
}
|
||||
if (form) {
|
||||
FIELD** fields = ::form_fields(form);
|
||||
int cnt = count();
|
||||
|
||||
OnError(::set_form_fields(form,(FIELD**)0));
|
||||
|
||||
if (b_autoDelete) {
|
||||
if (cnt>0) {
|
||||
for (int i=0; i <= cnt; i++)
|
||||
delete my_fields[i];
|
||||
}
|
||||
delete[] my_fields;
|
||||
}
|
||||
|
||||
::free_form(form);
|
||||
// It's essential to do this after free_form()
|
||||
delete[] fields;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::setSubWindow(NCursesWindow& nsub) {
|
||||
if (!isDescendant(nsub))
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
else {
|
||||
if (b_sub_owner)
|
||||
delete sub;
|
||||
sub = ⊄
|
||||
::set_form_sub(form,sub->w);
|
||||
}
|
||||
}
|
||||
|
||||
/* Internal hook functions. They will route the hook
|
||||
* calls to virtual methods of the NCursesForm class,
|
||||
* so in C++ providing a hook is done simply by
|
||||
* implementing a virtual method in a derived class
|
||||
*/
|
||||
void
|
||||
NCursesForm::frm_init(FORM *f) {
|
||||
getHook(f)->On_Form_Init();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::frm_term(FORM *f) {
|
||||
getHook(f)->On_Form_Termination();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::fld_init(FORM *f) {
|
||||
NCursesForm* F = getHook(f);
|
||||
F->On_Field_Init (*(F->current_field ()));
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::fld_term(FORM *f) {
|
||||
NCursesForm* F = getHook(f);
|
||||
F->On_Field_Termination (*(F->current_field ()));
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::On_Form_Init() {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::On_Form_Termination() {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::On_Field_Init(NCursesFormField& field) {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesForm::On_Field_Termination(NCursesFormField& field) {
|
||||
}
|
||||
|
||||
// call the form driver and do basic error checking.
|
||||
int
|
||||
NCursesForm::driver (int c) {
|
||||
int res = ::form_driver (form, c);
|
||||
switch (res) {
|
||||
case E_OK:
|
||||
case E_REQUEST_DENIED:
|
||||
case E_INVALID_FIELD:
|
||||
case E_UNKNOWN_COMMAND:
|
||||
break;
|
||||
default:
|
||||
OnError (res);
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
void NCursesForm::On_Request_Denied(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
void NCursesForm::On_Invalid_Field(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
void NCursesForm::On_Unknown_Command(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
static const int CMD_QUIT = MAX_COMMAND + 1;
|
||||
|
||||
NCursesFormField*
|
||||
NCursesForm::operator()(void) {
|
||||
int drvCmnd;
|
||||
int err;
|
||||
int c;
|
||||
|
||||
post();
|
||||
show();
|
||||
refresh();
|
||||
|
||||
while (((drvCmnd = virtualize((c=getKey()))) != CMD_QUIT)) {
|
||||
switch((err=driver(drvCmnd))) {
|
||||
case E_REQUEST_DENIED:
|
||||
On_Request_Denied(c);
|
||||
break;
|
||||
case E_INVALID_FIELD:
|
||||
On_Invalid_Field(c);
|
||||
break;
|
||||
case E_UNKNOWN_COMMAND:
|
||||
On_Unknown_Command(c);
|
||||
break;
|
||||
case E_OK:
|
||||
break;
|
||||
default:
|
||||
OnError(err);
|
||||
}
|
||||
}
|
||||
|
||||
unpost();
|
||||
hide();
|
||||
refresh();
|
||||
return my_fields[::field_index (::current_field (form))];
|
||||
}
|
||||
|
||||
// Provide a default key virtualization. Translate the keyboard
|
||||
// code c into a form request code.
|
||||
// The default implementation provides a hopefully straightforward
|
||||
// mapping for the most common keystrokes and form requests.
|
||||
int
|
||||
NCursesForm::virtualize(int c) {
|
||||
switch(c) {
|
||||
|
||||
case KEY_HOME : return(REQ_FIRST_FIELD);
|
||||
case KEY_END : return(REQ_LAST_FIELD);
|
||||
|
||||
case KEY_DOWN : return(REQ_DOWN_CHAR);
|
||||
case KEY_UP : return(REQ_UP_CHAR);
|
||||
case KEY_LEFT : return(REQ_PREV_CHAR);
|
||||
case KEY_RIGHT : return(REQ_NEXT_CHAR);
|
||||
|
||||
case KEY_NPAGE : return(REQ_NEXT_PAGE);
|
||||
case KEY_PPAGE : return(REQ_PREV_PAGE);
|
||||
|
||||
case KEY_BACKSPACE : return(REQ_DEL_PREV);
|
||||
case KEY_ENTER : return(REQ_NEW_LINE);
|
||||
case KEY_CLEAR : return(REQ_CLR_FIELD);
|
||||
|
||||
case CTRL('X') : return(CMD_QUIT); // eXit
|
||||
|
||||
case CTRL('F') : return(REQ_NEXT_FIELD); // Forward
|
||||
case CTRL('B') : return(REQ_PREV_FIELD); // Backward
|
||||
case CTRL('L') : return(REQ_LEFT_FIELD); // Left
|
||||
case CTRL('R') : return(REQ_RIGHT_FIELD); // Right
|
||||
case CTRL('U') : return(REQ_UP_FIELD); // Up
|
||||
case CTRL('D') : return(REQ_DOWN_FIELD); // Down
|
||||
|
||||
case CTRL('W') : return(REQ_NEXT_WORD);
|
||||
case CTRL('T') : return(REQ_PREV_WORD);
|
||||
|
||||
case CTRL('A') : return(REQ_BEG_FIELD);
|
||||
case CTRL('E') : return(REQ_END_FIELD);
|
||||
|
||||
case CTRL('I') : return(REQ_INS_CHAR);
|
||||
case CTRL('M') :
|
||||
case CTRL('J') : return(REQ_NEW_LINE);
|
||||
case CTRL('O') : return(REQ_INS_LINE);
|
||||
case CTRL('V') : return(REQ_DEL_CHAR);
|
||||
case CTRL('H') : return(REQ_DEL_PREV);
|
||||
case CTRL('Y') : return(REQ_DEL_LINE);
|
||||
case CTRL('G') : return(REQ_DEL_WORD);
|
||||
case CTRL('K') : return(REQ_CLR_EOF);
|
||||
|
||||
case CTRL('N') : return(REQ_NEXT_CHOICE);
|
||||
case CTRL('P') : return(REQ_PREV_CHOICE);
|
||||
|
||||
default:
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// User Defined Fieldtypes
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
bool UserDefinedFieldType::fcheck(FIELD *f, const void *u) {
|
||||
NCursesFormField* F = (NCursesFormField*)u;
|
||||
assert(F != 0);
|
||||
UserDefinedFieldType* udf = (UserDefinedFieldType*)(F->fieldtype());
|
||||
assert(udf != 0);
|
||||
return udf->field_check(*F);
|
||||
}
|
||||
|
||||
bool UserDefinedFieldType::ccheck(int c, const void *u) {
|
||||
NCursesFormField* F = (NCursesFormField*)u;
|
||||
assert(F != 0);
|
||||
UserDefinedFieldType* udf =
|
||||
(UserDefinedFieldType*)(F->fieldtype());
|
||||
assert(udf != 0);
|
||||
return udf->char_check(c);
|
||||
}
|
||||
|
||||
void* UserDefinedFieldType::makearg(va_list* va) {
|
||||
return va_arg(*va,NCursesFormField*);
|
||||
}
|
||||
|
||||
FIELDTYPE* UserDefinedFieldType::generic_fieldtype =
|
||||
::new_fieldtype(UserDefinedFieldType::fcheck,
|
||||
UserDefinedFieldType::ccheck);
|
||||
|
||||
FIELDTYPE* UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice =
|
||||
::new_fieldtype(UserDefinedFieldType::fcheck,
|
||||
UserDefinedFieldType::ccheck);
|
||||
|
||||
bool UserDefinedFieldType_With_Choice::next_choice(FIELD *f, const void *u) {
|
||||
NCursesFormField* F = (NCursesFormField*)u;
|
||||
assert(F != 0);
|
||||
UserDefinedFieldType_With_Choice* udf =
|
||||
(UserDefinedFieldType_With_Choice*)(F->fieldtype());
|
||||
assert(udf != 0);
|
||||
return udf->next(*F);
|
||||
}
|
||||
|
||||
bool UserDefinedFieldType_With_Choice::prev_choice(FIELD *f, const void *u) {
|
||||
NCursesFormField* F = (NCursesFormField*)u;
|
||||
assert(F != 0);
|
||||
UserDefinedFieldType_With_Choice* udf =
|
||||
(UserDefinedFieldType_With_Choice*)(F->fieldtype());
|
||||
assert(udf != 0);
|
||||
return udf->previous(*F);
|
||||
}
|
||||
|
||||
class UDF_Init {
|
||||
private:
|
||||
int code;
|
||||
static UDF_Init* I;
|
||||
public:
|
||||
UDF_Init() {
|
||||
code = ::set_fieldtype_arg(UserDefinedFieldType::generic_fieldtype,
|
||||
UserDefinedFieldType::makearg,
|
||||
NULL,
|
||||
NULL);
|
||||
if (code==E_OK)
|
||||
code = ::set_fieldtype_arg
|
||||
(UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice,
|
||||
UserDefinedFieldType::makearg,
|
||||
NULL,
|
||||
NULL);
|
||||
if (code==E_OK)
|
||||
code = ::set_fieldtype_choice
|
||||
(UserDefinedFieldType_With_Choice::generic_fieldtype_with_choice,
|
||||
UserDefinedFieldType_With_Choice::next_choice,
|
||||
UserDefinedFieldType_With_Choice::prev_choice);
|
||||
}
|
||||
};
|
||||
|
||||
UDF_Init* UDF_Init::I = new UDF_Init();
|
||||
|
@ -1,824 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: cursesf.h,v 1.16 2001/07/15 00:02:53 tom Exp $
|
||||
|
||||
#ifndef NCURSES_CURSESF_H_incl
|
||||
#define NCURSES_CURSESF_H_incl 1
|
||||
|
||||
#include <cursesp.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
# include <form.h>
|
||||
}
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// The abstract base class for buitin and user defined Fieldtypes.
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP NCursesFormField; // forward declaration
|
||||
|
||||
// Class to represent builtin field types as well as C++ written new
|
||||
// fieldtypes (see classes UserDefineFieldType...
|
||||
class NCURSES_IMPEXP NCursesFieldType {
|
||||
friend class NCursesFormField;
|
||||
|
||||
protected:
|
||||
FIELDTYPE* fieldtype;
|
||||
|
||||
inline void OnError(int err) const THROWS(NCursesFormException) {
|
||||
if (err!=E_OK)
|
||||
THROW(new NCursesFormException (err));
|
||||
}
|
||||
|
||||
NCursesFieldType(FIELDTYPE *f) : fieldtype(f) {
|
||||
}
|
||||
|
||||
virtual ~NCursesFieldType() {}
|
||||
|
||||
// Set the fields f fieldtype to this one.
|
||||
virtual void set(NCursesFormField& f) = 0;
|
||||
|
||||
public:
|
||||
NCursesFieldType() : fieldtype((FIELDTYPE*)0) {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// The class representing a forms field, wrapping the lowlevel FIELD struct
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP NCursesFormField {
|
||||
friend class NCursesForm;
|
||||
|
||||
protected:
|
||||
FIELD *field; // lowlevel structure
|
||||
NCursesFieldType* ftype; // Associated field type
|
||||
|
||||
// Error handler
|
||||
inline void OnError (int err) const THROWS(NCursesFormException) {
|
||||
if (err != E_OK)
|
||||
THROW(new NCursesFormException (err));
|
||||
}
|
||||
|
||||
public:
|
||||
// Create a 'Null' field. Can be used to delimit a field list
|
||||
NCursesFormField()
|
||||
: field((FIELD*)0), ftype((NCursesFieldType*)0) {
|
||||
}
|
||||
|
||||
// Create a new field
|
||||
NCursesFormField (int rows,
|
||||
int cols,
|
||||
int first_row = 0,
|
||||
int first_col = 0,
|
||||
int offscreen_rows = 0,
|
||||
int additional_buffers = 0)
|
||||
: ftype((NCursesFieldType*)0) {
|
||||
field = ::new_field(rows,cols,first_row,first_col,
|
||||
offscreen_rows, additional_buffers);
|
||||
if (!field)
|
||||
OnError(errno);
|
||||
}
|
||||
|
||||
virtual ~NCursesFormField ();
|
||||
|
||||
// Duplicate the field at a new position
|
||||
inline NCursesFormField* dup(int first_row, int first_col) {
|
||||
NCursesFormField* f = new NCursesFormField();
|
||||
if (!f)
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
else {
|
||||
f->ftype = ftype;
|
||||
f->field = ::dup_field(field,first_row,first_col);
|
||||
if (!f->field)
|
||||
OnError(errno);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
// Link the field to a new location
|
||||
inline NCursesFormField* link(int first_row, int first_col) {
|
||||
NCursesFormField* f = new NCursesFormField();
|
||||
if (!f)
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
else {
|
||||
f->ftype = ftype;
|
||||
f->field = ::link_field(field,first_row,first_col);
|
||||
if (!f->field)
|
||||
OnError(errno);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
// Get the lowlevel field representation
|
||||
inline FIELD* get_field() const {
|
||||
return field;
|
||||
}
|
||||
|
||||
// Retrieve info about the field
|
||||
inline void info(int& rows, int& cols,
|
||||
int& first_row, int& first_col,
|
||||
int& offscreen_rows, int& additional_buffers) const {
|
||||
OnError(::field_info(field, &rows, &cols,
|
||||
&first_row, &first_col,
|
||||
&offscreen_rows, &additional_buffers));
|
||||
}
|
||||
|
||||
// Retrieve info about the fields dynamic properties.
|
||||
inline void dynamic_info(int& dynamic_rows, int& dynamic_cols,
|
||||
int& max_growth) const {
|
||||
OnError(::dynamic_field_info(field, &dynamic_rows, &dynamic_cols,
|
||||
&max_growth));
|
||||
}
|
||||
|
||||
// For a dynamic field you may set the maximum growth limit.
|
||||
// A zero means unlimited growth.
|
||||
inline void set_maximum_growth(int growth = 0) {
|
||||
OnError(::set_max_field(field,growth));
|
||||
}
|
||||
|
||||
// Move the field to a new position
|
||||
inline void move(int row, int col) {
|
||||
OnError(::move_field(field,row,col));
|
||||
}
|
||||
|
||||
// Mark the field to start a new page
|
||||
inline void new_page(bool pageFlag = FALSE) {
|
||||
OnError(::set_new_page(field,pageFlag));
|
||||
}
|
||||
|
||||
// Retrieve whether or not the field starts a new page.
|
||||
inline bool is_new_page() const {
|
||||
return ::new_page(field);
|
||||
}
|
||||
|
||||
// Set the justification for the field
|
||||
inline void set_justification(int just) {
|
||||
OnError(::set_field_just(field,just));
|
||||
}
|
||||
|
||||
// Retrieve the fields justification
|
||||
inline int justification() const {
|
||||
return ::field_just(field);
|
||||
}
|
||||
// Set the foreground attribute for the field
|
||||
inline void set_foreground(chtype fore) {
|
||||
OnError(::set_field_fore(field,fore));
|
||||
}
|
||||
|
||||
// Retrieve the fields foreground attribute
|
||||
inline chtype fore() const {
|
||||
return ::field_fore(field);
|
||||
}
|
||||
|
||||
// Set the background attribute for the field
|
||||
inline void set_background(chtype back) {
|
||||
OnError(::set_field_back(field,back));
|
||||
}
|
||||
|
||||
// Retrieve the fields background attribute
|
||||
inline chtype back() const {
|
||||
return ::field_back(field);
|
||||
}
|
||||
|
||||
// Set the padding character for the field
|
||||
inline void set_pad_character(int pad) {
|
||||
OnError(::set_field_pad(field,pad));
|
||||
}
|
||||
|
||||
// Retrieve the fields padding character
|
||||
inline int pad() const {
|
||||
return ::field_pad(field);
|
||||
}
|
||||
|
||||
// Switch on the fields options
|
||||
inline void options_on (Field_Options options) {
|
||||
OnError (::field_opts_on (field, options));
|
||||
}
|
||||
|
||||
// Switch off the fields options
|
||||
inline void options_off (Field_Options options) {
|
||||
OnError (::field_opts_off (field, options));
|
||||
}
|
||||
|
||||
// Retrieve the fields options
|
||||
inline Field_Options options () const {
|
||||
return ::field_opts (field);
|
||||
}
|
||||
|
||||
// Set the fields options
|
||||
inline void set_options (Field_Options options) {
|
||||
OnError (::set_field_opts (field, options));
|
||||
}
|
||||
|
||||
// Mark the field as changed
|
||||
inline void set_changed(bool changeFlag = TRUE) {
|
||||
OnError(::set_field_status(field,changeFlag));
|
||||
}
|
||||
|
||||
// Test whether or not the field is marked as changed
|
||||
inline bool changed() const {
|
||||
return ::field_status(field);
|
||||
}
|
||||
|
||||
// Return the index of the field in the field array of a form
|
||||
// or -1 if the field is not associated to a form
|
||||
inline int (index)() const {
|
||||
return ::field_index(field);
|
||||
}
|
||||
|
||||
// Store a value in a fields buffer. The default buffer is nr. 0
|
||||
inline void set_value(const char *val, int buffer = 0) {
|
||||
OnError(::set_field_buffer(field,buffer,val));
|
||||
}
|
||||
|
||||
// Retrieve the value of a fields buffer. The default buffer is nr. 0
|
||||
inline char* value(int buffer = 0) const {
|
||||
return ::field_buffer(field,buffer);
|
||||
}
|
||||
|
||||
// Set the validation type of the field.
|
||||
inline void set_fieldtype(NCursesFieldType& f) {
|
||||
ftype = &f;
|
||||
f.set(*this); // A good friend may do that...
|
||||
}
|
||||
|
||||
// Retrieve the validation type of the field.
|
||||
inline NCursesFieldType* fieldtype() const {
|
||||
return ftype;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// The class representing a form, wrapping the lowlevel FORM struct
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP NCursesForm : public NCursesPanel {
|
||||
protected:
|
||||
FORM* form; // the lowlevel structure
|
||||
|
||||
private:
|
||||
NCursesWindow* sub; // the subwindow object
|
||||
bool b_sub_owner; // is this our own subwindow?
|
||||
bool b_framed; // has the form a border?
|
||||
bool b_autoDelete; // Delete fields when deleting form?
|
||||
|
||||
NCursesFormField** my_fields; // The array of fields for this form
|
||||
|
||||
// This structure is used for the form's user data field to link the
|
||||
// FORM* to the C++ object and to provide extra space for a user pointer.
|
||||
typedef struct {
|
||||
void* m_user; // the pointer for the user's data
|
||||
const NCursesForm* m_back; // backward pointer to C++ object
|
||||
const FORM* m_owner;
|
||||
} UserHook;
|
||||
|
||||
// Get the backward pointer to the C++ object from a FORM
|
||||
static inline NCursesForm* getHook(const FORM *f) {
|
||||
UserHook* hook = (UserHook*)::form_userptr(f);
|
||||
assert(hook != 0 && hook->m_owner==f);
|
||||
return (NCursesForm*)(hook->m_back);
|
||||
}
|
||||
|
||||
// This are the built-in hook functions in this C++ binding. In C++ we use
|
||||
// virtual member functions (see below On_..._Init and On_..._Termination)
|
||||
// to provide this functionality in an object oriented manner.
|
||||
static void frm_init(FORM *);
|
||||
static void frm_term(FORM *);
|
||||
static void fld_init(FORM *);
|
||||
static void fld_term(FORM *);
|
||||
|
||||
// Calculate FIELD* array for the menu
|
||||
FIELD** mapFields(NCursesFormField* nfields[]);
|
||||
|
||||
protected:
|
||||
// internal routines
|
||||
inline void set_user(void *user) {
|
||||
UserHook* uptr = (UserHook*)::form_userptr (form);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==form);
|
||||
uptr->m_user = user;
|
||||
}
|
||||
|
||||
inline void *get_user() {
|
||||
UserHook* uptr = (UserHook*)::form_userptr (form);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==form);
|
||||
return uptr->m_user;
|
||||
}
|
||||
|
||||
void InitForm (NCursesFormField* Fields[],
|
||||
bool with_frame,
|
||||
bool autoDeleteFields);
|
||||
|
||||
inline void OnError (int err) const THROWS(NCursesFormException) {
|
||||
if (err != E_OK)
|
||||
THROW(new NCursesFormException (err));
|
||||
}
|
||||
|
||||
// this wraps the form_driver call.
|
||||
virtual int driver (int c) ;
|
||||
|
||||
// 'Internal' constructor, builds an object without association to a
|
||||
// field array.
|
||||
NCursesForm( int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0)
|
||||
: NCursesPanel(lines,cols,begin_y,begin_x),
|
||||
form ((FORM*)0) {
|
||||
}
|
||||
|
||||
public:
|
||||
// Create form for the default panel.
|
||||
NCursesForm (NCursesFormField* Fields[],
|
||||
bool with_frame=FALSE, // reserve space for a frame?
|
||||
bool autoDelete_Fields=FALSE) // do automatic cleanup?
|
||||
: NCursesPanel() {
|
||||
InitForm(Fields, with_frame, autoDelete_Fields);
|
||||
}
|
||||
|
||||
// Create a form in a panel with the given position and size.
|
||||
NCursesForm (NCursesFormField* Fields[],
|
||||
int lines,
|
||||
int cols,
|
||||
int begin_y,
|
||||
int begin_x,
|
||||
bool with_frame=FALSE, // reserve space for a frame?
|
||||
bool autoDelete_Fields=FALSE) // do automatic cleanup?
|
||||
: NCursesPanel(lines, cols, begin_y, begin_x) {
|
||||
InitForm(Fields, with_frame, autoDelete_Fields);
|
||||
}
|
||||
|
||||
virtual ~NCursesForm();
|
||||
|
||||
// Set the default attributes for the form
|
||||
virtual void setDefaultAttributes();
|
||||
|
||||
// Retrieve current field of the form.
|
||||
inline NCursesFormField* current_field() const {
|
||||
return my_fields[::field_index(::current_field(form))];
|
||||
}
|
||||
|
||||
// Set the forms subwindow
|
||||
void setSubWindow(NCursesWindow& sub);
|
||||
|
||||
// Set these fields for the form
|
||||
inline void setFields(NCursesFormField* Fields[]) {
|
||||
OnError(::set_form_fields(form,mapFields(Fields)));
|
||||
}
|
||||
|
||||
// Remove the form from the screen
|
||||
inline void unpost (void) {
|
||||
OnError (::unpost_form (form));
|
||||
}
|
||||
|
||||
// Post the form to the screen if flag is true, unpost it otherwise
|
||||
inline void post(bool flag = TRUE) {
|
||||
OnError (flag ? ::post_form(form) : ::unpost_form (form));
|
||||
}
|
||||
|
||||
// Decorations
|
||||
inline void frame(const char *title=NULL, const char* btitle=NULL) {
|
||||
if (b_framed)
|
||||
NCursesPanel::frame(title,btitle);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
inline void boldframe(const char *title=NULL, const char* btitle=NULL) {
|
||||
if (b_framed)
|
||||
NCursesPanel::boldframe(title,btitle);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
inline void label(const char *topLabel, const char *bottomLabel) {
|
||||
if (b_framed)
|
||||
NCursesPanel::label(topLabel,bottomLabel);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
// -----
|
||||
// Hooks
|
||||
// -----
|
||||
|
||||
// Called after the form gets repositioned in its window.
|
||||
// This is especially true if the form is posted.
|
||||
virtual void On_Form_Init();
|
||||
|
||||
// Called before the form gets repositioned in its window.
|
||||
// This is especially true if the form is unposted.
|
||||
virtual void On_Form_Termination();
|
||||
|
||||
// Called after the field became the current field
|
||||
virtual void On_Field_Init(NCursesFormField& field);
|
||||
|
||||
// Called before this field is left as current field.
|
||||
virtual void On_Field_Termination(NCursesFormField& field);
|
||||
|
||||
// Calculate required window size for the form.
|
||||
void scale(int& rows, int& cols) const {
|
||||
OnError(::scale_form(form,&rows,&cols));
|
||||
}
|
||||
|
||||
// Retrieve number of fields in the form.
|
||||
int count() const {
|
||||
return ::field_count(form);
|
||||
}
|
||||
|
||||
// Make the page the current page of the form.
|
||||
void set_page(int page) {
|
||||
OnError(::set_form_page(form,page));
|
||||
}
|
||||
|
||||
// Retrieve current page number
|
||||
int page() const {
|
||||
return ::form_page(form);
|
||||
}
|
||||
|
||||
// Switch on the forms options
|
||||
inline void options_on (Form_Options options) {
|
||||
OnError (::form_opts_on (form, options));
|
||||
}
|
||||
|
||||
// Switch off the forms options
|
||||
inline void options_off (Form_Options options) {
|
||||
OnError (::form_opts_off (form, options));
|
||||
}
|
||||
|
||||
// Retrieve the forms options
|
||||
inline Form_Options options () const {
|
||||
return ::form_opts (form);
|
||||
}
|
||||
|
||||
// Set the forms options
|
||||
inline void set_options (Form_Options options) {
|
||||
OnError (::set_form_opts (form, options));
|
||||
}
|
||||
|
||||
// Are there more data in the current field after the data shown
|
||||
inline bool data_ahead() const {
|
||||
return ::data_ahead(form);
|
||||
}
|
||||
|
||||
// Are there more data in the current field before the data shown
|
||||
inline bool data_behind() const {
|
||||
return ::data_behind(form);
|
||||
}
|
||||
|
||||
// Position the cursor to the current field
|
||||
inline void position_cursor () {
|
||||
OnError (::pos_form_cursor (form));
|
||||
}
|
||||
// Set the current field
|
||||
inline void set_current(NCursesFormField& F) {
|
||||
OnError (::set_current_field(form, F.field));
|
||||
}
|
||||
|
||||
// Provide a default key virtualization. Translate the keyboard
|
||||
// code c into a form request code.
|
||||
// The default implementation provides a hopefully straightforward
|
||||
// mapping for the most common keystrokes and form requests.
|
||||
virtual int virtualize(int c);
|
||||
|
||||
// Operators
|
||||
inline NCursesFormField* operator[](int i) const {
|
||||
if ( (i < 0) || (i >= ::field_count (form)) )
|
||||
OnError (E_BAD_ARGUMENT);
|
||||
return my_fields[i];
|
||||
}
|
||||
|
||||
// Perform the menu's operation
|
||||
// Return the field where you left the form.
|
||||
virtual NCursesFormField* operator()(void);
|
||||
|
||||
// Exception handlers. The default is a Beep.
|
||||
virtual void On_Request_Denied(int c) const;
|
||||
virtual void On_Invalid_Field(int c) const;
|
||||
virtual void On_Unknown_Command(int c) const;
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// This is the typical C++ typesafe way to allow to attach
|
||||
// user data to a field of a form. Its assumed that the user
|
||||
// data belongs to some class T. Use T as template argument
|
||||
// to create a UserField.
|
||||
// -------------------------------------------------------------------------
|
||||
template<class T> class NCURSES_IMPEXP NCursesUserField : public NCursesFormField
|
||||
{
|
||||
public:
|
||||
NCursesUserField (int rows,
|
||||
int cols,
|
||||
int first_row = 0,
|
||||
int first_col = 0,
|
||||
const T* p_UserData = (T*)0,
|
||||
int offscreen_rows = 0,
|
||||
int additional_buffers = 0)
|
||||
: NCursesFormField (rows, cols,
|
||||
first_row, first_col,
|
||||
offscreen_rows, additional_buffers) {
|
||||
if (field)
|
||||
OnError(::set_field_userptr(field,(void *)p_UserData));
|
||||
}
|
||||
|
||||
virtual ~NCursesUserField() {};
|
||||
|
||||
inline const T* UserData (void) const {
|
||||
return (const T*)::field_userptr (field);
|
||||
}
|
||||
|
||||
inline virtual void setUserData(const T* p_UserData) {
|
||||
if (field)
|
||||
OnError (::set_field_userptr (field, (void *)p_UserData));
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// The same mechanism is used to attach user data to a form
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
template<class T> class NCURSES_IMPEXP NCursesUserForm : public NCursesForm
|
||||
{
|
||||
protected:
|
||||
// 'Internal' constructor, builds an object without association to a
|
||||
// field array.
|
||||
NCursesUserForm( int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
const T* p_UserData = (T*)0)
|
||||
: NCursesForm(lines,cols,begin_y,begin_x) {
|
||||
if (form)
|
||||
set_user ((void *)p_UserData);
|
||||
}
|
||||
|
||||
public:
|
||||
NCursesUserForm (NCursesFormField Fields[],
|
||||
bool with_frame=FALSE,
|
||||
bool autoDelete_Fields=FALSE)
|
||||
: NCursesForm (Fields, with_frame, autoDelete_Fields) {
|
||||
};
|
||||
|
||||
NCursesUserForm (NCursesFormField Fields[],
|
||||
const T* p_UserData = (T*)0,
|
||||
bool with_frame=FALSE,
|
||||
bool autoDelete_Fields=FALSE)
|
||||
: NCursesForm (Fields, with_frame, autoDelete_Fields) {
|
||||
if (form)
|
||||
set_user ((void *)p_UserData);
|
||||
};
|
||||
|
||||
NCursesUserForm (NCursesFormField Fields[],
|
||||
int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
const T* p_UserData = (T*)0,
|
||||
bool with_frame=FALSE,
|
||||
bool autoDelete_Fields=FALSE)
|
||||
: NCursesForm (Fields, lines, cols, begin_y, begin_x,
|
||||
with_frame, autoDelete_Fields) {
|
||||
if (form)
|
||||
set_user ((void *)p_UserData);
|
||||
};
|
||||
|
||||
virtual ~NCursesUserForm() {
|
||||
};
|
||||
|
||||
inline T* UserData (void) const {
|
||||
return (T*)get_user ();
|
||||
};
|
||||
|
||||
inline virtual void setUserData (const T* p_UserData) {
|
||||
if (form)
|
||||
set_user ((void *)p_UserData);
|
||||
}
|
||||
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Builtin Fieldtypes
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP Alpha_Field : public NCursesFieldType {
|
||||
private:
|
||||
int min_field_width;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,min_field_width));
|
||||
}
|
||||
|
||||
public:
|
||||
Alpha_Field(int width)
|
||||
: NCursesFieldType(TYPE_ALPHA),
|
||||
min_field_width(width) {
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP Alphanumeric_Field : public NCursesFieldType {
|
||||
private:
|
||||
int min_field_width;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,min_field_width));
|
||||
}
|
||||
|
||||
public:
|
||||
Alphanumeric_Field(int width)
|
||||
: NCursesFieldType(TYPE_ALNUM),
|
||||
min_field_width(width) {
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP Integer_Field : public NCursesFieldType {
|
||||
private:
|
||||
int precision;
|
||||
long lower_limit, upper_limit;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,
|
||||
precision,lower_limit,upper_limit));
|
||||
}
|
||||
|
||||
public:
|
||||
Integer_Field(int prec, long low=0L, long high=0L)
|
||||
: NCursesFieldType(TYPE_INTEGER),
|
||||
precision(prec), lower_limit(low), upper_limit(high) {
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP Numeric_Field : public NCursesFieldType {
|
||||
private:
|
||||
int precision;
|
||||
double lower_limit, upper_limit;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,
|
||||
precision,lower_limit,upper_limit));
|
||||
}
|
||||
|
||||
public:
|
||||
Numeric_Field(int prec, double low=0.0, double high=0.0)
|
||||
: NCursesFieldType(TYPE_NUMERIC),
|
||||
precision(prec), lower_limit(low), upper_limit(high) {
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP Regular_Expression_Field : public NCursesFieldType {
|
||||
private:
|
||||
char* regex;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,regex));
|
||||
}
|
||||
|
||||
public:
|
||||
Regular_Expression_Field(const char *expr)
|
||||
: NCursesFieldType(TYPE_REGEXP) {
|
||||
regex = new char[1 + ::strlen(expr)];
|
||||
(::strcpy)(regex,expr);
|
||||
}
|
||||
|
||||
~Regular_Expression_Field() {
|
||||
delete[] regex;
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP Enumeration_Field : public NCursesFieldType {
|
||||
private:
|
||||
char** list;
|
||||
int case_sensitive;
|
||||
int non_unique_matches;
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,
|
||||
list,case_sensitive,non_unique_matches));
|
||||
}
|
||||
public:
|
||||
Enumeration_Field(char* enums[],
|
||||
bool case_sens=FALSE,
|
||||
bool non_unique=FALSE)
|
||||
: NCursesFieldType(TYPE_ENUM),
|
||||
list(enums),
|
||||
case_sensitive(case_sens?-1:0),
|
||||
non_unique_matches(non_unique?-1:0) {
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP IPV4_Address_Field : public NCursesFieldType {
|
||||
private:
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype));
|
||||
}
|
||||
|
||||
public:
|
||||
IPV4_Address_Field() : NCursesFieldType(TYPE_IPV4) {
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Abstract base class for User-Defined Fieldtypes
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP UserDefinedFieldType : public NCursesFieldType {
|
||||
friend class UDF_Init; // Internal helper to set up statics
|
||||
private:
|
||||
// For all C++ defined fieldtypes we need only one generic lowlevel
|
||||
// FIELDTYPE* element.
|
||||
static FIELDTYPE* generic_fieldtype;
|
||||
|
||||
protected:
|
||||
// This are the functions required by the low level libforms functions
|
||||
// to construct a fieldtype.
|
||||
static bool fcheck(FIELD *, const void*);
|
||||
static bool ccheck(int c, const void *);
|
||||
static void* makearg(va_list*);
|
||||
|
||||
void set(NCursesFormField& f) {
|
||||
OnError(::set_field_type(f.get_field(),fieldtype,&f));
|
||||
}
|
||||
|
||||
protected:
|
||||
// Redefine this function to do a field validation. The argument
|
||||
// is a reference to the field you should validate.
|
||||
virtual bool field_check(NCursesFormField& f) = 0;
|
||||
|
||||
// Redefine this function to do a character validation. The argument
|
||||
// is the character to be validated.
|
||||
virtual bool char_check (int c) = 0;
|
||||
|
||||
public:
|
||||
UserDefinedFieldType() : NCursesFieldType(generic_fieldtype) {
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Abstract base class for User-Defined Fieldtypes with Choice functions
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP UserDefinedFieldType_With_Choice : public UserDefinedFieldType {
|
||||
friend class UDF_Init; // Internal helper to set up statics
|
||||
private:
|
||||
// For all C++ defined fieldtypes with choice functions we need only one
|
||||
// generic lowlevel FIELDTYPE* element.
|
||||
static FIELDTYPE* generic_fieldtype_with_choice;
|
||||
|
||||
// This are the functions required by the low level libforms functions
|
||||
// to construct a fieldtype with choice functions.
|
||||
static bool next_choice(FIELD*, const void *);
|
||||
static bool prev_choice(FIELD*, const void *);
|
||||
|
||||
protected:
|
||||
// Redefine this function to do the retrieval of the next choice value.
|
||||
// The argument is a reference to the field tobe examined.
|
||||
virtual bool next (NCursesFormField& f) = 0;
|
||||
|
||||
// Redefine this function to do the retrieval of the previous choice value.
|
||||
// The argument is a reference to the field tobe examined.
|
||||
virtual bool previous(NCursesFormField& f) = 0;
|
||||
|
||||
public:
|
||||
UserDefinedFieldType_With_Choice() {
|
||||
fieldtype = generic_fieldtype_with_choice;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NCURSES_CURSESF_H_incl
|
||||
|
@ -1,382 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesm.h"
|
||||
#include "cursesapp.h"
|
||||
|
||||
MODULE_ID("$Id: cursesm.cc,v 1.16 2001/07/14 20:54:43 juergen Exp $")
|
||||
|
||||
NCursesMenuItem::~NCursesMenuItem() {
|
||||
if (item)
|
||||
OnError(::free_item(item));
|
||||
}
|
||||
|
||||
bool
|
||||
NCursesMenuItem::action() {
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
NCursesMenuCallbackItem::~NCursesMenuCallbackItem() {
|
||||
}
|
||||
|
||||
bool
|
||||
NCursesMenuCallbackItem::action() {
|
||||
if (p_fct)
|
||||
return p_fct (*this);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Internal hook functions. They will route the hook
|
||||
* calls to virtual methods of the NCursesMenu class,
|
||||
* so in C++ providing a hook is done simply by
|
||||
* implementing a virtual method in a derived class
|
||||
*/
|
||||
void
|
||||
NCursesMenu::mnu_init(MENU *m) {
|
||||
getHook(m)->On_Menu_Init();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::mnu_term(MENU *m) {
|
||||
getHook(m)->On_Menu_Termination();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::itm_init(MENU *m) {
|
||||
NCursesMenu* M = getHook(m);
|
||||
M->On_Item_Init (*(M->current_item ()));
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::itm_term(MENU *m) {
|
||||
NCursesMenu* M = getHook(m);
|
||||
M->On_Item_Termination (*(M->current_item ()));
|
||||
}
|
||||
|
||||
/* Construct an ITEM* array from an array of NCursesMenuItem
|
||||
* objects.
|
||||
*/
|
||||
ITEM**
|
||||
NCursesMenu::mapItems(NCursesMenuItem* nitems[]) {
|
||||
int itemCount = 0,lcv;
|
||||
|
||||
for (lcv=0; nitems[lcv]->item; ++lcv)
|
||||
++itemCount;
|
||||
|
||||
ITEM** items = new ITEM*[itemCount + 1];
|
||||
|
||||
for (lcv=0;nitems[lcv]->item;++lcv) {
|
||||
items[lcv] = nitems[lcv]->item;
|
||||
}
|
||||
items[lcv] = NULL;
|
||||
|
||||
my_items = nitems;
|
||||
|
||||
if (menu)
|
||||
delete[] ::menu_items(menu);
|
||||
return items;
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::InitMenu(NCursesMenuItem* nitems[],
|
||||
bool with_frame,
|
||||
bool autoDelete_Items) {
|
||||
int mrows, mcols;
|
||||
|
||||
keypad(TRUE);
|
||||
meta(TRUE);
|
||||
|
||||
b_framed = with_frame;
|
||||
b_autoDelete = autoDelete_Items;
|
||||
|
||||
menu = (MENU*)0;
|
||||
menu = ::new_menu(mapItems(nitems));
|
||||
if (!menu)
|
||||
OnError (E_SYSTEM_ERROR);
|
||||
|
||||
UserHook* hook = new UserHook;
|
||||
hook->m_user = NULL;
|
||||
hook->m_back = this;
|
||||
hook->m_owner = menu;
|
||||
::set_menu_userptr(menu,(void*)hook);
|
||||
|
||||
::set_menu_init (menu, NCursesMenu::mnu_init);
|
||||
::set_menu_term (menu, NCursesMenu::mnu_term);
|
||||
::set_item_init (menu, NCursesMenu::itm_init);
|
||||
::set_item_term (menu, NCursesMenu::itm_term);
|
||||
|
||||
scale(mrows, mcols);
|
||||
::set_menu_win(menu, w);
|
||||
|
||||
if (with_frame) {
|
||||
if ((mrows > height()-2) || (mcols > width()-2))
|
||||
OnError(E_NO_ROOM);
|
||||
sub = new NCursesWindow(*this,mrows,mcols,1,1,'r');
|
||||
::set_menu_sub(menu, sub->w);
|
||||
b_sub_owner = TRUE;
|
||||
}
|
||||
else {
|
||||
sub = (NCursesWindow*)0;
|
||||
b_sub_owner = FALSE;
|
||||
}
|
||||
setDefaultAttributes();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::setDefaultAttributes() {
|
||||
NCursesApplication* S = NCursesApplication::getApplication();
|
||||
if (S) {
|
||||
::set_menu_fore(menu, S->foregrounds());
|
||||
::set_menu_back(menu, S->backgrounds());
|
||||
::set_menu_grey(menu, S->inactives());
|
||||
}
|
||||
}
|
||||
|
||||
NCursesMenu::~NCursesMenu() {
|
||||
UserHook* hook = (UserHook*)::menu_userptr(menu);
|
||||
delete hook;
|
||||
if (b_sub_owner) {
|
||||
delete sub;
|
||||
::set_menu_sub(menu,(WINDOW *)0);
|
||||
}
|
||||
if (menu) {
|
||||
ITEM** itms = ::menu_items(menu);
|
||||
int cnt = count();
|
||||
|
||||
OnError(::set_menu_items(menu,(ITEM**)0));
|
||||
|
||||
if (b_autoDelete) {
|
||||
if (cnt>0) {
|
||||
for (int i=0; i <= cnt; i++)
|
||||
delete my_items[i];
|
||||
}
|
||||
delete[] my_items;
|
||||
}
|
||||
|
||||
::free_menu(menu);
|
||||
// It's essential to do this after free_menu()
|
||||
delete[] itms;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::setSubWindow(NCursesWindow& nsub) {
|
||||
if (!isDescendant(nsub))
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
else {
|
||||
if (b_sub_owner)
|
||||
delete sub;
|
||||
sub = ⊄
|
||||
::set_menu_sub(menu,sub->w);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
NCursesMenu::set_pattern (const char *pat) {
|
||||
int res = ::set_menu_pattern (menu, pat);
|
||||
switch(res) {
|
||||
case E_OK:
|
||||
break;
|
||||
case E_NO_MATCH:
|
||||
return FALSE;
|
||||
default:
|
||||
OnError (res);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// call the menu driver and do basic error checking.
|
||||
int
|
||||
NCursesMenu::driver (int c) {
|
||||
int res = ::menu_driver (menu, c);
|
||||
switch (res) {
|
||||
case E_OK:
|
||||
case E_REQUEST_DENIED:
|
||||
case E_NOT_SELECTABLE:
|
||||
case E_UNKNOWN_COMMAND:
|
||||
case E_NO_MATCH:
|
||||
break;
|
||||
default:
|
||||
OnError (res);
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
static const int CMD_QUIT = MAX_COMMAND + 1;
|
||||
static const int CMD_ACTION = MAX_COMMAND + 2;
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Provide a default key virtualization. Translate the keyboard
|
||||
// code c into a menu request code.
|
||||
// The default implementation provides a hopefully straightforward
|
||||
// mapping for the most common keystrokes and menu requests.
|
||||
// -------------------------------------------------------------------------
|
||||
int
|
||||
NCursesMenu::virtualize(int c) {
|
||||
switch(c) {
|
||||
case CTRL('X') : return(CMD_QUIT); // eXit
|
||||
|
||||
case KEY_DOWN : return(REQ_DOWN_ITEM);
|
||||
case CTRL('N') : return(REQ_NEXT_ITEM); // Next
|
||||
case KEY_UP : return(REQ_UP_ITEM);
|
||||
case CTRL('P') : return(REQ_PREV_ITEM); // Previous
|
||||
|
||||
case CTRL('U') : return(REQ_SCR_ULINE); // Up
|
||||
case CTRL('D') : return(REQ_SCR_DLINE); // Down
|
||||
case CTRL('F') : return(REQ_SCR_DPAGE); // Forward
|
||||
case CTRL('B') : return(REQ_SCR_UPAGE); // Backward
|
||||
|
||||
case CTRL('Y') : return(REQ_CLEAR_PATTERN);
|
||||
case CTRL('H') : return(REQ_BACK_PATTERN);
|
||||
case CTRL('A') : return(REQ_NEXT_MATCH);
|
||||
case CTRL('E') : return(REQ_PREV_MATCH);
|
||||
case CTRL('T') : return(REQ_TOGGLE_ITEM);
|
||||
|
||||
case CTRL('J') :
|
||||
case CTRL('M') : return(CMD_ACTION);
|
||||
|
||||
case KEY_HOME : return(REQ_FIRST_ITEM);
|
||||
case KEY_LEFT : return(REQ_LEFT_ITEM);
|
||||
case KEY_RIGHT : return(REQ_RIGHT_ITEM);
|
||||
case KEY_END : return(REQ_LAST_ITEM);
|
||||
case KEY_BACKSPACE : return(REQ_BACK_PATTERN);
|
||||
case KEY_NPAGE : return(REQ_SCR_DPAGE);
|
||||
case KEY_PPAGE : return(REQ_SCR_UPAGE);
|
||||
|
||||
default:
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
NCursesMenuItem*
|
||||
NCursesMenu::operator()(void) {
|
||||
int drvCmnd;
|
||||
int err;
|
||||
int c;
|
||||
bool b_action = FALSE;
|
||||
|
||||
post();
|
||||
show();
|
||||
refresh();
|
||||
|
||||
while (!b_action && ((drvCmnd = virtualize((c=getKey()))) != CMD_QUIT)) {
|
||||
|
||||
switch((err=driver(drvCmnd))) {
|
||||
case E_REQUEST_DENIED:
|
||||
On_Request_Denied(c);
|
||||
break;
|
||||
case E_NOT_SELECTABLE:
|
||||
On_Not_Selectable(c);
|
||||
break;
|
||||
case E_UNKNOWN_COMMAND:
|
||||
if (drvCmnd == CMD_ACTION) {
|
||||
if (options() & O_ONEVALUE) {
|
||||
NCursesMenuItem* itm = current_item();
|
||||
assert(itm != 0);
|
||||
if (itm->options() & O_SELECTABLE)
|
||||
{
|
||||
b_action = itm->action();
|
||||
refresh();
|
||||
}
|
||||
else
|
||||
On_Not_Selectable(c);
|
||||
}
|
||||
else {
|
||||
int n = count();
|
||||
for(int i=0; i<n; i++) {
|
||||
NCursesMenuItem* itm = my_items[i];
|
||||
if (itm->value()) {
|
||||
b_action |= itm->action();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
On_Unknown_Command(c);
|
||||
break;
|
||||
case E_NO_MATCH:
|
||||
On_No_Match(c);
|
||||
break;
|
||||
case E_OK:
|
||||
break;
|
||||
default:
|
||||
OnError(err);
|
||||
}
|
||||
}
|
||||
|
||||
unpost();
|
||||
hide();
|
||||
refresh();
|
||||
if (options() & O_ONEVALUE)
|
||||
return my_items[::item_index (::current_item (menu))];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Menu_Init() {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Menu_Termination() {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Item_Init(NCursesMenuItem& item) {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Item_Termination(NCursesMenuItem& item) {
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Request_Denied(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Not_Selectable(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_No_Match(int c) const {
|
||||
::beep();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesMenu::On_Unknown_Command(int c) const {
|
||||
::beep();
|
||||
}
|
@ -1,592 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: cursesm.h,v 1.15 2001/03/24 21:41:28 tom Exp $
|
||||
|
||||
#ifndef NCURSES_CURSESM_H_incl
|
||||
#define NCURSES_CURSESM_H_incl 1
|
||||
|
||||
#include <cursesp.h>
|
||||
|
||||
extern "C" {
|
||||
# include <menu.h>
|
||||
}
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// This wraps the ITEM type of <menu.h>
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP NCursesMenuItem {
|
||||
friend class NCursesMenu;
|
||||
|
||||
protected:
|
||||
ITEM *item;
|
||||
|
||||
inline void OnError (int err) const THROWS(NCursesMenuException) {
|
||||
if (err != E_OK)
|
||||
THROW(new NCursesMenuException (err));
|
||||
}
|
||||
|
||||
public:
|
||||
NCursesMenuItem (const char* p_name = NULL,
|
||||
const char* p_descript = NULL ) {
|
||||
item = p_name ? ::new_item (p_name, p_descript) : (ITEM*)0;
|
||||
if (p_name && !item)
|
||||
OnError (E_SYSTEM_ERROR);
|
||||
}
|
||||
// Create an item. If you pass both parameters as NULL, a delimiting
|
||||
// item is constructed which can be used to terminate a list of
|
||||
// NCursesMenu objects.
|
||||
|
||||
virtual ~NCursesMenuItem ();
|
||||
// Release the items memory
|
||||
|
||||
inline const char* name () const {
|
||||
return ::item_name (item);
|
||||
}
|
||||
// Name of the item
|
||||
|
||||
inline const char* description () const {
|
||||
return ::item_description (item);
|
||||
}
|
||||
// Description of the item
|
||||
|
||||
inline int (index) (void) const {
|
||||
return ::item_index (item);
|
||||
}
|
||||
// Index of the item in an item array (or -1)
|
||||
|
||||
inline void options_on (Item_Options options) {
|
||||
OnError (::item_opts_on (item, options));
|
||||
}
|
||||
// Switch on the items options
|
||||
|
||||
inline void options_off (Item_Options options) {
|
||||
OnError (::item_opts_off (item, options));
|
||||
}
|
||||
// Switch off the item's option
|
||||
|
||||
inline Item_Options options () const {
|
||||
return ::item_opts (item);
|
||||
}
|
||||
// Retrieve the items options
|
||||
|
||||
inline void set_options (Item_Options options) {
|
||||
OnError (::set_item_opts (item, options));
|
||||
}
|
||||
// Set the items options
|
||||
|
||||
inline void set_value (bool f) {
|
||||
OnError (::set_item_value (item,f));
|
||||
}
|
||||
// Set/Reset the items selection state
|
||||
|
||||
inline bool value () const {
|
||||
return ::item_value (item);
|
||||
}
|
||||
// Retrieve the items selection state
|
||||
|
||||
inline bool visible () const {
|
||||
return ::item_visible (item);
|
||||
}
|
||||
// Retrieve visibility of the item
|
||||
|
||||
virtual bool action();
|
||||
// Perform an action associated with this item; you may use this in an
|
||||
// user supplied driver for a menu; you may derive from this class and
|
||||
// overload action() to supply items with different actions.
|
||||
// If an action returns true, the menu will be exited. The default action
|
||||
// is to do nothing.
|
||||
};
|
||||
|
||||
// Prototype for an items callback function.
|
||||
typedef bool ITEMCALLBACK(NCursesMenuItem&);
|
||||
|
||||
// If you don't like to create a child class for individual items to
|
||||
// overload action(), you may use this class and provide a callback
|
||||
// function pointer for items.
|
||||
class NCURSES_IMPEXP NCursesMenuCallbackItem : public NCursesMenuItem {
|
||||
private:
|
||||
ITEMCALLBACK* p_fct;
|
||||
|
||||
public:
|
||||
NCursesMenuCallbackItem(ITEMCALLBACK* fct = NULL,
|
||||
const char* p_name = NULL,
|
||||
const char* p_descript = NULL )
|
||||
: NCursesMenuItem (p_name, p_descript),
|
||||
p_fct (fct) {
|
||||
}
|
||||
|
||||
virtual ~NCursesMenuCallbackItem();
|
||||
|
||||
bool action();
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// This wraps the MENU type of <menu.h>
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class NCURSES_IMPEXP NCursesMenu : public NCursesPanel {
|
||||
protected:
|
||||
MENU *menu;
|
||||
|
||||
private:
|
||||
NCursesWindow* sub; // the subwindow object
|
||||
bool b_sub_owner; // is this our own subwindow?
|
||||
bool b_framed; // has the menu a border?
|
||||
bool b_autoDelete; // Delete items when deleting menu?
|
||||
|
||||
NCursesMenuItem** my_items; // The array of items for this menu
|
||||
|
||||
// This structure is used for the menu's user data field to link the
|
||||
// MENU* to the C++ object and to provide extra space for a user pointer.
|
||||
typedef struct {
|
||||
void* m_user; // the pointer for the user's data
|
||||
const NCursesMenu* m_back; // backward pointer to C++ object
|
||||
const MENU* m_owner;
|
||||
} UserHook;
|
||||
|
||||
// Get the backward pointer to the C++ object from a MENU
|
||||
static inline NCursesMenu* getHook(const MENU *m) {
|
||||
UserHook* hook = (UserHook*)::menu_userptr(m);
|
||||
assert(hook != 0 && hook->m_owner==m);
|
||||
return (NCursesMenu*)(hook->m_back);
|
||||
}
|
||||
|
||||
// This are the built-in hook functions in this C++ binding. In C++ we use
|
||||
// virtual member functions (see below On_..._Init and On_..._Termination)
|
||||
// to provide this functionality in an object oriented manner.
|
||||
static void mnu_init(MENU *);
|
||||
static void mnu_term(MENU *);
|
||||
static void itm_init(MENU *);
|
||||
static void itm_term(MENU *);
|
||||
|
||||
// Calculate ITEM* array for the menu
|
||||
ITEM** mapItems(NCursesMenuItem* nitems[]);
|
||||
|
||||
protected:
|
||||
// internal routines
|
||||
inline void set_user(void *user) {
|
||||
UserHook* uptr = (UserHook*)::menu_userptr (menu);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==menu);
|
||||
uptr->m_user = user;
|
||||
}
|
||||
|
||||
inline void *get_user() {
|
||||
UserHook* uptr = (UserHook*)::menu_userptr (menu);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==menu);
|
||||
return uptr->m_user;
|
||||
}
|
||||
|
||||
void InitMenu (NCursesMenuItem* menu[],
|
||||
bool with_frame,
|
||||
bool autoDeleteItems);
|
||||
|
||||
inline void OnError (int err) const THROWS(NCursesMenuException) {
|
||||
if (err != E_OK)
|
||||
THROW(new NCursesMenuException (this, err));
|
||||
}
|
||||
|
||||
// this wraps the menu_driver call.
|
||||
virtual int driver (int c) ;
|
||||
|
||||
// 'Internal' constructor to create a menu without association to
|
||||
// an array of items.
|
||||
NCursesMenu( int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0)
|
||||
: NCursesPanel(lines,cols,begin_y,begin_x),
|
||||
menu ((MENU*)0) {
|
||||
}
|
||||
|
||||
public:
|
||||
// Make a full window size menu
|
||||
NCursesMenu (NCursesMenuItem* Items[],
|
||||
bool with_frame=FALSE, // Reserve space for a frame?
|
||||
bool autoDelete_Items=FALSE) // Autocleanup of Items?
|
||||
: NCursesPanel() {
|
||||
InitMenu(Items, with_frame, autoDelete_Items);
|
||||
}
|
||||
|
||||
// Make a menu with a window of this size.
|
||||
NCursesMenu (NCursesMenuItem* Items[],
|
||||
int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
bool with_frame=FALSE, // Reserve space for a frame?
|
||||
bool autoDelete_Items=FALSE) // Autocleanup of Items?
|
||||
: NCursesPanel(lines, cols, begin_y, begin_x) {
|
||||
InitMenu(Items, with_frame, autoDelete_Items);
|
||||
}
|
||||
|
||||
virtual ~NCursesMenu ();
|
||||
|
||||
// Retrieve the menus subwindow
|
||||
inline NCursesWindow& subWindow() const {
|
||||
assert(sub!=NULL);
|
||||
return *sub;
|
||||
}
|
||||
|
||||
// Set the menus subwindow
|
||||
void setSubWindow(NCursesWindow& sub);
|
||||
|
||||
// Set these items for the menu
|
||||
inline void setItems(NCursesMenuItem* Items[]) {
|
||||
OnError(::set_menu_items(menu,mapItems(Items)));
|
||||
}
|
||||
|
||||
// Remove the menu from the screen
|
||||
inline void unpost (void) {
|
||||
OnError (::unpost_menu (menu));
|
||||
}
|
||||
|
||||
// Post the menu to the screen if flag is true, unpost it otherwise
|
||||
inline void post(bool flag = TRUE) {
|
||||
flag ? OnError (::post_menu(menu)) : OnError (::unpost_menu (menu));
|
||||
}
|
||||
|
||||
// Get the numer of rows and columns for this menu
|
||||
inline void scale (int& mrows, int& mcols) const {
|
||||
OnError (::scale_menu (menu, &mrows, &mcols));
|
||||
}
|
||||
|
||||
// Set the format of this menu
|
||||
inline void set_format(int mrows, int mcols) {
|
||||
OnError (::set_menu_format(menu, mrows, mcols));
|
||||
}
|
||||
|
||||
// Get the format of this menu
|
||||
inline void menu_format(int& rows,int& cols) {
|
||||
::menu_format(menu,&rows,&cols);
|
||||
}
|
||||
|
||||
// Items of the menu
|
||||
inline NCursesMenuItem* items() const {
|
||||
return *my_items;
|
||||
}
|
||||
|
||||
// Get the number of items in this menu
|
||||
inline int count() const {
|
||||
return ::item_count(menu);
|
||||
}
|
||||
|
||||
// Get the current item (i.e. the one the cursor is located)
|
||||
inline NCursesMenuItem* current_item() const {
|
||||
return my_items[::item_index(::current_item(menu))];
|
||||
}
|
||||
|
||||
// Get the marker string
|
||||
inline const char* mark() const {
|
||||
return ::menu_mark(menu);
|
||||
}
|
||||
|
||||
// Set the marker string
|
||||
inline void set_mark(const char *mark) {
|
||||
OnError (::set_menu_mark (menu, mark));
|
||||
}
|
||||
|
||||
// Get the name of the request code c
|
||||
inline static const char* request_name(int c) {
|
||||
return ::menu_request_name(c);
|
||||
}
|
||||
|
||||
// Get the current pattern
|
||||
inline char* pattern() const {
|
||||
return ::menu_pattern(menu);
|
||||
}
|
||||
|
||||
// true if there is a pattern match, false otherwise.
|
||||
bool set_pattern (const char *pat);
|
||||
|
||||
// set the default attributes for the menu
|
||||
// i.e. set fore, back and grey attribute
|
||||
virtual void setDefaultAttributes();
|
||||
|
||||
// Get the menus background attributes
|
||||
inline chtype back() const {
|
||||
return ::menu_back(menu);
|
||||
}
|
||||
|
||||
// Get the menus foreground attributes
|
||||
inline chtype fore() const {
|
||||
return ::menu_fore(menu);
|
||||
}
|
||||
|
||||
// Get the menus grey attributes (used for unselectable items)
|
||||
inline chtype grey() const {
|
||||
return ::menu_grey(menu);
|
||||
}
|
||||
|
||||
// Set the menus background attributes
|
||||
inline chtype set_background(chtype a) {
|
||||
return ::set_menu_back(menu,a);
|
||||
}
|
||||
|
||||
// Set the menus foreground attributes
|
||||
inline chtype set_foreground(chtype a) {
|
||||
return ::set_menu_fore(menu,a);
|
||||
}
|
||||
|
||||
// Set the menus grey attributes (used for unselectable items)
|
||||
inline chtype set_grey(chtype a) {
|
||||
return ::set_menu_grey(menu,a);
|
||||
}
|
||||
|
||||
inline void options_on (Menu_Options opts) {
|
||||
OnError (::menu_opts_on (menu,opts));
|
||||
}
|
||||
|
||||
inline void options_off(Menu_Options opts) {
|
||||
OnError (::menu_opts_off(menu,opts));
|
||||
}
|
||||
|
||||
inline Menu_Options options() const {
|
||||
return ::menu_opts(menu);
|
||||
}
|
||||
|
||||
inline void set_options (Menu_Options opts) {
|
||||
OnError (::set_menu_opts (menu,opts));
|
||||
}
|
||||
|
||||
inline int pad() const {
|
||||
return ::menu_pad(menu);
|
||||
}
|
||||
|
||||
inline void set_pad (int padch) {
|
||||
OnError (::set_menu_pad (menu, padch));
|
||||
}
|
||||
|
||||
// Position the cursor to the current item
|
||||
inline void position_cursor () const {
|
||||
OnError (::pos_menu_cursor (menu));
|
||||
}
|
||||
|
||||
// Set the current item
|
||||
inline void set_current(NCursesMenuItem& I) {
|
||||
OnError (::set_current_item(menu, I.item));
|
||||
}
|
||||
|
||||
// Get the current top row of the menu
|
||||
inline int top_row (void) const {
|
||||
return ::top_row (menu);
|
||||
}
|
||||
|
||||
// Set the current top row of the menu
|
||||
inline void set_top_row (int row) {
|
||||
OnError (::set_top_row (menu, row));
|
||||
}
|
||||
|
||||
// spacing control
|
||||
// Set the spacing for the menu
|
||||
inline void setSpacing(int spc_description,
|
||||
int spc_rows,
|
||||
int spc_columns) {
|
||||
OnError(::set_menu_spacing(menu,
|
||||
spc_description,
|
||||
spc_rows,
|
||||
spc_columns));
|
||||
}
|
||||
|
||||
// Get the spacing info for the menu
|
||||
inline void Spacing(int& spc_description,
|
||||
int& spc_rows,
|
||||
int& spc_columns) const {
|
||||
OnError(::menu_spacing(menu,
|
||||
&spc_description,
|
||||
&spc_rows,
|
||||
&spc_columns));
|
||||
}
|
||||
|
||||
// Decorations
|
||||
inline void frame(const char *title=NULL, const char* btitle=NULL) {
|
||||
if (b_framed)
|
||||
NCursesPanel::frame(title,btitle);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
inline void boldframe(const char *title=NULL, const char* btitle=NULL) {
|
||||
if (b_framed)
|
||||
NCursesPanel::boldframe(title,btitle);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
inline void label(const char *topLabel, const char *bottomLabel) {
|
||||
if (b_framed)
|
||||
NCursesPanel::label(topLabel,bottomLabel);
|
||||
else
|
||||
OnError(E_SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
// -----
|
||||
// Hooks
|
||||
// -----
|
||||
|
||||
// Called after the menu gets repositioned in its window.
|
||||
// This is especially true if the menu is posted.
|
||||
virtual void On_Menu_Init();
|
||||
|
||||
// Called before the menu gets repositioned in its window.
|
||||
// This is especially true if the menu is unposted.
|
||||
virtual void On_Menu_Termination();
|
||||
|
||||
// Called after the item became the current item
|
||||
virtual void On_Item_Init(NCursesMenuItem& item);
|
||||
|
||||
// Called before this item is left as current item.
|
||||
virtual void On_Item_Termination(NCursesMenuItem& item);
|
||||
|
||||
// Provide a default key virtualization. Translate the keyboard
|
||||
// code c into a menu request code.
|
||||
// The default implementation provides a hopefully straightforward
|
||||
// mapping for the most common keystrokes and menu requests.
|
||||
virtual int virtualize(int c);
|
||||
|
||||
|
||||
// Operators
|
||||
inline NCursesMenuItem* operator[](int i) const {
|
||||
if ( (i < 0) || (i >= ::item_count (menu)) )
|
||||
OnError (E_BAD_ARGUMENT);
|
||||
return (my_items[i]);
|
||||
}
|
||||
|
||||
// Perform the menu's operation
|
||||
// Return the item where you left the selection mark for a single
|
||||
// selection menu, or NULL for a multivalued menu.
|
||||
virtual NCursesMenuItem* operator()(void);
|
||||
|
||||
// --------------------
|
||||
// Exception handlers
|
||||
// Called by operator()
|
||||
// --------------------
|
||||
|
||||
// Called if the request is denied
|
||||
virtual void On_Request_Denied(int c) const;
|
||||
|
||||
// Called if the item is not selectable
|
||||
virtual void On_Not_Selectable(int c) const;
|
||||
|
||||
// Called if pattern doesn't match
|
||||
virtual void On_No_Match(int c) const;
|
||||
|
||||
// Called if the command is unknown
|
||||
virtual void On_Unknown_Command(int c) const;
|
||||
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// This is the typical C++ typesafe way to allow to attach
|
||||
// user data to an item of a menu. Its assumed that the user
|
||||
// data belongs to some class T. Use T as template argument
|
||||
// to create a UserItem.
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
template<class T> class NCURSES_IMPEXP NCursesUserItem : public NCursesMenuItem
|
||||
{
|
||||
public:
|
||||
NCursesUserItem (const char* p_name,
|
||||
const char* p_descript = NULL,
|
||||
const T* p_UserData = (T*)0)
|
||||
: NCursesMenuItem (p_name, p_descript) {
|
||||
if (item)
|
||||
OnError (::set_item_userptr (item, (void *)p_UserData));
|
||||
};
|
||||
|
||||
virtual ~NCursesUserItem() {};
|
||||
|
||||
inline const T* UserData (void) const {
|
||||
return (const T*)::item_userptr (item);
|
||||
};
|
||||
|
||||
inline virtual void setUserData(const T* p_UserData) {
|
||||
if (item)
|
||||
OnError (::set_item_userptr (item, (void *)p_UserData));
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// The same mechanism is used to attach user data to a menu
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
template<class T> class NCURSES_IMPEXP NCursesUserMenu : public NCursesMenu
|
||||
{
|
||||
protected:
|
||||
NCursesUserMenu( int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
const T* p_UserData = (T*)0)
|
||||
: NCursesMenu(lines,cols,begin_y,begin_x) {
|
||||
if (menu)
|
||||
set_user ((void *)p_UserData);
|
||||
}
|
||||
|
||||
public:
|
||||
NCursesUserMenu (NCursesMenuItem Items[],
|
||||
const T* p_UserData = (T*)0,
|
||||
bool with_frame=FALSE,
|
||||
bool autoDelete_Items=FALSE)
|
||||
: NCursesMenu (Items, with_frame, autoDelete_Items) {
|
||||
if (menu)
|
||||
set_user ((void *)p_UserData);
|
||||
};
|
||||
|
||||
NCursesUserMenu (NCursesMenuItem Items[],
|
||||
int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
const T* p_UserData = (T*)0,
|
||||
bool with_frame=FALSE)
|
||||
: NCursesMenu (Items, lines, cols, begin_y, begin_x, with_frame) {
|
||||
if (menu)
|
||||
set_user ((void *)p_UserData);
|
||||
};
|
||||
|
||||
virtual ~NCursesUserMenu() {
|
||||
};
|
||||
|
||||
inline T* UserData (void) const {
|
||||
return (T*)get_user ();
|
||||
};
|
||||
|
||||
inline virtual void setUserData (const T* p_UserData) {
|
||||
if (menu)
|
||||
set_user ((void *)p_UserData);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NCURSES_CURSESM_H_incl
|
@ -1,57 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesapp.h"
|
||||
|
||||
MODULE_ID("$Id: cursesmain.cc,v 1.8 2001/07/14 20:54:43 juergen Exp $")
|
||||
|
||||
/* This is the default implementation of main() for a NCursesApplication.
|
||||
* You only have to instantiate a static NCursesApplication object in your
|
||||
* main application source file and link this module with your application.
|
||||
*/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
NCursesApplication* A = NCursesApplication::getApplication();
|
||||
if (!A)
|
||||
return(1);
|
||||
else {
|
||||
int res;
|
||||
|
||||
A->handleArgs(argc,argv);
|
||||
::endwin();
|
||||
res = (*A)();
|
||||
::endwin();
|
||||
return(res);
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1993,1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesp.h"
|
||||
#include <string.h>
|
||||
|
||||
MODULE_ID("$Id: cursesp.cc,v 1.19 2001/07/14 20:54:43 juergen Exp $")
|
||||
|
||||
NCursesPanel* NCursesPanel::dummy = (NCursesPanel*)0;
|
||||
|
||||
void NCursesPanel::init() {
|
||||
p = ::new_panel(w);
|
||||
if (!p)
|
||||
OnError(ERR);
|
||||
|
||||
UserHook* hook = new UserHook;
|
||||
hook->m_user = NULL;
|
||||
hook->m_back = this;
|
||||
hook->m_owner = p;
|
||||
::set_panel_userptr(p, (void *)hook);
|
||||
}
|
||||
|
||||
NCursesPanel::~NCursesPanel() {
|
||||
UserHook* hook = (UserHook*)::panel_userptr(p);
|
||||
assert(hook != 0 && hook->m_back==this && hook->m_owner==p);
|
||||
delete hook;
|
||||
::del_panel(p);
|
||||
::update_panels();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesPanel::redraw() {
|
||||
PANEL *pan;
|
||||
|
||||
pan = ::panel_above(NULL);
|
||||
while (pan) {
|
||||
::touchwin(panel_window(pan));
|
||||
pan = ::panel_above(pan);
|
||||
}
|
||||
::update_panels();
|
||||
::doupdate();
|
||||
}
|
||||
|
||||
int
|
||||
NCursesPanel::refresh() {
|
||||
::update_panels();
|
||||
return ::doupdate();
|
||||
}
|
||||
|
||||
int
|
||||
NCursesPanel::noutrefresh() {
|
||||
::update_panels();
|
||||
return OK;
|
||||
}
|
||||
|
||||
void
|
||||
NCursesPanel::boldframe(const char *title, const char* btitle) {
|
||||
standout();
|
||||
frame(title, btitle);
|
||||
standend();
|
||||
}
|
||||
|
||||
void
|
||||
NCursesPanel::frame(const char *title,const char *btitle) {
|
||||
int err = OK;
|
||||
if (!title && !btitle) {
|
||||
err = box();
|
||||
}
|
||||
else {
|
||||
err = box();
|
||||
if (err==OK)
|
||||
label(title,btitle);
|
||||
}
|
||||
OnError(err);
|
||||
}
|
||||
|
||||
void
|
||||
NCursesPanel::label(const char *tLabel, const char *bLabel) {
|
||||
if (tLabel)
|
||||
centertext(0,tLabel);
|
||||
if (bLabel)
|
||||
centertext(maxy(),bLabel);
|
||||
}
|
||||
|
||||
void
|
||||
NCursesPanel::centertext(int row,const char *label) {
|
||||
if (label) {
|
||||
int x = (maxx() - ::strlen(label)) / 2;
|
||||
if (x<0)
|
||||
x=0;
|
||||
OnError(addstr(row, x, label, width()));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
NCursesPanel::getKey(void) {
|
||||
return getch();
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NCURSES_CURSESP_H_incl
|
||||
#define NCURSES_CURSESP_H_incl 1
|
||||
|
||||
// $Id: cursesp.h,v 1.15 2001/07/14 20:56:18 juergen Exp $
|
||||
|
||||
#include <cursesw.h>
|
||||
|
||||
extern "C" {
|
||||
# include <panel.h>
|
||||
}
|
||||
|
||||
class NCURSES_IMPEXP NCursesPanel : public NCursesWindow {
|
||||
protected:
|
||||
PANEL *p;
|
||||
static NCursesPanel *dummy;
|
||||
|
||||
private:
|
||||
// This structure is used for the panel's user data field to link the
|
||||
// PANEL* to the C++ object and to provide extra space for a user pointer.
|
||||
typedef struct {
|
||||
void* m_user; // the pointer for the user's data
|
||||
const NCursesPanel* m_back; // backward pointer to C++ object
|
||||
const PANEL* m_owner; // the panel itself
|
||||
} UserHook;
|
||||
|
||||
void init(); // Initialize the panel object
|
||||
|
||||
protected:
|
||||
void set_user(void *user) {
|
||||
UserHook* uptr = (UserHook*)::panel_userptr (p);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
|
||||
uptr->m_user = user;
|
||||
}
|
||||
// Set the user pointer of the panel.
|
||||
|
||||
void *get_user() {
|
||||
UserHook* uptr = (UserHook*)::panel_userptr (p);
|
||||
assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
|
||||
return uptr->m_user;
|
||||
}
|
||||
|
||||
void OnError (int err) const THROWS((NCursesPanelException)) {
|
||||
if (err==ERR)
|
||||
THROW(new NCursesPanelException (this, err));
|
||||
}
|
||||
// If err is equal to the curses error indicator ERR, an error handler
|
||||
// is called.
|
||||
|
||||
// Get a keystroke. Default implementation calls getch()
|
||||
virtual int getKey(void);
|
||||
|
||||
public:
|
||||
NCursesPanel(int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0)
|
||||
: NCursesWindow(lines,cols,begin_y,begin_x) {
|
||||
init();
|
||||
}
|
||||
// Create a panel with this size starting at the requested position.
|
||||
|
||||
NCursesPanel() : NCursesWindow(::stdscr) { init(); }
|
||||
// This constructor creates the default Panel associated with the
|
||||
// ::stdscr window
|
||||
|
||||
virtual ~NCursesPanel();
|
||||
|
||||
// basic manipulation
|
||||
inline void hide() {
|
||||
OnError (::hide_panel(p));
|
||||
}
|
||||
// Hide the panel. It stays in the stack but becomes invisible.
|
||||
|
||||
inline void show() {
|
||||
OnError (::show_panel(p));
|
||||
}
|
||||
// Show the panel, i.e. make it visible.
|
||||
|
||||
inline void top() {
|
||||
OnError (::top_panel(p));
|
||||
}
|
||||
// Make this panel the top panel in the stack.
|
||||
|
||||
inline void bottom() {
|
||||
OnError (::bottom_panel(p));
|
||||
}
|
||||
// Make this panel the bottom panel in the stack.
|
||||
// N.B.: The panel associated with ::stdscr is always on the bottom. So
|
||||
// actually bottom() makes the panel the first above ::stdscr.
|
||||
|
||||
virtual int mvwin(int y, int x) {
|
||||
OnError(::move_panel(p, y, x));
|
||||
return OK;
|
||||
}
|
||||
|
||||
inline bool hidden() const {
|
||||
return (::panel_hidden (p) ? TRUE : FALSE);
|
||||
}
|
||||
// Return TRUE if the panel is hidden, FALSE otherwise.
|
||||
|
||||
/* The functions panel_above() and panel_below() are not reflected in
|
||||
the NCursesPanel class. The reason for this is, that we cannot
|
||||
assume that a panel retrieved by those operations is one wrapped
|
||||
by a C++ class. Although this situation might be handled, we also
|
||||
need a reverse mapping from PANEL to NCursesPanel which needs some
|
||||
redesign of the low level stuff. At the moment, we define them in the
|
||||
interface but they will always produce an error. */
|
||||
inline NCursesPanel& above() const {
|
||||
OnError(ERR);
|
||||
return *dummy;
|
||||
}
|
||||
|
||||
inline NCursesPanel& below() const {
|
||||
OnError(ERR);
|
||||
return *dummy;
|
||||
}
|
||||
|
||||
// Those two are rewrites of the corresponding virtual members of
|
||||
// NCursesWindow
|
||||
virtual int refresh();
|
||||
// Propagate all panel changes to the virtual screen and update the
|
||||
// physical screen.
|
||||
|
||||
virtual int noutrefresh();
|
||||
// Propagate all panel changes to the virtual screen.
|
||||
|
||||
static void redraw();
|
||||
// Redraw all panels.
|
||||
|
||||
// decorations
|
||||
virtual void frame(const char* title=NULL,
|
||||
const char* btitle=NULL);
|
||||
// Put a frame around the panel and put the title centered in the top line
|
||||
// and btitle in the bottom line.
|
||||
|
||||
virtual void boldframe(const char* title=NULL,
|
||||
const char* btitle=NULL);
|
||||
// Same as frame(), but use highlighted attributes.
|
||||
|
||||
virtual void label(const char* topLabel,
|
||||
const char* bottomLabel);
|
||||
// Put the title centered in the top line and btitle in the bottom line.
|
||||
|
||||
virtual void centertext(int row,const char* label);
|
||||
// Put the label text centered in the specified row.
|
||||
};
|
||||
|
||||
/* We use templates to provide a typesafe mechanism to associate
|
||||
* user data with a panel. A NCursesUserPanel<T> is a panel
|
||||
* associated with some user data of type T.
|
||||
*/
|
||||
template<class T> class NCursesUserPanel : public NCursesPanel
|
||||
{
|
||||
public:
|
||||
NCursesUserPanel (int lines,
|
||||
int cols,
|
||||
int begin_y = 0,
|
||||
int begin_x = 0,
|
||||
const T* p_UserData = (T*)0)
|
||||
: NCursesPanel (lines, cols, begin_y, begin_x) {
|
||||
if (p)
|
||||
set_user ((void *)p_UserData);
|
||||
};
|
||||
// This creates an user panel of the requested size with associated
|
||||
// user data pointed to by p_UserData.
|
||||
|
||||
NCursesUserPanel(const T* p_UserData = (T*)0) : NCursesPanel() {
|
||||
if (p)
|
||||
set_user((void *)p_UserData);
|
||||
};
|
||||
// This creates an user panel associated with the ::stdscr and user data
|
||||
// pointed to by p_UserData.
|
||||
|
||||
virtual ~NCursesUserPanel() {};
|
||||
|
||||
T* UserData (void) const {
|
||||
return (T*)get_user ();
|
||||
};
|
||||
// Retrieve the user data associated with the panel.
|
||||
|
||||
virtual void setUserData (const T* p_UserData) {
|
||||
if (p)
|
||||
set_user ((void *)p_UserData);
|
||||
}
|
||||
// Associate the user panel with the user data pointed to by p_UserData.
|
||||
};
|
||||
|
||||
#endif // NCURSES_CURSESP_H_incl
|
@ -1,270 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1999,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1999 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "etip.h"
|
||||
#include "cursesw.h"
|
||||
|
||||
MODULE_ID("$Id: cursespad.cc,v 1.4 2001/03/24 21:25:57 tom Exp $")
|
||||
|
||||
NCursesPad::NCursesPad(int lines, int cols)
|
||||
: NCursesWindow(),
|
||||
viewWin((NCursesWindow*)0),
|
||||
viewSub((NCursesWindow*)0),
|
||||
h_gridsize(0), v_gridsize(0),
|
||||
min_row(0), min_col(0)
|
||||
{
|
||||
w = ::newpad(lines,cols);
|
||||
if ((WINDOW*)0==w) {
|
||||
count--;
|
||||
err_handler("Cannot construct window");
|
||||
}
|
||||
alloced = TRUE;
|
||||
}
|
||||
|
||||
|
||||
int NCursesPad::driver (int key) {
|
||||
// Default implementation
|
||||
switch(key) {
|
||||
case KEY_UP:
|
||||
// =======
|
||||
return REQ_PAD_UP;
|
||||
case KEY_DOWN:
|
||||
// =========
|
||||
return REQ_PAD_DOWN;
|
||||
case KEY_LEFT:
|
||||
// =========
|
||||
return REQ_PAD_LEFT;
|
||||
case KEY_RIGHT:
|
||||
// ==========
|
||||
return REQ_PAD_RIGHT;
|
||||
case KEY_EXIT:
|
||||
// =========
|
||||
case CTRL('X'):
|
||||
// ==========
|
||||
return REQ_PAD_EXIT;
|
||||
|
||||
default: return(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NCursesPad::operator()(void) {
|
||||
NCursesWindow* W = Win();
|
||||
|
||||
if ((NCursesWindow*)0 != W) {
|
||||
int Width = W->width();
|
||||
int Height = W->height();
|
||||
|
||||
int req = REQ_PAD_REFRESH;
|
||||
|
||||
W->keypad(TRUE);
|
||||
W->meta(TRUE);
|
||||
refresh();
|
||||
|
||||
do {
|
||||
bool changed = FALSE;
|
||||
|
||||
switch (req) {
|
||||
case REQ_PAD_REFRESH:
|
||||
// ================
|
||||
changed = TRUE;
|
||||
break;
|
||||
case REQ_PAD_LEFT:
|
||||
// =============
|
||||
if (min_col > 0) {
|
||||
changed = TRUE;
|
||||
if (min_col < h_gridsize)
|
||||
min_col = 0;
|
||||
else
|
||||
min_col -= h_gridsize;
|
||||
}
|
||||
else
|
||||
OnNavigationError(req);
|
||||
break;
|
||||
case REQ_PAD_RIGHT:
|
||||
// ==============
|
||||
if (min_col < (width() - Width - 1)) {
|
||||
changed = TRUE;
|
||||
if (min_col > (width() - Width - h_gridsize - 1))
|
||||
min_col = width() - Width - 1;
|
||||
else
|
||||
min_col += h_gridsize;
|
||||
}
|
||||
else
|
||||
OnNavigationError(req);
|
||||
break;
|
||||
case REQ_PAD_UP:
|
||||
// ===========
|
||||
if (min_row > 0) {
|
||||
changed = TRUE;
|
||||
if (min_row < v_gridsize)
|
||||
min_row = 0;
|
||||
else
|
||||
min_row -= v_gridsize;
|
||||
}
|
||||
else
|
||||
OnNavigationError(req);
|
||||
break;
|
||||
case REQ_PAD_DOWN:
|
||||
// =============
|
||||
if (min_row < (height() - Height - 1)) {
|
||||
changed = TRUE;
|
||||
if (min_row > (height() - Height - v_gridsize - 1))
|
||||
min_row = height() - Height - 1;
|
||||
else
|
||||
min_row += v_gridsize;
|
||||
}
|
||||
else
|
||||
OnNavigationError(req);
|
||||
break;
|
||||
|
||||
default:
|
||||
OnUnknownOperation(req);
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
noutrefresh();
|
||||
W->syncup();
|
||||
OnOperation(req);
|
||||
viewWin->refresh();
|
||||
}
|
||||
} while( (req=driver(W->getch())) != REQ_PAD_EXIT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int NCursesPad::refresh() {
|
||||
int res = noutrefresh();
|
||||
if (res==OK && ((NCursesWindow*)0 != viewWin)) {
|
||||
res = (viewWin->refresh());
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
int NCursesPad::noutrefresh() {
|
||||
int res = OK;
|
||||
NCursesWindow* W = Win();
|
||||
if ((NCursesWindow*)0 != W) {
|
||||
res = copywin(*W,min_row,min_col,
|
||||
0,0,W->maxy(),W->maxx(),
|
||||
FALSE);
|
||||
if (res==OK) {
|
||||
W->syncup();
|
||||
res = viewWin->noutrefresh();
|
||||
}
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
void NCursesPad::setWindow(NCursesWindow& view,
|
||||
int v_grid NCURSES_PARAM_INIT(1),
|
||||
int h_grid NCURSES_PARAM_INIT(1))
|
||||
{
|
||||
viewWin = &view;
|
||||
min_row = min_col = 0;
|
||||
if (h_grid <=0 || v_grid <= 0)
|
||||
err_handler("Illegal Gridsize");
|
||||
else {
|
||||
h_gridsize = h_grid;
|
||||
v_gridsize = v_grid;
|
||||
}
|
||||
}
|
||||
|
||||
void NCursesPad::setSubWindow(NCursesWindow& sub)
|
||||
{
|
||||
if ((NCursesWindow*)0 == viewWin)
|
||||
err_handler("Pad has no viewport");
|
||||
if (!viewWin->isDescendant(sub))
|
||||
THROW(new NCursesException("NCursesFramePad", E_SYSTEM_ERROR));
|
||||
viewSub = ⊂
|
||||
}
|
||||
|
||||
void NCursesFramedPad::OnOperation(int pad_req) {
|
||||
NCursesWindow* W = Win();
|
||||
NCursesWindow* Win = getWindow();
|
||||
|
||||
if (((NCursesWindow*)0 != W) && ((NCursesWindow*)0 != Win)) {
|
||||
int Width = W->width();
|
||||
int Height = W->height();
|
||||
int i, row, col, h_len, v_len;
|
||||
|
||||
h_len = (Width*Width + width() - 1)/width();
|
||||
if (h_len==0)
|
||||
h_len = 1;
|
||||
if (h_len > Width)
|
||||
h_len = Width;
|
||||
|
||||
v_len = (Height*Height + height() - 1)/height();
|
||||
if (v_len==0)
|
||||
v_len = 1;
|
||||
if (v_len > Height)
|
||||
v_len = Height;
|
||||
|
||||
col = (min_col * Width + width() - 1) / width();
|
||||
if (col + h_len > Width)
|
||||
col = Width - h_len;
|
||||
|
||||
row = (min_row * Height + height() - 1) / height();
|
||||
if (row + v_len > Height)
|
||||
row = Height - v_len;
|
||||
|
||||
Win->vline(1,Width+1,Height);
|
||||
Win->attron(A_REVERSE);
|
||||
if (v_len>=2) {
|
||||
Win->addch(row+1,Width+1,ACS_UARROW);
|
||||
for(i=2;i<v_len;i++)
|
||||
Win->addch(row+i,Width+1,' ');
|
||||
Win->addch(row+v_len,Width+1,ACS_DARROW);
|
||||
}
|
||||
else {
|
||||
for(i=1;i<=v_len;i++)
|
||||
Win->addch(row+i,Width+1,' ');
|
||||
}
|
||||
Win->attroff(A_REVERSE);
|
||||
|
||||
Win->hline(Height+1,1,Width);
|
||||
Win->attron(A_REVERSE);
|
||||
if (h_len >= 2) {
|
||||
Win->addch(Height+1,col+1,ACS_LARROW);
|
||||
for(i=2;i<h_len;i++)
|
||||
Win->addch(Height+1,col+i,' ');
|
||||
Win->addch(Height+1,col+h_len,ACS_RARROW);
|
||||
}
|
||||
else {
|
||||
for(i=1;i<=h_len;i++)
|
||||
Win->addch(Height+1,col+i,' ');
|
||||
}
|
||||
Win->attroff(A_REVERSE);
|
||||
}
|
||||
}
|
@ -1,455 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
written by Eric Newton (newton@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library is distributed in the hope
|
||||
that it will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
PURPOSE. See the GNU Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
modified by Ulrich Drepper (drepper@karlsruhe.gmd.de)
|
||||
and Anatoly Ivasyuk (anatoly@nick.csh.rit.edu)
|
||||
|
||||
modified by Juergen Pfeifer (juergen.pfeifer@gmx.net)
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursesw.h"
|
||||
|
||||
MODULE_ID("$Id: cursesw.cc,v 1.24 2001/12/08 21:02:33 tom Exp $")
|
||||
|
||||
#define COLORS_NEED_INITIALIZATION -1
|
||||
#define COLORS_NOT_INITIALIZED 0
|
||||
#define COLORS_MONOCHROME 1
|
||||
#define COLORS_ARE_REALLY_THERE 2
|
||||
|
||||
// declare static variables for the class
|
||||
long NCursesWindow::count = 0L;
|
||||
bool NCursesWindow::b_initialized = FALSE;
|
||||
|
||||
/*
|
||||
* The ncurses library has a fallback for vsscanf(), which may work...
|
||||
*/
|
||||
#if !(USE_STRSTREAM_VSCAN || USE_STRSTREAM_VSCAN_CAST)
|
||||
# undef USE_STDIO_VSCAN
|
||||
# define USE_STDIO_VSCAN 1
|
||||
#endif
|
||||
|
||||
#if defined(__GNUG__)
|
||||
# ifndef _IO_va_list
|
||||
# define _IO_va_list char *
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int
|
||||
NCursesWindow::scanw(const char* fmt, ...)
|
||||
{
|
||||
int result = ERR;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (::wgetnstr(w, buf, sizeof(buf)) != ERR) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#if USE_STDIO_VSCAN
|
||||
if (::vsscanf(buf, fmt, args) != -1)
|
||||
result = OK;
|
||||
#elif USE_STRSTREAM_VSCAN /* powerpc, os390 */
|
||||
strstreambuf ss(buf, sizeof(buf));
|
||||
if (ss.vscan(fmt, args) != -1)
|
||||
result = OK;
|
||||
#elif USE_STRSTREAM_VSCAN_CAST /* pre-gcc 3.0 */
|
||||
strstreambuf ss(buf, sizeof(buf));
|
||||
if (ss.vscan(fmt, (_IO_va_list)args) != -1)
|
||||
result = OK;
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NCursesWindow::scanw(int y, int x, const char* fmt, ...)
|
||||
{
|
||||
int result = ERR;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (::wmove(w, y, x) != ERR) {
|
||||
if (::wgetnstr(w, buf, sizeof(buf)) != ERR) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#if USE_STDIO_VSCAN
|
||||
if (::vsscanf(buf, fmt, args) != -1)
|
||||
result = OK;
|
||||
#elif USE_STRSTREAM_VSCAN /* powerpc, os390 */
|
||||
strstreambuf ss(buf, sizeof(buf));
|
||||
if (ss.vscan(fmt, args) != -1)
|
||||
result = OK;
|
||||
#elif USE_STRSTREAM_VSCAN_CAST /* pre-gcc 3.0 */
|
||||
strstreambuf ss(buf, sizeof(buf));
|
||||
if (ss.vscan(fmt, (_IO_va_list)args) != -1)
|
||||
result = OK;
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NCursesWindow::printw(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char buf[BUFSIZ];
|
||||
::vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return waddstr(w, buf);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NCursesWindow::printw(int y, int x, const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int result = ::wmove(w, y, x);
|
||||
if (result == OK) {
|
||||
char buf[BUFSIZ];
|
||||
::vsprintf(buf, fmt, args);
|
||||
result = waddstr(w, buf);
|
||||
}
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NCursesWindow::init(void)
|
||||
{
|
||||
leaveok(0);
|
||||
keypad(1);
|
||||
meta(1);
|
||||
}
|
||||
|
||||
void
|
||||
NCursesWindow::err_handler(const char *msg) const THROWS(NCursesException)
|
||||
{
|
||||
THROW(new NCursesException(msg));
|
||||
}
|
||||
|
||||
void
|
||||
NCursesWindow::initialize() {
|
||||
if (!b_initialized) {
|
||||
::initscr();
|
||||
b_initialized = TRUE;
|
||||
if (colorInitialized==COLORS_NEED_INITIALIZATION) {
|
||||
colorInitialized=COLORS_NOT_INITIALIZED;
|
||||
useColors();
|
||||
}
|
||||
::noecho();
|
||||
::cbreak();
|
||||
}
|
||||
}
|
||||
|
||||
NCursesWindow::NCursesWindow() {
|
||||
initialize();
|
||||
|
||||
w = (WINDOW *)0;
|
||||
init();
|
||||
alloced = FALSE;
|
||||
subwins = par = sib = 0;
|
||||
count++;
|
||||
}
|
||||
|
||||
NCursesWindow::NCursesWindow(int lines, int cols, int begin_y, int begin_x)
|
||||
{
|
||||
initialize();
|
||||
|
||||
w = ::newwin(lines, cols, begin_y, begin_x);
|
||||
if (w == 0) {
|
||||
err_handler("Cannot construct window");
|
||||
}
|
||||
init();
|
||||
|
||||
alloced = TRUE;
|
||||
subwins = par = sib = 0;
|
||||
count++;
|
||||
}
|
||||
|
||||
NCursesWindow::NCursesWindow(WINDOW* &window)
|
||||
{
|
||||
initialize();
|
||||
|
||||
w = window;
|
||||
init();
|
||||
alloced = FALSE;
|
||||
subwins = par = sib = 0;
|
||||
count++;
|
||||
}
|
||||
|
||||
NCursesWindow::NCursesWindow(NCursesWindow& win, int l, int c,
|
||||
int begin_y, int begin_x, char absrel)
|
||||
{
|
||||
initialize();
|
||||
if (absrel == 'a') { // absolute origin
|
||||
begin_y -= win.begy();
|
||||
begin_x -= win.begx();
|
||||
}
|
||||
|
||||
// Even though we treat subwindows as a tree, the standard curses
|
||||
// library needs the `subwin' call to link to the parent in
|
||||
// order to correctly perform refreshes, etc.
|
||||
// Friendly enough, this also works for pads.
|
||||
w = ::derwin(win.w, l, c, begin_y, begin_x);
|
||||
if (w == 0) {
|
||||
err_handler("Cannot construct subwindow");
|
||||
}
|
||||
|
||||
par = &win;
|
||||
sib = win.subwins;
|
||||
win.subwins = this;
|
||||
subwins = 0;
|
||||
alloced = TRUE;
|
||||
count++;
|
||||
}
|
||||
|
||||
NCursesWindow::NCursesWindow(NCursesWindow& win,
|
||||
bool do_box NCURSES_PARAM_INIT(TRUE))
|
||||
{
|
||||
initialize();
|
||||
w = :: derwin(win.w,win.height()-2,win.width()-2,1,1);
|
||||
if (w == 0) {
|
||||
err_handler("Cannot construct subwindow");
|
||||
}
|
||||
|
||||
par = &win;
|
||||
sib = win.subwins;
|
||||
win.subwins = this;
|
||||
subwins = 0;
|
||||
alloced = TRUE;
|
||||
count++;
|
||||
|
||||
if (do_box) {
|
||||
win.box();
|
||||
win.touchwin();
|
||||
}
|
||||
}
|
||||
|
||||
NCursesWindow NCursesWindow::Clone() {
|
||||
WINDOW *d = ::dupwin(w);
|
||||
NCursesWindow W(d);
|
||||
W.subwins = subwins;
|
||||
W.sib = sib;
|
||||
W.par = par;
|
||||
W.alloced = alloced;
|
||||
return W;
|
||||
}
|
||||
|
||||
typedef int (*RIPOFFINIT)(NCursesWindow&);
|
||||
static RIPOFFINIT R_INIT[5]; // There can't be more
|
||||
static int r_init_idx = 0;
|
||||
static RIPOFFINIT* prip = R_INIT;
|
||||
|
||||
extern "C" int _nc_ripoffline(int,int (*init)(WINDOW*,int));
|
||||
|
||||
NCursesWindow::NCursesWindow(WINDOW *win, int cols) {
|
||||
initialize();
|
||||
w = win;
|
||||
assert((w->_maxx+1)==cols);
|
||||
alloced = FALSE;
|
||||
subwins = par = sib = 0;
|
||||
}
|
||||
|
||||
int NCursesWindow::ripoff_init(WINDOW *w, int cols)
|
||||
{
|
||||
int res = ERR;
|
||||
|
||||
RIPOFFINIT init = *prip++;
|
||||
if (init) {
|
||||
NCursesWindow* W = new NCursesWindow(w,cols);
|
||||
res = init(*W);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int NCursesWindow::ripoffline(int ripoff_lines,
|
||||
int (*init)(NCursesWindow& win)) {
|
||||
int code = ::_nc_ripoffline(ripoff_lines,ripoff_init);
|
||||
if (code==OK && init && ripoff_lines) {
|
||||
R_INIT[r_init_idx++] = init;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
bool
|
||||
NCursesWindow::isDescendant(NCursesWindow& win) {
|
||||
for (NCursesWindow* p = subwins; p != NULL; p = p->sib) {
|
||||
if (p==&win)
|
||||
return TRUE;
|
||||
else {
|
||||
if (p->isDescendant(win))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
NCursesWindow::kill_subwindows()
|
||||
{
|
||||
for (NCursesWindow* p = subwins; p != 0; p = p->sib) {
|
||||
p->kill_subwindows();
|
||||
if (p->alloced) {
|
||||
if (p->w != 0)
|
||||
::delwin(p->w);
|
||||
p->alloced = FALSE;
|
||||
}
|
||||
p->w = 0; // cause a run-time error if anyone attempts to use...
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NCursesWindow::~NCursesWindow()
|
||||
{
|
||||
kill_subwindows();
|
||||
|
||||
if (par != 0) { // Snip us from the parent's list of subwindows.
|
||||
NCursesWindow * win = par->subwins;
|
||||
NCursesWindow * trail = 0;
|
||||
for (;;) {
|
||||
if (win == 0)
|
||||
break;
|
||||
else if (win == this) {
|
||||
if (trail != 0)
|
||||
trail->sib = win->sib;
|
||||
else
|
||||
par->subwins = win->sib;
|
||||
break;
|
||||
} else {
|
||||
trail = win;
|
||||
win = win->sib;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alloced && w != 0)
|
||||
::delwin(w);
|
||||
|
||||
if (alloced) {
|
||||
--count;
|
||||
if (count == 0) {
|
||||
::endwin();
|
||||
}
|
||||
else if (count < 0) { // cannot happen!
|
||||
err_handler("Too many windows destroyed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Color stuff
|
||||
//
|
||||
int NCursesWindow::colorInitialized = COLORS_NOT_INITIALIZED;
|
||||
|
||||
void
|
||||
NCursesWindow::useColors(void)
|
||||
{
|
||||
if (colorInitialized == COLORS_NOT_INITIALIZED) {
|
||||
if (b_initialized) {
|
||||
if (::has_colors()) {
|
||||
::start_color();
|
||||
colorInitialized = COLORS_ARE_REALLY_THERE;
|
||||
}
|
||||
else
|
||||
colorInitialized = COLORS_MONOCHROME;
|
||||
}
|
||||
else
|
||||
colorInitialized = COLORS_NEED_INITIALIZATION;
|
||||
}
|
||||
}
|
||||
|
||||
short
|
||||
NCursesWindow::getcolor(int getback) const
|
||||
{
|
||||
short fore, back;
|
||||
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE) {
|
||||
if (::pair_content((short)PAIR_NUMBER(w->_attrs), &fore, &back))
|
||||
err_handler("Can't get color pair");
|
||||
}
|
||||
else {
|
||||
// Monochrome means white on black
|
||||
back = COLOR_BLACK;
|
||||
fore = COLOR_WHITE;
|
||||
}
|
||||
return getback ? back : fore;
|
||||
}
|
||||
|
||||
int NCursesWindow::NumberOfColors()
|
||||
{
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE)
|
||||
return COLORS;
|
||||
else
|
||||
return 1; // monochrome (actually there are two ;-)
|
||||
}
|
||||
|
||||
short
|
||||
NCursesWindow::getcolor() const
|
||||
{
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE)
|
||||
return PAIR_NUMBER(w->_attrs);
|
||||
else
|
||||
return 0; // we only have pair zero
|
||||
}
|
||||
|
||||
int
|
||||
NCursesWindow::setpalette(short fore, short back, short pair)
|
||||
{
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE)
|
||||
return ::init_pair(pair, fore, back);
|
||||
else
|
||||
return OK;
|
||||
}
|
||||
|
||||
int
|
||||
NCursesWindow::setpalette(short fore, short back)
|
||||
{
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE)
|
||||
return setpalette(fore, back, (short)PAIR_NUMBER(w->_attrs));
|
||||
else
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NCursesWindow::setcolor(short pair)
|
||||
{
|
||||
if (colorInitialized==COLORS_ARE_REALLY_THERE) {
|
||||
if ((pair < 1) || (pair > COLOR_PAIRS))
|
||||
err_handler("Can't set color pair");
|
||||
|
||||
attroff(A_COLOR);
|
||||
attrset(COLOR_PAIR(pair));
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
#if HAVE_HAS_KEY
|
||||
extern "C" int _nc_has_mouse(void);
|
||||
|
||||
bool NCursesWindow::has_mouse() const {
|
||||
return ((::has_key(KEY_MOUSE) || ::_nc_has_mouse())
|
||||
? TRUE : FALSE);
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,122 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#include "cursslk.h"
|
||||
#include "cursesapp.h"
|
||||
#include <string.h>
|
||||
|
||||
MODULE_ID("$Id: cursslk.cc,v 1.9 2001/03/24 20:04:15 tom Exp $")
|
||||
|
||||
void Soft_Label_Key_Set::Soft_Label_Key::operator=(char *text) {
|
||||
delete[] label;
|
||||
label = new char[1 + ::strlen(text)];
|
||||
(::strcpy)(label,text);
|
||||
}
|
||||
|
||||
long Soft_Label_Key_Set::count = 0L;
|
||||
int Soft_Label_Key_Set::num_labels = 0;
|
||||
|
||||
Soft_Label_Key_Set::Label_Layout
|
||||
Soft_Label_Key_Set::format = None;
|
||||
|
||||
void Soft_Label_Key_Set::init() {
|
||||
slk_array = new Soft_Label_Key[num_labels];
|
||||
for(int i=0; i < num_labels; i++) {
|
||||
slk_array[i].num = i+1;
|
||||
}
|
||||
b_attrInit = FALSE;
|
||||
}
|
||||
|
||||
Soft_Label_Key_Set::Soft_Label_Key_Set() {
|
||||
if (format==None)
|
||||
Error("No default SLK layout");
|
||||
init();
|
||||
}
|
||||
|
||||
Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt) {
|
||||
if (fmt==None)
|
||||
Error("Invalid SLK Layout");
|
||||
if (count++==0) {
|
||||
format = fmt;
|
||||
if (ERR == ::slk_init((int)fmt))
|
||||
Error("slk_init");
|
||||
num_labels = (fmt>=PC_Style?12:8);
|
||||
}
|
||||
else if (fmt!=format)
|
||||
Error("All SLKs must have same layout");
|
||||
init();
|
||||
}
|
||||
|
||||
Soft_Label_Key_Set::~Soft_Label_Key_Set() {
|
||||
if (!::isendwin())
|
||||
clear();
|
||||
delete[] slk_array;
|
||||
count--;
|
||||
}
|
||||
|
||||
Soft_Label_Key_Set::Soft_Label_Key& Soft_Label_Key_Set::operator[](int i) {
|
||||
if (i<1 || i>num_labels)
|
||||
Error("Invalid Label index");
|
||||
return slk_array[i-1];
|
||||
}
|
||||
|
||||
void Soft_Label_Key_Set::activate_label(int i, bool bf) {
|
||||
if (!b_attrInit) {
|
||||
NCursesApplication* A = NCursesApplication::getApplication();
|
||||
if (A) attrset(A->labels());
|
||||
b_attrInit = TRUE;
|
||||
}
|
||||
Soft_Label_Key& K = (*this)[i];
|
||||
if (ERR==::slk_set(K.num,bf?K.label:"",K.format))
|
||||
Error("slk_set");
|
||||
noutrefresh();
|
||||
}
|
||||
|
||||
void Soft_Label_Key_Set::activate_labels(bool bf) {
|
||||
if (!b_attrInit) {
|
||||
NCursesApplication* A = NCursesApplication::getApplication();
|
||||
if (A) attrset(A->labels());
|
||||
b_attrInit = TRUE;
|
||||
}
|
||||
for(int i=1; i <= num_labels; i++) {
|
||||
Soft_Label_Key& K = (*this)[i];
|
||||
if (ERR==::slk_set(K.num,bf?K.label:"",K.format))
|
||||
Error("slk_set");
|
||||
}
|
||||
if (bf)
|
||||
restore();
|
||||
else
|
||||
clear();
|
||||
noutrefresh();
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
// * this is for making emacs happy: -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2000 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: cursslk.h,v 1.7 2001/03/24 21:41:47 tom Exp $
|
||||
|
||||
#ifndef NCURSES_CURSSLK_H_incl
|
||||
#define NCURSES_CURSSLK_H_incl
|
||||
|
||||
#include <cursesw.h>
|
||||
|
||||
class NCURSES_IMPEXP Soft_Label_Key_Set {
|
||||
public:
|
||||
// This inner class represents the attributes of a Soft Label Key (SLK)
|
||||
class NCURSES_IMPEXP Soft_Label_Key {
|
||||
friend class Soft_Label_Key_Set;
|
||||
public:
|
||||
typedef enum { Left=0, Center=1, Right=2 } Justification;
|
||||
|
||||
private:
|
||||
char *label; // The Text of the Label
|
||||
Justification format; // The Justification
|
||||
int num; // The number of the Label
|
||||
|
||||
Soft_Label_Key() : label((char*)0),format(Left),num(-1) {
|
||||
}
|
||||
|
||||
virtual ~Soft_Label_Key() {
|
||||
delete[] label;
|
||||
};
|
||||
|
||||
public:
|
||||
// Set the text of the Label
|
||||
void operator=(char *text);
|
||||
|
||||
// Set the Justification of the Label
|
||||
inline void operator=(Justification just) {
|
||||
format = just;
|
||||
}
|
||||
|
||||
// Retrieve the text of the label
|
||||
inline char* operator()(void) const {
|
||||
return label;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
typedef enum {
|
||||
None = -1,
|
||||
Three_Two_Three = 0,
|
||||
Four_Four = 1,
|
||||
PC_Style = 2,
|
||||
PC_Style_With_Index = 3
|
||||
} Label_Layout;
|
||||
|
||||
private:
|
||||
static long NCURSES_IMPEXP count; // Number of Key Sets
|
||||
static Label_Layout NCURSES_IMPEXP format; // Layout of the Key Sets
|
||||
static int NCURSES_IMPEXP num_labels; // Number Of Labels in Key Sets
|
||||
bool NCURSES_IMPEXP b_attrInit; // Are attributes initialized
|
||||
|
||||
Soft_Label_Key *slk_array; // The array of SLK's
|
||||
|
||||
// Init the Key Set
|
||||
void init();
|
||||
|
||||
// Activate or Deactivate Label# i, Label counting starts with 1!
|
||||
void activate_label(int i, bool bf=TRUE);
|
||||
|
||||
// Activate of Deactivate all Labels
|
||||
void activate_labels(bool bf);
|
||||
|
||||
protected:
|
||||
inline void Error (const char* msg) const THROWS(NCursesException) {
|
||||
THROW(new NCursesException (msg));
|
||||
}
|
||||
|
||||
// Remove SLK's from screen
|
||||
void clear() {
|
||||
if (ERR==::slk_clear())
|
||||
Error("slk_clear");
|
||||
}
|
||||
|
||||
// Restore them
|
||||
void restore() {
|
||||
if (ERR==::slk_restore())
|
||||
Error("slk_restore");
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// Construct a Key Set, use the most comfortable layout as default.
|
||||
// You must create a Soft_Label_Key_Set before you create any object of
|
||||
// the NCursesWindow, NCursesPanel or derived classes. (Actually before
|
||||
// ::initscr() is called).
|
||||
Soft_Label_Key_Set(Label_Layout fmt);
|
||||
|
||||
// This constructor assumes, that you already constructed a Key Set
|
||||
// with a layout by the constructor above. This layout will be reused.
|
||||
NCURSES_IMPEXP Soft_Label_Key_Set();
|
||||
|
||||
virtual ~Soft_Label_Key_Set();
|
||||
|
||||
// Get Label# i. Label counting starts with 1!
|
||||
NCURSES_IMPEXP Soft_Label_Key& operator[](int i);
|
||||
|
||||
// Retrieve number of Labels
|
||||
inline int labels() const { return num_labels; }
|
||||
|
||||
// Refresh the SLK portion of the screen
|
||||
inline void refresh() {
|
||||
if (ERR==::slk_refresh())
|
||||
Error("slk_refresh");
|
||||
}
|
||||
|
||||
// Mark the SLK portion of the screen for refresh, defer actual refresh
|
||||
// until next update call.
|
||||
inline void noutrefresh() {
|
||||
if (ERR==::slk_noutrefresh())
|
||||
Error("slk_noutrefresh");
|
||||
}
|
||||
|
||||
// Mark the whole SLK portion of the screen as modified
|
||||
inline void touch() {
|
||||
if (ERR==::slk_touch())
|
||||
Error("slk_touch");
|
||||
}
|
||||
|
||||
// Activate Label# i
|
||||
inline void show(int i) {
|
||||
activate_label(i,FALSE);
|
||||
activate_label(i,TRUE);
|
||||
}
|
||||
|
||||
// Hide Label# i
|
||||
inline void hide(int i) {
|
||||
activate_label(i,FALSE);
|
||||
}
|
||||
|
||||
// Show all Labels
|
||||
inline void show() {
|
||||
activate_labels(FALSE);
|
||||
activate_labels(TRUE);
|
||||
}
|
||||
|
||||
// Hide all Labels
|
||||
inline void hide() {
|
||||
activate_labels(FALSE);
|
||||
}
|
||||
|
||||
inline void attron(attr_t attrs) {
|
||||
if (ERR==::slk_attron(attrs))
|
||||
Error("slk_attron");
|
||||
}
|
||||
|
||||
inline void attroff(attr_t attrs) {
|
||||
if (ERR==::slk_attroff(attrs))
|
||||
Error("slk_attroff");
|
||||
}
|
||||
|
||||
inline void attrset(attr_t attrs) {
|
||||
if (ERR==::slk_attrset(attrs))
|
||||
Error("slk_attrset");
|
||||
}
|
||||
|
||||
inline void color(short color_pair_number) {
|
||||
if (ERR==::slk_color(color_pair_number))
|
||||
Error("slk_color");
|
||||
}
|
||||
|
||||
inline attr_t attr() const {
|
||||
return ::slk_attr();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // NCURSES_CURSSLK_H_incl
|
@ -1,492 +0,0 @@
|
||||
/*
|
||||
* Silly demo program for the NCursesPanel class.
|
||||
*
|
||||
* written by Anatoly Ivasyuk (anatoly@nick.csh.rit.edu)
|
||||
*
|
||||
* Demo code for NCursesMenu and NCursesForm written by
|
||||
* Juergen Pfeifer <juergen.pfeifer@gmx.net>
|
||||
*
|
||||
* $Id: demo.cc,v 1.21 2001/07/15 01:15:26 tom Exp $
|
||||
*/
|
||||
|
||||
#include "cursesapp.h"
|
||||
#include "cursesm.h"
|
||||
#include "cursesf.h"
|
||||
|
||||
#if HAVE_LIBC_H
|
||||
# include <libc.h>
|
||||
#endif
|
||||
|
||||
extern "C" unsigned int sleep(unsigned int);
|
||||
|
||||
#undef index // needed for NeXT
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class SillyDemo
|
||||
{
|
||||
public:
|
||||
void run(int sleeptime) {
|
||||
|
||||
NCursesPanel *std = new NCursesPanel();
|
||||
|
||||
// Make a few small demo panels
|
||||
|
||||
NCursesPanel *u = new NCursesPanel(8,20,12,4);
|
||||
NCursesPanel *v = new NCursesPanel(8,20,10,6);
|
||||
NCursesPanel *w = new NCursesPanel(8,20,8,8);
|
||||
NCursesPanel *x = new NCursesPanel(8,20,6,10);
|
||||
NCursesPanel *y = new NCursesPanel(8,20,4,12);
|
||||
NCursesPanel *z = new NCursesPanel(8,30,2,14);
|
||||
|
||||
// Draw something on the main screen, so we can see what happens
|
||||
// when panels get moved or deleted.
|
||||
|
||||
std->box();
|
||||
std->move(std->height()/2,1);
|
||||
std->hline(std->width()-2);
|
||||
std->move(1,std->width()/2);
|
||||
std->vline(std->height()-2);
|
||||
std->addch(0,std->width()/2,ACS_TTEE);
|
||||
std->addch(std->height()-1,std->width()/2,ACS_BTEE);
|
||||
std->addch(std->height()/2,0,ACS_LTEE);
|
||||
std->addch(std->height()/2,std->width()-1,ACS_RTEE);
|
||||
std->addch(std->height()/2,std->width()/2,ACS_PLUS);
|
||||
|
||||
// Draw frames with titles around panels so that we can see where
|
||||
// the panels are located.
|
||||
u->boldframe("Win U");
|
||||
v->frame("Win V");
|
||||
w->boldframe("Win W");
|
||||
x->frame("Win X");
|
||||
y->boldframe("Win Y");
|
||||
z->frame("Win Z");
|
||||
if (NCursesApplication::getApplication()->useColors()) {
|
||||
u->bkgd(' '|COLOR_PAIR(1));
|
||||
w->bkgd(' '|COLOR_PAIR(1));
|
||||
y->bkgd(' '|COLOR_PAIR(1));
|
||||
v->bkgd(' '|COLOR_PAIR(2));
|
||||
x->bkgd(' '|COLOR_PAIR(2));
|
||||
z->bkgd(' '|COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
// A refresh to any valid panel updates all panels and refreshes
|
||||
// the screen. Using std is just convenient - We know it's always
|
||||
// valid until the end of the program.
|
||||
|
||||
std->refresh();
|
||||
sleep(sleeptime);
|
||||
|
||||
// Show what happens when panels are deleted and moved.
|
||||
|
||||
sleep(sleeptime);
|
||||
delete u;
|
||||
std->refresh();
|
||||
|
||||
sleep(sleeptime);
|
||||
delete z;
|
||||
std->refresh();
|
||||
|
||||
sleep(sleeptime);
|
||||
delete v;
|
||||
std->refresh();
|
||||
|
||||
// show how it looks when a panel moves
|
||||
sleep(sleeptime);
|
||||
y->mvwin(5,30);
|
||||
std->refresh();
|
||||
|
||||
sleep(sleeptime);
|
||||
delete y;
|
||||
std->refresh();
|
||||
|
||||
// show how it looks when you raise a panel
|
||||
sleep(sleeptime);
|
||||
w->top();
|
||||
std->refresh();
|
||||
|
||||
sleep(sleeptime);
|
||||
delete w;
|
||||
std->refresh();
|
||||
|
||||
sleep(sleeptime);
|
||||
delete x;
|
||||
|
||||
std->clear();
|
||||
std->refresh();
|
||||
|
||||
// Don't forget to clean up the main screen. Since this is the
|
||||
// last thing using NCursesWindow, this has the effect of
|
||||
// shutting down ncurses and restoring the terminal state.
|
||||
|
||||
sleep(sleeptime);
|
||||
delete std;
|
||||
}
|
||||
};
|
||||
|
||||
class UserData
|
||||
{
|
||||
private:
|
||||
int u;
|
||||
public:
|
||||
UserData(int x) : u(x) {}
|
||||
int sleeptime() const { return u; }
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
template<class T> class MyAction : public NCursesUserItem<T>
|
||||
{
|
||||
public:
|
||||
MyAction (const char* p_name,
|
||||
const T* p_UserData)
|
||||
: NCursesUserItem<T>(p_name, (const char*)0, p_UserData)
|
||||
{};
|
||||
|
||||
~MyAction() {}
|
||||
|
||||
bool action() {
|
||||
SillyDemo a;
|
||||
a.run(NCursesUserItem<T>::UserData()->sleeptime());
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
class QuitItem : public NCursesMenuItem
|
||||
{
|
||||
public:
|
||||
QuitItem() : NCursesMenuItem("Quit") {
|
||||
}
|
||||
|
||||
bool action() {
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class Label : public NCursesFormField
|
||||
{
|
||||
public:
|
||||
Label(const char* title,
|
||||
int row, int col)
|
||||
: NCursesFormField(1,(int)::strlen(title),row,col) {
|
||||
set_value(title);
|
||||
options_off(O_EDIT|O_ACTIVE);
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class MyFieldType : public UserDefinedFieldType {
|
||||
private:
|
||||
int chk;
|
||||
protected:
|
||||
bool field_check(NCursesFormField& f) {
|
||||
return TRUE;
|
||||
}
|
||||
bool char_check(int c) {
|
||||
return (c==chk?TRUE:FALSE);
|
||||
}
|
||||
public:
|
||||
MyFieldType(int x) : chk(x) {
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class TestForm : public NCursesForm
|
||||
{
|
||||
private:
|
||||
NCursesFormField** F;
|
||||
MyFieldType* mft;
|
||||
Integer_Field *ift;
|
||||
Enumeration_Field *eft;
|
||||
|
||||
static char *weekdays[];
|
||||
|
||||
public:
|
||||
TestForm() : NCursesForm(13,51,(lines()-15)/2,(cols()-53)/2) {
|
||||
|
||||
F = new NCursesFormField*[10];
|
||||
mft = new MyFieldType('X');
|
||||
ift = new Integer_Field(0,1,10);
|
||||
eft = new Enumeration_Field(weekdays);
|
||||
|
||||
F[0] = new Label("Demo Entry Form",0,16);
|
||||
F[1] = new Label("Weekday Enum",2,1);
|
||||
F[2] = new Label("Number(1-10)",2,21);
|
||||
F[3] = new Label("Only 'X'",2,35);
|
||||
F[4] = new Label("Multiline Field (Dynamic and Scrollable)",5,1);
|
||||
F[5] = new NCursesFormField(1,18,3,1);
|
||||
F[6] = new NCursesFormField(1,12,3,21);
|
||||
F[7] = new NCursesFormField(1,12,3,35);
|
||||
F[8] = new NCursesFormField(4,46,6,1,2);
|
||||
F[9] = new NCursesFormField();
|
||||
|
||||
InitForm(F,TRUE,TRUE);
|
||||
boldframe();
|
||||
|
||||
F[5]->set_fieldtype(*eft);
|
||||
F[6]->set_fieldtype(*ift);
|
||||
|
||||
F[7]->set_fieldtype(*mft);
|
||||
F[7]->set_maximum_growth(20); // max. 20 characters
|
||||
F[7]->options_off(O_STATIC); // make field dynamic
|
||||
|
||||
F[8]->set_maximum_growth(10); // max. 10 lines
|
||||
F[8]->options_off(O_STATIC); // make field dynamic
|
||||
}
|
||||
|
||||
~TestForm() {
|
||||
delete mft;
|
||||
delete ift;
|
||||
delete eft;
|
||||
}
|
||||
};
|
||||
|
||||
char* TestForm::weekdays[] = {
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
|
||||
"Friday", "Saturday", (char *)0 };
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class FormAction : public NCursesMenuItem
|
||||
{
|
||||
public:
|
||||
FormAction(const char *s) : NCursesMenuItem(s) {
|
||||
}
|
||||
|
||||
bool action() {
|
||||
TestForm F;
|
||||
Soft_Label_Key_Set* S = new Soft_Label_Key_Set;
|
||||
for(int i=1; i <= S->labels(); i++) {
|
||||
char buf[5];
|
||||
::sprintf(buf,"Frm%02d",i);
|
||||
(*S)[i] = buf; // Text
|
||||
(*S)[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification
|
||||
}
|
||||
NCursesApplication::getApplication()->push(*S);
|
||||
F();
|
||||
NCursesApplication::getApplication()->pop();
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class PadAction : public NCursesMenuItem
|
||||
{
|
||||
public:
|
||||
PadAction(const char* s) : NCursesMenuItem(s) {
|
||||
}
|
||||
|
||||
bool action() {
|
||||
const int GRIDSIZE = 3;
|
||||
const int PADSIZE = 200;
|
||||
unsigned gridcount = 0;
|
||||
|
||||
NCursesPanel std;
|
||||
NCursesPanel P(std.lines()-2,std.cols()-2,1,1);
|
||||
NCursesFramedPad FP(P,PADSIZE,PADSIZE);
|
||||
|
||||
for (int i=0; i < PADSIZE; i++) {
|
||||
for (int j=0; j < PADSIZE; j++) {
|
||||
if (i % GRIDSIZE == 0 && j % GRIDSIZE == 0) {
|
||||
if (i==0 || j==0)
|
||||
FP.addch('+');
|
||||
else
|
||||
FP.addch((chtype)('A' + (gridcount++ % 26)));
|
||||
}
|
||||
else if (i % GRIDSIZE == 0)
|
||||
FP.addch('-');
|
||||
else if (j % GRIDSIZE == 0)
|
||||
FP.addch('|');
|
||||
else
|
||||
FP.addch(' ');
|
||||
}
|
||||
}
|
||||
|
||||
P.label("Pad Demo",NULL);
|
||||
FP();
|
||||
P.clear();
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class PassiveItem : public NCursesMenuItem {
|
||||
public:
|
||||
PassiveItem(const char* text) : NCursesMenuItem(text) {
|
||||
options_off(O_SELECTABLE);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class ScanAction : public NCursesMenuItem
|
||||
{
|
||||
public:
|
||||
ScanAction(const char* s) : NCursesMenuItem(s) {
|
||||
}
|
||||
|
||||
bool action() {
|
||||
NCursesPanel *std = new NCursesPanel();
|
||||
|
||||
NCursesPanel *w = new NCursesPanel(std->lines() - 2, std->cols() - 2, 1, 1);
|
||||
w->box();
|
||||
w->refresh();
|
||||
|
||||
NCursesPanel *s = new NCursesPanel(w->lines() - 6, w->cols() - 6, 3, 3);
|
||||
s->scrollok(TRUE);
|
||||
::echo();
|
||||
|
||||
s->printw("Enter decimal integers. The running total will be shown\n");
|
||||
int value = -1;
|
||||
int result = 0;
|
||||
while (value != 0) {
|
||||
value = 0;
|
||||
s->scanw("%d", &value);
|
||||
if (value != 0) {
|
||||
s->printw("%d: ", result += value);
|
||||
}
|
||||
s->refresh();
|
||||
}
|
||||
s->printw("\nPress any key to continue...");
|
||||
s->getch();
|
||||
|
||||
delete s;
|
||||
delete w;
|
||||
delete std;
|
||||
::noecho();
|
||||
return FALSE;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class MyMenu : public NCursesMenu
|
||||
{
|
||||
private:
|
||||
NCursesPanel* P;
|
||||
NCursesMenuItem** I;
|
||||
UserData *u;
|
||||
#define n_items 7
|
||||
|
||||
public:
|
||||
MyMenu ()
|
||||
: NCursesMenu (n_items+2, 8, (lines()-10)/2, (cols()-10)/2)
|
||||
{
|
||||
u = new UserData(1);
|
||||
I = new NCursesMenuItem*[1+n_items];
|
||||
I[0] = new PassiveItem("One");
|
||||
I[1] = new PassiveItem("Two");
|
||||
I[2] = new MyAction<UserData> ("Silly", u);
|
||||
I[3] = new FormAction("Form");
|
||||
I[4] = new PadAction("Pad");
|
||||
I[5] = new ScanAction("Scan");
|
||||
I[6] = new QuitItem();
|
||||
I[7] = new NCursesMenuItem(); // Terminating empty item
|
||||
|
||||
InitMenu(I,TRUE,TRUE);
|
||||
|
||||
P = new NCursesPanel(1,n_items,LINES-1,1);
|
||||
boldframe("Demo","Silly");
|
||||
P->show();
|
||||
}
|
||||
|
||||
~MyMenu()
|
||||
{
|
||||
P->hide();
|
||||
delete P;
|
||||
delete u;
|
||||
}
|
||||
|
||||
virtual void On_Menu_Init()
|
||||
{
|
||||
NCursesWindow W(::stdscr);
|
||||
P->move(0,0);
|
||||
P->clrtoeol();
|
||||
for(int i=1; i<=count(); i++)
|
||||
P->addch('0' + i);
|
||||
P->bkgd(W.getbkgd());
|
||||
refresh();
|
||||
}
|
||||
|
||||
virtual void On_Menu_Termination()
|
||||
{
|
||||
P->move(0,0);
|
||||
P->clrtoeol();
|
||||
refresh();
|
||||
}
|
||||
|
||||
virtual void On_Item_Init(NCursesMenuItem& item)
|
||||
{
|
||||
P->move(0,item.index());
|
||||
P->attron(A_REVERSE);
|
||||
P->printw("%1d",1+item.index());
|
||||
P->attroff(A_REVERSE);
|
||||
refresh();
|
||||
}
|
||||
|
||||
virtual void On_Item_Termination(NCursesMenuItem& item)
|
||||
{
|
||||
P->move(0,item.index());
|
||||
P->attroff(A_REVERSE);
|
||||
P->printw("%1d",1+item.index());
|
||||
refresh();
|
||||
}
|
||||
};
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
class TestApplication : public NCursesApplication {
|
||||
protected:
|
||||
int titlesize() const { return 1; }
|
||||
void title();
|
||||
Soft_Label_Key_Set::Label_Layout useSLKs() const {
|
||||
return Soft_Label_Key_Set::PC_Style_With_Index;
|
||||
}
|
||||
void init_labels(Soft_Label_Key_Set& S) const;
|
||||
|
||||
public:
|
||||
TestApplication() : NCursesApplication(TRUE) {
|
||||
}
|
||||
|
||||
int run();
|
||||
};
|
||||
|
||||
void TestApplication::init_labels(Soft_Label_Key_Set& S) const {
|
||||
for(int i=1; i <= S.labels(); i++) {
|
||||
char buf[5];
|
||||
::sprintf(buf,"Key%02d",i);
|
||||
S[i] = buf; // Text
|
||||
S[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification
|
||||
}
|
||||
}
|
||||
|
||||
void TestApplication::title() {
|
||||
const char * const title = "Simple C++ Binding Demo";
|
||||
const int len = ::strlen(title);
|
||||
|
||||
titleWindow->bkgd(screen_titles());
|
||||
titleWindow->addstr(0,(titleWindow->cols()-len)/2,title);
|
||||
titleWindow->noutrefresh();
|
||||
}
|
||||
|
||||
|
||||
int TestApplication::run() {
|
||||
MyMenu M;
|
||||
M();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
static TestApplication Demo;
|
@ -1,70 +0,0 @@
|
||||
#!/bin/sh
|
||||
# $Id: edit_cfg.sh,v 1.12 2001/12/08 20:44:59 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998,2000,2001 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1997
|
||||
#
|
||||
# Edit the default value of the etip.h file based on the autoconf-generated
|
||||
# values:
|
||||
#
|
||||
# $1 = ncurses_cfg.h
|
||||
# $2 = etip.h
|
||||
#
|
||||
echo "substituting autoconf'd values from $1 into $2"
|
||||
for name in \
|
||||
CPP_HAS_PARAM_INIT \
|
||||
ETIP_NEEDS_MATH_EXCEPTION \
|
||||
ETIP_NEEDS_MATH_H \
|
||||
HAVE_BUILTIN_H \
|
||||
HAVE_GPP_BUILTIN_H \
|
||||
HAVE_GXX_BUILTIN_H \
|
||||
HAVE_STRSTREAM_H \
|
||||
HAVE_TYPEINFO \
|
||||
HAVE_VALUES_H \
|
||||
USE_STRSTREAM_VSCAN \
|
||||
USE_STRSTREAM_VSCAN_CAST
|
||||
do
|
||||
mv $2 $2.bak
|
||||
if ( grep "[ ]$name[ ]1" $1 2>&1 >/dev/null)
|
||||
then
|
||||
value=1
|
||||
sed -e 's/define '$name'.*$/define '$name' 1/' $2.bak >$2
|
||||
else
|
||||
value=0
|
||||
sed -e 's/define '$name'.*$/define '$name' 0/' $2.bak >$2
|
||||
fi
|
||||
if (cmp -s $2 $2.bak)
|
||||
then
|
||||
echo '... '$name $value
|
||||
mv $2.bak $2
|
||||
else
|
||||
echo '... '$name $value
|
||||
rm -f $2.bak
|
||||
fi
|
||||
done
|
@ -1,291 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: etip.h.in,v 1.22 2001/12/08 21:26:49 tom Exp $
|
||||
|
||||
#ifndef NCURSES_ETIP_H_incl
|
||||
#define NCURSES_ETIP_H_incl 1
|
||||
|
||||
// These are substituted at configure/build time
|
||||
#ifndef HAVE_BUILTIN_H
|
||||
#define HAVE_BUILTIN_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GXX_BUILTIN_H
|
||||
#define HAVE_GXX_BUILTIN_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GPP_BUILTIN_H
|
||||
#define HAVE_GPP_BUILTIN_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRSTREAM_H
|
||||
#define HAVE_STRSTREAM_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_TYPEINFO
|
||||
#define HAVE_TYPEINFO 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VALUES_H
|
||||
#define HAVE_VALUES_H 0
|
||||
#endif
|
||||
|
||||
#ifndef ETIP_NEEDS_MATH_H
|
||||
#define ETIP_NEEDS_MATH_H 0
|
||||
#endif
|
||||
|
||||
#ifndef ETIP_NEEDS_MATH_EXCEPTION
|
||||
#define ETIP_NEEDS_MATH_EXCEPTION 0
|
||||
#endif
|
||||
|
||||
#ifndef CPP_HAS_PARAM_INIT
|
||||
#define CPP_HAS_PARAM_INIT 0
|
||||
#endif
|
||||
|
||||
#ifndef USE_STRSTREAM_VSCAN
|
||||
#define USE_STRSTREAM_VSCAN 0
|
||||
#endif
|
||||
|
||||
#ifndef USE_STRSTREAM_VSCAN_CAST
|
||||
#define USE_STRSTREAM_VSCAN_CAST 0
|
||||
#endif
|
||||
|
||||
#ifdef __GNUG__
|
||||
# if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
|
||||
# if HAVE_TYPEINFO
|
||||
# include <typeinfo>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__GNUG__)
|
||||
# if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
|
||||
# if ETIP_NEEDS_MATH_H
|
||||
# if ETIP_NEEDS_MATH_EXCEPTION
|
||||
# undef exception
|
||||
# define exception math_exception
|
||||
# endif
|
||||
# include <math.h>
|
||||
# endif
|
||||
# undef exception
|
||||
# define exception builtin_exception
|
||||
# if HAVE_GPP_BUILTIN_H
|
||||
# include <gpp/builtin.h>
|
||||
# elif HAVE_GXX_BUILTIN_H
|
||||
# include <g++/builtin.h>
|
||||
# else
|
||||
# include <builtin.h>
|
||||
# endif
|
||||
# undef exception
|
||||
# endif
|
||||
#elif defined (__SUNPRO_CC)
|
||||
# include <generic.h>
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include <ncurses_dll.h>
|
||||
|
||||
extern "C" {
|
||||
#if HAVE_VALUES_H
|
||||
# include <values.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <eti.h>
|
||||
#include <errno.h>
|
||||
}
|
||||
|
||||
// Language features
|
||||
#if CPP_HAS_PARAM_INIT
|
||||
#define NCURSES_PARAM_INIT(value) = value
|
||||
#else
|
||||
#define NCURSES_PARAM_INIT(value) /*nothing*/
|
||||
#endif
|
||||
|
||||
// Forward Declarations
|
||||
class NCURSES_IMPEXP NCursesPanel;
|
||||
class NCURSES_IMPEXP NCursesMenu;
|
||||
class NCURSES_IMPEXP NCursesForm;
|
||||
|
||||
class NCURSES_IMPEXP NCursesException
|
||||
{
|
||||
public:
|
||||
const char *message;
|
||||
int errorno;
|
||||
|
||||
NCursesException (const char* msg, int err)
|
||||
: message(msg), errorno (err)
|
||||
{};
|
||||
|
||||
NCursesException (const char* msg)
|
||||
: message(msg), errorno (E_SYSTEM_ERROR)
|
||||
{};
|
||||
|
||||
virtual const char *classname() const {
|
||||
return "NCursesWindow";
|
||||
}
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP NCursesPanelException : public NCursesException
|
||||
{
|
||||
public:
|
||||
const NCursesPanel* p;
|
||||
|
||||
NCursesPanelException (const char *msg, int err) :
|
||||
NCursesException (msg, err),
|
||||
p ((NCursesPanel*)0)
|
||||
{};
|
||||
|
||||
NCursesPanelException (const NCursesPanel* panel,
|
||||
const char *msg,
|
||||
int err) :
|
||||
NCursesException (msg, err),
|
||||
p (panel)
|
||||
{};
|
||||
|
||||
NCursesPanelException (int err) :
|
||||
NCursesException ("panel library error", err),
|
||||
p ((NCursesPanel*)0)
|
||||
{};
|
||||
|
||||
NCursesPanelException (const NCursesPanel* panel,
|
||||
int err) :
|
||||
NCursesException ("panel library error", err),
|
||||
p (panel)
|
||||
{};
|
||||
|
||||
virtual const char *classname() const {
|
||||
return "NCursesPanel";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP NCursesMenuException : public NCursesException
|
||||
{
|
||||
public:
|
||||
const NCursesMenu* m;
|
||||
|
||||
NCursesMenuException (const char *msg, int err) :
|
||||
NCursesException (msg, err),
|
||||
m ((NCursesMenu *)0)
|
||||
{};
|
||||
|
||||
NCursesMenuException (const NCursesMenu* menu,
|
||||
const char *msg,
|
||||
int err) :
|
||||
NCursesException (msg, err),
|
||||
m (menu)
|
||||
{};
|
||||
|
||||
NCursesMenuException (int err) :
|
||||
NCursesException ("menu library error", err),
|
||||
m ((NCursesMenu *)0)
|
||||
{};
|
||||
|
||||
NCursesMenuException (const NCursesMenu* menu,
|
||||
int err) :
|
||||
NCursesException ("menu library error", err),
|
||||
m (menu)
|
||||
{};
|
||||
|
||||
virtual const char *classname() const {
|
||||
return "NCursesMenu";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class NCURSES_IMPEXP NCursesFormException : public NCursesException
|
||||
{
|
||||
public:
|
||||
const NCursesForm* f;
|
||||
|
||||
NCursesFormException (const char *msg, int err) :
|
||||
NCursesException (msg, err),
|
||||
f ((NCursesForm*)0)
|
||||
{};
|
||||
|
||||
NCursesFormException (const NCursesForm* form,
|
||||
const char *msg,
|
||||
int err) :
|
||||
NCursesException (msg, err),
|
||||
f (form)
|
||||
{};
|
||||
|
||||
NCursesFormException (int err) :
|
||||
NCursesException ("form library error", err),
|
||||
f ((NCursesForm*)0)
|
||||
{};
|
||||
|
||||
NCursesFormException (const NCursesForm* form,
|
||||
int err) :
|
||||
NCursesException ("form library error", err),
|
||||
f (form)
|
||||
{};
|
||||
|
||||
virtual const char *classname() const {
|
||||
return "NCursesForm";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#if !(defined(__GNUG__)||defined(__SUNPRO_CC))
|
||||
# include <iostream.h>
|
||||
extern "C" void exit(int);
|
||||
#endif
|
||||
|
||||
inline void THROW(const NCursesException *e) {
|
||||
#if defined(__GNUG__)
|
||||
# if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
|
||||
(*lib_error_handler)(e?e->classname():"",e?e->message:"");
|
||||
#else
|
||||
throw *e;
|
||||
#endif
|
||||
#elif defined(__SUNPRO_CC)
|
||||
# if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
|
||||
genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
|
||||
#else
|
||||
throw *e;
|
||||
#endif
|
||||
#else
|
||||
if (e)
|
||||
cerr << e->message << endl;
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define THROWS(s)
|
||||
|
||||
#endif // NCURSES_ETIP_H_incl
|
@ -1,39 +0,0 @@
|
||||
# C++ headers
|
||||
# $Id: headers,v 1.2 1998/02/11 12:13:40 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1997
|
||||
#
|
||||
$(srcdir)/cursesapp.h
|
||||
$(srcdir)/cursesf.h
|
||||
$(srcdir)/cursesm.h
|
||||
$(srcdir)/cursesp.h
|
||||
$(srcdir)/cursesw.h
|
||||
$(srcdir)/cursslk.h
|
||||
etip.h
|
@ -1,49 +0,0 @@
|
||||
// * This makes emacs happy -*-Mode: C++;-*-
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1997 *
|
||||
****************************************************************************/
|
||||
|
||||
// $Id: internal.h,v 1.8 2001/03/24 21:36:17 tom Exp $
|
||||
|
||||
#ifndef NCURSES_CPLUS_INTERNAL_H
|
||||
#define NCURSES_CPLUS_INTERNAL_H 1
|
||||
|
||||
#include <ncurses_cfg.h>
|
||||
|
||||
#if USE_RCS_IDS
|
||||
#define MODULE_ID(id) static const char Ident[] = id;
|
||||
#else
|
||||
#define MODULE_ID(id) /*nothing*/
|
||||
#endif
|
||||
|
||||
#define CTRL(x) ((x) & 0x1f)
|
||||
|
||||
#endif // NCURSES_CPLUS_INTERNAL_H
|
@ -1,43 +0,0 @@
|
||||
# Program modules
|
||||
# $Id: modules,v 1.6 1999/07/31 09:46:54 juergen Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1995,1997
|
||||
#
|
||||
|
||||
@ base
|
||||
cursesf c++ $(srcdir) $(cursesf_h) $(cursesapp_h)
|
||||
cursesm c++ $(srcdir) $(cursesm_h) $(cursesapp_h)
|
||||
cursesp c++ $(srcdir) $(cursesp_h)
|
||||
cursesw c++ $(srcdir) $(cursesw_h)
|
||||
cursespad c++ $(srcdir) $(cursesw_h)
|
||||
cursslk c++ $(srcdir) $(cursslk_h) $(cursesapp_h)
|
||||
cursesapp c++ $(srcdir) $(cursesapp_h)
|
||||
cursesmain c++ $(srcdir) $(cursesapp_h)
|
||||
demo c++ $(srcdir) $(cursesf_h) $(cursesm_h) $(cursesapp_h)
|
@ -1,35 +0,0 @@
|
||||
/* Use this with indent 2.0 (2.1 is not acceptable, since it has more bugs) */
|
||||
/* indent 4 columns */
|
||||
-i4
|
||||
/* tab stops every 8 columns */
|
||||
-ts8
|
||||
/* cuddle 'else' */
|
||||
-ce
|
||||
/* force blank lines after procedure body */
|
||||
-bap
|
||||
/* do not force newline after comma in declaration */
|
||||
-nbc
|
||||
/* do not force blank line after declarations */
|
||||
-nbad
|
||||
/* format braces inline */
|
||||
-br
|
||||
/* do not line up parentheses */
|
||||
-lp
|
||||
/* put the type of a procedure on the line before its name */
|
||||
-psl
|
||||
/* do not insert a space between procedure name and '(' */
|
||||
-npcs
|
||||
/* leave preprocessor space */
|
||||
-lps
|
||||
/* swallow optional blank lines */
|
||||
-sob
|
||||
/* continuation indent of 0 spaces */
|
||||
-ci0
|
||||
/* force space before semicolon on same line */
|
||||
-ss
|
||||
|
||||
/* for vile */
|
||||
-T size_t
|
||||
-T LINE
|
||||
-T BUFFER
|
||||
-T WINDOW
|
@ -1,83 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,1999,2000,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
|
||||
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
** lib_insstr.c
|
||||
**
|
||||
** The routine winsnstr().
|
||||
**
|
||||
*/
|
||||
|
||||
#include <curses.priv.h>
|
||||
#include <ctype.h>
|
||||
|
||||
MODULE_ID("$Id: lib_insstr.c,v 1.19 2001/06/09 23:43:02 skimo Exp $")
|
||||
|
||||
NCURSES_EXPORT(int)
|
||||
winsnstr(WINDOW *win, const char *s, int n)
|
||||
{
|
||||
int code = ERR;
|
||||
NCURSES_SIZE_T oy;
|
||||
NCURSES_SIZE_T ox;
|
||||
const unsigned char *str = (const unsigned char *) s;
|
||||
const unsigned char *cp;
|
||||
|
||||
T((T_CALLED("winsnstr(%p,%s,%d)"), win, _nc_visbuf(s), n));
|
||||
|
||||
if (win && str) {
|
||||
oy = win->_cury;
|
||||
ox = win->_curx;
|
||||
for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
|
||||
if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') {
|
||||
NCURSES_CH_T wch;
|
||||
SetChar2(wch, *cp);
|
||||
_nc_waddch_nosync(win, wch);
|
||||
} else if (is7bits(*cp) && iscntrl(*cp)) {
|
||||
winsch(win, ' ' + (chtype) (*cp));
|
||||
winsch(win, (chtype) '^');
|
||||
win->_curx += 2;
|
||||
} else {
|
||||
winsch(win, (chtype) (*cp));
|
||||
win->_curx++;
|
||||
}
|
||||
if (win->_curx > win->_maxx)
|
||||
win->_curx = win->_maxx;
|
||||
}
|
||||
|
||||
win->_curx = ox;
|
||||
win->_cury = oy;
|
||||
_nc_synchook(win);
|
||||
code = OK;
|
||||
}
|
||||
returnCode(code);
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2002 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Thomas Dickey 2002 *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
** lib_ins_nwstr.c
|
||||
**
|
||||
** The routine wins_nwstr().
|
||||
**
|
||||
*/
|
||||
|
||||
#include <curses.priv.h>
|
||||
#include <ctype.h>
|
||||
|
||||
MODULE_ID("$Id: lib_ins_nwstr.c,v 1.2 2002/03/10 22:43:12 tom Exp $")
|
||||
|
||||
NCURSES_EXPORT(int)
|
||||
wins_nwstr(WINDOW *win, const wchar_t * wstr, int n)
|
||||
{
|
||||
int code = ERR;
|
||||
NCURSES_SIZE_T oy;
|
||||
NCURSES_SIZE_T ox;
|
||||
const wchar_t *cp;
|
||||
|
||||
T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbuf(wstr), n));
|
||||
|
||||
if (win != 0
|
||||
&& wstr != 0
|
||||
&& wcwidth(*wstr) > 0) {
|
||||
code = OK;
|
||||
if (n < 1)
|
||||
n = wcslen(wstr);
|
||||
oy = win->_cury;
|
||||
ox = win->_curx;
|
||||
for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
|
||||
NCURSES_CH_T wch;
|
||||
SetChar2(wch, *cp);
|
||||
if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') {
|
||||
_nc_waddch_nosync(win, wch);
|
||||
} else if (is7bits(*cp) && iscntrl(*cp)) {
|
||||
winsch(win, ' ' + (chtype) (*cp));
|
||||
winsch(win, (chtype) '^');
|
||||
win->_curx += 2;
|
||||
} else if (wins_wch(win, &wch) == ERR
|
||||
|| win->_curx > win->_maxx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
win->_curx = ox;
|
||||
win->_cury = oy;
|
||||
_nc_synchook(win);
|
||||
code = OK;
|
||||
}
|
||||
returnCode(code);
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
# $Id: Makefile.in,v 1.63 2002/02/03 00:54:10 china Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998,1999,2000,2001 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1996,1997,1998
|
||||
#
|
||||
# Makefile for ncurses tests.
|
||||
|
||||
# turn off _all_ suffix rules; we'll generate our own
|
||||
.SUFFIXES:
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
x = @PROG_EXT@
|
||||
|
||||
MODEL = ../@DFT_OBJ_SUBDIR@
|
||||
srcdir = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
libdir = @libdir@
|
||||
includedir = @includedir@
|
||||
|
||||
LIBTOOL = @LIBTOOL@
|
||||
|
||||
CC = @CC@
|
||||
CPP = @CPP@
|
||||
|
||||
CFLAGS = @CFLAGS@
|
||||
CPPFLAGS = -I../test -I$(srcdir) @CPPFLAGS@ -DHAVE_CONFIG_H
|
||||
|
||||
CCFLAGS = $(CPPFLAGS) $(CFLAGS)
|
||||
|
||||
CFLAGS_LIBTOOL = $(CCFLAGS)
|
||||
CFLAGS_NORMAL = $(CCFLAGS)
|
||||
CFLAGS_DEBUG = $(CCFLAGS) @CC_G_OPT@ -DTRACE
|
||||
CFLAGS_PROFILE = $(CCFLAGS) -pg
|
||||
CFLAGS_SHARED = $(CCFLAGS) @CC_SHARED_OPTS@
|
||||
|
||||
CFLAGS_DEFAULT = $(CFLAGS_@DFT_UPR_MODEL@)
|
||||
|
||||
REL_VERSION = @cf_cv_rel_version@
|
||||
ABI_VERSION = @cf_cv_abi_version@
|
||||
LOCAL_LIBS = @TEST_DEPS@
|
||||
MATH_LIB = @MATH_LIB@
|
||||
|
||||
LD = @LD@
|
||||
LINK = @LINK_TESTS@ $(LIBTOOL) $(CC) $(CFLAGS)
|
||||
|
||||
LDFLAGS = @LD_MODEL@ @TEST_ARGS@ @LIBS@ @EXTRA_LIBS@ @LOCAL_LDFLAGS@ @LDFLAGS@
|
||||
|
||||
LDFLAGS_LIBTOOL = $(LDFLAGS)
|
||||
LDFLAGS_NORMAL = $(LDFLAGS)
|
||||
LDFLAGS_DEBUG = $(LDFLAGS) @CC_G_OPT@
|
||||
LDFLAGS_PROFILE = $(LDFLAGS) -pg
|
||||
LDFLAGS_SHARED = $(LDFLAGS) @LD_SHARED_OPTS@
|
||||
|
||||
LDFLAGS_DEFAULT = $(LDFLAGS_@DFT_UPR_MODEL@)
|
||||
|
||||
LINT = @LINT@
|
||||
LINT_OPTS = @LINT_OPTS@
|
||||
LINT_LIBS = -lform -lmenu -lpanel -lncurses @LIBS@
|
||||
|
||||
TESTS = \
|
||||
blue$x \
|
||||
bs$x \
|
||||
cardfile$x \
|
||||
ditto$x \
|
||||
dots$x \
|
||||
filter$x \
|
||||
firework$x \
|
||||
firstlast$x \
|
||||
gdc$x \
|
||||
hanoi$x \
|
||||
hashtest$x \
|
||||
keynames$x \
|
||||
knight$x \
|
||||
lrtest$x \
|
||||
ncurses$x \
|
||||
newdemo$x \
|
||||
rain$x \
|
||||
railroad$x \
|
||||
tclock$x \
|
||||
testaddch$x \
|
||||
testcurs$x \
|
||||
testscanw$x \
|
||||
view$x \
|
||||
worm$x \
|
||||
xmas$x
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
sources:
|
||||
|
||||
blue$x: $(MODEL)/blue.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/blue.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
bs$x: $(MODEL)/bs.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/bs.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
cardfile$x: $(MODEL)/cardfile.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/cardfile.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
ditto$x: $(MODEL)/ditto.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/ditto.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
dots$x: $(MODEL)/dots.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/dots.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
filter$x: $(MODEL)/filter.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/filter.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
firework$x: $(MODEL)/firework.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/firework.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
firstlast$x: $(MODEL)/firstlast.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/firstlast.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
gdc$x: $(MODEL)/gdc.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/gdc.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
hanoi$x: $(MODEL)/hanoi.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/hanoi.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
hashtest$x: $(MODEL)/hashtest.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/hashtest.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
keynames$x: $(MODEL)/keynames.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/keynames.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
knight$x: $(MODEL)/knight.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/knight.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
lrtest$x: $(MODEL)/lrtest.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/lrtest.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
ncurses$x: $(MODEL)/ncurses.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/ncurses.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
newdemo$x: $(MODEL)/newdemo.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/newdemo.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
rain$x: $(MODEL)/rain.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/rain.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
railroad$x: $(MODEL)/railroad.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/railroad.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
tclock$x: $(MODEL)/tclock.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/tclock.o $(LDFLAGS_DEFAULT) $(MATH_LIB)
|
||||
|
||||
testaddch$x: $(MODEL)/testaddch.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/testaddch.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
testcurs$x: $(MODEL)/testcurs.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/testcurs.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
testscanw$x: $(MODEL)/testscanw.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/testscanw.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
view$x: $(MODEL)/view.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/view.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
worm$x: $(MODEL)/worm.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/worm.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
xmas$x: $(MODEL)/xmas.o $(LOCAL_LIBS)
|
||||
@ECHO_LINK@ $(LINK) -o $@ $(MODEL)/xmas.o $(LDFLAGS_DEFAULT)
|
||||
|
||||
libs \
|
||||
install \
|
||||
install.libs \
|
||||
install.test:
|
||||
|
||||
uninstall:
|
||||
uninstall.libs:
|
||||
uninstall.test:
|
||||
|
||||
mostlyclean ::
|
||||
-rm -f core tags TAGS *~ *.bak *.i *.ln *.atac trace
|
||||
|
||||
clean :: mostlyclean
|
||||
-rm -rf *.o screendump *.lis $(TESTS) .libs
|
||||
|
||||
distclean :: clean
|
||||
-rm -f Makefile ncurses_cfg.h config.*
|
||||
|
||||
realclean :: distclean
|
||||
|
||||
lint:
|
||||
sh -c 'for N in $(TESTS); do echo LINT:$$N; $(LINT) $(LINT_OPTS) $(CPPFLAGS) $(srcdir)/$$N.c $(LINT_LIBS); done'
|
||||
|
||||
# Use this to get a list of test-programs for the standalone configure script.
|
||||
echo_tests :
|
||||
@echo "$(TESTS)"
|
||||
echo_suffix :
|
||||
@echo "$x"
|
@ -1,22 +0,0 @@
|
||||
The programs in this directory are designed to test your newest toy :-)
|
||||
Check the sources for any further details.
|
||||
|
||||
blue - Blue Moon, a nifty solitaire (uses color)
|
||||
bs.c - the game of Battleships (uses color)
|
||||
firework.c - multi-colored fireworks (uses color)
|
||||
gdc.c - Great Digital Clock (uses color)
|
||||
hanoi.c - the game of hanoi (uses color essentially)
|
||||
knight.c - the game of Knight's Tour (uses color)
|
||||
lrtest.c - test of access to the lower-right corner
|
||||
ncurses.c - multi-test program (uses color)
|
||||
newdemo.c - another test from PDCurses (uses color)
|
||||
rain.c - rain drops keep falling on my head...
|
||||
tclock.c - analog/digital clock
|
||||
testcurs.c - a test from the PDCurses people (uses color)
|
||||
worm.c - worms run all over your screen (uses color)
|
||||
xmas.c - Xmas greeting card
|
||||
|
||||
The bs and knight games demonstrate processing of mouse events under xterm.
|
||||
This directory also contains:
|
||||
|
||||
tracemunch - Perl script to crunch trace scripts to make them easier to read
|
@ -1,429 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* *
|
||||
* B l u e M o o n *
|
||||
* ================= *
|
||||
* V2.2 *
|
||||
* A patience game by T.A.Lister *
|
||||
* Integral screen support by Eric S. Raymond *
|
||||
* *
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* Compile this with the command `cc -O blue.c -lcurses -o blue'. For best
|
||||
* results, use the ncurses(3) library. On non-Intel machines, SVr4 curses is
|
||||
* just as good.
|
||||
*
|
||||
* $Id: blue.c,v 1.23 2002/04/06 23:05:16 tom Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define NOCARD (-1)
|
||||
|
||||
#define ACE 0
|
||||
#define KING 12
|
||||
#define SUIT_LENGTH 13
|
||||
|
||||
#define HEARTS 0
|
||||
#define SPADES 1
|
||||
#define DIAMONDS 2
|
||||
#define CLUBS 3
|
||||
#define NSUITS 4
|
||||
|
||||
#define GRID_WIDTH 14 /* 13+1 */
|
||||
#define GRID_LENGTH 56 /* 4*(13+1) */
|
||||
#define PACK_SIZE 52
|
||||
|
||||
#define BASEROW 1
|
||||
#define PROMPTROW 11
|
||||
|
||||
#define RED_ON_WHITE 1
|
||||
#define BLACK_ON_WHITE 2
|
||||
#define BLUE_ON_WHITE 3
|
||||
|
||||
static RETSIGTYPE die(int onsig) GCC_NORETURN;
|
||||
|
||||
static int deck_size = PACK_SIZE; /* initial deck */
|
||||
static int deck[PACK_SIZE];
|
||||
|
||||
static int grid[GRID_LENGTH]; /* card layout grid */
|
||||
static int freeptr[4]; /* free card space pointers */
|
||||
|
||||
static int deal_number = 0;
|
||||
|
||||
static chtype ranks[SUIT_LENGTH][2] =
|
||||
{
|
||||
{' ', 'A'},
|
||||
{' ', '2'},
|
||||
{' ', '3'},
|
||||
{' ', '4'},
|
||||
{' ', '5'},
|
||||
{' ', '6'},
|
||||
{' ', '7'},
|
||||
{' ', '8'},
|
||||
{' ', '9'},
|
||||
{'1', '0'},
|
||||
{' ', 'J'},
|
||||
{' ', 'Q'},
|
||||
{' ', 'K'}
|
||||
};
|
||||
|
||||
/* Please note, that this is a bad example.
|
||||
Color values should not be or'ed in. This
|
||||
only works, because the characters used here
|
||||
are plain and have no color attribute themselves. */
|
||||
#ifdef COLOR_PAIR
|
||||
#define OR_COLORS(value,pair) ((value) | COLOR_PAIR(pair))
|
||||
#else
|
||||
#define OR_COLORS(value,pair) (value)
|
||||
#endif
|
||||
|
||||
#define PC_COLORS(value,pair) (OR_COLORS(value,pair) | A_ALTCHARSET)
|
||||
|
||||
static chtype letters[4] =
|
||||
{
|
||||
OR_COLORS('h', RED_ON_WHITE), /* hearts */
|
||||
OR_COLORS('s', BLACK_ON_WHITE), /* spades */
|
||||
OR_COLORS('d', RED_ON_WHITE), /* diamonds */
|
||||
OR_COLORS('c', BLACK_ON_WHITE), /* clubs */
|
||||
};
|
||||
|
||||
#if defined(__i386__)
|
||||
static chtype glyphs[] =
|
||||
{
|
||||
PC_COLORS('\003', RED_ON_WHITE), /* hearts */
|
||||
PC_COLORS('\006', BLACK_ON_WHITE), /* spades */
|
||||
PC_COLORS('\004', RED_ON_WHITE), /* diamonds */
|
||||
PC_COLORS('\005', BLACK_ON_WHITE), /* clubs */
|
||||
};
|
||||
#endif /* __i386__ */
|
||||
|
||||
static chtype *suits = letters; /* this may change to glyphs below */
|
||||
|
||||
static RETSIGTYPE
|
||||
die(int onsig)
|
||||
{
|
||||
(void) signal(onsig, SIG_IGN);
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
init_vars(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
deck_size = PACK_SIZE;
|
||||
for (i = 0; i < PACK_SIZE; i++)
|
||||
deck[i] = i;
|
||||
for (i = 0; i < 4; i++)
|
||||
freeptr[i] = i * GRID_WIDTH;
|
||||
}
|
||||
|
||||
static void
|
||||
shuffle(int size)
|
||||
{
|
||||
int i, j, numswaps, swapnum, temp;
|
||||
|
||||
numswaps = size * 10; /* an arbitrary figure */
|
||||
|
||||
for (swapnum = 0; swapnum < numswaps; swapnum++) {
|
||||
i = rand() % size;
|
||||
j = rand() % size;
|
||||
temp = deck[i];
|
||||
deck[i] = deck[j];
|
||||
deck[j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
deal_cards(void)
|
||||
{
|
||||
int ptr, card = 0, value, csuit, crank, suit, aces[4];
|
||||
|
||||
for (suit = HEARTS; suit <= CLUBS; suit++) {
|
||||
ptr = freeptr[suit];
|
||||
grid[ptr++] = NOCARD; /* 1st card space is blank */
|
||||
while ((ptr % GRID_WIDTH) != 0) {
|
||||
value = deck[card++];
|
||||
crank = value % SUIT_LENGTH;
|
||||
csuit = value / SUIT_LENGTH;
|
||||
if (crank == ACE)
|
||||
aces[csuit] = ptr;
|
||||
grid[ptr++] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (deal_number == 1) /* shift the aces down to the 1st column */
|
||||
for (suit = HEARTS; suit <= CLUBS; suit++) {
|
||||
grid[suit * GRID_WIDTH] = suit * SUIT_LENGTH;
|
||||
grid[aces[suit]] = NOCARD;
|
||||
freeptr[suit] = aces[suit];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
printcard(int value)
|
||||
{
|
||||
(void) addch(' ');
|
||||
if (value == NOCARD)
|
||||
(void) addstr(" ");
|
||||
else {
|
||||
addch(ranks[value % SUIT_LENGTH][0] | COLOR_PAIR(BLUE_ON_WHITE));
|
||||
addch(ranks[value % SUIT_LENGTH][1] | COLOR_PAIR(BLUE_ON_WHITE));
|
||||
addch(suits[value / SUIT_LENGTH]);
|
||||
}
|
||||
(void) addch(' ');
|
||||
}
|
||||
|
||||
static void
|
||||
display_cards(int deal)
|
||||
{
|
||||
int row, card;
|
||||
|
||||
clear();
|
||||
(void) printw(
|
||||
"Blue Moon 2.1 - by Tim Lister & Eric Raymond - Deal %d.\n",
|
||||
deal);
|
||||
for (row = HEARTS; row <= CLUBS; row++) {
|
||||
move(BASEROW + row + row + 2, 1);
|
||||
for (card = 0; card < GRID_WIDTH; card++)
|
||||
printcard(grid[row * GRID_WIDTH + card]);
|
||||
}
|
||||
|
||||
move(PROMPTROW + 2, 0);
|
||||
refresh();
|
||||
#define P(x) (void)printw("%s\n", x)
|
||||
P(" This 52-card solitaire starts with the entire deck shuffled and dealt");
|
||||
P("out in four rows. The aces are then moved to the left end of the layout,");
|
||||
P("making 4 initial free spaces. You may move to a space only the card that");
|
||||
P("matches the left neighbor in suit, and is one greater in rank. Kings are");
|
||||
P("high, so no cards may be placed to their right (they create dead spaces).");
|
||||
P(" When no moves can be made, cards still out of sequence are reshuffled");
|
||||
P("and dealt face up after the ends of the partial sequences, leaving a card");
|
||||
P("space after each sequence, so that each row looks like a partial sequence");
|
||||
P("followed by a space, followed by enough cards to make a row of 14. ");
|
||||
P(" A moment's reflection will show that this game cannot take more than 13");
|
||||
P("deals. A good score is 1-3 deals, 4-7 is average, 8 or more is poor. ");
|
||||
#undef P
|
||||
refresh();
|
||||
}
|
||||
|
||||
static int
|
||||
find(int card)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ((card < 0) || (card >= PACK_SIZE))
|
||||
return (NOCARD);
|
||||
for (i = 0; i < GRID_LENGTH; i++)
|
||||
if (grid[i] == card)
|
||||
return i;
|
||||
return (NOCARD);
|
||||
}
|
||||
|
||||
static void
|
||||
movecard(int src, int dst)
|
||||
{
|
||||
grid[dst] = grid[src];
|
||||
grid[src] = NOCARD;
|
||||
|
||||
move(BASEROW + (dst / GRID_WIDTH) * 2 + 2, (dst % GRID_WIDTH) * 5 + 1);
|
||||
printcard(grid[dst]);
|
||||
|
||||
move(BASEROW + (src / GRID_WIDTH) * 2 + 2, (src % GRID_WIDTH) * 5 + 1);
|
||||
printcard(grid[src]);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void
|
||||
play_game(void)
|
||||
{
|
||||
int dead = 0, i, j;
|
||||
char c;
|
||||
int selection[4], card;
|
||||
|
||||
while (dead < 4) {
|
||||
dead = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
card = grid[freeptr[i] - 1];
|
||||
|
||||
if (((card % SUIT_LENGTH) == KING)
|
||||
||
|
||||
(card == NOCARD))
|
||||
selection[i] = NOCARD;
|
||||
else
|
||||
selection[i] = find(card + 1);
|
||||
|
||||
if (selection[i] == NOCARD)
|
||||
dead++;
|
||||
};
|
||||
|
||||
if (dead < 4) {
|
||||
char live[NSUITS + 1], *lp = live;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (selection[i] != NOCARD) {
|
||||
move(BASEROW + (selection[i] / GRID_WIDTH) * 2 + 3,
|
||||
(selection[i] % GRID_WIDTH) * 5);
|
||||
(void) printw(" %c ", *lp++ = 'a' + i);
|
||||
}
|
||||
};
|
||||
*lp = '\0';
|
||||
|
||||
if (strlen(live) == 1) {
|
||||
move(PROMPTROW, 0);
|
||||
(void) printw(
|
||||
"Making forced moves... ");
|
||||
refresh();
|
||||
(void) sleep(1);
|
||||
c = live[0];
|
||||
} else {
|
||||
char buf[BUFSIZ];
|
||||
|
||||
(void) sprintf(buf,
|
||||
"Type [%s] to move, r to redraw, q or INTR to quit: ",
|
||||
live);
|
||||
|
||||
do {
|
||||
move(PROMPTROW, 0);
|
||||
(void) addstr(buf);
|
||||
move(PROMPTROW, (int) strlen(buf));
|
||||
clrtoeol();
|
||||
(void) addch(' ');
|
||||
} while
|
||||
(((c = getch()) < 'a' || c > 'd') && (c != 'r') && (c != 'q'));
|
||||
}
|
||||
|
||||
for (j = 0; j < 4; j++)
|
||||
if (selection[j] != NOCARD) {
|
||||
move(BASEROW + (selection[j] / GRID_WIDTH) * 2 + 3,
|
||||
(selection[j] % GRID_WIDTH) * 5);
|
||||
(void) printw(" ");
|
||||
}
|
||||
|
||||
if (c == 'r')
|
||||
display_cards(deal_number);
|
||||
else if (c == 'q')
|
||||
die(SIGINT);
|
||||
else {
|
||||
i = c - 'a';
|
||||
if (selection[i] == NOCARD)
|
||||
beep();
|
||||
else {
|
||||
movecard(selection[i], freeptr[i]);
|
||||
freeptr[i] = selection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
move(PROMPTROW, 0);
|
||||
standout();
|
||||
(void) printw("Finished deal %d - type any character to continue...", deal_number);
|
||||
standend();
|
||||
(void) getch();
|
||||
}
|
||||
|
||||
static int
|
||||
collect_discards(void)
|
||||
{
|
||||
int row, col, cardno = 0, finish, gridno;
|
||||
|
||||
for (row = HEARTS; row <= CLUBS; row++) {
|
||||
finish = 0;
|
||||
for (col = 1; col < GRID_WIDTH; col++) {
|
||||
gridno = row * GRID_WIDTH + col;
|
||||
|
||||
if ((grid[gridno] != (grid[gridno - 1] + 1)) && (finish == 0)) {
|
||||
finish = 1;
|
||||
freeptr[row] = gridno;
|
||||
};
|
||||
|
||||
if ((finish != 0) && (grid[gridno] != NOCARD))
|
||||
deck[cardno++] = grid[gridno];
|
||||
}
|
||||
}
|
||||
return cardno;
|
||||
}
|
||||
|
||||
static void
|
||||
game_finished(int deal)
|
||||
{
|
||||
clear();
|
||||
(void) printw("You finished the game in %d deals. This is ", deal);
|
||||
standout();
|
||||
if (deal < 2)
|
||||
(void) addstr("excellent");
|
||||
else if (deal < 4)
|
||||
(void) addstr("good");
|
||||
else if (deal < 8)
|
||||
(void) addstr("average");
|
||||
else
|
||||
(void) addstr("poor");
|
||||
standend();
|
||||
(void) addstr(". ");
|
||||
refresh();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
(void) signal(SIGINT, die);
|
||||
initscr();
|
||||
|
||||
/*
|
||||
* We use COLOR_GREEN because COLOR_BLACK is wired to the wrong thing.
|
||||
*/
|
||||
start_color();
|
||||
init_pair(RED_ON_WHITE, COLOR_RED, COLOR_WHITE);
|
||||
init_pair(BLUE_ON_WHITE, COLOR_BLUE, COLOR_WHITE);
|
||||
init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
|
||||
|
||||
#ifndef COLOR_PAIR
|
||||
letters[0] = OR_COLORS('h', RED_ON_WHITE); /* hearts */
|
||||
letters[1] = OR_COLORS('s', BLACK_ON_WHITE); /* spades */
|
||||
letters[2] = OR_COLORS('d', RED_ON_WHITE); /* diamonds */
|
||||
letters[3] = OR_COLORS('c', BLACK_ON_WHITE); /* clubs */
|
||||
#if defined(__i386__) && defined(A_ALTCHARSET)
|
||||
glyphs[0] = PC_COLORS('\003', RED_ON_WHITE); /* hearts */
|
||||
glyphs[1] = PC_COLORS('\006', BLACK_ON_WHITE); /* spades */
|
||||
glyphs[2] = PC_COLORS('\004', RED_ON_WHITE); /* diamonds */
|
||||
glyphs[3] = PC_COLORS('\005', BLACK_ON_WHITE); /* clubs */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) && defined(A_ALTCHARSET)
|
||||
if (tigetstr("smpch"))
|
||||
suits = glyphs;
|
||||
#endif /* __i386__ && A_ALTCHARSET */
|
||||
|
||||
cbreak();
|
||||
|
||||
if (argc == 2)
|
||||
srand((unsigned) atoi(argv[1]));
|
||||
else
|
||||
srand((unsigned) time((time_t *) 0));
|
||||
|
||||
init_vars();
|
||||
|
||||
do {
|
||||
deal_number++;
|
||||
shuffle(deck_size);
|
||||
deal_cards();
|
||||
display_cards(deal_number);
|
||||
play_game();
|
||||
}
|
||||
while
|
||||
((deck_size = collect_discards()) != 0);
|
||||
|
||||
game_finished(deal_number);
|
||||
|
||||
die(SIGINT);
|
||||
/*NOTREACHED */
|
||||
}
|
||||
|
||||
/* blue.c ends here */
|
@ -1,42 +0,0 @@
|
||||
.TH BATTLESHIPS 6 "Aug 23, 1989"
|
||||
.SH NAME
|
||||
bs \- battleships game
|
||||
.SH SYNOPSIS
|
||||
battle [ -b | -s ] [ -c ]
|
||||
.SH DESCRIPTION
|
||||
This program allows you to play the familiar Battleships game against the
|
||||
computer on a 10x10 board. The interface is visual and largely
|
||||
self-explanatory; you place your ships and pick your shots by moving the
|
||||
cursor around the `sea' with the rogue/hack motion keys hjklyubn.
|
||||
.PP
|
||||
Note that when selecting a ship to place, you must type the capital letter
|
||||
(these are, after all, capital ships). During ship placement, the `r' command
|
||||
may be used to ignore the current position and randomly place your currently
|
||||
selected ship. The `R' command will place all remaining ships randomly. The ^L
|
||||
command (form feed, ASCII 12) will force a screen redraw).
|
||||
.PP
|
||||
The command-line arguments control game modes.
|
||||
|
||||
.nf
|
||||
-b selects a `blitz' variant
|
||||
-s selects a `salvo' variant
|
||||
-c permits ships to be placed adjacently
|
||||
.fi
|
||||
|
||||
The `blitz' variant allows a side to shoot for as long as it continues to
|
||||
score hits.
|
||||
.PP
|
||||
The `salvo' game allows a player one shot per turn for each of his/her ships
|
||||
still afloat. This puts a premium scoring hits early and knocking out some
|
||||
ships and also makes much harder the situation where you face a superior force
|
||||
with only your PT-boat.
|
||||
.PP
|
||||
Normally, ships must be separated by at least one square of open water. The
|
||||
-c option disables this check and allows them to close-pack.
|
||||
.PP
|
||||
The algorithm the computer uses once it has found a ship to sink is provably
|
||||
optimal. The dispersion criterion for the random-fire algorithm may not be.
|
||||
.SH AUTHORS
|
||||
Originally written by one Bruce Holloway in 1986. Salvo mode added by Chuck A.
|
||||
DeGaul (cbosgd!cad). Visual user interface, `closepack' option, code rewrite
|
||||
and manual page by Eric S. Raymond <esr@snark.thyrsus.com> August 1989.
|
File diff suppressed because it is too large
Load Diff
@ -1,434 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1999-2001,2002 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1999
|
||||
*
|
||||
* $Id: cardfile.c,v 1.11 2002/04/06 23:12:50 tom Exp $
|
||||
*
|
||||
* File format: text beginning in column 1 is a title; other text forms the content.
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#if HAVE_FORM_H && HAVE_PANEL_H && HAVE_LIBFORM && HAVE_LIBPANEL
|
||||
|
||||
#include <form.h>
|
||||
#include <panel.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#define VISIBLE_CARDS 10
|
||||
#define OFFSET_CARD 2
|
||||
|
||||
#ifndef CTRL
|
||||
#define CTRL(x) ((x) & 0x1f)
|
||||
#endif
|
||||
|
||||
typedef struct _card {
|
||||
struct _card *link;
|
||||
PANEL *panel;
|
||||
FORM *form;
|
||||
char *title;
|
||||
char *content;
|
||||
} CARD;
|
||||
|
||||
static CARD *all_cards;
|
||||
static char default_name[] = "cardfile.dat";
|
||||
|
||||
#if !HAVE_STRDUP
|
||||
#define strdup my_strdup
|
||||
static char *
|
||||
strdup(char *s)
|
||||
{
|
||||
char *p = (char *) malloc(strlen(s) + 1);
|
||||
if (p)
|
||||
strcpy(p, s);
|
||||
return (p);
|
||||
}
|
||||
#endif /* not HAVE_STRDUP */
|
||||
|
||||
static const char *
|
||||
skip(const char *buffer)
|
||||
{
|
||||
while (isspace(UChar(*buffer)))
|
||||
buffer++;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
trim(char *buffer)
|
||||
{
|
||||
unsigned n = strlen(buffer);
|
||||
while (n-- && isspace(UChar(buffer[n])))
|
||||
buffer[n] = 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
static CARD *
|
||||
add_title(const char *title)
|
||||
{
|
||||
CARD *card, *p, *q;
|
||||
|
||||
for (p = all_cards, q = 0; p != 0; q = p, p = p->link) {
|
||||
int cmp = strcmp(p->title, title);
|
||||
if (cmp == 0)
|
||||
return p;
|
||||
if (cmp > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
card = (CARD *) calloc(1, sizeof(CARD));
|
||||
card->title = strdup(title);
|
||||
card->content = strdup("");
|
||||
|
||||
if (q == 0) {
|
||||
card->link = all_cards;
|
||||
all_cards = card;
|
||||
} else {
|
||||
card->link = q->link;
|
||||
q->link = card;
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
static void
|
||||
add_content(CARD * card, const char *content)
|
||||
{
|
||||
unsigned total, offset;
|
||||
|
||||
content = skip(content);
|
||||
if ((total = strlen(content)) != 0) {
|
||||
if ((offset = strlen(card->content)) != 0) {
|
||||
total += 1 + offset;
|
||||
card->content = (char *) realloc(card->content, total + 1);
|
||||
strcpy(card->content + offset++, " ");
|
||||
} else {
|
||||
card->content = (char *) malloc(total + 1);
|
||||
}
|
||||
strcpy(card->content + offset, content);
|
||||
}
|
||||
}
|
||||
|
||||
static CARD *
|
||||
new_card(void)
|
||||
{
|
||||
CARD *card = add_title("");
|
||||
add_content(card, "");
|
||||
return card;
|
||||
}
|
||||
|
||||
static CARD *
|
||||
find_card(char *title)
|
||||
{
|
||||
CARD *card;
|
||||
|
||||
for (card = all_cards; card != 0; card = card->link)
|
||||
if (!strcmp(card->title, title))
|
||||
break;
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
static void
|
||||
read_data(char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
CARD *card = 0;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
if ((fp = fopen(fname, "r")) != 0) {
|
||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||
trim(buffer);
|
||||
if (isspace(UChar(*buffer))) {
|
||||
if (card == 0)
|
||||
card = add_title("");
|
||||
add_content(card, buffer);
|
||||
} else if ((card = find_card(buffer)) == 0) {
|
||||
card = add_title(buffer);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
static void
|
||||
write_data(const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
CARD *p = 0;
|
||||
int n;
|
||||
|
||||
if (!strcmp(fname, default_name))
|
||||
fname = "cardfile.out";
|
||||
|
||||
if ((fp = fopen(fname, "w")) != 0) {
|
||||
for (p = all_cards; p != 0; p = p->link) {
|
||||
FIELD **f = form_fields(p->form);
|
||||
for (n = 0; f[n] != 0; n++) {
|
||||
char *s = field_buffer(f[n], 0);
|
||||
if (s != 0
|
||||
&& (s = strdup(s)) != 0) {
|
||||
trim(s);
|
||||
fprintf(fp, "%s%s\n", n ? "\t" : "", s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Count the cards
|
||||
*/
|
||||
static int
|
||||
count_cards(void)
|
||||
{
|
||||
CARD *p;
|
||||
int count = 0;
|
||||
|
||||
for (p = all_cards; p != 0; p = p->link)
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shuffle the panels to keep them in a natural hierarchy.
|
||||
*/
|
||||
static void
|
||||
order_cards(CARD * first, int depth)
|
||||
{
|
||||
if (first) {
|
||||
if (depth && first->link)
|
||||
order_cards(first->link, depth - 1);
|
||||
top_panel(first->panel);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the next card in the list
|
||||
*/
|
||||
static CARD *
|
||||
next_card(CARD * now)
|
||||
{
|
||||
if (now->link)
|
||||
now = now->link;
|
||||
return now;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the previous card in the list
|
||||
*/
|
||||
static CARD *
|
||||
prev_card(CARD * now)
|
||||
{
|
||||
CARD *p;
|
||||
for (p = all_cards; p != 0; p = p->link)
|
||||
if (p->link == now)
|
||||
return p;
|
||||
return now;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
static int
|
||||
form_virtualize(WINDOW *w)
|
||||
{
|
||||
int c = wgetch(w);
|
||||
|
||||
switch (c) {
|
||||
case CTRL('W'):
|
||||
return (MAX_FORM_COMMAND + 4);
|
||||
case CTRL('N'):
|
||||
return (MAX_FORM_COMMAND + 3);
|
||||
case CTRL('P'):
|
||||
return (MAX_FORM_COMMAND + 2);
|
||||
case CTRL('Q'):
|
||||
case 033:
|
||||
return (MAX_FORM_COMMAND + 1);
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
return (REQ_DEL_PREV);
|
||||
case KEY_DC:
|
||||
return (REQ_DEL_CHAR);
|
||||
case KEY_LEFT:
|
||||
return (REQ_LEFT_CHAR);
|
||||
case KEY_RIGHT:
|
||||
return (REQ_RIGHT_CHAR);
|
||||
|
||||
case KEY_DOWN:
|
||||
case KEY_NEXT:
|
||||
return (REQ_NEXT_FIELD);
|
||||
case KEY_UP:
|
||||
case KEY_PREVIOUS:
|
||||
return (REQ_PREV_FIELD);
|
||||
|
||||
default:
|
||||
return (c);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
static void
|
||||
cardfile(char *fname)
|
||||
{
|
||||
WINDOW *win;
|
||||
CARD *p;
|
||||
CARD *top_card;
|
||||
int visible_cards = count_cards();
|
||||
int panel_wide = COLS - (visible_cards * OFFSET_CARD);
|
||||
int panel_high = LINES - (visible_cards * OFFSET_CARD) - 5;
|
||||
int form_wide = panel_wide - 2;
|
||||
int form_high = panel_high - 2;
|
||||
int x = (visible_cards - 1) * OFFSET_CARD;
|
||||
int y = 0;
|
||||
int ch;
|
||||
int finished = FALSE;
|
||||
|
||||
move(LINES - 3, 0);
|
||||
addstr("^Q/ESC -- exit form ^W -- writes data to file\n");
|
||||
addstr("^N -- go to next card ^P -- go to previous card\n");
|
||||
addstr("Arrow keys move left/right within a field, up/down between fields");
|
||||
|
||||
/* make a panel for each CARD */
|
||||
for (p = all_cards; p != 0; p = p->link) {
|
||||
FIELD **f = (FIELD **) calloc(3, sizeof(FIELD *));
|
||||
|
||||
win = newwin(panel_high, panel_wide, x, y);
|
||||
keypad(win, TRUE);
|
||||
p->panel = new_panel(win);
|
||||
box(win, 0, 0);
|
||||
|
||||
/* ...and a form in each panel */
|
||||
f[0] = new_field(1, form_wide, 0, 0, 0, 0);
|
||||
set_field_back(f[0], A_REVERSE);
|
||||
set_field_buffer(f[0], 0, p->title);
|
||||
|
||||
f[1] = new_field(form_high - 1, form_wide, 1, 0, 0, 0);
|
||||
set_field_buffer(f[1], 0, p->content);
|
||||
set_field_just(f[1], JUSTIFY_LEFT);
|
||||
|
||||
f[2] = 0;
|
||||
|
||||
p->form = new_form(f);
|
||||
set_form_win(p->form, win);
|
||||
set_form_sub(p->form, derwin(win, form_high, form_wide, 1, 1));
|
||||
post_form(p->form);
|
||||
|
||||
x -= OFFSET_CARD;
|
||||
y += OFFSET_CARD;
|
||||
}
|
||||
|
||||
order_cards(top_card = all_cards, visible_cards);
|
||||
|
||||
while (!finished) {
|
||||
update_panels();
|
||||
doupdate();
|
||||
|
||||
switch (form_driver(top_card->form, ch =
|
||||
form_virtualize(panel_window(top_card->panel)))) {
|
||||
case E_OK:
|
||||
break;
|
||||
case E_UNKNOWN_COMMAND:
|
||||
switch (ch) {
|
||||
case MAX_FORM_COMMAND + 1:
|
||||
finished = TRUE;
|
||||
break;
|
||||
case MAX_FORM_COMMAND + 2:
|
||||
top_card = prev_card(top_card);
|
||||
order_cards(top_card, visible_cards);
|
||||
break;
|
||||
case MAX_FORM_COMMAND + 3:
|
||||
top_card = next_card(top_card);
|
||||
order_cards(top_card, visible_cards);
|
||||
break;
|
||||
case MAX_FORM_COMMAND + 4:
|
||||
write_data(fname);
|
||||
break;
|
||||
#ifdef KEY_RESIZE
|
||||
case KEY_RESIZE:
|
||||
flash();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
flash();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
if (argc > 1) {
|
||||
for (n = 1; n < argc; n++)
|
||||
read_data(argv[n]);
|
||||
if (count_cards() == 0)
|
||||
new_card();
|
||||
cardfile(argv[1]);
|
||||
} else {
|
||||
read_data(default_name);
|
||||
if (count_cards() == 0)
|
||||
new_card();
|
||||
cardfile(default_name);
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("This program requires the curses form and panel libraries\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
@ -1,13 +0,0 @@
|
||||
title 1
|
||||
Some text for title1
|
||||
and some more text
|
||||
title 2
|
||||
The quicker brown fox ran all over the lazy dog.
|
||||
put a card before the first two
|
||||
This is an example of a simple cardfile.
|
||||
show a fourth card
|
||||
The fourth card
|
||||
has a large amount of data,
|
||||
more than the other cards.
|
||||
At least, that is what I thought it should do, since I want to see how well
|
||||
the forms package handles justification.
|
2401
contrib/ncurses/test/configure
vendored
2401
contrib/ncurses/test/configure
vendored
File diff suppressed because it is too large
Load Diff
@ -1,327 +0,0 @@
|
||||
dnl***************************************************************************
|
||||
dnl Copyright (c) 1998-2000,2002 Free Software Foundation, Inc. *
|
||||
dnl *
|
||||
dnl Permission is hereby granted, free of charge, to any person obtaining a *
|
||||
dnl copy of this software and associated documentation files (the *
|
||||
dnl "Software"), to deal in the Software without restriction, including *
|
||||
dnl without limitation the rights to use, copy, modify, merge, publish, *
|
||||
dnl distribute, distribute with modifications, sublicense, and/or sell *
|
||||
dnl copies of the Software, and to permit persons to whom the Software is *
|
||||
dnl furnished to do so, subject to the following conditions: *
|
||||
dnl *
|
||||
dnl The above copyright notice and this permission notice shall be included *
|
||||
dnl in all copies or substantial portions of the Software. *
|
||||
dnl *
|
||||
dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
dnl *
|
||||
dnl Except as contained in this notice, the name(s) of the above copyright *
|
||||
dnl holders shall not be used in advertising or otherwise to promote the *
|
||||
dnl sale, use or other dealings in this Software without prior written *
|
||||
dnl authorization. *
|
||||
dnl***************************************************************************
|
||||
dnl
|
||||
dnl Author: Thomas E. Dickey 1996, etc.
|
||||
dnl
|
||||
dnl $Id: configure.in,v 1.35 2002/04/06 22:02:50 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)
|
||||
dnl
|
||||
dnl If you're configuring ncurses, you shouldn't need to use this script.
|
||||
dnl It's only for testing purposes.
|
||||
dnl
|
||||
dnl See http://dickey.his.com/autoconf/ for additional information.
|
||||
dnl ---------------------------------------------------------------------------
|
||||
AC_PREREQ(2.13.20000819)
|
||||
AC_INIT(ncurses.c)
|
||||
AC_CONFIG_HEADER(ncurses_cfg.h:ncurses_tst.hin)
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
dnl Things that we don't need (or must override) if we're not building ncurses
|
||||
CC_G_OPT="-g" AC_SUBST(CC_G_OPT)
|
||||
CC_SHARED_OPTS=unknown AC_SUBST(CC_SHARED_OPTS)
|
||||
CPPFLAGS="$CPPFLAGS" AC_SUBST(CPPFLAGS)
|
||||
DFT_DEP_SUFFIX="" AC_SUBST(DFT_DEP_SUFFIX)
|
||||
DFT_OBJ_SUBDIR=`pwd|sed -e's:.*/::'` AC_SUBST(DFT_OBJ_SUBDIR)
|
||||
DFT_UPR_MODEL="NORMAL" AC_SUBST(DFT_UPR_MODEL)
|
||||
ECHO_LINK='@ echo linking $@ ... ;' AC_SUBST(ECHO_LINK)
|
||||
EXTRA_LIBS="" AC_SUBST(EXTRA_LIBS)
|
||||
LD="ld" AC_SUBST(LD)
|
||||
LDFLAGS_SHARED="" AC_SUBST(LDFLAGS_SHARED)
|
||||
LD_MODEL="" AC_SUBST(LD_MODEL)
|
||||
LD_SHARED_OPTS="" AC_SUBST(LD_SHARED_OPTS)
|
||||
LIBTOOL="" AC_SUBST(LIBTOOL)
|
||||
LIB_NAME=curses AC_SUBST(LIB_NAME)
|
||||
LIB_PREFIX="-l" AC_SUBST(LIB_PREFIX)
|
||||
LINK_TESTS="" AC_SUBST(LINK_TESTS)
|
||||
LINT=lint AC_SUBST(LINT)
|
||||
LINT_OPTS="" AC_SUBST(LINT_OPTS)
|
||||
LOCAL_LDFLAGS="" AC_SUBST(LOCAL_LDFLAGS)
|
||||
MATH_LIB="-lm" AC_SUBST(MATH_LIB)
|
||||
PROG_EXT="" AC_SUBST(PROG_EXT)
|
||||
TEST_ARGS="" AC_SUBST(TEST_ARGS)
|
||||
TEST_DEPS="" AC_SUBST(TEST_DEPS)
|
||||
cf_cv_abi_version="" AC_SUBST(cf_cv_abi_version)
|
||||
cf_cv_rel_version="" AC_SUBST(cf_cv_rel_version)
|
||||
|
||||
dnl SunOS 4.x
|
||||
AC_ARG_WITH(5lib,
|
||||
[ --with-5lib use SunOS sysv-libraries],
|
||||
[LIBS="-L/usr/5lib $LIBS"
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/5include"])
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Check for libutf8
|
||||
AC_DEFUN([CF_LIBUTF8],
|
||||
[
|
||||
AC_CACHE_CHECK(for putwc in libutf8,cf_cv_libutf8,[
|
||||
cf_save_LIBS="$LIBS"
|
||||
LIBS="-lutf8 $LIBS"
|
||||
AC_TRY_LINK([
|
||||
#include <libutf8.h>],[putwc(0,0);],
|
||||
[cf_cv_libutf8=yes],
|
||||
[cf_cv_libutf8=no])
|
||||
LIBS="$cf_save_LIBS"
|
||||
])
|
||||
|
||||
if test "$cf_cv_libutf8" = yes ; then
|
||||
AC_DEFINE(HAVE_LIBUTF8_H)
|
||||
LIBS="-lutf8 $LIBS"
|
||||
fi
|
||||
])dnl
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl NcursesW, installed in conventional location
|
||||
AC_ARG_WITH(ncursesw,
|
||||
[ --with-ncursesw use wide ncurses-libraries (installed)],
|
||||
[
|
||||
AC_DEFINE(_GNU_SOURCE)
|
||||
AC_DEFINE(_XOPEN_SOURCE_EXTENDED)
|
||||
AC_CHECK_FUNC(initscr,,[
|
||||
AC_CHECK_LIB(gpm,Gpm_Open)
|
||||
LIB_NAME=ncursesw
|
||||
AC_CHECK_FUNC(putwc,,[CF_LIBUTF8])
|
||||
for p in $HOME /usr/local /usr
|
||||
do
|
||||
if test -f $p/include/ncursesw/curses.h
|
||||
then
|
||||
CPPFLAGS="$CPPFLAGS -I$p/include/ncursesw"
|
||||
test $p != /usr && CPPFLAGS="$CPPFLAGS -I$p/include"
|
||||
test $p != /usr && LIBS="-L$p/lib $LIBS"
|
||||
break
|
||||
elif test $p != /usr
|
||||
then
|
||||
if test -f $p/include/curses.h
|
||||
then
|
||||
CPPFLAGS="$CPPFLAGS -I$p/include"
|
||||
LIBS="-L$p/lib $LIBS"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
],[test -d /usr/ccs/lib && LIBS="-L/usr/ccs/lib $LIBS"])])
|
||||
|
||||
dnl Ncurses, installed in conventional location
|
||||
AC_ARG_WITH(ncurses,
|
||||
[ --with-ncurses use ncurses-libraries (installed)],
|
||||
[AC_CHECK_FUNC(initscr,,[
|
||||
AC_CHECK_LIB(gpm,Gpm_Open)
|
||||
LIB_NAME=ncurses
|
||||
for p in $HOME /usr/local /usr
|
||||
do
|
||||
if test -f $p/include/ncurses/curses.h
|
||||
then
|
||||
CPPFLAGS="$CPPFLAGS -I$p/include/ncurses"
|
||||
test $p != /usr && CPPFLAGS="$CPPFLAGS -I$p/include"
|
||||
test $p != /usr && LIBS="-L$p/lib $LIBS"
|
||||
break
|
||||
elif test $p != /usr
|
||||
then
|
||||
if test -f $p/include/curses.h
|
||||
then
|
||||
CPPFLAGS="$CPPFLAGS -I$p/include"
|
||||
LIBS="-L$p/lib $LIBS"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
],[test -d /usr/ccs/lib && LIBS="-L/usr/ccs/lib $LIBS"])])
|
||||
|
||||
dnl If we've not specified a library, assume we're using sysvr4 libraries
|
||||
dnl installed conventionally (e.g., SunOS 5.x - solaris).
|
||||
|
||||
dnl Autoconf builds up the $LIBS in reverse order
|
||||
|
||||
AC_CHECK_FUNC(initscr,,[
|
||||
AC_CHECK_LIB($LIB_NAME,initscr)])
|
||||
AC_CHECK_LIB(form,form_driver)
|
||||
AC_CHECK_LIB(menu,menu_driver)
|
||||
AC_CHECK_LIB(panel,new_panel)
|
||||
|
||||
AC_TYPE_SIGNAL
|
||||
|
||||
AC_STDC_HEADERS
|
||||
AC_HEADER_TIME
|
||||
AC_CHECK_HEADERS( \
|
||||
form.h \
|
||||
getopt.h \
|
||||
locale.h \
|
||||
menu.h \
|
||||
nc_alloc.h \
|
||||
nomacros.h \
|
||||
panel.h \
|
||||
sys/ioctl.h \
|
||||
sys/select.h \
|
||||
sys/time.h \
|
||||
termios.h \
|
||||
unistd.h \
|
||||
)
|
||||
|
||||
AC_CHECK_FUNCS( \
|
||||
getnstr \
|
||||
gettimeofday \
|
||||
napms \
|
||||
resize_term \
|
||||
resizeterm \
|
||||
strdup \
|
||||
use_default_colors \
|
||||
vsscanf \
|
||||
wresize \
|
||||
)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Solaris has a data item 'curses_version', which confuses AC_CHECK_FUNCS.
|
||||
dnl It's a character string "SVR4", not documented.
|
||||
AC_CACHE_CHECK(for function curses_version, cf_cv_func_curses_version,[
|
||||
AC_TRY_RUN([
|
||||
#include <curses.h>
|
||||
int main()
|
||||
{
|
||||
char temp[1024];
|
||||
sprintf(temp, "%s\n", curses_version());
|
||||
exit(0);
|
||||
}]
|
||||
,[cf_cv_func_curses_version=yes]
|
||||
,[cf_cv_func_curses_version=no]
|
||||
,[cf_cv_func_curses_version=unknown])
|
||||
rm -f core])
|
||||
test "$cf_cv_func_curses_version" = yes && AC_DEFINE(HAVE_CURSES_VERSION)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Check for likely values of acs_map[]:
|
||||
AC_CACHE_CHECK(for alternate character set array, cf_cv_curses_acs_map,[
|
||||
cf_cv_curses_acs_map=unknown
|
||||
for name in acs_map _acs_map __acs_map _nc_acs_map
|
||||
do
|
||||
AC_TRY_LINK([
|
||||
#include <curses.h>
|
||||
],[
|
||||
$name['k'] = ACS_PLUS
|
||||
],[cf_cv_curses_acs_map=$name; break])
|
||||
done
|
||||
])
|
||||
|
||||
test "$cf_cv_curses_acs_map" != unknown && AC_DEFINE_UNQUOTED(CURSES_ACS_ARRAY,$cf_cv_curses_acs_map)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Check for likely values of wacs_map[]:
|
||||
AC_CACHE_CHECK(for wide alternate character set array, cf_cv_curses_wacs_map,[
|
||||
cf_cv_curses_wacs_map=unknown
|
||||
for name in wacs_map _wacs_map __wacs_map _nc_wacs
|
||||
do
|
||||
AC_TRY_LINK([
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
#endif
|
||||
#include <curses.h>
|
||||
],[
|
||||
$name['k'] = *WACS_PLUS
|
||||
],[cf_cv_curses_wacs_map=$name; break])
|
||||
done
|
||||
])
|
||||
|
||||
test "$cf_cv_curses_wacs_map" != unknown && AC_DEFINE_UNQUOTED(CURSES_WACS_ARRAY,$cf_cv_curses_wacs_map)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Make an uppercase version of a variable
|
||||
dnl $1=uppercase($2)
|
||||
AC_DEFUN([CF_UPPER],
|
||||
[
|
||||
$1=`echo "$2" | sed y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%`
|
||||
])dnl
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Check if curses.h defines the given type
|
||||
AC_DEFUN([CF_CURSES_TYPE],
|
||||
[
|
||||
AC_MSG_CHECKING(for type $1 in curses.h)
|
||||
AC_TRY_COMPILE([
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
#endif
|
||||
#include <curses.h>],[
|
||||
$1 foo
|
||||
],cf_result=yes,cf_result=no)
|
||||
AC_MSG_RESULT($cf_result)
|
||||
if test $cf_result = yes ; then
|
||||
CF_UPPER(cf_result,have_type_$1)
|
||||
AC_DEFINE_UNQUOTED($cf_result)
|
||||
else
|
||||
AC_DEFINE_UNQUOTED($1,$2)
|
||||
fi
|
||||
])dnl
|
||||
|
||||
CF_CURSES_TYPE(attr_t,long)
|
||||
CF_CURSES_TYPE(mbstate_t,long)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl Check if we can include <sys/time.h> with <sys/select.h>; this breaks on
|
||||
dnl older SCO configurations.
|
||||
dnl [CF_SYS_TIME_SELECT]
|
||||
|
||||
AC_MSG_CHECKING(if sys/time.h works with sys/select.h)
|
||||
AC_CACHE_VAL(cf_cv_sys_time_select,[
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
],[],[cf_cv_sys_time_select=yes],
|
||||
[cf_cv_sys_time_select=no])
|
||||
])
|
||||
AC_MSG_RESULT($cf_cv_sys_time_select)
|
||||
test "$cf_cv_sys_time_select" = yes && AC_DEFINE(HAVE_SYS_TIME_SELECT)
|
||||
|
||||
dnl ---------------------------------------------------------------------------
|
||||
|
||||
AC_OUTPUT(Makefile,[
|
||||
cat >>Makefile <<TEST_EOF
|
||||
|
||||
# These rules are generated so we do not rely on suffix rules, which do not
|
||||
# work consistently for different make-programs (the '\$(MODEL)/' confuses
|
||||
# some, and the '\$x' confuses others).
|
||||
TEST_EOF
|
||||
LIST=`make echo_tests`
|
||||
LAST=`make echo_suffix`
|
||||
for n in $LIST
|
||||
do
|
||||
N=`echo $n | sed -e s/${LAST}\$//`
|
||||
cat >>Makefile <<TEST_EOF
|
||||
|
||||
\$(MODEL)/$N.o : $N.c \\
|
||||
test.priv.h \\
|
||||
ncurses_cfg.h
|
||||
@echo compiling $N; \$(CC) -c \$(CFLAGS_DEFAULT) $N.c
|
||||
TEST_EOF
|
||||
done
|
||||
],[],sort)
|
@ -1,148 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2001 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1998
|
||||
*
|
||||
* $Id: ditto.c,v 1.4 2001/09/15 21:53:37 tom Exp $
|
||||
*
|
||||
* The program illustrates how to set up multiple screens from a single
|
||||
* program. Invoke the program by specifying another terminal on the same
|
||||
* machine by specifying its device, e.g.,
|
||||
* ditto /dev/ttyp1
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
typedef struct {
|
||||
FILE *input;
|
||||
FILE *output;
|
||||
SCREEN *screen;
|
||||
} DITTO;
|
||||
|
||||
static void
|
||||
failed(const char *s)
|
||||
{
|
||||
perror(s);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: ditto [terminal1 ...]\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static FILE *
|
||||
open_tty(char *path)
|
||||
{
|
||||
FILE *fp;
|
||||
struct stat sb;
|
||||
|
||||
if (stat(path, &sb) < 0)
|
||||
failed(path);
|
||||
if ((sb.st_mode & S_IFMT) != S_IFCHR) {
|
||||
errno = ENOTTY;
|
||||
failed(path);
|
||||
}
|
||||
fp = fopen(path, "a+");
|
||||
if (fp == 0)
|
||||
failed(path);
|
||||
printf("opened %s\n", path);
|
||||
return fp;
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int j;
|
||||
int active_tty = 0;
|
||||
DITTO *data;
|
||||
|
||||
if (argc <= 1)
|
||||
usage();
|
||||
|
||||
if ((data = (DITTO *) calloc(argc, sizeof(DITTO))) == 0)
|
||||
failed("calloc data");
|
||||
|
||||
data[0].input = stdin;
|
||||
data[0].output = stdout;
|
||||
for (j = 1; j < argc; j++) {
|
||||
data[j].input =
|
||||
data[j].output = open_tty(argv[j]);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we got this far, we have open connection(s) to the terminal(s).
|
||||
* Set up the screens.
|
||||
*/
|
||||
for (j = 0; j < argc; j++) {
|
||||
active_tty++;
|
||||
data[j].screen = newterm(
|
||||
(char *) 0, /* assume $TERM is the same */
|
||||
data[j].output,
|
||||
data[j].input);
|
||||
if (data[j].screen == 0)
|
||||
failed("newterm");
|
||||
cbreak();
|
||||
noecho();
|
||||
scrollok(stdscr, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop, reading characters from any of the inputs and writing to all
|
||||
* of the screens.
|
||||
*/
|
||||
for (;;) {
|
||||
int ch;
|
||||
set_term(data[0].screen);
|
||||
ch = getch();
|
||||
if (ch == ERR)
|
||||
continue;
|
||||
if (ch == 4)
|
||||
break;
|
||||
for (j = 0; j < argc; j++) {
|
||||
set_term(data[j].screen);
|
||||
addch(ch);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleanup and exit
|
||||
*/
|
||||
for (j = argc - 1; j >= 0; j--) {
|
||||
set_term(data[j].screen);
|
||||
endwin();
|
||||
}
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1999-2001,2002 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1999
|
||||
*
|
||||
* $Id: dots.c,v 1.8 2002/04/06 21:33:42 tom Exp $
|
||||
*
|
||||
* A simple demo of the terminfo interface.
|
||||
*/
|
||||
#include <time.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define valid(s) ((s != 0) && s != (char *)-1)
|
||||
|
||||
static bool interrupted = FALSE;
|
||||
|
||||
static int
|
||||
outc(int c)
|
||||
{
|
||||
if (interrupted) {
|
||||
char tmp = c;
|
||||
write(STDOUT_FILENO, &tmp, 1);
|
||||
} else {
|
||||
putc(c, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
outs(char *s)
|
||||
{
|
||||
if (valid(s)) {
|
||||
tputs(s, 1, outc);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
outs(exit_attribute_mode);
|
||||
if (!outs(orig_colors))
|
||||
outs(orig_pair);
|
||||
outs(clear_screen);
|
||||
outs(cursor_normal);
|
||||
}
|
||||
|
||||
static void
|
||||
onsig(int n GCC_UNUSED)
|
||||
{
|
||||
interrupted = TRUE;
|
||||
cleanup();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static float
|
||||
ranf(void)
|
||||
{
|
||||
long r = (rand() & 077777);
|
||||
return ((float) r / 32768.);
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int x, y, z, j, p;
|
||||
float r;
|
||||
float c;
|
||||
|
||||
for (j = SIGHUP; j <= SIGTERM; j++)
|
||||
if (signal(j, SIG_IGN) != SIG_IGN)
|
||||
signal(j, onsig);
|
||||
|
||||
srand(time(0));
|
||||
setupterm((char *) 0, 1, (int *) 0);
|
||||
outs(clear_screen);
|
||||
outs(cursor_invisible);
|
||||
if (max_colors > 1) {
|
||||
if (!valid(set_a_foreground)
|
||||
|| !valid(set_a_background)
|
||||
|| (!valid(orig_colors) && !valid(orig_pair)))
|
||||
max_colors = -1;
|
||||
}
|
||||
|
||||
r = (float) (lines - 4);
|
||||
c = (float) (columns - 4);
|
||||
|
||||
for (;;) {
|
||||
x = (int) (c * ranf()) + 2;
|
||||
y = (int) (r * ranf()) + 2;
|
||||
p = (ranf() > 0.9) ? '*' : ' ';
|
||||
|
||||
tputs(tparm3(cursor_address, y, x), 1, outc);
|
||||
if (max_colors > 0) {
|
||||
z = (int) (ranf() * max_colors);
|
||||
if (ranf() > 0.01) {
|
||||
tputs(tparm2(set_a_foreground, z), 1, outc);
|
||||
} else {
|
||||
tputs(tparm2(set_a_background, z), 1, outc);
|
||||
}
|
||||
} else if (valid(exit_attribute_mode)
|
||||
&& valid(enter_reverse_mode)) {
|
||||
if (ranf() <= 0.01)
|
||||
outs((ranf() > 0.6) ? enter_reverse_mode :
|
||||
exit_attribute_mode);
|
||||
}
|
||||
outc(p);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998-2001,2002 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1998
|
||||
*
|
||||
* $Id: filter.c,v 1.7 2002/03/23 23:02:15 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
/*
|
||||
* An example of the 'filter()' function in ncurses, this program prompts
|
||||
* for commands and executes them (like a command shell). It illustrates
|
||||
* how ncurses can be used to implement programs that are not full-screen.
|
||||
*
|
||||
* Ncurses differs slightly from SVr4 curses. The latter does not flush its
|
||||
* state when exiting program mode, so the attributes on the command lines of
|
||||
* this program 'bleed' onto the executed commands. Rather than use the
|
||||
* reset_shell_mode() and reset_prog_mode() functions, we could invoke endwin()
|
||||
* and refresh(), but that does not work any better.
|
||||
*/
|
||||
|
||||
static int
|
||||
new_command(char *buffer, int length, attr_t underline)
|
||||
{
|
||||
int code;
|
||||
|
||||
attron(A_BOLD);
|
||||
printw("Command: ");
|
||||
attron(underline);
|
||||
code = getnstr(buffer, length);
|
||||
attroff(underline);
|
||||
attroff(A_BOLD);
|
||||
printw("\n");
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
char buffer[80];
|
||||
attr_t underline;
|
||||
|
||||
filter();
|
||||
(void) newterm((char *) 0, stdout, stdin);
|
||||
cbreak();
|
||||
keypad(stdscr, TRUE);
|
||||
|
||||
if (has_colors()) {
|
||||
int background = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() != ERR)
|
||||
background = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_CYAN, background);
|
||||
underline = COLOR_PAIR(1);
|
||||
} else {
|
||||
underline = A_UNDERLINE;
|
||||
}
|
||||
|
||||
while (new_command(buffer, sizeof(buffer) - 1, underline) != ERR
|
||||
&& strlen(buffer) != 0) {
|
||||
reset_shell_mode();
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
system(buffer);
|
||||
reset_prog_mode();
|
||||
touchwin(stdscr);
|
||||
erase();
|
||||
refresh();
|
||||
}
|
||||
printw("done");
|
||||
refresh();
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* $Id: firework.c,v 1.20 2002/03/23 21:41:42 tom Exp $
|
||||
*/
|
||||
#include <time.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
static int my_bg = COLOR_BLACK;
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
curs_set(1);
|
||||
endwin();
|
||||
}
|
||||
|
||||
static RETSIGTYPE
|
||||
onsig(int n GCC_UNUSED)
|
||||
{
|
||||
cleanup();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
showit(void)
|
||||
{
|
||||
int ch;
|
||||
napms(120);
|
||||
if ((ch = getch()) != ERR) {
|
||||
#ifdef KEY_RESIZE
|
||||
if (ch == KEY_RESIZE) {
|
||||
erase();
|
||||
} else
|
||||
#endif
|
||||
if (ch == 'q') {
|
||||
cleanup();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
} else if (ch == 's') {
|
||||
nodelay(stdscr, FALSE);
|
||||
} else if (ch == ' ') {
|
||||
nodelay(stdscr, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
get_colour(chtype * bold)
|
||||
{
|
||||
int attr;
|
||||
attr = (rand() % 16) + 1;
|
||||
|
||||
*bold = A_NORMAL;
|
||||
if (attr > 8) {
|
||||
*bold = A_BOLD;
|
||||
attr &= 7;
|
||||
}
|
||||
return (attr);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
explode(int row, int col)
|
||||
{
|
||||
chtype bold;
|
||||
erase();
|
||||
mvprintw(row, col, "-");
|
||||
showit();
|
||||
|
||||
init_pair(1, get_colour(&bold), my_bg);
|
||||
attrset(COLOR_PAIR(1) | bold);
|
||||
mvprintw(row - 1, col - 1, " - ");
|
||||
mvprintw(row + 0, col - 1, "-+-");
|
||||
mvprintw(row + 1, col - 1, " - ");
|
||||
showit();
|
||||
|
||||
init_pair(1, get_colour(&bold), my_bg);
|
||||
attrset(COLOR_PAIR(1) | bold);
|
||||
mvprintw(row - 2, col - 2, " --- ");
|
||||
mvprintw(row - 1, col - 2, "-+++-");
|
||||
mvprintw(row + 0, col - 2, "-+#+-");
|
||||
mvprintw(row + 1, col - 2, "-+++-");
|
||||
mvprintw(row + 2, col - 2, " --- ");
|
||||
showit();
|
||||
|
||||
init_pair(1, get_colour(&bold), my_bg);
|
||||
attrset(COLOR_PAIR(1) | bold);
|
||||
mvprintw(row - 2, col - 2, " +++ ");
|
||||
mvprintw(row - 1, col - 2, "++#++");
|
||||
mvprintw(row + 0, col - 2, "+# #+");
|
||||
mvprintw(row + 1, col - 2, "++#++");
|
||||
mvprintw(row + 2, col - 2, " +++ ");
|
||||
showit();
|
||||
|
||||
init_pair(1, get_colour(&bold), my_bg);
|
||||
attrset(COLOR_PAIR(1) | bold);
|
||||
mvprintw(row - 2, col - 2, " # ");
|
||||
mvprintw(row - 1, col - 2, "## ##");
|
||||
mvprintw(row + 0, col - 2, "# #");
|
||||
mvprintw(row + 1, col - 2, "## ##");
|
||||
mvprintw(row + 2, col - 2, " # ");
|
||||
showit();
|
||||
|
||||
init_pair(1, get_colour(&bold), my_bg);
|
||||
attrset(COLOR_PAIR(1) | bold);
|
||||
mvprintw(row - 2, col - 2, " # # ");
|
||||
mvprintw(row - 1, col - 2, "# #");
|
||||
mvprintw(row + 0, col - 2, " ");
|
||||
mvprintw(row + 1, col - 2, "# #");
|
||||
mvprintw(row + 2, col - 2, " # # ");
|
||||
showit();
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int j;
|
||||
int start, end, row, diff, flag = 0, direction;
|
||||
unsigned seed;
|
||||
|
||||
for (j = SIGHUP; j <= SIGTERM; j++)
|
||||
if (signal(j, SIG_IGN) != SIG_IGN)
|
||||
signal(j, onsig);
|
||||
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
keypad(stdscr, TRUE);
|
||||
nodelay(stdscr, TRUE);
|
||||
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
my_bg = -1;
|
||||
#endif
|
||||
}
|
||||
curs_set(0);
|
||||
|
||||
seed = time((time_t *) 0);
|
||||
srand(seed);
|
||||
for (;;) {
|
||||
do {
|
||||
start = rand() % (COLS - 3);
|
||||
end = rand() % (COLS - 3);
|
||||
start = (start < 2) ? 2 : start;
|
||||
end = (end < 2) ? 2 : end;
|
||||
direction = (start > end) ? -1 : 1;
|
||||
diff = abs(start - end);
|
||||
} while (diff < 2 || diff >= LINES - 2);
|
||||
attrset(A_NORMAL);
|
||||
for (row = 0; row < diff; row++) {
|
||||
mvprintw(LINES - row, start + (row * direction),
|
||||
(direction < 0) ? "\\" : "/");
|
||||
if (flag++) {
|
||||
showit();
|
||||
erase();
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
if (flag++) {
|
||||
showit();
|
||||
flag = 0;
|
||||
}
|
||||
seed = time((time_t *) 0);
|
||||
srand(seed);
|
||||
explode(LINES - row, start + (diff * direction));
|
||||
erase();
|
||||
showit();
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* This test was written by Alexander V. Lukyanov to demonstrate difference
|
||||
* between ncurses 4.1 and SVR4 curses
|
||||
*
|
||||
* $Id: firstlast.c,v 1.3 2001/09/15 21:46:34 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
static void
|
||||
fill(WINDOW *w, const char *str)
|
||||
{
|
||||
const char *s;
|
||||
for (;;) {
|
||||
for (s = str; *s; s++) {
|
||||
if (waddch(w, *s) == ERR) {
|
||||
wmove(w, 0, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
WINDOW *large, *small;
|
||||
initscr();
|
||||
noecho();
|
||||
|
||||
large = newwin(20, 60, 2, 10);
|
||||
small = newwin(10, 30, 7, 25);
|
||||
|
||||
/* test 1 - addch */
|
||||
fill(large, "LargeWindow");
|
||||
|
||||
refresh();
|
||||
wrefresh(large);
|
||||
wrefresh(small);
|
||||
|
||||
mvwaddstr(small, 5, 5, " Test <place to change> String ");
|
||||
wrefresh(small);
|
||||
getch();
|
||||
|
||||
touchwin(large);
|
||||
wrefresh(large);
|
||||
|
||||
mvwaddstr(small, 5, 5, " Test <***************> String ");
|
||||
wrefresh(small);
|
||||
|
||||
/* DIFFERENCE! */
|
||||
getch();
|
||||
|
||||
/* test 2: erase */
|
||||
erase();
|
||||
refresh();
|
||||
getch();
|
||||
|
||||
/* test 3: clrtoeol */
|
||||
werase(small);
|
||||
wrefresh(small);
|
||||
touchwin(large);
|
||||
wrefresh(large);
|
||||
wmove(small, 5, 0);
|
||||
waddstr(small, " clrtoeol>");
|
||||
wclrtoeol(small);
|
||||
wrefresh(small);
|
||||
|
||||
/* DIFFERENCE! */ ;
|
||||
getch();
|
||||
|
||||
/* test 4: clrtobot */
|
||||
werase(small);
|
||||
wrefresh(small);
|
||||
touchwin(large);
|
||||
wrefresh(large);
|
||||
wmove(small, 5, 3);
|
||||
waddstr(small, " clrtobot>");
|
||||
wclrtobot(small);
|
||||
wrefresh(small);
|
||||
|
||||
/* DIFFERENCE! */
|
||||
getch();
|
||||
|
||||
endwin();
|
||||
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
.TH GDC 6
|
||||
.SH NAME
|
||||
gdc \- grand digital clock (curses)
|
||||
.SH SYNOPSIS
|
||||
.B gdc
|
||||
[-s] [
|
||||
.I n
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
.I Gdc
|
||||
runs a digital clock made of reverse-video blanks on a curses
|
||||
compatible VDU screen. With an optional numeric argument
|
||||
.I n
|
||||
it stops after
|
||||
.I n
|
||||
seconds (default never).
|
||||
The optional
|
||||
.B -s
|
||||
flag makes digits scroll as they change. In this curses mode implementation,
|
||||
the scrolling option has trouble keeping up.
|
||||
.SH AUTHOR
|
||||
Amos Shapir, modified for curses by John Lupien.
|
@ -1,315 +0,0 @@
|
||||
/*
|
||||
* Grand digital clock for curses compatible terminals
|
||||
* Usage: gdc [-s] [n] -- run for n seconds (default infinity)
|
||||
* Flags: -s: scroll
|
||||
*
|
||||
* modified 10-18-89 for curses (jrl)
|
||||
* 10-18-89 added signal handling
|
||||
*
|
||||
* $Id: gdc.c,v 1.21 2002/03/23 22:17:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define YBASE 10
|
||||
#define XBASE 10
|
||||
#define XLENGTH 54
|
||||
#define YDEPTH 5
|
||||
|
||||
static short disp[11] =
|
||||
{
|
||||
075557, 011111, 071747, 071717, 055711,
|
||||
074717, 074757, 071111, 075757, 075717, 002020
|
||||
};
|
||||
static long older[6], next[6], newer[6], mask;
|
||||
|
||||
static int sigtermed = 0;
|
||||
static bool redirected = FALSE;
|
||||
static bool hascolor = FALSE;
|
||||
|
||||
static RETSIGTYPE
|
||||
sighndl(int signo)
|
||||
{
|
||||
signal(signo, sighndl);
|
||||
sigtermed = signo;
|
||||
if (redirected) {
|
||||
endwin();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drawbox(void)
|
||||
{
|
||||
chtype bottom[XLENGTH + 1];
|
||||
int n;
|
||||
|
||||
if (hascolor)
|
||||
attrset(COLOR_PAIR(3));
|
||||
|
||||
mvaddch(YBASE - 1, XBASE - 1, ACS_ULCORNER);
|
||||
hline(ACS_HLINE, XLENGTH);
|
||||
mvaddch(YBASE - 1, XBASE + XLENGTH, ACS_URCORNER);
|
||||
|
||||
mvaddch(YBASE + YDEPTH, XBASE - 1, ACS_LLCORNER);
|
||||
mvinchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH);
|
||||
for (n = 0; n < XLENGTH; n++)
|
||||
bottom[n] = ACS_HLINE | (bottom[n] & (A_ATTRIBUTES | A_COLOR));
|
||||
mvaddchnstr(YBASE + YDEPTH, XBASE, bottom, XLENGTH);
|
||||
mvaddch(YBASE + YDEPTH, XBASE + XLENGTH, ACS_LRCORNER);
|
||||
|
||||
move(YBASE, XBASE - 1);
|
||||
vline(ACS_VLINE, YDEPTH);
|
||||
|
||||
move(YBASE, XBASE + XLENGTH);
|
||||
vline(ACS_VLINE, YDEPTH);
|
||||
|
||||
if (hascolor)
|
||||
attrset(COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
static void
|
||||
standt(int on)
|
||||
{
|
||||
if (on) {
|
||||
if (hascolor) {
|
||||
attron(COLOR_PAIR(1));
|
||||
} else {
|
||||
attron(A_STANDOUT);
|
||||
}
|
||||
} else {
|
||||
if (hascolor) {
|
||||
attron(COLOR_PAIR(2));
|
||||
} else {
|
||||
attroff(A_STANDOUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set(int t, int n)
|
||||
{
|
||||
int i, m;
|
||||
|
||||
m = 7 << n;
|
||||
for (i = 0; i < 5; i++) {
|
||||
next[i] |= ((disp[t] >> ((4 - i) * 3)) & 07) << n;
|
||||
mask |= (next[i] ^ older[i]) & m;
|
||||
}
|
||||
if (mask & m)
|
||||
mask |= m;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: gdc [options] [count]"
|
||||
,""
|
||||
,"Options:"
|
||||
," -n redirect input to /dev/null"
|
||||
," -s scroll each number into place, rather than flipping"
|
||||
,""
|
||||
,"If you specify a count, gdc runs for that number of seconds"
|
||||
};
|
||||
unsigned j;
|
||||
for (j = 0; j < SIZEOF(msg); j++)
|
||||
fprintf(stderr, "%s\n", msg[j]);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
long t, a;
|
||||
int i, j, s, k;
|
||||
int count = 0;
|
||||
FILE *ofp = stdout;
|
||||
FILE *ifp = stdin;
|
||||
bool scrol = FALSE;
|
||||
|
||||
signal(SIGINT, sighndl);
|
||||
signal(SIGTERM, sighndl);
|
||||
signal(SIGKILL, sighndl);
|
||||
|
||||
while ((k = getopt(argc, argv, "sn")) != EOF) {
|
||||
switch (k) {
|
||||
case 's':
|
||||
scrol = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
ifp = fopen("/dev/null", "r");
|
||||
redirected = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (optind < argc) {
|
||||
count = atoi(argv[optind++]);
|
||||
}
|
||||
if (optind < argc)
|
||||
usage();
|
||||
|
||||
if (redirected) {
|
||||
char *name = getenv("TERM");
|
||||
if (name == 0
|
||||
|| newterm(name, ofp, ifp) == 0) {
|
||||
fprintf(stderr, "cannot open terminal\n");
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} else {
|
||||
initscr();
|
||||
}
|
||||
cbreak();
|
||||
noecho();
|
||||
nodelay(stdscr, 1);
|
||||
curs_set(0);
|
||||
|
||||
hascolor = has_colors();
|
||||
|
||||
if (hascolor) {
|
||||
int bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
bg = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_BLACK, COLOR_RED);
|
||||
init_pair(2, COLOR_RED, bg);
|
||||
init_pair(3, COLOR_WHITE, bg);
|
||||
attrset(COLOR_PAIR(2));
|
||||
}
|
||||
|
||||
restart:
|
||||
for (j = 0; j < 5; j++)
|
||||
older[j] = newer[j] = next[j] = 0;
|
||||
|
||||
clear();
|
||||
drawbox();
|
||||
|
||||
do {
|
||||
char buf[30];
|
||||
|
||||
time(&now);
|
||||
tm = localtime(&now);
|
||||
|
||||
mask = 0;
|
||||
set(tm->tm_sec % 10, 0);
|
||||
set(tm->tm_sec / 10, 4);
|
||||
set(tm->tm_min % 10, 10);
|
||||
set(tm->tm_min / 10, 14);
|
||||
set(tm->tm_hour % 10, 20);
|
||||
set(tm->tm_hour / 10, 24);
|
||||
set(10, 7);
|
||||
set(10, 17);
|
||||
|
||||
for (k = 0; k < 6; k++) {
|
||||
if (scrol) {
|
||||
for (i = 0; i < 5; i++)
|
||||
newer[i] = (newer[i] & ~mask) | (newer[i + 1] & mask);
|
||||
newer[5] = (newer[5] & ~mask) | (next[k] & mask);
|
||||
} else
|
||||
newer[k] = (newer[k] & ~mask) | (next[k] & mask);
|
||||
next[k] = 0;
|
||||
for (s = 1; s >= 0; s--) {
|
||||
standt(s);
|
||||
for (i = 0; i < 6; i++) {
|
||||
if ((a = (newer[i] ^ older[i]) & (s ? newer : older)[i])
|
||||
!= 0) {
|
||||
for (j = 0, t = 1 << 26; t; t >>= 1, j++) {
|
||||
if (a & t) {
|
||||
if (!(a & (t << 1))) {
|
||||
move(YBASE + i, XBASE + 2 * j);
|
||||
}
|
||||
addstr(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!s) {
|
||||
older[i] = newer[i];
|
||||
}
|
||||
}
|
||||
if (!s) {
|
||||
if (scrol)
|
||||
drawbox();
|
||||
refresh();
|
||||
/*
|
||||
* If we're scrolling, space out the refreshes to fake
|
||||
* movement. That's 7 frames, or 6 intervals, which would
|
||||
* be 166 msec if we spread it out over a second. It looks
|
||||
* better (but will well on a slow terminal, e.g., less
|
||||
* than 9600bd) to squeeze that into a half-second, and use
|
||||
* half of 170 msec to ensure that the program doesn't eat
|
||||
* a lot of time when asking what time it is, at the top of
|
||||
* this loop -TD
|
||||
*/
|
||||
if (scrol)
|
||||
napms(85);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* this depends on the detailed format of ctime(3) */
|
||||
(void) strcpy(buf, ctime(&now));
|
||||
(void) strcpy(buf + 10, buf + 19);
|
||||
mvaddstr(16, 30, buf);
|
||||
|
||||
move(6, 0);
|
||||
drawbox();
|
||||
refresh();
|
||||
|
||||
/*
|
||||
* If we're not scrolling, wait 1000 msec (1 sec). Use napms() rather
|
||||
* than sleep() because the latter does odd things on some systems,
|
||||
* e.g., suspending output as well.
|
||||
*/
|
||||
if (scrol)
|
||||
napms(500);
|
||||
else
|
||||
napms(1000);
|
||||
|
||||
/*
|
||||
* This is a safe way to check if we're interrupted - making the signal
|
||||
* handler set a flag that we can check. Since we're running
|
||||
* nodelay(), the wgetch() call returns immediately, and in particular
|
||||
* will return an error if interrupted. This works only if we can
|
||||
* read from the input, of course.
|
||||
*/
|
||||
switch (wgetch(stdscr)) {
|
||||
case 'q':
|
||||
count = 1;
|
||||
break;
|
||||
case 's':
|
||||
nodelay(stdscr, FALSE);
|
||||
break;
|
||||
case ' ':
|
||||
nodelay(stdscr, TRUE);
|
||||
break;
|
||||
#ifdef KEY_RESIZE
|
||||
case KEY_RESIZE:
|
||||
#endif
|
||||
case '?':
|
||||
goto restart;
|
||||
case ERR:
|
||||
if (sigtermed) {
|
||||
standend();
|
||||
endwin();
|
||||
fprintf(stderr, "gdc terminated by signal %d\n", sigtermed);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
/* FALLTHRU */
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
} while (--count);
|
||||
standend();
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,301 +0,0 @@
|
||||
/*
|
||||
* Name: Towers of Hanoi.
|
||||
*
|
||||
* Desc:
|
||||
* This is a playable copy of towers of hanoi.
|
||||
* Its sole purpose is to demonstrate my Amiga Curses package.
|
||||
* This program should compile on any system that has Curses.
|
||||
* 'hanoi' will give a manual game with 7 playing pieces.
|
||||
* 'hanoi n' will give a manual game with n playing pieces.
|
||||
* 'hanoi n a' will give an auto solved game with n playing pieces.
|
||||
*
|
||||
* Author: Simon J Raybould (sie@fulcrum.bt.co.uk).
|
||||
* (This version has been slightly modified by the ncurses maintainers.)
|
||||
*
|
||||
* Date: 05.Nov.90
|
||||
*
|
||||
* $Id: hanoi.c,v 1.23 2002/03/24 00:40:01 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define NPEGS 3 /* This is not configurable !! */
|
||||
#define MINTILES 3
|
||||
#define MAXTILES 9
|
||||
#define DEFAULTTILES 7
|
||||
#define TOPLINE 6
|
||||
#define BASELINE 16
|
||||
#define STATUSLINE (LINES-3)
|
||||
#define LEFTPEG 19
|
||||
#define MIDPEG 39
|
||||
#define RIGHTPEG 59
|
||||
|
||||
#define LENTOIND(x) (((x)-1)/2)
|
||||
#define OTHER(a,b) (3-((a)+(b)))
|
||||
|
||||
struct Peg {
|
||||
size_t Length[MAXTILES];
|
||||
int Count;
|
||||
};
|
||||
|
||||
static struct Peg Pegs[NPEGS];
|
||||
static int PegPos[] =
|
||||
{LEFTPEG, MIDPEG, RIGHTPEG};
|
||||
static int TileColour[] =
|
||||
{
|
||||
COLOR_GREEN, /* Length 3 */
|
||||
COLOR_MAGENTA, /* Length 5 */
|
||||
COLOR_RED, /* Length 7 */
|
||||
COLOR_BLUE, /* Length 9 */
|
||||
COLOR_CYAN, /* Length 11 */
|
||||
COLOR_YELLOW, /* Length 13 */
|
||||
COLOR_GREEN, /* Length 15 */
|
||||
COLOR_MAGENTA, /* Length 17 */
|
||||
COLOR_RED, /* Length 19 */
|
||||
};
|
||||
static int NMoves = 0;
|
||||
|
||||
static void InitTiles(int NTiles);
|
||||
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 NTiles, FromCol, ToCol;
|
||||
bool AutoFlag = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
#ifdef TRACE
|
||||
trace(TRACE_MAXIMUM);
|
||||
#endif
|
||||
initscr();
|
||||
if (has_colors()) {
|
||||
int i;
|
||||
int 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(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(NTiles);
|
||||
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)
|
||||
{
|
||||
if (From >= NPEGS)
|
||||
return TRUE;
|
||||
if (From < 0)
|
||||
return TRUE;
|
||||
if (To >= NPEGS)
|
||||
return TRUE;
|
||||
if (To < 0)
|
||||
return TRUE;
|
||||
if (From == To)
|
||||
return TRUE;
|
||||
if (!Pegs[From].Count)
|
||||
return TRUE;
|
||||
if (Pegs[To].Count &&
|
||||
Pegs[From].Length[Pegs[From].Count - 1] >
|
||||
Pegs[To].Length[Pegs[To].Count - 1])
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
InitTiles(int NTiles)
|
||||
{
|
||||
int Size, SlotNo;
|
||||
|
||||
for (Size = NTiles * 2 + 1, SlotNo = 0; Size >= 3; Size -= 2)
|
||||
Pegs[0].Length[SlotNo++] = Size;
|
||||
|
||||
Pegs[0].Count = NTiles;
|
||||
Pegs[1].Count = 0;
|
||||
Pegs[2].Count = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
DisplayTiles(void)
|
||||
{
|
||||
int Line, peg, SlotNo;
|
||||
char TileBuf[BUFSIZ];
|
||||
|
||||
erase();
|
||||
mvaddstr(1, 24, "T O W E R S O F H A N O I");
|
||||
mvaddstr(3, 34, "SJR 1990");
|
||||
mvprintw(19, 5, "Moves : %d", NMoves);
|
||||
attrset(A_REVERSE);
|
||||
mvaddstr(BASELINE, 8,
|
||||
" ");
|
||||
|
||||
for (Line = TOPLINE; Line < BASELINE; Line++) {
|
||||
mvaddch(Line, LEFTPEG, ' ');
|
||||
mvaddch(Line, MIDPEG, ' ');
|
||||
mvaddch(Line, RIGHTPEG, ' ');
|
||||
}
|
||||
mvaddch(BASELINE, LEFTPEG, '1');
|
||||
mvaddch(BASELINE, MIDPEG, '2');
|
||||
mvaddch(BASELINE, RIGHTPEG, '3');
|
||||
attrset(A_NORMAL);
|
||||
|
||||
/* Draw tiles */
|
||||
for (peg = 0; peg < NPEGS; peg++) {
|
||||
for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) {
|
||||
memset(TileBuf, ' ', Pegs[peg].Length[SlotNo]);
|
||||
TileBuf[Pegs[peg].Length[SlotNo]] = '\0';
|
||||
if (has_colors())
|
||||
attrset(COLOR_PAIR(LENTOIND(Pegs[peg].Length[SlotNo])));
|
||||
else
|
||||
attrset(A_REVERSE);
|
||||
mvaddstr(BASELINE - (SlotNo + 1),
|
||||
(int) (PegPos[peg] - Pegs[peg].Length[SlotNo] / 2),
|
||||
TileBuf);
|
||||
}
|
||||
}
|
||||
attrset(A_NORMAL);
|
||||
refresh();
|
||||
}
|
||||
|
||||
static int
|
||||
GetMove(int *From, int *To)
|
||||
{
|
||||
mvaddstr(STATUSLINE, 0, "Next move ('q' to quit) from ");
|
||||
clrtoeol();
|
||||
refresh();
|
||||
if ((*From = getch()) == 'q')
|
||||
return TRUE;
|
||||
*From -= ('0' + 1);
|
||||
addstr(" to ");
|
||||
clrtoeol();
|
||||
refresh();
|
||||
|
||||
if ((*To = getch()) == 'q')
|
||||
return TRUE;
|
||||
*To -= ('0' + 1);
|
||||
refresh();
|
||||
napms(500);
|
||||
|
||||
move(STATUSLINE, 0);
|
||||
clrtoeol();
|
||||
refresh();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
MakeMove(int From, int To)
|
||||
{
|
||||
Pegs[From].Count--;
|
||||
Pegs[To].Length[Pegs[To].Count] = Pegs[From].Length[Pegs[From].Count];
|
||||
Pegs[To].Count++;
|
||||
NMoves++;
|
||||
DisplayTiles();
|
||||
}
|
||||
|
||||
static void
|
||||
AutoMove(int From, int To, int Num)
|
||||
{
|
||||
if (Num == 1) {
|
||||
MakeMove(From, To);
|
||||
napms(500);
|
||||
return;
|
||||
}
|
||||
AutoMove(From, OTHER(From, To), Num - 1);
|
||||
MakeMove(From, To);
|
||||
napms(500);
|
||||
AutoMove(OTHER(From, To), To, Num - 1);
|
||||
}
|
||||
|
||||
static int
|
||||
Solved(int NumTiles)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < NPEGS; i++)
|
||||
if (Pegs[i].Count == NumTiles)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static 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");
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
/*
|
||||
* hashtest.c -- test hash mapping
|
||||
*
|
||||
* Generate timing statistics for vertical-motion optimization.
|
||||
*
|
||||
* $Id: hashtest.c,v 1.21 2002/03/23 22:17:24 tom Exp $
|
||||
*/
|
||||
|
||||
#ifdef TRACE
|
||||
#define Trace(p) _tracef p
|
||||
#define USE_TRACE 1
|
||||
#else
|
||||
#define Trace(p) /* nothing */
|
||||
#define USE_TRACE 0
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define LO_CHAR ' '
|
||||
#define HI_CHAR '~'
|
||||
|
||||
static bool continuous = FALSE;
|
||||
static bool reverse_loops = FALSE;
|
||||
static bool single_step = FALSE;
|
||||
static bool extend_corner = FALSE;
|
||||
static int foot_lines = 0;
|
||||
static int head_lines = 0;
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
move(LINES - 1, 0);
|
||||
clrtoeol();
|
||||
refresh();
|
||||
endwin();
|
||||
}
|
||||
|
||||
static RETSIGTYPE
|
||||
finish(int sig GCC_UNUSED)
|
||||
{
|
||||
cleanup();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
genlines(int base)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
#if USE_TRACE
|
||||
if (base == 'a')
|
||||
Trace(("Resetting screen"));
|
||||
else
|
||||
Trace(("Painting `%c' screen", base));
|
||||
#endif
|
||||
|
||||
/* Do this so writes to lower-right corner don't cause a spurious
|
||||
* scrolling operation. This _shouldn't_ break the scrolling
|
||||
* optimization, since that's computed in the refresh() call.
|
||||
*/
|
||||
scrollok(stdscr, FALSE);
|
||||
|
||||
move(0, 0);
|
||||
for (i = 0; i < head_lines; i++)
|
||||
for (j = 0; j < COLS; j++)
|
||||
addch((j % 8 == 0) ? ('A' + j / 8) : '-');
|
||||
|
||||
move(head_lines, 0);
|
||||
for (i = head_lines; i < LINES - foot_lines; i++) {
|
||||
int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
|
||||
int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
|
||||
for (j = 0; j < hi; j++)
|
||||
addch(c);
|
||||
}
|
||||
|
||||
for (i = LINES - foot_lines; i < LINES; i++) {
|
||||
move(i, 0);
|
||||
for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
|
||||
addch((j % 8 == 0) ? ('A' + j / 8) : '-');
|
||||
}
|
||||
|
||||
scrollok(stdscr, TRUE);
|
||||
if (single_step) {
|
||||
move(LINES - 1, 0);
|
||||
getch();
|
||||
} else
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void
|
||||
one_cycle(int ch)
|
||||
{
|
||||
if (continuous) {
|
||||
genlines(ch);
|
||||
} else if (ch != 'a') {
|
||||
genlines('a');
|
||||
genlines(ch);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
run_test(bool optimized GCC_UNUSED)
|
||||
{
|
||||
char ch;
|
||||
int lo = continuous ? LO_CHAR : 'a' - LINES;
|
||||
int hi = continuous ? HI_CHAR : 'a' + LINES;
|
||||
|
||||
if (lo < LO_CHAR)
|
||||
lo = LO_CHAR;
|
||||
if (hi > HI_CHAR)
|
||||
hi = HI_CHAR;
|
||||
|
||||
#if defined(TRACE) || defined(NCURSES_TEST)
|
||||
if (optimized) {
|
||||
Trace(("With hash mapping"));
|
||||
_nc_optimize_enable |= OPTIMIZE_HASHMAP;
|
||||
} else {
|
||||
Trace(("Without hash mapping"));
|
||||
_nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (reverse_loops)
|
||||
for (ch = hi; ch >= lo; ch--)
|
||||
one_cycle(ch);
|
||||
else
|
||||
for (ch = lo; ch <= hi; ch++)
|
||||
one_cycle(ch);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *const tbl[] =
|
||||
{
|
||||
"Usage: hashtest [options]"
|
||||
,""
|
||||
,"Options:"
|
||||
," -c continuous (don't reset between refresh's)"
|
||||
," -f num leave 'num' lines constant for footer"
|
||||
," -h num leave 'num' lines constant for header"
|
||||
," -l num repeat test 'num' times"
|
||||
," -n test the normal optimizer"
|
||||
," -o test the hashed optimizer"
|
||||
," -r reverse the loops"
|
||||
," -s single-step"
|
||||
," -x assume lower-right corner extension"
|
||||
};
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < SIZEOF(tbl); n++)
|
||||
fprintf(stderr, "%s\n", tbl[n]);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int test_loops = 1;
|
||||
int test_normal = FALSE;
|
||||
int test_optimize = FALSE;
|
||||
|
||||
while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
continuous = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
foot_lines = atoi(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
head_lines = atoi(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
test_loops = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
test_normal = TRUE;
|
||||
break;
|
||||
case 'o':
|
||||
test_optimize = TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
reverse_loops = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
single_step = TRUE;
|
||||
break;
|
||||
case 'x':
|
||||
extend_corner = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (!test_normal && !test_optimize) {
|
||||
test_normal = TRUE;
|
||||
test_optimize = TRUE;
|
||||
}
|
||||
#if USE_TRACE
|
||||
trace(TRACE_TIMES);
|
||||
#endif
|
||||
|
||||
(void) signal(SIGINT, finish); /* arrange interrupts to terminate */
|
||||
|
||||
(void) initscr(); /* initialize the curses library */
|
||||
keypad(stdscr, TRUE); /* enable keyboard mapping */
|
||||
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
|
||||
(void) cbreak(); /* take input chars one at a time, no wait for \n */
|
||||
(void) noecho(); /* don't echo input */
|
||||
scrollok(stdscr, TRUE);
|
||||
|
||||
while (test_loops-- > 0) {
|
||||
if (test_normal)
|
||||
run_test(FALSE);
|
||||
if (test_optimize)
|
||||
run_test(TRUE);
|
||||
}
|
||||
|
||||
cleanup(); /* we're done */
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
/* hashtest.c ends here */
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* $Id: keynames.c,v 1.3 2001/09/15 21:46:34 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int n;
|
||||
for (n = -1; n < 512; n++) {
|
||||
printf("%d(%5o):%s\n", n, n, keyname(n));
|
||||
}
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,700 +0,0 @@
|
||||
/*
|
||||
* Knight's Tour - a brain game
|
||||
*
|
||||
* The original of this game was anonymous. It had an unbelievably bogus
|
||||
* interface, you actually had to enter square coordinates! Redesign by
|
||||
* Eric S. Raymond <esr@snark.thyrsus.com> July 22 1995. Mouse support
|
||||
* added September 20th 1995.
|
||||
*
|
||||
* $Id: knight.c,v 1.24 2002/03/23 22:17:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
/* board size */
|
||||
#define BDEPTH 8
|
||||
#define BWIDTH 8
|
||||
|
||||
/* where to start the instructions */
|
||||
#define INSTRY 2
|
||||
#define INSTRX 35
|
||||
|
||||
/* corner of board */
|
||||
#define BOARDY 2
|
||||
#define BOARDX 0
|
||||
|
||||
/* notification line */
|
||||
#define NOTIFYY 21
|
||||
|
||||
/* virtual color values */
|
||||
#define TRAIL_COLOR 1
|
||||
#define PLUS_COLOR 2
|
||||
#define MINUS_COLOR 3
|
||||
|
||||
#define CX(x) (2 + 4 * (x))
|
||||
#define CY(y) (1 + 2 * (y))
|
||||
#define cellmove(y, x) wmove(boardwin, CY(y), CX(x))
|
||||
#define CXINV(x) (((x) - 1) / 4)
|
||||
#define CYINV(y) (((y) - 2) / 2)
|
||||
|
||||
typedef struct {
|
||||
short x, y;
|
||||
} cell;
|
||||
|
||||
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 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 */
|
||||
/* *INDENT-OFF* */
|
||||
static const struct {
|
||||
int y;
|
||||
int x;
|
||||
} offsets[] = {
|
||||
{ 2, 1 },
|
||||
{ 1, 2 },
|
||||
{ -1, 2 },
|
||||
{ -2, 1 },
|
||||
{ -2, -1 },
|
||||
{ -1, -2 },
|
||||
{ 1, -2 },
|
||||
{ 2, -1 },
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
init_program(void)
|
||||
{
|
||||
srand((unsigned) getpid());
|
||||
initscr();
|
||||
cbreak(); /* immediate char return */
|
||||
noecho(); /* no immediate echo */
|
||||
boardwin = newwin(BDEPTH * 2 + 1, BWIDTH * 4 + 1, BOARDY, BOARDX);
|
||||
helpwin = newwin(0, 0, INSTRY, INSTRX);
|
||||
msgwin = newwin(1, INSTRX - 1, NOTIFYY, 0);
|
||||
scrollok(msgwin, TRUE);
|
||||
keypad(boardwin, TRUE);
|
||||
|
||||
if (has_colors()) {
|
||||
int bg = COLOR_BLACK;
|
||||
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
bg = -1;
|
||||
#endif
|
||||
|
||||
(void) init_pair(TRAIL_COLOR, COLOR_CYAN, bg);
|
||||
(void) init_pair(PLUS_COLOR, COLOR_RED, bg);
|
||||
(void) init_pair(MINUS_COLOR, COLOR_GREEN, bg);
|
||||
|
||||
trail |= COLOR_PAIR(TRAIL_COLOR);
|
||||
plus |= COLOR_PAIR(PLUS_COLOR);
|
||||
minus |= COLOR_PAIR(MINUS_COLOR);
|
||||
}
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
(void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
|
||||
#endif /* NCURSES_MOUSE_VERSION */
|
||||
|
||||
oldch = minus;
|
||||
}
|
||||
|
||||
static void
|
||||
help1(void)
|
||||
/* game explanation -- initial help screen */
|
||||
{
|
||||
(void) waddstr(helpwin, "Knight's move is a solitaire puzzle. Your\n");
|
||||
(void) waddstr(helpwin, "objective is to visit each square of the \n");
|
||||
(void) waddstr(helpwin, "chessboard exactly once by making knight's\n");
|
||||
(void) waddstr(helpwin, "moves (one square right or left followed \n");
|
||||
(void) waddstr(helpwin, "by two squares up or down, or two squares \n");
|
||||
(void) waddstr(helpwin, "right or left followed by one square up or\n");
|
||||
(void) waddstr(helpwin, "down). You may start anywhere.\n\n");
|
||||
|
||||
(void) waddstr(helpwin, "Use arrow keys to move the cursor around.\n");
|
||||
(void) waddstr(helpwin, "When you want to move your knight to the \n");
|
||||
(void) waddstr(helpwin, "cursor location, press <space> or Enter.\n");
|
||||
(void) waddstr(helpwin, "Illegal moves will be rejected with an \n");
|
||||
(void) waddstr(helpwin, "audible beep.\n\n");
|
||||
(void) waddstr(helpwin, "The program will detect if you solve the\n");
|
||||
(void) waddstr(helpwin, "puzzle; also inform you when you run out\n");
|
||||
(void) waddstr(helpwin, "of legal moves.\n\n");
|
||||
|
||||
(void) mvwaddstr(helpwin, NOTIFYY - INSTRY, 0,
|
||||
"Press `?' to go to keystroke help.");
|
||||
}
|
||||
|
||||
static void
|
||||
help2(void)
|
||||
/* keystroke help screen */
|
||||
{
|
||||
(void) waddstr(helpwin, "Possible moves are shown with `-'.\n\n");
|
||||
|
||||
(void) waddstr(helpwin, "You can move around with the arrow keys or\n");
|
||||
(void) waddstr(helpwin, "with the rogue/hack movement keys. Other\n");
|
||||
(void) waddstr(helpwin, "commands allow you to undo moves or redraw.\n");
|
||||
(void) waddstr(helpwin, "Your mouse may work; try left-button to\n");
|
||||
(void) waddstr(helpwin, "move to the square under the pointer.\n\n");
|
||||
|
||||
(void) waddstr(helpwin, "x,q -- exit y k u 7 8 9\n");
|
||||
(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");
|
||||
|
||||
(void) waddstr(helpwin, "\nYou can place your knight on the selected\n");
|
||||
(void) waddstr(helpwin, "square with spacebar, Enter, or the keypad\n");
|
||||
(void) waddstr(helpwin, "center key. Use F/B to review the path.\n");
|
||||
|
||||
(void) mvwaddstr(helpwin, NOTIFYY - INSTRY, 0,
|
||||
"Press `?' to go to game explanation");
|
||||
}
|
||||
|
||||
static void
|
||||
show_help(bool * keyhelp)
|
||||
{
|
||||
werase(helpwin);
|
||||
if (*keyhelp) {
|
||||
help1();
|
||||
*keyhelp = FALSE;
|
||||
} else {
|
||||
help2();
|
||||
*keyhelp = TRUE;
|
||||
}
|
||||
wrefresh(helpwin);
|
||||
}
|
||||
|
||||
static bool
|
||||
chksqr(int r1, int c1)
|
||||
{
|
||||
if ((r1 < 0) || (r1 > BDEPTH - 1))
|
||||
return (FALSE);
|
||||
if ((c1 < 0) || (c1 > BWIDTH - 1))
|
||||
return (FALSE);
|
||||
return ((!board[r1][c1]) ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
static bool
|
||||
chkmoves(int rw, int col)
|
||||
/* check to see if valid moves are available */
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
for (n = 0; n < SIZEOF(offsets); n++)
|
||||
if (chksqr(rw + offsets[n].y, col + offsets[n].x))
|
||||
return (TRUE);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
dosquares(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
mvaddstr(0, 20, "KNIGHT'S MOVE -- a logical solitaire");
|
||||
|
||||
move(BOARDY, BOARDX);
|
||||
waddch(boardwin, ACS_ULCORNER);
|
||||
for (j = 0; j < 7; j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_TTEE);
|
||||
}
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_URCORNER);
|
||||
|
||||
for (i = 1; i < BDEPTH; i++) {
|
||||
move(BOARDY + i * 2 - 1, BOARDX);
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
}
|
||||
move(BOARDY + i * 2, BOARDX);
|
||||
waddch(boardwin, ACS_LTEE);
|
||||
for (j = 0; j < BWIDTH - 1; j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_PLUS);
|
||||
}
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_RTEE);
|
||||
}
|
||||
|
||||
move(BOARDY + i * 2 - 1, BOARDX);
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, ACS_VLINE);
|
||||
}
|
||||
|
||||
move(BOARDY + i * 2, BOARDX);
|
||||
waddch(boardwin, ACS_LLCORNER);
|
||||
for (j = 0; j < BWIDTH - 1; j++) {
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_BTEE);
|
||||
}
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_HLINE);
|
||||
waddch(boardwin, ACS_LRCORNER);
|
||||
}
|
||||
|
||||
static void
|
||||
mark_possibles(int prow, int pcol, 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);
|
||||
waddch(boardwin, mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
find_next_move(int *y, int *x)
|
||||
{
|
||||
unsigned j, k;
|
||||
int found = -1;
|
||||
int first = -1;
|
||||
int next = 0;
|
||||
int oldy, oldx;
|
||||
int newy, newx;
|
||||
|
||||
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);
|
||||
newy = oldy + offsets[k].y;
|
||||
newx = oldx + offsets[k].x;
|
||||
if (chksqr(newy, newx)) {
|
||||
if (first < 0)
|
||||
first = k;
|
||||
if (newy == *y
|
||||
&& newx == *x) {
|
||||
found = k;
|
||||
} else if (found >= 0) {
|
||||
next = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found < 0)
|
||||
next = first;
|
||||
if (next >= 0) {
|
||||
*y = oldy + offsets[next].y;
|
||||
*x = oldx + offsets[next].x;
|
||||
}
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unmarkcell(int row, int column)
|
||||
{
|
||||
cellmove(row, column);
|
||||
waddch(boardwin, '\b');
|
||||
waddch(boardwin, ' ');
|
||||
waddch(boardwin, minus);
|
||||
waddch(boardwin, ' ');
|
||||
}
|
||||
|
||||
static void
|
||||
markcell(chtype tchar, int row, int column)
|
||||
{
|
||||
cellmove(row, column);
|
||||
waddch(boardwin, '\b');
|
||||
waddch(boardwin, tchar);
|
||||
waddch(boardwin, tchar);
|
||||
waddch(boardwin, tchar);
|
||||
}
|
||||
|
||||
static void
|
||||
drawmove(chtype tchar, int oldy, int oldx, int row, int column)
|
||||
/* place the stars, update board & currents */
|
||||
{
|
||||
if (movecount <= 1) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < BDEPTH; i++) {
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
if (movecount == 0) {
|
||||
unmarkcell(i, j);
|
||||
} else {
|
||||
cellmove(i, j);
|
||||
if (winch(boardwin) == minus)
|
||||
waddch(boardwin, movecount ? ' ' : minus);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
markcell(tchar, oldy, oldx);
|
||||
mark_possibles(oldy, oldx, ' ');
|
||||
}
|
||||
|
||||
if (row != -1 && column != -1) {
|
||||
markcell(trail, row, column);
|
||||
mark_possibles(row, column, minus);
|
||||
board[row][column] = TRUE;
|
||||
}
|
||||
|
||||
wprintw(msgwin, "\nMove %d", movecount);
|
||||
if (trialcount != movecount)
|
||||
wprintw(msgwin, " (%d tries)", trialcount);
|
||||
wclrtoeol(msgwin);
|
||||
}
|
||||
|
||||
static int
|
||||
iabs(int num)
|
||||
{
|
||||
if (num < 0)
|
||||
return (-num);
|
||||
else
|
||||
return (num);
|
||||
}
|
||||
|
||||
static bool
|
||||
evalmove(int row, int column)
|
||||
/* evaluate move */
|
||||
{
|
||||
if (movecount == 1)
|
||||
return (TRUE);
|
||||
else if (board[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);
|
||||
|
||||
if (!((rdif == 1) && (cdif == 2)) && !((rdif == 2) && (cdif == 1))) {
|
||||
waddstr(msgwin, "\nThat's not a legal knight's move.");
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
completed(void)
|
||||
{
|
||||
int i, j, count = 0;
|
||||
|
||||
for (i = 0; i < BDEPTH; i++)
|
||||
for (j = 0; j < BWIDTH; j++)
|
||||
if (board[i][j] != 0)
|
||||
count += 1;
|
||||
return (count == (BWIDTH * BDEPTH) ? -1 : count);
|
||||
}
|
||||
|
||||
static void
|
||||
no_previous_move(void)
|
||||
{
|
||||
waddstr(msgwin, "\nNo previous move.");
|
||||
beep();
|
||||
}
|
||||
|
||||
static void
|
||||
play(void)
|
||||
/* play the game */
|
||||
{
|
||||
bool keyhelp; /* TRUE if keystroke help is up */
|
||||
int i, j, count;
|
||||
int lastcol = 0; /* last location visited */
|
||||
int lastrow = 0;
|
||||
int ny = 0, nx = 0;
|
||||
int review = 0; /* review history */
|
||||
int rw = 0, col = 0; /* current row and column */
|
||||
|
||||
do {
|
||||
/* clear screen and draw board */
|
||||
werase(boardwin);
|
||||
werase(helpwin);
|
||||
werase(msgwin);
|
||||
dosquares();
|
||||
help1();
|
||||
wnoutrefresh(stdscr);
|
||||
wnoutrefresh(helpwin);
|
||||
wnoutrefresh(msgwin);
|
||||
wnoutrefresh(boardwin);
|
||||
doupdate();
|
||||
|
||||
movecount = 0;
|
||||
for (i = 0; i < BDEPTH; i++) {
|
||||
for (j = 0; j < BWIDTH; j++) {
|
||||
board[i][j] = FALSE;
|
||||
unmarkcell(i, j);
|
||||
}
|
||||
}
|
||||
memset(history, 0, sizeof(history));
|
||||
history[0].y = history[0].x = -1;
|
||||
history[1].y = history[1].x = -1;
|
||||
lastrow = lastcol = -2;
|
||||
movecount = 1;
|
||||
trialcount = 1;
|
||||
keyhelp = FALSE;
|
||||
show_help(&keyhelp);
|
||||
|
||||
for (;;) {
|
||||
if (rw != lastrow || col != lastcol) {
|
||||
if (lastrow >= 0 && lastcol >= 0) {
|
||||
cellmove(lastrow, lastcol);
|
||||
if (board[lastrow][lastcol])
|
||||
waddch(boardwin, trail);
|
||||
else
|
||||
waddch(boardwin, oldch);
|
||||
}
|
||||
|
||||
cellmove(rw, col);
|
||||
oldch = winch(boardwin);
|
||||
|
||||
lastrow = rw;
|
||||
lastcol = col;
|
||||
}
|
||||
cellmove(rw, col);
|
||||
waddch(boardwin, plus);
|
||||
cellmove(rw, col);
|
||||
|
||||
wrefresh(msgwin);
|
||||
|
||||
switch (wgetch(boardwin)) {
|
||||
case 'k':
|
||||
case '8':
|
||||
case KEY_UP:
|
||||
ny = rw + BDEPTH - 1;
|
||||
nx = col;
|
||||
break;
|
||||
case 'j':
|
||||
case '2':
|
||||
case KEY_DOWN:
|
||||
ny = rw + 1;
|
||||
nx = col;
|
||||
break;
|
||||
case 'h':
|
||||
case '4':
|
||||
case KEY_LEFT:
|
||||
ny = rw;
|
||||
nx = col + BWIDTH - 1;
|
||||
break;
|
||||
case 'l':
|
||||
case '6':
|
||||
case KEY_RIGHT:
|
||||
ny = rw;
|
||||
nx = col + 1;
|
||||
break;
|
||||
case 'y':
|
||||
case '7':
|
||||
case KEY_A1:
|
||||
ny = rw + BDEPTH - 1;
|
||||
nx = col + BWIDTH - 1;
|
||||
break;
|
||||
case 'b':
|
||||
case '1':
|
||||
case KEY_C1:
|
||||
ny = rw + 1;
|
||||
nx = col + BWIDTH - 1;
|
||||
break;
|
||||
case 'u':
|
||||
case '9':
|
||||
case KEY_A3:
|
||||
ny = rw + BDEPTH - 1;
|
||||
nx = col + 1;
|
||||
break;
|
||||
case 'n':
|
||||
case '3':
|
||||
case KEY_C3:
|
||||
ny = rw + 1;
|
||||
nx = col + 1;
|
||||
break;
|
||||
|
||||
#ifdef NCURSES_MOUSE_VERSION
|
||||
case KEY_MOUSE:
|
||||
{
|
||||
MEVENT myevent;
|
||||
|
||||
getmouse(&myevent);
|
||||
if (myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
|
||||
&& myevent.x >= CX(0) && myevent.x <= CX(BWIDTH)) {
|
||||
nx = CXINV(myevent.x);
|
||||
ny = CYINV(myevent.y);
|
||||
ungetch('\n');
|
||||
break;
|
||||
} else {
|
||||
beep();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif /* NCURSES_MOUSE_VERSION */
|
||||
|
||||
case KEY_B2:
|
||||
case '\n':
|
||||
case ' ':
|
||||
review = 0;
|
||||
if (evalmove(rw, col)) {
|
||||
drawmove(trail,
|
||||
history[movecount - 1].y,
|
||||
history[movecount - 1].x,
|
||||
rw, col);
|
||||
history[movecount].y = rw;
|
||||
history[movecount].x = col;
|
||||
movecount++;
|
||||
trialcount++;
|
||||
|
||||
if (!chkmoves(rw, col)) {
|
||||
if (completed() < 0) {
|
||||
waddstr(msgwin, "\nYou won.");
|
||||
} else {
|
||||
waddstr(msgwin,
|
||||
"\nNo further moves are possible.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_UNDO:
|
||||
case KEY_BACKSPACE:
|
||||
case '\b':
|
||||
review = 0;
|
||||
if (movecount <= 0) {
|
||||
no_previous_move();
|
||||
} else if (movecount <= 1) {
|
||||
ny = history[movecount].y;
|
||||
nx = history[movecount].x;
|
||||
if (nx < 0 || ny < 0) {
|
||||
ny = lastrow;
|
||||
nx = lastcol;
|
||||
}
|
||||
movecount = 0;
|
||||
board[ny][nx] = FALSE;
|
||||
oldch = minus;
|
||||
drawmove(' ', ny, nx, -1, -1);
|
||||
movecount = 1;
|
||||
trialcount = 1;
|
||||
no_previous_move();
|
||||
} else {
|
||||
int oldy = history[movecount - 1].y;
|
||||
int oldx = history[movecount - 1].x;
|
||||
|
||||
if (!board[rw][col]) {
|
||||
cellmove(rw, col);
|
||||
waddch(boardwin, ' ');
|
||||
}
|
||||
|
||||
board[oldy][oldx] = FALSE;
|
||||
--movecount;
|
||||
ny = history[movecount - 1].y;
|
||||
nx = history[movecount - 1].x;
|
||||
if (nx < 0 || ny < 0) {
|
||||
ny = oldy;
|
||||
nx = oldx;
|
||||
}
|
||||
drawmove(' ', oldy, oldx, ny, nx);
|
||||
|
||||
/* avoid problems if we just changed the current cell */
|
||||
cellmove(lastrow, lastcol);
|
||||
oldch = winch(boardwin);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
nx = col;
|
||||
ny = rw;
|
||||
find_next_move(&ny, &nx);
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
if (review > 0) {
|
||||
review--;
|
||||
ny = history[movecount - review - 1].y;
|
||||
nx = history[movecount - review - 1].x;
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
if (review < movecount - 2) {
|
||||
review++;
|
||||
ny = history[movecount - review - 1].y;
|
||||
nx = history[movecount - review - 1].x;
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_REDO:
|
||||
case '\f':
|
||||
case 'r':
|
||||
clearok(curscr, TRUE);
|
||||
wnoutrefresh(stdscr);
|
||||
wnoutrefresh(boardwin);
|
||||
wnoutrefresh(msgwin);
|
||||
wnoutrefresh(helpwin);
|
||||
doupdate();
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
case 'x':
|
||||
goto dropout;
|
||||
|
||||
case '?':
|
||||
show_help(&keyhelp);
|
||||
break;
|
||||
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
|
||||
col = nx % BWIDTH;
|
||||
rw = ny % BDEPTH;
|
||||
}
|
||||
|
||||
dropout:
|
||||
if ((count = completed()) < 0)
|
||||
wprintw(msgwin, "\nYou won. Care to try again? ");
|
||||
else
|
||||
wprintw(msgwin, "\n%d squares filled. Try again? ", count);
|
||||
wclrtoeol(msgwin);
|
||||
} while
|
||||
(tolower(wgetch(msgwin)) == 'y');
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
init_program();
|
||||
|
||||
play();
|
||||
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* knight.c ends here */
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Test lower-right-hand corner access
|
||||
*
|
||||
* originally by Eric S. Raymond <esr@thyrsus.com>, written for animation
|
||||
* and resizing -TD
|
||||
*
|
||||
* This can't be part of the ncurses test-program, because ncurses rips off the
|
||||
* bottom line to do labels.
|
||||
*
|
||||
* $Id: lrtest.c,v 0.17 2002/04/06 20:45:22 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
typedef struct {
|
||||
int y, x, mode, dir, inc;
|
||||
chtype value;
|
||||
} MARK;
|
||||
|
||||
/*
|
||||
* Make a couple of markers go 'round the border to demonstrate that we can
|
||||
* really write to all positions properly.
|
||||
*/
|
||||
static void
|
||||
show(MARK * m)
|
||||
{
|
||||
mvaddch(m->y, m->x, m->value);
|
||||
if (m->mode == 0) { /* along the x-direction */
|
||||
m->x += m->inc;
|
||||
if (m->x >= COLS) {
|
||||
m->x = COLS - 1;
|
||||
m->inc = -m->dir * m->inc;
|
||||
m->y += m->inc;
|
||||
m->mode = 1;
|
||||
} else if (m->x < 0) {
|
||||
m->x = 0;
|
||||
m->inc = -m->dir * m->inc;
|
||||
m->y += m->inc;
|
||||
m->mode = 1;
|
||||
}
|
||||
} else { /* along the y-direction */
|
||||
m->y += m->inc;
|
||||
if (m->y >= LINES) {
|
||||
m->y = LINES - 1;
|
||||
m->inc = m->dir * m->inc;
|
||||
m->x += m->inc;
|
||||
m->mode = 0;
|
||||
} else if (m->y < 0) {
|
||||
m->y = 0;
|
||||
m->inc = m->dir * m->inc;
|
||||
m->x += m->inc;
|
||||
m->mode = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
static MARK marks[] =
|
||||
{
|
||||
{0, 0, 0, -1, 1, '+' | A_BOLD},
|
||||
{0, 0, 1, 1, 2, 'X'},
|
||||
{0, 0, 1, -1, 3, 'Y'},
|
||||
{0, 8, 0, -1, 1, '+' | A_BOLD},
|
||||
{0, 9, 0, -1, 1, '+' | A_BOLD},
|
||||
{1, 0, 1, 1, 1, '*' | A_REVERSE},
|
||||
{2, 0, 1, 1, 1, '*' | A_REVERSE}
|
||||
};
|
||||
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
nodelay(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
|
||||
#ifdef KEY_RESIZE
|
||||
keypad(stdscr, TRUE);
|
||||
restart:
|
||||
#endif
|
||||
move(LINES / 2 - 1, 4);
|
||||
if (!(has_ic()
|
||||
/* see PutCharLR() */
|
||||
|| auto_right_margin
|
||||
|| (enter_am_mode && exit_am_mode))) {
|
||||
addstr("Your terminal lacks the capabilities needed to address the\n");
|
||||
move(LINES / 2, 4);
|
||||
addstr("lower-right-hand corner of the screen.\n");
|
||||
} else {
|
||||
addstr("This is a test of access to the lower right corner.\n");
|
||||
move(LINES / 2, 4);
|
||||
addstr("If the top of the box is missing, the test failed.\n");
|
||||
move(LINES / 2 + 1, 4);
|
||||
addstr("Please report this (with a copy of your terminfo entry).\n");
|
||||
move(LINES / 2 + 2, 4);
|
||||
addstr("to the ncurses maintainers, at bug-ncurses@gnu.org.\n");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int ch;
|
||||
unsigned n;
|
||||
|
||||
box(stdscr, 0, 0);
|
||||
for (n = 0; n < SIZEOF(marks); n++) {
|
||||
show(&marks[n]);
|
||||
}
|
||||
|
||||
if ((ch = getch()) > 0) {
|
||||
if (ch == 'q')
|
||||
break;
|
||||
else if (ch == 's')
|
||||
nodelay(stdscr, FALSE);
|
||||
else if (ch == ' ')
|
||||
nodelay(stdscr, TRUE);
|
||||
#ifdef KEY_RESIZE
|
||||
else if (ch == KEY_RESIZE) {
|
||||
for (n = 0; n < SIZEOF(marks); n++) {
|
||||
if (marks[n].mode == 0) { /* moving along x-direction */
|
||||
if (marks[n].y)
|
||||
marks[n].y = LINES - 1;
|
||||
} else {
|
||||
if (marks[n].x)
|
||||
marks[n].x = COLS - 1;
|
||||
}
|
||||
}
|
||||
flash();
|
||||
erase();
|
||||
wrefresh(curscr);
|
||||
goto restart;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
napms(50);
|
||||
refresh();
|
||||
}
|
||||
|
||||
curs_set(1);
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* lrtest.c ends here */
|
@ -1,59 +0,0 @@
|
||||
# Test-Program modules
|
||||
# $Id: modules,v 1.13 2000/02/13 01:05:13 tom Exp $
|
||||
##############################################################################
|
||||
# Copyright (c) 1998,1999,2000 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"), #
|
||||
# to deal in the Software without restriction, including without limitation #
|
||||
# the rights to use, copy, modify, merge, publish, distribute, distribute #
|
||||
# with modifications, sublicense, and/or sell copies of the Software, and to #
|
||||
# permit persons to whom the Software is furnished to do so, subject to the #
|
||||
# following conditions: #
|
||||
# #
|
||||
# The above copyright notice and this permission notice shall be included in #
|
||||
# all copies or substantial portions of the Software. #
|
||||
# #
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
|
||||
# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
|
||||
# DEALINGS IN THE SOFTWARE. #
|
||||
# #
|
||||
# Except as contained in this notice, the name(s) of the above copyright #
|
||||
# holders shall not be used in advertising or otherwise to promote the sale, #
|
||||
# use or other dealings in this Software without prior written #
|
||||
# authorization. #
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Thomas E. Dickey <dickey@clark.net> 1997
|
||||
#
|
||||
|
||||
@ base
|
||||
blue progs $(srcdir) ../include/term.h
|
||||
bs progs $(srcdir)
|
||||
cardfile progs $(srcdir) ../include/panel.h ../include/menu.h ../include/form.h
|
||||
ditto progs $(srcdir)
|
||||
dots progs $(srcdir) ../include/term.h
|
||||
filter progs $(srcdir)
|
||||
firework progs $(srcdir) ../include/term.h
|
||||
firstlast progs $(srcdir)
|
||||
gdc progs $(srcdir)
|
||||
hanoi progs $(srcdir)
|
||||
hashtest progs $(srcdir)
|
||||
keynames progs $(srcdir)
|
||||
knight progs $(srcdir)
|
||||
lrtest progs $(srcdir)
|
||||
ncurses progs $(srcdir) ../include/panel.h ../include/menu.h ../include/form.h
|
||||
newdemo progs $(srcdir)
|
||||
rain progs $(srcdir) ../include/term.h
|
||||
railroad progs $(srcdir) ../include/termcap.h
|
||||
tclock progs $(srcdir)
|
||||
testaddch progs $(srcdir)
|
||||
testcurs progs $(srcdir)
|
||||
testscanw progs $(srcdir)
|
||||
view progs $(srcdir)
|
||||
worm progs $(srcdir)
|
||||
xmas progs $(srcdir)
|
File diff suppressed because it is too large
Load Diff
@ -1,56 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1998 *
|
||||
****************************************************************************/
|
||||
/*
|
||||
* $Id: ncurses_tst.hin,v 1.2 1998/02/11 12:14:05 tom Exp $
|
||||
*
|
||||
* This is a template-file used to generate the "ncurses_cfg.h" file.
|
||||
*
|
||||
* Rather than list every definition, the configuration script substitutes
|
||||
* the definitions that it finds using 'sed'. You need a patch (971222)
|
||||
* to autoconf 2.12 to do this.
|
||||
*/
|
||||
#ifndef NC_CONFIG_H
|
||||
#define NC_CONFIG_H
|
||||
@DEFS@
|
||||
|
||||
/* The C compiler may not treat these properly but C++ has to */
|
||||
#ifdef __cplusplus
|
||||
#undef const
|
||||
#undef inline
|
||||
#else
|
||||
#if defined(lint) || defined(TRACE)
|
||||
#undef inline
|
||||
#define inline /* nothing */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* NC_CONFIG_H */
|
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* newdemo.c - A demo program using PDCurses. The program illustrate
|
||||
* the use of colours for text output.
|
||||
*
|
||||
* $Id: newdemo.c,v 1.23 2002/03/23 22:17:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#define delay_output(x) napms(x)
|
||||
|
||||
/*
|
||||
* The Australian map
|
||||
*/
|
||||
const char *AusMap[16] =
|
||||
{
|
||||
" A A ",
|
||||
" N.T. AAAAA AAAA ",
|
||||
" AAAAAAAAAAA AAAAAAAA ",
|
||||
" AAAAAAAAAAAAAAAAAAAAAAAAA Qld.",
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
|
||||
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
|
||||
" AAAAAAAAAAAAAAAAAAAAAAAAA N.S.W.",
|
||||
"W.A. AAAAAAAAA AAAAAA Vic.",
|
||||
" AAA S.A. AA",
|
||||
" A Tas.",
|
||||
""
|
||||
};
|
||||
|
||||
/*
|
||||
* Funny messages
|
||||
*/
|
||||
#define NMESSAGES 6
|
||||
|
||||
NCURSES_CONST char *messages[] =
|
||||
{
|
||||
"Hello from the Land Down Under",
|
||||
"The Land of crocs. and a big Red Rock",
|
||||
"Where the sunflower runs along the highways",
|
||||
"the dusty red roads lead one to loneliness",
|
||||
"Blue sky in the morning and",
|
||||
"freezing nights and twinkling stars",
|
||||
""
|
||||
};
|
||||
|
||||
/*
|
||||
* Trap interrupt
|
||||
*/
|
||||
static RETSIGTYPE
|
||||
trap(int sig GCC_UNUSED)
|
||||
{
|
||||
endwin();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for user
|
||||
*/
|
||||
static int
|
||||
WaitForUser(WINDOW *win)
|
||||
{
|
||||
time_t t;
|
||||
chtype key;
|
||||
|
||||
nodelay(win, TRUE);
|
||||
t = time((time_t *) 0);
|
||||
while (1) {
|
||||
if ((int) (key = wgetch(win)) != ERR) {
|
||||
if (key == 'q' || key == 'Q')
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
if (time((time_t *) 0) - t > 5)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_colors(WINDOW *win, int pair, int foreground, int background)
|
||||
{
|
||||
if (has_colors()) {
|
||||
if (pair > COLOR_PAIRS)
|
||||
pair = COLOR_PAIRS;
|
||||
init_pair(pair, foreground, background);
|
||||
wattrset(win, COLOR_PAIR(pair));
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
use_colors(WINDOW *win, int pair, int attrs)
|
||||
{
|
||||
if (has_colors()) {
|
||||
if (pair > COLOR_PAIRS)
|
||||
pair = COLOR_PAIRS;
|
||||
attrs |= COLOR_PAIR(pair);
|
||||
}
|
||||
wattrset(win, attrs);
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test sub windows
|
||||
*/
|
||||
static int
|
||||
SubWinTest(WINDOW *win)
|
||||
{
|
||||
int w, h, sw, sh, bx, by;
|
||||
WINDOW *swin1, *swin2, *swin3;
|
||||
|
||||
getmaxyx(win, h, w);
|
||||
getbegyx(win, by, bx);
|
||||
sw = w / 3;
|
||||
sh = h / 3;
|
||||
if ((swin1 = subwin(win, sh, sw, by + 3, bx + 5)) == NULL)
|
||||
return 1;
|
||||
if ((swin2 = subwin(win, sh, sw, by + 4, bx + 8)) == NULL)
|
||||
return 1;
|
||||
if ((swin3 = subwin(win, sh, sw, by + 5, bx + 11)) == NULL)
|
||||
return 1;
|
||||
|
||||
set_colors(swin1, 8, COLOR_RED, COLOR_BLUE);
|
||||
werase(swin1);
|
||||
mvwaddstr(swin1, 0, 3, "Sub-window 1");
|
||||
wrefresh(swin1);
|
||||
|
||||
set_colors(swin2, 9, COLOR_CYAN, COLOR_MAGENTA);
|
||||
werase(swin2);
|
||||
mvwaddstr(swin2, 0, 3, "Sub-window 2");
|
||||
wrefresh(swin2);
|
||||
|
||||
set_colors(swin3, 10, COLOR_YELLOW, COLOR_GREEN);
|
||||
werase(swin3);
|
||||
mvwaddstr(swin3, 0, 3, "Sub-window 3");
|
||||
wrefresh(swin3);
|
||||
|
||||
delwin(swin1);
|
||||
delwin(swin2);
|
||||
delwin(swin3);
|
||||
WaitForUser(win);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bounce(int n, int *dir, int len)
|
||||
{
|
||||
if (*dir > 0)
|
||||
++n;
|
||||
else
|
||||
--n;
|
||||
if (n <= 1 || n >= len - 2)
|
||||
*dir = *dir ? 0 : 1;
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bouncing balls
|
||||
*/
|
||||
static int
|
||||
BouncingBalls(WINDOW *win)
|
||||
{
|
||||
int w, h;
|
||||
int x1, y1, xd1, yd1;
|
||||
int x2, y2, xd2, yd2;
|
||||
int x3, y3, xd3, yd3;
|
||||
|
||||
getmaxyx(win, h, w);
|
||||
|
||||
x1 = 2 + rand() % (w - 4);
|
||||
y1 = 2 + rand() % (h - 4);
|
||||
x2 = 2 + rand() % (w - 4);
|
||||
y2 = 2 + rand() % (h - 4);
|
||||
x3 = 2 + rand() % (w - 4);
|
||||
y3 = 2 + rand() % (h - 4);
|
||||
|
||||
xd1 = 1;
|
||||
yd1 = 1;
|
||||
xd2 = 1;
|
||||
yd2 = 0;
|
||||
xd3 = 0;
|
||||
yd3 = 1;
|
||||
|
||||
nodelay(win, TRUE);
|
||||
|
||||
while (wgetch(win) == ERR) {
|
||||
x1 = bounce(x1, &xd1, w);
|
||||
y1 = bounce(y1, &yd1, h);
|
||||
x2 = bounce(x2, &xd2, w);
|
||||
y2 = bounce(y2, &yd2, h);
|
||||
x3 = bounce(x3, &xd3, w);
|
||||
y3 = bounce(y3, &yd3, h);
|
||||
|
||||
set_colors(win, 11, COLOR_RED, COLOR_BLUE);
|
||||
mvwaddch(win, y1, x1, 'O');
|
||||
|
||||
set_colors(win, 12, COLOR_BLUE, COLOR_RED);
|
||||
mvwaddch(win, y2, x2, '*');
|
||||
|
||||
set_colors(win, 13, COLOR_YELLOW, COLOR_WHITE);
|
||||
mvwaddch(win, y3, x3, '@');
|
||||
|
||||
wmove(win, 0, 0);
|
||||
wrefresh(win);
|
||||
delay_output(100);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Main driver
|
||||
*/
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
WINDOW *win;
|
||||
int w, x, y, i, j, k;
|
||||
char buffer[200];
|
||||
const char *message;
|
||||
int width, height;
|
||||
chtype save[80];
|
||||
chtype c;
|
||||
|
||||
initscr();
|
||||
if (has_colors())
|
||||
start_color();
|
||||
cbreak();
|
||||
curs_set(0);
|
||||
signal(SIGINT, trap);
|
||||
width = 48;
|
||||
height = 14; /* Create a drawing window */
|
||||
win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
|
||||
if (win == NULL) {
|
||||
endwin();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
set_colors(win, 1, COLOR_WHITE, COLOR_BLUE);
|
||||
werase(win);
|
||||
|
||||
set_colors(win, 2, COLOR_RED, COLOR_RED);
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
/* Do ramdom output of a character */
|
||||
use_colors(win, 1, A_NORMAL);
|
||||
c = 'a';
|
||||
for (i = 0; i < 5000; ++i) {
|
||||
x = rand() % (width - 2) + 1;
|
||||
y = rand() % (height - 2) + 1;
|
||||
mvwaddch(win, y, x, c);
|
||||
wrefresh(win);
|
||||
nodelay(win, TRUE);
|
||||
if (wgetch(win) != ERR)
|
||||
break;
|
||||
if (i == 2000) {
|
||||
c = 'b';
|
||||
set_colors(win, 3, COLOR_CYAN, COLOR_YELLOW);
|
||||
}
|
||||
}
|
||||
|
||||
SubWinTest(win);
|
||||
/* Erase and draw green window */
|
||||
set_colors(win, 4, COLOR_YELLOW, COLOR_GREEN);
|
||||
wbkgd(win, use_colors(win, 4, A_BOLD));
|
||||
werase(win);
|
||||
wrefresh(win);
|
||||
/* Draw RED bounding box */
|
||||
use_colors(win, 2, A_NORMAL);
|
||||
box(win, ' ', ' ');
|
||||
wrefresh(win);
|
||||
/* Display Australia map */
|
||||
use_colors(win, 4, A_BOLD);
|
||||
i = 0;
|
||||
while (*AusMap[i]) {
|
||||
mvwaddstr(win, i + 1, 8, AusMap[i]);
|
||||
wrefresh(win);
|
||||
delay_output(50);
|
||||
++i;
|
||||
}
|
||||
|
||||
set_colors(win, 5, COLOR_BLUE, COLOR_WHITE);
|
||||
use_colors(win, 5, A_BLINK);
|
||||
mvwaddstr(win, height - 2, 6, " PDCurses 2.1 for DOS, OS/2 and Unix");
|
||||
wrefresh(win);
|
||||
|
||||
/* Draw running messages */
|
||||
set_colors(win, 6, COLOR_YELLOW, COLOR_WHITE);
|
||||
message = messages[j = 0];
|
||||
i = 1;
|
||||
w = width - 2;
|
||||
strcpy(buffer, message);
|
||||
while (j < NMESSAGES) {
|
||||
while ((int) strlen(buffer) < w) {
|
||||
strcat(buffer, " ... ");
|
||||
strcat(buffer, messages[++j % NMESSAGES]);
|
||||
}
|
||||
|
||||
if (i < w)
|
||||
mvwaddnstr(win, height / 2, w - i, buffer, i);
|
||||
else
|
||||
mvwaddnstr(win, height / 2, 1, buffer, w);
|
||||
|
||||
wrefresh(win);
|
||||
nodelay(win, TRUE);
|
||||
if (wgetch(win) != ERR) {
|
||||
flushinp();
|
||||
break;
|
||||
}
|
||||
if (i++ >= w) {
|
||||
for (k = 0; (buffer[k] = buffer[k + 1]) != '\0'; k++) ;
|
||||
}
|
||||
delay_output(100);
|
||||
}
|
||||
|
||||
j = 0;
|
||||
/* Draw running As across in RED */
|
||||
set_colors(win, 7, COLOR_RED, COLOR_GREEN);
|
||||
for (i = 2; i < width - 4; ++i) {
|
||||
k = mvwinch(win, 4, i);
|
||||
if (k == ERR)
|
||||
break;
|
||||
save[j++] = c = k;
|
||||
c &= A_CHARTEXT;
|
||||
mvwaddch(win, 4, i, c);
|
||||
}
|
||||
wrefresh(win);
|
||||
|
||||
/* Put a message up wait for a key */
|
||||
i = height - 2;
|
||||
use_colors(win, 5, A_NORMAL);
|
||||
mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit ");
|
||||
wrefresh(win);
|
||||
|
||||
if (WaitForUser(win) == 1)
|
||||
break;
|
||||
|
||||
j = 0; /* Restore the old line */
|
||||
for (i = 2; i < width - 4; ++i)
|
||||
mvwaddch(win, 4, i, save[j++]);
|
||||
wrefresh(win);
|
||||
|
||||
BouncingBalls(win);
|
||||
/* Put a message up wait for a key */
|
||||
i = height - 2;
|
||||
use_colors(win, 5, A_NORMAL);
|
||||
mvwaddstr(win, i, 5, " Type a key to continue or 'Q' to quit ");
|
||||
wrefresh(win);
|
||||
if (WaitForUser(win) == 1)
|
||||
break;
|
||||
}
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,242 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2000-2001,2002 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 2000
|
||||
*
|
||||
* $Id: railroad.c,v 1.10 2002/04/06 20:45:22 tom Exp $
|
||||
*
|
||||
* A simple demo of the termcap interface.
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static char *wipeit;
|
||||
static char *moveit;
|
||||
static int length;
|
||||
static int height;
|
||||
|
||||
static char *finisC;
|
||||
static char *finisS;
|
||||
static char *finisU;
|
||||
|
||||
static char *startC;
|
||||
static char *startS;
|
||||
static char *startU;
|
||||
|
||||
static char *backup;
|
||||
|
||||
static bool interrupted = FALSE;
|
||||
|
||||
static int
|
||||
outc(int c)
|
||||
{
|
||||
if (interrupted) {
|
||||
char tmp = c;
|
||||
write(STDOUT_FILENO, &tmp, 1);
|
||||
} else {
|
||||
putc(c, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
PutChar(int ch)
|
||||
{
|
||||
putchar(ch);
|
||||
fflush(stdout);
|
||||
napms(moveit ? 10 : 50); /* not really termcap... */
|
||||
}
|
||||
|
||||
static void
|
||||
Backup(void)
|
||||
{
|
||||
tputs(backup != 0 ? backup : "\b", 1, outc);
|
||||
}
|
||||
|
||||
static void
|
||||
ShowCursor(int flag)
|
||||
{
|
||||
if (startC != 0 && finisC != 0) {
|
||||
tputs(flag ? startC : finisC, 1, outc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
StandOut(int flag)
|
||||
{
|
||||
if (startS != 0 && finisS != 0) {
|
||||
tputs(flag ? startS : finisS, 1, outc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Underline(int flag)
|
||||
{
|
||||
if (startU != 0 && finisU != 0) {
|
||||
tputs(flag ? startU : finisU, 1, outc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ShowSign(char *string)
|
||||
{
|
||||
char *base = string;
|
||||
int ch, first, last;
|
||||
|
||||
if (moveit != 0) {
|
||||
tputs(tgoto(moveit, 0, height - 1), 1, outc);
|
||||
tputs(wipeit, 1, outc);
|
||||
}
|
||||
|
||||
while (*string != 0) {
|
||||
ch = *string;
|
||||
if (ch != ' ') {
|
||||
if (moveit != 0) {
|
||||
for (first = length - 2; first >= (string - base); first--) {
|
||||
if (first < length - 1) {
|
||||
tputs(tgoto(moveit, first + 1, height - 1), 1, outc);
|
||||
PutChar(' ');
|
||||
}
|
||||
tputs(tgoto(moveit, first, height - 1), 1, outc);
|
||||
PutChar(ch);
|
||||
}
|
||||
} else {
|
||||
last = ch;
|
||||
if (isalpha(ch)) {
|
||||
first = isupper(ch) ? 'A' : 'a';
|
||||
} else if (isdigit(ch)) {
|
||||
first = '0';
|
||||
} else {
|
||||
first = ch;
|
||||
}
|
||||
if (first < last) {
|
||||
Underline(1);
|
||||
while (first < last) {
|
||||
PutChar(first);
|
||||
Backup();
|
||||
first++;
|
||||
}
|
||||
Underline(0);
|
||||
}
|
||||
}
|
||||
if (moveit != 0)
|
||||
Backup();
|
||||
}
|
||||
StandOut(1);
|
||||
PutChar(ch);
|
||||
StandOut(0);
|
||||
fflush(stdout);
|
||||
string++;
|
||||
}
|
||||
if (moveit != 0)
|
||||
tputs(wipeit, 1, outc);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
Underline(0);
|
||||
StandOut(0);
|
||||
ShowCursor(1);
|
||||
}
|
||||
|
||||
static void
|
||||
onsig(int n GCC_UNUSED)
|
||||
{
|
||||
interrupted = TRUE;
|
||||
cleanup();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
railroad(char **args)
|
||||
{
|
||||
NCURSES_CONST char *name = getenv("TERM");
|
||||
char buffer[1024];
|
||||
char area[1024], *ap = area;
|
||||
int j;
|
||||
|
||||
if (name == 0)
|
||||
name = "dumb";
|
||||
if (tgetent(buffer, name)) {
|
||||
|
||||
wipeit = tgetstr("ce", &ap);
|
||||
height = tgetnum("li");
|
||||
length = tgetnum("co");
|
||||
moveit = tgetstr("cm", &ap);
|
||||
|
||||
if (wipeit == 0
|
||||
|| moveit == 0
|
||||
|| height <= 0
|
||||
|| length <= 0) {
|
||||
wipeit = 0;
|
||||
moveit = 0;
|
||||
height = 0;
|
||||
length = 0;
|
||||
}
|
||||
|
||||
startS = tgetstr("so", &ap);
|
||||
finisS = tgetstr("se", &ap);
|
||||
|
||||
startU = tgetstr("us", &ap);
|
||||
finisU = tgetstr("ue", &ap);
|
||||
|
||||
backup = tgetstr("le", &ap);
|
||||
|
||||
startC = tgetstr("ve", &ap);
|
||||
finisC = tgetstr("vi", &ap);
|
||||
|
||||
ShowCursor(0);
|
||||
|
||||
for (j = SIGHUP; j <= SIGTERM; j++)
|
||||
if (signal(j, SIG_IGN) != SIG_IGN)
|
||||
signal(j, onsig);
|
||||
|
||||
while (*args) {
|
||||
ShowSign(*args++);
|
||||
}
|
||||
ShowCursor(1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc > 1) {
|
||||
railroad(argv + 1);
|
||||
} else {
|
||||
static char world[] = "Hello World";
|
||||
static char *hello[] =
|
||||
{world, 0};
|
||||
railroad(hello);
|
||||
}
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* $Id: rain.c,v 1.19 2002/04/06 20:45:22 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
/* rain 11/3/1980 EPS/CITHEP */
|
||||
|
||||
static float ranf(void);
|
||||
static void onsig(int sig);
|
||||
|
||||
static int
|
||||
next_j(int j)
|
||||
{
|
||||
if (j == 0)
|
||||
j = 4;
|
||||
else
|
||||
--j;
|
||||
if (has_colors()) {
|
||||
int z = (int) (3 * ranf());
|
||||
chtype color = COLOR_PAIR(z);
|
||||
if (z)
|
||||
color |= A_BOLD;
|
||||
attrset(color);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int x, y, j;
|
||||
static int xpos[5], ypos[5];
|
||||
float r;
|
||||
float c;
|
||||
|
||||
for (j = SIGHUP; j <= SIGTERM; j++)
|
||||
if (signal(j, SIG_IGN) != SIG_IGN)
|
||||
signal(j, onsig);
|
||||
|
||||
initscr();
|
||||
if (has_colors()) {
|
||||
int bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
bg = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_BLUE, bg);
|
||||
init_pair(2, COLOR_CYAN, bg);
|
||||
}
|
||||
nl();
|
||||
noecho();
|
||||
curs_set(0);
|
||||
timeout(0);
|
||||
|
||||
r = (float) (LINES - 4);
|
||||
c = (float) (COLS - 4);
|
||||
for (j = 5; --j >= 0;) {
|
||||
xpos[j] = (int) (c * ranf()) + 2;
|
||||
ypos[j] = (int) (r * ranf()) + 2;
|
||||
}
|
||||
|
||||
for (j = 0;;) {
|
||||
x = (int) (c * ranf()) + 2;
|
||||
y = (int) (r * ranf()) + 2;
|
||||
|
||||
mvaddch(y, x, '.');
|
||||
|
||||
mvaddch(ypos[j], xpos[j], 'o');
|
||||
|
||||
j = next_j(j);
|
||||
mvaddch(ypos[j], xpos[j], 'O');
|
||||
|
||||
j = next_j(j);
|
||||
mvaddch(ypos[j] - 1, xpos[j], '-');
|
||||
mvaddstr(ypos[j], xpos[j] - 1, "|.|");
|
||||
mvaddch(ypos[j] + 1, xpos[j], '-');
|
||||
|
||||
j = next_j(j);
|
||||
mvaddch(ypos[j] - 2, xpos[j], '-');
|
||||
mvaddstr(ypos[j] - 1, xpos[j] - 1, "/ \\");
|
||||
mvaddstr(ypos[j], xpos[j] - 2, "| O |");
|
||||
mvaddstr(ypos[j] + 1, xpos[j] - 1, "\\ /");
|
||||
mvaddch(ypos[j] + 2, xpos[j], '-');
|
||||
|
||||
j = next_j(j);
|
||||
mvaddch(ypos[j] - 2, xpos[j], ' ');
|
||||
mvaddstr(ypos[j] - 1, xpos[j] - 1, " ");
|
||||
mvaddstr(ypos[j], xpos[j] - 2, " ");
|
||||
mvaddstr(ypos[j] + 1, xpos[j] - 1, " ");
|
||||
mvaddch(ypos[j] + 2, xpos[j], ' ');
|
||||
|
||||
xpos[j] = x;
|
||||
ypos[j] = y;
|
||||
|
||||
switch (getch()) {
|
||||
case ('q'):
|
||||
case ('Q'):
|
||||
curs_set(1);
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
case 's':
|
||||
nodelay(stdscr, FALSE);
|
||||
break;
|
||||
case ' ':
|
||||
nodelay(stdscr, TRUE);
|
||||
break;
|
||||
#ifdef KEY_RESIZE
|
||||
case (KEY_RESIZE):
|
||||
r = (float) (LINES - 4);
|
||||
c = (float) (COLS - 4);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
napms(50);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
onsig(int n GCC_UNUSED)
|
||||
{
|
||||
curs_set(1);
|
||||
endwin();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static float
|
||||
ranf(void)
|
||||
{
|
||||
long r = (rand() & 077777);
|
||||
return ((float) r / 32768.);
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
#include "test.priv.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# if HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
tclock - analog/digital clock for curses.
|
||||
If it gives you joy, then
|
||||
(a) I'm glad
|
||||
(b) you need to get out more :-)
|
||||
|
||||
This program is copyright Howard Jones, September 1994
|
||||
(ha.jones@ic.ac.uk). It may be freely distributed as
|
||||
long as this copyright message remains intact, and any
|
||||
modifications are clearly marked as such. [In fact, if
|
||||
you modify it, I wouldn't mind the modifications back,
|
||||
especially if they add any nice features. A good one
|
||||
would be a precalc table for the 60 hand positions, so
|
||||
that the floating point stuff can be ditched. As I said,
|
||||
it was a 20 hackup minute job.]
|
||||
|
||||
COMING SOON: tfishtank. Be the envy of your mac-owning
|
||||
colleagues.
|
||||
*/
|
||||
|
||||
/* To compile: cc -o tclock tclock.c -lcurses -lm */
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.141592654
|
||||
#endif
|
||||
|
||||
#define sign(_x) (_x<0?-1:1)
|
||||
|
||||
#define ASPECT 2.2
|
||||
#define ROUND(value) ((int)((value) + 0.5))
|
||||
|
||||
#define A2X(angle,radius) ROUND(ASPECT * radius * sin(angle))
|
||||
#define A2Y(angle,radius) ROUND(radius * cos(angle))
|
||||
|
||||
/* Plot a point */
|
||||
static void
|
||||
plot(int x, int y, char col)
|
||||
{
|
||||
mvaddch(y, x, (chtype) col);
|
||||
}
|
||||
|
||||
/* Draw a diagonal(arbitrary) line using Bresenham's alogrithm. */
|
||||
static void
|
||||
dline(int pair, int from_x, int from_y, int x2, int y2, char ch)
|
||||
{
|
||||
int dx, dy;
|
||||
int ax, ay;
|
||||
int sx, sy;
|
||||
int x, y;
|
||||
int d;
|
||||
|
||||
if (has_colors())
|
||||
attrset(COLOR_PAIR(pair));
|
||||
|
||||
dx = x2 - from_x;
|
||||
dy = y2 - from_y;
|
||||
|
||||
ax = abs(dx * 2);
|
||||
ay = abs(dy * 2);
|
||||
|
||||
sx = sign(dx);
|
||||
sy = sign(dy);
|
||||
|
||||
x = from_x;
|
||||
y = from_y;
|
||||
|
||||
if (ax > ay) {
|
||||
d = ay - (ax / 2);
|
||||
|
||||
while (1) {
|
||||
plot(x, y, ch);
|
||||
if (x == x2)
|
||||
return;
|
||||
|
||||
if (d >= 0) {
|
||||
y += sy;
|
||||
d -= ax;
|
||||
}
|
||||
x += sx;
|
||||
d += ay;
|
||||
}
|
||||
} else {
|
||||
d = ax - (ay / 2);
|
||||
|
||||
while (1) {
|
||||
plot(x, y, ch);
|
||||
if (y == y2)
|
||||
return;
|
||||
|
||||
if (d >= 0) {
|
||||
x += sx;
|
||||
d -= ay;
|
||||
}
|
||||
y += sy;
|
||||
d += ax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
|
||||
{
|
||||
int i, cx, cy;
|
||||
double cr, mradius, hradius, mangle, hangle;
|
||||
double sangle, sradius, hours;
|
||||
int hdx, hdy;
|
||||
int mdx, mdy;
|
||||
int sdx, sdy;
|
||||
int ch;
|
||||
int lastbeep = -1;
|
||||
time_t tim;
|
||||
struct tm *t;
|
||||
char szChar[10];
|
||||
int my_bg = COLOR_BLACK;
|
||||
#if HAVE_GETTIMEOFDAY
|
||||
struct timeval current;
|
||||
double fraction = 0.0;
|
||||
#endif
|
||||
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
nodelay(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
my_bg = -1;
|
||||
#endif
|
||||
init_pair(1, COLOR_RED, my_bg);
|
||||
init_pair(2, COLOR_MAGENTA, my_bg);
|
||||
init_pair(3, COLOR_GREEN, my_bg);
|
||||
}
|
||||
#ifdef KEY_RESIZE
|
||||
keypad(stdscr, TRUE);
|
||||
restart:
|
||||
#endif
|
||||
cx = (COLS - 1) / 2; /* 39 */
|
||||
cy = LINES / 2; /* 12 */
|
||||
if (cx / ASPECT < cy)
|
||||
cr = cx / ASPECT;
|
||||
else
|
||||
cr = cy;
|
||||
sradius = (5 * cr) / 6; /* 10 */
|
||||
mradius = (3 * cr) / 4; /* 9 */
|
||||
hradius = cr / 2; /* 6 */
|
||||
|
||||
for (i = 0; i < 12; i++) {
|
||||
sangle = (i + 1) * (2.0 * PI) / 12.0;
|
||||
sdx = A2X(sangle, sradius);
|
||||
sdy = A2Y(sangle, sradius);
|
||||
sprintf(szChar, "%d", i + 1);
|
||||
|
||||
mvaddstr(cy - sdy, cx + sdx, szChar);
|
||||
}
|
||||
|
||||
mvaddstr(0, 0, "ASCII Clock by Howard Jones (ha.jones@ic.ac.uk),1994");
|
||||
|
||||
sradius = (4 * sradius) / 5;
|
||||
for (;;) {
|
||||
napms(100);
|
||||
|
||||
tim = time(0);
|
||||
t = localtime(&tim);
|
||||
|
||||
hours = (t->tm_hour + (t->tm_min / 60.0));
|
||||
if (hours > 12.0)
|
||||
hours -= 12.0;
|
||||
|
||||
mangle = ((t->tm_min + (t->tm_sec / 60.0)) * (2 * PI) / 60.0);
|
||||
mdx = A2X(mangle, mradius);
|
||||
mdy = A2Y(mangle, mradius);
|
||||
|
||||
hangle = ((hours) * (2.0 * PI) / 12.0);
|
||||
hdx = A2X(hangle, hradius);
|
||||
hdy = A2Y(hangle, hradius);
|
||||
|
||||
#if HAVE_GETTIMEOFDAY
|
||||
gettimeofday(¤t, 0);
|
||||
fraction = (current.tv_usec / 1.0e6);
|
||||
#endif
|
||||
sangle = ((t->tm_sec + fraction) * (2.0 * PI) / 60.0);
|
||||
sdx = A2X(sangle, sradius);
|
||||
sdy = A2Y(sangle, sradius);
|
||||
|
||||
dline(3, cx, cy, cx + mdx, cy - mdy, '#');
|
||||
|
||||
attrset(A_REVERSE);
|
||||
dline(2, cx, cy, cx + hdx, cy - hdy, '.');
|
||||
attroff(A_REVERSE);
|
||||
|
||||
if (has_colors())
|
||||
attrset(COLOR_PAIR(1));
|
||||
|
||||
dline(1, cx, cy, cx + sdx, cy - sdy, 'O');
|
||||
|
||||
if (has_colors())
|
||||
attrset(COLOR_PAIR(0));
|
||||
|
||||
mvaddstr(LINES - 2, 0, ctime(&tim));
|
||||
refresh();
|
||||
if ((t->tm_sec % 5) == 0
|
||||
&& t->tm_sec != lastbeep) {
|
||||
lastbeep = t->tm_sec;
|
||||
beep();
|
||||
}
|
||||
|
||||
if ((ch = getch()) != ERR) {
|
||||
#ifdef KEY_RESIZE
|
||||
if (ch == KEY_RESIZE) {
|
||||
flash();
|
||||
erase();
|
||||
wrefresh(curscr);
|
||||
goto restart;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
dline(0, cx, cy, cx + hdx, cy - hdy, ' ');
|
||||
dline(0, cx, cy, cx + mdx, cy - mdy, ' ');
|
||||
dline(0, cx, cy, cx + sdx, cy - sdy, ' ');
|
||||
|
||||
}
|
||||
|
||||
curs_set(1);
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,212 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 1998,2000 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"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, distribute with modifications, sublicense, and/or sell *
|
||||
* copies of the Software, and to permit persons to whom the Software is *
|
||||
* furnished to do so, subject to the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included *
|
||||
* in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
||||
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
* *
|
||||
* Except as contained in this notice, the name(s) of the above copyright *
|
||||
* holders shall not be used in advertising or otherwise to promote the *
|
||||
* sale, use or other dealings in this Software without prior written *
|
||||
* authorization. *
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Author: Thomas E. Dickey <dickey@clark.net> 1996 *
|
||||
****************************************************************************/
|
||||
/* $Id: test.priv.h,v 1.34 2002/04/06 23:32:15 tom Exp $ */
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <ncurses_cfg.h>
|
||||
#else
|
||||
#define HAVE_CURSES_VERSION 0
|
||||
#define HAVE_RESIZETERM 0
|
||||
#define HAVE_USE_DEFAULT_COLORS 0
|
||||
#define HAVE_WRESIZE 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CURSES_VERSION
|
||||
#define HAVE_CURSES_VERSION 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FORM_H
|
||||
#define HAVE_FORM_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBFORM
|
||||
#define HAVE_LIBFORM 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBMENU
|
||||
#define HAVE_LIBMENU 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBPANEL
|
||||
#define HAVE_LIBPANEL 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LOCALE_H
|
||||
#define HAVE_LOCALE_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MENU_H
|
||||
#define HAVE_MENU_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NAPMS
|
||||
#define HAVE_NAPMS 1
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NC_ALLOC_H
|
||||
#define HAVE_NC_ALLOC_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_PANEL_H
|
||||
#define HAVE_PANEL_H 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_WRESIZE
|
||||
#define HAVE_WRESIZE 0
|
||||
#endif
|
||||
|
||||
#ifndef NCURSES_NOMACROS
|
||||
#define NCURSES_NOMACROS 0
|
||||
#endif
|
||||
|
||||
#ifndef NEED_PTEM_H
|
||||
#define NEED_PTEM_H 0
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h> /* include before curses.h to work around glibc bug */
|
||||
|
||||
#include <curses.h>
|
||||
#include <term.h>
|
||||
|
||||
#if NCURSES_NOMACROS
|
||||
#include <nomacros.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
/* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
|
||||
* doesn't hurt.
|
||||
*/
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
#endif /* HAVE_GETOPT_H */
|
||||
|
||||
#ifndef GCC_NORETURN
|
||||
#define GCC_NORETURN /* nothing */
|
||||
#endif
|
||||
#ifndef GCC_UNUSED
|
||||
#define GCC_UNUSED /* nothing */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETNSTR
|
||||
#define getnstr(s,n) getstr(s)
|
||||
#endif
|
||||
|
||||
#ifndef USE_WIDEC_SUPPORT
|
||||
#if defined(_XOPEN_SOURCE_EXTENDED) && defined(WACS_ULCORNER)
|
||||
#define USE_WIDEC_SUPPORT 1
|
||||
#else
|
||||
#define USE_WIDEC_SUPPORT 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_TYPE_ATTR_T
|
||||
#if !USE_WIDEC_SUPPORT
|
||||
#define attr_t long
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NCURSES_CH_T
|
||||
#if !USE_WIDEC_SUPPORT
|
||||
#define NCURSES_CH_T chtype
|
||||
#else
|
||||
#define NCURSES_CH_T cchar_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CCHARW_MAX
|
||||
#define CCHARW_MAX 5
|
||||
#endif
|
||||
|
||||
#ifndef KEY_MIN
|
||||
#define KEY_MIN 256 /* not defined in Solaris 8 */
|
||||
#endif
|
||||
|
||||
#ifndef getcurx
|
||||
#define getcurx(win) ((win)?(win)->_curx:ERR)
|
||||
#define getcury(win) ((win)?(win)->_cury:ERR)
|
||||
#endif
|
||||
|
||||
#ifndef getbegx
|
||||
#define getbegx(win) ((win)?(win)->_begx:ERR)
|
||||
#define getbegy(win) ((win)?(win)->_begy:ERR)
|
||||
#endif
|
||||
|
||||
#ifndef getmaxx
|
||||
#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
|
||||
#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
|
||||
#endif
|
||||
|
||||
/* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
|
||||
* (which is incompatible with legacy usage, doesn't solve any problems).
|
||||
*/
|
||||
#define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
|
||||
#define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
|
||||
|
||||
#define UChar(c) ((unsigned char)(c))
|
||||
|
||||
#define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
|
||||
|
||||
#if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
|
||||
#include <nc_alloc.h>
|
||||
#else
|
||||
#define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
|
||||
#define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
|
||||
#endif
|
||||
|
||||
#ifndef ExitProgram
|
||||
#define ExitProgram(code) exit(code)
|
||||
#endif
|
||||
|
||||
#ifndef EXIT_SUCCESS
|
||||
#define EXIT_SUCCESS 0
|
||||
#endif
|
||||
#ifndef EXIT_FAILURE
|
||||
#define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
/* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
|
||||
* curses which doesn't have const parameters declared (so far) in the places
|
||||
* that XSI shows.
|
||||
*/
|
||||
#ifndef NCURSES_CONST
|
||||
#define NCURSES_CONST /* nothing */
|
||||
#endif
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This is an example written by Alexander V. Lukyanov <lav@yars.free.net>,
|
||||
* to demonstrate an inconsistency between ncurses and SVr4 curses.
|
||||
*
|
||||
* $Id: testaddch.c,v 1.4 2001/09/15 21:46:34 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
|
||||
static void
|
||||
attr_addstr(const char *s, chtype a)
|
||||
{
|
||||
while (*s)
|
||||
addch(((unsigned char) (*s++)) | a);
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc GCC_UNUSED,
|
||||
char *argv[]GCC_UNUSED)
|
||||
{
|
||||
unsigned i;
|
||||
chtype back, set, attr;
|
||||
|
||||
initscr();
|
||||
start_color();
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
||||
init_pair(3, COLOR_BLACK, COLOR_MAGENTA);
|
||||
init_pair(4, COLOR_BLACK, COLOR_GREEN);
|
||||
init_pair(5, COLOR_BLACK, COLOR_CYAN);
|
||||
init_pair(6, COLOR_BLACK, COLOR_YELLOW);
|
||||
init_pair(7, COLOR_BLACK, COLOR_WHITE);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
back = (i & 1) ? A_BOLD | 'B' : ' ';
|
||||
set = (i & 2) ? A_REVERSE : 0;
|
||||
attr = (i & 4) ? COLOR_PAIR(4) : 0;
|
||||
|
||||
bkgdset(back);
|
||||
attrset(set);
|
||||
|
||||
attr_addstr("Test string with spaces -> <-\n", attr);
|
||||
}
|
||||
addch('\n');
|
||||
for (i = 0; i < 8; i++) {
|
||||
back = (i & 1) ? A_BOLD | 'B' | COLOR_PAIR(1) : ' ';
|
||||
set = (i & 2) ? A_REVERSE | COLOR_PAIR(2) : 0;
|
||||
attr = (i & 4) ? COLOR_PAIR(4) : 0;
|
||||
|
||||
bkgdset(back);
|
||||
attrset(set);
|
||||
|
||||
attr_addstr("Test string with spaces -> <-\n", attr);
|
||||
}
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,694 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* This is a test program for the PDCurses screen package for IBM PC type
|
||||
* machines.
|
||||
*
|
||||
* This program was written by John Burnell (johnb@kea.am.dsir.govt.nz)
|
||||
* wrs(5/28/93) -- modified to be consistent (perform identically) with either
|
||||
* PDCurses or under Unix System V, R4
|
||||
*
|
||||
* $Id: testcurs.c,v 1.29 2002/06/01 16:17:52 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if defined(XCURSES)
|
||||
char *XCursesProgramName = "testcurs";
|
||||
#endif
|
||||
|
||||
static int initTest(WINDOW **);
|
||||
static void display_menu(int, int);
|
||||
static void inputTest(WINDOW *);
|
||||
static void introTest(WINDOW *);
|
||||
static void outputTest(WINDOW *);
|
||||
static void padTest(WINDOW *);
|
||||
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;
|
||||
|
||||
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 SIZEOF(command)
|
||||
|
||||
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;
|
||||
unsigned n;
|
||||
|
||||
#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, 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)
|
||||
{
|
||||
int y1 = getmaxy(win);
|
||||
int x1 = getmaxx(win);
|
||||
int y0 = y1 < 10 ? y1 : 10;
|
||||
int x0 = 1;
|
||||
long save;
|
||||
|
||||
save = mvwinch(win, y0, x1 - 1);
|
||||
|
||||
mvwaddstr(win, y0, x0, " Press any key to continue");
|
||||
wclrtoeol(win);
|
||||
getyx(win, y0, x0);
|
||||
|
||||
mvwaddch(win, y0, x1 - 1, save);
|
||||
|
||||
wmove(win, y0, x0);
|
||||
raw();
|
||||
wgetch(win);
|
||||
}
|
||||
|
||||
static int
|
||||
initTest(WINDOW **win)
|
||||
{
|
||||
#ifdef PDCDEBUG
|
||||
PDC_debug("initTest called\n");
|
||||
#endif
|
||||
#ifdef TRACE
|
||||
trace(TRACE_MAXIMUM);
|
||||
#endif
|
||||
initscr();
|
||||
#ifdef PDCDEBUG
|
||||
PDC_debug("after initscr()\n");
|
||||
#endif
|
||||
#ifdef A_COLOR
|
||||
if (has_colors())
|
||||
start_color();
|
||||
#endif
|
||||
width = 60;
|
||||
height = 13; /* Create a drawing window */
|
||||
*win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
|
||||
if (*win == NULL) {
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
introTest(WINDOW *win)
|
||||
{
|
||||
wmove(win, height / 2 - 5, width / 2);
|
||||
wvline(win, ACS_VLINE, 10);
|
||||
wmove(win, height / 2, width / 2 - 10);
|
||||
whline(win, ACS_HLINE, 20);
|
||||
Continue(win);
|
||||
|
||||
beep();
|
||||
werase(win);
|
||||
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
cbreak();
|
||||
mvwaddstr(win, 1, 1,
|
||||
"You should have rectangle in the middle of the screen");
|
||||
mvwaddstr(win, 2, 1, "You should have heard a beep");
|
||||
Continue(win);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
scrollTest(WINDOW *win)
|
||||
{
|
||||
int i;
|
||||
int half;
|
||||
int OldY;
|
||||
NCURSES_CONST char *Message = "The window will now scroll slowly";
|
||||
|
||||
wclear(win);
|
||||
OldY = getmaxy(win);
|
||||
half = OldY / 2;
|
||||
mvwprintw(win, OldY - 2, 1, Message);
|
||||
wrefresh(win);
|
||||
scrollok(win, TRUE);
|
||||
for (i = 1; i <= OldY; i++) {
|
||||
napms(600);
|
||||
scroll(win);
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
werase(win);
|
||||
for (i = 1; i < OldY; i++) {
|
||||
mvwprintw(win, i, 1, "Line %d", i);
|
||||
}
|
||||
mvwprintw(win, OldY - 2, 1, "The top of the window will scroll");
|
||||
wmove(win, 1, 1);
|
||||
wsetscrreg(win, 0, half - 1);
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
for (i = 1; i <= half; i++) {
|
||||
napms(600);
|
||||
scroll(win);
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
werase(win);
|
||||
for (i = 1; i < OldY; i++) {
|
||||
mvwprintw(win, i, 1, "Line %d", i);
|
||||
}
|
||||
mvwprintw(win, 1, 1, "The bottom of the window will scroll");
|
||||
wmove(win, OldY - 2, 1);
|
||||
wsetscrreg(win, half, --OldY);
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
for (i = half; i <= OldY; i++) {
|
||||
napms(600);
|
||||
wscrl(win, -1);
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
}
|
||||
wsetscrreg(win, 0, OldY);
|
||||
}
|
||||
|
||||
static void
|
||||
inputTest(WINDOW *win)
|
||||
{
|
||||
int answered;
|
||||
int repeat;
|
||||
int w, h, bx, by, sw, sh, i, c, num;
|
||||
char buffer[80];
|
||||
WINDOW *subWin;
|
||||
wclear(win);
|
||||
|
||||
getmaxyx(win, h, w);
|
||||
getbegyx(win, by, bx);
|
||||
sw = w / 3;
|
||||
sh = h / 3;
|
||||
if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
|
||||
return;
|
||||
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
init_pair(2, COLOR_WHITE, COLOR_RED);
|
||||
wbkgd(subWin, COLOR_PAIR(2) | A_BOLD);
|
||||
} else
|
||||
wbkgd(subWin, A_BOLD);
|
||||
#else
|
||||
wbkgd(subWin, A_BOLD);
|
||||
#endif
|
||||
box(subWin, ACS_VLINE, ACS_HLINE);
|
||||
wrefresh(win);
|
||||
|
||||
nocbreak();
|
||||
mvwaddstr(win, 2, 1, "Press some keys for 5 seconds");
|
||||
mvwaddstr(win, 1, 1, "Pressing ^C should do nothing");
|
||||
wrefresh(win);
|
||||
|
||||
werase(subWin);
|
||||
box(subWin, ACS_VLINE, ACS_HLINE);
|
||||
for (i = 0; i < 5; i++) {
|
||||
mvwprintw(subWin, 1, 1, "Time = %d", i);
|
||||
wrefresh(subWin);
|
||||
napms(1000);
|
||||
flushinp();
|
||||
}
|
||||
|
||||
delwin(subWin);
|
||||
werase(win);
|
||||
flash();
|
||||
wrefresh(win);
|
||||
napms(500);
|
||||
|
||||
mvwaddstr(win, 2, 1, "Press a key, followed by ENTER");
|
||||
wmove(win, 9, 10);
|
||||
wrefresh(win);
|
||||
echo();
|
||||
noraw();
|
||||
wgetch(win);
|
||||
flushinp();
|
||||
|
||||
wmove(win, 9, 10);
|
||||
wdelch(win);
|
||||
mvwaddstr(win, 4, 1, "The character should now have been deleted");
|
||||
Continue(win);
|
||||
|
||||
wclear(win);
|
||||
mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
|
||||
mvwaddstr(win, 2, 1, "Press spacebar to finish");
|
||||
wrefresh(win);
|
||||
keypad(win, TRUE);
|
||||
raw();
|
||||
noecho();
|
||||
typeahead(-1);
|
||||
#if defined(PDCURSES)
|
||||
mouse_set(ALL_MOUSE_EVENTS);
|
||||
#endif
|
||||
for (;;) {
|
||||
wmove(win, 3, 5);
|
||||
c = wgetch(win);
|
||||
wclrtobot(win);
|
||||
if (c >= KEY_MIN)
|
||||
wprintw(win, "Key Pressed: %s", keyname(c));
|
||||
else if (isprint(c))
|
||||
wprintw(win, "Key Pressed: %c", c);
|
||||
else
|
||||
wprintw(win, "Key Pressed: %s", unctrl(c));
|
||||
#if defined(PDCURSES)
|
||||
if (c == KEY_MOUSE) {
|
||||
int button = 0;
|
||||
request_mouse_pos();
|
||||
if (BUTTON_CHANGED(1))
|
||||
button = 1;
|
||||
else if (BUTTON_CHANGED(2))
|
||||
button = 2;
|
||||
else if (BUTTON_CHANGED(3))
|
||||
button = 3;
|
||||
else
|
||||
button = 0;
|
||||
wmove(win, 4, 18);
|
||||
wprintw(win, "Button %d: ", button);
|
||||
if (MOUSE_MOVED)
|
||||
wprintw(win, "moved: ");
|
||||
else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
|
||||
wprintw(win, "pressed: ");
|
||||
else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
|
||||
wprintw(win, "double: ");
|
||||
else
|
||||
wprintw(win, "released: ");
|
||||
wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
|
||||
}
|
||||
#endif
|
||||
wrefresh(win);
|
||||
if (c == ' ')
|
||||
break;
|
||||
}
|
||||
#if 0
|
||||
nodelay(win, TRUE);
|
||||
wgetch(win);
|
||||
nodelay(win, FALSE);
|
||||
#endif
|
||||
#if defined(PDCURSES)
|
||||
mouse_set(0L);
|
||||
#endif
|
||||
refresh();
|
||||
|
||||
repeat = 0;
|
||||
do {
|
||||
static const char *fmt[] = {
|
||||
"%d %10s",
|
||||
"%d %[a-zA-Z]s",
|
||||
"%d %[][a-zA-Z]s",
|
||||
"%d %[^0-9]"
|
||||
};
|
||||
const char *format = fmt[repeat % SIZEOF(fmt)];
|
||||
|
||||
wclear(win);
|
||||
mvwaddstr(win, 3, 2, "The window should have moved");
|
||||
mvwaddstr(win, 4, 2,
|
||||
"This text should have appeared without you pressing a key");
|
||||
mvwprintw(win, 6, 2,
|
||||
"Scanning with format \"%s\"", format);
|
||||
mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
|
||||
erase();
|
||||
refresh();
|
||||
wrefresh(win);
|
||||
echo();
|
||||
noraw();
|
||||
num = 0;
|
||||
*buffer = 0;
|
||||
answered = mvwscanw(win, 7, 6, format, &num, buffer);
|
||||
mvwprintw(win, 8, 6,
|
||||
"String: %s Number: %d (%d values read)",
|
||||
buffer, num, answered);
|
||||
Continue(win);
|
||||
++repeat;
|
||||
} while (answered > 0);
|
||||
}
|
||||
|
||||
static void
|
||||
outputTest(WINDOW *win)
|
||||
{
|
||||
WINDOW *win1;
|
||||
char Buffer[80];
|
||||
chtype ch;
|
||||
int by, bx;
|
||||
|
||||
nl();
|
||||
wclear(win);
|
||||
mvwaddstr(win, 1, 1,
|
||||
"You should now have a screen in the upper left corner, and this text should have wrapped");
|
||||
mvwin(win, 2, 1);
|
||||
waddstr(win, "\nThis text should be down\n");
|
||||
waddstr(win, "and broken into two here ^");
|
||||
Continue(win);
|
||||
|
||||
wclear(win);
|
||||
wattron(win, A_BOLD);
|
||||
mvwaddstr(win, 1, 1, "A new window will appear with this text in it");
|
||||
mvwaddstr(win, 8, 1, "Press any key to continue");
|
||||
wrefresh(win);
|
||||
wgetch(win);
|
||||
|
||||
getbegyx(win, by, bx);
|
||||
|
||||
if (LINES < 24 || COLS < 75) {
|
||||
mvwaddstr(win, 5, 1,
|
||||
"Some tests have been skipped as they require a");
|
||||
mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
|
||||
Continue(win);
|
||||
} else {
|
||||
win1 = newwin(10, 50, 14, 25);
|
||||
if (win1 == NULL) {
|
||||
endwin();
|
||||
return;
|
||||
}
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
init_pair(3, COLOR_BLUE, COLOR_WHITE);
|
||||
wbkgd(win1, COLOR_PAIR(3));
|
||||
} else
|
||||
wbkgd(win1, A_NORMAL);
|
||||
#else
|
||||
wbkgd(win1, A_NORMAL);
|
||||
#endif
|
||||
wclear(win1);
|
||||
mvwaddstr(win1, 5, 1,
|
||||
"This text should appear; using overlay option");
|
||||
copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
|
||||
|
||||
#if defined(PDCURSES) && !defined(XCURSES)
|
||||
box(win1, 0xb3, 0xc4);
|
||||
#else
|
||||
box(win1, ACS_VLINE, ACS_HLINE);
|
||||
#endif
|
||||
wmove(win1, 8, 26);
|
||||
wrefresh(win1);
|
||||
wgetch(win1);
|
||||
|
||||
wclear(win1);
|
||||
wattron(win1, A_BLINK);
|
||||
mvwaddstr(win1, 4, 1,
|
||||
"This blinking text should appear in only the second window");
|
||||
wattroff(win1, A_BLINK);
|
||||
mvwin(win1, by, bx);
|
||||
overlay(win, win1);
|
||||
mvwin(win1, 14, 25);
|
||||
wmove(win1, 8, 26);
|
||||
wrefresh(win1);
|
||||
wgetch(win1);
|
||||
delwin(win1);
|
||||
}
|
||||
|
||||
clear();
|
||||
wclear(win);
|
||||
wrefresh(win);
|
||||
mvwaddstr(win, 6, 2, "This line shouldn't appear");
|
||||
mvwaddstr(win, 4, 2, "Only half of the next line is visible");
|
||||
mvwaddstr(win, 5, 2, "Only half of the next line is visible");
|
||||
wmove(win, 6, 1);
|
||||
wclrtobot(win);
|
||||
wmove(win, 5, 20);
|
||||
wclrtoeol(win);
|
||||
mvwaddstr(win, 8, 2, "This line also shouldn't appear");
|
||||
wmove(win, 8, 1);
|
||||
wdeleteln(win);
|
||||
Continue(win);
|
||||
|
||||
wmove(win, 5, 9);
|
||||
ch = winch(win);
|
||||
|
||||
wclear(win);
|
||||
wmove(win, 6, 2);
|
||||
waddstr(win, "The next char should be l: ");
|
||||
winsch(win, ch);
|
||||
Continue(win);
|
||||
|
||||
mvwinsstr(win, 6, 2, "A1B2C3D4E5");
|
||||
Continue(win);
|
||||
|
||||
wmove(win, 5, 1);
|
||||
winsertln(win);
|
||||
mvwaddstr(win, 5, 2, "The lines below should have moved down");
|
||||
Continue(win);
|
||||
|
||||
wclear(win);
|
||||
wmove(win, 2, 2);
|
||||
wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
|
||||
"is it");
|
||||
mvwaddstr(win, 10, 1, "Enter a string: ");
|
||||
wrefresh(win);
|
||||
noraw();
|
||||
echo();
|
||||
*Buffer = 0;
|
||||
wscanw(win, "%s", Buffer);
|
||||
|
||||
printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
|
||||
mvaddstr(10, 1, "Enter a string: ");
|
||||
*Buffer = 0;
|
||||
scanw("%s", Buffer);
|
||||
|
||||
if (tigetstr("cvvis") != 0) {
|
||||
wclear(win);
|
||||
curs_set(2);
|
||||
mvwaddstr(win, 1, 1, "The cursor should appear as a block (visible)");
|
||||
Continue(win);
|
||||
}
|
||||
|
||||
if (tigetstr("civis") != 0) {
|
||||
wclear(win);
|
||||
curs_set(0);
|
||||
mvwaddstr(win, 1, 1,
|
||||
"The cursor should have disappeared (invisible)");
|
||||
Continue(win);
|
||||
}
|
||||
|
||||
if (tigetstr("cnorm") != 0) {
|
||||
wclear(win);
|
||||
curs_set(1);
|
||||
mvwaddstr(win, 1, 1, "The cursor should be an underline (normal)");
|
||||
Continue(win);
|
||||
}
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
wclear(win);
|
||||
mvwaddstr(win, 1, 1, "Colors should change after you press a key");
|
||||
Continue(win);
|
||||
init_pair(1, COLOR_RED, COLOR_WHITE);
|
||||
wrefresh(win);
|
||||
}
|
||||
#endif
|
||||
|
||||
werase(win);
|
||||
mvwaddstr(win, 1, 1, "Information About Your Terminal");
|
||||
mvwaddstr(win, 3, 1, termname());
|
||||
mvwaddstr(win, 4, 1, longname());
|
||||
if (termattrs() & A_BLINK)
|
||||
mvwaddstr(win, 5, 1, "This terminal supports blinking.");
|
||||
else
|
||||
mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");
|
||||
|
||||
mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
|
||||
wrefresh(win);
|
||||
|
||||
mvwinnstr(win, 7, 5, Buffer, 18);
|
||||
mvaddstr(LINES - 2, 10, Buffer);
|
||||
refresh();
|
||||
Continue(win);
|
||||
}
|
||||
|
||||
#if defined(PDCURSES) && !defined(XCURSES)
|
||||
static void
|
||||
resizeTest(WINDOW *dummy GCC_UNUSED)
|
||||
{
|
||||
WINDOW *win1;
|
||||
|
||||
savetty();
|
||||
|
||||
clear();
|
||||
refresh();
|
||||
# if defined(OS2)
|
||||
resize_term(50, 120);
|
||||
# else
|
||||
resize_term(50, 80);
|
||||
# endif
|
||||
|
||||
win1 = newwin(10, 50, 14, 25);
|
||||
if (win1 == NULL) {
|
||||
endwin();
|
||||
return;
|
||||
}
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
init_pair(3, COLOR_BLUE, COLOR_WHITE);
|
||||
wattrset(win1, COLOR_PAIR(3));
|
||||
}
|
||||
#endif
|
||||
wclear(win1);
|
||||
|
||||
mvwaddstr(win1, 1, 1, "The screen may now have 50 lines");
|
||||
Continue(win1);
|
||||
|
||||
wclear(win1);
|
||||
resetty();
|
||||
|
||||
mvwaddstr(win1, 1, 1, "The screen should now be reset");
|
||||
Continue(win1);
|
||||
|
||||
delwin(win1);
|
||||
|
||||
clear();
|
||||
refresh();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
padTest(WINDOW *dummy GCC_UNUSED)
|
||||
{
|
||||
WINDOW *pad, *spad;
|
||||
|
||||
pad = newpad(50, 100);
|
||||
wattron(pad, A_REVERSE);
|
||||
mvwaddstr(pad, 5, 2, "This is a new pad");
|
||||
wattrset(pad, A_NORMAL);
|
||||
mvwaddstr(pad, 8, 0,
|
||||
"The end of this line should be truncated here:except now");
|
||||
mvwaddstr(pad, 11, 1, "This line should not appear.It will now");
|
||||
wmove(pad, 10, 1);
|
||||
wclrtoeol(pad);
|
||||
mvwaddstr(pad, 10, 1, " Press any key to continue");
|
||||
prefresh(pad, 0, 0, 0, 0, 10, 45);
|
||||
keypad(pad, TRUE);
|
||||
raw();
|
||||
wgetch(pad);
|
||||
|
||||
spad = subpad(pad, 12, 25, 6, 52);
|
||||
mvwaddstr(spad, 2, 2, "This is a new subpad");
|
||||
box(spad, 0, 0);
|
||||
prefresh(pad, 0, 0, 0, 0, 15, 75);
|
||||
keypad(pad, TRUE);
|
||||
raw();
|
||||
wgetch(pad);
|
||||
|
||||
mvwaddstr(pad, 35, 2, "This is displayed at line 35 in the pad");
|
||||
mvwaddstr(pad, 40, 1, " Press any key to continue");
|
||||
prefresh(pad, 30, 0, 0, 0, 10, 45);
|
||||
keypad(pad, TRUE);
|
||||
raw();
|
||||
wgetch(pad);
|
||||
|
||||
delwin(pad);
|
||||
}
|
||||
|
||||
static void
|
||||
display_menu(int old_option, int new_option)
|
||||
{
|
||||
register size_t i;
|
||||
|
||||
attrset(A_NORMAL);
|
||||
mvaddstr(3, 20, "PDCurses Test Program");
|
||||
|
||||
for (i = 0; i < MAX_OPTIONS; i++)
|
||||
mvaddstr(5 + i, 25, command[i].text);
|
||||
if (old_option != (-1))
|
||||
mvaddstr(5 + old_option, 25, command[old_option].text);
|
||||
attrset(A_REVERSE);
|
||||
mvaddstr(5 + new_option, 25, command[new_option].text);
|
||||
attrset(A_NORMAL);
|
||||
mvaddstr(13, 3,
|
||||
"Use Up and Down Arrows to select - Enter to run - Q to quit");
|
||||
refresh();
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/* gleaned from a web-search, shows a bug combining scanw and implicit scroll.
|
||||
* Date: 1997/03/17
|
||||
* From: bayern@morpheus.cis.yale.edu
|
||||
*
|
||||
* $Id: testscanw.c,v 1.8 2001/09/15 21:41:45 tom Exp $
|
||||
*/
|
||||
#include <test.priv.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
long badanswer = 1;
|
||||
long *response = &badanswer;
|
||||
|
||||
initscr();
|
||||
scrollok(stdscr, TRUE);
|
||||
idlok(stdscr, TRUE);
|
||||
echo();
|
||||
|
||||
#if 0
|
||||
trace(TRACE_UPDATE | TRACE_CALLS);
|
||||
#endif
|
||||
while (argc > 1) {
|
||||
if (isdigit(UChar(*argv[1])))
|
||||
move(atoi(argv[1]), 0);
|
||||
else if (!strcmp(argv[1], "-k"))
|
||||
keypad(stdscr, TRUE);
|
||||
argc--, argv++;
|
||||
}
|
||||
|
||||
while (badanswer) {
|
||||
printw("Enter a number (0 to quit):\n");
|
||||
printw("--> ");
|
||||
scanw("%20ld", response); /* yes, it's a pointer */
|
||||
}
|
||||
endwin();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# tracemunch -- compactify ncurses trace logs
|
||||
#
|
||||
# The error logs produced by ncurses with tracing enabled can be very tedious
|
||||
# to wade through. This script helps by compacting runs of log lines that
|
||||
# can be conveniently expressed as higher-level operations.
|
||||
#
|
||||
# ($Id: tracemunch,v 1.2 1995/10/06 15:02:37 esr Exp $)
|
||||
|
||||
$putattr="PutAttrChar\\('(.)' = 0x.., {A_NORMAL}\\) at \\(([0-9]+), ([0-9]+)\\)";
|
||||
$waddnstr="waddnstr\\(0x([0-9a-f]+),\"([^\"]+)\",[0-9]+\\) called {A_NORMAL}";
|
||||
|
||||
sub transaddr
|
||||
{
|
||||
$arg = $_[0];
|
||||
|
||||
$arg =~ s/$curscr/curscr/ if ($curscr);
|
||||
$arg =~ s/$newscr/newscr/ if ($newscr);
|
||||
$arg =~ s/$stdscr/stdscr/ if ($stdscr);
|
||||
|
||||
return $arg;
|
||||
}
|
||||
|
||||
while (<STDIN>)
|
||||
{
|
||||
CLASSIFY: {
|
||||
# Transform window pointer addresses so it's easier to compare logs
|
||||
$awaiting = "curscr" if ($_ =~ /creating curscr/);
|
||||
$awaiting = "newscr" if ($_ =~ /creating newscr/);
|
||||
$awaiting = "stdscr" if ($_ =~ /creating stdscr/);
|
||||
if ($awaiting && $_ =~ /newwin: returned window is 0x([0-9a-f]+)/)
|
||||
{
|
||||
$curscr = "0x$1" if ($awaiting eq "curscr");
|
||||
$newscr = "0x$1" if ($awaiting eq "newscr");
|
||||
$stdscr = "0x$1" if ($awaiting eq "stdscr");
|
||||
$awaiting = "";
|
||||
}
|
||||
|
||||
# Compactify runs of PutAttrChar calls (TR_CHARPUT)
|
||||
if ($_ =~ /$putattr/)
|
||||
{
|
||||
$putattr_chars = $1;
|
||||
$starty = $2;
|
||||
$startx = $3;
|
||||
while (<STDIN>)
|
||||
{
|
||||
if ($_ =~ /$putattr/) {
|
||||
$putattr_chars .= $1;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
print "RUN of PutAttrChar()s: \"$putattr_chars\" from ${starty}, ${startx}\n";
|
||||
redo CLASSIFY;
|
||||
}
|
||||
|
||||
# Compactify runs of waddnstr calls (TR_CALLS)
|
||||
if ($_ =~ /$waddnstr/)
|
||||
{
|
||||
$waddnstr_chars = $2;
|
||||
$winaddr = $1;
|
||||
while (<STDIN>)
|
||||
{
|
||||
if ($_ =~ /$waddnstr/ && $1 eq $winaddr) {
|
||||
$waddnstr_chars .= $2;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
$winaddstr = &transaddr($winaddr);
|
||||
print "RUN of waddnstr()s: $winaddr, \"$waddnstr_chars\"\n";
|
||||
redo CLASSIFY;
|
||||
}
|
||||
|
||||
# More transformations can go here
|
||||
|
||||
# Repeated runs of anything
|
||||
$anyline = &transaddr($_);
|
||||
$repeatcount = 1;
|
||||
while (<STDIN>) {
|
||||
if (&transaddr($_) eq $anyline) {
|
||||
$repeatcount++;
|
||||
} else {
|
||||
last;
|
||||
}
|
||||
}
|
||||
if ($repeatcount > 1) {
|
||||
print "${repeatcount} REPEATS OF $anyline";
|
||||
} else {
|
||||
print $anyline
|
||||
}
|
||||
redo CLASSIFY if $_;
|
||||
|
||||
} # :CLASSIFY
|
||||
}
|
||||
|
||||
# tracemunch ends here
|
@ -1,513 +0,0 @@
|
||||
/*
|
||||
* view.c -- a silly little viewer program
|
||||
*
|
||||
* written by Eric S. Raymond <esr@snark.thyrsus.com> December 1994
|
||||
* to test the scrolling code in ncurses.
|
||||
*
|
||||
* modified by Thomas Dickey <dickey@clark.net> July 1995 to demonstrate
|
||||
* the use of 'resizeterm()', and May 2000 to illustrate wide-character
|
||||
* handling.
|
||||
*
|
||||
* Takes a filename argument. It's a simple file-viewer with various
|
||||
* scroll-up and scroll-down commands.
|
||||
*
|
||||
* n -- scroll one line forward
|
||||
* p -- scroll one line back
|
||||
*
|
||||
* Either command accepts a numeric prefix interpreted as a repeat count.
|
||||
* Thus, typing `5n' should scroll forward 5 lines in the file.
|
||||
*
|
||||
* The way you can tell this is working OK is that, in the trace file,
|
||||
* there should be one scroll operation plus a small number of line
|
||||
* updates, as opposed to a whole-page update. This means the physical
|
||||
* scroll operation worked, and the refresh() code only had to do a
|
||||
* partial repaint.
|
||||
*
|
||||
* $Id: view.c,v 1.52 2002/04/27 22:37:39 tom Exp $
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
#if HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#else
|
||||
# include <sgtty.h>
|
||||
#endif
|
||||
|
||||
#if !defined(sun) || !HAVE_TERMIOS_H
|
||||
# if HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define my_pair 1
|
||||
|
||||
/* This is needed to compile 'struct winsize' */
|
||||
#if NEED_PTEM_H
|
||||
#include <sys/stream.h>
|
||||
#include <sys/ptem.h>
|
||||
#endif
|
||||
|
||||
static RETSIGTYPE finish(int sig) GCC_NORETURN;
|
||||
static void show_all(const char *tag);
|
||||
|
||||
#if defined(SIGWINCH) && defined(TIOCGWINSZ) && HAVE_RESIZETERM
|
||||
#define CAN_RESIZE 1
|
||||
#else
|
||||
#define CAN_RESIZE 0
|
||||
#endif
|
||||
|
||||
#if CAN_RESIZE
|
||||
static RETSIGTYPE adjust(int sig);
|
||||
static int interrupted;
|
||||
#endif
|
||||
|
||||
static bool waiting = FALSE;
|
||||
static int shift = 0;
|
||||
static bool try_color = FALSE;
|
||||
|
||||
static char *fname;
|
||||
static NCURSES_CH_T **my_lines;
|
||||
static NCURSES_CH_T **lptr;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
"Usage: view [options] file"
|
||||
,""
|
||||
,"Options:"
|
||||
," -c use color if terminal supports it"
|
||||
," -i ignore INT, QUIT, TERM signals"
|
||||
," -n NUM specify maximum number of lines (default 1000)"
|
||||
#if defined(KEY_RESIZE)
|
||||
," -r use old-style sigwinch handler rather than KEY_RESIZE"
|
||||
#endif
|
||||
#ifdef TRACE
|
||||
," -t trace screen updates"
|
||||
," -T NUM specify trace mask"
|
||||
#endif
|
||||
};
|
||||
size_t n;
|
||||
for (n = 0; n < SIZEOF(msg); n++)
|
||||
fprintf(stderr, "%s\n", msg[n]);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int
|
||||
ch_len(NCURSES_CH_T * src)
|
||||
{
|
||||
int result = 0;
|
||||
#if USE_WIDEC_SUPPORT
|
||||
#endif
|
||||
|
||||
#if USE_WIDEC_SUPPORT
|
||||
while (getcchar(src++, NULL, NULL, NULL, NULL) > 0)
|
||||
result++;
|
||||
#else
|
||||
while (*src++)
|
||||
result++;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a string into an array of chtype's. If UTF-8 mode is
|
||||
* active, translate the string accordingly.
|
||||
*/
|
||||
static NCURSES_CH_T *
|
||||
ch_dup(char *src)
|
||||
{
|
||||
unsigned len = strlen(src);
|
||||
NCURSES_CH_T *dst = typeMalloc(NCURSES_CH_T, len + 1);
|
||||
unsigned j, k;
|
||||
#if USE_WIDEC_SUPPORT
|
||||
wchar_t wstr[CCHARW_MAX + 1];
|
||||
wchar_t wch;
|
||||
int l = 0;
|
||||
mbstate_t state;
|
||||
size_t rc;
|
||||
int width;
|
||||
#endif
|
||||
|
||||
#if USE_WIDEC_SUPPORT
|
||||
memset(&state, 0, sizeof(state));
|
||||
#endif
|
||||
for (j = k = 0; j < len; j++) {
|
||||
#if USE_WIDEC_SUPPORT
|
||||
rc = mbrtowc(&wch, src + j, len - j, &state);
|
||||
if (rc == (size_t) -1 || rc == (size_t) -2)
|
||||
break;
|
||||
j += rc - 1;
|
||||
if ((width = wcwidth(wch)) < 0)
|
||||
break;
|
||||
if ((width > 0 && l > 0) || l == CCHARW_MAX) {
|
||||
wstr[l] = L'\0';
|
||||
l = 0;
|
||||
if (setcchar(dst + k, wstr, 0, 0, NULL) != OK)
|
||||
break;
|
||||
++k;
|
||||
}
|
||||
if (width == 0 && l == 0)
|
||||
wstr[l++] = L' ';
|
||||
wstr[l++] = wch;
|
||||
#else
|
||||
dst[k++] = src[j];
|
||||
#endif
|
||||
}
|
||||
#if USE_WIDEC_SUPPORT
|
||||
if (l > 0) {
|
||||
wstr[l] = L'\0';
|
||||
if (setcchar(dst + k, wstr, 0, 0, NULL) == OK)
|
||||
++k;
|
||||
}
|
||||
setcchar(dst + k, L"", 0, 0, NULL);
|
||||
#else
|
||||
dst[k] = 0;
|
||||
#endif
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int MAXLINES = 1000;
|
||||
FILE *fp;
|
||||
char buf[BUFSIZ];
|
||||
int i;
|
||||
int my_delay = 0;
|
||||
NCURSES_CH_T **olptr;
|
||||
int length = 0;
|
||||
int value = 0;
|
||||
bool done = FALSE;
|
||||
bool got_number = FALSE;
|
||||
#if CAN_RESIZE
|
||||
bool nonposix_resize = FALSE;
|
||||
#endif
|
||||
const char *my_label = "Input";
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
#ifndef NCURSES_VERSION
|
||||
/*
|
||||
* We know ncurses will catch SIGINT if we don't establish our own handler.
|
||||
* Other versions of curses may/may not catch it.
|
||||
*/
|
||||
(void) signal(SIGINT, finish); /* arrange interrupts to terminate */
|
||||
#endif
|
||||
|
||||
while ((i = getopt(argc, argv, "cin:rtT:")) != EOF) {
|
||||
switch (i) {
|
||||
case 'c':
|
||||
try_color = TRUE;
|
||||
break;
|
||||
case 'i':
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
break;
|
||||
case 'n':
|
||||
if ((MAXLINES = atoi(optarg)) < 1)
|
||||
usage();
|
||||
break;
|
||||
#if CAN_RESIZE
|
||||
case 'r':
|
||||
nonposix_resize = TRUE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef TRACE
|
||||
case 'T':
|
||||
trace(atoi(optarg));
|
||||
break;
|
||||
case 't':
|
||||
trace(TRACE_CALLS);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (optind + 1 != argc)
|
||||
usage();
|
||||
|
||||
if ((my_lines = typeMalloc(NCURSES_CH_T *, MAXLINES + 2)) == 0)
|
||||
usage();
|
||||
|
||||
fname = argv[optind];
|
||||
if ((fp = fopen(fname, "r")) == 0) {
|
||||
perror(fname);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
#if CAN_RESIZE
|
||||
if (nonposix_resize)
|
||||
(void) signal(SIGWINCH, adjust); /* arrange interrupts to resize */
|
||||
#endif
|
||||
|
||||
/* slurp the file */
|
||||
for (lptr = &my_lines[0]; (lptr - my_lines) < MAXLINES; lptr++) {
|
||||
char temp[BUFSIZ], *s, *d;
|
||||
int col;
|
||||
|
||||
if (fgets(buf, sizeof(buf), fp) == 0)
|
||||
break;
|
||||
|
||||
/* convert tabs so that shift will work properly */
|
||||
for (s = buf, d = temp, col = 0; (*d = *s) != '\0'; s++) {
|
||||
if (*d == '\n') {
|
||||
*d = '\0';
|
||||
break;
|
||||
} else if (*d == '\t') {
|
||||
col = (col | 7) + 1;
|
||||
while ((d - temp) != col)
|
||||
*d++ = ' ';
|
||||
} else
|
||||
#if USE_WIDEC_SUPPORT
|
||||
col++, d++;
|
||||
#else
|
||||
if (isprint(UChar(*d))) {
|
||||
col++;
|
||||
d++;
|
||||
} else {
|
||||
sprintf(d, "\\%03o", UChar(*s));
|
||||
d += strlen(d);
|
||||
col = (d - temp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*lptr = ch_dup(temp);
|
||||
}
|
||||
(void) fclose(fp);
|
||||
length = lptr - my_lines;
|
||||
|
||||
(void) initscr(); /* initialize the curses library */
|
||||
keypad(stdscr, TRUE); /* enable keyboard mapping */
|
||||
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
|
||||
(void) cbreak(); /* take input chars one at a time, no wait for \n */
|
||||
(void) noecho(); /* don't echo input */
|
||||
nodelay(stdscr, TRUE);
|
||||
idlok(stdscr, TRUE); /* allow use of insert/delete line */
|
||||
|
||||
if (try_color) {
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
init_pair(my_pair, COLOR_WHITE, COLOR_BLUE);
|
||||
bkgd(COLOR_PAIR(my_pair));
|
||||
} else {
|
||||
try_color = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
lptr = my_lines;
|
||||
while (!done) {
|
||||
int n, c;
|
||||
|
||||
if (!got_number)
|
||||
show_all(my_label);
|
||||
|
||||
n = 0;
|
||||
for (;;) {
|
||||
#if CAN_RESIZE
|
||||
if (interrupted) {
|
||||
adjust(0);
|
||||
my_label = "interrupt";
|
||||
}
|
||||
#endif
|
||||
waiting = TRUE;
|
||||
c = getch();
|
||||
waiting = FALSE;
|
||||
if ((c < 127) && isdigit(c)) {
|
||||
if (!got_number) {
|
||||
mvprintw(0, 0, "Count: ");
|
||||
clrtoeol();
|
||||
}
|
||||
addch(c);
|
||||
value = 10 * value + (c - '0');
|
||||
got_number = TRUE;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (got_number && value) {
|
||||
n = value;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
|
||||
if (c != ERR)
|
||||
my_label = keyname(c);
|
||||
switch (c) {
|
||||
case KEY_DOWN:
|
||||
case 'n':
|
||||
olptr = lptr;
|
||||
for (i = 0; i < n; i++)
|
||||
if ((lptr - my_lines) < (length - LINES + 1))
|
||||
lptr++;
|
||||
else
|
||||
break;
|
||||
wscrl(stdscr, lptr - olptr);
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
case 'p':
|
||||
olptr = lptr;
|
||||
for (i = 0; i < n; i++)
|
||||
if (lptr > my_lines)
|
||||
lptr--;
|
||||
else
|
||||
break;
|
||||
wscrl(stdscr, lptr - olptr);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case KEY_HOME:
|
||||
lptr = my_lines;
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
case KEY_END:
|
||||
if (length > LINES)
|
||||
lptr = my_lines + length - LINES + 1;
|
||||
else
|
||||
lptr = my_lines;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
case KEY_RIGHT:
|
||||
shift += n;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
case KEY_LEFT:
|
||||
shift -= n;
|
||||
if (shift < 0) {
|
||||
shift = 0;
|
||||
beep();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
done = TRUE;
|
||||
break;
|
||||
|
||||
#ifdef KEY_RESIZE
|
||||
case KEY_RESIZE: /* ignore this; ncurses will repaint */
|
||||
break;
|
||||
#endif
|
||||
case 's':
|
||||
if (got_number) {
|
||||
halfdelay(my_delay = n);
|
||||
} else {
|
||||
nodelay(stdscr, FALSE);
|
||||
my_delay = -1;
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
nodelay(stdscr, TRUE);
|
||||
my_delay = 0;
|
||||
break;
|
||||
case ERR:
|
||||
if (!my_delay)
|
||||
napms(50);
|
||||
break;
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
if (c >= KEY_MIN || (c > 0 && !isdigit(c))) {
|
||||
got_number = FALSE;
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
finish(0); /* we're done */
|
||||
}
|
||||
|
||||
static RETSIGTYPE
|
||||
finish(int sig)
|
||||
{
|
||||
endwin();
|
||||
ExitProgram(sig != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#if CAN_RESIZE
|
||||
/*
|
||||
* This uses functions that are "unsafe", but it seems to work on SunOS and
|
||||
* Linux. Usually: the "unsafe" refers to the functions that POSIX lists
|
||||
* which may be called from a signal handler. Those do not include buffered
|
||||
* I/O, which is used for instance in wrefresh(). To be really portable, you
|
||||
* should use the KEY_RESIZE return (which relies on ncurses' sigwinch
|
||||
* handler).
|
||||
*
|
||||
* The 'wrefresh(curscr)' is needed to force the refresh to start from the top
|
||||
* of the screen -- some xterms mangle the bitmap while resizing.
|
||||
*/
|
||||
static RETSIGTYPE
|
||||
adjust(int sig)
|
||||
{
|
||||
if (waiting || sig == 0) {
|
||||
struct winsize size;
|
||||
|
||||
if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) {
|
||||
resize_term(size.ws_row, size.ws_col);
|
||||
wrefresh(curscr); /* Linux needs this */
|
||||
show_all(sig ? "SIGWINCH" : "interrupt");
|
||||
}
|
||||
interrupted = FALSE;
|
||||
} else {
|
||||
interrupted = TRUE;
|
||||
}
|
||||
(void) signal(SIGWINCH, adjust); /* some systems need this */
|
||||
}
|
||||
#endif /* CAN_RESIZE */
|
||||
|
||||
static void
|
||||
show_all(const char *tag)
|
||||
{
|
||||
int i;
|
||||
char temp[BUFSIZ];
|
||||
NCURSES_CH_T *s;
|
||||
time_t this_time;
|
||||
|
||||
#if CAN_RESIZE
|
||||
sprintf(temp, "%s (%3dx%3d) col %d ", tag, LINES, COLS, shift);
|
||||
i = strlen(temp);
|
||||
sprintf(temp + i, "view %.*s", (int) (sizeof(temp) - 7 - i), fname);
|
||||
#else
|
||||
sprintf(temp, "view %.*s", (int) sizeof(temp) - 7, fname);
|
||||
#endif
|
||||
move(0, 0);
|
||||
printw("%.*s", COLS, temp);
|
||||
clrtoeol();
|
||||
this_time = time((time_t *) 0);
|
||||
strcpy(temp, ctime(&this_time));
|
||||
if ((i = strlen(temp)) != 0) {
|
||||
temp[--i] = 0;
|
||||
if (move(0, COLS - i - 2) != ERR)
|
||||
printw(" %s", temp);
|
||||
}
|
||||
|
||||
scrollok(stdscr, FALSE); /* prevent screen from moving */
|
||||
for (i = 1; i < LINES; i++) {
|
||||
move(i, 0);
|
||||
printw("%3ld:", (long) (lptr + i - my_lines));
|
||||
clrtoeol();
|
||||
if ((s = lptr[i - 1]) != 0) {
|
||||
int len = ch_len(s);
|
||||
if (len > shift)
|
||||
#if USE_WIDEC_SUPPORT
|
||||
add_wchstr(s + shift);
|
||||
#else
|
||||
addchstr(s + shift);
|
||||
#endif
|
||||
if (try_color)
|
||||
wchgat(stdscr, -1, A_NORMAL, my_pair, NULL);
|
||||
}
|
||||
}
|
||||
setscrreg(1, LINES - 1);
|
||||
scrollok(stdscr, TRUE);
|
||||
refresh();
|
||||
}
|
@ -1,425 +0,0 @@
|
||||
/*
|
||||
|
||||
@@@ @@@ @@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@
|
||||
@@@ @@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@
|
||||
@@@ @@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@@
|
||||
@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
|
||||
@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
|
||||
@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@
|
||||
@@@@@@@@@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@
|
||||
@@@@ @@@@ @@@@@@@@@@@@ @@@ @@@ @@@ @@@
|
||||
@@ @@ @@@@@@@@@@ @@@ @@@ @@@ @@@
|
||||
|
||||
Eric P. Scott
|
||||
Caltech High Energy Physics
|
||||
October, 1980
|
||||
|
||||
Hacks to turn this into a test frame for cursor movement:
|
||||
Eric S. Raymond <esr@snark.thyrsus.com>
|
||||
January, 1995
|
||||
|
||||
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.36 2002/03/23 21:46:54 tom Exp $
|
||||
*/
|
||||
|
||||
#include <test.priv.h>
|
||||
|
||||
static chtype flavor[] =
|
||||
{
|
||||
'O', '*', '#', '$', '%', '0', '@',
|
||||
};
|
||||
static const short xinc[] =
|
||||
{
|
||||
1, 1, 1, 0, -1, -1, -1, 0
|
||||
}, yinc[] =
|
||||
{
|
||||
-1, 0, 1, 1, 1, 0, -1, -1
|
||||
};
|
||||
static struct worm {
|
||||
int orientation, head;
|
||||
short *xpos, *ypos;
|
||||
} worm[40];
|
||||
|
||||
static const char *field;
|
||||
static int length = 16, number = 3;
|
||||
static chtype trail = ' ';
|
||||
|
||||
#ifdef TRACE
|
||||
int generation, trace_start, trace_end, singlestep;
|
||||
#endif /* TRACE */
|
||||
/* *INDENT-OFF* */
|
||||
static const struct options {
|
||||
int nopts;
|
||||
int opts[3];
|
||||
} normal[8]={
|
||||
{ 3, { 7, 0, 1 } },
|
||||
{ 3, { 0, 1, 2 } },
|
||||
{ 3, { 1, 2, 3 } },
|
||||
{ 3, { 2, 3, 4 } },
|
||||
{ 3, { 3, 4, 5 } },
|
||||
{ 3, { 4, 5, 6 } },
|
||||
{ 3, { 5, 6, 7 } },
|
||||
{ 3, { 6, 7, 0 } }
|
||||
}, upper[8]={
|
||||
{ 1, { 1, 0, 0 } },
|
||||
{ 2, { 1, 2, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 2, { 4, 5, 0 } },
|
||||
{ 1, { 5, 0, 0 } },
|
||||
{ 2, { 1, 5, 0 } }
|
||||
}, left[8]={
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 2, { 2, 3, 0 } },
|
||||
{ 1, { 3, 0, 0 } },
|
||||
{ 2, { 3, 7, 0 } },
|
||||
{ 1, { 7, 0, 0 } },
|
||||
{ 2, { 7, 0, 0 } }
|
||||
}, right[8]={
|
||||
{ 1, { 7, 0, 0 } },
|
||||
{ 2, { 3, 7, 0 } },
|
||||
{ 1, { 3, 0, 0 } },
|
||||
{ 2, { 3, 4, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 2, { 6, 7, 0 } }
|
||||
}, lower[8]={
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 2, { 0, 1, 0 } },
|
||||
{ 1, { 1, 0, 0 } },
|
||||
{ 2, { 1, 5, 0 } },
|
||||
{ 1, { 5, 0, 0 } },
|
||||
{ 2, { 5, 6, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } }
|
||||
}, upleft[8]={
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 1, { 3, 0, 0 } },
|
||||
{ 2, { 1, 3, 0 } },
|
||||
{ 1, { 1, 0, 0 } }
|
||||
}, upright[8]={
|
||||
{ 2, { 3, 5, 0 } },
|
||||
{ 1, { 3, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 1, { 5, 0, 0 } }
|
||||
}, lowleft[8]={
|
||||
{ 3, { 7, 0, 1 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 1, { 1, 0, 0 } },
|
||||
{ 2, { 1, 7, 0 } },
|
||||
{ 1, { 7, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } }
|
||||
}, lowright[8]={
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 1, { 7, 0, 0 } },
|
||||
{ 2, { 5, 7, 0 } },
|
||||
{ 1, { 5, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } },
|
||||
{ 0, { 0, 0, 0 } }
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
standend();
|
||||
refresh();
|
||||
curs_set(1);
|
||||
endwin();
|
||||
}
|
||||
|
||||
static RETSIGTYPE
|
||||
onsig(int sig GCC_UNUSED)
|
||||
{
|
||||
cleanup();
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static float
|
||||
ranf(void)
|
||||
{
|
||||
long r = (rand() & 077777);
|
||||
return ((float) r / 32768.);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
short **ref;
|
||||
int x, y;
|
||||
int n;
|
||||
struct worm *w;
|
||||
const struct options *op;
|
||||
int h;
|
||||
short *ip;
|
||||
int last, bottom;
|
||||
|
||||
for (x = 1; x < argc; x++) {
|
||||
char *p;
|
||||
p = argv[x];
|
||||
if (*p == '-')
|
||||
p++;
|
||||
switch (*p) {
|
||||
case 'f':
|
||||
field = "WORM";
|
||||
break;
|
||||
case 'l':
|
||||
if (++x == argc)
|
||||
goto usage;
|
||||
if ((length = atoi(argv[x])) < 2 || length > 1024) {
|
||||
fprintf(stderr, "%s: Invalid length\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (++x == argc)
|
||||
goto usage;
|
||||
if ((number = atoi(argv[x])) < 1 || number > 40) {
|
||||
fprintf(stderr, "%s: Invalid number of worms\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
trail = '.';
|
||||
break;
|
||||
#ifdef TRACE
|
||||
case 'S':
|
||||
singlestep = TRUE;
|
||||
break;
|
||||
case 'T':
|
||||
trace_start = atoi(argv[++x]);
|
||||
trace_end = atoi(argv[++x]);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
signal(SIGINT, onsig);
|
||||
initscr();
|
||||
noecho();
|
||||
cbreak();
|
||||
nonl();
|
||||
|
||||
curs_set(0);
|
||||
|
||||
bottom = LINES - 1;
|
||||
last = COLS - 1;
|
||||
|
||||
#ifdef A_COLOR
|
||||
if (has_colors()) {
|
||||
int bg = COLOR_BLACK;
|
||||
start_color();
|
||||
#if HAVE_USE_DEFAULT_COLORS
|
||||
if (use_default_colors() == OK)
|
||||
bg = -1;
|
||||
#endif
|
||||
|
||||
#define SET_COLOR(num, fg) \
|
||||
init_pair(num+1, fg, bg); \
|
||||
flavor[num] |= COLOR_PAIR(num+1) | A_BOLD
|
||||
|
||||
SET_COLOR(0, COLOR_GREEN);
|
||||
SET_COLOR(1, COLOR_RED);
|
||||
SET_COLOR(2, COLOR_CYAN);
|
||||
SET_COLOR(3, COLOR_WHITE);
|
||||
SET_COLOR(4, COLOR_MAGENTA);
|
||||
SET_COLOR(5, COLOR_BLUE);
|
||||
SET_COLOR(6, COLOR_YELLOW);
|
||||
}
|
||||
#endif /* A_COLOR */
|
||||
|
||||
ref = typeMalloc(short *, LINES);
|
||||
for (y = 0; y < LINES; y++) {
|
||||
ref[y] = typeMalloc(short, COLS);
|
||||
for (x = 0; x < COLS; x++) {
|
||||
ref[y][x] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BADCORNER
|
||||
/* if addressing the lower right corner doesn't work in your curses */
|
||||
ref[bottom][last] = 1;
|
||||
#endif /* BADCORNER */
|
||||
|
||||
for (n = number, w = &worm[0]; --n >= 0; w++) {
|
||||
w->orientation = w->head = 0;
|
||||
if (!(ip = typeMalloc(short, (length + 1)))) {
|
||||
fprintf(stderr, "%s: out of memory\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
w->xpos = ip;
|
||||
for (x = length; --x >= 0;)
|
||||
*ip++ = -1;
|
||||
if (!(ip = typeMalloc(short, (length + 1)))) {
|
||||
fprintf(stderr, "%s: out of memory\n", *argv);
|
||||
ExitProgram(EXIT_FAILURE);
|
||||
}
|
||||
w->ypos = ip;
|
||||
for (y = length; --y >= 0;)
|
||||
*ip++ = -1;
|
||||
}
|
||||
if (field) {
|
||||
const char *p;
|
||||
p = field;
|
||||
for (y = bottom; --y >= 0;) {
|
||||
for (x = COLS; --x >= 0;) {
|
||||
addch((chtype) (*p++));
|
||||
if (!*p)
|
||||
p = field;
|
||||
}
|
||||
}
|
||||
}
|
||||
napms(10);
|
||||
refresh();
|
||||
#ifndef TRACE
|
||||
nodelay(stdscr, TRUE);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
#ifdef TRACE
|
||||
if (trace_start || trace_end) {
|
||||
if (generation == trace_start) {
|
||||
trace(TRACE_CALLS);
|
||||
getch();
|
||||
} else if (generation == trace_end) {
|
||||
trace(0);
|
||||
getch();
|
||||
}
|
||||
|
||||
if (singlestep && generation > trace_start && generation < trace_end)
|
||||
getch();
|
||||
|
||||
generation++;
|
||||
}
|
||||
#else
|
||||
int ch;
|
||||
|
||||
if ((ch = getch()) > 0) {
|
||||
#ifdef KEY_RESIZE
|
||||
if (ch == KEY_RESIZE) {
|
||||
if (last != COLS - 1) {
|
||||
for (y = 0; y <= bottom; y++) {
|
||||
ref[y] = typeRealloc(short, COLS, ref[y]);
|
||||
for (x = last + 1; x < COLS; x++)
|
||||
ref[y][x] = 0;
|
||||
}
|
||||
last = COLS - 1;
|
||||
}
|
||||
if (bottom != LINES - 1) {
|
||||
for (y = LINES; y <= bottom; y++)
|
||||
free(ref[y]);
|
||||
ref = typeRealloc(short *, LINES, ref);
|
||||
for (y = bottom + 1; y < LINES; y++) {
|
||||
ref[y] = typeMalloc(short, COLS);
|
||||
for (x = 0; x < COLS; x++)
|
||||
ref[y][x] = 0;
|
||||
}
|
||||
bottom = LINES - 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Make it simple to put this into single-step mode, or resume
|
||||
* normal operation -TD
|
||||
*/
|
||||
if (ch == 'q') {
|
||||
cleanup();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
} else if (ch == 's') {
|
||||
nodelay(stdscr, FALSE);
|
||||
} else if (ch == ' ') {
|
||||
nodelay(stdscr, TRUE);
|
||||
}
|
||||
}
|
||||
#endif /* TRACE */
|
||||
|
||||
for (n = 0, w = &worm[0]; n < number; n++, w++) {
|
||||
if ((x = w->xpos[h = w->head]) < 0) {
|
||||
move(y = w->ypos[h] = bottom, x = w->xpos[h] = 0);
|
||||
addch(flavor[n % SIZEOF(flavor)]);
|
||||
ref[y][x]++;
|
||||
} else {
|
||||
y = w->ypos[h];
|
||||
}
|
||||
if (x > last)
|
||||
x = last;
|
||||
if (y > bottom)
|
||||
y = bottom;
|
||||
if (++h == length)
|
||||
h = 0;
|
||||
if (w->xpos[w->head = h] >= 0) {
|
||||
int x1, y1;
|
||||
x1 = w->xpos[h];
|
||||
y1 = w->ypos[h];
|
||||
if (y1 < LINES
|
||||
&& x1 < COLS
|
||||
&& --ref[y1][x1] == 0) {
|
||||
move(y1, x1);
|
||||
addch(trail);
|
||||
}
|
||||
}
|
||||
op = &(x == 0 ? (y == 0 ? upleft : (y == bottom ? lowleft :
|
||||
left)) :
|
||||
(x == last ? (y == 0 ? upright : (y == bottom ? lowright :
|
||||
right)) :
|
||||
(y == 0 ? upper : (y == bottom ? lower : normal))))[w->orientation];
|
||||
switch (op->nopts) {
|
||||
case 0:
|
||||
cleanup();
|
||||
ExitProgram(EXIT_SUCCESS);
|
||||
case 1:
|
||||
w->orientation = op->opts[0];
|
||||
break;
|
||||
default:
|
||||
w->orientation = op->opts[(int) (ranf() * (float) op->nopts)];
|
||||
}
|
||||
move(y += yinc[w->orientation], x += xinc[w->orientation]);
|
||||
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
addch(flavor[n % SIZEOF(flavor)]);
|
||||
ref[w->ypos[h] = y][w->xpos[h] = x]++;
|
||||
}
|
||||
napms(10);
|
||||
refresh();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user