libpayload: Rename PDCurses-3.4 to PDCurses

Change-Id: If881ec130833c7e7e62caa3d31e350a531f5bc8e
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-on: http://review.coreboot.org/12398
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Stefan Reinauer
2015-11-10 09:00:41 -08:00
parent 2ea24dabd6
commit 4f85a1eb76
164 changed files with 2 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,325 @@
PDCurses Implementor's Guide
============================
Version 1.3 - 200?/??/?? - notes about official ports
Version 1.2 - 2007/07/11 - added PDC_init_pair(), PDC_pair_content(),
version history; removed pdc_atrtab
Version 1.1 - 2007/06/06 - minor cosmetic change
Version 1.0 - 2007/04/01 - initial revision
This document is for those wishing to port PDCurses to a new platform,
or just wanting to better understand how it works. Nothing here should
be needed for application programming; for that, refer to PDCurses.txt,
as built in doc/, or distributed as a file separate from this source
package. This document assumes that you've read the user-level
documentation and are very familiar with application-level curses
programming.
If you want to submit your port for possible inclusion into the main
PDCurses distribution, please follow these guidelines:
- Don't modify anything in the pdcurses directory or in other port
directories. Don't modify curses.h or curspriv.h unless absolutely
necessary. (And prefer modifying curspriv.h over curses.h.)
- Use the same indentation style, naming and scope conventions as the
existing code.
- Release all your code to the public domain -- no copyright. Code
under GPL, BSD, etc. will not be accepted.
DATA STRUCTURES
---------------
A port of PDCurses must provide acs_map[], a 128-element array of
chtypes, with values laid out based on the Alternate Character Set of
the VT100 (see curses.h). PDC_transform_line() must use this table; when
it encounters a chtype with the A_ALTCHARSET flag set, and an A_CHARTEXT
value in the range 0-127, it must render it using the A_CHARTEXT portion
of the corresponding value from this table, instead of the original
value. Also, values may be read from this table by apps, and passed
through functions such as waddch(), which does no special processing on
control characters (0-31 and 127) when the A_ALTCHARSET flag is set.
Thus, any control characters used in acs_map[] should also have the
A_ALTCHARSET flag set. Implementations should provide suitable values
for all the ACS_ macros defined in curses.h; other values in the table
should be filled with their own indices (e.g., acs_map['E'] == 'E'). The
table can be either hardwired, or filled by PDC_scr_open(). Existing
ports define it in pdcdisp.c, but this is not required.
FUNCTIONS
---------
A port of PDCurses must implement the following functions, with extern
scope. These functions are traditionally divided into several modules,
as indicated below; this division is not required (only the functions
are), but may make it easier to follow for someone familiar with the
existing ports.
Any other functions you create as part of your implementation should
have static scope, if possible. If they can't be static, they should be
named with the "PDC_" prefix. This minimizes the risk of collision with
an application's choices.
Current PDCurses style also uses a single leading underscore with the
name of any static function; and modified BSD/Allman-style indentation,
approximately equivalent to "indent -kr -i8 -bl -bli0", with adjustments
to keep every line under 80 columns. This isn't essential, but a
consistent style helps readability.
pdcdisp.c:
----------
void PDC_gotoyx(int y, int x);
Move the physical cursor (as opposed to the logical cursor affected by
wmove()) to the given location. This is called mainly from doupdate().
In general, this function need not compare the old location with the new
one, and should just move the cursor unconditionally.
void PDC_transform_line(int lineno, int x, int len, const chtype *srcp);
The core output routine. It takes len chtype entities from srcp (a
pointer into curscr) and renders them to the physical screen at line
lineno, column x. It must also translate characters 0-127 via acs_map[],
if they're flagged with A_ALTCHARSET in the attribute portion of the
chtype.
pdcgetsc.c:
-----------
int PDC_get_columns(void);
Returns the size of the screen in columns. It's used in resize_term() to
set the new value of COLS. (Some existing implementations also call it
internally from PDC_scr_open(), but this is not required.)
int PDC_get_cursor_mode(void);
Returns the size/shape of the cursor. The format of the result is
unspecified, except that it must be returned as an int. This function is
called from initscr(), and the result is stored in SP->orig_cursor,
which is used by PDC_curs_set() to determine the size/shape of the
cursor in normal visibility mode (curs_set(1)).
int PDC_get_rows(void);
Returns the size of the screen in rows. It's used in resize_term() to
set the new value of LINES. (Some existing implementations also call it
internally from PDC_scr_open(), but this is not required.)
pdckbd.c:
---------
bool PDC_check_key(void);
Keyboard/mouse event check, called from wgetch(). Returns TRUE if
there's an event ready to process. This function must be non-blocking.
void PDC_flushinp(void);
This is the core of flushinp(). It discards any pending key or mouse
events, removing them from any internal queue and from the OS queue, if
applicable.
int PDC_get_key(void);
Get the next available key, or mouse event (indicated by a return of
KEY_MOUSE), and remove it from the OS' input queue, if applicable. This
function is called from wgetch(). This function may be blocking, and
traditionally is; but it need not be. If a valid key or mouse event
cannot be returned, for any reason, this function returns -1. Valid keys
are those that fall within the appropriate character set, or are in the
list of special keys found in curses.h (KEY_MIN through KEY_MAX). When
returning a special key code, this routine must also set SP->key_code to
TRUE; otherwise it must set it to FALSE. If SP->return_key_modifiers is
TRUE, this function may return modifier keys (shift, control, alt),
pressed alone, as special key codes; if SP->return_key_modifiers is
FALSE, it must not. If modifier keys are returned, it should only happen
if no other keys were pressed in the meantime; i.e., the return should
happen on key up. But if this is not possible, it may return the
modifier keys on key down (if and only if SP->return_key_modifiers is
TRUE).
int PDC_modifiers_set(void);
Called from PDC_return_key_modifiers(). If your platform needs to do
anything in response to a change in SP->return_key_modifiers, do it
here. Returns OK or ERR, which is passed on by the caller.
int PDC_mouse_set(void);
Called by mouse_set(), mouse_on(), and mouse_off() -- all the functions
that modify SP->_trap_mbe. If your platform needs to do anything in
response to a change in SP->_trap_mbe (for example, turning the mouse
cursor on or off), do it here. Returns OK or ERR, which is passed on by
the caller.
void PDC_set_keyboard_binary(bool on);
Set keyboard input to "binary" mode. If you need to do something to keep
the OS from processing ^C, etc. on your platform, do it here. TRUE turns
the mode on; FALSE reverts it. This function is called from raw() and
noraw().
pdcscrn.c:
----------
bool PDC_can_change_color(void);
Returns TRUE if init_color() and color_content() give meaningful
results, FALSE otherwise. Called from can_change_color().
int PDC_color_content(short color, short *red, short *green, short *blue);
The core of color_content(). This does all the work of that function,
except checking for values out of range and null pointers.
int PDC_init_color(short color, short red, short green, short blue);
The core of init_color(). This does all the work of that function,
except checking for values out of range.
void PDC_init_pair(short pair, short fg, short bg);
The core of init_pair(). This does all the work of that function, except
checking for values out of range. The values passed to this function
should be returned by a call to PDC_pair_content() with the same pair
number. PDC_transform_line() should use the specified colors when
rendering a chtype with the given pair number.
int PDC_pair_content(short pair, short *fg, short *bg);
The core of pair_content(). This does all the work of that function,
except checking for values out of range and null pointers.
void PDC_reset_prog_mode(void);
The non-portable functionality of reset_prog_mode() is handled here --
whatever's not done in _restore_mode(). In current ports: In OS/2, this
sets the keyboard to binary mode; in Win32, it enables or disables the
mouse pointer to match the saved mode; in others it does nothing.
void PDC_reset_shell_mode(void);
The same thing, for reset_shell_mode(). In OS/2 and Win32, it restores
the default console mode; in others it does nothing.
int PDC_resize_screen(int nlines, int ncols);
This does the main work of resize_term(). It may respond to non-zero
parameters, by setting the screen to the specified size; to zero
parameters, by setting the screen to a size chosen by the user at
runtime, in an unspecified way (e.g., by dragging the edges of the
window); or both. It may also do nothing, if there's no appropriate
action for the platform.
void PDC_restore_screen_mode(int i);
Called from _restore_mode() in kernel.c, this function does the actual
mode changing, if applicable. Currently used only in DOS and OS/2.
void PDC_save_screen_mode(int i);
Called from _save_mode() in kernel.c, this function saves the actual
screen mode, if applicable. Currently used only in DOS and OS/2.
void PDC_scr_close(void);
The platform-specific part of endwin(). It may restore the image of the
original screen saved by PDC_scr_open(), if the PDC_RESTORE_SCREEN
environment variable is set; either way, if using an existing terminal,
this function should restore it to the mode it had at startup, and move
the cursor to the lower left corner. (The X11 port does nothing.)
void PDC_scr_free(void);
Frees the memory for SP allocated by PDC_scr_open(). Called by
delscreen().
int PDC_scr_open(int argc, char **argv);
The platform-specific part of initscr(). It's actually called from
Xinitscr(); the arguments, if present, correspond to those used with
main(), and may be used to set the title of the terminal window, or for
other, platform-specific purposes. (The arguments are currently used
only in X11.) PDC_scr_open() must allocate memory for SP, and must
initialize acs_map[] (unless it's preset) and several members of SP,
including lines, cols, mouse_wait, orig_attr (and if orig_attr is TRUE,
orig_fore and orig_back), mono, _restore and _preserve. (Although SP is
used the same way in all ports, it's allocated here in order to allow
the X11 port to map it to a block of shared memory.) If using an
existing terminal, and the environment variable PDC_RESTORE_SCREEN is
set, this function may also store the existing screen image for later
restoration by PDC_scr_close().
pdcsetsc.c:
-----------
int PDC_curs_set(int visibility);
Called from curs_set(). Changes the appearance of the cursor -- 0 turns
it off, 1 is normal (the terminal's default, if applicable, as
determined by SP->orig_cursor), and 2 is high visibility. The exact
appearance of these modes is not specified.
pdcutil.c:
----------
void PDC_beep(void);
Emits a short audible beep. If this is not possible on your platform,
you must set SP->audible to FALSE during initialization (i.e., from
PDC_scr_open() -- not here); otherwise, set it to TRUE. This function is
called from beep().
void PDC_napms(int ms);
This is the core delay routine, called by napms(). It pauses for about
(the X/Open spec says "at least") ms milliseconds, then returns. High
degrees of accuracy and precision are not expected (though desirable, if
you can achieve them). More important is that this function gives back
the process' time slice to the OS, so that PDCurses idles at low CPU
usage.
const char *PDC_sysname(void);
Returns a short string describing the platform, such as "DOS" or "X11".
This is used by longname(). It must be no more than 100 characters; it
should be much, much shorter (existing platforms use no more than 5).
--------------------------------------------------------------------------
The following functions are implemented in the platform directories, but
are accessed directly by apps. Refer to the user documentation for their
descriptions:
pdcclip.c:
----------
int PDC_clearclipboard(void);
int PDC_freeclipboard(char *contents);
int PDC_getclipboard(char **contents, long *length);
int PDC_setclipboard(const char *contents, long length);
pdckbd.c:
---------
unsigned long PDC_get_input_fd(void);
pdcsetsc.c:
-----------
int PDC_set_blink(bool blinkon);
void PDC_set_title(const char *title);

View File

@@ -0,0 +1,108 @@
# Makefile for PDCurses library for X11
SHELL = @SHELL@
@SET_MAKE@
srcdir =@srcdir@
prefix =@prefix@
exec_prefix =$(DESTDIR)@exec_prefix@
libdir =$(exec_prefix)/lib
bindir =$(exec_prefix)/bin
includedir =$(exec_prefix)/include
pdcursesdir =./x11
INSTALL =$(srcdir)/install-sh
RANLIB =@RANLIB@
SHLPRE = @SHLPRE@
SHLPST = @SHLPST@
SHLFILE = XCurses
include $(srcdir)/version.mif
PDC_DIR=PDCurses-$(VERDOT)
ZIPFILE = pdcurs$(VER).zip
TARBALL = $(PDC_DIR).tar.gz
all \
clean \
distclean \
mostlyclean \
realclean ::
cd x11; $(MAKE) $(MFLAGS) $@
cd doc; $(MAKE) $(MFLAGS) $@
install ::
$(INSTALL) -d -m 755 $(libdir)
$(INSTALL) -d -m 755 $(bindir)
$(INSTALL) -d -m 755 $(includedir)
$(INSTALL) -d -m 755 $(includedir)/xcurses
$(INSTALL) -c -m 644 $(srcdir)/curses.h $(includedir)/xcurses.h
$(INSTALL) -c -m 644 $(srcdir)/curses.h $(includedir)/xcurses/curses.h
sed -e 's/#include <curses.h>/#include <xcurses.h>/' \
< $(srcdir)/panel.h > ./xpanel.h
$(INSTALL) -m 644 ./xpanel.h $(includedir)/xpanel.h
$(INSTALL) -c -m 644 $(srcdir)/panel.h $(includedir)/xcurses/panel.h
$(INSTALL) -c -m 644 $(srcdir)/term.h $(includedir)/xcurses/term.h
$(INSTALL) -c -m 644 $(pdcursesdir)/libXCurses.a $(libdir)/libXCurses.a
-$(RANLIB) $(libdir)/libXCurses.a
-$(INSTALL) -c -m 755 $(pdcursesdir)/$(SHLPRE)$(SHLFILE)$(SHLPST) \
$(libdir)/$(SHLPRE)$(SHLFILE)$(SHLPST)
ln -f -s $(libdir)/$(SHLPRE)$(SHLFILE)$(SHLPST) \
$(libdir)/$(SHLPRE)Xpanel$(SHLPST)
ln -f -s $(libdir)/libXCurses.a $(libdir)/libXpanel.a
-$(RANLIB) $(libdir)/libXpanel.a
$(INSTALL) -c -m 755 x11/xcurses-config $(bindir)/xcurses-config
clean ::
rm -f config.log config.cache config.status
distclean ::
rm -f config.log config.cache config.status
rm -f config.h Makefile x11/xcurses-config
manual:
cd doc; $(MAKE) $(MFLAGS) $@
$(ZIPFILE):
zip -9y $(ZIPFILE) README HISTORY IMPLEMNT *.spec *.mif *.def \
Makefile.in config.h.in configure configure.ac config.guess \
config.sub x11/xcurses-config.in install-sh aclocal.m4 curses.h \
curspriv.h panel.h term.h pdcurses/README \
pdcurses/*.c demos/README demos/*.c demos/*.h dos/README dos/*.c \
dos/*.h dos/*.mak dos/*.lrf os2/README os2/*.c os2/*.h os2/*.mak \
os2/*.lrf sdl1/README sdl1/*.c sdl1/*.h sdl1/Make* \
win32/README win32/*.c win32/*.h win32/*.mak \
win32/*.ico win32/*.rc x11/README x11/*.c x11/*.h x11/Makefile.* \
x11/*.xbm doc/*.txt doc/manext.c doc/Makefile
zip: $(ZIPFILE)
../$(TARBALL):
(cd ..; tar cvf - $(PDC_DIR)/README $(PDC_DIR)/HISTORY \
$(PDC_DIR)/IMPLEMNT $(PDC_DIR)/*.spec $(PDC_DIR)/*.mif \
$(PDC_DIR)/*.def $(PDC_DIR)/Makefile.in $(PDC_DIR)/aclocal.m4 \
$(PDC_DIR)/config.h.in $(PDC_DIR)/configure \
$(PDC_DIR)/config.guess $(PDC_DIR)/x11/xcurses-config.in \
$(PDC_DIR)/config.sub $(PDC_DIR)/configure.ac \
$(PDC_DIR)/install-sh $(PDC_DIR)/curses.h $(PDC_DIR)/curspriv.h \
$(PDC_DIR)/panel.h $(PDC_DIR)/term.h \
$(PDC_DIR)/pdcurses/README $(PDC_DIR)/pdcurses/*.c \
$(PDC_DIR)/demos/README $(PDC_DIR)/demos/*.c $(PDC_DIR)/demos/*.h \
$(PDC_DIR)/doc/*.txt $(PDC_DIR)/dos/README $(PDC_DIR)/dos/*.c \
$(PDC_DIR)/dos/*.h $(PDC_DIR)/dos/*.mak $(PDC_DIR)/dos/*.lrf \
$(PDC_DIR)/os2/README $(PDC_DIR)/os2/*.c $(PDC_DIR)/os2/*.h \
$(PDC_DIR)/os2/*.mak $(PDC_DIR)/os2/*.lrf \
$(PDC_DIR)/sdl1/README $(PDC_DIR)/sdl1/*.c $(PDC_DIR)/sdl1/*.h \
$(PDC_DIR)/sdl1/Make* $(PDC_DIR)/win32/README $(PDC_DIR)/win32/*.c \
$(PDC_DIR)/win32/*.h $(PDC_DIR)/win32/*.mak \
$(PDC_DIR)/win32/*.ico $(PDC_DIR)/win32/*.rc $(PDC_DIR)/x11/README \
$(PDC_DIR)/x11/*.c $(PDC_DIR)/x11/*.xbm $(PDC_DIR)/x11/*.h \
$(PDC_DIR)/x11/Makefile.* $(PDC_DIR)/doc/manext.c \
$(PDC_DIR)/doc/Makefile | gzip -9 > $(TARBALL))
dist: ../$(TARBALL)
rpm: ../$(TARBALL)
rpmbuild -ba $(srcdir)/PDCurses.spec

View File

@@ -0,0 +1,52 @@
# $Id: PDCurses.spec,v 1.18 2008/07/21 12:25:20 wmcbrine Exp $
%define ver 34
%define verdot 3.4
%define base /usr
Summary: Public Domain Curses for X11
Name: PDCurses
Version: %verdot
Release: 1
Copyright: Public Domain
Group: Development/Libraries
Source: %{name}-%{version}.tar.gz
URL: http://pdcurses.sourceforge.net
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Prefix: %base
%description
PDCurses for X11 is an implementation of the curses library that lets
you build text-mode curses programs as native X11 applications. For more
information, visit http://pdcurses.sourceforge.net/
%prep
%setup -q
%build
./configure --prefix=%{base}
make
%install
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_DIR/%{name}-%{version}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%defattr(-,root,root)
%doc README HISTORY
%{base}/bin/xcurses-config
%{base}/lib/libXCurses.a
%{base}/lib/libXpanel.a
%{base}/lib/libXCurses.so
%{base}/include/xcurses.h
%{base}/include/xpanel.h
%{base}/include/xcurses/curses.h
%{base}/include/xcurses/panel.h
%{base}/include/xcurses/term.h

View File

@@ -0,0 +1,48 @@
Welcome to PDCurses!
====================
Public Domain Curses, aka PDCurses, is an implementation of X/Open
curses for multiple platforms. The latest version can be found at:
http://pdcurses.sourceforge.net/
For changes, see the HISTORY file.
Legal Stuff
-----------
The core package is in the public domain, but small portions of PDCurses
are subject to copyright under various licenses. Each directory
contains a README file, with a section titled "Distribution Status"
which describes the status of the files in that directory.
If you use PDCurses in an application, an acknowledgement would be
appreciated, but is not mandatory. If you make corrections or
enhancements to PDCurses, please forward them to the current maintainer
for the benefit of other users.
This software is provided AS IS with NO WARRANTY whatsoever.
Ports
-----
PDCurses has been ported to DOS, OS/2, Win32, X11 and SDL. A directory
containing the port-specific source files exists for each of these
platforms. Build instructions are in the README file for each platform.
Distribution Status
-------------------
All files in this directory except configure, config.guess and
config.sub are released to the Public Domain. config.guess and
config.sub are under the GPL; configure is under a free license
described within it.
Maintainer
----------
William McBrine <wmcbrine@users.sf.net>

View File

@@ -0,0 +1,613 @@
dnl ---------------------------------------------------------------------------
dnl This file offers the following macros...
dnl ---------------------------------------------------------------------------
dnl MH_IPC
dnl MH_CHECK_X_INC
dnl MH_CHECK_X_LIB
dnl MH_CHECK_X_HEADERS
dnl MH_CHECK_X_KEYDEFS
dnl MH_CHECK_X_TYPEDEF
dnl MH_CHECK_LIB
dnl MH_SHARED_LIBRARY
dnl MH_HOWTO_DYN_LINK
dnl MH_CHECK_CC_O
dnl MH_SHLPST
dnl MH_CHECK_MAX_SIGNALS
dnl ---------------------------------------------------------------------------
dnl Determine if the system has System V IPC. ie sys/ipc.h and sys/shm.h
dnl headers.
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_IPC],
[
AC_CHECK_HEADER(sys/ipc.h)
if test $ac_cv_header_sys_ipc_h = no; then
AC_MSG_ERROR(Cannot find required header file sys/ipc.h; PDCurses cannot be configured)
fi
])dnl
dnl ---------------------------------------------------------------------------
dnl Set up the correct X header file location
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_X_INC],
[
mh_x11_dir=""
mh_x11_xaw_dir=""
mh_inc_dirs="$ac_x_header_dirs"
dnl Provide for user supplying directory
if test "x$x_includes" != xNONE ; then
mh_inc_dirs="$x_includes $mh_inc_dirs"
fi
dnl Try to determine the directory containing X headers
dnl We will append X11 to all the paths above as an extra check
for ac_dir in $mh_inc_dirs ; do
if test -r $ac_dir/Intrinsic.h; then
mh_x11_dir=$ac_dir
break
fi
if test -r $ac_dir/X11/Intrinsic.h; then
mh_x11_dir="$ac_dir/X11"
break
fi
done
dnl Try to determine the directory containing Xaw headers
dnl We will append X11 to all the paths above as an extra check
if test "$with_xaw3d" = yes; then
mh_xaw_dir="Xaw3d"
else
if test "$with_nextaw" = yes; then
mh_xaw_dir="neXtaw"
else
mh_xaw_dir="Xaw"
fi
fi
for ac_dir in $mh_inc_dirs ; do
if test -r $ac_dir/$mh_xaw_dir/Box.h; then
mh_x11_xaw_dir=$ac_dir
break
fi
if test -r $ac_dir/X11/$mh_xaw_dir/Box.h; then
mh_x11_xaw_dir="$ac_dir/X11"
break
fi
done
if test "x$mh_x11_dir" != "x" ; then
mh_x11_dir_no_x11=`echo $mh_x11_dir | sed 's/\/X11$//'`
if test "$mh_x11_dir_no_x11" != "$mh_x11_dir" ; then
MH_XINC_DIR="-I$mh_x11_dir -I$mh_x11_dir_no_x11"
else
MH_XINC_DIR="-I$mh_x11_dir"
fi
else
AC_MSG_ERROR(Cannot find required header file Intrinsic.h; PDCurses cannot be configured)
fi
if test "x$mh_x11_xaw_dir" != "x"; then
if test "$mh_x11_xaw_dir" != "$mh_x11_dir" ; then
MH_XINC_DIR="-I$mh_x11_xaw_dir $MH_XINC_DIR"
fi
else
AC_MSG_ERROR(Cannot find required Xaw header file Box.h; PDCurses cannot be configured)
fi
AC_SUBST(MH_XINC_DIR)
])dnl
dnl ---------------------------------------------------------------------------
dnl Set up the correct X library file location
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_X_LIB],
[
dnl Some systems require extra libraries...
mh_solaris_flag=no
mh_hpux9_flag=no
AC_REQUIRE([AC_CANONICAL_SYSTEM])
case "$target" in
*solaris*)
mh_solaris_flag=yes
;;
*pc-sco*)
extra_x_libs="Xext"
;;
sparc*sunos*)
extra_x_libs="Xext"
if test "$ac_cv_prog_CC" = "gcc" ; then
extra_ld_flags="-Wl,-Bstatic"
extra_ld_flags2="-Wl,-Bdynamic"
else
extra_ld_flags="-Bstatic"
extra_ld_flags2="-Bdynamic"
fi
;;
*hpux9*)
mh_hpux9_flag=yes
;;
esac
if test "$with_xaw3d" = yes; then
MH_X11_LIBS="Xaw3d Xmu Xt X11"
else
if test "$with_nextaw" = yes; then
MH_X11_LIBS="neXtaw Xmu Xt X11"
else
MH_X11_LIBS="Xaw Xmu Xt X11"
fi
fi
MH_X11R6_LIBS="SM ICE Xext"
mh_x11r6=no
mh_lib_dirs="$x_libraries `echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g`"
dnl try to find libSM.[a,sl,so,dylib]. If we find it we are using X11R6
for ac_dir in $mh_lib_dirs ; do
for mh_xsm in libSM.a libSM.so libSM.sl libSM.dylib; do
if test -r $ac_dir/$mh_xsm; then
mh_x11r6=yes
break 2
fi
done
done
if test "$mh_x11r6" = yes ; then
mh_libs="$MH_X11_LIBS $MH_X11R6_LIBS"
else
mh_libs="$MH_X11_LIBS $extra_x_libs"
fi
dnl Ensure that all required X libraries are found
mh_prev_dir=""
mh_where_found=""
mh_where_found_dirs=""
mh_solaris_path=""
for mh_lib in $mh_libs; do
mh_lib_found=no
for ac_dir in $mh_lib_dirs ; do
for mh_ext in a so sl dll.a dylib; do
if test -r $ac_dir/lib$mh_lib.$mh_ext; then
if test "x$mh_prev_dir" != "x$ac_dir" ; then
if test "x$mh_prev_dir" = "x" ; then
mh_where_found="$mh_where_found found in $ac_dir"
else
mh_where_found="$mh_where_found and in $ac_dir"
fi
mh_prev_dir=$ac_dir
mh_where_found_dirs="$mh_where_found_dirs $ac_dir"
MH_XLIBS="$MH_XLIBS -L$ac_dir"
mh_solaris_path="${mh_solaris_path}:$ac_dir"
fi
MH_XLIBS="$MH_XLIBS -l$mh_lib"
mh_lib_found=yes
break 2
fi
done
done
if test "$mh_lib_found" = no; then
AC_MSG_ERROR(Cannot find required X library; lib$mh_lib. PDCurses cannot be configured)
fi
done
mh_solaris_path=`echo $mh_solaris_path | sed 's/^://'`
if test "$mh_solaris_flag" = yes ; then
MH_XLIBS="-R$mh_solaris_path $extra_ld_flags $MH_XLIBS $extra_libs $extra_ld_flags2"
else
MH_XLIBS="$extra_ld_flags $MH_XLIBS $extra_libs $extra_ld_flags2"
fi
if test "$mh_hpux9_flag" = yes ; then
grep -q XtSetLanguageProc $mh_x11_dir/Intrinsic.h
if test $? -eq 0 ; then
mh_found_xtshellstrings=no
for mh_acdir in $mh_where_found_dirs ; do
for mh_xaw in `ls $mh_acdir/libXaw.*` ; do
nm $mh_xaw | grep XtShellStrings | grep -qv extern
if test $? -eq 0 ; then
mh_found_xtshellstrings=yes
fi
done
done
if test "$mh_found_xtshellstrings" = no ; then
AC_MSG_WARN(The X11 development environment has not been installed correctly.)
AC_MSG_WARN(The header file; Intrinsic.h, is for X11R5 while the Athena Widget)
AC_MSG_WARN(Set library; libXaw is for X11R4. This is a common problem with)
AC_MSG_WARN(HP-UX 9.x.)
AC_MSG_ERROR(X11 installation incomplete; cannot continue)
fi
fi
fi
AC_SUBST(MH_XLIBS)
])dnl
dnl ---------------------------------------------------------------------------
dnl Determine if the supplied X headers exist.
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_X_HEADERS],
[
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MH_XINC_DIR"
for mh_header in $1; do
AC_CHECK_HEADERS($mh_header)
done
CPPFLAGS="$save_CPPFLAGS"
])dnl
dnl ---------------------------------------------------------------------------
dnl Determine if various key definitions exist in keysym.h
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_X_KEYDEFS],
[
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $MH_XINC_DIR"
for mh_keydef in $1; do
AC_MSG_CHECKING(for $mh_keydef in keysym.h)
mh_upper_name="HAVE_`echo $mh_keydef | tr '[a-z]' '[A-Z]'`"
AC_TRY_COMPILE([#include <keysym.h>],
[int i = $mh_keydef;],
mh_have_key=yes; AC_DEFINE_UNQUOTED($mh_upper_name,1), mh_have_key=no )
AC_MSG_RESULT($mh_have_key)
done
CPPFLAGS="$save_CPPFLAGS"
])dnl
dnl ---------------------------------------------------------------------------
dnl Determine if supplied types have been typedefed
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_X_TYPEDEF],
[
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $SYS_DEFS $MH_XINC_DIR"
for td in $1 ; do
AC_MSG_CHECKING(if $td is typedefed:)
AC_TRY_COMPILE(
[#include "X11/Xlib.h"],
[$td fred],
[mh_td=yes],
[mh_td=no]
)
if test "$mh_td" = yes ; then
TD_upper=`echo $td | tr a-z A-Z`
AC_DEFINE_UNQUOTED(${TD_upper}_TYPEDEFED, 1)
fi
AC_MSG_RESULT($mh_td)
done
CPPFLAGS="$save_CPPFLAGS"
])dnl
dnl ---------------------------------------------------------------------------
dnl Check for presence of various libraries
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_LIB],
[
MH_EXTRA_LIBS=''
for mh_lib in $1; do
if test "$on_qnx" = yes; then
AC_MSG_CHECKING(for library -l${mh_lib})
if test -r /usr/lib/${mh_lib}3r.lib; then
AC_MSG_RESULT(found)
MH_EXTRA_LIBS="${MH_EXTRA_LIBS} -l${mh_lib}"
else
AC_MSG_RESULT(not found)
fi
else
AC_CHECK_LIB($mh_lib,main,mh_lib_found=yes,mh_lib_found=no)
if test "$mh_lib_found" = yes; then
MH_EXTRA_LIBS="${MH_EXTRA_LIBS} -l${mh_lib}"
fi
fi
done
])dnl
dnl ---------------------------------------------------------------------------
dnl Work out how to create a dynamically loaded module
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_HOWTO_DYN_LINK],
[
mh_compile='${CC-cc} -c $DYN_COMP conftest.$ac_ext 1>&AC_FD_CC'
cat > conftest.$ac_ext <<EOF
dnl [#]line __oline__ "[$]0"
[#]line __oline__ "configure"
int foo()
{
return(0);
}
EOF
if AC_TRY_EVAL(mh_compile) && test -s conftest.o; then
mh_dyn_link='ld -shared -o conftest.rxlib conftest.o -lc 1>&AC_FD_CC'
# mh_dyn_link='${CC} -Wl,-shared -o conftest.rxlib conftest.o -lc 1>&AC_FD_CC'
if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.rxlib; then
LD_RXLIB1="ld -shared"
# LD_RXLIB1="${CC} -Wl,-shared"
SHLPRE="lib"
SHLPST=".so"
else
mh_dyn_link='ld -G -o conftest.rxlib conftest.o 1>&AC_FD_CC'
# mh_dyn_link='${CC} -Wl,-G -o conftest.rxlib conftest.o 1>&AC_FD_CC'
if AC_TRY_EVAL(mh_dyn_link) && test -s conftest.rxlib; then
LD_RXLIB1="ld -G"
# LD_RXLIB1="${CC} -Wl,-G"
SHLPRE="lib"
SHLPST=".so"
else
LD_RXLIB1=""
SHLPRE=""
SHLPST=""
fi
fi
fi
rm -f conftest*
])dnl
dnl ---------------------------------------------------------------------------
dnl Determine how to build shared libraries etc..
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_SHARED_LIBRARY],
[
AC_REQUIRE([MH_SHLPST])
dnl
dnl If compiler is gcc, then flags should be the same for all platforms
dnl (just guessing on this)
dnl
AIX_DYN="no"
BEOS_DYN="no"
SHLFILE="$1"
SHLFILES="$*"
RXPACKEXPORTS=""
SHLPRE="lib"
LD_RXLIB1=""
AC_REQUIRE([AC_CANONICAL_SYSTEM])
case "$target" in
*hp-hpux*)
SYS_DEFS="-D_HPUX_SOURCE"
LD_RXLIB1="ld -b -q -n"
;;
*ibm-aix*)
SYS_DEFS="-D_ALL_SOURCE -DAIX"
AIX_DYN="yes"
DYN_COMP="-DDYNAMIC"
LD_RXLIB1="ld -bnoentry -bM:SRE"
RXPACKEXPORTS="-bE:$SHLFILE.exp"
RXPACKEXP="$SHLFILE.exp"
;;
*dec-osf*)
if test "$ac_cv_prog_CC" = "gcc"; then
SYS_DEFS="-D_POSIX_SOURCE -D_XOPEN_SOURCE"
else
SYS_DEFS="-D_POSIX_SOURCE -D_XOPEN_SOURCE -Olimit 800"
fi
LD_RXLIB1="ld -shared"
;;
*sequent-dynix*|*esix*|*dgux*)
LD_RXLIB1="ld -G"
;;
*solaris*)
if test "$ac_cv_prog_CC" = "gcc"; then
LD_RXLIB1="gcc -shared"
else
LD_RXLIB1="ld -G"
fi
;;
sparc*sunos*)
SYS_DEFS="-DSUNOS -DSUNOS_STRTOD_BUG"
LD_RXLIB1="ld"
;;
*linux*|*atheos*|*nto-qnx*)
LD_RXLIB1="${CC} -shared"
;;
*freebsd*)
LD_RXLIB1="ld -Bdynamic -Bshareable"
;;
*pc-sco*)
LD_RXLIB1="ld -dy -G"
;;
*beos*)
LD_RXLIB1="${CC} -Wl,-shared -nostart -Xlinker -soname=\$(@)"
BEOS_DYN="yes"
;;
*qnx*)
SHLPRE=""
DYN_COMP="-Q" # force no check for dynamic loading
SHLFILE=""
;;
*cygwin)
SHLPRE=""
DYN_COMP="-DDYNAMIC"
LD_RXLIB1="dllwrap --def \$(srcdir)/../win32/pdcurses.def --target i386-cygwin32 --dllname \$(@)"
# cygwininstall target MUST install the shared library itself because
# it puts it into $(bindir) not $(libdir) as all other platforms
;;
*darwin*)
DYN_COMP="-fno-common"
LD_RXLIB1="${CC} -flat_namespace -undefined suppress -dynamiclib -install_name=\$(@)"
;;
*)
;;
esac
dnl determine what switches our compiler uses for building objects
dnl suitable for inclusion in shared libraries
dnl Only call this if DYN_COMP is not set. If we have set DYN_COMP
dnl above, then we know how to compile AND link for dynamic libraries
if test "$DYN_COMP" = ""; then
AC_MSG_CHECKING(compiler flags for a dynamic object)
cat > conftest.$ac_ext <<EOF
dnl [#]line __oline__ "[$]0"
[#]line __oline__ "configure"
int a=0
EOF
DYN_COMP=""
mh_cv_stop=no
save_cflags="$CFLAGS"
mh_cv_flags="-fPIC -KPIC +Z"
for a in $mh_cv_flags; do
CFLAGS="-c $a"
mh_compile='${CC-cc} -c $CFLAGS conftest.$ac_ext > conftest.tmp 2>&1'
if AC_TRY_EVAL(mh_compile); then
DYN_COMP=""
else
slash="\\"
mh_dyncomp="`egrep -c $slash$a conftest.tmp`"
if test "$mh_dyncomp" = "0"; then
DYN_COMP="$a -DDYNAMIC"
AC_MSG_RESULT($a)
break
else
DYN_COMP=""
fi
fi
done
if test "$DYN_COMP" = ""; then
AC_MSG_RESULT(none of $mh_cv_flags supported)
fi
if test "$LD_RXLIB1" = ""; then
MH_HOWTO_DYN_LINK()
fi
CFLAGS=$save_cflags
rm -f conftest.*
fi
SHL_TARGETS=""
if test "$AIX_DYN" = "yes"; then
aix_exports="config.exports.aix"
echo "" > $aix_exports
fi
if test "$ac_cv_header_dl_h" = "yes" -o "$ac_cv_header_dlfcn_h" = "yes" -o "$AIX_DYN" = "yes" -o "$BEOS_DYN" = "yes" -o "$DLFCNINCDIR" != "" -o "$DLFCNLIBDIR" != ""; then
EXPS="1,2,3,4,5,6,7,8,9"
for a in $SHLFILES
do
SHL_TARGETS="${SHL_TARGETS} ${SHLPRE}${a}${SHLPST}"
this=`echo $EXPS | cut -d, -f1`
EXPS=`echo $EXPS | cut -d, -f2-`
if test "$AIX_DYN" = "yes"; then
echo "RXPACKEXP$this=$a.exp" >> $aix_exports
echo "RXPACKEXPORTS$this=-bE:$a.exp" >> $aix_exports
fi
done
fi
AC_SUBST(DYN_COMP)
AC_SUBST(LIBS)
AC_SUBST(LD_RXLIB1)
AC_SUBST(SHLPRE)
AC_SUBST(SHLPST)
AC_SUBST(SHL_TARGETS)
AC_SUBST(O2SAVE)
AC_SUBST(CC2O)
AC_SUBST(SAVE2O)
AC_SUBST(RXPACKEXPORTS)
])dnl
dnl ---------------------------------------------------------------------------
dnl Check if C compiler supports -c -o file.ooo
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_CC_O],
[
AC_MSG_CHECKING(whether $CC understand -c and -o together)
set dummy $CC; ac_cc="`echo [$]2 |
changequote(, )dnl
sed -e 's/[^a-zA-Z0-9_]/_/g' -e 's/^[0-9]/_/'`"
changequote([, ])dnl
AC_CACHE_VAL(ac_cv_prog_cc_${ac_cc}_c_o,
[echo 'foo(){}' > conftest.c
# We do the test twice because some compilers refuse to overwrite an
# existing .o file with -o, though they will create one.
eval ac_cv_prog_cc_${ac_cc}_c_o=no
ac_try='${CC-cc} -c conftest.c -o conftest.ooo 1>&AC_FD_CC'
if AC_TRY_EVAL(ac_try) && test -f conftest.ooo && AC_TRY_EVAL(ac_try);
then
ac_try='${CC-cc} -c conftest.c -o conftest.ooo 1>&AC_FD_CC'
if AC_TRY_EVAL(ac_try) && test -f conftest.ooo && AC_TRY_EVAL(ac_try);
then
eval ac_cv_prog_cc_${ac_cc}_c_o=yes
fi
fi
rm -f conftest*
])dnl
if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = yes"; then
O2SAVE=""
SAVE2O=""
CC2O="-o $"'@'
AC_MSG_RESULT(yes)
else
O2SAVE="-mv \`basename "$'@'" .sho\`.o \`basename "$'@'" .sho\`.o.save;"
SAVE2O="-mv \`basename "$'@'" .sho\`.o "$'@'"; mv \`basename "$'@'" .sho\`.o.save \`basename "$'@'" .sho\`.o"
CC2O=""
AC_MSG_RESULT(no)
fi
])
dnl ---------------------------------------------------------------------------
dnl Determines the file extension for shared libraries
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_SHLPST],
[
AC_MSG_CHECKING(shared library extension)
SHLPST=".so"
AC_REQUIRE([AC_CANONICAL_SYSTEM])
case "$target" in
*hp-hpux*)
SHLPST=".sl"
;;
*ibm-aix*)
SHLPST=".a"
;;
*qnx*)
SHLPST=""
;;
*cygwin*)
SHLPST=".dll"
;;
*darwin*)
SHLPST=".dylib"
;;
esac
AC_SUBST(SHLPST)
AC_MSG_RESULT($SHLPST)
])
dnl ---------------------------------------------------------------------------
dnl Determine the system limit for number of signals
dnl ---------------------------------------------------------------------------
AC_DEFUN([MH_CHECK_MAX_SIGNALS],
[
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $SYS_DEFS"
AC_MSG_CHECKING(for maximum signal specifier:)
AC_CACHE_VAL(mh_cv_max_signals,
mh_found="no"
for mh_sigs in $1; do
AC_TRY_COMPILE([#include <signal.h>],
[return $mh_sigs;],
mh_found="yes"; mh_cv_max_signals="$mh_sigs" )
if test "$mh_found" = "yes"; then
break;
fi
done)
CPPFLAGS="$save_CPPFLAGS"
if test "$mh_found" = "no"; then
AC_MSG_ERROR(Cannot find a system limit for number of signals. PDCurses cannot be configured on this machine.)
else
AC_DEFINE_UNQUOTED(PDC_MAX_SIGNALS,$mh_cv_max_signals)
AC_MSG_RESULT($mh_cv_max_signals)
fi
])dnl

View File

@@ -0,0 +1,133 @@
/* config.h.in. Generated from configure.ac by autoheader. */
/* Define if you have the <DECkeySym.h> header file */
#undef HAVE_DECKEYSYM_H
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <dl.h> header file. */
#undef HAVE_DL_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `poll' function. */
#undef HAVE_POLL
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define if you have the <Sunkeysym.h> header file */
#undef HAVE_SUNKEYSYM_H
/* Define to 1 if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP
/* Define to 1 if you have the `vsnprintf' function. */
#undef HAVE_VSNPRINTF
/* Define to 1 if you have the `vsscanf' function. */
#undef HAVE_VSSCANF
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_BEGIN
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_DELETE
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_DOWN
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_END
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_HOME
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_INSERT
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_LEFT
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_NEXT
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_PRIOR
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_RIGHT
/* Define if you have this defined in <keysym.h> */
#undef HAVE_XK_KP_UP
/* Define if you have the <xpm.h> header file */
#undef HAVE_XPM_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define as the system defined limit for number of signals */
#undef PDC_MAX_SIGNALS
/* Define as the return type of signal handlers (`int' or `void'). */
#undef RETSIGTYPE
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
/* Define if you want to use neXtaw library */
#undef USE_NEXTAW
/* Define if you want to use Xaw3d library */
#undef USE_XAW3D
/* Define XPointer is typedefed in X11/Xlib.h */
#undef XPOINTER_TYPEDEFED

View File

@@ -0,0 +1,285 @@
dnl $Id: configure.ac,v 1.35 2008/07/21 12:19:21 wmcbrine Exp $
dnl Process this file with autoconf to produce a configure script.
AC_INIT([PDCurses], [3.4], [wmcbrine@users.sf.net], [PDCurses])
AC_CONFIG_SRCDIR([curspriv.h])
AC_SUBST(prefix)
AC_PROG_CC
AC_CONFIG_HEADER(config.h)
dnl Checks for system first
AC_CANONICAL_SYSTEM([])
mymakefile="Makefile"
on_qnx=no
case "$target" in
*hp-hpux*)
SYS_DEFS="-D_HPUX_SOURCE"
;;
*ibm-aix*)
SYS_DEFS="-D_ALL_SOURCE"
mymakefile="Makefile.aix"
;;
*dec-osf*)
SYS_DEFS="-D_XOPEN_SOURCE_EXTENDED"
;;
*pc-sco*)
SYS_DEFS="-UM_XENIX -b elf"
;;
*qnx*)
on_qnx=yes
SYS_DEFS="-Q"
;;
*)
;;
esac
AC_SUBST(SYS_DEFS)
MH_CHECK_MAX_SIGNALS(NSIG __sys_nsig)
dnl Check for other programs.
AC_PROG_RANLIB
AC_PROG_INSTALL
AC_PROG_MAKE_SET
dnl ensure that the system has System V IPC support
MH_IPC
if test $ac_cv_header_stdc != yes; then
AC_MSG_ERROR([Need ANSI C headers])
fi
dnl Checks for libraries.
AC_CHECK_HEADERS(fcntl.h \
sys/time.h \
sys/select.h \
dlfcn.h \
dl.h
)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_TIME
MH_CHECK_LIB(socket nls)
AC_SUBST(MH_EXTRA_LIBS)
MH_CHECK_CC_O
dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(vsscanf usleep poll vsnprintf)
dnl Check for X includes and X libraries
AC_PATH_X
MH_CHECK_X_INC
MH_CHECK_X_LIB
MH_CHECK_X_HEADERS(DECkeysym.h Sunkeysym.h xpm.h)
MH_CHECK_X_KEYDEFS(XK_KP_Delete XK_KP_Insert XK_KP_End XK_KP_Down XK_KP_Next \
XK_KP_Left XK_KP_Right XK_KP_Home XK_KP_Up XK_KP_Prior XK_KP_Begin)
MH_CHECK_X_TYPEDEF(XPointer)
dnl
dnl extra for xpm library
if test $ac_cv_header_xpm_h = yes; then
MH_XLIBS="$MH_XLIBS -lXpm"
fi
dnl ---------- allow --enable-debug to compile in debug mode ---------
AC_ARG_ENABLE(debug,
[ --enable-debug turn on debugging],
[with_debug=$enableval],
[with_debug=no],
)
cflags_g="`echo $CFLAGS | grep -c '\-g'`"
cflags_O="`echo $CFLAGS | grep -c '\-O'`"
if test "$with_debug" = yes; then
if test "$cflags_g" = "0"; then
CFLAGS="${CFLAGS} -g"
fi
if test "$cflags_O" != "0"; then
CFLAGS="`echo ${CFLAGS} | sed -e s/-O.//`"
fi
CFLAGS="${CFLAGS} -DPDCDEBUG"
else
if test "$cflags_O" = "0"; then
CFLAGS="${CFLAGS} -O"
fi
if test "$cflags_g" != "0"; then
CFLAGS="`echo ${CFLAGS} | sed -e s/-g//`"
fi
fi
if test "$ac_cv_prog_CC" = "gcc"; then
if test "$with_debug" = yes; then
CFLAGS="${CFLAGS} -Wall"
else
CFLAGS="-O2 -Wall -fomit-frame-pointer"
fi
fi
if test "$on_qnx" = yes; then
if test "$with_debug" = yes; then
CFLAGS="-g"
else
CFLAGS="-Otax"
fi
fi
dnl --------------- check for wide character support -----------------
dnl allow --enable-widec to include wide character support
AC_ARG_ENABLE(widec,
[ --enable-widec include support for wide characters],
[with_widec=$enableval],
[with_widec=no],
)
if test "$with_widec" = yes; then
SYS_DEFS="$SYS_DEFS -DPDC_WIDE"
fi
dnl -------------------- check for XIM support -----------------------
dnl allow --enable-xim to include XIM support
AC_ARG_ENABLE(xim,
[ --enable-xim include support for XIM],
[with_xim=$enableval],
[with_xim=no],
)
if test "$with_xim" = yes; then
SYS_DEFS="$SYS_DEFS -DPDC_XIM"
fi
dnl ------------------------ force UTF-8? ----------------------------
dnl allow --enable-force-utf8 to override locale settings
AC_ARG_ENABLE(force-utf8,
[ --enable-force-utf8 override locale settings; use UTF-8],
[force_utf8=$enableval],
[force_utf8=no],
)
if test "$force_utf8" = yes; then
SYS_DEFS="$SYS_DEFS -DPDC_FORCE_UTF8"
fi
dnl ----------------- check for Purify support -----------------------
dnl allow --enable-purify to enable linking with Purify
AC_ARG_ENABLE(purify,
[ --enable-purify link with Purify (TM)],
[with_purify=$enableval],
[with_purify=no],
)
if test "$with_purify" = yes; then
PURIFY="purify"
else
PURIFY=""
fi
AC_SUBST(PURIFY)
dnl --------------------- check for Xaw3d library --------------------
dnl allow --with-xaw3d to link with PDCurses
AC_ARG_WITH(xaw3d,
[ --with-xaw3d link with Xaw3d],
[with_xaw3d=$withval],
[with_xaw3d=no],
)
if test "$with_xaw3d" = yes; then
AC_DEFINE([USE_XAW3D], [1],
[Define if you want to use Xaw3d library]
)
fi
dnl --------------------- check for neXtaw library -------------------
dnl allow --with-nextaw to link with PDCurses
AC_ARG_WITH(nextaw,
[ --with-nextaw link with neXtaw],
[with_nextaw=$withval],
[with_nextaw=no],
)
if test "$with_nextaw" = yes; then
AC_DEFINE([USE_NEXTAW], [1],
[Define if you want to use neXtaw library]
)
fi
dnl -------------- check how to make shared libraries ----------------
dnl Force the ability of shared library usage
MH_SHARED_LIBRARY(XCurses)
AC_CONFIG_FILES([Makefile x11/$mymakefile x11/xcurses-config])
AC_OUTPUT
case "$target" in
*ibm-aix*)
mv x11/Makefile.aix x11/Makefile
AC_MSG_RESULT(renaming x11/Makefile.aix to x11/Makefile)
;;
*)
;;
esac
AC_DEFINE([PDC_MAX_SIGNALS], [],
[Define as the system defined limit for number of signals]
)
AC_DEFINE([HAVE_DECKEYSYM_H], [],
[Define if you have the <DECkeySym.h> header file]
)
AC_DEFINE([HAVE_SUNKEYSYM_H], [],
[Define if you have the <Sunkeysym.h> header file]
)
AC_DEFINE([HAVE_XPM_H], [],
[Define if you have the <xpm.h> header file]
)
AC_DEFINE([HAVE_XK_KP_DELETE], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_INSERT], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_END], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_DOWN], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_NEXT], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_LEFT], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_RIGHT], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_HOME], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_UP], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_PRIOR], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([HAVE_XK_KP_BEGIN], [],
[Define if you have this defined in <keysym.h>]
)
AC_DEFINE([USE_XAW3D], [],
[Define if you want to use Xaw3d library]
)
AC_DEFINE([USE_NEXTAW], [],
[Define if you want to use neXtaw library]
)
AC_DEFINE([XPOINTER_TYPEDEFED], [],
[Define XPointer is typedefed in X11/Xlib.h]
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
/* Public Domain Curses */
/* $Id: curspriv.h,v 1.158 2008/07/13 16:08:16 wmcbrine Exp $ */
/* Private definitions and declarations for use within PDCurses.
These should generally not be referenced by applications. */
#ifndef __CURSES_INTERNALS__
#define __CURSES_INTERNALS__ 1
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#define CURSES_LIBRARY
#include <curses.h>
#if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \
defined(__CYGWIN32__) || defined(__MINGW32__) || \
defined(__WATCOMC__) || defined(__PACIFIC__)
# ifndef HAVE_VSSCANF
# define HAVE_VSSCANF /* have vsscanf() */
# endif
#endif
#if defined(__CYGWIN32__) || defined(__MINGW32__) || \
defined(__LCC__) || defined(__WATCOMC__)
# ifndef HAVE_VSNPRINTF
# define HAVE_VSNPRINTF /* have vsnprintf() */
# endif
#endif
#if defined(_MSC_VER) && defined(_WIN32) && !defined(_CRT_SECURE_NO_DEPRECATE)
# define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */
#endif
/*----------------------------------------------------------------------*/
typedef struct /* structure for ripped off lines */
{
int line;
int (*init)(WINDOW *, int);
} RIPPEDOFFLINE;
/* Window properties */
#define _SUBWIN 0x01 /* window is a subwindow */
#define _PAD 0x10 /* X/Open Pad. */
#define _SUBPAD 0x20 /* X/Open subpad. */
/* Miscellaneous */
#define _NO_CHANGE -1 /* flags line edge unchanged */
#define _ECHAR 0x08 /* Erase char (^H) */
#define _DWCHAR 0x17 /* Delete Word char (^W) */
#define _DLCHAR 0x15 /* Delete Line char (^U) */
extern WINDOW *pdc_lastscr;
extern bool pdc_trace_on; /* tracing flag */
extern bool pdc_color_started;
extern unsigned long pdc_key_modifiers;
extern MOUSE_STATUS pdc_mouse_status;
/*----------------------------------------------------------------------*/
/* Platform implementation functions */
void PDC_beep(void);
bool PDC_can_change_color(void);
int PDC_color_content(short, short *, short *, short *);
bool PDC_check_key(void);
int PDC_curs_set(int);
void PDC_flushinp(void);
int PDC_get_columns(void);
int PDC_get_cursor_mode(void);
int PDC_get_key(void);
int PDC_get_rows(void);
void PDC_gotoyx(int, int);
int PDC_init_color(short, short, short, short);
void PDC_init_pair(short, short, short);
int PDC_modifiers_set(void);
int PDC_mouse_set(void);
void PDC_napms(int);
int PDC_pair_content(short, short *, short *);
void PDC_reset_prog_mode(void);
void PDC_reset_shell_mode(void);
int PDC_resize_screen(int, int);
void PDC_restore_screen_mode(int);
void PDC_save_screen_mode(int);
void PDC_scr_close(void);
void PDC_scr_free(void);
int PDC_scr_open(int, char **);
void PDC_set_keyboard_binary(bool);
void PDC_transform_line(int, int, int, const chtype *);
const char *PDC_sysname(void);
/* Internal cross-module functions */
void PDC_init_atrtab(void);
WINDOW *PDC_makelines(WINDOW *);
WINDOW *PDC_makenew(int, int, int, int);
int PDC_mouse_in_slk(int, int);
void PDC_slk_free(void);
void PDC_slk_initialize(void);
void PDC_sync(WINDOW *);
#ifdef PDC_WIDE
int PDC_mbtowc(wchar_t *, const char *, size_t);
size_t PDC_mbstowcs(wchar_t *, const char *, size_t);
size_t PDC_wcstombs(char *, const wchar_t *, size_t);
#endif
#ifdef PDCDEBUG
# define PDC_LOG(x) if (pdc_trace_on) PDC_debug x
# define RCSID(x) static const char *rcsid = x;
#else
# define PDC_LOG(x)
# define RCSID(x)
#endif
/* Internal macros for attributes */
#ifdef CHTYPE_LONG
# define PDC_COLOR_PAIRS 256
#else
# define PDC_COLOR_PAIRS 32
#endif
#ifndef max
# define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
# define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor)
#define PDC_CLICK_PERIOD 150 /* time to wait for a click, if
not set by mouseinterval() */
#endif /* __CURSES_INTERNALS__*/

View File

@@ -0,0 +1,25 @@
PDCurses Demos
==============
This directory contains demonstration programs to show and test the
capabilities of curses libraries. Some of them predate PDCurses,
PCcurses or even pcurses/ncurses. Although some PDCurses-specific code
has been added, all programs remain portable to other implementations
(at a minimum, to ncurses).
Building
--------
The demos are built by the platform-specific makefiles, in the platform
directories. Alternatively, you can build them manually, individually,
and link with any curses library; e.g., "cc -lcurses -orain rain.c".
There are no dependencies besides curses and the standard C library, and
no configuration is needed.
Distribution Status
-------------------
Public Domain, except for rain.c and worm.c, which are under the ncurses
license (MIT-like).

View File

@@ -0,0 +1,148 @@
/* $Id: firework.c,v 1.25 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <stdio.h>
#include <signal.h>
#include <curses.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#define DELAYSIZE 200
void myrefresh(void);
void get_color(void);
void explode(int, int);
short color_table[] =
{
COLOR_RED, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
};
int main(int argc, char **argv)
{
int i, start, end, row, diff, flag, direction, seed;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
nodelay(stdscr, TRUE);
noecho();
if (has_colors())
start_color();
for (i = 0; i < 8; i++)
init_pair(i, color_table[i], COLOR_BLACK);
seed = time((time_t *)0);
srand(seed);
flag = 0;
while (getch() == ERR) /* loop until a key is hit */
{
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++)
{
mvaddstr(LINES - row, row * direction + start,
(direction < 0) ? "\\" : "/");
if (flag++)
{
myrefresh();
erase();
flag = 0;
}
}
if (flag++)
{
myrefresh();
flag = 0;
}
explode(LINES - row, diff * direction + start);
erase();
myrefresh();
}
endwin();
return 0;
}
void explode(int row, int col)
{
erase();
mvaddstr(row, col, "-");
myrefresh();
--col;
get_color();
mvaddstr(row - 1, col, " - ");
mvaddstr(row, col, "-+-");
mvaddstr(row + 1, col, " - ");
myrefresh();
--col;
get_color();
mvaddstr(row - 2, col, " --- ");
mvaddstr(row - 1, col, "-+++-");
mvaddstr(row, col, "-+#+-");
mvaddstr(row + 1, col, "-+++-");
mvaddstr(row + 2, col, " --- ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " +++ ");
mvaddstr(row - 1, col, "++#++");
mvaddstr(row, col, "+# #+");
mvaddstr(row + 1, col, "++#++");
mvaddstr(row + 2, col, " +++ ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " # ");
mvaddstr(row - 1, col, "## ##");
mvaddstr(row, col, "# #");
mvaddstr(row + 1, col, "## ##");
mvaddstr(row + 2, col, " # ");
myrefresh();
get_color();
mvaddstr(row - 2, col, " # # ");
mvaddstr(row - 1, col, "# #");
mvaddstr(row, col, " ");
mvaddstr(row + 1, col, "# #");
mvaddstr(row + 2, col, " # # ");
myrefresh();
}
void myrefresh(void)
{
napms(DELAYSIZE);
move(LINES - 1, COLS - 1);
refresh();
}
void get_color(void)
{
chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
attrset(COLOR_PAIR(rand() % 8) | bold);
}

View File

@@ -0,0 +1,425 @@
/*
* newdemo.c - A demo program using PDCurses. The program
* illustrates the use of colors for text output.
*
* Hacks by jbuhler@cs.washington.edu on 12/29/96
*
* $Id: newdemo.c,v 1.39 2008/07/13 16:08:17 wmcbrine Exp $
*/
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <curses.h>
#include <stdlib.h>
#include <time.h>
int WaitForUser(void);
int SubWinTest(WINDOW *);
int BouncingBalls(WINDOW *);
void trap(int);
/* An ASCII map of Australia */
char *AusMap[17] =
{
" A ",
" AA AA ",
" N.T. AAAAA AAAA ",
" AAAAAAAAAAA AAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAA Qld.",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA ",
" AAAAAAAAAAAAAAAAAAAAAAAAA N.S.W.",
"W.A. AAAAAAAAA AAAAAA Vic.",
" AAA S.A. AA",
" A Tas.",
""
};
/* Funny messages for the scroller */
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",
NULL
};
int WaitForUser(void)
{
chtype ch;
nodelay(stdscr, TRUE);
halfdelay(50);
ch = getch();
nodelay(stdscr, FALSE);
nocbreak(); /* Reset the halfdelay() value */
cbreak();
return (ch == '\033') ? ch : 0;
}
int SubWinTest(WINDOW *win)
{
WINDOW *swin1, *swin2, *swin3;
int w, h, sw, sh, bx, by;
wattrset(win, 0);
getmaxyx(win, h, w);
getbegyx(win, by, bx);
sw = w / 3;
sh = h / 3;
if ((swin1 = derwin(win, sh, sw, 3, 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;
init_pair(8, COLOR_RED, COLOR_BLUE);
wbkgd(swin1, COLOR_PAIR(8));
werase(swin1);
mvwaddstr(swin1, 0, 3, "Sub-window 1");
wrefresh(swin1);
init_pair(9, COLOR_CYAN, COLOR_MAGENTA);
wbkgd(swin2, COLOR_PAIR(9));
werase(swin2);
mvwaddstr(swin2, 0, 3, "Sub-window 2");
wrefresh(swin2);
init_pair(10, COLOR_YELLOW, COLOR_GREEN);
wbkgd(swin3, COLOR_PAIR(10));
werase(swin3);
mvwaddstr(swin3, 0, 3, "Sub-window 3");
wrefresh(swin3);
delwin(swin1);
delwin(swin2);
delwin(swin3);
WaitForUser();
return 0;
}
int BouncingBalls(WINDOW *win)
{
chtype c1, c2, c3, ball1, ball2, ball3;
int w, h, x1, y1, xd1, yd1, x2, y2, xd2, yd2, x3, y3, xd3, yd3, c;
curs_set(0);
wbkgd(win, COLOR_PAIR(1));
wrefresh(win);
wattrset(win, 0);
init_pair(11, COLOR_RED, COLOR_GREEN);
init_pair(12, COLOR_BLUE, COLOR_RED);
init_pair(13, COLOR_YELLOW, COLOR_WHITE);
ball1 = 'O' | COLOR_PAIR(11);
ball2 = '*' | COLOR_PAIR(12);
ball3 = '@' | COLOR_PAIR(13);
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 = -1;
xd3 = -1;
yd3 = 1;
nodelay(stdscr, TRUE);
while ((c = getch()) == ERR)
{
x1 += xd1;
if (x1 <= 1 || x1 >= w - 2)
xd1 *= -1;
y1 += yd1;
if (y1 <= 1 || y1 >= h - 2)
yd1 *= -1;
x2 += xd2;
if (x2 <= 1 || x2 >= w - 2)
xd2 *= -1;
y2 += yd2;
if (y2 <= 1 || y2 >= h - 2)
yd2 *= -1;
x3 += xd3;
if (x3 <= 1 || x3 >= w - 2)
xd3 *= -1;
y3 += yd3;
if (y3 <= 1 || y3 >= h - 2)
yd3 *= -1;
c1 = mvwinch(win, y1, x1);
c2 = mvwinch(win, y2, x2);
c3 = mvwinch(win, y3, x3);
mvwaddch(win, y1, x1, ball1);
mvwaddch(win, y2, x2, ball2);
mvwaddch(win, y3, x3, ball3);
wmove(win, 0, 0);
wrefresh(win);
mvwaddch(win, y1, x1, c1);
mvwaddch(win, y2, x2, c2);
mvwaddch(win, y3, x3, c3);
napms(150);
}
nodelay(stdscr, FALSE);
ungetch(c);
return 0;
}
/* Trap interrupt */
void trap(int sig)
{
if (sig == SIGINT)
{
endwin();
exit(0);
}
}
int main(int argc, char **argv)
{
WINDOW *win;
chtype save[80], ch;
int width, height, w, x, y, i, j, seed;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
start_color();
# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
use_default_colors();
# endif
cbreak();
noecho();
curs_set(0);
#if !defined(__TURBOC__) && !defined(OS2)
signal(SIGINT, trap);
#endif
noecho();
/* refresh stdscr so that reading from it will not cause it to
overwrite the other windows that are being created */
refresh();
/* Create a drawing window */
width = 48;
height = 15;
win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
if (win == NULL)
{
endwin();
return 1;
}
for (;;)
{
init_pair(1, COLOR_WHITE, COLOR_BLUE);
wbkgd(win, COLOR_PAIR(1));
werase(win);
init_pair(2, COLOR_RED, COLOR_RED);
wattrset(win, COLOR_PAIR(2));
box(win, ' ', ' ');
wrefresh(win);
wattrset(win, 0);
/* Do random output of a character */
ch = 'a';
nodelay(stdscr, TRUE);
for (i = 0; i < 5000; ++i)
{
x = rand() % (width - 2) + 1;
y = rand() % (height - 2) + 1;
mvwaddch(win, y, x, ch);
wrefresh(win);
if (getch() != ERR)
break;
if (i == 2000)
{
ch = 'b';
init_pair(3, COLOR_CYAN, COLOR_YELLOW);
wattrset(win, COLOR_PAIR(3));
}
}
nodelay(stdscr, FALSE);
SubWinTest(win);
/* Erase and draw green window */
init_pair(4, COLOR_YELLOW, COLOR_GREEN);
wbkgd(win, COLOR_PAIR(4));
wattrset(win, A_BOLD);
werase(win);
wrefresh(win);
/* Draw RED bounding box */
wattrset(win, COLOR_PAIR(2));
box(win, ' ', ' ');
wrefresh(win);
/* Display Australia map */
wattrset(win, A_BOLD);
i = 0;
while (*AusMap[i])
{
mvwaddstr(win, i + 1, 8, AusMap[i]);
wrefresh(win);
napms(100);
++i;
}
init_pair(5, COLOR_BLUE, COLOR_WHITE);
wattrset(win, COLOR_PAIR(5) | A_BLINK);
mvwaddstr(win, height - 2, 3,
" PDCurses 3.4 - DOS, OS/2, Win32, X11, SDL");
wrefresh(win);
/* Draw running messages */
init_pair(6, COLOR_BLACK, COLOR_WHITE);
wattrset(win, COLOR_PAIR(6));
w = width - 2;
nodelay(win, TRUE);
/* jbuhler's re-hacked scrolling messages */
for (j = 0; messages[j] != NULL; j++)
{
char *message = messages[j];
int msg_len = strlen(message);
int scroll_len = w + 2 * msg_len;
char *scrollbuf = malloc(scroll_len);
char *visbuf = scrollbuf + msg_len;
int stop = 0;
int i;
for (i = w + msg_len; i > 0; i--)
{
memset(visbuf, ' ', w);
strncpy(scrollbuf + i, message, msg_len);
mvwaddnstr(win, height / 2, 1, visbuf, w);
wrefresh(win);
if (wgetch(win) != ERR)
{
flushinp();
stop = 1;
break;
}
napms(100);
}
free(scrollbuf);
if (stop)
break;
}
j = 0;
/* Draw running 'A's across in RED */
init_pair(7, COLOR_RED, COLOR_GREEN);
wattron(win, COLOR_PAIR(7));
for (i = 2; i < width - 4; ++i)
{
ch = mvwinch(win, 5, i);
save[j++] = ch;
ch = ch & 0x7f;
mvwaddch(win, 5, i, ch);
}
wrefresh(win);
/* Put a message up; wait for a key */
i = height - 2;
wattrset(win, COLOR_PAIR(5));
mvwaddstr(win, i, 3,
" Type a key to continue or ESC to quit ");
wrefresh(win);
if (WaitForUser() == '\033')
break;
/* Restore the old line */
wattrset(win, 0);
for (i = 2, j = 0; i < width - 4; ++i)
mvwaddch(win, 5, i, save[j++]);
wrefresh(win);
BouncingBalls(win);
/* BouncingBalls() leaves a keystroke in the queue */
if (WaitForUser() == '\033')
break;
}
endwin();
return 0;
}

View File

@@ -0,0 +1,285 @@
/* $Id: ptest.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <panel.h>
#include <stdlib.h>
PANEL *p1, *p2, *p3, *p4, *p5;
WINDOW *w4, *w5;
long nap_msec = 1;
char *mod[] =
{
"test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST "
};
void pflush(void)
{
update_panels();
doupdate();
}
void backfill(void)
{
int y, x;
erase();
for (y = 0; y < LINES - 1; y++)
for (x = 0; x < COLS; x++)
printw("%d", (y + x) % 10);
}
void wait_a_while(long msec)
{
int c;
if (msec != 1)
timeout(msec);
c = getch();
if (c == 'q')
{
endwin();
exit(1);
}
}
void saywhat(const char *text)
{
mvprintw(LINES - 1, 0, "%-20.20s", text);
}
/* mkpanel - alloc a win and panel and associate them */
PANEL *mkpanel(int rows, int cols, int tly, int tlx)
{
WINDOW *win = newwin(rows, cols, tly, tlx);
PANEL *pan = (PANEL *)0;
if (win)
{
pan = new_panel(win);
if (!pan)
delwin(win);
}
return pan;
}
void rmpanel(PANEL *pan)
{
WINDOW *win = pan->win;
del_panel(pan);
delwin(win);
}
void fill_panel(PANEL *pan)
{
WINDOW *win = pan->win;
char num = *((char *)pan->user + 1);
int y, x, maxy, maxx;
box(win, 0, 0);
mvwprintw(win, 1, 1, "-pan%c-", num);
getmaxyx(win, maxy, maxx);
for (y = 2; y < maxy - 1; y++)
for (x = 1; x < maxx - 1; x++)
mvwaddch(win, y, x, num);
}
int main(int argc, char **argv)
{
int itmp, y;
if (argc > 1 && atol(argv[1]))
nap_msec = atol(argv[1]);
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
backfill();
for (y = 0; y < 5; y++)
{
p1 = mkpanel(10, 10, 0, 0);
set_panel_userptr(p1, "p1");
p2 = mkpanel(14, 14, 5, 5);
set_panel_userptr(p2, "p2");
p3 = mkpanel(6, 8, 12, 12);
set_panel_userptr(p3, "p3");
p4 = mkpanel(10, 10, 10, 30);
w4 = panel_window(p4);
set_panel_userptr(p4, "p4");
p5 = mkpanel(10, 10, 13, 37);
w5 = panel_window(p5);
set_panel_userptr(p5, "p5");
fill_panel(p1);
fill_panel(p2);
fill_panel(p3);
fill_panel(p4);
fill_panel(p5);
hide_panel(p4);
hide_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("h3 s1 s2 s4 s5;");
move_panel(p1, 0, 0);
hide_panel(p3);
show_panel(p1);
show_panel(p2);
show_panel(p4);
show_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("s1;");
show_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("s2;");
show_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("m2;");
move_panel(p2, 10, 10);
pflush();
wait_a_while(nap_msec);
saywhat("s3;");
show_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("m3;");
move_panel(p3, 5, 5);
pflush();
wait_a_while(nap_msec);
saywhat("b3;");
bottom_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("s4;");
show_panel(p4);
pflush();
wait_a_while(nap_msec);
saywhat("s5;");
show_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("t3;");
top_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("t1;");
top_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("t2;");
top_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("t3;");
top_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("t4;");
top_panel(p4);
pflush();
wait_a_while(nap_msec);
for (itmp = 0; itmp < 6; itmp++)
{
saywhat("m4;");
mvwaddstr(w4, 3, 1, mod[itmp]);
move_panel(p4, 4, itmp * 10);
mvwaddstr(w5, 4, 1, mod[itmp]);
pflush();
wait_a_while(nap_msec);
saywhat("m5;");
mvwaddstr(w4, 4, 1, mod[itmp]);
move_panel(p5, 7, itmp * 10 + 6);
mvwaddstr(w5, 3, 1, mod[itmp]);
pflush();
wait_a_while(nap_msec);
}
saywhat("m4;");
move_panel(p4, 4, itmp * 10);
pflush();
wait_a_while(nap_msec);
saywhat("t5;");
top_panel(p5);
pflush();
wait_a_while(nap_msec);
saywhat("t2;");
top_panel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("t1;");
top_panel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("d2;");
rmpanel(p2);
pflush();
wait_a_while(nap_msec);
saywhat("h3;");
hide_panel(p3);
pflush();
wait_a_while(nap_msec);
saywhat("d1;");
rmpanel(p1);
pflush();
wait_a_while(nap_msec);
saywhat("d4; ");
rmpanel(p4);
pflush();
wait_a_while(nap_msec);
saywhat("d5; ");
rmpanel(p5);
pflush();
wait_a_while(nap_msec);
if (nap_msec == 1)
break;
nap_msec = 100L;
}
endwin();
return 0;
} /* end of main */

View File

@@ -0,0 +1,159 @@
/****************************************************************************
* 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. *
****************************************************************************/
/* $Id: rain.c,v 1.11 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <stdlib.h>
#include <time.h>
/* rain 11/3/1980 EPS/CITHEP */
static int next_j(int j)
{
if (j == 0)
j = 4;
else
--j;
if (has_colors())
{
int z = rand() % 3;
chtype color = COLOR_PAIR(z);
if (z)
color |= A_BOLD;
attrset(color);
}
return j;
}
int main(int argc, char *argv[])
{
int x, y, j, r, c, seed;
static int xpos[5], ypos[5];
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
if (has_colors())
{
int bg = COLOR_BLACK;
start_color();
#if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
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);
keypad(stdscr, TRUE);
r = LINES - 4;
c = COLS - 4;
for (j = 5; --j >= 0;)
{
xpos[j] = rand() % c + 2;
ypos[j] = rand() % r + 2;
}
for (j = 0;;)
{
x = rand() % c + 2;
y = rand() % r + 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();
return EXIT_SUCCESS;
case 's':
nodelay(stdscr, FALSE);
break;
case ' ':
nodelay(stdscr, TRUE);
#ifdef KEY_RESIZE
break;
case KEY_RESIZE:
# ifdef PDCURSES
resize_term(0, 0);
erase();
# endif
r = LINES - 4;
c = COLS - 4;
#endif
}
napms(50);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,821 @@
/********************************* tui.c ************************************/
/*
* 'textual user interface'
*
* $Id: tui.c,v 1.34 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*/
#include <ctype.h>
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tui.h"
void statusmsg(char *);
int waitforkey(void);
void rmerror(void);
#if defined(__unix) && !defined(__DJGPP__)
#include <unistd.h>
#endif
#ifdef A_COLOR
# define TITLECOLOR 1 /* color pair indices */
# define MAINMENUCOLOR (2 | A_BOLD)
# define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE)
# define SUBMENUCOLOR (4 | A_BOLD)
# define SUBMENUREVCOLOR (5 | A_BOLD | A_REVERSE)
# define BODYCOLOR 6
# define STATUSCOLOR (7 | A_BOLD)
# define INPUTBOXCOLOR 8
# define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE)
#else
# define TITLECOLOR 0 /* color pair indices */
# define MAINMENUCOLOR (A_BOLD)
# define MAINMENUREVCOLOR (A_BOLD | A_REVERSE)
# define SUBMENUCOLOR (A_BOLD)
# define SUBMENUREVCOLOR (A_BOLD | A_REVERSE)
# define BODYCOLOR 0
# define STATUSCOLOR (A_BOLD)
# define INPUTBOXCOLOR 0
# define EDITBOXCOLOR (A_BOLD | A_REVERSE)
#endif
#define th 1 /* title window height */
#define mh 1 /* main menu height */
#define sh 2 /* status window height */
#define bh (LINES - th - mh - sh) /* body window height */
#define bw COLS /* body window width */
/******************************* STATIC ************************************/
static WINDOW *wtitl, *wmain, *wbody, *wstat; /* title, menu, body, status win*/
static int nexty, nextx;
static int key = ERR, ch = ERR;
static bool quit = FALSE;
static bool incurses = FALSE;
#ifndef PDCURSES
static char wordchar(void)
{
return 0x17; /* ^W */
}
#endif
static char *padstr(char *s, int length)
{
static char buf[MAXSTRLEN];
char fmt[10];
sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length);
sprintf(buf, fmt, s);
return buf;
}
static char *prepad(char *s, int length)
{
int i;
char *p = s;
if (length > 0)
{
memmove((void *)(s + length), (const void *)s, strlen(s) + 1);
for (i = 0; i < length; i++)
*p++ = ' ';
}
return s;
}
static void rmline(WINDOW *win, int nr) /* keeps box lines intact */
{
mvwaddstr(win, nr, 1, padstr(" ", bw - 2));
wrefresh(win);
}
static void initcolor(void)
{
#ifdef A_COLOR
if (has_colors())
start_color();
/* foreground, background */
init_pair(TITLECOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
init_pair(MAINMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(MAINMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
init_pair(SUBMENUCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(SUBMENUREVCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
init_pair(BODYCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLUE);
init_pair(STATUSCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_CYAN);
init_pair(INPUTBOXCOLOR & ~A_ATTR, COLOR_BLACK, COLOR_CYAN);
init_pair(EDITBOXCOLOR & ~A_ATTR, COLOR_WHITE, COLOR_BLACK);
#endif
}
static void setcolor(WINDOW *win, chtype color)
{
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
#ifdef A_COLOR
attr &= ~A_REVERSE; /* ignore reverse, use colors instead! */
wattrset(win, COLOR_PAIR(color & A_CHARTEXT) | attr);
#else
attr &= ~A_BOLD; /* ignore bold, gives messy display on HP-UX */
wattrset(win, attr);
#endif
}
static void colorbox(WINDOW *win, chtype color, int hasbox)
{
int maxy;
#ifndef PDCURSES
int maxx;
#endif
chtype attr = color & A_ATTR; /* extract Bold, Reverse, Blink bits */
setcolor(win, color);
#ifdef A_COLOR
if (has_colors())
wbkgd(win, COLOR_PAIR(color & A_CHARTEXT) | (attr & ~A_REVERSE));
else
#endif
wbkgd(win, attr);
werase(win);
#ifdef PDCURSES
maxy = getmaxy(win);
#else
getmaxyx(win, maxy, maxx);
#endif
if (hasbox && (maxy > 2))
box(win, 0, 0);
touchwin(win);
wrefresh(win);
}
static void idle(void)
{
char buf[MAXSTRLEN];
time_t t;
struct tm *tp;
if (time (&t) == -1)
return; /* time not available */
tp = localtime(&t);
sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d",
tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900,
tp->tm_hour, tp->tm_min, tp->tm_sec);
mvwaddstr(wtitl, 0, bw - strlen(buf) - 2, buf);
wrefresh(wtitl);
}
static void menudim(menu *mp, int *lines, int *columns)
{
int n, l, mmax = 0;
for (n=0; mp->func; n++, mp++)
if ((l = strlen(mp->name)) > mmax) mmax = l;
*lines = n;
*columns = mmax + 2;
}
static void setmenupos(int y, int x)
{
nexty = y;
nextx = x;
}
static void getmenupos(int *y, int *x)
{
*y = nexty;
*x = nextx;
}
static int hotkey(const char *s)
{
int c0 = *s; /* if no upper case found, return first char */
for (; *s; s++)
if (isupper((unsigned char)*s))
break;
return *s ? *s : c0;
}
static void repaintmenu(WINDOW *wmenu, menu *mp)
{
int i;
menu *p = mp;
for (i = 0; p->func; i++, p++)
mvwaddstr(wmenu, i + 1, 2, p->name);
touchwin(wmenu);
wrefresh(wmenu);
}
static void repaintmainmenu(int width, menu *mp)
{
int i;
menu *p = mp;
for (i = 0; p->func; i++, p++)
mvwaddstr(wmain, 0, i * width, prepad(padstr(p->name, width - 1), 1));
touchwin(wmain);
wrefresh(wmain);
}
static void mainhelp(void)
{
#ifdef ALT_X
statusmsg("Use arrow keys and Enter to select (Alt-X to quit)");
#else
statusmsg("Use arrow keys and Enter to select");
#endif
}
static void mainmenu(menu *mp)
{
int nitems, barlen, old = -1, cur = 0, c, cur0;
menudim(mp, &nitems, &barlen);
repaintmainmenu(barlen, mp);
while (!quit)
{
if (cur != old)
{
if (old != -1)
{
mvwaddstr(wmain, 0, old * barlen,
prepad(padstr(mp[old].name, barlen - 1), 1));
statusmsg(mp[cur].desc);
}
else
mainhelp();
setcolor(wmain, MAINMENUREVCOLOR);
mvwaddstr(wmain, 0, cur * barlen,
prepad(padstr(mp[cur].name, barlen - 1), 1));
setcolor(wmain, MAINMENUCOLOR);
old = cur;
wrefresh(wmain);
}
switch (c = (key != ERR ? key : waitforkey()))
{
case KEY_DOWN:
case '\n': /* menu item selected */
touchwin(wbody);
wrefresh(wbody);
rmerror();
setmenupos(th + mh, cur * barlen);
curs_set(1);
(mp[cur].func)(); /* perform function */
curs_set(0);
switch (key)
{
case KEY_LEFT:
cur = (cur + nitems - 1) % nitems;
key = '\n';
break;
case KEY_RIGHT:
cur = (cur + 1) % nitems;
key = '\n';
break;
default:
key = ERR;
}
repaintmainmenu(barlen, mp);
old = -1;
break;
case KEY_LEFT:
cur = (cur + nitems - 1) % nitems;
break;
case KEY_RIGHT:
cur = (cur + 1) % nitems;
break;
case KEY_ESC:
mainhelp();
break;
default:
cur0 = cur;
do
{
cur = (cur + 1) % nitems;
} while ((cur != cur0) && (hotkey(mp[cur].name) != toupper(c)));
if (hotkey(mp[cur].name) == toupper(c))
key = '\n';
}
}
rmerror();
touchwin(wbody);
wrefresh(wbody);
}
static void cleanup(void) /* cleanup curses settings */
{
if (incurses)
{
delwin(wtitl);
delwin(wmain);
delwin(wbody);
delwin(wstat);
curs_set(1);
endwin();
incurses = FALSE;
}
}
/******************************* EXTERNAL **********************************/
void clsbody(void)
{
werase(wbody);
wmove(wbody, 0, 0);
}
int bodylen(void)
{
#ifdef PDCURSES
return getmaxy(wbody);
#else
int maxy, maxx;
getmaxyx(wbody, maxy, maxx);
return maxy;
#endif
}
WINDOW *bodywin(void)
{
return wbody;
}
void rmerror(void)
{
rmline(wstat, 0);
}
void rmstatus(void)
{
rmline(wstat, 1);
}
void titlemsg(char *msg)
{
mvwaddstr(wtitl, 0, 2, padstr(msg, bw - 3));
wrefresh(wtitl);
}
void bodymsg(char *msg)
{
waddstr(wbody, msg);
wrefresh(wbody);
}
void errormsg(char *msg)
{
beep();
mvwaddstr(wstat, 0, 2, padstr(msg, bw - 3));
wrefresh(wstat);
}
void statusmsg(char *msg)
{
mvwaddstr(wstat, 1, 2, padstr(msg, bw - 3));
wrefresh(wstat);
}
bool keypressed(void)
{
ch = wgetch(wbody);
return ch != ERR;
}
int getkey(void)
{
int c = ch;
ch = ERR;
#ifdef ALT_X
quit = (c == ALT_X); /* PC only ! */
#endif
return c;
}
int waitforkey(void)
{
do idle(); while (!keypressed());
return getkey();
}
void DoExit(void) /* terminate program */
{
quit = TRUE;
}
void domenu(menu *mp)
{
int y, x, nitems, barlen, mheight, mw, old = -1, cur = 0, cur0;
bool stop = FALSE;
WINDOW *wmenu;
curs_set(0);
getmenupos(&y, &x);
menudim(mp, &nitems, &barlen);
mheight = nitems + 2;
mw = barlen + 2;
wmenu = newwin(mheight, mw, y, x);
colorbox(wmenu, SUBMENUCOLOR, 1);
repaintmenu(wmenu, mp);
key = ERR;
while (!stop && !quit)
{
if (cur != old)
{
if (old != -1)
mvwaddstr(wmenu, old + 1, 1,
prepad(padstr(mp[old].name, barlen - 1), 1));
setcolor(wmenu, SUBMENUREVCOLOR);
mvwaddstr(wmenu, cur + 1, 1,
prepad(padstr(mp[cur].name, barlen - 1), 1));
setcolor(wmenu, SUBMENUCOLOR);
statusmsg(mp[cur].desc);
old = cur;
wrefresh(wmenu);
}
switch (key = ((key != ERR) ? key : waitforkey()))
{
case '\n': /* menu item selected */
touchwin(wbody);
wrefresh(wbody);
setmenupos(y + 1, x + 1);
rmerror();
key = ERR;
curs_set(1);
(mp[cur].func)(); /* perform function */
curs_set(0);
repaintmenu(wmenu, mp);
old = -1;
break;
case KEY_UP:
cur = (cur + nitems - 1) % nitems;
key = ERR;
break;
case KEY_DOWN:
cur = (cur + 1) % nitems;
key = ERR;
break;
case KEY_ESC:
case KEY_LEFT:
case KEY_RIGHT:
if (key == KEY_ESC)
key = ERR; /* return to prev submenu */
stop = TRUE;
break;
default:
cur0 = cur;
do
{
cur = (cur + 1) % nitems;
} while ((cur != cur0) &&
(hotkey(mp[cur].name) != toupper((int)key)));
key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR;
}
}
rmerror();
delwin(wmenu);
touchwin(wbody);
wrefresh(wbody);
}
void startmenu(menu *mp, char *mtitle)
{
initscr();
incurses = TRUE;
initcolor();
wtitl = subwin(stdscr, th, bw, 0, 0);
wmain = subwin(stdscr, mh, bw, th, 0);
wbody = subwin(stdscr, bh, bw, th + mh, 0);
wstat = subwin(stdscr, sh, bw, th + mh + bh, 0);
colorbox(wtitl, TITLECOLOR, 0);
colorbox(wmain, MAINMENUCOLOR, 0);
colorbox(wbody, BODYCOLOR, 0);
colorbox(wstat, STATUSCOLOR, 0);
if (mtitle)
titlemsg(mtitle);
cbreak(); /* direct input (no newline required)... */
noecho(); /* ... without echoing */
curs_set(0); /* hide cursor (if possible) */
nodelay(wbody, TRUE); /* don't wait for input... */
halfdelay(10); /* ...well, no more than a second, anyway */
keypad(wbody, TRUE); /* enable cursor keys */
scrollok(wbody, TRUE); /* enable scrolling in main window */
leaveok(stdscr, TRUE);
leaveok(wtitl, TRUE);
leaveok(wmain, TRUE);
leaveok(wstat, TRUE);
mainmenu(mp);
cleanup();
}
static void repainteditbox(WINDOW *win, int x, char *buf)
{
#ifndef PDCURSES
int maxy;
#endif
int maxx;
#ifdef PDCURSES
maxx = getmaxx(win);
#else
getmaxyx(win, maxy, maxx);
#endif
werase(win);
mvwprintw(win, 0, 0, "%s", padstr(buf, maxx));
wmove(win, 0, x);
wrefresh(win);
}
/*
weditstr() - edit string
Description:
The initial value of 'str' with a maximum length of 'field' - 1,
which is supplied by the calling routine, is editted. The user's
erase (^H), kill (^U) and delete word (^W) chars are interpreted.
The PC insert or Tab keys toggle between insert and edit mode.
Escape aborts the edit session, leaving 'str' unchanged.
Enter, Up or Down Arrow are used to accept the changes to 'str'.
NOTE: editstr(), mveditstr(), and mvweditstr() are macros.
Return Value:
Returns the input terminating character on success (Escape,
Enter, Up or Down Arrow) and ERR on error.
Errors:
It is an error to call this function with a NULL window pointer.
The length of the initial 'str' must not exceed 'field' - 1.
*/
int weditstr(WINDOW *win, char *buf, int field)
{
char org[MAXSTRLEN], *tp, *bp = buf;
bool defdisp = TRUE, stop = FALSE, insert = FALSE;
int cury, curx, begy, begx, oldattr;
WINDOW *wedit;
int c = 0;
if ((field >= MAXSTRLEN) || (buf == NULL) ||
((int)strlen(buf) > field - 1))
return ERR;
strcpy(org, buf); /* save original */
wrefresh(win);
getyx(win, cury, curx);
getbegyx(win, begy, begx);
wedit = subwin(win, 1, field, begy + cury, begx + curx);
oldattr = wedit->_attrs;
colorbox(wedit, EDITBOXCOLOR, 0);
keypad(wedit, TRUE);
curs_set(1);
while (!stop)
{
idle();
repainteditbox(wedit, bp - buf, buf);
switch (c = wgetch(wedit))
{
case ERR:
break;
case KEY_ESC:
strcpy(buf, org); /* restore original */
stop = TRUE;
break;
case '\n':
case KEY_UP:
case KEY_DOWN:
stop = TRUE;
break;
case KEY_LEFT:
if (bp > buf)
bp--;
break;
case KEY_RIGHT:
defdisp = FALSE;
if (bp - buf < (int)strlen(buf))
bp++;
break;
case '\t': /* TAB -- because insert
is broken on HPUX */
case KEY_IC: /* enter insert mode */
case KEY_EIC: /* exit insert mode */
defdisp = FALSE;
insert = !insert;
curs_set(insert ? 2 : 1);
break;
default:
if (c == erasechar()) /* backspace, ^H */
{
if (bp > buf)
{
memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
bp--;
}
}
else if (c == killchar()) /* ^U */
{
bp = buf;
*bp = '\0';
}
else if (c == wordchar()) /* ^W */
{
tp = bp;
while ((bp > buf) && (*(bp - 1) == ' '))
bp--;
while ((bp > buf) && (*(bp - 1) != ' '))
bp--;
memmove((void *)bp, (const void *)tp, strlen(tp) + 1);
}
else if (isprint(c))
{
if (defdisp)
{
bp = buf;
*bp = '\0';
defdisp = FALSE;
}
if (insert)
{
if ((int)strlen(buf) < field - 1)
{
memmove((void *)(bp + 1), (const void *)bp,
strlen(bp) + 1);
*bp++ = c;
}
}
else if (bp - buf < field - 1)
{
/* append new string terminator */
if (!*bp)
bp[1] = '\0';
*bp++ = c;
}
}
}
}
curs_set(0);
wattrset(wedit, oldattr);
repainteditbox(wedit, bp - buf, buf);
delwin(wedit);
return c;
}
WINDOW *winputbox(WINDOW *win, int nlines, int ncols)
{
WINDOW *winp;
int cury, curx, begy, begx;
getyx(win, cury, curx);
getbegyx(win, begy, begx);
winp = newwin(nlines, ncols, begy + cury, begx + curx);
colorbox(winp, INPUTBOXCOLOR, 1);
return winp;
}
int getstrings(char *desc[], char *buf[], int field)
{
WINDOW *winput;
int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0;
int c = 0;
bool stop = FALSE;
for (n = 0; desc[n]; n++)
if ((l = strlen(desc[n])) > mmax)
mmax = l;
nlines = n + 2; ncols = mmax + field + 4;
getyx(wbody, oldy, oldx);
getmaxyx(wbody, maxy, maxx);
winput = mvwinputbox(wbody, (maxy - nlines) / 2, (maxx - ncols) / 2,
nlines, ncols);
for (i = 0; i < n; i++)
mvwprintw(winput, i + 1, 2, "%s", desc[i]);
i = 0;
while (!stop)
{
switch (c = mvweditstr(winput, i+1, mmax+3, buf[i], field))
{
case KEY_ESC:
stop = TRUE;
break;
case KEY_UP:
i = (i + n - 1) % n;
break;
case '\n':
case '\t':
case KEY_DOWN:
if (++i == n)
stop = TRUE; /* all passed? */
}
}
delwin(winput);
touchwin(wbody);
wmove(wbody, oldy, oldx);
wrefresh(wbody);
return c;
}

View File

@@ -0,0 +1,67 @@
/*
* 'textual user interface'
*
* $Id: tui.h,v 1.11 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*/
#ifndef _TUI_H_
#define _TUI_H_
#include <curses.h>
#ifdef A_COLOR
#define A_ATTR (A_ATTRIBUTES ^ A_COLOR) /* A_BLINK, A_REVERSE, A_BOLD */
#else
#define A_ATTR (A_ATTRIBUTES) /* standard UNIX attributes */
#endif
#define MAXSTRLEN 256
#define KEY_ESC 0x1b /* Escape */
typedef void (*FUNC)(void);
typedef struct
{
char *name; /* item label */
FUNC func; /* (pointer to) function */
char *desc; /* function description */
} menu;
/* ANSI C function prototypes: */
void clsbody(void);
int bodylen(void);
WINDOW *bodywin(void);
void rmerror(void);
void rmstatus(void);
void titlemsg(char *msg);
void bodymsg(char *msg);
void errormsg(char *msg);
void statusmsg(char *msg);
bool keypressed(void);
int getkey(void);
int waitforkey(void);
void DoExit(void);
void startmenu(menu *mp, char *title);
void domenu(menu *mp);
int weditstr(WINDOW *win, char *buf, int field);
WINDOW *winputbox(WINDOW *win, int nlines, int ncols);
int getstrings(char *desc[], char *buf[], int field);
#define editstr(s,f) (weditstr(stdscr,s,f))
#define mveditstr(y,x,s,f) (move(y,x)==ERR?ERR:editstr(s,f))
#define mvweditstr(w,y,x,s,f) (wmove(w,y,x)==ERR?ERR:weditstr(w,s,f))
#define inputbox(l,c) (winputbox(stdscr,l,c))
#define mvinputbox(y,x,l,c) (move(y,x)==ERR?w:inputbox(l,c))
#define mvwinputbox(w,y,x,l,c) (wmove(w,y,x)==ERR?w:winputbox(w,l,c))
#endif

View File

@@ -0,0 +1,233 @@
/*
* $Id: tuidemo.c,v 1.22 2008/07/14 12:35:23 wmcbrine Exp $
*
* Author : P.J. Kunst <kunst@prl.philips.nl>
* Date : 25-02-93
*
* Purpose: This program demonstrates the use of the 'curses' library
* for the creation of (simple) menu-operated programs.
* In the PDCurses version, use is made of colors for the
* highlighting of subwindows (title bar, status bar etc).
*
* Acknowledgement: some ideas were borrowed from Mark Hessling's
* version of the 'testcurs' program.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include "tui.h"
/* change this if source at other location */
#ifdef XCURSES
# define FNAME "../demos/tui.c"
#else
# define FNAME "..\\demos\\tui.c"
#endif
/**************************** strings entry box ***************************/
void address(void)
{
char *fieldname[6] =
{
"Name", "Street", "City", "State", "Country", (char *)0
};
char *fieldbuf[5];
WINDOW *wbody = bodywin();
int i, field = 50;
for (i = 0; i < 5; i++)
fieldbuf[i] = calloc(1, field + 1);
if (getstrings(fieldname, fieldbuf, field) != KEY_ESC)
{
for (i = 0; fieldname[i]; i++)
wprintw(wbody, "%10s : %s\n",
fieldname[i], fieldbuf[i]);
wrefresh(wbody);
}
for (i = 0; i < 5; i++)
free(fieldbuf[i]);
}
/**************************** string entry box ****************************/
char *getfname(char *desc, char *fname, int field)
{
char *fieldname[2];
char *fieldbuf[1];
fieldname[0] = desc;
fieldname[1] = 0;
fieldbuf[0] = fname;
return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
}
/**************************** a very simple file browser ******************/
void showfile(char *fname)
{
int i, bh = bodylen();
FILE *fp;
char buf[MAXSTRLEN];
bool ateof = FALSE;
statusmsg("FileBrowser: Hit key to continue, Q to quit");
if ((fp = fopen(fname, "r")) != NULL) /* file available? */
{
while (!ateof)
{
clsbody();
for (i = 0; i < bh - 1 && !ateof; i++)
{
buf[0] = '\0';
fgets(buf, MAXSTRLEN, fp);
if (strlen(buf))
bodymsg(buf);
else
ateof = TRUE;
}
switch (waitforkey())
{
case 'Q':
case 'q':
case 0x1b:
ateof = TRUE;
}
}
fclose(fp);
}
else
{
sprintf(buf, "ERROR: file '%s' not found", fname);
errormsg(buf);
}
}
/***************************** forward declarations ***********************/
void sub0(void), sub1(void), sub2(void), sub3(void);
void func1(void), func2(void);
void subfunc1(void), subfunc2(void);
void subsub(void);
/***************************** menus initialization ***********************/
menu MainMenu[] =
{
{ "Asub", sub0, "Go inside first submenu" },
{ "Bsub", sub1, "Go inside second submenu" },
{ "Csub", sub2, "Go inside third submenu" },
{ "Dsub", sub3, "Go inside fourth submenu" },
{ "", (FUNC)0, "" } /* always add this as the last item! */
};
menu SubMenu0[] =
{
{ "Exit", DoExit, "Terminate program" },
{ "", (FUNC)0, "" }
};
menu SubMenu1[] =
{
{ "OneBeep", func1, "Sound one beep" },
{ "TwoBeeps", func2, "Sound two beeps" },
{ "", (FUNC)0, "" }
};
menu SubMenu2[] =
{
{ "Browse", subfunc1, "Source file lister" },
{ "Input", subfunc2, "Interactive file lister" },
{ "Address", address, "Get address data" },
{ "", (FUNC)0, "" }
};
menu SubMenu3[] =
{
{ "SubSub", subsub, "Go inside sub-submenu" },
{ "", (FUNC)0, "" }
};
/***************************** main menu functions ************************/
void sub0(void)
{
domenu(SubMenu0);
}
void sub1(void)
{
domenu(SubMenu1);
}
void sub2(void)
{
domenu(SubMenu2);
}
void sub3(void)
{
domenu(SubMenu3);
}
/***************************** submenu1 functions *************************/
void func1(void)
{
beep();
bodymsg("One beep! ");
}
void func2(void)
{
beep();
bodymsg("Two beeps! ");
beep();
}
/***************************** submenu2 functions *************************/
void subfunc1(void)
{
showfile(FNAME);
}
void subfunc2(void)
{
char fname[MAXSTRLEN];
strcpy(fname, FNAME);
if (getfname ("File to browse:", fname, 50))
showfile(fname);
}
/***************************** submenu3 functions *************************/
void subsub(void)
{
domenu(SubMenu2);
}
/***************************** start main menu ***************************/
int main(int argc, char **argv)
{
setlocale(LC_ALL, "");
startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
return 0;
}

View File

@@ -0,0 +1,434 @@
/****************************************************************************
* Copyright (c) 2005 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. *
****************************************************************************/
/*
@@@ @@@ @@@@@@@@@@ @@@@@@@@@@@ @@@@@@@@@@@@
@@@ @@@ @@@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@@@@
@@@ @@@ @@@@ @@@@ @@@@ @@@@ @@@ @@@@
@@@ @@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@ @@@ @@@
@@@@@@@@@@@@ @@@@ @@@@ @@@ @@@ @@@ @@@
@@@@ @@@@ @@@@@@@@@@@@ @@@ @@@ @@@ @@@
@@ @@ @@@@@@@@@@ @@@ @@@ @@@ @@@
Eric P. Scott
Caltech High Energy Physics
October, 1980
Color by Eric S. Raymond
July, 1995
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
$Id: worm.c,v 1.16 2008/07/13 16:08:17 wmcbrine Exp $
*/
#include <curses.h>
#include <stdlib.h>
#include <time.h>
#define FLAVORS 7
static chtype flavor[FLAVORS] =
{
'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 = ' ';
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 } }
};
static void cleanup(void)
{
standend();
refresh();
curs_set(1);
endwin();
}
int main(int argc, char *argv[])
{
const struct options *op;
struct worm *w;
short **ref, *ip;
int x, y, n, h, last, bottom, seed;
for (x = 1; x < argc; x++)
{
char *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);
return 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);
return EXIT_FAILURE;
}
break;
case 't':
trail = '.';
break;
default:
usage:
fprintf(stderr, "usage: %s [-field] [-length #] "
"[-number #] [-trail]\n", *argv);
return EXIT_FAILURE;
}
}
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
seed = time((time_t *)0);
srand(seed);
noecho();
cbreak();
nonl();
keypad(stdscr, TRUE);
curs_set(0);
bottom = LINES - 1;
last = COLS - 1;
#ifdef A_COLOR
if (has_colors())
{
int bg = COLOR_BLACK;
start_color();
# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
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
ref = malloc(sizeof(short *) * LINES);
for (y = 0; y < LINES; y++)
{
ref[y] = malloc(sizeof(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
for (n = number, w = &worm[0]; --n >= 0; w++)
{
w->orientation = w->head = 0;
if ((ip = malloc(sizeof(short) * (length + 1))) == NULL)
{
fprintf(stderr, "%s: out of memory\n", *argv);
return EXIT_FAILURE;
}
w->xpos = ip;
for (x = length; --x >= 0;)
*ip++ = -1;
if ((ip = malloc(sizeof(short) * (length + 1))) == NULL)
{
fprintf(stderr, "%s: out of memory\n", *argv);
return EXIT_FAILURE;
}
w->ypos = ip;
for (y = length; --y >= 0;)
*ip++ = -1;
}
if (field)
{
const char *p = field;
for (y = bottom; --y >= 0;)
for (x = COLS; --x >= 0;)
{
addch((chtype) (*p++));
if (!*p)
p = field;
}
}
napms(12);
refresh();
nodelay(stdscr, TRUE);
for (;;)
{
int ch;
if ((ch = getch()) > 0)
{
#ifdef KEY_RESIZE
if (ch == KEY_RESIZE)
{
# ifdef PDCURSES
resize_term(0, 0);
erase();
# endif
if (last != COLS - 1)
{
for (y = 0; y <= bottom; y++)
{
ref[y] = realloc(ref[y], sizeof(short) * COLS);
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 = realloc(ref, sizeof(short *) * LINES);
for (y = bottom + 1; y < LINES; y++)
{
ref[y] = malloc(sizeof(short) * COLS);
for (x = 0; x < COLS; x++)
ref[y][x] = 0;
}
bottom = LINES - 1;
}
}
#endif /* KEY_RESIZE */
/* Make it simple to put this into single-step mode,
or resume normal operation - T. Dickey */
if (ch == 'q')
{
cleanup();
return EXIT_SUCCESS;
}
else if (ch == 's')
nodelay(stdscr, FALSE);
else if (ch == ' ')
nodelay(stdscr, TRUE);
}
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 % FLAVORS]);
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 = w->xpos[h];
int 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();
return EXIT_SUCCESS;
case 1:
w->orientation = op->opts[0];
break;
default:
w->orientation = op->opts[rand() % op->nopts];
}
move(y += yinc[w->orientation], x += xinc[w->orientation]);
if (y < 0)
y = 0;
addch(flavor[n % FLAVORS]);
ref[w->ypos[h] = y][w->xpos[h] = x]++;
}
napms(12);
refresh();
}
}

View File

@@ -0,0 +1,957 @@
/******************************************************************************/
/* asciixmas */
/* December 1989 Larry Bartz Indianapolis, IN */
/* */
/* */
/* I'm dreaming of an ascii character-based monochrome Christmas, */
/* Just like the one's I used to know! */
/* Via a full duplex communications channel, */
/* At 9600 bits per second, */
/* Even though it's kinda slow. */
/* */
/* I'm dreaming of an ascii character-based monochrome Christmas, */
/* With ev'ry C program I write! */
/* May your screen be merry and bright! */
/* And may all your Christmases be amber or green, */
/* (for reduced eyestrain and improved visibility)! */
/* */
/* */
/* */
/* IMPLEMENTATION */
/* */
/* Feel free to modify the defined string FROMWHO to reflect you, your */
/* organization, your site, whatever. */
/* */
/* This looks a lot better if you can turn off your cursor before execution. */
/* The cursor is distracting but it doesn't really ruin the show. */
/* */
/* At our site, we invoke this for our users just after login and the */
/* determination of terminal type. */
/* */
/* */
/* PORTABILITY */
/* */
/* I wrote this using only the very simplest curses functions so that it */
/* might be the most portable. I was personally able to test on five */
/* different cpu/UNIX combinations. */
/* */
/* */
/* COMPILE */
/* */
/* usually this: */
/* */
/* cc -O xmas.c -lcurses -o xmas -s */
/* */
/******************************************************************************/
/* $Id: xmas.c,v 1.29 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curses.h>
#include <signal.h>
void lil(WINDOW *);
void midtop(WINDOW *);
void bigtop(WINDOW *);
void bigface(WINDOW *, chtype);
void legs1(WINDOW *);
void legs2(WINDOW *);
void legs3(WINDOW *);
void legs4(WINDOW *);
void initdeer(void);
void boxit(void);
void seas(void);
void greet(void);
void fromwho(void);
void del_msg(void);
void tree(void);
void balls(void);
void star(void);
void strng1(void);
void strng2(void);
void strng3(void);
void strng4(void);
void strng5(void);
void blinkit(void);
void reindeer(void);
#define FROMWHO "From Larry Bartz, Mark Hessling and William McBrine"
int y_pos, x_pos;
WINDOW *treescrn, *treescrn2, *treescrn3, *treescrn4, *treescrn5,
*treescrn6, *treescrn7, *treescrn8, *dotdeer0, *stardeer0,
*lildeer0, *lildeer1, *lildeer2, *lildeer3, *middeer0,
*middeer1, *middeer2, *middeer3, *bigdeer0, *bigdeer1,
*bigdeer2, *bigdeer3, *bigdeer4, *lookdeer0, *lookdeer1,
*lookdeer2, *lookdeer3, *lookdeer4, *w_holiday, *w_del_msg;
int main(int argc, char **argv)
{
int loopy;
#ifdef XCURSES
Xinitscr(argc, argv);
#else
initscr();
#endif
nodelay(stdscr, TRUE);
noecho();
nonl();
refresh();
#ifdef A_COLOR
if (has_colors())
start_color();
#endif
curs_set(0);
treescrn = newwin(16, 27, 3, 53);
treescrn2 = newwin(16, 27, 3, 53);
treescrn3 = newwin(16, 27, 3, 53);
treescrn4 = newwin(16, 27, 3, 53);
treescrn5 = newwin(16, 27, 3, 53);
treescrn6 = newwin(16, 27, 3, 53);
treescrn7 = newwin(16, 27, 3, 53);
treescrn8 = newwin(16, 27, 3, 53);
w_holiday = newwin(1, 26, 3, 27);
w_del_msg = newwin(1, 12, 23, 60);
mvwaddstr(w_holiday, 0, 0, "H A P P Y H O L I D A Y S");
initdeer();
clear();
werase(treescrn);
touchwin(treescrn);
werase(treescrn2);
touchwin(treescrn2);
werase(treescrn8);
touchwin(treescrn8);
refresh();
napms(1000);
boxit();
del_msg();
napms(1000);
seas();
del_msg();
napms(1000);
greet();
del_msg();
napms(1000);
fromwho();
del_msg();
napms(1000);
tree();
napms(1000);
balls();
napms(1000);
star();
napms(1000);
strng1();
strng2();
strng3();
strng4();
strng5();
/* set up the windows for our blinking trees */
/* **************************************** */
/* treescrn3 */
overlay(treescrn, treescrn3);
/* balls */
mvwaddch(treescrn3, 4, 18, ' ');
mvwaddch(treescrn3, 7, 6, ' ');
mvwaddch(treescrn3, 8, 19, ' ');
mvwaddch(treescrn3, 11, 22, ' ');
/* star */
mvwaddch(treescrn3, 0, 12, '*');
/* strng1 */
mvwaddch(treescrn3, 3, 11, ' ');
/* strng2 */
mvwaddch(treescrn3, 5, 13, ' ');
mvwaddch(treescrn3, 6, 10, ' ');
/* strng3 */
mvwaddch(treescrn3, 7, 16, ' ');
mvwaddch(treescrn3, 7, 14, ' ');
/* strng4 */
mvwaddch(treescrn3, 10, 13, ' ');
mvwaddch(treescrn3, 10, 10, ' ');
mvwaddch(treescrn3, 11, 8, ' ');
/* strng5 */
mvwaddch(treescrn3, 11, 18, ' ');
mvwaddch(treescrn3, 12, 13, ' ');
/* treescrn4 */
overlay(treescrn, treescrn4);
/* balls */
mvwaddch(treescrn4, 3, 9, ' ');
mvwaddch(treescrn4, 4, 16, ' ');
mvwaddch(treescrn4, 7, 6, ' ');
mvwaddch(treescrn4, 8, 19, ' ');
mvwaddch(treescrn4, 11, 2, ' ');
mvwaddch(treescrn4, 12, 23, ' ');
/* star */
mvwaddch(treescrn4, 0, 12, '*' | A_STANDOUT);
/* strng1 */
mvwaddch(treescrn4, 3, 13, ' ');
/* strng2 */
/* strng3 */
mvwaddch(treescrn4, 7, 15, ' ');
mvwaddch(treescrn4, 8, 11, ' ');
/* strng4 */
mvwaddch(treescrn4, 9, 16, ' ');
mvwaddch(treescrn4, 10, 12, ' ');
mvwaddch(treescrn4, 11, 8, ' ');
/* strng5 */
mvwaddch(treescrn4, 11, 18, ' ');
mvwaddch(treescrn4, 12, 14, ' ');
/* treescrn5 */
overlay(treescrn, treescrn5);
/* balls */
mvwaddch(treescrn5, 3, 15, ' ');
mvwaddch(treescrn5, 10, 20, ' ');
mvwaddch(treescrn5, 12, 1, ' ');
/* star */
mvwaddch(treescrn5, 0, 12, '*');
/* strng1 */
mvwaddch(treescrn5, 3, 11, ' ');
/* strng2 */
mvwaddch(treescrn5, 5, 12, ' ');
/* strng3 */
mvwaddch(treescrn5, 7, 14, ' ');
mvwaddch(treescrn5, 8, 10, ' ');
/* strng4 */
mvwaddch(treescrn5, 9, 15, ' ');
mvwaddch(treescrn5, 10, 11, ' ');
mvwaddch(treescrn5, 11, 7, ' ');
/* strng5 */
mvwaddch(treescrn5, 11, 17, ' ');
mvwaddch(treescrn5, 12, 13, ' ');
/* treescrn6 */
overlay(treescrn, treescrn6);
/* balls */
mvwaddch(treescrn6, 6, 7, ' ');
mvwaddch(treescrn6, 7, 18, ' ');
mvwaddch(treescrn6, 10, 4, ' ');
mvwaddch(treescrn6, 11, 23, ' ');
/* star */
mvwaddch(treescrn6, 0, 12, '*' | A_STANDOUT);
/* strng1 */
/* strng2 */
mvwaddch(treescrn6, 5, 11, ' ');
/* strng3 */
mvwaddch(treescrn6, 7, 13, ' ');
mvwaddch(treescrn6, 8, 9, ' ');
/* strng4 */
mvwaddch(treescrn6, 9, 14, ' ');
mvwaddch(treescrn6, 10, 10, ' ');
mvwaddch(treescrn6, 11, 6, ' ');
/* strng5 */
mvwaddch(treescrn6, 11, 16, ' ');
mvwaddch(treescrn6, 12, 12, ' ');
/* treescrn7 */
overlay(treescrn, treescrn7);
/* balls */
mvwaddch(treescrn7, 3, 15, ' ');
mvwaddch(treescrn7, 6, 7, ' ');
mvwaddch(treescrn7, 7, 18, ' ');
mvwaddch(treescrn7, 10, 4, ' ');
mvwaddch(treescrn7, 11, 22, ' ');
/* star */
mvwaddch(treescrn7, 0, 12, '*');
/* strng1 */
mvwaddch(treescrn7, 3, 12, ' ');
/* strng2 */
mvwaddch(treescrn7, 5, 13, ' ');
mvwaddch(treescrn7, 6, 9, ' ');
/* strng3 */
mvwaddch(treescrn7, 7, 15, ' ');
mvwaddch(treescrn7, 8, 11, ' ');
/* strng4 */
mvwaddch(treescrn7, 9, 16, ' ');
mvwaddch(treescrn7, 10, 12, ' ');
mvwaddch(treescrn7, 11, 8, ' ');
/* strng5 */
mvwaddch(treescrn7, 11, 18, ' ');
mvwaddch(treescrn7, 12, 14, ' ');
napms(1000);
reindeer();
touchwin(w_holiday);
wrefresh(w_holiday);
wrefresh(w_del_msg);
napms(1000);
for (loopy = 0; loopy < 50; loopy++)
blinkit();
clear();
refresh();
endwin();
return 0;
}
void lil(WINDOW *win)
{
mvwaddch(win, 0, 0, (chtype) 'V');
mvwaddch(win, 1, 0, (chtype) '@');
mvwaddch(win, 1, 3, (chtype) '~');
}
void midtop(WINDOW *win)
{
mvwaddstr(win, 0, 2, "yy");
mvwaddstr(win, 1, 2, "0(=)~");
}
void bigtop(WINDOW *win)
{
mvwaddstr(win, 0, 17, "\\/");
mvwaddstr(win, 0, 20, "\\/");
mvwaddch(win, 1, 18, (chtype) '\\');
mvwaddch(win, 1, 20, (chtype) '/');
mvwaddstr(win, 2, 19, "|_");
mvwaddstr(win, 3, 18, "/^0\\");
mvwaddstr(win, 4, 17, "//\\");
mvwaddch(win, 4, 22, (chtype) '\\');
mvwaddstr(win, 5, 7, "^~~~~~~~~// ~~U");
}
void bigface(WINDOW *win, chtype noseattr)
{
mvwaddstr(win, 0, 16, "\\/ \\/");
mvwaddstr(win, 1, 17, "\\Y/ \\Y/");
mvwaddstr(win, 2, 19, "\\=/");
mvwaddstr(win, 3, 17, "^\\o o/^");
mvwaddstr(win, 4, 17, "//( )");
mvwaddstr(win, 5, 7, "^~~~~~~~~// \\");
waddch(win, 'O' | noseattr);
waddstr(win, "/");
}
void legs1(WINDOW *win)
{
mvwaddstr(win, 6, 7, "( \\_____( /");
mvwaddstr(win, 7, 8, "( ) /");
mvwaddstr(win, 8, 9, "\\\\ /");
mvwaddstr(win, 9, 11, "\\>/>");
}
void legs2(WINDOW *win)
{
mvwaddstr(win, 6, 7, "(( )____( /");
mvwaddstr(win, 7, 7, "( / |");
mvwaddstr(win, 8, 8, "\\/ |");
mvwaddstr(win, 9, 9, "|> |>");
}
void legs3(WINDOW *win)
{
mvwaddstr(win, 6, 6, "( ()_____( /");
mvwaddstr(win, 7, 6, "/ / /");
mvwaddstr(win, 8, 5, "|/ \\");
mvwaddstr(win, 9, 5, "/> \\>");
}
void legs4(WINDOW *win)
{
mvwaddstr(win, 6, 6, "( )______( /");
mvwaddstr(win, 7, 5, "(/ \\");
mvwaddstr(win, 8, 0, "v___= ----^");
}
void initdeer(void)
{
chtype noseattr;
#ifdef A_COLOR
if (has_colors())
{
init_pair(31, COLOR_RED, COLOR_BLACK);
noseattr = COLOR_PAIR(31);
}
else
#endif
noseattr = A_NORMAL;
/* set up the windows for our various reindeer */
dotdeer0 = newwin(3, 71, 0, 8);
stardeer0 = newwin(4, 56, 0, 8);
lildeer0 = newwin(7, 54, 0, 8);
middeer0 = newwin(15, 42, 0, 8);
bigdeer0 = newwin(10, 23, 0, 0);
lookdeer0 = newwin(10, 25, 0, 0);
/* lildeer1 */
lildeer1 = newwin(2, 4, 0, 0);
lil(lildeer1);
mvwaddstr(lildeer1, 1, 1, "<>");
/* lildeer2 */
lildeer2 = newwin(2, 4, 0, 0);
lil(lildeer2);
mvwaddstr(lildeer2, 1, 1, "||");
/* lildeer3 */
lildeer3 = newwin(2, 4, 0, 0);
lil(lildeer3);
mvwaddstr(lildeer3, 1, 1, "><");
/* middeer1 */
middeer1 = newwin(3, 7, 0, 0);
midtop(middeer1);
mvwaddstr(middeer1, 2, 3, "\\/");
/* middeer2 */
middeer2 = newwin(3, 7, 0, 0);
midtop(middeer2);
mvwaddch(middeer2, 2, 3, (chtype) '|');
mvwaddch(middeer2, 2, 5, (chtype) '|');
/* middeer3 */
middeer3 = newwin(3, 7, 0, 0);
midtop(middeer3);
mvwaddch(middeer3, 2, 2, (chtype) '/');
mvwaddch(middeer3, 2, 6, (chtype) '\\');
/* bigdeer1 */
bigdeer1 = newwin(10, 23, 0, 0);
bigtop(bigdeer1);
legs1(bigdeer1);
/* bigdeer2 */
bigdeer2 = newwin(10, 23, 0, 0);
bigtop(bigdeer2);
legs2(bigdeer2);
/* bigdeer3 */
bigdeer3 = newwin(10, 23, 0, 0);
bigtop(bigdeer3);
legs3(bigdeer3);
/* bigdeer4 */
bigdeer4 = newwin(10, 23, 0, 0);
bigtop(bigdeer4);
legs4(bigdeer4);
/* lookdeer1 */
lookdeer1 = newwin(10, 25, 0, 0);
bigface(lookdeer1, noseattr);
legs1(lookdeer1);
/* lookdeer2 */
lookdeer2 = newwin(10, 25, 0, 0);
bigface(lookdeer2, noseattr);
legs2(lookdeer2);
/* lookdeer3 */
lookdeer3 = newwin(10, 25, 0, 0);
bigface(lookdeer3, noseattr);
legs3(lookdeer3);
/* lookdeer4 */
lookdeer4 = newwin(10, 25, 0, 0);
bigface(lookdeer4, noseattr);
legs4(lookdeer4);
}
void boxit(void)
{
int x;
for (x = 0; x < 20; ++x)
mvaddch(x, 7, '|');
for (x = 0; x < 80; ++x)
{
if (x > 7)
mvaddch(19, x, '_');
mvaddch(22, x, '_');
}
}
void seas(void)
{
mvaddch(4, 1, 'S');
mvaddch(6, 1, 'E');
mvaddch(8, 1, 'A');
mvaddch(10, 1, 'S');
mvaddch(12, 1, 'O');
mvaddch(14, 1, 'N');
mvaddch(16, 1, '`');
mvaddch(18, 1, 'S');
}
void greet(void)
{
mvaddch(3, 5, 'G');
mvaddch(5, 5, 'R');
mvaddch(7, 5, 'E');
mvaddch(9, 5, 'E');
mvaddch(11, 5, 'T');
mvaddch(13, 5, 'I');
mvaddch(15, 5, 'N');
mvaddch(17, 5, 'G');
mvaddch(19, 5, 'S');
}
void fromwho(void)
{
mvaddstr(21, 13, FROMWHO);
}
void del_msg(void)
{
refresh();
}
void tree(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(30, COLOR_GREEN, COLOR_BLACK);
wattrset(treescrn, COLOR_PAIR(30));
}
#endif
mvwaddch(treescrn, 1, 11, (chtype) '/');
mvwaddch(treescrn, 2, 11, (chtype) '/');
mvwaddch(treescrn, 3, 10, (chtype) '/');
mvwaddch(treescrn, 4, 9, (chtype) '/');
mvwaddch(treescrn, 5, 9, (chtype) '/');
mvwaddch(treescrn, 6, 8, (chtype) '/');
mvwaddch(treescrn, 7, 7, (chtype) '/');
mvwaddch(treescrn, 8, 6, (chtype) '/');
mvwaddch(treescrn, 9, 6, (chtype) '/');
mvwaddch(treescrn, 10, 5, (chtype) '/');
mvwaddch(treescrn, 11, 3, (chtype) '/');
mvwaddch(treescrn, 12, 2, (chtype) '/');
mvwaddch(treescrn, 1, 13, (chtype) '\\');
mvwaddch(treescrn, 2, 13, (chtype) '\\');
mvwaddch(treescrn, 3, 14, (chtype) '\\');
mvwaddch(treescrn, 4, 15, (chtype) '\\');
mvwaddch(treescrn, 5, 15, (chtype) '\\');
mvwaddch(treescrn, 6, 16, (chtype) '\\');
mvwaddch(treescrn, 7, 17, (chtype) '\\');
mvwaddch(treescrn, 8, 18, (chtype) '\\');
mvwaddch(treescrn, 9, 18, (chtype) '\\');
mvwaddch(treescrn, 10, 19, (chtype) '\\');
mvwaddch(treescrn, 11, 21, (chtype) '\\');
mvwaddch(treescrn, 12, 22, (chtype) '\\');
mvwaddch(treescrn, 4, 10, (chtype) '_');
mvwaddch(treescrn, 4, 14, (chtype) '_');
mvwaddch(treescrn, 8, 7, (chtype) '_');
mvwaddch(treescrn, 8, 17, (chtype) '_');
mvwaddstr(treescrn, 13, 0,
"//////////// \\\\\\\\\\\\\\\\\\\\\\\\");
#ifdef A_COLOR
if (has_colors())
{
init_pair(20, COLOR_YELLOW, COLOR_BLACK);
wattrset(treescrn, COLOR_PAIR(20));
}
#endif
mvwaddstr(treescrn, 14, 11, "| |");
mvwaddstr(treescrn, 15, 11, "|_|");
wrefresh(treescrn);
wrefresh(w_del_msg);
}
void balls(void)
{
chtype ball1, ball2, ball3, ball4, ball5, ball6;
overlay(treescrn, treescrn2);
#ifdef A_COLOR
if (has_colors())
{
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_MAGENTA, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_pair(5, COLOR_YELLOW, COLOR_BLACK);
init_pair(6, COLOR_WHITE, COLOR_BLACK);
ball1 = COLOR_PAIR(1) | '@';
ball2 = COLOR_PAIR(2) | '@';
ball3 = COLOR_PAIR(3) | '@';
ball4 = COLOR_PAIR(4) | '@';
ball5 = COLOR_PAIR(5) | '@';
ball6 = COLOR_PAIR(6) | '@';
}
else
#endif
ball1 = ball2 = ball3 = ball4 = ball5 = ball6 = '@';
mvwaddch(treescrn2, 3, 9, ball1);
mvwaddch(treescrn2, 3, 15, ball2);
mvwaddch(treescrn2, 4, 8, ball3);
mvwaddch(treescrn2, 4, 16, ball4);
mvwaddch(treescrn2, 5, 7, ball5);
mvwaddch(treescrn2, 5, 17, ball6);
mvwaddch(treescrn2, 7, 6, ball1 | A_BOLD);
mvwaddch(treescrn2, 7, 18, ball2 | A_BOLD);
mvwaddch(treescrn2, 8, 5, ball3 | A_BOLD);
mvwaddch(treescrn2, 8, 19, ball4 | A_BOLD);
mvwaddch(treescrn2, 10, 4, ball5 | A_BOLD);
mvwaddch(treescrn2, 10, 20, ball6 | A_BOLD);
mvwaddch(treescrn2, 11, 2, ball1);
mvwaddch(treescrn2, 11, 22, ball2);
mvwaddch(treescrn2, 12, 1, ball3);
mvwaddch(treescrn2, 12, 23, ball4);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void star(void)
{
mvwaddch(treescrn2, 0, 12, (chtype) '*' | A_STANDOUT);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng1(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(10, COLOR_YELLOW, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(10) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 3, 11, ".:'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng2(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(11, COLOR_RED, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(11) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 5, 11, ",.:'");
mvwaddstr(treescrn2, 6, 9, ":'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng3(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(12, COLOR_GREEN, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(12) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 7, 13, ",.:'");
mvwaddstr(treescrn2, 8, 9, ",.:'");
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng4(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(13, COLOR_WHITE, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(13) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 9, 14, ",.:'");
mvwaddstr(treescrn2, 10, 10, ",.:'");
mvwaddstr(treescrn2, 11, 6, ",.:'");
mvwaddch(treescrn2, 12, 5, (chtype) '\'');
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void strng5(void)
{
#ifdef A_COLOR
if (has_colors())
{
init_pair(14, COLOR_CYAN, COLOR_BLACK);
wattrset(treescrn2, COLOR_PAIR(14) | A_BOLD);
}
#endif
mvwaddstr(treescrn2, 11, 16, ",.:'");
mvwaddstr(treescrn2, 12, 12, ",.:'");
/* save a fully lit tree */
overlay(treescrn2, treescrn);
wrefresh(treescrn2);
wrefresh(w_del_msg);
}
void blinkit(void)
{
static int cycle;
if (cycle > 4)
cycle = 0;
touchwin(treescrn8);
switch (cycle)
{
case 0:
overlay(treescrn3, treescrn8);
break;
case 1:
overlay(treescrn4, treescrn8);
break;
case 2:
overlay(treescrn5, treescrn8);
break;
case 3:
overlay(treescrn6, treescrn8);
break;
case 4:
overlay(treescrn7, treescrn8);
}
wrefresh(treescrn8);
wrefresh(w_del_msg);
napms(50);
touchwin(treescrn8);
/*ALL ON************************************************** */
overlay(treescrn, treescrn8);
wrefresh(treescrn8);
wrefresh(w_del_msg);
++cycle;
}
#define TSHOW(win, pause) touchwin(win); wrefresh(win); \
wrefresh(w_del_msg); napms(pause)
#define SHOW(win, pause) mvwin(win, y_pos, x_pos); wrefresh(win); \
wrefresh(w_del_msg); napms(pause)
void reindeer(void)
{
int looper;
y_pos = 0;
for (x_pos = 70; x_pos > 62; x_pos--)
{
if (x_pos < 62)
y_pos = 1;
for (looper = 0; looper < 4; looper++)
{
mvwaddch(dotdeer0, y_pos, x_pos, (chtype) '.');
wrefresh(dotdeer0);
wrefresh(w_del_msg);
werase(dotdeer0);
wrefresh(dotdeer0);
wrefresh(w_del_msg);
}
}
y_pos = 2;
for (; x_pos > 50; x_pos--)
{
for (looper = 0; looper < 4; looper++)
{
if (x_pos < 56)
{
y_pos = 3;
mvwaddch(stardeer0, y_pos, x_pos, (chtype) '*');
wrefresh(stardeer0);
wrefresh(w_del_msg);
werase(stardeer0);
wrefresh(stardeer0);
}
else
{
mvwaddch(dotdeer0, y_pos, x_pos, (chtype) '*');
wrefresh(dotdeer0);
wrefresh(w_del_msg);
werase(dotdeer0);
wrefresh(dotdeer0);
}
wrefresh(w_del_msg);
}
}
x_pos = 58;
for (y_pos = 2; y_pos < 5; y_pos++)
{
TSHOW(lildeer0, 50);
for (looper = 0; looper < 4; looper++)
{
SHOW(lildeer3, 50);
SHOW(lildeer2, 50);
SHOW(lildeer1, 50);
SHOW(lildeer2, 50);
SHOW(lildeer3, 50);
TSHOW(lildeer0, 50);
x_pos -= 2;
}
}
x_pos = 35;
for (y_pos = 5; y_pos < 10; y_pos++)
{
touchwin(middeer0);
wrefresh(middeer0);
wrefresh(w_del_msg);
for (looper = 0; looper < 2; looper++)
{
SHOW(middeer3, 50);
SHOW(middeer2, 50);
SHOW(middeer1, 50);
SHOW(middeer2, 50);
SHOW(middeer3, 50);
TSHOW(middeer0, 50);
x_pos -= 3;
}
}
napms(2000);
y_pos = 1;
for (x_pos = 8; x_pos < 16; x_pos++)
{
SHOW(bigdeer4, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer1, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer4, 30);
SHOW(bigdeer0, 30);
}
--x_pos;
for (looper = 0; looper < 6; looper++)
{
SHOW(lookdeer4, 40);
SHOW(lookdeer3, 40);
SHOW(lookdeer2, 40);
SHOW(lookdeer1, 40);
SHOW(lookdeer2, 40);
SHOW(lookdeer3, 40);
SHOW(lookdeer4, 40);
}
SHOW(lookdeer0, 40);
for (; y_pos < 10; y_pos++)
{
for (looper = 0; looper < 2; looper++)
{
SHOW(bigdeer4, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer1, 30);
SHOW(bigdeer2, 30);
SHOW(bigdeer3, 30);
SHOW(bigdeer4, 30);
}
SHOW(bigdeer0, 30);
}
--y_pos;
mvwin(lookdeer3, y_pos, x_pos);
wrefresh(lookdeer3);
wrefresh(w_del_msg);
}

View File

@@ -0,0 +1,37 @@
# Makefile for PDCurses manext program.
all: manual
manual: PDCurses.txt
PDCurses.txt: manext
cat intro.txt > PDCurses.txt
echo PDCurses Definitions and Variables >> PDCurses.txt
echo ================================== >> PDCurses.txt
./manext ../curses.h >> PDCurses.txt
echo PDCurses Functions >> PDCurses.txt
echo ================== >> PDCurses.txt
./manext ../pdcurses/*.c >> PDCurses.txt
./manext ../x11/*.c >> PDCurses.txt
cat x11.txt >> PDCurses.txt
echo >> PDCurses.txt
echo >> PDCurses.txt
echo \
-------------------------------------------------------------------------- \
>> PDCurses.txt
echo >> PDCurses.txt
cat sdl.txt >> PDCurses.txt
manext: manext.c
install:
echo Does nothing at the moment
clean:
-rm -rf *.o manext PDCurses.txt
distclean: clean
mostlyclean: clean
realclean: distclean

View File

@@ -0,0 +1,833 @@
PDCurses User's Guide
=====================
Curses Overview
---------------
The X/Open Curses Interface Definition describes a set of C-Language
functions that provide screen-handling and updating, which are
collectively known as the curses library.
The curses library permits manipulation of data structures called
windows which may be thought of as two-dimensional arrays of
characters representing all or part of a terminal's screen. The
windows are manipulated using a procedural interface described
elsewhere. The curses package maintains a record of what characters
are on the screen. At the most basic level, manipulation is done with
the routines move() and addch() which are used to "move" the curses
around and add characters to the default window, stdscr, which
represents the whole screen.
An application may use these routines to add data to the window in any
convenient order. Once all data have been added, the routine
refresh() is called. The package then determines what changes have
been made which affect the screen. The screen contents are then
changed to reflect those characters now in the window, using a
sequence of operations optimized for the type of terminal in use.
At a higher level routines combining the actions of move() and addch()
are defined, as are routines to add whole strings and to perform
format conversions in the manner of printf().
Interfaces are also defined to erase the entire window and to specify
the attributes of individual characters in the window. Attributes
such as inverse video, underline and blink can be used on a
per-character basis.
New windows can be created by allowing the application to build
several images of the screen and display the appropriate one very
quickly. New windows are created using the routine newwin(). For
each routine that manipulates the default window, stdscr, there is a
corresponding routine prefixed with w to manipulate the contents of a
specified window; for example, move() and wmove(). In fact, move(...)
is functionally equivalent to wmove( stdscr, ...). This is similar to
the interface offered by printf(...) and fprintf(stdout, ...).
Windows do not have to correspond to the entire screen. It is
possible to create smaller windows, and also to indicate that the
window is only partially visible on the screen. Furthermore, large
windows or pads, which are bigger than the actual screen size, may be
created.
Interfaces are also defined to allow input character manipulation and
to disable and enable many input attributes: character echo, single
character input with or without signal processing (cbreak or raw
modes), carriage returns mapping to newlines, screen scrolling, etc.
Data Types and the <curses.h> Header
------------------------------------
The data types supported by curses are described in this section.
As the library supports a procedural interface to the data types, actual
structure contents are not described. All curses data are manipulated
using the routines provided.
THE <curses.h> HEADER
The <curses.h> header defines various constants and declares the data
types that are available to the application.
DATA TYPES
The following data types are declared:
WINDOW * pointer to screen representation
SCREEN * pointer to terminal descriptor
bool boolean data type
chtype representation of a character in a window
cchar_t the wide-character equivalent of chtype
attr_t for WA_-style attributes
The actual WINDOW and SCREEN objects used to store information are
created by the corresponding routines and a pointer to them is provided.
All manipulation is through that pointer.
VARIABLES
The following variables are defined:
LINES number of lines on terminal screen
COLS number of columns on terminal screen
stdscr pointer to the default screen window
curscr pointer to the current screen image
SP pointer to the current SCREEN struct
Mouse_status status of the mouse
COLORS number of colors available
COLOR_PAIRS number of color pairs available
TABSIZE size of one TAB block
acs_map[] alternate character set map
ttytype[] terminal name/description
CONSTANTS
The following constants are defined:
GENERAL
FALSE boolean false value
TRUE boolean true value
NULL zero pointer value
ERR value returned on error condition
OK value returned on successful completion
VIDEO ATTRIBUTES
Normally, attributes are a property of the character.
For chtype:
A_ALTCHARSET use the alternate character set
A_BLINK bright background or blinking
A_BOLD bright foreground or bold
A_DIM half bright -- no effect in PDCurses
A_INVIS invisible
A_ITALIC italic
A_LEFTLINE line along the left edge
A_PROTECT protected (?) -- PDCurses renders this as a
combination of the *LINE attributes
A_REVERSE reverse video
A_RIGHTLINE line along the right edge
A_STANDOUT terminal's best highlighting mode
A_UNDERLINE underline
A_ATTRIBUTES bit-mask to extract attributes
A_CHARTEXT bit-mask to extract a character
A_COLOR bit-mask to extract a color-pair
Not all attributes will work on all terminals. A_RIGHTLINE, A_LEFTLINE
and A_ITALIC are specific to PDCurses. A_INVIS and A_ITALIC are given
the same value in PDCurses.
For attr_t:
WA_ALTCHARSET same as A_ALTCHARSET
WA_BLINK same as A_BLINK
WA_BOLD same as A_BOLD
WA_DIM same as A_DIM
WA_INVIS same as A_INVIS
WA_LEFT same as A_LEFTLINE
WA_PROTECT same as A_PROTECT
WA_REVERSE same as A_REVERSE
WA_RIGHT same as A_RIGHTLINE
WA_STANDOUT same as A_STANDOUT
WA_UNDERLINE same as A_UNDERLINE
Note that while A_LEFTLINE and A_RIGHTLINE are PDCurses-specific,
WA_LEFT and WA_RIGHT are standard. The following are also defined, for
compatibility, but currently have no effect in PDCurses: WA_HORIZONTAL,
WA_LOW, WA_TOP, WA_VERTICAL.
THE ALTERNATE CHARACTER SET
For use in chtypes and with related functions. These are a portable way
to represent graphics characters on different terminals.
VT100-compatible symbols -- box characters:
ACS_ULCORNER upper left box corner
ACS_LLCORNER lower left box corner
ACS_URCORNER upper right box corner
ACS_LRCORNER lower right box corner
ACS_RTEE right "T"
ACS_LTEE left "T"
ACS_BTEE bottom "T"
ACS_TTEE top "T"
ACS_HLINE horizontal line
ACS_VLINE vertical line
ACS_PLUS plus sign, cross, or four-corner piece
VT100-compatible symbols -- other:
ACS_S1 scan line 1
ACS_S9 scan line 9
ACS_DIAMOND diamond
ACS_CKBOARD checkerboard -- 50% grey
ACS_DEGREE degree symbol
ACS_PLMINUS plus/minus sign
ACS_BULLET bullet
Teletype 5410v1 symbols -- these are defined in SysV curses, but
are not well-supported by most terminals. Stick to VT100 characters
for optimum portability:
ACS_LARROW left arrow
ACS_RARROW right arrow
ACS_DARROW down arrow
ACS_UARROW up arrow
ACS_BOARD checkerboard -- lighter (less dense) than
ACS_CKBOARD
ACS_LANTERN lantern symbol
ACS_BLOCK solid block
That goes double for these -- undocumented SysV symbols. Don't use
them:
ACS_S3 scan line 3
ACS_S7 scan line 7
ACS_LEQUAL less than or equal
ACS_GEQUAL greater than or equal
ACS_PI pi
ACS_NEQUAL not equal
ACS_STERLING pounds sterling symbol
Box character aliases:
ACS_BSSB same as ACS_ULCORNER
ACS_SSBB same as ACS_LLCORNER
ACS_BBSS same as ACS_URCORNER
ACS_SBBS same as ACS_LRCORNER
ACS_SBSS same as ACS_RTEE
ACS_SSSB same as ACS_LTEE
ACS_SSBS same as ACS_BTEE
ACS_BSSS same as ACS_TTEE
ACS_BSBS same as ACS_HLINE
ACS_SBSB same as ACS_VLINE
ACS_SSSS same as ACS_PLUS
For cchar_t and wide-character functions, WACS_ equivalents are also
defined.
COLORS
For use with init_pair(), color_set(), etc.:
COLOR_BLACK
COLOR_BLUE
COLOR_GREEN
COLOR_CYAN
COLOR_RED
COLOR_MAGENTA
COLOR_YELLOW
COLOR_WHITE
Use these instead of numeric values. The definition of the colors
depends on the implementation of curses.
INPUT VALUES
The following constants might be returned by getch() if keypad() has
been enabled. Note that not all of these may be supported on a
particular terminal:
KEY_BREAK break key
KEY_DOWN the four arrow keys
KEY_UP
KEY_LEFT
KEY_RIGHT
KEY_HOME home key (upward+left arrow)
KEY_BACKSPACE backspace
KEY_F0 function keys; space for 64 keys is reserved
KEY_F(n) (KEY_F0+(n))
KEY_DL delete line
KEY_IL insert line
KEY_DC delete character
KEY_IC insert character
KEY_EIC exit insert character mode
KEY_CLEAR clear screen
KEY_EOS clear to end of screen
KEY_EOL clear to end of line
KEY_SF scroll 1 line forwards
KEY_SR scroll 1 line backwards (reverse)
KEY_NPAGE next page
KEY_PPAGE previous page
KEY_STAB set tab
KEY_CTAB clear tab
KEY_CATAB clear all tabs
KEY_ENTER enter or send
KEY_SRESET soft (partial) reset
KEY_RESET reset or hard reset
KEY_PRINT print or copy
KEY_LL home down or bottom (lower left)
KEY_A1 upper left of virtual keypad
KEY_A3 upper right of virtual keypad
KEY_B2 center of virtual keypad
KEY_C1 lower left of virtual keypad
KEY_C3 lower right of virtual keypad
KEY_BTAB Back tab key
KEY_BEG Beginning key
KEY_CANCEL Cancel key
KEY_CLOSE Close key
KEY_COMMAND Cmd (command) key
KEY_COPY Copy key
KEY_CREATE Create key
KEY_END End key
KEY_EXIT Exit key
KEY_FIND Find key
KEY_HELP Help key
KEY_MARK Mark key
KEY_MESSAGE Message key
KEY_MOVE Move key
KEY_NEXT Next object key
KEY_OPEN Open key
KEY_OPTIONS Options key
KEY_PREVIOUS Previous object key
KEY_REDO Redo key
KEY_REFERENCE Reference key
KEY_REFRESH Refresh key
KEY_REPLACE Replace key
KEY_RESTART Restart key
KEY_RESUME Resume key
KEY_SAVE Save key
KEY_SBEG Shifted beginning key
KEY_SCANCEL Shifted cancel key
KEY_SCOMMAND Shifted command key
KEY_SCOPY Shifted copy key
KEY_SCREATE Shifted create key
KEY_SDC Shifted delete char key
KEY_SDL Shifted delete line key
KEY_SELECT Select key
KEY_SEND Shifted end key
KEY_SEOL Shifted clear line key
KEY_SEXIT Shifted exit key
KEY_SFIND Shifted find key
KEY_SHELP Shifted help key
KEY_SHOME Shifted home key
KEY_SIC Shifted input key
KEY_SLEFT Shifted left arrow key
KEY_SMESSAGE Shifted message key
KEY_SMOVE Shifted move key
KEY_SNEXT Shifted next key
KEY_SOPTIONS Shifted options key
KEY_SPREVIOUS Shifted prev key
KEY_SPRINT Shifted print key
KEY_SREDO Shifted redo key
KEY_SREPLACE Shifted replace key
KEY_SRIGHT Shifted right arrow
KEY_SRSUME Shifted resume key
KEY_SSAVE Shifted save key
KEY_SSUSPEND Shifted suspend key
KEY_SUNDO Shifted undo key
KEY_SUSPEND Suspend key
KEY_UNDO Undo key
The virtual keypad is arranged like this:
A1 up A3
left B2 right
C1 down C3
This list is incomplete -- see curses.h for the full list, and use the
testcurs demo to see what values are actually returned. The above are
just the keys required by X/Open. In particular, PDCurses defines many
CTL_ and ALT_ combinations; these are not portable.
FUNCTIONS
The following table lists each curses routine and the name of the manual
page on which it is described.
Functions from the X/Open curses standard -- complete, except for
getch() and ungetch(), which are implemented as macros for DOS
compatibility:
Curses Function Manual Page Name
addch addch
addchnstr addchstr
addchstr addchstr
addnstr addstr
addstr addstr
attroff attr
attron attr
attrset attr
attr_get attr
attr_off attr
attr_on attr
attr_set attr
baudrate termattr
beep beep
bkgd bkgd
bkgdset bkgd
border border
box border
can_change_color color
cbreak inopts
chgat attr
clearok outopts
clear clear
clrtobot clear
clrtoeol clear
color_content color
color_set attr
copywin overlay
curs_set kernel
def_prog_mode kernel
def_shell_mode kernel
del_curterm terminfo
delay_output util
delch delch
deleteln deleteln
delscreen initscr
delwin window
derwin window
doupdate refresh
dupwin window
echochar addch
echo inopts
endwin initscr
erasechar termattr
erase clear
filter util
flash beep
flushinp getch
getbkgd bkgd
getnstr getstr
getstr getstr
getwin scr_dump
halfdelay inopts
has_colors color
has_ic termattr
has_il termattr
hline border
idcok outopts
idlok outopts
immedok outopts
inchnstr inchstr
inchstr inchstr
inch inch
init_color color
init_pair color
initscr initscr
innstr instr
insch insch
insdelln deleteln
insertln deleteln
insnstr innstr
insstr innstr
instr instr
intrflush inopts
isendwin initscr
is_linetouched touch
is_wintouched touch
keyname keyname
keypad inopts
killchar termattr
leaveok outopts
longname termattr
meta inopts
move move
mvaddch addch
mvaddchnstr addchstr
mvaddchstr addchstr
mvaddnstr addstr
mvaddstr addstr
mvchgat attr
mvcur terminfo
mvdelch delch
mvderwin window
mvgetch getch
mvgetnstr getstr
mvgetstr getstr
mvhline border
mvinch inch
mvinchnstr inchstr
mvinchstr inchstr
mvinnstr instr
mvinsch insch
mvinsnstr insstr
mvinsstr insstr
mvinstr instr
mvprintw printw
mvscanw scanw
mvvline border
mvwaddchnstr addchstr
mvwaddchstr addchstr
mvwaddch addch
mvwaddnstr addstr
mvwaddstr addstr
mvwchgat attr
mvwdelch delch
mvwgetch getch
mvwgetnstr getstr
mvwgetstr getstr
mvwhline border
mvwinchnstr inchstr
mvwinchstr inchstr
mvwinch inch
mvwinnstr instr
mvwinsch insch
mvwinsnstr insstr
mvwinsstr insstr
mvwinstr instr
mvwin window
mvwprintw printw
mvwscanw scanw
mvwvline border
napms kernel
newpad pad
newterm initscr
newwin window
nl inopts
nocbreak inopts
nodelay inopts
noecho inopts
nonl inopts
noqiflush inopts
noraw inopts
notimeout inopts
overlay overlay
overwrite overlay
pair_content color
pechochar pad
pnoutrefresh pad
prefresh pad
printw printw
putp terminfo
putwin scr_dump
qiflush inopts
raw inopts
redrawwin refresh
refresh refresh
reset_prog_mode kernel
reset_shell_mode kernel
resetty kernel
restartterm terminfo
ripoffline kernel
savetty kernel
scanw scanw
scr_dump scr_dump
scr_init scr_dump
scr_restore scr_dump
scr_set scr_dump
scrl scroll
scroll scroll
scrollok outopts
set_term initscr
setscrreg outopts
setterm terminfo
setupterm terminfo
slk_attroff slk
slk_attr_off slk
slk_attron slk
slk_attr_on slk
slk_attrset slk
slk_attr_set slk
slk_clear slk
slk_color slk
slk_init slk
slk_label slk
slk_noutrefresh slk
slk_refresh slk
slk_restore slk
slk_set slk
slk_touch slk
standend attr
standout attr
start_color color
subpad pad
subwin window
syncok window
termattrs termattrs
term_attrs termattrs
termname termattrs
tgetent termcap
tgetflag termcap
tgetnum termcap
tgetstr termcap
tgoto termcap
tigetflag terminfo
tigetnum terminfo
tigetstr terminfo
timeout inopts
touchline touch
touchwin touch
tparm terminfo
tputs terminfo
typeahead inopts
untouchwin touch
use_env util
vidattr terminfo
vid_attr terminfo
vidputs terminfo
vid_puts terminfo
vline border
vw_printw printw
vwprintw printw
vw_scanw scanw
vwscanw scanw
waddchnstr addchstr
waddchstr addchstr
waddch addch
waddnstr addstr
waddstr addstr
wattroff attr
wattron attr
wattrset attr
wattr_get attr
wattr_off attr
wattr_on attr
wattr_set attr
wbkgdset bkgd
wbkgd bkgd
wborder border
wchgat attr
wclear clear
wclrtobot clear
wclrtoeol clear
wcolor_set attr
wcursyncup window
wdelch delch
wdeleteln deleteln
wechochar addch
werase clear
wgetch getch
wgetnstr getstr
wgetstr getstr
whline border
winchnstr inchstr
winchstr inchstr
winch inch
winnstr instr
winsch insch
winsdelln deleteln
winsertln deleteln
winsnstr insstr
winsstr insstr
winstr instr
wmove move
wnoutrefresh refresh
wprintw printw
wredrawln refresh
wrefresh refresh
wscanw scanw
wscrl scroll
wsetscrreg outopts
wstandend attr
wstandout attr
wsyncdown window
wsyncup window
wtimeout inopts
wtouchln touch
wvline border
Wide-character functions from the X/Open standard -- these are only
available when PDCurses is built with PDC_WIDE defined, and the
prototypes are only available from curses.h when PDC_WIDE is defined
before its inclusion in your app:
addnwstr addstr
addwstr addstr
add_wch addch
add_wchnstr addchstr
add_wchstr addchstr
border_set border
box_set border
echo_wchar addch
erasewchar termattr
getbkgrnd bkgd
getcchar util
getn_wstr getstr
get_wch getch
get_wstr getstr
hline_set border
innwstr instr
ins_nwstr insstr
ins_wch insch
ins_wstr insstr
inwstr instr
in_wch inch
in_wchnstr inchstr
in_wchstr inchstr
key_name keyname
killwchar termattr
mvaddnwstr addstr
mvaddwstr addstr
mvadd_wch addch
mvadd_wchnstr addchstr
mvadd_wchstr addchstr
mvgetn_wstr getstr
mvget_wch getch
mvget_wstr getstr
mvhline_set border
mvinnwstr instr
mvins_nwstr insstr
mvins_wch insch
mvins_wstr insstr
mvinwstr instr
mvwaddnwstr addstr
mvwaddwstr addstr
mvwadd_wch addch
mvwadd_wchnstr addchstr
mvwadd_wchstr addchstr
mvwgetn_wstr getstr
mvwget_wch getch
mvwget_wstr getstr
mvwhline_set border
mvwinnwstr instr
mvwins_nwstr insstr
mvwins_wch insch
mvwins_wstr insstr
mvwin_wch inch
mvwin_wchnstr inchstr
mvwin_wchstr inchstr
mvwinwstr instr
mvwvline_set border
pecho_wchar pad
setcchar util
slk_wset slk
unget_wch getch
vline_set border
waddnwstr addstr
waddwstr addstr
wadd_wch addch
wadd_wchnstr addchstr
wadd_wchstr addchstr
wbkgrnd bkgd
wbkgrndset bkgd
wborder_set border
wecho_wchar addch
wgetbkgrnd bkgd
wgetn_wstr getstr
wget_wch getch
wget_wstr getstr
whline_set border
winnwstr instr
wins_nwstr insstr
wins_wch insch
wins_wstr insstr
winwstr instr
win_wch inch
win_wchnstr inchstr
win_wchstr inchstr
wunctrl util
wvline_set border
Quasi-standard functions, from Sys V or BSD curses:
getattrs attr
getbegx getyx
getbegy getyx
getmaxx getyx
getmaxy getyx
getparx getyx
getparx getyx
traceoff debug
traceon debug
unctrl util
Classic PDCurses mouse functions, based on Sys V:
mouse_set mouse
mouse_on mouse
mouse_off mouse
request_mouse_pos mouse
map_button mouse
wmouse_position mouse
getmouse mouse
getbmap mouse
Functions from ncurses:
assume_default_colors color
curses_version initscr
has_key keyname
use_default_colors color
wresize window
mouseinterval mouse
mousemask mouse
mouse_trafo mouse
nc_getmouse mouse
ungetmouse mouse
wenclose mouse
wmouse_trafo mouse
PDCurses-specific functions -- avoid these in code that's intended to be
portable:
addrawch addch
insrawch insch
is_termresized initscr
mvaddrawch addch
mvdeleteln deleteln
mvinsertln deleteln
mvinsrawch insch
mvwaddrawch addch
mvwdeleteln deleteln
mvwinsertln deleteln
mvwinsrawch insch
raw_output outopts
resize_term initscr
resize_window window
slk_wlabel slk
waddrawch addch
winsrawch insch
wordchar termattr
PDC_debug debug
PDC_ungetch getch
PDC_set_blink pdcsetsc
PDC_set_line_color color
PDC_set_title pdcsetsc
PDC_clearclipboard pdcclip
PDC_freeclipboard pdcclip
PDC_getclipboard pdcclip
PDC_setclipboard pdcclip
PDC_get_input_fd pdckbd
PDC_get_key_modifiers getch
PDC_return_key_modifiers getch
PDC_save_key_modifiers getch
Functions specific to the X11 port of PDCurses:
Xinitscr initscr
XCursesExit -
sb_init sb
sb_set_horz sb
sb_set_vert sb
sb_get_horz sb
sb_get_vert sb
sb_refresh sb
--------------------------------------------------------------------------

View File

@@ -0,0 +1,119 @@
/***********************************************************************/
/* MANEXT - Extract manual pages from C source code. */
/***********************************************************************/
/*
* MANEXT - A program to extract manual pages from C source code.
* Copyright (C) 1991-1996 Mark Hessling
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program 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
* General Public License for more details.
*
* If you make modifications to this software that you feel increases
* it usefulness for the rest of the community, please email the
* changes, enhancements, bug fixes as well as any and all ideas to me.
* This software is going to be maintained and enhanced as deemed
* necessary by the community.
*
* Mark Hessling <mark@rexx.org>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE 255
void display_info()
{
fprintf(stderr, "\nMANEXT 1.03 Copyright (C) 1991-1996 Mark Hessling\n"
"All rights reserved.\n"
"MANEXT is distributed under the terms of the GNU\n"
"General Public License and comes with NO WARRANTY.\n"
"See the file COPYING for details.\n"
"\nUsage: manext sourcefile [...]\n\n");
}
int main(int argc, char **argv)
{
char s[MAX_LINE + 1]; /* input line */
int i;
FILE *fp;
#ifdef __EMX__
_wildcard(&argc, &argv);
#endif
if (strcmp(argv[1], "-h") == 0)
{
display_info();
exit(1);
}
for (i = 1; i < argc; i++)
{
if ((fp = fopen(argv[i], "r")) == NULL)
{
fprintf(stderr, "\nCould not open %s\n", argv[i]);
continue;
}
while (!feof(fp))
{
if (fgets(s, (int)sizeof(s), fp) == NULL)
{
if (ferror(fp) != 0)
{
fprintf(stderr, "*** Error reading %s. Exiting.\n",
argv[i]);
exit(1);
}
break;
}
/* check for manual entry marker at beginning of line */
if (strncmp(s, "/*man-start*", 12) != 0)
continue;
/* inner loop */
for (;;)
{
/* read next line of manual entry */
if (fgets(s, (int)sizeof(s), fp) == NULL)
{
if (ferror(fp) != 0)
{
fprintf(stderr, "*** Error reading %s. Exiting.\n",
argv[i]);
exit(1);
}
break;
}
/* check for end of entry marker */
if (strncmp(s, "**man-end", 9) == 0)
break;
printf("%s", s);
}
printf("\n\n-----------------------------------"
"---------------------------------------\n\n");
}
fclose(fp);
}
return 0;
}

View File

@@ -0,0 +1,152 @@
SDL Considerations
==================
There are no special requirements to use PDCurses for SDL -- all
PDCurses-compatible code should work fine. (In fact, you can even build
against the Win32 console pdcurses.dll, and then swap in the SDL
pdcurses.dll.) Nothing extra is needed beyond the base SDL library.
However, there are some optional special features, described here.
The principal limitation of this port is that input is currently
restricted to ASCII (i.e., 0-127), plus the special keys like KEY_LEFT.
(You could have Unicode input, but then the input wouldn't match the
output, which is in Code Page 437.) Also, see the note about the
potential for incomplete output under "PDC_update_rects()", below.
Fonts
-----
The font is a simple BMP, 32 characters wide by 8 characters tall,
preferably with a palette. (BMPs without palettes still work, but in
that case, no attributes will be available, nor will the cursor work.)
The first entry in the palette (usually black) is treated as the
background color; the last entry (usually white) is treated as the
foreground. These are changed or made transparent as appropriate; any
other colors in the palette are passed through unchanged. So -- although
a one-bit depth is sufficient for a normal font -- you could redraw some
characters as multi-colored tiles.
The font must be monospaced. The size of each character is derived by
dividing the width of the BMP by 32 and the height by 8. There is no
constraint on the dimensions.
As provided in the default font and expected by acs_map[], the font is
in Code Page 437 form. But you can of course use any layout if you're
not relying on correct values for the ACS_* macros.
The font can be set via the environment variable PDC_FONT. If it's not
set, PDCurses looks for a file named "pdcfont.bmp" in the current
directory at the time of initscr(). If neither is found, it uses the
built-in default font encoded in deffont.h.
Backgrounds
-----------
PDCurses for SDL supports an optional background image BMP. This is used
whenever start_color() has not been called (see the ptest demo for an
example), or when use_default_colors() has been called after
start_color(), and the background color of a pair has been set to -1
(see newdemo, worm, and rain for examples). The usage parallels that of
ncurses in an appropriate terminal (e.g., Gnome Terminal). The image is
tiled to cover the PDCurses window, and can be any size or depth.
As with the font, you can point to a location for the background via the
environment variable PDC_BACKGROUND; "pdcback.bmp" is the fallback.
(There is no default background.)
Icons
-----
The icon (used with SDL_WM_SetIcon() -- not used for the executable
file) can be set via the environment variable PDC_ICON, and falls back
to "pdcicon.bmp", and then to the built-in icon from deficon.h. The
built-in icon is the PDCurses logo, as seen in ../x11/little_icon.xbm.
The SDL docs say that the icon must be 32x32, at least for use with MS
Windows.
If pdc_screen is preinitialized (see below), PDCurses does not attempt
to set the icon.
Screen size
-----------
The default screen size is 80x25 characters (whatever size they may be),
but you can override this via the environment variables PDC_COLS and/or
PDC_LINES. (Some other ports use COLS and LINES; this is not done here
because those values are, or should be, those of the controlling
terminal, and PDCurses for SDL is independent of the terminal.) If
pdc_screen is preinitialized (see below), these are ignored.
Integration with SDL
--------------------
If you want to go further, you can mix PDCurses and SDL functions. (Of
course this is extremely non-portable!) To aid you, there are several
external variables and functions specific to the SDL port; you could
include pdcsdl.h, or just add the declarations you need in your code:
PDCEX SDL_Surface *pdc_screen, *pdc_font, *pdc_icon, *pdc_back;
PDCEX int pdc_sheight, pdc_swidth, pdc_yoffset, pdc_xoffset;
void PDC_update_rects(void);
void PDC_retile(void);
pdc_screen is the main surface, created by SDL_SetVideoMode(), unless
it's preset before initscr(). You can perform normal SDL operations on
this surface, but PDCurses won't respect them when it updates. (For
that, see PDC_retile().) As an alternative, you can preinitialize this
surface before calling initscr(). In that case, you can use pdc_sheight,
pdc_swidth, pdc_yoffset and/or pdc_xoffset (q.v.) to confine PDCurses to
only a specific area of the surface, reserving the rest for other SDL
operations. If you preinitialize pdc_screen, you'll have to close it
yourself; PDCurses will ignore resize events, and won't try to set the
icon. Also note that if you preinitialize pdc_screen, it need not be the
display surface.
pdc_font, pdc_icon, and pdc_back are the SDL_surfaces for the font,
icon, and background, respectively. You can set any or all of them
before initscr(), and thus override any of the other ways to set them.
But note that pdc_icon will be ignored if pdc_screen is preset.
pdc_sheight and pdc_swidth are the dimensions of the area of pdc_screen
to be used by PDCurses. You can preset them before initscr(); if either
is not set, it defaults to the full screen size minus the x or y offset,
as appropriate.
pdc_xoffset and pdc_yoffset are the x and y offset for the area of
pdc_screen to be used by PDCurses. See the sdltest demo for an example.
PDC_retile() makes a copy of pdc_screen, then tiles it with the
background image, if any. The resulting surface is used as the
background for transparent character cells. PDC_retile() is called from
initscr() and resize_term(). However, you can also use it at other
times, to take advantage of the way it copies pdc_screen: Draw some SDL
stuff; call PDC_retile(); do some curses stuff -- it will use whatever
was on pdc_screen as the background. Then you can erase the curses
screen, do some more SDL stuff, and call PDC_retile() again to make a
new background. (If you don't erase the curses screen, it will be
incorporated into the background when you call PDC_retile().) But this
only works if no background image is set.
PDC_update_rects() is how the screen actually gets updated. For
performance reasons, when drawing, PDCurses for SDL maintains a table of
rectangles that need updating, and only updates (by calling this
function) during getch(), napms(), or when the table gets full.
Normally, this is sufficient; but if you're pausing in some way other
than by using napms(), and you're not doing keyboard checks, you may get
an incomplete update. If that happens, you can call PDC_update_rects()
manually.
Interaction with stdio
----------------------
As with X11, it's a bad idea to mix curses and stdio calls. (In fact,
that's true for PDCurses on any platform; but especially these two,
which don't run under terminals.) Depending on how SDL is built, stdout
and stderr may be redirected to files.

View File

@@ -0,0 +1,416 @@
X11 Considerations
==================
PDCurses for X11 uses the System V IPC shared memory facility, along
with sockets, to share data between the curses program and the child
process created to manage the X stuff.
When compiling your application, you need to include the <curses.h> or
<xcurses.h> that comes with PDCurses. You also need to link your code
with libXCurses. You may need to link with the following libraries under
X11R5:
Xaw Xmu Xt X11
or, under X11R6:
Xaw Xmu Xt X11 SM ICE Xext
You can run "xcurses-config --libs" to show the link parameters for your
system. If using dynamic linking, on some systems, "-lXCurses" suffices.
By calling Xinitscr() rather than initscr(), you can pass your program
name and resource overrides to PDCurses. The program name is used as the
title of the X window, and for defining X resources specific to your
program.
Interaction with stdio
----------------------
Be aware that curses programs that expect to have a normal tty
underneath them will be very disappointed! Output directed to stdout
will go to the xterm that invoked the PDCurses application, or to the
console if not invoked directly from an xterm. Similarly, stdin will
expect its input from the same place as stdout.
X Resources
-----------
PDCurses for X11 recognizes the following resources:
lines
cols
normalFont
italicFont
pointer
pointerForeColor
pointerBackColor
cursorColor
textCursor
colorBlack
colorRed
colorGreen
colorYellow
colorBlue
colorMagenta
colorCyan
colorWhite
colorBoldBlack
colorBoldRed
colorBoldGreen
colorBoldYellow
colorBoldBlue
colorBoldMagenta
colorBoldCyan
colorBoldWhite
bitmap
pixmap
translations
shmmin
borderWidth
borderColor
clickPeriod
doubleClickPeriod
composeKey
lines: Specifies the number of lines the "screen" will have.
Directly equates to LINES.
There is no theoretical maximum.
The minimum value must be 2.
Default: 24
cols: Specifies the number of columns the "screen" will have.
Directly equates to COLS.
There is no theoretical maximum.
The minimum value must be 2.
Default: 80
normalFont: The name of a fixed width font.
Default: 7x13
italicFont: The name of a fixed width font to be used for
characters with A_ITALIC attributes. Must have the
same cell size as normalFont.
Default: 7x13 (obviously not an italic font)
pointer: The name of a valid pointer cursor.
Default: xterm
pointerForeColor: The foreground color of the pointer.
Default: black
pointerBackColor: The background color of the pointer.
Default: white
textCursor: The alignment of the text cursor; horizontal or vertical.
Default: horizontal
colorBlack: The color of the COLOR_BLACK attribute.
Default: Black
colorRed: The color of the COLOR_RED attribute.
Default: red3
colorGreen: The color of the COLOR_GREEN attribute.
Default: green3
colorYellow: The color of the COLOR_YELLOW attribute.
Default: yellow3
colorBlue: The color of the COLOR_BLUE attribute.
Default: blue3
colorMagenta: The color of the COLOR_MAGENTA attribute.
Default: magenta3
colorCyan: The color of the COLOR_CYAN attribute.
Default: cyan3
colorWhite: The color of the COLOR_WHITE attribute.
Default: Grey
colorBoldBlack: COLOR_BLACK combined with A_BOLD.
Default: grey40
colorBoldRed: COLOR_RED combined with A_BOLD.
Default: red1
colorBoldGreen: COLOR_GREEN combined with A_BOLD.
Default: green1
colorBoldYellow: COLOR_YELLOW combined with A_BOLD.
Default: yellow1
colorBoldBlue: COLOR_BLUE combined with A_BOLD.
Default: blue1
colorBoldMagenta: COLOR_MAGENTA combined with A_BOLD.
Default: magenta1
colorBoldCyan: COLOR_CYAN combined with A_BOLD.
Default: cyan1
colorBoldWhite: COLOR_WHITE combined with A_BOLD.
Default: White
bitmap: The name of a valid bitmap file of depth 1 (black and white)
used for the application's icon. The file is an X bitmap.
Default: a 32x32 or 64x64 pixmap depending on the
window manager
pixmap: The name of a valid pixmap file of any depth
supported by the window manager (color) for the
application's icon, The file is an X11 pixmap. This
resource is only available if the libXpm package has
been installed (most systems have this by default).
This resource overrides the "bitmap" resource.
Default: none, uses default bitmap above
translations: Translations enable the user to customize the action
that occurs when a key, combination of keys, or a
button is pressed. The translations are similar to
those used by xterm.
Defaults:
<Key>: XCursesKeyPress()
<KeyUp>: XCursesKeyPress()
<BtnDown>: XCursesButton()
<BtnUp>: XCursesButton()
<BtnMotion>: XCursesButton()
The most useful action for KeyPress translations is
string(). The argument to the string() action can be
either a string or a hex representation of a
character; e.g., string(0x1b) will send the ASCII
escape character to the application; string("[11~")
will send [ 1 1 ~ , as separate keystrokes.
shmmin: On most systems, there are two Unix kernel parameters
that determine the allowable size of a shared memory
segment. These parameters are usually something like
SHMMIN and SHMMAX. To use shared memory, a program
must allocate a segment of shared memory that is
between these two values. Usually these values are
like 1 for SHMMIN and some large number for SHMMAX.
Sometimes the Unix kernel is configured to have a
value of SHMMIN that is bigger than the size of one
of the shared memory segments that libXCurses uses.
On these systems an error message like:
Cannot allocate shared memory for SCREEN: Invalid argument
will result. To overcome this problem, this resource
should be set to the kernel value for SHMMIN. This
ensures that a shared memory segment will always be
bigger than the kernel value for SHMMIN (and
hopefully less than SHMMAX!)
Default: 0
borderColor: The color of the border around the screen.
Default: black
borderWidth: The width in pixels of the border around the screen.
Default: 0
clickPeriod: The period (in milliseconds) between a button
press and a button release that determines if a click
of a button has occurred.
Default: 100
doubleClickPeriod: The period (in milliseconds) between two button
press events that determines if a double click
of a button has occurred.
Default: 200
composeKey: The name of the X key that defines the "compose key",
which is used to enter characters in the Latin-1
character set above 0xA0. (See "Compose Keys for
Latin-1" below.) This is used only when PDCurses is
built without XIM support. While in compose mode, the
text cursor will appear as a hollow rectangle.
Default: Multi_key
Using Resources
---------------
All applications have a top-level class name of "XCurses". If Xinitscr()
is used, it sets an application's top-level widget name. (Otherwise the
name defaults to "PDCurses".)
Examples for app-defaults or .Xdefaults:
!
! resources for XCurses class of programs
!
XCurses*lines: 30
XCurses*cols: 80
XCurses*normalFont: 9x13
XCurses*bitmap: /tmp/xcurses.xbm
XCurses*pointer: top_left_arrow
!
! resources for testcurs - XCurses
!
testcurs.colorRed: orange
testcurs.colorBlack: midnightblue
testcurs.lines: 25
*testcurs.Translations: #override \n \
<Key>F12: string(0x1b) string("[11~") \n
!
! resources for THE - XCurses
!
! resources with the * wildcard can be overridden by a parameter passed
! to initscr()
!
the*normalFont: 9x15
the*lines: 40
the*cols: 86
the*pointer: xterm
the*pointerForeColor: white
the*pointerBackColor: black
!
! resources with the . format can not be overridden by a parameter passed
! to Xinitscr()
!
the.bitmap: /home/mark/the/the64.xbm
the.pixmap: /home/mark/the/the64.xpm
Resources may also be passed as parameters to the Xinitscr() function.
Parameters are strings in the form of switches; e.g., to set the color
"red" to "indianred", and the number of lines to 30, the string passed
to Xinitscr would be: "-colorRed indianred -lines 30"
Compose Keys for Latin-1
------------------------
When built without XIM support, PDCurses for X11 provides its own,
limited compose key system for Latin-1 characters. The available
combinations are listed here. For a given character, any of the
combinations shown in the last column may be used. To generate a
character, press the "compose" key followed by one of the pairs of
keystrokes. Where no key is evident, the spacebar is used. Thus, to
generate the NO-BREAK SPACE, press the "compose" key followed by two
hits of the spacebar.
With a typical modern X server, you can get many more compose key
combinations by using XIM instead. Configure PDCurses with --enable-xim
to use XIM support.
This document is encoded in UTF-8.
+----+-----+---+---------------------------------+---------------------------+
|Hex | Dec |Chr| Description ISO 10646-1:1993(E) | Compose key combinations |
+----+-----+---+---------------------------------+---------------------------+
| A0 | 160 | | NO-BREAK SPACE | |
| A1 | 161 | ¡ | INVERTED EXCLAMATION MARK | ! !! |
| A2 | 162 | ¢ | CENT SIGN | c| |c c/ c$ C$ C| |
| A3 | 163 | £ | POUND SIGN | L- L$ L= l- l$ l= |-|
| A4 | 164 | ¤ | CURRENCY SIGN | xo ox XO g$ |
| A5 | 165 | ¥ | YEN SIGN | =y y= =Y Y= Y- y$ y-|
| A6 | 166 | ¦ | BROKEN BAR | | || vb VB |^ |
| A7 | 167 | § | SECTION SIGN | SO SS s! S! so |
| A8 | 168 | ¨ | DIAERESIS | " "" |
| A9 | 169 | © | COPYRIGHT SIGN | CO co OC |
| AA | 170 | ª | FEMININE ORDINAL INDICATOR | sa SA a_ A_ |
| AB | 171 | « | LEFT DOUBLE ANGLE QUOTES | << |
| AC | 172 | ¬ | NOT SIGN | -, no NO |
| AD | 173 | ­ | SOFT HYPHEN | - -- |
| AE | 174 | ® | REGISTERED SIGN | RO ro OR |
| AF | 175 | ¯ | MACRON | -^ _^ __ |
| B0 | 176 | ° | DEGREE SIGN | o 0^ 0* de DE ^0 |
| B1 | 177 | ± | PLUS-MINUS SIGN | -+ +- |
| B2 | 178 | ² | SUPERSCRIPT TWO | 2 2^ s2 ^2 |
| B3 | 179 | ³ | SUPERSCRIPT THREE | 3 3^ s3 ^3 |
| B4 | 180 | ´ | ACUTE ACCENT | ' '' |
| B5 | 181 | µ | MICRO SIGN | u /u /U *m *M |
| B6 | 182 | ¶ | PILCROW SIGN | p! P! pg PG |
| B7 | 183 | · | MIDDLE DOT | . .^ .. |
| B8 | 184 | ¸ | CEDILLA | , ,, |
| B9 | 185 | ¹ | SUPERSCRIPT ONE | 1 1^ s1 ^1 |
| BA | 186 | º | MASCULINE ORDINAL INDICATOR | o_ s0 S0 |
| BB | 187 | » | RIGHT DOUBLE ANGLE QUOTES | >> |
| BC | 188 | ¼ | VULGAR FRACTION ONE QUARTER | 14 |
| BD | 189 | ½ | VULGAR FRACTION ONE HALF | 12 |
| BE | 190 | ¾ | VULGAR FRACTION THREE QUARTERS | 34 |
| BF | 191 | ¿ | INVERTED QUESTION MARK | ? ?? |
| C0 | 192 | À | CAPITAL A WITH GRAVE ACCENT | `A A` |
| C1 | 193 | Á | CAPITAL A WITH ACUTE ACCENT | 'A A' |
| C2 | 194 | Â | CAPITAL A WITH CIRCUMFLEX ACCENT| ^A A^ A> |
| C3 | 195 | Ã | CAPITAL A WITH TILDE | ~A A~ A- |
| C4 | 196 | Ä | CAPITAL A WITH DIAERESIS | "A A" |
| C5 | 197 | Å | CAPITAL A WITH RING ABOVE | oA Ao A* OA *A |
| C6 | 198 | Æ | CAPITAL LIGATURE AE | AE |
| C7 | 199 | Ç | CAPITAL C WITH CEDILLA | ,C C, |
| C8 | 200 | È | CAPITAL E WITH GRAVE ACCENT | `E E` |
| C9 | 201 | É | CAPITAL E WITH ACUTE ACCENT | 'E E' |
| CA | 202 | Ê | CAPITAL E WITH CIRCUMFLEX ACCENT| ^E E^ E> |
| CB | 203 | Ë | CAPITAL E WITH DIAERESIS | "E E" |
| CC | 204 | Ì | CAPITAL I WITH GRAVE ACCENT | `I I` |
| CD | 205 | Í | CAPITAL I WITH ACUTE ACCENT | 'I I' |
| CE | 206 | Î | CAPITAL I WITH CIRCUMFLEX ACCENT| ^I I^ I> |
| CF | 207 | Ï | CAPITAL I WITH DIAERESIS | "I I" |
| D0 | 208 | Ð | CAPITAL ETH | D- |
| D1 | 209 | Ñ | CAPITAL N WITH TILDE | ~N N~ N- |
| D2 | 210 | Ò | CAPITAL O WITH GRAVE ACCENT | `O O` |
| D3 | 211 | Ó | CAPITAL O WITH ACUTE ACCENT | 'O O' |
| D4 | 212 | Ô | CAPITAL O WITH CIRCUMFLEX ACCENT| ^O O^ O> |
| D5 | 213 | Õ | CAPITAL O WITH TILDE | ~O O~ O- |
| D6 | 214 | Ö | CAPITAL O WITH DIAERESIS | "O O" |
| D7 | 215 | × | MULTIPLICATION SIGN | x xx XX mu MU |
| D8 | 216 | Ø | CAPITAL O WITH STROKE | /O O/ |
| D9 | 217 | Ù | CAPITAL U WITH GRAVE ACCENT | `U U` |
| DA | 218 | Ú | CAPITAL U WITH ACUTE ACCENT | 'U U' |
| DB | 219 | Û | CAPITAL U WITH CIRCUMFLEX ACCENT| ^U U^ U> |
| DC | 220 | Ü | CAPITAL U WITH DIAERESIS | "U U" |
| DD | 221 | Ý | CAPITAL Y WITH ACUTE ACCENT | 'Y Y' |
| DE | 222 | Þ | CAPITAL THORN | P TH |P |
| DF | 223 | ß | SMALL SHARP S | ss |
| E0 | 224 | à | SMALL A WITH GRAVE ACCENT | `a a` |
| E1 | 225 | á | SMALL A WITH ACUTE ACCENT | 'a a' |
| E2 | 226 | â | SMALL A WITH CIRCUMFLEX ACCENT | ^a a^ a> |
| E3 | 227 | ã | SMALL A WITH TILDE | ~a a~ a- |
| E4 | 228 | ä | SMALL A WITH DIAERESIS | "a a" |
| E5 | 229 | å | SMALL A WITH RING ABOVE | oa ao Oa a* *a |
| E6 | 230 | æ | SMALL LIGATURE AE | ae |
| E7 | 231 | ç | SMALL C WITH CEDILLA | ,c c, |
| E8 | 232 | è | SMALL E WITH GRAVE ACCENT | `e e` |
| E9 | 233 | é | SMALL E WITH ACUTE ACCENT | 'e e' |
| EA | 234 | ê | SMALL E WITH CIRCUMFLEX ACCENT | ^e e^ e> |
| EB | 235 | ë | SMALL E WITH DIAERESIS | "e e" |
| EC | 236 | ì | SMALL I WITH GRAVE ACCENT | `i i` |
| ED | 237 | í | SMALL I WITH ACUTE ACCENT | 'i i' |
| EE | 238 | î | SMALL I WITH CIRCUMFLEX ACCENT | ^i i^ i> |
| EF | 239 | ï | SMALL I WITH DIAERESIS | "i i" |
| F0 | 240 | ð | SMALL ETH | d- |
| F1 | 241 | ñ | SMALL N WITH TILDE | ~n n~ n- |
| F2 | 242 | ò | SMALL O WITH GRAVE ACCENT | `o o` |
| F3 | 243 | ó | SMALL O WITH ACUTE ACCENT | 'o o' |
| F4 | 244 | ô | SMALL O WITH CIRCUMFLEX ACCENT | ^o o^ o> |
| F5 | 245 | õ | SMALL O WITH TILDE | ~o o~ o- |
| F6 | 246 | ö | SMALL O WITH DIAERESIS | "o o" |
| F7 | 247 | ÷ | DIVISION SIGN | -: :- |
| F8 | 248 | ø | SMALL O WITH OBLIQUE BAR | /o o/ |
| F9 | 249 | ù | SMALL U WITH GRAVE ACCENT | `u u` |
| FA | 250 | ú | SMALL U WITH ACUTE ACCENT | 'u u' |
| FB | 251 | û | SMALL U WITH CIRCUMFLEX ACCENT | ^u u^ u> |
| FC | 252 | ü | SMALL U WITH DIAERESIS | "u u" |
| FD | 253 | ý | SMALL Y WITH ACUTE ACCENT | 'y y' |
| FE | 254 | þ | SMALL THORN | p th |p |
| FF | 255 | ÿ | SMALL Y WITH DIAERESIS | "y y" |
+----+-----+---+---------------------------------+---------------------------+
Deprecated
----------
XCursesProgramName is no longer used. To set the program name, you must
use Xinitscr(), or PDC_set_title() to set just the window title.
The XCursesExit() function is now called automatically via atexit().
(Multiple calls to it are OK, so you don't need to remove it if you've
already added it for previous versions of PDCurses.)
XCURSES is no longer defined automatically, but need not be defined,
unless you want the X11-specific prototypes. (Normal curses programs
won't need it.)

View File

@@ -0,0 +1,49 @@
PDCurses for DOS
================
This directory contains PDCurses source code files specific to DOS.
Building
--------
. Choose the appropriate makefile for your compiler:
bccdos.mak - Borland C++ 3.0+
gccdos.mak - DJGPP V2
mscdos.mak - Microsoft C
wccdos16.mak - Watcom 10.6+ (16-bit)
wccdos4g.mak - Watcom 10.6+ (32-bit)
. For 16-bit compilers, you can change the memory MODEL in the makefile.
(Large model is the default, and recommended.)
. Optionally, you can build in a different directory than the platform
directory by setting PDCURSES_SRCDIR to point to the directory where
you unpacked PDCurses, and changing to your target directory:
set PDCURSES_SRCDIR=c:\pdcurses
. Build it:
make -f makefile
(For Watcom, use "wmake" instead of "make"; for MSVC, "nmake".) You'll
get the libraries (pdcurses.lib or .a, depending on your compiler; and
panel.lib or .a), the demos (*.exe), and a lot of object files. Note
that the panel library is just a copy of the main library, provided
for convenience; both panel and curses functions are in the main
library.
Distribution Status
-------------------
The files in this directory are released to the Public Domain.
Acknowledgements
----------------
Watcom C port was provided by Pieter Kunst <kunst@prl.philips.nl>
DJGPP 1.x port was provided by David Nugent <davidn@csource.oz.au>

View File

@@ -0,0 +1,9 @@
+addch.obj +addchstr.obj +addstr.obj +attr.obj +beep.obj +bkgd.obj &
+border.obj +clear.obj +color.obj +delch.obj +deleteln.obj +deprec.obj &
+getch.obj +getstr.obj +getyx.obj +inch.obj +inchstr.obj +initscr.obj &
+inopts.obj +insch.obj +insstr.obj +instr.obj +kernel.obj +keyname.obj &
+mouse.obj +move.obj +outopts.obj +overlay.obj +pad.obj +panel.obj &
+printw.obj +refresh.obj +scanw.obj +scr_dump.obj +scroll.obj +slk.obj &
+termattr.obj +terminfo.obj +touch.obj +util.obj +window.obj +debug.obj &
+pdcclip.obj +pdcdisp.obj +pdcgetsc.obj +pdckbd.obj +pdcscrn.obj &
+pdcsetsc.obj +pdcutil.obj ,lib.map

View File

@@ -0,0 +1,82 @@
# Borland MAKE Makefile for PDCurses library - DOS BC++ 3.0+
#
# Usage: make -f [path\]bccdos.mak [DEBUG=] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
# Change the memory MODEL here, if desired
MODEL = l
O = obj
!ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
!include $(PDCURSES_SRCDIR)\libobjs.mif
osdir = $(PDCURSES_SRCDIR)\dos
!ifdef DEBUG
CFLAGS = -N -v -y -DPDCDEBUG
!else
CFLAGS = -O
!endif
CPPFLAGS = -I$(PDCURSES_SRCDIR)
BUILD = $(CC) -1- -K -G -rd -d -w-eff -w-par -c \
-m$(MODEL) $(CFLAGS) $(CPPFLAGS)
LIBEXE = tlib /C /E
LIBCURSES = pdcurses.lib
all: $(LIBCURSES) $(DEMOS)
clean:
-del *.obj
-del *.lib
-del *.map
-del *.exe
demos: $(DEMOS)
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
-del $@
$(LIBEXE) $@ @$(osdir)\bccdos.lrf
-copy $(LIBCURSES) panel.lib
.autodepend
{$(srcdir)\}.c.obj:
$(BUILD) $<
{$(osdir)\}.c.obj:
$(BUILD) $<
{$(demodir)\}.c.obj:
$(BUILD) $<
.c.obj:
$(BUILD) $<
.obj.exe:
$(CC) -m$(MODEL) -e$@ $** $(LIBCURSES)
tuidemo.exe: tuidemo.obj tui.obj $(LIBCURSES)
$(CC) -m$(MODEL) -e$@ $**
tui.obj: $(demodir)\tui.c $(demodir)\tui.h $(PDCURSES_CURSES_H)
$(BUILD) -I$(demodir) $(demodir)\tui.c
tuidemo.obj: $(demodir)\tuidemo.c $(PDCURSES_CURSES_H)
$(BUILD) -I$(demodir) $(demodir)\tuidemo.c
PLATFORM1 = Borland C++ 3.1
PLATFORM2 = Borland C/C++ 3.1 for DOS
ARCNAME = pdc$(VER)bcc
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,87 @@
# GNU MAKE (3.79.1) Makefile for PDCurses library - DOS DJGPP V2.0+
#
# Usage: make -f [path\]gccdos.mak [DEBUG=Y] [target]
#
# where target can be any of:
# [all|libs|demos|dist|pdcurses.a|testcurs.exe...]
O = o
ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
endif
include $(PDCURSES_SRCDIR)/version.mif
include $(PDCURSES_SRCDIR)/libobjs.mif
osdir = $(PDCURSES_SRCDIR)/dos
PDCURSES_DOS_H = $(osdir)/pdcdos.h
CC = gcc
ifeq ($(DEBUG),Y)
CFLAGS = -g -Wall -DPDCDEBUG
LDFLAGS = -g
else
CFLAGS = -O2 -Wall
LDFLAGS =
endif
CFLAGS += -I$(PDCURSES_SRCDIR)
LINK = gcc
LIBEXE = ar
LIBFLAGS = rcv
LIBCURSES = pdcurses.a
.PHONY: all libs clean demos dist
all: libs demos
libs: $(LIBCURSES)
clean:
-del *.o
-del *.a
-del *.exe
demos: $(DEMOS)
strip *.exe
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $(LIBFLAGS) $@ $?
-copy $(LIBCURSES) panel.a
$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS)
$(PDCOBJS) : $(PDCURSES_DOS_H)
$(DEMOS) : $(PDCURSES_CURSES_H) $(LIBCURSES)
panel.o : $(PANEL_HEADER)
terminfo.o: $(TERM_HEADER)
$(LIBOBJS) : %.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) $<
$(PDCOBJS) : %.o: $(osdir)/%.c
$(CC) -c $(CFLAGS) $<
firework.exe newdemo.exe rain.exe testcurs.exe worm.exe xmas.exe \
ptest.exe: %.exe: $(demodir)/%.c
$(CC) $(CFLAGS) -o$@ $< $(LIBCURSES)
tuidemo.exe: tuidemo.o tui.o
$(LINK) $(LDFLAGS) -o$@ tuidemo.o tui.o $(LIBCURSES)
tui.o: $(demodir)/tui.c $(demodir)/tui.h $(PDCURSES_CURSES_H)
$(CC) -c $(CFLAGS) -I$(demodir) -o$@ $<
tuidemo.o: $(demodir)/tuidemo.c $(PDCURSES_CURSES_H)
$(CC) -c $(CFLAGS) -I$(demodir) -o$@ $<
PLATFORM1 = DJGPP 2.03
PLATFORM2 = DJGPP 2.03 for DOS
ARCNAME = pdc$(VER)djg
include $(PDCURSES_SRCDIR)/makedist.mif

View File

@@ -0,0 +1,50 @@
-+addch.obj &
-+addchstr.obj &
-+addstr.obj &
-+attr.obj &
-+beep.obj &
-+bkgd.obj &
-+border.obj &
-+clear.obj &
-+color.obj &
-+delch.obj &
-+deleteln.obj &
-+deprec.obj &
-+getch.obj &
-+getstr.obj &
-+getyx.obj &
-+inch.obj &
-+inchstr.obj &
-+initscr.obj &
-+inopts.obj &
-+insch.obj &
-+insstr.obj &
-+instr.obj &
-+kernel.obj &
-+keyname.obj &
-+mouse.obj &
-+move.obj &
-+outopts.obj &
-+overlay.obj &
-+pad.obj &
-+panel.obj &
-+printw.obj &
-+refresh.obj &
-+scanw.obj &
-+scr_dump.obj &
-+scroll.obj &
-+slk.obj &
-+termattr.obj &
-+terminfo.obj &
-+touch.obj &
-+util.obj &
-+window.obj &
-+debug.obj &
-+pdcclip.obj &
-+pdcdisp.obj &
-+pdcgetsc.obj &
-+pdckbd.obj &
-+pdcscrn.obj &
-+pdcsetsc.obj &
-+pdcutil.obj &
,lib.map;

View File

@@ -0,0 +1,114 @@
# NMAKE Makefile for PDCurses library - Microsoft C for DOS
#
# Usage: nmake -f [path\]dosmsc.mak [DEBUG=] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
# Change the memory MODEL here, if desired
MODEL = L # one of L, S, M, T, H, C
SIZE = LARGE # one of LARGE, SMALL, MEDIUM, TINY, HUGE, COMPACT
O = obj
!ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
!include $(PDCURSES_SRCDIR)\libobjs.mif
osdir = $(PDCURSES_SRCDIR)\dos
PDCURSES_DOS_H = $(osdir)\pdcdos.h
CC = cl
!ifdef DEBUG
CFLAGS = /Od /Zi /DPDCDEBUG
LDFLAGS = /CO /NOE /SE:160
!else
CFLAGS = /Ox
LDFLAGS = /NOE /SE:160
!endif
CPPFLAGS = -I$(PDCURSES_SRCDIR)
BUILD = $(CC) /J /nologo /c /D$(SIZE) /A$(MODEL) $(CFLAGS) $(CPPFLAGS)
LINK = link
CCLIBS =
LIBEXE = lib
LIBCURSES = pdcurses.lib
all: $(LIBCURSES) $(DEMOS)
clean:
-del *.obj
-del *.lib
-del *.exe
demos: $(DEMOS)
DEMOOBJS = $(DEMOS:.exe=.obj) tui.obj
$(LIBOBJS) $(PDCOBJS) : $(PDCURSES_HEADERS)
$(DEMOOBJS) : $(PDCURSES_CURSES_H)
$(DEMOS) : $(LIBCURSES)
panel.obj : $(PANEL_HEADER)
terminfo.obj: $(TERM_HEADER)
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $@ @$(osdir)\mscdos.lrf
-copy $(LIBCURSES) panel.lib
{$(srcdir)\}.c{}.obj:
$(BUILD) $<
{$(osdir)\}.c{}.obj:
$(BUILD) $<
{$(demodir)\}.c{}.obj:
$(BUILD) $<
firework.exe: firework.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
newdemo.exe: newdemo.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
ptest.exe: ptest.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
rain.exe: rain.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
testcurs.exe: testcurs.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
tuidemo.exe: tuidemo.obj tui.obj
$(LINK) $(LDFLAGS) $*.obj+tui.obj,$*,,$(LIBCURSES);
worm.exe: worm.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
xmas.exe: xmas.obj
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
ptest.obj: $(demodir)\ptest.c $(PANEL_HEADER)
$(BUILD) $(demodir)\ptest.c
tui.obj: $(demodir)\tui.c $(demodir)\tui.h
$(BUILD) -I$(demodir) $(demodir)\tui.c
tuidemo.obj: $(demodir)\tuidemo.c
$(BUILD) -I$(demodir) $(demodir)\tuidemo.c
PLATFORM1 = Microsoft C
PLATFORM2 = Microsoft C for DOS
ARCNAME = pdc$(VER)msc
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,129 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcclip.c,v 1.33 2008/07/13 16:08:17 wmcbrine Exp $")
#include <stdlib.h>
/*man-start**************************************************************
Name: clipboard
Synopsis:
int PDC_getclipboard(char **contents, long *length);
int PDC_setclipboard(const char *contents, long length);
int PDC_freeclipboard(char *contents);
int PDC_clearclipboard(void);
Description:
PDC_getclipboard() gets the textual contents of the system's
clipboard. This function returns the contents of the clipboard
in the contents argument. It is the responsibilitiy of the
caller to free the memory returned, via PDC_freeclipboard().
The length of the clipboard contents is returned in the length
argument.
PDC_setclipboard copies the supplied text into the system's
clipboard, emptying the clipboard prior to the copy.
PDC_clearclipboard() clears the internal clipboard.
Return Values:
indicator of success/failure of call.
PDC_CLIP_SUCCESS the call was successful
PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
the clipboard contents
PDC_CLIP_EMPTY the clipboard contains no text
PDC_CLIP_ACCESS_ERROR no clipboard support
Portability X/Open BSD SYS V
PDC_getclipboard - - -
PDC_setclipboard - - -
PDC_freeclipboard - - -
PDC_clearclipboard - - -
**man-end****************************************************************/
/* global clipboard contents, should be NULL if none set */
static char *pdc_DOS_clipboard = NULL;
int PDC_getclipboard(char **contents, long *length)
{
int len;
PDC_LOG(("PDC_getclipboard() - called\n"));
if (!pdc_DOS_clipboard)
return PDC_CLIP_EMPTY;
len = strlen(pdc_DOS_clipboard);
if ((*contents = malloc(len + 1)) == NULL)
return PDC_CLIP_MEMORY_ERROR;
strcpy(*contents, pdc_DOS_clipboard);
*length = len;
return PDC_CLIP_SUCCESS;
}
int PDC_setclipboard(const char *contents, long length)
{
PDC_LOG(("PDC_setclipboard() - called\n"));
if (pdc_DOS_clipboard)
{
free(pdc_DOS_clipboard);
pdc_DOS_clipboard = NULL;
}
if (contents)
{
if ((pdc_DOS_clipboard = malloc(length + 1)) == NULL)
return PDC_CLIP_MEMORY_ERROR;
strcpy(pdc_DOS_clipboard, contents);
}
return PDC_CLIP_SUCCESS;
}
int PDC_freeclipboard(char *contents)
{
PDC_LOG(("PDC_freeclipboard() - called\n"));
/* should we also free empty the system clipboard? probably not */
if (contents)
{
/* NOTE: We free the memory, but we can not set caller's pointer
to NULL, so if caller calls again then will try to access
free'd memory. We 1st overwrite memory with a string so if
caller tries to use free memory they won't get what they
expect & hopefully notice. */
/* memset(contents, 0xFD, strlen(contents)); */
if (strlen(contents) >= strlen("PDCURSES"))
strcpy(contents, "PDCURSES");
free(contents);
}
return PDC_CLIP_SUCCESS;
}
int PDC_clearclipboard(void)
{
PDC_LOG(("PDC_clearclipboard() - called\n"));
if (pdc_DOS_clipboard)
{
free(pdc_DOS_clipboard);
pdc_DOS_clipboard = NULL;
}
return PDC_CLIP_SUCCESS;
}

View File

@@ -0,0 +1,158 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcdisp.c,v 1.65 2008/07/13 16:08:17 wmcbrine Exp $")
/* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these
match code page 437 and compatible pages (CP850, CP852, etc.) */
#ifdef CHTYPE_LONG
# define A(x) ((chtype)x | A_ALTCHARSET)
chtype acs_map[128] =
{
A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10),
A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19),
A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27), A(28),
A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&', '\'', '(',
')', '*',
A(0x1a), A(0x1b), A(0x18), A(0x19),
'/',
0xdb,
'1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
A(0x04), 0xb1,
'b', 'c', 'd', 'e',
0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d, 0x2d,
0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3, 0xf2, 0xe3,
0xd8, 0x9c, 0xf9,
A(127)
};
# undef A
#endif
#ifdef __PACIFIC__
void movedata(unsigned sseg, unsigned soff, unsigned dseg,
unsigned doff, unsigned n)
{
far char *src = MK_FP(sseg, soff);
far char *dst = MK_FP(dseg, doff);
while (n--)
*dst++ = *src++;
}
#endif
/* position hardware cursor at (y, x) */
void PDC_gotoyx(int row, int col)
{
PDCREGS regs;
PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));
regs.h.ah = 0x02;
regs.h.bh = 0;
regs.h.dh = (unsigned char) row;
regs.h.dl = (unsigned char) col;
PDCINT(0x10, regs);
}
/* update the given physical line to look like the corresponding line in
curscr */
void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
{
int j;
PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno));
if (pdc_direct_video)
{
#if SMALL || MEDIUM
# ifndef __PACIFIC__
struct SREGS segregs;
# endif
int ds;
#endif
/* this should be enough for the maximum width of a screen */
struct {unsigned char text, attr;} temp_line[256];
/* replace the attribute part of the chtype with the actual
color value for each chtype in the line */
for (j = 0; j < len; j++)
{
chtype ch = srcp[j];
temp_line[j].attr = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
#ifdef CHTYPE_LONG
if (ch & A_ALTCHARSET && !(ch & 0xff80))
ch = acs_map[ch & 0x7f];
#endif
temp_line[j].text = ch & 0xff;
}
#ifdef __DJGPP__
dosmemput(temp_line, len * 2,
(unsigned long)_FAR_POINTER(pdc_video_seg,
pdc_video_ofs + (lineno * curscr->_maxx + x) * 2));
#else
# if SMALL || MEDIUM
# ifdef __PACIFIC__
ds = FP_SEG((void far *) temp_line);
# else
segread(&segregs);
ds = segregs.ds;
# endif
movedata(ds, (int)temp_line, pdc_video_seg,
pdc_video_ofs + (lineno * curscr->_maxx + x) * 2, len * 2);
# else
memcpy((void *)_FAR_POINTER(pdc_video_seg,
pdc_video_ofs + (lineno * curscr->_maxx + x) * 2),
temp_line, len * 2);
# endif
#endif
}
else
for (j = 0; j < len;)
{
PDCREGS regs;
unsigned short count = 1;
chtype ch = srcp[j];
while ((j + count < len) && (ch == srcp[j + count]))
count++;
PDC_gotoyx(lineno, j + x);
regs.h.ah = 0x09;
regs.W.bx = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
regs.W.cx = count;
#ifdef CHTYPE_LONG
if (ch & A_ALTCHARSET && !(ch & 0xff80))
ch = acs_map[ch & 0x7f];
#endif
regs.h.al = (unsigned char) (ch & 0xff);
PDCINT(0x10, regs);
j += count;
}
}

View File

@@ -0,0 +1,186 @@
/* Public Domain Curses */
/* $Id: pdcdos.h,v 1.30 2008/07/13 16:08:17 wmcbrine Exp $ */
#include <curspriv.h>
#include <string.h>
#if defined(_MSC_VER) || defined(_QC)
# define MSC 1
#endif
#if defined(__PACIFIC__) && !defined(__SMALL__)
# define __SMALL__
#endif
#if defined(__HIGHC__) || MSC
# include <bios.h>
#endif
/*----------------------------------------------------------------------
* MEMORY MODEL SUPPORT:
*
* MODELS
* TINY cs,ds,ss all in 1 segment (not enough memory!)
* SMALL cs:1 segment, ds:1 segment
* MEDIUM cs:many segments, ds:1 segment
* COMPACT cs:1 segment, ds:many segments
* LARGE cs:many segments, ds:many segments
* HUGE cs:many segments, ds:segments > 64K
*/
#ifdef __TINY__
# define SMALL 1
#endif
#ifdef __SMALL__
# define SMALL 1
#endif
#ifdef __MEDIUM__
# define MEDIUM 1
#endif
#ifdef __COMPACT__
# define COMPACT 1
#endif
#ifdef __LARGE__
# define LARGE 1
#endif
#ifdef __HUGE__
# define HUGE 1
#endif
#include <dos.h>
extern unsigned char *pdc_atrtab;
extern int pdc_adapter;
extern int pdc_scrnmode;
extern int pdc_font;
extern bool pdc_direct_video;
extern bool pdc_bogus_adapter;
extern unsigned pdc_video_seg;
extern unsigned pdc_video_ofs;
#ifdef __DJGPP__ /* Note: works only in plain DOS... */
# if DJGPP == 2
# define _FAR_POINTER(s,o) ((((int)(s)) << 4) + ((int)(o)))
# else
# define _FAR_POINTER(s,o) (0xe0000000 + (((int)(s)) << 4) + ((int)(o)))
# endif
# define _FP_SEGMENT(p) (unsigned short)((((long)p) >> 4) & 0xffff)
#else
# ifdef __TURBOC__
# define _FAR_POINTER(s,o) MK_FP(s,o)
# else
# if defined(__WATCOMC__) && defined(__FLAT__)
# define _FAR_POINTER(s,o) ((((int)(s)) << 4) + ((int)(o)))
# else
# define _FAR_POINTER(s,o) (((long)s << 16) | (long)o)
# endif
# endif
# define _FP_SEGMENT(p) (unsigned short)(((long)p) >> 4)
#endif
#define _FP_OFFSET(p) ((unsigned short)p & 0x000f)
#ifdef __DJGPP__
# include <sys/movedata.h>
unsigned char getdosmembyte(int offs);
unsigned short getdosmemword(int offs);
unsigned long getdosmemdword(int offs);
void setdosmembyte(int offs, unsigned char b);
void setdosmemword(int offs, unsigned short w);
#else
# if SMALL || MEDIUM || MSC
# define PDC_FAR far
# else
# define PDC_FAR
# endif
# define getdosmembyte(offs) \
(*((unsigned char PDC_FAR *) _FAR_POINTER(0,offs)))
# define getdosmemword(offs) \
(*((unsigned short PDC_FAR *) _FAR_POINTER(0,offs)))
# define getdosmemdword(offs) \
(*((unsigned long PDC_FAR *) _FAR_POINTER(0,offs)))
# define setdosmembyte(offs,x) \
(*((unsigned char PDC_FAR *) _FAR_POINTER(0,offs)) = (x))
# define setdosmemword(offs,x) \
(*((unsigned short PDC_FAR *) _FAR_POINTER(0,offs)) = (x))
#endif
#if defined(__WATCOMC__) && defined(__386__)
typedef union
{
struct
{
unsigned long edi, esi, ebp, res, ebx, edx, ecx, eax;
} d;
struct
{
unsigned short di, di_hi, si, si_hi, bp, bp_hi, res, res_hi,
bx, bx_hi, dx, dx_hi, cx, cx_hi, ax, ax_hi,
flags, es, ds, fs, gs, ip, cs, sp, ss;
} w;
struct
{
unsigned char edi[4], esi[4], ebp[4], res[4],
bl, bh, ebx_b2, ebx_b3, dl, dh, edx_b2, edx_b3,
cl, ch, ecx_b2, ecx_b3, al, ah, eax_b2, eax_b3;
} h;
} pdc_dpmi_regs;
void PDC_dpmi_int(int, pdc_dpmi_regs *);
#endif
#ifdef __DJGPP__
# include <dpmi.h>
# define PDCREGS __dpmi_regs
# define PDCINT(vector, regs) __dpmi_int(vector, &regs)
#else
# ifdef __WATCOMC__
# ifdef __386__
# define PDCREGS pdc_dpmi_regs
# define PDCINT(vector, regs) PDC_dpmi_int(vector, &regs)
# else
# define PDCREGS union REGPACK
# define PDCINT(vector, regs) intr(vector, &regs)
# endif
# else
# define PDCREGS union REGS
# define PDCINT(vector, regs) int86(vector, &regs, &regs)
# endif
#endif
/* Wide registers in REGS: w or x? */
#ifdef __WATCOMC__
# define W w
#else
# define W x
#endif
/* Monitor (terminal) type information */
enum
{
_NONE, _MDA, _CGA,
_EGACOLOR = 0x04, _EGAMONO,
_VGACOLOR = 0x07, _VGAMONO,
_MCGACOLOR = 0x0a, _MCGAMONO,
_MDS_GENIUS = 0x30
};
/* Text-mode font size information */
enum
{
_FONT8 = 8,
_FONT14 = 14,
_FONT15, /* GENIUS */
_FONT16
};
#ifdef __PACIFIC__
void movedata(unsigned, unsigned, unsigned, unsigned, unsigned);
#endif

View File

@@ -0,0 +1,100 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcgetsc.c,v 1.42 2008/07/13 16:08:17 wmcbrine Exp $")
#include <stdlib.h>
/* return width of screen/viewport */
int PDC_get_columns(void)
{
PDCREGS regs;
int cols;
const char *env_cols;
PDC_LOG(("PDC_get_columns() - called\n"));
/* use the value from COLS environment variable, if set. MH 10-Jun-92 */
/* and use the minimum of COLS and return from int10h MH 18-Jun-92 */
regs.h.ah = 0x0f;
PDCINT(0x10, regs);
cols = (int)regs.h.ah;
env_cols = getenv("COLS");
if (env_cols)
cols = min(atoi(env_cols), cols);
PDC_LOG(("PDC_get_columns() - returned: cols %d\n", cols));
return cols;
}
/* get the cursor size/shape */
int PDC_get_cursor_mode(void)
{
PDC_LOG(("PDC_get_cursor_mode() - called\n"));
return getdosmemword(0x460);
}
/* return number of screen rows */
int PDC_get_rows(void)
{
const char *env_rows;
int rows;
PDC_LOG(("PDC_get_rows() - called\n"));
/* use the value from LINES environment variable, if set. MH 10-Jun-92 */
/* and use the minimum of LINES and *ROWS. MH 18-Jun-92 */
rows = getdosmembyte(0x484) + 1;
env_rows = getenv("LINES");
if (env_rows)
rows = min(atoi(env_rows), rows);
if (rows == 1 && pdc_adapter == _MDS_GENIUS)
rows = 66;
if (rows == 1 && pdc_adapter == _MDA)
rows = 25;
if (rows == 1)
{
rows = 25;
pdc_direct_video = FALSE;
}
switch (pdc_adapter)
{
case _EGACOLOR:
case _EGAMONO:
switch (rows)
{
case 25:
case 43:
break;
default:
rows = 25;
}
break;
case _VGACOLOR:
case _VGAMONO:
break;
default:
rows = 25;
break;
}
PDC_LOG(("PDC_get_rows() - returned: rows %d\n", rows));
return rows;
}

View File

@@ -0,0 +1,511 @@
/* Public Domain Curses */
/* MS C doesn't return flags from int86() */
#ifdef MSC
# define USE_KBHIT
#endif
#ifdef USE_KBHIT
# include <conio.h>
#endif
#include "pdcdos.h"
RCSID("$Id: pdckbd.c,v 1.87 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: pdckbd
Synopsis:
unsigned long PDC_get_input_fd(void);
Description:
PDC_get_input_fd() returns the file descriptor that PDCurses
reads its input from. It can be used for select().
Portability X/Open BSD SYS V
PDC_get_input_fd - - -
**man-end****************************************************************/
#ifdef __DJGPP__
# include <fcntl.h>
# include <io.h>
# include <signal.h>
#endif
/************************************************************************
* Table for key code translation of function keys in keypad mode *
* These values are for strict IBM keyboard compatibles only *
************************************************************************/
static short key_table[] =
{
-1, ALT_ESC, -1, 0,
-1, -1, -1, -1,
-1, -1, -1, -1,
-1, -1, ALT_BKSP, KEY_BTAB,
ALT_Q, ALT_W, ALT_E, ALT_R,
ALT_T, ALT_Y, ALT_U, ALT_I,
ALT_O, ALT_P, ALT_LBRACKET, ALT_RBRACKET,
ALT_ENTER, -1, ALT_A, ALT_S,
ALT_D, ALT_F, ALT_G, ALT_H,
ALT_J, ALT_K, ALT_L, ALT_SEMICOLON,
ALT_FQUOTE, ALT_BQUOTE, -1, ALT_BSLASH,
ALT_Z, ALT_X, ALT_C, ALT_V,
ALT_B, ALT_N, ALT_M, ALT_COMMA,
ALT_STOP, ALT_FSLASH, -1, ALT_PADSTAR,
-1, -1, -1, KEY_F(1),
KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9),
KEY_F(10), -1, -1, KEY_HOME,
KEY_UP, KEY_PPAGE, ALT_PADMINUS, KEY_LEFT,
KEY_B2, KEY_RIGHT, ALT_PADPLUS, KEY_END,
KEY_DOWN, KEY_NPAGE, KEY_IC, KEY_DC,
KEY_F(13), KEY_F(14), KEY_F(15), KEY_F(16),
KEY_F(17), KEY_F(18), KEY_F(19), KEY_F(20),
KEY_F(21), KEY_F(22), KEY_F(25), KEY_F(26),
KEY_F(27), KEY_F(28), KEY_F(29), KEY_F(30),
KEY_F(31), KEY_F(32), KEY_F(33), KEY_F(34),
KEY_F(37), KEY_F(38), KEY_F(39), KEY_F(40),
KEY_F(41), KEY_F(42), KEY_F(43), KEY_F(44),
KEY_F(45), KEY_F(46), -1, CTL_LEFT,
CTL_RIGHT, CTL_END, CTL_PGDN, CTL_HOME,
ALT_1, ALT_2, ALT_3, ALT_4,
ALT_5, ALT_6, ALT_7, ALT_8,
ALT_9, ALT_0, ALT_MINUS, ALT_EQUAL,
CTL_PGUP, KEY_F(11), KEY_F(12), KEY_F(23),
KEY_F(24), KEY_F(35), KEY_F(36), KEY_F(47),
KEY_F(48), CTL_UP, CTL_PADMINUS, CTL_PADCENTER,
CTL_PADPLUS, CTL_DOWN, CTL_INS, CTL_DEL,
CTL_TAB, CTL_PADSLASH, CTL_PADSTAR, ALT_HOME,
ALT_UP, ALT_PGUP, -1, ALT_LEFT,
-1, ALT_RIGHT, -1, ALT_END,
ALT_DOWN, ALT_PGDN, ALT_INS, ALT_DEL,
ALT_PADSLASH, ALT_TAB, ALT_PADENTER, -1
};
unsigned long pdc_key_modifiers = 0L;
static struct {unsigned short pressed, released;} button[3];
static bool mouse_avail = FALSE, mouse_vis = FALSE, mouse_moved = FALSE,
mouse_button = FALSE, key_pressed = FALSE;
static unsigned char mouse_scroll = 0;
static PDCREGS ms_regs, old_ms;
static unsigned short shift_status, old_shift = 0;
static unsigned char keyboard_function = 0xff, shift_function = 0xff,
check_function = 0xff;
static const unsigned short button_map[3] = {0, 2, 1};
unsigned long PDC_get_input_fd(void)
{
PDC_LOG(("PDC_get_input_fd() - called\n"));
return (unsigned long)fileno(stdin);
}
void PDC_set_keyboard_binary(bool on)
{
PDC_LOG(("PDC_set_keyboard_binary() - called\n"));
#ifdef __DJGPP__
setmode(fileno(stdin), on ? O_BINARY : O_TEXT);
signal(SIGINT, on ? SIG_IGN : SIG_DFL);
#endif
}
/* check if a key or mouse event is waiting */
bool PDC_check_key(void)
{
PDCREGS regs;
if (shift_function == 0xff)
{
int scan;
/* get shift status for all keyboards */
regs.h.ah = 0x02;
PDCINT(0x16, regs);
scan = regs.h.al;
/* get shift status for enhanced keyboards */
regs.h.ah = 0x12;
PDCINT(0x16, regs);
if (scan == regs.h.al && getdosmembyte(0x496) == 0x10)
{
keyboard_function = 0x10;
check_function = 0x11;
shift_function = 0x12;
}
else
{
keyboard_function = 0;
check_function = 1;
shift_function = 2;
}
}
regs.h.ah = shift_function;
PDCINT(0x16, regs);
shift_status = regs.W.ax;
if (mouse_vis)
{
unsigned short i;
ms_regs.W.ax = 3;
PDCINT(0x33, ms_regs);
mouse_button = FALSE;
for (i = 0; i < 3; i++)
{
regs.W.ax = 6;
regs.W.bx = button_map[i];
PDCINT(0x33, regs);
button[i].released = regs.W.bx;
if (regs.W.bx)
{
ms_regs.W.cx = regs.W.cx;
ms_regs.W.dx = regs.W.dx;
mouse_button = TRUE;
}
regs.W.ax = 5;
regs.W.bx = button_map[i];
PDCINT(0x33, regs);
button[i].pressed = regs.W.bx;
if (regs.W.bx)
{
ms_regs.W.cx = regs.W.cx;
ms_regs.W.dx = regs.W.dx;
mouse_button = TRUE;
}
}
mouse_scroll = ms_regs.h.bh;
mouse_moved = !mouse_button && ms_regs.h.bl &&
ms_regs.h.bl == old_ms.h.bl &&
(((ms_regs.W.cx ^ old_ms.W.cx) >> 3) ||
((ms_regs.W.dx ^ old_ms.W.dx) >> 3));
if (mouse_scroll || mouse_button || mouse_moved)
return TRUE;
}
if (old_shift && !shift_status) /* modifier released */
{
if (!key_pressed && SP->return_key_modifiers)
return TRUE;
}
else if (!old_shift && shift_status) /* modifier pressed */
key_pressed = FALSE;
old_shift = shift_status;
#ifndef USE_KBHIT
regs.h.ah = check_function;
PDCINT(0x16, regs);
return !(regs.W.flags & 64);
#else
return kbhit();
#endif
}
static int _process_mouse_events(void)
{
int i;
short shift_flags = 0;
memset(&pdc_mouse_status, 0, sizeof(pdc_mouse_status));
key_pressed = TRUE;
old_shift = shift_status;
SP->key_code = TRUE;
/* Set shift modifiers */
if (shift_status & 3)
shift_flags |= BUTTON_SHIFT;
if (shift_status & 4)
shift_flags |= BUTTON_CONTROL;
if (shift_status & 8)
shift_flags |= BUTTON_ALT;
/* Scroll wheel support for CuteMouse */
if (mouse_scroll)
{
pdc_mouse_status.changes = mouse_scroll & 0x80 ?
PDC_MOUSE_WHEEL_UP : PDC_MOUSE_WHEEL_DOWN;
pdc_mouse_status.x = -1;
pdc_mouse_status.y = -1;
return KEY_MOUSE;
}
if (mouse_moved)
{
pdc_mouse_status.changes = PDC_MOUSE_MOVED;
for (i = 0; i < 3; i++)
{
if (ms_regs.h.bl & (1 << button_map[i]))
{
pdc_mouse_status.button[i] = BUTTON_MOVED | shift_flags;
pdc_mouse_status.changes |= (1 << i);
}
}
}
else /* button event */
{
for (i = 0; i < 3; i++)
{
if (button[i].pressed)
{
/* Check for a click -- a PRESS followed
immediately by a release */
if (!button[i].released)
{
if (SP->mouse_wait)
{
PDCREGS regs;
napms(SP->mouse_wait);
regs.W.ax = 6;
regs.W.bx = button_map[i];
PDCINT(0x33, regs);
pdc_mouse_status.button[i] = regs.W.bx ?
BUTTON_CLICKED : BUTTON_PRESSED;
}
else
pdc_mouse_status.button[i] = BUTTON_PRESSED;
}
else
pdc_mouse_status.button[i] = BUTTON_CLICKED;
}
if (button[i].pressed || button[i].released)
{
pdc_mouse_status.button[i] |= shift_flags;
pdc_mouse_status.changes |= (1 << i);
}
}
}
pdc_mouse_status.x = ms_regs.W.cx >> 3;
pdc_mouse_status.y = ms_regs.W.dx >> 3;
old_ms = ms_regs;
return KEY_MOUSE;
}
/* return the next available key or mouse event */
int PDC_get_key(void)
{
PDCREGS regs;
int key, scan;
pdc_key_modifiers = 0;
if (mouse_vis && (mouse_scroll || mouse_button || mouse_moved))
return _process_mouse_events();
/* Return modifiers as keys? */
if (old_shift && !shift_status)
{
key = -1;
if (old_shift & 1)
key = KEY_SHIFT_R;
if (old_shift & 2)
key = KEY_SHIFT_L;
if (shift_function == 0x12)
{
if (old_shift & 0x400)
key = KEY_CONTROL_R;
if (old_shift & 0x100)
key = KEY_CONTROL_L;
if (old_shift & 0x800)
key = KEY_ALT_R;
if (old_shift & 0x200)
key = KEY_ALT_L;
}
else
{
if (old_shift & 4)
key = KEY_CONTROL_R;
if (old_shift & 8)
key = KEY_ALT_R;
}
key_pressed = FALSE;
old_shift = shift_status;
SP->key_code = TRUE;
return key;
}
regs.h.ah = keyboard_function;
PDCINT(0x16, regs);
key = regs.h.al;
scan = regs.h.ah;
if (SP->save_key_modifiers)
{
if (shift_status & 3)
pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT;
if (shift_status & 4)
pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL;
if (shift_status & 8)
pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT;
if (shift_status & 0x20)
pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK;
}
if (scan == 0x1c && key == 0x0a) /* ^Enter */
key = CTL_ENTER;
else if (scan == 0xe0 && key == 0x0d) /* PadEnter */
key = PADENTER;
else if (scan == 0xe0 && key == 0x0a) /* ^PadEnter */
key = CTL_PADENTER;
else if (scan == 0x37 && key == 0x2a) /* Star */
key = PADSTAR;
else if (scan == 0x4a && key == 0x2d) /* Minus */
key = PADMINUS;
else if (scan == 0x4e && key == 0x2b) /* Plus */
key = PADPLUS;
else if (scan == 0xe0 && key == 0x2f) /* Slash */
key = PADSLASH;
else if (key == 0x00 || (key == 0xe0 && scan > 53 && scan != 86))
key = (scan > 0xa7) ? -1 : key_table[scan];
if (shift_status & 3)
{
switch (key)
{
case KEY_HOME: /* Shift Home */
key = KEY_SHOME;
break;
case KEY_UP: /* Shift Up */
key = KEY_SUP;
break;
case KEY_PPAGE: /* Shift PgUp */
key = KEY_SPREVIOUS;
break;
case KEY_LEFT: /* Shift Left */
key = KEY_SLEFT;
break;
case KEY_RIGHT: /* Shift Right */
key = KEY_SRIGHT;
break;
case KEY_END: /* Shift End */
key = KEY_SEND;
break;
case KEY_DOWN: /* Shift Down */
key = KEY_SDOWN;
break;
case KEY_NPAGE: /* Shift PgDn */
key = KEY_SNEXT;
break;
case KEY_IC: /* Shift Ins */
key = KEY_SIC;
break;
case KEY_DC: /* Shift Del */
key = KEY_SDC;
}
}
key_pressed = TRUE;
SP->key_code = ((unsigned)key >= 256);
return key;
}
/* discard any pending keyboard or mouse input -- this is the core
routine for flushinp() */
void PDC_flushinp(void)
{
PDC_LOG(("PDC_flushinp() - called\n"));
/* Force the BIOS keyboard buffer head and tail pointers to be
the same... Real nasty trick... */
setdosmemword(0x41a, getdosmemword(0x41c));
}
int PDC_mouse_set(void)
{
PDCREGS regs;
unsigned long mbe = SP->_trap_mbe;
if (mbe && !mouse_avail)
{
regs.W.ax = 0;
PDCINT(0x33, regs);
mouse_avail = !!(regs.W.ax);
}
if (mbe)
{
if (mouse_avail && !mouse_vis)
{
memset(&old_ms, 0, sizeof(old_ms));
regs.W.ax = 1;
PDCINT(0x33, regs);
mouse_vis = TRUE;
}
}
else
{
if (mouse_avail && mouse_vis)
{
regs.W.ax = 2;
PDCINT(0x33, regs);
mouse_vis = FALSE;
}
}
return (mouse_avail || !mbe) ? OK : ERR;
}
int PDC_modifiers_set(void)
{
key_pressed = FALSE;
return OK;
}

View File

@@ -0,0 +1,757 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcscrn.c,v 1.89 2008/07/13 16:08:17 wmcbrine Exp $")
#include <stdlib.h>
#ifdef CHTYPE_LONG
# define PDC_OFFSET 32
#else
# define PDC_OFFSET 8
#endif
/* COLOR_PAIR to attribute encoding table. */
unsigned char *pdc_atrtab = (unsigned char *)NULL;
int pdc_adapter; /* screen type */
int pdc_scrnmode; /* default screen mode */
int pdc_font; /* default font size */
bool pdc_direct_video; /* allow direct screen memory writes */
bool pdc_bogus_adapter; /* TRUE if adapter has insane values */
unsigned pdc_video_seg; /* video base segment */
unsigned pdc_video_ofs; /* video base offset */
static short curstoreal[16], realtocurs[16] =
{
COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED,
COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8,
COLOR_BLUE + 8, COLOR_GREEN + 8, COLOR_CYAN + 8, COLOR_RED + 8,
COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8
};
static bool sizeable = FALSE; /* TRUE if adapter is resizeable */
static unsigned short *saved_screen = NULL;
static int saved_lines = 0;
static int saved_cols = 0;
static int saved_scrnmode[3];
static int saved_font[3];
/* Thanks to Jeff Duntemann, K16RA for providing the impetus
(through the Dr. Dobbs Journal, March 1989 issue) for getting
the routines below merged into Bjorn Larsson's PDCurses 1.3...
-- frotz@dri.com 900730 */
/* _get_font() - Get the current font size */
static int _get_font(void)
{
int retval;
retval = getdosmemword(0x485);
/* Assume the MDS Genius is in 66 line mode. */
if ((retval == 0) && (pdc_adapter == _MDS_GENIUS))
retval = _FONT15;
switch (pdc_adapter)
{
case _MDA:
retval = 10; /* POINTS is not certain on MDA/Hercules */
break;
case _EGACOLOR:
case _EGAMONO:
switch (retval)
{
case _FONT8:
case _FONT14:
break;
default:
retval = _FONT14;
}
break;
case _CGA:
retval = _FONT8;
}
return retval;
}
/* _set_font() - Sets the current font size, if the adapter allows such a
change. It is an error to attempt to change the font size on a
"bogus" adapter. The reason for this is that we have a known video
adapter identity problem. e.g. Two adapters report the same identifying
characteristics. */
static void _set_font(int size)
{
PDCREGS regs;
if (pdc_bogus_adapter)
return;
switch (pdc_adapter)
{
case _CGA:
case _MDA:
case _MCGACOLOR:
case _MCGAMONO:
case _MDS_GENIUS:
break;
case _EGACOLOR:
case _EGAMONO:
if (sizeable && (pdc_font != size))
{
switch (size)
{
case _FONT8:
regs.W.ax = 0x1112;
regs.h.bl = 0x00;
PDCINT(0x10, regs);
break;
case _FONT14:
regs.W.ax = 0x1111;
regs.h.bl = 0x00;
PDCINT(0x10, regs);
}
}
break;
case _VGACOLOR:
case _VGAMONO:
if (sizeable && (pdc_font != size))
{
switch (size)
{
case _FONT8:
regs.W.ax = 0x1112;
regs.h.bl = 0x00;
PDCINT(0x10, regs);
break;
case _FONT14:
regs.W.ax = 0x1111;
regs.h.bl = 0x00;
PDCINT(0x10, regs);
break;
case _FONT16:
regs.W.ax = 0x1114;
regs.h.bl = 0x00;
PDCINT(0x10, regs);
}
}
}
curs_set(SP->visibility);
pdc_font = _get_font();
}
/* _set_80x25() - force a known screen state: 80x25 text mode. Forces the
appropriate 80x25 alpha mode given the display adapter. */
static void _set_80x25(void)
{
PDCREGS regs;
switch (pdc_adapter)
{
case _CGA:
case _EGACOLOR:
case _EGAMONO:
case _VGACOLOR:
case _VGAMONO:
case _MCGACOLOR:
case _MCGAMONO:
regs.h.ah = 0x00;
regs.h.al = 0x03;
PDCINT(0x10, regs);
break;
case _MDA:
regs.h.ah = 0x00;
regs.h.al = 0x07;
PDCINT(0x10, regs);
}
}
/* _get_scrn_mode() - Return the current BIOS video mode */
static int _get_scrn_mode(void)
{
PDCREGS regs;
regs.h.ah = 0x0f;
PDCINT(0x10, regs);
return (int)regs.h.al;
}
/* _set_scrn_mode() - Sets the BIOS Video Mode Number only if it is
different from the current video mode. */
static void _set_scrn_mode(int new_mode)
{
PDCREGS regs;
if (_get_scrn_mode() != new_mode)
{
regs.h.ah = 0;
regs.h.al = (unsigned char) new_mode;
PDCINT(0x10, regs);
}
pdc_font = _get_font();
pdc_scrnmode = new_mode;
LINES = PDC_get_rows();
COLS = PDC_get_columns();
}
/* _sanity_check() - A video adapter identification sanity check. This
routine will force sane values for various control flags. */
static int _sanity_check(int adapter)
{
int fontsize = _get_font();
int rows = PDC_get_rows();
PDC_LOG(("_sanity_check() - called: Adapter %d\n", adapter));
switch (adapter)
{
case _EGACOLOR:
case _EGAMONO:
switch (rows)
{
case 25:
case 43:
break;
default:
pdc_bogus_adapter = TRUE;
}
switch (fontsize)
{
case _FONT8:
case _FONT14:
break;
default:
pdc_bogus_adapter = TRUE;
}
break;
case _VGACOLOR:
case _VGAMONO:
break;
case _CGA:
case _MDA:
case _MCGACOLOR:
case _MCGAMONO:
switch (rows)
{
case 25:
break;
default:
pdc_bogus_adapter = TRUE;
}
break;
default:
pdc_bogus_adapter = TRUE;
}
if (pdc_bogus_adapter)
{
sizeable = FALSE;
pdc_direct_video = FALSE;
}
return adapter;
}
/* _query_adapter_type() - Determine PC video adapter type. */
static int _query_adapter_type(void)
{
PDCREGS regs;
int retval = _NONE;
/* thanks to paganini@ax.apc.org for the GO32 fix */
#if !defined(__DJGPP__) && !defined(__WATCOMC__)
struct SREGS segs;
#endif
short video_base = getdosmemword(0x463);
PDC_LOG(("_query_adapter_type() - called\n"));
/* attempt to call VGA Identify Adapter Function */
regs.W.ax = 0x1a00;
PDCINT(0x10, regs);
if ((regs.h.al == 0x1a) && (retval == _NONE))
{
/* We know that the PS/2 video BIOS is alive and well. */
switch (regs.h.al)
{
case 0:
retval = _NONE;
break;
case 1:
retval = _MDA;
break;
case 2:
retval = _CGA;
break;
case 4:
retval = _EGACOLOR;
sizeable = TRUE;
break;
case 5:
retval = _EGAMONO;
break;
case 26: /* ...alt. VGA BIOS... */
case 7:
retval = _VGACOLOR;
sizeable = TRUE;
break;
case 8:
retval = _VGAMONO;
break;
case 10:
case 13:
retval = _MCGACOLOR;
break;
case 12:
retval = _MCGAMONO;
break;
default:
retval = _CGA;
}
}
else
{
/* No VGA BIOS, check for an EGA BIOS by selecting an
Alternate Function Service...
bx == 0x0010 --> return EGA information */
regs.h.ah = 0x12;
regs.W.bx = 0x10;
PDCINT(0x10, regs);
if ((regs.h.bl != 0x10) && (retval == _NONE))
{
/* An EGA BIOS exists */
regs.h.ah = 0x12;
regs.h.bl = 0x10;
PDCINT(0x10, regs);
if (regs.h.bh == 0)
retval = _EGACOLOR;
else
retval = _EGAMONO;
}
else if (retval == _NONE)
{
/* Now we know we only have CGA or MDA */
PDCINT(0x11, regs);
switch (regs.h.al & 0x30)
{
case 0x10:
case 0x20:
retval = _CGA;
break;
case 0x30:
retval = _MDA;
break;
default:
retval = _NONE;
}
}
}
if (video_base == 0x3d4)
{
pdc_video_seg = 0xb800;
switch (retval)
{
case _EGAMONO:
retval = _EGACOLOR;
break;
case _VGAMONO:
retval = _VGACOLOR;
}
}
if (video_base == 0x3b4)
{
pdc_video_seg = 0xb000;
switch (retval)
{
case _EGACOLOR:
retval = _EGAMONO;
break;
case _VGACOLOR:
retval = _VGAMONO;
}
}
if ((retval == _NONE)
#ifndef CGA_DIRECT
|| (retval == _CGA)
#endif
)
pdc_direct_video = FALSE;
if ((unsigned)pdc_video_seg == 0xb000)
SP->mono = TRUE;
else
SP->mono = FALSE;
/* Check for DESQview shadow buffer
thanks to paganini@ax.apc.org for the GO32 fix */
#ifndef __WATCOMC__
regs.h.ah = 0xfe;
regs.h.al = 0;
regs.x.di = pdc_video_ofs;
# ifdef __DJGPP__
regs.x.es = pdc_video_seg;
__dpmi_int(0x10, &regs);
pdc_video_seg = regs.x.es;
# else
segs.es = pdc_video_seg;
int86x(0x10, &regs, &regs, &segs);
pdc_video_seg = segs.es;
# endif
pdc_video_ofs = regs.x.di;
#endif
if (!pdc_adapter)
pdc_adapter = retval;
return _sanity_check(retval);
}
/* close the physical screen -- may restore the screen to its state
before PDC_scr_open(); miscellaneous cleanup */
void PDC_scr_close(void)
{
#if SMALL || MEDIUM
# ifndef __PACIFIC__
struct SREGS segregs;
# endif
int ds;
#endif
PDC_LOG(("PDC_scr_close() - called\n"));
if (getenv("PDC_RESTORE_SCREEN") && saved_screen)
{
#ifdef __DJGPP__
dosmemput(saved_screen, saved_lines * saved_cols * 2,
(unsigned long)_FAR_POINTER(pdc_video_seg,
pdc_video_ofs));
#else
# if (SMALL || MEDIUM)
# ifdef __PACIFIC__
ds = FP_SEG((void far *)saved_screen);
# else
segread(&segregs);
ds = segregs.ds;
# endif
movedata(ds, (int)saved_screen, pdc_video_seg, pdc_video_ofs,
(saved_lines * saved_cols * 2));
# else
memcpy((void *)_FAR_POINTER(pdc_video_seg, pdc_video_ofs),
(void *)saved_screen, (saved_lines * saved_cols * 2));
# endif
#endif
free(saved_screen);
saved_screen = NULL;
}
reset_shell_mode();
if (SP->visibility != 1)
curs_set(1);
/* Position cursor to the bottom left of the screen. */
PDC_gotoyx(PDC_get_rows() - 2, 0);
}
void PDC_scr_free(void)
{
if (SP)
free(SP);
if (pdc_atrtab)
free(pdc_atrtab);
pdc_atrtab = (unsigned char *)NULL;
}
/* open the physical screen -- allocate SP, miscellaneous intialization,
and may save the existing screen for later restoration */
int PDC_scr_open(int argc, char **argv)
{
#if SMALL || MEDIUM
# ifndef __PACIFIC__
struct SREGS segregs;
# endif
int ds;
#endif
int i;
PDC_LOG(("PDC_scr_open() - called\n"));
SP = calloc(1, sizeof(SCREEN));
pdc_atrtab = calloc(PDC_COLOR_PAIRS * PDC_OFFSET, 1);
if (!SP || !pdc_atrtab)
return ERR;
for (i = 0; i < 16; i++)
curstoreal[realtocurs[i]] = i;
SP->orig_attr = FALSE;
pdc_direct_video = TRUE; /* Assume that we can */
pdc_video_seg = 0xb000; /* Base screen segment addr */
pdc_video_ofs = 0x0; /* Base screen segment ofs */
pdc_adapter = _query_adapter_type();
pdc_scrnmode = _get_scrn_mode();
pdc_font = _get_font();
SP->lines = PDC_get_rows();
SP->cols = PDC_get_columns();
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = TRUE;
/* If the environment variable PDCURSES_BIOS is set, the DOS int10()
BIOS calls are used in place of direct video memory access. */
if (getenv("PDCURSES_BIOS"))
pdc_direct_video = FALSE;
/* This code for preserving the current screen. */
if (getenv("PDC_RESTORE_SCREEN"))
{
saved_lines = SP->lines;
saved_cols = SP->cols;
saved_screen = malloc(saved_lines * saved_cols * 2);
if (!saved_screen)
{
SP->_preserve = FALSE;
return OK;
}
#ifdef __DJGPP__
dosmemget((unsigned long)_FAR_POINTER(pdc_video_seg, pdc_video_ofs),
saved_lines * saved_cols * 2, saved_screen);
#else
# if SMALL || MEDIUM
# ifdef __PACIFIC__
ds = FP_SEG((void far *) saved_screen);
# else
segread(&segregs);
ds = segregs.ds;
# endif
movedata(pdc_video_seg, pdc_video_ofs, ds, (int)saved_screen,
(saved_lines * saved_cols * 2));
# else
memcpy((void *)saved_screen,
(void *)_FAR_POINTER(pdc_video_seg, pdc_video_ofs),
(saved_lines * saved_cols * 2));
# endif
#endif
}
SP->_preserve = (getenv("PDC_PRESERVE_SCREEN") != NULL);
return OK;
}
/* the core of resize_term() */
int PDC_resize_screen(int nlines, int ncols)
{
PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
nlines, ncols));
/* Trash the stored value of orig_cursor -- it's only good if the
video mode doesn't change */
SP->orig_cursor = 0x0607;
switch (pdc_adapter)
{
case _EGACOLOR:
if (nlines >= 43)
_set_font(_FONT8);
else
_set_80x25();
break;
case _VGACOLOR:
if (nlines > 28)
_set_font(_FONT8);
else
if (nlines > 25)
_set_font(_FONT14);
else
_set_80x25();
}
PDC_set_blink(COLORS == 8);
return OK;
}
void PDC_reset_prog_mode(void)
{
PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
}
void PDC_reset_shell_mode(void)
{
PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
}
void PDC_restore_screen_mode(int i)
{
if (i >= 0 && i <= 2)
{
pdc_font = _get_font();
_set_font(saved_font[i]);
if (_get_scrn_mode() != saved_scrnmode[i])
_set_scrn_mode(saved_scrnmode[i]);
}
}
void PDC_save_screen_mode(int i)
{
if (i >= 0 && i <= 2)
{
saved_font[i] = pdc_font;
saved_scrnmode[i] = pdc_scrnmode;
}
}
void PDC_init_pair(short pair, short fg, short bg)
{
unsigned char att, temp_bg;
chtype i;
fg = curstoreal[fg];
bg = curstoreal[bg];
for (i = 0; i < PDC_OFFSET; i++)
{
att = fg | (bg << 4);
if (i & (A_REVERSE >> PDC_ATTR_SHIFT))
att = bg | (fg << 4);
if (i & (A_UNDERLINE >> PDC_ATTR_SHIFT))
att = 1;
if (i & (A_INVIS >> PDC_ATTR_SHIFT))
{
temp_bg = att >> 4;
att = temp_bg << 4 | temp_bg;
}
if (i & (A_BOLD >> PDC_ATTR_SHIFT))
att |= 8;
if (i & (A_BLINK >> PDC_ATTR_SHIFT))
att |= 128;
pdc_atrtab[pair * PDC_OFFSET + i] = att;
}
}
int PDC_pair_content(short pair, short *fg, short *bg)
{
*fg = realtocurs[pdc_atrtab[pair * PDC_OFFSET] & 0x0F];
*bg = realtocurs[(pdc_atrtab[pair * PDC_OFFSET] & 0xF0) >> 4];
return OK;
}
/* _egapal() - Find the EGA palette value (0-63) for the color (0-15).
On VGA, this is an index into the DAC. */
static short _egapal(short color)
{
PDCREGS regs;
regs.W.ax = 0x1007;
regs.h.bl = curstoreal[color];
PDCINT(0x10, regs);
return regs.h.bh;
}
bool PDC_can_change_color(void)
{
return (pdc_adapter == _VGACOLOR);
}
/* These are only valid when pdc_adapter == _VGACOLOR */
int PDC_color_content(short color, short *red, short *green, short *blue)
{
PDCREGS regs;
/* Read single DAC register */
regs.W.ax = 0x1015;
regs.h.bl = _egapal(color);
PDCINT(0x10, regs);
/* Scale and store */
*red = DIVROUND((unsigned)(regs.h.dh) * 1000, 63);
*green = DIVROUND((unsigned)(regs.h.ch) * 1000, 63);
*blue = DIVROUND((unsigned)(regs.h.cl) * 1000, 63);
return OK;
}
int PDC_init_color(short color, short red, short green, short blue)
{
PDCREGS regs;
/* Scale */
regs.h.dh = DIVROUND((unsigned)red * 63, 1000);
regs.h.ch = DIVROUND((unsigned)green * 63, 1000);
regs.h.cl = DIVROUND((unsigned)blue * 63, 1000);
/* Set single DAC register */
regs.W.ax = 0x1010;
regs.W.bx = _egapal(color);
PDCINT(0x10, regs);
return OK;
}

View File

@@ -0,0 +1,99 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcsetsc.c,v 1.39 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: pdcsetsc
Synopsis:
int PDC_set_blink(bool blinkon);
void PDC_set_title(const char *title);
Description:
PDC_set_blink() toggles whether the A_BLINK attribute sets an
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
platforms. (Currently it only works in Win32 and X11.)
Portability X/Open BSD SYS V
PDC_set_blink - - -
PDC_set_title - - -
**man-end****************************************************************/
int PDC_curs_set(int visibility)
{
PDCREGS regs;
int ret_vis, start, end;
PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility));
ret_vis = SP->visibility;
SP->visibility = visibility;
switch (visibility)
{
case 0: /* invisible */
start = 32;
end = 0; /* was 32 */
break;
case 2: /* highly visible */
start = 0; /* full-height block */
end = 7;
break;
default: /* normal visibility */
start = (SP->orig_cursor >> 8) & 0xff;
end = SP->orig_cursor & 0xff;
}
/* if scrnmode is not set, some BIOSes hang */
regs.h.ah = 0x01;
regs.h.al = (unsigned char)pdc_scrnmode;
regs.h.ch = (unsigned char)start;
regs.h.cl = (unsigned char)end;
PDCINT(0x10, regs);
return ret_vis;
}
void PDC_set_title(const char *title)
{
PDC_LOG(("PDC_set_title() - called: <%s>\n", title));
}
int PDC_set_blink(bool blinkon)
{
PDCREGS regs;
switch (pdc_adapter)
{
case _EGACOLOR:
case _EGAMONO:
case _VGACOLOR:
case _VGAMONO:
regs.W.ax = 0x1003;
regs.W.bx = blinkon;
PDCINT(0x10, regs);
if (pdc_color_started)
COLORS = blinkon ? 8 : 16;
break;
default:
COLORS = 8;
}
return (COLORS - (blinkon * 8) != 8) ? OK : ERR;
}

View File

@@ -0,0 +1,105 @@
/* Public Domain Curses */
#include "pdcdos.h"
RCSID("$Id: pdcutil.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $")
void PDC_beep(void)
{
PDCREGS regs;
PDC_LOG(("PDC_beep() - called\n"));
regs.W.ax = 0x0e07; /* Write ^G in TTY fashion */
regs.W.bx = 0;
PDCINT(0x10, regs);
}
void PDC_napms(int ms)
{
PDCREGS regs;
long goal, start, current;
PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
goal = DIVROUND((long)ms, 50);
if (!goal)
goal++;
start = getdosmemdword(0x46c);
goal += start;
while (goal > (current = getdosmemdword(0x46c)))
{
if (current < start) /* in case of midnight reset */
return;
regs.W.ax = 0x1680;
PDCINT(0x2f, regs);
PDCINT(0x28, regs);
}
}
const char *PDC_sysname(void)
{
return "DOS";
}
#ifdef __DJGPP__
unsigned char getdosmembyte(int offset)
{
unsigned char b;
dosmemget(offset, sizeof(unsigned char), &b);
return b;
}
unsigned short getdosmemword(int offset)
{
unsigned short w;
dosmemget(offset, sizeof(unsigned short), &w);
return w;
}
unsigned long getdosmemdword(int offset)
{
unsigned long dw;
dosmemget(offset, sizeof(unsigned long), &dw);
return dw;
}
void setdosmembyte(int offset, unsigned char b)
{
dosmemput(&b, sizeof(unsigned char), offset);
}
void setdosmemword(int offset, unsigned short w)
{
dosmemput(&w, sizeof(unsigned short), offset);
}
#endif
#if defined(__WATCOMC__) && defined(__386__)
void PDC_dpmi_int(int vector, pdc_dpmi_regs *rmregs)
{
union REGPACK regs = {0};
rmregs->w.ss = 0;
rmregs->w.sp = 0;
rmregs->w.flags = 0;
regs.w.ax = 0x300;
regs.h.bl = vector;
regs.x.edi = FP_OFF(rmregs);
regs.x.es = FP_SEG(rmregs);
intr(0x31, &regs);
}
#endif

View File

@@ -0,0 +1,48 @@
# Watcom WMAKE Makefile for PDCurses library - DOS (16 bit) Watcom C/C++ 10.6+
#
# Usage: wmake -f [path\]wccdos16.mak [DEBUG=Y] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
# Change the memory MODEL here, if desired
MODEL = l
!ifdef %PDCURSES_SRCDIR
PDCURSES_SRCDIR = $(%PDCURSES_SRCDIR)
!else
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
osdir = $(PDCURSES_SRCDIR)\dos
CC = wcc
TARGET = dos
CFLAGS = /bt=$(TARGET) /zq /wx /m$(MODEL) /i=$(PDCURSES_SRCDIR)
!ifeq DEBUG Y
CFLAGS += /d2 /DPDCDEBUG
LDFLAGS = D W A op q sys $(TARGET)
!else
CFLAGS += /oneatx
LDFLAGS = op q sys $(TARGET)
!endif
LIBEXE = wlib /q /n /t
!include $(PDCURSES_SRCDIR)\watcom.mif
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
%write wccdos.lrf $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $@ @wccdos.lrf
-del wccdos.lrf
-copy $(LIBCURSES) panel.lib
PLATFORM1 = Watcom C++ 16-bit DOS
PLATFORM2 = Open Watcom 1.6 for 16-bit DOS
ARCNAME = pdc$(VER)16w
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,45 @@
# Watcom WMAKE Makefile for PDCurses library - DOS/4GW Watcom C/C++ 10.6+
#
# Usage: wmake -f [path\]wccdos4g.mak [DEBUG=Y] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
!ifdef %PDCURSES_SRCDIR
PDCURSES_SRCDIR = $(%PDCURSES_SRCDIR)
!else
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
osdir = $(PDCURSES_SRCDIR)\dos
CC = wcc386
TARGET = dos4g
CFLAGS = /bt=$(TARGET) /zq /wx /mf /i=$(PDCURSES_SRCDIR)
!ifeq DEBUG Y
CFLAGS += /d2 /DPDCDEBUG
LDFLAGS = D W A op q sys $(TARGET)
!else
CFLAGS += /oneatx
LDFLAGS = op q sys $(TARGET)
!endif
LIBEXE = wlib /q /n /t
!include $(PDCURSES_SRCDIR)\watcom.mif
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
%write wccdos.lrf $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $@ @wccdos.lrf
-del wccdos.lrf
-copy $(LIBCURSES) panel.lib
PLATFORM1 = Watcom C++ 32-bit DOS
PLATFORM2 = Open Watcom 1.6 for 32-bit DOS
ARCNAME = pdc$(VER)32w
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,374 @@
LINES
COLS
stdscr
curscr
SP
Mouse_status
COLORS
COLOR_PAIRS
TABSIZE
acs_map
ttytype
addch
addchnstr
addchstr
addnstr
addstr
attroff
attron
attrset
attr_get
attr_off
attr_on
attr_set
baudrate
beep
bkgd
bkgdset
border
box
can_change_color
cbreak
chgat
clearok
clear
clrtobot
clrtoeol
color_content
color_set
copywin
curs_set
def_prog_mode
def_shell_mode
delay_output
delch
deleteln
delscreen
delwin
derwin
doupdate
dupwin
echochar
echo
endwin
erasechar
erase
filter
flash
flushinp
getbkgd
getnstr
getstr
getwin
halfdelay
has_colors
has_ic
has_il
hline
idcok
idlok
immedok
inchnstr
inchstr
inch
init_color
init_pair
initscr
innstr
insch
insdelln
insertln
insnstr
insstr
instr
intrflush
isendwin
is_linetouched
is_wintouched
keyname
keypad
killchar
leaveok
longname
meta
move
mvaddch
mvaddchnstr
mvaddchstr
mvaddnstr
mvaddstr
mvchgat
mvcur
mvdelch
mvderwin
mvgetch
mvgetnstr
mvgetstr
mvhline
mvinch
mvinchnstr
mvinchstr
mvinnstr
mvinsch
mvinsnstr
mvinsstr
mvinstr
mvprintw
mvscanw
mvvline
mvwaddchnstr
mvwaddchstr
mvwaddch
mvwaddnstr
mvwaddstr
mvwchgat
mvwdelch
mvwgetch
mvwgetnstr
mvwgetstr
mvwhline
mvwinchnstr
mvwinchstr
mvwinch
mvwinnstr
mvwinsch
mvwinsnstr
mvwinsstr
mvwinstr
mvwin
mvwprintw
mvwscanw
mvwvline
napms
newpad
newterm
newwin
nl
nocbreak
nodelay
noecho
nonl
noqiflush
noraw
notimeout
overlay
overwrite
pair_content
pechochar
pnoutrefresh
prefresh
printw
putwin
qiflush
raw
redrawwin
refresh
reset_prog_mode
reset_shell_mode
resetty
ripoffline
savetty
scanw
scr_dump
scr_init
scrl
scrollok
scroll
scr_restore
scr_set
setscrreg
setsyx
set_term
slk_attroff
slk_attr_off
slk_attron
slk_attr_on
slk_attrset
slk_attr_set
slk_clear
slk_color
slk_init
slk_label
slk_noutrefresh
slk_refresh
slk_restore
slk_set
slk_touch
standend
standout
start_color
subpad
subwin
syncok
termattrs
term_attrs
termname
timeout
touchline
touchwin
typeahead
untouchwin
use_env
vidattr
vid_attr
vidputs
vid_puts
vline
vw_printw
vwprintw
vw_scanw
vwscanw
waddchnstr
waddchstr
waddch
waddnstr
waddstr
wattroff
wattron
wattrset
wattr_get
wattr_off
wattr_on
wattr_set
wbkgdset
wbkgd
wborder
wchgat
wclear
wclrtobot
wclrtoeol
wcolor_set
wcursyncup
wdelch
wdeleteln
wechochar
werase
wgetch
wgetnstr
wgetstr
whline
winchnstr
winchstr
winch
winnstr
winsch
winsdelln
winsertln
winsnstr
winsstr
winstr
wmove
wnoutrefresh
wprintw
wredrawln
wrefresh
wscanw
wscrl
wsetscrreg
wstandend
wstandout
wsyncdown
wsyncup
wtimeout
wtouchln
wvline
getattrs
getbegx
getbegy
getmaxx
getmaxy
getparx
getpary
getcurx
getcury
traceoff
traceon
unctrl
crmode
nocrmode
draino
resetterm
fixterm
saveterm
mouse_set
mouse_on
mouse_off
request_mouse_pos
map_button
wmouse_position
getmouse
getbmap
assume_default_colors
curses_version
has_key
use_default_colors
wresize
mouseinterval
mousemask
mouse_trafo
nc_getmouse
ungetmouse
wenclose
wmouse_trafo
addrawch
insrawch
is_termresized
mvaddrawch
mvdeleteln
mvinsertln
mvinsrawch
mvwaddrawch
mvwdeleteln
mvwinsertln
mvwinsrawch
raw_output
resize_term
resize_window
waddrawch
winsrawch
wordchar
bottom_panel
del_panel
hide_panel
move_panel
new_panel
panel_above
panel_below
panel_hidden
panel_userptr
panel_window
replace_panel
set_panel_userptr
show_panel
top_panel
update_panels
PDC_debug
PDC_ungetch
PDC_set_blink
PDC_set_line_color
PDC_set_title
PDC_clearclipboard
PDC_freeclipboard
PDC_getclipboard
PDC_setclipboard
PDC_get_input_fd
PDC_get_key_modifiers
PDC_save_key_modifiers
PDC_return_key_modifiers
cur_term
del_curterm
putp
restartterm
set_curterm
setterm
setupterm
tgetent
tgetflag
tgetnum
tgetstr
tgoto
tigetflag
tigetnum
tigetstr
tparm
tputs

View File

@@ -0,0 +1,90 @@
addnwstr
addwstr
add_wch
add_wchnstr
add_wchstr
border_set
box_set
echo_wchar
erasewchar
getbkgrnd
getcchar
getn_wstr
get_wch
get_wstr
hline_set
innwstr
ins_nwstr
ins_wch
ins_wstr
inwstr
in_wch
in_wchnstr
in_wchstr
key_name
killwchar
mvaddnwstr
mvaddwstr
mvadd_wch
mvadd_wchnstr
mvadd_wchstr
mvgetn_wstr
mvget_wch
mvget_wstr
mvhline_set
mvinnwstr
mvins_nwstr
mvins_wch
mvins_wstr
mvinwstr
mvin_wch
mvin_wchnstr
mvin_wchstr
mvvline_set
mvwaddnwstr
mvwaddwstr
mvwadd_wch
mvwadd_wchnstr
mvwadd_wchstr
mvwgetn_wstr
mvwget_wch
mvwget_wstr
mvwhline_set
mvwinnwstr
mvwins_nwstr
mvwins_wch
mvwins_wstr
mvwin_wch
mvwin_wchnstr
mvwin_wchstr
mvwinwstr
mvwvline_set
pecho_wchar
setcchar
slk_wset
unget_wch
vline_set
waddnwstr
waddwstr
wadd_wch
wadd_wchnstr
wadd_wchstr
wbkgrnd
wbkgrndset
wborder_set
wecho_wchar
wgetbkgrnd
wgetn_wstr
wget_wch
wget_wstr
whline_set
winnwstr
wins_nwstr
wins_wch
wins_wstr
winwstr
win_wch
win_wchnstr
win_wchstr
wunctrl
wvline_set

View File

@@ -0,0 +1,253 @@
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
#
# Modified 1 Feb 2000 MHES to cater for mkdir -p
#
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
mkdircmd="$mkdirprog -p"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdircmd "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

View File

@@ -0,0 +1,26 @@
# Common elements for most of the DOS, OS/2 and Win32
# makefiles (not Watcom or LCC)
PDCURSES_CURSES_H = $(PDCURSES_SRCDIR)/curses.h
PDCURSES_CURSPRIV_H = $(PDCURSES_SRCDIR)/curspriv.h
PDCURSES_HEADERS = $(PDCURSES_CURSES_H) $(PDCURSES_CURSPRIV_H)
PANEL_HEADER = $(PDCURSES_SRCDIR)/panel.h
TERM_HEADER = $(PDCURSES_SRCDIR)/term.h
srcdir = $(PDCURSES_SRCDIR)/pdcurses
demodir = $(PDCURSES_SRCDIR)/demos
LIBOBJS = addch.$(O) addchstr.$(O) addstr.$(O) attr.$(O) beep.$(O) \
bkgd.$(O) border.$(O) clear.$(O) color.$(O) delch.$(O) deleteln.$(O) \
deprec.$(O) getch.$(O) getstr.$(O) getyx.$(O) inch.$(O) inchstr.$(O) \
initscr.$(O) inopts.$(O) insch.$(O) insstr.$(O) instr.$(O) kernel.$(O) \
keyname.$(O) mouse.$(O) move.$(O) outopts.$(O) overlay.$(O) pad.$(O) \
panel.$(O) printw.$(O) refresh.$(O) scanw.$(O) scr_dump.$(O) scroll.$(O) \
slk.$(O) termattr.$(O) terminfo.$(O) touch.$(O) util.$(O) window.$(O) \
debug.$(O)
PDCOBJS = pdcclip.$(O) pdcdisp.$(O) pdcgetsc.$(O) pdckbd.$(O) pdcscrn.$(O) \
pdcsetsc.$(O) pdcutil.$(O)
DEMOS = testcurs.exe newdemo.exe xmas.exe tuidemo.exe firework.exe \
ptest.exe rain.exe worm.exe

View File

@@ -0,0 +1,20 @@
# Makefile include: build a binary archive with Info-ZIP
# under DOS, OS/2 or Win32
dist: $(PDCLIBS)
echo PDCurses $(VERDOT) for $(PLATFORM1) > file_id.diz
echo ------------------------------------------ >> file_id.diz
echo Public Domain Curses library for >> file_id.diz
echo $(PLATFORM2). >> file_id.diz
echo Source available in PDCURS$(VER).ZIP >> file_id.diz
echo Public Domain. >> file_id.diz
echo $(PDCURSES_SRCDIR)\README > flist
echo $(PDCURSES_SRCDIR)\HISTORY >> flist
echo $(PDCURSES_SRCDIR)\curses.h >> flist
echo $(PDCURSES_SRCDIR)\panel.h >> flist
echo $(PDCURSES_SRCDIR)\term.h >> flist
echo $(LIBCURSES) >> flist
echo file_id.diz >> flist
zip -9jX $(ARCNAME) -@ <flist
del flist
del file_id.diz

View File

@@ -0,0 +1,43 @@
PDCurses for OS/2
=================
This directory contains PDCurses source code files specific to OS/2.
Building
--------
. Choose the appropriate makefile for your compiler:
bccos2.mak - Borland C++ 2.0
gccos2.mak - EMX 0.9b+
iccos2.mak - C Set/2
wccos2.mak - Watcom 10.6+ (32-bit)
. Optionally, you can build in a different directory than the platform
directory by setting PDCURSES_SRCDIR to point to the directory where
you unpacked PDCurses, and changing to your target directory:
set PDCURSES_SRCDIR=c:\pdcurses
. Build it:
make -f makefilename
(For Watcom, use "wmake" instead of "make"; for MSVC or C Set/2,
"nmake".) You'll get the libraries (pdcurses.lib or .a, depending on
your compiler; and panel.lib or .a), the demos (*.exe), and a lot of
object files. Note that the panel library is just a copy of the main
library, provided for convenience; both panel and curses functions are
in the main library.
You can also use the optional parameter "DLL=Y" with EMX, to build the
library as a DLL:
make -f gccos2.mak DLL=Y
Distribution Status
-------------------
The files in this directory are released to the Public Domain.

View File

@@ -0,0 +1,90 @@
# Borland MAKE Makefile for PDCurses library - OS/2 BC++ 1.0+
#
# Usage: make -f [path\]bccos2.mak [DEBUG=] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
O = obj
!ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
!include $(PDCURSES_SRCDIR)\libobjs.mif
osdir = $(PDCURSES_SRCDIR)\os2
CC = bcc
!ifdef DEBUG
CFLAGS = -N -v -y -DPDCDEBUG
!else
CFLAGS = -O
!endif
CPPFLAGS = -I$(PDCURSES_SRCDIR)
BUILD = $(CC) -c $(CFLAGS) $(CPPFLAGS)
LINK = tlink
LIBEXE = tlib /C /E
LIBCURSES = pdcurses.lib
all: $(LIBCURSES) $(DEMOS)
clean:
-del *.obj
-del *.lib
-del *.exe
demos: $(DEMOS)
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
-del $@
$(LIBEXE) $@ \
+addch.obj +addchstr.obj +addstr.obj +attr.obj +beep.obj +bkgd.obj \
+border.obj +clear.obj +color.obj +delch.obj +deleteln.obj +deprec.obj \
+getch.obj +getstr.obj +getyx.obj +inch.obj +inchstr.obj +initscr.obj \
+inopts.obj +insch.obj +insstr.obj +instr.obj +kernel.obj +keyname.obj \
+mouse.obj +move.obj +outopts.obj +overlay.obj +pad.obj +panel.obj \
+printw.obj +refresh.obj +scanw.obj +scr_dump.obj +scroll.obj +slk.obj \
+termattr.obj +terminfo.obj +touch.obj +util.obj +window.obj +debug.obj \
+pdcclip.obj +pdcdisp.obj +pdcgetsc.obj +pdckbd.obj +pdcscrn.obj \
+pdcsetsc.obj +pdcutil.obj ,lib.map
-copy $(LIBCURSES) panel.lib
.autodepend
{$(srcdir)\}.c.obj:
$(BUILD) $<
{$(osdir)\}.c.obj:
$(BUILD) $<
{$(demodir)\}.c.obj:
$(BUILD) $<
.c.obj:
$(BUILD) $<
.obj.exe:
$(CC) -e$@ $** $(LIBCURSES)
tuidemo.exe: tuidemo.obj tui.obj $(LIBCURSES)
$(CC) -e$@ $**
tui.obj: $(demodir)\tui.c $(demodir)\tui.h $(PDCURSES_CURSES_H)
$(BUILD) -I$(demodir) $(demodir)\tui.c
tuidemo.obj: $(demodir)\tuidemo.c $(PDCURSES_CURSES_H)
$(BUILD) -I$(demodir) $(demodir)\tuidemo.c
PLATFORM1 = Borland C++ OS/2 1.0
PLATFORM2 = Borland C/C++ OS/2 1.0
ARCNAME = pdc$(VER)bcos2
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,148 @@
# GNU MAKE Makefile for PDCurses library - OS/2 emx 0.9c+
#
# Usage: make -f [path\]gccos2.mak [DEBUG=Y] [EMXVIDEO=Y] [DLL=Y] [target]
#
# where target can be any of:
# [all|demos|pdcurses.a|testcurs.exe...]
#
# The EMXVIDEO option compiles with the emx video library, which
# enables a PDCurses program to run under OS/2 and DOS.
O = o
ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
endif
include $(PDCURSES_SRCDIR)/version.mif
include $(PDCURSES_SRCDIR)/libobjs.mif
osdir = $(PDCURSES_SRCDIR)/os2
PDCURSES_OS2_H = $(osdir)/pdcos2.h
CC = gcc
CFLAGS = -I$(PDCURSES_SRCDIR) -c -Wall
ifeq ($(EMXVIDEO),Y)
CFLAGS += -DEMXVIDEO
CCLIBS = -lvideo
BINDFLAGS = -acm
else
CCLIBS =
BINDFLAGS =
endif
ifeq ($(DEBUG),Y)
CFLAGS += -g -DPDCDEBUG
LDFLAGS = -g
else
CFLAGS += -O2
LDFLAGS =
endif
BASEDEF = $(PDCURSES_SRCDIR)\exp-base.def
DEFDEPS = $(BASEDEF)
DEFFILE = pdcurses.def
DLLTARGET = pdcurses.dll
DLLFLAGS = -Zdll -Zcrtdll -Zomf
LINK = gcc
EMXBIND = emxbind
EMXOMF = emxomf
LIBEXE = ar
LIBFLAGS = rcv
ifeq ($(DLL),Y)
CFLAGS += -Zdll -Zcrtdll -Zomf
LDFLAGS += -Zlinker /PM:VIO -Zomf -Zcrtdll
LIBCURSES = pdcurses.lib
LIBDEPS = $(LIBOBJS) $(PDCOBJS) $(DEFFILE)
PDCLIBS = $(DLLTARGET)
EXEPOST =
TUIPOST =
CLEAN = *.dll *.lib $(DEFFILE)
else
LIBCURSES = pdcurses.a
LIBDEPS = $(LIBOBJS) $(PDCOBJS)
PDCLIBS = $(LIBCURSES)
EXEPOST = $(EMXBIND) $* $(BINDFLAGS)
TUIPOST = $(EMXBIND) tuidemo $(BINDFLAGS)
CLEAN = *.a testcurs newdemo xmas tuidemo firework ptest rain worm
endif
.PHONY: all libs clean demos dist
all: libs demos
libs: $(PDCLIBS)
clean:
-del *.o
-del *.exe
-del $(CLEAN)
demos: $(DEMOS)
DEMOOBJS = testcurs.o newdemo.o xmas.o tui.o tuidemo.o firework.o \
ptest.o rain.o worm.o
$(DEFFILE) : $(DEFDEPS)
echo LIBRARY PDCURSES > $@
echo DESCRIPTION 'PDCurses 3.4 Dynamic Linking library' >> $@
echo PROTMODE >>$@
echo DATA MULTIPLE READWRITE LOADONCALL >> $@
echo CODE LOADONCALL >> $@
echo EXPORTS >> $@
type $(BASEDEF) >> $@
$(LIBCURSES) : $(LIBDEPS)
$(LIBEXE) $(LIBFLAGS) $@ $?
-copy $(LIBCURSES) panel.a
$(DLLTARGET) : $(LIBDEPS)
$(LINK) $(DLLFLAGS) -o $(DLLTARGET) $? $(DEFFILE)
# lxlite $(DLLTARGET)
emximp -o $(LIBCURSES) $(DEFFILE)
$(LIBOBJS) $(PDCOBJS) $(DEMOOBJS) : $(PDCURSES_HEADERS)
$(PDCOBJS) : $(PDCURSES_OS2_H)
$(DEMOS) : $(LIBCURSES)
panel.o ptest.o: $(PANEL_HEADER)
terminfo.o: $(TERM_HEADER)
$(LIBOBJS) : %.o: $(srcdir)/%.c
$(CC) -c $(CFLAGS) -o$@ $<
$(PDCOBJS) : %.o: $(osdir)/%.c
$(CC) -c $(CFLAGS) -o$@ $<
firework.exe newdemo.exe rain.exe testcurs.exe worm.exe xmas.exe \
ptest.exe: %.exe: %.o
$(LINK) $(LDFLAGS) -o $* $< $(LIBCURSES) $(CCLIBS)
$(EXEPOST)
tuidemo.exe: tuidemo.o tui.o
$(LINK) $(LDFLAGS) -o tuidemo tuidemo.o tui.o $(LIBCURSES) $(CCLIBS)
$(TUIPOST)
firework.o newdemo.o ptest.o rain.o testcurs.o worm.o xmas.o: %.o: \
$(demodir)/%.c
$(CC) $(CFLAGS) -o$@ $<
tui.o: $(demodir)\tui.c $(demodir)\tui.h
$(CC) $(CFLAGS) -I$(demodir) -o $@ $<
tuidemo.o: $(demodir)\tuidemo.c
$(CC) $(CFLAGS) -I$(demodir) -o $@ $<
PLATFORM1 = EMX OS/2
PLATFORM2 = EMX 0.9d for OS/2
ARCNAME = pdc$(VER)_emx_os2
include $(PDCURSES_SRCDIR)/makedist.mif

View File

@@ -0,0 +1,50 @@
-+addch.obj &
-+addchstr.obj &
-+addstr.obj &
-+attr.obj &
-+beep.obj &
-+bkgd.obj &
-+border.obj &
-+clear.obj &
-+color.obj &
-+delch.obj &
-+deleteln.obj &
-+deprec.obj &
-+getch.obj &
-+getstr.obj &
-+getyx.obj &
-+inch.obj &
-+inchstr.obj &
-+initscr.obj &
-+inopts.obj &
-+insch.obj &
-+insstr.obj &
-+instr.obj &
-+kernel.obj &
-+keyname.obj &
-+mouse.obj &
-+move.obj &
-+outopts.obj &
-+overlay.obj &
-+pad.obj &
-+panel.obj &
-+printw.obj &
-+refresh.obj &
-+scanw.obj &
-+scr_dump.obj &
-+scroll.obj &
-+slk.obj &
-+termattr.obj &
-+terminfo.obj &
-+touch.obj &
-+util.obj &
-+window.obj &
-+debug.obj &
-+pdcclip.obj &
-+pdcdisp.obj &
-+pdcgetsc.obj &
-+pdckbd.obj &
-+pdcscrn.obj &
-+pdcsetsc.obj &
-+pdcutil.obj &
,lib.map;

View File

@@ -0,0 +1,256 @@
# NMAKE Makefile for PDCurses library - OS/2 C Set/2
#
# Usage: nmake -f [path\]iccos2.mak [DEBUG=] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
O = obj
!ifndef PDCURSES_SRCDIR
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
!include $(PDCURSES_SRCDIR)\libobjs.mif
osdir = $(PDCURSES_SRCDIR)\os2
PDCURSES_OS2_H = $(osdir)\pdcos2.h
CC = icc
!ifdef DEBUG
CFLAGS = /Sm /Ti+ /O- /Q+ /dPDCDEBUG
LDFLAGS = /NOLOGO /NOE /SE:160 /DEBUG /PMTYPE:VIO
!else
CFLAGS = /Sm /Ti- /O+ /Q+
LDFLAGS = /NOLOGO /NOE /EXEPACK /PACKCODE /PACKDATA /PMTYPE:VIO
!endif
CPPFLAGS = -I$(PDCURSES_SRCDIR)
BUILD = $(CC) -c $(CFLAGS) $(CPPFLAGS)
LINK = link386
LIBEXE = lib
LIBCURSES = pdcurses.lib
all: $(LIBCURSES) $(DEMOS)
clean:
-del *.obj
-del *.lib
-del *.exe
demos: $(DEMOS)
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $@ @$(osdir)\iccos2.lrf
-copy $(LIBCURSES) panel.lib
addch.obj: $(srcdir)\addch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\addch.c
addchstr.obj: $(srcdir)\addchstr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\addchstr.c
addstr.obj: $(srcdir)\addstr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\addstr.c
attr.obj: $(srcdir)\attr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\attr.c
beep.obj: $(srcdir)\beep.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\beep.c
bkgd.obj: $(srcdir)\bkgd.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\bkgd.c
border.obj: $(srcdir)\border.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\border.c
clear.obj: $(srcdir)\clear.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\clear.c
color.obj: $(srcdir)\color.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\color.c
delch.obj: $(srcdir)\delch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\delch.c
deleteln.obj: $(srcdir)\deleteln.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\deleteln.c
deprec.obj: $(srcdir)\deprec.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\deprec.c
getch.obj: $(srcdir)\getch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\getch.c
getstr.obj: $(srcdir)\getstr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\getstr.c
getyx.obj: $(srcdir)\getyx.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\getyx.c
inch.obj: $(srcdir)\inch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\inch.c
inchstr.obj: $(srcdir)\inchstr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\inchstr.c
initscr.obj: $(srcdir)\initscr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\initscr.c
inopts.obj: $(srcdir)\inopts.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\inopts.c
insch.obj: $(srcdir)\insch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\insch.c
insstr.obj: $(srcdir)\insstr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\insstr.c
instr.obj: $(srcdir)\instr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\instr.c
kernel.obj: $(srcdir)\kernel.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\kernel.c
keyname.obj: $(srcdir)\keyname.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\keyname.c
mouse.obj: $(srcdir)\mouse.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\mouse.c
move.obj: $(srcdir)\move.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\move.c
outopts.obj: $(srcdir)\outopts.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\outopts.c
overlay.obj: $(srcdir)\overlay.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\overlay.c
pad.obj: $(srcdir)\pad.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\pad.c
panel.obj: $(srcdir)\panel.c $(PDCURSES_HEADERS) $(PANEL_HEADER)
$(BUILD) $(srcdir)\panel.c
printw.obj: $(srcdir)\printw.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\printw.c
refresh.obj: $(srcdir)\refresh.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\refresh.c
scanw.obj: $(srcdir)\scanw.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\scanw.c
scr_dump.obj: $(srcdir)\scr_dump.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\scr_dump.c
scroll.obj: $(srcdir)\scroll.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\scroll.c
slk.obj: $(srcdir)\slk.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\slk.c
termattr.obj: $(srcdir)\termattr.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\termattr.c
terminfo.obj: $(srcdir)\terminfo.c $(PDCURSES_HEADERS) $(TERM_HEADER)
$(BUILD) $(srcdir)\terminfo.c
touch.obj: $(srcdir)\touch.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\touch.c
util.obj: $(srcdir)\util.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\util.c
window.obj: $(srcdir)\window.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\window.c
debug.obj: $(srcdir)\debug.c $(PDCURSES_HEADERS)
$(BUILD) $(srcdir)\debug.c
pdcclip.obj: $(osdir)\pdcclip.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcclip.c
pdcdisp.obj: $(osdir)\pdcdisp.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcdisp.c
pdcgetsc.obj: $(osdir)\pdcgetsc.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcgetsc.c
pdckbd.obj: $(osdir)\pdckbd.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdckbd.c
pdcscrn.obj: $(osdir)\pdcscrn.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcscrn.c
pdcsetsc.obj: $(osdir)\pdcsetsc.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcsetsc.c
pdcutil.obj: $(osdir)\pdcutil.c $(PDCURSES_HEADERS) $(PDCURSES_OS2_H)
$(BUILD) $(osdir)\pdcutil.c
firework.exe: firework.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
newdemo.exe: newdemo.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
ptest.exe: ptest.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
rain.exe: rain.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
testcurs.exe: testcurs.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
tuidemo.exe: tuidemo.obj tui.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj+tui.obj,$*,,$(LIBCURSES);
worm.exe: worm.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
xmas.exe: xmas.obj $(LIBCURSES)
$(LINK) $(LDFLAGS) $*.obj,$*,,$(LIBCURSES);
firework.obj: $(demodir)\firework.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\firework.c
newdemo.obj: $(demodir)\newdemo.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\newdemo.c
ptest.obj: $(demodir)\ptest.c $(PANEL_HEADER) $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\ptest.c
rain.obj: $(demodir)\rain.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\rain.c
testcurs.obj: $(demodir)\testcurs.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\testcurs.c
tui.obj: $(demodir)\tui.c $(demodir)\tui.h $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\tui.c
tuidemo.obj: $(demodir)\tuidemo.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\tuidemo.c
worm.obj: $(demodir)\worm.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\worm.c
xmas.obj: $(demodir)\xmas.c $(PDCURSES_CURSES_H)
$(BUILD) $(demodir)\xmas.c
PLATFORM1 = C Set/2 OS/2
PLATFORM2 = C Set/2 for OS/2
ARCNAME = pdc$(VER)_icc_os2
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,185 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcclip.c,v 1.33 2008/07/14 04:24:51 wmcbrine Exp $")
/*man-start**************************************************************
Name: clipboard
Synopsis:
int PDC_getclipboard(char **contents, long *length);
int PDC_setclipboard(const char *contents, long length);
int PDC_freeclipboard(char *contents);
int PDC_clearclipboard(void);
Description:
PDC_getclipboard() gets the textual contents of the system's
clipboard. This function returns the contents of the clipboard
in the contents argument. It is the responsibilitiy of the
caller to free the memory returned, via PDC_freeclipboard().
The length of the clipboard contents is returned in the length
argument.
PDC_setclipboard copies the supplied text into the system's
clipboard, emptying the clipboard prior to the copy.
PDC_clearclipboard() clears the internal clipboard.
Return Values:
indicator of success/failure of call.
PDC_CLIP_SUCCESS the call was successful
PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
the clipboard contents
PDC_CLIP_EMPTY the clipboard contains no text
PDC_CLIP_ACCESS_ERROR no clipboard support
Portability X/Open BSD SYS V
PDC_getclipboard - - -
PDC_setclipboard - - -
PDC_freeclipboard - - -
PDC_clearclipboard - - -
**man-end****************************************************************/
int PDC_getclipboard(char **contents, long *length)
{
#ifndef EMXVIDEO
HMQ hmq;
HAB hab;
PTIB ptib;
PPIB ppib;
ULONG ulRet;
long len;
int rc;
#endif
PDC_LOG(("PDC_getclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
if (!WinOpenClipbrd(hab))
{
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return PDC_CLIP_ACCESS_ERROR;
}
rc = PDC_CLIP_EMPTY;
ulRet = WinQueryClipbrdData(hab, CF_TEXT);
if (ulRet)
{
len = strlen((char *)ulRet);
*contents = malloc(len + 1);
if (!*contents)
rc = PDC_CLIP_MEMORY_ERROR;
else
{
strcpy((char *)*contents, (char *)ulRet);
*length = len;
rc = PDC_CLIP_SUCCESS;
}
}
WinCloseClipbrd(hab);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return rc;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}
int PDC_setclipboard(const char *contents, long length)
{
#ifndef EMXVIDEO
HAB hab;
PTIB ptib;
PPIB ppib;
ULONG ulRC;
PSZ szTextOut = NULL;
int rc;
#endif
PDC_LOG(("PDC_setclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
if (!WinOpenClipbrd(hab))
{
WinTerminate(hab);
return PDC_CLIP_ACCESS_ERROR;
}
rc = PDC_CLIP_MEMORY_ERROR;
ulRC = DosAllocSharedMem((PVOID)&szTextOut, NULL, length + 1,
PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
if (ulRC == 0)
{
strcpy(szTextOut, contents);
WinEmptyClipbrd(hab);
if (WinSetClipbrdData(hab, (ULONG)szTextOut, CF_TEXT, CFI_POINTER))
rc = PDC_CLIP_SUCCESS;
else
{
DosFreeMem(szTextOut);
rc = PDC_CLIP_ACCESS_ERROR;
}
}
WinCloseClipbrd(hab);
WinTerminate(hab);
return rc;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}
int PDC_freeclipboard(char *contents)
{
PDC_LOG(("PDC_freeclipboard() - called\n"));
if (contents)
free(contents);
return PDC_CLIP_SUCCESS;
}
int PDC_clearclipboard(void)
{
#ifndef EMXVIDEO
HAB hab;
PTIB ptib;
PPIB ppib;
#endif
PDC_LOG(("PDC_clearclipboard() - called\n"));
#ifndef EMXVIDEO
DosGetInfoBlocks(&ptib, &ppib);
ppib->pib_ultype = 3;
hab = WinInitialize(0);
WinEmptyClipbrd(hab);
WinCloseClipbrd(hab);
WinTerminate(hab);
return PDC_CLIP_SUCCESS;
#else
return PDC_CLIP_ACCESS_ERROR;
#endif
}

View File

@@ -0,0 +1,95 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcdisp.c,v 1.49 2008/07/14 04:24:51 wmcbrine Exp $")
/* ACS definitions originally by jshumate@wrdis01.robins.af.mil -- these
match code page 437 and compatible pages (CP850, CP852, etc.) */
#ifdef CHTYPE_LONG
# define A(x) ((chtype)x | A_ALTCHARSET)
chtype acs_map[128] =
{
A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9),
A(10), A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18),
A(19), A(20), A(21), A(22), A(23), A(24), A(25), A(26), A(27),
A(28), A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&',
'\'', '(', ')', '*',
A(0x1a), A(0x1b), A(0x18), A(0x19),
'/',
0xdb,
'1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
A(0x04), 0xb1,
'b', 'c', 'd', 'e',
0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d,
0x2d, 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3,
0xf2, 0xe3, 0xd8, 0x9c, 0xf9,
A(127)
};
# undef A
#endif
/* position hardware cursor at (y, x) */
void PDC_gotoyx(int row, int col)
{
PDC_LOG(("PDC_gotoyx() - called: row %d col %d\n", row, col));
#ifdef EMXVIDEO
v_gotoxy(col, row);
#else
VioSetCurPos(row, col, 0);
#endif
}
/* update the given physical line to look like the corresponding line in
curscr */
void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
{
/* this should be enough for the maximum width of a screen. */
struct {unsigned char text, attr;} temp_line[256];
int j;
PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno));
/* replace the attribute part of the chtype with the
actual color value for each chtype in the line */
for (j = 0; j < len; j++)
{
chtype ch = srcp[j];
temp_line[j].attr = pdc_atrtab[ch >> PDC_ATTR_SHIFT];
#ifdef CHTYPE_LONG
if (ch & A_ALTCHARSET && !(ch & 0xff80))
ch = acs_map[ch & 0x7f];
#endif
temp_line[j].text = ch & 0xff;
}
#ifdef EMXVIDEO
v_putline((char *)temp_line, x, lineno, len);
#else
VioWrtCellStr((PCH)temp_line, (USHORT)(len * sizeof(unsigned short)),
(USHORT)lineno, (USHORT)x, 0);
#endif
}

View File

@@ -0,0 +1,91 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcgetsc.c,v 1.39 2008/07/14 04:24:51 wmcbrine Exp $")
/* return width of screen/viewport */
int PDC_get_columns(void)
{
#ifdef EMXVIDEO
int rows = 0;
#else
VIOMODEINFO modeInfo = {0};
#endif
int cols = 0;
const char *env_cols;
PDC_LOG(("PDC_get_columns() - called\n"));
#ifdef EMXVIDEO
v_dimen(&cols, &rows);
#else
modeInfo.cb = sizeof(modeInfo);
VioGetMode(&modeInfo, 0);
cols = modeInfo.col;
#endif
env_cols = getenv("COLS");
if (env_cols)
cols = min(atoi(env_cols), cols);
PDC_LOG(("PDC_get_columns() - returned: cols %d\n", cols));
return cols;
}
/* get the cursor size/shape */
int PDC_get_cursor_mode(void)
{
#ifdef EMXVIDEO
int curstart = 0, curend = 0;
#else
VIOCURSORINFO cursorInfo;
#endif
PDC_LOG(("PDC_get_cursor_mode() - called\n"));
#ifdef EMXVIDEO
v_getctype(&curstart, &curend);
return (curstart << 8) | curend;
#else
VioGetCurType (&cursorInfo, 0);
return (cursorInfo.yStart << 8) | cursorInfo.cEnd;
#endif
}
/* return number of screen rows */
int PDC_get_rows(void)
{
#ifdef EMXVIDEO
int cols = 0;
#else
VIOMODEINFO modeInfo = {0};
#endif
int rows = 0;
const char *env_rows;
PDC_LOG(("PDC_get_rows() - called\n"));
/* use the value from LINES environment variable, if set. MH 10-Jun-92 */
/* and use the minimum of LINES and *ROWS. MH 18-Jun-92 */
#ifdef EMXVIDEO
v_dimen(&cols, &rows);
#else
modeInfo.cb = sizeof(modeInfo);
VioGetMode(&modeInfo, 0);
rows = modeInfo.row;
#endif
env_rows = getenv("LINES");
if (env_rows)
rows = min(atoi(env_rows), rows);
PDC_LOG(("PDC_get_rows() - returned: rows %d\n", rows));
return rows;
}

View File

@@ -0,0 +1,519 @@
/* Public Domain Curses */
#if defined(__EMX__) || defined(__WATCOMC__) || defined(__IBMC__) || \
defined(__TURBOC__)
# define HAVE_SIGNAL
# include <signal.h>
#endif
#include "pdcos2.h"
RCSID("$Id: pdckbd.c,v 1.89 2008/07/14 04:24:51 wmcbrine Exp $")
/*man-start**************************************************************
Name: pdckbd
Synopsis:
unsigned long PDC_get_input_fd(void);
Description:
PDC_get_input_fd() returns the file descriptor that PDCurses
reads its input from. It can be used for select().
Portability X/Open BSD SYS V
PDC_get_input_fd - - -
**man-end****************************************************************/
#ifdef EMXVIDEO
# include <termios.h>
static int tahead = -1;
#else
static KBDINFO kbdinfo; /* default keyboard mode */
static HMOU mouse_handle = 0;
static MOUSE_STATUS old_mouse_status;
static USHORT old_shift = 0;
static bool key_pressed = FALSE;
static int mouse_events = 0;
#endif
/************************************************************************
* Table for key code translation of function keys in keypad mode *
* These values are for strict IBM keyboard compatibles only *
************************************************************************/
static short key_table[] =
{
-1, ALT_ESC, -1, 0,
-1, -1, -1, -1,
-1, -1, -1, -1,
-1, -1, ALT_BKSP, KEY_BTAB,
ALT_Q, ALT_W, ALT_E, ALT_R,
ALT_T, ALT_Y, ALT_U, ALT_I,
ALT_O, ALT_P, ALT_LBRACKET, ALT_RBRACKET,
ALT_ENTER, -1, ALT_A, ALT_S,
ALT_D, ALT_F, ALT_G, ALT_H,
ALT_J, ALT_K, ALT_L, ALT_SEMICOLON,
ALT_FQUOTE, ALT_BQUOTE, -1, ALT_BSLASH,
ALT_Z, ALT_X, ALT_C, ALT_V,
ALT_B, ALT_N, ALT_M, ALT_COMMA,
ALT_STOP, ALT_FSLASH, -1, ALT_PADSTAR,
-1, -1, -1, KEY_F(1),
KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9),
KEY_F(10), -1, -1, KEY_HOME,
KEY_UP, KEY_PPAGE, ALT_PADMINUS, KEY_LEFT,
KEY_B2, KEY_RIGHT, ALT_PADPLUS, KEY_END,
KEY_DOWN, KEY_NPAGE, KEY_IC, KEY_DC,
KEY_F(13), KEY_F(14), KEY_F(15), KEY_F(16),
KEY_F(17), KEY_F(18), KEY_F(19), KEY_F(20),
KEY_F(21), KEY_F(22), KEY_F(25), KEY_F(26),
KEY_F(27), KEY_F(28), KEY_F(29), KEY_F(30),
KEY_F(31), KEY_F(32), KEY_F(33), KEY_F(34),
KEY_F(37), KEY_F(38), KEY_F(39), KEY_F(40),
KEY_F(41), KEY_F(42), KEY_F(43), KEY_F(44),
KEY_F(45), KEY_F(46), -1, CTL_LEFT,
CTL_RIGHT, CTL_END, CTL_PGDN, CTL_HOME,
ALT_1, ALT_2, ALT_3, ALT_4,
ALT_5, ALT_6, ALT_7, ALT_8,
ALT_9, ALT_0, ALT_MINUS, ALT_EQUAL,
CTL_PGUP, KEY_F(11), KEY_F(12), KEY_F(23),
KEY_F(24), KEY_F(35), KEY_F(36), KEY_F(47),
KEY_F(48), CTL_UP, CTL_PADMINUS, CTL_PADCENTER,
CTL_PADPLUS, CTL_DOWN, CTL_INS, CTL_DEL,
CTL_TAB, CTL_PADSLASH, CTL_PADSTAR, ALT_HOME,
ALT_UP, ALT_PGUP, -1, ALT_LEFT,
-1, ALT_RIGHT, -1, ALT_END,
ALT_DOWN, ALT_PGDN, ALT_INS, ALT_DEL,
ALT_PADSLASH, ALT_TAB, ALT_PADENTER, -1
};
unsigned long pdc_key_modifiers = 0L;
unsigned long PDC_get_input_fd(void)
{
PDC_LOG(("PDC_get_input_fd() - called\n"));
return (unsigned long)fileno(stdin);
}
#ifndef EMXVIDEO
void PDC_get_keyboard_info(void)
{
kbdinfo.cb = sizeof(kbdinfo);
KbdGetStatus(&kbdinfo, 0);
}
void PDC_set_keyboard_default(void)
{
KbdSetStatus(&kbdinfo, 0);
}
#endif /* ifndef EMXVIDEO */
void PDC_set_keyboard_binary(bool on)
{
PDC_LOG(("PDC_set_keyboard_binary() - called\n"));
#ifndef EMXVIDEO
if (on)
{
kbdinfo.fsMask &= ~(KEYBOARD_ASCII_MODE);
kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
}
else
{
kbdinfo.fsMask &= ~(KEYBOARD_BINARY_MODE);
kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
}
KbdSetStatus(&kbdinfo, 0);
#endif
#ifdef HAVE_SIGNAL
signal(SIGBREAK, on ? SIG_IGN : SIG_DFL);
#endif
}
/* check if a key or mouse event is waiting */
bool PDC_check_key(void)
{
#if !defined(_MSC_VER) && !defined(EMXVIDEO)
KBDKEYINFO keyInfo = {0};
#endif
#ifdef EMXVIDEO
if (tahead == -1) /* Nothing typed yet */
{
tahead = _read_kbd(0, 0, 0);
/* Read additional */
if (tahead == 0)
tahead = _read_kbd(0, 1, 0) << 8;
}
return (tahead != -1);
#else
# ifndef _MSC_VER
KbdGetStatus(&kbdinfo, 0);
if (mouse_handle)
{
MOUQUEINFO queue;
MouGetNumQueEl(&queue, mouse_handle);
mouse_events = queue.cEvents;
if (mouse_events)
return TRUE;
}
if (old_shift && !kbdinfo.fsState) /* modifier released */
{
if (!key_pressed && SP->return_key_modifiers)
return TRUE;
}
else if (!old_shift && kbdinfo.fsState) /* modifier pressed */
key_pressed = FALSE;
old_shift = kbdinfo.fsState;
KbdPeek(&keyInfo, 0); /* peek at keyboard */
return (keyInfo.fbStatus != 0);
# else
return kbhit();
# endif
#endif
}
#ifndef EMXVIDEO
static int _process_mouse_events(void)
{
MOUEVENTINFO event;
static const USHORT button_mask[] = {6, 96, 24},
move_mask[] = {2, 32, 8},
press_mask[] = {4, 64, 16};
USHORT count = 1;
short shift_flags = 0;
int i;
MouReadEventQue(&event, &count, mouse_handle);
mouse_events--;
for (i = 0; i < 3; i++)
{
pdc_mouse_status.button[i] =
((event.fs & move_mask[i]) ? BUTTON_MOVED : 0) |
((event.fs & press_mask[i]) ? BUTTON_PRESSED : 0);
/* PRESS events are sometimes mistakenly reported as MOVE
events. A MOVE should always follow a PRESS, so treat a MOVE
immediately after a RELEASE as a PRESS. */
if ((pdc_mouse_status.button[i] == BUTTON_MOVED) &&
(old_mouse_status.button[i] == BUTTON_RELEASED))
{
pdc_mouse_status.button[i] = BUTTON_PRESSED;
}
if (pdc_mouse_status.button[i] == BUTTON_PRESSED && SP->mouse_wait)
{
/* Check for a click -- a PRESS followed immediately by a
release */
if (!mouse_events)
{
MOUQUEINFO queue;
napms(SP->mouse_wait);
MouGetNumQueEl(&queue, mouse_handle);
mouse_events = queue.cEvents;
}
if (mouse_events)
{
MouReadEventQue(&event, &count, mouse_handle);
if (!(event.fs & button_mask[i]))
pdc_mouse_status.button[i] = BUTTON_CLICKED;
}
}
}
pdc_mouse_status.x = event.col;
pdc_mouse_status.y = event.row;
pdc_mouse_status.changes = 0;
for (i = 0; i < 3; i++)
{
if (old_mouse_status.button[i] != pdc_mouse_status.button[i])
pdc_mouse_status.changes |= (1 << i);
if (pdc_mouse_status.button[i] == BUTTON_MOVED)
{
/* Discard non-moved "moves" */
if (pdc_mouse_status.x == old_mouse_status.x &&
pdc_mouse_status.y == old_mouse_status.y)
return -1;
/* Motion events always flag the button as changed */
pdc_mouse_status.changes |= (1 << i);
pdc_mouse_status.changes |= PDC_MOUSE_MOVED;
break;
}
}
old_mouse_status = pdc_mouse_status;
/* Treat click events as release events for comparison purposes */
for (i = 0; i < 3; i++)
{
if (old_mouse_status.button[i] == BUTTON_CLICKED)
old_mouse_status.button[i] = BUTTON_RELEASED;
}
/* Check for SHIFT/CONTROL/ALT */
if (kbdinfo.fsState & KBDSTF_ALT)
shift_flags |= BUTTON_ALT;
if (kbdinfo.fsState & KBDSTF_CONTROL)
shift_flags |= BUTTON_CONTROL;
if (kbdinfo.fsState & (KBDSTF_LEFTSHIFT|KBDSTF_RIGHTSHIFT))
shift_flags |= BUTTON_SHIFT;
if (shift_flags)
{
for (i = 0; i < 3; i++)
{
if (pdc_mouse_status.changes & (1 << i))
pdc_mouse_status.button[i] |= shift_flags;
}
}
old_shift = kbdinfo.fsState;
key_pressed = TRUE;
SP->key_code = TRUE;
return KEY_MOUSE;
}
#endif
/* return the next available key or mouse event */
int PDC_get_key(void)
{
int key, scan;
#ifndef EMXVIDEO
KBDKEYINFO keyInfo = {0};
#endif
#ifdef EMXVIDEO
if (tahead == -1)
{
tahead = _read_kbd(0, 1, 0);
/* Read additional */
if (tahead == 0)
tahead = _read_kbd(0, 1, 0) << 8;
}
key = tahead & 0xff;
scan = tahead >> 8;
pdc_key_modifiers = 0L;
tahead = -1;
#else
pdc_key_modifiers = 0L;
if (mouse_handle && mouse_events)
return _process_mouse_events();
if (old_shift && !kbdinfo.fsState)
{
key = -1;
if (old_shift & KBDSTF_LEFTALT)
{
key = KEY_ALT_L;
}
else if (old_shift & KBDSTF_RIGHTALT)
{
key = KEY_ALT_R;
}
else if (old_shift & KBDSTF_LEFTCONTROL)
{
key = KEY_CONTROL_L;
}
else if (old_shift & KBDSTF_RIGHTCONTROL)
{
key = KEY_CONTROL_R;
}
else if (old_shift & KBDSTF_LEFTSHIFT)
{
key = KEY_SHIFT_L;
}
else if (old_shift & KBDSTF_RIGHTSHIFT)
{
key = KEY_SHIFT_R;
}
key_pressed = FALSE;
old_shift = kbdinfo.fsState;
SP->key_code = TRUE;
return key;
}
KbdCharIn(&keyInfo, IO_WAIT, 0); /* get a character */
key = keyInfo.chChar;
scan = keyInfo.chScan;
if (SP->save_key_modifiers)
{
if (keyInfo.fsState & KBDSTF_ALT)
pdc_key_modifiers |= PDC_KEY_MODIFIER_ALT;
if (keyInfo.fsState & KBDSTF_CONTROL)
pdc_key_modifiers |= PDC_KEY_MODIFIER_CONTROL;
if (keyInfo.fsState & KBDSTF_NUMLOCK_ON)
pdc_key_modifiers |= PDC_KEY_MODIFIER_NUMLOCK;
if (keyInfo.fsState & (KBDSTF_LEFTSHIFT|KBDSTF_RIGHTSHIFT))
pdc_key_modifiers |= PDC_KEY_MODIFIER_SHIFT;
}
#endif
if (scan == 0x1c && key == 0x0a) /* ^Enter */
key = CTL_ENTER;
else if (scan == 0xe0 && key == 0x0d) /* PadEnter */
key = PADENTER;
else if (scan == 0xe0 && key == 0x0a) /* ^PadEnter */
key = CTL_PADENTER;
else if (scan == 0x37 && key == 0x2a) /* Star */
key = PADSTAR;
else if (scan == 0x4a && key == 0x2d) /* Minus */
key = PADMINUS;
else if (scan == 0x4e && key == 0x2b) /* Plus */
key = PADPLUS;
else if (scan == 0xe0 && key == 0x2f) /* Slash */
key = PADSLASH;
else if (key == 0x00 || (key == 0xe0 && scan > 53 && scan != 86))
key = (scan > 0xa7) ? -1 : key_table[scan];
if (keyInfo.fsState & (KBDSTF_LEFTSHIFT|KBDSTF_RIGHTSHIFT))
{
switch (key)
{
case KEY_HOME: /* Shift Home */
key = KEY_SHOME;
break;
case KEY_UP: /* Shift Up */
key = KEY_SUP;
break;
case KEY_PPAGE: /* Shift PgUp */
key = KEY_SPREVIOUS;
break;
case KEY_LEFT: /* Shift Left */
key = KEY_SLEFT;
break;
case KEY_RIGHT: /* Shift Right */
key = KEY_SRIGHT;
break;
case KEY_END: /* Shift End */
key = KEY_SEND;
break;
case KEY_DOWN: /* Shift Down */
key = KEY_SDOWN;
break;
case KEY_NPAGE: /* Shift PgDn */
key = KEY_SNEXT;
break;
case KEY_IC: /* Shift Ins */
key = KEY_SIC;
break;
case KEY_DC: /* Shift Del */
key = KEY_SDC;
}
}
key_pressed = TRUE;
SP->key_code = ((unsigned)key >= 256);
return key;
}
/* discard any pending keyboard or mouse input -- this is the core
routine for flushinp() */
void PDC_flushinp(void)
{
PDC_LOG(("PDC_flushinp() - called\n"));
#ifdef EMXVIDEO
tcflush(0, TCIFLUSH);
#else
if (mouse_handle)
MouFlushQue(mouse_handle);
KbdFlushBuffer(0);
#endif
}
int PDC_mouse_set(void)
{
#ifndef EMXVIDEO
unsigned long mbe = SP->_trap_mbe;
if (mbe && !mouse_handle)
{
memset(&old_mouse_status, 0, sizeof(MOUSE_STATUS));
MouOpen(NULL, &mouse_handle);
if (mouse_handle)
MouDrawPtr(mouse_handle);
}
else if (!mbe && mouse_handle)
{
MouClose(mouse_handle);
mouse_handle = 0;
}
if (mbe && mouse_handle)
{
USHORT mask = ((mbe & (BUTTON1_PRESSED | BUTTON1_CLICKED |
BUTTON1_MOVED)) ? 6 : 0) |
((mbe & (BUTTON3_PRESSED | BUTTON3_CLICKED |
BUTTON3_MOVED)) ? 24 : 0) |
((mbe & (BUTTON2_PRESSED | BUTTON2_CLICKED |
BUTTON2_MOVED)) ? 96 : 0);
MouSetEventMask(&mask, mouse_handle);
}
#endif
return OK;
}
int PDC_modifiers_set(void)
{
key_pressed = FALSE;
return OK;
}

View File

@@ -0,0 +1,51 @@
/* Public Domain Curses */
/* $Id: pdcos2.h,v 1.9 2008/08/14 06:38:35 wmcbrine Exp $ */
#ifdef _MSC_VER
# define USE_OS2_H 1 /* Use the os2.h for the compiler */
# define APIRET USHORT
#endif
#include <stdlib.h>
#include <string.h>
#ifdef EMXVIDEO
# include <sys/video.h>
#else
# define INCL_DOS
# define INCL_DOSMISC
# define INCL_WIN
# define INCL_VIO
# define INCL_KBD
# define INCL_MOU
# include <os2.h>
#endif
#include <curspriv.h>
#ifdef __WATCOMC__
# define PDCTHUNK(x) ((ptr_16)(x))
# ifdef __386__
# define SEG16 _Seg16
# else
# define SEG16
# endif
typedef void * SEG16 ptr_16;
#else
# ifdef __EMX__
# ifdef __INNOTEK_LIBC__
# define PDCTHUNK(x) ((PCH)_libc_32to16(x))
# else
# define PDCTHUNK(x) ((PCH)_emx_32to16(x))
# endif
# endif
#endif
extern unsigned char *pdc_atrtab;
extern int pdc_font;
extern void PDC_get_keyboard_info(void);
extern void PDC_set_keyboard_default(void);

View File

@@ -0,0 +1,422 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcscrn.c,v 1.76 2008/07/14 04:24:51 wmcbrine Exp $")
#ifdef CHTYPE_LONG
# define PDC_OFFSET 32
#else
# define PDC_OFFSET 8
#endif
/* COLOR_PAIR to attribute encoding table. */
unsigned char *pdc_atrtab = (unsigned char *)NULL;
int pdc_font; /* default font size */
static short curstoreal[16], realtocurs[16] =
{
COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, COLOR_RED,
COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE, COLOR_BLACK + 8,
COLOR_BLUE + 8, COLOR_GREEN + 8, COLOR_CYAN + 8, COLOR_RED + 8,
COLOR_MAGENTA + 8, COLOR_YELLOW + 8, COLOR_WHITE + 8
};
#ifdef EMXVIDEO
static unsigned char *saved_screen = NULL;
static int saved_lines = 0;
static int saved_cols = 0;
#else
# ifdef PDCTHUNK
# ifdef __EMX__
# define THUNKEDVIO VIOCOLORREG
# else
typedef struct {
USHORT cb;
USHORT type;
USHORT firstcolorreg;
USHORT numcolorregs;
ptr_16 colorregaddr;
} THUNKEDVIO;
# endif
# endif
static PCH saved_screen = NULL;
static USHORT saved_lines = 0;
static USHORT saved_cols = 0;
static VIOMODEINFO scrnmode; /* default screen mode */
static VIOMODEINFO saved_scrnmode[3];
static int saved_font[3];
static bool can_change = FALSE;
static int _get_font(void)
{
VIOMODEINFO modeInfo = {0};
modeInfo.cb = sizeof(modeInfo);
VioGetMode(&modeInfo, 0);
return (modeInfo.vres / modeInfo.row);
}
static void _set_font(int size)
{
VIOMODEINFO modeInfo = {0};
if (pdc_font != size)
{
modeInfo.cb = sizeof(modeInfo);
/* set most parameters of modeInfo */
VioGetMode(&modeInfo, 0);
modeInfo.cb = 8; /* ignore horiz an vert resolution */
modeInfo.row = modeInfo.vres / size;
VioSetMode(&modeInfo, 0);
}
curs_set(SP->visibility);
pdc_font = _get_font();
}
#endif
/* close the physical screen -- may restore the screen to its state
before PDC_scr_open(); miscellaneous cleanup */
void PDC_scr_close(void)
{
PDC_LOG(("PDC_scr_close() - called\n"));
if (saved_screen && getenv("PDC_RESTORE_SCREEN"))
{
#ifdef EMXVIDEO
v_putline(saved_screen, 0, 0, saved_lines * saved_cols);
#else
VioWrtCellStr(saved_screen, saved_lines * saved_cols * 2,
0, 0, (HVIO)NULL);
#endif
free(saved_screen);
saved_screen = NULL;
}
reset_shell_mode();
if (SP->visibility != 1)
curs_set(1);
/* Position cursor to the bottom left of the screen. */
PDC_gotoyx(PDC_get_rows() - 2, 0);
}
void PDC_scr_free(void)
{
if (SP)
free(SP);
if (pdc_atrtab)
free(pdc_atrtab);
pdc_atrtab = (unsigned char *)NULL;
}
/* open the physical screen -- allocate SP, miscellaneous intialization,
and may save the existing screen for later restoration */
int PDC_scr_open(int argc, char **argv)
{
#ifdef EMXVIDEO
int adapter;
#else
USHORT totchars;
#endif
int i;
short r, g, b;
PDC_LOG(("PDC_scr_open() - called\n"));
SP = calloc(1, sizeof(SCREEN));
pdc_atrtab = calloc(PDC_COLOR_PAIRS * PDC_OFFSET, 1);
if (!SP || !pdc_atrtab)
return ERR;
for (i = 0; i < 16; i++)
curstoreal[realtocurs[i]] = i;
#ifdef EMXVIDEO
v_init();
#endif
SP->orig_attr = FALSE;
#ifdef EMXVIDEO
adapter = v_hardware();
SP->mono = (adapter == V_MONOCHROME);
pdc_font = SP->mono ? 14 : (adapter == V_COLOR_8) ? 8 : 12;
#else
VioGetMode(&scrnmode, 0);
PDC_get_keyboard_info();
pdc_font = _get_font();
#endif
SP->lines = PDC_get_rows();
SP->cols = PDC_get_columns();
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = TRUE;
/* This code for preserving the current screen */
if (getenv("PDC_RESTORE_SCREEN"))
{
saved_lines = SP->lines;
saved_cols = SP->cols;
saved_screen = malloc(2 * saved_lines * saved_cols);
if (!saved_screen)
{
SP->_preserve = FALSE;
return OK;
}
#ifdef EMXVIDEO
v_getline(saved_screen, 0, 0, saved_lines * saved_cols);
#else
totchars = saved_lines * saved_cols * 2;
VioReadCellStr((PCH)saved_screen, &totchars, 0, 0, (HVIO)NULL);
#endif
}
SP->_preserve = (getenv("PDC_PRESERVE_SCREEN") != NULL);
can_change = (PDC_color_content(0, &r, &g, &b) == OK);
return OK;
}
/* the core of resize_term() */
int PDC_resize_screen(int nlines, int ncols)
{
#ifndef EMXVIDEO
VIOMODEINFO modeInfo = {0};
USHORT result;
#endif
PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
nlines, ncols));
#ifdef EMXVIDEO
return ERR;
#else
modeInfo.cb = sizeof(modeInfo);
/* set most parameters of modeInfo */
VioGetMode(&modeInfo, 0);
modeInfo.fbType = 1;
modeInfo.row = nlines;
modeInfo.col = ncols;
result = VioSetMode(&modeInfo, 0);
LINES = PDC_get_rows();
COLS = PDC_get_columns();
return (result == 0) ? OK : ERR;
#endif
}
void PDC_reset_prog_mode(void)
{
PDC_LOG(("PDC_reset_prog_mode() - called.\n"));
#ifndef EMXVIDEO
PDC_set_keyboard_binary(TRUE);
#endif
}
void PDC_reset_shell_mode(void)
{
PDC_LOG(("PDC_reset_shell_mode() - called.\n"));
#ifndef EMXVIDEO
PDC_set_keyboard_default();
#endif
}
#ifndef EMXVIDEO
static bool _screen_mode_equals(VIOMODEINFO *oldmode)
{
VIOMODEINFO current = {0};
VioGetMode(&current, 0);
return ((current.cb == oldmode->cb) &&
(current.fbType == oldmode->fbType) &&
(current.color == oldmode->color) &&
(current.col == oldmode->col) &&
(current.row == oldmode->row) &&
(current.hres == oldmode->vres) &&
(current.vres == oldmode->vres));
}
#endif
void PDC_restore_screen_mode(int i)
{
#ifndef EMXVIDEO
if (i >= 0 && i <= 2)
{
pdc_font = _get_font();
_set_font(saved_font[i]);
if (!_screen_mode_equals(&saved_scrnmode[i]))
if (VioSetMode(&saved_scrnmode[i], 0) != 0)
{
pdc_font = _get_font();
scrnmode = saved_scrnmode[i];
LINES = PDC_get_rows();
COLS = PDC_get_columns();
}
}
#endif
}
void PDC_save_screen_mode(int i)
{
#ifndef EMXVIDEO
if (i >= 0 && i <= 2)
{
saved_font[i] = pdc_font;
saved_scrnmode[i] = scrnmode;
}
#endif
}
void PDC_init_pair(short pair, short fg, short bg)
{
unsigned char att, temp_bg;
chtype i;
fg = curstoreal[fg];
bg = curstoreal[bg];
for (i = 0; i < PDC_OFFSET; i++)
{
att = fg | (bg << 4);
if (i & (A_REVERSE >> PDC_ATTR_SHIFT))
att = bg | (fg << 4);
if (i & (A_UNDERLINE >> PDC_ATTR_SHIFT))
att = 1;
if (i & (A_INVIS >> PDC_ATTR_SHIFT))
{
temp_bg = att >> 4;
att = temp_bg << 4 | temp_bg;
}
if (i & (A_BOLD >> PDC_ATTR_SHIFT))
att |= 8;
if (i & (A_BLINK >> PDC_ATTR_SHIFT))
att |= 128;
pdc_atrtab[pair * PDC_OFFSET + i] = att;
}
}
int PDC_pair_content(short pair, short *fg, short *bg)
{
*fg = realtocurs[pdc_atrtab[pair * PDC_OFFSET] & 0x0F];
*bg = realtocurs[(pdc_atrtab[pair * PDC_OFFSET] & 0xF0) >> 4];
return OK;
}
bool PDC_can_change_color(void)
{
return can_change;
}
int PDC_color_content(short color, short *red, short *green, short *blue)
{
#ifdef PDCTHUNK
THUNKEDVIO vcr;
USHORT palbuf[4];
unsigned char pal[3];
int rc;
/* Read single DAC register */
palbuf[0] = 8;
palbuf[1] = 0;
palbuf[2] = curstoreal[color];
rc = VioGetState(&palbuf, 0);
if (rc)
return ERR;
vcr.cb = sizeof(vcr);
vcr.type = 3;
vcr.firstcolorreg = palbuf[3];
vcr.numcolorregs = 1;
vcr.colorregaddr = PDCTHUNK(pal);
rc = VioGetState(&vcr, 0);
if (rc)
return ERR;
/* Scale and store */
*red = DIVROUND((unsigned)(pal[0]) * 1000, 63);
*green = DIVROUND((unsigned)(pal[1]) * 1000, 63);
*blue = DIVROUND((unsigned)(pal[2]) * 1000, 63);
return OK;
#else
return ERR;
#endif
}
int PDC_init_color(short color, short red, short green, short blue)
{
#ifdef PDCTHUNK
THUNKEDVIO vcr;
USHORT palbuf[4];
unsigned char pal[3];
int rc;
/* Scale */
pal[0] = DIVROUND((unsigned)red * 63, 1000);
pal[1] = DIVROUND((unsigned)green * 63, 1000);
pal[2] = DIVROUND((unsigned)blue * 63, 1000);
/* Set single DAC register */
palbuf[0] = 8;
palbuf[1] = 0;
palbuf[2] = curstoreal[color];
rc = VioGetState(&palbuf, 0);
if (rc)
return ERR;
vcr.cb = sizeof(vcr);
vcr.type = 3;
vcr.firstcolorreg = palbuf[3];
vcr.numcolorregs = 1;
vcr.colorregaddr = PDCTHUNK(pal);
rc = VioSetState(&vcr, 0);
return rc ? ERR : OK;
#else
return ERR;
#endif
}

View File

@@ -0,0 +1,110 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcsetsc.c,v 1.44 2008/07/14 04:24:51 wmcbrine Exp $")
/*man-start**************************************************************
Name: pdcsetsc
Synopsis:
int PDC_set_blink(bool blinkon);
void PDC_set_title(const char *title);
Description:
PDC_set_blink() toggles whether the A_BLINK attribute sets an
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
platforms. (Currently it only works in Win32 and X11.)
Portability X/Open BSD SYS V
PDC_set_blink - - -
PDC_set_title - - -
**man-end****************************************************************/
int PDC_curs_set(int visibility)
{
#ifndef EMXVIDEO
VIOCURSORINFO pvioCursorInfo;
#endif
int ret_vis, hidden = 0, start = 0, end = 0;
PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", visibility));
ret_vis = SP->visibility;
SP->visibility = visibility;
switch(visibility)
{
case 0: /* invisible */
#ifdef EMXVIDEO
start = end = 0;
#else
start = pdc_font / 4;
end = pdc_font;
hidden = -1;
#endif
break;
case 2: /* highly visible */
start = 2; /* almost full-height block */
end = pdc_font - 1;
break;
default: /* normal visibility */
start = (SP->orig_cursor >> 8) & 0xff;
end = SP->orig_cursor & 0xff;
}
#ifdef EMXVIDEO
if (!visibility)
v_hidecursor();
else
v_ctype(start, end);
#else
pvioCursorInfo.yStart = (USHORT)start;
pvioCursorInfo.cEnd = (USHORT)end;
pvioCursorInfo.cx = (USHORT)1;
pvioCursorInfo.attr = hidden;
VioSetCurType((PVIOCURSORINFO)&pvioCursorInfo, 0);
#endif
return ret_vis;
}
void PDC_set_title(const char *title)
{
PDC_LOG(("PDC_set_title() - called:<%s>\n", title));
}
int PDC_set_blink(bool blinkon)
{
#ifndef EMXVIDEO
USHORT statebuf[3], result;
statebuf[0] = 6; /* length */
statebuf[1] = 2; /* blink/intensity */
statebuf[2] = !blinkon;
result = VioSetState(&statebuf, 0);
VioGetState(&statebuf, 0); /* needed? */
if (pdc_color_started)
COLORS = statebuf[2] ? 16 : 8;
return (result == 0) ? OK : ERR;
#else
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
#endif
}

View File

@@ -0,0 +1,36 @@
/* Public Domain Curses */
#include "pdcos2.h"
RCSID("$Id: pdcutil.c,v 1.14 2008/07/14 04:24:51 wmcbrine Exp $")
#if defined(OS2) && !defined(__EMX__)
APIRET APIENTRY DosSleep(ULONG ulTime);
#endif
void PDC_beep(void)
{
PDC_LOG(("PDC_beep() - called\n"));
#ifdef EMXVIDEO
putchar('\007');
#else
DosBeep(1380, 100);
#endif
}
void PDC_napms(int ms)
{
PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
#ifdef __EMX__
_sleep2(ms);
#else
DosSleep(ms);
#endif
}
const char *PDC_sysname(void)
{
return "OS/2";
}

View File

@@ -0,0 +1,43 @@
# Watcom WMAKE Makefile for PDCurses library - OS/2 Open Watcom 1.1+
#
# Usage: wmake -f [path\]wccos2.mak [DEBUG=Y] [target]
#
# where target can be any of:
# [all|demos|pdcurses.lib|testcurs.exe...]
!ifdef %PDCURSES_SRCDIR
PDCURSES_SRCDIR = $(%PDCURSES_SRCDIR)
!else
PDCURSES_SRCDIR = ..
!endif
!include $(PDCURSES_SRCDIR)\version.mif
osdir = $(PDCURSES_SRCDIR)\os2
CC = wcc386
TARGET = os2v2
CFLAGS = /bt=$(TARGET) /wx /s /zq /i=$(PDCURSES_SRCDIR)
!ifeq DEBUG Y
CFLAGS += /d2 /DPDCDEBUG
LDFLAGS = D A op q sys $(TARGET)
!else
CFLAGS += /oneatx
LDFLAGS = op q sys $(TARGET)
!endif
LIBEXE = wlib /q /n /b /c /t
!include $(PDCURSES_SRCDIR)\watcom.mif
$(LIBCURSES) : $(LIBOBJS) $(PDCOBJS)
$(LIBEXE) $@ $(LIBOBJS) $(PDCOBJS)
-copy $(LIBCURSES) panel.lib
PLATFORM1 = Watcom C++ OS/2
PLATFORM2 = Open Watcom 1.6 for OS/2
ARCNAME = pdc$(VER)_wcc_os2
!include $(PDCURSES_SRCDIR)\makedist.mif

View File

@@ -0,0 +1,58 @@
/* Public Domain Curses */
/* $Id: panel.h,v 1.19 2008/07/13 16:08:16 wmcbrine Exp $ */
/*----------------------------------------------------------------------*
* Panels for PDCurses *
*----------------------------------------------------------------------*/
#ifndef __PDCURSES_PANEL_H__
#define __PDCURSES_PANEL_H__ 1
#include <curses.h>
#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS)
extern "C"
{
#endif
typedef struct panelobs
{
struct panelobs *above;
struct panel *pan;
} PANELOBS;
typedef struct panel
{
WINDOW *win;
int wstarty;
int wendy;
int wstartx;
int wendx;
struct panel *below;
struct panel *above;
const void *user;
struct panelobs *obscure;
} PANEL;
int bottom_panel(PANEL *pan);
int del_panel(PANEL *pan);
int hide_panel(PANEL *pan);
int move_panel(PANEL *pan, int starty, int startx);
PANEL *new_panel(WINDOW *win);
PANEL *panel_above(const PANEL *pan);
PANEL *panel_below(const PANEL *pan);
int panel_hidden(const PANEL *pan);
const void *panel_userptr(const PANEL *pan);
WINDOW *panel_window(const PANEL *pan);
int replace_panel(PANEL *pan, WINDOW *win);
int set_panel_userptr(PANEL *pan, const void *uptr);
int show_panel(PANEL *pan);
int top_panel(PANEL *pan);
void update_panels(void);
#if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS)
}
#endif
#endif /* __PDCURSES_PANEL_H__ */

View File

@@ -0,0 +1,25 @@
PDCurses Portable Core
======================
This directory contains core PDCurses source code files common to all
platforms.
Building
--------
These modules are built by the platform-specific makefiles, in the
platform directories.
Distribution Status
-------------------
The files in this directory are released to the Public Domain.
Acknowledgements
----------------
The panel library was originally provided by
Warren Tucker <wht@n4hgf.mt-park.ga.us>

View File

@@ -0,0 +1,408 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: addch.c,v 1.54 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: addch
Synopsis:
int addch(const chtype ch);
int waddch(WINDOW *win, const chtype ch);
int mvaddch(int y, int x, const chtype ch);
int mvwaddch(WINDOW *win, int y, int x, const chtype ch);
int echochar(const chtype ch);
int wechochar(WINDOW *win, const chtype ch);
int addrawch(chtype ch);
int waddrawch(WINDOW *win, chtype ch);
int mvaddrawch(int y, int x, chtype ch);
int mvwaddrawch(WINDOW *win, int y, int x, chtype ch);
int add_wch(const cchar_t *wch);
int wadd_wch(WINDOW *win, const cchar_t *wch);
int mvadd_wch(int y, int x, const cchar_t *wch);
int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch);
int echo_wchar(const cchar_t *wch);
int wecho_wchar(WINDOW *win, const cchar_t *wch);
Description:
addch() adds the chtype ch to the default window (stdscr) at the
current cursor position, and advances the cursor. Note that
chtypes can convey both text (a single character) and
attributes, including a color pair. add_wch() is the wide-
character version of this function, taking a pointer to a
cchar_t instead of a chtype.
waddch() is like addch(), but also lets you specify the window.
(This is in fact the core output routine.) wadd_wch() is the
wide version.
mvaddch() moves the cursor to the specified (y, x) position, and
adds ch to stdscr. mvadd_wch() is the wide version.
mvwaddch() moves the cursor to the specified position and adds
ch to the specified window. mvwadd_wch() is the wide version.
echochar() adds ch to stdscr at the current cursor position and
calls refresh(). echo_wchar() is the wide version.
wechochar() adds ch to the specified window and calls
wrefresh(). wecho_wchar() is the wide version.
addrawch(), waddrawch(), mvaddrawch() and mvwaddrawch() are
PDCurses-specific wrappers for addch() etc. that disable the
translation of control characters.
The following applies to all these functions:
If the cursor moves on to the right margin, an automatic newline
is performed. If scrollok is enabled, and a character is added
to the bottom right corner of the window, the scrolling region
will be scrolled up one line. If scrolling is not allowed, ERR
will be returned.
If ch is a tab, newline, or backspace, the cursor will be moved
appropriately within the window. If ch is a newline, the
clrtoeol routine is called before the cursor is moved to the
beginning of the next line. If newline mapping is off, the
cursor will be moved to the next line, but the x coordinate will
be unchanged. If ch is a tab the cursor is moved to the next
tab position within the window. If ch is another control
character, it will be drawn in the ^X notation. Calling the
inch() routine after adding a control character returns the
representation of the control character, not the control
character.
Video attributes can be combined with a character by ORing them
into the parameter. Text, including attributes, can be copied
from one place to another by using inch() and addch().
Note that in PDCurses, for now, a cchar_t and a chtype are the
same. The text field is 16 bits wide, and is treated as Unicode
(UCS-2) when PDCurses is built with wide-character support
(define PDC_WIDE). So, in functions that take a chtype, like
addch(), both the wide and narrow versions will handle Unicode.
But for portability, you should use the wide functions.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
addch Y Y Y
waddch Y Y Y
mvaddch Y Y Y
mvwaddch Y Y Y
echochar Y - 3.0
wechochar Y - 3.0
addrawch - - -
waddrawch - - -
mvaddrawch - - -
mvwaddrawch - - -
add_wch Y
wadd_wch Y
mvadd_wch Y
mvwadd_wch Y
echo_wchar Y
wecho_wchar Y
**man-end****************************************************************/
int waddch(WINDOW *win, const chtype ch)
{
int x, y;
chtype text, attr;
bool xlat;
PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if (!win)
return ERR;
x = win->_curx;
y = win->_cury;
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
return ERR;
xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
text = ch & A_CHARTEXT;
attr = ch & A_ATTRIBUTES;
if (xlat && (text < ' ' || text == 0x7f))
{
int x2;
switch (text)
{
case '\t':
for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
{
if (waddch(win, attr | ' ') == ERR)
return ERR;
/* if tab to next line, exit the loop */
if (!win->_curx)
break;
}
return OK;
case '\n':
/* if lf -> crlf */
if (!SP->raw_out)
x = 0;
wclrtoeol(win);
if (++y > win->_bmarg)
{
y--;
if (wscrl(win, 1) == ERR)
return ERR;
}
break;
case '\b':
/* don't back over left margin */
if (--x < 0)
case '\r':
x = 0;
break;
case 0x7f:
if (waddch(win, attr | '^') == ERR)
return ERR;
return waddch(win, attr | '?');
default:
/* handle control chars */
if (waddch(win, attr | '^') == ERR)
return ERR;
return waddch(win, ch + '@');
}
}
else
{
/* If the incoming character doesn't have its own attribute,
then use the current attributes for the window. If it has
attributes but not a color component, OR the attributes to
the current attributes for the window. If it has a color
component, use the attributes solely from the incoming
character. */
if (!(attr & A_COLOR))
attr |= win->_attrs;
/* wrs (4/10/93): Apply the same sort of logic for the window
background, in that it only takes precedence if other color
attributes are not there and that the background character
will only print if the printing character is blank. */
if (!(attr & A_COLOR))
attr |= win->_bkgd & A_ATTRIBUTES;
else
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
if (text == ' ')
text = win->_bkgd & A_CHARTEXT;
/* Add the attribute back into the character. */
text |= attr;
/* Only change _firstch/_lastch if the character to be added is
different from the character/attribute that is already in
that position in the window. */
if (win->_y[y][x] != text)
{
if (win->_firstch[y] == _NO_CHANGE)
win->_firstch[y] = win->_lastch[y] = x;
else
if (x < win->_firstch[y])
win->_firstch[y] = x;
else
if (x > win->_lastch[y])
win->_lastch[y] = x;
win->_y[y][x] = text;
}
if (++x >= win->_maxx)
{
/* wrap around test */
x = 0;
if (++y > win->_bmarg)
{
y--;
if (wscrl(win, 1) == ERR)
{
PDC_sync(win);
return ERR;
}
}
}
}
win->_curx = x;
win->_cury = y;
if (win->_immed)
wrefresh(win);
if (win->_sync)
wsyncup(win);
return OK;
}
int addch(const chtype ch)
{
PDC_LOG(("addch() - called: ch=%x\n", ch));
return waddch(stdscr, ch);
}
int mvaddch(int y, int x, const chtype ch)
{
PDC_LOG(("mvaddch() - called: y=%d x=%d ch=%x\n", y, x, ch));
if (move(y,x) == ERR)
return ERR;
return waddch(stdscr, ch);
}
int mvwaddch(WINDOW *win, int y, int x, const chtype ch)
{
PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d ch=%d\n", win, y, x, ch));
if (wmove(win, y, x) == ERR)
return ERR;
return waddch(win, ch);
}
int echochar(const chtype ch)
{
PDC_LOG(("echochar() - called: ch=%x\n", ch));
return wechochar(stdscr, ch);
}
int wechochar(WINDOW *win, const chtype ch)
{
PDC_LOG(("wechochar() - called: win=%p ch=%x\n", win, ch));
if (waddch(win, ch) == ERR)
return ERR;
return wrefresh(win);
}
int waddrawch(WINDOW *win, chtype ch)
{
PDC_LOG(("waddrawch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
ch |= A_ALTCHARSET;
return waddch(win, ch);
}
int addrawch(chtype ch)
{
PDC_LOG(("addrawch() - called: ch=%x\n", ch));
return waddrawch(stdscr, ch);
}
int mvaddrawch(int y, int x, chtype ch)
{
PDC_LOG(("mvaddrawch() - called: y=%d x=%d ch=%d\n", y, x, ch));
if (move(y, x) == ERR)
return ERR;
return waddrawch(stdscr, ch);
}
int mvwaddrawch(WINDOW *win, int y, int x, chtype ch)
{
PDC_LOG(("mvwaddrawch() - called: win=%p y=%d x=%d ch=%d\n",
win, y, x, ch));
if (wmove(win, y, x) == ERR)
return ERR;
return waddrawch(win, ch);
}
#ifdef PDC_WIDE
int wadd_wch(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wadd_wch() - called: win=%p wch=%x\n", win, *wch));
return wch ? waddch(win, *wch) : ERR;
}
int add_wch(const cchar_t *wch)
{
PDC_LOG(("add_wch() - called: wch=%x\n", *wch));
return wadd_wch(stdscr, wch);
}
int mvadd_wch(int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvaddch() - called: y=%d x=%d wch=%x\n", y, x, *wch));
if (move(y,x) == ERR)
return ERR;
return wadd_wch(stdscr, wch);
}
int mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvwaddch() - called: win=%p y=%d x=%d wch=%d\n",
win, y, x, *wch));
if (wmove(win, y, x) == ERR)
return ERR;
return wadd_wch(win, wch);
}
int echo_wchar(const cchar_t *wch)
{
PDC_LOG(("echo_wchar() - called: wch=%x\n", *wch));
return wecho_wchar(stdscr, wch);
}
int wecho_wchar(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wecho_wchar() - called: win=%p wch=%x\n", win, *wch));
if (!wch || (wadd_wch(win, wch) == ERR))
return ERR;
return wrefresh(win);
}
#endif

View File

@@ -0,0 +1,242 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: addchstr.c,v 1.43 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: addchstr
Synopsis:
int addchstr(const chtype *ch);
int addchnstr(const chtype *ch, int n);
int waddchstr(WINDOW *win, const chtype *ch);
int waddchnstr(WINDOW *win, const chtype *ch, int n);
int mvaddchstr(int y, int x, const chtype *ch);
int mvaddchnstr(int y, int x, const chtype *ch, int n);
int mvwaddchstr(WINDOW *, int y, int x, const chtype *ch);
int mvwaddchnstr(WINDOW *, int y, int x, const chtype *ch, int n);
int add_wchstr(const cchar_t *wch);
int add_wchnstr(const cchar_t *wch, int n);
int wadd_wchstr(WINDOW *win, const cchar_t *wch);
int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n);
int mvadd_wchstr(int y, int x, const cchar_t *wch);
int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n);
int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch);
int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch,
int n);
Description:
These routines write a chtype or cchar_t string directly into
the window structure, starting at the current or specified
position. The four routines with n as the last argument copy at
most n elements, but no more than will fit on the line. If n =
-1 then the whole string is copied, up to the maximum number
that will fit on the line.
The cursor position is not advanced. These routines do not check
for newline or other special characters, nor does any line
wrapping occur.
Return Value:
All functions return OK or ERR.
Portability X/Open BSD SYS V
addchstr Y - 4.0
waddchstr Y - 4.0
mvaddchstr Y - 4.0
mvwaddchstr Y - 4.0
addchnstr Y - 4.0
waddchnstr Y - 4.0
mvaddchnstr Y - 4.0
mvwaddchnstr Y - 4.0
add_wchstr Y
wadd_wchstr Y
mvadd_wchstr Y
mvwadd_wchstr Y
add_wchnstr Y
wadd_wchnstr Y
mvadd_wchnstr Y
mvwadd_wchnstr Y
**man-end****************************************************************/
#include <string.h>
int waddchnstr(WINDOW *win, const chtype *ch, int n)
{
int y, x, maxx, minx;
chtype *ptr;
PDC_LOG(("waddchnstr() - called: win=%p n=%d\n", win, n));
if (!win || !ch || !n || n < -1)
return ERR;
x = win->_curx;
y = win->_cury;
ptr = &(win->_y[y][x]);
if (n == -1 || n > win->_maxx - x)
n = win->_maxx - x;
minx = win->_firstch[y];
maxx = win->_lastch[y];
for (; n && *ch; n--, x++, ptr++, ch++)
{
if (*ptr != *ch)
{
if (x < minx || minx == _NO_CHANGE)
minx = x;
if (x > maxx)
maxx = x;
PDC_LOG(("y %d x %d minx %d maxx %d *ptr %x *ch"
" %x firstch: %d lastch: %d\n",
y, x, minx, maxx, *ptr, *ch,
win->_firstch[y], win->_lastch[y]));
*ptr = *ch;
}
}
win->_firstch[y] = minx;
win->_lastch[y] = maxx;
return OK;
}
int addchstr(const chtype *ch)
{
PDC_LOG(("addchstr() - called\n"));
return waddchnstr(stdscr, ch, -1);
}
int addchnstr(const chtype *ch, int n)
{
PDC_LOG(("addchnstr() - called\n"));
return waddchnstr(stdscr, ch, n);
}
int waddchstr(WINDOW *win, const chtype *ch)
{
PDC_LOG(("waddchstr() - called: win=%p\n", win));
return waddchnstr(win, ch, -1);
}
int mvaddchstr(int y, int x, const chtype *ch)
{
PDC_LOG(("mvaddchstr() - called: y %d x %d\n", y, x));
if (move(y, x) == ERR)
return ERR;
return waddchnstr(stdscr, ch, -1);
}
int mvaddchnstr(int y, int x, const chtype *ch, int n)
{
PDC_LOG(("mvaddchnstr() - called: y %d x %d n %d\n", y, x, n));
if (move(y, x) == ERR)
return ERR;
return waddchnstr(stdscr, ch, n);
}
int mvwaddchstr(WINDOW *win, int y, int x, const chtype *ch)
{
PDC_LOG(("mvwaddchstr() - called:\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return waddchnstr(win, ch, -1);
}
int mvwaddchnstr(WINDOW *win, int y, int x, const chtype *ch, int n)
{
PDC_LOG(("mvwaddchnstr() - called: y %d x %d n %d \n", y, x, n));
if (wmove(win, y, x) == ERR)
return ERR;
return waddchnstr(win, ch, n);
}
#ifdef PDC_WIDE
int wadd_wchnstr(WINDOW *win, const cchar_t *wch, int n)
{
PDC_LOG(("wadd_wchnstr() - called: win=%p n=%d\n", win, n));
return waddchnstr(win, wch, n);
}
int add_wchstr(const cchar_t *wch)
{
PDC_LOG(("add_wchstr() - called\n"));
return wadd_wchnstr(stdscr, wch, -1);
}
int add_wchnstr(const cchar_t *wch, int n)
{
PDC_LOG(("add_wchnstr() - called\n"));
return wadd_wchnstr(stdscr, wch, n);
}
int wadd_wchstr(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wadd_wchstr() - called: win=%p\n", win));
return wadd_wchnstr(win, wch, -1);
}
int mvadd_wchstr(int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvadd_wchstr() - called: y %d x %d\n", y, x));
if (move(y, x) == ERR)
return ERR;
return wadd_wchnstr(stdscr, wch, -1);
}
int mvadd_wchnstr(int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvadd_wchnstr() - called: y %d x %d n %d\n", y, x, n));
if (move(y, x) == ERR)
return ERR;
return wadd_wchnstr(stdscr, wch, n);
}
int mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvwadd_wchstr() - called:\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wadd_wchnstr(win, wch, -1);
}
int mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvwadd_wchnstr() - called: y %d x %d n %d \n", y, x, n));
if (wmove(win, y, x) == ERR)
return ERR;
return wadd_wchnstr(win, wch, n);
}
#endif

View File

@@ -0,0 +1,237 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: addstr.c,v 1.44 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: addstr
Synopsis:
int addstr(const char *str);
int addnstr(const char *str, int n);
int waddstr(WINDOW *win, const char *str);
int waddnstr(WINDOW *win, const char *str, int n);
int mvaddstr(int y, int x, const char *str);
int mvaddnstr(int y, int x, const char *str, int n);
int mvwaddstr(WINDOW *win, int y, int x, const char *str);
int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);
int addwstr(const wchar_t *wstr);
int addnwstr(const wchar_t *wstr, int n);
int waddwstr(WINDOW *win, const wchar_t *wstr);
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n);
int mvaddwstr(int y, int x, const wchar_t *wstr);
int mvaddnwstr(int y, int x, const wchar_t *wstr, int n);
int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr);
int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
Description:
These routines write all the characters of the null-terminated
string str or wide-character string wstr to the given window.
The functionality is similar to calling waddch() once for each
character in the string; except that, when PDCurses is built
with wide-character support enabled, the narrow-character
functions treat the string as a multibyte string in the current
locale, and convert it. The routines with n as the last
argument write at most n characters; if n is negative, then the
entire string will be added.
Return Value:
All functions return OK or ERR.
Portability X/Open BSD SYS V
addstr Y Y Y
waddstr Y Y Y
mvaddstr Y Y Y
mvwaddstr Y Y Y
addnstr Y - 4.0
waddnstr Y - 4.0
mvaddnstr Y - 4.0
mvwaddnstr Y - 4.0
addwstr Y
waddwstr Y
mvaddwstr Y
mvwaddwstr Y
addnwstr Y
waddnwstr Y
mvaddnwstr Y
mvwaddnwstr Y
**man-end****************************************************************/
int waddnstr(WINDOW *win, const char *str, int n)
{
int i = 0;
PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));
if (!win || !str)
return ERR;
while (str[i] && (i < n || n < 0))
{
#ifdef PDC_WIDE
wchar_t wch;
int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);
if (retval <= 0)
return OK;
i += retval;
#else
chtype wch = (unsigned char)(str[i++]);
#endif
if (waddch(win, wch) == ERR)
return ERR;
}
return OK;
}
int addstr(const char *str)
{
PDC_LOG(("addstr() - called: string=\"%s\"\n", str));
return waddnstr(stdscr, str, -1);
}
int addnstr(const char *str, int n)
{
PDC_LOG(("addnstr() - called: string=\"%s\" n %d \n", str, n));
return waddnstr(stdscr, str, n);
}
int waddstr(WINDOW *win, const char *str)
{
PDC_LOG(("waddstr() - called: string=\"%s\"\n", str));
return waddnstr(win, str, -1);
}
int mvaddstr(int y, int x, const char *str)
{
PDC_LOG(("mvaddstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
if (move(y, x) == ERR)
return ERR;
return waddnstr(stdscr, str, -1);
}
int mvaddnstr(int y, int x, const char *str, int n)
{
PDC_LOG(("mvaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
y, x, str, n));
if (move(y, x) == ERR)
return ERR;
return waddnstr(stdscr, str, n);
}
int mvwaddstr(WINDOW *win, int y, int x, const char *str)
{
PDC_LOG(("mvwaddstr() - called: string=\"%s\"\n", str));
if (wmove(win, y, x) == ERR)
return ERR;
return waddnstr(win, str, -1);
}
int mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n)
{
PDC_LOG(("mvwaddnstr() - called: y %d x %d string=\"%s\" n %d \n",
y, x, str, n));
if (wmove(win, y, x) == ERR)
return ERR;
return waddnstr(win, str, n);
}
#ifdef PDC_WIDE
int waddnwstr(WINDOW *win, const wchar_t *wstr, int n)
{
int i = 0;
PDC_LOG(("waddnwstr() - called\n"));
if (!win || !wstr)
return ERR;
while (wstr[i] && (i < n || n < 0))
{
chtype wch = wstr[i++];
if (waddch(win, wch) == ERR)
return ERR;
}
return OK;
}
int addwstr(const wchar_t *wstr)
{
PDC_LOG(("addwstr() - called\n"));
return waddnwstr(stdscr, wstr, -1);
}
int addnwstr(const wchar_t *wstr, int n)
{
PDC_LOG(("addnwstr() - called\n"));
return waddnwstr(stdscr, wstr, n);
}
int waddwstr(WINDOW *win, const wchar_t *wstr)
{
PDC_LOG(("waddwstr() - called\n"));
return waddnwstr(win, wstr, -1);
}
int mvaddwstr(int y, int x, const wchar_t *wstr)
{
PDC_LOG(("mvaddstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return waddnwstr(stdscr, wstr, -1);
}
int mvaddnwstr(int y, int x, const wchar_t *wstr, int n)
{
PDC_LOG(("mvaddnstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return waddnwstr(stdscr, wstr, n);
}
int mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *wstr)
{
PDC_LOG(("mvwaddstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return waddnwstr(win, wstr, -1);
}
int mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
{
PDC_LOG(("mvwaddnstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return waddnwstr(win, wstr, n);
}
#endif

View File

@@ -0,0 +1,349 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: attr.c,v 1.41 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: attr
Synopsis:
int attroff(chtype attrs);
int wattroff(WINDOW *win, chtype attrs);
int attron(chtype attrs);
int wattron(WINDOW *win, chtype attrs);
int attrset(chtype attrs);
int wattrset(WINDOW *win, chtype attrs);
int standend(void);
int wstandend(WINDOW *win);
int standout(void);
int wstandout(WINDOW *win);
int color_set(short color_pair, void *opts);
int wcolor_set(WINDOW *win, short color_pair, void *opts);
int attr_get(attr_t *attrs, short *color_pair, void *opts);
int attr_off(attr_t attrs, void *opts);
int attr_on(attr_t attrs, void *opts);
int attr_set(attr_t attrs, short color_pair, void *opts);
int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair,
void *opts);
int wattr_off(WINDOW *win, attr_t attrs, void *opts);
int wattr_on(WINDOW *win, attr_t attrs, void *opts);
int wattr_set(WINDOW *win, attr_t attrs, short color_pair,
void *opts);
int chgat(int n, attr_t attr, short color, const void *opts);
int mvchgat(int y, int x, int n, attr_t attr, short color,
const void *opts);
int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr,
short color, const void *opts);
int wchgat(WINDOW *win, int n, attr_t attr, short color,
const void *opts);
chtype getattrs(WINDOW *win);
Description:
These functions manipulate the current attributes and/or colors
of the named window. These attributes can be any combination
of A_STANDOUT, A_REVERSE, A_BOLD, A_DIM, A_BLINK, A_UNDERLINE.
These constants are defined in <curses.h> and can be combined
with the bitwise-OR operator (|).
The current attributes of a window are applied to all chtypes
that are written into the window with waddch(). Attributes are
a property of the chtype, and move with the character through
any scrolling or insert/delete operations.
attrset() sets the current attributes of the given window to
attrs. attroff() turns off the named attributes without
affecting any other attributes; attron() turns them on.
color_set() sets the window color to the value of color_pair.
standout() is the same as attron(A_STANDOUT). standend() is the
same as attrset(A_NORMAL); that is, it turns off all attributes.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
attroff Y Y Y
wattroff Y Y Y
attron Y Y Y
wattron Y Y Y
attrset Y Y Y
wattrset Y Y Y
standend Y Y Y
wstandend Y Y Y
standout Y Y Y
wstandout Y Y Y
color_set Y
wcolor_set Y
attr_get Y
wattr_get Y
attr_on Y
wattr_on Y
attr_off Y
wattr_off Y
attr_set Y
wattr_set Y
chgat Y
wchgat Y
mvchgat Y
mvwchgat Y
getattrs -
**man-end****************************************************************/
int wattroff(WINDOW *win, chtype attrs)
{
PDC_LOG(("wattroff() - called\n"));
if (!win)
return ERR;
win->_attrs &= (~attrs & A_ATTRIBUTES);
return OK;
}
int attroff(chtype attrs)
{
PDC_LOG(("attroff() - called\n"));
return wattroff(stdscr, attrs);
}
int wattron(WINDOW *win, chtype attrs)
{
chtype newcolr, oldcolr, newattr, oldattr;
PDC_LOG(("wattron() - called\n"));
if (!win)
return ERR;
if ((win->_attrs & A_COLOR) && (attrs & A_COLOR))
{
oldcolr = win->_attrs & A_COLOR;
oldattr = win->_attrs ^ oldcolr;
newcolr = attrs & A_COLOR;
newattr = (attrs & A_ATTRIBUTES) ^ newcolr;
newattr |= oldattr;
win->_attrs = newattr | newcolr;
}
else
win->_attrs |= (attrs & A_ATTRIBUTES);
return OK;
}
int attron(chtype attrs)
{
PDC_LOG(("attron() - called\n"));
return wattron(stdscr, attrs);
}
int wattrset(WINDOW *win, chtype attrs)
{
PDC_LOG(("wattrset() - called\n"));
if (!win)
return ERR;
win->_attrs = attrs & A_ATTRIBUTES;
return OK;
}
int attrset(chtype attrs)
{
PDC_LOG(("attrset() - called\n"));
return wattrset(stdscr, attrs);
}
int standend(void)
{
PDC_LOG(("standend() - called\n"));
return wattrset(stdscr, A_NORMAL);
}
int standout(void)
{
PDC_LOG(("standout() - called\n"));
return wattrset(stdscr, A_STANDOUT);
}
int wstandend(WINDOW *win)
{
PDC_LOG(("wstandend() - called\n"));
return wattrset(win, A_NORMAL);
}
int wstandout(WINDOW *win)
{
PDC_LOG(("wstandout() - called\n"));
return wattrset(win, A_STANDOUT);
}
chtype getattrs(WINDOW *win)
{
return win ? win->_attrs : 0;
}
int wcolor_set(WINDOW *win, short color_pair, void *opts)
{
PDC_LOG(("wcolor_set() - called\n"));
if (!win)
return ERR;
win->_attrs = (win->_attrs & ~A_COLOR) | COLOR_PAIR(color_pair);
return OK;
}
int color_set(short color_pair, void *opts)
{
PDC_LOG(("color_set() - called\n"));
return wcolor_set(stdscr, color_pair, opts);
}
int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
{
PDC_LOG(("wattr_get() - called\n"));
if (!win)
return ERR;
if (attrs)
*attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);
if (color_pair)
*color_pair = PAIR_NUMBER(win->_attrs);
return OK;
}
int attr_get(attr_t *attrs, short *color_pair, void *opts)
{
PDC_LOG(("attr_get() - called\n"));
return wattr_get(stdscr, attrs, color_pair, opts);
}
int wattr_off(WINDOW *win, attr_t attrs, void *opts)
{
PDC_LOG(("wattr_off() - called\n"));
return wattroff(win, attrs);
}
int attr_off(attr_t attrs, void *opts)
{
PDC_LOG(("attr_off() - called\n"));
return wattroff(stdscr, attrs);
}
int wattr_on(WINDOW *win, attr_t attrs, void *opts)
{
PDC_LOG(("wattr_off() - called\n"));
return wattron(win, attrs);
}
int attr_on(attr_t attrs, void *opts)
{
PDC_LOG(("attr_on() - called\n"));
return wattron(stdscr, attrs);
}
int wattr_set(WINDOW *win, attr_t attrs, short color_pair, void *opts)
{
PDC_LOG(("wattr_set() - called\n"));
if (!win)
return ERR;
win->_attrs = (attrs & (A_ATTRIBUTES & ~A_COLOR)) | COLOR_PAIR(color_pair);
return OK;
}
int attr_set(attr_t attrs, short color_pair, void *opts)
{
PDC_LOG(("attr_get() - called\n"));
return wattr_set(stdscr, attrs, color_pair, opts);
}
int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
{
chtype *dest, newattr;
int startpos, endpos;
PDC_LOG(("wchgat() - called\n"));
if (!win)
return ERR;
newattr = (attr & A_ATTRIBUTES) | COLOR_PAIR(color);
startpos = win->_curx;
endpos = ((n < 0) ? win->_maxx : min(startpos + n, win->_maxx)) - 1;
dest = win->_y[win->_cury];
for (n = startpos; n <= endpos; n++)
dest[n] = (dest[n] & A_CHARTEXT) | newattr;
n = win->_cury;
if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
win->_firstch[n] = startpos;
if (endpos > win->_lastch[n])
win->_lastch[n] = endpos;
PDC_sync(win);
return OK;
}
int chgat(int n, attr_t attr, short color, const void *opts)
{
PDC_LOG(("chgat() - called\n"));
return wchgat(stdscr, n, attr, color, opts);
}
int mvchgat(int y, int x, int n, attr_t attr, short color, const void *opts)
{
PDC_LOG(("mvchgat() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wchgat(stdscr, n, attr, color, opts);
}
int mvwchgat(WINDOW *win, int y, int x, int n, attr_t attr, short color,
const void *opts)
{
PDC_LOG(("mvwchgat() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wchgat(win, n, attr, color, opts);
}

View File

@@ -0,0 +1,65 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: beep.c,v 1.34 2008/07/13 16:08:17 wmcbrine Exp $")
/*man-start**************************************************************
Name: beep
Synopsis:
int beep(void);
int flash(void);
Description:
beep() sounds the audible bell on the terminal, if possible;
if not, it calls flash().
flash() "flashes" the screen, by inverting the foreground and
background of every cell, pausing, and then restoring the
original attributes.
Return Value:
These functions return OK.
Portability X/Open BSD SYS V
beep Y Y Y
flash Y Y Y
**man-end****************************************************************/
int beep(void)
{
PDC_LOG(("beep() - called\n"));
if (SP->audible)
PDC_beep();
else
flash();
return OK;
}
int flash(void)
{
int z, y, x;
PDC_LOG(("flash() - called\n"));
/* Reverse each cell; wait; restore the screen */
for (z = 0; z < 2; z++)
{
for (y = 0; y < LINES; y++)
for (x = 0; x < COLS; x++)
curscr->_y[y][x] ^= A_REVERSE;
wrefresh(curscr);
if (!z)
napms(50);
}
return OK;
}

View File

@@ -0,0 +1,220 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: bkgd.c,v 1.39 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: bkgd
Synopsis:
int bkgd(chtype ch);
void bkgdset(chtype ch);
chtype getbkgd(WINDOW *win);
int wbkgd(WINDOW *win, chtype ch);
void wbkgdset(WINDOW *win, chtype ch);
int bkgrnd(const cchar_t *wch);
void bkgrndset(const cchar_t *wch);
int getbkgrnd(cchar_t *wch);
int wbkgrnd(WINDOW *win, const cchar_t *wch);
void wbkgrndset(WINDOW *win, const cchar_t *wch);
int wgetbkgrnd(WINDOW *win, cchar_t *wch);
Description:
bkgdset() and wbkgdset() manipulate the background of a window.
The background is a chtype consisting of any combination of
attributes and a character; it is combined with each chtype
added or inserted to the window by waddch() or winsch(). Only
the attribute part is used to set the background of non-blank
characters, while both character and attributes are used for
blank positions.
bkgd() and wbkgd() not only change the background, but apply it
immediately to every cell in the window.
The attributes that are defined with the attrset()/attron() set
of functions take precedence over the background attributes if
there is a conflict (e.g., different color pairs).
Return Value:
bkgd() and wbkgd() return OK, unless the window is NULL, in
which case they return ERR.
Portability X/Open BSD SYS V
bkgd Y - 4.0
bkgdset Y - 4.0
getbkgd Y
wbkgd Y - 4.0
wbkgdset Y - 4.0
bkgrnd Y
bkgrndset Y
getbkgrnd Y
wbkgrnd Y
wbkgrndset Y
wgetbkgrnd Y
**man-end****************************************************************/
int wbkgd(WINDOW *win, chtype ch)
{
int x, y;
chtype oldcolr, oldch, newcolr, newch, colr, attr;
chtype oldattr = 0, newattr = 0;
chtype *winptr;
PDC_LOG(("wbkgd() - called\n"));
if (!win)
return ERR;
if (win->_bkgd == ch)
return OK;
oldcolr = win->_bkgd & A_COLOR;
if (oldcolr)
oldattr = (win->_bkgd & A_ATTRIBUTES) ^ oldcolr;
oldch = win->_bkgd & A_CHARTEXT;
wbkgdset(win, ch);
newcolr = win->_bkgd & A_COLOR;
if (newcolr)
newattr = (win->_bkgd & A_ATTRIBUTES) ^ newcolr;
newch = win->_bkgd & A_CHARTEXT;
/* what follows is what seems to occur in the System V
implementation of this routine */
for (y = 0; y < win->_maxy; y++)
{
for (x = 0; x < win->_maxx; x++)
{
winptr = win->_y[y] + x;
ch = *winptr;
/* determine the colors and attributes of the character read
from the window */
colr = ch & A_COLOR;
attr = ch & (A_ATTRIBUTES ^ A_COLOR);
/* if the color is the same as the old background color,
then make it the new background color, otherwise leave it */
if (colr == oldcolr)
colr = newcolr;
/* remove any attributes (non color) from the character that
were part of the old background, then combine the
remaining ones with the new background */
attr ^= oldattr;
attr |= newattr;
/* change character if it is there because it was the old
background character */
ch &= A_CHARTEXT;
if (ch == oldch)
ch = newch;
ch |= (attr | colr);
*winptr = ch;
}
}
touchwin(win);
PDC_sync(win);
return OK;
}
int bkgd(chtype ch)
{
PDC_LOG(("bkgd() - called\n"));
return wbkgd(stdscr, ch);
}
void wbkgdset(WINDOW *win, chtype ch)
{
PDC_LOG(("wbkgdset() - called\n"));
if (win)
{
if (!(ch & A_CHARTEXT))
ch |= ' ';
win->_bkgd = ch;
}
}
void bkgdset(chtype ch)
{
PDC_LOG(("bkgdset() - called\n"));
wbkgdset(stdscr, ch);
}
chtype getbkgd(WINDOW *win)
{
PDC_LOG(("getbkgd() - called\n"));
return win ? win->_bkgd : (chtype)ERR;
}
#ifdef PDC_WIDE
int wbkgrnd(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wbkgrnd() - called\n"));
return wch ? wbkgd(win, *wch) : ERR;
}
int bkgrnd(const cchar_t *wch)
{
PDC_LOG(("bkgrnd() - called\n"));
return wbkgrnd(stdscr, wch);
}
void wbkgrndset(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wbkgdset() - called\n"));
if (wch)
wbkgdset(win, *wch);
}
void bkgrndset(const cchar_t *wch)
{
PDC_LOG(("bkgrndset() - called\n"));
wbkgrndset(stdscr, wch);
}
int wgetbkgrnd(WINDOW *win, cchar_t *wch)
{
PDC_LOG(("wgetbkgrnd() - called\n"));
if (!win || !wch)
return ERR;
*wch = win->_bkgd;
return OK;
}
int getbkgrnd(cchar_t *wch)
{
PDC_LOG(("getbkgrnd() - called\n"));
return wgetbkgrnd(stdscr, wch);
}
#endif

View File

@@ -0,0 +1,408 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: border.c,v 1.53 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: border
Synopsis:
int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
chtype tr, chtype bl, chtype br);
int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
chtype bs, chtype tl, chtype tr, chtype bl, chtype br);
int box(WINDOW *win, chtype verch, chtype horch);
int hline(chtype ch, int n);
int vline(chtype ch, int n);
int whline(WINDOW *win, chtype ch, int n);
int wvline(WINDOW *win, chtype ch, int n);
int mvhline(int y, int x, chtype ch, int n);
int mvvline(int y, int x, chtype ch, int n);
int mvwhline(WINDOW *win, int y, int x, chtype ch, int n);
int mvwvline(WINDOW *win, int y, int x, chtype ch, int n);
int border_set(const cchar_t *ls, const cchar_t *rs,
const cchar_t *ts, const cchar_t *bs,
const cchar_t *tl, const cchar_t *tr,
const cchar_t *bl, const cchar_t *br);
int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
const cchar_t *ts, const cchar_t *bs,
const cchar_t *tl, const cchar_t *tr,
const cchar_t *bl, const cchar_t *br);
int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch);
int hline_set(const cchar_t *wch, int n);
int vline_set(const cchar_t *wch, int n);
int whline_set(WINDOW *win, const cchar_t *wch, int n);
int wvline_set(WINDOW *win, const cchar_t *wch, int n);
int mvhline_set(int y, int x, const cchar_t *wch, int n);
int mvvline_set(int y, int x, const cchar_t *wch, int n);
int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n);
Description:
border(), wborder(), and box() draw a border around the edge of
the window. If any argument is zero, an appropriate default is
used:
ls left side of border ACS_VLINE
rs right side of border ACS_VLINE
ts top side of border ACS_HLINE
bs bottom side of border ACS_HLINE
tl top left corner of border ACS_ULCORNER
tr top right corner of border ACS_URCORNER
bl bottom left corner of border ACS_LLCORNER
br bottom right corner of border ACS_LRCORNER
hline() and whline() draw a horizontal line, using ch, starting
from the current cursor position. The cursor position does not
change. The line is at most n characters long, or as many as
will fit in the window.
vline() and wvline() draw a vertical line, using ch, starting
from the current cursor position. The cursor position does not
change. The line is at most n characters long, or as many as
will fit in the window.
Return Value:
These functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
border Y - 4.0
wborder Y - 4.0
box Y Y Y
hline Y - 4.0
vline Y - 4.0
whline Y - 4.0
wvline Y - 4.0
mvhline Y
mvvline Y
mvwhline Y
mvwvline Y
border_set Y
wborder_set Y
box_set Y
hline_set Y
vline_set Y
whline_set Y
wvline_set Y
mvhline_set Y
mvvline_set Y
mvwhline_set Y
mvwvline_set Y
**man-end****************************************************************/
/* _attr_passthru() -- Takes a single chtype 'ch' and checks if the
current attribute of window 'win', as set by wattrset(), and/or the
current background of win, as set by wbkgd(), should by combined with
it. Attributes set explicitly in ch take precedence. */
static chtype _attr_passthru(WINDOW *win, chtype ch)
{
chtype attr;
/* If the incoming character doesn't have its own attribute, then
use the current attributes for the window. If the incoming
character has attributes, but not a color component, OR the
attributes to the current attributes for the window. If the
incoming character has a color component, use only the attributes
from the incoming character. */
attr = ch & A_ATTRIBUTES;
if (!(attr & A_COLOR))
attr |= win->_attrs;
/* wrs (4/10/93) -- Apply the same sort of logic for the window
background, in that it only takes precedence if other color
attributes are not there. */
if (!(attr & A_COLOR))
attr |= win->_bkgd & A_ATTRIBUTES;
else
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
ch = (ch & A_CHARTEXT) | attr;
return ch;
}
int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
chtype tl, chtype tr, chtype bl, chtype br)
{
int i, ymax, xmax;
PDC_LOG(("wborder() - called\n"));
if (!win)
return ERR;
ymax = win->_maxy - 1;
xmax = win->_maxx - 1;
ls = _attr_passthru(win, ls ? ls : ACS_VLINE);
rs = _attr_passthru(win, rs ? rs : ACS_VLINE);
ts = _attr_passthru(win, ts ? ts : ACS_HLINE);
bs = _attr_passthru(win, bs ? bs : ACS_HLINE);
tl = _attr_passthru(win, tl ? tl : ACS_ULCORNER);
tr = _attr_passthru(win, tr ? tr : ACS_URCORNER);
bl = _attr_passthru(win, bl ? bl : ACS_LLCORNER);
br = _attr_passthru(win, br ? br : ACS_LRCORNER);
for (i = 1; i < xmax; i++)
{
win->_y[0][i] = ts;
win->_y[ymax][i] = bs;
}
for (i = 1; i < ymax; i++)
{
win->_y[i][0] = ls;
win->_y[i][xmax] = rs;
}
win->_y[0][0] = tl;
win->_y[0][xmax] = tr;
win->_y[ymax][0] = bl;
win->_y[ymax][xmax] = br;
for (i = 0; i <= ymax; i++)
{
win->_firstch[i] = 0;
win->_lastch[i] = xmax;
}
PDC_sync(win);
return OK;
}
int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl,
chtype tr, chtype bl, chtype br)
{
PDC_LOG(("border() - called\n"));
return wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
}
int box(WINDOW *win, chtype verch, chtype horch)
{
PDC_LOG(("box() - called\n"));
return wborder(win, verch, verch, horch, horch, 0, 0, 0, 0);
}
int whline(WINDOW *win, chtype ch, int n)
{
chtype *dest;
int startpos, endpos;
PDC_LOG(("whline() - called\n"));
if (!win || n < 1)
return ERR;
startpos = win->_curx;
endpos = min(startpos + n, win->_maxx) - 1;
dest = win->_y[win->_cury];
ch = _attr_passthru(win, ch ? ch : ACS_HLINE);
for (n = startpos; n <= endpos; n++)
dest[n] = ch;
n = win->_cury;
if (startpos < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
win->_firstch[n] = startpos;
if (endpos > win->_lastch[n])
win->_lastch[n] = endpos;
PDC_sync(win);
return OK;
}
int hline(chtype ch, int n)
{
PDC_LOG(("hline() - called\n"));
return whline(stdscr, ch, n);
}
int mvhline(int y, int x, chtype ch, int n)
{
PDC_LOG(("mvhline() - called\n"));
if (move(y, x) == ERR)
return ERR;
return whline(stdscr, ch, n);
}
int mvwhline(WINDOW *win, int y, int x, chtype ch, int n)
{
PDC_LOG(("mvwhline() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return whline(win, ch, n);
}
int wvline(WINDOW *win, chtype ch, int n)
{
int endpos, x;
PDC_LOG(("wvline() - called\n"));
if (!win || n < 1)
return ERR;
endpos = min(win->_cury + n, win->_maxy);
x = win->_curx;
ch = _attr_passthru(win, ch ? ch : ACS_VLINE);
for (n = win->_cury; n < endpos; n++)
{
win->_y[n][x] = ch;
if (x < win->_firstch[n] || win->_firstch[n] == _NO_CHANGE)
win->_firstch[n] = x;
if (x > win->_lastch[n])
win->_lastch[n] = x;
}
PDC_sync(win);
return OK;
}
int vline(chtype ch, int n)
{
PDC_LOG(("vline() - called\n"));
return wvline(stdscr, ch, n);
}
int mvvline(int y, int x, chtype ch, int n)
{
PDC_LOG(("mvvline() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wvline(stdscr, ch, n);
}
int mvwvline(WINDOW *win, int y, int x, chtype ch, int n)
{
PDC_LOG(("mvwvline() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wvline(win, ch, n);
}
#ifdef PDC_WIDE
int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
const cchar_t *ts, const cchar_t *bs, const cchar_t *tl,
const cchar_t *tr, const cchar_t *bl, const cchar_t *br)
{
PDC_LOG(("wborder_set() - called\n"));
return wborder(win, ls ? *ls : 0, rs ? *rs : 0, ts ? *ts : 0,
bs ? *bs : 0, tl ? *tl : 0, tr ? *tr : 0,
bl ? *bl : 0, br ? *br : 0);
}
int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
const cchar_t *bl, const cchar_t *br)
{
PDC_LOG(("border_set() - called\n"));
return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
}
int box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)
{
PDC_LOG(("box_set() - called\n"));
return wborder_set(win, verch, verch, horch, horch,
(const cchar_t *)NULL, (const cchar_t *)NULL,
(const cchar_t *)NULL, (const cchar_t *)NULL);
}
int whline_set(WINDOW *win, const cchar_t *wch, int n)
{
PDC_LOG(("whline_set() - called\n"));
return wch ? whline(win, *wch, n) : ERR;
}
int hline_set(const cchar_t *wch, int n)
{
PDC_LOG(("hline_set() - called\n"));
return whline_set(stdscr, wch, n);
}
int mvhline_set(int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvhline_set() - called\n"));
if (move(y, x) == ERR)
return ERR;
return whline_set(stdscr, wch, n);
}
int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvwhline_set() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return whline_set(win, wch, n);
}
int wvline_set(WINDOW *win, const cchar_t *wch, int n)
{
PDC_LOG(("wvline_set() - called\n"));
return wch ? wvline(win, *wch, n) : ERR;
}
int vline_set(const cchar_t *wch, int n)
{
PDC_LOG(("vline_set() - called\n"));
return wvline_set(stdscr, wch, n);
}
int mvvline_set(int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvvline_set() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wvline_set(stdscr, wch, n);
}
int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
{
PDC_LOG(("mvwvline_set() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wvline_set(win, wch, n);
}
#endif

View File

@@ -0,0 +1,154 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: clear.c,v 1.35 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: clear
Synopsis:
int clear(void);
int wclear(WINDOW *win);
int erase(void);
int werase(WINDOW *win);
int clrtobot(void);
int wclrtobot(WINDOW *win);
int clrtoeol(void);
int wclrtoeol(WINDOW *win);
Description:
erase() and werase() copy blanks (i.e. the background chtype) to
every cell of the window.
clear() and wclear() are similar to erase() and werase(), but
they also call clearok() to ensure that the the window is
cleared on the next wrefresh().
clrtobot() and wclrtobot() clear the window from the current
cursor position to the end of the window.
clrtoeol() and wclrtoeol() clear the window from the current
cursor position to the end of the current line.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
clear Y Y Y
wclear Y Y Y
erase Y Y Y
werase Y Y Y
clrtobot Y Y Y
wclrtobot Y Y Y
clrtoeol Y Y Y
wclrtoeol Y Y Y
**man-end****************************************************************/
int wclrtoeol(WINDOW *win)
{
int x, y, minx;
chtype blank, *ptr;
PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n",
win->_cury, win->_curx));
if (!win)
return ERR;
y = win->_cury;
x = win->_curx;
/* wrs (4/10/93) account for window background */
blank = win->_bkgd;
for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++)
*ptr = blank;
if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE)
win->_firstch[y] = x;
win->_lastch[y] = win->_maxx - 1;
PDC_sync(win);
return OK;
}
int clrtoeol(void)
{
PDC_LOG(("clrtoeol() - called\n"));
return wclrtoeol(stdscr);
}
int wclrtobot(WINDOW *win)
{
PDC_LOG(("wclrtobot() - called\n"));
if (!win)
return ERR;
int savey = win->_cury;
int savex = win->_curx;
/* should this involve scrolling region somehow ? */
if (win->_cury + 1 < win->_maxy)
{
win->_curx = 0;
win->_cury++;
for (; win->_maxy > win->_cury; win->_cury++)
wclrtoeol(win);
win->_cury = savey;
win->_curx = savex;
}
wclrtoeol(win);
PDC_sync(win);
return OK;
}
int clrtobot(void)
{
PDC_LOG(("clrtobot() - called\n"));
return wclrtobot(stdscr);
}
int werase(WINDOW *win)
{
PDC_LOG(("werase() - called\n"));
if (wmove(win, 0, 0) == ERR)
return ERR;
return wclrtobot(win);
}
int erase(void)
{
PDC_LOG(("erase() - called\n"));
return werase(stdscr);
}
int wclear(WINDOW *win)
{
PDC_LOG(("wclear() - called\n"));
if (!win)
return ERR;
win->_clear = TRUE;
return werase(win);
}
int clear(void)
{
PDC_LOG(("clear() - called\n"));
return wclear(stdscr);
}

View File

@@ -0,0 +1,295 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: color.c,v 1.83 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: color
Synopsis:
int start_color(void);
int init_pair(short pair, short fg, short bg);
int init_color(short color, short red, short green, short blue);
bool has_colors(void);
bool can_change_color(void);
int color_content(short color, short *red, short *green, short *blue);
int pair_content(short pair, short *fg, short *bg);
int assume_default_colors(int f, int b);
int use_default_colors(void);
int PDC_set_line_color(short color);
Description:
To use these routines, start_color() must be called, usually
immediately after initscr(). Colors are always used in pairs,
referred to as color-pairs. A color-pair consists of a
foreground color and a background color. A color-pair is
initialized via init_pair(). After initialization, COLOR_PAIR(n)
can be used like any other video attribute.
start_color() initializes eight basic colors (black, red, green,
yellow, blue, magenta, cyan, and white), and two global
variables; COLORS and COLOR_PAIRS (respectively defining the
maximum number of colors and color-pairs the terminal is capable
of displaying).
init_pair() changes the definition of a color-pair. It takes
three arguments: the number of the color-pair to be redefined,
and the new values of the foreground and background colors. The
pair number must be between 0 and COLOR_PAIRS - 1, inclusive.
The foreground and background must be between 0 and COLORS - 1,
inclusive. If the color pair was previously initialized, the
screen is refreshed, and all occurrences of that color-pair are
changed to the new definition.
has_colors() indicates if the terminal supports, and can
maniplulate color. It returns TRUE or FALSE.
can_change_color() indicates if the terminal has the capability
to change the definition of its colors.
pair_content() is used to determine what the colors of a given
color-pair consist of.
assume_default_colors() and use_default_colors() emulate the
ncurses extensions of the same names. assume_default_colors(f,
b) is essentially the same as init_pair(0, f, b) (which isn't
allowed); it redefines the default colors. use_default_colors()
allows the use of -1 as a foreground or background color with
init_pair(), and calls assume_default_colors(-1, -1); -1
represents the foreground or background color that the terminal
had at startup. If the environment variable PDC_ORIGINAL_COLORS
is set at the time start_color() is called, that's equivalent to
calling use_default_colors().
PDC_set_line_color() is used to set the color, globally, for
the color of the lines drawn for the attributes: A_UNDERLINE,
A_OVERLINE, A_LEFTLINE and A_RIGHTLINE. A value of -1 (the
default) indicates that the current foreground color should be
used.
NOTE: COLOR_PAIR() and PAIR_NUMBER() are implemented as macros.
Return Value:
All functions return OK on success and ERR on error, except for
has_colors() and can_change_colors(), which return TRUE or FALSE.
Portability X/Open BSD SYS V
start_color Y - 3.2
init_pair Y - 3.2
init_color Y - 3.2
has_colors Y - 3.2
can_change_color Y - 3.2
color_content Y - 3.2
pair_content Y - 3.2
assume_default_colors - - -
use_default_colors - - -
PDC_set_line_color - - -
**man-end****************************************************************/
#include <stdlib.h>
#include <string.h>
int COLORS = 0;
int COLOR_PAIRS = PDC_COLOR_PAIRS;
bool pdc_color_started = FALSE;
/* pair_set[] tracks whether a pair has been set via init_pair() */
static bool pair_set[PDC_COLOR_PAIRS];
static bool default_colors = FALSE;
static short first_col = 0;
int start_color(void)
{
PDC_LOG(("start_color() - called\n"));
if (SP->mono)
return ERR;
pdc_color_started = TRUE;
PDC_set_blink(FALSE); /* Also sets COLORS, to 8 or 16 */
if (!default_colors && SP->orig_attr && getenv("PDC_ORIGINAL_COLORS"))
default_colors = TRUE;
PDC_init_atrtab();
memset(pair_set, 0, PDC_COLOR_PAIRS);
return OK;
}
static void _normalize(short *fg, short *bg)
{
if (*fg == -1)
*fg = SP->orig_attr ? SP->orig_fore : COLOR_WHITE;
if (*bg == -1)
*bg = SP->orig_attr ? SP->orig_back : COLOR_BLACK;
}
int init_pair(short pair, short fg, short bg)
{
PDC_LOG(("init_pair() - called: pair %d fg %d bg %d\n", pair, fg, bg));
if (!pdc_color_started || pair < 1 || pair >= COLOR_PAIRS ||
fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS)
return ERR;
_normalize(&fg, &bg);
/* To allow the PDC_PRESERVE_SCREEN option to work, we only reset
curscr if this call to init_pair() alters a color pair created by
the user. */
if (pair_set[pair])
{
short oldfg, oldbg;
PDC_pair_content(pair, &oldfg, &oldbg);
if (oldfg != fg || oldbg != bg)
curscr->_clear = TRUE;
}
PDC_init_pair(pair, fg, bg);
pair_set[pair] = TRUE;
return OK;
}
bool has_colors(void)
{
PDC_LOG(("has_colors() - called\n"));
return !(SP->mono);
}
int init_color(short color, short red, short green, short blue)
{
PDC_LOG(("init_color() - called\n"));
if (color < 0 || color >= COLORS || !PDC_can_change_color() ||
red < 0 || red > 1000 || green < 0 || green > 1000 ||
blue < 0 || blue > 1000)
return ERR;
return PDC_init_color(color, red, green, blue);
}
int color_content(short color, short *red, short *green, short *blue)
{
PDC_LOG(("color_content() - called\n"));
if (color < 0 || color >= COLORS || !red || !green || !blue)
return ERR;
if (PDC_can_change_color())
return PDC_color_content(color, red, green, blue);
else
{
/* Simulated values for platforms that don't support palette
changing */
short maxval = (color & 8) ? 1000 : 680;
*red = (color & COLOR_RED) ? maxval : 0;
*green = (color & COLOR_GREEN) ? maxval : 0;
*blue = (color & COLOR_BLUE) ? maxval : 0;
return OK;
}
}
bool can_change_color(void)
{
PDC_LOG(("can_change_color() - called\n"));
return PDC_can_change_color();
}
int pair_content(short pair, short *fg, short *bg)
{
PDC_LOG(("pair_content() - called\n"));
if (pair < 0 || pair >= COLOR_PAIRS || !fg || !bg)
return ERR;
return PDC_pair_content(pair, fg, bg);
}
int assume_default_colors(int f, int b)
{
PDC_LOG(("assume_default_colors() - called: f %d b %d\n", f, b));
if (f < -1 || f >= COLORS || b < -1 || b >= COLORS)
return ERR;
if (pdc_color_started)
{
short fg, bg, oldfg, oldbg;
fg = f;
bg = b;
_normalize(&fg, &bg);
PDC_pair_content(0, &oldfg, &oldbg);
if (oldfg != fg || oldbg != bg)
curscr->_clear = TRUE;
PDC_init_pair(0, fg, bg);
}
return OK;
}
int use_default_colors(void)
{
PDC_LOG(("use_default_colors() - called\n"));
default_colors = TRUE;
first_col = -1;
return assume_default_colors(-1, -1);
}
int PDC_set_line_color(short color)
{
PDC_LOG(("PDC_set_line_color() - called: %d\n", color));
if (color < -1 || color >= COLORS)
return ERR;
SP->line_color = color;
return OK;
}
void PDC_init_atrtab(void)
{
int i;
short fg, bg;
if (pdc_color_started && !default_colors)
{
fg = COLOR_WHITE;
bg = COLOR_BLACK;
}
else
fg = bg = -1;
_normalize(&fg, &bg);
for (i = 0; i < PDC_COLOR_PAIRS; i++)
PDC_init_pair(i, fg, bg);
}

View File

@@ -0,0 +1,81 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: debug.c,v 1.7 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: debug
Synopsis:
void traceon(void);
void traceoff(void);
void PDC_debug(const char *, ...);
Description:
traceon() and traceoff() toggle the recording of debugging
information to the file "trace". Although not standard, similar
functions are in some other curses implementations.
PDC_debug() is the function that writes to the file, based on
whether traceon() has been called. It's used from the PDC_LOG()
macro.
Portability X/Open BSD SYS V
traceon - - -
traceoff - - -
PDC_debug - - -
**man-end****************************************************************/
#include <string.h>
#include <sys/types.h>
#include <time.h>
bool pdc_trace_on = FALSE;
void PDC_debug(const char *fmt, ...)
{
va_list args;
FILE *dbfp;
char hms[9];
time_t now;
if (!pdc_trace_on)
return;
/* open debug log file append */
dbfp = fopen("trace", "a");
if (!dbfp)
{
fprintf(stderr,
"PDC_debug(): Unable to open debug log file\n");
return;
}
time(&now);
strftime(hms, 9, "%H:%M:%S", localtime(&now));
fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms);
va_start(args, fmt);
vfprintf(dbfp, fmt, args);
va_end(args);
fclose(dbfp);
}
void traceon(void)
{
PDC_LOG(("traceon() - called\n"));
pdc_trace_on = TRUE;
}
void traceoff(void)
{
PDC_LOG(("traceoff() - called\n"));
pdc_trace_on = FALSE;
}

View File

@@ -0,0 +1,93 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: delch.c,v 1.33 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: delch
Synopsis:
int delch(void);
int wdelch(WINDOW *win);
int mvdelch(int y, int x);
int mvwdelch(WINDOW *win, int y, int x);
Description:
The character under the cursor in the window is deleted. All
characters to the right on the same line are moved to the left
one position and the last character on the line is filled with
a blank. The cursor position does not change (after moving to
y, x if coordinates are specified).
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
delch Y Y Y
wdelch Y Y Y
mvdelch Y Y Y
mvwdelch Y Y Y
**man-end****************************************************************/
#include <string.h>
int wdelch(WINDOW *win)
{
int y, x, maxx;
chtype *temp1;
PDC_LOG(("wdelch() - called\n"));
if (!win)
return ERR;
y = win->_cury;
x = win->_curx;
maxx = win->_maxx - 1;
temp1 = &win->_y[y][x];
memmove(temp1, temp1 + 1, (maxx - x) * sizeof(chtype));
/* wrs (4/10/93) account for window background */
win->_y[y][maxx] = win->_bkgd;
win->_lastch[y] = maxx;
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
win->_firstch[y] = x;
PDC_sync(win);
return OK;
}
int delch(void)
{
PDC_LOG(("delch() - called\n"));
return wdelch(stdscr);
}
int mvdelch(int y, int x)
{
PDC_LOG(("mvdelch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wdelch(stdscr);
}
int mvwdelch(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwdelch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wdelch(win);
}

View File

@@ -0,0 +1,208 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: deleteln.c,v 1.35 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: deleteln
Synopsis:
int deleteln(void);
int wdeleteln(WINDOW *win);
int insdelln(int n);
int winsdelln(WINDOW *win, int n);
int insertln(void);
int winsertln(WINDOW *win);
int mvdeleteln(int y, int x);
int mvwdeleteln(WINDOW *win, int y, int x);
int mvinsertln(int y, int x);
int mvwinsertln(WINDOW *win, int y, int x);
Description:
With the deleteln() and wdeleteln() functions, the line under
the cursor in the window is deleted. All lines below the
current line are moved up one line. The bottom line of the
window is cleared. The cursor position does not change.
With the insertln() and winsertn() functions, a blank line is
inserted above the current line and the bottom line is lost.
mvdeleteln(), mvwdeleteln(), mvinsertln() and mvwinsertln()
allow moving the cursor and inserting/deleting in one call.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
deleteln Y Y Y
wdeleteln Y Y Y
mvdeleteln - - -
mvwdeleteln - - -
insdelln Y - 4.0
winsdelln Y - 4.0
insertln Y Y Y
winsertln Y Y Y
mvinsertln - - -
mvwinsertln - - -
**man-end****************************************************************/
int wdeleteln(WINDOW *win)
{
chtype blank, *temp, *ptr;
int y;
PDC_LOG(("wdeleteln() - called\n"));
if (!win)
return ERR;
/* wrs (4/10/93) account for window background */
blank = win->_bkgd;
temp = win->_y[win->_cury];
for (y = win->_cury; y < win->_bmarg; y++)
{
win->_y[y] = win->_y[y + 1];
win->_firstch[y] = 0;
win->_lastch[y] = win->_maxx - 1;
}
for (ptr = temp; (ptr - temp < win->_maxx); ptr++)
*ptr = blank; /* make a blank line */
if (win->_cury <= win->_bmarg)
{
win->_firstch[win->_bmarg] = 0;
win->_lastch[win->_bmarg] = win->_maxx - 1;
win->_y[win->_bmarg] = temp;
}
return OK;
}
int deleteln(void)
{
PDC_LOG(("deleteln() - called\n"));
return wdeleteln(stdscr);
}
int mvdeleteln(int y, int x)
{
PDC_LOG(("mvdeleteln() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wdeleteln(stdscr);
}
int mvwdeleteln(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwdeleteln() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wdeleteln(win);
}
int winsdelln(WINDOW *win, int n)
{
int i;
PDC_LOG(("winsdelln() - called\n"));
if (!win)
return ERR;
if (n > 0)
{
for (i = 0; i < n; i++)
if (winsertln(win) == ERR)
return ERR;
}
else if (n < 0)
{
n = -n;
for (i = 0; i < n; i++)
if (wdeleteln(win) == ERR)
return ERR;
}
return OK;
}
int insdelln(int n)
{
PDC_LOG(("insdelln() - called\n"));
return winsdelln(stdscr, n);
}
int winsertln(WINDOW *win)
{
chtype blank, *temp, *end;
int y;
PDC_LOG(("winsertln() - called\n"));
if (!win)
return ERR;
/* wrs (4/10/93) account for window background */
blank = win->_bkgd;
temp = win->_y[win->_maxy - 1];
for (y = win->_maxy - 1; y > win->_cury; y--)
{
win->_y[y] = win->_y[y - 1];
win->_firstch[y] = 0;
win->_lastch[y] = win->_maxx - 1;
}
win->_y[win->_cury] = temp;
for (end = &temp[win->_maxx - 1]; temp <= end; temp++)
*temp = blank;
win->_firstch[win->_cury] = 0;
win->_lastch[win->_cury] = win->_maxx - 1;
return OK;
}
int insertln(void)
{
PDC_LOG(("insertln() - called\n"));
return winsertln(stdscr);
}
int mvinsertln(int y, int x)
{
PDC_LOG(("mvinsertln() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winsertln(stdscr);
}
int mvwinsertln(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwinsertln() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winsertln(win);
}

View File

@@ -0,0 +1,29 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: deprec.c,v 1.6 2008/07/13 16:08:18 wmcbrine Exp $")
/* Deprecated functions. These should not be used, and will eventually
be removed. They're here solely for the benefit of applications that
linked to them in older versions of PDCurses. */
bool PDC_check_bios_key(void)
{
return PDC_check_key();
}
int PDC_get_bios_key(void)
{
return PDC_get_key();
}
bool PDC_get_ctrl_break(void)
{
return !SP->raw_inp;
}
int PDC_set_ctrl_break(bool setting)
{
return setting ? noraw() : raw();
}

View File

@@ -0,0 +1,410 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: getch.c,v 1.72 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: getch
Synopsis:
int getch(void);
int wgetch(WINDOW *win);
int mvgetch(int y, int x);
int mvwgetch(WINDOW *win, int y, int x);
int ungetch(int ch);
int flushinp(void);
int get_wch(wint_t *wch);
int wget_wch(WINDOW *win, wint_t *wch);
int mvget_wch(int y, int x, wint_t *wch);
int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch);
int unget_wch(const wchar_t wch);
unsigned long PDC_get_key_modifiers(void);
int PDC_save_key_modifiers(bool flag);
int PDC_return_key_modifiers(bool flag);
Description:
With the getch(), wgetch(), mvgetch(), and mvwgetch() functions,
a character is read from the terminal associated with the window.
In nodelay mode, if there is no input waiting, the value ERR is
returned. In delay mode, the program will hang until the system
passes text through to the program. Depending on the setting of
cbreak(), this will be after one character or after the first
newline. Unless noecho() has been set, the character will also
be echoed into the designated window.
If keypad() is TRUE, and a function key is pressed, the token for
that function key will be returned instead of the raw characters.
Possible function keys are defined in <curses.h> with integers
beginning with 0401, whose names begin with KEY_.
If nodelay(win, TRUE) has been called on the window and no input
is waiting, the value ERR is returned.
ungetch() places ch back onto the input queue to be returned by
the next call to wgetch().
flushinp() throws away any type-ahead that has been typed by the
user and has not yet been read by the program.
PDC_get_key_modifiers() returns the keyboard modifiers (shift,
control, alt, numlock) effective at the time of the last getch()
call, if PDC_save_key_modifiers(TRUE) has been called before the
getch(). Use the macros PDC_KEY_MODIFIER_* to determine which
modifier(s) were set. PDC_return_key_modifiers() tells getch()
to return modifier keys pressed alone as keystrokes (KEY_ALT_L,
etc.). These may not work on all platforms.
NOTE: getch() and ungetch() are implemented as macros, to avoid
conflict with many DOS compiler's runtime libraries.
Return Value:
These functions return ERR or the value of the character, meta
character or function key token.
Portability X/Open BSD SYS V
getch Y Y Y
wgetch Y Y Y
mvgetch Y Y Y
mvwgetch Y Y Y
ungetch Y Y Y
flushinp Y Y Y
get_wch Y
wget_wch Y
mvget_wch Y
mvwget_wch Y
unget_wch Y
PDC_get_key_modifiers - - -
**man-end****************************************************************/
#define _INBUFSIZ 512 /* size of terminal input buffer */
#define NUNGETCH 256 /* max # chars to ungetch() */
static int c_pindex = 0; /* putter index */
static int c_gindex = 1; /* getter index */
static int c_ungind = 0; /* ungetch() push index */
static int c_ungch[NUNGETCH]; /* array of ungotten chars */
static int _mouse_key(WINDOW *win)
{
int i, key = KEY_MOUSE;
unsigned long mbe = SP->_trap_mbe;
/* Filter unwanted mouse events */
for (i = 0; i < 3; i++)
{
if (pdc_mouse_status.changes & (1 << i))
{
int shf = i * 5;
short button = pdc_mouse_status.button[i] & BUTTON_ACTION_MASK;
if ( (!(mbe & (BUTTON1_PRESSED << shf)) &&
(button == BUTTON_PRESSED))
|| (!(mbe & (BUTTON1_CLICKED << shf)) &&
(button == BUTTON_CLICKED))
|| (!(mbe & (BUTTON1_DOUBLE_CLICKED << shf)) &&
(button == BUTTON_DOUBLE_CLICKED))
|| (!(mbe & (BUTTON1_MOVED << shf)) &&
(button == BUTTON_MOVED))
|| (!(mbe & (BUTTON1_RELEASED << shf)) &&
(button == BUTTON_RELEASED))
)
pdc_mouse_status.changes ^= (1 << i);
}
}
if (pdc_mouse_status.changes & PDC_MOUSE_MOVED)
{
if (!(mbe & (BUTTON1_MOVED|BUTTON2_MOVED|BUTTON3_MOVED)))
pdc_mouse_status.changes ^= PDC_MOUSE_MOVED;
}
if (pdc_mouse_status.changes &
(PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN))
{
if (!(mbe & MOUSE_WHEEL_SCROLL))
pdc_mouse_status.changes &=
~(PDC_MOUSE_WHEEL_UP|PDC_MOUSE_WHEEL_DOWN);
}
if (!pdc_mouse_status.changes)
return -1;
/* Check for click in slk area */
i = PDC_mouse_in_slk(pdc_mouse_status.y, pdc_mouse_status.x);
if (i)
{
if (pdc_mouse_status.button[0] & (BUTTON_PRESSED|BUTTON_CLICKED))
key = KEY_F(i);
else
key = -1;
}
return key;
}
int wgetch(WINDOW *win)
{
static int buffer[_INBUFSIZ]; /* character buffer */
int key, waitcount;
PDC_LOG(("wgetch() - called\n"));
if (!win)
return ERR;
waitcount = 0;
/* set the number of 1/20th second napms() calls */
if (SP->delaytenths)
waitcount = 2 * SP->delaytenths;
else
if (win->_delayms)
{
/* Can't really do millisecond intervals, so delay in
1/20ths of a second (50ms) */
waitcount = win->_delayms / 50;
if (!waitcount)
waitcount = 1;
}
/* refresh window when wgetch is called if there have been changes
to it and it is not a pad */
if (!(win->_flags & _PAD) && ((!win->_leaveit &&
(win->_begx + win->_curx != SP->curscol ||
win->_begy + win->_cury != SP->cursrow)) || is_wintouched(win)))
wrefresh(win);
/* if ungotten char exists, remove and return it */
if (c_ungind)
return c_ungch[--c_ungind];
/* if normal and data in buffer */
if ((!SP->raw_inp && !SP->cbreak) && (c_gindex < c_pindex))
return buffer[c_gindex++];
/* prepare to buffer data */
c_pindex = 0;
c_gindex = 0;
/* to get here, no keys are buffered. go and get one. */
for (;;) /* loop for any buffering */
{
/* is there a keystroke ready? */
if (!PDC_check_key())
{
/* if not, handle timeout() and halfdelay() */
if (SP->delaytenths || win->_delayms)
{
if (!waitcount)
return ERR;
waitcount--;
}
else
if (win->_nodelay)
return ERR;
napms(50); /* sleep for 1/20th second */
continue; /* then check again */
}
/* if there is, fetch it */
key = PDC_get_key();
if (SP->key_code)
{
/* filter special keys if not in keypad mode */
if (!win->_use_keypad)
key = -1;
/* filter mouse events; translate mouse clicks in the slk
area to function keys */
else if (key == KEY_MOUSE)
key = _mouse_key(win);
}
/* unwanted key? loop back */
if (key == -1)
continue;
/* translate CR */
if (key == '\r' && SP->autocr && !SP->raw_inp)
key = '\n';
/* if echo is enabled */
if (SP->echo && !SP->key_code)
{
waddch(win, key);
wrefresh(win);
}
/* if no buffering */
if (SP->raw_inp || SP->cbreak)
return key;
/* if no overflow, put data in buffer */
if (key == '\b')
{
if (c_pindex > c_gindex)
c_pindex--;
}
else
if (c_pindex < _INBUFSIZ - 2)
buffer[c_pindex++] = key;
/* if we got a line */
if (key == '\n' || key == '\r')
return buffer[c_gindex++];
}
}
int mvgetch(int y, int x)
{
PDC_LOG(("mvgetch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wgetch(stdscr);
}
int mvwgetch(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwgetch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wgetch(win);
}
int PDC_ungetch(int ch)
{
PDC_LOG(("ungetch() - called\n"));
if (c_ungind >= NUNGETCH) /* pushback stack full */
return ERR;
c_ungch[c_ungind++] = ch;
return OK;
}
int flushinp(void)
{
PDC_LOG(("flushinp() - called\n"));
PDC_flushinp();
c_gindex = 1; /* set indices to kill buffer */
c_pindex = 0;
c_ungind = 0; /* clear c_ungch array */
return OK;
}
unsigned long PDC_get_key_modifiers(void)
{
PDC_LOG(("PDC_get_key_modifiers() - called\n"));
return pdc_key_modifiers;
}
int PDC_save_key_modifiers(bool flag)
{
PDC_LOG(("PDC_save_key_modifiers() - called\n"));
SP->save_key_modifiers = flag;
return OK;
}
int PDC_return_key_modifiers(bool flag)
{
PDC_LOG(("PDC_return_key_modifiers() - called\n"));
SP->return_key_modifiers = flag;
return PDC_modifiers_set();
}
#ifdef PDC_WIDE
int wget_wch(WINDOW *win, wint_t *wch)
{
int key;
PDC_LOG(("wget_wch() - called\n"));
if (!wch)
return ERR;
key = wgetch(win);
if (key == ERR)
return ERR;
*wch = key;
return SP->key_code ? KEY_CODE_YES : OK;
}
int get_wch(wint_t *wch)
{
PDC_LOG(("get_wch() - called\n"));
return wget_wch(stdscr, wch);
}
int mvget_wch(int y, int x, wint_t *wch)
{
PDC_LOG(("mvget_wch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wget_wch(stdscr, wch);
}
int mvwget_wch(WINDOW *win, int y, int x, wint_t *wch)
{
PDC_LOG(("mvwget_wch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wget_wch(win, wch);
}
int unget_wch(const wchar_t wch)
{
return PDC_ungetch(wch);
}
#endif

View File

@@ -0,0 +1,471 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: getstr.c,v 1.51 2008/07/14 04:24:51 wmcbrine Exp $")
/*man-start**************************************************************
Name: getstr
Synopsis:
int getstr(char *str);
int wgetstr(WINDOW *win, char *str);
int mvgetstr(int y, int x, char *str);
int mvwgetstr(WINDOW *win, int y, int x, char *str);
int getnstr(char *str, int n);
int wgetnstr(WINDOW *win, char *str, int n);
int mvgetnstr(int y, int x, char *str, int n);
int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n);
int get_wstr(wint_t *wstr);
int wget_wstr(WINDOW *win, wint_t *wstr);
int mvget_wstr(int y, int x, wint_t *wstr);
int mvwget_wstr(WINDOW *win, int, int, wint_t *wstr);
int getn_wstr(wint_t *wstr, int n);
int wgetn_wstr(WINDOW *win, wint_t *wstr, int n);
int mvgetn_wstr(int y, int x, wint_t *wstr, int n);
int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n);
Description:
These routines call wgetch() repeatedly to build a string,
interpreting erase and kill characters along the way, until a
newline or carriage return is received. When PDCurses is built
with wide-character support enabled, the narrow-character
functions convert the wgetch()'d values into a multibyte string
in the current locale before returning it. The resulting string
is placed in the area pointed to by *str. The routines with n as
the last argument read at most n characters.
Note that there's no way to know how long the buffer passed to
wgetstr() is, so use wgetnstr() to avoid buffer overflows.
Return Value:
This functions return ERR on failure or any other value on
success.
Portability X/Open BSD SYS V
getstr Y Y Y
wgetstr Y Y Y
mvgetstr Y Y Y
mvwgetstr Y Y Y
getnstr Y - 4.0
wgetnstr Y - 4.0
mvgetnstr Y - -
mvwgetnstr Y - -
get_wstr Y
wget_wstr Y
mvget_wstr Y
mvwget_wstr Y
getn_wstr Y
wgetn_wstr Y
mvgetn_wstr Y
mvwgetn_wstr Y
**man-end****************************************************************/
#define MAXLINE 255
int wgetnstr(WINDOW *win, char *str, int n)
{
#ifdef PDC_WIDE
wchar_t wstr[MAXLINE + 1];
if (n < 0 || n > MAXLINE)
n = MAXLINE;
if (wgetn_wstr(win, (wint_t *)wstr, n) == ERR)
return ERR;
return PDC_wcstombs(str, wstr, n);
#else
int ch, i, num, x, chars;
char *p;
bool stop, oldecho, oldcbreak, oldnodelay;
PDC_LOG(("wgetnstr() - called\n"));
if (!win || !str)
return ERR;
chars = 0;
p = str;
stop = FALSE;
x = win->_curx;
oldcbreak = SP->cbreak; /* remember states */
oldecho = SP->echo;
oldnodelay = win->_nodelay;
SP->echo = FALSE; /* we do echo ourselves */
cbreak(); /* ensure each key is returned immediately */
win->_nodelay = FALSE; /* don't return -1 */
wrefresh(win);
while (!stop)
{
ch = wgetch(win);
switch (ch)
{
case '\t':
ch = ' ';
num = TABSIZE - (win->_curx - x) % TABSIZE;
for (i = 0; i < num; i++)
{
if (chars < n)
{
if (oldecho)
waddch(win, ch);
*p++ = ch;
++chars;
}
else
beep();
}
break;
case _ECHAR: /* CTRL-H -- Delete character */
if (p > str)
{
if (oldecho)
waddstr(win, "\b \b");
ch = (unsigned char)(*--p);
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
chars--;
}
break;
case _DLCHAR: /* CTRL-U -- Delete line */
while (p > str)
{
if (oldecho)
waddstr(win, "\b \b");
ch = (unsigned char)(*--p);
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
}
chars = 0;
break;
case _DWCHAR: /* CTRL-W -- Delete word */
while ((p > str) && (*(p - 1) == ' '))
{
if (oldecho)
waddstr(win, "\b \b");
--p; /* remove space */
chars--;
}
while ((p > str) && (*(p - 1) != ' '))
{
if (oldecho)
waddstr(win, "\b \b");
ch = (unsigned char)(*--p);
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
chars--;
}
break;
case '\n':
case '\r':
stop = TRUE;
if (oldecho)
waddch(win, '\n');
break;
default:
if (chars < n)
{
if (!SP->key_code && ch < 0x100)
{
*p++ = ch;
if (oldecho)
waddch(win, ch);
chars++;
}
}
else
beep();
break;
}
wrefresh(win);
}
*p = '\0';
SP->echo = oldecho; /* restore old settings */
SP->cbreak = oldcbreak;
win->_nodelay = oldnodelay;
return OK;
#endif
}
int getstr(char *str)
{
PDC_LOG(("getstr() - called\n"));
return wgetnstr(stdscr, str, MAXLINE);
}
int wgetstr(WINDOW *win, char *str)
{
PDC_LOG(("wgetstr() - called\n"));
return wgetnstr(win, str, MAXLINE);
}
int mvgetstr(int y, int x, char *str)
{
PDC_LOG(("mvgetstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wgetnstr(stdscr, str, MAXLINE);
}
int mvwgetstr(WINDOW *win, int y, int x, char *str)
{
PDC_LOG(("mvwgetstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wgetnstr(win, str, MAXLINE);
}
int getnstr(char *str, int n)
{
PDC_LOG(("getnstr() - called\n"));
return wgetnstr(stdscr, str, n);
}
int mvgetnstr(int y, int x, char *str, int n)
{
PDC_LOG(("mvgetnstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wgetnstr(stdscr, str, n);
}
int mvwgetnstr(WINDOW *win, int y, int x, char *str, int n)
{
PDC_LOG(("mvwgetnstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wgetnstr(win, str, n);
}
#ifdef PDC_WIDE
int wgetn_wstr(WINDOW *win, wint_t *wstr, int n)
{
int ch, i, num, x, chars;
wint_t *p;
bool stop, oldecho, oldcbreak, oldnodelay;
PDC_LOG(("wgetn_wstr() - called\n"));
if (!win || !wstr)
return ERR;
chars = 0;
p = wstr;
stop = FALSE;
x = win->_curx;
oldcbreak = SP->cbreak; /* remember states */
oldecho = SP->echo;
oldnodelay = win->_nodelay;
SP->echo = FALSE; /* we do echo ourselves */
cbreak(); /* ensure each key is returned immediately */
win->_nodelay = FALSE; /* don't return -1 */
wrefresh(win);
while (!stop)
{
ch = wgetch(win);
switch (ch)
{
case '\t':
ch = ' ';
num = TABSIZE - (win->_curx - x) % TABSIZE;
for (i = 0; i < num; i++)
{
if (chars < n)
{
if (oldecho)
waddch(win, ch);
*p++ = ch;
++chars;
}
else
beep();
}
break;
case _ECHAR: /* CTRL-H -- Delete character */
if (p > wstr)
{
if (oldecho)
waddstr(win, "\b \b");
ch = *--p;
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
chars--;
}
break;
case _DLCHAR: /* CTRL-U -- Delete line */
while (p > wstr)
{
if (oldecho)
waddstr(win, "\b \b");
ch = *--p;
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
}
chars = 0;
break;
case _DWCHAR: /* CTRL-W -- Delete word */
while ((p > wstr) && (*(p - 1) == ' '))
{
if (oldecho)
waddstr(win, "\b \b");
--p; /* remove space */
chars--;
}
while ((p > wstr) && (*(p - 1) != ' '))
{
if (oldecho)
waddstr(win, "\b \b");
ch = *--p;
if ((ch < ' ') && (oldecho))
waddstr(win, "\b \b");
chars--;
}
break;
case '\n':
case '\r':
stop = TRUE;
if (oldecho)
waddch(win, '\n');
break;
default:
if (chars < n)
{
if (!SP->key_code)
{
*p++ = ch;
if (oldecho)
waddch(win, ch);
chars++;
}
}
else
beep();
break;
}
wrefresh(win);
}
*p = '\0';
SP->echo = oldecho; /* restore old settings */
SP->cbreak = oldcbreak;
win->_nodelay = oldnodelay;
return OK;
}
int get_wstr(wint_t *wstr)
{
PDC_LOG(("get_wstr() - called\n"));
return wgetn_wstr(stdscr, wstr, MAXLINE);
}
int wget_wstr(WINDOW *win, wint_t *wstr)
{
PDC_LOG(("wget_wstr() - called\n"));
return wgetn_wstr(win, wstr, MAXLINE);
}
int mvget_wstr(int y, int x, wint_t *wstr)
{
PDC_LOG(("mvget_wstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wgetn_wstr(stdscr, wstr, MAXLINE);
}
int mvwget_wstr(WINDOW *win, int y, int x, wint_t *wstr)
{
PDC_LOG(("mvwget_wstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wgetn_wstr(win, wstr, MAXLINE);
}
int getn_wstr(wint_t *wstr, int n)
{
PDC_LOG(("getn_wstr() - called\n"));
return wgetn_wstr(stdscr, wstr, n);
}
int mvgetn_wstr(int y, int x, wint_t *wstr, int n)
{
PDC_LOG(("mvgetn_wstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wgetn_wstr(stdscr, wstr, n);
}
int mvwgetn_wstr(WINDOW *win, int y, int x, wint_t *wstr, int n)
{
PDC_LOG(("mvwgetn_wstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wgetn_wstr(win, wstr, n);
}
#endif

View File

@@ -0,0 +1,143 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: getyx.c,v 1.29 2008/07/15 17:13:26 wmcbrine Exp $")
/*man-start**************************************************************
Name: getyx
Synopsis:
void getyx(WINDOW *win, int y, int x);
void getparyx(WINDOW *win, int y, int x);
void getbegyx(WINDOW *win, int y, int x);
void getmaxyx(WINDOW *win, int y, int x);
void getsyx(int y, int x);
int setsyx(int y, int x);
int getbegy(WINDOW *win);
int getbegx(WINDOW *win);
int getcury(WINDOW *win);
int getcurx(WINDOW *win);
int getpary(WINDOW *win);
int getparx(WINDOW *win);
int getmaxy(WINDOW *win);
int getmaxx(WINDOW *win);
Description:
The getyx() macro (defined in curses.h -- the prototypes here
are merely illustrative) puts the current cursor position of the
specified window into y and x. getbegyx() and getmaxyx() return
the starting coordinates and size of the specified window,
respectively. getparyx() returns the starting coordinates of the
parent's window, if the specified window is a subwindow;
otherwise it sets y and x to -1. These are all macros.
getsyx() gets the coordinates of the virtual screen cursor, and
stores them in y and x. If leaveok() is TRUE, it returns -1, -1.
If lines have been removed with ripoffline(), then getsyx()
includes these lines in its count; so, the returned y and x
values should only be used with setsyx().
setsyx() sets the virtual screen cursor to the y, x coordinates.
If y, x are -1, -1, leaveok() is set TRUE.
getsyx() and setsyx() are meant to be used by a library routine
that manipulates curses windows without altering the position of
the cursor. Note that getsyx() is defined only as a macro.
getbegy(), getbegx(), getcurx(), getcury(), getmaxy(),
getmaxx(), getpary(), and getparx() return the appropriate
coordinate or size values, or ERR in the case of a NULL window.
Portability X/Open BSD SYS V
getyx Y Y Y
getparyx - - 4.0
getbegyx - - 3.0
getmaxyx - - 3.0
getsyx - - 3.0
setsyx - - 3.0
getbegy - - -
getbegx - - -
getcury - - -
getcurx - - -
getpary - - -
getparx - - -
getmaxy - - -
getmaxx - - -
**man-end****************************************************************/
int getbegy(WINDOW *win)
{
PDC_LOG(("getbegy() - called\n"));
return win ? win->_begy : ERR;
}
int getbegx(WINDOW *win)
{
PDC_LOG(("getbegx() - called\n"));
return win ? win->_begx : ERR;
}
int getcury(WINDOW *win)
{
PDC_LOG(("getcury() - called\n"));
return win ? win->_cury : ERR;
}
int getcurx(WINDOW *win)
{
PDC_LOG(("getcurx() - called\n"));
return win ? win->_curx : ERR;
}
int getpary(WINDOW *win)
{
PDC_LOG(("getpary() - called\n"));
return win ? win->_pary : ERR;
}
int getparx(WINDOW *win)
{
PDC_LOG(("getparx() - called\n"));
return win ? win->_parx : ERR;
}
int getmaxy(WINDOW *win)
{
PDC_LOG(("getmaxy() - called\n"));
return win ? win->_maxy : ERR;
}
int getmaxx(WINDOW *win)
{
PDC_LOG(("getmaxx() - called\n"));
return win ? win->_maxx : ERR;
}
int setsyx(int y, int x)
{
PDC_LOG(("setsyx() - called\n"));
if(y == -1 && x == -1)
{
curscr->_leaveit = TRUE;
return OK;
}
else
{
curscr->_leaveit = FALSE;
return wmove(curscr, y, x);
}
}

View File

@@ -0,0 +1,125 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: inch.c,v 1.33 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: inch
Synopsis:
chtype inch(void);
chtype winch(WINDOW *win);
chtype mvinch(int y, int x);
chtype mvwinch(WINDOW *win, int y, int x);
int in_wch(cchar_t *wcval);
int win_wch(WINDOW *win, cchar_t *wcval);
int mvin_wch(int y, int x, cchar_t *wcval);
int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval);
Description:
The inch() functions retrieve the character and attribute from
the current or specified window position, in the form of a
chtype. If a NULL window is specified, (chtype)ERR is returned.
The in_wch() functions are the wide-character versions; instead
of returning a chtype, they store a cchar_t at the address
specified by wcval, and return OK or ERR. (No value is stored
when ERR is returned.) Note that in PDCurses, chtype and cchar_t
are the same.
Portability X/Open BSD SYS V
inch Y Y Y
winch Y Y Y
mvinch Y Y Y
mvwinch Y Y Y
in_wch Y
win_wch Y
mvin_wch Y
mvwin_wch Y
**man-end****************************************************************/
chtype winch(WINDOW *win)
{
PDC_LOG(("winch() - called\n"));
if (!win)
return (chtype)ERR;
return win->_y[win->_cury][win->_curx];
}
chtype inch(void)
{
PDC_LOG(("inch() - called\n"));
return winch(stdscr);
}
chtype mvinch(int y, int x)
{
PDC_LOG(("mvinch() - called\n"));
if (move(y, x) == ERR)
return (chtype)ERR;
return stdscr->_y[stdscr->_cury][stdscr->_curx];
}
chtype mvwinch(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwinch() - called\n"));
if (wmove(win, y, x) == ERR)
return (chtype)ERR;
return win->_y[win->_cury][win->_curx];
}
#ifdef PDC_WIDE
int win_wch(WINDOW *win, cchar_t *wcval)
{
PDC_LOG(("win_wch() - called\n"));
if (!win || !wcval)
return ERR;
*wcval = win->_y[win->_cury][win->_curx];
return OK;
}
int in_wch(cchar_t *wcval)
{
PDC_LOG(("in_wch() - called\n"));
return win_wch(stdscr, wcval);
}
int mvin_wch(int y, int x, cchar_t *wcval)
{
PDC_LOG(("mvin_wch() - called\n"));
if (!wcval || (move(y, x) == ERR))
return ERR;
*wcval = stdscr->_y[stdscr->_cury][stdscr->_curx];
return OK;
}
int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval)
{
PDC_LOG(("mvwin_wch() - called\n"));
if (!wcval || (wmove(win, y, x) == ERR))
return ERR;
*wcval = win->_y[win->_cury][win->_curx];
return OK;
}
#endif

View File

@@ -0,0 +1,211 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: inchstr.c,v 1.34 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: inchstr
Synopsis:
int inchstr(chtype *ch);
int inchnstr(chtype *ch, int n);
int winchstr(WINDOW *win, chtype *ch);
int winchnstr(WINDOW *win, chtype *ch, int n);
int mvinchstr(int y, int x, chtype *ch);
int mvinchnstr(int y, int x, chtype *ch, int n);
int mvwinchstr(WINDOW *, int y, int x, chtype *ch);
int mvwinchnstr(WINDOW *, int y, int x, chtype *ch, int n);
int in_wchstr(cchar_t *wch);
int in_wchnstr(cchar_t *wch, int n);
int win_wchstr(WINDOW *win, cchar_t *wch);
int win_wchnstr(WINDOW *win, cchar_t *wch, int n);
int mvin_wchstr(int y, int x, cchar_t *wch);
int mvin_wchnstr(int y, int x, cchar_t *wch, int n);
int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch);
int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n);
Description:
These routines read a chtype or cchar_t string from the window,
starting at the current or specified position, and ending at the
right margin, or after n elements, whichever is less.
Return Value:
All functions return the number of elements read, or ERR on
error.
Portability X/Open BSD SYS V
inchstr Y - 4.0
winchstr Y - 4.0
mvinchstr Y - 4.0
mvwinchstr Y - 4.0
inchnstr Y - 4.0
winchnstr Y - 4.0
mvinchnstr Y - 4.0
mvwinchnstr Y - 4.0
in_wchstr Y
win_wchstr Y
mvin_wchstr Y
mvwin_wchstr Y
in_wchnstr Y
win_wchnstr Y
mvin_wchnstr Y
mvwin_wchnstr Y
**man-end****************************************************************/
int winchnstr(WINDOW *win, chtype *ch, int n)
{
chtype *src;
int i;
PDC_LOG(("winchnstr() - called\n"));
if (!win || !ch || n < 0)
return ERR;
if ((win->_curx + n) > win->_maxx)
n = win->_maxx - win->_curx;
src = win->_y[win->_cury] + win->_curx;
for (i = 0; i < n; i++)
*ch++ = *src++;
*ch = (chtype)0;
return OK;
}
int inchstr(chtype *ch)
{
PDC_LOG(("inchstr() - called\n"));
return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx);
}
int winchstr(WINDOW *win, chtype *ch)
{
PDC_LOG(("winchstr() - called\n"));
return winchnstr(win, ch, win->_maxx - win->_curx);
}
int mvinchstr(int y, int x, chtype *ch)
{
PDC_LOG(("mvinchstr() - called: y %d x %d\n", y, x));
if (move(y, x) == ERR)
return ERR;
return winchnstr(stdscr, ch, stdscr->_maxx - stdscr->_curx);
}
int mvwinchstr(WINDOW *win, int y, int x, chtype *ch)
{
PDC_LOG(("mvwinchstr() - called:\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winchnstr(win, ch, win->_maxx - win->_curx);
}
int inchnstr(chtype *ch, int n)
{
PDC_LOG(("inchnstr() - called\n"));
return winchnstr(stdscr, ch, n);
}
int mvinchnstr(int y, int x, chtype *ch, int n)
{
PDC_LOG(("mvinchnstr() - called: y %d x %d n %d\n", y, x, n));
if (move(y, x) == ERR)
return ERR;
return winchnstr(stdscr, ch, n);
}
int mvwinchnstr(WINDOW *win, int y, int x, chtype *ch, int n)
{
PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n));
if (wmove(win, y, x) == ERR)
return ERR;
return winchnstr(win, ch, n);
}
#ifdef PDC_WIDE
int win_wchnstr(WINDOW *win, cchar_t *wch, int n)
{
PDC_LOG(("win_wchnstr() - called\n"));
return winchnstr(win, wch, n);
}
int in_wchstr(cchar_t *wch)
{
PDC_LOG(("in_wchstr() - called\n"));
return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx);
}
int win_wchstr(WINDOW *win, cchar_t *wch)
{
PDC_LOG(("win_wchstr() - called\n"));
return win_wchnstr(win, wch, win->_maxx - win->_curx);
}
int mvin_wchstr(int y, int x, cchar_t *wch)
{
PDC_LOG(("mvin_wchstr() - called: y %d x %d\n", y, x));
if (move(y, x) == ERR)
return ERR;
return win_wchnstr(stdscr, wch, stdscr->_maxx - stdscr->_curx);
}
int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wch)
{
PDC_LOG(("mvwin_wchstr() - called:\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return win_wchnstr(win, wch, win->_maxx - win->_curx);
}
int in_wchnstr(cchar_t *wch, int n)
{
PDC_LOG(("in_wchnstr() - called\n"));
return win_wchnstr(stdscr, wch, n);
}
int mvin_wchnstr(int y, int x, cchar_t *wch, int n)
{
PDC_LOG(("mvin_wchnstr() - called: y %d x %d n %d\n", y, x, n));
if (move(y, x) == ERR)
return ERR;
return win_wchnstr(stdscr, wch, n);
}
int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wch, int n)
{
PDC_LOG(("mvwinchnstr() - called: y %d x %d n %d \n", y, x, n));
if (wmove(win, y, x) == ERR)
return ERR;
return win_wchnstr(win, wch, n);
}
#endif

View File

@@ -0,0 +1,342 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: initscr.c,v 1.114 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: initscr
Synopsis:
WINDOW *initscr(void);
WINDOW *Xinitscr(int argc, char *argv[]);
int endwin(void);
bool isendwin(void);
SCREEN *newterm(const char *type, FILE *outfd, FILE *infd);
SCREEN *set_term(SCREEN *new);
void delscreen(SCREEN *sp);
int resize_term(int nlines, int ncols);
bool is_termresized(void);
const char *curses_version(void);
Description:
initscr() should be the first curses routine called. It will
initialize all curses data structures, and arrange that the
first call to refresh() will clear the screen. In case of
error, initscr() will write a message to standard error and end
the program.
endwin() should be called before exiting or escaping from curses
mode temporarily. It will restore tty modes, move the cursor to
the lower left corner of the screen and reset the terminal into
the proper non-visual mode. To resume curses after a temporary
escape, call refresh() or doupdate().
isendwin() returns TRUE if endwin() has been called without a
subsequent refresh, unless SP is NULL.
In some implementations of curses, newterm() allows the use of
multiple terminals. Here, it's just an alternative interface for
initscr(). It always returns SP, or NULL.
delscreen() frees the memory allocated by newterm() or
initscr(), since it's not freed by endwin(). This function is
usually not needed. In PDCurses, the parameter must be the
value of SP, and delscreen() sets SP to NULL.
set_term() does nothing meaningful in PDCurses, but is included
for compatibility with other curses implementations.
resize_term() is effectively two functions: When called with
nonzero values for nlines and ncols, it attempts to resize the
screen to the given size. When called with (0, 0), it merely
adjusts the internal structures to match the current size after
the screen is resized by the user. On the currently supported
platforms, this functionality is mutually exclusive: X11 allows
user resizing, while DOS, OS/2 and Win32 allow programmatic
resizing. If you want to support user resizing, you should check
for getch() returning KEY_RESIZE, and/or call is_termresized()
at appropriate times; if either condition occurs, call
resize_term(0, 0). Then, with either user or programmatic
resizing, you'll have to resize any windows you've created, as
appropriate; resize_term() only handles stdscr and curscr.
is_termresized() returns TRUE if the curses screen has been
resized by the user, and a call to resize_term() is needed.
Checking for KEY_RESIZE is generally preferable, unless you're
not handling the keyboard.
curses_version() returns a string describing the version of
PDCurses.
Return Value:
All functions return NULL on error, except endwin(), which
returns ERR on error.
Portability X/Open BSD SYS V
initscr Y Y Y
endwin Y Y Y
isendwin Y - 3.0
newterm Y - Y
set_term Y - Y
delscreen Y - 4.0
resize_term - - -
is_termresized - - -
curses_version - - -
**man-end****************************************************************/
#include <stdlib.h>
char ttytype[128];
const char *_curses_notice = "PDCurses 3.4 - Public Domain 2008";
SCREEN *SP = (SCREEN*)NULL; /* curses variables */
WINDOW *curscr = (WINDOW *)NULL; /* the current screen image */
WINDOW *stdscr = (WINDOW *)NULL; /* the default screen window */
WINDOW *pdc_lastscr = (WINDOW *)NULL; /* the last screen image */
int LINES = 0; /* current terminal height */
int COLS = 0; /* current terminal width */
int TABSIZE = 8;
MOUSE_STATUS Mouse_status, pdc_mouse_status;
extern RIPPEDOFFLINE linesripped[5];
extern char linesrippedoff;
#ifndef XCURSES
static
#endif
WINDOW *Xinitscr(int argc, char *argv[])
{
int i;
PDC_LOG(("Xinitscr() - called\n"));
if (SP && SP->alive)
return NULL;
if (PDC_scr_open(argc, argv) == ERR)
{
fprintf(stderr, "initscr(): Unable to create SP\n");
exit(8);
}
SP->autocr = TRUE; /* cr -> lf by default */
SP->raw_out = FALSE; /* tty I/O modes */
SP->raw_inp = FALSE; /* tty I/O modes */
SP->cbreak = TRUE;
SP->save_key_modifiers = FALSE;
SP->return_key_modifiers = FALSE;
SP->echo = TRUE;
SP->visibility = 1;
SP->resized = FALSE;
SP->_trap_mbe = 0L;
SP->_map_mbe_to_key = 0L;
SP->linesrippedoff = 0;
SP->linesrippedoffontop = 0;
SP->delaytenths = 0;
SP->line_color = -1;
SP->orig_cursor = PDC_get_cursor_mode();
LINES = SP->lines;
COLS = SP->cols;
if (LINES < 2 || COLS < 2)
{
fprintf(stderr, "initscr(): LINES=%d COLS=%d: too small.\n",
LINES, COLS);
exit(4);
}
if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL)
{
fprintf(stderr, "initscr(): Unable to create curscr.\n");
exit(2);
}
if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL)
{
fprintf(stderr, "initscr(): Unable to create pdc_lastscr.\n");
exit(2);
}
wattrset(pdc_lastscr, (chtype)(-1));
werase(pdc_lastscr);
PDC_slk_initialize();
LINES -= SP->slklines;
/* We have to sort out ripped off lines here, and reduce the height
of stdscr by the number of lines ripped off */
for (i = 0; i < linesrippedoff; i++)
{
if (linesripped[i].line < 0)
(*linesripped[i].init)(newwin(1, COLS, LINES - 1, 0), COLS);
else
(*linesripped[i].init)(newwin(1, COLS,
SP->linesrippedoffontop++, 0), COLS);
SP->linesrippedoff++;
LINES--;
}
linesrippedoff = 0;
if (!(stdscr = newwin(LINES, COLS, SP->linesrippedoffontop, 0)))
{
fprintf(stderr, "initscr(): Unable to create stdscr.\n");
exit(1);
}
wclrtobot(stdscr);
/* If preserving the existing screen, don't allow a screen clear */
if (SP->_preserve)
{
untouchwin(curscr);
untouchwin(stdscr);
stdscr->_clear = FALSE;
curscr->_clear = FALSE;
}
else
curscr->_clear = TRUE;
PDC_init_atrtab(); /* set up default colors */
MOUSE_X_POS = MOUSE_Y_POS = -1;
BUTTON_STATUS(1) = BUTTON_RELEASED;
BUTTON_STATUS(2) = BUTTON_RELEASED;
BUTTON_STATUS(3) = BUTTON_RELEASED;
Mouse_status.changes = 0;
SP->alive = TRUE;
def_shell_mode();
sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname());
return stdscr;
}
WINDOW *initscr(void)
{
PDC_LOG(("initscr() - called\n"));
return Xinitscr(0, NULL);
}
int endwin(void)
{
PDC_LOG(("endwin() - called\n"));
/* Allow temporary exit from curses using endwin() */
def_prog_mode();
PDC_scr_close();
SP->alive = FALSE;
return OK;
}
bool isendwin(void)
{
PDC_LOG(("isendwin() - called\n"));
return SP ? !(SP->alive) : FALSE;
}
SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
{
PDC_LOG(("newterm() - called\n"));
return Xinitscr(0, NULL) ? SP : NULL;
}
SCREEN *set_term(SCREEN *new)
{
PDC_LOG(("set_term() - called\n"));
/* We only support one screen */
return (new == SP) ? SP : NULL;
}
void delscreen(SCREEN *sp)
{
PDC_LOG(("delscreen() - called\n"));
if (sp != SP)
return;
PDC_slk_free(); /* free the soft label keys, if needed */
delwin(stdscr);
delwin(curscr);
delwin(pdc_lastscr);
stdscr = (WINDOW *)NULL;
curscr = (WINDOW *)NULL;
pdc_lastscr = (WINDOW *)NULL;
SP->alive = FALSE;
PDC_scr_free(); /* free SP and pdc_atrtab */
SP = (SCREEN *)NULL;
}
int resize_term(int nlines, int ncols)
{
PDC_LOG(("resize_term() - called: nlines %d\n", nlines));
if (!stdscr || PDC_resize_screen(nlines, ncols) == ERR)
return ERR;
SP->lines = PDC_get_rows();
LINES = SP->lines - SP->linesrippedoff - SP->slklines;
SP->cols = COLS = PDC_get_columns();
if (wresize(curscr, SP->lines, SP->cols) == ERR ||
wresize(stdscr, LINES, COLS) == ERR ||
wresize(pdc_lastscr, SP->lines, SP->cols) == ERR)
return ERR;
werase(pdc_lastscr);
curscr->_clear = TRUE;
if (SP->slk_winptr)
{
if (wresize(SP->slk_winptr, SP->slklines, COLS) == ERR)
return ERR;
wmove(SP->slk_winptr, 0, 0);
wclrtobot(SP->slk_winptr);
PDC_slk_initialize();
slk_noutrefresh();
}
touchwin(stdscr);
wnoutrefresh(stdscr);
return OK;
}
bool is_termresized(void)
{
PDC_LOG(("is_termresized() - called\n"));
return SP->resized;
}
const char *curses_version(void)
{
return _curses_notice;
}

View File

@@ -0,0 +1,321 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: inopts.c,v 1.43 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: inopts
Synopsis:
int cbreak(void);
int nocbreak(void);
int echo(void);
int noecho(void);
int halfdelay(int tenths);
int intrflush(WINDOW *win, bool bf);
int keypad(WINDOW *win, bool bf);
int meta(WINDOW *win, bool bf);
int nl(void);
int nonl(void);
int nodelay(WINDOW *win, bool bf);
int notimeout(WINDOW *win, bool bf);
int raw(void);
int noraw(void);
void noqiflush(void);
void qiflush(void);
void timeout(int delay);
void wtimeout(WINDOW *win, int delay);
int typeahead(int fildes);
int crmode(void);
int nocrmode(void);
Description:
cbreak() and nocbreak() toggle cbreak mode. In cbreak mode,
characters typed by the user are made available immediately, and
erase/kill character processing is not performed. In nocbreak
mode, typed characters are buffered until a newline or carriage
return. Interrupt and flow control characters are unaffected by
this mode. PDCurses always starts in cbreak mode.
echo() and noecho() control whether typed characters are echoed
by the input routine. Initially, input characters are echoed.
Subsequent calls to echo() and noecho() do not flush type-ahead.
halfdelay() is similar to cbreak(), but allows for a time limit
to be specified, in tenths of a second. This causes getch() to
block for that period before returning ERR if no key has been
received. tenths must be between 1 and 255.
keypad() controls whether getch() returns function/special keys
as single key codes (e.g., the left arrow key as KEY_LEFT). Per
X/Open, the default for keypad mode is OFF. You'll probably want
it on. With keypad mode off, if a special key is pressed,
getch() does nothing or returns ERR.
nodelay() controls whether wgetch() is a non-blocking call. If
the option is enabled, and no input is ready, wgetch() will
return ERR. If disabled, wgetch() will hang until input is
ready.
nl() enables the translation of a carriage return into a newline
on input. nonl() disables this. Initially, the translation does
occur.
raw() and noraw() toggle raw mode. Raw mode is similar to cbreak
mode, in that characters typed are immediately passed through to
the user program. The difference is that in raw mode, the INTR,
QUIT, SUSP, and STOP characters are passed through without being
interpreted, and without generating a signal.
In PDCurses, the meta() function sets raw mode on or off.
timeout() and wtimeout() set blocking or non-blocking reads for
the specified window. The delay is measured in milliseconds. If
it's negative, a blocking read is used; if zero, then non-
blocking reads are done -- if no input is waiting, ERR is
returned immediately. If the delay is positive, the read blocks
for the delay period; if the period expires, ERR is returned.
intrflush(), notimeout(), noqiflush(), qiflush() and typeahead()
do nothing in PDCurses, but are included for compatibility with
other curses implementations.
crmode() and nocrmode() are archaic equivalents to cbreak() and
nocbreak(), respectively.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
cbreak Y Y Y
nocbreak Y Y Y
echo Y Y Y
noecho Y Y Y
halfdelay Y - Y
intrflush Y - Y
keypad Y - Y
meta Y - Y
nl Y Y Y
nonl Y Y Y
nodelay Y - Y
notimeout Y - Y
raw Y Y Y
noraw Y Y Y
noqiflush Y - Y
qiflush Y - Y
timeout Y - Y
wtimeout Y - Y
typeahead Y - Y
crmode -
nocrmode -
**man-end****************************************************************/
int cbreak(void)
{
PDC_LOG(("cbreak() - called\n"));
SP->cbreak = TRUE;
return OK;
}
int nocbreak(void)
{
PDC_LOG(("nocbreak() - called\n"));
SP->cbreak = FALSE;
SP->delaytenths = 0;
return OK;
}
int echo(void)
{
PDC_LOG(("echo() - called\n"));
SP->echo = TRUE;
return OK;
}
int noecho(void)
{
PDC_LOG(("noecho() - called\n"));
SP->echo = FALSE;
return OK;
}
int halfdelay(int tenths)
{
PDC_LOG(("halfdelay() - called\n"));
if (tenths < 1 || tenths > 255)
return ERR;
SP->delaytenths = tenths;
return OK;
}
int intrflush(WINDOW *win, bool bf)
{
PDC_LOG(("intrflush() - called\n"));
return OK;
}
int keypad(WINDOW *win, bool bf)
{
PDC_LOG(("keypad() - called\n"));
if (!win)
return ERR;
win->_use_keypad = bf;
return OK;
}
int meta(WINDOW *win, bool bf)
{
PDC_LOG(("meta() - called\n"));
SP->raw_inp = bf;
return OK;
}
int nl(void)
{
PDC_LOG(("nl() - called\n"));
SP->autocr = TRUE;
return OK;
}
int nonl(void)
{
PDC_LOG(("nonl() - called\n"));
SP->autocr = FALSE;
return OK;
}
int nodelay(WINDOW *win, bool flag)
{
PDC_LOG(("nodelay() - called\n"));
if (!win)
return ERR;
win->_nodelay = flag;
return OK;
}
int notimeout(WINDOW *win, bool flag)
{
PDC_LOG(("notimeout() - called\n"));
return OK;
}
int raw(void)
{
PDC_LOG(("raw() - called\n"));
PDC_set_keyboard_binary(TRUE);
SP->raw_inp = TRUE;
return OK;
}
int noraw(void)
{
PDC_LOG(("noraw() - called\n"));
PDC_set_keyboard_binary(FALSE);
SP->raw_inp = FALSE;
return OK;
}
void noqiflush(void)
{
PDC_LOG(("noqiflush() - called\n"));
}
void qiflush(void)
{
PDC_LOG(("qiflush() - called\n"));
}
int typeahead(int fildes)
{
PDC_LOG(("typeahead() - called\n"));
return OK;
}
void wtimeout(WINDOW *win, int delay)
{
PDC_LOG(("wtimeout() - called\n"));
if (!win)
return;
if (delay < 0)
{
/* This causes a blocking read on the window, so turn on delay
mode */
win->_nodelay = FALSE;
win->_delayms = 0;
}
else if (!delay)
{
/* This causes a non-blocking read on the window, so turn off
delay mode */
win->_nodelay = TRUE;
win->_delayms = 0;
}
else
{
/* This causes the read on the window to delay for the number of
milliseconds. Also forces the window into non-blocking read
mode */
/*win->_nodelay = TRUE;*/
win->_delayms = delay;
}
}
void timeout(int delay)
{
PDC_LOG(("timeout() - called\n"));
wtimeout(stdscr, delay);
}
int crmode(void)
{
PDC_LOG(("crmode() - called\n"));
return cbreak();
}
int nocrmode(void)
{
PDC_LOG(("nocrmode() - called\n"));
return nocbreak();
}

View File

@@ -0,0 +1,268 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: insch.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: insch
Synopsis:
int insch(chtype ch);
int winsch(WINDOW *win, chtype ch);
int mvinsch(int y, int x, chtype ch);
int mvwinsch(WINDOW *win, int y, int x, chtype ch);
int insrawch(chtype ch);
int winsrawch(WINDOW *win, chtype ch);
int mvinsrawch(int y, int x, chtype ch);
int mvwinsrawch(WINDOW *win, int y, int x, chtype ch);
int ins_wch(const cchar_t *wch);
int wins_wch(WINDOW *win, const cchar_t *wch);
int mvins_wch(int y, int x, const cchar_t *wch);
int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch);
Description:
The insch() functions insert a chtype into the window at the
current or specified cursor position. The cursor is NOT
advanced. A newline is equivalent to clrtoeol(); tabs are
expanded; other control characters are converted as with
unctrl().
The ins_wch() functions are the wide-character
equivalents, taking cchar_t pointers rather than chtypes.
Video attributes can be combined with a character by ORing
them into the parameter. Text, including attributes, can be
copied from one place to another using inch() and insch().
insrawch() etc. are PDCurses-specific wrappers for insch() etc.
that disable the translation of control characters.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
insch Y Y Y
winsch Y Y Y
mvinsch Y Y Y
mvwinsch Y Y Y
insrawch - - -
winsrawch - - -
ins_wch Y
wins_wch Y
mvins_wch Y
mvwins_wch Y
**man-end****************************************************************/
#include <string.h>
int winsch(WINDOW *win, chtype ch)
{
int x, y;
chtype attr;
bool xlat;
PDC_LOG(("winsch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if (!win)
return ERR;
x = win->_curx;
y = win->_cury;
if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0)
return ERR;
xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
attr = ch & A_ATTRIBUTES;
ch &= A_CHARTEXT;
if (xlat && (ch < ' ' || ch == 0x7f))
{
int x2;
switch (ch)
{
case '\t':
for (x2 = ((x / TABSIZE) + 1) * TABSIZE; x < x2; x++)
{
if (winsch(win, attr | ' ') == ERR)
return ERR;
}
return OK;
case '\n':
wclrtoeol(win);
break;
case 0x7f:
if (winsch(win, attr | '?') == ERR)
return ERR;
return winsch(win, attr | '^');
default:
/* handle control chars */
if (winsch(win, attr | (ch + '@')) == ERR)
return ERR;
return winsch(win, attr | '^');
}
}
else
{
int maxx;
chtype *temp;
/* If the incoming character doesn't have its own attribute,
then use the current attributes for the window. If it has
attributes but not a color component, OR the attributes to
the current attributes for the window. If it has a color
component, use the attributes solely from the incoming
character. */
if (!(attr & A_COLOR))
attr |= win->_attrs;
/* wrs (4/10/93): Apply the same sort of logic for the window
background, in that it only takes precedence if other color
attributes are not there and that the background character
will only print if the printing character is blank. */
if (!(attr & A_COLOR))
attr |= win->_bkgd & A_ATTRIBUTES;
else
attr |= win->_bkgd & (A_ATTRIBUTES ^ A_COLOR);
if (ch == ' ')
ch = win->_bkgd & A_CHARTEXT;
/* Add the attribute back into the character. */
ch |= attr;
maxx = win->_maxx;
temp = &win->_y[y][x];
memmove(temp + 1, temp, (maxx - x - 1) * sizeof(chtype));
win->_lastch[y] = maxx - 1;
if ((win->_firstch[y] == _NO_CHANGE) || (win->_firstch[y] > x))
win->_firstch[y] = x;
*temp = ch;
}
PDC_sync(win);
return OK;
}
int insch(chtype ch)
{
PDC_LOG(("insch() - called\n"));
return winsch(stdscr, ch);
}
int mvinsch(int y, int x, chtype ch)
{
PDC_LOG(("mvinsch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winsch(stdscr, ch);
}
int mvwinsch(WINDOW *win, int y, int x, chtype ch)
{
PDC_LOG(("mvwinsch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winsch(win, ch);
}
int winsrawch(WINDOW *win, chtype ch)
{
PDC_LOG(("winsrawch() - called: win=%p ch=%x "
"(char=%c attr=0x%x)\n", win, ch,
ch & A_CHARTEXT, ch & A_ATTRIBUTES));
if ((ch & A_CHARTEXT) < ' ' || (ch & A_CHARTEXT) == 0x7f)
ch |= A_ALTCHARSET;
return winsch(win, ch);
}
int insrawch(chtype ch)
{
PDC_LOG(("insrawch() - called\n"));
return winsrawch(stdscr, ch);
}
int mvinsrawch(int y, int x, chtype ch)
{
PDC_LOG(("mvinsrawch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winsrawch(stdscr, ch);
}
int mvwinsrawch(WINDOW *win, int y, int x, chtype ch)
{
PDC_LOG(("mvwinsrawch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winsrawch(win, ch);
}
#ifdef PDC_WIDE
int wins_wch(WINDOW *win, const cchar_t *wch)
{
PDC_LOG(("wins_wch() - called\n"));
return wch ? winsch(win, *wch) : ERR;
}
int ins_wch(const cchar_t *wch)
{
PDC_LOG(("ins_wch() - called\n"));
return wins_wch(stdscr, wch);
}
int mvins_wch(int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvins_wch() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wins_wch(stdscr, wch);
}
int mvwins_wch(WINDOW *win, int y, int x, const cchar_t *wch)
{
PDC_LOG(("mvwins_wch() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wins_wch(win, wch);
}
#endif

View File

@@ -0,0 +1,261 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: insstr.c,v 1.46 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: insstr
Synopsis:
int insstr(const char *str);
int insnstr(const char *str, int n);
int winsstr(WINDOW *win, const char *str);
int winsnstr(WINDOW *win, const char *str, int n);
int mvinsstr(int y, int x, const char *str);
int mvinsnstr(int y, int x, const char *str, int n);
int mvwinsstr(WINDOW *win, int y, int x, const char *str);
int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n);
int ins_wstr(const wchar_t *wstr);
int ins_nwstr(const wchar_t *wstr, int n);
int wins_wstr(WINDOW *win, const wchar_t *wstr);
int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n);
int mvins_wstr(int y, int x, const wchar_t *wstr);
int mvins_nwstr(int y, int x, const wchar_t *wstr, int n);
int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr);
int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n);
Description:
The insstr() functions insert a character string into a window
at the current cursor position, by repeatedly calling winsch().
When PDCurses is built with wide-character support enabled, the
narrow-character functions treat the string as a multibyte
string in the current locale, and convert it first. All
characters to the right of the cursor are moved to the right,
with the possibility of the rightmost characters on the line
being lost. The cursor position does not change (after moving
to y, x, if specified). The routines with n as the last
argument insert at most n characters; if n is negative, then the
entire string is inserted.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
insstr Y - 4.0
winsstr Y - 4.0
mvinsstr Y - 4.0
mvwinsstr Y - 4.0
insnstr Y - 4.0
winsnstr Y - 4.0
mvinsnstr Y - 4.0
mvwinsnstr Y - 4.0
ins_wstr Y
wins_wstr Y
mvins_wstr Y
mvwins_wstr Y
ins_nwstr Y
wins_nwstr Y
mvins_nwstr Y
mvwins_nwstr Y
**man-end****************************************************************/
#include <string.h>
int winsnstr(WINDOW *win, const char *str, int n)
{
#ifdef PDC_WIDE
wchar_t wstr[513], *p;
int i;
#endif
int len;
PDC_LOG(("winsnstr() - called: string=\"%s\" n %d \n", str, n));
if (!win || !str)
return ERR;
len = strlen(str);
if (n < 0 || n < len)
n = len;
#ifdef PDC_WIDE
if (n > 512)
n = 512;
p = wstr;
i = 0;
while (str[i] && i < n)
{
int retval = PDC_mbtowc(p, str + i, n - i);
if (retval <= 0)
break;
p++;
i += retval;
}
while (p > wstr)
if (winsch(win, *--p) == ERR)
#else
while (n)
if (winsch(win, (unsigned char)(str[--n])) == ERR)
#endif
return ERR;
return OK;
}
int insstr(const char *str)
{
PDC_LOG(("insstr() - called: string=\"%s\"\n", str));
return winsnstr(stdscr, str, -1);
}
int winsstr(WINDOW *win, const char *str)
{
PDC_LOG(("winsstr() - called: string=\"%s\"\n", str));
return winsnstr(win, str, -1);
}
int mvinsstr(int y, int x, const char *str)
{
PDC_LOG(("mvinsstr() - called: y %d x %d string=\"%s\"\n", y, x, str));
if (move(y, x) == ERR)
return ERR;
return winsnstr(stdscr, str, -1);
}
int mvwinsstr(WINDOW *win, int y, int x, const char *str)
{
PDC_LOG(("mvwinsstr() - called: string=\"%s\"\n", str));
if (wmove(win, y, x) == ERR)
return ERR;
return winsnstr(win, str, -1);
}
int insnstr(const char *str, int n)
{
PDC_LOG(("insnstr() - called: string=\"%s\" n %d \n", str, n));
return winsnstr(stdscr, str, n);
}
int mvinsnstr(int y, int x, const char *str, int n)
{
PDC_LOG(("mvinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
y, x, str, n));
if (move(y, x) == ERR)
return ERR;
return winsnstr(stdscr, str, n);
}
int mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n)
{
PDC_LOG(("mvwinsnstr() - called: y %d x %d string=\"%s\" n %d \n",
y, x, str, n));
if (wmove(win, y, x) == ERR)
return ERR;
return winsnstr(win, str, n);
}
#ifdef PDC_WIDE
int wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
{
const wchar_t *p;
int len;
PDC_LOG(("wins_nwstr() - called\n"));
if (!win || !wstr)
return ERR;
for (len = 0, p = wstr; *p; p++)
len++;
if (n < 0 || n < len)
n = len;
while (n)
if (winsch(win, wstr[--n]) == ERR)
return ERR;
return OK;
}
int ins_wstr(const wchar_t *wstr)
{
PDC_LOG(("ins_wstr() - called\n"));
return wins_nwstr(stdscr, wstr, -1);
}
int wins_wstr(WINDOW *win, const wchar_t *wstr)
{
PDC_LOG(("wins_wstr() - called\n"));
return wins_nwstr(win, wstr, -1);
}
int mvins_wstr(int y, int x, const wchar_t *wstr)
{
PDC_LOG(("mvins_wstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wins_nwstr(stdscr, wstr, -1);
}
int mvwins_wstr(WINDOW *win, int y, int x, const wchar_t *wstr)
{
PDC_LOG(("mvwinsstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wins_nwstr(win, wstr, -1);
}
int ins_nwstr(const wchar_t *wstr, int n)
{
PDC_LOG(("ins_nwstr() - called\n"));
return wins_nwstr(stdscr, wstr, n);
}
int mvins_nwstr(int y, int x, const wchar_t *wstr, int n)
{
PDC_LOG(("mvinsnstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return wins_nwstr(stdscr, wstr, n);
}
int mvwins_nwstr(WINDOW *win, int y, int x, const wchar_t *wstr, int n)
{
PDC_LOG(("mvwinsnstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return wins_nwstr(win, wstr, n);
}
#endif

View File

@@ -0,0 +1,243 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: instr.c,v 1.44 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: instr
Synopsis:
int instr(char *str);
int innstr(char *str, int n);
int winstr(WINDOW *win, char *str);
int winnstr(WINDOW *win, char *str, int n);
int mvinstr(int y, int x, char *str);
int mvinnstr(int y, int x, char *str, int n);
int mvwinstr(WINDOW *win, int y, int x, char *str);
int mvwinnstr(WINDOW *win, int y, int x, char *str, int n);
int inwstr(wchar_t *wstr);
int innwstr(wchar_t *wstr, int n);
int winwstr(WINDOW *win, wchar_t *wstr);
int winnwstr(WINDOW *win, wchar_t *wstr, int n);
int mvinwstr(int y, int x, wchar_t *wstr);
int mvinnwstr(int y, int x, wchar_t *wstr, int n);
int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr);
int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n);
Description:
These functions take characters (or wide characters) from the
current or specified position in the window, and return them as
a string in str (or wstr). Attributes are ignored. The functions
with n as the last argument return a string at most n characters
long.
Return Value:
Upon successful completion, innstr(), mvinnstr(), mvwinnstr()
and winnstr() return the number of characters actually read into
the string; instr(), mvinstr(), mvwinstr() and winstr() return
OK. Otherwise, all these functions return ERR.
Portability X/Open BSD SYS V
instr Y - 4.0
winstr Y - 4.0
mvinstr Y - 4.0
mvwinstr Y - 4.0
innstr Y - 4.0
winnstr Y - 4.0
mvinnstr Y - 4.0
mvwinnstr Y - 4.0
inwstr Y
winwstr Y
mvinwstr Y
mvwinwstr Y
innwstr Y
winnwstr Y
mvinnwstr Y
mvwinnwstr Y
**man-end****************************************************************/
int winnstr(WINDOW *win, char *str, int n)
{
#ifdef PDC_WIDE
wchar_t wstr[513];
if (n < 0 || n > 512)
n = 512;
if (winnwstr(win, wstr, n) == ERR)
return ERR;
return PDC_wcstombs(str, wstr, n);
#else
chtype *src;
int i;
PDC_LOG(("winnstr() - called: n %d \n", n));
if (!win || !str)
return ERR;
if (n < 0 || (win->_curx + n) > win->_maxx)
n = win->_maxx - win->_curx;
src = win->_y[win->_cury] + win->_curx;
for (i = 0; i < n; i++)
str[i] = src[i] & A_CHARTEXT;
str[i] = '\0';
return i;
#endif
}
int instr(char *str)
{
PDC_LOG(("instr() - called: string=\"%s\"\n", str));
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
}
int winstr(WINDOW *win, char *str)
{
PDC_LOG(("winstr() - called: \n"));
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
}
int mvinstr(int y, int x, char *str)
{
PDC_LOG(("mvinstr() - called: y %d x %d \n", y, x));
if (move(y, x) == ERR)
return ERR;
return (ERR == winnstr(stdscr, str, stdscr->_maxx)) ? ERR : OK;
}
int mvwinstr(WINDOW *win, int y, int x, char *str)
{
PDC_LOG(("mvwinstr() - called: y %d x %d \n", y, x));
if (wmove(win, y, x) == ERR)
return ERR;
return (ERR == winnstr(win, str, win->_maxx)) ? ERR : OK;
}
int innstr(char *str, int n)
{
PDC_LOG(("innstr() - called: n %d \n", n));
return winnstr(stdscr, str, n);
}
int mvinnstr(int y, int x, char *str, int n)
{
PDC_LOG(("mvinnstr() - called: y %d x %d n %d \n", y, x, n));
if (move(y, x) == ERR)
return ERR;
return winnstr(stdscr, str, n);
}
int mvwinnstr(WINDOW *win, int y, int x, char *str, int n)
{
PDC_LOG(("mvwinnstr() - called: y %d x %d n %d \n", y, x, n));
if (wmove(win, y, x) == ERR)
return ERR;
return winnstr(win, str, n);
}
#ifdef PDC_WIDE
int winnwstr(WINDOW *win, wchar_t *wstr, int n)
{
chtype *src;
int i;
PDC_LOG(("winnstr() - called: n %d \n", n));
if (!win || !wstr)
return ERR;
if (n < 0 || (win->_curx + n) > win->_maxx)
n = win->_maxx - win->_curx;
src = win->_y[win->_cury] + win->_curx;
for (i = 0; i < n; i++)
wstr[i] = src[i] & A_CHARTEXT;
wstr[i] = L'\0';
return i;
}
int inwstr(wchar_t *wstr)
{
PDC_LOG(("inwstr() - called\n"));
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
}
int winwstr(WINDOW *win, wchar_t *wstr)
{
PDC_LOG(("winwstr() - called\n"));
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
}
int mvinwstr(int y, int x, wchar_t *wstr)
{
PDC_LOG(("mvinwstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return (ERR == winnwstr(stdscr, wstr, stdscr->_maxx)) ? ERR : OK;
}
int mvwinwstr(WINDOW *win, int y, int x, wchar_t *wstr)
{
PDC_LOG(("mvwinstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return (ERR == winnwstr(win, wstr, win->_maxx)) ? ERR : OK;
}
int innwstr(wchar_t *wstr, int n)
{
PDC_LOG(("innwstr() - called\n"));
return winnwstr(stdscr, wstr, n);
}
int mvinnwstr(int y, int x, wchar_t *wstr, int n)
{
PDC_LOG(("mvinnstr() - called\n"));
if (move(y, x) == ERR)
return ERR;
return winnwstr(stdscr, wstr, n);
}
int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *wstr, int n)
{
PDC_LOG(("mvwinnwstr() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
return winnwstr(win, wstr, n);
}
#endif

View File

@@ -0,0 +1,256 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: kernel.c,v 1.78 2008/07/15 17:13:26 wmcbrine Exp $")
/*man-start**************************************************************
Name: kernel
Synopsis:
int def_prog_mode(void);
int def_shell_mode(void);
int reset_prog_mode(void);
int reset_shell_mode(void);
int resetty(void);
int savetty(void);
int ripoffline(int line, int (*init)(WINDOW *, int));
int curs_set(int visibility);
int napms(int ms);
int draino(int ms);
int resetterm(void);
int fixterm(void);
int saveterm(void);
Description:
def_prog_mode() and def_shell_mode() save the current terminal
modes as the "program" (in curses) or "shell" (not in curses)
state for use by the reset_prog_mode() and reset_shell_mode()
functions. This is done automatically by initscr().
reset_prog_mode() and reset_shell_mode() restore the terminal to
"program" (in curses) or "shell" (not in curses) state. These
are done automatically by endwin() and doupdate() after an
endwin(), so they would normally not be called before these
functions.
savetty() and resetty() save and restore the state of the
terminal modes. savetty() saves the current state in a buffer,
and resetty() restores the state to what it was at the last call
to savetty().
curs_set() alters the appearance of the cursor. A visibility of
0 makes it disappear; 1 makes it appear "normal" (usually an
underline) and 2 makes it "highly visible" (usually a block).
ripoffline() reduces the size of stdscr by one line. If the
"line" parameter is positive, the line is removed from the top
of the screen; if negative, from the bottom. Up to 5 lines can
be ripped off stdscr by calling ripoffline() repeatedly. The
function argument, init, is called from within initscr() or
newterm(), so ripoffline() must be called before either of these
functions. The init function receives a pointer to a one-line
WINDOW, and the width of the window. Calling ripoffline() with a
NULL init function pointer is an error.
napms() suspends the program for the specified number of
milliseconds. draino() is an archaic equivalent.
resetterm(), fixterm() and saveterm() are archaic equivalents
for reset_shell_mode(), reset_prog_mode() and def_prog_mode(),
respectively.
Return Value:
All functions return OK on success and ERR on error, except
curs_set(), which returns the previous visibility.
Portability X/Open BSD SYS V
def_prog_mode Y Y Y
def_shell_mode Y Y Y
reset_prog_mode Y Y Y
reset_shell_mode Y Y Y
resetty Y Y Y
savetty Y Y Y
ripoffline Y - 3.0
curs_set Y - 3.0
napms Y Y Y
draino -
resetterm -
fixterm -
saveterm -
**man-end****************************************************************/
#include <string.h>
RIPPEDOFFLINE linesripped[5];
char linesrippedoff = 0;
static struct cttyset
{
bool been_set;
SCREEN saved;
} ctty[3];
enum { PDC_SH_TTY, PDC_PR_TTY, PDC_SAVE_TTY };
static void _save_mode(int i)
{
ctty[i].been_set = TRUE;
memcpy(&(ctty[i].saved), SP, sizeof(SCREEN));
PDC_save_screen_mode(i);
}
static int _restore_mode(int i)
{
if (ctty[i].been_set == TRUE)
{
memcpy(SP, &(ctty[i].saved), sizeof(SCREEN));
if (ctty[i].saved.raw_out)
raw();
PDC_restore_screen_mode(i);
if ((LINES != ctty[i].saved.lines) ||
(COLS != ctty[i].saved.cols))
resize_term(ctty[i].saved.lines, ctty[i].saved.cols);
PDC_curs_set(ctty[i].saved.visibility);
PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol);
}
return ctty[i].been_set ? OK : ERR;
}
int def_prog_mode(void)
{
PDC_LOG(("def_prog_mode() - called\n"));
_save_mode(PDC_PR_TTY);
return OK;
}
int def_shell_mode(void)
{
PDC_LOG(("def_shell_mode() - called\n"));
_save_mode(PDC_SH_TTY);
return OK;
}
int reset_prog_mode(void)
{
PDC_LOG(("reset_prog_mode() - called\n"));
_restore_mode(PDC_PR_TTY);
PDC_reset_prog_mode();
return OK;
}
int reset_shell_mode(void)
{
PDC_LOG(("reset_shell_mode() - called\n"));
_restore_mode(PDC_SH_TTY);
PDC_reset_shell_mode();
return OK;
}
int resetty(void)
{
PDC_LOG(("resetty() - called\n"));
return _restore_mode(PDC_SAVE_TTY);
}
int savetty(void)
{
PDC_LOG(("savetty() - called\n"));
_save_mode(PDC_SAVE_TTY);
return OK;
}
int curs_set(int visibility)
{
int ret_vis;
PDC_LOG(("curs_set() - called: visibility=%d\n", visibility));
if ((visibility < 0) || (visibility > 2))
return ERR;
ret_vis = PDC_curs_set(visibility);
/* If the cursor is changing from invisible to visible, update
its position */
if (visibility && !ret_vis)
PDC_gotoyx(SP->cursrow, SP->curscol);
return ret_vis;
}
int napms(int ms)
{
PDC_LOG(("napms() - called: ms=%d\n", ms));
if (ms)
PDC_napms(ms);
return OK;
}
int ripoffline(int line, int (*init)(WINDOW *, int))
{
PDC_LOG(("ripoffline() - called: line=%d\n", line));
if (linesrippedoff < 5 && line && init)
{
linesripped[(int)linesrippedoff].line = line;
linesripped[(int)linesrippedoff++].init = init;
return OK;
}
return ERR;
}
int draino(int ms)
{
PDC_LOG(("draino() - called\n"));
return napms(ms);
}
int resetterm(void)
{
PDC_LOG(("resetterm() - called\n"));
return reset_shell_mode();
}
int fixterm(void)
{
PDC_LOG(("fixterm() - called\n"));
return reset_prog_mode();
}
int saveterm(void)
{
PDC_LOG(("saveterm() - called\n"));
return def_prog_mode();
}

View File

@@ -0,0 +1,125 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: keyname.c,v 1.8 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: keyname
Synopsis:
char *keyname(int key);
char *key_name(wchar_t c);
bool has_key(int key);
Description:
keyname() returns a string corresponding to the argument key.
key may be any key returned by wgetch().
key_name() is the wide-character version. It takes a wchar_t
parameter, but still returns a char *.
has_key() returns TRUE for recognized keys, FALSE otherwise.
This function is an ncurses extension.
Portability X/Open BSD SYS V
keyname Y - 3.0
key_name Y
has_key - - -
**man-end****************************************************************/
const char *keyname(int key)
{
/* Key names must be in exactly the same order as in curses.h */
static const char *key_name[] =
{
"KEY_BREAK", "KEY_DOWN", "KEY_UP", "KEY_LEFT", "KEY_RIGHT",
"KEY_HOME", "KEY_BACKSPACE", "KEY_F0", "KEY_F(1)", "KEY_F(2)",
"KEY_F(3)", "KEY_F(4)", "KEY_F(5)", "KEY_F(6)", "KEY_F(7)",
"KEY_F(8)", "KEY_F(9)", "KEY_F(10)", "KEY_F(11)", "KEY_F(12)",
"KEY_F(13)", "KEY_F(14)", "KEY_F(15)", "KEY_F(16)", "KEY_F(17)",
"KEY_F(18)", "KEY_F(19)", "KEY_F(20)", "KEY_F(21)", "KEY_F(22)",
"KEY_F(23)", "KEY_F(24)", "KEY_F(25)", "KEY_F(26)", "KEY_F(27)",
"KEY_F(28)", "KEY_F(29)", "KEY_F(30)", "KEY_F(31)", "KEY_F(32)",
"KEY_F(33)", "KEY_F(34)", "KEY_F(35)", "KEY_F(36)", "KEY_F(37)",
"KEY_F(38)", "KEY_F(39)", "KEY_F(40)", "KEY_F(41)", "KEY_F(42)",
"KEY_F(43)", "KEY_F(44)", "KEY_F(45)", "KEY_F(46)", "KEY_F(47)",
"KEY_F(48)", "KEY_F(49)", "KEY_F(50)", "KEY_F(51)", "KEY_F(52)",
"KEY_F(53)", "KEY_F(54)", "KEY_F(55)", "KEY_F(56)", "KEY_F(57)",
"KEY_F(58)", "KEY_F(59)", "KEY_F(60)", "KEY_F(61)", "KEY_F(62)",
"KEY_F(63)", "KEY_DL", "KEY_IL", "KEY_DC", "KEY_IC", "KEY_EIC",
"KEY_CLEAR", "KEY_EOS", "KEY_EOL", "KEY_SF", "KEY_SR",
"KEY_NPAGE", "KEY_PPAGE", "KEY_STAB", "KEY_CTAB", "KEY_CATAB",
"KEY_ENTER", "KEY_SRESET", "KEY_RESET", "KEY_PRINT", "KEY_LL",
"KEY_ABORT", "KEY_SHELP", "KEY_LHELP", "KEY_BTAB", "KEY_BEG",
"KEY_CANCEL", "KEY_CLOSE", "KEY_COMMAND", "KEY_COPY",
"KEY_CREATE", "KEY_END", "KEY_EXIT", "KEY_FIND", "KEY_HELP",
"KEY_MARK", "KEY_MESSAGE", "KEY_MOVE", "KEY_NEXT", "KEY_OPEN",
"KEY_OPTIONS", "KEY_PREVIOUS", "KEY_REDO", "KEY_REFERENCE",
"KEY_REFRESH", "KEY_REPLACE", "KEY_RESTART", "KEY_RESUME",
"KEY_SAVE", "KEY_SBEG", "KEY_SCANCEL", "KEY_SCOMMAND",
"KEY_SCOPY", "KEY_SCREATE", "KEY_SDC", "KEY_SDL", "KEY_SELECT",
"KEY_SEND", "KEY_SEOL", "KEY_SEXIT", "KEY_SFIND", "KEY_SHOME",
"KEY_SIC", "UNKNOWN KEY", "KEY_SLEFT", "KEY_SMESSAGE",
"KEY_SMOVE", "KEY_SNEXT", "KEY_SOPTIONS", "KEY_SPREVIOUS",
"KEY_SPRINT", "KEY_SREDO", "KEY_SREPLACE", "KEY_SRIGHT",
"KEY_SRSUME", "KEY_SSAVE", "KEY_SSUSPEND", "KEY_SUNDO",
"KEY_SUSPEND", "KEY_UNDO", "ALT_0", "ALT_1", "ALT_2", "ALT_3",
"ALT_4", "ALT_5", "ALT_6", "ALT_7", "ALT_8", "ALT_9", "ALT_A",
"ALT_B", "ALT_C", "ALT_D", "ALT_E", "ALT_F", "ALT_G", "ALT_H",
"ALT_I", "ALT_J", "ALT_K", "ALT_L", "ALT_M", "ALT_N", "ALT_O",
"ALT_P", "ALT_Q", "ALT_R", "ALT_S", "ALT_T", "ALT_U", "ALT_V",
"ALT_W", "ALT_X", "ALT_Y", "ALT_Z", "CTL_LEFT", "CTL_RIGHT",
"CTL_PGUP", "CTL_PGDN", "CTL_HOME", "CTL_END", "KEY_A1",
"KEY_A2", "KEY_A3", "KEY_B1", "KEY_B2", "KEY_B3", "KEY_C1",
"KEY_C2", "KEY_C3", "PADSLASH", "PADENTER", "CTL_PADENTER",
"ALT_PADENTER", "PADSTOP", "PADSTAR", "PADMINUS", "PADPLUS",
"CTL_PADSTOP", "CTL_PADCENTER", "CTL_PADPLUS", "CTL_PADMINUS",
"CTL_PADSLASH", "CTL_PADSTAR", "ALT_PADPLUS", "ALT_PADMINUS",
"ALT_PADSLASH", "ALT_PADSTAR", "ALT_PADSTOP", "CTL_INS",
"ALT_DEL", "ALT_INS", "CTL_UP", "CTL_DOWN", "CTL_TAB",
"ALT_TAB", "ALT_MINUS", "ALT_EQUAL", "ALT_HOME", "ALT_PGUP",
"ALT_PGDN", "ALT_END", "ALT_UP", "ALT_DOWN", "ALT_RIGHT",
"ALT_LEFT", "ALT_ENTER", "ALT_ESC", "ALT_BQUOTE",
"ALT_LBRACKET", "ALT_RBRACKET", "ALT_SEMICOLON", "ALT_FQUOTE",
"ALT_COMMA", "ALT_STOP", "ALT_FSLASH", "ALT_BKSP", "CTL_BKSP",
"PAD0", "CTL_PAD0", "CTL_PAD1", "CTL_PAD2", "CTL_PAD3",
"CTL_PAD4", "CTL_PAD5", "CTL_PAD6", "CTL_PAD7","CTL_PAD8",
"CTL_PAD9", "ALT_PAD0", "ALT_PAD1", "ALT_PAD2", "ALT_PAD3",
"ALT_PAD4", "ALT_PAD5", "ALT_PAD6", "ALT_PAD7", "ALT_PAD8",
"ALT_PAD9", "CTL_DEL", "ALT_BSLASH", "CTL_ENTER",
"SHF_PADENTER", "SHF_PADSLASH", "SHF_PADSTAR", "SHF_PADPLUS",
"SHF_PADMINUS", "SHF_UP", "SHF_DOWN", "SHF_IC", "SHF_DC",
"KEY_MOUSE", "KEY_SHIFT_L", "KEY_SHIFT_R", "KEY_CONTROL_L",
"KEY_CONTROL_R", "KEY_ALT_L", "KEY_ALT_R", "KEY_RESIZE",
"KEY_SUP", "KEY_SDOWN"
};
PDC_LOG(("keyname() - called: key %d\n", key));
if ((key >= 0) && (key < 0x80))
return unctrl((chtype)key);
return has_key(key) ? key_name[key - KEY_MIN] : "UNKNOWN KEY";
}
bool has_key(int key)
{
PDC_LOG(("has_key() - called: key %d\n", key));
return (key >= KEY_MIN && key <= KEY_MAX);
}
#ifdef PDC_WIDE
char *key_name(wchar_t c)
{
PDC_LOG(("key_name() - called\n"));
return keyname((int)c);
}
#endif

View File

@@ -0,0 +1,429 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: mouse.c,v 1.45 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: mouse
Synopsis:
int mouse_set(unsigned long mbe);
int mouse_on(unsigned long mbe);
int mouse_off(unsigned long mbe);
int request_mouse_pos(void);
int map_button(unsigned long button);
void wmouse_position(WINDOW *win, int *y, int *x);
unsigned long getmouse(void);
unsigned long getbmap(void);
int mouseinterval(int wait);
bool wenclose(const WINDOW *win, int y, int x);
bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen);
bool mouse_trafo(int *y, int *x, bool to_screen);
mmask_t mousemask(mmask_t mask, mmask_t *oldmask);
int nc_getmouse(MEVENT *event);
int ungetmouse(MEVENT *event);
Description:
As of PDCurses 3.0, there are two separate mouse interfaces: the
classic interface, which is based on the undocumented Sys V
mouse functions; and an ncurses-compatible interface. Both are
active at all times, and you can mix and match functions from
each, though it's not recommended. The ncurses interface is
essentially an emulation layer built on top of the classic
interface; it's here to allow easier porting of ncurses apps.
The classic interface: mouse_set(), mouse_on(), mouse_off(),
request_mouse_pos(), map_button(), wmouse_position(),
getmouse(), and getbmap(). An application using this interface
would start by calling mouse_set() or mouse_on() with a non-zero
value, often ALL_MOUSE_EVENTS. Then it would check for a
KEY_MOUSE return from getch(). If found, it would call
request_mouse_pos() to get the current mouse status.
mouse_set(), mouse_on() and mouse_off() are analagous to
attrset(), attron() and attroff(). These functions set the
mouse button events to trap. The button masks used in these
functions are defined in curses.h and can be or'ed together.
They are the group of masks starting with BUTTON1_RELEASED.
request_mouse_pos() requests curses to fill in the Mouse_status
structure with the current state of the mouse.
map_button() enables the specified mouse action to activate the
Soft Label Keys if the action occurs over the area of the screen
where the Soft Label Keys are displayed. The mouse actions are
defined in curses.h in the group that starts with BUTTON_RELEASED.
wmouse_position() determines if the current mouse position is
within the window passed as an argument. If the mouse is
outside the current window, -1 is returned in the y and x
arguments; otherwise the y and x coordinates of the mouse
(relative to the top left corner of the window) are returned in
y and x.
getmouse() returns the current status of the trapped mouse
buttons as set by mouse_set() or mouse_on().
getbmap() returns the current status of the button action used
to map a mouse action to the Soft Label Keys as set by the
map_button() function.
The ncurses interface: mouseinterval(), wenclose(),
wmouse_trafo(), mouse_trafo(), mousemask(), nc_getmouse(), and
ungetmouse(). A typical application using this interface would
start by calling mousemask() with a non-zero value, often
ALL_MOUSE_EVENTS. Then it would check for a KEY_MOUSE return
from getch(). If found, it would call nc_getmouse() to get the
current mouse status.
mouseinterval() sets the timeout for a mouse click. On all
current platforms, PDCurses receives mouse button press and
release events, but must synthesize click events. It does this
by checking whether a release event is queued up after a press
event. If it gets a press event, and there are no more events
waiting, it will wait for the timeout interval, then check again
for a release. A press followed by a release is reported as
BUTTON_CLICKED; otherwise it's passed through as BUTTON_PRESSED.
The default timeout is 150ms; valid values are 0 (no clicks
reported) through 1000ms. In x11, the timeout can also be set
via the clickPeriod resource. The return value from
mouseinterval() is the old timeout. To check the old value
without setting a new one, call it with a parameter of -1. Note
that although there's no classic equivalent for this function
(apart from the clickPeriod resource), the value set applies in
both interfaces.
wenclose() reports whether the given screen-relative y, x
coordinates fall within the given window.
wmouse_trafo() converts between screen-relative and window-
relative coordinates. A to_screen parameter of TRUE means to
convert from window to screen; otherwise the reverse. The
function returns FALSE if the coordinates aren't within the
window, or if any of the parameters are NULL. The coordinates
have been converted when the function returns TRUE.
mouse_trafo() is the stdscr version of wmouse_trafo().
mousemask() is nearly equivalent to mouse_set(), but instead of
OK/ERR, it returns the value of the mask after setting it. (This
isn't necessarily the same value passed in, since the mask could
be altered on some platforms.) And if the second parameter is a
non-null pointer, mousemask() stores the previous mask value
there. Also, since the ncurses interface doesn't work with
PDCurses' BUTTON_MOVED events, mousemask() filters them out.
nc_getmouse() returns the current mouse status in an MEVENT
struct. This is equivalent to ncurses' getmouse(), renamed to
avoid conflict with PDCurses' getmouse(). But if you define
NCURSES_MOUSE_VERSION (preferably as 2) before including
curses.h, it defines getmouse() to nc_getmouse(), along with a
few other redefintions needed for compatibility with ncurses
code. nc_getmouse() calls request_mouse_pos(), which (not
getmouse()) is the classic equivalent.
ungetmouse() is the mouse equivalent of ungetch(). However,
PDCurses doesn't maintain a queue of mouse events; only one can
be pushed back, and it can overwrite or be overwritten by real
mouse events.
Portability X/Open BSD SYS V
mouse_set - - 4.0
mouse_on - - 4.0
mouse_off - - 4.0
request_mouse_pos - - 4.0
map_button - - 4.0
wmouse_position - - 4.0
getmouse - - 4.0
getbmap - - 4.0
mouseinterval - - -
wenclose - - -
wmouse_trafo - - -
mouse_trafo - - -
mousemask - - -
nc_getmouse - - -
ungetmouse - - -
**man-end****************************************************************/
#include <string.h>
static bool ungot = FALSE;
int mouse_set(unsigned long mbe)
{
PDC_LOG(("mouse_set() - called: event %x\n", mbe));
SP->_trap_mbe = mbe;
return PDC_mouse_set();
}
int mouse_on(unsigned long mbe)
{
PDC_LOG(("mouse_on() - called: event %x\n", mbe));
SP->_trap_mbe |= mbe;
return PDC_mouse_set();
}
int mouse_off(unsigned long mbe)
{
PDC_LOG(("mouse_off() - called: event %x\n", mbe));
SP->_trap_mbe &= ~mbe;
return PDC_mouse_set();
}
int map_button(unsigned long button)
{
PDC_LOG(("map_button() - called: button %x\n", button));
/****************** this does nothing at the moment ***************/
SP->_map_mbe_to_key = button;
return OK;
}
int request_mouse_pos(void)
{
PDC_LOG(("request_mouse_pos() - called\n"));
Mouse_status = pdc_mouse_status;
return OK;
}
void wmouse_position(WINDOW *win, int *y, int *x)
{
PDC_LOG(("wmouse_position() - called\n"));
if (win && wenclose(win, MOUSE_Y_POS, MOUSE_X_POS))
{
if (y)
*y = MOUSE_Y_POS - win->_begy;
if (x)
*x = MOUSE_X_POS - win->_begx;
}
else
{
if (y)
*y = -1;
if (x)
*x = -1;
}
}
unsigned long getmouse(void)
{
PDC_LOG(("getmouse() - called\n"));
return SP->_trap_mbe;
}
unsigned long getbmap(void)
{
PDC_LOG(("getbmap() - called\n"));
return SP->_map_mbe_to_key;
}
/* ncurses mouse interface */
int mouseinterval(int wait)
{
int old_wait;
PDC_LOG(("mouseinterval() - called: %d\n", wait));
old_wait = SP->mouse_wait;
if (wait >= 0 && wait <= 1000)
SP->mouse_wait = wait;
return old_wait;
}
bool wenclose(const WINDOW *win, int y, int x)
{
PDC_LOG(("wenclose() - called: %p %d %d\n", win, y, x));
return (win && y >= win->_begy && y < win->_begy + win->_maxy
&& x >= win->_begx && x < win->_begx + win->_maxx);
}
bool wmouse_trafo(const WINDOW *win, int *y, int *x, bool to_screen)
{
int newy, newx;
PDC_LOG(("wmouse_trafo() - called\n"));
if (!win || !y || !x)
return FALSE;
newy = *y;
newx = *x;
if (to_screen)
{
newy += win->_begy;
newx += win->_begx;
if (!wenclose(win, newy, newx))
return FALSE;
}
else
{
if (wenclose(win, newy, newx))
{
newy -= win->_begy;
newx -= win->_begx;
}
else
return FALSE;
}
*y = newy;
*x = newx;
return TRUE;
}
bool mouse_trafo(int *y, int *x, bool to_screen)
{
PDC_LOG(("mouse_trafo() - called\n"));
return wmouse_trafo(stdscr, y, x, to_screen);
}
mmask_t mousemask(mmask_t mask, mmask_t *oldmask)
{
PDC_LOG(("mousemask() - called\n"));
if (oldmask)
*oldmask = SP->_trap_mbe;
/* The ncurses interface doesn't work with our move events, so
filter them here */
mask &= ~(BUTTON1_MOVED | BUTTON2_MOVED | BUTTON3_MOVED);
mouse_set(mask);
return SP->_trap_mbe;
}
int nc_getmouse(MEVENT *event)
{
int i;
mmask_t bstate = 0;
PDC_LOG(("nc_getmouse() - called\n"));
if (!event)
return ERR;
ungot = FALSE;
request_mouse_pos();
event->id = 0;
event->x = Mouse_status.x;
event->y = Mouse_status.y;
event->z = 0;
for (i = 0; i < 3; i++)
{
if (Mouse_status.changes & (1 << i))
{
int shf = i * 5;
short button = Mouse_status.button[i] & BUTTON_ACTION_MASK;
if (button == BUTTON_RELEASED)
bstate |= (BUTTON1_RELEASED << shf);
else if (button == BUTTON_PRESSED)
bstate |= (BUTTON1_PRESSED << shf);
else if (button == BUTTON_CLICKED)
bstate |= (BUTTON1_CLICKED << shf);
else if (button == BUTTON_DOUBLE_CLICKED)
bstate |= (BUTTON1_DOUBLE_CLICKED << shf);
button = Mouse_status.button[i] & BUTTON_MODIFIER_MASK;
if (button & PDC_BUTTON_SHIFT)
bstate |= BUTTON_MODIFIER_SHIFT;
if (button & PDC_BUTTON_CONTROL)
bstate |= BUTTON_MODIFIER_CONTROL;
if (button & PDC_BUTTON_ALT)
bstate |= BUTTON_MODIFIER_ALT;
}
}
if (MOUSE_WHEEL_UP)
bstate |= BUTTON4_PRESSED;
else if (MOUSE_WHEEL_DOWN)
bstate |= BUTTON5_PRESSED;
/* extra filter pass -- mainly for button modifiers */
event->bstate = bstate & SP->_trap_mbe;
return OK;
}
int ungetmouse(MEVENT *event)
{
int i;
unsigned long bstate;
PDC_LOG(("ungetmouse() - called\n"));
if (!event || ungot)
return ERR;
ungot = TRUE;
pdc_mouse_status.x = event->x;
pdc_mouse_status.y = event->y;
pdc_mouse_status.changes = 0;
bstate = event->bstate;
for (i = 0; i < 3; i++)
{
int shf = i * 5;
short button = 0;
if (bstate & ((BUTTON1_RELEASED | BUTTON1_PRESSED |
BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED) << shf))
{
pdc_mouse_status.changes |= 1 << i;
if (bstate & (BUTTON1_PRESSED << shf))
button = BUTTON_PRESSED;
if (bstate & (BUTTON1_CLICKED << shf))
button = BUTTON_CLICKED;
if (bstate & (BUTTON1_DOUBLE_CLICKED << shf))
button = BUTTON_DOUBLE_CLICKED;
if (bstate & BUTTON_MODIFIER_SHIFT)
button |= PDC_BUTTON_SHIFT;
if (bstate & BUTTON_MODIFIER_CONTROL)
button |= PDC_BUTTON_CONTROL;
if (bstate & BUTTON_MODIFIER_ALT)
button |= PDC_BUTTON_ALT;
}
pdc_mouse_status.button[i] = button;
}
if (bstate & BUTTON4_PRESSED)
pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_UP;
else if (bstate & BUTTON5_PRESSED)
pdc_mouse_status.changes |= PDC_MOUSE_WHEEL_DOWN;
return ungetch(KEY_MOUSE);
}

View File

@@ -0,0 +1,54 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: move.c,v 1.28 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: move
Synopsis:
int move(int y, int x);
int wmove(WINDOW *win, int y, int x);
Description:
The cursor associated with the window is moved to the given
location. This does not move the physical cursor of the
terminal until refresh() is called. The position specified is
relative to the upper left corner of the window, which is (0,0).
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
move Y Y Y
wmove Y Y Y
**man-end****************************************************************/
int move(int y, int x)
{
PDC_LOG(("move() - called: y=%d x=%d\n", y, x));
if (!stdscr || x < 0 || y < 0 || x >= stdscr->_maxx || y >= stdscr->_maxy)
return ERR;
stdscr->_curx = x;
stdscr->_cury = y;
return OK;
}
int wmove(WINDOW *win, int y, int x)
{
PDC_LOG(("wmove() - called: y=%d x=%d\n", y, x));
if (!win || x < 0 || y < 0 || x >= win->_maxx || y >= win->_maxy)
return ERR;
win->_curx = x;
win->_cury = y;
return OK;
}

View File

@@ -0,0 +1,156 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: outopts.c,v 1.39 2008/07/14 12:22:13 wmcbrine Exp $")
/*man-start**************************************************************
Name: outopts
Synopsis:
int clearok(WINDOW *win, bool bf);
int idlok(WINDOW *win, bool bf);
void idcok(WINDOW *win, bool bf);
void immedok(WINDOW *win, bool bf);
int leaveok(WINDOW *win, bool bf);
int setscrreg(int top, int bot);
int wsetscrreg(WINDOW *win, int top, int bot);
int scrollok(WINDOW *win, bool bf);
int raw_output(bool bf);
Description:
With clearok(), if bf is TRUE, the next call to wrefresh() with
this window will clear the screen completely and redraw the
entire screen.
immedok(), called with a second argument of TRUE, causes an
automatic wrefresh() every time a change is made to the
specified window.
Normally, the hardware cursor is left at the location of the
window being refreshed. leaveok() allows the cursor to be
left wherever the update happens to leave it. It's useful
for applications where the cursor is not used, since it reduces
the need for cursor motions. If possible, the cursor is made
invisible when this option is enabled.
wsetscrreg() sets a scrolling region in a window; "top" and
"bot" are the line numbers for the top and bottom margins. If
this option and scrollok() are enabled, any attempt to move off
the bottom margin will cause all lines in the scrolling region
to scroll up one line. setscrreg() is the stdscr version.
idlok() and idcok() do nothing in PDCurses, but are provided for
compatibility with other curses implementations.
raw_output() enables the output of raw characters using the
standard *add* and *ins* curses functions (that is, it disables
translation of control characters).
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
clearok Y Y Y
idlok Y Y Y
idcok Y - 4.0
immedok Y - 4.0
leaveok Y Y Y
setscrreg Y Y Y
wsetscrreg Y Y Y
scrollok Y Y Y
raw_output - - -
**man-end****************************************************************/
int clearok(WINDOW *win, bool bf)
{
PDC_LOG(("clearok() - called\n"));
if (!win)
return ERR;
win->_clear = bf;
return OK;
}
int idlok(WINDOW *win, bool bf)
{
PDC_LOG(("idlok() - called\n"));
return OK;
}
void idcok(WINDOW *win, bool bf)
{
PDC_LOG(("idcok() - called\n"));
}
void immedok(WINDOW *win, bool bf)
{
PDC_LOG(("immedok() - called\n"));
if (win)
win->_immed = bf;
}
int leaveok(WINDOW *win, bool bf)
{
PDC_LOG(("leaveok() - called\n"));
if (!win)
return ERR;
win->_leaveit = bf;
curs_set(!bf);
return OK;
}
int setscrreg(int top, int bottom)
{
PDC_LOG(("setscrreg() - called: top %d bottom %d\n", top, bottom));
return wsetscrreg(stdscr, top, bottom);
}
int wsetscrreg(WINDOW *win, int top, int bottom)
{
PDC_LOG(("wsetscrreg() - called: top %d bottom %d\n", top, bottom));
if (win && 0 <= top && top <= win->_cury &&
win->_cury <= bottom && bottom < win->_maxy)
{
win->_tmarg = top;
win->_bmarg = bottom;
return OK;
}
else
return ERR;
}
int scrollok(WINDOW *win, bool bf)
{
PDC_LOG(("scrollok() - called\n"));
if (!win)
return ERR;
win->_scroll = bf;
return OK;
}
int raw_output(bool bf)
{
PDC_LOG(("raw_output() - called\n"));
SP->raw_out = bf;
return OK;
}

View File

@@ -0,0 +1,256 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: overlay.c,v 1.36 2008/07/14 12:35:23 wmcbrine Exp $")
/*man-start**************************************************************
Name: overlay
Synopsis:
int overlay(const WINDOW *src_w, WINDOW *dst_w)
int overwrite(const WINDOW *src_w, WINDOW *dst_w)
int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr,
int src_tc, int dst_tr, int dst_tc, int dst_br,
int dst_bc, bool overlay)
Description:
overlay() and overwrite() copy all the text from src_w into
dst_w. The windows need not be the same size. Those characters
in the source window that intersect with the destination window
are copied, so that the characters appear in the same physical
position on the screen. The difference between the two functions
is that overlay() is non-destructive (blanks are not copied)
while overwrite() is destructive (blanks are copied).
copywin() is similar, but doesn't require that the two windows
overlap. The arguments src_tc and src_tr specify the top left
corner of the region to be copied. dst_tc, dst_tr, dst_br, and
dst_bc specify the region within the destination window to copy
to. The argument "overlay", if TRUE, indicates that the copy is
done non-destructively (as in overlay()); blanks in the source
window are not copied to the destination window. When overlay is
FALSE, blanks are copied.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
overlay Y Y Y
overwrite Y Y Y
copywin Y - 3.0
**man-end****************************************************************/
/* Thanks to Andreas Otte <venn@@uni-paderborn.de> for the
corrected overlay()/overwrite() behavior. */
static int _copy_win(const WINDOW *src_w, WINDOW *dst_w, int src_tr,
int src_tc, int src_br, int src_bc, int dst_tr,
int dst_tc, bool _overlay)
{
int col, line, y1, fc, *minchng, *maxchng;
chtype *w1ptr, *w2ptr;
int lc = 0;
int xdiff = src_bc - src_tc;
int ydiff = src_br - src_tr;
if (!src_w || !dst_w)
return ERR;
minchng = dst_w->_firstch;
maxchng = dst_w->_lastch;
for (y1 = 0; y1 < dst_tr; y1++)
{
minchng++;
maxchng++;
}
for (line = 0; line < ydiff; line++)
{
w1ptr = src_w->_y[line + src_tr] + src_tc;
w2ptr = dst_w->_y[line + dst_tr] + dst_tc;
fc = _NO_CHANGE;
for (col = 0; col < xdiff; col++)
{
if ((*w1ptr) != (*w2ptr) &&
!((*w1ptr & A_CHARTEXT) == ' ' && _overlay))
{
*w2ptr = *w1ptr;
if (fc == _NO_CHANGE)
fc = col + dst_tc;
lc = col + dst_tc;
}
w1ptr++;
w2ptr++;
}
if (*minchng == _NO_CHANGE)
{
*minchng = fc;
*maxchng = lc;
}
else if (fc != _NO_CHANGE)
{
if (fc < *minchng)
*minchng = fc;
if (lc > *maxchng)
*maxchng = lc;
}
minchng++;
maxchng++;
}
return OK;
}
int overlay(const WINDOW *src_w, WINDOW *dst_w)
{
int first_line, first_col, last_line, last_col;
int src_start_x, src_start_y, dst_start_x, dst_start_y;
int xdiff, ydiff;
PDC_LOG(("overlay() - called\n"));
if (!src_w || !dst_w)
return ERR;
first_col = max(dst_w->_begx, src_w->_begx);
first_line = max(dst_w->_begy, src_w->_begy);
last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx);
last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy);
/* determine the overlapping region of the two windows in real
coordinates */
/* if no overlapping region, do nothing */
if ((last_col < first_col) || (last_line < first_line))
return OK;
/* size of overlapping region */
xdiff = last_col - first_col;
ydiff = last_line - first_line;
if (src_w->_begx <= dst_w->_begx)
{
src_start_x = dst_w->_begx - src_w->_begx;
dst_start_x = 0;
}
else
{
dst_start_x = src_w->_begx - dst_w->_begx;
src_start_x = 0;
}
if (src_w->_begy <= dst_w->_begy)
{
src_start_y = dst_w->_begy - src_w->_begy;
dst_start_y = 0;
}
else
{
dst_start_y = src_w->_begy - dst_w->_begy;
src_start_y = 0;
}
return _copy_win(src_w, dst_w, src_start_y, src_start_x,
src_start_y + ydiff, src_start_x + xdiff,
dst_start_y, dst_start_x, TRUE);
}
int overwrite(const WINDOW *src_w, WINDOW *dst_w)
{
int first_line, first_col, last_line, last_col;
int src_start_x, src_start_y, dst_start_x, dst_start_y;
int xdiff, ydiff;
PDC_LOG(("overwrite() - called\n"));
if (!src_w || !dst_w)
return ERR;
first_col = max(dst_w->_begx, src_w->_begx);
first_line = max(dst_w->_begy, src_w->_begy);
last_col = min(src_w->_begx + src_w->_maxx, dst_w->_begx + dst_w->_maxx);
last_line = min(src_w->_begy + src_w->_maxy, dst_w->_begy + dst_w->_maxy);
/* determine the overlapping region of the two windows in real
coordinates */
/* if no overlapping region, do nothing */
if ((last_col < first_col) || (last_line < first_line))
return OK;
/* size of overlapping region */
xdiff = last_col - first_col;
ydiff = last_line - first_line;
if (src_w->_begx <= dst_w->_begx)
{
src_start_x = dst_w->_begx - src_w->_begx;
dst_start_x = 0;
}
else
{
dst_start_x = src_w->_begx - dst_w->_begx;
src_start_x = 0;
}
if (src_w->_begy <= dst_w->_begy)
{
src_start_y = dst_w->_begy - src_w->_begy;
dst_start_y = 0;
}
else
{
dst_start_y = src_w->_begy - dst_w->_begy;
src_start_y = 0;
}
return _copy_win(src_w, dst_w, src_start_y, src_start_x,
src_start_y + ydiff, src_start_x + xdiff,
dst_start_y, dst_start_x, FALSE);
}
int copywin(const WINDOW *src_w, WINDOW *dst_w, int src_tr, int src_tc,
int dst_tr, int dst_tc, int dst_br, int dst_bc, int _overlay)
{
int src_end_x, src_end_y;
int src_rows, src_cols, dst_rows, dst_cols;
int min_rows, min_cols;
PDC_LOG(("copywin() - called\n"));
if (!src_w || !dst_w || dst_w == curscr || dst_br > dst_w->_maxy
|| dst_bc > dst_w->_maxx || dst_tr < 0 || dst_tc < 0)
return ERR;
src_rows = src_w->_maxy - src_tr;
src_cols = src_w->_maxx - src_tc;
dst_rows = dst_br - dst_tr + 1;
dst_cols = dst_bc - dst_tc + 1;
min_rows = min(src_rows, dst_rows);
min_cols = min(src_cols, dst_cols);
src_end_y = src_tr + min_rows;
src_end_x = src_tc + min_cols;
return _copy_win(src_w, dst_w, src_tr, src_tc, src_end_y, src_end_x,
dst_tr, dst_tc, _overlay);
}

View File

@@ -0,0 +1,259 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: pad.c,v 1.50 2008/07/14 12:22:13 wmcbrine Exp $")
/*man-start**************************************************************
Name: pad
Synopsis:
WINDOW *newpad(int nlines, int ncols);
WINDOW *subpad(WINDOW *orig, int nlines, int ncols,
int begy, int begx);
int prefresh(WINDOW *win, int py, int px, int sy1, int sx1,
int sy2, int sx2);
int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1,
int sy2, int sx2);
int pechochar(WINDOW *pad, chtype ch);
int pecho_wchar(WINDOW *pad, const cchar_t *wch);
Description:
A pad is a special kind of window, which is not restricted by
the screen size, and is not necessarily associated with a
particular part of the screen. You can use a pad when you need
a large window, and only a part of the window will be on the
screen at one time. Pads are not refreshed automatically (e.g.,
from scrolling or echoing of input). You can't call wrefresh()
with a pad as an argument; use prefresh() or pnoutrefresh()
instead. Note that these routines require additional parameters
to specify the part of the pad to be displayed, and the location
to use on the screen.
newpad() creates a new pad data structure.
subpad() creates a new sub-pad within a pad, at position (begy,
begx), with dimensions of nlines lines and ncols columns. This
position is relative to the pad, and not to the screen as with
subwin. Changes to either the parent pad or sub-pad will affect
both. When using sub-pads, you may need to call touchwin()
before calling prefresh().
pnoutrefresh() copies the specified pad to the virtual screen.
prefresh() calls pnoutrefresh(), followed by doupdate().
These routines are analogous to wnoutrefresh() and wrefresh().
(py, px) specifies the upper left corner of the part of the pad
to be displayed; (sy1, sx1) and (sy2, sx2) describe the screen
rectangle that will contain the selected part of the pad.
pechochar() is functionally equivalent to addch() followed by
a call to prefresh(), with the last-used coordinates and
dimensions. pecho_wchar() is the wide-character version.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
newpad Y - Y
subpad Y - Y
prefresh Y - Y
pnoutrefresh Y - Y
pechochar Y - 3.0
pecho_wchar Y
**man-end****************************************************************/
#include <string.h>
/* save values for pechochar() */
static int save_pminrow, save_pmincol;
static int save_sminrow, save_smincol, save_smaxrow, save_smaxcol;
WINDOW *newpad(int nlines, int ncols)
{
WINDOW *win;
PDC_LOG(("newpad() - called: lines=%d cols=%d\n", nlines, ncols));
if ( !(win = PDC_makenew(nlines, ncols, -1, -1))
|| !(win = PDC_makelines(win)) )
return (WINDOW *)NULL;
werase(win);
win->_flags = _PAD;
/* save default values in case pechochar() is the first call to
prefresh(). */
save_pminrow = 0;
save_pmincol = 0;
save_sminrow = 0;
save_smincol = 0;
save_smaxrow = min(LINES, nlines) - 1;
save_smaxcol = min(COLS, ncols) - 1;
return win;
}
WINDOW *subpad(WINDOW *orig, int nlines, int ncols, int begy, int begx)
{
WINDOW *win;
int i;
int j = begy;
int k = begx;
PDC_LOG(("subpad() - called: lines=%d cols=%d begy=%d begx=%d\n",
nlines, ncols, begy, begx));
if (!orig || !(orig->_flags & _PAD))
return (WINDOW *)NULL;
/* make sure window fits inside the original one */
if ((begy < orig->_begy) || (begx < orig->_begx) ||
(begy + nlines) > (orig->_begy + orig->_maxy) ||
(begx + ncols) > (orig->_begx + orig->_maxx))
return (WINDOW *)NULL;
if (!nlines)
nlines = orig->_maxy - 1 - j;
if (!ncols)
ncols = orig->_maxx - 1 - k;
if ( !(win = PDC_makenew(nlines, ncols, begy, begx)) )
return (WINDOW *)NULL;
/* initialize window variables */
win->_attrs = orig->_attrs;
win->_leaveit = orig->_leaveit;
win->_scroll = orig->_scroll;
win->_nodelay = orig->_nodelay;
win->_use_keypad = orig->_use_keypad;
win->_parent = orig;
for (i = 0; i < nlines; i++)
win->_y[i] = (orig->_y[j++]) + k;
win->_flags = _SUBPAD;
/* save default values in case pechochar() is the first call
to prefresh(). */
save_pminrow = 0;
save_pmincol = 0;
save_sminrow = 0;
save_smincol = 0;
save_smaxrow = min(LINES, nlines) - 1;
save_smaxcol = min(COLS, ncols) - 1;
return win;
}
int prefresh(WINDOW *win, int py, int px, int sy1, int sx1, int sy2, int sx2)
{
PDC_LOG(("prefresh() - called\n"));
if (pnoutrefresh(win, py, px, sy1, sx1, sy2, sx2) == ERR)
return ERR;
doupdate();
return OK;
}
int pnoutrefresh(WINDOW *w, int py, int px, int sy1, int sx1, int sy2, int sx2)
{
int num_cols;
int sline = sy1;
int pline = py;
PDC_LOG(("pnoutrefresh() - called\n"));
if (!w || !(w->_flags & (_PAD|_SUBPAD)) || (sy2 >= LINES) || (sy2 >= COLS))
return ERR;
if (py < 0)
py = 0;
if (px < 0)
px = 0;
if (sy1 < 0)
sy1 = 0;
if (sx1 < 0)
sx1 = 0;
if (sy2 < sy1 || sx2 < sx1)
return ERR;
num_cols = min((sx2 - sx1 + 1), (w->_maxx - px));
while (sline <= sy2)
{
if (pline < w->_maxy)
{
memcpy(curscr->_y[sline] + sx1, w->_y[pline] + px,
num_cols * sizeof(chtype));
if ((curscr->_firstch[sline] == _NO_CHANGE)
|| (curscr->_firstch[sline] > sx1))
curscr->_firstch[sline] = sx1;
if (sx2 > curscr->_lastch[sline])
curscr->_lastch[sline] = sx2;
w->_firstch[pline] = _NO_CHANGE; /* updated now */
w->_lastch[pline] = _NO_CHANGE; /* updated now */
}
sline++;
pline++;
}
if (w->_clear)
{
w->_clear = FALSE;
curscr->_clear = TRUE;
}
/* position the cursor to the pad's current position if possible --
is the pad current position going to end up displayed? if not,
then don't move the cursor; if so, move it to the correct place */
if (!w->_leaveit && w->_cury >= py && w->_curx >= px &&
w->_cury <= py + (sy2 - sy1) && w->_curx <= px + (sx2 - sx1))
{
curscr->_cury = (w->_cury - py) + sy1;
curscr->_curx = (w->_curx - px) + sx1;
}
return OK;
}
int pechochar(WINDOW *pad, chtype ch)
{
PDC_LOG(("pechochar() - called\n"));
if (waddch(pad, ch) == ERR)
return ERR;
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
save_smincol, save_smaxrow, save_smaxcol);
}
#ifdef PDC_WIDE
int pecho_wchar(WINDOW *pad, const cchar_t *wch)
{
PDC_LOG(("pecho_wchar() - called\n"));
if (!wch || (waddch(pad, *wch) == ERR))
return ERR;
return prefresh(pad, save_pminrow, save_pmincol, save_sminrow,
save_smincol, save_smaxrow, save_smaxcol);
}
#endif

View File

@@ -0,0 +1,630 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: panel.c,v 1.8 2008/07/14 12:35:23 wmcbrine Exp $")
/*man-start**************************************************************
Name: panel
Synopsis:
int bottom_panel(PANEL *pan);
int del_panel(PANEL *pan);
int hide_panel(PANEL *pan);
int move_panel(PANEL *pan, int starty, int startx);
PANEL *new_panel(WINDOW *win);
PANEL *panel_above(const PANEL *pan);
PANEL *panel_below(const PANEL *pan);
int panel_hidden(const PANEL *pan);
const void *panel_userptr(const PANEL *pan);
WINDOW *panel_window(const PANEL *pan);
int replace_panel(PANEL *pan, WINDOW *win);
int set_panel_userptr(PANEL *pan, const void *uptr);
int show_panel(PANEL *pan);
int top_panel(PANEL *pan);
void update_panels(void);
Description:
The panel library is built using the curses library, and any
program using panels routines must call one of the curses
initialization routines such as initscr(). A program using these
routines must be linked with the panels and curses libraries.
The header <panel.h> includes the header <curses.h>.
The panels package gives the applications programmer a way to
have depth relationships between curses windows; a curses window
is associated with every panel. The panels routines allow curses
windows to overlap without making visible the overlapped
portions of underlying windows. The initial curses window,
stdscr, lies beneath all panels. The set of currently visible
panels is the 'deck' of panels.
The panels package allows the applications programmer to create
panels, fetch and set their associated windows, shuffle panels
in the deck, and manipulate panels in other ways.
bottom_panel() places pan at the bottom of the deck. The size,
location and contents of the panel are unchanged.
del_panel() deletes pan, but not its associated winwow.
hide_panel() removes a panel from the deck and thus hides it
from view.
move_panel() moves the curses window associated with pan, so
that its upper lefthand corner is at the supplied coordinates.
(Do not use mvwin() on the window.)
new_panel() creates a new panel associated with win and returns
the panel pointer. The new panel is placed at the top of the
deck.
panel_above() returns a pointer to the panel in the deck above
pan, or NULL if pan is the top panel. If the value of pan passed
is NULL, this function returns a pointer to the bottom panel in
the deck.
panel_below() returns a pointer to the panel in the deck below
pan, or NULL if pan is the bottom panel. If the value of pan
passed is NULL, this function returns a pointer to the top panel
in the deck.
panel_hidden() returns OK if pan is hidden and ERR if it is not.
panel_userptr() - Each panel has a user pointer available for
maintaining relevant information. This function returns a
pointer to that information previously set up by
set_panel_userptr().
panel_window() returns a pointer to the curses window associated
with the panel.
replace_panel() replaces the current window of pan with win.
set_panel_userptr() - Each panel has a user pointer available
for maintaining relevant information. This function sets the
value of that information.
show_panel() makes a previously hidden panel visible and places
it back in the deck on top.
top_panel() places pan on the top of the deck. The size,
location and contents of the panel are unchanged.
update_panels() refreshes the virtual screen to reflect the
depth relationships between the panels in the deck. The user
must use doupdate() to refresh the physical screen.
Return Value:
Each routine that returns a pointer to an object returns NULL if
an error occurs. Each panel routine that returns an integer,
returns OK if it executes successfully and ERR if it does not.
Portability X/Open BSD SYS V
bottom_panel - - Y
del_panel - - Y
hide_panel - - Y
move_panel - - Y
new_panel - - Y
panel_above - - Y
panel_below - - Y
panel_hidden - - Y
panel_userptr - - Y
panel_window - - Y
replace_panel - - Y
set_panel_userptr - - Y
show_panel - - Y
top_panel - - Y
update_panels - - Y
Credits:
Original Author - Warren Tucker <wht@n4hgf.mt-park.ga.us>
**man-end****************************************************************/
#include <panel.h>
#include <stdlib.h>
PANEL *_bottom_panel = (PANEL *)0;
PANEL *_top_panel = (PANEL *)0;
PANEL _stdscr_pseudo_panel = { (WINDOW *)0 };
#ifdef PANEL_DEBUG
static void dPanel(char *text, PANEL *pan)
{
PDC_LOG(("%s id=%s b=%s a=%s y=%d x=%d", text, pan->user,
pan->below ? pan->below->user : "--",
pan->above ? pan->above->user : "--",
pan->wstarty, pan->wstartx));
}
static void dStack(char *fmt, int num, PANEL *pan)
{
char s80[80];
sprintf(s80, fmt, num, pan);
PDC_LOG(("%s b=%s t=%s", s80, _bottom_panel ? _bottom_panel->user : "--",
_top_panel ? _top_panel->user : "--"));
if (pan)
PDC_LOG(("pan id=%s", pan->user));
pan = _bottom_panel;
while (pan)
{
dPanel("stk", pan);
pan = pan->above;
}
}
/* debugging hook for wnoutrefresh */
static void Wnoutrefresh(PANEL *pan)
{
dPanel("wnoutrefresh", pan);
wnoutrefresh(pan->win);
}
static void Touchpan(PANEL *pan)
{
dPanel("Touchpan", pan);
touchwin(pan->win);
}
static void Touchline(PANEL *pan, int start, int count)
{
char s80[80];
sprintf(s80, "Touchline s=%d c=%d", start, count);
dPanel(s80, pan);
touchline(pan->win, start, count);
}
#else /* PANEL_DEBUG */
#define dPanel(text, pan)
#define dStack(fmt, num, pan)
#define Wnoutrefresh(pan) wnoutrefresh((pan)->win)
#define Touchpan(pan) touchwin((pan)->win)
#define Touchline(pan, start, count) touchline((pan)->win, start, count)
#endif /* PANEL_DEBUG */
static bool _panels_overlapped(PANEL *pan1, PANEL *pan2)
{
if (!pan1 || !pan2)
return FALSE;
return ((pan1->wstarty >= pan2->wstarty && pan1->wstarty < pan2->wendy)
|| (pan2->wstarty >= pan1->wstarty && pan2->wstarty < pan1->wendy))
&& ((pan1->wstartx >= pan2->wstartx && pan1->wstartx < pan2->wendx)
|| (pan2->wstartx >= pan1->wstartx && pan2->wstartx < pan1->wendx));
}
static void _free_obscure(PANEL *pan)
{
PANELOBS *tobs = pan->obscure; /* "this" one */
PANELOBS *nobs; /* "next" one */
while (tobs)
{
nobs = tobs->above;
free((char *)tobs);
tobs = nobs;
}
pan->obscure = (PANELOBS *)0;
}
static void _override(PANEL *pan, int show)
{
int y;
PANEL *pan2;
PANELOBS *tobs = pan->obscure; /* "this" one */
if (show == 1)
Touchpan(pan);
else if (!show)
{
Touchpan(pan);
Touchpan(&_stdscr_pseudo_panel);
}
else if (show == -1)
while (tobs && (tobs->pan != pan))
tobs = tobs->above;
while (tobs)
{
if ((pan2 = tobs->pan) != pan)
for (y = pan->wstarty; y < pan->wendy; y++)
if ((y >= pan2->wstarty) && (y < pan2->wendy) &&
((is_linetouched(pan->win, y - pan->wstarty)) ||
(is_linetouched(stdscr, y))))
Touchline(pan2, y - pan2->wstarty, 1);
tobs = tobs->above;
}
}
static void _calculate_obscure(void)
{
PANEL *pan, *pan2;
PANELOBS *tobs; /* "this" one */
PANELOBS *lobs; /* last one */
pan = _bottom_panel;
while (pan)
{
if (pan->obscure)
_free_obscure(pan);
lobs = (PANELOBS *)0;
pan2 = _bottom_panel;
while (pan2)
{
if (_panels_overlapped(pan, pan2))
{
if ((tobs = malloc(sizeof(PANELOBS))) == NULL)
return;
tobs->pan = pan2;
dPanel("obscured", pan2);
tobs->above = (PANELOBS *)0;
if (lobs)
lobs->above = tobs;
else
pan->obscure = tobs;
lobs = tobs;
}
pan2 = pan2->above;
}
_override(pan, 1);
pan = pan->above;
}
}
/* check to see if panel is in the stack */
static bool _panel_is_linked(const PANEL *pan)
{
PANEL *pan2 = _bottom_panel;
while (pan2)
{
if (pan2 == pan)
return TRUE;
pan2 = pan2->above;
}
return FALSE;
}
/* link panel into stack at top */
static void _panel_link_top(PANEL *pan)
{
#ifdef PANEL_DEBUG
dStack("<lt%d>", 1, pan);
if (_panel_is_linked(pan))
return;
#endif
pan->above = (PANEL *)0;
pan->below = (PANEL *)0;
if (_top_panel)
{
_top_panel->above = pan;
pan->below = _top_panel;
}
_top_panel = pan;
if (!_bottom_panel)
_bottom_panel = pan;
_calculate_obscure();
dStack("<lt%d>", 9, pan);
}
/* link panel into stack at bottom */
static void _panel_link_bottom(PANEL *pan)
{
#ifdef PANEL_DEBUG
dStack("<lb%d>", 1, pan);
if (_panel_is_linked(pan))
return;
#endif
pan->above = (PANEL *)0;
pan->below = (PANEL *)0;
if (_bottom_panel)
{
_bottom_panel->below = pan;
pan->above = _bottom_panel;
}
_bottom_panel = pan;
if (!_top_panel)
_top_panel = pan;
_calculate_obscure();
dStack("<lb%d>", 9, pan);
}
static void _panel_unlink(PANEL *pan)
{
PANEL *prev;
PANEL *next;
#ifdef PANEL_DEBUG
dStack("<u%d>", 1, pan);
if (!_panel_is_linked(pan))
return;
#endif
_override(pan, 0);
_free_obscure(pan);
prev = pan->below;
next = pan->above;
/* if non-zero, we will not update the list head */
if (prev)
{
prev->above = next;
if(next)
next->below = prev;
}
else if (next)
next->below = prev;
if (pan == _bottom_panel)
_bottom_panel = next;
if (pan == _top_panel)
_top_panel = prev;
_calculate_obscure();
pan->above = (PANEL *)0;
pan->below = (PANEL *)0;
dStack("<u%d>", 9, pan);
}
/************************************************************************
* The following are the public functions for the panels library. *
************************************************************************/
int bottom_panel(PANEL *pan)
{
if (!pan)
return ERR;
if (pan == _bottom_panel)
return OK;
if (_panel_is_linked(pan))
hide_panel(pan);
_panel_link_bottom(pan);
return OK;
}
int del_panel(PANEL *pan)
{
if (pan)
{
if (_panel_is_linked(pan))
hide_panel(pan);
free((char *)pan);
return OK;
}
return ERR;
}
int hide_panel(PANEL *pan)
{
if (!pan)
return ERR;
if (!_panel_is_linked(pan))
{
pan->above = (PANEL *)0;
pan->below = (PANEL *)0;
return ERR;
}
_panel_unlink(pan);
return OK;
}
int move_panel(PANEL *pan, int starty, int startx)
{
WINDOW *win;
int maxy, maxx;
if (!pan)
return ERR;
if (_panel_is_linked(pan))
_override(pan, 0);
win = pan->win;
if (mvwin(win, starty, startx) == ERR)
return ERR;
getbegyx(win, pan->wstarty, pan->wstartx);
getmaxyx(win, maxy, maxx);
pan->wendy = pan->wstarty + maxy;
pan->wendx = pan->wstartx + maxx;
if (_panel_is_linked(pan))
_calculate_obscure();
return OK;
}
PANEL *new_panel(WINDOW *win)
{
PANEL *pan = malloc(sizeof(PANEL));
if (!_stdscr_pseudo_panel.win)
{
_stdscr_pseudo_panel.win = stdscr;
_stdscr_pseudo_panel.wstarty = 0;
_stdscr_pseudo_panel.wstartx = 0;
_stdscr_pseudo_panel.wendy = LINES;
_stdscr_pseudo_panel.wendx = COLS;
_stdscr_pseudo_panel.user = "stdscr";
_stdscr_pseudo_panel.obscure = (PANELOBS *)0;
}
if (pan)
{
int maxy, maxx;
pan->win = win;
pan->above = (PANEL *)0;
pan->below = (PANEL *)0;
getbegyx(win, pan->wstarty, pan->wstartx);
getmaxyx(win, maxy, maxx);
pan->wendy = pan->wstarty + maxy;
pan->wendx = pan->wstartx + maxx;
#ifdef PANEL_DEBUG
pan->user = "new";
#else
pan->user = (char *)0;
#endif
pan->obscure = (PANELOBS *)0;
show_panel(pan);
}
return pan;
}
PANEL *panel_above(const PANEL *pan)
{
return pan ? pan->above : _bottom_panel;
}
PANEL *panel_below(const PANEL *pan)
{
return pan ? pan->below : _top_panel;
}
int panel_hidden(const PANEL *pan)
{
if (!pan)
return ERR;
return _panel_is_linked(pan) ? ERR : OK;
}
const void *panel_userptr(const PANEL *pan)
{
return pan ? pan->user : NULL;
}
WINDOW *panel_window(const PANEL *pan)
{
PDC_LOG(("panel_window() - called\n"));
return pan->win;
}
int replace_panel(PANEL *pan, WINDOW *win)
{
int maxy, maxx;
if (!pan)
return ERR;
if (_panel_is_linked(pan))
_override(pan, 0);
pan->win = win;
getbegyx(win, pan->wstarty, pan->wstartx);
getmaxyx(win, maxy, maxx);
pan->wendy = pan->wstarty + maxy;
pan->wendx = pan->wstartx + maxx;
if (_panel_is_linked(pan))
_calculate_obscure();
return OK;
}
int set_panel_userptr(PANEL *pan, const void *uptr)
{
if (!pan)
return ERR;
pan->user = uptr;
return OK;
}
int show_panel(PANEL *pan)
{
if (!pan)
return ERR;
if (pan == _top_panel)
return OK;
if (_panel_is_linked(pan))
hide_panel(pan);
_panel_link_top(pan);
return OK;
}
int top_panel(PANEL *pan)
{
return show_panel(pan);
}
void update_panels(void)
{
PANEL *pan;
PDC_LOG(("update_panels() - called\n"));
pan = _bottom_panel;
while (pan)
{
_override(pan, -1);
pan = pan->above;
}
if (is_wintouched(stdscr))
Wnoutrefresh(&_stdscr_pseudo_panel);
pan = _bottom_panel;
while (pan)
{
if (is_wintouched(pan->win) || !pan->above)
Wnoutrefresh(pan);
pan = pan->above;
}
}

View File

@@ -0,0 +1,123 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: printw.c,v 1.40 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: printw
Synopsis:
int printw(const char *fmt, ...);
int wprintw(WINDOW *win, const char *fmt, ...);
int mvprintw(int y, int x, const char *fmt, ...);
int mvwprintw(WINDOW *win, int y, int x, const char *fmt,...);
int vwprintw(WINDOW *win, const char *fmt, va_list varglist);
int vw_printw(WINDOW *win, const char *fmt, va_list varglist);
Description:
The printw() functions add a formatted string to the window at
the current or specified cursor position. The format strings are
the same as used in the standard C library's printf(). (printw()
can be used as a drop-in replacement for printf().)
Return Value:
All functions return the number of characters printed, or
ERR on error.
Portability X/Open BSD SYS V
printw Y Y Y
wprintw Y Y Y
mvprintw Y Y Y
mvwprintw Y Y Y
vwprintw Y - 4.0
vw_printw Y
**man-end****************************************************************/
#include <string.h>
int vwprintw(WINDOW *win, const char *fmt, va_list varglist)
{
char printbuf[513];
int len;
PDC_LOG(("vwprintw() - called\n"));
#ifdef HAVE_VSNPRINTF
len = vsnprintf(printbuf, 512, fmt, varglist);
#else
len = vsprintf(printbuf, fmt, varglist);
#endif
return (waddstr(win, printbuf) == ERR) ? ERR : len;
}
int printw(const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("printw() - called\n"));
va_start(args, fmt);
retval = vwprintw(stdscr, fmt, args);
va_end(args);
return retval;
}
int wprintw(WINDOW *win, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("wprintw() - called\n"));
va_start(args, fmt);
retval = vwprintw(win, fmt, args);
va_end(args);
return retval;
}
int mvprintw(int y, int x, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("mvprintw() - called\n"));
if (move(y, x) == ERR)
return ERR;
va_start(args, fmt);
retval = vwprintw(stdscr, fmt, args);
va_end(args);
return retval;
}
int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("mvwprintw() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
va_start(args, fmt);
retval = vwprintw(win, fmt, args);
va_end(args);
return retval;
}
int vw_printw(WINDOW *win, const char *fmt, va_list varglist)
{
PDC_LOG(("vw_printw() - called\n"));
return vwprintw(win, fmt, varglist);
}

View File

@@ -0,0 +1,276 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: refresh.c,v 1.56 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: refresh
Synopsis:
int refresh(void);
int wrefresh(WINDOW *win);
int wnoutrefresh(WINDOW *win);
int doupdate(void);
int redrawwin(WINDOW *win);
int wredrawln(WINDOW *win, int beg_line, int num_lines);
Description:
wrefresh() copies the named window to the physical terminal
screen, taking into account what is already there in order to
optimize cursor movement. refresh() does the same, using stdscr.
These routines must be called to get any output on the terminal,
as other routines only manipulate data structures. Unless
leaveok() has been enabled, the physical cursor of the terminal
is left at the location of the window's cursor.
wnoutrefresh() and doupdate() allow multiple updates with more
efficiency than wrefresh() alone. wrefresh() works by first
calling wnoutrefresh(), which copies the named window to the
virtual screen. It then calls doupdate(), which compares the
virtual screen to the physical screen and does the actual
update. A series of calls to wrefresh() will result in
alternating calls to wnoutrefresh() and doupdate(), causing
several bursts of output to the screen. By first calling
wnoutrefresh() for each window, it is then possible to call
doupdate() only once.
In PDCurses, redrawwin() is equivalent to touchwin(), and
wredrawln() is the same as touchline(). In some other curses
implementations, there's a subtle distinction, but it has no
meaning in PDCurses.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
refresh Y Y Y
wrefresh Y Y Y
wnoutrefresh Y Y Y
doupdate Y Y Y
redrawwin Y - 4.0
wredrawln Y - 4.0
**man-end****************************************************************/
#include <string.h>
int wnoutrefresh(WINDOW *win)
{
int begy, begx; /* window's place on screen */
int i, j;
PDC_LOG(("wnoutrefresh() - called: win=%p\n", win));
if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
return ERR;
begy = win->_begy;
begx = win->_begx;
for (i = 0, j = begy; i < win->_maxy; i++, j++)
{
if (win->_firstch[i] != _NO_CHANGE)
{
chtype *src = win->_y[i];
chtype *dest = curscr->_y[j] + begx;
int first = win->_firstch[i]; /* first changed */
int last = win->_lastch[i]; /* last changed */
/* ignore areas on the outside that are marked as changed,
but really aren't */
while (first <= last && src[first] == dest[first])
first++;
while (last >= first && src[last] == dest[last])
last--;
/* if any have really changed... */
if (first <= last)
{
memcpy(dest + first, src + first,
(last - first + 1) * sizeof(chtype));
first += begx;
last += begx;
if (first < curscr->_firstch[j] ||
curscr->_firstch[j] == _NO_CHANGE)
curscr->_firstch[j] = first;
if (last > curscr->_lastch[j])
curscr->_lastch[j] = last;
}
win->_firstch[i] = _NO_CHANGE; /* updated now */
}
win->_lastch[i] = _NO_CHANGE; /* updated now */
}
if (win->_clear)
win->_clear = FALSE;
if (!win->_leaveit)
{
curscr->_cury = win->_cury + begy;
curscr->_curx = win->_curx + begx;
}
return OK;
}
int doupdate(void)
{
int y;
bool clearall;
PDC_LOG(("doupdate() - called\n"));
if (!curscr)
return ERR;
if (isendwin()) /* coming back after endwin() called */
{
reset_prog_mode();
clearall = TRUE;
SP->alive = TRUE; /* so isendwin() result is correct */
}
else
clearall = curscr->_clear;
for (y = 0; y < SP->lines; y++)
{
PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n",
y, SP->lines, (curscr->_firstch[y] != _NO_CHANGE) ?
"Yes" : "No"));
if (clearall || curscr->_firstch[y] != _NO_CHANGE)
{
int first, last;
chtype *src = curscr->_y[y];
chtype *dest = pdc_lastscr->_y[y];
if (clearall)
{
first = 0;
last = COLS - 1;
}
else
{
first = curscr->_firstch[y];
last = curscr->_lastch[y];
}
while (first <= last)
{
int len = 0;
/* build up a run of changed cells; if two runs are
separated by a single unchanged cell, ignore the
break */
if (clearall)
len = last - first + 1;
else
while (first + len <= last &&
(src[first + len] != dest[first + len] ||
(len && first + len < last &&
src[first + len + 1] != dest[first + len + 1])
)
)
len++;
/* update the screen, and pdc_lastscr */
if (len)
{
PDC_transform_line(y, first, len, src + first);
memcpy(dest + first, src + first, len * sizeof(chtype));
first += len;
}
/* skip over runs of unchanged cells */
while (first <= last && src[first] == dest[first])
first++;
}
curscr->_firstch[y] = _NO_CHANGE;
curscr->_lastch[y] = _NO_CHANGE;
}
}
curscr->_clear = FALSE;
if (SP->visibility)
PDC_gotoyx(curscr->_cury, curscr->_curx);
SP->cursrow = curscr->_cury;
SP->curscol = curscr->_curx;
return OK;
}
int wrefresh(WINDOW *win)
{
bool save_clear;
PDC_LOG(("wrefresh() - called\n"));
if ( !win || (win->_flags & (_PAD|_SUBPAD)) )
return ERR;
save_clear = win->_clear;
if (win == curscr)
curscr->_clear = TRUE;
else
wnoutrefresh(win);
if (save_clear && win->_maxy == SP->lines && win->_maxx == SP->cols)
curscr->_clear = TRUE;
return doupdate();
}
int refresh(void)
{
PDC_LOG(("refresh() - called\n"));
return wrefresh(stdscr);
}
int wredrawln(WINDOW *win, int start, int num)
{
int i;
PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n",
win, start, num));
if (!win || start > win->_maxy || start + num > win->_maxy)
return ERR;
for (i = start; i < start + num; i++)
{
win->_firstch[i] = 0;
win->_lastch[i] = win->_maxx - 1;
}
return OK;
}
int redrawwin(WINDOW *win)
{
PDC_LOG(("redrawwin() - called: win=%p\n", win));
if (!win)
return ERR;
return wredrawln(win, 0, win->_maxy);
}

View File

@@ -0,0 +1,575 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: scanw.c,v 1.42 2008/07/14 12:22:13 wmcbrine Exp $")
/*man-start**************************************************************
Name: scanw
Synopsis:
int scanw(const char *fmt, ...);
int wscanw(WINDOW *win, const char *fmt, ...);
int mvscanw(int y, int x, const char *fmt, ...);
int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...);
int vwscanw(WINDOW *win, const char *fmt, va_list varglist);
int vw_scanw(WINDOW *win, const char *fmt, va_list varglist);
Description:
These routines correspond to the standard C library's scanf()
family. Each gets a string from the window via wgetnstr(), and
uses the resulting line as input for the scan.
Return Value:
On successful completion, these functions return the number of
items successfully matched. Otherwise they return ERR.
Portability X/Open BSD SYS V
scanw Y Y Y
wscanw Y Y Y
mvscanw Y Y Y
mvwscanw Y Y Y
vwscanw Y - 4.0
vw_scanw Y
**man-end****************************************************************/
#include <string.h>
#ifndef HAVE_VSSCANF
# include <stdlib.h>
# include <ctype.h>
# include <limits.h>
static int _pdc_vsscanf(const char *, const char *, va_list);
# define vsscanf _pdc_vsscanf
#endif
int vwscanw(WINDOW *win, const char *fmt, va_list varglist)
{
char scanbuf[256];
PDC_LOG(("vwscanw() - called\n"));
if (wgetnstr(win, scanbuf, 255) == ERR)
return ERR;
return vsscanf(scanbuf, fmt, varglist);
}
int scanw(const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("scanw() - called\n"));
va_start(args, fmt);
retval = vwscanw(stdscr, fmt, args);
va_end(args);
return retval;
}
int wscanw(WINDOW *win, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("wscanw() - called\n"));
va_start(args, fmt);
retval = vwscanw(win, fmt, args);
va_end(args);
return retval;
}
int mvscanw(int y, int x, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("mvscanw() - called\n"));
if (move(y, x) == ERR)
return ERR;
va_start(args, fmt);
retval = vwscanw(stdscr, fmt, args);
va_end(args);
return retval;
}
int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
{
va_list args;
int retval;
PDC_LOG(("mvscanw() - called\n"));
if (wmove(win, y, x) == ERR)
return ERR;
va_start(args, fmt);
retval = vwscanw(win, fmt, args);
va_end(args);
return retval;
}
int vw_scanw(WINDOW *win, const char *fmt, va_list varglist)
{
PDC_LOG(("vw_scanw() - called\n"));
return vwscanw(win, fmt, varglist);
}
#ifndef HAVE_VSSCANF
/* _pdc_vsscanf() - Internal routine to parse and format an input
buffer. It scans a series of input fields; each field is formatted
according to a supplied format string and the formatted input is
stored in the variable number of addresses passed. Returns the number
of input fields or EOF on error.
Don't compile this unless required. Some compilers (at least Borland
C++ 3.0) have to link with math libraries due to the use of floats.
Based on vsscanf.c and input.c from emx 0.8f library source,
Copyright (c) 1990-1992 by Eberhard Mattes, who has kindly agreed to
its inclusion in PDCurses. */
#define WHITE(x) ((x) == ' ' || (x) == '\t' || (x) == '\n')
#define NEXT(x) \
do { \
x = *buf++; \
if (!x) \
return (count ? count : EOF); \
++chars; \
} while (0)
#define UNGETC() \
do { \
--buf; --chars; \
} while (0)
static int _pdc_vsscanf(const char *buf, const char *fmt, va_list arg_ptr)
{
int count, chars, c, width, radix, d, i;
int *int_ptr;
long *long_ptr;
short *short_ptr;
char *char_ptr;
unsigned char f;
char neg, assign, ok, size;
long n;
char map[256], end;
double dx, dd, *dbl_ptr;
float *flt_ptr;
int exp;
char eneg;
count = 0;
chars = 0;
c = 0;
while ((f = *fmt) != 0)
{
if (WHITE(f))
{
do
{
++fmt;
f = *fmt;
}
while (WHITE(f));
do
{
c = *buf++;
if (!c)
{
if (!f || count)
return count;
else
return EOF;
} else
++chars;
}
while (WHITE(c));
UNGETC();
} else if (f != '%')
{
NEXT(c);
if (c != f)
return count;
++fmt;
} else
{
assign = TRUE;
width = INT_MAX;
char_ptr = NULL;
++fmt;
if (*fmt == '*')
{
assign = FALSE;
++fmt;
}
if (isdigit(*fmt))
{
width = 0;
while (isdigit(*fmt))
width = width * 10 + (*fmt++ - '0');
if (!width)
width = INT_MAX;
}
size = 0;
if (*fmt == 'h' || *fmt == 'l')
size = *fmt++;
f = *fmt;
switch (f)
{
case 'c':
if (width == INT_MAX)
width = 1;
if (assign)
char_ptr = va_arg(arg_ptr, char *);
while (width > 0)
{
--width;
NEXT(c);
if (assign)
{
*char_ptr++ = (char) c;
++count;
}
}
break;
case '[':
memset(map, 0, 256);
end = 0;
++fmt;
if (*fmt == '^')
{
++fmt;
end = 1;
}
i = 0;
for (;;)
{
f = (unsigned char) *fmt;
switch (f)
{
case 0:
/* avoid skipping past 0 */
--fmt;
NEXT(c);
goto string;
case ']':
if (i > 0)
{
NEXT(c);
goto string;
}
/* no break */
default:
if (fmt[1] == '-' && fmt[2]
&& f < (unsigned char)fmt[2])
{
memset(map + f, 1, (unsigned char)fmt[2] - f);
fmt += 2;
}
else
map[f] = 1;
break;
}
++fmt;
++i;
}
case 's':
memset(map, 0, 256);
map[' '] = 1;
map['\n'] = 1;
map['\r'] = 1;
map['\t'] = 1;
end = 1;
do
{
NEXT(c);
}
while (WHITE(c));
string:
if (assign)
char_ptr = va_arg(arg_ptr, char *);
while (width > 0 && map[(unsigned char) c] != end)
{
--width;
if (assign)
*char_ptr++ = (char) c;
c = *buf++;
if (!c)
break;
else
++chars;
}
if (assign)
{
*char_ptr = 0;
++count;
}
if (!c)
return count;
else
UNGETC();
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
neg = ok = FALSE;
dx = 0.0;
do
{
NEXT(c);
}
while (WHITE(c));
if (c == '+')
{
NEXT(c);
--width;
} else if (c == '-')
{
neg = TRUE;
NEXT(c);
--width;
}
while (width > 0 && isdigit(c))
{
--width;
dx = dx * 10.0 + (double) (c - '0');
ok = TRUE;
c = *buf++;
if (!c)
break;
else
++chars;
}
if (width > 0 && c == '.')
{
--width;
dd = 10.0;
NEXT(c);
while (width > 0 && isdigit(c))
{
--width;
dx += (double) (c - '0') / dd;
dd *= 10.0;
ok = TRUE;
c = *buf++;
if (!c)
break;
else
++chars;
}
}
if (!ok)
return count;
if (width > 0 && (c == 'e' || c == 'E'))
{
eneg = FALSE;
exp = 0;
NEXT(c);
--width;
if (width > 0 && c == '+')
{
NEXT(c);
--width;
} else if (width > 0 && c == '-')
{
eneg = TRUE;
NEXT(c);
--width;
}
if (!(width > 0 && isdigit(c)))
{
UNGETC();
return count;
}
while (width > 0 && isdigit(c))
{
--width;
exp = exp * 10 + (c - '0');
c = *buf++;
if (!c)
break;
else
++chars;
}
if (eneg)
exp = -exp;
while (exp > 0)
{
dx *= 10.0;
--exp;
}
while (exp < 0)
{
dx /= 10.0;
++exp;
}
}
if (assign)
{
if (neg)
dx = -dx;
if (size == 'l')
{
dbl_ptr = va_arg(arg_ptr, double *);
*dbl_ptr = dx;
}
else
{
flt_ptr = va_arg(arg_ptr, float *);
*flt_ptr = (float)dx;
}
++count;
}
if (!c)
return count;
else
UNGETC();
break;
case 'i':
neg = FALSE;
radix = 10;
do
{
NEXT(c);
}
while (WHITE(c));
if (!(width > 0 && c == '0'))
goto scan_complete_number;
NEXT(c);
--width;
if (width > 0 && (c == 'x' || c == 'X'))
{
NEXT(c);
radix = 16;
--width;
}
else if (width > 0 && (c >= '0' && c <= '7'))
radix = 8;
goto scan_unsigned_number;
case 'd':
case 'u':
case 'o':
case 'x':
case 'X':
do
{
NEXT(c);
}
while (WHITE(c));
switch (f)
{
case 'o':
radix = 8;
break;
case 'x':
case 'X':
radix = 16;
break;
default:
radix = 10;
break;
}
scan_complete_number:
neg = FALSE;
if (width > 0 && c == '+')
{
NEXT(c);
--width;
}
else if (width > 0 && c == '-' && radix == 10)
{
neg = TRUE;
NEXT(c);
--width;
}
scan_unsigned_number:
n = 0;
ok = FALSE;
while (width > 0)
{
--width;
if (isdigit(c))
d = c - '0';
else if (isupper(c))
d = c - 'A' + 10;
else if (islower(c))
d = c - 'a' + 10;
else
break;
if (d < 0 || d >= radix)
break;
ok = TRUE;
n = n * radix + d;
c = *buf++;
if (!c)
break;
else
++chars;
}
if (!ok)
return count;
if (assign)
{
if (neg)
n = -n;
switch (size)
{
case 'h':
short_ptr = va_arg(arg_ptr, short *);
*short_ptr = (short) n;
break;
case 'l':
long_ptr = va_arg(arg_ptr, long *);
*long_ptr = (long) n;
break;
default:
int_ptr = va_arg(arg_ptr, int *);
*int_ptr = (int) n;
}
++count;
}
if (!c)
return count;
else
UNGETC();
break;
case 'n':
if (assign)
{
int_ptr = va_arg(arg_ptr, int *);
*int_ptr = chars;
++count;
}
break;
default:
if (!f) /* % at end of string */
return count;
NEXT(c);
if (c != f)
return count;
break;
}
++fmt;
}
}
return count;
}
#endif /* HAVE_VSSCANF */

View File

@@ -0,0 +1,210 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: scr_dump.c,v 1.30 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: scr_dump
Synopsis:
int putwin(WINDOW *win, FILE *filep);
WINDOW *getwin(FILE *filep);
int scr_dump(const char *filename);
int scr_init(const char *filename);
int scr_restore(const char *filename);
int scr_set(const char *filename);
Description:
getwin() reads window-related data previously stored in a file
by putwin(). It then creates and initialises a new window using
that data.
putwin() writes all data associated with a window into a file,
using an unspecified format. This information can be retrieved
later using getwin().
scr_dump() writes the current contents of the virtual screen to
the file named by filename in an unspecified format.
scr_restore() function sets the virtual screen to the contents
of the file named by filename, which must have been written
using scr_dump(). The next refresh operation restores the screen
to the way it looked in the dump file.
In PDCurses, scr_init() does nothing, and scr_set() is a synonym
for scr_restore(). Also, scr_dump() and scr_restore() save and
load from curscr. This differs from some other implementations,
where scr_init() works with curscr, and scr_restore() works with
newscr; but the effect should be the same. (PDCurses has no
newscr.)
Return Value:
On successful completion, getwin() returns a pointer to the
window it created. Otherwise, it returns a null pointer. Other
functions return OK or ERR.
Portability X/Open BSD SYS V
putwin Y
getwin Y
scr_dump Y
scr_init Y
scr_restore Y
scr_set Y
**man-end****************************************************************/
#include <stdlib.h>
#include <string.h>
#define DUMPVER 1 /* Should be updated whenever the WINDOW struct is
changed */
int putwin(WINDOW *win, FILE *filep)
{
static const char *marker = "PDC";
static const unsigned char version = DUMPVER;
PDC_LOG(("putwin() - called\n"));
/* write the marker and the WINDOW struct */
if (filep && fwrite(marker, strlen(marker), 1, filep)
&& fwrite(&version, 1, 1, filep)
&& fwrite(win, sizeof(WINDOW), 1, filep))
{
int i;
/* write each line */
for (i = 0; i < win->_maxy && win->_y[i]; i++)
if (!fwrite(win->_y[i], win->_maxx * sizeof(chtype), 1, filep))
return ERR;
return OK;
}
return ERR;
}
WINDOW *getwin(FILE *filep)
{
WINDOW *win;
char marker[4];
int i, nlines, ncols;
PDC_LOG(("getwin() - called\n"));
if ( !(win = malloc(sizeof(WINDOW))) )
return (WINDOW *)NULL;
/* check for the marker, and load the WINDOW struct */
if (!filep || !fread(marker, 4, 1, filep) || strncmp(marker, "PDC", 3)
|| marker[3] != DUMPVER || !fread(win, sizeof(WINDOW), 1, filep))
{
free(win);
return (WINDOW *)NULL;
}
nlines = win->_maxy;
ncols = win->_maxx;
/* allocate the line pointer array */
if ( !(win->_y = malloc(nlines * sizeof(chtype *))) )
{
free(win);
return (WINDOW *)NULL;
}
/* allocate the minchng and maxchng arrays */
if ( !(win->_firstch = malloc(nlines * sizeof(int))) )
{
free(win->_y);
free(win);
return (WINDOW *)NULL;
}
if ( !(win->_lastch = malloc(nlines * sizeof(int))) )
{
free(win->_firstch);
free(win->_y);
free(win);
return (WINDOW *)NULL;
}
/* allocate the lines */
if ( !(win = PDC_makelines(win)) )
return (WINDOW *)NULL;
/* read them */
for (i = 0; i < nlines; i++)
{
if (!fread(win->_y[i], ncols * sizeof(chtype), 1, filep))
{
delwin(win);
return (WINDOW *)NULL;
}
}
touchwin(win);
return win;
}
int scr_dump(const char *filename)
{
FILE *filep;
PDC_LOG(("scr_dump() - called: filename %s\n", filename));
if (filename && (filep = fopen(filename, "wb")) != NULL)
{
int result = putwin(curscr, filep);
fclose(filep);
return result;
}
return ERR;
}
int scr_init(const char *filename)
{
PDC_LOG(("scr_init() - called: filename %s\n", filename));
return OK;
}
int scr_restore(const char *filename)
{
FILE *filep;
PDC_LOG(("scr_restore() - called: filename %s\n", filename));
if (filename && (filep = fopen(filename, "rb")) != NULL)
{
WINDOW *replacement = getwin(filep);
fclose(filep);
if (replacement)
{
int result = overwrite(replacement, curscr);
delwin(replacement);
return result;
}
}
return ERR;
}
int scr_set(const char *filename)
{
PDC_LOG(("scr_set() - called: filename %s\n", filename));
return scr_restore(filename);
}

View File

@@ -0,0 +1,98 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: scroll.c,v 1.36 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: scroll
Synopsis:
int scroll(WINDOW *win);
int scrl(int n);
int wscrl(WINDOW *win, int n);
Description:
scroll() causes the window to scroll up one line. This involves
moving the lines in the window data strcture.
With a positive n, scrl() and wscrl() scroll the window up n
lines (line i + n becomes i); otherwise they scroll the window
down n lines.
For these functions to work, scrolling must be enabled via
scrollok(). Note also that scrolling is not allowed if the
supplied window is a pad.
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
scroll Y Y Y
scrl Y - 4.0
wscrl Y - 4.0
**man-end****************************************************************/
int wscrl(WINDOW *win, int n)
{
int i, l, dir, start, end;
chtype blank, *temp;
/* Check if window scrolls. Valid for window AND pad */
if (!win || !win->_scroll || !n)
return ERR;
blank = win->_bkgd;
if (n > 0)
{
start = win->_tmarg;
end = win->_bmarg;
dir = 1;
}
else
{
start = win->_bmarg;
end = win->_tmarg;
dir = -1;
}
for (l = 0; l < (n * dir); l++)
{
temp = win->_y[start];
/* re-arrange line pointers */
for (i = start; i != end; i += dir)
win->_y[i] = win->_y[i + dir];
win->_y[end] = temp;
/* make a blank line */
for (i = 0; i < win->_maxx; i++)
*temp++ = blank;
}
touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1);
PDC_sync(win);
return OK;
}
int scrl(int n)
{
PDC_LOG(("scrl() - called\n"));
return wscrl(stdscr, n);
}
int scroll(WINDOW *win)
{
PDC_LOG(("scroll() - called\n"));
return wscrl(win, 1);
}

View File

@@ -0,0 +1,643 @@
/* Public Domain Curses */
#include <curspriv.h>
RCSID("$Id: slk.c,v 1.61 2008/07/13 16:08:18 wmcbrine Exp $")
/*man-start**************************************************************
Name: slk
Synopsis:
int slk_init(int fmt);
int slk_set(int labnum, const char *label, int justify);
int slk_refresh(void);
int slk_noutrefresh(void);
char *slk_label(int labnum);
int slk_clear(void);
int slk_restore(void);
int slk_touch(void);
int slk_attron(const chtype attrs);
int slk_attr_on(const attr_t attrs, void *opts);
int slk_attrset(const chtype attrs);
int slk_attr_set(const attr_t attrs, short color_pair, void *opts);
int slk_attroff(const chtype attrs);
int slk_attr_off(const attr_t attrs, void *opts);
int slk_color(short color_pair);
int slk_wset(int labnum, const wchar_t *label, int justify);
int PDC_mouse_in_slk(int y, int x);
void PDC_slk_free(void);
void PDC_slk_initialize(void);
wchar_t *slk_wlabel(int labnum)
Description:
These functions manipulate a window that contain Soft Label Keys
(SLK). To use the SLK functions, a call to slk_init() must be
made BEFORE initscr() or newterm(). slk_init() removes 1 or 2
lines from the useable screen, depending on the format selected.
The line(s) removed from the screen are used as a separate
window, in which SLKs are displayed.
slk_init() requires a single parameter which describes the
format of the SLKs as follows:
0 3-2-3 format
1 4-4 format
2 4-4-4 format (ncurses extension)
3 4-4-4 format with index line (ncurses extension)
2 lines used
55 5-5 format (pdcurses format)
slk_refresh(), slk_noutrefresh() and slk_touch() are analogous
to refresh(), noutrefresh() and touch().
Return Value:
All functions return OK on success and ERR on error.
Portability X/Open BSD SYS V
slk_init Y - Y
slk_set Y - Y
slk_refresh Y - Y
slk_noutrefresh Y - Y
slk_label Y - Y
slk_clear Y - Y
slk_restore Y - Y
slk_touch Y - Y
slk_attron Y - Y
slk_attrset Y - Y
slk_attroff Y - Y
slk_attr_on Y
slk_attr_set Y
slk_attr_off Y
slk_wset Y
PDC_mouse_in_slk - - -
PDC_slk_free - - -
PDC_slk_initialize - - -
slk_wlabel - - -
**man-end****************************************************************/
#include <stdlib.h>
enum { LABEL_NORMAL = 8, LABEL_EXTENDED = 10, LABEL_NCURSES_EXTENDED = 12 };
static int label_length = 0;
static int labels = 0;
static int label_fmt = 0;
static int label_line = 0;
static bool hidden = FALSE;
static struct SLK {
chtype label[32];
int len;
int format;
int start_col;
} *slk = (struct SLK *)NULL;
/* slk_init() is the slk initialization routine.
This must be called before initscr().
label_fmt = 0, 1 or 55.
0 = 3-2-3 format
1 = 4 - 4 format
2 = 4-4-4 format (ncurses extension for PC 12 function keys)
3 = 4-4-4 format (ncurses extension for PC 12 function keys -
with index line)
55 = 5 - 5 format (extended for PC, 10 function keys) */
int slk_init(int fmt)
{
PDC_LOG(("slk_init() - called\n"));
if (SP)
return ERR;
switch (fmt)
{
case 0: /* 3 - 2 - 3 */
labels = LABEL_NORMAL;
break;
case 1: /* 4 - 4 */
labels = LABEL_NORMAL;
break;
case 2: /* 4 4 4 */
labels = LABEL_NCURSES_EXTENDED;
break;
case 3: /* 4 4 4 with index */
labels = LABEL_NCURSES_EXTENDED;
break;
case 55: /* 5 - 5 */
labels = LABEL_EXTENDED;
break;
default:
return ERR;
}
label_fmt = fmt;
slk = calloc(labels, sizeof(struct SLK));
if (!slk)
labels = 0;
return slk ? OK : ERR;
}
/* draw a single button */
static void _drawone(int num)
{
int i, col, slen;
if (hidden)
return;
slen = slk[num].len;
switch (slk[num].format)
{
case 0: /* LEFT */
col = 0;
break;
case 1: /* CENTER */
col = (label_length - slen) / 2;
if (col + slen > label_length)
--col;
break;
default: /* RIGHT */
col = label_length - slen;
}
wmove(SP->slk_winptr, label_line, slk[num].start_col);
for (i = 0; i < label_length; ++i)
waddch(SP->slk_winptr, (i >= col && i < (col + slen)) ?
slk[num].label[i - col] : ' ');
}
/* redraw each button */
static void _redraw(void)
{
int i;
for (i = 0; i < labels; ++i)
_drawone(i);
}
/* slk_set() Used to set a slk label to a string.
labnum = 1 - 8 (or 10) (number of the label)
label = string (8 or 7 bytes total), or NULL
justify = 0 : left, 1 : center, 2 : right */
int slk_set(int labnum, const char *label, int justify)
{
#ifdef PDC_WIDE
wchar_t wlabel[32];
PDC_mbstowcs(wlabel, label, 31);
return slk_wset(labnum, wlabel, justify);
#else
PDC_LOG(("slk_set() - called\n"));
if (labnum < 1 || labnum > labels || justify < 0 || justify > 2)
return ERR;
labnum--;
if (!label || !(*label))
{
/* Clear the label */
*slk[labnum].label = 0;
slk[labnum].format = 0;
slk[labnum].len = 0;
}
else
{
int i, j = 0;
/* Skip leading spaces */
while (label[j] == ' ')
j++;
/* Copy it */
for (i = 0; i < label_length; i++)
{
chtype ch = label[i + j];
slk[labnum].label[i] = ch;
if (!ch)
break;
}
/* Drop trailing spaces */
while ((i + j) && (label[i + j - 1] == ' '))
i--;
slk[labnum].label[i] = 0;
slk[labnum].format = justify;
slk[labnum].len = i;
}
_drawone(labnum);
return OK;
#endif
}
int slk_refresh(void)
{
PDC_LOG(("slk_refresh() - called\n"));
return (slk_noutrefresh() == ERR) ? ERR : doupdate();
}
int slk_noutrefresh(void)
{
PDC_LOG(("slk_noutrefresh() - called\n"));
return wnoutrefresh(SP->slk_winptr);
}
char *slk_label(int labnum)
{
static char temp[33];
#ifdef PDC_WIDE
wchar_t *wtemp = slk_wlabel(labnum);
PDC_wcstombs(temp, wtemp, 32);
#else
chtype *p;
int i;
PDC_LOG(("slk_label() - called\n"));
if (labnum < 1 || labnum > labels)
return (char *)0;
for (i = 0, p = slk[labnum - 1].label; *p; i++)
temp[i] = *p++;
temp[i] = '\0';
#endif
return temp;
}
int slk_clear(void)
{
PDC_LOG(("slk_clear() - called\n"));
hidden = TRUE;
werase(SP->slk_winptr);
return wrefresh(SP->slk_winptr);
}
int slk_restore(void)
{
PDC_LOG(("slk_restore() - called\n"));
hidden = FALSE;
_redraw();
return wrefresh(SP->slk_winptr);
}
int slk_touch(void)
{
PDC_LOG(("slk_touch() - called\n"));
return touchwin(SP->slk_winptr);
}
int slk_attron(const chtype attrs)
{
int rc;
PDC_LOG(("slk_attron() - called\n"));
rc = wattron(SP->slk_winptr, attrs);
_redraw();
return rc;
}
int slk_attr_on(const attr_t attrs, void *opts)
{
PDC_LOG(("slk_attr_on() - called\n"));
return slk_attron(attrs);
}
int slk_attroff(const chtype attrs)
{
int rc;
PDC_LOG(("slk_attroff() - called\n"));
rc = wattroff(SP->slk_winptr, attrs);
_redraw();
return rc;
}
int slk_attr_off(const attr_t attrs, void *opts)
{
PDC_LOG(("slk_attr_off() - called\n"));
return slk_attroff(attrs);
}
int slk_attrset(const chtype attrs)
{
int rc;
PDC_LOG(("slk_attrset() - called\n"));
rc = wattrset(SP->slk_winptr, attrs);
_redraw();
return rc;
}
int slk_color(short color_pair)
{
int rc;
PDC_LOG(("slk_color() - called\n"));
rc = wcolor_set(SP->slk_winptr, color_pair, NULL);
_redraw();
return rc;
}
int slk_attr_set(const attr_t attrs, short color_pair, void *opts)
{
PDC_LOG(("slk_attr_set() - called\n"));
return slk_attrset(attrs | COLOR_PAIR(color_pair));
}
static void _slk_calc(void)
{
int i, center, col = 0;
label_length = COLS / labels;
if (label_length > 31)
label_length = 31;
switch (label_fmt)
{
case 0: /* 3 - 2 - 3 F-Key layout */
--label_length;
slk[0].start_col = col;
slk[1].start_col = (col += label_length);
slk[2].start_col = (col += label_length);
center = COLS / 2;
slk[3].start_col = center - label_length + 1;
slk[4].start_col = center + 1;
col = COLS - (label_length * 3) + 1;
slk[5].start_col = col;
slk[6].start_col = (col += label_length);
slk[7].start_col = (col += label_length);
break;
case 1: /* 4 - 4 F-Key layout */
for (i = 0; i < 8; i++)
{
slk[i].start_col = col;
col += label_length;
if (i == 3)
col = COLS - (label_length * 4) + 1;
}
break;
case 2: /* 4 4 4 F-Key layout */
case 3: /* 4 4 4 F-Key layout with index */
for (i = 0; i < 4; i++)
{
slk[i].start_col = col;
col += label_length;
}
center = COLS/2;
slk[4].start_col = center - (label_length * 2) + 1;
slk[5].start_col = center - label_length - 1;
slk[6].start_col = center + 1;
slk[7].start_col = center + label_length + 1;
col = COLS - (label_length * 4) + 1;
for (i = 8; i < 12; i++)
{
slk[i].start_col = col;
col += label_length;
}
break;
default: /* 5 - 5 F-Key layout */
for (i = 0; i < 10; i++)
{
slk[i].start_col = col;
col += label_length;
if (i == 4)
col = COLS - (label_length * 5) + 1;
}
}
--label_length;
/* make sure labels are all in window */
_redraw();
}
void PDC_slk_initialize(void)
{
if (slk)
{
if (label_fmt == 3)
{
SP->slklines = 2;
label_line = 1;
}
else
SP->slklines = 1;
if (!SP->slk_winptr)
{
if ( !(SP->slk_winptr = newwin(SP->slklines, COLS,
LINES - SP->slklines, 0)) )
return;
wattrset(SP->slk_winptr, A_REVERSE);
}
_slk_calc();
/* if we have an index line, display it now */
if (label_fmt == 3)
{
chtype save_attr;
int i;
save_attr = SP->slk_winptr->_attrs;
wattrset(SP->slk_winptr, A_NORMAL);
wmove(SP->slk_winptr, 0, 0);
whline(SP->slk_winptr, 0, COLS);
for (i = 0; i < labels; i++)
mvwprintw(SP->slk_winptr, 0, slk[i].start_col, "F%d", i + 1);
SP->slk_winptr->_attrs = save_attr;
}
touchwin(SP->slk_winptr);
}
}
void PDC_slk_free(void)
{
if (slk)
{
if (SP->slk_winptr)
{
delwin(SP->slk_winptr);
SP->slk_winptr = (WINDOW *)NULL;
}
free(slk);
slk = (struct SLK *)NULL;
label_length = 0;
labels = 0;
label_fmt = 0;
label_line = 0;
hidden = FALSE;
}
}
int PDC_mouse_in_slk(int y, int x)
{
int i;
PDC_LOG(("PDC_mouse_in_slk() - called: y->%d x->%d\n", y, x));
/* If the line on which the mouse was clicked is NOT the last line
of the screen, we are not interested in it. */
if (!slk || !SP->slk_winptr || (y != SP->slk_winptr->_begy + label_line))
return 0;
for (i = 0; i < labels; i++)
if (x >= slk[i].start_col && x < (slk[i].start_col + label_length))
return i + 1;
return 0;
}
#ifdef PDC_WIDE
int slk_wset(int labnum, const wchar_t *label, int justify)
{
PDC_LOG(("slk_wset() - called\n"));
if (labnum < 1 || labnum > labels || justify < 0 || justify > 2)
return ERR;
labnum--;
if (!label || !(*label))
{
/* Clear the label */
*slk[labnum].label = 0;
slk[labnum].format = 0;
slk[labnum].len = 0;
}
else
{
int i, j = 0;
/* Skip leading spaces */
while (label[j] == L' ')
j++;
/* Copy it */
for (i = 0; i < label_length; i++)
{
chtype ch = label[i + j];
slk[labnum].label[i] = ch;
if (!ch)
break;
}
/* Drop trailing spaces */
while ((i + j) && (label[i + j - 1] == L' '))
i--;
slk[labnum].label[i] = 0;
slk[labnum].format = justify;
slk[labnum].len = i;
}
_drawone(labnum);
return OK;
}
wchar_t *slk_wlabel(int labnum)
{
static wchar_t temp[33];
chtype *p;
int i;
PDC_LOG(("slk_wlabel() - called\n"));
if (labnum < 1 || labnum > labels)
return (wchar_t *)0;
for (i = 0, p = slk[labnum - 1].label; *p; i++)
temp[i] = *p++;
temp[i] = '\0';
return temp;
}
#endif

Some files were not shown because too many files have changed in this diff Show More