diff options
144 files changed, 5642 insertions, 3288 deletions
diff --git a/lib/libcurses/MKexpanded.sh b/lib/libcurses/MKexpanded.sh index e2e8363d22e..6eb6b196374 100644 --- a/lib/libcurses/MKexpanded.sh +++ b/lib/libcurses/MKexpanded.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#! /bin/sh ################################################################################ # Copyright 1997 by Thomas E. Dickey <dickey@clark.net> # # All Rights Reserved. # @@ -18,7 +18,7 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # # PERFORMANCE OF THIS SOFTWARE. # ################################################################################ -# Id: MKexpanded.sh,v 1.4 1997/05/10 20:21:58 tom Exp $ +# Id: MKexpanded.sh,v 1.5 1997/08/31 01:59:30 tom Exp $ # # Script to generate 'expanded.c', a dummy source that contains functions # corresponding to complex macros used in this library. By making functions, @@ -57,10 +57,6 @@ cat >$TMP <<EOF #undef FALSE /* this is a marker */ IGNORE -chtype _nc_ch_or_attr(chtype ch, attr_t at) -{ - return ch_or_attr(ch,at); -} void _nc_toggle_attr_on(attr_t *S, attr_t at) { toggle_attr_on(*S,at); diff --git a/lib/libcurses/MKkeyname.awk b/lib/libcurses/MKkeyname.awk index 85f19457163..bb7727941ed 100644 --- a/lib/libcurses/MKkeyname.awk +++ b/lib/libcurses/MKkeyname.awk @@ -1,10 +1,12 @@ -# Id: MKkeyname.awk,v 1.6 1997/04/05 23:38:17 tom Exp $ +# Id: MKkeyname.awk,v 1.12 1997/11/15 22:16:55 tom Exp $ BEGIN { + print "/* generated by MKkeyname.awk */" print "" print "#include <ncurses_cfg.h>" print "#include <stdlib.h>" - print "#include <term.h>" + print "#include <string.h>" print "#include <curses.h>" + print "#include <term.h>" print "" print "struct kn {" print "\tconst char *name;" @@ -14,7 +16,10 @@ BEGIN { print "const struct kn key_names[] = {" } -{printf "\t{\"%s\", %s,},\n", $1, $2;} +/^[^#]/ { +# printf "\t{ \"%s\",%*s%s },\n", $1, 16-length($1), " ", $1; + printf "\t{ \"%s\",%s },\n", $1, $1; + } END { print "};" @@ -22,11 +27,28 @@ END { print "const char *keyname(int c)" print "{" print "int i, size = sizeof(key_names)/sizeof(struct kn);" + print "static char name[5];" + print "char *p;" print "" - print "\tfor (i = 0; i < size; i++) {" - print "\t\tif (key_names[i].code == c) return key_names[i].name;" + print "\tfor (i = 0; i < size; i++)" + print "\t\tif (key_names[i].code == c)" + print "\t\t\treturn key_names[i].name;" + print "\tif (c >= 256) return \"UNKNOWN KEY\";" + print "\tp = name;" + print "\tif (c >= 128) {" + print "\t\tstrcpy(p, \"M-\");" + print "\t\tp += 2;" + print "\t\tc -= 128;" print "\t}" - print "\treturn NULL;" + print "\tif (c < 0)" + print "\t\tsprintf(p, \"%d\", c);" + print "\telse if (c < 32)" + print "\t\tsprintf(p, \"^%c\", c + '@');" + print "\telse if (c == 127)" + print "\t\tstrcpy(p, \"^?\");" + print "\telse" + print "\t\tsprintf(p, \"%c\", c);" + print "\treturn name;" print "}" print "" } diff --git a/lib/libcurses/MKkeys.awk b/lib/libcurses/MKkeys.awk index 669c455ef54..3618300ad1a 100644 --- a/lib/libcurses/MKkeys.awk +++ b/lib/libcurses/MKkeys.awk @@ -1 +1 @@ -{printf "\tadd_to_try(%s, %s);\n", $1, $2;} +/^[^#]/ { if ($1 != "" && $2 != "" ) { printf "\tadd_to_try(%s, %s);\n", $2, $1;} } diff --git a/lib/libcurses/MKlib_gen.sh b/lib/libcurses/MKlib_gen.sh index 86f1a6253d4..03c02075c29 100644 --- a/lib/libcurses/MKlib_gen.sh +++ b/lib/libcurses/MKlib_gen.sh @@ -2,7 +2,7 @@ # # MKlib_gen.sh -- generate sources from curses.h macro definitions # -# (Id: MKlib_gen.sh,v 1.9 1997/05/10 23:48:19 tom Exp $) +# (Id: MKlib_gen.sh,v 1.10 1997/07/26 22:12:20 tom Exp $) # # The XSI Curses standard requires all curses entry points to exist as # functions, even though many definitions would normally be shadowed @@ -28,8 +28,11 @@ preprocessor="$1 -I../include" AWK="$2" +ED1=sed1$$.sed +ED2=sed2$$.sed +ED3=sed3$$.sed TMP=gen$$.c -trap "rm -f $TMP" 0 1 2 5 15 +trap "rm -f $ED1 $ED2 $ED3 $TMP" 0 1 2 5 15 (cat <<EOF #include <ncurses_cfg.h> @@ -38,32 +41,77 @@ trap "rm -f $TMP" 0 1 2 5 15 DECLARATIONS EOF -sed -n -e "/^extern.*generated/s/^extern \([^;]*\);.*/\1/p" \ -| sed \ - -e "/(void)/b nc" \ - -e "s/,/ a1% /" \ - -e "s/,/ a2% /" \ - -e "s/,/ a3% /" \ - -e "s/,/ a4% /" \ - -e "s/,/ a5% /" \ - -e "s/,/ a6% /" \ - -e "s/,/ a7% /" \ - -e "s/,/ a8% /" \ - -e "s/,/ a9% /" \ - -e "s/,/ a10% /" \ - -e "s/,/ a11% /" \ - -e "s/,/ a12% /" \ - -e "s/,/ a13% /" \ - -e "s/,/ a14% /" \ - -e "s/,/ a15% /" \ - -e "s/*/ * /g" \ - -e "s/%/ , /g" \ - -e "s/)/ z)/" \ - -e ":nc" \ - -e "/(/s// ( /" \ - -e "s/)/ )/" \ -| $AWK '{ - print "\n" +cat >$ED1 <<EOF1 +/^extern.*generated/{ + h + s/^.*generated:\([^ *]*\).*/P_#if_USE_\1_SUPPORT/p + g + s/^extern \([^;]*\);.*/\1/p + g + s/^.*generated:\([^ *]*\).*/P_#endif/p +} +EOF1 + +cat >$ED2 <<EOF2 +/^P_/b nc +/(void)/b nc + s/,/ a1% / + s/,/ a2% / + s/,/ a3% / + s/,/ a4% / + s/,/ a5% / + s/,/ a6% / + s/,/ a7% / + s/,/ a8% / + s/,/ a9% / + s/,/ a10% / + s/,/ a11% / + s/,/ a12% / + s/,/ a13% / + s/,/ a14% / + s/,/ a15% / + s/*/ * /g + s/%/ , /g + s/)/ z)/ +:nc + /(/s// ( / + s/)/ )/ +EOF2 + +cat >$ED3 <<EOF3 +/^P_/{ + s/^P_#if_/#if / + s/^P_// + b done +} + s/ */ /g + s/ */ /g + s/ ,/,/g + s/ )/)/g + s/ gen_/ / + s/^M_/#undef / + /^%%/s// / +:done +EOF3 + +sed -n -f $ED1 | sed -f $ED2 \ +| $AWK ' +BEGIN { + skip=0; + } + /^P_#if/ { + print "\n" + print $0 + skip=0; + } + /^P_#endif/ { + print $0 + skip=1; + } + $0 !~ /^P_/ { + if (skip) + print "\n" + skip=1; print "M_" $2 print $0; @@ -182,15 +230,13 @@ BEGIN { print " * It is generated by MKlib_gen.sh." print " *" print " * This is a file of trivial functions generated from macro" - print " * definitions in curses.h in order to satisfy the XSI Curses" - print " * requirement that every macro also exist as a callable" - print " * function." + print " * definitions in curses.h to satisfy the XSI Curses requirement" + print " * that every macro also exist as a callable function." print " *" print " * It will never be linked unless you call one of the entry" print " * points with its normal macro definition disabled. In that" print " * case, if you have no shared libraries, it will indirectly" print " * pull most of the rest of the library into your link image." - print " * Cope with it." print " */" print "#include <curses.priv.h>" print "" @@ -198,14 +244,7 @@ BEGIN { /^DECLARATIONS/ {start = 1; next;} {if (start) print $0;} ' \ -| sed \ - -e 's/ */ /g' \ - -e 's/ */ /g' \ - -e 's/ ,/,/g' \ - -e 's/ )/)/g' \ - -e 's/ gen_/ /' \ - -e 's/^M_/#undef /' \ - -e '/^%%/s// /' \ +| sed -f $ED3 \ | sed \ -e 's/^.*T_CALLED.*returnCode( \([a-z].*) \));/ return \1;/' \ -e 's/^.*T_CALLED.*returnCode( \((wmove.*) \));/ return \1;/' diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 36a6cd8eaeb..b5f86ddaa24 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,27 +1,34 @@ -# $OpenBSD: Makefile,v 1.17 1997/11/28 23:05:05 millert Exp $ +# $OpenBSD: Makefile,v 1.18 1997/12/03 05:20:48 millert Exp $ # Uncomment this to enable tracing in libcurses #CURSESTRACE=-DTRACE LIB= curses -SRCS= hardscroll.c hashmap.c lib_acs.c lib_addch.c lib_addstr.c \ - lib_baudrate.c lib_beep.c lib_bkgd.c lib_box.c lib_clear.c \ - lib_clrbot.c lib_clreol.c lib_color.c lib_data.c lib_delch.c \ - lib_delwin.c lib_dft_fgbg.c lib_doupdate.c lib_endwin.c lib_erase.c \ - lib_getch.c lib_getstr.c lib_inchstr.c lib_initscr.c lib_insch.c \ - lib_insdel.c lib_insstr.c lib_instr.c lib_isendwin.c lib_kernel.c \ - lib_longname.c lib_mouse.c lib_move.c lib_mvcur.c lib_mvwin.c \ - lib_newterm.c lib_newwin.c lib_options.c lib_overlay.c lib_pad.c \ - lib_print.c lib_printw.c lib_raw.c lib_refresh.c lib_scanw.c \ - lib_screen.c lib_scroll.c lib_scrreg.c lib_set_term.c lib_slk.c \ - lib_touch.c lib_tstp.c lib_twait.c lib_vidattr.c lib_window.c \ - resizeterm.c unctrl.c wresize.c +SRCS= define_key.c hardscroll.c hashmap.c keyok.c lib_acs.c lib_addch.c \ + lib_addstr.c lib_baudrate.c lib_beep.c lib_bkgd.c lib_box.c \ + lib_clear.c lib_clrbot.c lib_clreol.c lib_color.c lib_data.c \ + lib_delch.c lib_delwin.c lib_dft_fgbg.c lib_doupdate.c lib_endwin.c \ + lib_erase.c lib_flash.c lib_getch.c lib_getstr.c lib_hline.c \ + lib_inchstr.c lib_initscr.c lib_insch.c lib_insdel.c lib_insstr.c \ + lib_instr.c lib_isendwin.c lib_kernel.c lib_longname.c lib_mouse.c \ + lib_move.c lib_mvcur.c lib_mvwin.c lib_newterm.c lib_newwin.c \ + lib_options.c lib_overlay.c lib_pad.c lib_print.c lib_printw.c \ + lib_raw.c lib_redrawln.c lib_refresh.c lib_scanw.c lib_screen.c \ + lib_scroll.c lib_scrreg.c lib_set_term.c lib_slk.c lib_slkatrof.c \ + lib_slkatron.c lib_slkatrset.c lib_slkattr.c lib_slkclear.c \ + lib_slkinit.c lib_slklab.c lib_slkrefr.c lib_slkset.c lib_slktouch.c \ + lib_touch.c lib_tstp.c lib_twait.c lib_ungetch.c lib_vidattr.c \ + lib_vline.c lib_wattroff.c lib_wattron.c lib_window.c nc_panel.c \ + resizeterm.c safe_sprintf.c softscroll.c tries.c unctrl.c \ + wresize.c SRCS+= expanded.c lib_gen.c lib_keyname.c .if defined(${CURSESTRACE}) -SRCS+= lib_trace.c lib_traceatr.c lib_tracechr.c lib_tracedmp.c lib_tracemse.c +SRCS+= lib_trace.c lib_traceatr.c lib_tracechr.c lib_tracedmp.c \ + lib_tracemse.c trace_buf.c .endif CFLAGS+= -I. -I${.CURDIR} -DTERMIOS -DEXTERN_TERMINFO ${CURSESTRACE} LDADD+= -ltermlib +# XXX - add new man pages MAN= curs_addch.3 curs_addchstr.3 curs_addstr.3 curs_attr.3 curs_beep.3 \ curs_bkgd.3 curs_border.3 curs_clear.3 curs_color.3 curs_delch.3 \ curs_deleteln.3 curs_getch.3 curs_getstr.3 curs_getyx.3 curs_inch.3 \ diff --git a/lib/libcurses/config.h b/lib/libcurses/config.h deleted file mode 100644 index e9b3a016aa9..00000000000 --- a/lib/libcurses/config.h +++ /dev/null @@ -1,43 +0,0 @@ -/* generated by configure-script - * On host: OpenBSD gandalf.sigmasoft.com 1.2 OpenBSD 1.2 (GANDALF) #1: Sun Apr 28 03:30:40 PDT 1996 tholo@gandalf.sigmasoft.com:/usr/src/sys/arch/i386/compile/GANDALF i386 - */ -#ifndef NC_CONFIG_H -#define NC_CONFIG_H - -#define CC_HAS_INLINE_FUNCS 1 -#define HAVE_DIRENT_H 1 -#define HAVE_EXTERN_ERRNO 1 -#define HAVE_EXTERN_SYS_ERRLIST 1 -#define HAVE_FCNTL_H 1 -#define HAVE_FORM_H 1 -#define HAVE_GETTIMEOFDAY 1 -#define HAVE_GETTTYNAM 1 -#define HAVE_LIMITS_H 1 -#define HAVE_MEMCCPY 1 -#define HAVE_MENU_H 1 -#define HAVE_PANEL_H 1 -#define HAVE_REGEXP_H 1 -#define HAVE_REGEX_H 1 -#define HAVE_SETBUFFER 1 -#define HAVE_SETVBUF 1 -#define HAVE_SIGACTION 1 -#define HAVE_STRDUP 1 -#define HAVE_STRERROR 1 -#define HAVE_SYS_IOCTL_H 1 -#define HAVE_SYS_PARAM_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_TIME_H 1 -#define HAVE_TERMIOS_H 1 -#define HAVE_TTYENT_H 1 -#define HAVE_UNISTD_H 1 -#define HAVE_USLEEP 1 -#define HAVE_VSSCANF 1 -#define STDC_HEADERS 1 - - /* The C compiler may not treat these properly, but C++ has to */ -#ifdef __cplusplus -#undef const -#undef inline -#endif - -#endif /* NC_CONFIG_H */ diff --git a/lib/libcurses/curs_addch.3tbl b/lib/libcurses/curs_addch.3tbl index 2a50efa09db..d6fbc149768 100644 --- a/lib/libcurses/curs_addch.3tbl +++ b/lib/libcurses/curs_addch.3tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_addch.3tbl,v 1.2 1997/12/03 05:20:49 millert Exp $ '\" t .TH curs_addch 3X "" .SH NAME @@ -42,7 +43,7 @@ literally, use \fBechochar\fR.) Video attributes can be combined with a character argument passed to \fBaddch\fR or related functions by logical-ORing them into the character. (Thus, text, including attributes, can be copied from one place to another -using \fBinch\fR and \fBaddch\fR.). See the \fBcurs_attr\fR(3X) page for +using \fBinch\fR and \fBaddch\fR.). See the \fBcurs_attr\fR(3) page for values of predefined video attribute constants that can be usefully OR'ed into characters. @@ -133,10 +134,10 @@ The seven ACS symbols starting with \fBACS_S3\fR were not documented in any publicly released System V. However, many publicly available terminfos include \fBacsc\fR strings in which their key characters (pryz{|}) are embedded, and a second-hand list of their character descriptions has come -to light. The ACS-prefixed names for them were invented for \fBcurses\fR(3X). +to light. The ACS-prefixed names for them were invented for \fBcurses\fR(3). .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_attr\fR(3X), \fBcurs_clear\fR(3X), -\fBcurs_inch\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X), +\fBcurses\fR(3), \fBcurs_attr\fR(3), \fBcurs_clear\fR(3), +\fBcurs_inch\fR(3), \fBcurs_outopts\fR(3), \fBcurs_refresh\fR(3), \fBputc\fR(3S). .\"# .\"# The following sets edit modes for GNU EMACS diff --git a/lib/libcurses/curs_addchstr.3 b/lib/libcurses/curs_addchstr.3 index fd5600dd2e1..8c030d956f9 100644 --- a/lib/libcurses/curs_addchstr.3 +++ b/lib/libcurses/curs_addchstr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_addchstr.3,v 1.2 1997/12/03 05:20:50 millert Exp $ .TH curs_addchstr 3X "" .SH NAME \fBaddchstr\fR, \fBaddchnstr\fR, \fBwaddchstr\fR, @@ -46,7 +47,7 @@ Note that all routines except \fBwaddchnstr\fR may be macros. .SH PORTABILITY All these entry points are described in the XSI Curses standard, Issue 4. .SH SEE ALSO -\fBcurses\fR(3X). +\fBcurses\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_addstr.3 b/lib/libcurses/curs_addstr.3 index 3859a34b8b4..a6541a41a16 100644 --- a/lib/libcurses/curs_addstr.3 +++ b/lib/libcurses/curs_addstr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_addstr.3,v 1.2 1997/12/03 05:20:50 millert Exp $ .TH curs_addstr 3X "" .SH NAME \fBaddstr\fR, \fBaddnstr\fR, \fBwaddstr\fR, \fBwaddnstr\fR, @@ -39,7 +40,7 @@ All these entry points are described in the XSI Curses standard, Issue 4. The XSI errors EILSEQ and EOVERFLOW, associated with extended-level conformance, are not yet detected. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_addch\fR(3X). +\fBcurses\fR(3), \fBcurs_addch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_attr.3tbl b/lib/libcurses/curs_attr.3tbl index 64669500bcb..8c84d812f64 100644 --- a/lib/libcurses/curs_attr.3tbl +++ b/lib/libcurses/curs_attr.3tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_attr.3tbl,v 1.2 1997/12/03 05:20:51 millert Exp $ .\" Id: curs_attr.3x,v 1.12 1997/01/05 01:14:33 tom Exp $ .TH curs_attr 3X "" .SH NAME @@ -162,8 +163,8 @@ The XSI standard extended conformance level adds new highlights \fBA_VERTICAL\fR (and corresponding \fBWA_\fR macros for each) which this curses does not yet support. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_addch\fR(3X), \fBcurs_addstr\fR(3X), -\fBcurs_printw\fR(3X) +\fBcurses\fR(3), \fBcurs_addch\fR(3), \fBcurs_addstr\fR(3), +\fBcurs_printw\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_beep.3 b/lib/libcurses/curs_beep.3 index 140f255c762..25dbb3101d4 100644 --- a/lib/libcurses/curs_beep.3 +++ b/lib/libcurses/curs_beep.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_beep.3,v 1.2 1997/12/03 05:20:51 millert Exp $ .TH curs_beep 3X "" .SH NAME \fBbeep\fR, \fBflash\fR - \fBcurses\fR bell and screen flash routines @@ -25,7 +26,7 @@ possible to tell when the beep or flash failed. These functions are defined in the XSI Curses standard, Issue 4. Like SVr4, it specifies that they always return \fBOK\fR. .SH SEE ALSO -\fBcurses\fR(3X) +\fBcurses\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_bkgd.3 b/lib/libcurses/curs_bkgd.3 index a1b823fbb2f..699eba2ba45 100644 --- a/lib/libcurses/curs_bkgd.3 +++ b/lib/libcurses/curs_bkgd.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_bkgd.3,v 1.3 1997/12/03 05:20:51 millert Exp $ .\" Id: curs_bkgd.3x,v 1.10 1996/07/20 23:48:30 tom Exp $ .TH curs_bkgd 3X "" . @@ -65,7 +66,7 @@ specifies that \fBbkgd\fR and \fBwbkgd\fR return \fBERR\fR, on failure. but gives no failure conditions. . .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_addch\fR(3X), \fBcurs_outopts\fR(3X) +\fBcurses\fR(3), \fBcurs_addch\fR(3), \fBcurs_outopts\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_border.3 b/lib/libcurses/curs_border.3 index 1ba70e61592..b889935b5ab 100644 --- a/lib/libcurses/curs_border.3 +++ b/lib/libcurses/curs_border.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_border.3,v 1.3 1997/12/03 05:20:52 millert Exp $ .\" Id: curs_border.3x,v 1.8 1996/08/04 00:29:11 tom Exp $ .TH curs_border 3X "" .SH NAME @@ -71,7 +72,7 @@ described there which this implementation does not yet support. The standard specifies that they return \fBERR\fR on failure, but specifies no error conditions. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_outopts\fR(3X). +\fBcurses\fR(3), \fBcurs_outopts\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_clear.3 b/lib/libcurses/curs_clear.3 index a923efe7753..4e9f691189d 100644 --- a/lib/libcurses/curs_clear.3 +++ b/lib/libcurses/curs_clear.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_clear.3,v 1.3 1997/12/03 05:20:52 millert Exp $ .TH curs_clear 3X "" .SH NAME \fBerase\fR, \fBwerase\fR, \fBclear\fR, @@ -56,7 +57,7 @@ ability to do the equivalent of \fBclearok(..., 1)\fR by saying \fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under curses. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X) +\fBcurses\fR(3), \fBcurs_outopts\fR(3), \fBcurs_refresh\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_color.3 b/lib/libcurses/curs_color.3 index 133baf97057..b1f797a815d 100644 --- a/lib/libcurses/curs_color.3 +++ b/lib/libcurses/curs_color.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_color.3,v 1.3 1997/12/03 05:20:53 millert Exp $ .\" Id: curs_color.3x,v 1.8 1997/01/19 02:50:30 tom Exp $ .TH curs_color 3X "" .SH NAME @@ -150,10 +151,10 @@ The \fBinit_pair\fP routine accepts negative values of foreground and background color to support the \fBuse_default_colors\fP extension, but only if that routine has been first invoked. .SH SEE ALSO -\fBcurses\fR(3X), -\fBcurs_initscr\fR(3X), -\fBcurs_attr\fR(3X), -\fBdft_fgbg\fR(3X) +\fBcurses\fR(3), +\fBcurs_initscr\fR(3), +\fBcurs_attr\fR(3), +\fBdft_fgbg\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_delch.3 b/lib/libcurses/curs_delch.3 index d7973a98962..1f6ac9b28dc 100644 --- a/lib/libcurses/curs_delch.3 +++ b/lib/libcurses/curs_delch.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_delch.3,v 1.2 1997/12/03 05:20:53 millert Exp $ .TH curs_delch 3X "" .SH NAME \fBdelch\fR, \fBwdelch\fR, \fBmvdelch\fR, \fBmvwdelch\fR - @@ -30,7 +31,7 @@ These functions are described in the XSI Curses standard, Issue 4. The standard specifies that they return \fBERR\fR on failure, but specifies no error conditions. .SH SEE ALSO -\fBcurses\fR(3X) +\fBcurses\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_deleteln.3 b/lib/libcurses/curs_deleteln.3 index 2b4710990aa..f01b8a21696 100644 --- a/lib/libcurses/curs_deleteln.3 +++ b/lib/libcurses/curs_deleteln.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_deleteln.3,v 1.2 1997/12/03 05:20:53 millert Exp $ .TH curs_deleteln 3X "" .SH NAME \fBdeleteln\fR, \fBwdeleteln\fR, \fBinsdelln\fR, @@ -46,7 +47,7 @@ These routines do not require a hardware line delete or insert feature in the terminal. In fact, they won't use hardware line delete/insert unless \fBidlok(..., TRUE)\fR has been set on the current window. .SH SEE ALSO -\fBcurses\fR(3X) +\fBcurses\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_getch.3tbl b/lib/libcurses/curs_getch.3tbl index ceab5335d71..e73c2578cf1 100644 --- a/lib/libcurses/curs_getch.3tbl +++ b/lib/libcurses/curs_getch.3tbl @@ -1,4 +1,5 @@ -.\" Id: curs_getch.3x,v 1.10 1997/01/05 11:57:54 Jesse.Thilo Exp $ +.\" $OpenBSD: curs_getch.3tbl,v 1.2 1997/12/03 05:20:54 millert Exp $ +.\" Id: curs_getch.3x,v 1.11 1997/11/02 00:20:41 tom Exp $ .TH curs_getch 3X "" .SH NAME \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, @@ -121,6 +122,7 @@ KEY_FIND/Find key KEY_HELP/Help key KEY_MARK/Mark key KEY_MESSAGE/Message key +KEY_MOUSE/Mouse event read KEY_MOVE/Move key KEY_NEXT/Next object key KEY_OPEN/Open key @@ -130,6 +132,7 @@ KEY_REDO/Redo key KEY_REFERENCE/Ref(erence) key KEY_REFRESH/Refresh key KEY_REPLACE/Replace key +KEY_RESIZE/Screen resized KEY_RESTART/Restart key KEY_RESUME/Resume key KEY_SAVE/Save key @@ -227,10 +230,14 @@ interrupts \fBgetch\fR and causes it to return ERR with \fBerrno\fR set to interrupt \fBgetch\fR. The \fBhas_key\fR function is unique to \fBcurses\fR. We recommend that -any code using it be conditionalized on the NCURSES feature macro. +any code using it be conditionalized on the \fBNCURSES_VERSION\fR feature macro. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_inopts\fR(3X), \fBcurs_move\fR(3X), -\fBcurs_refresh\fR(3X). +\fBcurses\fR(3), +\fBcurs_inopts\fR(3), +\fBcurs_mouse\fR(3), +\fBcurs_move\fR(3), +\fBcurs_refresh\fR(3), +\fBresizeterm\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_getstr.3 b/lib/libcurses/curs_getstr.3 index cd3abf4d6da..cda751ab0f6 100644 --- a/lib/libcurses/curs_getstr.3 +++ b/lib/libcurses/curs_getstr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_getstr.3,v 1.3 1997/12/03 05:20:54 millert Exp $ .TH curs_getstr 3X "" .SH NAME \fBgetstr\fR, \fBwgetstr\fR, \fBmvgetstr\fR, @@ -64,7 +65,7 @@ string by those implementations was predictable but not useful The functions \fBgetnstr\fR, \fBmvgetnstr\fR, and \fBmvwgetnstr\fR were present but not documented in SVr4. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_getch\fR(3X). +\fBcurses\fR(3), \fBcurs_getch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_getyx.3 b/lib/libcurses/curs_getyx.3 index 58a3a52e8eb..fb0935d0e94 100644 --- a/lib/libcurses/curs_getyx.3 +++ b/lib/libcurses/curs_getyx.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_getyx.3,v 1.2 1997/12/03 05:20:55 millert Exp $ .TH curs_getyx 3X "" .SH NAME \fBgetyx\fR, \fBgetparyx\fR, \fBgetbegyx\fR, @@ -34,7 +35,7 @@ necessary before the variables \fIy\fR and \fIx\fR. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO -\fBcurses\fR(3X) +\fBcurses\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_inch.3tbl b/lib/libcurses/curs_inch.3tbl index 48aa2e5fcc7..93be75d4c12 100644 --- a/lib/libcurses/curs_inch.3tbl +++ b/lib/libcurses/curs_inch.3tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_inch.3tbl,v 1.2 1997/12/03 05:20:55 millert Exp $ .\" Id: curs_inch.3x,v 1.7 1997/01/05 01:29:23 tom Exp $ .TH curs_inch 3X "" .SH NAME @@ -35,7 +36,7 @@ Note that all of these routines may be macros. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO -\fBcurses\fR(3X). +\fBcurses\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_inchstr.3 b/lib/libcurses/curs_inchstr.3 index 75c02b2fdb5..bb504047c1f 100644 --- a/lib/libcurses/curs_inchstr.3 +++ b/lib/libcurses/curs_inchstr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_inchstr.3,v 1.2 1997/12/03 05:20:56 millert Exp $ .TH curs_inchstr 3X "" .SH NAME \fBinchstr\fR, \fBinchnstr\fR, \fBwinchstr\fR, @@ -31,7 +32,7 @@ the last argument, return a leading substring at most \fIn\fR characters long (exclusive of the trailing (chtype)0). Constants defined in \fB<curses.h>\fR can be used with the \fB&\fR (logical AND) operator to extract the character or the attribute alone from any position -in the \fIchstr\fR [see curs_inch(3X)]. +in the \fIchstr\fR [see curs_inch(3)]. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR upon successful completion (the number of characters @@ -46,7 +47,7 @@ These functions are described in the XSI Curses standard, Issue 4. It is no more specific than the SVr4 documentation on the trailing 0. It does specify that the successful return of the functions is \fBOK\fR. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_inch\fR(3X). +\fBcurses\fR(3), \fBcurs_inch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_initscr.3 b/lib/libcurses/curs_initscr.3 index 0ede098dc19..53f1b722866 100644 --- a/lib/libcurses/curs_initscr.3 +++ b/lib/libcurses/curs_initscr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_initscr.3,v 1.2 1997/12/03 05:20:56 millert Exp $ .TH curs_initscr 3X "" .SH NAME \fBinitscr\fR, \fBnewterm\fR, \fBendwin\fR, @@ -77,8 +78,8 @@ These functions are described in the XSI Curses standard, Issue 4. It specifies that portable applications must not call \fBinitscr\fR more than once. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_kernel\fR(3X), \fBcurs_refresh\fR(3X), -\fBcurs_slk\fR(3X), \fBcurs_util\fR(3X) +\fBcurses\fR(3), \fBcurs_kernel\fR(3), \fBcurs_refresh\fR(3), +\fBcurs_slk\fR(3), \fBcurs_util\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_inopts.3 b/lib/libcurses/curs_inopts.3 index aa53b61e57a..adb13498805 100644 --- a/lib/libcurses/curs_inopts.3 +++ b/lib/libcurses/curs_inopts.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_inopts.3,v 1.2 1997/12/03 05:20:56 millert Exp $ .TH curs_inopts 3X "" .SH NAME \fBcbreak\fR, \fBnocbreak\fR, \fBecho\fR, @@ -53,7 +54,7 @@ mode. Initially the terminal may or may not be in \fBcbreak\fR mode, as the mode is inherited; therefore, a program should call \fBcbreak\fR or \fBnocbreak\fR explicitly. Most interactive programs using \fBcurses\fR set the \fBcbreak\fR -mode. Note that \fBcbreak\fR overrides \fBraw\fR. [See curs_getch(3X) for a +mode. Note that \fBcbreak\fR overrides \fBraw\fR. [See curs_getch(3) for a discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.] The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by @@ -61,7 +62,7 @@ the user are echoed by \fBgetch\fR as they are typed. Echoing by the tty driver is always disabled, but initially \fBgetch\fR is in echo mode, so characters typed are echoed. Authors of most interactive programs prefer to do their own echoing in a controlled area of the screen, or not to echo at all, so -they disable echoing by calling \fBnoecho\fR. [See curs_getch(3X) for a +they disable echoing by calling \fBnoecho\fR. [See curs_getch(3) for a discussion of how these routines interact with \fBcbreak\fR and \fBnocbreak\fR.] @@ -174,7 +175,7 @@ they attempt to restore to normal (`cooked') mode from raw and cbreak modes respectively. Mixing raw/noraw and cbreak/nocbreak calls leads to tty driver control states that are hard to predict or understand; it is not recommended. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_getch\fR(3X), \fBcurs_initscr\fR(3X), \fBtermio\fR(7) +\fBcurses\fR(3), \fBcurs_getch\fR(3), \fBcurs_initscr\fR(3), \fBtermio\fR(7) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_insch.3 b/lib/libcurses/curs_insch.3 index 11f49053095..80657e21f12 100644 --- a/lib/libcurses/curs_insch.3 +++ b/lib/libcurses/curs_insch.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_insch.3,v 1.2 1997/12/03 05:20:57 millert Exp $ .TH curs_insch 3X "" .SH NAME \fBinsch\fR, \fBwinsch\fR, \fBmvinsch\fR, \fBmvwinsch\fR - @@ -30,7 +31,7 @@ Note that \fBinsch\fR, \fBmvinsch\fR, and \fBmvwinsch\fR may be macros. .SH PORTABILITY These functions are described in the XSI Curses standard, Issue 4. .SH SEE ALSO -\fBcurses\fR(3X). +\fBcurses\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_insstr.3 b/lib/libcurses/curs_insstr.3 index 8c3c0af6a45..dc479057c6d 100644 --- a/lib/libcurses/curs_insstr.3 +++ b/lib/libcurses/curs_insstr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_insstr.3,v 1.4 1997/12/03 05:20:57 millert Exp $ .TH curs_insstr 3X "" .SH NAME \fBinsstr\fR, \fBinsnstr\fR, \fBwinsstr\fR, \fBwinsnstr\fR, @@ -52,7 +53,7 @@ const qualifiers to the arguments. The XSI Curses error conditions are not yet detected (this implementation does not yet support XPG4 multi-byte characters). .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_clear\fR(3X), \fBcurs_inch\fR(3X). +\fBcurses\fR(3), \fBcurs_clear\fR(3), \fBcurs_inch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_instr.3 b/lib/libcurses/curs_instr.3 index 34be1cb3c69..40d40ba4faa 100644 --- a/lib/libcurses/curs_instr.3 +++ b/lib/libcurses/curs_instr.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_instr.3,v 1.3 1997/12/03 05:20:58 millert Exp $ .\" Id: curs_instr.3x,v 1.7 1997/03/15 23:25:24 tom Exp $ .TH curs_instr 3X "" .SH NAME @@ -46,7 +47,7 @@ The curses library extends the XSI description by allowing a negative value for \fIn\fR. In this case, the functions return the string ending at the right margin. .SH SEE ALSO -\fBcurses\fR(3X). +\fBcurses\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_kernel.3 b/lib/libcurses/curs_kernel.3 index ffba687f89c..dfdc8aaaf1f 100644 --- a/lib/libcurses/curs_kernel.3 +++ b/lib/libcurses/curs_kernel.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_kernel.3,v 1.3 1997/12/03 05:20:58 millert Exp $ .TH curs_kernel 3X "" .SH NAME \fBdef_prog_mode\fR, \fBdef_shell_mode\fR, @@ -70,7 +71,7 @@ at the beginning, do its manipulation of its own windows, do a \fBdoupdate\fR. The \fBripoffline\fR routine provides access to the same facility that -\fBslk_init\fR [see curs_slk(3X)] uses to reduce the size of the +\fBslk_init\fR [see curs_slk(3)] uses to reduce the size of the screen. \fBripoffline\fR must be called before \fBinitscr\fR or \fBnewterm\fR is called. If \fIline\fR is positive, a line is removed from the top of \fBstdscr\fR; if \fIline\fR is negative, a line is @@ -113,8 +114,8 @@ The SVr4 documentation describes \fBsetsyx\fR and \fBgetsyx\fR as having return type int. This is misleading, as they are macros with no documented semantics for the return value. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X), -\fBcurs_scr_dump\fR(3X), \fBcurs_slk\fR(3X) +\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_outopts\fR(3), \fBcurs_refresh\fR(3), +\fBcurs_scr_dump\fR(3), \fBcurs_slk\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_mouse.3tbl b/lib/libcurses/curs_mouse.3tbl index 988bbc32b6a..16797ed1d72 100644 --- a/lib/libcurses/curs_mouse.3tbl +++ b/lib/libcurses/curs_mouse.3tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_mouse.3tbl,v 1.2 1997/12/03 05:20:59 millert Exp $ '\" t .TH curs_mouse 3X "" .SH NAME @@ -142,7 +143,7 @@ report sequence will appear in the string read. Mouse events under xterm will not be detected correctly in a window with its keypad bit off. .SH SEE ALSO -\fBcurses\fR(3X). +\fBcurses\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_move.3 b/lib/libcurses/curs_move.3 index 7d915ed2843..4e817407eb0 100644 --- a/lib/libcurses/curs_move.3 +++ b/lib/libcurses/curs_move.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_move.3,v 1.2 1997/12/03 05:20:59 millert Exp $ .TH curs_move 3X "" .SH NAME \fBmove\fR, \fBwmove\fR - move \fBcurses\fR window cursor @@ -25,7 +26,7 @@ standard specifies that if (y,x) is within a multi-column character, the cursor is moved to the first column of that character; however, this implementation does not yet support the extended-level XSI multi-byte characters. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_refresh\fR(3X) +\fBcurses\fR(3), \fBcurs_refresh\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_outopts.3 b/lib/libcurses/curs_outopts.3 index 1e56ab12a77..d23c3e0be14 100644 --- a/lib/libcurses/curs_outopts.3 +++ b/lib/libcurses/curs_outopts.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_outopts.3,v 1.3 1997/12/03 05:20:59 millert Exp $ .TH curs_outopts 3X "" .SH NAME \fBclearok\fR, \fBidlok\fR, \fBidcok immedok\fR, @@ -125,8 +126,8 @@ Note that \fBclearok\fR, \fBleaveok\fR, \fBscrollok\fR, \fBidcok\fR, \fBnl\fR, The \fBimmedok\fR routine is useful for windows that are used as terminal emulators. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_addch\fR(3X), \fBcurs_clear\fR(3X), -\fBcurs_initscr\fR(3X), \fBcurs_scroll\fR(3X), \fBcurs_refresh\fR(3X) +\fBcurses\fR(3), \fBcurs_addch\fR(3), \fBcurs_clear\fR(3), +\fBcurs_initscr\fR(3), \fBcurs_scroll\fR(3), \fBcurs_refresh\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_overlay.3 b/lib/libcurses/curs_overlay.3 index 0c7b93df37f..e85f8304a98 100644 --- a/lib/libcurses/curs_overlay.3 +++ b/lib/libcurses/curs_overlay.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_overlay.3,v 1.2 1997/12/03 05:21:00 millert Exp $ .TH curs_overlay 3X "" .SH NAME \fBoverlay\fR, \fBoverwrite\fR, \fBcopywin\fR - overlay and @@ -37,7 +38,7 @@ The XSI Curses standard, Issue 4 describes these functions (adding the const qualifiers). It further specifies their behavior in the presence of characters with multi-byte renditions (not yet supported in this implementation). .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_pad\fR(3X), \fBcurs_refresh\fR(3X) +\fBcurses\fR(3), \fBcurs_pad\fR(3), \fBcurs_refresh\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_pad.3 b/lib/libcurses/curs_pad.3 index 18969c94e3e..142f7c7c0f1 100644 --- a/lib/libcurses/curs_pad.3 +++ b/lib/libcurses/curs_pad.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_pad.3,v 1.2 1997/12/03 05:21:00 millert Exp $ .TH curs_pad 3X "" .SH NAME \fBnewpad\fR, \fBsubpad\fR, \fBprefresh\fR, @@ -73,7 +74,7 @@ Note that \fBpechochar\fR may be a macro. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_refresh\fR(3X), \fBcurs_touch\fR(3X), \fBcurs_addch\fR(3X). +\fBcurses\fR(3), \fBcurs_refresh\fR(3), \fBcurs_touch\fR(3), \fBcurs_addch\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_print.3 b/lib/libcurses/curs_print.3 index ee45d9f51c4..96992c34ac0 100644 --- a/lib/libcurses/curs_print.3 +++ b/lib/libcurses/curs_print.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_print.3,v 1.2 1997/12/03 05:21:01 millert Exp $ .TH curs_print 3X "" .SH NAME \fBmcprint\fR - ship binary data to printer @@ -36,7 +37,7 @@ in SVr4 curses, 4.4BSD curses, or any other previous version of curses. Padding in the \fBmc5p\fR, \fBmc4\fR and \fBmc5\fR capabilities will not be interpreted. .SH SEE ALSO -\fBcurses\fR(3X)\fR +\fBcurses\fR(3)\fR .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_printw.3 b/lib/libcurses/curs_printw.3 index e3ac2e8d5ed..ab203882db4 100644 --- a/lib/libcurses/curs_printw.3 +++ b/lib/libcurses/curs_printw.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_printw.3,v 1.3 1997/12/03 05:21:02 millert Exp $ .TH curs_printw 3X "" .SH NAME \fBprintw\fR, \fBwprintw\fR, \fBmvprintw\fR, @@ -38,7 +39,7 @@ The XSI Curses standard, Issue 4 describes these functions. The function \fBvwprintw\fR is marked TO BE WITHDRAWN, and is to be replaced by a function \fBvw_printw\fR using the \fB<stdarg.h>\fR interface. .SH SEE ALSO -\fBcurses\fR(3X), \fBprintf\fR(3S), \fBvprintf(3S)\fR +\fBcurses\fR(3), \fBprintf\fR(3S), \fBvprintf(3S)\fR .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_refresh.3 b/lib/libcurses/curs_refresh.3 index 77bae2eeb90..dcfb0d915a6 100644 --- a/lib/libcurses/curs_refresh.3 +++ b/lib/libcurses/curs_refresh.3 @@ -1,3 +1,5 @@ +.\" $OpenBSD: curs_refresh.3,v 1.2 1997/12/03 05:21:02 millert Exp $ +.\" Id: curs_refresh.3x,v 1.6 1997/11/29 20:11:26 tom Exp $ .TH curs_refresh 3X "" .SH NAME \fBrefresh\fR, \fBwrefresh\fR, \fBwnoutrefresh\fR, @@ -55,10 +57,9 @@ changed. (But see the section on \fBPORTABILITY\fR below for a warning about exploiting this behavior.) The \fBwredrawln\fR routine indicates to \fBcurses\fR that some screen lines -are corrupted and should be thrown away before anything is written over them -it touches the indicated lines (marking them changed) then does a refresh -of the window. The routine \fBredrawwin\fR() touches the entire window and then -refreshes it. +are corrupted and should be thrown away before anything is written over them. +It touches the indicated lines (marking them changed). +The routine \fBredrawwin\fR() touches the entire window. .SH RETURN VALUE Routines that return an integer return \fBERR\fR upon failure, and \fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful @@ -75,7 +76,7 @@ either behavior in programs that might have to be linked with other curses implementations. Instead, you can do an explicit \fBtouchwin()\fR before the \fBwnoutrefresh()\fR call to guarantee an entire-contents copy anywhere. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_outopts\fR(3X) +\fBcurses\fR(3), \fBcurs_outopts\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_resize.3 b/lib/libcurses/curs_resize.3 index 1ec283e97e1..102dbb52a96 100644 --- a/lib/libcurses/curs_resize.3 +++ b/lib/libcurses/curs_resize.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_resize.3,v 1.2 1997/12/03 05:21:02 millert Exp $ .TH wresize 3X "" .SH NAME diff --git a/lib/libcurses/curs_scanw.3 b/lib/libcurses/curs_scanw.3 index 6ce1c0d2f84..5265bf3ffd3 100644 --- a/lib/libcurses/curs_scanw.3 +++ b/lib/libcurses/curs_scanw.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_scanw.3,v 1.2 1997/12/03 05:21:03 millert Exp $ .TH curs_scanw 3X "" .SH NAME \fBscanw\fR, \fBwscanw\fR, \fBmvscanw\fR, @@ -39,7 +40,7 @@ The XSI Curses standard, Issue 4 describes these functions. The function \fBvwscanw\fR is marked TO BE WITHDRAWN, and is to be replaced by a function \fBvw_scanw\fR using the \fB<stdarg.h>\fR interface. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_getstr\fR, \fBcurs_printw\fR, \fBscanf\fR(3S) +\fBcurses\fR(3), \fBcurs_getstr\fR, \fBcurs_printw\fR, \fBscanf\fR(3S) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_scr_dmp.3 b/lib/libcurses/curs_scr_dmp.3 index c1b89f12059..5f7765ded27 100644 --- a/lib/libcurses/curs_scr_dmp.3 +++ b/lib/libcurses/curs_scr_dmp.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_scr_dmp.3,v 1.2 1997/12/03 05:21:03 millert Exp $ .TH curs_scr_dump 3X "" .SH NAME \fBscr_dump\fR, \fBscr_restore\fR, @@ -40,7 +41,7 @@ what is currently on the screen, and also what the program wants on the screen. This can be thought of as a screen inheritance function. To read (write) a window from (to) a file, use the \fBgetwin\fR and -\fBputwin\fR routines [see \fBcurs_util\fR(3X)]. +\fBputwin\fR routines [see \fBcurs_util\fR(3)]. .SH RETURN VALUE All routines return the integer \fBERR\fR upon failure and \fBOK\fR upon success. @@ -54,8 +55,8 @@ The SVr4 docs merely say under \fBscr_init\fR that the dump data is also considered invalid "if the time-stamp of the tty is old" but don't define "old". .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_refresh\fR(3X), -\fBcurs_util\fR(3X), \fBsystem\fR(3S) +\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_refresh\fR(3), +\fBcurs_util\fR(3), \fBsystem\fR(3S) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_scroll.3 b/lib/libcurses/curs_scroll.3 index 0ac518d5b25..1f0de577447 100644 --- a/lib/libcurses/curs_scroll.3 +++ b/lib/libcurses/curs_scroll.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_scroll.3,v 1.2 1997/12/03 05:21:03 millert Exp $ .TH curs_scroll 3X "" .SH NAME \fBscroll\fR, \fBsrcl\fR, \fBwscrl\fR - scroll a \fBcurses\fR window @@ -40,7 +41,7 @@ Under this implementation it is. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_outopts\fR(3X) +\fBcurses\fR(3), \fBcurs_outopts\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_slk.3 b/lib/libcurses/curs_slk.3 index f1fda3908d7..5751e921098 100644 --- a/lib/libcurses/curs_slk.3 +++ b/lib/libcurses/curs_slk.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_slk.3,v 1.3 1997/12/03 05:21:04 millert Exp $ .TH curs_slk 3X "" .SH NAME \fBslk_init\fR, \fBslk_set\fR, \fBslk_refresh\fR, @@ -95,7 +96,7 @@ argument type of the attribute-manipulation functions \fBslk_attron\fR, qualifiers. The format codes \fB2\fR and \fB3\fR for \fBslk_init()\fR and the function \fBslk_attr\fR are specific to curses. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_attr\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_refresh\fR(3X) +\fBcurses\fR(3), \fBcurs_attr\fR(3), \fBcurs_initscr\fR(3), \fBcurs_refresh\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_termattrs.3 b/lib/libcurses/curs_termattrs.3 index c76c7fafaa0..4424a4717f9 100644 --- a/lib/libcurses/curs_termattrs.3 +++ b/lib/libcurses/curs_termattrs.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_termattrs.3,v 1.3 1997/12/03 05:21:04 millert Exp $ .TH curs_termattrs 3X "" .SH NAME \fBbaudrate\fR, \fBerasechar\fR, \fBhas_ic\fR, @@ -69,7 +70,7 @@ Note that \fBtermattrs\fR may be a macro. The XSI Curses standard, Issue 4 describes these functions. It changes the return type of \fBtermattrs\fR to the new type \fBattr_t\fR. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_outopts\fR(3X) +\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_outopts\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_touch.3 b/lib/libcurses/curs_touch.3 index 961ccbe66da..8651d6287f2 100644 --- a/lib/libcurses/curs_touch.3 +++ b/lib/libcurses/curs_touch.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_touch.3,v 1.2 1997/12/03 05:21:05 millert Exp $ .TH curs_touch 3X "" .SH NAME \fBtouchwin\fR, \fBtouchline\fR, \fBuntouchwin\fR, @@ -55,7 +56,7 @@ curses. .SH NOTES Note that all routines except \fBwtouchln\fR may be macros. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_refresh\fR(3X). +\fBcurses\fR(3), \fBcurs_refresh\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_util.3 b/lib/libcurses/curs_util.3 index 0d2e0b88b74..f2cb31f62eb 100644 --- a/lib/libcurses/curs_util.3 +++ b/lib/libcurses/curs_util.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_util.3,v 1.2 1997/12/03 05:21:05 millert Exp $ .TH curs_util 3X "" .SH NAME \fBunctrl\fR, \fBkeyname\fR, \fBfilter\fR, @@ -76,7 +77,7 @@ erroneously fails to describe the disabling of \fBcuu\fR). .SH NOTES Note that \fBunctrl\fR is a macro, which is defined in <\fBunctrl.h\fR>. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_scr_dump\fR(3X). +\fBcurses\fR(3), \fBcurs_initscr\fR(3), \fBcurs_scr_dump\fR(3). .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curs_window.3 b/lib/libcurses/curs_window.3 index 9bd3facd818..c5a15ca07a3 100644 --- a/lib/libcurses/curs_window.3 +++ b/lib/libcurses/curs_window.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: curs_window.3,v 1.2 1997/12/03 05:21:06 millert Exp $ .TH curs_window 3X "" .SH NAME \fBnewwin\fR, \fBdelwin\fR, \fBmvwin\fR, @@ -114,7 +115,7 @@ in slower updates. .SH PORTABILITY The XSI Curses standard, Issue 4 describes these functions. .SH SEE ALSO -\fBcurses\fR(3X), \fBcurs_refresh\fR(3X), \fBcurs_touch\fR(3X) +\fBcurses\fR(3), \fBcurs_refresh\fR(3), \fBcurs_touch\fR(3) .\"# .\"# The following sets edit modes for GNU EMACS .\"# Local Variables: diff --git a/lib/libcurses/curses.3tbl b/lib/libcurses/curses.3tbl index 6ef4b0a28bd..39083f8e6e1 100644 --- a/lib/libcurses/curses.3tbl +++ b/lib/libcurses/curses.3tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: curses.3tbl,v 1.2 1997/12/03 05:21:06 millert Exp $ .\" Id: ncurses.3x,v 1.19 1997/01/05 00:42:39 tom Exp $ .TH curses 3X "" .ds n 5 @@ -13,7 +14,7 @@ of updating character screens with reasonable optimization. This implementation is ``new curses'' (ncurses) and is the approved replacement for 4.4BSD classic curses, which has been discontinued. -The \fBcurses\fR routines emulate the \fBcurses\fR(3X) library of System V +The \fBcurses\fR routines emulate the \fBcurses\fR(3) library of System V Release 4 UNIX, and the XPG4 curses standard (XSI curses) but the \fBcurses\fR library is freely redistributable in source form. Differences from the SVr4 curses are summarized under the EXTENSIONS and BUGS sections below and @@ -78,7 +79,7 @@ about the character may also be stored with each character. Special windows called \fIpads\fR may also be manipulated. These are windows which are not constrained to the size of the screen and whose contents need not -be completely displayed. See curs_pad(3X) for more information. +be completely displayed. See curs_pad(3) for more information. In addition to drawing characters on the screen, video attributes and colors may be supported, causing the characters to show up in such modes as @@ -163,273 +164,273 @@ l l l l . \fBcurses\fR Routine Name/Manual Page Name = -addch/curs_addch(3X) -addchnstr/curs_addchstr(3X) -addchstr/curs_addchstr(3X) -addnstr/curs_addstr(3X) -addstr/curs_addstr(3X) -attroff/curs_attr(3X) -attron/curs_attr(3X) -attrset/curs_attr(3X) -baudrate/curs_termattrs(3X) -beep/curs_beep(3X) -bkgd/curs_bkgd(3X) -bkgdset/curs_bkgd(3X) -border/curs_border(3X) -box/curs_border(3X) -can_change_color/curs_color(3X) -cbreak/curs_inopts(3X) -clear/curs_clear(3X) -clearok/curs_outopts(3X) -clrtobot/curs_clear(3X) -clrtoeol/curs_clear(3X) -color_content/curs_color(3X) -copywin/curs_overlay(3X) -curs_set/curs_kernel(3X) -def_prog_mode/curs_kernel(3X) -def_shell_mode/curs_kernel(3X) -del_curterm/curs_terminfo(3X) -delay_output/curs_util(3X) -delch/curs_delch(3X) -deleteln/curs_deleteln(3X) -delscreen/curs_initscr(3X) -delwin/curs_window(3X) -derwin/curs_window(3X) -doupdate/curs_refresh(3X) -dupwin/curs_window(3X) -echo/curs_inopts(3X) -echochar/curs_addch(3X) -endwin/curs_initscr(3X) -erase/curs_clear(3X) -erasechar/curs_termattrs(3X) -filter/curs_util(3X) -flash/curs_beep(3X) -flushinp/curs_util(3X) -getbegyx/curs_getyx(3X) -getch/curs_getch(3X) -getmaxyx/curs_getyx(3X) -getmouse/curs_mouse(3X)* -getparyx/curs_getyx(3X) -getstr/curs_getstr(3X) -getsyx/curs_kernel(3X) -getwin/curs_util(3X) -getyx/curs_getyx(3X) -halfdelay/curs_inopts(3X) -has_colors/curs_color(3X) -has_ic/curs_termattrs(3X) -has_il/curs_termattrs(3X) -has_key/curs_getch(3X)* -hline/curs_border(3X) -idcok/curs_outopts(3X) -idlok/curs_outopts(3X) -immedok/curs_outopts(3X) -inch/curs_inch(3X) -inchnstr/curs_inchstr(3X) -inchstr/curs_inchstr(3X) -init_color/curs_color(3X) -init_pair/curs_color(3X) -initscr/curs_initscr(3X) -innstr/curs_instr(3X) -insch/curs_insch(3X) -insdelln/curs_deleteln(3X) -insertln/curs_deleteln(3X) -insnstr/curs_insstr(3X) -insstr/curs_insstr(3X) -instr/curs_instr(3X) -intrflush/curs_inopts(3X) -is_linetouched/curs_touch(3X) -is_wintouched/curs_touch(3X) -isendwin/curs_initscr(3X) -keyname/curs_util(3X) -keypad/curs_inopts(3X) -killchar/curs_termattrs(3X) -leaveok/curs_outopts(3X) -longname/curs_termattrs(3X) -mcprint/curs_print(3X)* -meta/curs_inopts(3X) -mouseinterval/curs_mouse(3X)* -mousemask/curs_mouse(3X)* -move/curs_move(3X) -mvaddch/curs_addch(3X) -mvaddchnstr/curs_addchstr(3X) -mvaddchstr/curs_addchstr(3X) -mvaddnstr/curs_addstr(3X) -mvaddstr/curs_addstr(3X) -mvcur/curs_terminfo(3X) -mvdelch/curs_delch(3X) -mvderwin/curs_window(3X) -mvgetch/curs_getch(3X) -mvgetstr/curs_getstr(3X) -mvinch/curs_inch(3X) -mvinchnstr/curs_inchstr(3X) -mvinchstr/curs_inchstr(3X) -mvinnstr/curs_instr(3X) -mvinsch/curs_insch(3X) -mvinsnstr/curs_insstr(3X) -mvinsstr/curs_insstr(3X) -mvinstr/curs_instr(3X) -mvprintw/curs_printw(3X) -mvscanw/curs_scanw(3X) -mvwaddch/curs_addch(3X) -mvwaddchnstr/curs_addchstr(3X) -mvwaddchstr/curs_addchstr(3X) -mvwaddnstr/curs_addstr(3X) -mvwaddstr/curs_addstr(3X) -mvwdelch/curs_delch(3X) -mvwgetch/curs_getch(3X) -mvwgetstr/curs_getstr(3X) -mvwin/curs_window(3X) -mvwinch/curs_inch(3X) -mvwinchnstr/curs_inchstr(3X) -mvwinchstr/curs_inchstr(3X) -mvwinnstr/curs_instr(3X) -mvwinsch/curs_insch(3X) -mvwinsnstr/curs_insstr(3X) -mvwinsstr/curs_insstr(3X) -mvwinstr/curs_instr(3X) -mvwprintw/curs_printw(3X) -mvwscanw/curs_scanw(3X) -napms/curs_kernel(3X) -newpad/curs_pad(3X) -newterm/curs_initscr(3X) -newwin/curs_window(3X) -nl/curs_outopts(3X) -nocbreak/curs_inopts(3X) -nodelay/curs_inopts(3X) -noecho/curs_inopts(3X) -nonl/curs_outopts(3X) -noqiflush/curs_inopts(3X) -noraw/curs_inopts(3X) -notimeout/curs_inopts(3X) -overlay/curs_overlay(3X) -overwrite/curs_overlay(3X) -pair_content/curs_color(3X) -pechochar/curs_pad(3X) -pnoutrefresh/curs_pad(3X) -prefresh/curs_pad(3X) -printw/curs_printw(3X) -putp/curs_terminfo(3X) -putwin/curs_util(3X) -qiflush/curs_inopts(3X) -raw/curs_inopts(3X) -redrawwin/curs_refresh(3X) -refresh/curs_refresh(3X) -reset_prog_mode/curs_kernel(3X) -reset_shell_mode/curs_kernel(3X) -resetty/curs_kernel(3X) +addch/curs_addch(3) +addchnstr/curs_addchstr(3) +addchstr/curs_addchstr(3) +addnstr/curs_addstr(3) +addstr/curs_addstr(3) +attroff/curs_attr(3) +attron/curs_attr(3) +attrset/curs_attr(3) +baudrate/curs_termattrs(3) +beep/curs_beep(3) +bkgd/curs_bkgd(3) +bkgdset/curs_bkgd(3) +border/curs_border(3) +box/curs_border(3) +can_change_color/curs_color(3) +cbreak/curs_inopts(3) +clear/curs_clear(3) +clearok/curs_outopts(3) +clrtobot/curs_clear(3) +clrtoeol/curs_clear(3) +color_content/curs_color(3) +copywin/curs_overlay(3) +curs_set/curs_kernel(3) +def_prog_mode/curs_kernel(3) +def_shell_mode/curs_kernel(3) +del_curterm/curs_terminfo(3) +delay_output/curs_util(3) +delch/curs_delch(3) +deleteln/curs_deleteln(3) +delscreen/curs_initscr(3) +delwin/curs_window(3) +derwin/curs_window(3) +doupdate/curs_refresh(3) +dupwin/curs_window(3) +echo/curs_inopts(3) +echochar/curs_addch(3) +endwin/curs_initscr(3) +erase/curs_clear(3) +erasechar/curs_termattrs(3) +filter/curs_util(3) +flash/curs_beep(3) +flushinp/curs_util(3) +getbegyx/curs_getyx(3) +getch/curs_getch(3) +getmaxyx/curs_getyx(3) +getmouse/curs_mouse(3)* +getparyx/curs_getyx(3) +getstr/curs_getstr(3) +getsyx/curs_kernel(3) +getwin/curs_util(3) +getyx/curs_getyx(3) +halfdelay/curs_inopts(3) +has_colors/curs_color(3) +has_ic/curs_termattrs(3) +has_il/curs_termattrs(3) +has_key/curs_getch(3)* +hline/curs_border(3) +idcok/curs_outopts(3) +idlok/curs_outopts(3) +immedok/curs_outopts(3) +inch/curs_inch(3) +inchnstr/curs_inchstr(3) +inchstr/curs_inchstr(3) +init_color/curs_color(3) +init_pair/curs_color(3) +initscr/curs_initscr(3) +innstr/curs_instr(3) +insch/curs_insch(3) +insdelln/curs_deleteln(3) +insertln/curs_deleteln(3) +insnstr/curs_insstr(3) +insstr/curs_insstr(3) +instr/curs_instr(3) +intrflush/curs_inopts(3) +is_linetouched/curs_touch(3) +is_wintouched/curs_touch(3) +isendwin/curs_initscr(3) +keyname/curs_util(3) +keypad/curs_inopts(3) +killchar/curs_termattrs(3) +leaveok/curs_outopts(3) +longname/curs_termattrs(3) +mcprint/curs_print(3)* +meta/curs_inopts(3) +mouseinterval/curs_mouse(3)* +mousemask/curs_mouse(3)* +move/curs_move(3) +mvaddch/curs_addch(3) +mvaddchnstr/curs_addchstr(3) +mvaddchstr/curs_addchstr(3) +mvaddnstr/curs_addstr(3) +mvaddstr/curs_addstr(3) +mvcur/curs_terminfo(3) +mvdelch/curs_delch(3) +mvderwin/curs_window(3) +mvgetch/curs_getch(3) +mvgetstr/curs_getstr(3) +mvinch/curs_inch(3) +mvinchnstr/curs_inchstr(3) +mvinchstr/curs_inchstr(3) +mvinnstr/curs_instr(3) +mvinsch/curs_insch(3) +mvinsnstr/curs_insstr(3) +mvinsstr/curs_insstr(3) +mvinstr/curs_instr(3) +mvprintw/curs_printw(3) +mvscanw/curs_scanw(3) +mvwaddch/curs_addch(3) +mvwaddchnstr/curs_addchstr(3) +mvwaddchstr/curs_addchstr(3) +mvwaddnstr/curs_addstr(3) +mvwaddstr/curs_addstr(3) +mvwdelch/curs_delch(3) +mvwgetch/curs_getch(3) +mvwgetstr/curs_getstr(3) +mvwin/curs_window(3) +mvwinch/curs_inch(3) +mvwinchnstr/curs_inchstr(3) +mvwinchstr/curs_inchstr(3) +mvwinnstr/curs_instr(3) +mvwinsch/curs_insch(3) +mvwinsnstr/curs_insstr(3) +mvwinsstr/curs_insstr(3) +mvwinstr/curs_instr(3) +mvwprintw/curs_printw(3) +mvwscanw/curs_scanw(3) +napms/curs_kernel(3) +newpad/curs_pad(3) +newterm/curs_initscr(3) +newwin/curs_window(3) +nl/curs_outopts(3) +nocbreak/curs_inopts(3) +nodelay/curs_inopts(3) +noecho/curs_inopts(3) +nonl/curs_outopts(3) +noqiflush/curs_inopts(3) +noraw/curs_inopts(3) +notimeout/curs_inopts(3) +overlay/curs_overlay(3) +overwrite/curs_overlay(3) +pair_content/curs_color(3) +pechochar/curs_pad(3) +pnoutrefresh/curs_pad(3) +prefresh/curs_pad(3) +printw/curs_printw(3) +putp/curs_terminfo(3) +putwin/curs_util(3) +qiflush/curs_inopts(3) +raw/curs_inopts(3) +redrawwin/curs_refresh(3) +refresh/curs_refresh(3) +reset_prog_mode/curs_kernel(3) +reset_shell_mode/curs_kernel(3) +resetty/curs_kernel(3) resizeterm/resizeterm(3x)* -restartterm/curs_terminfo(3X) -ripoffline/curs_kernel(3X) -savetty/curs_kernel(3X) -scanw/curs_scanw(3X) -scr_dump/curs_scr_dump(3X) -scr_init/curs_scr_dump(3X) -scr_restore/curs_scr_dump(3X) -scr_set/curs_scr_dump(3X) -scrl/curs_scroll(3X) -scroll/curs_scroll(3X) -scrollok/curs_outopts(3X) -set_curterm/curs_terminfo(3X) -set_term/curs_initscr(3X) -setscrreg/curs_outopts(3X) -setsyx/curs_kernel(3X) -setterm/curs_terminfo(3X) -setupterm/curs_terminfo(3X) -slk_attr/curs_slk(3X)* -slk_attroff/curs_slk(3X) -slk_attron/curs_slk(3X) -slk_attrset/curs_slk(3X) -slk_clear/curs_slk(3X) -slk_init/curs_slk(3X) -slk_label/curs_slk(3X) -slk_noutrefresh/curs_slk(3X) -slk_refresh/curs_slk(3X) -slk_restore/curs_slk(3X) -slk_set/curs_slk(3X) -slk_touch/curs_slk(3X) -standend/curs_attr(3X) -standout/curs_attr(3X) -start_color/curs_color(3X) -subpad/curs_pad(3X) -subwin/curs_window(3X) -syncok/curs_window(3X) -termattrs/curs_termattrs(3X) -termname/curs_termattrs(3X) -tgetent/curs_termcap(3X) -tgetflag/curs_termcap(3X) -tgetnum/curs_termcap(3X) -tgetstr/curs_termcap(3X) -tgoto/curs_termcap(3X) -tigetflag/curs_terminfo(3X) -tigetnum/curs_terminfo(3X) -tigetstr/curs_terminfo(3X) -timeout/curs_inopts(3X) -touchline/curs_touch(3X) -touchwin/curs_touch(3X) -tparm/curs_terminfo(3X) -tputs/curs_termcap(3X) -tputs/curs_terminfo(3X) -typeahead/curs_inopts(3X) -unctrl/curs_util(3X) -ungetch/curs_getch(3X) -ungetmouse/curs_mouse(3X)* -untouchwin/curs_touch(3X) -use_env/curs_util(3X) -vidattr/curs_terminfo(3X) -vidputs/curs_terminfo(3X) -vline/curs_border(3X) -vwprintw/curs_printw(3X) -vwscanw/curs_scanw(3X) -waddch/curs_addch(3X) -waddchnstr/curs_addchstr(3X) -waddchstr/curs_addchstr(3X) -waddnstr/curs_addstr(3X) -waddstr/curs_addstr(3X) -wattroff/curs_attr(3X) -wattron/curs_attr(3X) -wattrset/curs_attr(3X) -wbkgd/curs_bkgd(3X) -wbkgdset/curs_bkgd(3X) -wborder/curs_border(3X) -wclear/curs_clear(3X) -wclrtobot/curs_clear(3X) -wclrtoeol/curs_clear(3X) -wcursyncup/curs_window(3X) -wdelch/curs_delch(3X) -wdeleteln/curs_deleteln(3X) -wechochar/curs_addch(3X) -wenclose/curs_mouse(3X)* -werase/curs_clear(3X) -wgetch/curs_getch(3X) -wgetnstr/curs_getstr(3X) -wgetstr/curs_getstr(3X) -whline/curs_border(3X) -winch/curs_inch(3X) -winchnstr/curs_inchstr(3X) -winchstr/curs_inchstr(3X) -winnstr/curs_instr(3X) -winsch/curs_insch(3X) -winsdelln/curs_deleteln(3X) -winsertln/curs_deleteln(3X) -winsnstr/curs_insstr(3X) -winsstr/curs_insstr(3X) -winstr/curs_instr(3X) -wmove/curs_move(3X) -wnoutrefresh/curs_refresh(3X) -wprintw/curs_printw(3X) -wredrawln/curs_refresh(3X) -wrefresh/curs_refresh(3X) +restartterm/curs_terminfo(3) +ripoffline/curs_kernel(3) +savetty/curs_kernel(3) +scanw/curs_scanw(3) +scr_dump/curs_scr_dump(3) +scr_init/curs_scr_dump(3) +scr_restore/curs_scr_dump(3) +scr_set/curs_scr_dump(3) +scrl/curs_scroll(3) +scroll/curs_scroll(3) +scrollok/curs_outopts(3) +set_curterm/curs_terminfo(3) +set_term/curs_initscr(3) +setscrreg/curs_outopts(3) +setsyx/curs_kernel(3) +setterm/curs_terminfo(3) +setupterm/curs_terminfo(3) +slk_attr/curs_slk(3)* +slk_attroff/curs_slk(3) +slk_attron/curs_slk(3) +slk_attrset/curs_slk(3) +slk_clear/curs_slk(3) +slk_init/curs_slk(3) +slk_label/curs_slk(3) +slk_noutrefresh/curs_slk(3) +slk_refresh/curs_slk(3) +slk_restore/curs_slk(3) +slk_set/curs_slk(3) +slk_touch/curs_slk(3) +standend/curs_attr(3) +standout/curs_attr(3) +start_color/curs_color(3) +subpad/curs_pad(3) +subwin/curs_window(3) +syncok/curs_window(3) +termattrs/curs_termattrs(3) +termname/curs_termattrs(3) +tgetent/curs_termcap(3) +tgetflag/curs_termcap(3) +tgetnum/curs_termcap(3) +tgetstr/curs_termcap(3) +tgoto/curs_termcap(3) +tigetflag/curs_terminfo(3) +tigetnum/curs_terminfo(3) +tigetstr/curs_terminfo(3) +timeout/curs_inopts(3) +touchline/curs_touch(3) +touchwin/curs_touch(3) +tparm/curs_terminfo(3) +tputs/curs_termcap(3) +tputs/curs_terminfo(3) +typeahead/curs_inopts(3) +unctrl/curs_util(3) +ungetch/curs_getch(3) +ungetmouse/curs_mouse(3)* +untouchwin/curs_touch(3) +use_env/curs_util(3) +vidattr/curs_terminfo(3) +vidputs/curs_terminfo(3) +vline/curs_border(3) +vwprintw/curs_printw(3) +vwscanw/curs_scanw(3) +waddch/curs_addch(3) +waddchnstr/curs_addchstr(3) +waddchstr/curs_addchstr(3) +waddnstr/curs_addstr(3) +waddstr/curs_addstr(3) +wattroff/curs_attr(3) +wattron/curs_attr(3) +wattrset/curs_attr(3) +wbkgd/curs_bkgd(3) +wbkgdset/curs_bkgd(3) +wborder/curs_border(3) +wclear/curs_clear(3) +wclrtobot/curs_clear(3) +wclrtoeol/curs_clear(3) +wcursyncup/curs_window(3) +wdelch/curs_delch(3) +wdeleteln/curs_deleteln(3) +wechochar/curs_addch(3) +wenclose/curs_mouse(3)* +werase/curs_clear(3) +wgetch/curs_getch(3) +wgetnstr/curs_getstr(3) +wgetstr/curs_getstr(3) +whline/curs_border(3) +winch/curs_inch(3) +winchnstr/curs_inchstr(3) +winchstr/curs_inchstr(3) +winnstr/curs_instr(3) +winsch/curs_insch(3) +winsdelln/curs_deleteln(3) +winsertln/curs_deleteln(3) +winsnstr/curs_insstr(3) +winsstr/curs_insstr(3) +winstr/curs_instr(3) +wmove/curs_move(3) +wnoutrefresh/curs_refresh(3) +wprintw/curs_printw(3) +wredrawln/curs_refresh(3) +wrefresh/curs_refresh(3) wresize/wresize(3x)* -wscanw/curs_scanw(3X) -wscrl/curs_scroll(3X) -wsetscrreg/curs_outopts(3X) -wstandend/curs_attr(3X) -wstandout/curs_attr(3X) -wsyncdown/curs_window(3X) -wsyncup/curs_window(3X) -wtimeout/curs_inopts(3X) -wtouchln/curs_touch(3X) -wvline/curs_border(3X) +wscanw/curs_scanw(3) +wscrl/curs_scroll(3) +wsetscrreg/curs_outopts(3) +wstandend/curs_attr(3) +wstandout/curs_attr(3) +wsyncdown/curs_window(3) +wsyncup/curs_window(3) +wtimeout/curs_inopts(3) +wtouchln/curs_touch(3) +wvline/curs_border(3) .TE .SH RETURN VALUE Routines that return an integer return \fBERR\fR upon failure and an @@ -473,11 +474,11 @@ display). See the EXTENSIONS sections of \fBcurs_addch\fR(3x) and \fBcurs_attr\fR(3x). The \fBcurses\fR library includes facilities for capturing mouse events on -certain terminals (including xterm). See the \fBcurs_mouse\fR(3X) +certain terminals (including xterm). See the \fBcurs_mouse\fR(3) manual page for details. The \fBcurses\fR library includes a function for directing application output -to a printer attached to the terminal device. See the \fBcurs_print\fR(3X) +to a printer attached to the terminal device. See the \fBcurs_print\fR(3) manual page for details. .SH PORTABILITY The \fBcurses\fR library is intended to be BASE-level conformant with the XSI @@ -575,21 +576,21 @@ the XSI Curses and \fBcurses\fR calls) are described in \fBPORTABILITY\fR sections of the library man pages. .PP The routine \fBhas_key\fR is not part of XPG4, nor is it present in SVr4. See -the \fBcurs_getch\fR(3X) manual page for details. +the \fBcurs_getch\fR(3) manual page for details. .PP The routine \fBslk_attr\fR is not part of XPG4, nor is it present in SVr4. See -the \fBcurs_slk\fR(3X) manual page for details. +the \fBcurs_slk\fR(3) manual page for details. .PP The routines \fBgetmouse\fR, \fBmousemask\fR, \fBungetmouse\fR, \fBmouseinterval\fR, and \fBwenclose\fR relating to mouse interfacing are not -part of XPG4, nor are they present in SVr4. See the \fBcurs_mouse\fR(3X) +part of XPG4, nor are they present in SVr4. See the \fBcurs_mouse\fR(3) manual page for details. .PP The routine \fBmcprint\fR was not present in any previous curses -implementation. See the \fBcurs_print\fR(3X) manual page for details. +implementation. See the \fBcurs_print\fR(3) manual page for details. .PP The routine \fBwresize\fR is not part of XPG4, nor is it present in SVr4. See -the \fBwresize\fR(3X) manual page for details. +the \fBwresize\fR(3) manual page for details. .PP In historic curses versions, delays embedded in the capabilities \fBcr\fR, \fBind\fR, \fBcub1\fR, \fBff\fR and \fBtab\fR activated corresponding delay diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 5710984870e..c44f4b198d1 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,3 +1,5 @@ +/* $OpenBSD: curses.h,v 1.5 1997/12/03 05:21:07 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * **************************************************************************** @@ -18,17 +20,24 @@ * * ***************************************************************************/ -/* Id: curses.h.in,v 1.44 1997/04/20 01:32:08 tom Exp $ */ +/* Id: curses.h.in,v 1.59 1997/11/15 22:02:42 tom Exp $ */ #ifndef __NCURSES_H #define __NCURSES_H + #define CURSES 1 #define CURSES_H 1 +/* This should be defined for the enhanced functionality to be visible. + * However, none of the wide-character (enhanced) functionality is implemented. + * So we do not define it (yet). +#define _XOPEN_CURSES 1 + */ + /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 4 #define NCURSES_VERSION_MINOR 1 -#define NCURSES_VERSION_PATCH 970515 +#define NCURSES_VERSION_PATCH 971129 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION @@ -52,9 +61,7 @@ typedef _CHTYPE_T_ chtype; #endif #else -#ifndef _UNCTRL_H -typedef unsigned long chtype; -#endif +typedef unsigned long chtype; #endif #include <stdio.h> @@ -93,26 +100,25 @@ extern "C" { /* * XSI attributes. In the ncurses implementation, they are identical to the - * A_ attributes because attr_t is just an int. The XSI Curses attr_* and - * wattr_* entry points are all mapped to attr* and wattr* entry points. + * A_ attributes. */ -#define WA_ATTRIBUTES 0xffffff00 -#define WA_NORMAL 0x00000000 -#define WA_STANDOUT 0x00010000 -#define WA_UNDERLINE 0x00020000 -#define WA_REVERSE 0x00040000 -#define WA_BLINK 0x00080000 -#define WA_DIM 0x00100000 -#define WA_BOLD 0x00200000 -#define WA_ALTCHARSET 0x00400000 -#define WA_INVIS 0x00800000 -#define WA_PROTECT 0x01000000 -#define WA_HORIZONTAL 0x02000000 /* XSI Curses attr -- not yet used */ -#define WA_LEFT 0x04000000 /* XSI Curses attr -- not yet used */ -#define WA_LOW 0x08000000 /* XSI Curses attr -- not yet used */ -#define WA_RIGHT 0x10000000 /* XSI Curses attr -- not yet used */ -#define WA_TOP 0x20000000 /* XSI Curses attr -- not yet used */ -#define WA_VERTICAL 0x40000000 /* XSI Curses attr -- not yet used */ +#define WA_ATTRIBUTES A_ATTRIBUTES +#define WA_NORMAL A_NORMAL +#define WA_STANDOUT A_STANDOUT +#define WA_UNDERLINE A_UNDERLINE +#define WA_REVERSE A_REVERSE +#define WA_BLINK A_BLINK +#define WA_DIM A_DIM +#define WA_BOLD A_BOLD +#define WA_ALTCHARSET A_ALTCHARSET +#define WA_INVIS A_INVIS +#define WA_PROTECT A_PROTECT +#define WA_HORIZONTAL A_HORIZONTAL +#define WA_LEFT A_LEFT +#define WA_LOW A_LOW +#define WA_RIGHT A_RIGHT +#define WA_TOP A_TOP +#define WA_VERTICAL A_VERTICAL /* colors */ extern int COLORS; @@ -156,7 +162,7 @@ extern chtype acs_map[]; #define ACS_DARROW (acs_map['.']) /* arrow pointing down */ #define ACS_UARROW (acs_map['-']) /* arrow pointing up */ #define ACS_BOARD (acs_map['h']) /* board of squares */ -#define ACS_LANTERN (acs_map['I']) /* lantern symbol */ +#define ACS_LANTERN (acs_map['i']) /* lantern symbol */ #define ACS_BLOCK (acs_map['0']) /* solid square block */ /* * These aren't documented, but a lot of System Vs have them anyway @@ -240,7 +246,16 @@ typedef struct cchar_t; #endif /* _XOPEN_SOURCE_EXTENDED */ -struct _win_st { +struct ldat +{ + chtype *text; /* text of the line */ + short firstchar; /* first changed character in the line */ + short lastchar; /* last changed character in the line */ + short oldindex; /* index of the line at last update */ +}; + +struct _win_st +{ short _cury, _curx; /* current cursor position */ /* window location and size */ @@ -265,15 +280,7 @@ struct _win_st { bool _use_keypad; /* process function keys into KEY_ symbols? */ int _delay; /* 0 = nodelay, <0 = blocking, >0 = delay */ - /* the actual line data */ - struct ldat - { - chtype *text; /* text of the line */ - short firstchar; /* first changed character in the line */ - short lastchar; /* last changed character in the line */ - short oldindex; /* index of the line at last update */ - } - *_line; + struct ldat *_line; /* the actual line data */ /* global screen state */ short _regtop; /* top line of scrolling region */ @@ -295,9 +302,13 @@ struct _win_st { short _yoffset; /* real begy is _begy + _yoffset */ }; -extern WINDOW *stdscr, *curscr, *newscr; +extern WINDOW *stdscr; +extern WINDOW *curscr; +extern WINDOW *newscr; -extern int LINES, COLS, TABSIZE; +extern int LINES; +extern int COLS; +extern int TABSIZE; /* * This global was an undocumented feature under AIX curses. @@ -305,9 +316,11 @@ extern int LINES, COLS, TABSIZE; extern int ESCDELAY; /* ESC expire time in milliseconds */ /* non-XSI extensions (dickey@clark.net) */ +extern int define_key (char *, int); +extern int keyok (int, bool); extern int resizeterm (int, int); -extern int wresize (WINDOW *, int, int); extern int use_default_colors (void); +extern int wresize (WINDOW *, int, int); extern char ttytype[]; /* needed for backward compatibility */ @@ -315,8 +328,9 @@ extern char ttytype[]; /* needed for backward compatibility */ * GCC (and some other compilers) define '__attribute__'; we're using this * macro to alert the compiler to flag inconsistencies in printf/scanf-like * function calls. Just in case '__attribute__' isn't defined, make a dummy. + * G++ doesn't accept it anyway. */ -#if !defined(__GNUC__) && !defined(__attribute__) +#if defined(__cplusplus) || (!defined(__GNUC__) && !defined(__attribute__)) #define __attribute__(p) /* nothing */ #endif @@ -394,6 +408,7 @@ extern int clearok(WINDOW *,bool); /* implemented */ extern int clrtobot(void); /* generated */ extern int clrtoeol(void); /* generated */ extern int color_content(short,short*,short*,short*); /* implemented */ +extern int color_set(short,void*); /* missing */ extern int COLOR_PAIR(int); /* generated */ extern int copywin(const WINDOW*,WINDOW*,int,int,int,int,int,int,int); /* implemented */ extern int curs_set(int); /* implemented */ @@ -411,6 +426,7 @@ extern int echo(void); /* implemented */ extern int echochar(const chtype); /* generated */ #ifdef _XOPEN_SOURCE_EXTENDED extern int echo_wchar(const cchar_t *); /* missing */ +extern int erasewchar(wchar_t*); /* missing */ #endif /* _XOPEN_SOURCE_EXTENDED */ extern int endwin(void); /* implemented */ extern char erasechar(void); /* implemented */ @@ -434,7 +450,7 @@ extern int getstr(char *); /* generated */ #ifdef _XOPEN_SOURCE_EXTENDED extern int get_wch(wint_t *); /* missing */ #endif /* _XOPEN_SOURCE_EXTENDED */ -extern WINDOW *getwin(FILE *); /* not in XPG4 */ +extern WINDOW *getwin(FILE *); /* implemented */ #ifdef _XOPEN_SOURCE_EXTENDED extern int get_wstr(wint_t *); /* missing */ #endif /* _XOPEN_SOURCE_EXTENDED */ @@ -628,7 +644,7 @@ extern int overlay(const WINDOW*,WINDOW *); /* implemented */ extern int overwrite(const WINDOW*,WINDOW *); /* implemented */ extern int pair_content(short,short*,short*); /* implemented */ extern int PAIR_NUMBER(int); /* generated */ -extern int pechochar(WINDOW *, chtype); /* implemented */ +extern int pechochar(WINDOW *, const chtype); /* implemented */ #ifdef _XOPEN_SOURCE_EXTENDED extern int pecho_wchar(WINDOW *, const cchar_t *); /* missing */ #endif /* _XOPEN_SOURCE_EXTENDED */ @@ -664,18 +680,12 @@ extern int setcchar(cchar_t *, wchar_t *, attr_t, short, const void *); /* missi extern int setscrreg(int,int); /* generated */ extern SCREEN *set_term(SCREEN *); /* implemented */ extern int slk_attroff(const attr_t); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern int slk_attr_off(attr_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_attr_off(attr_t); /* generated:WIDEC */ extern int slk_attron(const attr_t); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern int slk_attr_on(attr_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_attr_on(attr_t); /* generated:WIDEC */ extern int slk_attrset(const attr_t); /* implemented */ extern attr_t slk_attr(void); /* implemented */ -#ifdef _XOPEN_SOURCE_EXTENDED -extern int slk_attr_set(attr_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_attr_set(attr_t); /* generated:WIDEC */ extern int slk_clear(void); /* implemented */ extern int slk_init(int); /* implemented */ extern char *slk_label(int); /* implemented */ @@ -693,7 +703,8 @@ extern int start_color(void); /* implemented */ extern WINDOW *subpad(WINDOW *, int, int, int, int); /* implemented */ extern WINDOW *subwin(WINDOW *,int,int,int,int); /* implemented */ extern int syncok(WINDOW *, bool); /* implemented */ -extern attr_t termattrs(void); /* implemented */ +extern chtype termattrs(void); /* implemented */ +extern attr_t term_attrs(void); /* missing */ extern char *termname(void); /* implemented */ extern int tigetflag(const char *); /* implemented */ extern int tigetnum(const char *); /* implemented */ @@ -708,9 +719,7 @@ extern int untouchwin(WINDOW *); /* generated */ #ifndef EXTERN_TERMINFO extern int vidattr(chtype); /* implemented */ #endif -#ifdef _XOPEN_SOURCE_EXTENDED -extern int vid_attr(attr_t); /* missing */ -#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int vid_attr(attr_t); /* generated:WIDEC */ extern int vidputs(chtype, int (*)(int)); /* implemented */ #ifdef _XOPEN_SOURCE_EXTENDED extern int vid_puts(attr_t, int (*)(int)); /* missing */ @@ -742,7 +751,7 @@ extern int wattr_on(WINDOW *, const attr_t); /* implemented */ extern int wattr_off(WINDOW *, const attr_t); /* implemented */ extern int wattr_set(WINDOW *, attr_t); /* generated */ extern int wbkgd(WINDOW *,const chtype); /* implemented */ -extern void wbkgdset(WINDOW *,chtype); /* generated */ +extern void wbkgdset(WINDOW *,chtype); /* implemented */ #ifdef _XOPEN_SOURCE_EXTENDED extern int wbkgrndset(WINDOW *,const cchar_t *); /* missing */ extern int wbkgrnd(WINDOW *,const cchar_t *); /* missing */ @@ -755,6 +764,7 @@ extern int wchgat(WINDOW *, int, attr_t, short, const void *);/* implemented */ extern int wclear(WINDOW *); /* implemented */ extern int wclrtobot(WINDOW *); /* implemented */ extern int wclrtoeol(WINDOW *); /* implemented */ +extern int wcolor_set(WINDOW*,short,void*); /* missing */ extern void wcursyncup(WINDOW *); /* implemented */ extern int wdelch(WINDOW *); /* implemented */ extern int wdeleteln(WINDOW *); /* generated */ @@ -827,26 +837,44 @@ extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ #endif /* _XOPEN_SOURCE_EXTENDED */ /* attributes */ -#define A_ATTRIBUTES 0xffffff00 -#define A_NORMAL 0x00000000 -#define A_STANDOUT 0x00010000 -#define A_UNDERLINE 0x00020000 -#define A_REVERSE 0x00040000 -#define A_BLINK 0x00080000 -#define A_DIM 0x00100000 -#define A_BOLD 0x00200000 -#define A_ALTCHARSET 0x00400000 -#define A_INVIS 0x00800000 -#define A_PROTECT 0x01000000 -#define A_HORIZONTAL 0x02000000 /* XSI Curses attr -- not yet used */ -#define A_LEFT 0x04000000 /* XSI Curses attr -- not yet used */ -#define A_LOW 0x08000000 /* XSI Curses attr -- not yet used */ -#define A_RIGHT 0x10000000 /* XSI Curses attr -- not yet used */ -#define A_TOP 0x20000000 /* XSI Curses attr -- not yet used */ -#define A_VERTICAL 0x40000000 /* XSI Curses attr -- not yet used */ -#define A_CHARTEXT 0x000000ff -#define A_COLOR 0x0000ff00 -#define COLOR_PAIR(n) ((n) << 8) + +#define NCURSES_BITS(mask,shift) ((mask) << ((shift) + 8)) + +#define A_NORMAL 0L +#define A_ATTRIBUTES NCURSES_BITS(~(1UL - 1UL),0) +#define A_CHARTEXT (NCURSES_BITS(1UL,0) - 1UL) +#define A_COLOR NCURSES_BITS(((1UL) << 8) - 1UL,0) +#define A_STANDOUT NCURSES_BITS(1UL,8) +#define A_UNDERLINE NCURSES_BITS(1UL,9) +#define A_REVERSE NCURSES_BITS(1UL,10) +#define A_BLINK NCURSES_BITS(1UL,11) +#define A_DIM NCURSES_BITS(1UL,12) +#define A_BOLD NCURSES_BITS(1UL,13) +#define A_ALTCHARSET NCURSES_BITS(1UL,14) +#define A_INVIS NCURSES_BITS(1UL,15) + +/* Tradeoff on 32-bit machines ('protect' vs widec). The others (e.g., left + * highlight are not implemented in any terminal descriptions, anyway. + */ +#if ((16 + 8) < 32) +#define A_PROTECT NCURSES_BITS(1UL,16) +#define A_HORIZONTAL NCURSES_BITS(1UL,17) +#define A_LEFT NCURSES_BITS(1UL,18) +#define A_LOW NCURSES_BITS(1UL,19) +#define A_RIGHT NCURSES_BITS(1UL,20) +#define A_TOP NCURSES_BITS(1UL,21) +#define A_VERTICAL NCURSES_BITS(1UL,22) +#else +#define A_PROTECT 0L +#define A_HORIZONTAL 0L +#define A_LEFT 0L +#define A_LOW 0L +#define A_RIGHT 0L +#define A_TOP 0L +#define A_VERTICAL 0L +#endif + +#define COLOR_PAIR(n) NCURSES_BITS(n, 0) #define PAIR_NUMBER(a) (((a) & A_COLOR) >> 8) /* @@ -864,27 +892,28 @@ extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ #define nocrmode() nocbreak() #define gettmode() -#define getyx(win,y,x) (y = (win)->_cury, x = (win)->_curx) -#define getbegyx(win,y,x) (y = (win)->_begy, x = (win)->_begx) -#define getmaxyx(win,y,x) (y = (win)->_maxy + 1, x = (win)->_maxx + 1) -#define getparyx(win,y,x) (y = (win)->_pary, x = (win)->_parx) +#define getyx(win,y,x) (y = (win)?(win)->_cury:ERR, x = (win)?(win)->_curx:ERR) +#define getbegyx(win,y,x) (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR) +#define getmaxyx(win,y,x) (y = (win)?((win)->_maxy + 1):ERR, x = (win)?((win)->_maxx + 1):ERR) +#define getparyx(win,y,x) (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR) #define getsyx(y,x) getyx(stdscr, y, x) #define setsyx(y,x) (stdscr->_cury = y, stdscr->_curx = x) -#define wbkgdset(win, ch) \ - (((win)->_attrs = (((win)->_attrs & ~((win)->_bkgd & A_ATTRIBUTES)) | \ - ((ch) & A_ATTRIBUTES))), \ - ((win)->_bkgd = (ch))) - /* It seems older SYSV curses versions define these */ -#define getattrs(win) ((win)->_attrs) -#define getmaxx(win) ((win)->_maxx + 1) -#define getmaxy(win) ((win)->_maxy + 1) - -#define winch(win) ((win)->_line[(win)->_cury].text[(win)->_curx]) +#define getattrs(win) ((win)?(win)->_attrs:A_NORMAL) +#define getcurx(win) ((win)?(win)->_curx:ERR) +#define getcury(win) ((win)?(win)->_cury:ERR) +#define getbegx(win) ((win)?(win)->_begx:ERR) +#define getbegy(win) ((win)?(win)->_begy:ERR) +#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR) +#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR) +#define getparx(win) ((win)?(win)->_parx:ERR) +#define getpary(win) ((win)?(win)->_pary:ERR) + +#define winch(win) ((win)?(win)->_line[(win)->_cury].text[(win)->_curx]:0) #define wstandout(win) (wattr_set(win,A_STANDOUT)) #define wstandend(win) (wattr_set(win,A_NORMAL)) -#define wattr_set(win,at) ((win)->_attrs = (at)) +#define wattr_set(win,at) ((win)?((win)->_attrs = (at)):0) #define wattron(win,at) wattr_on(win, at) #define wattroff(win,at) wattr_off(win, at) @@ -892,9 +921,9 @@ extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ #define scroll(win) wscrl(win,1) -#define touchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 1) +#define touchwin(win) wtouchln((win), 0, getmaxy(win), 1) #define touchline(win, s, c) wtouchln((win), s, c, 1) -#define untouchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 0) +#define untouchwin(win) wtouchln((win), 0, getmaxy(win), 0) #define box(win, v, h) wborder(win, v, v, h, h, 0, 0, 0, 0) #define border(ls, rs, ts, bs, tl, tr, bl, br) wborder(stdscr, ls, rs, ts, bs, tl, tr, bl, br) @@ -1064,6 +1093,10 @@ extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ #define mvwinwstr(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winnwstr(stdscr,c,-1)) #define mvwvline_set(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline_set(win,c,n)) +#define slk_attr_off(a) slk_attroff(a) +#define slk_attr_on(a) slk_attron(a) +#define slk_attr_set(a) slk_attrset(a) +#define vid_attr(a) vidattr(a) #define vline_set(c,n) vhline_set(stdscr,c,n) #define waddwstr(win,wstr,n) waddnwstr(win,wstr,-1) #define wattr_get(win) ((win)->_attrs) @@ -1186,6 +1219,7 @@ extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ #define KEY_SUSPEND 0627 /* Suspend */ #define KEY_UNDO 0630 /* Undo */ #define KEY_MOUSE 0631 /* Mouse event has occurred */ +#define KEY_RESIZE 0632 /* Terminal resize event */ #define KEY_MAX 0777 /* Maximum key value */ /* mouse interface */ @@ -1243,7 +1277,7 @@ MEVENT; extern int getmouse(MEVENT *); extern int ungetmouse(MEVENT *); extern mmask_t mousemask(mmask_t, mmask_t *); -extern bool wenclose(WINDOW *, int, int); +extern bool wenclose(const WINDOW *, int, int); extern int mouseinterval(int); /* other non-XSI functions */ @@ -1282,6 +1316,7 @@ extern void trace(const unsigned int); #if defined(TRACE) || defined(NCURSES_TEST) extern int _nc_optimize_enable; /* enable optimizations */ +extern const char *_nc_visbuf(const char *); #define OPTIMIZE_MVCUR 0x01 /* cursor movement optimization */ #define OPTIMIZE_HASHMAP 0x02 /* diff hashing to detect scrolls */ #define OPTIMIZE_SCROLL 0x04 /* scroll optimization */ diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index b638a6ec182..d6c99a4e8cb 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,3 +1,5 @@ +/* $OpenBSD: curses.priv.h,v 1.3 1997/12/03 05:21:07 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -21,7 +23,7 @@ /* - * Id: curses.priv.h,v 1.61 1997/04/26 20:54:54 tom Exp $ + * Id: curses.priv.h,v 1.93 1997/11/01 23:01:54 tom Exp $ * * curses.priv.h * @@ -33,9 +35,13 @@ #ifndef CURSES_PRIV_H #define CURSES_PRIV_H 1 +#ifdef __cplusplus +extern "C" { +#endif + #include <ncurses_cfg.h> -#ifdef USE_RCS_IDS +#if USE_RCS_IDS #define MODULE_ID(id) static const char Ident[] = id; #else #define MODULE_ID(id) /*nothing*/ @@ -74,10 +80,12 @@ #include <errno.h> -#if !HAVE_EXTERN_ERRNO +#if DECL_ERRNO extern int errno; #endif +#include <nc_panel.h> + /* Some systems have a broken 'select()', but workable 'poll()'. Use that */ #if HAVE_POLL && HAVE_SYS_STROPTS_H && HAVE_POLL_H #define USE_FUNC_POLL 1 @@ -92,18 +100,31 @@ extern int errno; #define USE_GPM_SUPPORT 0 #endif +#define DEFAULT_MAXCLICK 166 + /* - * ht/cbt expansion flakes out randomly under Linux 1.1.47, but only when - * we're throwing control codes at the screen at high volume. To see this, - * re-enable TABS_OK and run worm for a while. Other systems probably don't - * want to define this either due to uncertainties about tab delays and - * expansion in raw mode. + * As currently coded, hashmap relies on the scroll-hints logic. */ -#undef TABS_OK /* OK to use tab/backtab for local motions? */ +#if !USE_SCROLL_HINTS +#if USE_HASHMAP +#define USE_SCROLL_HINTS 1 +#else +#define USE_SCROLL_HINTS 0 +#endif +#endif + +#if USE_SCROLL_HINTS +#define if_USE_SCROLL_HINTS(stmt) stmt +#else +#define if_USE_SCROLL_HINTS(stmt) /*nothing*/ +#endif /* - * The internal types (e.g., struct screen) must precede <curses.h>, otherwise - * we cannot construct lint-libraries (structures must be fully-defined). + * Note: ht/cbt expansion flakes out randomly under Linux 1.1.47, but only + * when we're throwing control codes at the screen at high volume. To see + * this, re-enable USE_HARD_TABS and run worm for a while. Other systems + * probably don't want to define this either due to uncertainties about tab + * delays and expansion in raw mode. */ struct tries { @@ -114,30 +135,6 @@ struct tries { }; /* - * Structure for soft labels. - */ - -typedef struct -{ - char *text; /* text for the label */ - char *form_text; /* formatted text (left/center/...) */ - int x; /* x coordinate of this field */ - char dirty; /* this label has changed */ - char visible; /* field is visible */ -} slk_ent; - -typedef struct { - char dirty; /* all labels have changed */ - char hidden; /* soft labels are hidden */ - struct _win_st *win; - slk_ent *ent; - char *buffer; /* buffer for labels */ - short maxlab; /* number of available labels */ - short labcnt; /* number of allocated labels */ - short maxlen; /* length of labels */ -} SLK; - -/* * Definitions for color pairs */ #define C_SHIFT 8 /* we need more bits than there are colors */ @@ -157,7 +154,38 @@ color_t; #define MAXCOLUMNS 135 #define MAXLINES 66 -#define FIFO_SIZE MAXLINES +#define FIFO_SIZE MAXCOLUMNS+2 /* for nocbreak mode input */ + +#define ACS_LEN 128 + +#define WINDOWLIST struct _win_list + +#include <curses.h> /* we'll use -Ipath directive to get the right one! */ + +/* + * Structure for soft labels. + */ + +typedef struct +{ + char *text; /* text for the label */ + char *form_text; /* formatted text (left/center/...) */ + int x; /* x coordinate of this field */ + char dirty; /* this label has changed */ + char visible; /* field is visible */ +} slk_ent; + +typedef struct { + char dirty; /* all labels have changed */ + char hidden; /* soft labels are hidden */ + struct _win_st *win; + slk_ent *ent; + char* buffer; /* buffer for labels */ + short maxlab; /* number of available labels */ + short labcnt; /* number of allocated labels */ + short maxlen; /* length of labels */ + chtype attr; /* soft label attribute */ +} SLK; struct screen { int _ifd; /* input file ptr for screen */ @@ -173,14 +201,20 @@ struct screen { short _columns; /* screen columns */ short _lines_avail; /* lines available for stdscr */ short _topstolen; /* lines stolen from top */ - struct _win_st *_curscr; /* current screen */ - struct _win_st *_newscr; /* virtual screen to be updated to */ - struct _win_st *_stdscr; /* screen's full-window context */ + + WINDOW *_curscr; /* current screen */ + WINDOW *_newscr; /* virtual screen to be updated to */ + WINDOW *_stdscr; /* screen's full-window context */ + struct tries *_keytry; /* "Try" for use with keypad mode */ + struct tries *_key_ok; /* Disabled keys via keyok(,FALSE) */ + unsigned int _fifo[FIFO_SIZE]; /* input push-back buffer */ - signed char _fifohead, /* head of fifo queue */ + short _fifohead, /* head of fifo queue */ _fifotail, /* tail of fifo queue */ - _fifopeek; /* where to peek for next char */ + _fifopeek, /* where to peek for next char */ + _fifohold; /* set if breakout marked */ + int _endwin; /* are we out of window mode? */ unsigned long _current_attr; /* terminal attribute current set */ int _coloron; /* is color enabled? */ @@ -194,7 +228,7 @@ struct screen { int _echo; /* True if echo on */ int _use_meta; /* use the meta key? */ SLK *_slk; /* ptr to soft key struct / NULL */ - int _baudrate; /* used to compute padding */ + int _baudrate; /* used to compute padding */ /* cursor movement costs; units are 10ths of milliseconds */ int _char_padding; /* cost of character put */ @@ -202,10 +236,10 @@ struct screen { int _cup_cost; /* cost of (cursor_address) */ int _home_cost; /* cost of (cursor_home) */ int _ll_cost; /* cost of (cursor_to_ll) */ -#ifdef TABS_OK +#if USE_HARD_TABS int _ht_cost; /* cost of (tab) */ int _cbt_cost; /* cost of (backtab) */ -#endif /* TABS_OK */ +#endif /* USE_HARD_TABS */ int _cub1_cost; /* cost of (cursor_left) */ int _cuf1_cost; /* cost of (cursor_right) */ int _cud1_cost; /* cost of (cursor_down) */ @@ -233,22 +267,67 @@ struct screen { int _carriage_return_length; int _cursor_home_length; int _cursor_to_ll_length; + /* used in lib_color.c */ color_t *_color_table; /* screen's color palette */ int _color_count; /* count of colors in palette */ unsigned short *_color_pairs; /* screen's color pair list */ int _pair_count; /* count of color pairs */ int _default_color; /* use default colors */ + chtype _xmc_suppress; /* attributes to suppress if xmc */ + chtype _xmc_triggers; /* attributes to process if xmc */ + chtype _acs_map[ACS_LEN]; + + /* + * These data correspond to the state of the idcok() and idlok() + * functions. A caveat is in order here: the XSI and SVr4 + * documentation specify that these functions apply to the window which + * is given as an argument. However, ncurses implements this logic + * only for the newscr/curscr update process, _not_ per-window. + */ + bool _nc_sp_idlok; + bool _nc_sp_idcok; +#define _nc_idlok SP->_nc_sp_idlok +#define _nc_idcok SP->_nc_sp_idcok + + /* + * These are the data that support the mouse interface. + */ + int _maxclick; + bool (*_mouse_event) (SCREEN *); + bool (*_mouse_inline)(SCREEN *); + bool (*_mouse_parse) (int); + void (*_mouse_resume)(SCREEN *); + void (*_mouse_wrap) (SCREEN *); + int _mouse_fd; /* file-descriptor, if any */ + + /* + * This supports automatic resizing + */ + int (*_resize)(int,int); + + /* + * These are data that support the proper handling of the panel stack on an + * per screen basis. + */ + struct panelhook _panelHook; + /* + * Linked-list of all windows, to support '_nc_resizeall()' and + * '_nc_freeall()' + */ + WINDOWLIST *_nc_sp_windows; +#define _nc_windows SP->_nc_sp_windows + + bool _sig_winch; + SCREEN *_next_screen; }; -/* Ncurses' public interface follows the internal types */ -#include <curses.h> /* we'll use -Ipath directive to get the right one! */ +extern SCREEN *_nc_screen_chain; #ifdef NCURSES_NOMACROS #include <nomacros.h> #endif -#define WINDOWLIST struct _win_list WINDOWLIST { WINDOWLIST *next; WINDOW *win; @@ -308,6 +387,7 @@ typedef struct { #define CHANGED -1 +#define SIZEOF(v) (sizeof(v)/sizeof(v[0])) #define typeCalloc(type,elts) (type *)calloc(elts,sizeof(type)) #define FreeIfNeeded(p) if(p != 0) free(p) #define FreeAndNull(p) free(p); p = 0 @@ -328,38 +408,38 @@ typedef struct { #define T(a) TR(TRACE_CALLS, a) #define TPUTS_TRACE(s) _nc_tputs_trace = s; #define TRACE_RETURN(value,type) return _nc_retrace_##type(value) -#define returnWin(code) TRACE_RETURN(code,win) -#define returnPtr(code) TRACE_RETURN(code,ptr) +#define returnAttr(code) TRACE_RETURN(code,attr_t) #define returnCode(code) TRACE_RETURN(code,int) +#define returnPtr(code) TRACE_RETURN(code,ptr) #define returnVoid T((T_RETURN(""))); return +#define returnWin(code) TRACE_RETURN(code,win) extern unsigned _nc_tracing; extern WINDOW * _nc_retrace_win(WINDOW *); +extern attr_t _nc_retrace_attr_t(attr_t); extern char *_nc_retrace_ptr(char *); extern const char *_nc_tputs_trace; extern const char *_nc_visbuf(const char *); extern const char *_nc_visbuf2(int, const char *); extern int _nc_retrace_int(int); extern long _nc_outchars; +extern void _nc_fifo_dump(void); #else #define T(a) #define TR(n, a) #define TPUTS_TRACE(s) -#define returnWin(code) return code +#define returnAttr(code) return code #define returnCode(code) return code +#define returnPtr(code) return code #define returnVoid return +#define returnWin(code) return code #endif #define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch)) #define ALL_BUT_COLOR ((chtype)~(A_COLOR)) #define IGNORE_COLOR_OFF FALSE - - -/* Macro to put together character and attribute info and return it. - If colors are in the attribute, they have precedence. */ -#define ch_or_attr(ch,at) \ - ((PAIR_NUMBER(at) > 0) ? \ - ((((chtype)ch) & ALL_BUT_COLOR) | (at)) : ((((chtype)ch) | (at)))) +#define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK) +#define XMC_CHANGES(c) ((c) & SP->_xmc_suppress) #define toggle_attr_on(S,at) \ @@ -398,8 +478,23 @@ extern long _nc_outchars; ? (SP->_ich1_cost * count) \ : INFINITY)) +#if USE_XMC_SUPPORT +#define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) { \ + attr_t chg = SP->_current_attr; \ + vidattr(AttrOf(c)); \ + if (magic_cookie_glitch > 0 \ + && XMC_CHANGES((chg ^ SP->_current_attr))) { \ + T(("%s @%d before glitch %d,%d", \ + __FILE__, __LINE__, \ + SP->_cursrow, \ + SP->_curscol)); \ + _nc_do_xmc_glitch(chg); \ + } \ + } +#else #define UpdateAttrs(c) if (SP->_current_attr != AttrOf(c)) \ vidattr(AttrOf(c)); +#endif /* * Check whether the given character can be output by clearing commands. This @@ -407,16 +502,11 @@ extern long _nc_outchars; * as A_REVERSE. All attribute flags which don't affect appearance of a space * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded. */ -#define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK) #define can_clear_with(ch) \ ((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK) #ifdef NCURSES_EXPANDED -#undef ch_or_attr -#define ch_or_attr(ch,at) _nc_ch_or_attr(ch,at) -extern chtype _nc_ch_or_attr(chtype, attr_t); - #undef toggle_attr_on #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at) extern void _nc_toggle_attr_on(attr_t *, attr_t); @@ -447,8 +537,27 @@ extern void _nc_expanded(void); #endif +/* comp_scan.c */ +extern char _nc_trans_string(char *); /* used by 'tack' program */ + +/* doupdate.c */ +#if USE_XMC_SUPPORT +extern void _nc_do_xmc_glitch(attr_t); +#endif + +/* hardscroll.c */ +#if defined(TRACE) || defined(SCROLLDEBUG) +extern void _nc_linedump(void); +#endif + +/* hardscroll.c */ +#if defined(TRACE) || defined(SCROLLDEBUG) +extern void _nc_linedump(void); +#endif + /* lib_acs.c */ extern void init_acs(void); /* no prefix, this name is traditional */ +extern int _nc_msec_cost(const char *const, int); /* used by 'tack' program */ /* lib_mvcur.c */ #define INFINITY 1000000 /* cost: too high to use */ @@ -456,24 +565,33 @@ extern void init_acs(void); /* no prefix, this name is traditional */ extern void _nc_mvcur_init(void); extern void _nc_mvcur_resume(void); extern void _nc_mvcur_wrap(void); -extern int _nc_mvcur_scrolln(int, int, int, int); + +extern int _nc_scrolln(int, int, int, int); + +extern void _nc_screen_init(void); +extern void _nc_screen_resume(void); +extern void _nc_screen_wrap(void); /* lib_mouse.c */ -extern void _nc_mouse_init(SCREEN *); -extern bool _nc_mouse_event(SCREEN *); -extern bool _nc_mouse_inline(SCREEN *); -extern bool _nc_mouse_parse(int); -extern void _nc_mouse_wrap(SCREEN *); -extern void _nc_mouse_resume(SCREEN *); -extern int _nc_max_click_interval; -extern int _nc_mouse_fd(void); +extern int _nc_has_mouse(void); + +/* safe_sprintf.c */ +extern char * _nc_printf_string(const char *fmt, va_list ap); + +/* softscroll.c */ +extern void _nc_setup_scroll(void); +extern void _nc_perform_scroll(void); + +/* tries.c */ +extern void _nc_add_to_try(struct tries **tree, char *str, unsigned short code); +extern char *_nc_expand_try(struct tries *tree, unsigned short code, size_t len); +extern int _nc_remove_key(struct tries **tree, unsigned short code); /* elsewhere ... */ extern WINDOW *_nc_makenew(int, int, int, int, int); +extern char *_nc_trace_buf(int, size_t); extern chtype _nc_background(WINDOW *); extern chtype _nc_render(WINDOW *, chtype); -extern char *_nc_trace_buf(int, size_t); -extern int _nc_initscr(void); extern int _nc_keypad(bool); #ifdef EXTERN_TERMINFO #define _nc_outch _ti_outc @@ -482,19 +600,18 @@ extern int _nc_outch(int); extern int _nc_setupscreen(short, short const, FILE *); extern int _nc_timed_wait(int, int, int *); extern int _nc_waddch_nosync(WINDOW *, const chtype); -extern void _nc_backspace(WINDOW *win); extern void _nc_do_color(int, int (*)(int)); -extern void _nc_freeall(void); extern void _nc_free_and_exit(int); +extern void _nc_freeall(void); extern void _nc_freewin(WINDOW *win); -extern void _nc_get_screensize(void); extern void _nc_hash_map(void); extern void _nc_outstr(const char *str); extern void _nc_scroll_optimize(void); -extern void _nc_scroll_window(WINDOW *, int const, short const, short const); +extern void _nc_scroll_window(WINDOW *, int const, short const, short const, chtype); extern void _nc_set_buffer(FILE *ofp, bool buffered); extern void _nc_signal_handler(bool); extern void _nc_synchook(WINDOW *win); +extern void _nc_update_screensize(void); /* * On systems with a broken linker, define 'SP' as a function to force the @@ -510,6 +627,7 @@ extern SCREEN *_nc_screen(void); extern int _nc_alloc_screen(void); extern void _nc_set_screen(SCREEN *); #else +/* current screen is private data; avoid possible linking conflicts too */ extern SCREEN *SP; #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0) #define _nc_set_screen(sp) SP = sp @@ -521,12 +639,12 @@ extern int _nc_usleep(unsigned int); #endif /* - * ncurses' term.h defines this but since we use our own terminfo - * we need to define it here. + * ncurses' terminfo defines these but since we use our own terminfo + * we need to fake it here. */ #ifdef EXTERN_TERMINFO -#define GET_TTY(fd, buf) tcgetattr(fd, buf) -#define SET_TTY(fd, buf) tcsetattr(fd, TCSADRAIN, buf) +#define _nc_get_curterm(buf) tcgetattr(cur_term->Filedes, buf) +#define _nc_set_curterm(buf) tcsetattr(cur_term->Filedes, TCSADRAIN, buf) #endif /* @@ -541,6 +659,17 @@ extern int _nc_usleep(unsigned int); extern int _nc_slk_format; /* != 0 if slk_init() called */ extern int _nc_slk_initialize(WINDOW *, int); +/* + * Some constants related to SLK's + */ +#define MAX_SKEY_OLD 8 /* count of soft keys */ +#define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */ +#define MAX_SKEY_PC 12 /* This is what most PC's have */ +#define MAX_SKEY_LEN_PC 5 + +#define MAX_SKEY (SLK_STDFMT ? MAX_SKEY_OLD : MAX_SKEY_PC) +#define MAX_SKEY_LEN (SLK_STDFMT ? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC) + /* Macro to check whether or not we use a standard format */ #define SLK_STDFMT (_nc_slk_format < 3) /* Macro to determine height of label window */ @@ -550,8 +679,8 @@ extern int _nc_ripoffline(int line, int (*init)(WINDOW *,int)); #define UNINITIALISED ((struct tries * ) -1) -extern bool _nc_idlok, _nc_idcok; - -extern WINDOWLIST *_nc_windows; +#ifdef __cplusplus +} +#endif #endif /* CURSES_PRIV_H */ diff --git a/lib/libcurses/define_key.c b/lib/libcurses/define_key.c new file mode 100644 index 00000000000..20909144c17 --- /dev/null +++ b/lib/libcurses/define_key.c @@ -0,0 +1,44 @@ +/* $OpenBSD: define_key.c,v 1.1 1997/12/03 05:21:08 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. THE ABOVE LISTED * + * COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * + * EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY * + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("Id: define_key.c,v 1.1 1997/05/29 09:56:26 tom Exp $") + +int +define_key(char *str, int keycode) +{ + int code = ERR; + + T((T_CALLED("define_key(%s,%d)"), _nc_visbuf(str), keycode)); + if (keycode > 0) { + if (has_key(keycode)) { + if (_nc_remove_key(&(SP->_keytry), keycode)) + code = OK; + } + if (str != 0) { + (void) _nc_add_to_try(&(SP->_keytry), str, keycode); + code = OK; + } + } + returnCode(code); +} diff --git a/lib/libcurses/fifo_defs.h b/lib/libcurses/fifo_defs.h new file mode 100644 index 00000000000..1e445612f65 --- /dev/null +++ b/lib/libcurses/fifo_defs.h @@ -0,0 +1,49 @@ +/* $OpenBSD: fifo_defs.h,v 1.1 1997/12/03 05:21:08 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * Common macros for lib_getch.c, lib_ungetch.c + * + * Id: fifo_defs.h,v 1.1 1997/10/19 02:31:46 tom Exp $ + */ + +#ifndef FIFO_DEFS_H +#define FIFO_DEFS_H 1 + +#define head SP->_fifohead +#define tail SP->_fifotail +/* peek points to next uninterpreted character */ +#define peek SP->_fifopeek + +#define h_inc() { head == FIFO_SIZE-1 ? head = 0 : head++; if (head == tail) head = -1, tail = 0;} +#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;} +#define t_inc() { tail == FIFO_SIZE-1 ? tail = 0 : tail++; if (tail == head) tail = -1;} +#define t_dec() { tail == 0 ? tail = FIFO_SIZE-1 : tail--; if (head == tail) fifo_clear();} +#define p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;} + +#define cooked_key_in_fifo() (head!=-1 && peek!=head) +#define raw_key_in_fifo() (head!=-1 && peek!=tail) + +#undef HIDE_EINTR + +#endif /* FIFO_DEFS_H */ diff --git a/lib/libcurses/hardscroll.c b/lib/libcurses/hardscroll.c index 6da4aac9d81..c77560461f5 100644 --- a/lib/libcurses/hardscroll.c +++ b/lib/libcurses/hardscroll.c @@ -1,3 +1,5 @@ +/* $OpenBSD: hardscroll.c,v 1.6 1997/12/03 05:21:08 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -92,59 +94,9 @@ be moved out of order. THE ALGORITHM -First, mark each line on the real screen that is *not* carried over to the -virtual screen discarded (that is, with a -1 oldnum index). - -Second, optionally run through each virtual line with a non -1 oldnum. If the -line is sufficiently changed, mark it -1 (we don't want to move it). The exact -test for "sufficiently changed" is not relevant to the control flow of this -algorithm. Cases the test should detect are those in which rewriting -the line from whatever might be on the real screen would be cheaper than the -move. Blank lines on a terminal with clear-to-eol probably meet this test. - -Here is pseudo-code for the remainder of the algorithm: - - repeat -1: first = 0; -2: no_hunk_moved = TRUE; - - # on each pass, try to find a movable hunk -3: while (first < screen_depth) - - # scan for start of hunk -4: while (oldnum field of first == -1) - first++ - - # if we have no hunk, quit this pass -5: if (first >= screen_depth) - break; - - # we found a hunk -6: last = (end of longest continues oldnum range starting here) - -7: ofirst = (first line's oldnum, where it was on real screen) -8: olast = (last line's oldnum, where it was on real screen) - - # figure the hunk's displacement -9: disp = first - (first virtual line's oldnum field) - - # does the hunk want to move? -10: if (disp != 0) - # is the hunk movable without destroying info? -11: if (real [ofirst+disp, olast+disp] are all in range or DISCARDED) -12: if (disp > 0) -13: scroll real [ofirst, olast+disp] down by disp - (mark [ofirst, olast+disp] DISCARDED) -14: else if (disp < 0) -15: scroll real [ofirst+disp, olast] up by disp - (mark [ofirst+disp, olast] DISCARDED) -16: no_hunk_moved = FALSE - - # done trying to move this hunk -17: first = last + 1; - end while - until -18: no_hunk_moved; # quit when a complete pass finds no movable hunks +The scrolling is done in two passes. The first pass is from top to bottom +scroling hunks UP. The second one is from bottom to top scrolling hunks DOWN. +Obviously enough, no lines to be scrolled will be destroyed. (lav) HOW TO TEST THIS: @@ -178,203 +130,115 @@ a representative sample of cases: AUTHOR Eric S. Raymond <esr@snark.thyrsus.com>, November 1994 + New algorithm by Alexander V. Lukyanov <lav@yars.free.net>, Aug 1997 *****************************************************************************/ #include <curses.priv.h> -MODULE_ID("Id: hardscroll.c,v 1.17 1997/02/15 22:33:12 tom Exp $") - -#if defined(TRACE) || defined(SCROLLDEBUG) -void _nc_linedump(void); -#endif /* defined(TRACE) || defined(SCROLLDEBUG) */ - -/* if only this number of lines is carried over, nuke the screen and redraw */ -#define CLEAR_THRESHOLD 3 +MODULE_ID("Id: hardscroll.c,v 1.28 1997/10/26 21:56:41 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) -#define LINES 24 -int oldnums[LINES], reallines[LINES]; +int oldnums[MAXLINES]; #define OLDNUM(n) oldnums[n] -#define REAL(m) reallines[m] #undef T #define T(x) (void) printf x ; (void) putchar('\n'); #else #include <curses.h> #define OLDNUM(n) newscr->_line[n].oldindex -#define REAL(m) curscr->_line[m].oldindex #ifndef _NEWINDEX #define _NEWINDEX -1 #endif /* _NEWINDEX */ #endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */ -static bool all_discarded(int const top, int const bottom, int const disp) -/* has the given range of real lines been marked discarded? */ -{ - int n; - - for (n = top + disp; n <= bottom + disp; n++) - if (REAL(n) != _NEWINDEX && !(REAL(n) <= bottom && REAL(n) >= top)) - return(FALSE); - - return(TRUE); -} void _nc_scroll_optimize(void) /* scroll optimization to transform curscr to newscr */ { - bool no_hunk_moved; /* no hunk moved on this pass? */ - int n, new_lines; -#if defined(TRACE) || defined(SCROLLDEBUG) - int pass = 0; -#endif /* defined(TRACE) || defined(SCROLLDEBUG) */ + int i; + int start, end, shift; TR(TRACE_ICALLS, ("_nc_scroll_optimize() begins")); - /* mark any line not carried over with _NEWINDEX */ - for (n = 0; n < LINES; n++) - REAL(n) += (MAXLINES + 1); - for (n = 0; n < LINES; n++) - if (OLDNUM(n) != _NEWINDEX - && REAL(OLDNUM(n)) >= MAXLINES) - REAL(OLDNUM(n)) -= (MAXLINES + 1); - for (n = new_lines = 0; n < LINES; n++) - if (REAL(n) > MAXLINES) - { - REAL(n) = _NEWINDEX; - new_lines++; - } - - /* - * ^F in vi (which scrolls forward by LINES-2 in the file) exposes - * a weakness in this design. Ideally, vertical motion - * optimization should cost its actions and then force a - * ClrUpdate() and complete redraw if that would be faster than - * the scroll. Unfortunately, this would be a serious pain to - * arrange; hence, this hack. If there are few enough lines - * carried over, don't bother with the scrolling, we just nuke the - * screen and redraw the whole thing. Keith Bostic argues that - * this will be a win on strictly visual grounds even if the - * resulting update is theoretically sub-optimal. Experience - * with vi says he's probably right. - */ - if (LINES - new_lines <= CLEAR_THRESHOLD) - { - T(("too few lines carried over, nuking screen")); -#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) - clearok(stdscr, TRUE); -#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ - return; - } - #ifdef TRACE - TR(TRACE_UPDATE | TRACE_MOVE, ("After real line marking:")); if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) _nc_linedump(); #endif /* TRACE */ - /* time to shuffle lines to do scroll optimization */ - do { - int first; /* first line of current hunk */ - int last; /* last line of current hunk */ - int ofirst; /* oldnum index of first line */ - int olast; /* oldnum index of last line */ - int disp; /* hunk displacement */ - - TR(TRACE_UPDATE | TRACE_MOVE, ("Pass %d:", pass++)); - - first = 0; /* start scan at top line */ - no_hunk_moved = TRUE; - - while (first < LINES) - { - /* find the beginning of a hunk */ - while (first < LINES && OLDNUM(first) == _NEWINDEX) - first++; - if (first >= LINES) - break; - - /* find the end of the hunk */ - for (last = first; last < LINES; last++) - if (last == LINES - 1 || OLDNUM(last + 1) != OLDNUM(last) + 1) - break; - - /* find the corresponding range on the old screen */ - ofirst = OLDNUM(first); - olast = OLDNUM(last); - - /* compute the hunk's displacement */ - disp = first - OLDNUM(first); - - TR(TRACE_UPDATE | TRACE_MOVE, ("found hunk: first = %2d, last = %2d, ofirst = %2d, olast = %2d, disp = %2d", - first, last, ofirst, olast, disp)); - - /* OK, time to try to move the hunk? */ - if (disp != 0) - if (all_discarded(ofirst, olast, disp)) - { - int m; - - if (disp > 0) - olast += disp; - else /* (disp < 0) */ - ofirst += disp; - - TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", ofirst, olast, -disp)); + /* pass 1 - from top to bottom scrolling up */ + for (i = 0; i < screen_lines; ) + { + while (i < screen_lines && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) <= i)) + i++; + if (i >= screen_lines) + break; + + shift = OLDNUM(i) - i; /* shift > 0 */ + start = i; + + i++; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + end = i-1 + shift; + + TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift)); #if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) - if (_nc_mvcur_scrolln(-disp, ofirst, olast, LINES - 1) == ERR) - break; - _nc_scroll_window(curscr, -disp, ofirst, olast); + if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) + { + TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll")); + continue; + } #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + } - for (m = ofirst; m <= olast; m++) - { - REAL(m) = _NEWINDEX; + /* pass 2 - from bottom to top scrolling down */ + for (i = screen_lines-1; i >= 0; ) + { + while (i >= 0 && (OLDNUM(i) == _NEWINDEX || OLDNUM(i) >= i)) + i--; + if (i < 0) + break; + + shift = OLDNUM(i) - i; /* shift < 0 */ + end = i; + + i--; + while (i >= 0 && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i--; + start = i+1 - (-shift); + + TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift)); #if !defined(SCROLLDEBUG) && !defined(HASHDEBUG) - /* - * This will tell the second stage of the optimizer - * that every line in the hunk on the real screen has - * been changed. - */ - curscr->_line[m].firstchar = 0; - curscr->_line[m].lastchar = curscr->_maxx; -#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ - } - for (m = first; m <= last; m++) - OLDNUM(m) = _NEWINDEX; - - no_hunk_moved = FALSE; - } - - /* OK, done with this hunk */ - first = last + 1; + if (_nc_scrolln(shift, start, end, screen_lines - 1) == ERR) + { + TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll")); + continue; } - } while - (!no_hunk_moved); +#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ + } } #if defined(TRACE) || defined(SCROLLDEBUG) void _nc_linedump(void) /* dump the state of the real and virtual oldnum fields */ { + static size_t have; + static char *buf; + int n; - char *buf; + size_t want = (screen_lines + 1) * 4; - /* We assume an int is at most 32 bits in size. */ - if ((buf = malloc((LINES * 12) + 5)) == NULL) { - errno = ENOMEM; - returnCode(ERR); - } - (void) strcpy(buf, "real"); - for (n = 0; n < LINES; n++) - (void) sprintf(buf + strlen(buf), " %02d", REAL(n)); - TR(TRACE_UPDATE | TRACE_MOVE, (buf)); + if (have < want) + buf = malloc(have = want); (void) strcpy(buf, "virt"); - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n)); TR(TRACE_UPDATE | TRACE_MOVE, (buf)); +#if NO_LEAKS free(buf); + have = 0; +#endif } #endif /* defined(TRACE) || defined(SCROLLDEBUG) */ @@ -387,16 +251,13 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) #ifdef TRACE _nc_tracing = TRACE_MOVE; -#endif /* TRACE */ +#endif for (;;) { int n; - for (n = 0; n < LINES; n++) - { - reallines[n] = n; + for (n = 0; n < screen_lines; n++) oldnums[n] = _NEWINDEX; - } /* grab the test vector */ if (fgets(line, sizeof(line), stdin) == (char *)NULL) diff --git a/lib/libcurses/hashmap.c b/lib/libcurses/hashmap.c index d9557e0cf2e..9a98221f30e 100644 --- a/lib/libcurses/hashmap.c +++ b/lib/libcurses/hashmap.c @@ -1,3 +1,5 @@ +/* $OpenBSD: hashmap.c,v 1.2 1997/12/03 05:21:09 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -35,11 +37,8 @@ vertical-motion optimizer portion of the update logic (see hardscroll.c). Line pairs are recognized by applying a modified Heckel's algorithm, sped up by hashing. If a line hash is unique in both screens, those -lines must be a pair. If the hashes of the two lines immediately following -lines known to be a pair are the same, the following lines are also a pair. -We apply these rules repeatedly until no more pairs are found. The -modifications stem from the fact that there may already be oldindex info -associated with the virtual screen, which has to be respected. +lines must be a pair. Then if the lines just before or after the pair +are the same or similar, they are a pair too. We don't worry about false pairs produced by hash collisions, on the assumption that such cases are rare and will only make the latter stages @@ -59,13 +58,12 @@ AUTHOR #include <curses.priv.h> -MODULE_ID("Id: hashmap.c,v 1.12 1997/05/03 20:30:06 tom Exp $") +MODULE_ID("Id: hashmap.c,v 1.23 1997/10/18 17:25:02 tom Exp $") #ifdef HASHDEBUG -#define LINES 24 #define TEXTWIDTH 1 -int oldnums[LINES], reallines[LINES]; -static chtype oldtext[LINES][TEXTWIDTH], newtext[LINES][TEXTWIDTH]; +int oldnums[MAXLINES], reallines[MAXLINES]; +static chtype oldtext[MAXLINES][TEXTWIDTH], newtext[MAXLINES][TEXTWIDTH]; #define OLDNUM(n) oldnums[n] #define REAL(m) reallines[m] #define OLDTEXT(n) oldtext[n] @@ -84,67 +82,216 @@ static chtype oldtext[LINES][TEXTWIDTH], newtext[LINES][TEXTWIDTH]; #endif /* _NEWINDEX */ #endif /* HASHDEBUG */ -/* Chris Torek's hash function (from his DB package). */ -static inline unsigned long hash4(const void *key, size_t len) +static inline unsigned long hash(chtype *text) { - register long h, loop; - register unsigned const char *k; - -#define HASH4a h = (h << 5) - h + *k++; -#define HASH4b h = (h << 5) + h + *k++; -#define HASH4 HASH4b - h = 0; - k = (unsigned const char *)key; - if (len > 0) { - loop = (len + 8 - 1) >> 3; - switch (len & (8 - 1)) { - case 0: - do { /* All fall throughs */ - HASH4; - case 7: - HASH4; - case 6: - HASH4; - case 5: - HASH4; - case 4: - HASH4; - case 3: - HASH4; - case 2: - HASH4; - case 1: - HASH4; - } while (--loop); - } + int i; + chtype ch; + unsigned long result = 0; + for (i = TEXTWIDTH; i>0; i--) + { + ch = *text++; + result += (result<<5) + ch + (ch>>16); } - return ((unsigned long)h); + return result; } -static inline unsigned long hash(chtype *text) +/* approximate update cost */ +static int update_cost(chtype *from,chtype *to) { - return(hash4(text, TEXTWIDTH*sizeof(*text))); + int cost=0; + int i; + + for (i=TEXTWIDTH; i>0; i--) + if (*from++ != *to++) + cost++; + + return cost; } +static int update_cost_from_blank(chtype *to) +{ + int cost=0; + int i; -void _nc_hash_map(void) + /* FIXME: ClrBlank should be used */ + for (i=TEXTWIDTH; i>0; i--) + if (BLANK != *to++) + cost++; + + return cost; +} + +/* + * Returns true when moving line 'from' to line 'to' seems to be cost + * effective. 'blank' indicates whether the line 'to' would become blank. + */ +static inline bool cost_effective(const int from, const int to, const bool blank) { - typedef struct + int new_from; + + if (from == to) + return FALSE; + + new_from = OLDNUM(from); + if (new_from == _NEWINDEX) + new_from = from; + + /* + * On the left side of >= is the cost before moving; + * on the right side -- cost after moving. + */ + return (((blank ? update_cost_from_blank(NEWTEXT(to)) + : update_cost(OLDTEXT(to),NEWTEXT(to))) + + update_cost(OLDTEXT(new_from),NEWTEXT(from))) + >= ((new_from==from ? update_cost_from_blank(NEWTEXT(from)) + : update_cost(OLDTEXT(new_from),NEWTEXT(from))) + + update_cost(OLDTEXT(from),NEWTEXT(to)))) ? TRUE : FALSE; +} + + +typedef struct +{ + unsigned long hashval; + int oldcount, newcount; + int oldindex, newindex; +} + sym; + +static sym *hashtab=0; +static int lines_alloc=0; +static long *oldhash=0; +static long *newhash=0; + +static void grow_hunks(void) +{ + int start, end, shift; + int back_limit, forward_limit; /* limits for cells to fill */ + int back_ref_limit, forward_ref_limit; /* limits for refrences */ + int i; + int next_hunk; + + /* + * This is tricky part. We have unique pairs to use as anchors. + * Use these to deduce the presence of spans of identical lines. + */ + back_limit = 0; + back_ref_limit = 0; + + i = 0; + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + for ( ; i < screen_lines; i=next_hunk) { - unsigned long hashval; - int oldcount, newcount; - int oldindex, newindex; + start = i; + shift = OLDNUM(i) - i; + + /* get forward limit */ + i = start+1; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + end = i; + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + next_hunk = i; + forward_limit = i; + if (i >= screen_lines || OLDNUM(i) >= i) + forward_ref_limit = i; + else + forward_ref_limit = OLDNUM(i); + + i = start-1; + /* grow back */ + if (shift < 0) + back_limit = back_ref_limit + (-shift); + while (i >= back_limit) + { + if(newhash[i] == oldhash[i+shift] + || cost_effective(i+shift, i, shift<0)) + { + OLDNUM(i) = i+shift; + TR(TRACE_UPDATE | TRACE_MOVE, + ("connected new line %d to old line %d (backward continuation)", + i, i+shift)); + } + else + { + TR(TRACE_UPDATE | TRACE_MOVE, + ("not connecting new line %d to old line %d (backward continuation)", + i, i+shift)); + break; + } + i--; + } + + i = end; + /* grow forward */ + if (shift > 0) + forward_limit = forward_ref_limit - shift; + while (i < forward_limit) + { + if(newhash[i] == oldhash[i+shift] + || cost_effective(i+shift, i, shift>0)) + { + OLDNUM(i) = i+shift; + TR(TRACE_UPDATE | TRACE_MOVE, + ("connected new line %d to old line %d (forward continuation)", + i, i+shift)); + } + else + { + TR(TRACE_UPDATE | TRACE_MOVE, + ("not connecting new line %d to old line %d (forward continuation)", + i, i+shift)); + break; + } + i++; + } + + back_ref_limit = back_limit = i; + if (shift > 0) + back_ref_limit += shift; } - sym; - sym hashtab[MAXLINES*2], *sp; +} + +void _nc_hash_map(void) +{ + sym *sp; register int i; - long oldhash[MAXLINES], newhash[MAXLINES]; - bool keepgoing; + int start, shift, size; + + + if (screen_lines > lines_alloc) + { + if (hashtab) + free (hashtab); + hashtab = malloc (sizeof(*hashtab)*(screen_lines+1)*2); + if (!hashtab) + { + if (oldhash) + FreeAndNull(oldhash); + lines_alloc = 0; + return; + } + + if (oldhash) + free (oldhash); + oldhash = malloc (sizeof(*oldhash)*screen_lines*2); + if (!oldhash) + { + if (hashtab) + FreeAndNull(hashtab); + lines_alloc = 0; + return; + } + + lines_alloc = screen_lines; + } + newhash = oldhash + screen_lines; /* two arrays in the same memory block */ /* * Set up and count line-hash values. */ - memset(hashtab, '\0', sizeof(sym) * MAXLINES); - for (i = 0; i < LINES; i++) + memset(hashtab, '\0', sizeof(*hashtab)*(screen_lines+1)*2); + for (i = 0; i < screen_lines; i++) { unsigned long hashval = hash(OLDTEXT(i)); @@ -156,7 +303,7 @@ void _nc_hash_map(void) sp->oldcount++; sp->oldindex = i; } - for (i = 0; i < LINES; i++) + for (i = 0; i < screen_lines; i++) { unsigned long hashval = hash(NEWTEXT(i)); @@ -173,13 +320,14 @@ void _nc_hash_map(void) /* * Mark line pairs corresponding to unique hash pairs. - * Note: we only do this where the new line doesn't - * already have a valid oldindex -- this way we preserve the - * information left in place by the software scrolling functions. + * + * We don't mark lines with offset 0, because it can make fail + * extending hunks by cost_effective. Otherwise, it does not + * have any side effects. */ for (sp = hashtab; sp->hashval; sp++) if (sp->oldcount == 1 && sp->newcount == 1 - && OLDNUM(sp->newindex) == _NEWINDEX) + && sp->oldindex != sp->newindex) { TR(TRACE_UPDATE | TRACE_MOVE, ("new line %d is hash-identical to old line %d (unique)", @@ -187,42 +335,44 @@ void _nc_hash_map(void) OLDNUM(sp->newindex) = sp->oldindex; } + grow_hunks(); + /* - * Now for the tricky part. We have unique pairs to use as anchors. - * Use these to deduce the presence of spans of identical lines. + * Eliminate bad or impossible shifts -- this includes removing + * those hunks which could not grow because of conflicts, as well + * those which are to be moved too far, they are likely to destroy + * more than carry. */ - do { - keepgoing = FALSE; - - for (i = 0; i < LINES-1; i++) - if (OLDNUM(i) != _NEWINDEX && OLDNUM(i+1) == _NEWINDEX) - { - if (OLDNUM(i) + 1 < LINES - && newhash[i+1] == oldhash[OLDNUM(i) + 1]) - { - OLDNUM(i+1) = OLDNUM(i) + 1; - TR(TRACE_UPDATE | TRACE_MOVE, - ("new line %d is hash-identical to old line %d (forward continuation)", - i+1, OLDNUM(i) + 1)); - keepgoing = TRUE; - } - } - - for (i = 0; i < LINES-1; i++) - if (OLDNUM(i) != _NEWINDEX && OLDNUM(i-1) == _NEWINDEX) + for (i = 0; i < screen_lines; ) + { + while (i < screen_lines && OLDNUM(i) == _NEWINDEX) + i++; + if (i >= screen_lines) + break; + start = i; + shift = OLDNUM(i) - i; + i++; + while (i < screen_lines && OLDNUM(i) != _NEWINDEX && OLDNUM(i) - i == shift) + i++; + size = i - start; + if (size <= abs(shift)) + { + while (start < i) { - if (OLDNUM(i) - 1 >= 0 - && newhash[i-1] == oldhash[OLDNUM(i) - 1]) - { - OLDNUM(i-1) = OLDNUM(i) - 1; - TR(TRACE_UPDATE | TRACE_MOVE, - ("new line %d is hash-identical to old line %d (backward continuation)", - i-1, OLDNUM(i) - 1)); - keepgoing = TRUE; - } + OLDNUM(start) = _NEWINDEX; + start++; } - } while - (keepgoing); + } + } + + /* After clearing invalid hunks, try grow the rest. */ + grow_hunks(); + +#if NO_LEAKS + FreeAndNull(hashtab); + FreeAndNull(oldhash); + lines_alloc = 0; +#endif } #ifdef HASHDEBUG @@ -230,18 +380,19 @@ void _nc_hash_map(void) int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) { - extern void _nc_linedump(void); char line[BUFSIZ], *st; int n; - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) { reallines[n] = n; oldnums[n] = _NEWINDEX; oldtext[n][0] = newtext[n][0] = '.'; } +#ifdef TRACE _nc_tracing = TRACE_MOVE; +#endif for (;;) { /* grab a test command */ @@ -255,7 +406,7 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) break; case 'l': /* get initial line number vector */ - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) { reallines[n] = n; oldnums[n] = _NEWINDEX; @@ -269,9 +420,9 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) break; case 'n': /* use following letters as text of new lines */ - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) newtext[n][0] = '.'; - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) if (line[n+1] == '\n') break; else @@ -279,9 +430,9 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) break; case 'o': /* use following letters as text of old lines */ - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) oldtext[n][0] = '.'; - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) if (line[n+1] == '\n') break; else @@ -289,14 +440,16 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) break; case 'd': /* dump state of test arrays */ +#ifdef TRACE _nc_linedump(); +#endif (void) fputs("Old lines: [", stdout); - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) putchar(oldtext[n][0]); putchar(']'); putchar('\n'); (void) fputs("New lines: [", stdout); - for (n = 0; n < LINES; n++) + for (n = 0; n < screen_lines; n++) putchar(newtext[n][0]); putchar(']'); putchar('\n'); @@ -305,7 +458,9 @@ main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) case 'h': /* apply hash mapper and see scroll optimization */ _nc_hash_map(); (void) fputs("Result:\n", stderr); +#ifdef TRACE _nc_linedump(); +#endif _nc_scroll_optimize(); (void) fputs("Done.\n", stderr); break; diff --git a/lib/libcurses/keyok.c b/lib/libcurses/keyok.c new file mode 100644 index 00000000000..6c334f87042 --- /dev/null +++ b/lib/libcurses/keyok.c @@ -0,0 +1,59 @@ +/* $OpenBSD: keyok.c,v 1.1 1997/12/03 05:21:09 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. THE ABOVE LISTED * + * COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * + * EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY * + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("Id: keyok.c,v 1.1 1997/05/29 01:32:51 tom Exp $") + +/* + * Enable (or disable) ncurses' interpretation of a keycode by adding (or + * removing) the corresponding 'tries' entry. + * + * Do this by storing a second tree of tries, which records the disabled keys. + * The simplest way to copy is to make a function that returns the string (with + * nulls set to 0200), then use that to reinsert the string into the + * corresponding tree. + */ + +int keyok(int c, bool flag) +{ + int code = ERR; + char *s; + + T((T_CALLED("keyok(%d,%d)"), c, flag)); + if (flag) { + if ((s = _nc_expand_try(SP->_key_ok, c, 0)) != 0 + && _nc_remove_key(&(SP->_key_ok), c)) { + _nc_add_to_try(&(SP->_keytry), s, c); + free(s); + code = OK; + } + } else { + if ((s = _nc_expand_try(SP->_keytry, c, 0)) != 0 + && _nc_remove_key(&(SP->_keytry), c)) { + _nc_add_to_try(&(SP->_key_ok), s, c); + free(s); + code = OK; + } + } + returnCode(code); +} diff --git a/lib/libcurses/keys.list b/lib/libcurses/keys.list index f9e3dd657c8..b07de56b80c 100644 --- a/lib/libcurses/keys.list +++ b/lib/libcurses/keys.list @@ -1,150 +1,158 @@ -key_a1 KEY_A1 -key_a3 KEY_A3 -key_b2 KEY_B2 -key_backspace KEY_BACKSPACE -key_beg KEY_BEG -key_btab KEY_BTAB -key_c1 KEY_C1 -key_c3 KEY_C3 -key_cancel KEY_CANCEL -key_catab KEY_CATAB -key_clear KEY_CLEAR -key_close KEY_CLOSE -key_command KEY_COMMAND -key_copy KEY_COPY -key_create KEY_CREATE -key_ctab KEY_CTAB -key_dc KEY_DC -key_dl KEY_DL -key_down KEY_DOWN -key_eic KEY_EIC -key_end KEY_END -key_enter KEY_ENTER -key_eol KEY_EOL -key_eos KEY_EOS -key_exit KEY_EXIT -key_f0 KEY_F(0) -key_f1 KEY_F(1) -key_f2 KEY_F(2) -key_f3 KEY_F(3) -key_f4 KEY_F(4) -key_f5 KEY_F(5) -key_f6 KEY_F(6) -key_f7 KEY_F(7) -key_f8 KEY_F(8) -key_f9 KEY_F(9) -key_f10 KEY_F(10) -key_f11 KEY_F(11) -key_f12 KEY_F(12) -key_f13 KEY_F(13) -key_f14 KEY_F(14) -key_f15 KEY_F(15) -key_f16 KEY_F(16) -key_f17 KEY_F(17) -key_f18 KEY_F(18) -key_f19 KEY_F(19) -key_f20 KEY_F(20) -key_f21 KEY_F(21) -key_f22 KEY_F(22) -key_f23 KEY_F(23) -key_f24 KEY_F(24) -key_f25 KEY_F(25) -key_f26 KEY_F(26) -key_f27 KEY_F(27) -key_f28 KEY_F(28) -key_f29 KEY_F(29) -key_f30 KEY_F(30) -key_f31 KEY_F(31) -key_f32 KEY_F(32) -key_f33 KEY_F(33) -key_f34 KEY_F(34) -key_f35 KEY_F(35) -key_f36 KEY_F(36) -key_f37 KEY_F(37) -key_f38 KEY_F(38) -key_f39 KEY_F(39) -key_f40 KEY_F(40) -key_f41 KEY_F(41) -key_f42 KEY_F(42) -key_f43 KEY_F(43) -key_f44 KEY_F(44) -key_f45 KEY_F(45) -key_f46 KEY_F(46) -key_f47 KEY_F(47) -key_f48 KEY_F(48) -key_f49 KEY_F(49) -key_f50 KEY_F(50) -key_f51 KEY_F(51) -key_f52 KEY_F(52) -key_f53 KEY_F(53) -key_f54 KEY_F(54) -key_f55 KEY_F(55) -key_f56 KEY_F(56) -key_f57 KEY_F(57) -key_f58 KEY_F(58) -key_f59 KEY_F(59) -key_f60 KEY_F(60) -key_f61 KEY_F(61) -key_f62 KEY_F(62) -key_f63 KEY_F(63) -key_find KEY_FIND -key_help KEY_HELP -key_home KEY_HOME -key_ic KEY_IC -key_il KEY_IL -key_left KEY_LEFT -key_ll KEY_LL -key_mark KEY_MARK -key_message KEY_MESSAGE -key_move KEY_MOVE -key_next KEY_NEXT -key_npage KEY_NPAGE -key_open KEY_OPEN -key_options KEY_OPTIONS -key_ppage KEY_PPAGE -key_previous KEY_PREVIOUS -key_print KEY_PRINT -key_redo KEY_REDO -key_reference KEY_REFERENCE -key_refresh KEY_REFRESH -key_replace KEY_REPLACE -key_restart KEY_RESTART -key_resume KEY_RESUME -key_right KEY_RIGHT -key_save KEY_SAVE -key_sbeg KEY_SBEG -key_scancel KEY_SCANCEL -key_scommand KEY_SCOMMAND -key_scopy KEY_SCOPY -key_screate KEY_SCREATE -key_sdc KEY_SDC -key_sdl KEY_SDL -key_select KEY_SELECT -key_send KEY_SEND -key_seol KEY_SEOL -key_sexit KEY_SEXIT -key_sf KEY_SF -key_sfind KEY_SFIND -key_shelp KEY_SHELP -key_shome KEY_SHOME -key_sic KEY_SIC -key_sleft KEY_SLEFT -key_smessage KEY_SMESSAGE -key_smove KEY_SMOVE -key_snext KEY_SNEXT -key_soptions KEY_SOPTIONS -key_sprevious KEY_SPREVIOUS -key_sprint KEY_SPRINT -key_sr KEY_SR -key_sredo KEY_SREDO -key_sreplace KEY_SREPLACE -key_sright KEY_SRIGHT -key_srsume KEY_SRSUME -key_ssave KEY_SSAVE -key_ssuspend KEY_SSUSPEND -key_stab KEY_STAB -key_sundo KEY_SUNDO -key_suspend KEY_SUSPEND -key_undo KEY_UNDO -key_up KEY_UP -key_mouse KEY_MOUSE +# Id: keys.list,v 1.5 1997/10/25 21:05:24 tom Exp $ +# The first column is the #define symbol that is in curses.h +# The second column is the term.h symbol, for terminfo +# Not all keycodes have corresponding terminfo capabilities. +KEY_A1 key_a1 +KEY_A3 key_a3 +KEY_B2 key_b2 +KEY_BACKSPACE key_backspace +KEY_BEG key_beg +KEY_BREAK +KEY_BTAB key_btab +KEY_C1 key_c1 +KEY_C3 key_c3 +KEY_CANCEL key_cancel +KEY_CATAB key_catab +KEY_CLEAR key_clear +KEY_CLOSE key_close +KEY_COMMAND key_command +KEY_COPY key_copy +KEY_CREATE key_create +KEY_CTAB key_ctab +KEY_DC key_dc +KEY_DL key_dl +KEY_DOWN key_down +KEY_EIC key_eic +KEY_END key_end +KEY_ENTER key_enter +KEY_EOL key_eol +KEY_EOS key_eos +KEY_EXIT key_exit +KEY_F(0) key_f0 +KEY_F(1) key_f1 +KEY_F(10) key_f10 +KEY_F(11) key_f11 +KEY_F(12) key_f12 +KEY_F(13) key_f13 +KEY_F(14) key_f14 +KEY_F(15) key_f15 +KEY_F(16) key_f16 +KEY_F(17) key_f17 +KEY_F(18) key_f18 +KEY_F(19) key_f19 +KEY_F(2) key_f2 +KEY_F(20) key_f20 +KEY_F(21) key_f21 +KEY_F(22) key_f22 +KEY_F(23) key_f23 +KEY_F(24) key_f24 +KEY_F(25) key_f25 +KEY_F(26) key_f26 +KEY_F(27) key_f27 +KEY_F(28) key_f28 +KEY_F(29) key_f29 +KEY_F(3) key_f3 +KEY_F(30) key_f30 +KEY_F(31) key_f31 +KEY_F(32) key_f32 +KEY_F(33) key_f33 +KEY_F(34) key_f34 +KEY_F(35) key_f35 +KEY_F(36) key_f36 +KEY_F(37) key_f37 +KEY_F(38) key_f38 +KEY_F(39) key_f39 +KEY_F(4) key_f4 +KEY_F(40) key_f40 +KEY_F(41) key_f41 +KEY_F(42) key_f42 +KEY_F(43) key_f43 +KEY_F(44) key_f44 +KEY_F(45) key_f45 +KEY_F(46) key_f46 +KEY_F(47) key_f47 +KEY_F(48) key_f48 +KEY_F(49) key_f49 +KEY_F(5) key_f5 +KEY_F(50) key_f50 +KEY_F(51) key_f51 +KEY_F(52) key_f52 +KEY_F(53) key_f53 +KEY_F(54) key_f54 +KEY_F(55) key_f55 +KEY_F(56) key_f56 +KEY_F(57) key_f57 +KEY_F(58) key_f58 +KEY_F(59) key_f59 +KEY_F(6) key_f6 +KEY_F(60) key_f60 +KEY_F(61) key_f61 +KEY_F(62) key_f62 +KEY_F(63) key_f63 +KEY_F(7) key_f7 +KEY_F(8) key_f8 +KEY_F(9) key_f9 +KEY_FIND key_find +KEY_HELP key_help +KEY_HOME key_home +KEY_IC key_ic +KEY_IL key_il +KEY_LEFT key_left +KEY_LL key_ll +KEY_MARK key_mark +KEY_MESSAGE key_message +KEY_MOUSE key_mouse +KEY_MOVE key_move +KEY_NEXT key_next +KEY_NPAGE key_npage +KEY_OPEN key_open +KEY_OPTIONS key_options +KEY_PPAGE key_ppage +KEY_PREVIOUS key_previous +KEY_PRINT key_print +KEY_REDO key_redo +KEY_REFERENCE key_reference +KEY_REFRESH key_refresh +KEY_REPLACE key_replace +KEY_RESET +KEY_RESIZE +KEY_RESTART key_restart +KEY_RESUME key_resume +KEY_RIGHT key_right +KEY_SAVE key_save +KEY_SBEG key_sbeg +KEY_SCANCEL key_scancel +KEY_SCOMMAND key_scommand +KEY_SCOPY key_scopy +KEY_SCREATE key_screate +KEY_SDC key_sdc +KEY_SDL key_sdl +KEY_SELECT key_select +KEY_SEND key_send +KEY_SEOL key_seol +KEY_SEXIT key_sexit +KEY_SF key_sf +KEY_SFIND key_sfind +KEY_SHELP key_shelp +KEY_SHOME key_shome +KEY_SIC key_sic +KEY_SLEFT key_sleft +KEY_SMESSAGE key_smessage +KEY_SMOVE key_smove +KEY_SNEXT key_snext +KEY_SOPTIONS key_soptions +KEY_SPREVIOUS key_sprevious +KEY_SPRINT key_sprint +KEY_SR key_sr +KEY_SREDO key_sredo +KEY_SREPLACE key_sreplace +KEY_SRESET +KEY_SRIGHT key_sright +KEY_SRSUME key_srsume +KEY_SSAVE key_ssave +KEY_SSUSPEND key_ssuspend +KEY_STAB key_stab +KEY_SUNDO key_sundo +KEY_SUSPEND key_suspend +KEY_UNDO key_undo +KEY_UP key_up diff --git a/lib/libcurses/lib_acs.c b/lib/libcurses/lib_acs.c index e72c653bebf..eae5d2849d2 100644 --- a/lib/libcurses/lib_acs.c +++ b/lib/libcurses/lib_acs.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_acs.c,v 1.3 1997/12/03 05:21:10 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -24,9 +26,9 @@ #include <curses.priv.h> #include <term.h> /* ena_acs, acs_chars */ -MODULE_ID("Id: lib_acs.c,v 1.8 1997/04/24 11:04:07 tom Exp $") +MODULE_ID("Id: lib_acs.c,v 1.11 1997/08/15 21:44:16 Alexander.V.Lukyanov Exp $") -chtype acs_map[128]; +chtype acs_map[ACS_LEN]; void init_acs(void) { @@ -92,7 +94,7 @@ void init_acs(void) case 'q':case 'x':case 'n':case 'o': case 's':case '`':case 'a':case 'f': case 'g':case '~':case ',':case '+': - case '.':case '-':case 'h':case 'I': + case '.':case '-':case 'h':case 'i': case '0':case 'p':case 'r':case 'y': case 'z':case '{':case '|':case '}': acs_map[(unsigned int)acs_chars[i]] = @@ -105,7 +107,6 @@ void init_acs(void) } } #ifdef TRACE -#define SIZEOF(v) (sizeof(v)/sizeof(v[0])) /* Show the equivalent mapping, noting if it does not match the * given attribute, whether by re-ordering or duplication. */ diff --git a/lib/libcurses/lib_addch.c b/lib/libcurses/lib_addch.c index 5ad512c0dd1..cd22cff9a38 100644 --- a/lib/libcurses/lib_addch.c +++ b/lib/libcurses/lib_addch.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_addch.c,v 1.3 1997/12/03 05:21:10 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -22,30 +24,14 @@ /* ** lib_addch.c ** -** The routines waddch(), wattr_on(), wattr_off(), wchgat(). +** The routines waddch(), wchgat(). ** */ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("Id: lib_addch.c,v 1.30 1997/04/12 17:45:55 tom Exp $") - -int wattr_on(WINDOW *win, const attr_t at) -{ - T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at))); - T(("... current %s", _traceattr(win->_attrs))); - toggle_attr_on(win->_attrs,at); - returnCode(OK); -} - -int wattr_off(WINDOW *win, const attr_t at) -{ - T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at))); - T(("... current %s", _traceattr(win->_attrs))); - toggle_attr_off(win->_attrs,at); - returnCode(OK); -} +MODULE_ID("Id: lib_addch.c,v 1.36 1997/10/08 09:38:17 jtc Exp $") int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UNUSED) { @@ -53,13 +39,17 @@ int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UN T((T_CALLED("wchgat(%p,%d,%s,%d)"), win, n, _traceattr(attr), color)); - toggle_attr_on(attr,COLOR_PAIR(color)); + if (win) { + toggle_attr_on(attr,COLOR_PAIR(color)); - for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) + for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) win->_line[win->_cury].text[i] - = ch_or_attr(TextOf(win->_line[win->_cury].text[i]),attr); + = TextOf(win->_line[win->_cury].text[i]) | attr; - returnCode(OK); + returnCode(OK); + } + else + returnCode(ERR); } /* @@ -72,14 +62,29 @@ int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts GCC_UN * window sync hook, for use by string-put functions. */ +/* Return bit mask for clearing color pair number if given ch has color */ +#define COLOR_MASK(ch) (~(chtype)((ch)&A_COLOR?A_COLOR:0)) + static inline chtype render_char(WINDOW *win, chtype ch) /* compute a rendition of the given char correct for the current context */ { - if (TextOf(ch) == ' ') - ch = ch_or_attr(ch, win->_bkgd); - else if (!(ch & A_ATTRIBUTES)) - ch = ch_or_attr(ch, (win->_bkgd & A_ATTRIBUTES)); - TR(TRACE_VIRTPUT, ("bkg = %#lx -> ch = %#lx", win->_bkgd, ch)); + chtype a = win->_attrs; + + if (ch == ' ') + { + /* color in attrs has precedence over bkgd */ + ch = a | (win->_bkgd & COLOR_MASK(a)); + } + else + { + /* color in attrs has precedence over bkgd */ + a |= (win->_bkgd & A_ATTRIBUTES) & COLOR_MASK(a); + /* color in ch has precedence */ + ch |= (a & COLOR_MASK(ch)); + } + + TR(TRACE_VIRTPUT, ("bkg = %lx, attrs = %lx -> ch = %lx", win->_bkgd, + win->_attrs, ch)); return(ch); } @@ -87,18 +92,17 @@ static inline chtype render_char(WINDOW *win, chtype ch) chtype _nc_background(WINDOW *win) /* make render_char() visible while still allowing us to inline it below */ { - return(render_char(win, BLANK)); + return (win->_bkgd); } chtype _nc_render(WINDOW *win, chtype ch) /* make render_char() visible while still allowing us to inline it below */ { - chtype c = render_char(win,ch); - return (ch_or_attr(c,win->_attrs)); + return render_char(win, ch); } /* check if position is legal; if not, return error */ -#ifdef NDEBUG /* treat this like an assertion */ +#ifndef NDEBUG /* treat this like an assertion */ #define CHECK_POSITION(win, x, y) \ if (y > win->_maxy \ || x > win->_maxx \ @@ -116,12 +120,12 @@ chtype _nc_render(WINDOW *win, chtype ch) static inline int waddch_literal(WINDOW *win, chtype ch) { -register int x, y; + int x; + struct ldat *line; x = win->_curx; - y = win->_cury; - CHECK_POSITION(win, x, y); + CHECK_POSITION(win, x, win->_cury); /* * If we're trying to add a character at the lower-right corner more @@ -134,21 +138,20 @@ register int x, y; } ch = render_char(win, ch); - ch = ch_or_attr(ch,win->_attrs); TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); - if (win->_line[y].text[x] != ch) { - if (win->_line[y].firstchar == _NOCHANGE) - win->_line[y].firstchar = win->_line[y].lastchar = x; - else if (x < win->_line[y].firstchar) - win->_line[y].firstchar = x; - else if (x > win->_line[y].lastchar) - win->_line[y].lastchar = x; - - } - - win->_line[y].text[x++] = ch; - TR(TRACE_VIRTPUT, ("(%d, %d) = %s", y, x, _tracechtype(ch))); + line = win->_line+win->_cury; + + if (line->firstchar == _NOCHANGE) + line->firstchar = line->lastchar = x; + else if (x < line->firstchar) + line->firstchar = x; + else if (x > line->lastchar) + line->lastchar = x; + + line->text[x++] = ch; + + TR(TRACE_VIRTPUT, ("(%d, %d) = %s", win->_cury, x, _tracechtype(ch))); if (x > win->_maxx) { /* * The _WRAPPED flag is useful only for telling an application @@ -161,42 +164,40 @@ register int x, y; * add a character to the lower-right corner. */ win->_flags |= _WRAPPED; - if (++y > win->_regbottom) { - y = win->_regbottom; - x = win->_maxx; - if (win->_scroll) - scroll(win); - else { - win->_curx = x; - win->_cury = y; + if (++win->_cury > win->_regbottom) { + win->_cury = win->_regbottom; + win->_curx = win->_maxx; + if (!win->_scroll) return (ERR); - } + scroll(win); } - x = 0; + win->_curx = 0; + return (OK); } - win->_curx = x; - win->_cury = y; - return OK; } static inline -int waddch_nosync(WINDOW *win, const chtype c) +int waddch_nosync(WINDOW *win, const chtype ch) /* the workhorse function -- add a character to the given window */ { -register chtype ch = c; -register int x, y; + int x, y; + int t; + const char *s; + + if (ch & A_ALTCHARSET) + return waddch_literal(win, ch); + t = TextOf(ch); + s = unctrl(t); + if (s[1] == 0) /* not a control char */ + return waddch_literal(win, ch); + x = win->_curx; y = win->_cury; - CHECK_POSITION(win, x, y); - - if (ch & A_ALTCHARSET) - goto noctrl; - - switch ((int)TextOf(ch)) { + switch (t) { case '\t': x += (TABSIZE-(x%TABSIZE)); @@ -206,8 +207,9 @@ register int x, y; */ if ((! win->_scroll && (y == win->_regbottom)) || (x <= win->_maxx)) { + chtype blank = (' ' | AttrOf(ch)); while (win->_curx < x) { - if (waddch_literal(win, (' ' | AttrOf(ch))) == ERR) + if (waddch_literal(win, blank) == ERR) return(ERR); } break; @@ -241,18 +243,13 @@ register int x, y; win->_flags &= ~_WRAPPED; break; case '\b': - if (x > 0) { - x--; - win->_flags &= ~_WRAPPED; - } + if (x == 0) + return (OK); + x--; + win->_flags &= ~_WRAPPED; break; default: - if (is7bits(TextOf(ch)) && iscntrl(TextOf(ch))) - return(waddstr(win, unctrl((unsigned char)ch))); - - /* FALLTHRU */ - noctrl: - return waddch_literal(win, ch); + return(waddstr(win, s)); } win->_curx = x; @@ -281,7 +278,7 @@ int waddch(WINDOW *win, const chtype ch) TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), win, _tracechtype(ch))); - if (waddch_nosync(win, ch) != ERR) + if (win && (waddch_nosync(win, ch) != ERR)) { _nc_synchook(win); code = OK; @@ -297,7 +294,7 @@ int wechochar(WINDOW *win, const chtype ch) TR(TRACE_VIRTPUT|TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"), win, _tracechtype(ch))); - if (waddch_literal(win, ch) != ERR) + if (win && (waddch_nosync(win, ch) != ERR)) { bool save_immed = win->_immed; win->_immed = TRUE; diff --git a/lib/libcurses/lib_addstr.c b/lib/libcurses/lib_addstr.c index 2ece75c6cd7..0b8cc81e6c0 100644 --- a/lib/libcurses/lib_addstr.c +++ b/lib/libcurses/lib_addstr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_addstr.c,v 1.3 1997/12/03 05:21:11 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,7 +30,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_addstr.c,v 1.11 1997/03/08 21:38:52 tom Exp $") +MODULE_ID("Id: lib_addstr.c,v 1.13 1997/09/20 15:02:34 juergen Exp $") int waddnstr(WINDOW *win, const char *const astr, int n) @@ -37,24 +39,23 @@ unsigned const char *str = (unsigned const char *)astr; int code = ERR; T((T_CALLED("waddnstr(%p,%s,%d)"), win, _nc_visbuf(astr), n)); - T(("... current %s", _traceattr(win->_attrs))); - - if (str != 0) { - - TR(TRACE_VIRTPUT, ("str is not null")); - code = OK; - if (n < 0) - n = (int)strlen(astr); - - while((n-- > 0) && (*str != '\0')) { - TR(TRACE_VIRTPUT, ("*str = %#x", *str)); - if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) { - code = ERR; - break; - } - } + + if (win && (str != 0)) { + T(("... current %s", _traceattr(win->_attrs))); + TR(TRACE_VIRTPUT, ("str is not null")); + code = OK; + if (n < 0) + n = (int)strlen(astr); + + while((n-- > 0) && (*str != '\0')) { + TR(TRACE_VIRTPUT, ("*str = %#x", *str)); + if (_nc_waddch_nosync(win, (chtype)*str++) == ERR) { + code = ERR; + break; + } + } + _nc_synchook(win); } - _nc_synchook(win); TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); returnCode(code); } @@ -62,29 +63,41 @@ int code = ERR; int waddchnstr(WINDOW *win, const chtype *const astr, int n) { -short oy = win->_cury; -short ox = win->_curx; -const chtype *str = (const chtype *)astr; +short y = win->_cury; +short x = win->_curx; int code = OK; - T((T_CALLED("waddchnstr(%p,%p,%d)"), win, str, n)); + T((T_CALLED("waddchnstr(%p,%p,%d)"), win, astr, n)); + + if (!win) + returnCode(ERR); if (n < 0) { + const chtype *str; n = 0; - while (*str++ != 0) + for (str=(const chtype *)astr; *str!=0; str++) n++; - str = (const chtype *)astr; } + if (n > win->_maxx - x + 1) + n = win->_maxx - x + 1; + if (n == 0) + returnCode(code); - while(n-- > 0) { - if (_nc_waddch_nosync(win, *str++) == ERR) { - code = ERR; - break; - } + if (win->_line[y].firstchar == _NOCHANGE) + { + win->_line[y].firstchar = x; + win->_line[y].lastchar = x+n-1; + } + else + { + if (x < win->_line[y].firstchar) + win->_line[y].firstchar = x; + if (x+n-1 > win->_line[y].lastchar) + win->_line[y].lastchar = x+n-1; } + + memcpy(win->_line[y].text+x, astr, n*sizeof(*astr)); - win->_curx = ox; - win->_cury = oy; _nc_synchook(win); returnCode(code); } diff --git a/lib/libcurses/lib_baudrate.c b/lib/libcurses/lib_baudrate.c index 2dfd34dbfb8..d951911e0ab 100644 --- a/lib/libcurses/lib_baudrate.c +++ b/lib/libcurses/lib_baudrate.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_baudrate.c,v 1.2 1997/12/03 05:21:11 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,7 +30,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term, pad_char */ -MODULE_ID("Id: lib_baudrate.c,v 1.7 1997/04/26 17:41:48 tom Exp $") +MODULE_ID("Id: lib_baudrate.c,v 1.9 1997/10/25 23:34:13 tom Exp $") /* * int @@ -58,37 +60,32 @@ static struct speed const speeds[] = { {B2400, 2400}, {B4800, 4800}, {B9600, 9600}, -#define MAX_BAUD B9600 #ifdef B19200 -#undef MAX_BAUD -#define MAX_BAUD B19200 {B19200, 19200}, #else #ifdef EXTA -#define MAX_BAUD EXTA {EXTA, 19200}, #endif #endif #ifdef B38400 -#undef MAX_BAUD -#define MAX_BAUD B38400 {B38400, 38400}, #else #ifdef EXTB -#define MAX_BAUD EXTB {EXTB, 38400}, #endif #endif #ifdef B57600 -#undef MAX_BAUD -#define MAX_BAUD B57600 {B57600, 57600}, #endif #ifdef B115200 -#undef MAX_BAUD -#define MAX_BAUD B115200 {B115200, 115200}, #endif +#ifdef B230400 + {B230400, 230400}, +#endif +#ifdef B460800 + {B460800, 460800}, +#endif }; int @@ -122,10 +119,10 @@ char *debug_rate; #else ret = cur_term->Nttyb.sg_ospeed; #endif - if(ret < 0 || ret > MAX_BAUD) + if(ret < 0 || (speed_t)ret > speeds[SIZEOF(speeds)-1].s) returnCode(ERR); SP->_baudrate = ERR; - for (i = 0; i < (sizeof(speeds) / sizeof(struct speed)); i++) + for (i = 0; i < SIZEOF(speeds); i++) if (speeds[i].s == (speed_t)ret) { SP->_baudrate = speeds[i].sp; diff --git a/lib/libcurses/lib_beep.c b/lib/libcurses/lib_beep.c index 4439162e44d..2ff91968132 100644 --- a/lib/libcurses/lib_beep.c +++ b/lib/libcurses/lib_beep.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_beep.c,v 1.3 1997/12/03 05:21:12 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -23,14 +25,14 @@ /* * beep.c * - * Routines beep() and flash() + * The routine beep(). * */ #include <curses.priv.h> #include <term.h> /* beep, flash */ -MODULE_ID("Id: lib_beep.c,v 1.3 1997/02/02 00:27:01 tom Exp $") +MODULE_ID("Id: lib_beep.c,v 1.4 1997/10/08 09:38:17 jtc Exp $") /* * beep() @@ -55,27 +57,3 @@ int beep(void) else returnCode(ERR); } - -/* - * flash() - * - * Flash the current terminal's screen if possible. If not, - * sound the audible bell if one exists. - * - */ - -int flash(void) -{ - T((T_CALLED("flash()"))); - - /* FIXME: should make sure that we are not in altchar mode */ - if (flash_screen) { - TPUTS_TRACE("flash_screen"); - returnCode(putp(flash_screen)); - } else if (bell) { - TPUTS_TRACE("bell"); - returnCode(putp(bell)); - } - else - returnCode(ERR); -} diff --git a/lib/libcurses/lib_bkgd.c b/lib/libcurses/lib_bkgd.c index 3d4c0be6bd7..d573fce9d60 100644 --- a/lib/libcurses/lib_bkgd.c +++ b/lib/libcurses/lib_bkgd.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_bkgd.c,v 1.3 1997/12/03 05:21:12 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -21,32 +23,54 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_bkgd.c,v 1.7 1997/04/12 17:44:37 tom Exp $") +MODULE_ID("Id: lib_bkgd.c,v 1.11 1997/10/18 19:03:49 tom Exp $") + +void wbkgdset(WINDOW *win, chtype ch) +{ + T((T_CALLED("wbkgdset(%p,%s)"), win, _tracechtype(ch))); + + if (win) { + chtype off = AttrOf(win->_bkgd); + chtype on = AttrOf(ch); + + toggle_attr_off(win->_attrs,off); + toggle_attr_on (win->_attrs,on); + + if (TextOf(ch)==0) + ch |= BLANK; + win->_bkgd = ch; + } + returnVoid; +} int wbkgd(WINDOW *win, const chtype ch) { -int x, y; -chtype old_bkgd = getbkgd(win); -chtype new_bkgd = ch; - - T((T_CALLED("wbkgd(%p,%s)"), win, _tracechtype(new_bkgd))); - - if (TextOf(new_bkgd) == 0) - new_bkgd |= BLANK; - wbkgdset(win, new_bkgd); - wattrset(win, AttrOf(new_bkgd)); - - for (y = 0; y <= win->_maxy; y++) { - for (x = 0; x <= win->_maxx; x++) { - if (win->_line[y].text[x] == old_bkgd) - win->_line[y].text[x] = new_bkgd; - else - win->_line[y].text[x] = - TextOf(win->_line[y].text[x]) - | AttrOf(new_bkgd); - } - } - touchwin(win); - _nc_synchook(win); - returnCode(OK); + int code = ERR; + int x, y; + chtype new_bkgd = ch; + + T((T_CALLED("wbkgd(%p,%s)"), win, _tracechtype(new_bkgd))); + + if (win) { + chtype old_bkgd = getbkgd(win); + + wbkgdset(win, new_bkgd); + wattrset(win, AttrOf(win->_bkgd)); + + for (y = 0; y <= win->_maxy; y++) { + for (x = 0; x <= win->_maxx; x++) { + if (win->_line[y].text[x] == old_bkgd) + win->_line[y].text[x] = win->_bkgd; + else + win->_line[y].text[x] = + _nc_render(win,(A_ALTCHARSET & + AttrOf(win->_line[y].text[x])) + | TextOf(win->_line[y].text[x])); + } + } + touchwin(win); + _nc_synchook(win); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/lib_box.c b/lib/libcurses/lib_box.c index 2eaf312238a..4baf37586ae 100644 --- a/lib/libcurses/lib_box.c +++ b/lib/libcurses/lib_box.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_box.c,v 1.3 1997/12/03 05:21:12 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -24,16 +26,13 @@ /* ** lib_box.c ** -** line drawing routines: -** wborder() -** whline() -** wvline() +** The routine wborder(). ** */ #include <curses.priv.h> -MODULE_ID("Id: lib_box.c,v 1.7 1997/04/12 17:51:49 tom Exp $") +MODULE_ID("Id: lib_box.c,v 1.9 1997/10/08 09:38:17 jtc Exp $") int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br) @@ -52,6 +51,9 @@ short endx, endy; _tracechtype2(7,bl), _tracechtype2(8,br))); + if (!win) + returnCode(ERR); + if (ls == 0) ls = ACS_VLINE; if (rs == 0) rs = ACS_VLINE; if (ts == 0) ts = ACS_HLINE; @@ -96,65 +98,3 @@ short endx, endy; _nc_synchook(win); returnCode(OK); } - -int whline(WINDOW *win, chtype ch, int n) -{ -short line; -short start; -short end; - - T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); - - line = win->_cury; - start = win->_curx; - end = start + n - 1; - if (end > win->_maxx) - end = win->_maxx; - - if (win->_line[line].firstchar == _NOCHANGE || win->_line[line].firstchar > start) - win->_line[line].firstchar = start; - if (win->_line[line].lastchar == _NOCHANGE || win->_line[line].lastchar < start) - win->_line[line].lastchar = end; - - if (ch == 0) - ch = ACS_HLINE; - ch = _nc_render(win, ch); - - while ( end >= start) { - win->_line[line].text[end] = ch; - end--; - } - - returnCode(OK); -} - -int wvline(WINDOW *win, chtype ch, int n) -{ -short row, col; -short end; - - T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); - - row = win->_cury; - col = win->_curx; - end = row + n - 1; - if (end > win->_maxy) - end = win->_maxy; - - if (ch == 0) - ch = ACS_VLINE; - ch = _nc_render(win, ch); - - while(end >= row) { - win->_line[end].text[col] = ch; - if (win->_line[end].firstchar == _NOCHANGE || win->_line[end].firstchar > col) - win->_line[end].firstchar = col; - if (win->_line[end].lastchar == _NOCHANGE || win->_line[end].lastchar < col) - win->_line[end].lastchar = col; - end--; - } - - _nc_synchook(win); - returnCode(OK); -} - diff --git a/lib/libcurses/lib_clear.c b/lib/libcurses/lib_clear.c index 3318a9f68d7..7164d316075 100644 --- a/lib/libcurses/lib_clear.c +++ b/lib/libcurses/lib_clear.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_clear.c,v 1.3 1997/12/03 05:21:13 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,15 +30,16 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_clear.c,v 1.3 1997/02/01 23:18:18 tom Exp $") +MODULE_ID("Id: lib_clear.c,v 1.4 1997/09/20 15:02:34 juergen Exp $") int wclear(WINDOW *win) { - T((T_CALLED("wclear(%p)"), win)); +int code = ERR; - werase(win); - - win->_clear = TRUE; + T((T_CALLED("wclear(%p)"), win)); - returnCode(OK); + if ((code = werase(win))!=ERR) + win->_clear = TRUE; + + returnCode(code); } diff --git a/lib/libcurses/lib_clrbot.c b/lib/libcurses/lib_clrbot.c index 9580df1a904..ad2469c264f 100644 --- a/lib/libcurses/lib_clrbot.c +++ b/lib/libcurses/lib_clrbot.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_clrbot.c,v 1.3 1997/12/03 05:21:13 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,45 +30,40 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_clrbot.c,v 1.9 1997/02/01 23:18:18 tom Exp $") +MODULE_ID("Id: lib_clrbot.c,v 1.12 1997/09/20 15:02:34 juergen Exp $") int wclrtobot(WINDOW *win) { -chtype *ptr, *end, *maxx = NULL; -short y, startx, minx; +int code = ERR; +chtype blank; +chtype *ptr, *end; +short y, startx; T((T_CALLED("wclrtobot(%p)"), win)); - startx = win->_curx; - - T(("clearing from y = %d to y = %d with maxx = %d", win->_cury, win->_maxy, win->_maxx)); - - for (y = win->_cury; y <= win->_maxy; y++) { - minx = _NOCHANGE; - end = &win->_line[y].text[win->_maxx]; - - for (ptr = &win->_line[y].text[startx]; ptr <= end; ptr++) { - chtype blank = _nc_background(win); - - if (*ptr != blank) { - maxx = ptr; - if (minx == _NOCHANGE) - minx = ptr - win->_line[y].text; - *ptr = blank; - } - } - - if (minx != _NOCHANGE) { - if (win->_line[y].firstchar > minx - || win->_line[y].firstchar == _NOCHANGE) - win->_line[y].firstchar = minx; - - if (win->_line[y].lastchar < maxx - win->_line[y].text) - win->_line[y].lastchar = maxx - win->_line[y].text; - } - - startx = 0; + if (win) { + startx = win->_curx; + + T(("clearing from y = %d to y = %d with maxx = %d", win->_cury, win->_maxy, win->_maxx)); + + for (y = win->_cury; y <= win->_maxy; y++) { + end = &win->_line[y].text[win->_maxx]; + + blank = _nc_background(win); + for (ptr = &win->_line[y].text[startx]; ptr <= end; ptr++) + *ptr = blank; + + if (win->_line[y].firstchar > startx + || win->_line[y].firstchar == _NOCHANGE) + win->_line[y].firstchar = startx; + + win->_line[y].lastchar = win->_maxx; + + startx = 0; + } + _nc_synchook(win); + code = OK; } - _nc_synchook(win); - returnCode(OK); + returnCode(code); } + diff --git a/lib/libcurses/lib_clreol.c b/lib/libcurses/lib_clreol.c index 6ffd0fcee53..2b04e0a0a79 100644 --- a/lib/libcurses/lib_clreol.c +++ b/lib/libcurses/lib_clreol.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_clreol.c,v 1.3 1997/12/03 05:21:14 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,49 +31,54 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_clreol.c,v 1.9 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("Id: lib_clreol.c,v 1.13 1997/09/20 15:02:34 juergen Exp $") int wclrtoeol(WINDOW *win) { -chtype *maxx, *ptr, *end; -short y, x, minx; +int code = ERR; +chtype blank; +chtype *ptr, *end; +short y, x; T((T_CALLED("wclrtoeol(%p)"), win)); - y = win->_cury; - x = win->_curx; - - /* - * We don't want to clear if we just wrapped the cursor. There's no - * point in clearing if we're not on a legal position, either. - */ - if (win->_flags & _WRAPPED - || y > win->_maxy - || x > win->_maxx) - returnCode(ERR); - - end = &win->_line[y].text[win->_maxx]; - minx = _NOCHANGE; - maxx = &win->_line[y].text[x]; - - for (ptr = maxx; ptr <= end; ptr++) { - chtype blank = _nc_background(win); - - if (*ptr != blank) { - maxx = ptr; - if (minx == _NOCHANGE) - minx = ptr - win->_line[y].text; - *ptr = blank; - } - } + if (win) { - if (minx != _NOCHANGE) { - if (win->_line[y].firstchar > minx || win->_line[y].firstchar == _NOCHANGE) - win->_line[y].firstchar = minx; + y = win->_cury; + x = win->_curx; - if (win->_line[y].lastchar < maxx - win->_line[y].text) - win->_line[y].lastchar = maxx - win->_line[y].text; + /* + * If we have just wrapped the cursor, the clear applies to the new + * line, unless we are at the lower right corner. + */ + if (win->_flags & _WRAPPED + && y < win->_maxy) { + win->_flags &= ~_WRAPPED; + } + + /* + * There's no point in clearing if we're not on a legal position, + * either. + */ + if (win->_flags & _WRAPPED + || y > win->_maxy + || x > win->_maxx) + returnCode(ERR); + + blank = _nc_background(win); + end = &win->_line[y].text[win->_maxx]; + + for (ptr = &win->_line[y].text[x]; ptr <= end; ptr++) + *ptr = blank; + + if (win->_line[y].firstchar > win->_curx + || win->_line[y].firstchar == _NOCHANGE) + win->_line[y].firstchar = win->_curx; + + win->_line[y].lastchar = win->_maxx; + + _nc_synchook(win); + code = OK; } - _nc_synchook(win); - returnCode(OK); + returnCode(code); } diff --git a/lib/libcurses/lib_color.c b/lib/libcurses/lib_color.c index 1e8dc9acf21..eec595e3e02 100644 --- a/lib/libcurses/lib_color.c +++ b/lib/libcurses/lib_color.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_color.c,v 1.4 1997/12/03 05:21:14 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,7 +31,13 @@ #include <term.h> -MODULE_ID("Id: lib_color.c,v 1.17 1997/05/03 19:16:05 tom Exp $") +MODULE_ID("Id: lib_color.c,v 1.21 1997/11/30 00:19:33 tom Exp $") + +/* + * Only 8 ANSI colors are defined; the ISO 6429 control sequences work only + * for 8 values (0-7). + */ +#define MAX_ANSI_COLOR 8 /* * These should be screen structure members. They need to be globals for @@ -39,17 +47,24 @@ MODULE_ID("Id: lib_color.c,v 1.17 1997/05/03 19:16:05 tom Exp $") int COLOR_PAIRS; int COLORS; +/* + * Given a RGB range of 0..1000, we'll normally set the individual values + * to about 2/3 of the maximum, leaving full-range for bold/bright colors. + */ +#define RGB_ON 680 +#define RGB_OFF 0 + static const color_t cga_palette[] = { - /* R G B */ - {0, 0, 0}, /* COLOR_BLACK */ - {1000, 0, 0}, /* COLOR_RED */ - {0, 1000, 0}, /* COLOR_GREEN */ - {1000, 1000, 0}, /* COLOR_YELLOW */ - {0, 0, 1000}, /* COLOR_BLUE */ - {1000, 0, 1000}, /* COLOR_MAGENTA */ - {0, 1000, 1000}, /* COLOR_CYAN */ - {1000, 1000, 1000}, /* COLOR_WHITE */ + /* R G B */ + {RGB_OFF, RGB_OFF, RGB_OFF}, /* COLOR_BLACK */ + {RGB_ON, RGB_OFF, RGB_OFF}, /* COLOR_RED */ + {RGB_OFF, RGB_ON, RGB_OFF}, /* COLOR_GREEN */ + {RGB_ON, RGB_ON, RGB_OFF}, /* COLOR_YELLOW */ + {RGB_OFF, RGB_OFF, RGB_ON}, /* COLOR_BLUE */ + {RGB_ON, RGB_OFF, RGB_ON}, /* COLOR_MAGENTA */ + {RGB_OFF, RGB_ON, RGB_ON}, /* COLOR_CYAN */ + {RGB_ON, RGB_ON, RGB_ON}, /* COLOR_WHITE */ }; static const color_t hls_palette[] = { @@ -121,11 +136,12 @@ int start_color(void) } #ifdef hue_lightness_saturation +/* This function was originally written by Daniel Weaver <danw@znyx.com> */ static void rgb2hls(short r, short g, short b, short *h, short *l, short *s) /* convert RGB to HLS system */ { short min, max, t; - + if ((min = g < r ? g : r) > b) min = b; if ((max = g > r ? g : r) < b) max = b; @@ -223,14 +239,8 @@ int init_color(short color, short r, short g, short b) if (color < 0 || color >= COLORS) returnCode(ERR); -#ifdef hue_lightness_saturation - if (hue_lightness_saturation == TRUE) - if (r < 0 || r > 360 || g < 0 || g > 100 || b < 0 || b > 100) - returnCode(ERR); - if (hue_lightness_saturation == FALSE) -#endif /* hue_lightness_saturation */ - if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) - returnCode(ERR); + if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) + returnCode(ERR); #ifdef hue_lightness_saturation if (hue_lightness_saturation) @@ -259,19 +269,19 @@ int init_color(short color, short r, short g, short b) bool can_change_color(void) { T((T_CALLED("can_change_color()"))); - returnCode(can_change != 0); + returnCode ((can_change != 0) ? TRUE : FALSE); } bool has_colors(void) { T((T_CALLED("has_colors()"))); - returnCode((orig_pair != NULL || orig_colors != NULL) - && (max_colors != -1) && (max_pairs != -1) - && - (((set_foreground != NULL) && (set_background != NULL)) - || ((set_a_foreground != NULL) && (set_a_background != NULL)) - || set_color_pair) - ); + returnCode (((orig_pair != NULL || orig_colors != NULL) + && (max_colors != -1) && (max_pairs != -1) + && (((set_foreground != NULL) + && (set_background != NULL)) + || ((set_a_foreground != NULL) + && (set_a_background != NULL)) + || set_color_pair)) ? TRUE : FALSE); } int color_content(short color, short *r, short *g, short *b) @@ -280,9 +290,9 @@ int color_content(short color, short *r, short *g, short *b) if (color < 0 || color > COLORS) returnCode(ERR); - *r = SP->_color_table[color].red; - *g = SP->_color_table[color].green; - *b = SP->_color_table[color].blue; + if (r) *r = SP->_color_table[color].red; + if (g) *g = SP->_color_table[color].green; + if (b) *b = SP->_color_table[color].blue; returnCode(OK); } @@ -292,8 +302,8 @@ int pair_content(short pair, short *f, short *b) if ((pair < 0) || (pair > COLOR_PAIRS)) returnCode(ERR); - *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); - *b = (SP->_color_pairs[pair] & C_MASK); + if (f) *f = ((SP->_color_pairs[pair] >> C_SHIFT) & C_MASK); + if (b) *b = (SP->_color_pairs[pair] & C_MASK); returnCode(OK); } @@ -354,7 +364,7 @@ void _nc_do_color(int pair, int (*outc)(int)) } if (fg != C_MASK) { - if (set_a_foreground) + if (set_a_foreground && fg <= MAX_ANSI_COLOR) { TPUTS_TRACE("set_a_foreground"); tputs(tparm(set_a_foreground, fg), 1, outc); @@ -367,7 +377,7 @@ void _nc_do_color(int pair, int (*outc)(int)) } if (bg != C_MASK) { - if (set_a_background) + if (set_a_background && bg <= MAX_ANSI_COLOR) { TPUTS_TRACE("set_a_background"); tputs(tparm(set_a_background, bg), 1, outc); diff --git a/lib/libcurses/lib_data.c b/lib/libcurses/lib_data.c index c7d6c559590..ec0b56a120d 100644 --- a/lib/libcurses/lib_data.c +++ b/lib/libcurses/lib_data.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_data.c,v 1.3 1997/12/03 05:21:14 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,24 +30,11 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_data.c,v 1.8 1997/01/18 23:02:54 tom Exp $") +MODULE_ID("Id: lib_data.c,v 1.10 1997/09/03 15:27:09 Alexander.V.Lukyanov Exp $") WINDOW *stdscr, *curscr, *newscr; -/* - * Linked-list of all windows, to support '_nc_resizeall()' and '_nc_freeall()' - */ -WINDOWLIST *_nc_windows; - -/* - * These data correspond to the state of the idcok() and idlok() functions. A - * caveat is in order here: the XSI and SVr4 documentation specify that these - * functions apply to the window which is given as an argument. However, - * ncurses implements this logic only for the newscr/curscr update process, - * _not_ per-window. - */ -bool _nc_idcok = TRUE; -bool _nc_idlok = FALSE; +SCREEN *_nc_screen_chain; /* * The variable 'SP' will be defined as a function on systems that cannot link diff --git a/lib/libcurses/lib_delch.c b/lib/libcurses/lib_delch.c index 4813c4b2fd2..df857dde085 100644 --- a/lib/libcurses/lib_delch.c +++ b/lib/libcurses/lib_delch.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_delch.c,v 1.3 1997/12/03 05:21:15 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,31 +30,35 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_delch.c,v 1.5 1997/02/01 23:18:18 tom Exp $") +MODULE_ID("Id: lib_delch.c,v 1.6 1997/09/20 15:02:34 juergen Exp $") int wdelch(WINDOW *win) { +int code = ERR; chtype *temp1, *temp2; chtype *end; chtype blank = _nc_background(win); T((T_CALLED("wdelch(%p)"), win)); - end = &win->_line[win->_cury].text[win->_maxx]; - temp2 = &win->_line[win->_cury].text[win->_curx + 1]; - temp1 = temp2 - 1; - - while (temp1 < end) + if (win) { + end = &win->_line[win->_cury].text[win->_maxx]; + temp2 = &win->_line[win->_cury].text[win->_curx + 1]; + temp1 = temp2 - 1; + + while (temp1 < end) *temp1++ = *temp2++; - - *temp1 = blank; - - win->_line[win->_cury].lastchar = win->_maxx; - - if (win->_line[win->_cury].firstchar == _NOCHANGE - || win->_line[win->_cury].firstchar > win->_curx) + + *temp1 = blank; + + win->_line[win->_cury].lastchar = win->_maxx; + + if (win->_line[win->_cury].firstchar == _NOCHANGE + || win->_line[win->_cury].firstchar > win->_curx) win->_line[win->_cury].firstchar = win->_curx; - - _nc_synchook(win); - returnCode(OK); + + _nc_synchook(win); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/lib_delwin.c b/lib/libcurses/lib_delwin.c index 542abcaf437..290159c4841 100644 --- a/lib/libcurses/lib_delwin.c +++ b/lib/libcurses/lib_delwin.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_delwin.c,v 1.3 1997/12/03 05:21:15 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_dft_fgbg.c b/lib/libcurses/lib_dft_fgbg.c index 1494f39a307..a821af4d677 100644 --- a/lib/libcurses/lib_dft_fgbg.c +++ b/lib/libcurses/lib_dft_fgbg.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_dft_fgbg.c,v 1.2 1997/12/03 05:21:16 millert Exp $ */ + /****************************************************************************** * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * * All Rights Reserved. * diff --git a/lib/libcurses/lib_doupdate.c b/lib/libcurses/lib_doupdate.c index 841ca48a95a..b62efe5cd62 100644 --- a/lib/libcurses/lib_doupdate.c +++ b/lib/libcurses/lib_doupdate.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_doupdate.c,v 1.4 1997/12/03 05:21:16 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * **************************************************************************** @@ -37,7 +39,7 @@ #define USE_TRACE_TIMES 0 #endif -#if HAVE_SYS_TIME_H && ! SYSTEM_LOOKS_LIKE_SCO +#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT #include <sys/time.h> #endif @@ -56,7 +58,7 @@ #include <term.h> -MODULE_ID("Id: lib_doupdate.c,v 1.60 1997/05/03 19:32:55 Alexander.V.Lukyanov Exp $") +MODULE_ID("Id: lib_doupdate.c,v 1.93 1997/11/15 22:48:57 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -67,7 +69,7 @@ MODULE_ID("Id: lib_doupdate.c,v 1.60 1997/05/03 19:32:55 Alexander.V.Lukyanov Ex * Note: Input-check-and-abort is no longer done if the screen is being * updated from scratch. This is a feature, not a bug. */ -#define CHECK_INTERVAL 6 +#define CHECK_INTERVAL 5 /* * Enable checking to see if doupdate and friends are tracking the true @@ -77,11 +79,10 @@ MODULE_ID("Id: lib_doupdate.c,v 1.60 1997/05/03 19:32:55 Alexander.V.Lukyanov Ex /* #define POSITION_DEBUG */ static inline chtype ClrBlank ( WINDOW *win ); -static inline chtype ClrSetup ( WINDOW *scr ); static int ClrBottom(int total); static int InsStr( chtype *line, int count ); -static void ClearScreen( void ); -static void ClrUpdate( WINDOW *scr ); +static void ClearScreen( chtype blank ); +static void ClrUpdate( WINDOW *win ); static void DelChar( int count ); static void TransformLine( int const lineno ); @@ -175,6 +176,16 @@ static inline void PutAttrChar(chtype ch) static bool check_pending(void) /* check for pending input */ { + bool have_pending = FALSE; + + /* + * Only carry out this check when the flag is zero, otherwise we'll + * have the refreshing slow down drastically (or stop) if there's an + * unread character available. + */ + if(SP->_fifohold != 0) + return FALSE; + if (SP->_checkfd >= 0) { #if USE_FUNC_POLL struct pollfd fds[1]; @@ -182,8 +193,7 @@ static bool check_pending(void) fds[0].events = POLLIN; if (poll(fds, 1, 0) > 0) { - fflush(SP->_ofp); - return TRUE; + have_pending = TRUE; } #elif HAVE_SELECT fd_set fdset; @@ -196,11 +206,14 @@ static bool check_pending(void) FD_SET(SP->_checkfd, &fdset); if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) > 0) { - fflush(SP->_ofp); - return TRUE; + have_pending = TRUE; } #endif } + if (have_pending) { + SP->_fifohold = 5; + fflush(SP->_ofp); + } return FALSE; } @@ -214,73 +227,82 @@ static void callPutChar(chtype const); #define callPutChar(ch) PutChar(ch) #endif -static inline void PutChar(chtype const ch) -/* insert character, handling automargin stuff */ +static inline void PutChar(chtype const ch); /* forward declaration */ + +/* put char at lower right corner */ +static void PutCharLR(chtype const ch) { - if (!(SP->_cursrow == screen_lines-1 && SP->_curscol == screen_columns-1 - && auto_right_margin && !eat_newline_glitch)) + if (!auto_right_margin) { - PutAttrChar(ch); /* normal case */ + /* we can put the char directly */ + PutAttrChar(ch); } - else if (!auto_right_margin /* maybe we can suppress automargin */ - || (enter_am_mode && exit_am_mode)) + else if (enter_am_mode && exit_am_mode) { - bool old_am = auto_right_margin; + /* we can suppress automargin */ + TPUTS_TRACE("exit_am_mode"); + putp(exit_am_mode); - if (old_am) - { - TPUTS_TRACE("exit_am_mode"); - putp(exit_am_mode); - } PutAttrChar(ch); - if (old_am) - { - TPUTS_TRACE("enter_am_mode"); - putp(enter_am_mode); - } + + TPUTS_TRACE("enter_am_mode"); + putp(enter_am_mode); } - else + else if ((enter_insert_mode && exit_insert_mode) + || insert_character || parm_ich) { GoTo(screen_lines-1,screen_columns-2); callPutChar(ch); GoTo(screen_lines-1,screen_columns-2); - if (InsStr(newscr->_line[screen_lines-1].text+screen_columns-2,1)==ERR) - return; + InsStr(newscr->_line[screen_lines-1].text+screen_columns-2,1); } +} - if (SP->_curscol >= screen_columns) +static void wrap_cursor(void) +{ + if (eat_newline_glitch) { - if (eat_newline_glitch) - { - /* - * xenl can manifest two different ways. The vt100 - * way is that, when you'd expect the cursor to wrap, - * it stays hung at the right margin (on top of the - * character just emitted) and doesn't wrap until the - * *next* graphic char is emitted. The c100 way is - * to ignore LF received just after an am wrap. - * - * An aggressive way to handle this would be to - * emit CR/LF after the char and then assume the wrap - * is done, you're on the first position of the next - * line, and the terminal out of its weird state. - * Here it's safe to just tell the code that the - * cursor is in hyperspace and let the next mvcur() - * call straighten things out. - */ - SP->_curscol = -1; - SP->_cursrow = -1; - } - else if (auto_right_margin) - { - SP->_curscol = 0; - SP->_cursrow++; - } - else - { - SP->_curscol--; - } + /* + * xenl can manifest two different ways. The vt100 + * way is that, when you'd expect the cursor to wrap, + * it stays hung at the right margin (on top of the + * character just emitted) and doesn't wrap until the + * *next* graphic char is emitted. The c100 way is + * to ignore LF received just after an am wrap. + * + * An aggressive way to handle this would be to + * emit CR/LF after the char and then assume the wrap + * is done, you're on the first position of the next + * line, and the terminal out of its weird state. + * Here it's safe to just tell the code that the + * cursor is in hyperspace and let the next mvcur() + * call straighten things out. + */ + SP->_curscol = -1; + SP->_cursrow = -1; } + else if (auto_right_margin) + { + SP->_curscol = 0; + SP->_cursrow++; + } + else + { + SP->_curscol--; + } +} + +static inline void PutChar(chtype const ch) +/* insert character, handling automargin stuff */ +{ + if (SP->_cursrow == screen_lines-1 && SP->_curscol == screen_columns-1) + PutCharLR(ch); + else + PutAttrChar(ch); + + if (SP->_curscol >= screen_columns) + wrap_cursor(); + #ifdef POSITION_DEBUG position_check(SP->_cursrow, SP->_curscol, "PutChar"); #endif /* POSITION_DEBUG */ @@ -298,7 +320,7 @@ static inline void PutChar(chtype const ch) * * This code is optimized using ech and rep. */ -static inline int EmitRange(const chtype *ntext, int num) +static int EmitRange(const chtype *ntext, int num) { int i; @@ -431,7 +453,7 @@ static void callPutChar(chtype const ch) { \ win->_line[row].firstchar = _NOCHANGE; \ win->_line[row].lastchar = _NOCHANGE; \ - win->_line[row].oldindex = row; \ + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); \ } int doupdate(void) @@ -457,26 +479,33 @@ struct tms before, after; _nc_signal_handler(FALSE); - if (SP->_endwin == TRUE) { - - T(("coming back from shell mode")); - reset_prog_mode(); + if (SP->_fifohold) + SP->_fifohold--; #ifndef EXTERN_TERMINFO + if (SP->_endwin || SP->_sig_winch) + { /* * This is a transparent extension: XSI does not address it, - * and applications need not know that ncurses can do it. + * and applications need not know that ncurses can do it. * * Check if the terminal size has changed while curses was off * (this can happen in an xterm, for example), and resize the * ncurses data structures accordingly. */ - _nc_get_screensize(); - resizeterm(LINES, COLS); + _nc_update_screensize(); + } #endif + + if (SP->_endwin) { + + T(("coming back from shell mode")); + reset_prog_mode(); + _nc_mvcur_resume(); - _nc_mouse_resume(SP); - newscr->_clear = TRUE; + _nc_screen_resume(); + SP->_mouse_resume(SP); + SP->_endwin = FALSE; } @@ -499,6 +528,7 @@ struct tms before, after; * guaranteed room for its cookie). If not, nuke the added * attributes out of the span. */ +#if USE_XMC_SUPPORT if (magic_cookie_glitch > 0) { int j, k; attr_t rattr = A_NORMAL; @@ -510,8 +540,10 @@ struct tms before, after; chtype turnon = AttrOf(newscr->_line[i].text[j]) & ~rattr; /* is an attribute turned on here? */ - if (turnon == 0) + if (turnon == 0) { + rattr = AttrOf(newscr->_line[i].text[j]); continue; + } T(("At (%d, %d): from %s...", i, j, _traceattr(rattr))); T(("...to %s",_traceattr(turnon))); @@ -522,7 +554,7 @@ struct tms before, after; * ensure there's enough room to set the attribute before * the first non-blank in the run. */ -#define SAFE(a) !((a) & ~NONBLANK_ATTR) +#define SAFE(a) !((a) & (chtype)~NONBLANK_ATTR) if (TextOf(newscr->_line[i].text[j])==' ' && SAFE(turnon)) { newscr->_line[i].text[j] &= ~turnon; @@ -538,11 +570,13 @@ struct tms before, after; if (!failed) { bool end_onscreen = FALSE; - int m, n = -1; + int m, n = j; /* find end of span, if it's onscreen */ for (m = i; m < screen_lines; m++) - for (n = j; n < screen_columns; n++) + { + for ( ; n < screen_columns; n++) + { if (AttrOf(newscr->_line[m].text[n]) == rattr) { end_onscreen = TRUE; @@ -550,6 +584,9 @@ struct tms before, after; _traceattr(turnon),m,n)); goto foundit; } + } + n = 0; + } T(("Range attributed with %s ends offscreen", _traceattr(turnon))); foundit:; @@ -567,7 +604,7 @@ struct tms before, after; while (n >= 0 && TextOf(lastline[n]) == ' ' && SAFE(AttrOf(lastline[n]))) - lastline[n--] &=~ turnon; + lastline[n--] &= ~turnon; /* check that there's enough room at end of span */ for (k = 1; k <= magic_cookie_glitch; k++) @@ -580,18 +617,22 @@ struct tms before, after; if (failed) { - int p, q; + int p, q = j; T(("Clearing %s beginning at (%d, %d)", _traceattr(turnon), i, j)); /* turn off new attributes over span */ for (p = i; p < screen_lines; p++) - for (q = j; q < screen_columns; q++) + { + for ( ; q < screen_columns; q++) + { if (AttrOf(newscr->_line[p].text[q]) == rattr) goto foundend; - else - newscr->_line[p].text[q] &=~ turnon; + newscr->_line[p].text[q] &= ~turnon; + } + q = 0; + } foundend:; } else @@ -619,36 +660,60 @@ struct tms before, after; } #endif /* TRACE */ } +#endif /* USE_XMC_SUPPORT */ nonempty = 0; if (curscr->_clear) { /* force refresh ? */ + /* yes, clear all & update */ T(("clearing and updating curscr")); - ClrUpdate(newscr); /* yes, clear all & update */ + if (is_wintouched(newscr)) + ClrUpdate(newscr); + else + ClrUpdate(curscr); curscr->_clear = FALSE; /* reset flag */ + newscr->_clear = FALSE; /* reset flag */ } else if (newscr->_clear) { T(("clearing and updating newscr")); ClrUpdate(newscr); newscr->_clear = FALSE; } else { - int changedlines; + int changedlines = CHECK_INTERVAL; + + if(check_pending()) + goto cleanup; nonempty = min(screen_lines, newscr->_maxy+1); -#if 0 /* still 5% slower 960928 */ +#if USE_HASHMAP /* still 5% slower 960928 */ #if defined(TRACE) || defined(NCURSES_TEST) if (_nc_optimize_enable & OPTIMIZE_HASHMAP) #endif /*TRACE */ _nc_hash_map(); +#elif !USE_SCROLL_HINTS + _nc_setup_scroll(); #endif #if defined(TRACE) || defined(NCURSES_TEST) if (_nc_optimize_enable & OPTIMIZE_SCROLL) #endif /*TRACE */ +#if USE_SCROLL_HINTS || USE_HASHMAP _nc_scroll_optimize(); +#else + _nc_perform_scroll(); +#endif - if (clr_eos) - nonempty = ClrBottom(nonempty); + nonempty = ClrBottom(nonempty); T(("Transforming lines, nonempty %d", nonempty)); - for (i = changedlines = 0; i < nonempty; i++) { + for (i = 0; i < nonempty; i++) { + /* + * Here is our line-breakout optimization. + */ + if (changedlines == CHECK_INTERVAL) + { + if (check_pending()) + goto cleanup; + changedlines = 0; + } + /* * newscr->line[i].firstchar is normally set * by wnoutrefresh. curscr->line[i].firstchar @@ -667,13 +732,6 @@ struct tms before, after; MARK_NOCHANGE(newscr,i) if (i <= curscr->_maxy) MARK_NOCHANGE(curscr,i) - - /* - * Here is our line-breakout optimization. - */ - if ((changedlines % CHECK_INTERVAL) == CHECK_INTERVAL-1 - && check_pending()) - goto cleanup; } } @@ -717,9 +775,7 @@ struct tms before, after; * * Returns the attributed character that corresponds to the "cleared" * screen. If the terminal has the back-color-erase feature, this will be - * colored according to the wbkgd() call. (Other attributes are - * unspecified, hence assumed to be reset in accordance with - * 'ClrSetup()'). + * colored according to the wbkgd() call. * * We treat 'curscr' specially because it isn't supposed to be set directly * in the wbkgd() call. Assume 'stdscr' for this case. @@ -736,64 +792,37 @@ chtype blank = BLANK; } /* - * ClrSetup(win) - * - * Ensures that if the terminal recognizes back-color-erase, that we - * set the video attributes to match the window's background color - * before an erase operation. - */ -static inline chtype ClrSetup (WINDOW *win) -{ - if (back_color_erase) - vidattr(BCE_BKGD(win) & BCE_ATTRS); - return ClrBlank(win); -} - -/* -** ClrUpdate(scr) +** ClrUpdate(win) ** ** Update by clearing and redrawing the entire screen. ** */ -static void ClrUpdate(WINDOW *scr) +static void ClrUpdate(WINDOW *win) { -int i = 0, j = 0; -int lastNonBlank; -chtype blank = ClrSetup(scr); - - T(("ClrUpdate(%p) called", scr)); - ClearScreen(); - - if (scr != curscr) { - for (i = 0; i < screen_lines ; i++) - for (j = 0; j < screen_columns; j++) - curscr->_line[i].text[j] = blank; + int i; + chtype blank = ClrBlank(win); + int nonempty = min(screen_lines, newscr->_maxy+1); + + T(("ClrUpdate() called")); + + if (win == curscr) { + /* discard updates */ + for (i = 0; i < screen_lines ; i++) { + memcpy( newscr->_line[i].text, + curscr->_line[i].text, + screen_columns * sizeof(chtype)); + } } - T(("updating screen from scratch")); - for (i = 0; i < min(screen_lines, scr->_maxy + 1); i++) { - lastNonBlank = scr->_maxx; + ClearScreen(blank); - while (lastNonBlank >= 0 - && scr->_line[i].text[lastNonBlank] == blank) - lastNonBlank--; + T(("updating screen from scratch")); - if (lastNonBlank >= 0) { - if (lastNonBlank > screen_columns) - lastNonBlank = screen_columns; - GoTo(i, 0); - PutRange(curscr->_line[i].text, - scr->_line[i].text, i, 0, lastNonBlank); - } - } + nonempty = ClrBottom(nonempty); - if (scr != curscr) { - for (i = 0; i < screen_lines ; i++) - memcpy(curscr->_line[i].text, - scr->_line[i].text, - screen_columns * sizeof(chtype)); - } + for (i = 0; i < nonempty; i++) + TransformLine(i); } /* @@ -834,6 +863,31 @@ bool needclear = FALSE; } /* +** ClrToEOS(blank) +** +** Clear to end of screen, starting at the cursor position +*/ + +static void ClrToEOS(chtype blank) +{ +int row, col; + + UpdateAttrs(blank); + TPUTS_TRACE("clr_eos"); + row = SP->_cursrow; + tputs(clr_eos, screen_lines-row, _nc_outch); + + for (col = SP->_curscol; col < screen_columns; col++) + curscr->_line[row].text[col] = blank; + + for (row++; row < screen_lines; row++) + { + for (col = 0; col < screen_columns; col++) + curscr->_line[row].text[col] = blank; + } +} + +/* * ClrBottom(total) * * Test if clearing the end of the screen would satisfy part of the @@ -851,7 +905,7 @@ int last = min(screen_columns, newscr->_maxx+1); size_t length = sizeof(chtype) * last; chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ - if(!can_clear_with(blank)) + if(!clr_eos || !can_clear_with(blank)) return total; if (tstLine == 0) @@ -867,20 +921,15 @@ chtype blank = newscr->_line[total-1].text[last-1]; /* lower right char */ for (row = total-1; row >= 0; row--) { if (memcmp(tstLine, newscr->_line[row].text, length)) break; - if (newscr->_line[row].firstchar != _NOCHANGE) + if (memcmp(tstLine, curscr->_line[row].text, length)) top = row; } - if (top < total) { + /* don't use clr_eos for just one line if clr_eol available */ + if (top < total-1 || (top < total && !clr_eol && !clr_bol)) { GoTo(top,0); - UpdateAttrs(blank); - TPUTS_TRACE("clr_eos"); - putp(clr_eos); - while (total-- > top) { - for (col = 0; col <= curscr->_maxx; col++) - curscr->_line[total].text[col] = blank; - } - total++; + ClrToEOS(blank); + total = top; } } #if NO_LEAKS @@ -934,6 +983,59 @@ bool attrchanged = FALSE; GoTo(lineno, firstChar); ClrToEOL(ClrBlank(curscr)); PutRange(oldLine, newLine, lineno, 0, (screen_columns-1)); +#if USE_XMC_SUPPORT + +#define NEW(r,c) newscr->_line[r].text[c] +#define xmc_turn_on(a,b) ((((a)^(b)) & ~(a) & SP->_xmc_triggers) != 0) +#define xmc_turn_off(a,b) xmc_turn_on(b,a) + + /* + * This is a very simple loop to paint characters which may have the + * magic cookie glitch embedded. It doesn't know much about video + * attributes which are continued from one line to the next. It + * assumes that we have filtered out requests for attribute changes + * that do not get mapped to blank positions. + * + * FIXME: we are not keeping track of where we put the cookies, so this + * will work properly only once, since we may overwrite a cookie in a + * following operation. + */ + } else if (magic_cookie_glitch > 0) { + GoTo(lineno, firstChar); + for (n = 0; n < screen_columns; n++) { + int m = n + magic_cookie_glitch; + + /* check for turn-on: + * If we are writing an attributed blank, where the + * previous cell is not attributed. + */ + if (TextOf(newLine[n]) == ' ' + && ((n > 0 + && xmc_turn_on(newLine[n-1], newLine[n])) + || (n == 0 + && lineno > 0 + && xmc_turn_on(NEW(lineno-1,screen_columns-1), newLine[n])))) { + n = m; + } + + PutChar(newLine[n]); + + /* check for turn-off: + * If we are writing an attributed non-blank, where the + * next cell is blank, and not attributed. + */ + if (TextOf(newLine[n]) != ' ' + && ((n+1 < screen_columns + && xmc_turn_off(newLine[n], newLine[n+1])) + || (n+1 >= screen_columns + && lineno+1 < screen_lines + && xmc_turn_off(newLine[n], NEW(lineno+1,0))))) { + n = m; + } + + } +#undef NEW +#endif } else { chtype blank; @@ -960,10 +1062,20 @@ bool attrchanged = FALSE; if (nFirstChar > oFirstChar + SP->_el1_cost) { - GoTo(lineno, nFirstChar - 1); - UpdateAttrs(blank); - TPUTS_TRACE("clr_bol"); - putp(clr_bol); + if (nFirstChar >= screen_columns && SP->_el_cost <= SP->_el1_cost) + { + GoTo(lineno, 0); + UpdateAttrs(blank); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } + else + { + GoTo(lineno, nFirstChar - 1); + UpdateAttrs(blank); + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + } while (firstChar < nFirstChar) oldLine[firstChar++] = blank; @@ -979,7 +1091,7 @@ bool attrchanged = FALSE; { /* find the last differing character */ nLastChar = screen_columns - 1; - + while (nLastChar > firstChar && newLine[nLastChar] == oldLine[nLastChar]) nLastChar--; @@ -1005,11 +1117,11 @@ bool attrchanged = FALSE; nLastChar--; if((nLastChar == firstChar) - && (SP->_el_cost < (screen_columns - nLastChar))) { + && (SP->_el_cost < (oLastChar - nLastChar))) { GoTo(lineno, firstChar); - ClrToEOL(blank); if(newLine[firstChar] != blank ) PutChar(newLine[firstChar]); + ClrToEOL(blank); } else if( newLine[nLastChar] != oldLine[oLastChar] || !(_nc_idcok && has_ic()) ) { GoTo(lineno, firstChar); @@ -1082,18 +1194,20 @@ bool attrchanged = FALSE; } /* -** ClearScreen() +** ClearScreen(blank) ** ** Clear the physical screen and put cursor at home ** */ -static void ClearScreen(void) +static void ClearScreen(chtype blank) { + int i, j; T(("ClearScreen() called")); if (clear_screen) { + UpdateAttrs(blank); TPUTS_TRACE("clear_screen"); putp(clear_screen); SP->_cursrow = SP->_curscol = 0; @@ -1104,22 +1218,32 @@ static void ClearScreen(void) SP->_cursrow = SP->_curscol = -1; GoTo(0,0); + UpdateAttrs(blank); TPUTS_TRACE("clr_eos"); putp(clr_eos); } else if (clr_eol) { SP->_cursrow = SP->_curscol = -1; - while (SP->_cursrow < screen_lines) { - GoTo(SP->_cursrow, 0); + for (i = 0; i < screen_lines; i++) { + GoTo(i, 0); + UpdateAttrs(blank); TPUTS_TRACE("clr_eol"); putp(clr_eol); } GoTo(0,0); + } else { + T(("cannot clear screen")); + return; + } + + for (i = 0; i < screen_lines; i++) { + for (j = 0; j < screen_columns; j++) + curscr->_line[i].text[j] = blank; } + T(("screen cleared")); } - /* ** InsStr(line, count) ** @@ -1208,3 +1332,395 @@ void _nc_outstr(const char *str) _nc_outchars += strlen(str); #endif /* TRACE */ } + +/* + * Physical-scrolling support + * + * This code was adapted from Keith Bostic's hardware scrolling + * support for 4.4BSD curses. I (esr) translated it to use terminfo + * capabilities, narrowed the call interface slightly, and cleaned + * up some convoluted tests. I also added support for the memory_above + * memory_below, and non_dest_scroll_region capabilities. + * + * For this code to work, we must have either + * change_scroll_region and scroll forward/reverse commands, or + * insert and delete line capabilities. + * When the scrolling region has been set, the cursor has to + * be at the last line of the region to make the scroll up + * happen, or on the first line of region to scroll down. + * + * This code makes one aesthetic decision in the opposite way from + * BSD curses. BSD curses preferred pairs of il/dl operations + * over scrolls, allegedly because il/dl looked faster. We, on + * the other hand, prefer scrolls because (a) they're just as fast + * on many terminals and (b) using them avoids bouncing an + * unchanged bottom section of the screen up and down, which is + * visually nasty. + * + * (lav): added more cases, used dl/il when bot==maxy and in csr case. + * + * I used assumption that capabilities il/il1/dl/dl1 work inside + * changed scroll region not shifting screen contents outside of it. + * If there are any terminals behaving different way, it would be + * necessary to add some conditions to scroll_csr_forward/backward. + */ + +/* Try to scroll up assuming given csr (miny, maxy). Returns ERR on failure */ +static int scroll_csr_forward(int n, int top, int bot, int miny, int maxy, chtype blank) +{ + int i; + + if (n == 1 && scroll_forward && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + TPUTS_TRACE("scroll_forward"); + tputs(scroll_forward, 0, _nc_outch); + } + else if (n == 1 && delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + else if (parm_index && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_index"); + tputs(tparm(parm_index, n, 0), n, _nc_outch); + } + else if (parm_delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_delete_line"); + tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + } + else if (scroll_forward && top == miny && bot == maxy) + { + GoTo(bot, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("scroll_forward"); + tputs(scroll_forward, 0, _nc_outch); + } + } + else if (delete_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + } + else + return ERR; + + return OK; +} + +/* Try to scroll down assuming given csr (miny, maxy). Returns ERR on failure */ +/* n > 0 */ +static int scroll_csr_backward(int n, int top, int bot, int miny, int maxy, chtype blank) +{ + int i; + + if (n == 1 && scroll_reverse && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("scroll_reverse"); + tputs(scroll_reverse, 0, _nc_outch); + } + else if (n == 1 && insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + else if (parm_rindex && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_rindex"); + tputs(tparm(parm_rindex, n, 0), n, _nc_outch); + } + else if (parm_insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + } + else if (scroll_reverse && top == miny && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("scroll_reverse"); + tputs(scroll_reverse, 0, _nc_outch); + } + } + else if (insert_line && bot == maxy) + { + GoTo(top, 0); + UpdateAttrs(blank); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + } + else + return ERR; + + return OK; +} + +/* scroll by using delete_line at del and insert_line at ins */ +/* n > 0 */ +static int scroll_idl(int n, int del, int ins, chtype blank) +{ + int i; + + if(!((parm_delete_line || delete_line) && (parm_insert_line || insert_line))) + return ERR; + + GoTo(del, 0); + UpdateAttrs(blank); + if (n == 1 && delete_line) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + else if (parm_delete_line) + { + TPUTS_TRACE("parm_delete_line"); + tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + } + else /* if (delete_line) */ + { + for (i = 0; i < n; i++) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + } + + GoTo(ins, 0); + UpdateAttrs(blank); + if (n == 1 && insert_line) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + else if (parm_insert_line) + { + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + } + else /* if (insert_line) */ + { + for (i = 0; i < n; i++) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + } + + return OK; +} + +int _nc_scrolln(int n, int top, int bot, int maxy) +/* scroll region from top to bot by n lines */ +{ + chtype blank=ClrBlank(stdscr); + int i; + bool cursor_saved=FALSE; + int res; + + TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy)); + +#if USE_XMC_SUPPORT + /* + * If we scroll, we might remove a cookie. + */ + if (magic_cookie_glitch > 0) { + return (ERR); + } +#endif + + if (n > 0) /* scroll up (forward) */ + { + /* + * Explicitly clear if stuff pushed off top of region might + * be saved by the terminal. + */ + if (non_dest_scroll_region || (memory_above && top == 0)) { + for (i = 0; i < n; i++) + { + GoTo(i, 0); + ClrToEOL(BLANK); + } + } + + res = scroll_csr_forward(n, top, bot, 0, maxy, blank); + + if (res == ERR && change_scroll_region) + { + if ((((n==1 && scroll_forward) || parm_index) + && (SP->_cursrow == bot || SP->_cursrow == bot-1)) + && save_cursor && restore_cursor) + { + cursor_saved=TRUE; + TPUTS_TRACE("save_cursor"); + tputs(save_cursor, 0, _nc_outch); + } + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + if (cursor_saved) + { + TPUTS_TRACE("restore_cursor"); + tputs(restore_cursor, 0, _nc_outch); + } + else + { + SP->_cursrow = SP->_curscol = -1; + } + + res = scroll_csr_forward(n, top, bot, top, bot, blank); + + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + SP->_cursrow = SP->_curscol = -1; + } + + if (res == ERR && _nc_idlok) + res = scroll_idl(n, top, bot-n+1, blank); + } + else /* (n < 0) - scroll down (backward) */ + { + /* + * Do explicit clear to end of region if it's possible that the + * terminal might hold on to stuff we push off the end. + */ + if (non_dest_scroll_region || (memory_below && bot == maxy)) + { + if (bot == maxy && clr_eos) + { + GoTo(maxy + n, 0); + ClrToEOS(BLANK); + } + else if (clr_eol) + { + for (i = 0; i < -n; i++) + { + GoTo(maxy + n + i, 0); + ClrToEOL(BLANK); + } + } + } + + res = scroll_csr_backward(-n, top, bot, 0, maxy, blank); + + if (res == ERR && change_scroll_region) + { + if (top != 0 && (SP->_cursrow == top || SP->_cursrow == top-1) + && save_cursor && restore_cursor) + { + cursor_saved=TRUE; + TPUTS_TRACE("save_cursor"); + tputs(save_cursor, 0, _nc_outch); + } + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); + if (cursor_saved) + { + TPUTS_TRACE("restore_cursor"); + tputs(restore_cursor, 0, _nc_outch); + } + else + { + SP->_cursrow = SP->_curscol = -1; + } + + res = scroll_csr_backward(-n, top, bot, top, bot, blank); + + TPUTS_TRACE("change_scroll_region"); + tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); + SP->_cursrow = SP->_curscol = -1; + } + + if (res == ERR && _nc_idlok) + res = scroll_idl(-n, bot+n+1, top, blank); + } + + if (res == ERR) + return(ERR); + + _nc_scroll_window(curscr, n, top, bot, blank); + + return(OK); +} + + +void _nc_screen_resume() +{ + /* make sure terminal is in a sane known state */ + SP->_current_attr = A_NORMAL; + newscr->_clear = TRUE; + + if (SP->_coloron == TRUE && orig_pair) + putp(orig_pair); + if (exit_attribute_mode) + putp(exit_attribute_mode); + else + { + /* turn off attributes */ + if (exit_alt_charset_mode) + putp(exit_alt_charset_mode); + if (exit_standout_mode) + putp(exit_standout_mode); + if (exit_underline_mode) + putp(exit_underline_mode); + } + if (exit_insert_mode) + putp(exit_insert_mode); + if (enter_am_mode && exit_am_mode) + putp(auto_right_margin ? enter_am_mode : exit_am_mode); +} + +void _nc_screen_init() +{ + _nc_screen_resume(); +} + +/* wrap up screen handling */ +void _nc_screen_wrap() +{ + UpdateAttrs(A_NORMAL); +} + +#if USE_XMC_SUPPORT +void _nc_do_xmc_glitch(attr_t previous) +{ + attr_t chg = XMC_CHANGES(previous ^ SP->_current_attr); + + while (chg != 0) { + if (chg & 1) { + SP->_curscol += magic_cookie_glitch; + if (SP->_curscol >= SP->_columns) + wrap_cursor(); + T(("bumped to %d,%d after cookie", SP->_cursrow, SP->_curscol)); + } + chg >>= 1; + } +} +#endif /* USE_XMC_SUPPORT */ diff --git a/lib/libcurses/lib_endwin.c b/lib/libcurses/lib_endwin.c index f3fce19e72a..a5b96972691 100644 --- a/lib/libcurses/lib_endwin.c +++ b/lib/libcurses/lib_endwin.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_endwin.c,v 1.4 1997/12/03 05:21:16 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,39 +32,19 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("Id: lib_endwin.c,v 1.10 1997/02/02 00:36:41 tom Exp $") +MODULE_ID("Id: lib_endwin.c,v 1.13 1997/10/11 22:05:27 tom Exp $") int endwin(void) { T((T_CALLED("endwin()"))); - SP->_endwin = TRUE; - - _nc_mouse_wrap(SP); - - /* SP->_curs{row,col} may be used later in _nc_mvcur_wrap,save_curs */ - mvcur(-1, -1, SP->_cursrow = screen_lines - 1, SP->_curscol = 0); - - curs_set(1); /* set cursor to normal mode */ - - if (SP->_coloron == TRUE && orig_pair) - putp(orig_pair); - - _nc_mvcur_wrap(); /* wrap up cursor addressing */ - - if (SP && (SP->_current_attr != A_NORMAL)) - vidattr(A_NORMAL); - - /* - * Reset terminal's tab counter. There's a long-time bug that - * if you exit a "curses" program such as vi or more, tab - * forward, and then backspace, the cursor doesn't go to the - * right place. The problem is that the kernel counts the - * escape sequences that reset things as column positions. - * Utter a \r to reset this invisibly. - */ - _nc_outch('\r'); + if (SP) { + SP->_endwin = TRUE; + SP->_mouse_wrap(SP); + _nc_screen_wrap(); + _nc_mvcur_wrap(); /* wrap up cursor addressing */ + } returnCode(reset_shell_mode()); } diff --git a/lib/libcurses/lib_erase.c b/lib/libcurses/lib_erase.c index 3bdf64a4523..37575c79141 100644 --- a/lib/libcurses/lib_erase.c +++ b/lib/libcurses/lib_erase.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_erase.c,v 1.3 1997/12/03 05:21:17 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,40 +31,33 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_erase.c,v 1.7 1997/02/01 23:18:18 tom Exp $") +MODULE_ID("Id: lib_erase.c,v 1.10 1997/09/20 15:02:34 juergen Exp $") int werase(WINDOW *win) { +int code = ERR; int y; -chtype *sp, *end, *start, *maxx = NULL; -short minx; +chtype blank; +chtype *sp, *end, *start; T((T_CALLED("werase(%p)"), win)); - for (y = 0; y <= win->_maxy; y++) { - minx = _NOCHANGE; - start = win->_line[y].text; - end = &start[win->_maxx]; - - maxx = start; - for (sp = start; sp <= end; sp++) { - maxx = sp; - if (minx == _NOCHANGE) - minx = sp - start; - *sp = _nc_background(win); - } - - if (minx != _NOCHANGE) { - if (win->_line[y].firstchar > minx || - win->_line[y].firstchar == _NOCHANGE) - win->_line[y].firstchar = minx; - - if (win->_line[y].lastchar < maxx - win->_line[y].text) - win->_line[y].lastchar = maxx - win->_line[y].text; - } + if (win) { + blank = _nc_background(win); + for (y = 0; y <= win->_maxy; y++) { + start = win->_line[y].text; + end = &start[win->_maxx]; + + for (sp = start; sp <= end; sp++) + *sp = blank; + + win->_line[y].firstchar = 0; + win->_line[y].lastchar = win->_maxx; + } + win->_curx = win->_cury = 0; + win->_flags &= ~_WRAPPED; + _nc_synchook(win); + code = OK; } - win->_curx = win->_cury = 0; - win->_flags &= ~_WRAPPED; - _nc_synchook(win); - returnCode(OK); + returnCode(code); } diff --git a/lib/libcurses/lib_flash.c b/lib/libcurses/lib_flash.c new file mode 100644 index 00000000000..05ec2e26330 --- /dev/null +++ b/lib/libcurses/lib_flash.c @@ -0,0 +1,59 @@ +/* $OpenBSD: lib_flash.c,v 1.1 1997/12/03 05:21:17 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + + +/* + * flash.c + * + * The routine flash(). + * + */ + +#include <curses.priv.h> +#include <term.h> /* beep, flash */ + +MODULE_ID("Id: lib_flash.c,v 1.1 1997/10/08 05:59:49 jtc Exp $") + +/* + * flash() + * + * Flash the current terminal's screen if possible. If not, + * sound the audible bell if one exists. + * + */ + +int flash(void) +{ + T((T_CALLED("flash()"))); + + /* FIXME: should make sure that we are not in altchar mode */ + if (flash_screen) { + TPUTS_TRACE("flash_screen"); + returnCode(putp(flash_screen)); + } else if (bell) { + TPUTS_TRACE("bell"); + returnCode(putp(bell)); + } + else + returnCode(ERR); +} diff --git a/lib/libcurses/lib_getch.c b/lib/libcurses/lib_getch.c index c0d0d5af203..c3e936cd302 100644 --- a/lib/libcurses/lib_getch.c +++ b/lib/libcurses/lib_getch.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_getch.c,v 1.3 1997/12/03 05:21:18 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -28,34 +30,21 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_getch.c,v 1.24 1997/02/15 21:12:16 tom Exp $") - -#define head SP->_fifohead -#define tail SP->_fifotail -#define peek SP->_fifopeek +MODULE_ID("Id: lib_getch.c,v 1.37 1997/11/30 00:37:38 tom Exp $") -#define h_inc() { head == FIFO_SIZE-1 ? head = 0 : head++; if (head == tail) head = -1, tail = 0;} -#define h_dec() { head == 0 ? head = FIFO_SIZE-1 : head--; if (head == tail) tail = -1;} -#define t_inc() { tail == FIFO_SIZE-1 ? tail = 0 : tail++; if (tail == head) tail = -1;} -#define p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;} +#include <fifo_defs.h> int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ -static int fifo_peek(void) +static inline int fifo_peek(void) { - T(("peeking at %d", peek+1)); - return SP->_fifo[++peek]; + int ch = SP->_fifo[peek]; + T(("peeking at %d", peek)); + + p_inc(); + return ch; } -#ifdef TRACE -static inline void fifo_dump(void) -{ -int i; - T(("head = %d, tail = %d, peek = %d", head, tail, peek)); - for (i = 0; i < 10; i++) - T(("char %d = %s", i, _trace_key(SP->_fifo[i]))); -} -#endif /* TRACE */ static inline int fifo_pull(void) { @@ -63,55 +52,48 @@ int ch; ch = SP->_fifo[head]; T(("pulling %d from %d", ch, head)); - h_inc(); + if (peek == head) + { + h_inc(); + peek = head; + } + else + h_inc(); + #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) fifo_dump(); + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); #endif return ch; } -int ungetch(int ch) -{ - if (tail == -1) - return ERR; - if (head == -1) { - head = 0; - t_inc() - } else - h_dec(); - - SP->_fifo[head] = ch; - T(("ungetch ok")); -#ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) fifo_dump(); -#endif - return OK; -} - static inline int fifo_push(void) { int n; unsigned int ch; if (tail == -1) return ERR; - /* FALLTHRU */ + +#ifdef HIDE_EINTR again: errno = 0; +#endif + #if USE_GPM_SUPPORT - if ((_nc_mouse_fd() >= 0) + if ((SP->_mouse_fd >= 0) && (_nc_timed_wait(3, -1, (int *)0) & 2)) { - _nc_mouse_event(SP); + SP->_mouse_event(SP); ch = KEY_MOUSE; n = 1; } else #endif { - unsigned char c2; + unsigned char c2=0; n = read(SP->_ifd, &c2, 1); ch = c2; } +#ifdef HIDE_EINTR /* * Under System V curses with non-restarting signals, getch() returns * with value ERR when a handled signal keeps it from completing. @@ -123,20 +105,23 @@ again: */ if (n <= 0 && errno == EINTR) goto again; +#endif if ((n == -1) || (n == 0)) { - T(("read(%d,&ch,1)=%d", SP->_ifd, n)); + T(("read(%d,&ch,1)=%d, errno=%d", SP->_ifd, n, errno)); return ERR; } T(("read %d characters", n)); SP->_fifo[tail] = ch; - if (head == -1) head = tail; + SP->_fifohold = 0; + if (head == -1) + head = peek = tail; t_inc(); T(("pushed %#x at %d", ch, tail)); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) fifo_dump(); + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); #endif return ch; } @@ -151,34 +136,9 @@ int i; static int kgetch(WINDOW *); -void _nc_backspace(WINDOW *win) -{ - if (win->_curx == 0) - { - beep(); - return; - } - - mvwaddstr(curscr, win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx, "\b \b"); - waddstr(win, "\b \b"); - - /* - * This used to do the equivalent of _nc_outstr("\b \b"), which - * would fail on terminals with a non-backspace cursor_left - * character. - */ - mvcur(win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx, - win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx - 1); - _nc_outstr(" "); - mvcur(win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx, - win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx - 1); - SP->_curscol--; -} +#define wgetch_should_refresh(win) (\ + (is_wintouched(win) || (win->_flags & _HASMOVED)) \ + && !(win->_flags & _ISPAD)) int wgetch(WINDOW *win) @@ -187,6 +147,19 @@ int ch; T((T_CALLED("wgetch(%p)"), win)); + if (!win) + returnCode(ERR); + + if (cooked_key_in_fifo()) + { + if (wgetch_should_refresh(win)) + wrefresh(win); + + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + /* * Handle cooked mode. Grab a string from the screen, * stuff its contents in the FIFO queue, and pop off @@ -200,23 +173,15 @@ int ch; wgetnstr(win, buf, MAXCOLUMNS); - for (sp = buf; *sp; sp++) - ungetch(*sp); + /* ungetch in reverse order */ ungetch('\n'); + for (sp = buf+strlen(buf); sp>buf; sp--) + ungetch(sp[-1]); - return(fifo_pull()); + returnCode(fifo_pull()); } - /* this should be eliminated */ - if (!has_ic() - && !win->_scroll - && (SP->_echo) - && (win->_flags & _FULLWIN) - && win->_curx == win->_maxx - && win->_cury == win->_maxy) - returnCode(ERR); - - if ((is_wintouched(win) || (win->_flags & _HASMOVED)) && !(win->_flags & _ISPAD)) + if (wgetch_should_refresh(win)) wrefresh(win); if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { @@ -224,11 +189,11 @@ int ch; T(("timed delay in wgetch()")); if (SP->_cbreak > 1) - delay = (SP->_cbreak-1) * 100; + delay = (SP->_cbreak - 1) * 100; else delay = win->_delay; - T(("delay is %d microseconds", delay)); + T(("delay is %d milliseconds", delay)); if (head == -1) /* fifo is empty */ if (!_nc_timed_wait(3, delay, (int *)0)) @@ -246,7 +211,7 @@ int ch; * * Note: if the mouse code starts failing to compose * press/release events into clicks, you should probably - * increase _nc_max_click_interval. + * increase the wait with mouseinterval(). */ int runcount = 0; @@ -255,13 +220,13 @@ int ch; if (ch == KEY_MOUSE) { ++runcount; - if (_nc_mouse_inline(SP)) + if (SP->_mouse_inline(SP)) break; } } while (ch == KEY_MOUSE - && (_nc_timed_wait(3, _nc_max_click_interval, (int *)0) - || !_nc_mouse_parse(runcount))); + && (_nc_timed_wait(3, SP->_maxclick, (int *)0) + || !SP->_mouse_parse(runcount))); if (runcount > 0 && ch != KEY_MOUSE) { /* mouse event sequence ended by keystroke, push it */ @@ -276,6 +241,17 @@ int ch; if (ch == ERR) { + if(SP->_sig_winch) + { + _nc_update_screensize(); + /* resizeterm can push KEY_RESIZE */ + if(cooked_key_in_fifo()) + { + ch = fifo_pull(); + T(("wgetch returning (pre-cooked): %#x = %s", ch, _trace_key(ch));) + returnCode(ch); + } + } T(("wgetch returning ERR")); returnCode(ERR); } @@ -295,20 +271,8 @@ int ch; if (!SP->_use_meta) ch &= 0x7f; - if (!(win->_flags & _ISPAD) && SP->_echo) { - /* there must be a simpler way of doing this */ - if (ch == erasechar() || ch == KEY_BACKSPACE || ch == KEY_LEFT) - _nc_backspace(win); - else if (ch < KEY_MIN) { - mvwaddch(curscr, - win->_begy + win->_cury + win->_yoffset, - win->_begx + win->_curx, - ch); - waddch(win, (chtype)ch); - } - else - beep(); - } + if (SP->_echo && ch < KEY_MIN && !(win->_flags & _ISPAD)) + wechochar(win, (chtype)ch); T(("wgetch returning : %#x = %s", ch, _trace_key(ch));) @@ -326,6 +290,9 @@ int ch; ** sequence is received by the time the alarm goes off, pass through ** the sequence gotten so far. ** +** This function must be called when there is no cooked keys in queue. +** (that is head==-1 || peek==head) +** */ static int @@ -339,43 +306,60 @@ int timeleft = ESCDELAY; ptr = SP->_keytry; - if (head == -1) { - if ((ch = fifo_push()) == ERR) - return ERR; - peek = 0; - while (ptr != NULL) { - TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char)ch))); - while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) - ptr = ptr->sibling; + for(;;) + { + if (!raw_key_in_fifo()) + { + if(fifo_push() == ERR) + { + peek = head; /* the keys stay uninterpreted */ + return ERR; + } + } + ch = fifo_peek(); + if (ch >= KEY_MIN) + { + peek = head; + /* assume the key is the last in fifo */ + t_dec(); /* remove the key */ + return ch; + } + + TR(TRACE_IEVENT, ("ch: %s", _trace_key((unsigned char)ch))); + while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) + ptr = ptr->sibling; #ifdef TRACE - if (ptr == NULL) - {TR(TRACE_IEVENT, ("ptr is null"));} - else - TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", - ptr, ptr->ch, ptr->value)); + if (ptr == NULL) + {TR(TRACE_IEVENT, ("ptr is null"));} + else + TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); #endif /* TRACE */ - if (ptr != NULL) - if (ptr->value != 0) { /* sequence terminated */ - TR(TRACE_IEVENT, ("end of sequence")); - fifo_clear(); - return(ptr->value); - } else { /* go back for another character */ - ptr = ptr->child; - TR(TRACE_IEVENT, ("going back for more")); - } else - break; - - TR(TRACE_IEVENT, ("waiting for rest of sequence")); - if (!_nc_timed_wait(3, timeleft, &timeleft)) { - TR(TRACE_IEVENT, ("ran out of time")); - return(fifo_pull()); - } else { - TR(TRACE_IEVENT, ("got more!")); - fifo_push(); - ch = fifo_peek(); - } + if (ptr == NULL) + break; + + if (ptr->value != 0) { /* sequence terminated */ + TR(TRACE_IEVENT, ("end of sequence")); + if (peek == tail) + fifo_clear(); + else + head = peek; + return(ptr->value); + } + + ptr = ptr->child; + + if (!raw_key_in_fifo()) + { + TR(TRACE_IEVENT, ("waiting for rest of sequence")); + if (!_nc_timed_wait(3, timeleft, &timeleft)) { + TR(TRACE_IEVENT, ("ran out of time")); + break; + } } } - return(fifo_pull()); + ch = fifo_pull(); + peek = head; + return ch; } diff --git a/lib/libcurses/lib_getstr.c b/lib/libcurses/lib_getstr.c index 55248e20e6b..80da38ba294 100644 --- a/lib/libcurses/lib_getstr.c +++ b/lib/libcurses/lib_getstr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_getstr.c,v 1.3 1997/12/03 05:21:19 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,7 +32,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("Id: lib_getstr.c,v 1.11 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("Id: lib_getstr.c,v 1.18 1997/09/20 15:02:34 juergen Exp $") /* * This wipes out the last character, no matter whether it was a tab, control @@ -60,7 +62,7 @@ static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool ec int wgetnstr(WINDOW *win, char *str, int maxlen) { TTY buf; -bool oldnl, oldecho, oldraw, oldcbreak, oldkeypad; +bool oldnl, oldecho, oldraw, oldcbreak; char erasec; char killc; char *oldstr; @@ -69,18 +71,19 @@ int y, x; T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); - GET_TTY(cur_term->Filedes, &buf); + if (!win) + returnCode(ERR); + + _nc_get_curterm(&buf); oldnl = SP->_nl; oldecho = SP->_echo; oldraw = SP->_raw; oldcbreak = SP->_cbreak; - oldkeypad = win->_use_keypad; nl(); noecho(); noraw(); cbreak(); - keypad(win, TRUE); erasec = erasechar(); killc = killchar(); @@ -101,8 +104,13 @@ int y, x; if (ch == '\n' || ch == '\r' || ch == KEY_DOWN - || ch == KEY_ENTER) + || ch == KEY_ENTER) { + if (oldecho == TRUE + && win->_cury == win->_maxy + && win->_scroll) + wechochar(win, '\n'); break; + } if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (str > oldstr) { str = WipeOut(win, y, x, oldstr, str, oldecho); @@ -117,6 +125,7 @@ int y, x; } else { *str++ = ch; if (oldecho == TRUE) { + int oldy = win->_cury; if (waddch(win, ch) == ERR) { /* * We can't really use the lower-right @@ -127,6 +136,20 @@ int y, x; waddch(win, ' '); str = WipeOut(win, y, x, oldstr, str, oldecho); continue; + } else if (win->_flags & _WRAPPED) { + /* + * If the last waddch forced a wrap & + * scroll, adjust our reference point + * for erasures. + */ + if (win->_scroll + && oldy == win->_maxy + && win->_cury == win->_maxy) { + if (--y <= 0) { + y = 0; + } + } + win->_flags &= ~_WRAPPED; } wrefresh(win); } @@ -147,10 +170,7 @@ int y, x; SP->_raw = oldraw; SP->_cbreak = oldcbreak; - SET_TTY(cur_term->Filedes, &buf); - - if (oldkeypad == FALSE) - keypad(win, FALSE); + _nc_set_curterm(&buf); *str = '\0'; if (ch == ERR) diff --git a/lib/libcurses/lib_hline.c b/lib/libcurses/lib_hline.c new file mode 100644 index 00000000000..0559ac3ba8c --- /dev/null +++ b/lib/libcurses/lib_hline.c @@ -0,0 +1,71 @@ +/* $OpenBSD: lib_hline.c,v 1.1 1997/12/03 05:21:19 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + + + +/* +** lib_hline.c +** +** The routine whline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("Id: lib_hline.c,v 1.1 1997/10/08 05:59:50 jtc Exp $") + +int whline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short line; +short start; +short end; + + T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + line = win->_cury; + start = win->_curx; + end = start + n - 1; + if (end > win->_maxx) + end = win->_maxx; + + if (win->_line[line].firstchar == _NOCHANGE + || win->_line[line].firstchar > start) + win->_line[line].firstchar = start; + if (win->_line[line].lastchar == _NOCHANGE + || win->_line[line].lastchar < start) + win->_line[line].lastchar = end; + + if (ch == 0) + ch = ACS_HLINE; + ch = _nc_render(win, ch); + + while ( end >= start) { + win->_line[line].text[end] = ch; + end--; + } + code = OK; + } + returnCode(code); +} diff --git a/lib/libcurses/lib_inchstr.c b/lib/libcurses/lib_inchstr.c index 8ed9a8725cb..7c40224f9c4 100644 --- a/lib/libcurses/lib_inchstr.c +++ b/lib/libcurses/lib_inchstr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_inchstr.c,v 1.3 1997/12/03 05:21:19 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,16 +31,21 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_inchstr.c,v 1.5 1997/02/02 01:06:03 tom Exp $") +MODULE_ID("Id: lib_inchstr.c,v 1.6 1997/09/20 15:02:34 juergen Exp $") int winchnstr(WINDOW *win, chtype *str, int n) { - int i; + int i = 0; T((T_CALLED("winchnstr(%p,%p,%d)"), win, str, n)); - for (i = 0; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) + if (!str) + returnCode(0); + + if (win) { + for (; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) str[i] = win->_line[win->_cury].text[win->_curx + i]; + } str[i] = (chtype)0; returnCode(i); diff --git a/lib/libcurses/lib_initscr.c b/lib/libcurses/lib_initscr.c index 8b2b90562cd..4b1bbfc987e 100644 --- a/lib/libcurses/lib_initscr.c +++ b/lib/libcurses/lib_initscr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_initscr.c,v 1.3 1997/12/03 05:21:20 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -27,42 +29,12 @@ */ #include <curses.priv.h> -#include <term.h> /* cur_term */ #if HAVE_SYS_TERMIO_H #include <sys/termio.h> /* needed for ISC */ #endif -MODULE_ID("Id: lib_initscr.c,v 1.18 1997/03/08 14:03:59 tom Exp $") - -#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ -#define ONLCR 0 -#endif - -/* - * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not - * restored during the curses session. The library simulates echo in software. - * (The behavior is unspecified if the application enables hardware echo). - * - * The newterm function also initializes terminal settings. - */ -int _nc_initscr(void) -{ - /* for extended XPG4 conformance requires cbreak() at this point */ - /* (SVr4 curses does this anyway) */ - cbreak(); - -#ifdef TERMIOS - cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); - cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); - cur_term->Nttyb.c_oflag &= ~(ONLCR); -#else - cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); -#endif - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - return ERR; - return OK; -} +MODULE_ID("Id: lib_initscr.c,v 1.19 1997/06/28 17:41:12 tom Exp $") WINDOW *initscr(void) { @@ -100,7 +72,6 @@ static char ret[15]; if (term != 0) { (void) strncpy(ret, term, sizeof(ret) - 1); - ret[sizeof(ret) - 1] = '\0'; term = ret; } return term; diff --git a/lib/libcurses/lib_insch.c b/lib/libcurses/lib_insch.c index 1702208019e..b94a6f64676 100644 --- a/lib/libcurses/lib_insch.c +++ b/lib/libcurses/lib_insch.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_insch.c,v 1.3 1997/12/03 05:21:20 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,27 +32,31 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_insch.c,v 1.7 1997/04/12 17:43:02 tom Exp $") +MODULE_ID("Id: lib_insch.c,v 1.8 1997/09/20 15:02:34 juergen Exp $") int winsch(WINDOW *win, chtype c) { +int code = ERR; chtype *temp1, *temp2; chtype *end; T((T_CALLED("winsch(%p, %s)"), win, _tracechtype(c))); - end = &win->_line[win->_cury].text[win->_curx]; - temp1 = &win->_line[win->_cury].text[win->_maxx]; - temp2 = temp1 - 1; + if (win) { + end = &win->_line[win->_cury].text[win->_curx]; + temp1 = &win->_line[win->_cury].text[win->_maxx]; + temp2 = temp1 - 1; - while (temp1 > end) + while (temp1 > end) *temp1-- = *temp2--; - - *temp1 = _nc_render(win, c); - - win->_line[win->_cury].lastchar = win->_maxx; - if (win->_line[win->_cury].firstchar == _NOCHANGE - || win->_line[win->_cury].firstchar > win->_curx) + + *temp1 = _nc_render(win, c); + + win->_line[win->_cury].lastchar = win->_maxx; + if (win->_line[win->_cury].firstchar == _NOCHANGE + || win->_line[win->_cury].firstchar > win->_curx) win->_line[win->_cury].firstchar = win->_curx; - returnCode(OK); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/lib_insdel.c b/lib/libcurses/lib_insdel.c index c367c93d5d0..d8f069d23f7 100644 --- a/lib/libcurses/lib_insdel.c +++ b/lib/libcurses/lib_insdel.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_insdel.c,v 1.3 1997/12/03 05:21:20 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,19 +32,21 @@ #include <curses.priv.h> -MODULE_ID("$Id") +MODULE_ID("Id: lib_insdel.c,v 1.7 1997/09/20 15:02:34 juergen Exp $") int winsdelln(WINDOW *win, int n) { - T((T_CALLED("winsdel(%p,%d)"), win, n)); +int code = ERR; - if (n == 0) - returnCode(OK); - - _nc_scroll_window(win, -n, win->_cury, win->_maxy); - touchline(win, win->_cury, win->_maxy - win->_cury + 1); + T((T_CALLED("winsdel(%p,%d)"), win, n)); - _nc_synchook(win); - returnCode(OK); + if (win) { + if (n != 0) { + _nc_scroll_window(win, -n, win->_cury, win->_maxy, _nc_background(win)); + _nc_synchook(win); + } + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/lib_insstr.c b/lib/libcurses/lib_insstr.c index c25071f76d5..de65b7bd457 100644 --- a/lib/libcurses/lib_insstr.c +++ b/lib/libcurses/lib_insstr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_insstr.c,v 1.3 1997/12/03 05:21:21 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -31,33 +33,38 @@ #include <curses.priv.h> #include <ctype.h> -MODULE_ID("Id: lib_insstr.c,v 1.9 1997/02/15 16:09:53 tom Exp $") +MODULE_ID("Id: lib_insstr.c,v 1.10 1997/09/20 15:02:34 juergen Exp $") int winsnstr(WINDOW *win, const char *str, int n) { -short oy = win->_cury; -short ox = win->_curx; +int code = ERR; +short oy; +short ox ; const char *cp; - T((T_CALLED("winsstr(%p,%s,%d)"), win, _nc_visbuf(str), n)); - - for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { - if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') - _nc_waddch_nosync(win, (chtype)(*cp)); - else if (is7bits(*cp) && iscntrl(*cp)) { - winsch(win, ' ' + (chtype)(*cp)); - winsch(win, '^'); - win->_curx += 2; - } else { - winsch(win, (chtype)(*cp)); - win->_curx++; - } - if (win->_curx > win->_maxx) - win->_curx = win->_maxx; - } + T((T_CALLED("winsstr(%p,%s,%d)"), win, _nc_visbuf(str), n)); - win->_curx = ox; - win->_cury = oy; - _nc_synchook(win); - returnCode(OK); + if (win && str) { + oy = win->_cury; ox = win->_curx; + for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { + if (*cp == '\n' || *cp == '\r' || *cp == '\t' || *cp == '\b') + _nc_waddch_nosync(win, (chtype)(*cp)); + else if (is7bits(*cp) && iscntrl(*cp)) { + winsch(win, ' ' + (chtype)(*cp)); + winsch(win, '^'); + win->_curx += 2; + } else { + winsch(win, (chtype)(*cp)); + win->_curx++; + } + if (win->_curx > win->_maxx) + win->_curx = win->_maxx; + } + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + code = OK; + } + returnCode(code); } diff --git a/lib/libcurses/lib_instr.c b/lib/libcurses/lib_instr.c index d21de453a09..b3f2397179d 100644 --- a/lib/libcurses/lib_instr.c +++ b/lib/libcurses/lib_instr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_instr.c,v 1.3 1997/12/03 05:21:21 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,28 +31,33 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_instr.c,v 1.6 1997/05/03 10:51:07 juergen Exp $") +MODULE_ID("Id: lib_instr.c,v 1.7 1997/09/20 15:02:34 juergen Exp $") int winnstr(WINDOW *win, char *str, int n) { - int i, row, col; + int i=0, row, col; T((T_CALLED("winnstr(%p,%p,%d)"), win, str, n)); - getyx(win, row, col); - - if (n < 0) - n = win->_maxx - win->_curx + 1; - - for (i = 0; i < n;) { - str[i++] = TextOf(win->_line[row].text[col]); - if (++col > win->_maxx) { - col = 0; - if (++row > win->_maxy) - break; - } + if (!str) + returnCode(0); + + if (win) { + getyx(win, row, col); + + if (n < 0) + n = win->_maxx - win->_curx + 1; + + for (; i < n;) { + str[i++] = TextOf(win->_line[row].text[col]); + if (++col > win->_maxx) { + col = 0; + if (++row > win->_maxy) + break; + } + } } str[i] = '\0'; /* SVr4 does not seem to count the null */ - returnCode(i); } + diff --git a/lib/libcurses/lib_isendwin.c b/lib/libcurses/lib_isendwin.c index 55c57c9d6ab..20d69a22ab6 100644 --- a/lib/libcurses/lib_isendwin.c +++ b/lib/libcurses/lib_isendwin.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_isendwin.c,v 1.3 1997/12/03 05:21:22 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_kernel.c b/lib/libcurses/lib_kernel.c index a6d0083d076..537adeb5c27 100644 --- a/lib/libcurses/lib_kernel.c +++ b/lib/libcurses/lib_kernel.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_kernel.c,v 1.3 1997/12/03 05:21:22 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -41,7 +43,7 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("Id: lib_kernel.c,v 1.13 1997/02/02 00:33:14 tom Exp $") +MODULE_ID("Id: lib_kernel.c,v 1.14 1997/09/02 22:41:57 tom Exp $") int napms(int ms) { @@ -56,7 +58,7 @@ int reset_prog_mode(void) { T((T_CALLED("reset_prog_mode()"))); - SET_TTY(cur_term->Filedes, &cur_term->Nttyb); + _nc_set_curterm(&cur_term->Nttyb); if (SP && stdscr && stdscr->_use_keypad) _nc_keypad(TRUE); @@ -74,7 +76,7 @@ int reset_shell_mode(void) _nc_keypad(FALSE); } - SET_TTY(cur_term->Filedes, &cur_term->Ottyb); + _nc_set_curterm(&cur_term->Ottyb); returnCode(OK); } #endif /* EXTERN_TERMINFO */ @@ -162,7 +164,7 @@ int savetty(void) { T((T_CALLED("savetty()"))); - GET_TTY(cur_term->Filedes, &buf); + _nc_get_curterm(&buf); returnCode(OK); } @@ -170,6 +172,6 @@ int resetty(void) { T((T_CALLED("resetty()"))); - SET_TTY(cur_term->Filedes, &buf); + _nc_set_curterm(&buf); returnCode(OK); } diff --git a/lib/libcurses/lib_longname.c b/lib/libcurses/lib_longname.c index c53da02d7d0..5dd46bf1422 100644 --- a/lib/libcurses/lib_longname.c +++ b/lib/libcurses/lib_longname.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_longname.c,v 1.5 1997/12/03 05:21:22 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_mouse.c b/lib/libcurses/lib_mouse.c index d7ddf67883d..1076b1bd78c 100644 --- a/lib/libcurses/lib_mouse.c +++ b/lib/libcurses/lib_mouse.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_mouse.c,v 1.3 1997/12/03 05:21:23 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -61,14 +63,12 @@ #endif #endif -MODULE_ID("Id: lib_mouse.c,v 0.22 1997/02/15 22:33:37 tom Exp $") +MODULE_ID("Id: lib_mouse.c,v 0.31 1997/10/11 22:40:49 tom Exp $") #define MY_TRACE TRACE_ICALLS|TRACE_IEVENT #define INVALID_EVENT -1 -int _nc_max_click_interval = 166; /* max press/release separation */ - static int mousetype; #define M_XTERM -1 /* use xterm's mouse tracking? */ #define M_NONE 0 /* no mouse device */ @@ -82,6 +82,10 @@ static Gpm_Connect gpm_connect; static mmask_t eventmask; /* current event mask */ +static bool _nc_mouse_parse(int); +static void _nc_mouse_resume(SCREEN *); +static void _nc_mouse_wrap(SCREEN *); + /* maintain a circular list of mouse events */ #define EV_MAX 8 /* size of circular event queue */ static MEVENT events[EV_MAX]; /* hold the last mouse event seen */ @@ -101,10 +105,25 @@ static void _trace_slot(const char *tag) } #endif -void _nc_mouse_init(SCREEN *sp GCC_UNUSED) -/* initialize the mouse -- called at screen-setup time */ +/* FIXME: The list of names should be configurable */ +static int is_xterm(const char *name) +{ + return (!strncmp(name, "xterm", 5) + || !strncmp(name, "rxvt", 4) + || !strncmp(name, "kterm", 5) + || !strncmp(name, "color_xterm", 11)); +} + +static void _nc_mouse_init(void) +/* initialize the mouse */ { int i; + static int initialized; + + if (initialized) { + return; + } + initialized = TRUE; TR(MY_TRACE, ("_nc_mouse_init() called")); @@ -113,11 +132,12 @@ void _nc_mouse_init(SCREEN *sp GCC_UNUSED) #ifdef EXTERN_TERMINFO /* we know how to recognize mouse events under xterm */ - if (!strncmp(cur_term->name, "xterm", 5) && key_mouse) + if (key_mouse != 0 && is_xterm(cur_term->name)) mousetype = M_XTERM; #else /* we know how to recognize mouse events under xterm */ - if (!strncmp(cur_term->type.term_names, "xterm", 5) && key_mouse) + if (key_mouse != 0 + && is_xterm(cur_term->type.term_names)) mousetype = M_XTERM; #endif @@ -129,24 +149,15 @@ void _nc_mouse_init(SCREEN *sp GCC_UNUSED) gpm_connect.defaultMask = ~gpm_connect.eventMask; gpm_connect.minMod = 0; gpm_connect.maxMod = ~0; - if (Gpm_Open (&gpm_connect, 0) >= 0) /* returns the file-descriptor */ + if (Gpm_Open (&gpm_connect, 0) >= 0) { /* returns the file-descriptor */ mousetype = M_GPM; + SP->_mouse_fd = gpm_fd; + } } #endif } -int _nc_mouse_fd(void) -{ - if (mousetype == M_XTERM) - return -1; -#if USE_GPM_SUPPORT - else if (mousetype == M_GPM) - return gpm_fd; -#endif - return -1; -} - -bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) +static bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) /* query to see if there is a pending mouse event */ { #if USE_GPM_SUPPORT @@ -159,7 +170,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) { eventp->id = 0; /* there's only one mouse... */ - eventp->bstate = 0; + eventp->bstate = 0; switch (ev.type & 0x0f) { case(GPM_DOWN): @@ -178,7 +189,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) eventp->x = ev.x - 1; eventp->y = ev.y - 1; - eventp->z = 0; + eventp->z = 0; /* bump the next-free pointer into the circular list */ eventp = NEXT(eventp); @@ -189,7 +200,7 @@ bool _nc_mouse_event(SCREEN *sp GCC_UNUSED) return(FALSE); /* no event waiting */ } -bool _nc_mouse_inline(SCREEN *sp) +static bool _nc_mouse_inline(SCREEN *sp) /* mouse report received in the keyboard stream -- parse its info */ { TR(MY_TRACE, ("_nc_mouse_inline() called")); @@ -307,8 +318,10 @@ bool _nc_mouse_inline(SCREEN *sp) static void mouse_activate(bool on) { + _nc_mouse_init(); if (mousetype == M_XTERM) { + keyok(KEY_MOUSE, on); if (on) { TPUTS_TRACE("xterm mouse initialization"); @@ -321,6 +334,22 @@ static void mouse_activate(bool on) } (void) fflush(SP->_ofp); } + + /* Make runtime binding to cut down on object size of applications that do + * not use the mouse (e.g., 'clear'). + */ + if (on) + { + SP->_mouse_event = _nc_mouse_event; + SP->_mouse_inline = _nc_mouse_inline; + SP->_mouse_parse = _nc_mouse_parse; + SP->_mouse_resume = _nc_mouse_resume; + SP->_mouse_wrap = _nc_mouse_wrap; +#if USE_GPM_SUPPORT + if (mousetype == M_GPM) + SP->_mouse_fd = gpm_fd; +#endif + } } /************************************************************************** @@ -329,7 +358,7 @@ static void mouse_activate(bool on) * **************************************************************************/ -bool _nc_mouse_parse(int runcount) +static bool _nc_mouse_parse(int runcount) /* parse a run of atomic mouse events into a gesture */ { MEVENT *ep, *runp, *next, *prev = PREV(eventp); @@ -363,7 +392,9 @@ bool _nc_mouse_parse(int runcount) { TR(MY_TRACE, ("_nc_mouse_parse: returning simple mouse event %s at slot %d", _tracemouse(prev), prev-events)); - return (PREV(prev)->id >= 0) ? (PREV(prev)->bstate & eventmask) : 0; + return (prev->id >= 0) + ? ((prev->bstate & eventmask) ? TRUE : FALSE) + : FALSE; } /* find the start of the run */ @@ -562,7 +593,7 @@ bool _nc_mouse_parse(int runcount) return(PREV(eventp)->id != INVALID_EVENT); } -void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) +static void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) /* release mouse -- called by endwin() before shellout/exit */ { TR(MY_TRACE, ("_nc_mouse_wrap() called")); @@ -574,7 +605,7 @@ void _nc_mouse_wrap(SCREEN *sp GCC_UNUSED) /* GPM: pass all mouse events to next client */ } -void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) +static void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) /* re-connect to mouse -- called by doupdate() after shellout */ { TR(MY_TRACE, ("_nc_mouse_resume() called")); @@ -595,6 +626,8 @@ void _nc_mouse_resume(SCREEN *sp GCC_UNUSED) int getmouse(MEVENT *aevent) /* grab a copy of the current mouse event */ { + T((T_CALLED("getmouse(%p)"), aevent)); + if (aevent && (mousetype == M_XTERM || mousetype == M_GPM)) { /* compute the current-event pointer */ @@ -607,9 +640,9 @@ int getmouse(MEVENT *aevent) _tracemouse(prev), prev-events)); prev->id = INVALID_EVENT; /* so the queue slot becomes free */ - return(OK); + returnCode(OK); } - return(ERR); + returnCode(ERR); } int ungetmouse(MEVENT *aevent) @@ -628,9 +661,14 @@ int ungetmouse(MEVENT *aevent) mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) /* set the mouse event mask */ { + mmask_t result = 0; + + T((T_CALLED("mousemask(%#lx,%p)"), newmask, oldmask)); + if (oldmask) *oldmask = eventmask; + _nc_mouse_init(); if (mousetype == M_XTERM || mousetype == M_GPM) { eventmask = newmask & @@ -644,22 +682,22 @@ mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) mouse_activate(eventmask != 0); - return(eventmask); + result = eventmask; } - return(0); + returnCode(result); } -bool wenclose(WINDOW *win, int y, int x) +bool wenclose(const WINDOW *win, int y, int x) /* check to see if given window encloses given screen location */ { if (win) { y -= win->_yoffset; - return (win->_begy <= y && - win->_begx <= x && - (win->_begx + win->_maxx) >= x && - (win->_begy + win->_maxy) >= y); + return ((win->_begy <= y && + win->_begx <= x && + (win->_begx + win->_maxx) >= x && + (win->_begy + win->_maxy) >= y) ? TRUE : FALSE); } return FALSE; } @@ -667,10 +705,23 @@ bool wenclose(WINDOW *win, int y, int x) int mouseinterval(int maxclick) /* set the maximum mouse interval within which to recognize a click */ { - int oldval = _nc_max_click_interval; + int oldval; + + if (SP != 0) { + oldval = SP->_maxclick; + if (maxclick >= 0) + SP->_maxclick = maxclick; + } else { + oldval = DEFAULT_MAXCLICK; + } - _nc_max_click_interval = maxclick; return(oldval); } +/* This may be used by other routines to ask for the existence of mouse + support */ +int _nc_has_mouse(void) { + return (mousetype==M_NONE ? 0:1); +} + /* lib_mouse.c ends here */ diff --git a/lib/libcurses/lib_move.c b/lib/libcurses/lib_move.c index 3799bb57a8a..095c7d40043 100644 --- a/lib/libcurses/lib_move.c +++ b/lib/libcurses/lib_move.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_move.c,v 1.3 1997/12/03 05:21:23 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,15 +31,16 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_move.c,v 1.6 1997/02/02 00:00:47 tom Exp $") +MODULE_ID("Id: lib_move.c,v 1.7 1997/09/20 15:02:34 juergen Exp $") int wmove(WINDOW *win, int y, int x) { T((T_CALLED("wmove(%p,%d,%d)"), win, y, x)); - if (x >= 0 && x <= win->_maxx && - y >= 0 && y <= win->_maxy) + if (win && + x >= 0 && x <= win->_maxx && + y >= 0 && y <= win->_maxy) { win->_curx = (short)x; win->_cury = (short)y; diff --git a/lib/libcurses/lib_mvcur.c b/lib/libcurses/lib_mvcur.c index 807b6c5eeeb..203d0692253 100644 --- a/lib/libcurses/lib_mvcur.c +++ b/lib/libcurses/lib_mvcur.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_mvcur.c,v 1.6 1997/12/03 05:21:24 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -25,7 +27,7 @@ ** ** The routines for moving the physical cursor and scrolling: ** -** void _nc_mvcur_init(void), mvcur_wrap(void) +** void _nc_mvcur_init(void) ** ** void _nc_mvcur_resume(void) ** @@ -33,8 +35,6 @@ ** ** void _nc_mvcur_wrap(void) ** -** int _nc_mvcur_scrolln(int n, int top, int bot, int maxy) -** ** Comparisons with older movement optimizers: ** SVr3 curses mvcur() can't use cursor_to_ll or auto_left_margin. ** 4.4BSD curses can't use cuu/cud/cuf/cub/hpa/vpa/tab/cbt for local @@ -116,10 +116,10 @@ * int _cup_cost; // cost of (cursor_address) * int _home_cost; // cost of (cursor_home) * int _ll_cost; // cost of (cursor_to_ll) - *#ifdef TABS_OK + *#if USE_HARD_TABS * int _ht_cost; // cost of (tab) - * int _cbt_cost; // cost of (backtab) - *#endif TABS_OK + * int _cbt_cost; // cost of (back_tab) + *#endif USE_HARD_TABS * int _cub1_cost; // cost of (cursor_left) * int _cuf1_cost; // cost of (cursor_right) * int _cud1_cost; // cost of (cursor_down) @@ -133,7 +133,7 @@ * int _ech_cost; // cost of (erase_chars) * int _rep_cost; // cost of (repeat_char) * - * The TABS_OK switch controls whether it is reliable to use tab/backtabs + * The USE_HARD_TABS switch controls whether it is reliable to use tab/backtabs * for local motions. On many systems, it's not, due to uncertainties about * tab delays and whether or not tabs will be expanded in raw mode. If you * have parm_right_cursor, tab motions don't win you a lot anyhow. @@ -143,7 +143,7 @@ #include <term.h> #include <ctype.h> -MODULE_ID("Id: lib_mvcur.c,v 1.37 1997/05/03 22:15:26 Peter.Wemm Exp $") +MODULE_ID("Id: lib_mvcur.c,v 1.48 1997/10/25 23:34:11 tom Exp $") #define STRLEN(s) (s != 0) ? strlen(s) : 0 @@ -154,7 +154,7 @@ MODULE_ID("Id: lib_mvcur.c,v 1.37 1997/05/03 22:15:26 Peter.Wemm Exp $") #define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x] /* desired state */ #define BAUDRATE SP->_baudrate /* bits per second */ -#ifdef MAIN +#if defined(MAIN) || defined(NCURSES_TEST) #include <sys/time.h> static bool profiling = FALSE; @@ -163,9 +163,6 @@ static float diff; #define OPT_SIZE 512 -static void save_curs(void); -static void restore_curs(void); -static int cost_of(const char *const cap, int affcnt); static int normalized_cost(const char *const cap, int affcnt); /**************************************************************************** @@ -178,7 +175,7 @@ static int normalized_cost(const char *const cap, int affcnt); static int trace_cost_of(const char *capname, const char *cap, int affcnt) { - int result = cost_of(cap,affcnt); + int result = _nc_msec_cost(cap,affcnt); TR(TRACE_CHARPUT|TRACE_MOVE, ("CostOf %s %d", capname, result)); return result; } @@ -195,12 +192,12 @@ trace_normalized_cost(const char *capname, const char *cap, int affcnt) #else -#define CostOf(cap,affcnt) cost_of(cap,affcnt); +#define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt); #define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt); #endif -static int cost_of(const char *const cap, int affcnt) +int _nc_msec_cost(const char *const cap, int affcnt) /* compute the cost of a given operation */ { if (cap == 0) @@ -240,7 +237,7 @@ static int cost_of(const char *const cap, int affcnt) static int normalized_cost(const char *const cap, int affcnt) /* compute the effective character-count for an operation (round up) */ { - int cost = cost_of(cap, affcnt); + int cost = _nc_msec_cost(cap, affcnt); if (cost != INFINITY) cost = (cost + SP->_char_padding - 1) / SP->_char_padding; return cost; @@ -251,11 +248,8 @@ static void reset_scroll_region(void) { if (change_scroll_region) { - /* change_scroll_region may trash the cursor location */ - save_curs(); TPUTS_TRACE("change_scroll_region"); putp(tparm(change_scroll_region, 0, screen_lines - 1)); - restore_curs(); } } @@ -279,6 +273,15 @@ void _nc_mvcur_resume(void) * a vt100 emulation through xterm. */ reset_scroll_region(); + SP->_cursrow = SP->_curscol = -1; + + /* restore cursor shape */ + if (SP->_cursor != -1) + { + int cursor = SP->_cursor; + SP->_cursor = -1; + curs_set (cursor); + } } void _nc_mvcur_init(void) @@ -296,10 +299,10 @@ void _nc_mvcur_init(void) SP->_cr_cost = CostOf(carriage_return, 0); SP->_home_cost = CostOf(cursor_home, 0); SP->_ll_cost = CostOf(cursor_to_ll, 0); -#ifdef TABS_OK +#if USE_HARD_TABS SP->_ht_cost = CostOf(tab, 0); SP->_cbt_cost = CostOf(back_tab, 0); -#endif /* TABS_OK */ +#endif /* USE_HARD_TABS */ SP->_cub1_cost = CostOf(cursor_left, 0); SP->_cuf1_cost = CostOf(cursor_right, 0); SP->_cud1_cost = CostOf(cursor_down, 0); @@ -377,12 +380,27 @@ void _nc_mvcur_init(void) void _nc_mvcur_wrap(void) /* wrap up cursor-addressing mode */ { - reset_scroll_region(); + /* leave cursor at screen bottom */ + mvcur(-1, -1, screen_lines - 1, 0); + + /* set cursor to normal mode */ + if (SP->_cursor != -1) + curs_set(1); + if (exit_ca_mode) { TPUTS_TRACE("exit_ca_mode"); putp(exit_ca_mode); } + /* + * Reset terminal's tab counter. There's a long-time bug that + * if you exit a "curses" program such as vi or more, tab + * forward, and then backspace, the cursor doesn't go to the + * right place. The problem is that the kernel counts the + * escape sequences that reset things as column positions. + * Utter a \r to reset this invisibly. + */ + _nc_outch('\r'); } /**************************************************************************** @@ -417,7 +435,12 @@ repeated_append (int total, int num, int repeat, char *dst, const char *src) #ifndef NO_OPTIMIZE #define NEXTTAB(fr) (fr + init_tabs - (fr % init_tabs)) -#define LASTTAB(fr) (fr - init_tabs + (fr % init_tabs)) + +/* + * Assume back_tab (CBT) does not wrap backwards at the left margin, return + * a negative value at that point to simplify the loop. + */ +#define LASTTAB(fr) ((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1) /* Note: we'd like to inline this for speed, but GNU C barfs on the attempt. */ @@ -456,7 +479,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) { if (result) result[0] = '\0'; - vcost = repeated_append(vcost, SP->_cud1_cost, n, result, cursor_down); + vcost = repeated_append(0, SP->_cud1_cost, n, result, cursor_down); } } else /* (to_y < from_y) */ @@ -474,7 +497,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) { if (result) result[0] = '\0'; - vcost = repeated_append(vcost, SP->_cuu1_cost, n, result, cursor_up); + vcost = repeated_append(0, SP->_cuu1_cost, n, result, cursor_up); } } @@ -487,7 +510,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) if (to_x != from_x) { - char try[OPT_SIZE]; + char str[OPT_SIZE]; hcost = INFINITY; @@ -513,9 +536,9 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) { int lhcost = 0; - try[0] = '\0'; + str[0] = '\0'; -#ifdef TABS_OK +#if USE_HARD_TABS /* use hard tabs, if we have them, to do as much as possible */ if (init_tabs > 0 && tab) { @@ -523,7 +546,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) { - lhcost = repeated_append(lhcost, SP->_ht_cost, 1, try, tab); + lhcost = repeated_append(lhcost, SP->_ht_cost, 1, str, tab); if (lhcost == INFINITY) break; } @@ -531,7 +554,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) n = to_x - fr; from_x = fr; } -#endif /* TABS_OK */ +#endif /* USE_HARD_TABS */ #if defined(REAL_ATTR) && defined(WANT_CHAR) /* @@ -558,7 +581,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) char *sp; int i; - sp = try + strlen(try); + sp = str + strlen(str); for (i = 0; i < n; i++) *sp++ = WANT_CHAR(to_y, from_x + i); @@ -568,13 +591,13 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) else #endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ { - lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, try, cursor_right); + lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, str, cursor_right); } if (lhcost < hcost) { if (result) - (void) strcpy(result, try); + (void) strcpy(result, str); hcost = lhcost; } } @@ -594,30 +617,30 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) { int lhcost = 0; - try[0] = '\0'; + str[0] = '\0'; -#ifdef TABS_OK +#if USE_HARD_TABS if (init_tabs > 0 && back_tab) { int nxt, fr; for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) { - lhcost = repeated_append(lhcost, SP->_cbt_cost, 1, try, back_tab); + lhcost = repeated_append(lhcost, SP->_cbt_cost, 1, str, back_tab); if (lhcost == INFINITY) break; } - n = to_x - fr; + n = fr - to_x; } -#endif /* TABS_OK */ +#endif /* USE_HARD_TABS */ - lhcost = repeated_append(lhcost, SP->_cub1_cost, n, try, cursor_left); + lhcost = repeated_append(lhcost, SP->_cub1_cost, n, str, cursor_left); if (lhcost < hcost) { if (result) - (void) strcpy(result, try); + (void) strcpy(result, str); hcost = lhcost; } } @@ -649,7 +672,7 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) char use[OPT_SIZE], *sp; int tactic = 0, newcost, usecost = INFINITY; -#ifdef MAIN +#if defined(MAIN) || defined(NCURSES_TEST) struct timeval before, after; gettimeofday(&before, NULL); @@ -676,10 +699,9 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) * (like, say, local-movement \n getting mapped to some obscure * character because A_ALTCHARSET is on). */ - if (yold == -1 || xold == -1 || - REAL_ATTR != A_NORMAL || NOT_LOCAL(yold, xold, ynew, xnew)) + if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) { -#ifdef MAIN +#if defined(MAIN) || defined(NCURSES_TEST) if (!profiling) { (void) fputs("nonlocal\n", stderr); @@ -702,15 +724,12 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) } /* tactic #2: use carriage-return + local movement */ - if (yold < screen_lines - 1 && xold < screen_columns - 1) - { - if (carriage_return + if (yold != -1 && carriage_return && ((newcost=relative_move(NULL, yold,0,ynew,xnew, ovw)) != INFINITY) && SP->_cr_cost + newcost < usecost) - { - tactic = 2; - usecost = SP->_cr_cost + newcost; - } + { + tactic = 2; + usecost = SP->_cr_cost + newcost; } /* tactic #3: use home-cursor + local movement */ @@ -736,7 +755,7 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) * unless strange wrap behavior indicated by xenl might hose us. */ if (auto_left_margin && !eat_newline_glitch - && yold > 0 && yold < screen_lines - 1 && cursor_left + && yold > 0 && cursor_left && ((newcost=relative_move(NULL, yold-1, screen_columns-1, ynew, xnew, ovw)) != INFINITY) && SP->_cr_cost + SP->_cub1_cost + newcost + newcost < usecost) { @@ -781,7 +800,7 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) } #endif /* !NO_OPTIMIZE */ -#ifdef MAIN +#if defined(MAIN) || defined(NCURSES_TEST) gettimeofday(&after, NULL); diff = after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000; @@ -861,288 +880,7 @@ int mvcur(int yold, int xold, int ynew, int xnew) return(onscreen_mvcur(yold, xold, ynew, xnew, TRUE)); } - -/**************************************************************************** - * - * Cursor save_restore - * - ****************************************************************************/ - -/* assumption: sc/rc is faster than cursor addressing */ - -static int oy, ox; /* ugh, mvcur_scrolln() needs to see this */ - -static void save_curs(void) -{ - if (save_cursor && restore_cursor) - { - TPUTS_TRACE("save_cursor"); - putp(save_cursor); - } - - oy = CURRENT_ROW; - ox = CURRENT_COLUMN; -} - -static void restore_curs(void) -{ - if (save_cursor && restore_cursor) - { - TPUTS_TRACE("restore_cursor"); - putp(restore_cursor); - } - else - onscreen_mvcur(-1, -1, oy, ox, FALSE); -} - -/**************************************************************************** - * - * Physical-scrolling support - * - ****************************************************************************/ - -static int DoTheScrolling(int n, int top, int bot, int maxy) -/* scroll region from top to bot by n lines */ -{ - int i; - - /* - * This code was adapted from Keith Bostic's hardware scrolling - * support for 4.4BSD curses. I (esr) translated it to use terminfo - * capabilities, narrowed the call interface slightly, and cleaned - * up some convoluted tests. I also added support for the memory_above - * memory_below, and non_dest_scroll_region capabilities. - * - * For this code to work, we must have either - * change_scroll_region and scroll forward/reverse commands, or - * insert and delete line capabilities. - * When the scrolling region has been set, the cursor has to - * be at the last line of the region to make the scroll - * happen. - * - * This code makes one aesthetic decision in the opposite way from - * BSD curses. BSD curses preferred pairs of il/dl operations - * over scrolls, allegedly because il/dl looked faster. We, on - * the other hand, prefer scrolls because (a) they're just as fast - * on many terminals and (b) using them avoids bouncing an - * unchanged bottom section of the screen up and down, which is - * visually nasty. - */ - if (n > 0) - { - /* - * Explicitly clear if stuff pushed off top of region might - * be saved by the terminal. - */ - if (non_dest_scroll_region || (memory_above && top == 0)) { - for (i = 0; i < n; i++) - { - mvcur(-1, -1, i, 0); - TPUTS_TRACE("clr_eol"); - tputs(clr_eol, n, _nc_outch); - } - } - - if (change_scroll_region && (scroll_forward || parm_index)) - { - TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); - - onscreen_mvcur(-1, -1, bot, 0, TRUE); - - if (parm_index != NULL) - { - TPUTS_TRACE("parm_index"); - tputs(tparm(parm_index, n, 0), n, _nc_outch); - } - else - { - for (i = 0; i < n; i++) - { - TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); - } - } - TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); - } - else if (parm_index && top == 0 && bot == maxy) - { - onscreen_mvcur(oy, ox, bot, 0, TRUE); - TPUTS_TRACE("parm_index"); - tputs(tparm(parm_index, n, 0), n, _nc_outch); - } - else if (scroll_forward && top == 0 && bot == maxy) - { - onscreen_mvcur(oy, ox, bot, 0, TRUE); - for (i = 0; i < n; i++) - { - TPUTS_TRACE("scroll_forward"); - tputs(scroll_forward, 0, _nc_outch); - } - } - else if (_nc_idlok - && (parm_delete_line || delete_line) - && (parm_insert_line || insert_line)) - { - onscreen_mvcur(oy, ox, top, 0, TRUE); - - if (parm_delete_line) - { - TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); - } - else - { - for (i = 0; i < n; i++) - { - TPUTS_TRACE("parm_index"); - tputs(delete_line, 0, _nc_outch); - } - } - - onscreen_mvcur(top, 0, bot - n + 1, 0, FALSE); - - /* Push down the bottom region. */ - if (parm_insert_line) - { - TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); - } - else - { - for (i = 0; i < n; i++) - { - TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); - } - } - } - else - return(ERR); - } - else /* (n < 0) */ - { - /* - * Do explicit clear to end of region if it's possible that the - * terminal might hold on to stuff we push off the end. - */ - if (non_dest_scroll_region || (memory_below && bot == maxy)) - { - if (bot == maxy && clr_eos) - { - mvcur(-1, -1, lines + n, 0); - TPUTS_TRACE("clr_eos"); - tputs(clr_eos, n, _nc_outch); - } - else if (clr_eol) - { - for (i = 0; i < -n; i++) - { - mvcur(-1, -1, lines + n + i, 0); - TPUTS_TRACE("clr_eol"); - tputs(clr_eol, n, _nc_outch); - } - } - } - - if (change_scroll_region && (scroll_reverse || parm_rindex)) - { - TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, top, bot), 0, _nc_outch); - - onscreen_mvcur(-1, -1, top, 0, TRUE); - - if (parm_rindex) - { - TPUTS_TRACE("parm_rindex"); - tputs(tparm(parm_rindex, -n, 0), -n, _nc_outch); - } - else - { - for (i = n; i < 0; i++) - { - TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); - } - } - TPUTS_TRACE("change_scroll_region"); - tputs(tparm(change_scroll_region, 0, maxy), 0, _nc_outch); - } - else if (parm_rindex && top == 0 && bot == maxy) - { - onscreen_mvcur(oy, ox, bot + n + 1, 0, TRUE); - - TPUTS_TRACE("parm_rindex"); - tputs(tparm(parm_rindex, -n, 0), -n, _nc_outch); - } - else if (scroll_reverse && top == 0 && bot == maxy) - { - onscreen_mvcur(-1, -1, 0, 0, TRUE); - for (i = n; i < 0; i++) - { - TPUTS_TRACE("scroll_reverse"); - tputs(scroll_reverse, 0, _nc_outch); - } - } - else if (_nc_idlok - && (parm_delete_line || delete_line) - && (parm_insert_line || insert_line)) - { - onscreen_mvcur(oy, ox, bot + n + 1, 0, TRUE); - - if (parm_delete_line) - { - TPUTS_TRACE("parm_delete_line"); - tputs(tparm(parm_delete_line, -n, 0), -n, _nc_outch); - } - else - { - for (i = n; i < 0; i++) - { - TPUTS_TRACE("delete_line"); - tputs(delete_line, 0, _nc_outch); - } - } - - onscreen_mvcur(bot + n + 1, 0, top, 0, FALSE); - - /* Scroll the block down. */ - if (parm_insert_line) - { - TPUTS_TRACE("parm_insert_line"); - tputs(tparm(parm_insert_line, -n, 0), -n, _nc_outch); - } - else - { - for (i = n; i < 0; i++) - { - TPUTS_TRACE("insert_line"); - tputs(insert_line, 0, _nc_outch); - } - } - } - else - return(ERR); - } - - return(OK); -} - -int _nc_mvcur_scrolln(int n, int top, int bot, int maxy) -/* scroll region from top to bot by n lines */ -{ - int code; - - TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy)); - - save_curs(); - code = DoTheScrolling(n, top, bot, maxy); - restore_curs(); - return(code); -} - -#ifdef MAIN +#if defined(MAIN) || defined(NCURSES_TEST) /**************************************************************************** * * Movement optimizer test code @@ -1152,11 +890,11 @@ int _nc_mvcur_scrolln(int n, int top, int bot, int maxy) #include <tic.h> #include <dump_entry.h> -char *_nc_progname = "mvcur"; +const char *_nc_progname = "mvcur"; static unsigned long xmits; -int tputs(const char *string, int affcnt, int (*outc)(int)) +int tputs(const char *string, int affcnt GCC_UNUSED, int (*outc)(int) GCC_UNUSED) /* stub tputs() that dumps sequences in a visible form */ { if (profiling) @@ -1194,7 +932,7 @@ static int roll(int n) return (j % n); } -int main(int argc, char *argv[]) +int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED) { char *p; @@ -1261,7 +999,7 @@ int main(int argc, char *argv[]) gettimeofday(&after, NULL); printf("\" (%ld msec)\n", - after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000); + (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000)); } else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) { @@ -1270,11 +1008,11 @@ int main(int argc, char *argv[]) putchar('"'); gettimeofday(&before, NULL); - _nc_mvcur_scrolln(fy, fx, ty, tx); + _nc_scrolln(fy, fx, ty, tx); gettimeofday(&after, NULL); printf("\" (%ld msec)\n", - after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000); + (long)(after.tv_usec - before.tv_usec + (after.tv_sec - before.tv_sec) * 1000000)); } else if (buf[0] == 'r') { @@ -1320,12 +1058,12 @@ int main(int argc, char *argv[]) else if (buf[0] == 'i') { dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0); - dump_entry(&cur_term->type, NULL); + dump_entry(&cur_term->type, 0, 0); putchar('\n'); } else if (buf[0] == 'o') { - if (_nc_optime_enable & OPTIMIZE_MVCUR) + if (_nc_optimize_enable & OPTIMIZE_MVCUR) { _nc_optimize_enable &=~ OPTIMIZE_MVCUR; (void) puts("Optimization is now off."); @@ -1424,10 +1162,10 @@ int main(int argc, char *argv[]) (void) printf("cup cost: %d\n", SP->_cup_cost); (void) printf("home cost: %d\n", SP->_home_cost); (void) printf("ll cost: %d\n", SP->_ll_cost); -#ifdef TABS_OK +#if USE_HARD_TABS (void) printf("ht cost: %d\n", SP->_ht_cost); (void) printf("cbt cost: %d\n", SP->_cbt_cost); -#endif /* TABS_OK */ +#endif /* USE_HARD_TABS */ (void) printf("cub1 cost: %d\n", SP->_cub1_cost); (void) printf("cuf1 cost: %d\n", SP->_cuf1_cost); (void) printf("cud1 cost: %d\n", SP->_cud1_cost); diff --git a/lib/libcurses/lib_mvwin.c b/lib/libcurses/lib_mvwin.c index 22bdb4a2604..acc84ead00d 100644 --- a/lib/libcurses/lib_mvwin.c +++ b/lib/libcurses/lib_mvwin.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_mvwin.c,v 1.3 1997/12/03 05:21:24 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,27 +32,94 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_mvwin.c,v 1.3 1997/02/02 00:20:41 tom Exp $") +MODULE_ID("Id: lib_mvwin.c,v 1.5 1997/09/20 15:02:34 juergen Exp $") int mvwin(WINDOW *win, int by, int bx) { T((T_CALLED("mvwin(%p,%d,%d)"), win, by, bx)); - if (win->_flags & _SUBWIN) + if (!win || (win->_flags & _ISPAD)) returnCode(ERR); + /* Copying subwindows is allowed, but it is expensive... */ + if (win->_flags & _SUBWIN) { + int err = ERR; + WINDOW *parent = win->_parent; + if (parent) + { /* Now comes the complicated and costly part, you should really + * try to avoid to move subwindows. Because a subwindow shares + * the text buffers with its parent, one can't do a simple + * memmove of the text buffers. One has to create a copy, then + * to relocate the subwindow and then to do a copy. + */ + if ((by - parent->_begy == win->_pary) && + (bx - parent->_begx == win->_parx)) + err=OK; /* we don't actually move */ + else { + WINDOW* clone = dupwin(win); + if (clone) { + /* now we have the clone, so relocate win */ + + werase(win); /* Erase the original place */ + wbkgd(win,parent->_bkgd);/* fill with parents background */ + wsyncup(win); /* Tell the parent(s) */ + + err = mvderwin(win, + by - parent->_begy, + bx - parent->_begx); + if (err!=ERR) { + err = copywin(clone,win, + 0, 0, 0, 0, win->_maxy, win->_maxx, 0); + if (ERR!=err) + wsyncup(win); + } + if (ERR==delwin(clone)) + err=ERR; + } + } + } + returnCode(err); + } + if (by + win->_maxy > screen_lines - 1 || bx + win->_maxx > screen_columns - 1 || by < 0 || bx < 0) returnCode(ERR); - + else { /* We have to clear the area on the virtual screen where the + * window is currently. Actually the following code is + * equivalent to erase() the window at it's current place and + * then to call a wnoutrefresh(). We can't do it this easy way, + * because we still need the content of the window at its new + * place:-) + * N.B.: Its not worth to think about an optimization to + * clear only the parts that are not overlapped by the new + * location of the window. The overlapped region will already + * be replaced by the next wnoutrefresh() for this window. + */ + int x,y; + for(y=0;y<=win->_maxy;y++) { + struct ldat* nline = &(newscr->_line[y+win->_begy+win->_yoffset]); + for(x=0;x<=win->_maxx;x++) { + nline->text[x+win->_begx] = newscr->_bkgd; + } + if (nline->firstchar==_NOCHANGE) { + nline->firstchar = win->_begx; + nline->lastchar = win->_begx + win->_maxx; + } else { + if (nline->firstchar > win->_begx) + nline->firstchar = win->_begx; + if (nline->lastchar < (win->_begx + win->_maxx)) + nline->lastchar = (win->_begx + win->_maxx); + } + } + } /* * Whether or not the window is moved, touch the window's contents so * that a following call to 'wrefresh()' will paint the window at the * new location. This ensures that if the caller has refreshed another * window at the same location, that this one will be displayed. - */ + */ win->_begy = by; win->_begx = bx; returnCode(touchwin(win)); diff --git a/lib/libcurses/lib_newterm.c b/lib/libcurses/lib_newterm.c index 06cf4fd668e..a1076190e60 100644 --- a/lib/libcurses/lib_newterm.c +++ b/lib/libcurses/lib_newterm.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_newterm.c,v 1.3 1997/12/03 05:21:25 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,15 +32,48 @@ #include <curses.priv.h> -#ifdef SVR4_TERMIO +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif #include <term.h> /* clear_screen, cup & friends, cur_term */ -MODULE_ID("Id: lib_newterm.c,v 1.23 1997/03/30 01:42:01 tom Exp $") +MODULE_ID("Id: lib_newterm.c,v 1.30 1997/11/08 17:32:31 tom Exp $") + +#ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ +#define ONLCR 0 +#endif + +/* + * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not + * restored during the curses session. The library simulates echo in software. + * (The behavior is unspecified if the application enables hardware echo). + * + * The newterm function also initializes terminal settings, and since initscr + * is supposed to behave as if it calls newterm, we do it here. + */ +static inline int _nc_initscr(void) +{ + /* for extended XPG4 conformance requires cbreak() at this point */ + /* (SVr4 curses does this anyway) */ + cbreak(); + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); + cur_term->Nttyb.c_iflag &= ~(ICRNL|INLCR|IGNCR); + cur_term->Nttyb.c_oflag &= ~(ONLCR); +#else + cur_term->Nttyb.sg_flags &= ~(ECHO|CRMOD); +#endif + return _nc_set_curterm(&cur_term->Nttyb); +} -/* This should be moved to TERMINAL */ +/* + * filter() has to be called before either initscr() or newterm(), so there is + * apparently no way to make this flag apply to some terminals and not others, + * aside from possibly delaying a filter() call until some terminals have been + * initialized. + */ static int filter_mode = FALSE; void filter(void) @@ -49,6 +84,7 @@ void filter(void) SCREEN * newterm(const char *term, FILE *ofp, FILE *ifp) { int errret; +SCREEN* current; #ifdef TRACE char *t = getenv("NCURSES_TRACE"); @@ -60,12 +96,12 @@ char *t = getenv("NCURSES_TRACE"); /* this loads the capability entry, then sets LINES and COLS */ if (setupterm(term, fileno(ofp), &errret) == ERR) - return NULL; + return 0; /* * Check for mismatched graphic-rendition capabilities. Most SVr4 - * terminfo tree contain entries that have rmul or rmso equated to sgr0 - * (Solaris curses copes with those entries). We do this only for + * terminfo trees contain entries that have rmul or rmso equated to + * sgr0 (Solaris curses copes with those entries). We do this only for * curses, since many termcap applications assume that smso/rmso and * smul/rmul are paired, and will not function properly if we remove * rmso or rmul. Curses applications shouldn't be looking at this @@ -92,12 +128,12 @@ char *t = getenv("NCURSES_TRACE"); T(("TABSIZE = %d", TABSIZE)); #ifdef clear_screen - clear_screen = (char *)NULL; - cursor_down = parm_down_cursor = (char *)NULL; - cursor_address = (char *)NULL; - cursor_up = parm_up_cursor = (char *)NULL; - row_address = (char *)NULL; - + clear_screen = 0; + cursor_down = parm_down_cursor = 0; + cursor_address = 0; + cursor_up = parm_up_cursor = 0; + row_address = 0; + cursor_home = carriage_return; #endif /* clear_screen */ } @@ -112,13 +148,17 @@ char *t = getenv("NCURSES_TRACE"); if (_nc_slk_format) { if (ERR==_nc_ripoffline(-SLK_LINES, _nc_slk_initialize)) - return NULL; + return 0; } /* this actually allocates the screen structure, and saves the * original terminal settings. */ - if (_nc_setupscreen(LINES, COLS, ofp) == ERR) - return NULL; + current = SP; + _nc_set_screen(0); + if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { + _nc_set_screen(current); + return 0; + } #ifdef num_labels /* if the terminal type has real soft labels, set those up */ @@ -144,8 +184,8 @@ char *t = getenv("NCURSES_TRACE"); _nc_signal_handler(TRUE); - /* open a connection to the screen's associated mouse, if any */ - _nc_mouse_init(SP); + /* initialize terminal to a sane state */ + _nc_screen_init(); /* Initialize the terminal line settings. */ _nc_initscr(); diff --git a/lib/libcurses/lib_newwin.c b/lib/libcurses/lib_newwin.c index 66269e31638..937dac1a939 100644 --- a/lib/libcurses/lib_newwin.c +++ b/lib/libcurses/lib_newwin.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_newwin.c,v 1.3 1997/12/03 05:21:25 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,7 +32,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_newwin.c,v 1.17 1997/02/15 21:46:05 tom Exp $") +MODULE_ID("Id: lib_newwin.c,v 1.18 1997/08/09 17:21:49 tom Exp $") void _nc_freewin(WINDOW *win) { @@ -236,7 +238,7 @@ bool is_pad = (flags & _ISPAD); win->_line[i].firstchar = 0; win->_line[i].lastchar = num_columns-1; - win->_line[i].oldindex = i; + if_USE_SCROLL_HINTS(win->_line[i].oldindex = i); } if (!is_pad && (begx + num_columns == screen_columns)) { diff --git a/lib/libcurses/lib_options.c b/lib/libcurses/lib_options.c index be33dd2e446..7af726649ad 100644 --- a/lib/libcurses/lib_options.c +++ b/lib/libcurses/lib_options.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_options.c,v 1.3 1997/12/03 05:21:26 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -34,6 +36,8 @@ MODULE_ID("Id: lib_options.c,v 1.22 1997/05/01 23:46:18 Alexander.V.Lukyanov Exp $") +static void add_to_try(char *, short); + int has_ic(void) { T((T_CALLED("has_ic()"))); @@ -53,8 +57,12 @@ int idlok(WINDOW *win, bool flag) { T((T_CALLED("idlok(%p,%d)"), win, flag)); - _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region); - returnCode(OK); + if (win) { + _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region); + returnCode(OK); + } + else + returnCode(ERR); } @@ -62,7 +70,8 @@ void idcok(WINDOW *win, bool flag) { T((T_CALLED("idcok(%p,%d)"), win, flag)); - _nc_idcok = win->_idcok = flag && has_ic(); + if (win) + _nc_idcok = win->_idcok = flag && has_ic(); returnVoid; } @@ -72,8 +81,12 @@ int clearok(WINDOW *win, bool flag) { T((T_CALLED("clearok(%p,%d)"), win, flag)); - win->_clear = flag; - returnCode(OK); + if (win) { + win->_clear = flag; + returnCode(OK); + } + else + returnCode(ERR); } @@ -81,7 +94,8 @@ void immedok(WINDOW *win, bool flag) { T((T_CALLED("immedok(%p,%d)"), win, flag)); - win->_immed = flag; + if (win) + win->_immed = flag; returnVoid; } @@ -90,12 +104,16 @@ int leaveok(WINDOW *win, bool flag) { T((T_CALLED("leaveok(%p,%d)"), win, flag)); - win->_leaveok = flag; - if (flag == TRUE) - curs_set(0); + if (win) { + win->_leaveok = flag; + if (flag == TRUE) + curs_set(0); + else + curs_set(1); + returnCode(OK); + } else - curs_set(1); - returnCode(OK); + returnCode(ERR); } @@ -103,8 +121,12 @@ int scrollok(WINDOW *win, bool flag) { T((T_CALLED("scrollok(%p,%d)"), win, flag)); - win->_scroll = flag; - returnCode(OK); + if (win) { + win->_scroll = flag; + returnCode(OK); + } + else + returnCode(ERR); } int halfdelay(int t) @@ -123,69 +145,56 @@ int nodelay(WINDOW *win, bool flag) { T((T_CALLED("nodelay(%p,%d)"), win, flag)); - if (flag == TRUE) - win->_delay = 0; - else win->_delay = -1; - returnCode(OK); + if (win) { + if (flag == TRUE) + win->_delay = 0; + else win->_delay = -1; + returnCode(OK); + } + else + returnCode(ERR); } int notimeout(WINDOW *win, bool f) { T((T_CALLED("notimout(%p,%d)"), win, f)); - win->_notimeout = f; - returnCode(OK); + if (win) { + win->_notimeout = f; + returnCode(OK); + } + else + returnCode(ERR); } int wtimeout(WINDOW *win, int delay) { T((T_CALLED("wtimeout(%p,%d)"), win, delay)); - win->_delay = delay; - returnCode(OK); -} - -static void init_keytry(void); -static void add_to_try(char *, short); - -/* Turn the keypad on/off - * - * Note: we flush the output because changing this mode causes some terminals - * to emit different escape sequences for cursor and keypad keys. If we don't - * flush, then the next wgetch may get the escape sequence that corresponds to - * the terminal state _before_ switching modes. - */ -int _nc_keypad(bool flag) -{ - if (flag && keypad_xmit) - { - TPUTS_TRACE("keypad_xmit"); - putp(keypad_xmit); - (void) fflush(SP->_ofp); - } - else if (! flag && keypad_local) - { - TPUTS_TRACE("keypad_local"); - putp(keypad_local); - (void) fflush(SP->_ofp); + if (win) { + win->_delay = delay; + returnCode(OK); } - - if (SP->_keytry == UNINITIALISED) - init_keytry(); - return(OK); + else + returnCode(ERR); } int keypad(WINDOW *win, bool flag) { T((T_CALLED("keypad(%p,%d)"), win, flag)); - win->_use_keypad = flag; - returnCode(_nc_keypad(flag)); + if (win) { + win->_use_keypad = flag; + returnCode(_nc_keypad(flag)); + } + else + returnCode(ERR); } int meta(WINDOW *win GCC_UNUSED, bool flag) { + /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); SP->_use_meta = flag; @@ -252,6 +261,38 @@ int cursor = SP->_cursor; returnCode(cursor==-1 ? 1 : cursor); } +int typeahead(int fd) +{ + T((T_CALLED("typeahead(%d)"), fd)); + SP->_checkfd = fd; + returnCode(OK); +} + +/* +** has_key() +** +** Return TRUE if the current terminal has the given key +** +*/ + + +static int has_key_internal(int keycode, struct tries *tp) +{ + if (tp == 0) + return(FALSE); + else if (tp->value == keycode) + return(TRUE); + else + return(has_key_internal(keycode, tp->child) + || has_key_internal(keycode, tp->sibling)); +} + +int has_key(int keycode) +{ + T((T_CALLED("has_key(%d)"), keycode)); + returnCode(has_key_internal(keycode, SP->_keytry)); +} + /* ** init_keytry() ** @@ -367,34 +408,29 @@ struct tries *ptr, *savedptr; return; } -int typeahead(int fd) -{ - T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); -} - -/* -** has_key() -** -** Return TRUE if the current terminal has the given key -** -*/ - - -static int has_key_internal(int keycode, struct tries *tp) +/* Turn the keypad on/off + * + * Note: we flush the output because changing this mode causes some terminals + * to emit different escape sequences for cursor and keypad keys. If we don't + * flush, then the next wgetch may get the escape sequence that corresponds to + * the terminal state _before_ switching modes. + */ +int _nc_keypad(bool flag) { - if (!tp) - return(FALSE); - else if (tp->value == keycode) - return(TRUE); - else - return(has_key_internal(keycode, tp->child) - || has_key_internal(keycode, tp->sibling)); -} + if (flag && keypad_xmit) + { + TPUTS_TRACE("keypad_xmit"); + putp(keypad_xmit); + (void) fflush(SP->_ofp); + } + else if (! flag && keypad_local) + { + TPUTS_TRACE("keypad_local"); + putp(keypad_local); + (void) fflush(SP->_ofp); + } -int has_key(int keycode) -{ - T((T_CALLED("has_key(%d)"), keycode)); - returnCode(has_key_internal(keycode, SP->_keytry)); + if (SP->_keytry == UNINITIALISED) + init_keytry(); + return(OK); } diff --git a/lib/libcurses/lib_overlay.c b/lib/libcurses/lib_overlay.c index a3ce2d6c771..e67c39e9587 100644 --- a/lib/libcurses/lib_overlay.c +++ b/lib/libcurses/lib_overlay.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_overlay.c,v 1.3 1997/12/03 05:21:26 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,7 +31,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_overlay.c,v 1.8 1997/04/24 10:34:38 tom Exp $") +MODULE_ID("Id: lib_overlay.c,v 1.9 1997/09/20 15:02:34 juergen Exp $") static int overlap(const WINDOW *const s, WINDOW *const d, int const flag) { @@ -93,6 +95,9 @@ bool touched; T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); + if (!src || !dst) + returnCode(ERR); + /* make sure rectangle exists in source */ if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { diff --git a/lib/libcurses/lib_pad.c b/lib/libcurses/lib_pad.c index 1d2a6339d39..bede7b0ba18 100644 --- a/lib/libcurses/lib_pad.c +++ b/lib/libcurses/lib_pad.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_pad.c,v 1.3 1997/12/03 05:21:26 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,7 +31,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_pad.c,v 1.18 1997/04/12 17:42:52 tom Exp $") +MODULE_ID("Id: lib_pad.c,v 1.24 1997/09/20 15:02:34 juergen Exp $") WINDOW *newpad(int l, int c) { @@ -46,7 +48,7 @@ int i; returnWin(0); for (i = 0; i < l; i++) { - win->_line[i].oldindex = _NEWINDEX; + if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX); if ((win->_line[i].text = typeCalloc(chtype, ((size_t)c))) == 0) { _nc_freewin(win); returnWin(0); @@ -60,13 +62,14 @@ int i; WINDOW *subpad(WINDOW *orig, int l, int c, int begy, int begx) { -WINDOW *win; +WINDOW *win = (WINDOW *)0; T((T_CALLED("subpad(%d, %d)"), l, c)); - if (!(orig->_flags & _ISPAD) || ((win = derwin(orig, l, c, begy, begx)) == NULL)) + if (orig) { + if (!(orig->_flags & _ISPAD) || ((win = derwin(orig, l, c, begy, begx)) == NULL)) returnWin(0); - + } returnWin(win); } @@ -84,6 +87,7 @@ int prefresh(WINDOW *win, int pminrow, int pmincol, int pnoutrefresh(WINDOW *win, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol) { +const int my_len = 2; /* parameterize the threshold for hardscroll */ short i, j; short m, n; short pmaxrow; @@ -153,7 +157,7 @@ bool wide; * windows). Note that changing this formula will not break any code, * merely change the costs of various update cases. */ - wide = (sminrow <= 1 && win->_maxx >= (newscr->_maxx - 1)); + wide = (smincol < my_len && smaxcol > (newscr->_maxx - my_len)); for (i = pminrow, m = sminrow + win->_yoffset; i <= pmaxrow && m <= newscr->_maxy; @@ -174,17 +178,30 @@ bool wide; } } +#if USE_SCROLL_HINTS if (wide) { int nind = m + displaced; if (oline->oldindex < 0 || nind < sminrow - || nind > smaxrow) + || nind > smaxrow) { nind = _NEWINDEX; + } else if (displaced) { + register struct ldat *pline = &curscr->_line[nind]; + for (j = 0; j <= my_len; j++) { + int k = newscr->_maxx - j; + if (pline->text[j] != nline->text[j] + || pline->text[k] != nline->text[k]) { + nind = _NEWINDEX; + break; + } + } + } nline->oldindex = nind; } +#endif /* USE_SCROLL_HINTS */ oline->firstchar = oline->lastchar = _NOCHANGE; - oline->oldindex = i; + if_USE_SCROLL_HINTS(oline->oldindex = i); } /* @@ -193,10 +210,12 @@ bool wide; * procedure. The only rows that should have an index value are those * that are displayed during this cycle. */ +#if USE_SCROLL_HINTS for (i = pminrow-1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) win->_line[i].oldindex = _NEWINDEX; for (i = pmaxrow+1; (i <= win->_maxy) && (win->_line[i].oldindex >= 0); i++) win->_line[i].oldindex = _NEWINDEX; +#endif win->_begx = smincol; win->_begy = sminrow; @@ -235,14 +254,23 @@ bool wide; returnCode(OK); } -int pechochar(WINDOW *pad, chtype ch) +int pechochar(WINDOW *pad, const chtype ch) { T((T_CALLED("pechochar(%p, %s)"), pad, _tracechtype(ch))); - if (pad->_flags & _ISPAD) - returnCode(ERR); + if (pad == 0) + returnCode(ERR); + + if (!(pad->_flags & _ISPAD)) + returnCode(wechochar(pad,ch)); - waddch(curscr, ch); - doupdate(); + waddch(pad, ch); + prefresh(pad, pad->_pad._pad_y, + pad->_pad._pad_x, + pad->_pad._pad_top, + pad->_pad._pad_left, + pad->_pad._pad_bottom, + pad->_pad._pad_right); + returnCode(OK); } diff --git a/lib/libcurses/lib_print.c b/lib/libcurses/lib_print.c index 31c10ade575..987b1c86fa4 100644 --- a/lib/libcurses/lib_print.c +++ b/lib/libcurses/lib_print.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_print.c,v 1.2 1997/12/03 05:21:27 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_printw.c b/lib/libcurses/lib_printw.c index 4e296624a94..7ca50e2e26b 100644 --- a/lib/libcurses/lib_printw.c +++ b/lib/libcurses/lib_printw.c @@ -1,25 +1,25 @@ - -/*************************************************************************** -* COPYRIGHT NOTICE * -**************************************************************************** -* ncurses is copyright (C) 1992-1995 * -* Zeyd M. Ben-Halim * -* zmbenhal@netcom.com * -* Eric S. Raymond * -* esr@snark.thyrsus.com * -* * -* Permission is hereby granted to reproduce and distribute ncurses * -* by any means and for any fee, whether alone or as part of a * -* larger distribution, in source or in binary form, PROVIDED * -* this notice is included with any such distribution, and is not * -* removed from any of its header files. Mention of ncurses in any * -* applications linked with it is highly appreciated. * -* * -* ncurses comes AS IS with no warranty, implied or expressed. * -* * -***************************************************************************/ - - +/* $OpenBSD: lib_printw.c,v 1.5 1997/12/03 05:21:27 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ /* ** lib_printw.c @@ -30,66 +30,72 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_printw.c,v 1.3 1997/02/16 00:07:23 tom Exp $") +MODULE_ID("Id: lib_printw.c,v 1.5 1997/08/31 21:22:33 tom Exp $") int printw(const char *fmt, ...) { -va_list argp; -char buf[BUFSIZ]; + va_list argp; + int code; T(("printw(%s,...) called", _nc_visbuf(fmt))); va_start(argp, fmt); - vsnprintf(buf, sizeof buf, fmt, argp); + code = vwprintw(stdscr, fmt, argp); va_end(argp); - return(waddstr(stdscr, buf)); -} - + return code; +} int wprintw(WINDOW *win, const char *fmt, ...) { -va_list argp; -char buf[BUFSIZ]; + va_list argp; + int code; T(("wprintw(%p,%s,...) called", win, _nc_visbuf(fmt))); va_start(argp, fmt); - vsnprintf(buf, sizeof buf, fmt, argp); + code = vwprintw(win, fmt, argp); va_end(argp); - return(waddstr(win, buf)); -} - + return code; +} int mvprintw(int y, int x, const char *fmt, ...) { -va_list argp; -char buf[BUFSIZ]; - - va_start(argp, fmt); - vsnprintf(buf, sizeof buf, fmt, argp); - va_end(argp); - return(move(y, x) == OK ? waddstr(stdscr, buf) : ERR); + va_list argp; + int code = move(y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(stdscr, fmt, argp); + va_end(argp); + } + return code; } - - int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) { -va_list argp; -char buf[BUFSIZ]; - - va_start(argp, fmt); - vsnprintf(buf, sizeof buf, fmt, argp); - va_end(argp); - return(wmove(win, y, x) == OK ? waddstr(win, buf) : ERR); + va_list argp; + int code = wmove(win, y, x); + + if (code != ERR) { + va_start(argp, fmt); + code = vwprintw(win, fmt, argp); + va_end(argp); + } + return code; } int vwprintw(WINDOW *win, const char *fmt, va_list argp) { -char buf[BUFSIZ]; - - vsnprintf(buf, sizeof buf, fmt, argp); - return(waddstr(win, buf)); + char *buf = _nc_printf_string(fmt, argp); + int code = ERR; + + if (buf != 0) { + code = waddstr(win, buf); +#if USE_SAFE_SPRINTF + free(buf); +#endif + } + return code; } diff --git a/lib/libcurses/lib_raw.c b/lib/libcurses/lib_raw.c index 4cd1b953678..204d3424227 100644 --- a/lib/libcurses/lib_raw.c +++ b/lib/libcurses/lib_raw.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_raw.c,v 1.3 1997/12/03 05:21:27 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -41,9 +43,9 @@ #include <curses.priv.h> #include <term.h> /* cur_term */ -MODULE_ID("Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $") +MODULE_ID("Id: lib_raw.c,v 1.21 1997/11/01 19:05:35 tom Exp $") -#ifdef SVR4_TERMIO +#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif @@ -62,11 +64,32 @@ MODULE_ID("Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $") #define COOKED_INPUT (IXON|BRKINT|PARMRK) #ifdef TRACE + +typedef struct {unsigned int val; const char *name;} BITNAMES; + +static void lookup_bits(char *buf, const BITNAMES *table, const char *label, unsigned int val) +{ + const BITNAMES *sp; + + (void) strcat(buf, label); + (void) strcat(buf, ": {"); + for (sp = table; sp->name; sp++) + if (sp->val != 0 + && (val & sp->val) == sp->val) + { + (void) strcat(buf, sp->name); + (void) strcat(buf, ", "); + } + if (buf[strlen(buf) - 2] == ',') + buf[strlen(buf) - 2] = '\0'; + (void) strcat(buf,"} "); +} + char *_tracebits(void) /* describe the state of the terminal control bits exactly */ { -static char buf[BUFSIZ]; -static const struct {unsigned int val; const char *name;} +char *buf; +static const BITNAMES #ifdef TERMIOS iflags[] = @@ -95,8 +118,10 @@ cflags[] = { {CLOCAL, "CLOCAL"}, {CREAD, "CREAD"}, - {CSIZE, "CSIZE"}, {CSTOPB, "CSTOPB"}, +#if !defined(CS5) || !defined(CS8) + {CSIZE, "CSIZE"}, +#endif {HUPCL, "HUPCL"}, {PARENB, "PARENB"}, {PARODD|PARENB, "PARODD"}, /* concession to readability */ @@ -112,72 +137,41 @@ lflags[] = {ICANON, "ICANON"}, {ISIG, "ISIG"}, {NOFLSH, "NOFLSH"}, -#if TOSTOP != 0 {TOSTOP, "TOSTOP"}, -#endif -#if IEXTEN != 0 {IEXTEN, "IEXTEN"}, -#endif {0, NULL} #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN) - }, - *sp; + }; + + + buf = _nc_trace_buf(0, + 8 + sizeof(iflags) + + 8 + sizeof(oflags) + + 8 + sizeof(cflags) + + 8 + sizeof(lflags) + + 8); if (cur_term->Nttyb.c_iflag & ALLIN) - { - (void) strcpy(buf, "iflags: {"); - for (sp = iflags; sp->val; sp++) - if ((cur_term->Nttyb.c_iflag & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); - } + lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag); if (cur_term->Nttyb.c_oflag & ALLOUT) - { - (void) strcat(buf, "oflags: {"); - for (sp = oflags; sp->val; sp++) - if ((cur_term->Nttyb.c_oflag & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); - } + lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag); if (cur_term->Nttyb.c_cflag & ALLCTRL) - { - (void) strcat(buf, "cflags: {"); - for (sp = cflags; sp->val; sp++) - if ((cur_term->Nttyb.c_cflag & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); + lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag); + +#if defined(CS5) && defined(CS8) + switch (cur_term->Nttyb.c_cflag & CSIZE) { + case CS5: strcat(buf, "CS5 "); break; + case CS6: strcat(buf, "CS6 "); break; + case CS7: strcat(buf, "CS7 "); break; + case CS8: strcat(buf, "CS8 "); break; + default: strcat(buf, "CSIZE? "); break; } +#endif if (cur_term->Nttyb.c_lflag & ALLLOCAL) - { - (void) strcat(buf, "lflags: {"); - for (sp = lflags; sp->val; sp++) - if ((cur_term->Nttyb.c_lflag & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); - } + lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag); #else /* reference: ttcompat(4M) on SunOS 4.1 */ @@ -211,21 +205,14 @@ cflags[] = {XTABS, "XTABS"}, {0, NULL} #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS) - }, - *sp; + }; + + buf = _nc_trace_buf(0, + 8 + sizeof(cflags)); if (cur_term->Nttyb.sg_flags & ALLCTRL) { - (void) strcat(buf, "cflags: {"); - for (sp = cflags; sp->val; sp++) - if ((cur_term->Nttyb.sg_flags & sp->val) == sp->val) - { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); - } - if (buf[strlen(buf) - 2] == ',') - buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf,"} "); + lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags); } #endif @@ -256,9 +243,7 @@ int raw(void) #else cur_term->Nttyb.sg_flags |= RAW; #endif - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - returnCode(OK); + returnCode(_nc_set_curterm(&cur_term->Nttyb)); } int cbreak(void) @@ -278,9 +263,7 @@ int cbreak(void) #else cur_term->Nttyb.sg_flags |= CBREAK; #endif - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); } int echo(void) @@ -316,10 +299,7 @@ int qiflush(void) BEFORE("qiflush"); cur_term->Nttyb.c_lflag &= ~(NOFLSH); AFTER("qiflush"); - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - else - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); #else returnCode(ERR); #endif @@ -341,9 +321,7 @@ int noraw(void) #else cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK); #endif - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); } @@ -361,9 +339,7 @@ int nocbreak(void) #else cur_term->Nttyb.sg_flags &= ~CBREAK; #endif - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); } int noecho(void) @@ -396,10 +372,7 @@ int noqiflush(void) BEFORE("noqiflush"); cur_term->Nttyb.c_lflag |= NOFLSH; AFTER("noqiflush"); - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - else - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); #else returnCode(ERR); #endif @@ -425,10 +398,7 @@ int intrflush(WINDOW *win GCC_UNUSED, bool flag) else cur_term->Nttyb.c_lflag |= (NOFLSH); AFTER("intrflush"); - if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1) - returnCode(ERR); - else - returnCode(OK); + returnCode(_nc_set_curterm( &cur_term->Nttyb)); #else returnCode(ERR); #endif diff --git a/lib/libcurses/lib_redrawln.c b/lib/libcurses/lib_redrawln.c new file mode 100644 index 00000000000..0fc687e03c8 --- /dev/null +++ b/lib/libcurses/lib_redrawln.c @@ -0,0 +1,58 @@ +/* $OpenBSD: lib_redrawln.c,v 1.1 1997/12/03 05:21:28 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +/* + * lib_redrawln.c + * + * The routine wredrawln(). + * + */ + +#include <curses.priv.h> + +MODULE_ID("Id: lib_redrawln.c,v 1.1 1997/11/29 20:10:56 tom Exp $") + +int wredrawln(WINDOW *win, int beg, int num) +{ +int i; + + T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); + + if (touchline(win, beg, num) == OK) { + size_t len = win->_maxx * sizeof(chtype); + + /* + * XSI says that wredrawln() tells the library not to base + * optimization on the contents of the lines that are marked. + * We do that by changing the contents to nulls after touching + * the corresponding lines to get the optimizer's attention. + * + * FIXME: this won't work if the application makes further + * updates before the next refresh. + */ + for (i = beg; (i < beg + num) && (i < win->_maxy); i++) { + memset(win->_line[i].text, 0, len); + } + } + returnCode(OK); +} diff --git a/lib/libcurses/lib_refresh.c b/lib/libcurses/lib_refresh.c index d2d3c1e008d..65c32f7d7e9 100644 --- a/lib/libcurses/lib_refresh.c +++ b/lib/libcurses/lib_refresh.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_refresh.c,v 1.3 1997/12/03 05:21:28 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -24,21 +26,13 @@ /* * lib_refresh.c * - * The routines wredrawln(), wrefresh() and wnoutrefresh(). + * The routines wrefresh() and wnoutrefresh(). * */ #include <curses.priv.h> -MODULE_ID("Id: lib_refresh.c,v 1.14 1997/02/02 01:05:26 tom Exp $") - -int wredrawln(WINDOW *win, int beg, int num) -{ - T((T_CALLED("wredrawln(%p,%d,%d)"), win, beg, num)); - touchline(win, beg, num); - wrefresh(win); - returnCode(OK); -} +MODULE_ID("Id: lib_refresh.c,v 1.17 1997/11/29 19:54:29 tom Exp $") int wrefresh(WINDOW *win) { @@ -153,14 +147,16 @@ bool wide; } +#if USE_SCROLL_HINTS if (wide) { int oind = oline->oldindex; nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind + win->_yoffset; } +#endif /* USE_SCROLL_HINTS */ oline->firstchar = oline->lastchar = _NOCHANGE; - oline->oldindex = i; + if_USE_SCROLL_HINTS(oline->oldindex = i); } if (win->_clear) { diff --git a/lib/libcurses/lib_resize.c b/lib/libcurses/lib_resize.c deleted file mode 100644 index 0855d3f9fb5..00000000000 --- a/lib/libcurses/lib_resize.c +++ /dev/null @@ -1,154 +0,0 @@ - -/*************************************************************************** -* COPYRIGHT NOTICE * -**************************************************************************** -* ncurses is copyright (C) 1992-1995 * -* Zeyd M. Ben-Halim * -* zmbenhal@netcom.com * -* Eric S. Raymond * -* esr@snark.thyrsus.com * -* * -* Permission is hereby granted to reproduce and distribute ncurses * -* by any means and for any fee, whether alone or as part of a * -* larger distribution, in source or in binary form, PROVIDED * -* this notice is included with any such distribution, and is not * -* removed from any of its header files. Mention of ncurses in any * -* applications linked with it is highly appreciated. * -* * -* ncurses comes AS IS with no warranty, implied or expressed. * -* * -***************************************************************************/ - -/* - * Note: This code is not part of the SVr4/XSI Curses API! - */ - -#include <curses.priv.h> -#include <stdlib.h> - -int wresize(WINDOW *win, int new_lines, int new_cols) -{ - chtype blank = _nc_render(win, ' ', BLANK); - register int i, j; - - T(("wresize(win=%p, lines=%d, cols=%d) called", win, new_lines, new_cols)); - - if (new_lines <= 0 || new_cols <= 0) - return ERR; - - /* window height is different, must mess with the line vector */ - if (new_lines != win->_maxy+1) - { - struct ldat *tp; - - /* free old lines no longer used */ - if (!(win->_flags & _SUBWIN)) - for (i = new_lines + 1; i <= win->_maxy; i++) - free((char *)(win->_line[i].text)); - - /* resize the window line vector */ - if (!(win->_line = realloc(win->_line, sizeof(struct ldat) * new_lines))) - return(ERR); - - /* grab new lines for the window if needed */ - for (tp=&win->_line[i=win->_maxy+1]; tp<&win->_line[new_lines]; i++,tp++) - { - if (win->_flags & _SUBWIN) /* set up alias pointers */ - tp->text = &(win->_parent->_line[win->_pary+i].text[win->_parx]); - else /* allocate new lines if needed */ - { - if (!(tp->text = (chtype *)malloc(sizeof(chtype) * new_cols))) { - errno = ENOMEM; - return(ERR); - } - for (j = 0; j < new_cols; j++) - tp->text[j] = blank; - } - - tp->firstchar = 0; - tp->lastchar = new_cols; - tp->oldindex = i; - } - - /* - * This is kind of nasty. We have to clip the scrolling region to - * within the new window size. We also have to assume that if the - * bottom of the scrolling region is the last line, the user wants - * that bottom to stick to the bottom of the resized window. The - * real problem here is that the API doesn't distinguish between - * resetting the scroll region to the entire window and setting it - * to an explicit scroll region that happens to include the whole - * window. - */ - if (win->_regtop > new_lines - 1 || win->_regtop == win->_maxy) - win->_regtop = new_lines - 1; - if (win->_regbottom > new_lines - 1 || win->_regbottom == win->_maxy) - win->_regbottom = new_lines - 1; - } - - /* window width is different, resize all old lines */ - if (new_cols != win->_maxx+1) - for (i = 0; i < min(new_lines, win->_maxy+1); i++) - { - /* if not a subwindow, we have our own storage; resize each line */ - if (!(win->_flags & _SUBWIN)) - { - win->_line[i].text=realloc(win->_line[i].text,sizeof(chtype)*new_cols); - if (win->_line[i].text == (chtype *)NULL) - return(ERR); - } - - if (new_cols > win->_maxx+1) /* window is growing horizontally */ - { - if (win->_line[i].firstchar == _NOCHANGE) - win->_line[i].firstchar = win->_maxx+1; - win->_line[i].lastchar = new_cols; - for (j = win->_maxx+1; j < new_cols; j++) /* blank-fill ends */ - win->_line[i].text[j] = blank; - } - else /* window is shrinking horizontally */ - { - if (win->_line[i].firstchar > win->_maxx+1) - win->_line[i].firstchar = _NOCHANGE; - else if (win->_line[i].lastchar > new_cols) - win->_line[i].lastchar = new_cols; - } - } - - /* clip the cursor position to within the new size */ - if (win->_curx > new_cols - 1) - win->_curx = new_cols - 1; - if (win->_cury > new_lines - 1) - win->_cury = new_lines - 1; - - /* whether this is a full-width or full-depth window may have changed */ - win->_flags &=~ (_ENDLINE|_FULLWIN|_SCROLLWIN); - if (win->_begx + new_cols == screen_columns) - { - win->_flags |= _ENDLINE; - - if (win->_begx == 0 && new_lines == screen_lines && win->_begy == 0) - win->_flags |= _FULLWIN; - - if (win->_begy + new_lines == screen_lines) - win->_flags |= _SCROLLWIN; - } - - /* right margin may have moved, set _NEED_WRAP properly */ - if ((win->_flags & _NEED_WRAP) && win->_curx != new_cols - 1) - { - win->_curx++; - win->_flags &=~ _NEED_WRAP; - } - if (!(win->_flags & _NEED_WRAP) && win->_curx == new_cols) - { - win->_curx--; - win->_flags |= _NEED_WRAP; - } - - /* finally, update size members */ - win->_maxy = new_lines - 1; - win->_maxx = new_cols - 1; - - return OK; -} diff --git a/lib/libcurses/lib_scanw.c b/lib/libcurses/lib_scanw.c index 2d61dfeab01..07c7a091b5e 100644 --- a/lib/libcurses/lib_scanw.c +++ b/lib/libcurses/lib_scanw.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_scanw.c,v 1.3 1997/12/03 05:21:29 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,7 +32,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_scanw.c,v 1.4 1997/02/08 14:45:51 tom Exp $") +MODULE_ID("Id: lib_scanw.c,v 1.5 1997/08/30 23:49:19 tom Exp $") #if !HAVE_VSSCANF extern int vsscanf(const char *str, const char *format, ...); @@ -40,7 +42,7 @@ int vwscanw(WINDOW *win, const char *fmt, va_list argp) { char buf[BUFSIZ]; - if (wgetstr(win, buf) == ERR) + if (wgetnstr(win, buf, sizeof(buf)-1) == ERR) return(ERR); return(vsscanf(buf, fmt, argp)); diff --git a/lib/libcurses/lib_screen.c b/lib/libcurses/lib_screen.c index c99bb4849cc..a152f5b6174 100644 --- a/lib/libcurses/lib_screen.c +++ b/lib/libcurses/lib_screen.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_screen.c,v 1.3 1997/12/03 05:21:29 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -26,22 +28,22 @@ #include <time.h> #include <term.h> /* exit_ca_mode, non_rev_rmcup */ -MODULE_ID("Id: lib_screen.c,v 1.7 1997/02/02 00:41:10 tom Exp $") +MODULE_ID("Id: lib_screen.c,v 1.9 1997/10/18 19:22:52 tom Exp $") static time_t dumptime; WINDOW *getwin(FILE *filep) { - WINDOW try, *nwin; + WINDOW tmp, *nwin; int n; T((T_CALLED("getwin(%p)"), filep)); - (void) fread(&try, sizeof(WINDOW), 1, filep); + (void) fread(&tmp, sizeof(WINDOW), 1, filep); if (ferror(filep)) returnWin(0); - if ((nwin = newwin(try._maxy+1, try._maxx+1, 0, 0)) == 0) + if ((nwin = newwin(tmp._maxy+1, tmp._maxx+1, 0, 0)) == 0) returnWin(0); /* @@ -49,28 +51,28 @@ WINDOW *getwin(FILE *filep) * fields, because the window hierarchy within which they * made sense is probably gone. */ - nwin->_curx = try._curx; - nwin->_cury = try._cury; - nwin->_maxy = try._maxy; - nwin->_maxx = try._maxx; - nwin->_begy = try._begy; - nwin->_begx = try._begx; - nwin->_yoffset = try._yoffset; - nwin->_flags = try._flags & ~(_SUBWIN|_ISPAD); - - nwin->_attrs = try._attrs; - nwin->_bkgd = try._bkgd; - - nwin->_clear = try._clear; - nwin->_scroll = try._scroll; - nwin->_leaveok = try._leaveok; - nwin->_use_keypad = try._use_keypad; - nwin->_delay = try._delay; - nwin->_immed = try._immed; - nwin->_sync = try._sync; - - nwin->_regtop = try._regtop; - nwin->_regbottom = try._regbottom; + nwin->_curx = tmp._curx; + nwin->_cury = tmp._cury; + nwin->_maxy = tmp._maxy; + nwin->_maxx = tmp._maxx; + nwin->_begy = tmp._begy; + nwin->_begx = tmp._begx; + nwin->_yoffset = tmp._yoffset; + nwin->_flags = tmp._flags & ~(_SUBWIN|_ISPAD); + + nwin->_attrs = tmp._attrs; + nwin->_bkgd = tmp._bkgd; + + nwin->_clear = tmp._clear; + nwin->_scroll = tmp._scroll; + nwin->_leaveok = tmp._leaveok; + nwin->_use_keypad = tmp._use_keypad; + nwin->_delay = tmp._delay; + nwin->_immed = tmp._immed; + nwin->_sync = tmp._sync; + + nwin->_regtop = tmp._regtop; + nwin->_regbottom = tmp._regbottom; for (n = 0; n < nwin->_maxy + 1; n++) { @@ -89,23 +91,26 @@ WINDOW *getwin(FILE *filep) int putwin(WINDOW *win, FILE *filep) { - int n; + int code = ERR; + int n; T((T_CALLED("putwin(%p,%p)"), win, filep)); - (void) fwrite(win, sizeof(WINDOW), 1, filep); - if (ferror(filep)) - returnCode(ERR); - - for (n = 0; n < win->_maxy + 1; n++) - { - (void) fwrite(win->_line[n].text, - sizeof(chtype), (size_t)(win->_maxx + 1), filep); - if (ferror(filep)) - returnCode(ERR); + if (win) { + (void) fwrite(win, sizeof(WINDOW), 1, filep); + if (ferror(filep)) + returnCode(code); + + for (n = 0; n < win->_maxy + 1; n++) + { + (void) fwrite(win->_line[n].text, + sizeof(chtype), (size_t)(win->_maxx + 1), filep); + if (ferror(filep)) + returnCode(code); + } + code = OK; } - - returnCode(OK); + returnCode(code); } int scr_restore(const char *file) diff --git a/lib/libcurses/lib_scroll.c b/lib/libcurses/lib_scroll.c index 4b58bf3468e..af78ed3cc8c 100644 --- a/lib/libcurses/lib_scroll.c +++ b/lib/libcurses/lib_scroll.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_scroll.c,v 1.3 1997/12/03 05:21:30 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -32,12 +34,11 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_scroll.c,v 1.11 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("Id: lib_scroll.c,v 1.15 1997/09/20 15:02:34 juergen Exp $") -void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom) +void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom, chtype blank) { int line, j; -chtype blank = _nc_background(win); size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top,bottom)); @@ -59,14 +60,12 @@ size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); memcpy(win->_line[line].text, win->_line[line+n].text, to_copy); - win->_line[line].oldindex = win->_line[line+n].oldindex; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); } for (line = top; line < top-n; line++) { for (j = 0; j <= win->_maxx; j ++) win->_line[line].text[j] = blank; - win->_line[line].oldindex = _NEWINDEX; - win->_line[line].firstchar = 0; - win->_line[line].lastchar = win->_maxx; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); } } @@ -76,16 +75,15 @@ size_t to_copy = (size_t)(sizeof(chtype) * (win->_maxx + 1)); memcpy(win->_line[line].text, win->_line[line+n].text, to_copy); - win->_line[line].oldindex = win->_line[line+n].oldindex; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = win->_line[line+n].oldindex); } for (line = bottom; line > bottom-n; line--) { for (j = 0; j <= win->_maxx; j ++) win->_line[line].text[j] = blank; - win->_line[line].oldindex = _NEWINDEX; - win->_line[line].firstchar = 0; - win->_line[line].lastchar = win->_maxx; + if_USE_SCROLL_HINTS(win->_line[line].oldindex = _NEWINDEX); } } + touchline(win, top, bottom-top+1); } int @@ -93,7 +91,7 @@ wscrl(WINDOW *win, int n) { T((T_CALLED("wscrl(%p,%d)"), win, n)); - if (! win->_scroll) + if (!win || !win->_scroll) returnCode(ERR); if (n == 0) @@ -103,8 +101,7 @@ wscrl(WINDOW *win, int n) (-n > (win->_regbottom - win->_regtop))) returnCode(ERR); - _nc_scroll_window(win, n, win->_regtop, win->_regbottom); - touchline(win, win->_regtop, (int)(win->_regbottom - win->_regtop + 1)); + _nc_scroll_window(win, n, win->_regtop, win->_regbottom, _nc_background(win)); _nc_synchook(win); returnCode(OK); diff --git a/lib/libcurses/lib_scrreg.c b/lib/libcurses/lib_scrreg.c index 2c2c3e50a24..b542d90d6e3 100644 --- a/lib/libcurses/lib_scrreg.c +++ b/lib/libcurses/lib_scrreg.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_scrreg.c,v 1.3 1997/12/03 05:21:30 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -30,20 +32,21 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_scrreg.c,v 1.5 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("Id: lib_scrreg.c,v 1.6 1997/09/20 15:02:34 juergen Exp $") int wsetscrreg(WINDOW *win, int top, int bottom) { T((T_CALLED("wsetscrreg(%p,%d,%d)"), win, top, bottom)); - if (top >= 0 && top <= win->_maxy && - bottom >= 0 && bottom <= win->_maxy && - bottom > top) - { - win->_regtop = (short)top; - win->_regbottom = (short)bottom; - - returnCode(OK); - } else - returnCode(ERR); + if (win && + top >= 0 && top <= win->_maxy && + bottom >= 0 && bottom <= win->_maxy && + bottom > top) + { + win->_regtop = (short)top; + win->_regbottom = (short)bottom; + + returnCode(OK); + } else + returnCode(ERR); } diff --git a/lib/libcurses/lib_set_term.c b/lib/libcurses/lib_set_term.c index ecb2bb88af1..5735154f86d 100644 --- a/lib/libcurses/lib_set_term.c +++ b/lib/libcurses/lib_set_term.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_set_term.c,v 1.4 1997/12/03 05:21:31 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -32,7 +34,7 @@ #include <term.h> /* cur_term */ -MODULE_ID("Id: lib_set_term.c,v 1.17 1997/05/01 23:46:18 Alexander.V.Lukyanov Exp $") +MODULE_ID("Id: lib_set_term.c,v 1.35 1997/11/08 21:23:37 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -106,12 +108,13 @@ SCREEN *oldSP; oldSP = SP; _nc_set_screen(screen); - cur_term = SP->_term; + set_curterm(SP->_term); curscr = SP->_curscr; newscr = SP->_newscr; stdscr = SP->_stdscr; COLORS = SP->_color_count; COLOR_PAIRS = SP->_pair_count; + memcpy(acs_map, SP->_acs_map, sizeof(chtype)*ACS_LEN); T((T_RETURN("%p"), oldSP)); return(oldSP); @@ -131,12 +134,25 @@ static void _nc_free_keytry(struct tries *kt) */ void delscreen(SCREEN *sp) { + SCREEN **scan = &_nc_screen_chain; + T((T_CALLED("delscreen(%p)"), sp)); + while(*scan) + { + if (*scan == sp) + { + *scan = sp->_next_screen; + break; + } + scan = &(*scan)->_next_screen; + } + _nc_freewin(sp->_curscr); _nc_freewin(sp->_newscr); _nc_freewin(sp->_stdscr); _nc_free_keytry(sp->_keytry); + _nc_free_keytry(sp->_key_ok); FreeIfNeeded(sp->_color_table); FreeIfNeeded(sp->_color_pairs); @@ -159,17 +175,29 @@ void delscreen(SCREEN *sp) returnVoid; } -ripoff_t rippedoff[5], *rsp = rippedoff; -#define N_RIPS (int)(sizeof(rippedoff)/sizeof(rippedoff[0])) +static ripoff_t rippedoff[5]; +static ripoff_t *rsp = rippedoff; +#define N_RIPS SIZEOF(rippedoff) + +static bool no_mouse_event (SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; } +static bool no_mouse_parse (int code GCC_UNUSED) { return TRUE; } +static void no_mouse_resume(SCREEN *sp GCC_UNUSED) { } +static void no_mouse_wrap (SCREEN *sp GCC_UNUSED) { } int _nc_setupscreen(short slines, short const scolumns, FILE *output) /* OS-independent screen initializations */ { -int bottom_stolen = 0, i; +int bottom_stolen = 0; +size_t i; + assert(SP==0); /* has been reset in newterm() ! */ if (!_nc_alloc_screen()) return ERR; + SP->_next_screen = _nc_screen_chain; + _nc_screen_chain = SP; + _nc_set_buffer(output, TRUE); SP->_term = cur_term; SP->_lines = slines; @@ -177,24 +205,67 @@ int bottom_stolen = 0, i; SP->_columns = scolumns; SP->_cursrow = -1; SP->_curscol = -1; - SP->_keytry = UNINITIALISED; SP->_nl = TRUE; SP->_raw = FALSE; SP->_cbreak = FALSE; - SP->_echo = FALSE; + SP->_echo = TRUE; SP->_fifohead = -1; - SP->_fifotail = 0; - SP->_fifopeek = 0; SP->_endwin = TRUE; SP->_ofp = output; - SP->_coloron = 0; - SP->_curscr = 0; - SP->_newscr = 0; - SP->_stdscr = 0; - SP->_topstolen = 0; SP->_cursor = -1; /* cannot know real cursor shape */ + SP->_maxclick = DEFAULT_MAXCLICK; + SP->_mouse_event = no_mouse_event; + SP->_mouse_inline = no_mouse_inline; + SP->_mouse_parse = no_mouse_parse; + SP->_mouse_resume = no_mouse_resume; + SP->_mouse_wrap = no_mouse_wrap; + SP->_mouse_fd = -1; + + /* initialize the panel hooks */ + SP->_panelHook.top_panel = (struct panel*)0; + SP->_panelHook.bottom_panel = (struct panel*)0; + SP->_panelHook.stdscr_pseudo_panel = (struct panel*)0; + + /* + * If we've no magic cookie support, we suppress attributes that xmc + * would affect, i.e., the attributes that affect the rendition of a + * space. Note that this impacts the alternate character set mapping + * as well. + */ + if (magic_cookie_glitch > 0) { + + SP->_xmc_triggers = termattrs() & ( + A_ALTCHARSET | + A_BLINK | + A_BOLD | + A_REVERSE | + A_STANDOUT | + A_UNDERLINE + ); + SP->_xmc_suppress = SP->_xmc_triggers & (chtype)~(A_BOLD); + + T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress))); +#if USE_XMC_SUPPORT + /* + * To keep this simple, suppress all of the optimization hooks + * except for clear_screen and the cursor addressing. + */ + clr_eol = 0; + clr_eos = 0; + set_attributes = 0; +#else + magic_cookie_glitch = -1; + acs_chars = 0; +#endif + } init_acs(); + memcpy(SP->_acs_map, acs_map, sizeof(chtype)*ACS_LEN); + + _nc_idcok = TRUE; + _nc_idlok = FALSE; + + _nc_windows = 0; /* no windows yet */ T(("creating newscr")); if ((newscr = newwin(slines, scolumns, 0, 0)) == 0) @@ -206,6 +277,7 @@ int bottom_stolen = 0, i; SP->_newscr = newscr; SP->_curscr = curscr; + SP->_resize = resizeterm; newscr->_clear = TRUE; curscr->_clear = FALSE; @@ -236,7 +308,10 @@ int bottom_stolen = 0, i; } SP->_lines_avail -= count; } + rsp->line = 0; } + /* reset the stack */ + rsp = rippedoff; T(("creating stdscr")); assert ((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines); diff --git a/lib/libcurses/lib_slk.c b/lib/libcurses/lib_slk.c index 6d9869ae2e6..c9a643a9199 100644 --- a/lib/libcurses/lib_slk.c +++ b/lib/libcurses/lib_slk.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_slk.c,v 1.3 1997/12/03 05:21:31 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,254 +31,32 @@ #include <ctype.h> #include <term.h> /* num_labels, label_*, plab_norm */ -MODULE_ID("Id: lib_slk.c,v 1.11 1997/01/18 23:06:32 tom Exp $") - -#define MAX_SKEY_OLD 8 /* count of soft keys */ -#define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */ -#define MAX_SKEY_PC 12 /* This is what most PC's have */ -#define MAX_SKEY_LEN_PC 5 +MODULE_ID("Id: lib_slk.c,v 1.13 1997/10/18 18:10:12 tom Exp $") -#define MAX_SKEY (SLK_STDFMT ? MAX_SKEY_OLD : MAX_SKEY_PC) -#define MAX_SKEY_LEN (SLK_STDFMT ? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC) /* * We'd like to move these into the screen context structure, but cannot, * because slk_init() is called before initscr()/newterm(). */ -int _nc_slk_format; /* one more than format specified in slk_init() */ - -static chtype _slk_attr = A_STANDOUT; /* soft label attribute */ -static SLK *_slk; -static void slk_paint_info(WINDOW *win); - -/* - * Fetch the label text. - */ - -char * -slk_label(int n) -{ - T(("slk_label(%d)", n)); - - if (SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) - return NULL; - return(SP->_slk->ent[n-1].text); -} - -/* - * Write the soft labels to the soft-key window. - */ - -static void -slk_intern_refresh(SLK *slk) -{ -int i; - for (i = 0; i < slk->labcnt; i++) { - if (slk->dirty || slk->ent[i].dirty) { - if (slk->ent[i].visible) { -#ifdef num_labels - if (num_labels > 0 && SLK_STDFMT) - { - if (i < num_labels) { - TPUTS_TRACE("plab_norm"); - putp(tparm(plab_norm, i, slk->win,slk->ent[i].form_text)); - } - } - else -#endif /* num_labels */ - { - wmove(slk->win,SLK_LINES-1,slk->ent[i].x); - wattrset(slk->win,_slk_attr); - waddnstr(slk->win,slk->ent[i].form_text, MAX_SKEY_LEN); - /* if we simulate SLK's, it's looking much more - natural to use the current ATTRIBUTE also - for the label window */ - wattrset(slk->win,stdscr->_attrs); - } - } - slk->ent[i].dirty = FALSE; - } - } - slk->dirty = FALSE; - -#ifdef num_labels - if (num_labels > 0) - if (slk->hidden) - { - TPUTS_TRACE("label_off"); - putp(label_off); - } - else - { - TPUTS_TRACE("label_on"); - putp(label_on); - } -#endif /* num_labels */ -} - -/* - * Refresh the soft labels. - */ - -int -slk_noutrefresh(void) -{ - T(("slk_noutrefresh()")); - - if (SP->_slk == NULL) - return(ERR); - if (SP->_slk->hidden) - return(OK); - slk_intern_refresh(SP->_slk); - return(wnoutrefresh(SP->_slk->win)); -} - -/* - * Refresh the soft labels. - */ - -int -slk_refresh(void) -{ - T(("slk_refresh()")); - - if (SP->_slk == NULL) - return(ERR); - if (SP->_slk->hidden) - return(OK); - slk_intern_refresh(SP->_slk); - return(wrefresh(SP->_slk->win)); -} - -/* - * Restore the soft labels on the screen. - */ - -int -slk_restore(void) -{ - T(("slk_restore()")); - - if (SP->_slk == NULL) - return(ERR); - SP->_slk->hidden = FALSE; - SP->_slk->dirty = TRUE; - /* we have to repaint info line eventually */ - slk_paint_info(SP->_slk->win); - return slk_refresh(); -} - -/* - * Set soft label text. - */ - -int -slk_set(int i, const char *astr, int format) -{ -SLK *slk = SP->_slk; -size_t len; -const char *str = astr; -const char *p; - - T(("slk_set(%d, \"%s\", %d)", i, str, format)); - - if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2) - return(ERR); - if (str == NULL) - str = ""; - - while (isspace(*str)) str++; /* skip over leading spaces */ - p = str; - while (isprint(*p)) p++; /* The first non-print stops */ - - --i; /* Adjust numbering of labels */ - - len = (size_t)(p - str); - if (len > (unsigned)slk->maxlen) - len = slk->maxlen; - if (len==0) - slk->ent[i].text[0] = 0; - else - (void) strncpy(slk->ent[i].text, str, len); - memset(slk->ent[i].form_text,' ', (unsigned)slk->maxlen); - slk->ent[i].text[slk->maxlen] = 0; - /* len = strlen(slk->ent[i].text); */ - - switch(format) { - case 0: /* left-justified */ - memcpy(slk->ent[i].form_text, - slk->ent[i].text, - len); - break; - case 1: /* centered */ - memcpy(slk->ent[i].form_text+(slk->maxlen - len)/2, - slk->ent[i].text, - len); - break; - case 2: /* right-justified */ - memcpy(slk->ent[i].form_text+ slk->maxlen - len, - slk->ent[i].text, - len); - break; - } - slk->ent[i].form_text[slk->maxlen] = 0; - slk->ent[i].dirty = TRUE; - return(OK); -} - -/* - * Force the code to believe that the soft keys have been changed. - */ - -int -slk_touch(void) -{ - T(("slk_touch()")); - - if (SP->_slk == NULL) - return(ERR); - SP->_slk->dirty = TRUE; - return(OK); -} - -/* - * Remove soft labels from the screen. - */ - -int -slk_clear(void) -{ - T(("slk_clear()")); - - if (SP->_slk == NULL) - return(ERR); - SP->_slk->hidden = TRUE; - /* For simulated SLK's it's looks much more natural to - inherit those attributes from the standard screen */ - SP->_slk->win->_bkgd = stdscr->_bkgd; - SP->_slk->win->_attrs = stdscr->_attrs; - werase(SP->_slk->win); - return wrefresh(SP->_slk->win); -} +int _nc_slk_format; /* one more than format specified in slk_init() */ /* * Paint the info line for the PC style SLK emulation. - * + * */ - static void slk_paint_info(WINDOW *win) { if (win && _nc_slk_format==4) { int i; - + mvwhline (win,0,0,0,getmaxx(win)); wmove (win,0,0); - - for (i = 0; i < _slk->maxlab; i++) { + + for (i = 0; i < SP->_slk->maxlab; i++) { if (win && _nc_slk_format==4) { - mvwaddch(win,0,_slk->ent[i].x,'F'); + mvwaddch(win,0,SP->_slk->ent[i].x,'F'); if (i<9) waddch(win,'1'+i); else @@ -293,7 +73,6 @@ slk_paint_info(WINDOW *win) * Initialize soft labels. * Called from newterm() */ - int _nc_slk_initialize(WINDOW *stwin, int cols) { @@ -302,53 +81,53 @@ char *p; T(("slk_initialize()")); - if (_slk) + if (SP->_slk) { /* we did this already, so simply return */ - SP->_slk = _slk; return(OK); } else - if ((SP->_slk = _slk = typeCalloc(SLK, 1)) == 0) + if ((SP->_slk = typeCalloc(SLK, 1)) == 0) return(ERR); - _slk->ent = NULL; - _slk->buffer = NULL; + SP->_slk->ent = NULL; + SP->_slk->buffer = NULL; + SP->_slk->attr = A_STANDOUT; #ifdef num_labels - _slk->maxlab = (num_labels > 0) ? num_labels : MAX_SKEY; - _slk->maxlen = (num_labels > 0) ? label_width * label_height : MAX_SKEY_LEN; - _slk->labcnt = (_slk->maxlab < MAX_SKEY) ? MAX_SKEY : _slk->maxlab; + SP->_slk->maxlab = (num_labels > 0) ? num_labels : MAX_SKEY; + SP->_slk->maxlen = (num_labels > 0) ? label_width * label_height : MAX_SKEY_LEN; + SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY) ? MAX_SKEY : SP->_slk->maxlab; #else - _slk->labcnt = _slk->maxlab = MAX_SKEY; - _slk->maxlen = MAX_SKEY_LEN; + SP->_slk->labcnt = SP->_slk->maxlab = MAX_SKEY; + SP->_slk->maxlen = MAX_SKEY_LEN; #endif /* num_labels */ - _slk->ent = typeCalloc(slk_ent, _slk->labcnt); - if (_slk->ent == NULL) + SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt); + if (SP->_slk->ent == NULL) goto exception; - p = _slk->buffer = (char*) calloc(2*_slk->labcnt,(1+_slk->maxlen)); - if (_slk->buffer == NULL) + p = SP->_slk->buffer = (char*) calloc(2*SP->_slk->labcnt,(1+SP->_slk->maxlen)); + if (SP->_slk->buffer == NULL) goto exception; - for (i = 0; i < _slk->labcnt; i++) { - _slk->ent[i].text = p; - p += (1 + _slk->maxlen); - _slk->ent[i].form_text = p; - p += (1 + _slk->maxlen); - memset(_slk->ent[i].form_text, ' ', (unsigned)_slk->maxlen); - _slk->ent[i].visible = (i < _slk->maxlab); + for (i = 0; i < SP->_slk->labcnt; i++) { + SP->_slk->ent[i].text = p; + p += (1 + SP->_slk->maxlen); + SP->_slk->ent[i].form_text = p; + p += (1 + SP->_slk->maxlen); + memset(SP->_slk->ent[i].form_text, ' ', (unsigned)(SP->_slk->maxlen)); + SP->_slk->ent[i].visible = (i < SP->_slk->maxlab); } if (_nc_slk_format >= 3) /* PC style */ { - int gap = (cols - 3 * (3 + 4*_slk->maxlen))/2; + int gap = (cols - 3 * (3 + 4*SP->_slk->maxlen))/2; if (gap < 1) gap = 1; - for (i = x = 0; i < _slk->maxlab; i++) { - _slk->ent[i].x = x; - x += _slk->maxlen; + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; x += (i==3 || i==7) ? gap : 1; } if (_nc_slk_format == 4) @@ -356,26 +135,26 @@ char *p; } else { if (_nc_slk_format == 2) { /* 4-4 */ - int gap = cols - (_slk->maxlab * _slk->maxlen) - 6; + int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6; if (gap < 1) gap = 1; - for (i = x = 0; i < _slk->maxlab; i++) { - _slk->ent[i].x = x; - x += _slk->maxlen; + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; x += (i == 3) ? gap : 1; } } else { if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */ - int gap = (cols - (_slk->maxlab * _slk->maxlen) - 5) / 2; + int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5) / 2; if (gap < 1) gap = 1; - for (i = x = 0; i < _slk->maxlab; i++) { - _slk->ent[i].x = x; - x += _slk->maxlen; + for (i = x = 0; i < SP->_slk->maxlab; i++) { + SP->_slk->ent[i].x = x; + x += SP->_slk->maxlen; x += (i == 2 || i == 4) ? gap : 1; } } @@ -383,16 +162,16 @@ char *p; goto exception; } } - _slk->dirty = TRUE; - if ((_slk->win = stwin) == NULL) + SP->_slk->dirty = TRUE; + if ((SP->_slk->win = stwin) == NULL) { exception: - if (_slk) + if (SP->_slk) { - FreeIfNeeded(_slk->buffer); - FreeIfNeeded(_slk->ent); - free(_slk); - SP->_slk = _slk = (SLK*)0; + FreeIfNeeded(SP->_slk->buffer); + FreeIfNeeded(SP->_slk->ent); + free(SP->_slk); + SP->_slk = (SLK*)0; return(ERR); } } @@ -400,44 +179,21 @@ char *p; return(OK); } + /* - * Initialize soft labels. Called by the user before initscr(). + * Restore the soft labels on the screen. */ - int -slk_init(int format) -{ - if (format < 0 || format > 3) - return(ERR); - _nc_slk_format = 1 + format; - return(OK); -} - -/* Functions to manipulate the soft-label attribute */ - -int -slk_attrset(const attr_t attr) -{ - _slk_attr = attr; - return(OK); -} - -int -slk_attron(const attr_t attr) +slk_restore(void) { - toggle_attr_on(_slk_attr,attr); - return(OK); -} + T((T_CALLED("slk_restore()"))); -int -slk_attroff(const attr_t attr) -{ - toggle_attr_off(_slk_attr,attr); - return(OK); -} + if (SP->_slk == NULL) + return(ERR); + SP->_slk->hidden = FALSE; + SP->_slk->dirty = TRUE; + /* we have to repaint info line eventually */ + slk_paint_info(SP->_slk->win); -attr_t -slk_attr(void) -{ - return _slk_attr; + returnCode(slk_refresh()); } diff --git a/lib/libcurses/lib_unctrl.c b/lib/libcurses/lib_slkatrof.c index 2511ecfb0e8..7ae4cfd911b 100644 --- a/lib/libcurses/lib_unctrl.c +++ b/lib/libcurses/lib_slkatrof.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_slkatrof.c,v 1.1 1997/12/03 05:21:31 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -19,29 +21,25 @@ * * ***************************************************************************/ +/* + * lib_slkatrof.c + * Soft key routines. + * Switch off labels attributes + */ +#include <curses.priv.h> +MODULE_ID("Id: lib_slkatrof.c,v 1.2 1997/10/18 18:05:46 tom Exp $") -#include <unctrl.h> - -char *unctrl(register chtype uch) +int +slk_attroff(const attr_t attr) { - static char buffer[3] = "^x"; + T((T_CALLED("slk_attroff(%s)"), _traceattr(attr))); - if ((uch & 0x60) != 0 && uch != 0x7F) { - /* - * Printable character. Simply return the character as a one-character - * string. - */ - buffer[1] = uch; - return &buffer[1]; + if (SP!=0 && SP->_slk!=0) + { + toggle_attr_off(SP->_slk->attr,attr); + returnCode(OK); } - /* - * It is a control character. DEL is handled specially (^?). All others - * use ^x notation, where x is the character code for the control character - * with 0x40 ORed in. (Control-A becomes ^A etc.). - */ - buffer[1] = (uch == 0x7F ? '?' : (uch | 0x40)); - - return buffer; - + else + returnCode(ERR); } diff --git a/lib/libcurses/lib_slkatron.c b/lib/libcurses/lib_slkatron.c new file mode 100644 index 00000000000..26b44cdc7f2 --- /dev/null +++ b/lib/libcurses/lib_slkatron.c @@ -0,0 +1,45 @@ +/* $OpenBSD: lib_slkatron.c,v 1.1 1997/12/03 05:21:32 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkatron.c + * Soft key routines. + * Switch on labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slkatron.c,v 1.2 1997/10/18 18:06:17 tom Exp $") + +int +slk_attron(const attr_t attr) +{ + T((T_CALLED("slk_attron(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + toggle_attr_on(SP->_slk->attr,attr); + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/lib/libcurses/lib_slkatrset.c b/lib/libcurses/lib_slkatrset.c new file mode 100644 index 00000000000..aab576bd6dd --- /dev/null +++ b/lib/libcurses/lib_slkatrset.c @@ -0,0 +1,45 @@ +/* $OpenBSD: lib_slkatrset.c,v 1.1 1997/12/03 05:21:32 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkatrset.c + * Soft key routines. + * Set the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slkatrset.c,v 1.2 1997/10/18 18:06:23 tom Exp $") + +int +slk_attrset(const attr_t attr) +{ + T((T_CALLED("slk_attrset(%s)"), _traceattr(attr))); + + if (SP!=0 && SP->_slk!=0) + { + SP->_slk->attr = attr; + returnCode(OK); + } + else + returnCode(ERR); +} diff --git a/lib/libcurses/lib_slkattr.c b/lib/libcurses/lib_slkattr.c new file mode 100644 index 00000000000..4586c994adc --- /dev/null +++ b/lib/libcurses/lib_slkattr.c @@ -0,0 +1,44 @@ +/* $OpenBSD: lib_slkattr.c,v 1.1 1997/12/03 05:21:32 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkattr.c + * Soft key routines. + * Fetch the labels attributes + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slkattr.c,v 1.2 1997/10/18 18:07:45 tom Exp $") + +attr_t +slk_attr(void) +{ + T((T_CALLED("slk_attr()"))); + + if (SP!=0 && SP->_slk!=0) + { + returnAttr(SP->_slk->attr); + } + else + returnAttr(0); +} diff --git a/lib/libcurses/lib_slkclear.c b/lib/libcurses/lib_slkclear.c new file mode 100644 index 00000000000..29d5f3c7519 --- /dev/null +++ b/lib/libcurses/lib_slkclear.c @@ -0,0 +1,48 @@ +/* $OpenBSD: lib_slkclear.c,v 1.1 1997/12/03 05:21:33 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkclear.c + * Soft key routines. + * Remove soft labels from the screen. + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slkclear.c,v 1.2 1997/10/18 18:08:12 tom Exp $") + +int +slk_clear(void) +{ + T((T_CALLED("slk_clear()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->hidden = TRUE; + /* For simulated SLK's it's looks much more natural to + inherit those attributes from the standard screen */ + SP->_slk->win->_bkgd = stdscr->_bkgd; + SP->_slk->win->_attrs = stdscr->_attrs; + werase(SP->_slk->win); + + returnCode(wrefresh(SP->_slk->win)); +} diff --git a/lib/libcurses/lib_slkinit.c b/lib/libcurses/lib_slkinit.c new file mode 100644 index 00000000000..b04e683dc10 --- /dev/null +++ b/lib/libcurses/lib_slkinit.c @@ -0,0 +1,41 @@ +/* $OpenBSD: lib_slkinit.c,v 1.1 1997/12/03 05:21:33 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkinit.c + * Soft key routines. + * Initialize soft labels. Called by the user before initscr(). + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slkinit.c,v 1.2 1997/10/18 18:05:46 tom Exp $") + +int +slk_init(int format) +{ + T((T_CALLED("slk_init(%d)"), format)); + if (format < 0 || format > 3) + returnCode(ERR); + _nc_slk_format = 1 + format; + returnCode(OK); +} diff --git a/lib/libcurses/lib_slklab.c b/lib/libcurses/lib_slklab.c new file mode 100644 index 00000000000..e6b98d1908b --- /dev/null +++ b/lib/libcurses/lib_slklab.c @@ -0,0 +1,41 @@ +/* $OpenBSD: lib_slklab.c,v 1.1 1997/12/03 05:21:34 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slklab.c + * Soft key routines. + * Fetch the label text. + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slklab.c,v 1.3 1997/10/18 19:02:06 tom Exp $") + +char* +slk_label(int n) +{ + T((T_CALLED("slk_label(%d)"), n)); + + if (SP == NULL || SP->_slk == NULL || n < 1 || n > SP->_slk->labcnt) + returnPtr(0); + returnPtr(SP->_slk->ent[n-1].text); +} diff --git a/lib/libcurses/lib_slkrefr.c b/lib/libcurses/lib_slkrefr.c new file mode 100644 index 00000000000..a8827fa3f05 --- /dev/null +++ b/lib/libcurses/lib_slkrefr.c @@ -0,0 +1,116 @@ +/* $OpenBSD: lib_slkrefr.c,v 1.1 1997/12/03 05:21:34 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkrefr.c + * Write SLK window to the (virtual) screen. + */ +#include <curses.priv.h> +#include <term.h> /* num_labels, label_*, plab_norm */ + +MODULE_ID("Id: lib_slkrefr.c,v 1.3 1997/10/18 19:02:17 tom Exp $") + +/* + * Write the soft labels to the soft-key window. + */ +static void +slk_intern_refresh(SLK *slk) +{ +int i; + for (i = 0; i < slk->labcnt; i++) { + if (slk->dirty || slk->ent[i].dirty) { + if (slk->ent[i].visible) { +#ifdef num_labels + if (num_labels > 0 && SLK_STDFMT) + { + if (i < num_labels) { + TPUTS_TRACE("plab_norm"); + putp(tparm(plab_norm, i, slk->win,slk->ent[i].form_text)); + } + } + else +#endif /* num_labels */ + { + wmove(slk->win,SLK_LINES-1,slk->ent[i].x); + if (SP && SP->_slk) + wattrset(slk->win,SP->_slk->attr); + waddnstr(slk->win,slk->ent[i].form_text, MAX_SKEY_LEN); + /* if we simulate SLK's, it's looking much more + natural to use the current ATTRIBUTE also + for the label window */ + wattrset(slk->win,stdscr->_attrs); + } + } + slk->ent[i].dirty = FALSE; + } + } + slk->dirty = FALSE; + +#ifdef num_labels + if (num_labels > 0) + if (slk->hidden) + { + TPUTS_TRACE("label_off"); + putp(label_off); + } + else + { + TPUTS_TRACE("label_on"); + putp(label_on); + } +#endif /* num_labels */ +} + +/* + * Refresh the soft labels. + */ +int +slk_noutrefresh(void) +{ + T((T_CALLED("slk_noutrefresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wnoutrefresh(SP->_slk->win)); +} + +/* + * Refresh the soft labels. + */ +int +slk_refresh(void) +{ + T((T_CALLED("slk_refresh()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + if (SP->_slk->hidden) + returnCode(OK); + slk_intern_refresh(SP->_slk); + + returnCode(wrefresh(SP->_slk->win)); +} diff --git a/lib/libcurses/lib_slkset.c b/lib/libcurses/lib_slkset.c new file mode 100644 index 00000000000..b6c0a50b787 --- /dev/null +++ b/lib/libcurses/lib_slkset.c @@ -0,0 +1,85 @@ +/* $OpenBSD: lib_slkset.c,v 1.1 1997/12/03 05:21:35 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slkset.c + * Set soft label text. + */ +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("Id: lib_slkset.c,v 1.2 1997/10/18 18:09:27 tom Exp $") + +int +slk_set(int i, const char *astr, int format) +{ +SLK *slk = SP->_slk; +size_t len; +const char *str = astr; +const char *p; + + T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format)); + + if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2) + returnCode(ERR); + if (str == NULL) + str = ""; + + while (isspace(*str)) str++; /* skip over leading spaces */ + p = str; + while (isprint(*p)) p++; /* The first non-print stops */ + + --i; /* Adjust numbering of labels */ + + len = (size_t)(p - str); + if (len > (unsigned)slk->maxlen) + len = slk->maxlen; + if (len==0) + slk->ent[i].text[0] = 0; + else + (void) strncpy(slk->ent[i].text, str, len); + memset(slk->ent[i].form_text,' ', (unsigned)slk->maxlen); + slk->ent[i].text[slk->maxlen] = 0; + /* len = strlen(slk->ent[i].text); */ + + switch(format) { + case 0: /* left-justified */ + memcpy(slk->ent[i].form_text, + slk->ent[i].text, + len); + break; + case 1: /* centered */ + memcpy(slk->ent[i].form_text+(slk->maxlen - len)/2, + slk->ent[i].text, + len); + break; + case 2: /* right-justified */ + memcpy(slk->ent[i].form_text+ slk->maxlen - len, + slk->ent[i].text, + len); + break; + } + slk->ent[i].form_text[slk->maxlen] = 0; + slk->ent[i].dirty = TRUE; + returnCode(OK); +} diff --git a/lib/libcurses/lib_slktouch.c b/lib/libcurses/lib_slktouch.c new file mode 100644 index 00000000000..48e680a5324 --- /dev/null +++ b/lib/libcurses/lib_slktouch.c @@ -0,0 +1,43 @@ +/* $OpenBSD: lib_slktouch.c,v 1.1 1997/12/03 05:21:35 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* + * lib_slktouch.c + * Soft key routines. + * Force the code to believe that the soft keys have been changed. + */ +#include <curses.priv.h> + +MODULE_ID("Id: lib_slktouch.c,v 1.2 1997/10/18 18:09:53 tom Exp $") + +int +slk_touch(void) +{ + T((T_CALLED("slk_touch()"))); + + if (SP == NULL || SP->_slk == NULL) + returnCode(ERR); + SP->_slk->dirty = TRUE; + + returnCode(OK); +} diff --git a/lib/libcurses/lib_touch.c b/lib/libcurses/lib_touch.c index 3d21449edc8..18d0a14bd95 100644 --- a/lib/libcurses/lib_touch.c +++ b/lib/libcurses/lib_touch.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_touch.c,v 1.3 1997/12/03 05:21:35 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -31,14 +33,14 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_touch.c,v 1.3 1997/02/02 00:26:15 tom Exp $") +MODULE_ID("Id: lib_touch.c,v 1.4 1997/09/19 22:16:33 juergen Exp $") int is_linetouched(WINDOW *win, int line) { T((T_CALLED("is_linetouched(%p,%d)"), win, line)); /* XSI doesn't define any error */ - if (line > win->_maxy || line < 0) + if (!win || (line > win->_maxy) || (line < 0)) returnCode(ERR); returnCode(win->_line[line].firstchar != _NOCHANGE ? TRUE : FALSE); @@ -50,9 +52,10 @@ int i; T((T_CALLED("is_wintouched(%p)"), win)); - for (i = 0; i <= win->_maxy; i++) - if (win->_line[i].firstchar != _NOCHANGE) - returnCode(TRUE); + if (win) + for (i = 0; i <= win->_maxy; i++) + if (win->_line[i].firstchar != _NOCHANGE) + returnCode(TRUE); returnCode(FALSE); } @@ -62,7 +65,11 @@ int i; T((T_CALLED("wtouchln(%p,%d,%d,%d)"), win, y, n, changed)); + if (!win || (n<0) || (y<0) || (y>win->_maxy)) + returnCode(ERR); + for (i = y; i < y+n; i++) { + if (i>win->_maxy) break; win->_line[i].firstchar = changed ? 0 : _NOCHANGE; win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE; } diff --git a/lib/libcurses/lib_trace.c b/lib/libcurses/lib_trace.c index 0aa2e525a99..b38f3f5a152 100644 --- a/lib/libcurses/lib_trace.c +++ b/lib/libcurses/lib_trace.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_trace.c,v 1.2 1997/12/03 05:21:36 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -29,7 +31,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_trace.c,v 1.23 1997/05/02 00:13:07 tom Exp $") +MODULE_ID("Id: lib_trace.c,v 1.24 1997/11/30 00:47:42 tom Exp $") #include <ctype.h> #if HAVE_FCNTL_H @@ -121,6 +123,7 @@ va_list ap; bool before = FALSE; bool after = FALSE; int doit = _nc_tracing; +int save_err = errno; if (strlen(fmt) >= sizeof(Called) - 1) { if (!strncmp(fmt, Called, sizeof(Called)-1)) { @@ -155,6 +158,7 @@ int doit = _nc_tracing; if (after && level) level--; + errno = save_err; } /* Trace 'int' return-values */ diff --git a/lib/libcurses/lib_traceatr.c b/lib/libcurses/lib_traceatr.c index d477c501bad..e8497d6721a 100644 --- a/lib/libcurses/lib_traceatr.c +++ b/lib/libcurses/lib_traceatr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_traceatr.c,v 1.3 1997/12/03 05:21:36 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -32,49 +34,10 @@ #include <curses.priv.h> #include <term.h> /* acs_chars */ -MODULE_ID("Id: lib_traceatr.c,v 1.20 1997/05/06 11:07:27 tom Exp $") +MODULE_ID("Id: lib_traceatr.c,v 1.23 1997/10/18 18:21:32 tom Exp $") #define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name) -char * _nc_trace_buf(int bufnum, size_t want) -{ - static struct { - char *text; - size_t size; - } *list; - static size_t have; - - if (bufnum < 0) - bufnum = 0; - - if ((size_t)(bufnum+1) > have) { - size_t need = (bufnum + 1) * 2; - size_t used = sizeof(*list) * need; - list = (list == 0) ? malloc(used) : realloc(list, used); - if (list == 0) { - errno = ENOMEM; - return(NULL); - } - while (need > have) - list[have++].text = 0; - } - - if (list[bufnum].text == 0) - { - list[bufnum].text = malloc(want); - list[bufnum].size = want; - } - else if (want > list[bufnum].size) { - list[bufnum].text = realloc(list[bufnum].text, want); - list[bufnum].size = want; - } - if (list[bufnum].text != 0) - *(list[bufnum].text) = '\0'; - else - errno = ENOMEM; - return list[bufnum].text; -} - char *_traceattr2(int bufnum, attr_t newmode) { char *buf = _nc_trace_buf(bufnum, BUFSIZ); @@ -151,6 +114,13 @@ char *_traceattr(attr_t newmode) return _traceattr2(0, newmode); } +/* Trace 'int' return-values */ +attr_t _nc_retrace_attr_t(attr_t code) +{ + T((T_RETURN("%s"), _traceattr(code))); + return code; +} + char *_tracechtype2(int bufnum, chtype ch) { char *buf = _nc_trace_buf(bufnum, BUFSIZ); @@ -186,7 +156,7 @@ char *found = 0; {'.', "ACS_DARROW"}, /* arrow pointing down */ {'-', "ACS_UARROW"}, /* arrow pointing up */ {'h', "ACS_BOARD"}, /* board of squares */ - {'I', "ACS_LANTERN"}, /* lantern symbol */ + {'i', "ACS_LANTERN"}, /* lantern symbol */ {'0', "ACS_BLOCK"}, /* solid square block */ {'p', "ACS_S3"}, /* scan line 3 */ {'r', "ACS_S7"}, /* scan line 7 */ diff --git a/lib/libcurses/lib_tracechr.c b/lib/libcurses/lib_tracechr.c index 2a4eed712d0..bffadbbf2ae 100644 --- a/lib/libcurses/lib_tracechr.c +++ b/lib/libcurses/lib_tracechr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_tracechr.c,v 1.2 1997/12/03 05:21:36 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_tracedmp.c b/lib/libcurses/lib_tracedmp.c index d14a15c687d..2b7d9d397cf 100644 --- a/lib/libcurses/lib_tracedmp.c +++ b/lib/libcurses/lib_tracedmp.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_tracedmp.c,v 1.2 1997/12/03 05:21:37 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_tracemse.c b/lib/libcurses/lib_tracemse.c index 3cd220617f3..72bbdb7eda0 100644 --- a/lib/libcurses/lib_tracemse.c +++ b/lib/libcurses/lib_tracemse.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_tracemse.c,v 1.2 1997/12/03 05:21:37 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * diff --git a/lib/libcurses/lib_tstp.c b/lib/libcurses/lib_tstp.c index abee316c0e0..454555ce305 100644 --- a/lib/libcurses/lib_tstp.c +++ b/lib/libcurses/lib_tstp.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_tstp.c,v 1.5 1997/12/03 05:21:38 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -31,21 +33,21 @@ #include <signal.h> -#if HAVE_SIGACTION -#if !HAVE_TYPE_SIGACTION -typedef struct sigaction sigaction_t; -#endif -#else /* !HAVE_SIGACTION */ -#if HAVE_SIGVEC +#if !HAVE_SIGACTION #include <SigAction.h> -#endif +#elif !HAVE_TYPE_SIGACTION +typedef struct sigaction sigaction_t; #endif -#ifdef SVR4_ACTION +#if defined(SVR4_ACTION) && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif -MODULE_ID("Id: lib_tstp.c,v 1.8 1996/11/17 00:11:41 tom Exp $") +#ifndef SIGWINCH +#undef USE_SIGWINCH /* FIXME: configure should resolve this */ +#endif + +MODULE_ID("Id: lib_tstp.c,v 1.13 1997/11/01 19:05:13 tom Exp $") /* * Note: This code is fragile! Its problem is that different OSs @@ -110,7 +112,7 @@ static void tstp(int dummy GCC_UNUSED) */ (void)sigemptyset(&mask); (void)sigaddset(&mask, SIGALRM); -#ifdef SIGWINCH +#if USE_SIGWINCH (void)sigaddset(&mask, SIGWINCH); #endif (void)sigprocmask(SIG_BLOCK, &mask, &omask); @@ -173,18 +175,36 @@ static void cleanup(int sig) sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = SIG_IGN; - if (sigaction(sig, &act, (sigaction_t *)0) == 0) { - endwin(); - } + if (sigaction(sig, &act, (sigaction_t *)0) == 0) #else - if (signal(sig, SIG_IGN) != SIG_ERR) { + if (signal(sig, SIG_IGN) != SIG_ERR) +#endif + { + SCREEN *scan = _nc_screen_chain; + while(scan) + { + set_term(scan); endwin(); + SP->_endwin = FALSE; /* in case we have an atexit! */ + scan = scan->_next_screen; + } } -#endif } exit(EXIT_FAILURE); } +#if USE_SIGWINCH +static void sigwinch(int sig GCC_UNUSED) +{ + SCREEN *scan = _nc_screen_chain; + while(scan) + { + scan->_sig_winch = TRUE; + scan = scan->_next_screen; + } +} +#endif /* USE_SIGWINCH */ + /* * If the given signal is still in its default state, set it to the given * handler. @@ -194,11 +214,12 @@ static int CatchIfDefault(int sig, sigaction_t *act) { sigaction_t old_act; -#ifdef SA_RESTART - act->sa_flags |= SA_RESTART; -#endif /* SA_RESTART */ if (sigaction(sig, (sigaction_t *)0, &old_act) == 0 - && old_act.sa_handler == SIG_DFL) { + && (old_act.sa_handler == SIG_DFL +#if USE_SIGWINCH + || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN) +#endif + )) { (void)sigaction(sig, act, (sigaction_t *)0); return TRUE; } @@ -210,7 +231,11 @@ static int CatchIfDefault(int sig, RETSIGTYPE (*handler)()) void (*ohandler)(); ohandler = signal(sig, SIG_IGN); - if (ohandler == SIG_DFL) { + if (ohandler == SIG_DFL +#if USE_SIGWINCH + || (sig == SIGWINCH && ohandler == SIG_IGN) +#endif + ) { signal(sig, handler); return TRUE; } else { @@ -252,10 +277,14 @@ static int ignore; { sigemptyset(&act.sa_mask); act.sa_flags = 0; +#if USE_SIGWINCH + act.sa_handler = sigwinch; + CatchIfDefault(SIGWINCH, &act); +#endif + #ifdef SA_RESTART act.sa_flags |= SA_RESTART; #endif /* SA_RESTART */ - act.sa_handler = cleanup; CatchIfDefault(SIGINT, &act); CatchIfDefault(SIGTERM, &act); @@ -265,18 +294,31 @@ static int ignore; ignore = TRUE; } } -#else +#else /* !SIGTSTP */ if (enable) { #if HAVE_SIGACTION || HAVE_SIGVEC static sigaction_t act; + sigemptyset(&act.sa_mask); +#if USE_SIGWINCH + act.sa_handler = sigwinch; + CatchIfDefault(SIGWINCH, &act); +#endif +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ act.sa_handler = cleanup; CatchIfDefault(SIGINT, &act); CatchIfDefault(SIGTERM, &act); -#else + +#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ + CatchIfDefault(SIGINT, cleanup); CatchIfDefault(SIGTERM, cleanup); +#if USE_SIGWINCH + CatchIfDefault(SIGWINCH, sigwinch); #endif +#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */ } -#endif +#endif /* !SIGTSTP */ } diff --git a/lib/libcurses/lib_twait.c b/lib/libcurses/lib_twait.c index 92f29b8b748..13209d71c5b 100644 --- a/lib/libcurses/lib_twait.c +++ b/lib/libcurses/lib_twait.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_twait.c,v 1.3 1997/12/03 05:21:38 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -24,6 +26,8 @@ ** ** The routine _nc_timed_wait(). ** +** (This file was originally written by Eric Raymond; however except for +** comments, none of the original code remains - T.Dickey). */ #include <curses.priv.h> @@ -35,8 +39,7 @@ #include <sys/time.h> #endif #elif HAVE_SELECT -/* on SCO, <sys/time.h> conflicts with <sys/select.h> */ -#if HAVE_SYS_TIME_H && ! SYSTEM_LOOKS_LIKE_SCO +#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT #include <sys/time.h> #endif #if HAVE_SYS_SELECT_H @@ -44,7 +47,7 @@ #endif #endif -MODULE_ID("Id: lib_twait.c,v 1.18 1997/02/15 18:27:51 tom Exp $") +MODULE_ID("Id: lib_twait.c,v 1.26 1997/11/30 01:09:23 tom Exp $") /* * We want to define GOOD_SELECT if the last argument of select(2) is @@ -65,7 +68,7 @@ MODULE_ID("Id: lib_twait.c,v 1.18 1997/02/15 18:27:51 tom Exp $") static void _nc_gettime(struct timeval *tp) { gettimeofday(tp, (struct timezone *)0); - T(("time: %ld.%06ld", tp->tv_sec, tp->tv_usec)); + T(("time: %ld.%06ld", (long) tp->tv_sec, (long) tp->tv_usec)); } #endif #endif @@ -98,13 +101,14 @@ struct timeval tval; #endif /* !HAVE_USLEEP */ /* - * Wait a specified number of milliseconds, returning true if the timer + * Wait a specified number of milliseconds, returning nonzero if the timer * didn't expire before there is activity on the specified file descriptors. * The file-descriptors are specified by the mode: * 0 - none (absolute time) * 1 - ncurses' normal input-descriptor * 2 - mouse descriptor, if any * 3 - either input or mouse. + * We return a mask that corresponds to the mode (e.g., 2 for mouse activity). * * If the milliseconds given are -1, the wait blocks until activity on the * descriptors. @@ -142,11 +146,16 @@ long delta; T(("start twait: %lu.%06lu secs", (long) ntimeout.tv_sec, (long) ntimeout.tv_usec)); +#ifdef HIDE_EINTR /* * The do loop tries to make it look like we have restarting signals, * even if we don't. */ do { +#endif /* HIDE_EINTR */ +#if !GOOD_SELECT && HAVE_GETTIMEOFDAY + retry: +#endif count = 0; #if USE_FUNC_POLL @@ -156,12 +165,11 @@ long delta; count++; } if ((mode & 2) - && (fd = _nc_mouse_fd()) >= 0) { + && (fd = SP->_mouse_fd) >= 0) { fds[count].fd = fd; fds[count].events = POLLIN; count++; } - result = poll(fds, count, milliseconds); #elif HAVE_SELECT /* @@ -175,7 +183,7 @@ long delta; count = SP->_ifd + 1; } if ((mode & 2) - && (fd = _nc_mouse_fd()) >= 0) { + && (fd = SP->_mouse_fd) >= 0) { FD_SET(fd, &set); count = max(fd, count) + 1; } @@ -219,17 +227,20 @@ long delta; if (result == 0 && (ntimeout.tv_sec != 0 || ntimeout.tv_usec > 100000)) { napms(100); - continue; + goto retry; } #endif +#ifdef HIDE_EINTR } while (result == -1 && errno == EINTR); +#endif /* return approximate time left on the ntimeout, in milliseconds */ if (timeleft) *timeleft = (ntimeout.tv_sec * 1000) + (ntimeout.tv_usec / 1000); - T(("end twait: returned %d, remaining time %lu.%06lu secs (%d msec)", - result, (long) ntimeout.tv_sec, (long) ntimeout.tv_usec, + T(("end twait: returned %d (%d), remaining time %lu.%06lu secs (%d msec)", + result, errno, + (long) ntimeout.tv_sec, (long) ntimeout.tv_usec, timeleft ? *timeleft : -1)); /* @@ -251,7 +262,7 @@ long delta; } #elif HAVE_SELECT if ((mode & 2) - && (fd = _nc_mouse_fd()) >= 0 + && (fd = SP->_mouse_fd) >= 0 && FD_ISSET(fd, &set)) result |= 2; if ((mode & 1) diff --git a/lib/libcurses/lib_ungetch.c b/lib/libcurses/lib_ungetch.c new file mode 100644 index 00000000000..cbcebd15241 --- /dev/null +++ b/lib/libcurses/lib_ungetch.c @@ -0,0 +1,64 @@ +/* $OpenBSD: lib_ungetch.c,v 1.1 1997/12/03 05:21:39 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* +** lib_ungetch.c +** +** The routine ungetch(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("Id: lib_ungetch.c,v 1.1 1997/10/19 02:59:56 tom Exp $") + +#include <fifo_defs.h> + +#ifdef TRACE +void _nc_fifo_dump(void) +{ +int i; + T(("head = %d, tail = %d, peek = %d", head, tail, peek)); + for (i = 0; i < 10; i++) + T(("char %d = %s", i, _trace_key(SP->_fifo[i]))); +} +#endif /* TRACE */ + +int ungetch(int ch) +{ + if (tail == -1) + return ERR; + if (head == -1) { + head = 0; + t_inc() + peek = tail; /* no raw keys */ + } else + h_dec(); + + SP->_fifo[head] = ch; + T(("ungetch %#x ok", ch)); +#ifdef TRACE + if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); +#endif + return OK; +} diff --git a/lib/libcurses/lib_vidattr.c b/lib/libcurses/lib_vidattr.c index fe5041d2c6c..81e515f5672 100644 --- a/lib/libcurses/lib_vidattr.c +++ b/lib/libcurses/lib_vidattr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_vidattr.c,v 1.3 1997/12/03 05:21:39 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -52,7 +54,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("Id: lib_vidattr.c,v 1.14 1997/05/06 16:02:43 tom Exp $") +MODULE_ID("Id: lib_vidattr.c,v 1.17 1997/09/28 00:23:21 tom Exp $") #define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc) @@ -76,6 +78,10 @@ int pair, current_pair; T(("previous attribute was %s", _traceattr(previous_attr))); +#if !USE_XMC_SUPPORT + if (magic_cookie_glitch > 0) + newmode &= ~(SP->_xmc_suppress); +#endif if (newmode == previous_attr) returnCode(OK); @@ -180,9 +186,9 @@ int vidattr(attr_t newmode) returnCode(vidputs(newmode, _nc_outch)); } -attr_t termattrs(void) +chtype termattrs(void) { - int attrs = A_NORMAL; + chtype attrs = A_NORMAL; if (enter_alt_charset_mode) attrs |= A_ALTCHARSET; diff --git a/lib/libcurses/lib_vline.c b/lib/libcurses/lib_vline.c new file mode 100644 index 00000000000..eb6e5519f63 --- /dev/null +++ b/lib/libcurses/lib_vline.c @@ -0,0 +1,71 @@ +/* $OpenBSD: lib_vline.c,v 1.1 1997/12/03 05:21:40 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + + + +/* +** lib_vline.c +** +** The routine wvline(). +** +*/ + +#include <curses.priv.h> + +MODULE_ID("Id: lib_vline.c,v 1.1 1997/10/08 05:59:50 jtc Exp $") + +int wvline(WINDOW *win, chtype ch, int n) +{ +int code = ERR; +short row, col; +short end; + + T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n)); + + if (win) { + row = win->_cury; + col = win->_curx; + end = row + n - 1; + if (end > win->_maxy) + end = win->_maxy; + + if (ch == 0) + ch = ACS_VLINE; + ch = _nc_render(win, ch); + + while(end >= row) { + win->_line[end].text[col] = ch; + if (win->_line[end].firstchar == _NOCHANGE + || win->_line[end].firstchar > col) + win->_line[end].firstchar = col; + if (win->_line[end].lastchar == _NOCHANGE + || win->_line[end].lastchar < col) + win->_line[end].lastchar = col; + end--; + } + + _nc_synchook(win); + code = OK; + } + returnCode(code); +} diff --git a/lib/libcurses/lib_wattroff.c b/lib/libcurses/lib_wattroff.c new file mode 100644 index 00000000000..fa81cce4a77 --- /dev/null +++ b/lib/libcurses/lib_wattroff.c @@ -0,0 +1,45 @@ +/* $OpenBSD: lib_wattroff.c,v 1.1 1997/12/03 05:21:40 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* +** lib_wattroff.c +** +** The routine wattr_off(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("Id: lib_wattroff.c,v 1.1 1997/10/08 05:59:51 jtc Exp $") + +int wattr_off(WINDOW *win, const attr_t at) +{ + T((T_CALLED("wattr_off(%p,%s)"), win, _traceattr(at))); + if (win) { + T(("... current %s", _traceattr(win->_attrs))); + toggle_attr_off(win->_attrs,at); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/lib/libcurses/lib_wattron.c b/lib/libcurses/lib_wattron.c new file mode 100644 index 00000000000..8563d75f59f --- /dev/null +++ b/lib/libcurses/lib_wattron.c @@ -0,0 +1,45 @@ +/* $OpenBSD: lib_wattron.c,v 1.1 1997/12/03 05:21:41 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + +/* +** lib_wattron.c +** +** The routines wattr_on(). +** +*/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("Id: lib_wattron.c,v 1.1 1997/10/08 05:59:51 jtc Exp $") + +int wattr_on(WINDOW *win, const attr_t at) +{ + T((T_CALLED("wattr_on(%p,%s)"), win, _traceattr(at))); + if (win) { + T(("... current %s", _traceattr(win->_attrs))); + toggle_attr_on(win->_attrs,at); + returnCode(OK); + } else + returnCode(ERR); +} diff --git a/lib/libcurses/lib_window.c b/lib/libcurses/lib_window.c index aa4d1206893..be801afa018 100644 --- a/lib/libcurses/lib_window.c +++ b/lib/libcurses/lib_window.c @@ -1,3 +1,5 @@ +/* $OpenBSD: lib_window.c,v 1.3 1997/12/03 05:21:41 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * @@ -27,7 +29,7 @@ #include <curses.priv.h> -MODULE_ID("Id: lib_window.c,v 1.8 1997/02/02 01:14:43 tom Exp $") +MODULE_ID("Id: lib_window.c,v 1.10 1997/09/20 15:02:34 juergen Exp $") void _nc_synchook(WINDOW *win) /* hook to be called after each window change */ @@ -39,12 +41,12 @@ void _nc_synchook(WINDOW *win) int mvderwin(WINDOW *win, int y, int x) /* move a derived window */ { - WINDOW *orig = win->_parent; + WINDOW *orig; int i; T((T_CALLED("mvderwin(%p,%d,%d)"), win, y, x)); - if (orig) + if (win && (orig = win->_parent)) { if (win->_parx==x && win->_pary==y) returnCode(OK); @@ -182,9 +184,10 @@ int i; T((T_CALLED("dupwin(%p)"), win)); - if ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx)) == NULL) - returnWin(0); - + if ((win==NULL) || + ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx)) == NULL)) + returnWin(0); + nwin->_curx = win->_curx; nwin->_cury = win->_cury; nwin->_maxy = win->_maxy; @@ -193,7 +196,11 @@ int i; nwin->_begx = win->_begx; nwin->_yoffset = win->_yoffset; - nwin->_flags = win->_flags; + nwin->_flags = win->_flags & ~_SUBWIN; + /* Due to the use of newwin(), the clone is not a subwindow. + * The text is really copied into the clone. + */ + nwin->_attrs = win->_attrs; nwin->_bkgd = win->_bkgd; @@ -204,9 +211,11 @@ int i; nwin->_delay = win->_delay; nwin->_immed = win->_immed; nwin->_sync = win->_sync; - nwin->_parx = win->_parx; - nwin->_pary = win->_pary; - nwin->_parent = win->_parent; + + nwin->_parx = 0; + nwin->_pary = 0; + nwin->_parent = (WINDOW*)0; + /* See above: the clone isn't a subwindow! */ nwin->_regtop = win->_regtop; nwin->_regbottom = win->_regbottom; diff --git a/lib/libcurses/nc_alloc.h b/lib/libcurses/nc_alloc.h index 489dca19308..28d2ca2701e 100644 --- a/lib/libcurses/nc_alloc.h +++ b/lib/libcurses/nc_alloc.h @@ -1,3 +1,5 @@ +/* $OpenBSD: nc_alloc.h,v 1.2 1997/12/03 05:21:41 millert Exp $ */ + /****************************************************************************** * Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net> * * All Rights Reserved. * diff --git a/lib/libcurses/nc_panel.c b/lib/libcurses/nc_panel.c new file mode 100644 index 00000000000..5dac3602060 --- /dev/null +++ b/lib/libcurses/nc_panel.c @@ -0,0 +1,32 @@ +/* $OpenBSD: nc_panel.c,v 1.1 1997/12/03 05:21:42 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +#include <curses.priv.h> + +MODULE_ID("Id: nc_panel.c,v 1.1 1997/10/21 10:20:26 juergen Exp $") + +struct panelhook* +_nc_panelhook(void) +{ + return (SP ? &(SP->_panelHook) : NULL); +} diff --git a/lib/libcurses/nc_panel.h b/lib/libcurses/nc_panel.h new file mode 100644 index 00000000000..b75d1f88090 --- /dev/null +++ b/lib/libcurses/nc_panel.h @@ -0,0 +1,56 @@ +/* $OpenBSD: nc_panel.h,v 1.1 1997/12/03 05:21:42 millert Exp $ */ + + +/*************************************************************************** +* COPYRIGHT NOTICE * +**************************************************************************** +* ncurses is copyright (C) 1992-1995 * +* Zeyd M. Ben-Halim * +* zmbenhal@netcom.com * +* Eric S. Raymond * +* esr@snark.thyrsus.com * +* * +* Permission is hereby granted to reproduce and distribute ncurses * +* by any means and for any fee, whether alone or as part of a * +* larger distribution, in source or in binary form, PROVIDED * +* this notice is included with any such distribution, and is not * +* removed from any of its header files. Mention of ncurses in any * +* applications linked with it is highly appreciated. * +* * +* ncurses comes AS IS with no warranty, implied or expressed. * +* * +***************************************************************************/ + + +/* + * Id: nc_panel.h,v 1.1 1997/10/21 10:00:34 juergen Exp $ + * + * nc_panel.h + * + * Headerfile to provide an interface for the panel layer into + * the SCREEN structure of the ncurses core. + */ + +#ifndef NC_PANEL_H +#define NC_PANEL_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +struct panel; /* Forward Declaration */ + +struct panelhook { + struct panel* top_panel; + struct panel* bottom_panel; + struct panel* stdscr_pseudo_panel; +}; + +/* Retrieve the panelhook of the current screen */ +extern struct panelhook* _nc_panelhook(void); + +#ifdef __cplusplus +} +#endif + +#endif /* NC_PANEL_H */ diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index e465257d066..a386240cae4 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -1,9 +1,37 @@ +/* $OpenBSD: ncurses_cfg.h,v 1.2 1997/12/03 05:21:42 millert Exp $ */ + /* generated by configure-script * On host: OpenBSD xerxes.courtesan.com 2.2 XERXES#13 i386 */ #ifndef NC_CONFIG_H #define NC_CONFIG_H +/****************************************************************************** + * Copyright 1995 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. THE ABOVE LISTED * + * COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * + * EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY * + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ +/* + * This is a template-file used to generate the "ncurses_cfg.h" file. + * + * Rather than list every definition, the configuration script substitutes + * the definitions that it finds using 'sed'. + */ + #define CC_HAS_INLINE_FUNCS 1 #define GCC_NORETURN __attribute__((noreturn)) #define GCC_PRINTF 1 @@ -11,33 +39,34 @@ #define GCC_UNUSED __attribute__((unused)) #define HAVE_BUILTIN_H 1 #define HAVE_DIRENT_H 1 -#define HAVE_EXTERN_ERRNO 1 -#define HAVE_EXTERN_SYS_ERRLIST 1 #define HAVE_FCNTL_H 1 #define HAVE_FORM_H 1 #define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTTYNAM 1 #define HAVE_LIMITS_H 1 #define HAVE_LOCALE_H 1 +#define HAVE_LONG_FILE_NAMES 1 #define HAVE_MEMCCPY 1 #define HAVE_MENU_H 1 #define HAVE_NC_ALLOC_H 1 #define HAVE_PANEL_H 1 #define HAVE_POLL 1 #define HAVE_POLL_H 1 -#define HAVE_REGEX_H 1 +#define HAVE_REGEX_H_FUNCS 1 #define HAVE_SELECT 1 #define HAVE_SETBUF 1 #define HAVE_SETBUFFER 1 #define HAVE_SETVBUF 1 #define HAVE_SIGACTION 1 #define HAVE_SIGVEC 1 +#define HAVE_SIZECHANGE 1 #define HAVE_STRDUP 1 #define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_PARAM_H 1 #define HAVE_SYS_SELECT_H 1 #define HAVE_SYS_TIMES_H 1 #define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TIME_SELECT 1 #define HAVE_TCGETATTR 1 #define HAVE_TERMIOS_H 1 #define HAVE_TIMES 1 @@ -45,13 +74,18 @@ #define HAVE_TYPEINFO 1 #define HAVE_UNISTD_H 1 #define HAVE_USLEEP 1 +#define HAVE_VSNPRINTF 1 #define HAVE_VSSCANF 1 +#define NDEBUG 1 #define PURE_TERMINFO 1 #define RETSIGTYPE void #define STDC_HEADERS 1 -#define SYSTEM_NAME "OpenBSD 2.2" +#define SYSTEM_NAME "openbsd2.2" +#define TYPEOF_CHTYPE long +#define USE_DATABASE 1 +#define USE_SCROLL_HINTS 1 - /* The C compiler may not treat these properly, but C++ has to */ + /* The C compiler may not treat these properly but C++ has to */ #ifdef __cplusplus #undef const #undef inline diff --git a/lib/libcurses/resizeterm.c b/lib/libcurses/resizeterm.c index 760ce6f296d..dca4af293b0 100644 --- a/lib/libcurses/resizeterm.c +++ b/lib/libcurses/resizeterm.c @@ -1,3 +1,5 @@ +/* $OpenBSD: resizeterm.c,v 1.2 1997/12/03 05:21:43 millert Exp $ */ + /****************************************************************************** * Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net> * * All Rights Reserved. * @@ -29,7 +31,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("Id: resizeterm.c,v 1.3 1997/02/02 01:03:06 tom Exp $") +MODULE_ID("Id: resizeterm.c,v 1.5 1997/09/07 03:20:59 tom Exp $") /* * This function reallocates NCURSES window structures. It is invoked in @@ -49,10 +51,17 @@ resizeterm(int ToLines, int ToCols) ToLines, ToCols, screen_lines, screen_columns)); + SP->_sig_winch = FALSE; + if (ToLines != screen_lines || ToCols != screen_columns) { WINDOWLIST *wp; +#if USE_SIGWINCH + ungetch(KEY_RESIZE); /* so application can know this */ + clearok(curscr, TRUE); /* screen contents is unknown */ +#endif + for (wp = _nc_windows; wp != 0; wp = wp->next) { WINDOW *win = wp->win; int myLines = win->_maxy + 1; diff --git a/lib/libcurses/safe_sprintf.c b/lib/libcurses/safe_sprintf.c new file mode 100644 index 00000000000..e8cc79edb7c --- /dev/null +++ b/lib/libcurses/safe_sprintf.c @@ -0,0 +1,232 @@ +/* $OpenBSD: safe_sprintf.c,v 1.1 1997/12/03 05:21:43 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +#include <curses.priv.h> +#include <ctype.h> + +MODULE_ID("Id: safe_sprintf.c,v 1.4 1997/11/01 23:01:09 tom Exp $") + +#if USE_SAFE_SPRINTF + +typedef enum { Flags, Width, Prec, Type, Format } PRINTF; + +#define VA_INTGR(type) ival = va_arg(ap, type) +#define VA_FLOAT(type) fval = va_arg(ap, type) +#define VA_POINT(type) pval = (void *)va_arg(ap, type) + +/* + * Scan a variable-argument list for printf to determine the number of + * characters that would be emitted. + */ +static int +_nc_printf_length(const char *fmt, va_list ap) +{ + size_t length = BUFSIZ; + char *buffer; + char *format; + int len = 0; + + if (fmt == 0 || *fmt == '\0') + return -1; + if ((format = malloc(strlen(fmt)+1)) == 0) + return -1; + if ((buffer = malloc(length)) == 0) { + free(format); + return -1; + } + + while (*fmt != '\0') { + if (*fmt == '%') { + PRINTF state = Flags; + char *pval = ""; + double fval = 0.0; + int done = FALSE; + int ival = 0; + int prec = -1; + int type = 0; + int used = 0; + int width = -1; + size_t f = 0; + + format[f++] = *fmt; + while (*++fmt != '\0' && len >= 0 && !done) { + format[f++] = *fmt; + + if (isdigit(*fmt)) { + int num = *fmt - '0'; + if (state == Flags && num != 0) + state = Width; + if (state == Width) { + if (width < 0) + width = 0; + width = (width * 10) + num; + } else if (state == Prec) { + if (prec < 0) + prec = 0; + prec = (prec * 10) + num; + } + } else if (*fmt == '*') { + VA_INTGR(int); + if (state == Flags) + state = Width; + if (state == Width) { + width = ival; + } else if (state == Prec) { + prec = ival; + } + sprintf(&format[--f], "%d", ival); + f = strlen(format); + } else if (isalpha(*fmt)) { + done = TRUE; + switch (*fmt) { + case 'Z': /* FALLTHRU */ + case 'h': /* FALLTHRU */ + case 'l': /* FALLTHRU */ + case 'L': /* FALLTHRU */ + done = FALSE; + type = *fmt; + break; + case 'i': /* FALLTHRU */ + case 'd': /* FALLTHRU */ + case 'u': /* FALLTHRU */ + case 'x': /* FALLTHRU */ + case 'X': /* FALLTHRU */ + if (type == 'l') + VA_INTGR(long); + else if (type == 'Z') + VA_INTGR(size_t); + else + VA_INTGR(int); + used = 'i'; + break; + case 'f': /* FALLTHRU */ + case 'e': /* FALLTHRU */ + case 'E': /* FALLTHRU */ + case 'g': /* FALLTHRU */ + case 'G': /* FALLTHRU */ + if (type == 'L') + VA_FLOAT(long double); + else + VA_FLOAT(double); + used = 'f'; + break; + case 'c': + VA_INTGR(int); + used = 'i'; + break; + case 's': + VA_POINT(char *); + if (prec < 0) + prec = strlen(pval); + if (prec > (int)length) { + length = length + prec; + buffer = realloc(buffer, length); + if (buffer == 0) { + free(format); + return -1; + } + } + used = 'p'; + break; + case 'p': + VA_POINT(void *); + used = 'p'; + break; + case 'n': + VA_POINT(int *); + used = 0; + break; + default: + break; + } + } else if (*fmt == '.') { + state = Prec; + } else if (*fmt == '%') { + done = TRUE; + used = 'p'; + } + } + format[f] = '\0'; + switch (used) { + case 'i': + sprintf(buffer, format, ival); + break; + case 'f': + sprintf(buffer, format, fval); + break; + default: + sprintf(buffer, format, pval); + break; + } + len += (int)strlen(buffer); + } else { + fmt++; + len++; + } + } + + free(buffer); + free(format); + return len; +} +#endif + +/* + * Wrapper for vsprintf that allocates a buffer big enough to hold the result. + */ +char * +_nc_printf_string(const char *fmt, va_list ap) +{ +#if USE_SAFE_SPRINTF + char *buf = 0; + int len = _nc_printf_length(fmt, ap); + + if (len > 0) { + buf = malloc(len+1); + vsprintf(buf, fmt, ap); + } +#else + static int rows, cols; + static char *buf; + static size_t len; + + if (screen_lines > rows || screen_columns > cols) { + if (screen_lines > rows) rows = screen_lines; + if (screen_columns > cols) cols = screen_columns; + len = (rows * (cols + 1)) + 1; + if (buf == 0) + buf = malloc(len); + else + buf = realloc(buf, len); + } + + if (buf != 0) { +# if HAVE_VSNPRINTF + vsnprintf(buf, len, fmt, ap); /* GNU extension */ +# else + vsprintf(buf, fmt, ap); /* ANSI */ +# endif +#endif + } + return buf; +} diff --git a/lib/libcurses/shlib_version b/lib/libcurses/shlib_version index d9961ea9fef..890c57389b5 100644 --- a/lib/libcurses/shlib_version +++ b/lib/libcurses/shlib_version @@ -1,2 +1,2 @@ major=4 -minor=0 +minor=1 diff --git a/lib/libcurses/softscroll.c b/lib/libcurses/softscroll.c new file mode 100644 index 00000000000..87fd4ac7d11 --- /dev/null +++ b/lib/libcurses/softscroll.c @@ -0,0 +1,248 @@ +/* $OpenBSD: softscroll.c,v 1.1 1997/12/03 05:21:44 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("Id: softscroll.c,v 1.5 1997/10/18 18:38:47 tom Exp $") + +/* + * Compute indices for the given WINDOW, preparing it for scrolling. + * + * TODO (this implementation is only for proof-of-concept) + * (a) ensure that curscr's oldindex values are cached properly so we + * don't have to recompute them on each pass. + * (b) investigate if there are gains to be made by iterating newscr's + * row indices outward from the current position, rather than by + * all rows. + */ +static void compute_curscr(void) +{ + int y, x, z; + for (y = 0; y < screen_lines; y++) { + struct ldat *nline = &curscr->_line[y]; + int found = y; + for (z = 0; z < y; z++) { + int same = TRUE; + struct ldat *oline = &curscr->_line[z]; + for (x = 0; x < screen_columns; x++) { + if (nline->text[x] != oline->text[x]) { + same = FALSE; + break; + } + } + if (same) { + found = z; + break; + } + } + nline->oldindex = found; + } +} + +static void compute_newscr(void) +{ + int y, x, z; + for (y = 0; y < screen_lines; y++) { + struct ldat *nline = &newscr->_line[y]; + int found = _NEWINDEX; + for (z = 0; z < screen_lines; z++) { + int same = TRUE; + struct ldat *oline = &curscr->_line[z]; + for (x = 0; x < screen_columns; x++) { + if (nline->text[x] != oline->text[x]) { + same = FALSE; + break; + } + } + if (same) { + found = z; + break; + } + } + nline->oldindex = found; + } +} + +void +_nc_setup_scroll(void) +{ +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) { + _tracef("_nc_setup_scroll"); + _nc_linedump(); + } +#endif /* TRACE */ + compute_curscr(); + compute_newscr(); +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) { + _tracef("..._nc_setup_scroll"); + _nc_linedump(); + } +#endif +} + +#define MINDISP 2 +#define NEWNUM(n) newscr->_line[n].oldindex +#define OLDNUM(n) curscr->_line[n].oldindex + +/* + * This performs essentially the same function as _nc_scroll_optimize(), but + * uses different assumptions about the .oldindex values. More than one line + * may have the same .oldindex value. We don't assume the values are ordered. + * + * (Neither algorithm takes into account the cost of constructing the lines + * which are scrolled) + */ +void +_nc_perform_scroll(void) +{ + int disp; + int row; + int top, bottom, maxdisp; + int partial; + + /* + * Find the top/bottom lines that are different between curscr and + * newscr, limited by the terminal's ability to scroll portions of the + * screen. + * + * FIXME: this doesn't account for special cases of insert/delete line. + */ + if (change_scroll_region + && (scroll_forward || parm_index) + && (scroll_reverse || parm_rindex)) { + partial = TRUE; + for (row = 0, top = -1; row < screen_lines; row++) { + if (OLDNUM(row) != NEWNUM(row)) { + break; + } + top = row; + } + top++; + + for (row = screen_lines-1, bottom = screen_lines; row >= 0; row--) { + if (OLDNUM(row) != NEWNUM(row)) { + break; + } + bottom = row; + } + bottom--; + } else { + partial = FALSE; + top = 0; + bottom = screen_lines - 1; + } + + maxdisp = (bottom - top + 1) / 2; + if (maxdisp < MINDISP) + return; + + T(("_nc_perform_scroll %d..%d (maxdisp=%d)", top, bottom, maxdisp)); + + for (disp = 1; disp < maxdisp; disp++) { + int n; + int fn, fwd = 0; + int bn, bak = 0; + int first, last; + int moved; + + do { + /* check for forward-movement */ + for (fn = top + disp; fn < screen_lines - disp; fn++) { + int eql = 0; + for (n = fn, fwd = 0; n < screen_lines; n++) { + if (NEWNUM(n) == _NEWINDEX + || NEWNUM(n) != OLDNUM(n-disp)) + break; + fwd++; + if (OLDNUM(n) == NEWNUM(n)) + eql++; + } + if (eql == fwd) + fwd = 0; + if (fwd >= disp) + break; + fwd = 0; + } + + /* check for backward-movement */ + for (bn = top + disp; bn < screen_lines - disp; bn++) { + int eql = 0; + for (n = bn, bak = 0; n < screen_lines; n++) { + if (OLDNUM(n) == _NEWINDEX + || OLDNUM(n) != NEWNUM(n-disp)) + break; + bak++; + if (OLDNUM(n-disp) == NEWNUM(n-disp)) + eql++; + } + if (eql == bak) + bak = 0; + if (bak >= disp) + break; + bak = 0; + } + + /* choose only one, in case they overlap */ + if (fwd > bak) { + first = fn - disp; + last = fn + fwd - 1; + moved = -disp; + } else if (bak) { + first = bn - disp; + last = bn + bak - 1; + moved = disp; + } else { + break; + } + + TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", first, last, moved)); + if (_nc_scrolln(moved, first, last, screen_lines - 1) == ERR) + { + TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll")); + break; + } + + /* If the scrolled text was at one end of the range + * of changed lines, adjust the loop limits. + */ + if (first == top) + top = last + 1; + if (last == bottom) + bottom = first - 1; + + maxdisp = (bottom - top + 1) / 2; + if (maxdisp < MINDISP) + return; + + /* In any case, mark the lines so we don't try to + * use them in a subsequent scroll. + */ + for (fn = first; fn <= last; fn++) { + OLDNUM(fn) = + NEWNUM(fn) = _NEWINDEX; + } + } while (partial); + } +} diff --git a/lib/libcurses/trace_buf.c b/lib/libcurses/trace_buf.c new file mode 100644 index 00000000000..610c66bd4c9 --- /dev/null +++ b/lib/libcurses/trace_buf.c @@ -0,0 +1,77 @@ +/* $OpenBSD: trace_buf.c,v 1.1 1997/12/03 05:21:44 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. * + * * + * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR * + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ +/* + * trace_buf.c - Tracing/Debugging buffers (attributes) + */ + +#include <curses.priv.h> + +MODULE_ID("Id: trace_buf.c,v 1.2 1997/10/26 22:09:05 tom Exp $") + +char * _nc_trace_buf(int bufnum, size_t want) +{ + static struct { + char *text; + size_t size; + } *list; + static size_t have; + +#if NO_LEAKS + if (bufnum < 0) { + if (have) { + while (have--) { + free(list[have].text); + } + free(list); + } + return 0; + } +#endif + + if ((size_t)(bufnum+1) > have) { + size_t need = (bufnum + 1) * 2; + size_t used = sizeof(*list) * need; + list = (list == 0) ? malloc(used) : realloc(list, used); + if (list == 0) { + errno = ENOMEM; + return(NULL); + } + while (need > have) + list[have++].text = 0; + } + + if (list[bufnum].text == 0) + { + list[bufnum].text = malloc(want); + list[bufnum].size = want; + } + else if (want > list[bufnum].size) { + list[bufnum].text = realloc(list[bufnum].text, want); + list[bufnum].size = want; + } + if (list[bufnum].text != 0) + *(list[bufnum].text) = '\0'; + else + errno = ENOMEM; + return list[bufnum].text; +} diff --git a/lib/libcurses/tries.c b/lib/libcurses/tries.c new file mode 100644 index 00000000000..a93e59fa983 --- /dev/null +++ b/lib/libcurses/tries.c @@ -0,0 +1,174 @@ +/* $OpenBSD: tries.c,v 1.1 1997/12/03 05:21:45 millert Exp $ */ + +/****************************************************************************** + * Copyright 1997 by Thomas E. Dickey <dickey@clark.net> * + * All Rights Reserved. * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose and without fee is hereby granted, 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 the above listed copyright holder(s) * + * not be used in advertising or publicity pertaining to distribution of the * + * software without specific, written prior permission. THE ABOVE LISTED * + * COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * + * EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY * + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ******************************************************************************/ + +/* +** tries.c +** +** Functions to manage the tree of partial-completions for keycodes. +** +*/ + +#include <curses.priv.h> + +MODULE_ID("Id: tries.c,v 1.5 1997/10/26 21:55:15 tom Exp $") + +#define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0' + +void _nc_add_to_try(struct tries **tree, char *str, unsigned short code) +{ + static bool out_of_memory = FALSE; + struct tries *ptr, *savedptr; + unsigned char *txt = (unsigned char *)str; + + if (txt == 0 || out_of_memory || code == 0) + return; + + if ((*tree) != 0) { + ptr = savedptr = (*tree); + + for (;;) { + unsigned char cmp = *txt; + + while (ptr->ch != cmp + && ptr->sibling != 0) + ptr = ptr->sibling; + + if (ptr->ch == cmp) { + if (*(++txt) == '\0') { + ptr->value = code; + return; + } + if (ptr->child != 0) + ptr = ptr->child; + else + break; + } else { + if ((ptr->sibling = typeCalloc(struct tries,1)) == 0) { + out_of_memory = TRUE; + return; + } + + savedptr = ptr = ptr->sibling; + SET_TRY(ptr,txt); + ptr->value = 0; + + break; + } + } /* end for (;;) */ + } else { /* (*tree) == 0 :: First sequence to be added */ + savedptr = ptr = (*tree) = typeCalloc(struct tries,1); + + if (ptr == 0) { + out_of_memory = TRUE; + return; + } + + SET_TRY(ptr,txt); + ptr->value = 0; + } + + /* at this point, we are adding to the try. ptr->child == 0 */ + + while (*txt) { + ptr->child = typeCalloc(struct tries,1); + + ptr = ptr->child; + + if (ptr == 0) { + out_of_memory = TRUE; + + while ((ptr = savedptr) != 0) { + savedptr = ptr->child; + free(ptr); + } + + return; + } + + SET_TRY(ptr,txt); + ptr->value = 0; + } + + ptr->value = code; + return; +} + +/* + * Expand a keycode into the string that it corresponds to, returning null if + * no match was found, otherwise allocating a string of the result. + */ +char *_nc_expand_try(struct tries *tree, unsigned short code, size_t len) +{ + struct tries *ptr = tree; + char *result = 0; + + if (code != 0) { + while (ptr != 0) { + if ((result = _nc_expand_try(ptr->child, code, len + 1)) != 0) { + break; + } + if (ptr->value == code) { + result = typeCalloc(char, len+2); + break; + } + ptr = ptr->sibling; + } + } + if (result != 0) { + if ((result[len] = ptr->ch) == 0) + *((unsigned char *)(result+len)) = 128; +#ifdef TRACE + if (len == 0) + _tracef("expand_key %s %s", _trace_key(code), _nc_visbuf(result)); +#endif + } + return result; +} + +/* + * Remove a code from the specified tree, freeing the unused nodes. Returns + * true if the code was found/removed. + */ +int _nc_remove_key(struct tries **tree, unsigned short code) +{ + if (code == 0) + return FALSE; + + while (*tree != 0) { + if (_nc_remove_key(&(*tree)->child, code)) { + return TRUE; + } + if ((*tree)->value == code) { + if((*tree)->child) { + /* don't cut the whole sub-tree */ + (*tree)->value = 0; + } else { + struct tries *to_free = *tree; + *tree = (*tree)->sibling; + free(to_free); + } + return TRUE; + } + tree = &(*tree)->sibling; + } + return FALSE; +} diff --git a/lib/libcurses/unctrl.c b/lib/libcurses/unctrl.c index 93ca24252c4..4fdaf06bdf9 100644 --- a/lib/libcurses/unctrl.c +++ b/lib/libcurses/unctrl.c @@ -1,3 +1,5 @@ +/* $OpenBSD: unctrl.c,v 1.4 1997/12/03 05:21:45 millert Exp $ */ + /* generated by MKunctrl.awk */ #include <curses.priv.h> diff --git a/lib/libcurses/unctrl.h b/lib/libcurses/unctrl.h index 32554512eb9..14590cb364a 100644 --- a/lib/libcurses/unctrl.h +++ b/lib/libcurses/unctrl.h @@ -1,3 +1,5 @@ +/* $OpenBSD: unctrl.h,v 1.3 1997/12/03 05:21:45 millert Exp $ */ + /*************************************************************************** * COPYRIGHT NOTICE * **************************************************************************** @@ -24,14 +26,9 @@ * Display a printable version of a control character. * Control characters are displayed in caret notation (^x), DELETE is displayed * as ^?. Printable characters are displayed as is. - * - * The returned pointer points to a static buffer which gets overwritten by - * each call. Therefore, you must copy the resulting string to a safe place - * before calling unctrl() again. - * */ -/* Id: unctrl.h.in,v 1.5 1997/04/26 23:04:09 tom Exp $ */ +/* Id: unctrl.h.in,v 1.7 1997/09/13 23:19:40 tom Exp $ */ #ifndef _UNCTRL_H #define _UNCTRL_H 1 @@ -45,6 +42,7 @@ extern "C" { #include <curses.h> +#undef unctrl extern NCURSES_CONST char *unctrl(chtype); #ifdef __cplusplus diff --git a/lib/libcurses/wresize.3 b/lib/libcurses/wresize.3 index f95fbb733d5..9659e514716 100644 --- a/lib/libcurses/wresize.3 +++ b/lib/libcurses/wresize.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: wresize.3,v 1.2 1997/12/03 05:21:46 millert Exp $ .\"***************************************************************************** .\" Copyright 1996 by Thomas E. Dickey <dickey@clark.net> * .\" All Rights Reserved. * diff --git a/lib/libcurses/wresize.c b/lib/libcurses/wresize.c index d50ef2f2a52..bdc423d00b6 100644 --- a/lib/libcurses/wresize.c +++ b/lib/libcurses/wresize.c @@ -1,3 +1,5 @@ +/* $OpenBSD: wresize.c,v 1.3 1997/12/03 05:21:46 millert Exp $ */ + /****************************************************************************** * Copyright 1996,1997 by Thomas E. Dickey <dickey@clark.net> * * All Rights Reserved. * @@ -21,7 +23,7 @@ #include <curses.priv.h> #include <term.h> -MODULE_ID("Id: wresize.c,v 1.5 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("Id: wresize.c,v 1.8 1997/09/20 15:03:39 juergen Exp $") /* * Reallocate a curses WINDOW struct to either shrink or grow to the specified @@ -47,21 +49,24 @@ static void *doalloc(void *p, size_t n) int wresize(WINDOW *win, int ToLines, int ToCols) { - register int row; - int size_x, size_y; - struct ldat *pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0; + register int row; + int size_x, size_y; + struct ldat *pline; + chtype blank; #ifdef TRACE T((T_CALLED("wresize(%p,%d,%d)"), win, ToLines, ToCols)); - TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", - win->_begy, win->_begx, - win->_maxy, win->_maxx, - win->_regtop, win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) - _tracedump("...before", win); + if (win) { + TR(TRACE_UPDATE, ("...beg (%d, %d), max(%d,%d), reg(%d,%d)", + win->_begy, win->_begx, + win->_maxy, win->_maxx, + win->_regtop, win->_regbottom)); + if (_nc_tracing & TRACE_UPDATE) + _tracedump("...before", win); + } #endif - if (--ToLines < 0 || --ToCols < 0) + if (!win || --ToLines < 0 || --ToCols < 0) returnCode(ERR); size_x = win->_maxx; @@ -71,6 +76,8 @@ wresize(WINDOW *win, int ToLines, int ToCols) && ToCols == size_x) returnCode(OK); + pline = (win->_flags & _SUBWIN) ? win->_parent->_line : 0; + /* * If the number of lines has changed, adjust the size of the overall * vector: @@ -99,13 +106,13 @@ wresize(WINDOW *win, int ToLines, int ToCols) /* * Adjust the width of the columns: */ + blank = _nc_background(win); for (row = 0; row <= ToLines; row++) { chtype *s = win->_line[row].text; int begin = (s == 0) ? 0 : size_x + 1; int end = ToCols; - chtype blank = _nc_background(win); - win->_line[row].oldindex = row; + if_USE_SCROLL_HINTS(win->_line[row].oldindex = row); if (ToCols != size_x || s == 0) { if (! (win->_flags & _SUBWIN)) { |