diff options
-rw-r--r-- | lib/Makefile | 6 | ||||
-rw-r--r-- | lib/libcurses/MKkeyname.awk | 31 | ||||
-rw-r--r-- | lib/libcurses/MKkeys.awk | 1 | ||||
-rw-r--r-- | lib/libcurses/Makefile | 57 | ||||
-rw-r--r-- | lib/libcurses/config.h | 43 | ||||
-rw-r--r-- | lib/libcurses/curs_addch.3 | 146 | ||||
-rw-r--r-- | lib/libcurses/curs_addchstr.3 | 55 | ||||
-rw-r--r-- | lib/libcurses/curs_addstr.3 | 48 | ||||
-rw-r--r-- | lib/libcurses/curs_attr.3 | 167 | ||||
-rw-r--r-- | lib/libcurses/curs_beep.3 | 34 | ||||
-rw-r--r-- | lib/libcurses/curs_bkgd.3 | 60 | ||||
-rw-r--r-- | lib/libcurses/curs_border.3 | 71 | ||||
-rw-r--r-- | lib/libcurses/curs_clear.3 | 65 | ||||
-rw-r--r-- | lib/libcurses/curs_color.3 | 148 | ||||
-rw-r--r-- | lib/libcurses/curs_delch.3 | 39 | ||||
-rw-r--r-- | lib/libcurses/curs_deleteln.3 | 55 | ||||
-rw-r--r-- | lib/libcurses/curs_getch.3 | 203 | ||||
-rw-r--r-- | lib/libcurses/curs_getstr.3 | 66 | ||||
-rw-r--r-- | lib/libcurses/curs_getyx.3 | 43 | ||||
-rw-r--r-- | lib/libcurses/curs_inch.3 | 42 | ||||
-rw-r--r-- | lib/libcurses/curs_inchstr.3 | 55 | ||||
-rw-r--r-- | lib/libcurses/curs_initscr.3 | 87 | ||||
-rw-r--r-- | lib/libcurses/curs_inopts.3 | 183 | ||||
-rw-r--r-- | lib/libcurses/curs_insch.3 | 39 | ||||
-rw-r--r-- | lib/libcurses/curs_insstr.3 | 61 | ||||
-rw-r--r-- | lib/libcurses/curs_instr.3 | 53 | ||||
-rw-r--r-- | lib/libcurses/curs_kernel.3 | 123 | ||||
-rw-r--r-- | lib/libcurses/curs_mouse.3 | 151 | ||||
-rw-r--r-- | lib/libcurses/curs_move.3 | 34 | ||||
-rw-r--r-- | lib/libcurses/curs_outopts.3 | 134 | ||||
-rw-r--r-- | lib/libcurses/curs_overlay.3 | 46 | ||||
-rw-r--r-- | lib/libcurses/curs_pad.3 | 82 | ||||
-rw-r--r-- | lib/libcurses/curs_printw.3 | 47 | ||||
-rw-r--r-- | lib/libcurses/curs_refresh.3 | 84 | ||||
-rw-r--r-- | lib/libcurses/curs_scanw.3 | 48 | ||||
-rw-r--r-- | lib/libcurses/curs_scr_dmp.3 | 64 | ||||
-rw-r--r-- | lib/libcurses/curs_scroll.3 | 49 | ||||
-rw-r--r-- | lib/libcurses/curs_slk.3 | 91 | ||||
-rw-r--r-- | lib/libcurses/curs_termattrs.3 | 78 | ||||
-rw-r--r-- | lib/libcurses/curs_touch.3 | 64 | ||||
-rw-r--r-- | lib/libcurses/curs_util.3 | 85 | ||||
-rw-r--r-- | lib/libcurses/curs_window.3 | 123 | ||||
-rw-r--r-- | lib/libcurses/curses.3 | 805 | ||||
-rw-r--r-- | lib/libcurses/curses.h | 1509 | ||||
-rw-r--r-- | lib/libcurses/curses.priv.h | 270 | ||||
-rw-r--r-- | lib/libcurses/hardscroll.c | 420 | ||||
-rw-r--r-- | lib/libcurses/keys.list | 150 | ||||
-rw-r--r-- | lib/libcurses/lib_acs.c | 113 | ||||
-rw-r--r-- | lib/libcurses/lib_addch.c | 287 | ||||
-rw-r--r-- | lib/libcurses/lib_addstr.c | 88 | ||||
-rw-r--r-- | lib/libcurses/lib_beep.c | 79 | ||||
-rw-r--r-- | lib/libcurses/lib_bkgd.c | 41 | ||||
-rw-r--r-- | lib/libcurses/lib_box.c | 146 | ||||
-rw-r--r-- | lib/libcurses/lib_clear.c | 40 | ||||
-rw-r--r-- | lib/libcurses/lib_clrbot.c | 72 | ||||
-rw-r--r-- | lib/libcurses/lib_clreol.c | 70 | ||||
-rw-r--r-- | lib/libcurses/lib_color.c | 325 | ||||
-rw-r--r-- | lib/libcurses/lib_data.c | 64 | ||||
-rw-r--r-- | lib/libcurses/lib_delch.c | 56 | ||||
-rw-r--r-- | lib/libcurses/lib_delwin.c | 53 | ||||
-rw-r--r-- | lib/libcurses/lib_doupdate.c | 840 | ||||
-rw-r--r-- | lib/libcurses/lib_endwin.c | 55 | ||||
-rw-r--r-- | lib/libcurses/lib_erase.c | 66 | ||||
-rw-r--r-- | lib/libcurses/lib_getch.c | 329 | ||||
-rw-r--r-- | lib/libcurses/lib_getstr.c | 131 | ||||
-rw-r--r-- | lib/libcurses/lib_inchstr.c | 43 | ||||
-rw-r--r-- | lib/libcurses/lib_initscr.c | 75 | ||||
-rw-r--r-- | lib/libcurses/lib_insch.c | 54 | ||||
-rw-r--r-- | lib/libcurses/lib_insdel.c | 51 | ||||
-rw-r--r-- | lib/libcurses/lib_insstr.c | 61 | ||||
-rw-r--r-- | lib/libcurses/lib_instr.c | 44 | ||||
-rw-r--r-- | lib/libcurses/lib_isendwin.c | 37 | ||||
-rw-r--r-- | lib/libcurses/lib_kernel.c | 309 | ||||
-rw-r--r-- | lib/libcurses/lib_longname.c | 53 | ||||
-rw-r--r-- | lib/libcurses/lib_mouse.c | 580 | ||||
-rw-r--r-- | lib/libcurses/lib_move.c | 48 | ||||
-rw-r--r-- | lib/libcurses/lib_mvcur.c | 1389 | ||||
-rw-r--r-- | lib/libcurses/lib_mvwin.c | 55 | ||||
-rw-r--r-- | lib/libcurses/lib_newterm.c | 189 | ||||
-rw-r--r-- | lib/libcurses/lib_newwin.c | 193 | ||||
-rw-r--r-- | lib/libcurses/lib_options.c | 364 | ||||
-rw-r--r-- | lib/libcurses/lib_overlay.c | 135 | ||||
-rw-r--r-- | lib/libcurses/lib_pad.c | 258 | ||||
-rw-r--r-- | lib/libcurses/lib_printw.c | 93 | ||||
-rw-r--r-- | lib/libcurses/lib_raw.c | 322 | ||||
-rw-r--r-- | lib/libcurses/lib_refresh.c | 141 | ||||
-rw-r--r-- | lib/libcurses/lib_resize.c | 152 | ||||
-rw-r--r-- | lib/libcurses/lib_scanw.c | 88 | ||||
-rw-r--r-- | lib/libcurses/lib_screen.c | 171 | ||||
-rw-r--r-- | lib/libcurses/lib_scroll.c | 110 | ||||
-rw-r--r-- | lib/libcurses/lib_scrreg.c | 47 | ||||
-rw-r--r-- | lib/libcurses/lib_set_term.c | 141 | ||||
-rw-r--r-- | lib/libcurses/lib_slk.c | 328 | ||||
-rw-r--r-- | lib/libcurses/lib_touch.c | 64 | ||||
-rw-r--r-- | lib/libcurses/lib_tstp.c | 252 | ||||
-rw-r--r-- | lib/libcurses/lib_twait.c | 118 | ||||
-rw-r--r-- | lib/libcurses/lib_unctrl.c | 47 | ||||
-rw-r--r-- | lib/libcurses/lib_vidattr.c | 275 | ||||
-rw-r--r-- | lib/libcurses/lib_window.c | 173 | ||||
-rw-r--r-- | lib/libcurses/unctrl.h | 45 | ||||
-rw-r--r-- | lib/libocurses/EXAMPLES/ex1.c (renamed from lib/libcurses/EXAMPLES/ex1.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/Makefile | 24 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/Makefile (renamed from lib/libcurses/PSD.doc/Makefile) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/Master (renamed from lib/libcurses/PSD.doc/Master) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/appen.A (renamed from lib/libcurses/PSD.doc/appen.A) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/appen.B (renamed from lib/libcurses/PSD.doc/appen.B) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/appen.C (renamed from lib/libcurses/PSD.doc/appen.C) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/c_macros (renamed from lib/libcurses/PSD.doc/c_macros) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/doc.I (renamed from lib/libcurses/PSD.doc/doc.I) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/doc.II (renamed from lib/libcurses/PSD.doc/doc.II) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/doc.III (renamed from lib/libcurses/PSD.doc/doc.III) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/doc.IV (renamed from lib/libcurses/PSD.doc/doc.IV) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/ex1.c (renamed from lib/libcurses/PSD.doc/ex1.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/ex2.c (renamed from lib/libcurses/PSD.doc/ex2.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/fns.doc (renamed from lib/libcurses/PSD.doc/fns.doc) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.0 (renamed from lib/libcurses/PSD.doc/intro.0) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.1 (renamed from lib/libcurses/PSD.doc/intro.1) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.2 (renamed from lib/libcurses/PSD.doc/intro.2) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.3 (renamed from lib/libcurses/PSD.doc/intro.3) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.4 (renamed from lib/libcurses/PSD.doc/intro.4) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.5 (renamed from lib/libcurses/PSD.doc/intro.5) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/intro.6 (renamed from lib/libcurses/PSD.doc/intro.6) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/life.c (renamed from lib/libcurses/PSD.doc/life.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/macros (renamed from lib/libcurses/PSD.doc/macros) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/twinkle1.c (renamed from lib/libcurses/PSD.doc/twinkle1.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/twinkle2.c (renamed from lib/libcurses/PSD.doc/twinkle2.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/PSD.doc/win_st.c (renamed from lib/libcurses/PSD.doc/win_st.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/addbytes.c (renamed from lib/libcurses/addbytes.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/addch.c (renamed from lib/libcurses/addch.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/addnstr.c (renamed from lib/libcurses/addnstr.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/box.c (renamed from lib/libcurses/box.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/clear.c (renamed from lib/libcurses/clear.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/clrtobot.c (renamed from lib/libcurses/clrtobot.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/clrtoeol.c (renamed from lib/libcurses/clrtoeol.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/cr_put.c (renamed from lib/libcurses/cr_put.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/ctrace.c (renamed from lib/libcurses/ctrace.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/cur_hash.c (renamed from lib/libcurses/cur_hash.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/curses.c (renamed from lib/libcurses/curses.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/curses.h | 341 | ||||
-rw-r--r-- | lib/libocurses/delch.c (renamed from lib/libcurses/delch.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/deleteln.c (renamed from lib/libcurses/deleteln.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/delwin.c (renamed from lib/libcurses/delwin.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/erase.c (renamed from lib/libcurses/erase.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/fullname.c (renamed from lib/libcurses/fullname.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/getch.c (renamed from lib/libcurses/getch.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/getstr.c (renamed from lib/libcurses/getstr.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/id_subwins.c (renamed from lib/libcurses/id_subwins.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/idlok.c (renamed from lib/libcurses/idlok.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/initscr.c (renamed from lib/libcurses/initscr.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/insch.c (renamed from lib/libcurses/insch.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/insertln.c (renamed from lib/libcurses/insertln.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/longname.c (renamed from lib/libcurses/longname.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/move.c (renamed from lib/libcurses/move.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/mvwin.c (renamed from lib/libcurses/mvwin.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/newwin.c (renamed from lib/libcurses/newwin.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/ocurses.3 | 197 | ||||
-rw-r--r-- | lib/libocurses/overlay.c (renamed from lib/libcurses/overlay.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/overwrite.c (renamed from lib/libcurses/overwrite.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/printw.c (renamed from lib/libcurses/printw.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/putchar.c (renamed from lib/libcurses/putchar.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/refresh.c (renamed from lib/libcurses/refresh.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/scanw.c (renamed from lib/libcurses/scanw.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/scroll.c (renamed from lib/libcurses/scroll.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/setterm.c (renamed from lib/libcurses/setterm.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/shlib_version (renamed from lib/libcurses/shlib_version) | 0 | ||||
-rw-r--r-- | lib/libocurses/standout.c (renamed from lib/libcurses/standout.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/toucholap.c (renamed from lib/libcurses/toucholap.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/touchwin.c (renamed from lib/libcurses/touchwin.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/tscroll.c (renamed from lib/libcurses/tscroll.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/tstp.c (renamed from lib/libcurses/tstp.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/tty.c (renamed from lib/libcurses/tty.c) | 0 | ||||
-rw-r--r-- | lib/libocurses/unctrl.c (renamed from lib/libcurses/unctrl.c) | 0 |
172 files changed, 15695 insertions, 542 deletions
diff --git a/lib/Makefile b/lib/Makefile index b68bbcb6623..973fce0a6b8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 1996/05/31 05:48:53 tholo Exp $ +# $OpenBSD: Makefile,v 1.6 1996/06/02 06:04:50 tholo Exp $ # $NetBSD: Makefile,v 1.20 1996/05/12 04:30:18 mhitch Exp $ SUBDIR= csu libarch libc libcompat libcrypt libcurses libedit libl \ - libm libpcap libresolv librpcsvc libskey libtelnet libterm \ - libtermlib libutil liby + libm libocurses libpcap libresolv librpcsvc libskey libtelnet \ + libterm libtermlib libutil liby # XXX Temporarely until all ports are able to use libkvm (leo) .if (${MACHINE} == "amiga") || \ diff --git a/lib/libcurses/MKkeyname.awk b/lib/libcurses/MKkeyname.awk new file mode 100644 index 00000000000..4d03ae95e23 --- /dev/null +++ b/lib/libcurses/MKkeyname.awk @@ -0,0 +1,31 @@ + +BEGIN { + print "" + print "#include <stdlib.h>" + print "#include \"curses.h\"" + print "#include \"term.h\"" + print "" + print "struct kn {" + print "\tchar *name;" + print "\tint code;" + print "};" + print "" + print "const struct kn key_names[] = {" +} + +{printf "\t{\"%s\", %s,},\n", $1, $2;} + +END { + print "};" + print "" + print "const char *keyname(int c)" + print "{" + print "int i, size = sizeof(key_names)/sizeof(struct kn);" + print "" + print "\tfor (i = 0; i < size; i++) {" + print "\t\tif (key_names[i].code == c) return key_names[i].name;" + print "\t}" + print "\treturn NULL;" + print "}" + print "" +} diff --git a/lib/libcurses/MKkeys.awk b/lib/libcurses/MKkeys.awk new file mode 100644 index 00000000000..669c455ef54 --- /dev/null +++ b/lib/libcurses/MKkeys.awk @@ -0,0 +1 @@ +{printf "\tadd_to_try(%s, %s);\n", $1, $2;} diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 408903dbfba..3de99d58687 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,24 +1,45 @@ -# @(#)Makefile 8.2 (Berkeley) 1/2/94 +LIB= curses +SRCS= hardscroll.c lib_acs.c lib_delch.c lib_insstr.c lib_options.c \ + lib_set_term.c lib_addch.c lib_delwin.c lib_instr.c lib_overlay.c \ + lib_slk.c lib_addstr.c lib_doupdate.c lib_isendwin.c lib_pad.c \ + lib_touch.c lib_beep.c lib_endwin.c lib_kernel.c lib_printw.c \ + lib_tstp.c lib_bkgd.c lib_erase.c lib_longname.c lib_raw.c \ + lib_twait.c lib_box.c lib_getch.c lib_mouse.c lib_refresh.c \ + lib_unctrl.c lib_clear.c lib_getstr.c lib_move.c lib_resize.c \ + lib_vidattr.c lib_clrbot.c lib_inchstr.c lib_mvcur.c lib_scanw.c \ + lib_window.c lib_clreol.c lib_initscr.c lib_mvwin.c lib_screen.c \ + lib_color.c lib_insch.c lib_newterm.c lib_scroll.c lib_data.c \ + lib_insdel.c lib_keyname.c lib_newwin.c lib_scrreg.c +CFLAGS+= -I. -I${.CURDIR} -DTERMIOS -DEXTERN_TERMINFO +LDADD+= -ltermlib +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 \ + curs_inchstr.3 curs_initscr.3 curs_inopts.3 curs_insch.3 curs_insstr.3 \ + curs_instr.3 curs_kernel.3 curs_mouse.3 curs_move.3 curs_outopts.3 \ + curs_overlay.3 curs_pad.3 curs_printw.3 curs_refresh.3 curs_scanw.3 \ + curs_scr_dmp.3 curs_scroll.3 curs_slk.3 curs_termattrs.3 curs_touch.3 \ + curs_util.3 curs_window.3 curses.3 +MLINKS+=curses.3 ncurses.3 +CLEANFILES+= lib_keyname.c keys.tries -CFLAGS+=#-DTFILE=\"/dev/ttyp0\" -CFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR} -LIB= curses -SRCS= addbytes.c addch.c addnstr.c box.c clear.c clrtobot.c clrtoeol.c \ - cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c delwin.c \ - erase.c fullname.c getch.c getstr.c id_subwins.c idlok.c initscr.c \ - insch.c insertln.c longname.c move.c mvwin.c newwin.c overlay.c \ - overwrite.c printw.c putchar.c refresh.c scanw.c scroll.c setterm.c \ - standout.c toucholap.c touchwin.c tscroll.c tstp.c tty.c unctrl.c -MAN= curses.3 +beforedepend: keys.tries includes: - -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/curses.h > \ - /dev/null 2>&1 || \ - install -c -o ${BINOWN} -g ${BINGRP} -m 444 curses.h \ - ${DESTDIR}/usr/include + @cd ${.CURDIR}; for i in unctrl.h; do \ + cmp -s $$i ${DESTDIR}/usr/include/$$i || \ + install -c -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ + ${DESTDIR}/usr/include; done + @cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/curses.h || \ + install -c -m 444 -o $(BINOWN) -g $(BINGRP) curses.h \ + ${DESTDIR}/usr/include -.if make(install) -SUBDIR+= PSD.doc -.endif +keys.tries: ${.CURDIR}/keys.list ${.CURDIR}/MKkeys.awk + awk -f ${.CURDIR}/MKkeys.awk ${.CURDIR}/keys.list > keys.tries + +lib_keyname.c: ${.CURDIR}/keys.list ${.CURDIR}/MKkeyname.awk + awk -f ${.CURDIR}/MKkeyname.awk ${.CURDIR}/keys.list > lib_keyname.c .include <bsd.lib.mk> + +lib_options.o lib_options.so lib_options.po lib_options.ln: keys.tries diff --git a/lib/libcurses/config.h b/lib/libcurses/config.h new file mode 100644 index 00000000000..e9b3a016aa9 --- /dev/null +++ b/lib/libcurses/config.h @@ -0,0 +1,43 @@ +/* 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.3 b/lib/libcurses/curs_addch.3 new file mode 100644 index 00000000000..e32eba1ef1b --- /dev/null +++ b/lib/libcurses/curs_addch.3 @@ -0,0 +1,146 @@ +'\" t +.TH curs_addch 3X "" +.SH NAME +\fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, +\fBechochar\fR, \fBwechochar\fR - add a character (with attributes) to a +\fBcurses\fR window, then advance the cursor +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint addch(chtype ch);\fR +.br +\fBint waddch(WINDOW *win, chtype ch);\fR +.br +\fBint mvaddch(int y, int x, chtype ch);\fR +.br +\fBint mvwaddch(WINDOW *win, int y, int x, chtype ch);\fR +.br +\fBint echochar(chtype ch);\fR +.br +\fBint wechochar(WINDOW *win, chtype ch);\fR +.br +.SH DESCRIPTION +The \fBaddch\fR, \fBwaddch\fR, \fBmvaddch\fR and \fBmvwaddch\fR routines put +the character \fIch\fR into the given window at its current window position, +which is then advanced. They are analogous to \fBputchar\fR in \fBstdio\fR(3). +If the advance is at the right margin, the cursor automatically wraps to the +beginning of the next line. At the bottom of the current scrolling region, if +\fBscrollok\fR is enabled, the scrolling region is scrolled up one line. + +If \fIch\fR is a tab, newline, or backspace, the cursor is moved appropriately +within the window. Backspace moves the cursor one character left; at the left +edge of a window it does nothing. Newline does a \fBclrtoeol\fR, then moves +the cursor to the window left margin on the next line, scrolling the window if +on the last line). Tabs are considered to be at every eighth column. + +If \fIch\fR is any control character other than tab, newline, or backspace, it +is drawn in \fB^\fR\fIX\fR notation. Calling \fBwinch\fR after adding a +control character does not return the character itself, but instead returns +the ^-representation of the control character. (To emit control characters +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 +values of predefined video attribute constants that can be usefully ORed +into characters. + +The \fBechochar\fR and \fBwechochar\fR routines are equivalent to a call to +\fBaddch\fR followed by a call to \fBrefresh\fR, or a call to \fBwaddch\fR +followed by a call to \fBwrefresh\fR. The knowledge that only a single +character is being output is used and, for non-control characters, a +considerable performance gain may be seen by using these routines instead of +their equivalents. +.SS Line Graphics +The following variables may be used to add line drawing characters to the +screen with routines of the \fBaddch\fR family. The default character listed +below is used if the \fBacsc\fR capability doesn't define a terminal-specific +replacement for it (but see the EXTENSIONS section below). The names are +taken from VT100 nomenclature. + +.TS +l l l +_ _ _ +l l l. +\fIName\fR \fIDefault\fR \fIDescription\fR +ACS_ULCORNER + upper left-hand corner +ACS_LLCORNER + lower left-hand corner +ACS_URCORNER + upper right-hand corner +ACS_LRCORNER + lower right-hand corner +ACS_RTEE + right tee +ACS_LTEE + left tee +ACS_BTEE + bottom tee +ACS_TTEE + top tee +ACS_HLINE - horizontal line +ACS_VLINE | vertical line +ACS_PLUS + plus +ACS_S1 - scan line 1 +ACS_S9 \&_ scan line 9 +ACS_DIAMOND + diamond +ACS_CKBOARD : checker board (stipple) +ACS_DEGREE ' degree symbol +ACS_PLMINUS # plus/minus +ACS_BULLET o bullet +ACS_LARROW < arrow pointing left +ACS_RARROW > arrow pointing right +ACS_DARROW v arrow pointing down +ACS_UARROW ^ arrow pointing up +ACS_BOARD # board of squares +ACS_LANTERN # lantern symbol +ACS_BLOCK # solid square block +ACS_S3 - scan line 3 +ACS_S7 - scan line 7 +ACS_LEQUAL < less-than-or-equal-to +ACS_GEQUAL > greater-than-or-equal-to +ACS_PI * greek pi +ACS_NEQUAL ! not-equal +ACS_STERLING f pound-sterling symbol +.TE + +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success +(the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon +successful completion, unless otherwise noted in the preceding routine +descriptions. +.SH NOTES +Note that \fBaddch\fR, \fBmvaddch\fR, \fBmvwaddch\fR, and +\fBechochar\fR may be macros. +.SH EXTENSIONS +The following extended \fBcurses\fR features are available only on PC-clone +consoles and compatible terminals obeying the ANSI.SYS de-facto standard for +terminal control sequences. They are not part of XSI curses. + +The attribute A_ALTCHARSET actually forces literal display of PC ROM characters +including the high-half graphics. Your console driver may still capture or +translate a few (such as ESC) but this feature should give you access to the +card-suit characters, up and down-arrow, and most others in the range 0-32. +(In a terminfo entry designed for use with \fBncurses\fR, the high-half +characters are obtained using this attribute with an \fBacsc\fR string in +which the second of each pair is a high-half character.) + +Giving \fBwechochar\fR an argument with its high bit set will produce the +corresponding high-half ASCII graphic (SVr4 curses also has this feature but +does not document it). A control-character argument, however, will not +typically produce the corresponding graphic; characters such as CR, NL, FF and +TAB are typically interpreted by the console driver itself, and ESC will be +interpreted as the leader of a control sequence. +.SH PORTABILITY +All these functions are described in the XSI Curses standard, Issue 4. +The defaults specified for forms-drawing characters apply in the POSIX locale. + +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 \fBncurses\fR(3X). +.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), +\fBputc\fR(3S). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_addchstr.3 b/lib/libcurses/curs_addchstr.3 new file mode 100644 index 00000000000..fd5600dd2e1 --- /dev/null +++ b/lib/libcurses/curs_addchstr.3 @@ -0,0 +1,55 @@ +.TH curs_addchstr 3X "" +.SH NAME +\fBaddchstr\fR, \fBaddchnstr\fR, \fBwaddchstr\fR, +\fBwaddchnstr\fR, \fBmvaddchstr\fR, \fBmvaddchnstr\fR, \fBmvwaddchstr\fR, +\fBmvwaddchnstr\fR - add a string of characters (and attributes) to a +\fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint addchstr(const chtype *chstr);\fR +.br +\fBint addchnstr(const chtype *chstr, int n);\fR +.br +\fBint waddchstr(WINDOW *win, const chtype *chstr);\fR +.br +\fBint waddchnstr(WINDOW *win, const chtype *chstr, int n);\fR +.br +\fBint mvaddchstr(int y, int x, const chtype *chstr);\fR +.br +\fBint mvaddchnstr(int y, int x, const chtype *chstr, int n);\fR +.br +\fBint mvwaddchstr(WINDOW *win, int y, int x, const chtype *chstr);\fR +.br +\fBint mvwaddchnstr(WINDOW *win, int y, int x, const chtype *chstr, int n);\fR +.SH DESCRIPTION +These routines copy \fIchstr\fR into the window image structure at and after +the current cursor position. The four routines with \fIn\fR as the last +argument copy at most \fIn\fR elements, but no more than will fit on the line. +If \fBn\fR=\fB-1\fR then the whole string is copied, to the maximum number of +characters that will fit on the line. + +The window cursor is \fInot\fR advanced, and these routines work faster than +\fBwaddnstr\fR. On the other hand, they don't perform any kind of checking +(such as for the newline, backspace, or carriage return characters), they don't +advance the current cursor position, they don't expand other control characters +to ^-escapes, and they truncate the string if it crosses the right margin, +rather then wrapping it around to the new line. + +.SH RETURN VALUES +All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success +(the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon +successful completion, unless otherwise noted in the preceding routine +descriptions. +.SH NOTES +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_addstr.3 b/lib/libcurses/curs_addstr.3 new file mode 100644 index 00000000000..3859a34b8b4 --- /dev/null +++ b/lib/libcurses/curs_addstr.3 @@ -0,0 +1,48 @@ +.TH curs_addstr 3X "" +.SH NAME +\fBaddstr\fR, \fBaddnstr\fR, \fBwaddstr\fR, \fBwaddnstr\fR, +\fBmvaddstr\fR, \fBmvaddnstr\fR, \fBmvwaddstr\fR, \fBmvwaddnstr\fR - add a +string of characters to a \fBcurses\fR window and advance cursor +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint addstr(const char *str);\fR +.br +\fBint addnstr(const char *str, int n);\fR +.br +\fBint waddstr(WINDOW *win, const char *str);\fR +.br +\fBint waddnstr(WINDOW *win, const char *str, int n);\fR +.br +\fBint mvaddstr(int y, int x, const char *str);\fR +.br +\fBint mvaddnstr(int y, int x, const char *str, int n);\fR +.br +\fBint mvwaddstr(WINDOW *win, int y, int x, const char *str);\fR +.br +\fBint mvwaddnstr(WINDOW *win, int y, int x, const char *str, int n);\fR +.SH DESCRIPTION +These routines write the characters of the (null-terminated) character string +\fIstr\fR on the given window. It is similar to calling \fBwaddch\fR once for +each character in the string. The four routines with \fIn\fR as the last +argument write at most \fIn\fR characters. If \fIn\fR is -1, then the +entire string will be added. +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and \fBOK\fR on success +(the SVr4 manuals specify only "an integer value other than \fBERR\fR") upon +successful completion. +.SH NOTES +Note that all of these routines except \fBwaddstr\fR and \fBwaddnstr\fR may be +macros. +.SH PORTABILITY +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_attr.3 b/lib/libcurses/curs_attr.3 new file mode 100644 index 00000000000..d08df520173 --- /dev/null +++ b/lib/libcurses/curs_attr.3 @@ -0,0 +1,167 @@ +.TH curs_attr 3X "" +.SH NAME +\fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, +\fBattrset\fR, \fBwattrset\fR, \fBstandend\fR, \fBwstandend\fR, \fBstandout\fR, +\fBwstandout\fR - \fBcurses\fR character and window attribute control routines +.SH SYNOPSIS +\fB#include <curses.h>\fR +.br +\fBint attroff(int attrs);\fR +.br +\fBint wattroff(WINDOW *win, int attrs);\fR +.br +\fBint attron(int attrs);\fR +.br +\fBint wattron(WINDOW *win, int attrs);\fR +.br +\fBint attrset(int attrs);\fR +.br +\fBint wattrset(WINDOW *win, int attrs);\fR +.br +\fBint standend(void);\fR +.br +\fBint wstandend(WINDOW *win);\fR +.br +\fBint standout(void);\fR +.br +\fBint wstandout(WINDOW *win);\fR +.br +\fBattr_t attr_get(void);\fR +.br +\fBattr_t wattr_get(WINDOW *);\fR +.br +\fBint attr_off(attr_t attrs);\fR +.br +\fBint wattr_off(WINDOW *, attr_t attrs);\fR +.br +\fBint attr_on(attr_t attrs);\fR +.br +\fBint wattr_on(WINDOW *, attr_t attrs);\fR +.br +\fBint attr_set(attr_t attrs);\fR +.br +\fBint wattr_set(WINDOW *, attr_t attrs);\fR +.br +\fBint chgat(int n, attr_t attr, short color, const void *opts)\fR +.br +\fBint wchgat(WINDOW *, int n, attr_t attr, + short color, const void *opts)\fR +.br +\fBint mvchgat(int y, int x, int n, attr_t attr, + short color, const void *opts)\fR +.br +\fBint mvwchgat(WINDOW *, int y, int x, int n, attr_t attr, + short color, const void *opts)\fR +.br +.SH DESCRIPTION +These routines manipulate the current attributes of the named window. The +current attributes of a window apply to all characters that are written into +the window with \fBwaddch\fR, \fBwaddstr\fR and \fBwprintw\fR. Attributes are +a property of the character, and move with the character through any scrolling +and insert/delete line/character operations. To the extent possible, they are +displayed as appropriate modifications to the graphic rendition of characters +put on the screen. + +The routine \fBattrset\fR sets the current attributes of the given window to +\fIattrs\fR. The routine \fBattroff\fR turns off the named attributes without +turning any other attributes on or off. The routine \fBattron\fR turns on the +named attributes without affecting any others. The routine \fBstandout\fR is +the same as \fBattron(A_STANDOUT)\fR. The routine \fBstandend\fR is the same +as \fBattrset(A_NORMAL)\fR or \fBattrset(0)\fR, that is, it turns off all +attributes. + +The routine \fBwattr_get\fR returns the current attribute for the given +window; \fBattr_get\fR returns the current attribute for \fBstdscr\fR. +The remaining \fBattr_\fR* functions operate exactly like the corresponding +\fBattr\fR* functions, except that they take arguments of type \fBattr_t\fR +rather than \fBint\fR. + +The routine \fBchgat\fR changes the attributes of a given number of characters +starting at the current cursor location of \fBstdscr\fR. It does not update +the cursor and does not perform wrapping. A character count of -1 or greater +than the remaining window width means to change attributes all the way to the +end of the current line. The \fBwchgat\fR function generalizes this to any +window; the \fBmvwchgat\fR function does a cursor move before acting. In these +functions, the color argument is a color-pair index (as in the first argument +of \fIinit_pair\fR, see \fBcurs_color\fR(3x)). The \fBopts\fR argument is not +presently used, but is reserved for the future (leave it \fBNULL\fR). +.SS Attributes +The following video attributes, defined in \fB<curses.h>\fR, can be passed to +the routines \fBattron\fR, \fBattroff\fR, and \fBattrset\fR, or OR-ed with the +characters passed to \fBaddch\fR. + +.nf +\fBA_NORMAL\fR Normal display (no highlight) +\fBA_STANDOUT\fR Best highlighting mode of the terminal. +\fBA_UNDERLINE\fR Underlining +\fBA_REVERSE\fR Reverse video +\fBA_BLINK\fR Blinking +\fBA_DIM\fR Half bright +\fBA_BOLD\fR Extra bright or bold +\fBA_PROTECT\fR Protected mode +\fBA_INVIS\fR Invisible or blank mode +\fBA_ALTCHARSET\fR Alternate character set +\fBA_CHARTEXT\fR Bit-mask to extract a character +\fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR Color-pair number \fIn\fR +.fi + +The following macro is the reverse of \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR: + +.DS C +\fBPAIR_NUMBER(\fIattrs\fR) Returns the pair number associated + with the \fBCOLOR_PAIR(\fR\fIn\fR\fB)\fR attribute. +.DE + +The return values of many of these routines are not meaningful (they are +implemented as macro-expanded assignments and simply return their argument). +The SVr4 manual page claims (falsely) that these routines always return \fB1\fR. + +.SH NOTES +Note that \fBattroff\fR, \fBwattroff\fR, \fBattron\fR, \fBwattron\fR, +\fBattrset\fR, \fBwattrset\fR, \fBstandend\fR and \fBstandout\fR may be macros. +.SH PORTABILITY +All these functions are supported in the XSI Curses standard, Issue 4. The +standard defined the dedicated type for highlights, \fBattr_t\fR, which is not +defined in SVr4 curses. The functions taking \fBattr_t\fR arguments are +not supported under SVr4. + +The XSI Curses standard states that whether the traditional functions +\fBattron\fR/\fBattroff\fR/\fBattrset\fR can manipulate attributes other than +\fBA_BLINK\fR, \fBA_BOLD\fR, \fBA_DIM\fR, \fBA_REVERSE\fR, \fBA_STANDOUT\fR, or +\fBA_UNDERLINE\fR is "unspecified". Under this implementation as well as +SVr4 curses, these functions correctly manipulate all other highlights +(specifically, \fBA_ALTCHARSET\fR, \fBA_PROTECT\fR, and \fBA_INVIS\fR). + +XSI Curses added the new entry points, \fBattr_get\fR, \fBattr_on\fR, +\fBattr_off\fR, \fBattr_set\fR, \fBwattr_on\fR, \fBwattr_off\fR, +\fBwattr_get\fR, \fBwattr_set\fR. These are intended to work with +a new series of highlight macros prefixed with \fBWA_\fR. + +.nf +\fBWA_NORMAL\fR Normal display (no highlight) +\fBWA_STANDOUT\fR Best highlighting mode of the terminal. +\fBWA_UNDERLINE\fR Underlining +\fBWA_REVERSE\fR Reverse video +\fBWA_BLINK\fR Blinking +\fBWA_DIM\fR Half bright +\fBWA_BOLD\fR Extra bright or bold +\fBWA_ALTCHARSET\fR Alternate character set +.fi + +The XSI curses standard specifies that each pair of corresponding \fBA_\fR +and \fBWA_\fR-using functions operates on the same current-highlight +information. + +The XSI standard extended conformance level adds new highlights +\fBA_HORIZONTAL\fR, \fBA_LEFT\fR, \fBA_LOW\fR, \fBA_RIGHT\fR, \fBA_TOP\fR, +\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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_beep.3 b/lib/libcurses/curs_beep.3 new file mode 100644 index 00000000000..140f255c762 --- /dev/null +++ b/lib/libcurses/curs_beep.3 @@ -0,0 +1,34 @@ +.TH curs_beep 3X "" +.SH NAME +\fBbeep\fR, \fBflash\fR - \fBcurses\fR bell and screen flash routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint beep(void);\fR +.br +\fBint flash(void);\fR +.br +.SH DESCRIPTION +The \fBbeep\fR and \fBflash\fR routines are used to alert the terminal user. +The routine \fBbeep\fR sounds an audible alarm on the terminal, if possible; +otherwise it flashes the screen (visible bell). The routine \fBflash\fR +flashes the screen, and if that is not possible, sounds the alert. If neither +alert is possible, nothing happens. Nearly all terminals have an audible alert +(bell or beep), but only some can flash the screen. +.SH RETURN VALUE +These routines return \fBOK\fR if they succeed in beeping or flashing, +\fBERR\fR otherwise. +.SH EXTENSIONS +SVr4's beep and flash routines always returned \fBOK\fR, so it was not +possible to tell when the beep or flash failed. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_bkgd.3 b/lib/libcurses/curs_bkgd.3 new file mode 100644 index 00000000000..cc3372c8e47 --- /dev/null +++ b/lib/libcurses/curs_bkgd.3 @@ -0,0 +1,60 @@ +.TH curs_bkgd 3X "" +.SH NAME +\fBbkgdset\fR, \fBwbkgdset\fR, \fBbkgd\fR, +\fBwbkgd\fR - \fBcurses\fR window background manipulation routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBvoid bkgdset(const chtype ch);\fR +.br +\fBvoid wbkgdset(WINDOW *win, const chtype ch);\fR +.br +\fBint bkgd(const chtype ch);\fR +.br +\fBint wbkgd(WINDOW *win, const chtype ch);\fR +.br +\fBchtype wgetbkgd(WINDOW *win);\fR +.br +.SH DESCRIPTION +The \fBbkgdset\fR and \fBwbkgdset\fR routines manipulate the +background of the named window. Background is a \fBchtype\fR +consisting of any combination of attributes and a character. The +attribute part of the background is combined (ORed) with all non-blank +characters that are written into the window with \fBwaddch\fR. Both +the character and attribute parts of the background are combined with +the blank characters. The background becomes a property of the +character and moves with the character through any scrolling and +insert/delete line/character operations. To the extent possible on a +particular terminal, the attribute part of the background is displayed +as the graphic rendition of the character put on the screen. + +The \fBbkgd\fR and \fBwbkgd\fR routines combine the new background +with every position in the window. Background is any combination of +attributes and a character. Only the attribute part is used to set +the background of non-blank characters, while both character and +attributes are used for blank positions. To the extent possible on a +particular terminal, the attribute part of the background is displayed +as the graphic rendition of the character put on the screen. + +The \fBwgetbkgd\fR function returns the given window's current background +character/attribute pair. +.SH RETURN VALUE +The routines \fBbkgd\fR and \fBwbkgd\fR return the integer \fBOK\fR. +The SVr4.0 manual says "or a non-negative integer if \fBimmedok\fR is set", +but this appears to be an error. +.SH NOTES +Note that \fBbkgdset\fR and \fBbkgd\fR may be macros. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. The draft +does not include \fBconst\fR qualifiers on the arguments. The standard +specifies that \fBbkgd\fR and \fBwbkgd\fR return \fBERR\fR, on failure. but +gives no failure conditions. The draft describes the new function +\fBwgetbkgd\fR, which is not in SVr4. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_addch\fR(3X), \fBcurs_outopts\fR(3X) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_border.3 b/lib/libcurses/curs_border.3 new file mode 100644 index 00000000000..c3d845acfc8 --- /dev/null +++ b/lib/libcurses/curs_border.3 @@ -0,0 +1,71 @@ +.TH curs_border 3X "" +.SH NAME +\fBborder\fR, \fBwborder\fR, \fBbox\fR, +\fBhline\fR, \fBwhline\fR, \fBvline\fR, \fBwvline\fR - create +\fBcurses\fR borders, horizontal and vertical lines +.SH SYNOPSIS +\fB#include <curses.h>\fR +.br +\fBint border(chtype ls, chtype rs, chtype ts, chtype bs, + chtype tl, chtype tr, chtype bl, chtype br);\fR +.br +\fBint wborder(WINDOW *win, chtype ls, chtype rs, + chtype ts, chtype bs, chtype tl, chtype tr, + chtype bl, chtype br);\fR +.br +\fBint box(WINDOW *win, chtype verch, chtype horch);\fR +.br +\fBint hline(chtype ch, int n);\fR +.br +\fBint whline(WINDOW *win, chtype ch, int n);\fR +.br +\fBint vline(chtype ch, int n);\fR +.br +\fBint wvline(WINDOW *win, chtype ch, int n);\fR +.br +.SH DESCRIPTION +The \fBborder\fR, \fBwborder\fR and \fBbox\fR routines draw a box around the +edges of a window. The argument \fIls\fR is a character and attributes used +for the left side of the border, \fIrs\fR - right side, \fIts\fR - top side, +\fIbs\fR - bottom side, \fItl\fR - top left-hand corner, \fItr\fR - top +right-hand corner, \fIbl\fR - bottom left-hand corner, and \fIbr\fR - bottom +right-hand corner. If any of these arguments is zero, then the following +default values (defined in \fBcurses.h\fR) are used instead: \fBACS_VLINE\fR, +\fBACS_VLINE\fR, \fBACS_HLINE\fR, \fBACS_HLINE\fR, \fB\fBACS_ULCORNER\fR, +\fBACS_URCORNER\fR, \fBACS_BLCORNER\fR, \fBACS_BRCORNER\fR. + +\fBbox(\fR\fIwin\fR\gB, \fR\fIverch\fR\fB, \fR\fIhorch\fR\fB)\fR is a shorthand +for the following call: \fBwborder(\fR\fIwin\fR\fB,\fR \fIverch\fR\fB,\fR +\fIverch\fR\fB,\fR \fIhorch\fR\fB,\fR \fIhorch\fR\fB, 0, 0, 0, 0)\fR. + +The \fBhline\fR and \fBwhline\fR functions draw a horizontal (left to right) +line using \fIch\fR starting at the current cursor position in the window. The +current cursor position is not changed. The line is at most \fIn\fR characters +long, or as many as fit into the window. + +The \fBvline\fR and \fBwvline\fR functions draw a vertical (top to bottom) line +using \fIch\fR starting at the current cursor position in the window. The +current cursor position is not changed. The line is at most \fIn\fR characters +long, or as many as fit into the window. +.SH RETURN VALUE +All routines return the integer \fBOK\fR. The SVr4.0 manual says "or a +non-negative integer if \fBimmedok\fR is set", but this appears to be an error. +.SH NOTES +The borders generated by these functions are \fIinside\fR borders (this +is also true of SVr4 curses, though the fact is not documented). + +Note that \fBborder\fR and \fBbox\fR may be macros. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. Additional +functions \fBmvhline\fR, \fBmvvline\fR, \fBmvwhline\fR, and \fBmvwvline\fR are +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_clear.3 b/lib/libcurses/curs_clear.3 new file mode 100644 index 00000000000..1a9efb7ce15 --- /dev/null +++ b/lib/libcurses/curs_clear.3 @@ -0,0 +1,65 @@ +.TH curs_clear 3X "" +.SH NAME +\fBerase\fR, \fBwerase\fR, \fBclear\fR, +\fBwclear\fR, \fBclrtobot\fR, \fBwclrtobot\fR, \fBclrtoeol\fR, +\fBwclrtoeol\fR - clear all or part of a \fBcurses\fR window +.SH SYNOPSIS +\fB# include <curses.h>\fR + +\fBint erase(void);\fR +.br +\fBint werase(WINDOW *win);\fR +.br +\fBint clear(void);\fR +.br +\fBint wclear(WINDOW *win);\fR +.br +\fBint clrtobot(void);\fR +.br +\fBint wclrtobot(WINDOW *win);\fR +.br +\fBint clrtoeol(void);\fR +.br +\fBint wclrtoeol(WINDOW *win);\fR +.br +.SH DESCRIPTION +The \fBerase\fR and \fBwerase\fR routines copy blanks to every +position in the window, clearing the screen. + +The \fBclear\fR and \fBwclear\fR routines are like \fBerase\fR and +\fBwerase\fR, but they also call \fBclearok\fR, so that the screen is +cleared completely on the next call to \fBwrefresh\fR for that window +and repainted from scratch. + +The \fBclrtobot\fR and \fBwclrtobot\fR routines erase from the cursor to the +end of screen. That is, they erase all lines below the cursor in the window. +Also, the current line to the right of the cursor, inclusive, is erased. + +The \fBclrtoeol\fR and \fBwclrtoeol\fR routines erase the current line +to the right of the cursor, inclusive, to the end of the current line. + +Blanks created by erasure have the current background rendition (as set +by \fBwbkgdset\fR) merged into them. +.SH RETURN VALUE +All routines return the integer \fBOK\fR. The SVr4.0 manual says "or a +non-negative integer if \fBimmedok\fR is set", but this appears to be an error. +.SH NOTES +Note that \fBerase\fR, \fBwerase\fR, \fBclear\fR, \fBwclear\fR, +\fBclrtobot\fR, and \fBclrtoeol\fR may be macros. +.SH PORTABILITY +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. + +Some historic curses implementations had, as an undocumented feature, the +ability to do the equivalent of \fBclearok(..., 1)\fR by saying +\fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under +ncurses. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_outopts\fR(3X), \fBcurs_refresh\fR(3X) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_color.3 b/lib/libcurses/curs_color.3 new file mode 100644 index 00000000000..ef015207411 --- /dev/null +++ b/lib/libcurses/curs_color.3 @@ -0,0 +1,148 @@ +.TH curs_color 3X "" +.SH NAME +\fBstart_color\fR, \fBinit_pair\fR, +\fBinit_color\fR, \fBhas_colors\fR, \fBcan_change_color\fR, +\fBcolor_content\fR, \fBpair_content\fR - \fBcurses\fR color +manipulation routines +.SH SYNOPSIS +\fB# include <curses.h>\fR +.br +\fBint start_color(void);\fR +.br +\fBint init_pair(short pair, short f, short b);\fR +.br +\fBint init_color(short color, short r, short g, short b);\fR +.br +\fBbool has_colors(void);\fR +.br +\fBbool can_change_color(void);\fR +.br +\fBint color_content(short color, short *r, short *g, short *b);\fR +.br +\fBint pair_content(short pair, short *f, short *b);\fR +.br +.SH DESCRIPTION +.SS Overview +\fBcurses\fR support color attributes on terminals with that capability. To +use these routines \fBstart_color\fR must be called, usually right after +\fBinitscr\fR. Colors are always used in pairs (referred to as color-pairs). +A color-pair consists of a foreground color (for characters) and a background +color (for the blank field on which the characters are displayed). A +programmer initializes a color-pair with the routine \fBinit_pair\fR. After it +has been initialized, \fBCOLOR_PAIR\fR(\fIn\fR), a macro defined in +\fB<curses.h>\fR, can be used as a new video attribute. + +If a terminal is capable of redefining colors, the programmer can use the +routine \fBinit_color\fR to change the definition of a color. The routines +\fBhas_colors\fR and \fBcan_change_color\fR return \fBTRUE\fR or \fBFALSE\fR, +depending on whether the terminal has color capabilities and whether the +programmer can change the colors. The routine \fBcolor_content\fR allows a +programmer to extract the amounts of red, green, and blue components in an +initialized color. The routine \fBpair_content\fR allows a programmer to find +out how a given color-pair is currently defined. +.SS Routine Descriptions +The \fBstart_color\fR routine requires no arguments. It must be +called if the programmer wants to use colors, and before any other +color manipulation routine is called. It is good practice to call +this routine right after \fBinitscr\fR. \fBstart_color\fR initializes +eight basic colors (black, red, green, yellow, blue, magenta, cyan, +and white), and two global variables, \fBCOLORS\fR and +\fBCOLOR_PAIRS\fR (respectively defining the maximum number of colors +and color-pairs the terminal can support). It also restores the +colors on the terminal to the values they had when the terminal was +just turned on. + +The \fBinit_pair\fR routine changes the definition of a color-pair. It takes +three arguments: the number of the color-pair to be changed, the foreground +color number, and the background color number. The value of the first argument +must be between \fB1\fR and \fBCOLOR_PAIRS-1\fR. The value of the second and +third arguments must be between 0 and \fBCOLORS\fR (the 0 color pair is wired +to white on black and cannot be changed). If the color-pair was previously +initialized, the screen is refreshed and all occurrences of that color-pair is +changed to the new definition. + +The \fBinit_color\fR routine changes the definition of a color. It takes four +arguments: the number of the color to be changed followed by three RGB values +(for the amounts of red, green, and blue components). The value of the first +argument must be between \fB0\fR and \fBCOLORS\fR. (See the section +\fBColors\fR for the default color index.) Each of the last three arguments +must be a value between 0 and 1000. When \fBinit_color\fR is used, all +occurrences of that color on the screen immediately change to the new +definition. + +The \fBhas_colors\fR routine requires no arguments. It returns \fBTRUE\fR if +the terminal can manipulate colors; otherwise, it returns \fBFALSE\fR. This +routine facilitates writing terminal-independent programs. For example, a +programmer can use it to decide whether to use color or some other video +attribute. + +The \fBcan_change_color\fR routine requires no arguments. It returns +\fBTRUE\fR if the terminal supports colors and can change their definitions; +other, it returns \fBFALSE\fR. This routine facilitates writing +terminal-independent programs. + +The \fBcolor_content\fR routine gives programmers a way to find the intensity +of the red, green, and blue (RGB) components in a color. It requires four +arguments: the color number, and three addresses of \fBshort\fRs for storing +the information about the amounts of red, green, and blue components in the +given color. The value of the first argument must be between 0 and +\fBCOLORS\fR. The values that are stored at the addresses pointed to by the +last three arguments are between 0 (no component) and 1000 (maximum amount of +component). + +The \fBpair_content\fR routine allows programmers to find out what colors a +given color-pair consists of. It requires three arguments: the color-pair +number, and two addresses of \fBshort\fRs for storing the foreground and the +background color numbers. The value of the first argument must be between 1 +and \fBCOLOR_PAIRS-1\fR. The values that are stored at the addresses pointed +to by the second and third arguments are between 0 and \fBCOLORS\fR. +.SS Colors +In \fB<curses.h>\fR the following macros are defined. These are the default +colors. \fBcurses\fR also assumes that \fBCOLOR_BLACK\fR is the default +background color for all terminals. + +.nf + \fBCOLOR_BLACK\fR + \fBCOLOR_RED\fR + \fBCOLOR_GREEN\fR + \fBCOLOR_YELLOW\fR + \fBCOLOR_BLUE\fR + \fBCOLOR_MAGENTA\fR + \fBCOLOR_CYAN\fR + \fBCOLOR_WHITE\fR +.fi +.SH RETURN VALUE +The routines \fBcan_change_color()\fR and \fBhas_colors()\fR return \fBTRUE\fR +or \fBFALSE\fR. + +All other routines return the integer \fBERR\fR upon failure and an \fBOK\fR +(SVr4 specifies only "an integer value other than \fBERR\fR") upon successful +completion. +.SH NOTES +Note that setting an implicit background color via a color pair affects only +character cells that a character write operation explicitly touches. To change +the background color used when parts of a window are blanked by erasing or +scrolling operastions, see \fBcurs_bkgd\fR(3x). + +Several caveats apply on 386 and 486 machines with VGA-compatible graphics: + +COLOR_YELLOW is actually brown. To get yellow, use COLOR_YELLOW combined with +the \fBA_BOLD\fR attribute. + +The A_BLINK attribute should in theory cause the background to go bright. This +often fails to work, and even some cards for which it mostly works (such as the +Paradise and compatibles) do the wrong thing when you try to set a bright +"yellow" background (you get a blinking yellow foreground instead). + +Color RGB values are not settable. +.SH PORTABILITY +This implementation satisfies XSI Curses's minumum maximums +for \fBCOLORS\fR and \fBCOLOR_PAIRS\fR. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_attr\fR(3X) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_delch.3 b/lib/libcurses/curs_delch.3 new file mode 100644 index 00000000000..d7973a98962 --- /dev/null +++ b/lib/libcurses/curs_delch.3 @@ -0,0 +1,39 @@ +.TH curs_delch 3X "" +.SH NAME +\fBdelch\fR, \fBwdelch\fR, \fBmvdelch\fR, \fBmvwdelch\fR - +delete character under the cursor in a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint delch(void);\fR +.br +\fBint wdelch(WINDOW *win);\fR +.br +\fBint mvdelch(int y, int x);\fR +.br +\fBint mvwdelch(WINDOW *win, int y, int x);\fR +.br +.SH DESCRIPTION +These routines delete the character under the cursor; all characters to the +right of the cursor on the same line are moved to the left one position and the +last character on the line is filled with a blank. The cursor position does +not change (after moving to \fIy\fR, \fIx\fR, if specified). (This does not +imply use of the hardware delete character feature.) +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion. +.SH NOTES +Note that \fBdelch\fR, \fBmvdelch\fR, and \fBmvwdelch\fR may be macros. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_deleteln.3 b/lib/libcurses/curs_deleteln.3 new file mode 100644 index 00000000000..2b4710990aa --- /dev/null +++ b/lib/libcurses/curs_deleteln.3 @@ -0,0 +1,55 @@ +.TH curs_deleteln 3X "" +.SH NAME +\fBdeleteln\fR, \fBwdeleteln\fR, \fBinsdelln\fR, +\fBwinsdelln\fR, \fBinsertln\fR, \fBwinsertln\fR - delete and insert +lines in a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint deleteln(void);\fR +.br +\fBint wdeleteln(WINDOW *win);\fR +.br +\fBint insdelln(int n);\fR +.br +\fBint winsdelln(WINDOW *win, int n);\fR +.br +\fBint insertln(void);\fR +.br +\fBint winsertln(WINDOW *win);\fR +.br +.SH DESCRIPTION +The \fBdeleteln\fR and \fBwdeleteln\fR routines delete the line under the +cursor in the window; all lines below the current line are moved up one line. +The bottom line of the window is cleared. The cursor position does not change. + +The \fBinsdelln\fR and \fBwinsdelln\fR routines, for positive \fIn\fR, insert +\fIn\fR lines into the specified window above the current line. The \fIn\fR +bottom lines are lost. For negative \fIn\fR, delete \fIn\fR lines (starting +with the one under the cursor), and move the remaining lines up. The bottom +\fIn\fR lines are cleared. The current cursor position remains the same. + +The \fBinsertln\fR and \fBinsertln\fR routines, insert a blank line above the +current line and the bottom line is lost. +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion. +.SH PORTABILITY +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 NOTES +Note that all but \fBwinsdelln\fR may be a macros. + +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_getch.3 b/lib/libcurses/curs_getch.3 new file mode 100644 index 00000000000..293bcf29fc4 --- /dev/null +++ b/lib/libcurses/curs_getch.3 @@ -0,0 +1,203 @@ +.TH curs_getch 3X "" +.SH NAME +\fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, +\fBmvwgetch\fR, \fBungetch\fR - get (or push back) characters from +\fBcurses\fR terminal keyboard +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint getch(void);\fR +.br +\fBint wgetch(WINDOW *win);\fR +.br +\fBint mvgetch(int y, int x);\fR +.br +\fBint mvwgetch(WINDOW *win, int y, int x);\fR +.br +\fBint ungetch(int ch);\fR +.br +.SH DESCRIPTION +The \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR and \fBmvwgetch\fR, routines read +a character from the window. In no-delay mode, if no input is waiting, the +value \fBERR\fR is returned. In delay mode, the program waits until the system +passes text through to the program. Depending on the setting of \fBcbreak\fR, +this is after one character (cbreak mode), or after the first newline (nocbreak +mode). In half-delay mode, the program waits until a character is typed or the +specified timeout has been reached. + +If \fBnoecho\fR has been set, then the character will also be echoed into the +designated window according to the following rules: +If the character is the current erase character, left arrow, or backspace, +the cursor is moved one space to the left and that screen position is erased +as if \fBdelch\fR had been called. +If the character value is any other \fBKEY_\fR define, the user is alerted +with a \fBbeep\fR call. +Otherwise the character is simply output to the screen. + +If the window is not a pad, and it has been moved or modified since the last +call to \fBwrefresh\fR, \fBwrefresh\fR will be called before another character +is read. + +If \fBkeypad\fR is \fBTRUE\fR, and a function key is pressed, the token for +that function key is returned instead of the raw characters. Possible function +keys are defined in \fB<curses.h>\fR as macros with values outside the range +of 8-bit characters whose names begin with \fBKEY_.\fR Thus, a variable +intended to hold the return value of a function key must be of short size or +larger. + +When a character that could be the beginning of a function key is received +(which, on modern terminals, means an escape character), \fBcurses\fR sets a +timer. If the remainder of the sequence does not come in within the designated +time, the character is passed through; otherwise, the function key value is +returned. For this reason, many terminals experience a delay between the time +a user presses the escape key and the escape is returned to the program. + +The \fBungetch\fR routine places \fIch\fR back onto the input queue to be +returned by the next call to \fBwgetch\fR. Note that there is, in effect, +just one input queue for all windows. + +.SS Function Keys +The following function keys, defined in \fB<curses.h>\fR, might be returned by +\fBgetch\fR if \fBkeypad\fR has been enabled. Note that not all of these are +necessarily supported on any particular terminal. +.nf +__________________________________________________________________ +\fIName\fR \fIKey\fR \fIname\fR +__________________________________________________________________ +KEY_BREAK Break key +KEY_DOWN The four arrow keys ... +KEY_UP +KEY_LEFT +KEY_RIGHT +KEY_HOME Home key (upward+left arrow) +KEY_BACKSPACE Backspace +KEY_F0 Function keys; space for 64 keys is reserved. +KEY_F(\fIn\fR) For 0 \fI<\fR \fIn\fR \fI<\fR 63 +KEY_DL Delete line +KEY_IL Insert line +KEY_DC Delete character +KEY_IC Insert char or enter insert mode +KEY_EIC Exit insert char mode +KEY_CLEAR Clear screen +KEY_EOS Clear to end of screen +KEY_EOL Clear to end of line +KEY_SF Scroll 1 line forward +KEY_SR Scroll 1 line backward (reverse) +KEY_NPAGE Next page +KEY_PPAGE Previous page +KEY_STAB Set tab +KEY_CTAB Clear tab +KEY_CATAB Clear all tabs +KEY_ENTER Enter or send +KEY_SRESET Soft (partial) reset +KEY_RESET Reset or hard reset +KEY_PRINT Print or copy +KEY_LL Home down or bottom (lower left). Keypad is + arranged like this: + \fBA1\fR \fBup\fR \fBA3\fR + \fBleft\fR \fBB2\fR \fBright\fR + \fBC1\fR \fBdown\fR \fBC3\fR +KEY_A1 Upper left of keypad +KEY_A3 Upper right of keypad +KEY_B2 Center of keypad +KEY_C1 Lower left of keypad +KEY_C3 Lower right of keypad +KEY_BTAB Back tab key +KEY_BEG Beg(inning) key +KEY_CANCEL Cancel key +KEY_CLOSE Close key +KEY_COMMAND Cmd (command) key +KEY_COPY Copy key +KEY_CREATE Create key +KEY_END End key +KEY_EXIT Exit key +KEY_FIND Find key +KEY_HELP Help key +KEY_MARK Mark key +KEY_MESSAGE Message key +KEY_MOVE Move key +KEY_NEXT Next object key +KEY_OPEN Open key +KEY_OPTIONS Options key +KEY_PREVIOUS Previous object key +KEY_REDO Redo key +KEY_REFERENCE Ref(erence) key +KEY_REFRESH Refresh key +KEY_REPLACE Replace key +KEY_RESTART Restart key +KEY_RESUME Resume key +KEY_SAVE Save key +KEY_SBEG Shifted beginning key +KEY_SCANCEL Shifted cancel key +KEY_SCOMMAND Shifted command key +KEY_SCOPY Shifted copy key +KEY_SCREATE Shifted create key +KEY_SDC Shifted delete char key +KEY_SDL Shifted delete line key +KEY_SELECT Select key +KEY_SEND Shifted end key +KEY_SEOL Shifted clear line key +KEY_SEXIT Shifted exit key +KEY_SFIND Shifted find key +KEY_SHELP Shifted help key +KEY_SHOME Shifted home key +KEY_SIC Shifted input key +KEY_SLEFT Shifted left arrow key +KEY_SMESSAGE Shifted message key +KEY_SMOVE Shifted move key +KEY_SNEXT Shifted next key +KEY_SOPTIONS Shifted options key +KEY_SPREVIOUS Shifted prev key +KEY_SPRINT Shifted print key +KEY_SREDO Shifted redo key +KEY_SREPLACE Shifted replace key +KEY_SRIGHT Shifted right arrow +KEY_SRSUME Shifted resume key +KEY_SSAVE Shifted save key +KEY_SSUSPEND Shifted suspend key +KEY_SUNDO Shifted undo key +KEY_SUSPEND Suspend key +KEY_UNDO Undo key +.fi + +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and an integer value +other than \fBERR\fR" (\fBOK\fR in the case of ungetch()) upon successful +completion. +.SH NOTES +Use of the escape key by a programmer for a single character function is +discouraged, as it will cause a delay of up to one second while the +keypad code looks for a following function-key sequence. + +When using \fBgetch\fR, \fBwgetch\fR, \fBmvgetch\fR, or +\fBmvwgetch\fR, nocbreak mode (\fBnocbreak\fR) and echo mode +(\fBecho\fR) should not be used at the same time. Depending on the +state of the tty driver when each character is typed, the program may +produce undesirable results. + +Note that \fBgetch\fR, \fBmvgetch\fR, and \fBmvwgetch\fR may be macros. + +Historically, the set of keypad macros was largely defined by the extremely +function-key-rich keyboard of the AT&T 7300, aka 3B1, aka Safari 4. Modern +personal computers usually have only a small subset of these. IBM PC-style +consoles typically support little more than \fBKEY_UP\fR, \fBKEY_DOWN\fR, +\fBKEY_LEFT\fR, \fBKEY_RIGHT\fR, \fBKEY_HOME\fR, \fBKEY_END\fR, +\fBKEY_NPAGE\fR, \fBKEY_PPAGE\fR, and function keys 1 through 12. The Ins key +is usually mapped to \fBKEY_IC\fR. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. They read +single-byte characters only. The standard specifies that they return \fBERR\fR +on failure, but specifies no error conditions. + +The echo behavior of these functions on input of \fBKEY_\fR or backspace +characters was not specified. This description is adopted from the XSI +Curses standard. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_inopts\fR(3X), \fBcurs_move\fR(3X), +\fBcurs_refresh\fR(3X). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_getstr.3 b/lib/libcurses/curs_getstr.3 new file mode 100644 index 00000000000..95845739807 --- /dev/null +++ b/lib/libcurses/curs_getstr.3 @@ -0,0 +1,66 @@ +.TH curs_getstr 3X "" +.SH NAME +\fBgetstr\fR, \fBwgetstr\fR, \fBmvgetstr\fR, +\fBmvwgetstr\fR, \fBwgetnstr\fR - accept character strings from +\fBcurses\fR terminal keyboard +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint getstr(char *str);\fR +.br +\fBint wgetstr(WINDOW *win, char *str);\fR +.br +\fBint mvgetstr(int y, int x, char *str);\fR +.br +\fBint mvwgetstr(WINDOW *win, int y, int x, char *str);\fR +.br +\fBint wgetnstr(WINDOW *win, char *str, int n);\fR +.br +.SH DESCRIPTION +The function \fBgetstr\fR is equivalent to a series of calls to \fBgetch\fR, +until a newline or carriage return is received (the terminating character is +not included in the returned string). The resulting value is placed in the +area pointed to by the character pointer \fIstr\fR. + +\fBwgetnstr\fR reads at most \fIn\fR characters, thus preventing a possible +overflow of the input buffer. Any attempt to enter more characters (other +than the terminating newline or carriage return) causes a beep. Function +keys also cause a beep and are ignored. + +The user's erase and kill characters are interpreted. If keypad +mode is on for the window, \fBKEY_LEFT\fR and \fBKEY_BACKSPACE\fR +are both considered equivalent to the user's kill character. + +Characters input are echoed only if \fBecho\fR is currently on. In that case, +backspace is echoed as deletion of the previous character (typically a left +motion). +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion. +.SH NOTES +Note that \fBgetstr\fR, \fBmvgetstr\fR, and \fBmvwgetstr\fR may be macros. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. They read +single-byte characters only. The standard specifies that they return \fBERR\fR +on failure, but the single error condition \fBEOVERFLOW\fR associated with +extended-level conformance is not yet returned (the XSI curses support for +multi-byte characters is not yet present). + +SVr3 and early SVr4 curses implementations did not reject function keys; +the SVr4.0 documentation claimed that "special keys" (such as function +keys, "home" key, "clear" key, \fIetc\fR.) are interpreted" without +giving details. It lied. In fact, the `character' value appended to the +string by those implementations was predictable but not useful +(being, in fact, the low-order eight bits of the key's KEY_ value). + +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_getyx.3 b/lib/libcurses/curs_getyx.3 new file mode 100644 index 00000000000..58a3a52e8eb --- /dev/null +++ b/lib/libcurses/curs_getyx.3 @@ -0,0 +1,43 @@ +.TH curs_getyx 3X "" +.SH NAME +\fBgetyx\fR, \fBgetparyx\fR, \fBgetbegyx\fR, +\fBgetmaxyx\fR - get \fBcurses\fR cursor and window coordinates +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBvoid getyx(WINDOW *win, int y, int x);\fR +.br +\fBvoid getparyx(WINDOW *win, int y, int x);\fR +.br +\fBvoid getbegyx(WINDOW *win, int y, int x);\fR +.br +\fBvoid getmaxyx(WINDOW *win, int y, int x);\fR +.br +.SH DESCRIPTION +The \fBgetyx\fR macro places the current cursor position of the given window in +the two integer variables \fIy\fR and \fIx\fR. + +If \fIwin\fR is a subwindow, the \fBgetparyx\fR macro places the beginning +coordinates of the subwindow relative to the parent window into two integer +variables \fIy\fR and \fIx\fR. Otherwise, \fB-1\fR is placed into \fIy\fR and +\fIx\fR. + +Like \fBgetyx\fR, the \fBgetbegyx\fR and \fBgetmaxyx\fR macros store +the current beginning coordinates and size of the specified window. +.SH RETURN VALUE +The return values of these macros are undefined (\fIi\fR.\fIe\fR., +they should not be used as the right-hand side of assignment +statements). +.SH NOTES +All of these interfaces are macros and that "\fB&\fR" is not +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_inch.3 b/lib/libcurses/curs_inch.3 new file mode 100644 index 00000000000..688a12c415a --- /dev/null +++ b/lib/libcurses/curs_inch.3 @@ -0,0 +1,42 @@ +.TH curs_inch 3X "" +.SH NAME +\fBinch\fR, \fBwinch\fR, \fBmvinch\fR, \fBmvwinch\fR +- get a character and attributes from a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBchtype inch(void);\fR +.br +\fBchtype winch(WINDOW *win);\fR +.br +\fBchtype mvinch(int y, int x);\fR +.br +\fBchtype mvwinch(WINDOW *win, int y, int x);\fR +.br +.SH DESCRIPTION +These routines return the character, of type \fBchtype\fR, at the current +position in the named window. If any attributes are set for that position, +their values are OR-ed into the value returned. Constants defined in +\fB<curses.h>\fR can be used with the \fB&\fR (logical AND) operator to +extract the character or attributes alone. + +.SS Attributes +The following bit-masks may be AND-ed with characters returned by \fBwinch\fR. + +.nf +\fBA_CHARTEXT\fR Bit-mask to extract character +\fBA_ATTRIBUTES\fR Bit-mask to extract attributes +\fBA_COLOR\fR Bit-mask to extract color-pair field information +.fi +.SH NOTES +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_inchstr.3 b/lib/libcurses/curs_inchstr.3 new file mode 100644 index 00000000000..75c02b2fdb5 --- /dev/null +++ b/lib/libcurses/curs_inchstr.3 @@ -0,0 +1,55 @@ +.TH curs_inchstr 3X "" +.SH NAME +\fBinchstr\fR, \fBinchnstr\fR, \fBwinchstr\fR, +\fBwinchnstr\fR, \fBmvinchstr\fR, \fBmvinchnstr\fR, \fBmvwinchstr\fR, +\fBmvwinchnstr\fR - get a string of characters (and attributes) from a +\fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint inchstr(chtype *chstr);\fR +.br +\fBint inchnstr(chtype *chstr, int n);\fR +.br +\fBint winchstr(WINDOW *win, chtype *chstr);\fR +.br +\fBint winchnstr(WINDOW *win, chtype *chstr, int n);\fR +.br +\fBint mvinchstr(int y, int x, chtype *chstr);\fR +.br +\fBint mvinchnstr(int y, int x, chtype *chstr, int n);\fR +.br +\fBint mvwinchstr(WINDOW *win, int y, int x, chtype *chstr);\fR +.br +\fBint mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n);\fR +.br +.SH DESCRIPTION +These routines return a NULL-terminated array of \fBchtype\fR quantities, +starting at the current cursor position in the named window and ending at the +right margin of the window. The four functions with \fIn\fR as +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)]. +.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 +retrieved, exclusive of the trailing 0). +.SH NOTES +Note that all routines except \fBwinchnstr\fR may be macros. SVr4 does not +document whether the result string is 0-terminated; it does not document +whether a length limit argument includes any trailing 0; and it does not +document the meaning of the return value. +.SH PORTABILITY +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_initscr.3 b/lib/libcurses/curs_initscr.3 new file mode 100644 index 00000000000..0ede098dc19 --- /dev/null +++ b/lib/libcurses/curs_initscr.3 @@ -0,0 +1,87 @@ +.TH curs_initscr 3X "" +.SH NAME +\fBinitscr\fR, \fBnewterm\fR, \fBendwin\fR, +\fBisendwin\fR, \fBset_term\fR, \fBdelscreen\fR - \fBcurses\fR screen +initialization and manipulation routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBWINDOW *initscr(void);\fR +.br +\fBint endwin(void);\fR +.br +\fBint isendwin(void);\fR +.br +\fBSCREEN *newterm(const char *type, FILE *outfd, FILE *infd);\fR +.br +\fBSCREEN *set_term(SCREEN *new);\fR +.br +\fBvoid delscreen(SCREEN* sp);\fR +.br +.SH DESCRIPTION +\fBinitscr\fR is normally the first \fBcurses\fR routine to call when +initializing a program. A few special routines sometimes need to be +called before it; these are \fBslk_init\fR, \fBfilter\fR, \fBripoffline\fR, +\fBuse_env\fR. For multiple-terminal applications, \fBnewterm\fR may be +called before \fBinitscr\fR. + +The initscr code determines the terminal type and initializes all \fBcurses\fR +data structures. \fBinitscr\fR also causes the first call to \fBrefresh\fR to +clear the screen. If errors occur, \fBinitscr\fR writes an appropriate error +message to standard error and exits; otherwise, a pointer is returned to +\fBstdscr\fR. + +A program that outputs to more than one terminal should use the \fBnewterm\fR +routine for each terminal instead of \fBinitscr\fR. A program that needs to +inspect capabilities, so it can continue to run in a line-oriented mode if the +terminal cannot support a screen-oriented program, would also use +\fBnewterm\fR. The routine \fBnewterm\fR should be called once for each +terminal. It returns a variable of type \fBSCREEN *\fR which should be saved +as a reference to that terminal. The arguments are the \fItype\fR of the +terminal to be used in place of \fB$TERM\fR, a file pointer for output to the +terminal, and another file pointer for input from the terminal (if \fItype\fR +is \fBNULL\fR, \fB$TERM\fR will be used). The program must also call +\fBendwin\fR for each terminal being used before exiting from \fBcurses\fR. +If \fBnewterm\fR is called more than once for the same terminal, the first +terminal referred to must be the last one for which \fBendwin\fR is called. + +A program should always call \fBendwin\fR before exiting or escaping from +\fBcurses\fR mode temporarily. This routine restores tty modes, moves the +cursor to the lower left-hand corner of the screen and resets the terminal into +the proper non-visual mode. Calling \fBrefresh\fR or \fBdoupdate\fR after a +temporary escape causes the program to resume visual mode. + +The \fBisendwin\fR routine returns \fBTRUE\fR if \fBendwin\fR has been +called without any subsequent calls to \fBwrefresh\fR, and \fBFALSE\fR +otherwise. + +The \fBset_term\fR routine is used to switch between different +terminals. The screen reference \fBnew\fR becomes the new current +terminal. The previous terminal is returned by the routine. This is +the only routine which manipulates \fBSCREEN\fR pointers; all other +routines affect only the current terminal. + +The \fBdelscreen\fR routine frees storage associated with the +\fBSCREEN\fR data structure. The \fBendwin\fR routine does not do +this, so \fBdelscreen\fR should be called after \fBendwin\fR if a +particular \fBSCREEN\fR is no longer needed. +.SH RETURN VALUE +\fBendwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR +upon successful completion. + +Routines that return pointers always return \fBNULL\fR on error. +.SH NOTES +Note that \fBinitscr\fR and \fBnewterm\fR may be macros. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_inopts.3 b/lib/libcurses/curs_inopts.3 new file mode 100644 index 00000000000..aa53b61e57a --- /dev/null +++ b/lib/libcurses/curs_inopts.3 @@ -0,0 +1,183 @@ +.TH curs_inopts 3X "" +.SH NAME +\fBcbreak\fR, \fBnocbreak\fR, \fBecho\fR, +\fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR, \fBkeypad\fR, +\fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBraw\fR, \fBnoraw\fR, +\fBnoqiflush\fR, \fBqiflush\fR, \fBtimeout\fR, \fBwtimeout\fR, +\fBtypeahead\fR - \fBcurses\fR input options +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint cbreak(void);\fR +.br +\fBint nocbreak(void);\fR +.br +\fBint echo(void);\fR +.br +\fBint noecho(void);\fR +.br +\fBint halfdelay(int tenths);\fR +.br +\fBint intrflush(WINDOW *win, bool bf);\fR +.br +\fBint keypad(WINDOW *win, bool bf);\fR +.br +\fBint meta(WINDOW *win, bool bf);\fR +.br +\fBint nodelay(WINDOW *win, bool bf);\fR +.br +\fBint raw(void);\fR +.br +\fBint noraw(void);\fR +.br +\fBvoid noqiflush(void);\fR +.br +\fBvoid qiflush(void);\fR +.br +\fBint notimeout(WINDOW *win, bool bf);\fR +.br +\fBvoid timeout(int delay);\fR +.br +\fBvoid wtimeout(WINDOW *win, int delay);\fR +.br +\fBint typeahead(int fd);\fR +.br +.SH DESCRIPTION +Normally, the tty driver buffers typed characters until a newline or carriage +return is typed. The \fBcbreak\fR routine disables line buffering and +erase/kill character-processing (interrupt and flow control characters are +unaffected), making characters typed by the user immediately available to the +program. The \fBnocbreak\fR routine returns the terminal to normal (cooked) +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 +discussion of how these routines interact with \fBecho\fR and \fBnoecho\fR.] + +The \fBecho\fR and \fBnoecho\fR routines control whether characters typed by +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 +discussion of how these routines interact with \fBcbreak\fR and +\fBnocbreak\fR.] + +The \fBhalfdelay\fR routine is used for half-delay mode, which is similar to +\fBcbreak\fR mode in that characters typed by the user are immediately +available to the program. However, after blocking for \fItenths\fR tenths of +seconds, ERR is returned if nothing has been typed. The value of \fBtenths\fR +must be a number between 1 and 255. Use \fBnocbreak\fR to leave half-delay +mode. + +If the \fBintrflush\fR option is enabled, (\fIbf\fR is \fBTRUE\fR), when an +interrupt key is pressed on the keyboard (interrupt, break, quit) all output in +the tty driver queue will be flushed, giving the effect of faster response to +the interrupt, but causing \fBcurses\fR to have the wrong idea of what is on +the screen. Disabling (\fIbf\fR is \fBFALSE\fR), the option prevents the +flush. The default for the option is inherited from the tty driver settings. +The window argument is ignored. + +The \fBkeypad\fR option enables the keypad of the user's terminal. If +enabled (\fIbf\fR is \fBTRUE\fR), the user can press a function key +(such as an arrow key) and \fBwgetch\fR returns a single value +representing the function key, as in \fBKEY_LEFT\fR. If disabled +(\fIbf\fR is \fBFALSE\fR), \fBcurses\fR does not treat function keys +specially and the program has to interpret the escape sequences +itself. If the keypad in the terminal can be turned on (made to +transmit) and off (made to work locally), turning on this option +causes the terminal keypad to be turned on when \fBwgetch\fR is +called. The default value for keypad is false. + +Initially, whether the terminal returns 7 or 8 significant bits on +input depends on the control mode of the tty driver [see termio(7)]. +To force 8 bits to be returned, invoke \fBmeta\fR(\fIwin\fR, +\fBTRUE\fR); this is equivalent, under POSIX, to setting the CS8 flag +on the terminal. To force 7 bits to be returned, invoke +\fBmeta\fR(\fIwin\fR, \fBFALSE\fR); this is equivalent, under POSIX, +to setting the CS8 flag on the terminal. The window argument, +\fIwin\fR, is always ignored. If the terminfo capabilities \fBsmm\fR +(meta_on) and \fBrmm\fR (meta_off) are defined for the terminal, +\fBsmm\fR is sent to the terminal when \fBmeta\fR(\fIwin\fR, +\fBTRUE\fR) is called and \fBrmm\fR is sent when \fBmeta\fR(\fIwin\fR, +\fBFALSE\fR) is called. + +The \fBnodelay\fR option causes \fBgetch\fR to be a non-blocking call. +If no input is ready, \fBgetch\fR returns \fBERR\fR. If disabled +(\fIbf\fR is \fBFALSE\fR), \fBgetch\fR waits until a key is pressed. + +While interpreting an input escape sequence, \fBwgetch\fR sets a timer +while waiting for the next character. If \fBnotimeout(\fR\fIwin\fR, +\fBTRUE\fR) is called, then \fBwgetch\fR does not set a timer. The +purpose of the timeout is to differentiate between sequences received +from a function key and those typed by a user. + +The \fBraw\fR and \fBnoraw\fR routines place the terminal into or out of raw +mode. Raw mode is similar to \fBcbreak\fR mode, in that characters typed are +immediately passed through to the user program. The differences are that in +raw mode, the interrupt, quit, suspend, and flow control characters are all +passed through uninterpreted, instead of generating a signal. The behavior of +the BREAK key depends on other bits in the tty driver that are not set by +\fBcurses\fR. + +When the \fBnoqiflush\fR routine is used, normal flush of input and +output queues associated with the \fBINTR\fR, \fBQUIT\fR and +\fBSUSP\fR characters will not be done [see termio(7)]. When +\fBqiflush\fR is called, the queues will be flushed when these control +characters are read. You may want to call \fBnoqiflush()\fR in a signal +handler if you want output to continue as though the interrupt +had not occurred, after the handler exits. + +The \fBtimeout\fR and \fBwtimeout\fR routines set blocking or +non-blocking read for a given window. If \fIdelay\fR is negative, +blocking read is used (\fIi\fR.\fIe\fR., waits indefinitely for +input). If \fIdelay\fR is zero, then non-blocking read is used +(\fIi\fR.\fIe\fR., read returns \fBERR\fR if no input is waiting). If +\fIdelay\fR is positive, then read blocks for \fIdelay\fR +milliseconds, and returns \fBERR\fR if there is still no input. +Hence, these routines provide the same functionality as \fBnodelay\fR, +plus the additional capability of being able to block for only +\fIdelay\fR milliseconds (where \fIdelay\fR is positive). + +The \fBcurses\fR library does ``line-breakout optimization'' by looking for +typeahead periodically while updating the screen. If input is found, +and it is coming from a tty, the current update is postponed until +\fBrefresh\fR or \fBdoupdate\fR is called again. This allows faster +response to commands typed in advance. Normally, the input FILE +pointer passed to \fBnewterm\fR, or \fBstdin\fR in the case that +\fBinitscr\fR was used, will be used to do this typeahead checking. +The \fBtypeahead\fR routine specifies that the file descriptor +\fIfd\fR is to be used to check for typeahead instead. If \fIfd\fR is +-1, then no typeahead checking is done. +.SH RETURN VALUE +All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion, unless otherwise noted in the preceding routine descriptions. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. + +The curses library obeys the XPG4 standard and the historical practice of the +AT&T curses implementations, in that the echo bit is cleared when curses +initializes the terminal state. BSD curses differed from this slightly; it +left the echo bit on at initialization, but the BSD \fBraw\fR call turned it +off as a side-effect. For best portability, set echo or noecho explicitly +just after initialization, even if your program remains in cooked mode. +.SH NOTES +Note that \fBecho\fR, \fBnoecho\fR, \fBhalfdelay\fR, \fBintrflush\fR, +\fBmeta\fR, \fBnodelay\fR, \fBnotimeout\fR, \fBnoqiflush\fR, +\fBqiflush\fR, \fBtimeout\fR, and \fBwtimeout\fR may be macros. + +The \fBnoraw\fR and \fBnocbreak\fR calls follow historical practice in that +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_insch.3 b/lib/libcurses/curs_insch.3 new file mode 100644 index 00000000000..11f49053095 --- /dev/null +++ b/lib/libcurses/curs_insch.3 @@ -0,0 +1,39 @@ +.TH curs_insch 3X "" +.SH NAME +\fBinsch\fR, \fBwinsch\fR, \fBmvinsch\fR, \fBmvwinsch\fR - +insert a character before cursor in a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint insch(chtype ch);\fR +.br +\fBint winsch(WINDOW *win, chtype ch);\fR +.br +\fBint mvinsch(int y, int x, chtype ch);\fR +.br +\fBint mvwinsch(WINDOW *win, int y, int x, chtype ch);\fR +.br +.SH DESCRIPTION +These routines, insert the character \fIch\fR before the character under the +cursor. All characters to the right of the cursor are moved one space to the +right, with the possibility of the rightmost character on the line being lost. +The insertion operation does not change the cursor position. +.SH RETURN VALUE +All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion, unless otherwise noted in the preceding routine descriptions. +.SH NOTES +These routines do not necessarily imply use of a hardware insert character +feature. + +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_insstr.3 b/lib/libcurses/curs_insstr.3 new file mode 100644 index 00000000000..965c16fd4d4 --- /dev/null +++ b/lib/libcurses/curs_insstr.3 @@ -0,0 +1,61 @@ +.TH curs_insstr 3X "" +.SH NAME +\fBinsstr\fR, \fBinsnstr\fR, \fBwinsstr\fR, \fBwinsnstr\fR, +\fBmvinsstr\fR, \fBmvinsnstr\fR, \fBmvwinsstr\fR, \fBmvwinsnstr\fR - insert +string before cursor in a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR +.br +\fBint insstr(const char *str);\fR +.br +\fBint insnstr(const char *str, int n);\fR +.br +\fBint winsstr(WINDOW *win, const char *str);\fR +.br +\fBint winsnstr(WINDOW *win, const char *str, int n);\fR +.br +\fBint mvinsstr(int y, int x, const char *str);\fR +.br +\fBint mvinsnstr(int y, int x, const char *str, int n);\fR +.br +\fBint mvwinsstr(WINDOW *win, int y, int x, const char *str);\fR +.br +\fBint mvwinsnstr(WINDOW *win, int y, int x, const char *str, int n);\fR +.br +.SH DESCRIPTION +These routines insert a character string (as many characters as will fit on the +line) before the character under the cursor. All characters to the right of +the cursor are shifted right, with the possibility of the rightmost characters +on the line being lost. The cursor position does not change (after moving to +\fIy\fR, \fIx\fR, if specified). The four routines with \fIn\fR as the last +argument insert a leading substring of at most \fIn\fR characters. If +\fIn\fR<=0, then the entire string is inserted. + +If a character in \fIstr\fR is a tab, newline, carriage return or +backspace, the cursor is moved appropriately within the window. A +newline also does a \fBclrtoeol\fR before moving. Tabs are considered +to be at every eighth column. If a character in \fIstr\fR is another +control character, it is drawn in the \fB^\fR\fIX\fR notation. +Calling \fBwinch\fR after adding a control character (and moving to +it, if necessary) does not return the control character, but instead +returns a character in the the ^-representation of the control character. +.SH RETURN VALUE +All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion, unless otherwise noted in the preceding routine descriptions. +.SH NOTES +Note that all but \fBwinsnstr\fR may be macros. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4, which adds +const qualifiers to the arguments. The XSI Curses error conditions +\fBEILSEQ\fR and \fBEILOVERFLOW\fR associated with extended-level conformance +are not yet detected (this implementation does not yet support XPG4 multibyte +characters). +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_clear\fR(3X), \fBcurs_inch\fR(3X). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_instr.3 b/lib/libcurses/curs_instr.3 new file mode 100644 index 00000000000..e7c681664a5 --- /dev/null +++ b/lib/libcurses/curs_instr.3 @@ -0,0 +1,53 @@ +.TH curs_instr 3X "" +.SH NAME +\fBinstr\fR, \fBinnstr\fR, \fBwinstr\fR, \fBwinnstr\fR, +\fBmvinstr\fR, \fBmvinnstr\fR, \fBmvwinstr\fR, \fBmvwinnstr\fR - get a string +of characters from a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint instr(char *str);\fR +.br +\fBint innstr(char *str, int n);\fR +.br +\fBint winstr(WINDOW *win, char *str);\fR +.br +\fBint winnstr(WINDOW *win, char *str, int n);\fR +.br +\fBint mvinstr(int y, int x, char *str);\fR +.br +\fBint mvinnstr(int y, int x, char *str, int n);\fR +.br +\fBint mvwinstr(WINDOW *win, int y, int x, char *str);\fR +.br +\fBint mvwinnstr(WINDOW *win, int y, int x, char *str, int n);\fR +.br +.SH DESCRIPTION +These routines return a string of characters in \fIstr\fR, extracted starting +at the current cursor position in the named window and ending at the right +margin of the window. Attributes are stripped from the characters. The four +functions with \fIn\fR as the last argument return a leading substring at most +\fIn\fR characters long (exclusive of the trailing NUL). +.SH RETURN VALUE +All routines that return an integer return \fBERR\fR upon failure and OK (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion, unless otherwise noted in the preceding routine descriptions. +.SH NOTES +Note that all routines except \fBwinnstr\fR may be macros. SVr4 does not +document whether a length limit includes or excludes the trailing NUL, and +does not document the meaning of the return values. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. The +standard specifies that they always return \fBOK\fR on success. The XSI Curses +error conditions \fBEILSEQ\fR and \fBEILOVERFLOW\fR associated with +extebded-level conformance are not yet detected (this implementation does not +yet support XPG4 multibyte characters). +.SH SEE ALSO +\fBcurses\fR(3X). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: + diff --git a/lib/libcurses/curs_kernel.3 b/lib/libcurses/curs_kernel.3 new file mode 100644 index 00000000000..7fda81b2560 --- /dev/null +++ b/lib/libcurses/curs_kernel.3 @@ -0,0 +1,123 @@ +.TH curs_kernel 3X "" +.SH NAME +\fBdef_prog_mode\fR, \fBdef_shell_mode\fR, +\fBreset_prog_mode\fR, \fBreset_shell_mode\fR, \fBresetty\fR, +\fBsavetty\fR, \fBgetsyx\fR, \fBsetsyx\fR, \fBripoffline\fR, +\fBcurs_set\fR, \fBnapms\fR - low-level \fBxscurses\fR routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint def_prog_mode(void);\fR +.br +\fBint def_shell_mode(void);\fR +.br +\fBint reset_prog_mode(void);\fR +.br +\fBint reset_shell_mode(void);\fR +.br +\fBint resetty(void);\fR +.br +\fBint savetty(void);\fR +.br +\fBvoid getsyx(int y, int x);\fR +.br +\fBvoid setsyx(int y, int x);\fR +.br +\fBint ripoffline(int line, int (*init)(WINDOW *, int));\fR +.br +\fBint curs_set(int visibility);\fR +.br +\fBint napms(unsigned int ms);\fR +.br +.SH DESCRIPTION +The following routines give low-level access to various \fBcurses\fR +capabilities. Theses routines typically are used inside library +routines. + +The \fBdef_prog_mode\fR and \fBdef_shell_mode\fR routines save the +current terminal modes as the "program" (in \fBcurses\fR) or "shell" +(not in \fBcurses\fR) state for use by the \fBreset_prog_mode\fR and +\fBreset_shell_mode\fR routines. This is done automatically by +\fBinitscr\fR. There is one such save area for each screen context +allocated by \fBnewterm()\fR. + +The \fBreset_prog_mode\fR and \fBreset_shell_mode\fR routines restore +the terminal to "program" (in \fBcurses\fR) or "shell" (out of +\fBcurses\fR) state. These are done automatically by \fBendwin\fR +and, after an \fBendwin\fR, by \fBdoupdate\fR, so they normally are +not called. + +The \fBresetty\fR and \fBsavetty\fR routines save and restore the +state of the terminal modes. \fBsavetty\fR saves the current state in +a buffer and \fBresetty\fR restores the state to what it was at the +last call to \fBsavetty\fR. + +The \fBgetsyx\fR routine returns the current coordinates of the virtual screen +cursor in \fIy\fR and \fIx\fR. If \fBleaveok\fR is currently \fBTRUE\fR, then +\fB-1\fR,\fB-1\fR is returned. If lines have been removed from the top of the +screen, using \fBripoffline\fR, \fIy\fR and \fIx\fR include these lines; +therefore, \fIy\fR and \fIx\fR should be used only as arguments for +\fBsetsyx\fR. + +The \fBsetsyx\fR routine sets the virtual screen cursor to +\fIy\fR, \fIx\fR. If \fIy\fR and \fIx\fR are both \fB-1\fR, then +\fBleaveok\fR is set. The two routines \fBgetsyx\fR and \fBsetsyx\fR +are designed to be used by a library routine, which manipulates +\fBcurses\fR windows but does not want to change the current position +of the program's cursor. The library routine would call \fBgetsyx\fR +at the beginning, do its manipulation of its own windows, do a +\fBwnoutrefresh\fR on its windows, call \fBsetsyx\fR, and then call +\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 +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 +removed from the bottom. When this is done inside \fBinitscr\fR, the +routine \fBinit\fR (supplied by the user) is called with two +arguments: a window pointer to the one-line window that has been +allocated and an integer with the number of columns in the window. +Inside this initialization routine, the integer variables \fBLINES\fR +and \fBCOLS\fR (defined in \fB<curses.h>\fR) are not guaranteed to be +accurate and \fBwrefresh\fR or \fBdoupdate\fR must not be called. It +is allowable to call \fBwnoutrefresh\fR during the initialization +routine. + +\fBripoffline\fR can be called up to five times before calling \fBinitscr\fR or +\fBnewterm\fR. + +The \fBcurs_set\fR routine sets the cursor state is set to invisible, +normal, or very visible for \fBvisibility\fR equal to \fB0\fR, +\fB1\fR, or \fB2\fR respectively. If the terminal supports the +\fIvisibility\fR requested, the previous \fIcursor\fR state is +returned; otherwise, \fBERR\fR is returned. + +The \fBnapms\fR routine is used to sleep for \fIms\fR milliseconds. +.SH RETURN VALUE +Except for \fBcurs_set\fR, these routines always return \fBOK\fR. +\fBcurs_set\fR returns the previous cursor state, or \fBERR\fR if the +requested \fIvisibility\fR is not supported. +.SH NOTES +Note that \fBgetsyx\fR is a macro, so \fB&\fR is not necessary before +the variables \fIy\fR and \fIx\fR. + +The SVr4 man pages warn that the return value of \fBcurs_set\fR "is currently +incorrect". This implementation gets it right, but it may be unwise to count +on the correctness of the return value anywhere else. +.SH PORTABILITY +The functions \fBsetsyx\fR and \fBgetsyx\fR are not described in the XSI +Curses standard, Issue 4. All other functions are as described in XSI Curses. + +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_mouse.3 b/lib/libcurses/curs_mouse.3 new file mode 100644 index 00000000000..4781f99bed8 --- /dev/null +++ b/lib/libcurses/curs_mouse.3 @@ -0,0 +1,151 @@ +'\" t +.TH curs_mouse 3X "" +.SH NAME +\fBgetmouse\fR, \fBungetmouse\fR, +\fBmousemask\fR - mouse interface through curses +.SH SYNOPSIS +.nf +\fB#include <curses.h>\fR + +\fBtypedef unsigned long mmask_t; + +typedef struct +{ + short id; \fI/* ID to distinguish multiple devices */\fB + int x, y, z; \fI/* event coordinates */\fB + mmask_t bstate; \fI/* button state bits */\fB +} +MEVENT;\fR +.fi +.br +\fBint getmouse(MEVENT *event);\fR +.br +\fBint ungetmouse(MEVENT *event);\fR +.br +\fBmmask_t mousemask(mmask_t newmask, mmask_t *oldmask);\fR +.br +\fBbool wenclose(WINDOW *win, int y, int x)\fR +.br +\fBint mouseinterval(int erval)\fR +.br +.SH DESCRIPTION +These functions provide an interface to mouse events from +\fBcurses\fR(3x). Mouse events are represented by \fBKEY_MOUSE\fR +pseudo-key values in the \fBwgetch\fR input stream. + +To make mouse events visible, use the \fBmousemask\fR function. This will set +the mouse events to be reported. By default, no mouse events are reported. +The function will return a mask to indicate which of the specified mouse events +can be reported; on complete failure it returns 0. If oldmask is non-NULL, +this function fills the indicated location with the previous value of the given +window's mouse event mask. + +As a side effect, setting a zero mousemask may turn off the mouse pointer; +setting a nonzero mask may turn it on. Whether this happens is +device-dependent. + +Here are the mouse event type masks: + +.TS +l l +_ _ +l l. +\fIName\fR \fIDescription\fR +BUTTON1_PRESSED mouse button 1 down +BUTTON1_RELEASED mouse button 1 up +BUTTON1_CLICKED mouse button 1 clicked +BUTTON1_DOUBLE_CLICKED mouse button 1 double clicked +BUTTON1_TRIPLE_CLICKED mouse button 1 triple clicked +BUTTON2_PRESSED mouse button 2 down +BUTTON2_RELEASED mouse button 2 up +BUTTON2_CLICKED mouse button 2 clicked +BUTTON2_DOUBLE_CLICKED mouse button 2 double clicked +BUTTON2_TRIPLE_CLICKED mouse button 2 triple clicked +BUTTON3_PRESSED mouse button 3 down +BUTTON3_RELEASED mouse button 3 up +BUTTON3_CLICKED mouse button 3 clicked +BUTTON3_DOUBLE_CLICKED mouse button 3 double clicked +BUTTON3_TRIPLE_CLICKED mouse button 3 triple clicked +BUTTON4_PRESSED mouse button 4 down +BUTTON4_RELEASED mouse button 4 up +BUTTON4_CLICKED mouse button 4 clicked +BUTTON4_DOUBLE_CLICKED mouse button 4 double clicked +BUTTON4_TRIPLE_CLICKED mouse button 4 triple clicked +BUTTON_SHIFT shift was down during button state change +BUTTON_CTRL control was down during button state change +BUTTON_ALT alt was down during button state change +ALL_MOUSE_EVENTS report all button state changes +REPORT_MOUSE_POSITION report mouse movement +.TE + +Once a class of mouse events have been made visible in a window, +calling the \fBwgetch\fR function on that window may return +\fBKEY_MOUSE\fR as an indicator that a mouse event has been queued. +To read the event data and pop the event off the queue, call +\fBgetmouse\fR. This function will return \fBOK\fR if a mouse event +is actually visible in the given window, \fBERR\fR otherwise. +When \fBgetmouse\fR returns \fBOK\fR, the data deposited as y and +x in the event structure coordinates will be screen-relative character-cell +coordinates. The returned state mask will have exactly one bit set to +indicate the event type. + +The \fBungetmouse\fR function behaves analogously to \fBungetch\fR. It pushes +a \fBKEY_MOUSE\fR event onto the input queue, and associates with that event +the given state data and screen-relative character-cell coordinates. + +The \fBwenclose\fR function tests whether a given pair of screen-relative +character-cell coordinates is enclosed by a given window, returning TRUE +if it is and FALSE otherwise. It is useful for determining what subset of +the screen windows enclose the location of a mouse event. + +The \fBmouseinterval\fR function sets the maximum time (in thousands of a +second) that can elapse between press and release events in order for them to +be recognized as a click. This function returns the previous interval value. +The default is one fifth of a second. + +Note that mouse events will be ignored when input is in cooked mode, and will +cause an error beep when cooked mode is being simulated in a window by a +function such as \fBgetstr\fR that expects a linefeed for input-loop +termination. + +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure or \fBOK\fR +upon successful completion. +.SH PORTABILITY +These calls were designed for \fBcurses\fR(3x), and are not found in SVr4 +curses, 4.4BSD curses, or any other previous version of curses. + +The feature macro \fBNCURSES_MOUSE_VERSION\fR is provided so the preprocessor +can be used to test whether these features are present (its value is 1). NOTE: +THIS INTERFACE IS EXPERIMENTAL AND IS SUBJECT TO CHANGE WITHOUT NOTICE! If the +interface is changed, the value of \fBNCURSES_MOUSE_VERSION\fR will be +incremented. + +The order of the \fBMEVENT\fR structure members is not guaranteed. +Additional fields may be added to the structure in the future. + +Under \fBcurses\fR(3x), these calls are implemented using either +xterm's built-in mouse-tracking API or Alessandro Rubini's gpm server. +If you are using something other than xterm there is no gpm daemon +running on your machine, mouse events will not be visible to +\fBcurses\fR(3x) (and the \fBwmousemask\fR function will always +return \fB0\fR). + +The z member in the event structure is not presently used. It is intended +for use with touchscreens (which may be pressure-sensitive) or with +3D-mice/trackballs/power gloves. +.SH BUGS +Mouse events under xterm will not in fact be ignored during cooked mode, +if they have been enabled by \fBwmousemask\fR. Instead, the xterm mouse +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_move.3 b/lib/libcurses/curs_move.3 new file mode 100644 index 00000000000..7d915ed2843 --- /dev/null +++ b/lib/libcurses/curs_move.3 @@ -0,0 +1,34 @@ +.TH curs_move 3X "" +.SH NAME +\fBmove\fR, \fBwmove\fR - move \fBcurses\fR window cursor +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint move(int y, int x);\fR +.br +\fBint wmove(WINDOW *win, int y, int x);\fR +.br +.SH DESCRIPTION +These routines move the cursor associated with the window to line \fIy\fR and +column \fIx\fR. This routine does not move the physical cursor of the terminal +until \fBrefresh\fR is called. The position specified is relative to the upper +left-hand corner of the window, which is (0,0). +.SH RETURN VALUE +These routines return \fBERR\fR upon failure and OK (SVr4 +specifies only "an integer value other than \fBERR\fR") upon successful +completion. +.SH NOTES +Note that \fBmove\fR may be a macro. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. The +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_outopts.3 b/lib/libcurses/curs_outopts.3 new file mode 100644 index 00000000000..e69383b4ad4 --- /dev/null +++ b/lib/libcurses/curs_outopts.3 @@ -0,0 +1,134 @@ +.TH curs_outopts 3X "" +.SH NAME +\fBclearok\fR, \fBidlok\fR, \fBidcok immedok\fR, +\fBleaveok\fR, \fBsetscrreg\fR, \fBwsetscrreg\fR, \fBscrollok\fR, +\fBnl\fR, \fBnonl\fR - \fBcurses\fR output options +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint clearok(WINDOW *win, bool bf);\fR +.br +\fBint idlok(WINDOW *win, bool bf);\fR +.br +\fBvoid idcok(WINDOW *win, bool bf);\fR +.br +\fBvoid immedok(WINDOW *win, bool bf);\fR +.br +\fBint leaveok(WINDOW *win, bool bf);\fR +.br +\fBint setscrreg(int top, int bot);\fR +.br +\fBint wsetscrreg(WINDOW *win, int top, int bot);\fR +.br +\fBint scrollok(WINDOW *win, bool bf);\fR +.br +\fBint nl(void);\fR +.br +\fBint nonl(void);\fR +.br +.SH DESCRIPTION +These routines set options that change the style of output within +\fBcurses\fR. All options are initially \fBFALSE\fR, unless otherwise stated. +It is not necessary to turn these options off before calling \fBendwin\fR. + +If \fBclearok\fR is called with \fBTRUE\fR as argument, the next +call to \fBwrefresh\fR with this window will clear the screen completely and +redraw the entire screen from scratch. This is useful when the contents of the +screen are uncertain, or in some cases for a more pleasing visual effect. If +the \fIwin\fR argument to \fBclearok\fR is the global variable \fBcurscr\fR, +the next call to \fBwrefresh\fR with any window causes the screen to be cleared +and repainted from scratch. + +If \fBidlok\fR is called with \fBTRUE\fR as argument, +\fBcurses\fR considers using the hardware insert/delete line feature of +terminals so equipped. If disabled (\fIbf\fR is \fBFALSE\fR), \fBcurses\fR +very seldom uses this feature. (The insert/delete character feature is always +considered.) This option should be enabled only if the application needs +insert/delete line, for example, for a screen editor. It is disabled by +default because insert/delete line tends to be visually annoying when used in +applications where it isn't really needed. If insert/delete line cannot be +used, \fBcurses\fR redraws the changed portions of all lines. + +If \fBidcok\fR is called with \fBTRUE\fR as argument, +\fBcurses\fR considers using the hardware insert/delete character feature of +terminals so equipped. This is enabled by default. + +If \fBimmedok\fR is called with \fBTRUE as argument\fR, any change +in the window image, such as the ones caused by \fBwaddch, wclrtobot, wscrl\fR, +\fIetc\fR., automatically cause a call to \fBwrefresh\fR. However, it may +degrade the performance considerably, due to repeated calls to \fBwrefresh\fR. +It is disabled by default. + +Normally, the hardware cursor is left at the location of the window cursor +being refreshed. The \fBleaveok\fR option allows the cursor to be left +wherever the update happens to leave it. It is useful for applications where +the cursor is not used, since it reduces the need for cursor motions. If +possible, the cursor is made invisible when this option is enabled. + +The \fBsetscrreg\fR and \fBwsetscrreg\fR routines allow the application +programmer to set a software scrolling region in a window. \fItop\fR and +\fIbot\fR are the line numbers of the top and bottom margin of the scrolling +region. (Line 0 is the top line of the window.) If this option and +\fBscrollok\fR are enabled, an attempt to move off the bottom margin line +causes all lines in the scrolling region to scroll one line in the direction +of the first line. Only the text of the window is scrolled. (Note that this +has nothing to do with the use of a physical scrolling region capability in the +terminal, like that in the VT100. If \fBidlok\fR is enabled and the terminal +has either a scrolling region or insert/delete line capability, they will +probably be used by the output routines.) + +The \fBscrollok\fR option controls what happens when the cursor of a window is +moved off the edge of the window or scrolling region, either as a result of a +newline action on the bottom line, or typing the last character of the last +line. If disabled, (\fIbf\fR is \fBFALSE\fR), the cursor is left on the bottom +line. If enabled, (\fIbf\fR is \fBTRUE\fR), the window is scrolled up one line +(Note that in order to get the physical scrolling effect on the terminal, it is +also necessary to call \fBidlok\fR). + +The \fBnl\fR and \fBnonl\fR routines control whether the underlying display +device translates the return key into newline on input, and whether it +translates newline into return and line-feed on output (in either case, the +call \fBaddch('\n')\fR does the equivalent of return and line feed on the +virtual screen). Initially, these translations do occur. If you disable them +using \fBnonl\fR, \fBcurses\fR will be able to make better use of the line-feed +capability, resulting in faster cursor motion. Also, \fBcurses\fR will then be +able to detect the return key. +.SH RETURN VALUE +The functions \fBsetscrreg\fR and \fBwsetscrreg\fR return \fBOK\fR upon success +and \fBERR\fR upon failure. All other routines that return an integer always +return \fBOK\fR. +.SH PORTABILITY +These functions are described in the XSI Curses standard, Issue 4. + +The XSI Curses standard is ambiguous on the question of whether \fBraw\fR() +should disable the CRLF translations controlled by \fBnl\fR() and \fBnonl\fR(). +BSD curses did turn off these translations; AT&T curses (at least as late as +SVr1) did not. We choose to do so, on the theory that a programmer requesting +raw input wants a clean (ideally 8-bit clean) connection that the operating +system does not mess with. + +Some historic curses implementations had, as an undocumented feature, the +ability to do the equivalent of \fBclearok(..., 1)\fR by saying +\fBtouchwin(stdscr)\fR or \fBclear(stdscr)\fR. This will not work under +curses. + +Earlier System V curses implementations specified that with \fBscrollok\fR +enabled, any window modification triggering a scroll also forced a physical +refresh. XSI Curses does not require this, and \fBcurses\fR avoids doing +it in order to perform better vertical-motion optimization at \fBwrefresh\fR +time. +.SH NOTES +Note that \fBclearok\fR, \fBleaveok\fR, \fBscrollok\fR, \fBidcok\fR, \fBnl\fR, +\fBnonl\fR and \fBsetscrreg\fR may be macros. + +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_overlay.3 b/lib/libcurses/curs_overlay.3 new file mode 100644 index 00000000000..0c7b93df37f --- /dev/null +++ b/lib/libcurses/curs_overlay.3 @@ -0,0 +1,46 @@ +.TH curs_overlay 3X "" +.SH NAME +\fBoverlay\fR, \fBoverwrite\fR, \fBcopywin\fR - overlay and +manipulate overlapped \fBcurses\fR windows +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint overlay(const WINDOW *srcwin, WINDOW *dstwin);\fR +.br +\fBint overwrite(const WINDOW *srcwin, WINDOW *dstwin);\fR +.br +\fBint copywin(WINDOW *srcwin, WINDOW *dstwin, int sminrow, + int smincol, int dminrow, int dmincol, int dmaxrow, + int dmaxcol, int overlay);\fR +.SH DESCRIPTION +The \fBoverlay\fR and \fBoverwrite\fR routines overlay \fIsrcwin\fR on +top of \fIdstwin\fR. \fIscrwin\fR and \fIdstwin\fR are not required +to be the same size; only text where the two windows overlap is +copied. The difference is that \fBoverlay\fR is non-destructive +(blanks are not copied) whereas \fBoverwrite\fR is destructive. + +The \fBcopywin\fR routine provides a finer granularity of control over the +\fBoverlay\fR and \fBoverwrite\fR routines. Like in the \fBprefresh\fR +routine, a rectangle is specified in the destination window, (\fIdminrow\fR, +\fIdmincol\fR) and (\fIdmaxrow\fR, \fIdmaxcol\fR), and the upper-left-corner +coordinates of the source window, (\fIsminrow\fR, \fIsmincol\fR). If the +argument \fIoverlay\fR is \fBtrue\fR, then copying is non-destructive, as in +\fBoverlay\fR. +.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 +completion. +.SH NOTES +Note that \fBoverlay\fR and \fBoverwrite\fR may be macros. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_pad.3 b/lib/libcurses/curs_pad.3 new file mode 100644 index 00000000000..18969c94e3e --- /dev/null +++ b/lib/libcurses/curs_pad.3 @@ -0,0 +1,82 @@ +.TH curs_pad 3X "" +.SH NAME +\fBnewpad\fR, \fBsubpad\fR, \fBprefresh\fR, +\fBpnoutrefresh\fR, \fBpechochar\fR - create and display \fBcurses\fR +pads +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBWINDOW *newpad(int nlines, int ncols);\fR +.br +\fBWINDOW *subpad(WINDOW *orig, int nlines, int ncols, + int begin_y, int begin_x);\fR +.br +\fBint prefresh(WINDOW *pad, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol);\fR +.br +\fBint pnoutrefresh(WINDOW *pad, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol);\fR +.br +\fBint pechochar(WINDOW *pad, chtype ch);\fR +.SH DESCRIPTION +The \fBnewpad\fR routine creates and returns a pointer to a new pad data +structure with the given number of lines, \fInlines\fR, and columns, +\fIncols\fR. A pad is like a window, except that it is not restricted by the +screen size, and is not necessarily associated with a particular part of the +screen. Pads can be used when a large window is needed, and only a part of the +window will be on the screen at one time. Automatic refreshes of pads +(\fIe\fR.\fIg\fR., from scrolling or echoing of input) do not occur. It is not +legal to call \fBwrefresh\fR with a \fIpad\fR as an argument; the routines +\fBprefresh\fR or \fBpnoutrefresh\fR should be called instead. Note that these +routines require additional parameters to specify the part of the pad to be +displayed and the location on the screen to be used for the display. + +The \fBsubpad\fR routine creates and returns a pointer to a subwindow within a +pad with the given number of lines, \fInlines\fR, and columns, \fIncols\fR. +Unlike \fBsubwin\fR, which uses screen coordinates, the window is at position +(\fIbegin\fR_\fIx\fR\fB,\fR \fIbegin\fR_\fIy\fR) on the pad. The window is +made in the middle of the window \fIorig\fR, so that changes made to one window +affect both windows. During the use of this routine, it will often be +necessary to call \fBtouchwin\fR or \fBtouchline\fR on \fIorig\fR before +calling \fBprefresh\fR. + +The \fBprefresh\fR and \fBpnoutrefresh\fR routines are analogous to +\fBwrefresh\fR and \fBwnoutrefresh\fR except that they relate to pads instead +of windows. The additional parameters are needed to indicate what part of the +pad and screen are involved. \fIpminrow\fR and \fIpmincol\fR specify the upper +left-hand corner of the rectangle to be displayed in the pad. \fIsminrow\fR, +\fIsmincol\fR, \fIsmaxrow\fR, and \fIsmaxcol\fR specify the edges of the +rectangle to be displayed on the screen. The lower right-hand corner of the +rectangle to be displayed in the pad is calculated from the screen coordinates, +since the rectangles must be the same size. Both rectangles must be entirely +contained within their respective structures. Negative values of +\fIpminrow\fR, \fIpmincol\fR, \fIsminrow\fR, or \fIsmincol\fR are treated as if +they were zero. + +The \fBpechochar\fR routine is functionally equivalent to a call to \fBaddch\fR +followed by a call to \fBrefresh\fR, a call to \fBwaddch\fR followed by a call +to \fBwrefresh\fR, or a call to \fBwaddch\fR followed by a call to +\fBprefresh.\fR The knowledge that only a single character is being output is +taken into consideration and, for non-control characters, a considerable +performance gain might be seen by using these routines instead of their +equivalents. In the case of \fBpechochar\fR, the last location of the pad on +the screen is reused for the arguments to \fBprefresh\fR. +.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 +completion. + +Routines that return pointers return \fBNULL\fR on error, and set \fBerrno\fR +to \fBENOMEM\fR. +.SH NOTES +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_printw.3 b/lib/libcurses/curs_printw.3 new file mode 100644 index 00000000000..c6db4c099ce --- /dev/null +++ b/lib/libcurses/curs_printw.3 @@ -0,0 +1,47 @@ +.TH curs_printw 3X "" +.SH NAME +\fBprintw\fR, \fBwprintw\fR, \fBmvprintw\fR, +\fBmvwprintw\fR, \fBvwprintw\fR - print formatted output in +\fBcurses\fR windows +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint printw(char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint wprintw(WINDOW *win, char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint mvprintw(int y, int x, char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint mvwprintw(WINDOW *win, int y, int x, + \fBchar *fmt\fR [\fB, arg]\fR ...); + +\fB#include <varargs.h>\fR +.br +\fBint vwprintw(WINDOW *win, char *fmt, varglist);\fR +.br +.SH DESCRIPTION +The \fBprintw\fR, \fBwprintw\fR, \fBmvprintw\fR and \fBmvwprintw\fR +routines are analogous to \fBprintf\fR [see \fBprintf\fR(3S)]. In +effect, the string that would be output by \fBprintf\fR is output +instead as though \fBwaddstr\fR were used on the given window. + +The \fBvwprintw\fR routine is analogous to \fBvprintf\fR [see +\fBprintf\fR(3S)] and performs a \fBwprintw\fR using a variable +argument list. The third argument is a \fBva_list\fR, a pointer to a +list of arguments, as defined in \fB<varargs.h>\fR. +.SH RETURN VALUE +Routines that return an integer return \fBERR\fR upon failure and \fBOK\fR +(SVr4 onlyspecifies "an integer value other than \fBERR\fR") upon successful +completion. +.SH PORTABILITY +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 +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_refresh.3 b/lib/libcurses/curs_refresh.3 new file mode 100644 index 00000000000..77bae2eeb90 --- /dev/null +++ b/lib/libcurses/curs_refresh.3 @@ -0,0 +1,84 @@ +.TH curs_refresh 3X "" +.SH NAME +\fBrefresh\fR, \fBwrefresh\fR, \fBwnoutrefresh\fR, +\fBdoupdate\fR, \fBredrawwin\fR, \fBwredrawln\fR - refresh +\fBcurses\fR windows and lines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint refresh(void);\fR +.br +\fBint wrefresh(WINDOW *win);\fR +.br +\fBint wnoutrefresh(WINDOW *win);\fR +.br +\fBint doupdate(void);\fR +.br +\fBint redrawwin(WINDOW *win);\fR +.br +\fBint wredrawln(WINDOW *win, int beg_line, int num_lines);\fR +.br +.SH DESCRIPTION +The \fBrefresh\fR and \fBwrefresh\fR routines (or \fBwnoutrefresh\fR and +\fBdoupdate\fR) must be called to get actual output to the terminal, as other +routines merely manipulate data structures. The routine \fBwrefresh\fR copies +the named window to the physical terminal screen, taking into account what is +already there in order to do optimizations. The \fBrefresh\fR routine is the +same, using \fBstdscr\fR as the default window. Unless \fBleaveok\fR has been +enabled, the physical cursor of the terminal is left at the location of the +cursor for that window. + +The \fBwnoutrefresh\fR and \fBdoupdate\fR routines allow multiple updates with +more efficiency than \fBwrefresh\fR alone. In addition to all the window +structures, \fBcurses\fR keeps two data structures representing the terminal +screen: a physical screen, describing what is actually on the screen, and a +virtual screen, describing what the programmer wants to have on the screen. + +The routine \fBwrefresh\fR works by first calling \fBwnoutrefresh\fR, which +copies the named window to the virtual screen, and then calling \fBdoupdate\fR, +which compares the virtual screen to the physical screen and does the actual +update. If the programmer wishes to output several windows at once, a series +of calls to \fBwrefresh\fR results in alternating calls to \fBwnoutrefresh\fR +and \fBdoupdate\fR, causing several bursts of output to the screen. By first +calling \fBwnoutrefresh\fR for each window, it is then possible to call +\fBdoupdate\fR once, resulting in only one burst of output, with fewer total +characters transmitted and less CPU time used. If the \fIwin\fR argument to +\fBwrefresh\fR is the global variable \fBcurscr\fR, the screen is immediately +cleared and repainted from scratch. + +The phrase "copies the named window to the virtual screen" above is ambiguous. +What actually happens is that all \fItouched\fR (changed) lines in the window +are copied to the virtual screen. This affects programs that use overlapping +windows; it means that if two windows overlap, you can refresh them in either +order and the overlap region will be modified only when it is explicitly +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. +.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 +completion. +.SH NOTES +Note that \fBrefresh\fR and \fBredrawwin\fR may be macros. +.SH PORTABILITY +The XSI Curses standard, Issue 4 describes these functions. + +Whether \fBwnoutrefresh()\fR copies to the virtual screen the entire contents +of a window or just its changed portions has never been well-documented in +historic curses versions (including SVr4). It might be unwise to rely on +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_scanw.3 b/lib/libcurses/curs_scanw.3 new file mode 100644 index 00000000000..6ce1c0d2f84 --- /dev/null +++ b/lib/libcurses/curs_scanw.3 @@ -0,0 +1,48 @@ +.TH curs_scanw 3X "" +.SH NAME +\fBscanw\fR, \fBwscanw\fR, \fBmvscanw\fR, +\fBmvwscanw\fR, \fBvwscanw\fR - convert formatted input from a +\fBcurses\fR widow +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint scanw(char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint wscanw(WINDOW *win, char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint mvscanw(int y, int x, char *fmt\fR [\fB, arg\fR] \fB...);\fR +.br +\fBint mvwscanw(WINDOW *win, int y, int x, + char *fmt\fR [\fB, arg]\fR \fB...);\fR +.br +\fBint vwscanw(WINDOW *win, char *fmt, va_list varglist);\fR +.SH DESCRIPTION +The \fBscanw\fR, \fBwscanw\fR and \fBmvscanw\fR routines are analogous to +\fBscanf\fR [see \fBscanf\fR(3S)]. The effect of these routines is as though +\fBwgetstr\fR were called on the window, and the resulting line used as input +for \fBsscanf\fR(3). Fields which do not map to a variable in the \fIfmt\fR +field are lost. + +The \fBvwscanw\fR routine is similar to \fBvwprintw\fR in that it performs a +\fBwscanw\fR using a variable argument list. The third argument is a +\fIva\fR_\fIlist\fR, a pointer to a list of arguments, as defined in +\fB<varargs.h>\fR. +.SH RETURN VALUE +\fBvwscanw\fR returns \fBERR\fR on failure and an integer equal to the +number of fields scanned on success. + +Applications may use the return value from the \fBscanw\fR, \fBwscanw\fR, +\fBmvscanw\fR and \fBmvwscanw\fR routines to determine the number of fields +which were mapped in the call. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_scr_dmp.3 b/lib/libcurses/curs_scr_dmp.3 new file mode 100644 index 00000000000..c1b89f12059 --- /dev/null +++ b/lib/libcurses/curs_scr_dmp.3 @@ -0,0 +1,64 @@ +.TH curs_scr_dump 3X "" +.SH NAME +\fBscr_dump\fR, \fBscr_restore\fR, +\fBscr_init\fR, \fBscr_set\fR - read (write) a \fBcurses\fR screen +from (to) a file +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint scr_dump(const char *filename);\fR +.br +\fBint scr_restore(const char *filename);\fR +.br +\fBint scr_init(const char *filename);\fR +.br +\fBint scr_set(const char *filename);\fR +.br +.SH DESCRIPTION +The \fBscr_dump\fR routine dumps the current contents of the virtual screen +to the file \fIfilename\fR. + +The \fBscr_restore\fR routine sets the virtual screen to the contents +of \fIfilename\fR, which must have been written using \fBscr_dump\fR. The next +call to \fBdoupdate\fR restores the screen to the way it looked in the dump +file. + +The \fBscr_init\fR routine reads in the contents of \fIfilename\fR and uses +them to initialize the \fBcurses\fR data structures about what the terminal +currently has on its screen. If the data is determined to be valid, +\fBcurses\fR bases its next update of the screen on this information rather +than clearing the screen and starting from scratch. \fBscr_init\fR is used +after \fBinitscr\fR or a \fBsystem\fR [see \fBsystem\fR(BA_LIB)] call to share +the screen with another process which has done a \fBscr_dump\fR after its +\fBendwin\fR call. The data is declared invalid if the terminfo capabilities +\fBrmcup\fR and \fBnrrmc\fR exist; also if the terminal has been written to +since the preceding \fBscr_dump\fR call. + +The \fBscr_set\fR routine is a combination of \fBscr_restore\fR and +\fBscr_init\fR. It tells the program that the information in \fIfilename\fR is +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)]. +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and \fBOK\fR +upon success. +.SH NOTES +Note that \fBscr_init\fR, \fBscr_set\fR, and \fBscr_restore\fR may be macros. +.SH PORTABILITY +The XSI Curses standard, Issue 4, describes these functions (adding the const +qualifiers). + +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_scroll.3 b/lib/libcurses/curs_scroll.3 new file mode 100644 index 00000000000..0ac518d5b25 --- /dev/null +++ b/lib/libcurses/curs_scroll.3 @@ -0,0 +1,49 @@ +.TH curs_scroll 3X "" +.SH NAME +\fBscroll\fR, \fBsrcl\fR, \fBwscrl\fR - scroll a \fBcurses\fR window +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint scroll(WINDOW *win);\fR +.br +\fBint scrl(int n);\fR +.br +\fBint wscrl(WINDOW *win, int n);\fR +.br +.SH DESCRIPTION +The \fBscroll\fR routine scrolls the window up one line. This involves moving +the lines in the window data structure. As an optimization, if the scrolling +region of the window is the entire screen, the physical screen may be scrolled +at the same time. + +For positive \fIn\fR, the \fBscrl\fR and \fBwscrl\fR routines scroll the +window up \fIn\fR lines (line \fIi\fR+\fIn\fR becomes \fIi\fR); otherwise +scroll the window down \fIn\fR lines. This involves moving the lines in the +window character image structure. The current cursor position is not changed. + +For these functions to work, scrolling must be enabled via \fBscrollok\fR. +.SH RETURN VALUE +These routines return \fBERR\fR upon failure, and \fBOK\fR (SVr4 only specifies +"an integer value other than \fBERR\fR") upon successful completion. +.SH NOTES +Note that \fBscrl\fR and \fBscroll\fR may be macros. + +The SVr4 documentation says that the optimization of physically scrolling +immediately if the scroll region is the entire screen "is" performed, not +"may be" performed. This implementation deliberately does not guarantee +that this will occur, in order to leave open the possibility of smarter +optimization of multiple scroll actions on the next update. + +Neither the SVr4 documentation specifies whether the current attribute or +current color-pair of blanks generated by the scroll function is zeroed. +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_slk.3 b/lib/libcurses/curs_slk.3 new file mode 100644 index 00000000000..e735b9f2666 --- /dev/null +++ b/lib/libcurses/curs_slk.3 @@ -0,0 +1,91 @@ +.TH curs_slk 3X "" +.SH NAME +\fBslk_init\fR, \fBslk_set\fR, \fBslk_refresh\fR, +\fBslk_noutrefresh\fR, \fBslk_label\fR, \fBslk_clear\fR, \fBslk_restore\fR, +\fBslk_touch\fR, \fBslk_attron\fR, \fBslk_attrset\fR, \fBslk_attroff\fR - +\fBcurses\fR soft label routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint slk_init(int fmt);\fR +.br +\fBint slk_set(int labnum, const char *label, int fmt);\fR +.br +\fBint slk_refresh(void);\fR +.br +\fBint slk_noutrefresh(void);\fR +.br +\fBchar *slk_label(int labnum);\fR +.br +\fBint slk_clear(void);\fR +.br +\fBint slk_restore(void);\fR +.br +\fBint slk_touch(void);\fR +.br +\fBint slk_attron(attr_t attrs);\fR +.br +\fBint slk_attrset(attr_t attrs);\fR +.br +\fBint slk_attroff(attr_t attrs);\fR +.br +.SH DESCRIPTION +The slk* functions manipulate the set of soft function-key labels that exist on +many terminals. For those terminals that do not have soft labels, +\fBcurses\fR takes over the bottom line of \fBstdscr\fR, reducing the size of +\fBstdscr\fR and the variable \fBLINES\fR. \fBcurses\fR standardizes on eight +labels of up to eight characters each. + +The \fBslk_init\fR routine must be called before \fBinitscr\fR or \fBnewterm\fR +is called. If \fBinitscr\fR eventually uses a line from \fBstdscr\fR to +emulate the soft labels, then \fIfmt\fR determines how the labels are arranged +on the screen. Setting \fIfmt\fR to \fB0\fR indicates a 3-2-3 arrangement of +the labels; \fB1\fR indicates a 4-4 arrangement. + +The \fBslk_set\fR routine requires \fIlabnum\fR to be a label number, +from \fB1\fR to \fB8\fR; \fIlabel\fR must be the string to be put on the +label, up to eight characters in length. A null string or a null +pointer sets up a blank label. \fIfmt\fR is either \fB0\fR, \fB1\fR, +or \fB2\fR, indicating whether the label is to be left-justified, +centered, or right-justified, respectively, within the label. + +The \fBslk_refresh\fR and \fBslk_noutrefresh\fR routines correspond to +the \fBwrefresh\fR and \fBwnoutrefresh\fR routines. + +The \fBslk_label\fR routine returns the current label for label number +\fIlabnum\fR, with leading and trailing blanks stripped. + +The \fBslk_clear\fR routine clears the soft labels from the screen. + +The \fBslk_restore\fR routine, restores the soft labels to the screen +after a \fBslk_clear\fR has been performed. + +The \fBslk_touch\fR routine forces all the soft labels to be output +the next time a \fBslk_noutrefresh\fR is performed. + +The \fBslk_attron\fR, \fBslk_attrset\fR and \fBslk_attroff\fR routines +correspond to \fBattron\fR, \fBattrset\fR, and \fBattroff\fR. They +have an effect only if soft labels are simulated on the bottom line of +the screen. The default highlight for soft keys is A_STANDOUT (as in +System V curses, which does not document this fact). +.SH RETURN VALUE +These routines return \fBERR\fR upon failure and OK (SVr4 specifies only "an +integer value other than \fBERR\fR") upon successful completion. + +\fBslk_label\fR returns \fBNULL\fR on error. +.SH NOTES +Most applications would use \fBslk_noutrefresh\fR because a +\fBwrefresh\fR is likely to follow soon. +.SH PORTABILITY +The XSI Curses standard, Issue 4, describes these functions. It changes the +argument type of the attribute-manipulation functions \fBslk_attron\fR, +\fBslk_attroff\fR, \fBslk_attrset\fR to be \fBattr_t\fR, and adds \fBconst\fR +qualifiers. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_attr\fR(3X), \fBcurs_initscr\fR(3X), \fBcurs_refresh\fR(3X) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_termattrs.3 b/lib/libcurses/curs_termattrs.3 new file mode 100644 index 00000000000..5c65d3c573e --- /dev/null +++ b/lib/libcurses/curs_termattrs.3 @@ -0,0 +1,78 @@ +.TH curs_termattrs 3X "" +.SH NAME +\fBbaudrate\fR, \fBerasechar\fR, \fBhas_ic\fR, +\fBhas_il\fR, \fBkillchar\fR, \fBlongname\fR, \fBtermattrs\fR, +\fBtermname\fR - \fBcurses\fR environment query routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBint baudrate(void);\fR +.br +\fBchar erasechar(void);\fR +.br +\fBint has_ic(void);\fR +.br +\fBint has_il(void);\fR +.br +\fBchar killchar(void);\fR +.br +\fBchar *longname(void);\fR +.br +\fBattr_t termattrs(void);\fR +.br +\fBchar *termname(void);\fR +.br +.SH DESCRIPTION +The \fBbaudrate\fR routine returns the output speed of the terminal. The +number returned is in bits per second, for example \fB9600\fR, and is an +integer. + +The \fBerasechar\fR routine returns the user's current erase character. + +The \fBhas_ic\fR routine is true if the terminal has insert- and delete- +character capabilities. + +The \fBhas_il\fR routine is true if the terminal has insert- and delete-line +capabilities, or can simulate them using scrolling regions. This might +be used to determine if it would be appropriate to turn on physical +scrolling using \fBscrollok\fR. + +The \fBkillchar\fR routine returns the user's current line kill character. + +The \fBlongname\fR routine returns a pointer to a static area +containing a verbose description of the current terminal. The maximum +length of a verbose description is 128 characters. It is defined only +after the call to \fBinitscr\fR or \fBnewterm\fR. The area is +overwritten by each call to \fBnewterm\fR and is not restored by +\fBset_term\fR, so the value should be saved between calls to +\fBnewterm\fR if \fBlongname\fR is going to be used with multiple +terminals. + +If a given terminal doesn't support a video attribute that an +application program is trying to use, \fBcurses\fR may substitute a +different video attribute for it. The \fBtermattrs\fR function +returns a logical \fBOR\fR of all video attributes supported by the +terminal. This information is useful when a \fBcurses\fR program +needs complete control over the appearance of the screen. + +The \fBtermname\fR routine returns the value of the environmental +variable \fBTERM\fR (truncated to 14 characters). +.SH RETURN VALUE +\fBlongname\fR and \fBtermname\fR return \fBNULL\fR on error. + +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 +completion. +.SH NOTES +Note that \fBtermattrs\fR may be a macro. +.SH PORTABILITY +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_touch.3 b/lib/libcurses/curs_touch.3 new file mode 100644 index 00000000000..961ccbe66da --- /dev/null +++ b/lib/libcurses/curs_touch.3 @@ -0,0 +1,64 @@ +.TH curs_touch 3X "" +.SH NAME +\fBtouchwin\fR, \fBtouchline\fR, \fBuntouchwin\fR, +\fBwtouchln\fR, \fBis_linetouched\fR, \fBis_wintouched\fR - +\fBcurses\fR refresh control routines +.SH SYNOPSIS +\fB#include <curses.h>\fR +.br +\fBint touchwin(WINDOW *win);\fR +.br +\fBint touchline(WINDOW *win, int start, int count);\fR +.br +\fBint untouchwin(WINDOW *win);\fR +.br +\fBint wtouchln(WINDOW *win, int y, int n, int changed);\fR +.br +\fBint is_linetouched(WINDOW *win, int line);\fR +.br +\fBint is_wintouched(WINDOW *win);\fR +.br +.SH DESCRIPTION +The \fBtouchwin\fR and \fBtouchline\fR routines throw away all +optimization information about which parts of the window have been +touched, by pretending that the entire window has been drawn on. This +is sometimes necessary when using overlapping windows, since a change +to one window affects the other window, but the records of which lines +have been changed in the other window do not reflect the change. The +routine \fBtouchline\fR only pretends that \fIcount\fR lines have been +changed, beginning with line \fIstart\fR. + +The \fBuntouchwin\fR routine marks all lines in the window as unchanged since +the last call to \fBwrefresh\fR. + +The \fBwtouchln\fR routine makes \fIn\fR lines in the window, starting +at line \fIy\fR, look as if they have (\fIchanged\fR\fB=1\fR) or have +not (\fIchanged\fR\fB=0\fR) been changed since the last call to +\fBwrefresh\fR. + +The \fBis_linetouched\fR and \fBis_wintouched\fR routines return +\fBTRUE\fR if the specified line/window was modified since the last +call to \fBwrefresh\fR; otherwise they return \fBFALSE\fR. In +addition, \fBis_linetouched\fR returns \fBERR\fR if \fIline\fR is not +valid for the given window. +.SH RETURN VALUE +All routines return the integer \fBERR\fR upon failure and an integer value +other than \fBERR\fR upon successful completion, unless otherwise noted in the +preceding routine descriptions. +.SH PORTABILITY +The XSI Curses standard, Issue 4 describes these functions. + +Some historic curses implementations had, as an undocumented feature, the +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 NOTES +Note that all routines except \fBwtouchln\fR may be macros. +.SH SEE ALSO +\fBcurses\fR(3X), \fBcurs_refresh\fR(3X). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_util.3 b/lib/libcurses/curs_util.3 new file mode 100644 index 00000000000..0d2e0b88b74 --- /dev/null +++ b/lib/libcurses/curs_util.3 @@ -0,0 +1,85 @@ +.TH curs_util 3X "" +.SH NAME +\fBunctrl\fR, \fBkeyname\fR, \fBfilter\fR, +\fBuse_env\fR, \fBputwin\fR, \fBgetwin\fR, \fBdelay_output\fR, +\fBflushinp\fR - miscellaneous \fBcurses\fR utility routines +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBchar *unctrl(chtype c);\fR +.br +\fBchar *keyname(int c);\fR +.br +\fBvoid filter(void);\fR +.br +\fBvoid use_env(char bool);\fR +.br +\fBint putwin(WINDOW *win, FILE *filep);\fR +.br +\fBWINDOW *getwin(FILE *filep);\fR +.br +\fBint delay_output(int ms);\fR +.br +\fBint flushinp(void);\fR +.br +.SH DESCRIPTION +The \fBunctrl\fR macro expands to a character string which is a printable +representation of the character \fIc\fR. Control characters are displayed in +the \fB^\fR\fIX\fR notation. Printing characters are displayed as is. + +The \fBkeyname\fR routine returns a character string corresponding to +the key \fIc\fR. + +The \fBfilter\fR routine, if used, must be called before \fBinitscr\fR or +\fBnewterm\fR are called. The effect is that, during those calls, \fBLINES\fR +is set to 1; the capabilities \fBclear\fR, \fBcup\fR, \fBcud\fR, \fBcud1\fR, +\fBcuu1\fR, \fBcuu\fR, \fBvpa\fR are disabled; and the \fBhome\fR string is +set to the value of \fBcr\fR. + +The \fBuse_env\fR routine, if used, is called before \fBinitscr\fR or +\fBnewterm\fR are called. When called with \fBFALSE\fR as an +argument, the values of \fBlines\fR and \fBcolumns\fR specified in the +\fIterminfo\fR database will be used, even if environment variables +\fBLINES\fR and \fBCOLUMNS\fR (used by default) are set, or if +\fBcurses\fR is running in a window (in which case default behavior +would be to use the window size if \fBLINES\fR and \fBCOLUMNS\fR are +not set). + +The \fBputwin\fR routine writes all data associated with window \fIwin\fR into +the file to which \fIfilep\fR points. This information can be later retrieved +using the \fBgetwin\fR function. + +The \fBgetwin\fR routine reads window related data stored in the file by +\fBputwin\fR. The routine then creates and initializes a new window using that +data. It returns a pointer to the new window. + +The \fBdelay_output\fR routine inserts an \fIms\fR millisecond pause +in output. This routine should not be used extensively because +padding characters are used rather than a CPU pause. + +The \fBflushinp\fR routine throws away any typeahead that has been typed by the +user and has not yet been read by the program. +.SH RETURN VALUE +Except for \fBflushinp\fR, routines that return an integer return \fBERR\fR +upon failure and \fBOK\fR (SVr4 specifies only "an integer value other than +\fBERR\fR") upon successful completion. + +\fBflushinp\fR always returns \fBOK\fR. + +Routines that return pointers return \fBNULL\fR on error. +.SH PORTABILITY +The XSI Curses standard, Issue 4 describes these functions. + +The SVr4 documentation describes the action of \fBfilter\fR only in the vaguest +terms. The description here is adapted from the XSI Curses standard (which +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). +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curs_window.3 b/lib/libcurses/curs_window.3 new file mode 100644 index 00000000000..9bd3facd818 --- /dev/null +++ b/lib/libcurses/curs_window.3 @@ -0,0 +1,123 @@ +.TH curs_window 3X "" +.SH NAME +\fBnewwin\fR, \fBdelwin\fR, \fBmvwin\fR, +\fBsubwin\fR, \fBderwin\fR, \fBmvderwin\fR, \fBdupwin\fR, +\fBwsyncup\fR, \fBsyncok\fR, \fBwcursyncup\fR, \fBwsyncdown\fR - +create \fBcurses\fR windows +.SH SYNOPSIS +\fB#include <curses.h>\fR + +\fBWINDOW *newwin(int nlines, int ncols, int begin_y,\fR + \fBintbegin_x);\fR +.br +\fBint delwin(WINDOW *win);\fR +.br +\fBint mvwin(WINDOW *win, int y, int x);\fR +.br +\fBWINDOW *subwin(WINDOW *orig, int nlines, int ncols, + int begin_y, int begin_x);\fR +.br +\fBWINDOW *derwin(WINDOW *orig, int nlines, int ncols, + int begin_y, int begin_x);\fR +.br +\fBint mvderwin(WINDOW *win, int par_y, int par_x);\fR +.br +\fBWINDOW *dupwin(WINDOW *win);\fR +.br +\fBvoid wsyncup(WINDOW *win);\fR +.br +\fBint syncok(WINDOW *win, bool bf);\fR +.br +\fBvoid wcursyncup(WINDOW *win);\fR +.br +\fBvoid wsyncdown(WINDOW *win);\fR +.br +.SH DESCRIPTION +Calling \fBnewwin\fR creates and returns a pointer to a new window with the +given number of lines and columns. The upper left-hand corner of the window is +at line \fIbegin\fR_\fIy\fR, column \fIbegin\fR_\fIx\fR. If either +\fInlines\fR or \fIncols\fR is zero, they default to \fBLINES -\fR +\fIbegin\fR_\fIy\fR and \fBCOLS -\fR \fIbegin\fR_\fIx\fR. A new full-screen +window is created by calling \fBnewwin(0,0,0,0)\fR. + +Calling \fBdelwin\fR deletes the named window, freeing all memory +associated with it (it does not actually erase the window's screen +image). Subwindows must be deleted before the main window can be +deleted. + +Calling \fBmvwin\fR moves the window so that the upper left-hand +corner is at position (\fIx\fR, \fIy\fR). If the move would cause the +window to be off the screen, it is an error and the window is not +moved. Moving subwindows is allowed, but should be avoided. + +Calling \fBsubwin\fR creates and returns a pointer to a new window +with the given number of lines, \fInlines\fR, and columns, +\fIncols\fR. The window is at position (\fIbegin\fR_\fIy\fR, +\fIbegin\fR_\fIx\fR) on the screen. (This position is relative to the +screen, and not to the window \fIorig\fR.) The window is made in the +middle of the window \fIorig\fR, so that changes made to one window +will affect both windows. The subwindow shares memory with the window +\fIorig\fR. When using this routine, it is necessary to call +\fBtouchwin\fR or \fBtouchline\fR on \fIorig\fR before calling +\fBwrefresh\fR on the subwindow. + +Calling \fBderwin\fR is the same as calling \fBsubwin,\fR except that +\fIbegin\fR_\fIy\fR and \fIbegin\fR_\fIx\fR are relative to the origin +of the window \fIorig\fR rather than the screen. There is no +difference between the subwindows and the derived windows. + +Calling \fBmvderwin\fR moves a derived window (or subwindow) +inside its parent window. The screen-relative parameters of the +window are not changed. This routine is used to display different +parts of the parent window at the same physical position on the +screen. + +Calling \fBdupwin\fR creates an exact duplicate of the window \fIwin\fR. + +Calling \fBwsyncup\fR touches all locations in ancestors of \fIwin\fR that are +changed in \fIwin\fR. If \fBsyncok\fR is called with second argument +\fBTRUE\fR then \fBwsyncup\fR is called automatically whenever there is a +change in the window. + +The \fBwsyncdown\fR routine touches each location in \fIwin\fR that has been +touched in any of its ancestor windows. This routine is called by +\fBwrefresh\fR, so it should almost never be necessary to call it manually. + +The routine \fBwcursyncup\fR updates the current cursor position of all the +ancestors of the window to reflect the current cursor position of the +window. +.SH RETURN VALUE +Routines that return an integer return the integer \fBERR\fR upon failure and +\fBOK\fR (SVr4 only specifies "an integer value other than \fBERR\fR") upon +successful completion. + +\fBdelwin\fR returns the integer \fBERR\fR upon failure and \fBOK\fR +upon successful completion. + +Routines that return pointers return \fBNULL\fR on error. +.SH NOTES +If many small changes are made to the window, the \fBwsyncup\fR option could +degrade performance. + +Note that \fBsyncok\fR may be a macro. +.SH BUGS +The subwindow functions (\fIsubwin\fR, \fIderwin\fR, \fImvderwin\fR, +\fBwsyncup\fR, \fBwsyncdown\fR, \fBwcursyncup\fR, \fBsyncok\fR) are flaky, +incompletely implemented, and not well tested. + +The System V curses documentation is very unclear about what \fBwsyncup\fR +and \fBwsyncdown\fR actually do. It seems to imply that they are only +supposed to touch exactly those lines that are affected by ancestor changes. +The language here, and the behavior of the \fBcurses\fR implementation, +is patterned on the XPG4 curses standard. The weaker XPG4 spec may result +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) +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curses.3 b/lib/libcurses/curses.3 index ea0093b61ad..a47086d4871 100644 --- a/lib/libcurses/curses.3 +++ b/lib/libcurses/curses.3 @@ -1,197 +1,608 @@ -.\" Copyright (c) 1985, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)curses.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt CURSES 3 -.Os BSD 4 -.Sh NAME -.Nm curses -.Nd screen functions with ``optimal'' cursor motion -.Sh SYNOPSIS -.Nm cc -.Op Ar flags -.Ar files -.Fl lcurses ltermcap -.Op Ar libraries -.Sh DESCRIPTION -These routines give the user a method of updating screens with reasonable -optimization. They keep an image of the current screen, -and the user sets up an image of a new one. Then the -.Fn refresh -tells the routines to make the current screen look like the new one. -In order to initialize the routines, the routine -.Fn initscr -must be called before any of the other routines that deal with windows and -screens are used. The routine -.Fn endwin -should be called before exiting. -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr getenv 3 , -.Xr tty 4 , -.Xr termcap 5 -.Rs -.%T Screen Updating and Cursor Movement Optimization: A Library Package -.%A Ken Arnold -.Re -.Sh AUTHOR -.An Ken Arnold -.Sh FUNCTIONS -.Bl -column "subwin(win,lines,cols,begin_y,begin_x) " -.It addch(ch) add a character to -.Em stdscr -.It addstr(str) add a string to -.Em stdscr -.It box(win,vert,hor) draw a box around a window -.It cbreak() set cbreak mode -.It clear() clear -.Em stdscr -.It clearok(scr,boolf) set clear flag for -.Em scr -.It clrtobot() clear to bottom on -.Em stdscr -.It clrtoeol() clear to end of line on -.Em stdscr -.It delch() delete a character -.It deleteln() delete a line -.It delwin(win) delete -.Em stdscr -.It echo() set echo mode -.It endwin() end window modes -.It erase() erase -.Em stdscr -.It flusok(win,boolf) set flush-on-refresh flag for -.Em win -.It getch() get a char through -.Em stdscr -.It getcap(name) get terminal capability -.Em name -.It getstr(str) get a string through -.Em stdscr -.It gettmode() get tty modes -.It getyx(win,y,x) get (y,x) co-ordinates -.It inch() get char at current (y,x) co-ordinates -.It initscr() initialize screens -.It insch(c) insert a char -.It insertln() insert a line -.It leaveok(win,boolf) set leave flag for -.Em stdscr -.It longname(termbuf,name) get long name from -.Em termbuf -.It move(y,x) move to (y,x) on -.Em stdscr -.It mvcur(lasty,lastx,newy,newx) actually move cursor -.It newwin(lines,cols,begin_y,begin_x)\ create a new window -.It nl() set newline mapping -.It nocbreak() unset cbreak mode -.It noecho() unset echo mode -.It nonl() unset newline mapping -.It noraw() unset raw mode -.It overlay(win1,win2) overlay win1 on win2 -.It overwrite(win1,win2) overwrite win1 on top of win2 -.It printw(fmt,arg1,arg2,...) printf on -.Em stdscr -.It raw() set raw mode -.It refresh() make current screen look like -.Em stdscr -.It resetty() reset tty flags to stored value -.It savetty() stored current tty flags -.It scanw(fmt,arg1,arg2,...) scanf through -.Em stdscr -.It scroll(win) scroll -.Em win -one line -.It scrollok(win,boolf) set scroll flag -.It setterm(name) set term variables for name -.It standend() end standout mode -.It standout() start standout mode -.It subwin(win,lines,cols,begin_y,begin_x)\ create a subwindow -.It touchline(win,y,sx,ex) mark line -.Em y -.Em sx -through -.Em sy -as changed -.It touchoverlap(win1,win2) mark overlap of -.Em win1 -on -.Em win2 -as changed -.It touchwin(win) \*(lqchange\*(rq all of -.Em win -.It unctrl(ch) printable version of -.Em ch -.It waddch(win,ch) add char to -.Em win -.It waddstr(win,str) add string to -.Em win -.It wclear(win) clear -.Em win -.It wclrtobot(win) clear to bottom of -.Em win -.It wclrtoeol(win) clear to end of line on -.Em win -.It wdelch(win) delete char from -.Em win -.It wdeleteln(win) delete line from -.Em win -.It werase(win) erase -.Em win -.It wgetch(win) get a char through -.Em win -.It wgetstr(win,str) get a string through -.Em win -.It winch(win) get char at current (y,x) in -.Em win -.It winsch(win,c) insert char into -.Em win -.It winsertln(win) insert line into -.Em win -.It wmove(win,y,x) set current (y,x) co-ordinates on -.Em win -.It wprintw(win,fmt,arg1,arg2,...)\ printf on -.Em win -.It wrefresh(win) make screen look like -.Em win -.It wscanw(win,fmt,arg1,arg2,...)\ scanf through -.Em win -.It wstandend(win) end standout mode on -.Em win -.It wstandout(win) start standout mode on -.Em win -.El -.Sh HISTORY -The -.Nm -package appeared in -.Bx 4.0 . +.TH curses 3X "" +.ds n 5 +.ds d /usr/share/terminfo +.SH NAME +\fBcurses\fR - CRT screen handling and optimization package +.SH SYNOPSIS +\fB#include <curses.h>\fR +.br +.SH DESCRIPTION +The \fBcurses\fR library routines give the user a terminal-independent method +of updating character screens with reasonable optimization. This +implementation is ``new curses'' (ncurses) and is the approved replacement for +4.4BSD classic curses, which is being discontinued. + +The \fBcurses\fR routines emulate the \fBcurses\fR(3X) 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 +described in detail in the EXTENSIONS and BUGS sections of individual man +pages. + +A program using these routines must be linked with the \fB-lcurses\fR option. + +The \fBcurses\fR package supports: overall screen, window and pad +manipulation; output to windows and pads; reading terminal input; control over +terminal and \fBcurses\fR input and output options; environment query +routines; color manipulation; use of soft label keys; terminfo capabilities; +and access to low-level terminal-manipulation routines. + +To initialize the routines, the routine \fBinitscr\fR or \fBnewterm\fR +must be called before any of the other routines that deal with windows +and screens are used. The routine \fBendwin\fR must be called before +exiting. To get character-at-a-time input without echoing (most +interactive, screen oriented programs want this), the following +sequence should be used: + + \fBinitscr(); cbreak(); noecho();\fR + +Most programs would additionally use the sequence: + + \fBnonl();\fR + \fBintrflush(stdscr, FALSE);\fR + \fBkeypad(stdscr, TRUE);\fR + +Before a \fBcurses\fR program is run, the tab stops of the terminal +should be set and its initialization strings, if defined, must be +output. This can be done by executing the \fBtput init\fR command +after the shell environment variable \fBTERM\fR has been exported. +\fBtset(1)\fR is usually responsible for doing this. +[See \fBterminfo\fR(\*n) for further details.] + +The \fBcurses\fR library permits manipulation of data structures, +called \fIwindows\fR, which can be thought of as two-dimensional +arrays of characters representing all or part of a CRT screen. A +default window called \fBstdscr\fR, which is the size of the terminal +screen, is supplied. Others may be created with \fBnewwin\fR. + +Note that \fBcurses\fR does not handle overlapping windows, that's done by +the \fBpanels(3x)\fR library. This means that you can either use +\fBstdscr\fR or divide the screen into tiled windows and not using +\fBstdscr\fR at all. Mixing the two will result in unpredictable, and +undesired, effects. + +Windows are referred to by variables declared as \fBWINDOW *\fR. +These data structures are manipulated with routines described here and +elsewhere in the \fBcurses\fR manual pages. Among which the most basic +routines are \fBmove\fR and \fBaddch\fR. More general versions of +these routines are included with names beginning with \fBw\fR, +allowing the user to specify a window. The routines not beginning +with \fBw\fR affect \fBstdscr\fR.) + +After using routines to manipulate a window, \fBrefresh\fR is called, +telling \fBcurses\fR to make the user's CRT screen look like +\fBstdscr\fR. The characters in a window are actually of type +\fBchtype\fR, (character and attribute data) so that other information +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. + +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 +underlined, in reverse video, or in color on terminals that support such +display enhancements. Line drawing characters may be specified to be output. +On input, \fBcurses\fR is also able to translate arrow and function keys that +transmit escape sequences into single values. The video attributes, line +drawing characters, and input values use names, defined in \fB<curses.h>\fR, +such as \fBA_REVERSE\fR, \fBACS_HLINE\fR, and \fBKEY_LEFT\fR. + +If the environment variables \fBLINES\fR and \fBCOLUMNS\fR are set, or if the +program is executing in a window environment, line and column information in +the environment will override information read by \fIterminfo\fR. This would +effect a program running in an AT&T 630 layer, for example, where the size of a +screen is changeable. + +If the environment variable \fBTERMINFO\fR is defined, any program using +\fBcurses\fR checks for a local terminal definition before checking in the +standard place. For example, if \fBTERM\fR is set to \fBatt4424\fR, then the +compiled terminal definition is found in + + \fB\*d/a/att4424\fR. + +(The \fBa\fR is copied from the first letter of \fBatt4424\fR to avoid +creation of huge directories.) However, if \fBTERMINFO\fR is set to +\fB$HOME/myterms\fR, \fBcurses\fR first checks + + \fB$HOME/myterms/a/att4424\fR, + +and if that fails, it then checks + + \fB\*d/a/att4424\fR. + +This is useful for developing experimental definitions or when write +permission in \fB\*d\fR is not available. + +The integer variables \fBLINES\fR and \fBCOLS\fR are defined in +\fB<curses.h>\fR and will be filled in by \fBinitscr\fR with the size of the +screen. The constants \fBTRUE\fR and \fBFALSE\fR have the values \fB1\fR and +\fB0\fR, respectively. + +The \fBcurses\fR routines also define the \fBWINDOW *\fR variable \fBcurscr\fR +which is used for certain low-level operations like clearing and redrawing a +screen containing garbage. The \fBcurscr\fR can be used in only a few +routines. + +.SS Routine and Argument Names +Many \fBcurses\fR routines have two or more versions. The routines prefixed +with \fBw\fR require a window argument. The routines prefixed with \fBp\fR +require a pad argument. Those without a prefix generally use \fBstdscr\fR. + +The routines prefixed with \fBmv\fR require a \fIy\fR and \fIx\fR +coordinate to move to before performing the appropriate action. The +\fBmv\fR routines imply a call to \fBmove\fR before the call to the +other routine. The coordinate \fIy\fR always refers to the row (of +the window), and \fIx\fR always refers to the column. The upper +left-hand corner is always (0,0), not (1,1). + +The routines prefixed with \fBmvw\fR take both a window argument and +\fIx\fR and \fIy\fR coordinates. The window argument is always +specified before the coordinates. + +In each case, \fIwin\fR is the window affected, and \fIpad\fR is the +pad affected; \fIwin\fR and \fIpad\fR are always pointers to type +\fBWINDOW\fR. + +Option setting routines require a Boolean flag \fIbf\fR with the value +\fBTRUE\fR or \fBFALSE\fR; \fIbf\fR is always of type \fBbool\fR. The +variables \fIch\fR and \fIattrs\fR below are always of type +\fBchtype\fR. The types \fBWINDOW\fR, \fBSCREEN\fR, \fBbool\fR, and +\fBchtype\fR are defined in \fB<curses.h>\fR. The type \fBTERMINAL\fR +is defined in \fB<term.h>\fR. All other arguments are integers. + +.SS Routine Name Index +The following table lists each \fBcurses\fR routine and the name of +the manual page on which it is described. Routines flagged with `*' +are ncurses-specific, not described by XPG4 or present in SVr4. + +.nf +\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) +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) +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) +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_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) +wresize curs_resize(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) +.fi +.SH RETURN VALUE +Routines that return an integer return \fBERR\fR upon failure and an +integer value other than \fBERR\fR upon successful completion, unless +otherwise noted in the routine descriptions. + +All macros return the value of the \fBw\fR version, except \fBsetscrreg\fR, +\fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, \fBgetmaxyx\fR. The return +values of \fBsetscrreg\fR, \fBwsetscrreg\fR, \fBgetyx\fR, \fBgetbegyx\fR, and +\fBgetmaxyx\fR are undefined (\fIi\fR.\fIe\fR., these should not be used as the +right-hand side of assignment statements). + +Routines that return pointers return \fBNULL\fR on error. +.SH SEE ALSO +\fBterminfo\fR(\*n) and 3X pages whose names begin "curs_" for detailed routine +descriptions. +.SH EXTENSIONS +The \fBcurses\fR library can be compiled with an option (\fB-DTERMCAP_FILE\fR) +that falls back to the old-style /etc/termcap file if the terminal setup code +cannot find a terminfo entry corresponding to \fBTERM\fR. Use of this feature +is not recommended, as it essentially includes an entire termcap compiler in +the \fBcurses\fR startup code, at significant cost in core and startup cycles. + +Compiling with \fB-DTERMCAP_FILE\fR changes the library's initialization +sequence in a way intended to mimic the behavior of 4.4BSD curses. If there is +no local or system terminfo entry matching \fBTERM\fR, then the library looks +for termcap entries in the following places: (1) if \fBTERMINFO\fR is +undefined, in the file named by \fBTERMCAP_FILE\fR; (2) if \fBTERMINFO\fR is +defined and begins with a slash, it is interpreted as the name of a termcap +file to search for \fBTERM\fR; (3) otherwise, if \fBTERMINFO\fR has a leading +string that looks like a terminal entry name list, and it matches \fBTERM\fR, +the contents of \fBTERMINFO\fR is interpreted as a termcap; (4) if +\fBTERMINFO\fR looks like a termcap but doesn't match \fBTERM\fR, the termcap +file is searched for among the colon-separated paths in the environment +variable \fBTERMPATHS\fR if that is defined, and in ~/.termcap and the file +value of \fBTERMCAP_FILE\fR otherwise. + +Versions of \fBcurses\fR compiled on PC clones support display of the PC ROM +characters (including ROM characters 0-31, which stock SVr4 curses cannot +display). See the EXTENSIONS sections of \fBcurs_addch\fR(3x) and +\fBcurs_attr\fR(3x). +.SH PORTABILITY +The \fBcurses\fR library is intended to be BASE-level conformant with the XSI +Curses standard. Certain portions of the EXTENDED XSI Curses functionality +(including color support) are supported. The following EXTENDED XSI Curses +calls in support of wide (multibyte) characters are not yet implemented: +\fBaddnwstr\fB, +\fBaddwstr\fB, +\fBmvaddnwstr\fB, +\fBmvwaddnwstr\fB, +\fBmvaddwstr\fB, +\fBwaddnwstr\fB, +\fBwaddwstr\fB, +\fBadd_wch\fB, +\fBwadd_wch\fB, +\fBmvadd_wch\fB, +\fBmvwadd_wch\fB, +\fBadd_wchnstr\fB, +\fBadd_wchstr\fB, +\fBwadd_wchnstr\fB, +\fBwadd_wchstr\fB, +\fBmvadd_wchnstr\fB, +\fBmvadd_wchstr\fB, +\fBmvwadd_wchnstr\fB, +\fBmvwadd_wchstr\fB, +\fBbkgrndset\fB, +\fBbkgrnd\fB, +\fBgetbkgrnd\fB, +\fBwbkgrnd\fB, +\fBwbkgrndset\fB, +\fBwgetbkgrnd\fB, +\fBborder_set\fB, +\fBwborder_set\fB, +\fBbox_set\fB, +\fBhline_set\fB, +\fBmvhline_set\fB, +\fBmvvline_set\fB, +\fBmvwhline_set\fB, +\fBmvwvline_set\fB, +\fBwhline_set\fB, +\fBvhline_set\fB, +\fBwvline_set\fB, +\fBecho_wchar\fB, +\fBwecho_wchar\fB, +\fBerasewchar\fB, +\fBkillwchar\fB, +\fBget_wch\fB, +\fBmvget_wch\fB, +\fBmvwget_ch\fB, +\fBwget_wch\fB, +\fBgetwchtype\fB, +\fBget_wstr\fB, +\fBgetn_wstr\fB, +\fBwget_wstr\fB, +\fBwgetn_wstr\fB, +\fBmvget_wstr\fB, +\fBmvgetn_wstr\fB, +\fBmvwget_wstr\fB, +\fBmvwgetn_wstr\fB, +\fBinnwstr\fB, +\fBinwstr\fB, +\fBwinnwstr\fB, +\fBwinwstr\fB, +\fBmvinnwstr\fB, +\fBmvinwstr\fB, +\fBmvwinnwstr\fB, +\fBmvwinwstr\fB, +\fBins_nwstr\fB, +\fBins_wstr\fB, +\fBmvins_nwstr\fB, +\fBmvins_wstr\fB, +\fBmvwins_nwstr\fB, +\fBmvwins_wstr\fB, +\fBwins_nwstr\fB, +\fBwins_wstr\fB, +\fBins_wch\fB, +\fBwins_wch\fB, +\fBmvins_wch\fB, +\fBmvwins_wch\fB, +\fBin_wch\fB, +\fBwin_wch\fB, +\fBmvin_wch\fB, +\fBmvwin_wch\fB, +\fBinwchstr\fB, +\fBinwchnstr\fB, +\fBwinwchstr\fB, +\fBwinwchnstr\fB, +\fBmvinwchstr\fB, +\fBmvinwchnstr\fB, +\fBmvinwchstr\fB, +\fBmvwinwchnstr\fB. +.PP +A small number of local differences (that is, individual differences between +the XSI Curses and \fBcurses\fR calls) are described in \fBPORTABILITY\fR +sections of the library man pages. +.PP +The terminfo format supported by \fBcurses\fR is binary-compatible with SVr4, +but not conformant with XSI curses. This is because the XSI Curses drafters, +in a remarkable fit of braindamage, changed the undocumented SVr4 capability +\fBgetm\fR from a string to a boolean, changing the binary offsets of all +capabilities after it in the SVr4 order and making it impossible for any +SVr4-compatible implementation to be fully conformant. +.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) +manual page for details. +.PP +The routine \fBwresize\fR is not part of XPG4, nor is it present in SVr4. See +the \fBcurs_resize\fR(3X) 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 +bits in the UNIX tty driver. In this implementation, all padding is done by +NUL sends. This method is slightly more expensive, but narrows the interface +to the UNIX kernel significantly and increases the package's portability +correspondingly. +.PP +In the XSI standard and SVr4 manual pages, many entry points have prototype +arguments of the for \fBchar *const\fR (or \fBcchar_t *const\fR, or \fBwchar_t +*const\fR, or \fBvoid *const\fR). Depending on one's interpretation of the +ANSI C standard (see section 3.5.4.1), these declarations are either (a) +meaningless, or (b) meaningless and illegal. The declaration \fBconst char +*x\fR is a modifiable pointer to unmodifiable data, but \fBchar *const x\fR' is +an unmodifiable pointer to modifiable data. Given that C passes arguments by +value, \fB<type> *const\fR as a formal type is at best dubious. Some compilers +choke on the prototypes. Therefore, in this implementation, they have been +changed to \fBconst <type> *\fR globally. +.SH NOTES +The header file \fB<curses.h>\fR automatically includes the header files +\fB<stdio.h>\fR and \fB<unctrl.h>\fR. + +If standard output from a \fBcurses\fR program is re-directed to something +which is not a tty, screen updates will be directed to standard error. This +was an undocumented feature of AT&T System V Release 3 curses. +.SH AUTHORS +Zeyd M. Ben-Halim, Eric S. Raymond. Descends from the original pcurses +by Pavel Curtis. +.\"# +.\"# The following sets edit modes for GNU EMACS +.\"# Local Variables: +.\"# mode:nroff +.\"# fill-column:79 +.\"# End: diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index cee7f96e013..95c2c95a5a4 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,341 +1,1202 @@ -/* - * Copyright (c) 1981, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +#ifndef __NCURSES_H +#define __NCURSES_H +#define CURSES 1 +#define CURSES_H 1 +#define NCURSES_VERSION "1.9.9e" + +#ifndef _CHTYPE_T_ +#define _CHTYPE_T_ unsigned long +typedef _CHTYPE_T_ chtype; +#endif + +#include <stdio.h> +#include <unctrl.h> +#include <stdarg.h> +#ifdef _XOPEN_SOURCE_EXTENDED +#include <stddef.h> /* we want wchar_t */ +#endif /* _XOPEN_SOURCE_EXTENDED */ + +/* XSI and SVr4 specify that curses implements 'bool'. However, C++ may also + * implement it. If so, we must use the C++ compiler's type to avoid conflict + * with other interfaces. * - * @(#)curses.h 8.4 (Berkeley) 8/10/94 + * To simplify use with/without the configuration script, we define the symbols + * CXX_BUILTIN_BOOL and CXX_TYPE_OF_BOOL; they're edited by the configure + * script. + */ + +#undef TRUE +#undef FALSE +#define CXX_BUILTIN_BOOL 1 +#define CXX_TYPE_OF_BOOL char + +#if defined(__cplusplus) && CXX_BUILTIN_BOOL +#define TRUE ((CXX_TYPE_OF_BOOL)true) +#define FALSE ((CXX_TYPE_OF_BOOL)false) +#else +typedef CXX_TYPE_OF_BOOL bool; +#define TRUE ((bool)1) +#define FALSE ((bool)0) +#endif + +/* + * 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. */ +#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 */ + +/* colors */ +extern int COLORS; +extern int COLOR_PAIRS; +extern unsigned char *color_pairs; -#ifndef _CURSES_H_ -#define _CURSES_H_ +#define COLOR_BLACK 0 +#define COLOR_RED 1 +#define COLOR_GREEN 2 +#define COLOR_YELLOW 3 +#define COLOR_BLUE 4 +#define COLOR_MAGENTA 5 +#define COLOR_CYAN 6 +#define COLOR_WHITE 7 -#include <sys/types.h> -#include <sys/cdefs.h> +/* line graphics */ -#include <stdio.h> +extern chtype acs_map[]; +/* VT100 symbols begin here */ +#define ACS_ULCORNER (acs_map['l']) /* upper left corner */ +#define ACS_LLCORNER (acs_map['m']) /* lower left corner */ +#define ACS_URCORNER (acs_map['k']) /* upper right corner */ +#define ACS_LRCORNER (acs_map['j']) /* lower right corner */ +#define ACS_LTEE (acs_map['t']) /* tee pointing right */ +#define ACS_RTEE (acs_map['u']) /* tee pointing left */ +#define ACS_BTEE (acs_map['v']) /* tee pointing up */ +#define ACS_TTEE (acs_map['w']) /* tee pointing down */ +#define ACS_HLINE (acs_map['q']) /* horizontal line */ +#define ACS_VLINE (acs_map['x']) /* vertical line */ +#define ACS_PLUS (acs_map['n']) /* large plus or crossover */ +#define ACS_S1 (acs_map['o']) /* scan line 1 */ +#define ACS_S9 (acs_map['s']) /* scan line 9 */ +#define ACS_DIAMOND (acs_map['`']) /* diamond */ +#define ACS_CKBOARD (acs_map['a']) /* checker board (stipple) */ +#define ACS_DEGREE (acs_map['f']) /* degree symbol */ +#define ACS_PLMINUS (acs_map['g']) /* plus/minus */ +#define ACS_BULLET (acs_map['~']) /* bullet */ +/* Teletype 5410v1 symbols begin here */ +#define ACS_LARROW (acs_map[',']) /* arrow pointing left */ +#define ACS_RARROW (acs_map['+']) /* arrow pointing right */ +#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_BLOCK (acs_map['0']) /* solid square block */ /* - * The following #defines and #includes are present for backward - * compatibility only. They should not be used in future code. - * - * START BACKWARD COMPATIBILITY ONLY. + * These aren't documented, but a lot of System Vs have them anyway + * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings). + * The ACS_names may not match AT&T's, our source didn't know them. */ -#ifndef _CURSES_PRIVATE -#define bool char -#define reg register +#define ACS_S3 (acs_map['p']) /* scan line 3 */ +#define ACS_S7 (acs_map['r']) /* scan line 7 */ +#define ACS_LEQUAL (acs_map['y']) /* less/equal */ +#define ACS_GEQUAL (acs_map['z']) /* greater/equal */ +#define ACS_PI (acs_map['{']) /* Pi */ +#define ACS_NEQUAL (acs_map['|']) /* not equal */ +#define ACS_STERLING (acs_map['}']) /* UK pound sign */ + +/* + * Line drawing ACS names are of the form ACS_trbl, where t is the top, r + * is the right, b is the bottom, and l is the left. t, r, b, and l might + * be B (blank), S (single), D (double), or T (thick). The subset defined + * here only uses B and S. + */ +#define ACS_BSSB ACS_ULCORNER +#define ACS_SSBB ACS_LLCORNER +#define ACS_BBSS ACS_URCORNER +#define ACS_SBBS ACS_LRCORNER +#define ACS_SBSS ACS_RTEE +#define ACS_SSSB ACS_LTEE +#define ACS_SSBS ACS_BTEE +#define ACS_BSSS ACS_TTEE +#define ACS_BSBS ACS_HLINE +#define ACS_SBSB ACS_VLINE +#define ACS_SSSS ACS_PLUS -#ifndef TRUE -#define TRUE (1) +#if !defined(ERR) || ((ERR) != -1) +#define ERR (-1) #endif -#ifndef FALSE -#define FALSE (0) + +#if !defined(OK) || ((OK) != 0) +#define OK (0) #endif -#define _puts(s) tputs(s, 0, __cputchar) -#define _putchar(c) __cputchar(c) - -/* Old-style terminal modes access. */ -#define baudrate() (cfgetospeed(&__baset)) -#define crmode() cbreak() -#define erasechar() (__baset.c_cc[VERASE]) -#define killchar() (__baset.c_cc[VKILL]) -#define nocrmode() nocbreak() -#define ospeed (cfgetospeed(&__baset)) -#endif /* _CURSES_PRIVATE */ - -extern char GT; /* Gtty indicates tabs. */ -extern char NONL; /* Term can't hack LF doing a CR. */ -extern char UPPERCASE; /* Terminal is uppercase only. */ - -extern int My_term; /* Use Def_term regardless. */ -extern char *Def_term; /* Default terminal type. */ - -/* Termcap capabilities. */ -extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, - PC, UL, XB, XN, XT, XS, XX; -extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, - *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, - *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, - *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, - *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, - *VE, *al, *dl, *sf, *sr, - *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, - *RIGHT_PARM; - -/* END BACKWARD COMPATIBILITY ONLY. */ - -/* 8-bit ASCII characters. */ -#define unctrl(c) __unctrl[(c) & 0xff] -#define unctrllen(ch) __unctrllen[(ch) & 0xff] - -extern char *__unctrl[256]; /* Control strings. */ -extern char __unctrllen[256]; /* Control strings length. */ +/* values for the _flags member */ +#define _SUBWIN 0x01 /* is this a sub-window? */ +#define _ENDLINE 0x02 /* is the window flush right? */ +#define _FULLWIN 0x04 /* is the window full-screen? */ +#define _SCROLLWIN 0x08 /* bottom edge is at screen bottom? */ +#define _ISPAD 0x10 /* is this window a pad? */ +#define _HASMOVED 0x20 /* has cursor moved since last refresh? */ +#define _NEED_WRAP 0x40 /* cursor wrap pending */ /* - * A window an array of __LINE structures pointed to by the 'lines' pointer. - * A line is an array of __LDATA structures pointed to by the 'line' pointer. - * - * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new - * fields are added -- padding fields with *constant values* should ensure - * that the compiler will not generate any padding when storing an array of - * __LDATA structures. This is to enable consistent use of memcmp, and memcpy - * for comparing and copying arrays. + * this value is used in the firstchar and lastchar fields to mark + * unchanged lines + */ +#define _NOCHANGE -1 + +/* + * this value is used in the oldindex field to mark lines created by insertions + * and scrolls. */ -typedef struct { - char ch; /* the actual character */ - -#define __STANDOUT 0x01 /* Added characters are standout. */ - char attr; /* attributes of character */ -} __LDATA; - -#define __LDATASIZE (sizeof(__LDATA)) - -typedef struct { -#define __ISDIRTY 0x01 /* Line is dirty. */ -#define __ISPASTEOL 0x02 /* Cursor is past end of line */ -#define __FORCEPAINT 0x04 /* Force a repaint of the line */ - unsigned int flags; - unsigned int hash; /* Hash value for the line. */ - size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ - size_t firstch, lastch; /* First and last changed columns. */ - __LDATA *line; /* Pointer to the line text. */ -} __LINE; - -typedef struct __window { /* Window structure. */ - struct __window *nextp, *orig; /* Subwindows list and parent. */ - size_t begy, begx; /* Window home. */ - size_t cury, curx; /* Current x, y coordinates. */ - size_t maxy, maxx; /* Maximum values for curx, cury. */ - short ch_off; /* x offset for firstch/lastch. */ - __LINE **lines; /* Array of pointers to the lines */ - __LINE *lspace; /* line space (for cleanup) */ - __LDATA *wspace; /* window space (for cleanup) */ - -#define __ENDLINE 0x001 /* End of screen. */ -#define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ -#define __FULLWIN 0x004 /* Window is a screen. */ -#define __IDLINE 0x008 /* Insert/delete sequences. */ -#define __SCROLLWIN 0x010 /* Last char will scroll window. */ -#define __SCROLLOK 0x020 /* Scrolling ok. */ -#define __CLEAROK 0x040 /* Clear on next refresh. */ -#define __WSTANDOUT 0x080 /* Standout window */ -#define __LEAVEOK 0x100 /* If curser left */ - unsigned int flags; -} WINDOW; - -/* Curses external declarations. */ -extern WINDOW *curscr; /* Current screen. */ -extern WINDOW *stdscr; /* Standard screen. */ - -extern struct termios __orig_termios; /* Terminal state before curses */ -extern struct termios __baset; /* Our base terminal state */ -extern int __tcaction; /* If terminal hardware set. */ - -extern int COLS; /* Columns on the screen. */ -extern int LINES; /* Lines on the screen. */ - -extern char *ttytype; /* Full name of current terminal. */ - -#define ERR (0) /* Error return. */ -#define OK (1) /* Success return. */ - -/* Standard screen pseudo functions. */ -#define addbytes(s, n) __waddbytes(stdscr, s, n, 0) -#define addch(ch) waddch(stdscr, ch) -#define addnstr(s, n) waddnstr(stdscr, s, n) -#define addstr(s) __waddbytes(stdscr, s, strlen(s), 0) -#define clear() wclear(stdscr) -#define clrtobot() wclrtobot(stdscr) -#define clrtoeol() wclrtoeol(stdscr) -#define delch() wdelch(stdscr) -#define deleteln() wdeleteln(stdscr) -#define erase() werase(stdscr) -#define getch() wgetch(stdscr) -#define getstr(s) wgetstr(stdscr, s) -#define inch() winch(stdscr) -#define insch(ch) winsch(stdscr, ch) -#define insertln() winsertln(stdscr) -#define move(y, x) wmove(stdscr, y, x) -#define refresh() wrefresh(stdscr) -#define standend() wstandend(stdscr) -#define standout() wstandout(stdscr) -#define waddbytes(w, s, n) __waddbytes(w, s, n, 0) -#define waddstr(w, s) __waddbytes(w, s, strlen(s), 0) - -/* Standard screen plus movement pseudo functions. */ -#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) -#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) -#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) -#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) -#define mvdelch(y, x) mvwdelch(stdscr, y, x) -#define mvgetch(y, x) mvwgetch(stdscr, y, x) -#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) -#define mvinch(y, x) mvwinch(stdscr, y, x) -#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) -#define mvwaddbytes(w, y, x, s, n) \ - (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) -#define mvwaddch(w, y, x, ch) \ - (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) -#define mvwaddnstr(w, y, x, s, n) \ - (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) -#define mvwaddstr(w, y, x, s) \ - (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0)) -#define mvwdelch(w, y, x) \ - (wmove(w, y, x) == ERR ? ERR : wdelch(w)) -#define mvwgetch(w, y, x) \ - (wmove(w, y, x) == ERR ? ERR : wgetch(w)) -#define mvwgetstr(w, y, x, s) \ - (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) -#define mvwinch(w, y, x) \ - (wmove(w, y, x) == ERR ? ERR : winch(w)) -#define mvwinsch(w, y, x, c) \ - (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) - -/* Psuedo functions. */ -#define clearok(w, bf) \ - ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK)) -#define flushok(w, bf) \ - ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH)) -#define getyx(w, y, x) \ - (y) = (w)->cury, (x) = (w)->curx -#define leaveok(w, bf) \ - ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK)) -#define scrollok(w, bf) \ - ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK)) -#define winch(w) \ - ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177) - -/* Public function prototypes. */ -__BEGIN_DECLS -int box __P((WINDOW *, int, int)); -int cbreak __P((void)); -int delwin __P((WINDOW *)); -int echo __P((void)); -int endwin __P((void)); -char *fullname __P((char *, char *)); -char *getcap __P((char *)); -int gettmode __P((void)); -void idlok __P((WINDOW *, int)); -WINDOW *initscr __P((void)); -char *longname __P((char *, char *)); -int mvcur __P((int, int, int, int)); -int mvprintw __P((int, int, const char *, ...)); -int mvscanw __P((int, int, const char *, ...)); -int mvwin __P((WINDOW *, int, int)); -int mvwprintw __P((WINDOW *, int, int, const char *, ...)); -int mvwscanw __P((WINDOW *, int, int, const char *, ...)); -WINDOW *newwin __P((int, int, int, int)); -int nl __P((void)); -int nocbreak __P((void)); -int noecho __P((void)); -int nonl __P((void)); -int noraw __P((void)); -int overlay __P((WINDOW *, WINDOW *)); -int overwrite __P((WINDOW *, WINDOW *)); -int printw __P((const char *, ...)); -int raw __P((void)); -int resetty __P((void)); -int savetty __P((void)); -int scanw __P((const char *, ...)); -int scroll __P((WINDOW *)); -int setterm __P((char *)); -int sscans __P((WINDOW *, const char *, ...)); -WINDOW *subwin __P((WINDOW *, int, int, int, int)); -int suspendwin __P((void)); -int touchline __P((WINDOW *, int, int, int)); -int touchoverlap __P((WINDOW *, WINDOW *)); -int touchwin __P((WINDOW *)); -int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); -int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); -int waddch __P((WINDOW *, int)); -int waddnstr __P((WINDOW *, const char *, int)); -int wclear __P((WINDOW *)); -int wclrtobot __P((WINDOW *)); -int wclrtoeol __P((WINDOW *)); -int wdelch __P((WINDOW *)); -int wdeleteln __P((WINDOW *)); -int werase __P((WINDOW *)); -int wgetch __P((WINDOW *)); -int wgetstr __P((WINDOW *, char *)); -int winsch __P((WINDOW *, int)); -int winsertln __P((WINDOW *)); -int wmove __P((WINDOW *, int, int)); -int wprintw __P((WINDOW *, const char *, ...)); -int wrefresh __P((WINDOW *)); -int wscanw __P((WINDOW *, const char *, ...)); -int wstandend __P((WINDOW *)); -int wstandout __P((WINDOW *)); -int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); - -/* Private functions that are needed for user programs prototypes. */ -void __cputchar __P((int)); -int __waddbytes __P((WINDOW *, const char *, int, int)); -__END_DECLS - -/* Private functions. */ -#ifdef _CURSES_PRIVATE -void __CTRACE __P((const char *, ...)); -unsigned int __hash __P((char *, int)); -void __id_subwins __P((WINDOW *)); -int __mvcur __P((int, int, int, int, int)); -void __restore_stophandler __P((void)); -void __set_stophandler __P((void)); -void __set_subwin __P((WINDOW *, WINDOW *)); -void __startwin __P((void)); -void __stop_signal_handler __P((int)); -void __swflags __P((WINDOW *)); -int __touchline __P((WINDOW *, int, int, int, int)); -int __touchwin __P((WINDOW *)); -char *__tscroll __P((const char *, int, int)); -int __waddch __P((WINDOW *, __LDATA *)); - -/* Private #defines. */ -#define min(a,b) (a < b ? a : b) -#define max(a,b) (a > b ? a : b) - -/* Private externs. */ -extern int __echoit; -extern int __endwin; -extern int __pfast; -extern int __rawmode; -extern int __noqch; +#define _NEWINDEX -1 + +typedef struct screen SCREEN; +typedef struct _win_st WINDOW; + +typedef chtype attr_t; /* ...must be at least as wide as chtype */ + +#ifdef _XOPEN_SOURCE_EXTENDED +#ifndef _WCHAR_T +typedef unsigned long wchar_t; +#endif /* _WCHAR_T */ +#ifndef _WINT_T +typedef long int wint_t; +#endif /* _WINT_T */ + +#define CCHARW_MAX 5 +typedef struct +{ + attr_t attr; + wchar_t chars[CCHARW_MAX]; +} +cchar_t; +#endif /* _XOPEN_SOURCE_EXTENDED */ + +struct _win_st { + short _cury, _curx; /* current cursor position */ + + /* window location and size */ + short _maxy, _maxx; /* maximums of x and y, NOT window size */ + short _begy, _begx; /* screen coords of upper-left-hand corner */ + + short _flags; /* window state flags */ + + /* attribute tracking */ + attr_t _attrs; /* current attribute for non-space character */ + chtype _bkgd; /* current background char/attribute pair */ + + /* option values set by user */ + bool _notimeout; /* no time out on function-key entry? */ + bool _clear; /* consider all data in the window invalid? */ + bool _leaveok; /* OK to not reset cursor on exit? */ + bool _scroll; /* OK to scroll this window? */ + bool _idlok; /* OK to use insert/delete line? */ + bool _idcok; /* OK to use insert/delete char? */ + bool _immed; /* window in immed mode? (not yet used) */ + bool _sync; /* window in sync mode? */ + 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; + + /* global screen state */ + short _regtop; /* top line of scrolling region */ + short _regbottom; /* bottom line of scrolling region */ + + /* these are used only if this is a sub-window */ + int _parx; /* x coordinate of this window in parent */ + int _pary; /* y coordinate of this window in parent */ + WINDOW *_parent; /* pointer to parent if a sub-window */ + + /* these are used only if this is a pad */ + struct pdat + { + short _pad_y, _pad_x; + short _pad_top, _pad_left; + short _pad_bottom, _pad_right; + } _pad; +}; + +extern WINDOW *stdscr, *curscr, *newscr; + +extern int LINES, COLS, TABSIZE; + +/* + * This global was an undocumented feature under AIX curses. + */ +extern int ESCDELAY; /* ESC expire time in milliseconds */ + +#ifdef __cplusplus +extern "C" { +#endif + +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. + */ +#if !defined(__GNUC__) && !defined(__attribute__) +#define __attribute__(p) /* nothing */ #endif -/* Termcap functions. */ -__BEGIN_DECLS -int tgetent __P((char *, char *)); -int tgetnum __P((char *)); -int tgetflag __P((char *)); -char *tgetstr __P((char *, char **)); -char *tgoto __P((char *, int, int)); -void tputs __P((char *, int, void (*)(int))); -__END_DECLS - -#endif /* !_CURSES_H_ */ +/* + * Function prototypes. This is the complete XSI Curses list of required + * functions. Those marked `generated' will have sources generated from the + * macro definitions later in this file, in order to satisfy XPG4.2 + * requirements. + */ + +extern int addch(const chtype); /* generated */ +extern int addchnstr(const chtype *, int); /* generated */ +extern int addchstr(const chtype *); /* generated */ +extern int addnstr(const char *, int); /* generated */ +extern int addstr(const char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int addnwstr(const wchar_t *, int); /* missing */ +extern int addwstr(const wchar_t *); /* missing */ +extern int add_wch(const cchar_t *); /* missing */ +extern int add_wchnstr(const cchar_t *, int); /* missing */ +extern int add_wchstr(const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int attroff(int); /* generated */ +extern int attron(int); /* generated */ +extern int attrset(int); /* generated */ +extern int attr_get(void); /* generated */ +extern int attr_off(int); /* implemented */ +extern int attr_on(int); /* implemented */ +extern int attr_set(int); /* generated */ +extern int baudrate(void); /* implemented */ +extern int beep(void); /* implemented */ +extern int bkgd(chtype); /* generated */ +extern void bkgdset(chtype); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int bkgrndset(const cchar_t *); /* missing */ +extern int bkgrnd(const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int border(chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int border_set(cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int box(WINDOW *, chtype, chtype); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int box_set(WINDOW *, cchar_t, cchar_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern bool can_change_color(void); /* implemented */ +extern int cbreak(void); /* implemented */ +extern int chgat(int, attr_t, short, const void *); /* generated */ +extern int clear(void); /* generated */ +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_PAIR(int); /* generated */ +extern int copywin(const WINDOW*,WINDOW*,int,int,int,int,int,int,int); /* implemented */ +extern int curs_set(int); /* implemented */ +extern int def_prog_mode(void); /* implemented */ +extern int def_shell_mode(void); /* implemented */ +extern int delay_output(float); /* implemented */ +extern int delch(void); /* generated */ +extern void delscreen(SCREEN *); /* implemented */ +extern int delwin(WINDOW *); /* implemented */ +extern int deleteln(void); /* generated */ +extern WINDOW *derwin(WINDOW *,int,int,int,int); /* implemented */ +extern int doupdate(void); /* implemented */ +extern WINDOW *dupwin(WINDOW *); /* implemented */ +extern int echo(void); /* implemented */ +extern int echochar(const chtype); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int echo_wchar(const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int endwin(void); /* implemented */ +extern char erasechar(void); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int erase_wchar(wchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern void filter(void); /* implemented */ +extern int flash(void); /* implemented */ +extern int flushinp(void); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern chtype getbkgd(WINDOW *); /* missing */ +extern int getbkgrnd(cchar_t *); /* missing */ +extern int getcchar(const cchar_t *, wchar_t*, attr_t*, short*, void*); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int getch(void); /* generated */ +extern int getnstr(char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int getn_wstr(wint_t *, int n); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +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 */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int get_wstr(wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int halfdelay(int); /* implemented */ +extern int has_colors(void); /* implemented */ +extern int has_ic(void); /* implemented */ +extern int has_il(void); /* implemented */ +extern int hline(chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int hline_set(const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int idcok(WINDOW *, bool); /* implemented */ +extern int idlok(WINDOW *, bool); /* implemented */ +extern int immedok(WINDOW *, bool); /* implemented */ +extern chtype inch(void); /* generated */ +extern int inchnstr(chtype *, int); /* generated */ +extern int inchstr(chtype *); /* generated */ +extern WINDOW *initscr(void); /* implemented */ +extern int init_color(short,short,short,short); /* implemented */ +extern int init_pair(short,short,short); /* implemented */ +extern int innstr(char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int innwstr(wchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int insch(chtype); /* generated */ +extern int insdelln(int); /* generated */ +extern int insertln(void); /* generated */ +extern int insnstr(const char *, int); /* generated */ +extern int insstr(const char *); /* generated */ +extern int instr(char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int ins_nwstr(const wchar_t *, int); /* missing */ +extern int ins_wch(const cchar_t *); /* missing */ +extern int ins_wstr(const wchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int intrflush(WINDOW *,bool); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int inwstr(wchar_t *); /* missing */ +extern int in_wch(const cchar_t *); /* missing */ +extern int in_wchstr(const cchar_t *); /* missing */ +extern int in_wchntr(const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int isendwin(void); /* implemented */ +extern int is_linetouched(WINDOW *,int); /* implemented */ +extern int is_wintouched(WINDOW *); /* implemented */ +extern const char *keyname(int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int key_name(wchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int keypad(WINDOW *,bool); /* implemented */ +extern char killchar(void); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int killwchar(wchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int leaveok(WINDOW *,bool); /* implemented */ +extern char *longname(void); /* implemented */ +extern int meta(WINDOW *,bool); /* implemented */ +extern int move(int, int); /* generated */ +extern int mvaddch(int, int, const chtype); /* generated */ +extern int mvaddchnstr(int, int, const chtype *, int); /* generated */ +extern int mvaddchstr(int, int, const chtype *); /* generated */ +extern int mvaddnstr(int, int, const char *, int); /* generated */ +extern int mvaddstr(int, int, const char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvaddnwstr(int, int, const wchar_t *, int); /* missing */ +extern int mvaddwstr(int, int, const wchar_t *); /* missing */ +extern int mvadd_wch(int, int, const cchar_t *); /* missing */ +extern int mvadd_wchnstr(int, int, const cchar_t *, int);/* missing */ +extern int mvadd_wchstr(int, int, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvchgat(int, int, int, attr_t, short, const void *); /* generated */ +extern int mvcur(int,int,int,int); /* implemented */ +extern int mvdelch(int, int); /* generated */ +extern int mvderwin(WINDOW *, int, int); /* implemented */ +extern int mvgetch(int, int); /* generated */ +extern int mvgetnstr(int, int, char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvgetn_wstr(int, int, wint_t *, int n); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvgetstr(int, int, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvget_wch(int, int, wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvget_wstr(int, int, wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvhline(int, int, chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvhline_set(int, int, const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern chtype mvinch(int, int); /* generated */ +extern int mvinchnstr(int, int, chtype *, int); /* generated */ +extern int mvinchstr(int, int, chtype *); /* generated */ +extern int mvinnstr(int, int, char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvinnwstr(int, int, wchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvinsch(int, int, chtype); /* generated */ +extern int mvinsnstr(int, int, const char *, int); /* generated */ +extern int mvinsstr(int, int, const char *); /* generated */ +extern int mvinstr(int, int, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvins_nwstr(int, int, const wchar_t *, int); /* missing */ +extern int mvins_wch(int, int, const cchar_t *); /* missing */ +extern int mvins_wstr(int, int, const wchar_t *); /* missing */ +extern int mvinwstr(int, int, wchar_t *); /* missing */ +extern int mvin_wch(int, int, const cchar_t *); /* missing */ +extern int mvin_wchstr(int, int, const cchar_t *); /* missing */ +extern int mvin_wchntr(int, int, const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvprintw(int,int,const char *,...); /* implemented */ +extern int mvscanw(int,int,const char *,...); /* implemented */ +extern int mvvline(int, int, chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvvline_set(int, int, const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwaddch(WINDOW *, int, int, const chtype); /* generated */ +extern int mvwaddchnstr(WINDOW *, int, int, const chtype *, int);/* generated */ +extern int mvwaddchstr(WINDOW *, int, int, const chtype *); /* generated */ +extern int mvwaddnstr(WINDOW *, int, int, const char *, int); /* generated */ +extern int mvwaddstr(WINDOW *, int, int, const char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int);/* missing */ +extern int mvwaddwstr(WINDOW *, int, int, const wchar_t *); /* missing */ +extern int mvwadd_wch(WINDOW *, int, int, const cchar_t *); /* missing */ +extern int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int); /* missing */ +extern int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *);/* generated */ +extern int mvwdelch(WINDOW *, int, int); /* generated */ +extern int mvwgetch(WINDOW *, int, int); /* generated */ +extern int mvwgetnstr(WINDOW *, int, int, char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwgetn_wstr(WINDOW *, int, int, wint_t *, int n);/* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwgetstr(WINDOW *, int, int, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwget_wch(WINDOW *, int, int, wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwget_wstr(WINDOW *, int, int, wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwhline(WINDOW *, int, int, chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwhline_set(WINDOW *, int, int, const cchar_t *, int);/* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwin(WINDOW *,int,int); /* implemented */ +extern chtype mvwinch(WINDOW *, int, int); /* generated */ +extern int mvwinchnstr(WINDOW *, int, int, chtype *, int); /* generated */ +extern int mvwinchstr(WINDOW *, int, int, chtype *); /* generated */ +extern int mvwinnstr(WINDOW *, int, int, char *, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwinnwstr(WINDOW *, int, int, wchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwinsch(WINDOW *, int, int, chtype); /* generated */ +extern int mvwinsnstr(WINDOW *, int, int, const char *, int); /* generated */ +extern int mvwinsstr(WINDOW *, int, int, const char *); /* generated */ +extern int mvwinstr(WINDOW *, int, int, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwins_nwstr(WINDOW *, int,int, const wchar_t *,int); /* missing */ +extern int mvwins_wch(WINDOW *, int, int, const cchar_t *); /* missing */ +extern int mvwins_wstr(WINDOW *, int, int, const wchar_t *); /* missing */ +extern int mvwinwstr(WINDOW *, int, int, wchar_t *); /* missing */ +extern int mvwin_wch(WINDOW *, int, int, const cchar_t *); /* missing */ +extern int mvwin_wchnstr(WINDOW *, int,int,const cchar_t *,int); /* missing */ +extern int mvwin_wchstr(WINDOW *, int, int, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int mvwprintw(WINDOW*,int,int,const char *,...); /* implemented */ +extern int mvwscanw(WINDOW *,int,int,const char *,...); /* implemented */ +extern int mvwvline(WINDOW *,int, int, chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int mvwvline_set(WINDOW *, int,int, const cchar_t *,int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int napms(int); /* implemented */ +extern WINDOW *newpad(int,int); /* implemented */ +extern SCREEN *newterm(const char *,FILE *,FILE *); /* implemented */ +extern WINDOW *newwin(int,int,int,int); /* implemented */ +extern int nl(void); /* implemented */ +extern int nocbreak(void); /* implemented */ +extern int nodelay(WINDOW *,bool); /* implemented */ +extern int noecho(void); /* implemented */ +extern int nonl(void); /* implemented */ +extern int noqiflush(void); /* implemented */ +extern int noraw(void); /* implemented */ +extern int notimeout(WINDOW *,bool); /* implemented */ +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 */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int pecho_wchar(WINDOW *, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int pnoutrefresh(WINDOW*,int,int,int,int,int,int);/* implemented */ +extern int prefresh(WINDOW *,int,int,int,int,int,int); /* implemented */ +extern int printw(const char *,...); /* implemented */ +extern int putp(const char *); /* implemented */ +extern int putwin(WINDOW *, FILE *); /* implemented */ +extern int qiflush(void); /* implemented */ +extern int raw(void); /* implemented */ +extern int redrawwin(WINDOW *); /* generated */ +extern int refresh(void); /* generated */ +extern int resetty(void); /* implemented */ +extern int reset_prog_mode(void); /* implemented */ +extern int reset_shell_mode(void); /* implemented */ +extern int ripoffline(int line, int (*init)(WINDOW *, int));/* implemented */ +extern int savetty(void); /* implemented */ +extern int scanw(const char *,...); /* implemented */ +extern int scr_dump(const char *); /* implemented */ +extern int scr_init(const char *); /* implemented */ +extern int scrl(int); /* generated */ +extern int scroll(WINDOW *); /* generated */ +extern int scrollok(WINDOW *,bool); /* implemented */ +extern int scr_restore(const char *); /* implemented */ +extern int scr_set(const char *); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int setcchar(cchar_t *, wchar_t *, attr_t, short, const void *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int setscrreg(int,int); /* generated */ +extern SCREEN *set_term(SCREEN *); /* implemented */ +extern int slk_attroff(chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int slk_attr_off(attr_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_attron(chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int slk_attr_on(attr_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_attrset(chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int slk_attr_set(attr_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int slk_clear(void); /* implemented */ +extern int slk_init(int); /* implemented */ +extern char *slk_label(int); /* implemented */ +extern int slk_noutrefresh(void); /* implemented */ +extern int slk_refresh(void); /* implemented */ +extern int slk_restore(void); /* implemented */ +extern int slk_set(int,const char *,int); /* implemented */ +extern int slk_touch(void); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int slk_wset(int, wchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int standout(void); /* generated */ +extern int standend(void); /* generated */ +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 *win, bool); /* implemented */ +extern attr_t termattrs(void); /* implemented */ +extern char *termname(void); /* implemented */ +extern int tigetflag(const char *); /* implemented */ +extern int tigetnum(const char *); /* implemented */ +extern char *tigetstr(const char *); /* implemented */ +extern int timeout(int); /* implemented */ +extern int typeahead(int); /* implemented */ +extern int ungetch(int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int unget_wch(const wchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int untouchwin(WINDOW *); /* generated */ +extern int vidattr(chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int vid_attr(attr_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int vidputs(chtype, int (*)(int)); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int vid_puts(attr_t, int (*)(int)); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int vline(chtype, int); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int vline_set(const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int vwprintw(WINDOW *,const char *,va_list); /* implemented */ +extern int vw_printw(WINDOW *,const char *,va_list); /* implemented */ +extern int vwscanw(WINDOW *,const char *,va_list); /* implemented */ +extern int vw_scanw(WINDOW *,const char *,va_list); /* implemented */ +extern int waddch(WINDOW *, const chtype); /* implemented */ +extern int waddchnstr(WINDOW *,const chtype *const,int); /* implemented */ +extern int waddchstr(WINDOW *,const chtype *); /* generated */ +extern int waddnstr(WINDOW *,const char *const,int); /* implemented */ +extern int waddstr(WINDOW *,const char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int waddwstr(WINDOW *,const wchar_t *); /* missing */ +extern int wadd_wch(WINDOW *,const cchar_t *); /* missing */ +extern int wadd_wchnstr(WINDOW *,const cchar_t *,int); /* missing */ +extern int wadd_wchstr(WINDOW *,const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wattron(WINDOW *, int); /* generated */ +extern int wattroff(WINDOW *, int); /* generated */ +extern int wattrset(WINDOW *, int); /* generated */ +extern attr_t wattr_get(WINDOW *); /* generated */ +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); /* implemented */ +extern int wbkgd(WINDOW *,const chtype); /* implemented */ +extern void wbkgdset(WINDOW *,chtype); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wbkgrndset(WINDOW *,const cchar_t *); /* missing */ +extern int wbkgrnd(WINDOW *,const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wborder(WINDOW *,chtype,chtype,chtype,chtype,chtype,chtype,chtype,chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wborder_set(WINDOW *,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t,cchar_t); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +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 void wcursyncup(WINDOW *); /* implemented */ +extern int wdelch(WINDOW *); /* implemented */ +extern int wdeleteln(WINDOW *); /* generated */ +extern int wechochar(WINDOW *, const chtype); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wecho_wchar(WINDOW *, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int werase(WINDOW *); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wgetbkgrnd(WINDOW *, cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wgetch(WINDOW *); /* implemented */ +extern int wgetnstr(WINDOW *,char *,int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wgetn_wstr(WINDOW *,wint_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wgetstr(WINDOW *, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wget_wch(WINDOW *, wint_t *); /* missing */ +extern int wget_wstr(WINDOW *, wint_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int whline(WINDOW *, chtype, int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int whline_set(WINDOW *, const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern chtype winch(WINDOW *); /* generated */ +extern int winchnstr(WINDOW *, chtype *, int); /* implemented */ +extern int winchstr(WINDOW *, chtype *); /* generated */ +extern int winnstr(WINDOW *, char *, int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int winnwstr(WINDOW *, wchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int winsch(WINDOW *, chtype); /* implemented */ +extern int winsdelln(WINDOW *,int); /* implemented */ +extern int winsertln(WINDOW *); /* generated */ +extern int winsnstr(WINDOW *, const char *,int); /* implemented */ +extern int winsstr(WINDOW *, const char *); /* generated */ +extern int winstr(WINDOW *, char *); /* generated */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wins_nwstr(WINDOW *, const wchar_t *, int); /* missing */ +extern int wins_wch(WINDOW *, const cchar_t *); /* missing */ +extern int wins_wstr(WINDOW *, const wchar_t *); /* missing */ +extern int winwstr(WINDOW *, wchar_t *); /* missing */ +extern int win_wch(WINDOW *, const cchar_t *); /* missing */ +extern int win_wchnstr(WINDOW *, const cchar_t *, int); /* missing */ +extern int win_wchstr(WINDOW *, const cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wmove(WINDOW *,int,int); /* implemented */ +extern int wnoutrefresh(WINDOW *); /* implemented */ +extern int wprintw(WINDOW *,const char *,...); /* implemented */ +extern int wredrawln(WINDOW *,int,int); /* implemented */ +extern int wrefresh(WINDOW *); /* implemented */ +extern int wresize(WINDOW *, int, int); /* implemented */ +extern int wscanw(WINDOW *,const char *,...); /* implemented */ +extern int wscrl(WINDOW *,int); /* implemented */ +extern int wsetscrreg(WINDOW *,int,int); /* implemented */ +extern int wstandout(WINDOW *); /* generated */ +extern int wstandend(WINDOW *); /* generated */ +extern void wsyncdown(WINDOW *); /* implemented */ +extern void wsyncup(WINDOW *); /* implemented */ +extern int wtimeout(WINDOW *,int); /* implemented */ +extern int wtouchln(WINDOW *,int,int,int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern wchar_t wunctrl(cchar_t *); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ +extern int wvline(WINDOW *,chtype,int); /* implemented */ +#ifdef _XOPEN_SOURCE_EXTENDED +extern int wvline_set(WINDOW *, const cchar_t *, int); /* missing */ +#endif /* _XOPEN_SOURCE_EXTENDED */ + +#ifdef __cplusplus +} +#endif + +/* 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 PAIR_NUMBER(a) ((a & A_COLOR) >> 8) + +/* + * pseudo functions + */ +#define wgetstr(w, s) wgetnstr(w, s, -1) +#define getnstr(s, n) wgetnstr(stdscr, s, n) + +#define setterm(term) setupterm(term, 1, (int *)0) + +#define fixterm() reset_prog_mode() +#define resetterm() reset_shell_mode() +#define saveterm() def_prog_mode() +#define crmode() cbreak() +#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 getsyx(y,x) getyx(stdscr, y, x) +#define setsyx(y,x) (stdscr->_cury = y, stdscr->_curx = x) + +#define wbkgdset(win,ch) ((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 wstandout(win) (wattr_set(win,A_STANDOUT)) +#define wstandend(win) (wattr_set(win,A_NORMAL)) +#define wattr_set(win,at) ((win)->_attrs = (at)) + +#define wattron(win,at) wattr_on(win, at) +#define wattroff(win,at) wattr_off(win, at) +#define wattrset(win,at) wattr_set(win, at) + +#define scroll(win) wscrl(win,1) + +#define touchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 1) +#define touchline(win, s, c) wtouchln((win), s, c, 1) +#define untouchwin(win) wtouchln((win), 0, (win)->_maxy + 1, 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) +#define hline(ch, n) whline(stdscr, ch, n) +#define vline(ch, n) wvline(stdscr, ch, n) + +#define winstr(w, s) winnstr(w, s, -1) +#define winchstr(w, s) winchnstr(w, s, -1) +#define winsstr(w, s) winsnstr(w, s, -1) + +#define redrawwin(w) wredrawln(w, 0, w->_maxy+1) +#define waddstr(win,str) waddnstr(win,str,-1) +#define waddchstr(win,str) waddchnstr(win,str,-1) + +/* + * pseudo functions for standard screen + */ + +#define bkgdset(ch) wbkgdset(stdscr,ch) +#define bkgd(ch) wbkgd(stdscr,ch) +#define inch() winch(stdscr) +#define standout() wstandout(stdscr) +#define standend() wstandend(stdscr) +#define attron(at) wattron(stdscr,at) +#define attroff(at) wattroff(stdscr,at) +#define attrset(at) wattrset(stdscr,at) +#define addch(ch) waddch(stdscr,ch) +#define echochar(c) wechochar(stdscr, c) +#define getch() wgetch(stdscr) +#define addstr(str) waddnstr(stdscr,str,-1) +#define getstr(str) wgetstr(stdscr,str) +#define move(y, x) wmove(stdscr,y,x) +#define clear() wclear(stdscr) +#define erase() werase(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define insertln() winsdelln(stdscr, 1) +#define winsertln(w) winsdelln(w, 1) +#define deleteln() winsdelln(stdscr, -1) +#define wdeleteln(w) winsdelln(w, -1) +#define refresh() wrefresh(stdscr) +#define insch(c) winsch(stdscr,c) +#define delch() wdelch(stdscr) +#define setscrreg(t,b) wsetscrreg(stdscr,t,b) +#define scrl(n) wscrl(stdscr,n) +#define timeout(delay) wtimeout(stdscr, delay) +#define addnstr(str,n) waddnstr(stdscr,str,n) +#define addchstr(str) waddchstr(stdscr,str) +#define addchnstr(str,n) waddchnstr(stdscr,str, n) +#define insdelln(n) winsdelln(stdscr, n) +#define insstr(s) winsstr(stdscr, s) +#define insnstr(s,n) winsnstr(stdscr, s, n) +#define instr(s) winstr(stdscr, s) +#define innstr(s,n) winnstr(stdscr, s, n) +#define inchstr(s) winchstr(stdscr, s) +#define inchnstr(s,n) winchnstr(stdscr, s, n) + +/* + * mv functions + */ + +#define mvwaddch(win,y,x,ch) (wmove(win,y,x) == ERR ? ERR : waddch(win,ch)) +#define mvwgetch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wgetch(win)) +#define mvwaddchnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,n)) +#define mvwaddchstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddchnstr(win,str,-1)) +#define mvwaddnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,n)) +#define mvwaddstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : waddnstr(win,str,-1)) +#define mvwgetstr(win,y,x,str) (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str)) +#define mvgetnstr(y,x,str,n) (move(y,x) == ERR ? ERR : wgetnstr(stdscr,str,n)) +#define mvwgetnstr(win,y,x,str,n) (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n)) +#define mvwinch(win,y,x) (wmove(win,y,x) == ERR ? ERR : winch(win)) +#define mvwdelch(win,y,x) (wmove(win,y,x) == ERR ? ERR : wdelch(win)) +#define mvwinsch(win,y,x,c) (wmove(win,y,x) == ERR ? ERR : winsch(win,c)) +#define mvwhline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : whline(win,c,n)) +#define mvwvline(win,y,x,c,n) (wmove(win,y,x) == ERR ? ERR : wvline(win,c,n)) +#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch) +#define mvaddchnstr(y,x,str,n) mvwaddchnstr(stdscr,y,x,str,n) +#define mvaddchstr(y,x,str) mvwaddchstr(stdscr,y,x,str) +#define mvgetch(y,x) mvwgetch(stdscr,y,x) +#define mvaddnstr(y,x,str,n) mvwaddnstr(stdscr,y,x,str,n) +#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str) +#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str) +#define mvinch(y,x) mvwinch(stdscr,y,x) +#define mvdelch(y,x) mvwdelch(stdscr,y,x) +#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c) +#define mvhline(y,x,c,n) mvwhline(stdscr,y,x,c,n) +#define mvvline(y,x,c,n) mvwvline(stdscr,y,x,c,n) +#define mvwinsstr(w, y, x, s) (wmove(w,y,x) == ERR ? ERR : winsstr(w,s)) +#define mvwinsnstr(w, y, x, s, n) (wmove(w,y,x) == ERR ? ERR : winsnstr(w,s,n)) +#define mvinsstr(y,x,s) mvwinsstr(stdscr,y,x,s) +#define mvinsnstr(y,x,s,n) mvwinsnstr(stdscr,y,x,s,n) +#define mvwinstr(w, y, x, s) (wmove(w,y,x) == ERR ? ERR : winstr(w,s)) +#define mvwinnstr(w, y, x, s, n) (wmove(w,y,x) == ERR ? ERR : winnstr(w,s,n)) +#define mvinstr(y,x,s) mvwinstr(stdscr,y,x,s) +#define mvinnstr(y,x,s,n) mvwinnstr(stdscr,y,x,s,n) +#define mvwinchstr(w, y, x, s) (wmove(w,y,x) == ERR ? ERR : winchstr(w,s)) +#define mvwinchnstr(w, y, x, s, n) (wmove(w,y,x) == ERR ? ERR : winchnstr(w,s,n)) +#define mvinchstr(y,x,s) mvwinchstr(stdscr,y,x,s) +#define mvinchnstr(y,x,s,n) mvwinchnstr(stdscr,y,x,s,n) + +/* + * XSI curses macros for XPG4 conformance. + * The underling functions needed to make these work are: + * waddnwstr(), waddchnwstr(), wadd_wch(), wborder_set(), wchgat(), + * wecho_wchar(), wgetn_wstr(), wget_wch(), whline_set(), vhline_set(), + * winnwstr(), wins_nwstr(), wins_wch(), win_wch(), win_wchnstr(). + * Except for wchgat(), these are not yet implemented. They will be someday. + */ +#define addnwstr(wstr, n) waddnwstr(stdscr, wstr, n) +#define addwstr(wstr, n) waddnwstr(stdscr, wstr, -1) +#define mvaddnwstr(y,x,wstr, n) (wmove(stdscr,y,x) == ERR ? ERR : waddnwstr(stdscr, wstr, n)) +#define mvaddwstr(y,x,wstr, n) (wmove(stdscr,y,x) == ERR ? ERR : waddnwstr(stdscr, wstr, -1)) +#define mvwaddnwstr(y,x,win,wstr,n) (wmove(win,y,x) == ERR ? ERR : waddnwstr(stdscr, wstr, n)) +#define mvwaddwstr(y,x,win,wstr,n) (wmove(win,y,x) == ERR ? ERR : waddnwstr(stdscr, wstr, -1)) +#define waddwstr(win, wstr, n) waddnwstr(win, wstr, -1) +#define add_wch(c) wadd_wch(stsdscr, c) +#define mvadd_wch(y,x,c) (wmove(stdscr,y,x) == ERR ? ERR : wadd_wch(stsdscr, c)) +#define mvwadd_wch(y,x,win,c) (wmove(win,y,x) == ERR ? ERR : wadd_wch(stsdscr, c)) +#define wattr_get(win) ((win)->_attrs) +#define attr_get() wattr_get(stdscr) +#define attr_off(a) wattr_off(stdscr, a) +#define attr_on(a) wattr_on(stdscr, a) +#define attr_set(a) wattr_set(stdscr, a) +#define wgetbkgd(win) ((win)->_bkgd) +#define box_set(w,v,h) wborder_set(w,v,v,h,h,0,0,0,9) +#define chgat(n, a, c, o) wchgat(stdscr, n, a, c, o) +#define mvchgat(y,x, n,a,c, o) (move(y,x)==ERR ? ERR : wchgat(stdscr,n,a,c,o)) +#define mvwchgat(w,y,x,n,a,c,o) (wmove(w,y,x) == ERR ? ERR : wchgat(w,n,a,c,o)) +#define echo_wchar(c) wecho_wchar(stdscr, c) +#define getn_wstr(t, n) wgetn_wstr(stdscr, t, n) +#define get_wstr(t) wgetn_wstr(stdscr, t, -1) +#define mvgetn_wstr(y, x, t, n) (move(y,x)==ERR ? ERR:wgetn_wstr(stdscr,t,n)) +#define mvget_wstr(y, x, t) (move(y,x)==ERR ? ERR:wgetn_wstr(stdscr,t,-1)) +#define mvwgetn_wstr(w,y,x,t,n) (wmove(w,y,x)==ERR ? ERR : wgetn_wstr(w,t,n)) +#define mvwget_wstr(w, y, x, t) (wmove(w,y,x)==ERR ? ERR : wgetn_wstr(w,t,-1)) +#define wget_wstr(w, t) wgetn_wstr(w, t, -1) +#define get_wch(c) wget_wch(stdscr, c) +#define mvget_wch(y, x, c) (move(y,x) == ERR ? ERR : wget_wch(stdscr, c)) +#define mvwget_wch(y, x, c) (wmove(w,y,x) == ERR ? ERR : wget_wch(w, n)) +#define hline_set(c, n) whline_set(stdscr, c, n) +#define mvhline_set(y,x,c,n) (move(y,x)==ERR ? ERR : whline_set(stdscr,c,n)) +#define mvvline_set(y,x,c,n) (move(y,x)==ERR ? ERR : wvline_set(stdscr,c,n)) +#define mvwhline_set(w,y,x,c,n) (wmove(w,y,x)==ERR ? ERR : whline_set(w,c,n)) +#define mvwvline_set(w,y,x,c,n) (wmove(w,y,x)==ERR ? ERR : wvline_set(w,c,n)) +#define vline_set(c, n) vhline_set(stdscr, c, n) +#define innwstr(c, n) winnwstr(stdscr, c, n) +#define inwstr(c) winnwstr(stdscr, c, -1) +#define mvinnwstr(y, x, c, n) (move(y,x)==ERR ? ERR : winnwstr(stdscr, c, n)) +#define mvinwstr(y, x, c) (move(y,x)==ERR ? ERR : winnwstr(stdscr, c,-1)) +#define mvwinnwstr(w,y,x,c,n) (wmove(w,y,x)==ERR ? ERR:winnwstr(stdscr,c,n)) +#define mvwinwstr(w,y,x,c) (wmove(w,y,x)==ERR ? ERR:winnwstr(stdscr,c,-1)) +#define winwstr(w, c) winnwstr(w, c, -1) +#define ins_nwstr(t, n) wins_nwstr(stdscr, t, n) +#define ins_wstr(t) wins_nwstr(stdscr, t, -1) +#define mvins_nwstr(y,x,t,n) (move(y,x)==ERR ? ERR: wins_nwstr(stdscr,t,n)) +#define mvins_wstr(y,x,t) (move(y,x)==ERR ? ERR: wins_nwstr(stdscr,t,-1)) +#define mvwins_nwstr(w,y,x,t,n) (wmove(w,y,x)==ERR?ERR:wins_nwstr(stdscr,t,n)) +#define mvwins_wstr(w,y,x,t) (wmove(w,y,x)==ERR?ERR:wins_nwstr(stdscr,t,-1)) +#define wins_wstr(w, t) wins_nwstr(w, t, -1) +#define ins_wch(c) wins_wch(stdscr, c) +#define mvins_wch(y,x,c) (move(y,x) == ERR ? ERR : wins_wch(c)) +#define mwvins_wch(w,y,x,c) (wmove(w,y,x) == ERR ? ERR : wins_wch(c)) +#define in_wch(c) win_wch(stdscr, c) +#define mvin_wch(y,x,c) (move(y,x) == ERR ? ERR : win_wch(stdscr, c)) +#define mvwin_wch(w,y,x,c) (wmove(w, y,x) == ERR ? ERR : win_wch(w, c)) +#define in_wchnstr(c, n) win_wchnstr(stdscr, c, n) +#define in_wchstr(c) win_wchnstr(stdscr, c, -1) +#define mvin_wchnstr(y,x,c,n) (move(y,x)==ERR ? ERR:win_wchnstr(stdscr,c,n)) +#define mvin_wchstr(y, x, c) (move(y,x)==ERR ? ERR:win_wchnstr(stdscr,c,-1)) +#define mvwin_wchnstr(w,y,x,c,n) (wmove(w,y,x)==ERR ? ERR:win_wchnstr(stdscr,c,n)) +#define mvwin_wchstr(w,y,x,c) (wmove(w,y,x)==ERR ? ERR:win_wchnstr(stdscr,c,-1)) +#define win_wchstr(w, c) win_wchnstr(w, c, -1) + + +/* + * XSI curses deprecates SVr4 vwprintw/vwscanw, which are supposed to use + * varargs.h. It adds new calls vw_printw/vw_scanw, which are supposed to + * use POSIX stdarg.h. The ncurses versions of vwprintw/vwscanw already + * use stdarg.h, so... + */ +#define vw_printw vwprintw +#define vw_scanw vwscanw + +/* + * Pseudo-character tokens outside ASCII range. The curses wgetch() function + * will return any given one of these only if the corresponding k- capability + * is defined in your terminal's terminfo entry. + */ +#define KEY_CODE_YES 0400 /* A wchar_t contains a key code */ +#define KEY_MIN 0401 /* Minimum curses key */ +#define KEY_BREAK 0401 /* Break key (unreliable) */ +#define KEY_DOWN 0402 /* Down-arrow */ +#define KEY_UP 0403 /* Up-arrow */ +#define KEY_LEFT 0404 /* Left-arrow */ +#define KEY_RIGHT 0405 /* Right-arrow */ +#define KEY_HOME 0406 /* Home key (upward+left arrow) */ +#define KEY_BACKSPACE 0407 /* Backspace (unreliable) */ +#define KEY_F0 0410 /* Function keys. Space for 64 */ +#define KEY_F(n) (KEY_F0+(n)) /* Value of function key n */ +#define KEY_DL 0510 /* Delete line */ +#define KEY_IL 0511 /* Insert line */ +#define KEY_DC 0512 /* Delete character */ +#define KEY_IC 0513 /* Insert char or enter insert mode */ +#define KEY_EIC 0514 /* Exit insert char mode */ +#define KEY_CLEAR 0515 /* Clear screen */ +#define KEY_EOS 0516 /* Clear to end of screen */ +#define KEY_EOL 0517 /* Clear to end of line */ +#define KEY_SF 0520 /* Scroll 1 line forward */ +#define KEY_SR 0521 /* Scroll 1 line backward (reverse) */ +#define KEY_NPAGE 0522 /* Next page */ +#define KEY_PPAGE 0523 /* Previous page */ +#define KEY_STAB 0524 /* Set tab */ +#define KEY_CTAB 0525 /* Clear tab */ +#define KEY_CATAB 0526 /* Clear all tabs */ +#define KEY_ENTER 0527 /* Enter or send (unreliable) */ +#define KEY_SRESET 0530 /* Soft (partial) reset (unreliable) */ +#define KEY_RESET 0531 /* Reset or hard reset (unreliable) */ +#define KEY_PRINT 0532 /* Print */ +#define KEY_LL 0533 /* Home down or bottom (lower left) */ + +/* The keypad is arranged like this: */ +/* a1 up a3 */ +/* left b2 right */ +/* c1 down c3 */ + +#define KEY_A1 0534 /* Upper left of keypad */ +#define KEY_A3 0535 /* Upper right of keypad */ +#define KEY_B2 0536 /* Center of keypad */ +#define KEY_C1 0537 /* Lower left of keypad */ +#define KEY_C3 0540 /* Lower right of keypad */ +#define KEY_BTAB 0541 /* Back tab */ +#define KEY_BEG 0542 /* Beg (beginning) */ +#define KEY_CANCEL 0543 /* Cancel */ +#define KEY_CLOSE 0544 /* Close */ +#define KEY_COMMAND 0545 /* Cmd (command) */ +#define KEY_COPY 0546 /* Copy */ +#define KEY_CREATE 0547 /* Create */ +#define KEY_END 0550 /* End */ +#define KEY_EXIT 0551 /* Exit */ +#define KEY_FIND 0552 /* Find */ +#define KEY_HELP 0553 /* Help */ +#define KEY_MARK 0554 /* Mark */ +#define KEY_MESSAGE 0555 /* Message */ +#define KEY_MOVE 0556 /* Move */ +#define KEY_NEXT 0557 /* Next */ +#define KEY_OPEN 0560 /* Open */ +#define KEY_OPTIONS 0561 /* Options */ +#define KEY_PREVIOUS 0562 /* Prev (previous) */ +#define KEY_REDO 0563 /* Redo */ +#define KEY_REFERENCE 0564 /* Ref (reference) */ +#define KEY_REFRESH 0565 /* Refresh */ +#define KEY_REPLACE 0566 /* Replace */ +#define KEY_RESTART 0567 /* Restart */ +#define KEY_RESUME 0570 /* Resume */ +#define KEY_SAVE 0571 /* Save */ +#define KEY_SBEG 0572 /* Shifted Beg (beginning) */ +#define KEY_SCANCEL 0573 /* Shifted Cancel */ +#define KEY_SCOMMAND 0574 /* Shifted Command */ +#define KEY_SCOPY 0575 /* Shifted Copy */ +#define KEY_SCREATE 0576 /* Shifted Create */ +#define KEY_SDC 0577 /* Shifted Delete char */ +#define KEY_SDL 0600 /* Shifted Delete line */ +#define KEY_SELECT 0601 /* Select */ +#define KEY_SEND 0602 /* Shifted End */ +#define KEY_SEOL 0603 /* Shifted Clear line */ +#define KEY_SEXIT 0604 /* Shifted Dxit */ +#define KEY_SFIND 0605 /* Shifted Find */ +#define KEY_SHELP 0606 /* Shifted Help */ +#define KEY_SHOME 0607 /* Shifted Home */ +#define KEY_SIC 0610 /* Shifted Input */ +#define KEY_SLEFT 0611 /* Shifted Left arrow */ +#define KEY_SMESSAGE 0612 /* Shifted Message */ +#define KEY_SMOVE 0613 /* Shifted Move */ +#define KEY_SNEXT 0614 /* Shifted Next */ +#define KEY_SOPTIONS 0615 /* Shifted Options */ +#define KEY_SPREVIOUS 0616 /* Shifted Prev */ +#define KEY_SPRINT 0617 /* Shifted Print */ +#define KEY_SREDO 0620 /* Shifted Redo */ +#define KEY_SREPLACE 0621 /* Shifted Replace */ +#define KEY_SRIGHT 0622 /* Shifted Right arrow */ +#define KEY_SRSUME 0623 /* Shifted Resume */ +#define KEY_SSAVE 0624 /* Shifted Save */ +#define KEY_SSUSPEND 0625 /* Shifted Suspend */ +#define KEY_SUNDO 0626 /* Shifted Undo */ +#define KEY_SUSPEND 0627 /* Suspend */ +#define KEY_UNDO 0630 /* Undo */ +#define KEY_MOUSE 0631 /* Mouse event has occurred */ +#define KEY_MAX 0777 /* Maximum key value */ + +/* mouse interface */ +#define NCURSES_MOUSE_VERSION 1 + +/* event masks */ +#define BUTTON1_RELEASED 000000000001L +#define BUTTON1_PRESSED 000000000002L +#define BUTTON1_CLICKED 000000000004L +#define BUTTON1_DOUBLE_CLICKED 000000000010L +#define BUTTON1_TRIPLE_CLICKED 000000000020L +#define BUTTON1_RESERVED_EVENT 000000000040L +#define BUTTON2_RELEASED 000000000100L +#define BUTTON2_PRESSED 000000000200L +#define BUTTON2_CLICKED 000000000400L +#define BUTTON2_DOUBLE_CLICKED 000000001000L +#define BUTTON2_TRIPLE_CLICKED 000000002000L +#define BUTTON2_RESERVED_EVENT 000000004000L +#define BUTTON3_RELEASED 000000010000L +#define BUTTON3_PRESSED 000000020000L +#define BUTTON3_CLICKED 000000040000L +#define BUTTON3_DOUBLE_CLICKED 000000100000L +#define BUTTON3_TRIPLE_CLICKED 000000200000L +#define BUTTON3_RESERVED_EVENT 000000400000L +#define BUTTON4_RELEASED 000001000000L +#define BUTTON4_PRESSED 000002000000L +#define BUTTON4_CLICKED 000004000000L +#define BUTTON4_DOUBLE_CLICKED 000010000000L +#define BUTTON4_TRIPLE_CLICKED 000020000000L +#define BUTTON4_RESERVED_EVENT 000040000000L +#define BUTTON_CTRL 000100000000L +#define BUTTON_SHIFT 000200000000L +#define BUTTON_ALT 000400000000L +#define ALL_MOUSE_EVENTS 000777777777L +#define REPORT_MOUSE_POSITION 001000000000L + +/* macros to extract single event-bits from masks */ +#define BUTTON_RELEASE(e, x) ((e) & (001 << (6 * ((x) - 1)))) +#define BUTTON_PRESS(e, x) ((e) & (002 << (6 * ((x) - 1)))) +#define BUTTON_CLICK(e, x) ((e) & (004 << (6 * ((x) - 1)))) +#define BUTTON_DOUBLE_CLICK(e, x) ((e) & (010 << (6 * ((x) - 1)))) +#define BUTTON_TRIPLE_CLICK(e, x) ((e) & (020 << (6 * ((x) - 1)))) +#define BUTTON_RESERVED_EVENT(e, x) ((e) & (040 << (6 * ((x) - 1)))) + +typedef unsigned long mmask_t; + +typedef struct +{ + short id; /* ID to distinguish multiple devices */ + int x, y, z; /* event coordinates (character-cell) */ + mmask_t bstate; /* button state bits */ +} +MEVENT; + +int getmouse(MEVENT *event); +int ungetmouse(MEVENT *event); +mmask_t mousemask(mmask_t newmask, mmask_t *oldmask); +bool wenclose(WINDOW *win, int y, int x); +int mouseinterval(int); + +/* Debugging : use with libncurses_g.a */ + +extern void _tracef(const char *, ...) __attribute__((format(printf,1,2))); +extern void _tracedump(char *, WINDOW *); +extern char *_traceattr(attr_t mode); +extern char *_tracechar(const unsigned char); +extern char *_tracemouse(const MEVENT *); +extern void trace(const unsigned int tracelevel); + +/* trace masks */ +#define TRACE_DISABLE 0x00 /* turn off tracing */ +#define TRACE_UPDATE 0x01 /* trace update actions, old & new screens */ +#define TRACE_MOVE 0x02 /* trace cursor moves and scrolls */ +#define TRACE_CHARPUT 0x04 /* trace all character outputs */ +#define TRACE_ORDINARY 0x07 /* trace all update actions */ +#define TRACE_CALLS 0x08 /* trace all curses calls */ +#define TRACE_VIRTPUT 0x10 /* trace virtual character puts */ +#define TRACE_FIFO 0x20 /* also fifo actions by getch() */ +#define TRACE_MAXIMUM 0xff /* maximum trace level */ + +#ifdef TRACE +extern bool no_optimize; /* suppress optimization */ +#endif /* TRACE */ + +#endif /* __NCURSES_H */ diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h new file mode 100644 index 00000000000..a1e023265d1 --- /dev/null +++ b/lib/libcurses/curses.priv.h @@ -0,0 +1,270 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +/* + * curses.priv.h + * + * Header file for curses library objects which are private to + * the library. + * + */ + +#include <config.h> + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if HAVE_LIMITS_H +# include <limits.h> +#elif HAVE_SYS_PARAM_H +# include <sys/param.h> +#endif + +#ifndef PATH_MAX +# if defined(_POSIX_PATH_MAX) +# define PATH_MAX _POSIX_PATH_MAX +# elif defined(MAXPATHLEN) +# define PATH_MAX MAXPATHLEN +# else +# define PATH_MAX 255 /* the Posix minimum pathsize */ +# endif +#endif + +#include <assert.h> + +#include <curses.h> /* we'll use -Ipath directive to get the right one! */ + +/* The terminfo source is assumed to be 7-bit ASCII */ +#define is7bits(c) ((unsigned)(c) < 128) + +#ifndef min +#define min(a,b) ((a) > (b) ? (b) : (a)) +#endif + +#ifndef max +#define max(a,b) ((a) < (b) ? (b) : (a)) +#endif + +/* usually in <unistd.h> */ +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + +#ifndef R_OK +#define R_OK 4 /* Test for read permission. */ +#endif +#ifndef W_OK +#define W_OK 2 /* Test for write permission. */ +#endif +#ifndef X_OK +#define X_OK 1 /* Test for execute permission. */ +#endif +#ifndef F_OK +#define F_OK 0 /* Test for existence. */ +#endif + +#define TextOf(c) ((c) & (chtype)A_CHARTEXT) +#define AttrOf(c) ((c) & (chtype)A_ATTRIBUTES) + +#define BLANK (' '|A_NORMAL) + +#define CHANGED -1 + +/* + * 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. + */ +#undef TABS_OK /* OK to use tab/backtab for local motions? */ + +#ifdef TRACE +#define T(a) if (_nc_tracing & TRACE_CALLS) _tracef a +#define TR(n, a) if (_nc_tracing & (n)) _tracef a +#define TPUTS_TRACE(s) _nc_tputs_trace = s; +extern unsigned _nc_tracing; +extern char *_nc_tputs_trace; +extern char *_nc_visbuf(const char *); +#else +#define T(a) +#define TR(n, a) +#define TPUTS_TRACE(s) +#endif + +/* lib_acs.c */ +extern void init_acs(void); /* no prefix, this name is traditional */ + +/* lib_mvcur.c */ +extern void _nc_mvcur_init(SCREEN *sp); +extern void _nc_mvcur_wrap(void); +extern int _nc_mvcur_scrolln(int, int, int, int); + +/* 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; + +/* elsewhere ... */ +extern int _nc_keypad(bool flag); +extern WINDOW *_nc_makenew(int, int, int, int); +#ifdef EXTERN_TERMINFO +#define _nc_outch _ti_outc +#endif +extern int _nc_outch(int); +extern chtype _nc_render(WINDOW *, chtype, chtype); +extern int _nc_waddch_nosync(WINDOW *, const chtype); +extern void _nc_scroll_optimize(void); +extern void _nc_scroll_window(WINDOW *, int const, short const, short const); +extern int _nc_setupscreen(short, short const); +extern void _nc_backspace(WINDOW *win); +extern void _nc_outstr(char *str); +extern void _nc_signal_handler(bool); +extern void _nc_synchook(WINDOW *win); +extern int _nc_timed_wait(int fd, int wait, int *timeleft); +extern void _nc_do_color(int, int (*)(int)); + +struct try { + struct try *child; /* ptr to child. NULL if none */ + struct try *sibling; /* ptr to sibling. NULL if none */ + unsigned char ch; /* character at this node */ + unsigned short value; /* code of string so far. 0 if none. */ +}; + +/* + * Structure for soft labels. + */ + +typedef struct { + char dirty; /* all labels have changed */ + char hidden; /* soft lables are hidden */ + WINDOW *win; + struct slk_ent { + char text[9]; /* text for the label */ + char form_text[9]; /* formatted text (left/center/...) */ + int x; /* x coordinate of this field */ + char dirty; /* this label has changed */ + char visible; /* field is visible */ + } ent[8]; +} SLK; + +#define FIFO_SIZE 32 + +struct screen { + int _ifd; /* input file ptr for screen */ + FILE *_ofp; /* output file ptr for screen */ + int _checkfd; /* filedesc for typeahead check */ +#ifdef EXTERN_TERMINFO + struct _terminal *_term; /* terminal type information */ +#else + struct term *_term; /* terminal type information */ +#endif + short _lines; /* screen lines */ + short _columns; /* screen columns */ + WINDOW *_curscr; /* current screen */ + WINDOW *_newscr; /* virtual screen to be updated to */ + WINDOW *_stdscr; /* screen's full-window context */ + struct try *_keytry; /* "Try" for use with keypad mode */ + unsigned int _fifo[FIFO_SIZE]; /* input pushback buffer */ + signed char _fifohead, /* head of fifo queue */ + _fifotail, /* tail of fifo queue */ + _fifopeek; /* where to peek for next char */ + bool _endwin; /* are we out of window mode? */ + chtype _current_attr; /* terminal attribute current set */ + bool _coloron; /* is color enabled? */ + int _cursor; /* visibility of the cursor */ + int _cursrow; /* physical cursor row */ + int _curscol; /* physical cursor column */ + bool _nl; /* True if NL -> CR/NL is on */ + bool _raw; /* True if in raw mode */ + int _cbreak; /* 1 if in cbreak mode */ + /* > 1 if in halfdelay mode */ + bool _echo; /* True if echo on */ + bool _use_meta; /* use the meta key? */ + SLK *_slk; /* ptr to soft key struct / NULL */ + int _baudrate; /* used to compute padding */ + + /* cursor movement costs; units are 10ths of milliseconds */ + int _char_padding; /* cost of character put */ + int _cr_cost; /* cost of (carriage_return) */ + 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 + int _ht_cost; /* cost of (tab) */ + int _cbt_cost; /* cost of (backtab) */ +#endif /* TABS_OK */ + int _cub1_cost; /* cost of (cursor_left) */ + int _cuf1_cost; /* cost of (cursor_right) */ + int _cud1_cost; /* cost of (cursor_down) */ + int _cuu1_cost; /* cost of (cursor_up) */ + int _cub_cost; /* cost of (parm_cursor_left) */ + int _cuf_cost; /* cost of (parm_cursor_right) */ + int _cud_cost; /* cost of (parm_cursor_down) */ + int _cuu_cost; /* cost of (parm_cursor_up) */ + int _hpa_cost; /* cost of (column_address) */ + int _vpa_cost; /* cost of (row_address) */ +}; + +/* + * On systems with a broken linker, define 'SP' as a function to force the + * linker to pull in the data-only module with 'SP'. + */ +#ifndef BROKEN_LINKER +#define BROKEN_LINKER 0 +#endif + +#if BROKEN_LINKER +#define SP _nc_screen() +extern SCREEN *_nc_screen(void); +extern int _nc_alloc_screen(void); +extern void _nc_set_screen(SCREEN *); +#else +extern SCREEN *SP; +#define _nc_alloc_screen() ((SP = (SCREEN *) calloc(1, sizeof(*SP))) != NULL) +#define _nc_set_screen(sp) SP = sp +#endif + +/* + * We don't want to use the lines or columns capabilities internally, + * because if the application is running multiple screens under + * X windows, it's quite possible they could all have type xterm + * but have different sizes! So... + */ +#define screen_lines SP->_lines +#define screen_columns SP->_columns + +extern int _slk_init; /* TRUE if slk_init() called */ +extern int slk_initialize(WINDOW *, int); + +#define MAXCOLUMNS 135 +#define MAXLINES 66 +#define UNINITIALISED ((struct try * ) -1) diff --git a/lib/libcurses/hardscroll.c b/lib/libcurses/hardscroll.c new file mode 100644 index 00000000000..73d185b199e --- /dev/null +++ b/lib/libcurses/hardscroll.c @@ -0,0 +1,420 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +/****************************************************************************** + +NAME + hardscroll.c -- hardware-scrolling optimization for ncurses + +SYNOPSIS + void _nc_scroll_optimize(void) + +DESCRIPTION + OVERVIEW + +This algorithm for computes optimum hardware scrolling to transform an +old screen (curscr) into a new screen (newscr) via vertical line moves. + +Because the screen has a `grain' (there are insert/delete/scroll line +operations but no insert/delete/scroll column operations), it is efficient +break the update algorithm into two pieces: a first stage that does only line +moves, optimizing the end product of user-invoked insertions, deletions, and +scrolls; and a second phase (corresponding to the present doupdate code in +ncurses) that does only line transformations. + +The common case we want hardware scrolling for is to handle line insertions +and deletions in screen-oriented text-editors. This two-stage approach will +accomplish that at a low computation and code-size cost. + + LINE-MOVE COMPUTATION + +Now, to a discussion of the line-move computation. + +For expository purposes, consider the screen lines to be represented by +integers 0..23 (with the understanding that the value of 23 may vary). +Let a new line introduced by insertion, scrolling, or at the bottom of +the screen following a line delete be given the index -1. + +Assume that the real screen starts with lines 0..23. Now, we have +the following possible line-oriented operations on the screen: + +Insertion: inserts a line at a given screen row, forcing all lines below +to scroll forward. The last screen line is lost. For example, an insertion +at line 5 would produce: 0..4 -1 5..23. + +Deletion: deletes a line at a given screen row, forcing all lines below +to scroll forward. The last screen line is made new. For example, a deletion +at line 7 would produce: 0..6 8..23 -1. + +Scroll up: move a range of lines up 1. The bottom line of the range +becomes new. For example, scrolling up the region from 9 to 14 will +produce 0..8 10..14 -1 15..23. + +Scroll down: move a range of lines down 1. The top line of the range +becomes new. For example, scrolling down the region from 12 to 16 will produce +0..11 -1 12..15 17..23. + +Now, an obvious property of all these operations is that they preserve the +order of old lines, though not their position in the sequence. + +The key trick of this algorithm is that the original line indices described +above are actually maintained as _line[].oldindex fields in the window +structure, and stick to each line through scroll and insert/delete operations. + +Thus, it is possible at update time to look at the oldnum fields and compute +an optimal set of il/dl/scroll operations that will take the real screen +lines to the virtual screen lines. Once these vertical moves have been done, +we can hand off to the second stage of the update algorithm, which does line +transformations. + +Note that the move computation does not need to have the full generality +of a diff algorithm (which it superficially resembles) because lines cannot +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 + +HOW TO TEST THIS: + +Use the following production: + +hardscroll: hardscroll.c + $(CC) -g -DMAINDEBUG hardscroll.c -o hardscroll + +Then just type scramble vectors and watch. The following test loads are +a representative sample of cases: + +----------------------------- CUT HERE ------------------------------------ +# No lines moved + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 +# +# A scroll up + 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -1 +# +# A scroll down +-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 +# +# An insertion (after line 12) + 0 1 2 3 4 5 6 7 8 9 10 11 12 -1 13 14 15 16 17 18 19 20 21 22 +# +# A simple deletion (line 10) + 0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 21 22 23 -1 +# +# A more complex case +-1 -1 -1 -1 -1 3 4 5 6 7 -1 -1 8 9 10 11 12 13 14 15 16 17 -1 -1 +----------------------------- CUT HERE ------------------------------------ + +AUTHOR + Eric S. Raymond <esr@snark.thyrsus.com>, November 1994 + +*****************************************************************************/ + +#include "curses.priv.h" + +#include <stdlib.h> +#include <string.h> + +#if defined(TRACE) || defined(MAINDEBUG) +static void linedump(void); +#endif /* defined(TRACE) || defined(MAINDEBUG) */ + +/* if only this number of lines is carried over, nuke the screen and redraw */ +#define CLEAR_THRESHOLD 3 + +#ifdef MAINDEBUG +#define LINES 24 +static int oldnums[LINES], reallines[LINES]; +#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 /* MAINDEBUG */ + +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(MAINDEBUG) + int pass = 0; +#endif /* defined(TRACE) || defined(MAINDEBUG) */ + + TR(TRACE_CALLS, ("_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")); +#ifndef MAINDEBUG + clearok(stdscr, TRUE); +#endif /* MAINDEBUG */ + return; + } + +#ifdef TRACE + TR(TRACE_UPDATE | TRACE_MOVE, ("After real line marking:")); + if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) + 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)); +#ifndef MAINDEBUG + (void) _nc_mvcur_scrolln(-disp, ofirst, olast, LINES - 1); + _nc_scroll_window(curscr, -disp, ofirst, olast); +#endif /* MAINDEBUG */ + + for (m = ofirst; m <= olast; m++) + { + REAL(m) = _NEWINDEX; +#ifndef MAINDEBUG + /* + * 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 /* MAINDEBUG */ + } + for (m = first; m <= last; m++) + OLDNUM(m) = _NEWINDEX; + + no_hunk_moved = FALSE; + } + + /* OK, done with this hunk */ + first = last + 1; + } + } while + (!no_hunk_moved); +} + +#if defined(TRACE) || defined(MAINDEBUG) +static void linedump(void) +/* dump the state of the real and virtual oldnum fields */ +{ + int n; + char buf[BUFSIZ]; + + (void) strcpy(buf, "real"); + for (n = 0; n < LINES; n++) + (void) sprintf(buf + strlen(buf), " %02d", REAL(n)); + TR(TRACE_UPDATE | TRACE_MOVE, (buf)); + + (void) strcpy(buf, "virt"); + for (n = 0; n < LINES; n++) + (void) sprintf(buf + strlen(buf), " %02d", OLDNUM(n)); + TR(TRACE_UPDATE | TRACE_MOVE, (buf)); +} +#endif /* defined(TRACE) || defined(MAINDEBUG) */ + +#ifdef MAINDEBUG + +main() +{ + char line[BUFSIZ], *st; + + _nc_tracing = TRACE_MOVE; + for (;;) + { + int n; + + for (n = 0; n < LINES; n++) + { + reallines[n] = n; + oldnums[n] = _NEWINDEX; + } + + /* grab the test vector */ + if (fgets(line, sizeof(line), stdin) == (char *)NULL) + exit(0); + + /* parse it */ + n = 0; + if (line[0] == '#') + { + (void) fputs(line, stderr); + continue; + } + st = strtok(line, " "); + do { + oldnums[n++] = atoi(st); + } while + (st = strtok((char *)NULL, " ")); + + /* display it */ + (void) fputs("Initial input:\n", stderr); + linedump(); + + _nc_scroll_optimize(); + } +} + +#endif /* MAINDEBUG */ + +/* hardscroll.c ends here */ + diff --git a/lib/libcurses/keys.list b/lib/libcurses/keys.list new file mode 100644 index 00000000000..f9e3dd657c8 --- /dev/null +++ b/lib/libcurses/keys.list @@ -0,0 +1,150 @@ +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 diff --git a/lib/libcurses/lib_acs.c b/lib/libcurses/lib_acs.c new file mode 100644 index 00000000000..ba867d7cc73 --- /dev/null +++ b/lib/libcurses/lib_acs.c @@ -0,0 +1,113 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + + +#include "curses.priv.h" +#include "term.h" /* ena_acs, acs_chars */ +#include <string.h> + +chtype acs_map[128]; + +void init_acs(void) +{ + T(("initializing ACS map")); + + /* + * Initializations for a UNIX-like multi-terminal environment. Use + * ASCII chars and count on the terminfo description to do better. + */ + ACS_ULCORNER = '+'; /* should be upper left corner */ + ACS_LLCORNER = '+'; /* should be lower left corner */ + ACS_URCORNER = '+'; /* should be upper right corner */ + ACS_LRCORNER = '+'; /* should be lower right corner */ + ACS_RTEE = '+'; /* should be tee pointing left */ + ACS_LTEE = '+'; /* should be tee pointing right */ + ACS_BTEE = '+'; /* should be tee pointing up */ + ACS_TTEE = '+'; /* should be tee pointing down */ + ACS_HLINE = '-'; /* should be horizontal line */ + ACS_VLINE = '|'; /* should be vertical line */ + ACS_PLUS = '+'; /* should be large plus or crossover */ + ACS_S1 = '~'; /* should be scan line 1 */ + ACS_S9 = '_'; /* should be scan line 9 */ + ACS_DIAMOND = '+'; /* should be diamond */ + ACS_CKBOARD = ':'; /* should be checker board (stipple) */ + ACS_DEGREE = '\''; /* should be degree symbol */ + ACS_PLMINUS = '#'; /* should be plus/minus */ + ACS_BULLET = 'o'; /* should be bullet */ + ACS_LARROW = '<'; /* should be arrow pointing left */ + ACS_RARROW = '>'; /* should be arrow pointing right */ + ACS_DARROW = 'v'; /* should be arrow pointing down */ + ACS_UARROW = '^'; /* should be arrow pointing up */ + ACS_BOARD = '#'; /* should be board of squares */ + ACS_LANTERN = '#'; /* should be lantern symbol */ + ACS_BLOCK = '#'; /* should be solid square block */ + /* these defaults were invented for ncurses */ + ACS_S3 = '-'; /* should be scan line 3 */ + ACS_S7 = '-'; /* should be scan line 7 */ + ACS_LEQUAL = '<'; /* should be less-than-or-equal-to */ + ACS_GEQUAL = '>'; /* should be greater-than-or-equal-to */ + ACS_PI = '*'; /* should be greek pi */ + ACS_NEQUAL = '!'; /* should be not-equal */ + ACS_STERLING = 'f'; /* should be pound-sterling symbol */ + +#ifdef ena_acs + if (ena_acs != NULL) + { + TPUTS_TRACE("ena_acs"); + putp(ena_acs); + } +#endif /* ena_acs */ + +#ifdef acs_chars +#define ALTCHAR(c) ((chtype)(c) & A_CHARTEXT) | A_ALTCHARSET + + if (acs_chars != NULL) { + size_t i = 0; + size_t length = strlen(acs_chars); + + while (i < length) + switch (acs_chars[i]) { + case 'l':case 'm':case 'k':case 'j': + case 'u':case 't':case 'v':case 'w': + 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 '0':case 'p':case 'r':case 'y': + case 'z':case '{':case '|':case '}': + acs_map[(unsigned int)acs_chars[i]] = + ALTCHAR(acs_chars[i+1]); + i++; + /* FALLTHRU */ + default: + i++; + break; + } + } +#ifdef TRACE + else { + T(("acsc not defined, using default mapping")); + } +#endif /* TRACE */ +#endif /* acs_char */ +} + diff --git a/lib/libcurses/lib_addch.c b/lib/libcurses/lib_addch.c new file mode 100644 index 00000000000..005c5bfbd22 --- /dev/null +++ b/lib/libcurses/lib_addch.c @@ -0,0 +1,287 @@ + +/*************************************************************************** +* 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_addch.c +** +** The routines waddch(), wattr_on(), wattr_off(), wchgat(). +** +*/ + +#include "curses.priv.h" +#include <ctype.h> +#include "unctrl.h" + +#define ALL_BUT_COLOR ((chtype)~(A_COLOR)) + +int wattr_on(WINDOW *win, const attr_t at) +{ + T(("wattr_on(%p,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs))); + if (PAIR_NUMBER(at) > 0x00) { + win->_attrs = (win->_attrs & ALL_BUT_COLOR) | at ; + T(("new attribute is %s", _traceattr(win->_attrs))); + } else { + win->_attrs |= at; + T(("new attribute is %s", _traceattr(win->_attrs))); + } + return OK; +} + +int wattr_off(WINDOW *win, const attr_t at) +{ +#define IGNORE_COLOR_OFF FALSE + + T(("wattr_off(%p,%s) current = %s", win, _traceattr(at), _traceattr(win->_attrs))); + if (IGNORE_COLOR_OFF == TRUE) { + if (PAIR_NUMBER(at) == 0xff) /* turn off color */ + win->_attrs &= ~at; + else /* leave color alone */ + win->_attrs &= ~(at|ALL_BUT_COLOR); + } else { + if (PAIR_NUMBER(at) > 0x00) /* turn off color */ + win->_attrs &= ~at; + else /* leave color alone */ + win->_attrs &= ~(at|ALL_BUT_COLOR); + } + T(("new attribute is %s", _traceattr(win->_attrs))); + return OK; +} + +int wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts) +{ + int i; + + for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) + win->_line[win->_cury].text[i] + = (win->_line[win->_cury].text[i] & A_CHARTEXT) + | attr + | COLOR_PAIR(color); + + return OK; +} + +/* + * Ugly microtweaking alert. Everything from here to end of module is + * likely to be speed-critical -- profiling data sure says it is! + * Most of the important screen-painting functions are shells around + * waddch(). So we make every effort to reduce function-call overhead + * by inlining stuff, even at the cost of making wrapped copies for + * export. Also we supply some internal versions that don't call the + * window sync hook, for use by string-put functions. + */ + +static __inline chtype render_char(WINDOW *win, chtype oldch, chtype newch) +/* compute a rendition of the given char correct for the current context */ +{ + if ((oldch & A_CHARTEXT) == ' ') + newch |= win->_bkgd; + else if (!(newch & A_ATTRIBUTES)) + newch |= (win->_bkgd & A_ATTRIBUTES); + TR(TRACE_VIRTPUT, ("bkg = %lx -> ch = %lx", win->_bkgd, newch)); + + return(newch); +} + +chtype _nc_render(WINDOW *win, chtype oldch, chtype newch) +/* make render_char() visible while still allowing us to inline it below */ +{ + return(render_char(win, oldch, newch)); +} + +/* actions needed to process a newline within addch_nosync() */ +#define DO_NEWLINE x = 0; \ + win->_flags &= ~_NEED_WRAP; \ + y++; \ + if (y > win->_regbottom) { \ + y--; \ + if (win->_scroll) \ + scroll(win); \ + } + +/* check if position is legal; if not, return error */ +#define CHECK_POSITION(win, x, y) \ + if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) { \ + TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \ + "(_maxx = %d, _maxy = %d)", win, x, y, \ + win->_maxx, win->_maxy)); \ + win->_curx = win->_cury = 0; \ + win->_flags &= ~_NEED_WRAP; \ + return(ERR); \ + } + +static __inline +int waddch_literal(WINDOW *win, chtype ch) +{ +register int x, y; + + x = win->_curx; + y = win->_cury; + + CHECK_POSITION(win, x, y); + + if (win->_flags & _NEED_WRAP) { + TR(TRACE_MOVE, ("new char when NEED_WRAP set at %d,%d",y,x)); + DO_NEWLINE + } + + /* + * We used to pass in + * win->_line[y].text[x] + * as a second argument, but the value of the old character + * is not relevant here. + */ + ch = render_char(win, 0, ch); + + TR(TRACE_VIRTPUT, ("win attr = %s", _traceattr(win->_attrs))); + ch |= 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 | %s", + y, x, + _tracechar((unsigned char)(ch & A_CHARTEXT)), + _traceattr((ch & (chtype)A_ATTRIBUTES)))); + if (x > win->_maxx) { + TR(TRACE_MOVE, ("NEED_WRAP set at %d,%d",y,x)); + win->_flags |= _NEED_WRAP; + x--; + } + + win->_curx = x; + win->_cury = y; + + return OK; +} + +static __inline +int waddch_nosync(WINDOW *win, const chtype c) +/* the workhorse function -- add a character to the given window */ +{ +register chtype ch = c; +register int x, y; +int newx; + + x = win->_curx; + y = win->_cury; + + CHECK_POSITION(win, x, y); + + if (ch & A_ALTCHARSET) + goto noctrl; + + switch ((int)(ch&A_CHARTEXT)) { + case '\t': + if (win->_flags & _NEED_WRAP) { + x = 0; + newx = min(TABSIZE, win->_maxx+1); + } else + newx = min(x + (TABSIZE-(x%TABSIZE)), win->_maxx+1); + while (win->_curx < newx) { + if (waddch_literal(win, ' ' | (ch&A_ATTRIBUTES)) == ERR) + return(ERR); + } + return(OK); + case '\n': + wclrtoeol(win); + DO_NEWLINE + break; + case '\r': + x = 0; + win->_flags &= ~_NEED_WRAP; + break; + case '\b': + if (win->_flags & _NEED_WRAP) + win->_flags &= ~_NEED_WRAP; + else if (--x < 0) + x = 0; + break; + default: + if (is7bits(ch & A_CHARTEXT) && iscntrl(ch & A_CHARTEXT)) + return(waddstr(win, unctrl((unsigned char)ch))); + + /* FALLTHRU */ + noctrl: + waddch_literal(win, ch); + return(OK); + } + + win->_curx = x; + win->_cury = y; + + return(OK); +} + +#undef DO_NEWLINE + +int _nc_waddch_nosync(WINDOW *win, const chtype c) +/* export copy of waddch_nosync() so the string-put functions can use it */ +{ + return(waddch_nosync(win, c)); +} + +/* + * The versions below call _nc_synhook(). We wanted to avoid this in the + * version exported for string puts; they'll call _nc_synchook once at end + * of run. + */ + +/* These are actual entry points */ + +int waddch(WINDOW *win, const chtype ch) +{ + TR(TRACE_VIRTPUT, ("waddch(%p, %s | %s) called", win, + _tracechar((unsigned char)(ch & A_CHARTEXT)), + _traceattr((ch & (chtype)A_ATTRIBUTES)))); + + if (waddch_nosync(win, ch) == ERR) + return(ERR); + else + { + _nc_synchook(win); + TR(TRACE_VIRTPUT, ("waddch() is done")); + return(OK); + } +} + +int wechochar(WINDOW *win, const chtype ch) +{ + TR(TRACE_VIRTPUT, ("wechochar(%p,%s (%s)) called", win, + _tracechar((unsigned char)(ch & A_CHARTEXT)), + _traceattr((ch & (chtype)A_ATTRIBUTES)))); + + if (waddch_literal(win, ch) == ERR) + return(ERR); + else + { + _nc_synchook(win); + TR(TRACE_VIRTPUT, ("wechochar() is done")); + return(OK); + } +} diff --git a/lib/libcurses/lib_addstr.c b/lib/libcurses/lib_addstr.c new file mode 100644 index 00000000000..6d98d0464c6 --- /dev/null +++ b/lib/libcurses/lib_addstr.c @@ -0,0 +1,88 @@ + +/*************************************************************************** +* 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_addstr.c +* +** The routines waddnstr(), waddchnstr(). +** +*/ + +#include "curses.priv.h" +#include <string.h> + +int +waddnstr(WINDOW *win, const char *const astr, int n) +{ +unsigned char *str = (unsigned char *)astr; +int code = ERR; + + T(("waddnstr(%p,\"%s\",%d) called %s", win, _nc_visbuf(astr), n, _traceattr(win->_attrs))); + + if (str != NULL) { + + 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); + TR(TRACE_VIRTPUT, ("waddnstr returns %d", code)); + return code; +} + +int +waddchnstr(WINDOW *win, const chtype *const astr, int n) +{ +short oy = win->_cury; +short ox = win->_curx; +chtype *str = (chtype *)astr; +int code = OK; + + T(("waddchnstr(%p,%p,%d) called", win, str, n)); + + if (n < 0) { + n = 0; + while (*str++ != 0) + n++; + str = (chtype *)astr; + } + + while(n-- > 0) { + if (_nc_waddch_nosync(win, *str++) == ERR) { + code = ERR; + break; + } + } + + win->_curx = ox; + win->_cury = oy; + _nc_synchook(win); + return code; +} diff --git a/lib/libcurses/lib_beep.c b/lib/libcurses/lib_beep.c new file mode 100644 index 00000000000..0beee7c160c --- /dev/null +++ b/lib/libcurses/lib_beep.c @@ -0,0 +1,79 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +/* + * beep.c + * + * Routines beep() and flash() + * + */ + +#include "curses.priv.h" +#include "term.h" /* beep, flash */ + +/* + * beep() + * + * Sound the current terminal's audible bell if it has one. If not, + * flash the screen if possible. + * + */ + +int beep(void) +{ + T(("beep() called")); + + /* should make sure that we are not in altchar mode */ + if (bell) { + TPUTS_TRACE("bell"); + return(putp(bell)); + } else if (flash_screen) { + TPUTS_TRACE("flash_screen"); + return(putp(flash_screen)); + } + else + return(ERR); +} + +/* + * flash() + * + * Flash the current terminal's screen if possible. If not, + * sound the audible bell if one exists. + * + */ + +int flash(void) +{ + T(("flash() called")); + + /* should make sure that we are not in altchar mode */ + if (flash_screen) { + TPUTS_TRACE("flash_screen"); + return(putp(flash_screen)); + } else if (bell) { + TPUTS_TRACE("bell"); + return(putp(bell)); + } + else + return(ERR); +} diff --git a/lib/libcurses/lib_bkgd.c b/lib/libcurses/lib_bkgd.c new file mode 100644 index 00000000000..aa6ff7a7ff1 --- /dev/null +++ b/lib/libcurses/lib_bkgd.c @@ -0,0 +1,41 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + +#include "curses.priv.h" + +int wbkgd(WINDOW *win, const chtype ch) +{ +int x, y; + + T(("wbkgd(%p, %lx) called", win, ch)); + wbkgdset(win, ch); + + for (y = 0; y <= win->_maxy; y++) + for (x = 0; x <= win->_maxx; x++) + if ((win->_line[y].text[x]&A_CHARTEXT) == ' ') + win->_line[y].text[x] |= ch; + else + win->_line[y].text[x] |= (ch&A_ATTRIBUTES); + touchwin(win); + _nc_synchook(win); + return OK; +} + diff --git a/lib/libcurses/lib_box.c b/lib/libcurses/lib_box.c new file mode 100644 index 00000000000..bf45be33336 --- /dev/null +++ b/lib/libcurses/lib_box.c @@ -0,0 +1,146 @@ + +/*************************************************************************** +* 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_box.c +** +** line drawing routines: +** wborder() +** whline() +** wvline() +** +*/ + +#include "curses.priv.h" + +int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, + chtype bs, chtype tl, chtype tr, chtype bl, chtype br) +{ +short i; +short endx, endy; + + T(("wborder() called")); + + if (ls == 0) ls = ACS_VLINE; + if (rs == 0) rs = ACS_VLINE; + if (ts == 0) ts = ACS_HLINE; + if (bs == 0) bs = ACS_HLINE; + if (tl == 0) tl = ACS_ULCORNER; + if (tr == 0) tr = ACS_URCORNER; + if (bl == 0) bl = ACS_LLCORNER; + if (br == 0) br = ACS_LRCORNER; + + ls |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + rs |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + ts |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + bs |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + tl |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + tr |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + bl |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + br |= (win->_attrs ? win->_attrs : (win->_bkgd & A_ATTRIBUTES)); + + T(("using %lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx", ls, rs, ts, bs, tl, tr, bl, br)); + + endx = win->_maxx; + endy = win->_maxy; + + for (i = 0; i <= endx; i++) { + win->_line[0].text[i] = ts; + win->_line[endy].text[i] = bs; + } + win->_line[endy].firstchar = win->_line[0].firstchar = 0; + win->_line[endy].lastchar = win->_line[0].lastchar = endx; + + for (i = 0; i <= endy; i++) { + win->_line[i].text[0] = ls; + win->_line[i].text[endx] = rs; + win->_line[i].firstchar = 0; + win->_line[i].lastchar = endx; + } + win->_line[0].text[0] = tl; + win->_line[0].text[endx] = tr; + win->_line[endy].text[0] = bl; + win->_line[endy].text[endx] = br; + + _nc_synchook(win); + return OK; +} + +int whline(WINDOW *win, chtype ch, int n) +{ +short line; +short start; +short end; + + T(("whline(%p,%lx,%d) called", win, 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; + while ( end >= start) { + win->_line[line].text[end] = ch | win->_attrs; + end--; + } + + return OK; +} + +int wvline(WINDOW *win, chtype ch, int n) +{ +short row, col; +short end; + + T(("wvline(%p,%lx,%d) called", win, 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; + + while(end >= row) { + win->_line[end].text[col] = ch | win->_attrs; + 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); + return OK; +} + diff --git a/lib/libcurses/lib_clear.c b/lib/libcurses/lib_clear.c new file mode 100644 index 00000000000..6f329139818 --- /dev/null +++ b/lib/libcurses/lib_clear.c @@ -0,0 +1,40 @@ + +/*************************************************************************** +* 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_clear.c +** +** The routine wclear(). +** +*/ + +#include "curses.priv.h" + +int wclear(WINDOW *win) +{ + T(("wclear(%p) called", win)); + + werase(win); + + win->_clear = TRUE; + + return OK; +} diff --git a/lib/libcurses/lib_clrbot.c b/lib/libcurses/lib_clrbot.c new file mode 100644 index 00000000000..f7feca7ec5d --- /dev/null +++ b/lib/libcurses/lib_clrbot.c @@ -0,0 +1,72 @@ + +/*************************************************************************** +* 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_clrbot.c +** +** The routine wclrtobot(). +** +*/ + +#include "curses.priv.h" + +int wclrtobot(WINDOW *win) +{ +chtype *ptr, *end, *maxx = NULL; +short y, startx, minx; + + T(("wclrtobot(%p) called", win)); + + startx = win->_curx; + if (win->_flags & _NEED_WRAP) + startx++; + + 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++) { + int blank = _nc_render(win, *ptr, BLANK); + + 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; + } + _nc_synchook(win); + return OK; +} diff --git a/lib/libcurses/lib_clreol.c b/lib/libcurses/lib_clreol.c new file mode 100644 index 00000000000..146432ac575 --- /dev/null +++ b/lib/libcurses/lib_clreol.c @@ -0,0 +1,70 @@ + +/*************************************************************************** +* 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_clreol.c +** +** The routine wclrtoeol(). +** +*/ + +#include "curses.priv.h" + +int wclrtoeol(WINDOW *win) +{ +chtype *maxx, *ptr, *end; +short y, x, minx; + + T(("wclrtoeol(%p) called", win)); + + y = win->_cury; + x = win->_curx; + if (win->_flags & _NEED_WRAP + || y > win->_maxy + || x > win->_maxx) + return ERR; + + end = &win->_line[y].text[win->_maxx]; + minx = _NOCHANGE; + maxx = &win->_line[y].text[x]; + + for (ptr = maxx; ptr <= end; ptr++) { + int blank = _nc_render(win, win->_line[y].text[x], BLANK); + + 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; + } + _nc_synchook(win); + return(OK); +} diff --git a/lib/libcurses/lib_color.c b/lib/libcurses/lib_color.c new file mode 100644 index 00000000000..b690cb71f33 --- /dev/null +++ b/lib/libcurses/lib_color.c @@ -0,0 +1,325 @@ + +/*************************************************************************** +* 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_color.c + * + * Handles color emulation of SYS V curses + * + */ + +#include "curses.priv.h" +#include <stdlib.h> +#include <string.h> +#include "term.h" + +int COLOR_PAIRS; +int COLORS; +unsigned char *color_pairs; + +typedef struct +{ + short red, green, blue; +} +color_t; +static color_t *color_table; + +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 */ +}; +static const color_t hls_palette[] = +{ + /* H L S */ + {0, 0, 0}, /* COLOR_BLACK */ + {120, 50, 100}, /* COLOR_RED */ + {240, 50, 100}, /* COLOR_GREEN */ + {180, 50, 100}, /* COLOR_YELLOW */ + {330, 50, 100}, /* COLOR_BLUE */ + {60, 50, 100}, /* COLOR_MAGENTA */ + {300, 50, 100}, /* COLOR_CYAN */ + {0, 50, 100}, /* COLOR_WHITE */ +}; + +int start_color(void) +{ + T(("start_color() called.")); + +#ifdef orig_pair + if (orig_pair != NULL) + { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + } +#endif /* orig_pair */ +#ifdef orig_colors + if (orig_colors != NULL) + { + TPUTS_TRACE("orig_colors"); + putp(orig_colors); + } +#endif /* orig_colors */ +#if defined(orig_pair) && defined(orig_colors) + if (!orig_pair && !orig_colors) + return ERR; +#endif /* defined(orig_pair) && defined(orig_colors) */ + if (max_pairs != -1) + COLOR_PAIRS = max_pairs; + else + return ERR; + color_pairs = calloc((unsigned int)max_pairs, sizeof(char)); + if (max_colors != -1) + COLORS = max_colors; + else + return ERR; + SP->_coloron = 1; + +#ifdef hue_lightness_saturation + color_table = malloc(sizeof(color_t) * COLORS); + if (hue_lightness_saturation) + memcpy(color_table, hls_palette, sizeof(color_t) * COLORS); + else +#endif /* hue_lightness_saturation */ + memcpy(color_table, cga_palette, sizeof(color_t) * COLORS); + + if (orig_colors) + { + TPUTS_TRACE("orig_colors"); + putp(orig_colors); + } + + T(("started color: COLORS = %d, COLOR_PAIRS = %d", COLORS, COLOR_PAIRS)); + + return OK; +} + +#ifdef hue_lightness_saturation +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; + + /* calculate lightness */ + *l = (min + max) / 20; + + if (min == max) /* black, white and all shades of gray */ + { + *h = 0; + *s = 0; + return; + } + + /* calculate saturation */ + if (*l < 50) + *s = ((max - min) * 100) / (max + min); + else *s = ((max - min) * 100) / (2000 - max - min); + + /* calculate hue */ + if (r == max) + t = 120 + ((g - b) * 60) / (max - min); + else + if (g == max) + t = 240 + ((b - r) * 60) / (max - min); + else + t = 360 + ((r - g) * 60) / (max - min); + + *h = t % 360; +} +#endif /* hue_lightness_saturation */ + +int init_pair(short pair, short f, short b) +{ + T(("init_pair( %d, %d, %d )", pair, f, b)); + + if ((pair < 1) || (pair >= COLOR_PAIRS)) + return ERR; + if ((f < 0) || (f >= COLORS) || (b < 0) || (b >= COLORS)) + return ERR; + + /* + * FIXME: when a pair's content is changed, replace its colors + * (if pair was initialized before a screen update is performed + * replacing original pair colors with the new ones) + */ + + color_pairs[pair] = ( (f & 0x0f) | (b & 0x0f) << 4 ); + + if (initialize_pair) + { + const color_t *tp = hue_lightness_saturation ? hls_palette : cga_palette; + + T(("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)\n", + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + + if (initialize_pair) + { + TPUTS_TRACE("initialize_pair"); + putp(tparm(initialize_pair, + pair, + tp[f].red, tp[f].green, tp[f].blue, + tp[b].red, tp[b].green, tp[b].blue)); + } + } + + return OK; +} + +int init_color(short color, short r, short g, short b) +{ +#ifdef initialize_color + if (initialize_color == NULL) + return ERR; +#endif /* initialize_color */ + + if (color < 0 || color >= COLORS) + return ERR; +#ifdef hue_lightness_saturation + if (hue_lightness_saturation == TRUE) + if (r < 0 || r > 360 || g < 0 || g > 100 || b < 0 || b > 100) + return ERR; + if (hue_lightness_saturation == FALSE) +#endif /* hue_lightness_saturation */ + if (r < 0 || r > 1000 || g < 0 || g > 1000 || b < 0 || b > 1000) + return ERR; + +#ifdef hue_lightness_saturation + if (hue_lightness_saturation) + rgb2hls(r, g, b, + &color_table[color].red, + &color_table[color].green, + &color_table[color].blue); + else +#endif /* hue_lightness_saturation */ + { + color_table[color].red = r; + color_table[color].green = g; + color_table[color].blue = b; + } + +#ifdef initialize_color + if (initialize_color) + { + TPUTS_TRACE("initialize_color"); + putp(tparm(initialize_color, color, r, g, b)); + } +#endif /* initialize_color */ + return OK; +} + +bool can_change_color(void) +{ + return (can_change != 0); +} + +int has_colors(void) +{ + return ((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) + ); +} + +int color_content(short color, short *r, short *g, short *b) +{ + if (color < 0 || color > COLORS) + return ERR; + + *r = color_table[color].red; + *g = color_table[color].green; + *b = color_table[color].blue; + return OK; +} + +int pair_content(short pair, short *f, short *b) +{ + + if ((pair < 1) || (pair > COLOR_PAIRS)) + return ERR; + *f = color_pairs[pair] & 0x0f; + *b = color_pairs[pair] & 0xf0; + *b >>= 4; + return OK; +} + + +void _nc_do_color(int pair, int (*outc)(int)) +{ + short fg, bg; + + if (pair == 0) + { + if (orig_pair) + { + TPUTS_TRACE("orig_pair"); + tputs(orig_pair, 1, outc); + } + } + else + { + if (set_color_pair) + { + TPUTS_TRACE("set_color_pair"); + tputs(tparm(set_color_pair, pair), 1, outc); + } + else + { + pair_content(pair, &fg, &bg); + + T(("setting colors: pair = %d, fg = %d, bg = %d\n", pair, fg, bg)); + + if (set_a_foreground) + { + TPUTS_TRACE("set_a_foreground"); + tputs(tparm(set_a_foreground, fg), 1, outc); + } + else + { + TPUTS_TRACE("set_foreground"); + tputs(tparm(set_foreground, fg), 1, outc); + } + if (set_a_background) + { + TPUTS_TRACE("set_a_background"); + tputs(tparm(set_a_background, bg), 1, outc); + } + else + { + TPUTS_TRACE("set_background"); + tputs(tparm(set_background, bg), 1, outc); + } + } + } +} diff --git a/lib/libcurses/lib_data.c b/lib/libcurses/lib_data.c new file mode 100644 index 00000000000..b3c962e3c16 --- /dev/null +++ b/lib/libcurses/lib_data.c @@ -0,0 +1,64 @@ + +/*************************************************************************** +* 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_data.c +** +** Common data that may/may not be allocated, but is referenced globally +** +*/ + +#include "curses.priv.h" + +#include <stdlib.h> + +WINDOW *stdscr, *curscr, *newscr; + +/* + * The variable 'SP' will be defined as a function on systems that cannot link + * data-only modules, since it is used in a lot of places within ncurses and we + * cannot guarantee that any application will use any particular function. We + * put the WINDOW variables in this module, because it appears that any + * application that uses them will also use 'SP'. + * + * This module intentionally does not reference other ncurses modules, to avoid + * module coupling that increases the size of the executable. + */ +#if BROKEN_LINKER +static SCREEN *my_screen; + +SCREEN *_nc_screen(void) +{ + return my_screen; +} + +int _nc_alloc_screen(void) +{ + return ((my_screen = (SCREEN *) calloc(sizeof(*SP), 1)) != NULL); +} + +void _nc_set_screen(SCREEN *sp) +{ + my_screen = sp; +} +#else +SCREEN *SP; +#endif diff --git a/lib/libcurses/lib_delch.c b/lib/libcurses/lib_delch.c new file mode 100644 index 00000000000..6f8f37185dd --- /dev/null +++ b/lib/libcurses/lib_delch.c @@ -0,0 +1,56 @@ + +/*************************************************************************** +* 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_delch.c +** +** The routine wdelch(). +** +*/ + +#include "curses.priv.h" + +int wdelch(WINDOW *win) +{ +chtype *temp1, *temp2; +chtype *end; +chtype blank = _nc_render(win, ' ', BLANK | win->_attrs); + + T(("wdelch(%p) called", 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) + win->_line[win->_cury].firstchar = win->_curx; + + _nc_synchook(win); + return OK; +} diff --git a/lib/libcurses/lib_delwin.c b/lib/libcurses/lib_delwin.c new file mode 100644 index 00000000000..b3453cad74a --- /dev/null +++ b/lib/libcurses/lib_delwin.c @@ -0,0 +1,53 @@ + +/*************************************************************************** +* 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_delwin.c +** +** The routine delwin(). +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> + +int delwin(WINDOW *win) +{ +int i; + + T(("delwin(%p) called", win)); + + if (win == NULL) + return(ERR); + + if (! (win->_flags & _SUBWIN)) { + for (i = 0; i <= win->_maxy && win->_line[i].text; i++) + free(win->_line[i].text); + } + + free(win->_line); + + touchwin((win->_flags & _SUBWIN) ? win->_parent : curscr); + + free(win); + + return(OK); +} diff --git a/lib/libcurses/lib_doupdate.c b/lib/libcurses/lib_doupdate.c new file mode 100644 index 00000000000..3d6f2d79e38 --- /dev/null +++ b/lib/libcurses/lib_doupdate.c @@ -0,0 +1,840 @@ + +/*************************************************************************** +* 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_doupdate.c + * + * The routine doupdate() and its dependents. Also _nc_outstr(), + * so all physcal output is concentrated here. + * + *-----------------------------------------------------------------*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include <sys/types.h> +#if HAVE_SYS_TIME_H && ! SYSTEM_LOOKS_LIKE_SCO +#include <sys/time.h> +#endif +#if HAVE_SYS_SELECT_H +#include <sys/types.h> +#include <sys/select.h> +#endif +#include <string.h> +#include "term.h" + +/* + * This define controls the line-breakout optimization. Every once in a + * while during screen refresh, we want to check for input and abort the + * update if there's some waiting. CHECK_INTERVAL controls the number of + * changed lines to be emitted between input checks. + * + * 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 + +/* + * Enable checking to see if doupdate and friends are tracking the true + * cursor position correctly. NOTE: this is a debugging hack which will + * work ONLY on ANSI-compatible terminals! + */ +/* #define POSITION_DEBUG */ + +static void ClrUpdate( WINDOW *scr ); +static void TransformLine( int const lineno ); +static void NoIDcTransformLine( int const lineno ); +static void IDcTransformLine( int const lineno ); +static void ClearScreen( void ); +static int InsStr( chtype *line, int count ); +static void DelChar( int count ); + +#define UpdateAttrs(c) if (curscr->_attrs != AttrOf(c)) { \ + curscr->_attrs = AttrOf(c); \ + vidputs(curscr->_attrs, _nc_outch); \ + } + +#ifdef POSITION_DEBUG +/**************************************************************************** + * + * Debugging code. Only works on ANSI-standard terminals. + * + ****************************************************************************/ + +void position_check(int expected_y, int expected_x, char *legend) +/* check to see if the real cursor position matches the virtual */ +{ + static char buf[9]; + int y, x; + + if (_nc_tracing) + return; + + memset(buf, '\0', sizeof(buf)); + (void) write(1, "\033[6n", 4); /* only works on ANSI-compatibles */ + (void) read(0, (void *)buf, 8); + _tracef("probe returned %s", _nc_visbuf(buf)); + + /* try to interpret as a position report */ + if (sscanf(buf, "\033[%d;%dR", &y, &x) != 2) + _tracef("position probe failed in %s", legend); + else if (y - 1 != expected_y || x - 1 != expected_x) + _tracef("position seen (%d, %d) doesn't match expected one (%d, %d) in %s", + y-1, x-1, expected_y, expected_x, legend); + else + _tracef("position matches OK in %s", legend); +} +#endif /* POSITION_DEBUG */ + +/**************************************************************************** + * + * Optimized update code + * + ****************************************************************************/ + +static __inline void GoTo(int const row, int const col) +{ + chtype oldattr = SP->_current_attr; + + TR(TRACE_MOVE, ("GoTo(%d, %d) from (%d, %d)", + row, col, SP->_cursrow, SP->_curscol)); + +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "GoTo"); +#endif /* POSITION_DEBUG */ + + /* + * Force restore even if msgr is on when we're in an alternate + * character set -- these have a strong tendency to screw up the + * CR & LF used for local character motions! + */ + if ((oldattr & A_ALTCHARSET) + || (oldattr && !move_standout_mode)) + { + TR(TRACE_CHARPUT, ("turning off (%lx) %s before move", + oldattr, _traceattr(oldattr))); + vidattr(A_NORMAL); + curscr->_attrs = A_NORMAL; + } + + mvcur(SP->_cursrow, SP->_curscol, row, col); + SP->_cursrow = row; + SP->_curscol = col; +} + +static __inline void PutAttrChar(chtype ch) +{ + if (tilde_glitch && (TextOf(ch) == '~')) + ch = ('`' | AttrOf(ch)); + + TR(TRACE_CHARPUT, ("PutAttrChar(%s, %s) at (%d, %d)", + _tracechar((unsigned char)TextOf(ch)), + _traceattr(AttrOf(ch)), + SP->_cursrow, SP->_curscol)); + UpdateAttrs(ch); + putc((int)TextOf(ch), SP->_ofp); + SP->_curscol++; + if (char_padding) { + TPUTS_TRACE("char_padding"); + putp(char_padding); + } +} + +static bool check_pending(void) +/* check for pending input */ +{ + if (SP->_checkfd >= 0) { + fd_set fdset; + struct timeval ktimeout; + + ktimeout.tv_sec = + ktimeout.tv_usec = 0; + + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (select(SP->_checkfd+1, &fdset, NULL, NULL, &ktimeout) != 0) + { + fflush(SP->_ofp); + return TRUE; + } + } + return FALSE; +} + +/* + * No one supports recursive inline functions. However, gcc is quieter if we + * instantiate the recursive part separately. + */ +#if CC_HAS_INLINE_FUNCS +static void callPutChar(chtype const); +#else +#define callPutChar(ch) PutChar(ch) +#endif + +static __inline void PutChar(chtype const ch) +/* insert character, handling automargin stuff */ +{ + if (!(SP->_cursrow == screen_lines-1 && SP->_curscol == screen_columns-1 + && auto_right_margin && !eat_newline_glitch)) + { + PutAttrChar(ch); /* normal case */ + } + else if (!auto_right_margin /* maybe we can suppress automargin */ + || (enter_am_mode && exit_am_mode)) + { + bool old_am = auto_right_margin; + + 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); + } + } + else + { + 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; + } + + if (SP->_curscol >= screen_columns) + { + 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--; + } + } +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "PutChar"); +#endif /* POSITION_DEBUG */ +} + +#if CC_HAS_INLINE_FUNCS +static void callPutChar(chtype const ch) +{ + PutChar(ch); +} +#endif + +int doupdate(void) +{ +int i; + + T(("doupdate() called")); + +#ifdef TRACE + if (_nc_tracing & TRACE_UPDATE) + { + if (curscr->_clear) + _tracef("curscr is clear"); + else + _tracedump("curscr", curscr); + _tracedump("newscr", newscr); + } +#endif /* TRACE */ + + _nc_signal_handler(FALSE); + + if (SP->_endwin == TRUE) { + T(("coming back from shell mode")); + reset_prog_mode(); + if (enter_ca_mode) + { + TPUTS_TRACE("enter_ca_mode"); + putp(enter_ca_mode); + } + /* + * Undo the effects of terminal init strings that assume + * they know the screen size. Useful when you're running + * a vt100 emulation through xterm. Note: this may change + * the physical cursor location. + */ + if (change_scroll_region) + { + TPUTS_TRACE("change_scroll_region"); + putp(tparm(change_scroll_region, 0, screen_lines - 1)); + } + _nc_mouse_resume(SP); + newscr->_clear = TRUE; + SP->_endwin = FALSE; + } + + /* + * FIXME: Full support for magic-cookie terminals could go in here. + * The theory: we scan the virtual screen looking for attribute + * changes. Where we find one, check to make sure it's realizable + * by seeing if the required number of un-attributed blanks are + * present before or after the change. If not, nuke the attributes + * out of the following or preceding cells on the virtual screen, + * forward to the next change or backwards to the previous one. If + * so, displace the change by the required number of characters. + */ + + if (curscr->_clear) { /* force refresh ? */ + T(("clearing and updating curscr")); + ClrUpdate(curscr); /* yes, clear all & update */ + curscr->_clear = FALSE; /* reset flag */ + } else { + if (newscr->_clear) { + T(("clearing and updating newscr")); + ClrUpdate(newscr); + newscr->_clear = FALSE; + } else { + int changedlines; + + _nc_scroll_optimize(); + + T(("Transforming lines")); + for (i = changedlines = 0; + i < min(screen_lines,newscr->_maxy+1); + i++) + { + /* + * newscr->line[i].firstchar is normally set + * by wnoutrefresh. curscr->line[i].firstchar + * is normally set by _nc_scroll_window in the + * vertical-movement optimization code, + */ + if (newscr->_line[i].firstchar != _NOCHANGE + || curscr->_line[i].firstchar != _NOCHANGE) + { + TransformLine(i); + changedlines++; + } + + /* mark line changed successfully */ + if (i <= newscr->_maxy) + { + newscr->_line[i].firstchar = _NOCHANGE; + newscr->_line[i].lastchar = _NOCHANGE; + newscr->_line[i].oldindex = i; + } + if (i <= curscr->_maxy) + { + curscr->_line[i].firstchar = _NOCHANGE; + curscr->_line[i].lastchar = _NOCHANGE; + curscr->_line[i].oldindex = i; + } + + /* + * Here is our line-breakout optimization. + */ + if ((changedlines % CHECK_INTERVAL) == changedlines-1 + && check_pending()) + goto cleanup; + } + } + } + + /* this code won't be executed often */ + for (i = screen_lines; i <= newscr->_maxy; i++) + { + newscr->_line[i].firstchar = _NOCHANGE; + newscr->_line[i].lastchar = _NOCHANGE; + newscr->_line[i].oldindex = i; + } + for (i = screen_lines; i <= curscr->_maxy; i++) + { + curscr->_line[i].firstchar = _NOCHANGE; + curscr->_line[i].lastchar = _NOCHANGE; + curscr->_line[i].oldindex = i; + } + + curscr->_curx = newscr->_curx; + curscr->_cury = newscr->_cury; + + GoTo(curscr->_cury, curscr->_curx); + + cleanup: + if (curscr->_attrs != A_NORMAL) + vidattr(curscr->_attrs = A_NORMAL); + + fflush(SP->_ofp); + + _nc_signal_handler(TRUE); + + return OK; +} + +/* +** ClrUpdate(scr) +** +** Update by clearing and redrawing the entire screen. +** +*/ + +static void ClrUpdate(WINDOW *scr) +{ +int i = 0, j = 0; +int lastNonBlank; + + T(("ClrUpdate(%p) called", scr)); + if (back_color_erase) { + T(("back_color_erase, turning attributes off")); + vidattr(A_NORMAL); + } + ClearScreen(); + + if (scr != curscr) { + for (i = 0; i < screen_lines ; i++) + for (j = 0; j < screen_columns; j++) + curscr->_line[i].text[j] = ' '; /* shouldn't this include the bkgd? */ + } + + T(("updating screen from scratch")); + for (i = 0; i < min(screen_lines, scr->_maxy + 1); i++) { + GoTo(i, 0); + lastNonBlank = scr->_maxx; + + while (scr->_line[i].text[lastNonBlank] == BLANK && lastNonBlank > 0) + lastNonBlank--; + + for (j = 0; j <= min(lastNonBlank, screen_columns); j++) { + PutChar(scr->_line[i].text[j]); + } + } + + + if (scr != curscr) { + for (i = 0; i < screen_lines ; i++) + for (j = 0; j < screen_columns; j++) + curscr->_line[i].text[j] = scr->_line[i].text[j]; + } +} + +/* +** ClrToEOL() +** +** Clear to EOL. Deal with background color erase if terminal has this +** glitch. This code forces the current color and highlight to A_NORMAL +** before emitting the erase sequence, then restores the current +** attribute. +*/ + +static void ClrToEOL(void) +{ +int j; +attr_t oldcolor = 0; /* initialization pacifies -Wall */ + + if (back_color_erase) { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + oldcolor = SP->_current_attr & A_COLOR; + SP->_current_attr &=~ A_COLOR; + } + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + if (back_color_erase) + vidattr(SP->_current_attr | oldcolor); + + for (j = SP->_curscol; j < screen_columns; j++) + curscr->_line[SP->_cursrow].text[j] = ' '; +} + +static void ClrToBOL(void) +{ +int j; +attr_t oldcolor = 0; /* initialization pacifies -Wall */ + + if (back_color_erase) { + TPUTS_TRACE("orig_pair"); + putp(orig_pair); + oldcolor = SP->_current_attr & A_COLOR; + SP->_current_attr &=~ A_COLOR; + } + TPUTS_TRACE("clr_bol"); + putp(clr_bol); + if (back_color_erase) + vidattr(SP->_current_attr | oldcolor); + + for (j = 0; j <= SP->_curscol; j++) + curscr->_line[SP->_cursrow].text[j] = ' '; +} + +/* +** TransformLine(lineno) +** +** Call either IDcTransformLine or NoIDcTransformLine to do the +** update, depending upon availability of insert/delete character. +*/ + +static void TransformLine(int const lineno) +{ + + T(("TransformLine(%d) called",lineno)); + + if ( (insert_character || (enter_insert_mode && exit_insert_mode)) + && delete_character) + IDcTransformLine(lineno); + else + NoIDcTransformLine(lineno); +} + + + +/* +** NoIDcTransformLine(lineno) +** +** Transform the given line in curscr to the one in newscr, without +** using Insert/Delete Character. +** +** firstChar = position of first different character in line +** lastChar = position of last different character in line +** +** overwrite all characters between firstChar and lastChar. +** +*/ + +static void NoIDcTransformLine(int const lineno) +{ +int firstChar, lastChar; +chtype *newLine = newscr->_line[lineno].text; +chtype *oldLine = curscr->_line[lineno].text; +int k; +int attrchanged = 0; + + T(("NoIDcTransformLine(%d) called", lineno)); + + firstChar = 0; + while (firstChar < screen_columns - 1 && newLine[firstChar] == oldLine[firstChar]) { + if(ceol_standout_glitch) { + if(AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + attrchanged = 1; + } + firstChar++; + } + + T(("first char at %d is %lx", firstChar, newLine[firstChar])); + if (firstChar > screen_columns) + return; + + if(ceol_standout_glitch && attrchanged) { + firstChar = 0; + lastChar = screen_columns - 1; + GoTo(lineno, firstChar); + if(clr_eol) + ClrToEOL(); + } else { + lastChar = screen_columns - 1; + while (lastChar > firstChar && newLine[lastChar] == oldLine[lastChar]) + lastChar--; + GoTo(lineno, firstChar); + } + + T(("updating chars %d to %d", firstChar, lastChar)); + for (k = firstChar; k <= lastChar; k++) { + PutChar(newLine[k]); + oldLine[k] = newLine[k]; + } +} + +/* +** IDcTransformLine(lineno) +** +** Transform the given line in curscr to the one in newscr, using +** Insert/Delete Character. +** +** firstChar = position of first different character in line +** oLastChar = position of last different character in old line +** nLastChar = position of last different character in new line +** +** move to firstChar +** overwrite chars up to min(oLastChar, nLastChar) +** if oLastChar < nLastChar +** insert newLine[oLastChar+1..nLastChar] +** else +** delete oLastChar - nLastChar spaces +*/ + +static void IDcTransformLine(int const lineno) +{ +int firstChar, oLastChar, nLastChar; +chtype *newLine = newscr->_line[lineno].text; +chtype *oldLine = curscr->_line[lineno].text; +int k, n; +int attrchanged = 0; + + T(("IDcTransformLine(%d) called", lineno)); + + if(ceol_standout_glitch && clr_eol) { + firstChar = 0; + while(firstChar < screen_columns) { + if(AttrOf(newLine[firstChar]) != AttrOf(oldLine[firstChar])) + attrchanged = 1; + firstChar++; + } + } + + firstChar = 0; + + if (attrchanged) { + GoTo(lineno, firstChar); + ClrToEOL(); + for( k = 0 ; k <= (screen_columns-1) ; k++ ) + PutChar(newLine[k]); + } else { + while (firstChar < screen_columns && + newLine[firstChar] == oldLine[firstChar]) + firstChar++; + + if (firstChar >= screen_columns) + return; + + if (clr_bol) + { + int oFirstChar, nFirstChar; + + for (oFirstChar = 0; oFirstChar < screen_columns; oFirstChar++) + if (oldLine[oFirstChar] != BLANK) + break; + for (nFirstChar = 0; nFirstChar < screen_columns; nFirstChar++) + if (newLine[nFirstChar] != BLANK) + break; + + if (nFirstChar > oFirstChar + (int)strlen(clr_bol)) + { + GoTo(lineno, nFirstChar - 1); + ClrToBOL(); + + if(nFirstChar == screen_columns) + return; + + if (nFirstChar > firstChar) + firstChar = nFirstChar; + } + } + + oLastChar = screen_columns - 1; + while (oLastChar > firstChar && oldLine[oLastChar] == BLANK) + oLastChar--; + + nLastChar = screen_columns - 1; + while (nLastChar > firstChar && newLine[nLastChar] == BLANK) + nLastChar--; + + if((nLastChar == firstChar) + && clr_eol + && (curscr->_attrs == A_NORMAL)) { + GoTo(lineno, firstChar); + ClrToEOL(); + if(newLine[firstChar] != BLANK ) + PutChar(newLine[firstChar]); + } else if( newLine[nLastChar] != oldLine[oLastChar] ) { + n = max( nLastChar , oLastChar ); + + GoTo(lineno, firstChar); + for( k=firstChar ; k <= n ; k++ ) + PutChar(newLine[k]); + } else { + while (newLine[nLastChar] == oldLine[oLastChar]) { + if (nLastChar != 0 + && oLastChar != 0) { + nLastChar--; + oLastChar--; + } else { + break; + } + } + + n = min(oLastChar, nLastChar); + GoTo(lineno, firstChar); + + for (k=firstChar; k <= n; k++) + PutChar(newLine[k]); + + if (oLastChar < nLastChar) + InsStr(&newLine[k], nLastChar - oLastChar); + + else if (oLastChar > nLastChar ) { + /* + * The delete-char sequence will effectively + * shift in blanks from the right margin of the + * screen. Ensure that they are the right + * color by setting the video attributes from + * the last character on the row. + */ + UpdateAttrs(newLine[screen_columns-1]); + DelChar(oLastChar - nLastChar); + } + } + } + for (k = firstChar; k < screen_columns; k++) + oldLine[k] = newLine[k]; +} + +/* +** ClearScreen() +** +** Clear the physical screen and put cursor at home +** +*/ + +static void ClearScreen(void) +{ + + T(("ClearScreen() called")); + + if (clear_screen) { + TPUTS_TRACE("clear_screen"); + putp(clear_screen); + SP->_cursrow = SP->_curscol = 0; +#ifdef POSITION_DEBUG + position_check(SP->_cursrow, SP->_curscol, "ClearScreen"); +#endif /* POSITION_DEBUG */ + } else if (clr_eos) { + SP->_cursrow = SP->_curscol = -1; + GoTo(0,0); + + 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); + TPUTS_TRACE("clr_eol"); + putp(clr_eol); + } + GoTo(0,0); + } + T(("screen cleared")); +} + + +/* +** InsStr(line, count) +** +** Insert the count characters pointed to by line. +** +*/ + +static int InsStr(chtype *line, int count) +{ + T(("InsStr(%p,%d) called", line, count)); + + if (enter_insert_mode && exit_insert_mode) { + TPUTS_TRACE("enter_insert_mode"); + putp(enter_insert_mode); + while (count) { + PutAttrChar(*line); + line++; + count--; + } + TPUTS_TRACE("exit_insert_mode"); + putp(exit_insert_mode); + return(OK); + } else if (parm_ich) { + TPUTS_TRACE("parm_ich"); + tputs(tparm(parm_ich, count), count, _nc_outch); + while (count) { + PutAttrChar(*line); + line++; + count--; + } + return(OK); + } else { + while (count) { + TPUTS_TRACE("insert_character"); + putp(insert_character); + PutAttrChar(*line); + if (insert_padding) + { + TPUTS_TRACE("insert_padding"); + putp(insert_padding); + } + line++; + count--; + } + return(OK); + } +} + +/* +** DelChar(count) +** +** Delete count characters at current position +** +*/ + +static void DelChar(int count) +{ + T(("DelChar(%d) called, position = (%d,%d)", count, newscr->_cury, newscr->_curx)); + + if (parm_dch) { + TPUTS_TRACE("parm_dch"); + tputs(tparm(parm_dch, count), count, _nc_outch); + } else { + while (count--) + { + TPUTS_TRACE("delete_character"); + putp(delete_character); + } + } +} + +/* +** _nc_outstr(char *str) +** +** Emit a string without waiting for update. +*/ + +void _nc_outstr(char *str) +{ + FILE *ofp = SP ? SP->_ofp : stdout; + + (void) fputs(str, ofp); + (void) fflush(ofp); +} diff --git a/lib/libcurses/lib_endwin.c b/lib/libcurses/lib_endwin.c new file mode 100644 index 00000000000..065b5c7567b --- /dev/null +++ b/lib/libcurses/lib_endwin.c @@ -0,0 +1,55 @@ + +/*************************************************************************** +* 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_endwin.c +** +** The routine endwin(). +** +*/ + +#include "curses.priv.h" +#include "term.h" + +int +endwin(void) +{ + T(("endwin() called")); + + SP->_endwin = TRUE; + + _nc_mouse_wrap(SP); + + mvcur(-1, -1, screen_lines - 1, 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 (curscr && (curscr->_attrs != A_NORMAL)) + vidattr(curscr->_attrs = A_NORMAL); + + return(reset_shell_mode()); +} diff --git a/lib/libcurses/lib_erase.c b/lib/libcurses/lib_erase.c new file mode 100644 index 00000000000..1a3ee5c8841 --- /dev/null +++ b/lib/libcurses/lib_erase.c @@ -0,0 +1,66 @@ + +/*************************************************************************** +* 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_erase.c +** +** The routine werase(). +** +*/ + +#include "curses.priv.h" + +int werase(WINDOW *win) +{ +int y; +chtype *sp, *end, *start, *maxx = NULL; +short minx; + + T(("werase(%p) called", 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_render(win, *sp, 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; + } + } + win->_curx = win->_cury = 0; + win->_flags &= ~_NEED_WRAP; + _nc_synchook(win); + return OK; +} diff --git a/lib/libcurses/lib_getch.c b/lib/libcurses/lib_getch.c new file mode 100644 index 00000000000..12372bc0fc0 --- /dev/null +++ b/lib/libcurses/lib_getch.c @@ -0,0 +1,329 @@ + +/*************************************************************************** +* 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_getch.c +** +** The routine getch(). +** +*/ + +#include "curses.priv.h" +#include <sys/types.h> +#include <string.h> +#include <errno.h> +#if !HAVE_EXTERN_ERRNO +extern int errno; +#endif + +#define head SP->_fifohead +#define tail SP->_fifotail +#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 p_inc() { peek == FIFO_SIZE-1 ? peek = 0 : peek++;} + +int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ + +static int fifo_peek(void) +{ + T(("peeking at %d", peek+1)); + return SP->_fifo[++peek]; +} + +#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, _tracechar(SP->_fifo[i]))); +} +#endif /* TRACE */ + +static __inline int fifo_pull(void) +{ +int ch; + ch = SP->_fifo[head]; + T(("pulling %d from %d", ch, head)); + + h_inc(); +#ifdef TRACE + if (_nc_tracing & TRACE_FIFO) 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_FIFO) fifo_dump(); +#endif + return OK; +} + +static __inline int fifo_push(void) +{ +int n; +unsigned char ch; + + if (tail == -1) return ERR; + /* FALLTHRU */ +again: + n = read(SP->_ifd, &ch, 1); + if (n == -1 && errno == EINTR) + goto again; + T(("read %d characters", n)); + + SP->_fifo[tail] = ch; + if (head == -1) head = tail; + t_inc(); + T(("pushed %#x at %d", ch, tail)); +#ifdef TRACE + if (_nc_tracing & TRACE_FIFO) fifo_dump(); +#endif + return ch; +} + +static __inline void fifo_clear(void) +{ +int i; + for (i = 0; i < FIFO_SIZE; i++) + SP->_fifo[i] = 0; + head = -1; tail = peek = 0; +} + +static int kgetch(WINDOW *); + +void _nc_backspace(WINDOW *win) +{ + if (win->_curx == 0) + { + beep(); + return; + } + + mvwaddstr(curscr, win->_begy + win->_cury, 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->_begx + win->_curx, + win->_begy + win->_cury, win->_begx + win->_curx - 1); + _nc_outstr(" "); + mvcur(win->_begy + win->_cury, win->_begx + win->_curx, + win->_begy + win->_cury, win->_begx + win->_curx - 1); + SP->_curscol--; +} + +int +wgetch(WINDOW *win) +{ +bool setHere = FALSE; /* cbreak mode was set here */ +int ch; + + T(("wgetch(%p) called", win)); + + /* this should be eliminated */ + if (! win->_scroll && (SP->_echo) && (win->_flags & _FULLWIN) + && win->_curx == win->_maxx && win->_cury == win->_maxy) + return(ERR); + + if ((is_wintouched(win) || (win->_flags & _HASMOVED)) && !(win->_flags & _ISPAD)) + wrefresh(win); + + if (SP->_echo && ! (SP->_raw || SP->_cbreak)) { + cbreak(); + setHere = TRUE; + } + + if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { + int delay; + + T(("timed delay in wgetch()")); + if (SP->_cbreak > 1) + delay = (SP->_cbreak-1) * 100; + else + delay = win->_delay; + + T(("delay is %d microseconds", delay)); + + if (head == -1) /* fifo is empty */ + if (_nc_timed_wait(SP->_ifd, delay, NULL) == 0) + return ERR; + /* else go on to read data available */ + } + + /* + * Give the mouse interface a chance to pick up an event. + * If no mouse event, check for keyboard input. + */ + if (_nc_mouse_event(SP)) + ch = KEY_MOUSE; + else if (win->_use_keypad) { + /* + * This is tricky. We only want to get special-key + * events one at a time. But we want to accumulate + * mouse events until either (a) the mouse logic tells + * us it's picked up a complete gesture, or (b) + * there's a detectable time lapse after one. + * + * Note: if the mouse code starts failing to compose + * press/release events into clicks, you should probably + * increase _nc_max_click_interval. + */ + int runcount = 0; + + do { + ch = kgetch(win); + if (ch == KEY_MOUSE) + { + ++runcount; + if (_nc_mouse_inline(SP)) + break; + } + } while + (ch == KEY_MOUSE + && (_nc_timed_wait(SP->_ifd, _nc_max_click_interval, NULL) + || !_nc_mouse_parse(runcount))); + if (runcount > 0 && ch != KEY_MOUSE) + { + /* mouse event sequence ended by keystroke, push it */ + ungetch(ch); + ch = KEY_MOUSE; + } + } else { + if (head == -1) + fifo_push(); + ch = fifo_pull(); + } + + /* Strip 8th-bit if so desired. We do this only for characters that + * are in the range 128-255, to provide compatibility with terminals + * that display only 7-bit characters. Note that 'ch' may be a + * function key at this point, so we mustn't strip _those_. + */ + if ((ch < KEY_MIN) && (ch & 0x80)) + 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->_begx + win->_curx, + (chtype)(ch | win->_attrs)); + waddch(win, (chtype)(ch | win->_attrs)); + } + else + beep(); + } + if (setHere) + nocbreak(); + + T(("wgetch returning : 0x%x = %s", + ch, + (ch > KEY_MIN) ? keyname(ch) : unctrl(ch))); + + return(ch); +} + + +/* +** int +** kgetch() +** +** Get an input character, but take care of keypad sequences, returning +** an appropriate code when one matches the input. After each character +** is received, set an alarm call based on ESCDELAY. If no more of the +** sequence is received by the time the alarm goes off, pass through +** the sequence gotten so far. +** +*/ + +static int +kgetch(WINDOW *win) +{ +struct try *ptr; +int ch = 0; +int timeleft = ESCDELAY; + + TR(TRACE_FIFO, ("kgetch(%p) called", win)); + + ptr = SP->_keytry; + + if (head == -1) { + ch = fifo_push(); + peek = 0; + while (ptr != NULL) { + TR(TRACE_FIFO, ("ch: %s", _tracechar((unsigned char)ch))); + while ((ptr != NULL) && (ptr->ch != (unsigned char)ch)) + ptr = ptr->sibling; +#ifdef TRACE + if (ptr == NULL) + {TR(TRACE_FIFO, ("ptr is null"));} + else + TR(TRACE_FIFO, ("ptr=%p, ch=%d, value=%d", + ptr, ptr->ch, ptr->value)); +#endif /* TRACE */ + + if (ptr != NULL) + if (ptr->value != 0) { /* sequence terminated */ + TR(TRACE_FIFO, ("end of sequence")); + fifo_clear(); + return(ptr->value); + } else { /* go back for another character */ + ptr = ptr->child; + TR(TRACE_FIFO, ("going back for more")); + } else + break; + + TR(TRACE_FIFO, ("waiting for rest of sequence")); + if (_nc_timed_wait(SP->_ifd, timeleft, &timeleft) < 1) { + TR(TRACE_FIFO, ("ran out of time")); + return(fifo_pull()); + } else { + TR(TRACE_FIFO, ("got more!")); + fifo_push(); + ch = fifo_peek(); + } + } + } + return(fifo_pull()); +} diff --git a/lib/libcurses/lib_getstr.c b/lib/libcurses/lib_getstr.c new file mode 100644 index 00000000000..5f4dbcd2b7c --- /dev/null +++ b/lib/libcurses/lib_getstr.c @@ -0,0 +1,131 @@ + +/*************************************************************************** +* 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_getstr.c +** +** The routine wgetstr(). +** +*/ + +#include "curses.priv.h" +#include "unctrl.h" +#include <string.h> + +int wgetnstr(WINDOW *win, char *str, int maxlen) +{ +bool oldnl, oldecho, oldraw, oldcbreak, oldkeypad; +char erasec; +char killc; +char *oldstr; +int ch; + + T(("wgetnstr(%p,%p, %d) called", win, str, maxlen)); + + 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(); + + oldstr = str; + + if (is_wintouched(win) || (win->_flags & _HASMOVED)) + wrefresh(win); + + while ((ch = wgetch(win)) != ERR) { + /* + * Some terminals (the Wyse-50 is the most common) generate + * a \n from the down-arrow key. With this logic, it's the + * user's choice whether to set kcud=\n for wgetch(); + * terminating *getstr() with \n should work either way. + */ + if (ch == '\n' || ch == '\r' || ch == KEY_DOWN) + break; + if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { + if (str > oldstr) { + str--; + if (oldecho == TRUE) + _nc_backspace(win); + } + } else if (ch == killc) { + while (str > oldstr) { + str--; + if (oldecho == TRUE) + _nc_backspace(win); + } + } else if (ch >= KEY_MIN + || (maxlen >= 0 && str - oldstr >= maxlen)) { + beep(); + } else { + if (oldecho == TRUE) { + char *glyph = unctrl(ch); + + mvwaddstr(curscr, win->_begy + win->_cury, + win->_begx + win->_curx, glyph); + waddstr(win, glyph); + _nc_outstr(glyph); + SP->_curscol += strlen(glyph); + } + *str++ = ch; + } + } + + win->_curx = 0; + win->_flags &= ~_NEED_WRAP; + if (win->_cury < win->_maxy) + win->_cury++; + wrefresh(win); + + if (oldnl == FALSE) + nonl(); + + if (oldecho == TRUE) + echo(); + + if (oldraw == TRUE) + raw(); + + if (oldcbreak == FALSE) + nocbreak(); + + if (oldkeypad == FALSE) + keypad(win, FALSE); + + if (ch == ERR) { + *str = '\0'; + return ERR; + } + *str = '\0'; + + T(("wgetnstr returns \"%s\"", _nc_visbuf(oldstr))); + + return(OK); +} diff --git a/lib/libcurses/lib_inchstr.c b/lib/libcurses/lib_inchstr.c new file mode 100644 index 00000000000..2dc64bff0d6 --- /dev/null +++ b/lib/libcurses/lib_inchstr.c @@ -0,0 +1,43 @@ + +/*************************************************************************** +* 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_inchstr.c +** +** The routine winchnstr(). +** +*/ + +#include "curses.priv.h" + +int winchnstr(WINDOW *win, chtype *str, int n) +{ + int i; + + T(("winchnstr(%p,'%p',%d) called", win, str, n)); + + for (i = 0; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) + str[i] = win->_line[win->_cury].text[win->_curx + i]; + str[i] = (chtype)0; + + return(i); +} diff --git a/lib/libcurses/lib_initscr.c b/lib/libcurses/lib_initscr.c new file mode 100644 index 00000000000..b9c6fcaaad9 --- /dev/null +++ b/lib/libcurses/lib_initscr.c @@ -0,0 +1,75 @@ + +/*************************************************************************** +* 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_initscr.c +** +** The routines initscr(), and termname(). +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include <string.h> + +WINDOW *initscr(void) +{ +char *name = getenv("TERM"); + + if (name == 0) + name = "unknown"; + if (newterm(name, stdout, stdin) == NULL) { + fprintf(stderr, "Error opening terminal: %s.\n", name); + exit(1); + } + + /* allow user to set maximum escape delay from the environment */ + if ((name = getenv("ESCDELAY"))) + ESCDELAY = atoi(getenv("ESCDELAY")); + + def_shell_mode(); + + /* follow the XPG4 requirement to turn echo off at this point */ + noecho(); + +#ifdef _XOPEN_SOURCE_EXTENDED + /* for extended XPG4 conformance requires cbreak() at this point */ + cbreak(); +#endif /* _XOPEN_SOURCE_EXTENDED */ + + def_prog_mode(); + return(stdscr); +} + +char *termname(void) +{ +char *term = getenv("TERM"); +static char ret[15]; + + T(("termname() called")); + + if (term == (char *)NULL) + return(char *)NULL; + else { + (void) strncpy(ret, term, sizeof(ret) - 1); + return(ret); + } +} diff --git a/lib/libcurses/lib_insch.c b/lib/libcurses/lib_insch.c new file mode 100644 index 00000000000..b2f13744e5b --- /dev/null +++ b/lib/libcurses/lib_insch.c @@ -0,0 +1,54 @@ + +/*************************************************************************** +* 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_insch.c +** +** The routine winsch(). +** +*/ + +#include "curses.priv.h" + +int winsch(WINDOW *win, chtype c) +{ +chtype *temp1, *temp2; +chtype *end; + + T(("winsch(%p,'%lx') called", win, c)); + + end = &win->_line[win->_cury].text[win->_curx]; + temp1 = &win->_line[win->_cury].text[win->_maxx]; + temp2 = temp1 - 1; + + while (temp1 > end) + *temp1-- = *temp2--; + + *temp1 = _nc_render(win, c, c | win->_attrs); + + 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; + return OK; +} diff --git a/lib/libcurses/lib_insdel.c b/lib/libcurses/lib_insdel.c new file mode 100644 index 00000000000..a6e6a86c78b --- /dev/null +++ b/lib/libcurses/lib_insdel.c @@ -0,0 +1,51 @@ + +/*************************************************************************** +* 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_insdel.c +** +** The routine winsdelln(win, n). +** positive n insert n lines above current line +** negative n delete n lines starting from current line +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> + +int +winsdelln(WINDOW *win, int n) +{ + T(("winsdel(%p,%d) called", win, n)); + + if (n == 0) + return OK; + + _nc_scroll_window(win, -n, win->_cury, win->_maxy); + touchline(win, win->_cury, win->_maxy - win->_cury + 1); + + _nc_synchook(win); + return OK; +} + + diff --git a/lib/libcurses/lib_insstr.c b/lib/libcurses/lib_insstr.c new file mode 100644 index 00000000000..1d1d867ecc8 --- /dev/null +++ b/lib/libcurses/lib_insstr.c @@ -0,0 +1,61 @@ + +/*************************************************************************** +* 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_insstr.c +** +** The routine winsnstr(). +** +*/ + +#include "curses.priv.h" +#include <ctype.h> + +int winsnstr(WINDOW *win, const char *str, int n) +{ +short oy = win->_cury; +short ox = win->_curx; +char *cp; + + T(("winsstr(%p,'%s',%d) called", win, str, n)); + + for (cp = (char *)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); + return OK; +} diff --git a/lib/libcurses/lib_instr.c b/lib/libcurses/lib_instr.c new file mode 100644 index 00000000000..e1ef5272fd9 --- /dev/null +++ b/lib/libcurses/lib_instr.c @@ -0,0 +1,44 @@ + +/*************************************************************************** +* 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_instr.c +** +** The routine winnstr(). +** +*/ + +#include "curses.priv.h" + +int winnstr(WINDOW *win, char *str, int n) +{ + int i; + + T(("winnstr(%p,'%p',%d) called", win, str, n)); + + for (i = 0; (n < 0 || (i < n)) && (win->_curx + i <= win->_maxx); i++) + str[i] = win->_line[win->_cury].text[win->_curx + i] & A_CHARTEXT; + str[i] = '\0'; + + return(i); +} + diff --git a/lib/libcurses/lib_isendwin.c b/lib/libcurses/lib_isendwin.c new file mode 100644 index 00000000000..bfd991e3cfb --- /dev/null +++ b/lib/libcurses/lib_isendwin.c @@ -0,0 +1,37 @@ + +/*************************************************************************** +* 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_endwin.c +** +** The routine endwin(). +** +*/ + +#include "curses.priv.h" + +int isendwin(void) +{ + if (SP == NULL) + return FALSE; + return SP->_endwin; +} diff --git a/lib/libcurses/lib_kernel.c b/lib/libcurses/lib_kernel.c new file mode 100644 index 00000000000..622c549acea --- /dev/null +++ b/lib/libcurses/lib_kernel.c @@ -0,0 +1,309 @@ + +/*************************************************************************** +* 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_kernel.c + * + * Misc. low-level routines: + * napms() + * reset_prog_mode() + * reset_shell_mode() + * baudrate() + * delay_output() + * erasechar() + * killchar() + * flushinp() + * savetty() + * resetty() + * + * + */ + +#include "curses.priv.h" +#include "term.h" /* cur_term, pad_char */ +#include <errno.h> +#if !HAVE_EXTERN_ERRNO +extern int errno; +#endif + +int napms(int ms) +{ + T(("napms(%d) called", ms)); + + usleep(1000*(unsigned)ms); + return OK; +} + +#ifndef EXTERN_TERMINFO +int reset_prog_mode(void) +{ + T(("reset_prog_mode() called")); + +#ifdef TERMIOS + tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb); +#else + stty(cur_term->Filedes, &cur_term->Nttyb); +#endif + if (SP && stdscr && stdscr->_use_keypad) + _nc_keypad(TRUE); + + return OK; +} + + +int reset_shell_mode(void) +{ + T(("reset_shell_mode() called")); + + if (SP) + { + fflush(SP->_ofp); + _nc_keypad(FALSE); + } + +#ifdef TERMIOS + tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Ottyb); +#else + stty(cur_term->Filedes, &cur_term->Ottyb); +#endif + return OK; +} +#endif /* EXTERN_TERMINFO */ + +int delay_output(float ms) +{ + T(("delay_output(%f) called", ms)); + + if (SP == 0 || SP->_baudrate == ERR) + return(ERR); +#ifdef no_pad_char + else if (no_pad_char) + _nc_timed_wait(0, (int)ms, (int *)NULL); +#endif /* no_pad_char */ + else { + register int nullcount; + char null = '\0'; + +#ifdef pad_char + if (pad_char) + null = pad_char[0]; +#endif /* pad_char */ + + for (nullcount = ms * 1000 / SP->_baudrate; nullcount > 0; nullcount--) + putc(null, SP->_ofp); + (void) fflush(SP->_ofp); + } + + return OK; +} + +/* + * erasechar() + * + * Return erase character as given in cur_term->Ottyb. + * + */ + +char +erasechar(void) +{ + T(("erasechar() called")); + +#ifdef TERMIOS + return(cur_term->Ottyb.c_cc[VERASE]); +#else + return(cur_term->Ottyb.sg_erase); +#endif + +} + + + +/* + * killchar() + * + * Return kill character as given in cur_term->Ottyb. + * + */ + +char +killchar(void) +{ + T(("killchar() called")); + +#ifdef TERMIOS + return(cur_term->Ottyb.c_cc[VKILL]); +#else + return(cur_term->Ottyb.sg_kill); +#endif +} + + + +/* + * flushinp() + * + * Flush any input on cur_term->Filedes + * + */ + +int flushinp(void) +{ + T(("flushinp() called")); + +#ifdef TERMIOS + tcflush(cur_term->Filedes, TCIFLUSH); +#else + errno = 0; + do { + ioctl(cur_term->Filedes, TIOCFLUSH, 0); + } while + (errno == EINTR); +#endif + if (SP) { + SP->_fifohead = -1; + SP->_fifotail = 0; + SP->_fifopeek = 0; + } + return OK; + +} + + + +/* + * int + * baudrate() + * + * Returns the current terminal's baud rate. + * + */ + +struct speed { + speed_t s; + int sp; +}; + +static struct speed const speeds[] = { + {B0, 0}, + {B50, 50}, + {B75, 75}, + {B110, 110}, + {B134, 134}, + {B150, 150}, + {B200, 200}, + {B300, 300}, + {B600, 600}, + {B1200, 1200}, + {B1800, 1800}, + {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 +}; + +int +baudrate(void) +{ +int i, ret; + + T(("baudrate() called")); + +#ifdef TERMIOS + ret = cfgetospeed(&cur_term->Nttyb); +#else + ret = cur_term->Nttyb.sg_ospeed; +#endif + if(ret < 0 || ret > MAX_BAUD) + return ERR; + SP->_baudrate = ERR; + for (i = 0; i < (sizeof(speeds) / sizeof(struct speed)); i++) + if (speeds[i].s == ret) + { + SP->_baudrate = speeds[i].sp; + break; + } + return(SP->_baudrate); +} + + +/* +** savetty() and resetty() +** +*/ + +static TTY buf; + +int savetty(void) +{ + T(("savetty() called")); + +#ifdef TERMIOS + tcgetattr(cur_term->Filedes, &buf); +#else + gtty(cur_term->Filedes, &buf); +#endif + return OK; +} + +int resetty(void) +{ + T(("resetty() called")); + +#ifdef TERMIOS + tcsetattr(cur_term->Filedes, TCSANOW, &buf); +#else + stty(cur_term->Filedes, &buf); +#endif + return OK; +} + diff --git a/lib/libcurses/lib_longname.c b/lib/libcurses/lib_longname.c new file mode 100644 index 00000000000..d9883ae3d50 --- /dev/null +++ b/lib/libcurses/lib_longname.c @@ -0,0 +1,53 @@ + +/*************************************************************************** +* 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_longname.c +** +** The routine longname(). +** +*/ + +#ifdef EXTERN_TERMINFO +#include <term.h> +#else +#include "curses.priv.h" +#endif +#include <string.h> + +char * +longname(void) +{ +#ifdef EXTERN_TERMINFO + return cur_term->name; +#else +char *ptr; + + T(("longname() called")); + + for (ptr = ttytype + strlen(ttytype); ptr > ttytype; ptr--) + if (*ptr == '|') + return(ptr + 1); + + return(ttytype); +#endif +} diff --git a/lib/libcurses/lib_mouse.c b/lib/libcurses/lib_mouse.c new file mode 100644 index 00000000000..e8f73f65f36 --- /dev/null +++ b/lib/libcurses/lib_mouse.c @@ -0,0 +1,580 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + +/* + * This module is intended to encapsulate ncurses's interface to pointing + * devices. + * + * The first method used is xterm's internal mouse-tracking facility. + * The second (not yet implemented) will be Alessandro Rubini's GPM server. + * + * Notes for implementors of new mouse-interface methods: + * + * The code is logically split into a lower level that accepts event reports + * in a device-dependent format and an upper level that parses mouse gestures + * and filters events. The mediating data structure is a circular queue of + * MEVENT structures. + * + * Functionally, the lower level's job is to pick up primitive events and + * put them on the circular queue. This can happen in one of two ways: + * either (a) _nc_mouse_event() detects a series of incoming mouse reports + * and queues them, or (b) code in lib_getch.c detects the kmous prefix in + * the keyboard input stream and calls _nc_mouse_inline to queue up a series + * of adjacent mouse reports. + * + * In either case, _nc_mouse_parse() should be called after the series is + * accepted to parse the digested mouse reports (low-level MEVENTs) into + * a gesture (a high-level or composite MEVENT). + * + * Don't be too shy about adding new event types or modifiers, if you can find + * room for them in the 32-bit mask. The API is written so that users get + * feedback on which theoretical event types they won't see when they call + * mousemask. There's one bit per button (the RESERVED_EVENT bit) not being + * used yet, and a couple of bits open at the high end. + */ + +#include <curses.h> +#include <string.h> +#include "term.h" +#include "curses.priv.h" + +#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 */ +#define M_GPM 1 /* use GPM (not yet implemented) */ + +static mmask_t eventmask; /* current event mask */ + +/* 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 */ +static MEVENT *eventp = events; /* next free slot in event queue */ +#define NEXT(ep) ((ep == events + EV_MAX - 1) ? events : ep + 1) +#define PREV(ep) ((ep == events) ? events + EV_MAX - 1 : ep - 1) + +void _nc_mouse_init(SCREEN *sp) +/* initialize the mouse -- called at screen-setup time */ +{ + int i; + + T(("_nc_mouse_init() called")); + + for (i = 0; i < EV_MAX; i++) + events[i].id = INVALID_EVENT; + +#ifdef EXTERN_TERMINFO + /* we know how to recognize mouse events under xterm */ + if (!strncmp(cur_term->name, "xterm", 5) && key_mouse) + mousetype = M_XTERM; +#else + /* we know how to recognize mouse events under xterm */ + if (!strncmp(cur_term->type.term_names, "xterm", 5) && key_mouse) + mousetype = M_XTERM; +#endif + + /* GPM: initialize connection to gpm server */ +} + +bool _nc_mouse_event(SCREEN *sp) +/* query to see if there is a pending mouse event */ +{ + /* xterm: never have to query, mouse events are in the keyboard stream */ + /* GPM: query server for event, return TRUE if we find one */ + return(FALSE); /* no event waiting */ +} + +bool _nc_mouse_inline(SCREEN *sp) +/* mouse report received in the keyboard stream -- parse its info */ +{ + T(("_nc_mouse_inline() called")); + + if (mousetype == M_XTERM) + { + char kbuf[4]; + MEVENT *prev; + + /* This code requires that your xterm entry contain the kmous + * capability and that it be set to the \E[M documented in the + * Xterm Control Sequences reference. This is how we + * arrange for mouse events to be reported via a KEY_MOUSE + * return value from wgetch(). After this value is received, + * _nc_mouse_inline() gets called and is immediately + * responsible for parsing the mouse status information + * following the prefix. + * + * The following quotes from the ctrlseqs.ms document in the + * X distribution, describing the X mouse tracking feature: + * + * Parameters for all mouse tracking escape sequences + * generated by xterm encode numeric parameters in a single + * character as value+040. For example, ! is 1. + * + * On button press or release, xterm sends ESC [ M CbCxCy. + * The low two bits of Cb encode button information: 0=MB1 + * pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The + * upper bits encode what modifiers were down when the + * button was pressed and are added together. 4=Shift, + * 8=Meta, 16=Control. Cx and Cy are the x and y coordinates + * of the mouse event. The upper left corner is (1,1). + * + * (End quote) By the time we get here, we've eaten the + * key prefix. + */ + (void) read(sp->_ifd, &kbuf, 3); + kbuf[3] = '\0'; + +#ifdef MOUSEDEBUG + T(("_nc_mouse_inline sees the following xterm data: '%s'", kbuf)); +#endif /* MOUSEDEBUG */ + + eventp->id = 0; /* there's only one mouse... */ + + /* processing code goes here */ + eventp->bstate = 0; + switch (kbuf[0] & 0x3) + { + case 0x0: + eventp->bstate = BUTTON1_PRESSED; + break; + + case 0x1: + eventp->bstate = BUTTON2_PRESSED; + break; + + case 0x2: + eventp->bstate = BUTTON3_PRESSED; + break; + + case 0x3: + /* + * Release events aren't reported for individual buttons, + * just for the button set as a whole... + */ + eventp->bstate = + (BUTTON1_RELEASED | + BUTTON2_RELEASED | + BUTTON3_RELEASED); + /* + * ...however, because there are no kinds of mouse events under + * xterm that can intervene between press and release, we can + * deduce which buttons were actually released by looking at the + * previous event. + */ + prev = PREV(eventp); + if (!(prev->bstate & BUTTON1_PRESSED)) + eventp->bstate &=~ BUTTON1_RELEASED; + if (!(prev->bstate & BUTTON2_PRESSED)) + eventp->bstate &=~ BUTTON2_RELEASED; + if (!(prev->bstate & BUTTON3_PRESSED)) + eventp->bstate &=~ BUTTON3_RELEASED; + break; + } + + if (kbuf[0] & 4) { + eventp->bstate |= BUTTON_SHIFT; + } + if (kbuf[0] & 8) { + eventp->bstate |= BUTTON_ALT; + } + if (kbuf[0] & 16) { + eventp->bstate |= BUTTON_CTRL; + } + + eventp->x = (kbuf[1] - ' ') - 1; + eventp->y = (kbuf[2] - ' ') - 1; + T(("_nc_mouse_inline: primitive mouse-event %s has slot %d", _tracemouse(eventp), eventp - events)); + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + } + + return(FALSE); +} + +static void mouse_activate(bool on) +{ + if (mousetype == M_XTERM) + { + if (on) + { + TPUTS_TRACE("xterm mouse initialization"); + putp("\033[?1000h"); + } + else + { + TPUTS_TRACE("xterm mouse deinitialization"); + putp("\033[?1000l"); + } + (void) fflush(SP->_ofp); + } +} + +/************************************************************************** + * + * Device-independent code + * + **************************************************************************/ + +bool _nc_mouse_parse(int runcount) +/* parse a run of atomic mouse events into a gesture */ +{ + MEVENT *ep, *runp, *next, *prev = PREV(eventp); + int n; + bool merge; + + T(("_nc_mouse_parse() called")); + /* + * When we enter this routine, the event list next-free pointer + * points just past a run of mouse events that we know were separated + * in time by less than the critical click interval. The job of this + * routine is to collaps this run into a single higher-level event + * or gesture. + * + * We accomplish this in two passes. The first pass merges press/release + * pairs into click events. The second merges runs of click events into + * double or triple-click events. + * + * It's possible that the run may not resolve to a single event (for + * example, if the user quadruple-clicks). If so, leading events + * in the run are ignored. + * + * Note that this routine is independent of the format of the specific + * format of the pointing-device's reports. We can use it to parse + * gestures on anything that reports press/release events on a per- + * button basis, as long as the device-dependent mouse code puts stuff + * on the queue in MEVENT format. + */ + if (runcount == 1) + { + T(("_nc_mouse_parse: returning simple mouse event %s at slot %d", + _tracemouse(prev), prev-events)); + return(PREV(prev)->bstate & eventmask); + } + + /* find the start of the run */ + runp = eventp; + for (n = runcount; n > 0; n--) + runp = PREV(runp); + +#ifdef MOUSEDEBUG + T(("before mouse press/release merge:")); + for (ep = events; ep < events + EV_MAX; ep++) + T(("mouse event queue slot %d = %s", ep-events, _tracemouse(ep))); + T(("_nc_mouse_parse: run starts at %d, ends at %d, count %d", + runp-events, ((eventp - events) + (EV_MAX - 1)) % EV_MAX, runcount)); +#endif /* MOUSEDEBUG */ + + /* first pass; merge press/release pairs */ + do { + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + { + if (ep->x == next->x && ep->y == next->y + && (ep->bstate & (BUTTON1_PRESSED|BUTTON2_PRESSED|BUTTON3_PRESSED)) + && (!(ep->bstate & BUTTON1_PRESSED) + == !(next->bstate & BUTTON1_RELEASED)) + && (!(ep->bstate & BUTTON2_PRESSED) + == !(next->bstate & BUTTON2_RELEASED)) + && (!(ep->bstate & BUTTON3_PRESSED) + == !(next->bstate & BUTTON3_RELEASED)) + ) + { + if ((eventmask & BUTTON1_CLICKED) + && (ep->bstate & BUTTON1_PRESSED)) + { + ep->bstate &=~ BUTTON1_PRESSED; + ep->bstate |= BUTTON1_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_CLICKED) + && (ep->bstate & BUTTON2_PRESSED)) + { + ep->bstate &=~ BUTTON2_PRESSED; + ep->bstate |= BUTTON2_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_CLICKED) + && (ep->bstate & BUTTON3_PRESSED)) + { + ep->bstate &=~ BUTTON3_PRESSED; + ep->bstate |= BUTTON3_CLICKED; + merge = TRUE; + } + if (merge) + next->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef MOUSEDEBUG + T(("before mouse click merges:")); + for (ep = events; ep < events + EV_MAX; ep++) + T(("mouse event queue slot %d = %s", ep-events, _tracemouse(ep))); + T(("_nc_mouse_parse: run starts at %d, ends at %d, count %d", + runp-events, ((eventp - events) + (EV_MAX - 1)) % EV_MAX, runcount)); +#endif /* MOUSEDEBUG */ + + /* + * Second pass; merge click runs. At this point, click events are + * each followed by one invalid event. We merge click events + * forward in the queue. + * + * NOTE: There is a problem with this design! If the application + * allows enough click events to pile up in the circular queue so + * they wrap around, it will cheerfully merge the newest forward + * into the oldest, creating a bogus doubleclick and confusing + * the queue-traversal logic rather badly. Generally this won't + * happen, because calling getmouse() marks old events invalid and + * ineligible for merges. The true solution to this problem would + * be to timestamp each MEVENT and perform the obvious sanity check, + * but the timer element would have to have sub-second resolution, + * which would get us into portability trouble. + */ + do { + MEVENT *follower; + + merge = FALSE; + for (ep = runp; next = NEXT(ep), next != eventp; ep = next) + if (ep->id != INVALID_EVENT) + { + if (next->id != INVALID_EVENT) + continue; + follower = NEXT(next); + if (follower->id == INVALID_EVENT) + continue; + + /* merge click events forward */ + if ((ep->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED)) + && (follower->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) + { + if ((eventmask & BUTTON1_DOUBLE_CLICKED) + && (follower->bstate & BUTTON1_CLICKED)) + { + follower->bstate &=~ BUTTON1_CLICKED; + follower->bstate |= BUTTON1_DOUBLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_DOUBLE_CLICKED) + && (follower->bstate & BUTTON2_CLICKED)) + { + follower->bstate &=~ BUTTON2_CLICKED; + follower->bstate |= BUTTON2_DOUBLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_DOUBLE_CLICKED) + && (follower->bstate & BUTTON3_CLICKED)) + { + follower->bstate &=~ BUTTON3_CLICKED; + follower->bstate |= BUTTON3_DOUBLE_CLICKED; + merge = TRUE; + } + if (merge) + ep->id = INVALID_EVENT; + } + + /* merge double-click events forward */ + if ((ep->bstate & + (BUTTON1_DOUBLE_CLICKED + | BUTTON2_DOUBLE_CLICKED + | BUTTON3_DOUBLE_CLICKED)) + && (follower->bstate & + (BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED))) + { + if ((eventmask & BUTTON1_TRIPLE_CLICKED) + && (follower->bstate & BUTTON1_CLICKED)) + { + follower->bstate &=~ BUTTON1_CLICKED; + follower->bstate |= BUTTON1_TRIPLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON2_TRIPLE_CLICKED) + && (follower->bstate & BUTTON2_CLICKED)) + { + follower->bstate &=~ BUTTON2_CLICKED; + follower->bstate |= BUTTON2_TRIPLE_CLICKED; + merge = TRUE; + } + if ((eventmask & BUTTON3_TRIPLE_CLICKED) + && (follower->bstate & BUTTON3_CLICKED)) + { + follower->bstate &=~ BUTTON3_CLICKED; + follower->bstate |= BUTTON3_TRIPLE_CLICKED; + merge = TRUE; + } + if (merge) + ep->id = INVALID_EVENT; + } + } + } while + (merge); + +#ifdef MOUSEDEBUG + T(("before mouse event queue compaction:")); + for (ep = events; ep < events + EV_MAX; ep++) + T(("mouse event queue slot %d = %s", ep-events, _tracemouse(ep))); + T(("_nc_mouse_parse: uncompacted run starts at %d, ends at %d, count %d", + runp-events, ((eventp - events) + (EV_MAX - 1)) % EV_MAX, runcount)); +#endif /* MOUSEDEBUG */ + + /* + * Now try to throw away trailing events flagged invalid, or that + * don't match the current event mask. + */ + for (; runcount; prev = PREV(eventp), runcount--) + if (prev->id == INVALID_EVENT || !(prev->bstate & eventmask)) + eventp = prev; + +#ifdef TRACE +#ifdef MOUSEDEBUG + T(("after mouse event queue compaction:")); + for (ep = events; ep < events + EV_MAX; ep++) + T(("mouse event queue slot %d = %s", ep-events, _tracemouse(ep))); + T(("_nc_mouse_parse: compacted run starts at %d, ends at %d, count %d", + runp-events, ((eventp - events) + (EV_MAX - 1)) % EV_MAX, runcount)); +#endif /* MOUSEDEBUG */ + for (ep = runp; ep != eventp; ep = NEXT(ep)) + if (ep->id != INVALID_EVENT) + T(("_nc_mouse_parse: returning composite mouse event %s at slot %d", + _tracemouse(ep), ep-events)); +#endif /* TRACE */ + + /* after all this, do we have a valid event? */ + return(PREV(eventp)->id != INVALID_EVENT); +} + +void _nc_mouse_wrap(SCREEN *sp) +/* release mouse -- called by endwin() before shellout/exit */ +{ + T(("_nc_mouse_wrap() called")); + + /* xterm: turn off reporting */ + if (mousetype == M_XTERM && eventmask) + { + mouse_activate(FALSE); + eventmask = 0; + } + + /* GPM: pass all mouse events to next client */ +} + +void _nc_mouse_resume(SCREEN *sp) +/* re-connect to mouse -- called by doupdate() after shellout */ +{ + T(("_nc_mouse_resume() called")); + + /* xterm: re-enable reporting */ + if (mousetype == M_XTERM && eventmask) + mouse_activate(TRUE); + + /* GPM: reclaim our event set */ +} + +/************************************************************************** + * + * Mouse interface entry points for the API + * + **************************************************************************/ + +int getmouse(MEVENT *aevent) +/* grab a copy of the current mouse event */ +{ + if (mousetype == M_XTERM) + { + /* compute the current-event pointer */ + MEVENT *prev = PREV(eventp); + + /* copy the event we find there */ + *aevent = *prev; + +#ifdef MOUSEDEBUG + T(("getmouse: returning event %s from slot %d", + _tracemouse(prev), prev-events)); +#endif /* MOUSEDEBUG */ + + prev->id = INVALID_EVENT; /* so the queue slot becomes free */ + return(OK); + } + return(ERR); +} + +int ungetmouse(MEVENT *aevent) +/* enqueue a synthesized mouse event to be seen by the next wgetch() */ +{ + /* stick the given event in the next-free slot */ + *eventp = *aevent; + + /* bump the next-free pointer into the circular list */ + eventp = NEXT(eventp); + + /* push back the notification event on the keyboard queue */ + return ungetch(KEY_MOUSE); +} + +mmask_t mousemask(mmask_t newmask, mmask_t *oldmask) +/* set the mouse event mask */ +{ + if (oldmask) + *oldmask = eventmask; + + if (mousetype == M_XTERM) + { + eventmask = newmask & + (BUTTON_ALT | BUTTON_CTRL | BUTTON_SHIFT + | BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED + | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED + | BUTTON2_PRESSED | BUTTON2_RELEASED | BUTTON2_CLICKED + | BUTTON2_DOUBLE_CLICKED | BUTTON2_TRIPLE_CLICKED + | BUTTON3_PRESSED | BUTTON3_RELEASED | BUTTON3_CLICKED + | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED); + + mouse_activate(eventmask != 0); + + return(eventmask); + } + + return(0); +} + +bool wenclose(WINDOW *win, int y, int x) +/* check to see if given window encloses given screen location */ +{ + return + (win->_begy <= y && win->_begx <= x + && win->_maxx >= x && win->_maxy >= y); +} + +int mouseinterval(int maxclick) +/* set the maximum mouse interval within which to recognize a click */ +{ + int oldval = _nc_max_click_interval; + + _nc_max_click_interval = maxclick; + return(oldval); +} + +/* lib_mouse.c ends here */ diff --git a/lib/libcurses/lib_move.c b/lib/libcurses/lib_move.c new file mode 100644 index 00000000000..547aa1762e3 --- /dev/null +++ b/lib/libcurses/lib_move.c @@ -0,0 +1,48 @@ + +/*************************************************************************** +* 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_move.c +** +** The routine wmove(). +** +*/ + +#include "curses.priv.h" + +int +wmove(WINDOW *win, int y, int x) +{ + T(("wmove(%p,%d,%d) called", win, y, x)); + + if (x >= 0 && x <= win->_maxx && + y >= 0 && y <= win->_maxy) + { + win->_curx = (short)x; + win->_cury = (short)y; + + win->_flags &= ~_NEED_WRAP; + win->_flags |= _HASMOVED; + return(OK); + } else + return(ERR); +} diff --git a/lib/libcurses/lib_mvcur.c b/lib/libcurses/lib_mvcur.c new file mode 100644 index 00000000000..b8483e95480 --- /dev/null +++ b/lib/libcurses/lib_mvcur.c @@ -0,0 +1,1389 @@ + +/*************************************************************************** +* 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_mvcur.c +** +** The routines for moving the physical cursor and scrolling: +** +** void _nc_mvcur_init(void), mvcur_wrap(void) +** +** int mvcur(int old_y, int old_x, int new_y, int new_x) +** +** 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 +** motions. It doesn't use tactics based on auto_left_margin. Weirdly +** enough, it doesn't use its own hardware-scrolling routine to scroll up +** destination lines for out-of-bounds addresses! +** old ncurses optimizer: less accurate cost computations (in fact, +** it was broken and had to be commented out!). +** +** Compile with -DMAIN to build an interactive tester/timer for the movement +** optimizer. You can use it to investigate the optimizer's behavior. +** You can also use it for tuning the formulas used to determine whether +** or not full optimization is attempted. +** +** This code has a nasty tendency to find bugs in terminfo entries, because it +** exercises the non-cup movement capabilities heavily. If you think you've +** found a bug, try deleting subsets of the following capabilities (arranged +** in decreasing order of suspiciousness): it, tab, cbt, hpa, vpa, cuu, cud, +** cuf, cub, cuu1, cud1, cuf1, cub1. It may be that one or more are wrong. +** +** Note: you should expect this code to look like a resource hog in a profile. +** That's because it does a lot of I/O, through the tputs() calls. The I/O +** cost swamps the computation overhead (and as machines get faster, this +** will become even more true). Comments in the test exerciser at the end +** go into detail about tuning and how you can gauge the optimizer's +** effectiveness. +**/ + +/**************************************************************************** + * + * Constants and macros for optimizer tuning. + * + ****************************************************************************/ + +/* + * The average overhead of a full optimization computation in character + * transmission times. If it's too high, the algorithm will be a bit + * over-biased toward using cup rather than local motions; if it's too + * low, the algorithm may spend more time than is strictly optimal + * looking for non-cup motions. Profile the optimizer using the `t' + * command of the exerciser (see below), and round to the nearest integer. + * + * Yes, I (esr) thought about computing expected overhead dynamically, say + * by derivation from a running average of optimizer times. But the + * whole point of this optimization is to *decrease* the frequency of + * system calls. :-) + */ +#define COMPUTE_OVERHEAD 1 /* I use a 90MHz Pentium @ 9.6Kbps */ + +/* + * LONG_DIST is the distance we consider to be just as costly to move over as a + * cup sequence is to emit. In other words, it's the length of a cup sequence + * adjusted for average computation overhead. The magic number is the length + * of "\033[yy;xxH", the typical cup sequence these days. + */ +#define LONG_DIST (8 - COMPUTE_OVERHEAD) + +/* + * Tell whether a motion is optimizable by local motions. Needs to be cheap to + * compute. In general, all the fast moves go to either the right or left edge + * of the screen. So any motion to a location that is (a) further away than + * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST, + * we'll consider nonlocal. + */ +#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) && (tx < screen_lines - 1 - LONG_DIST) && (abs(ty-fy) + abs(tx-fx) > LONG_DIST)) + +/**************************************************************************** + * + * External interfaces + * + ****************************************************************************/ + +/* + * For this code to work OK, the following components must live in the + * screen structure: + * + * int _char_padding; // cost of character put + * int _cr_cost; // cost of (carriage_return) + * 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 + * int _ht_cost; // cost of (tab) + * int _cbt_cost; // cost of (backtab) + *#endif TABS_OK + * int _cub1_cost; // cost of (cursor_left) + * int _cuf1_cost; // cost of (cursor_right) + * int _cud1_cost; // cost of (cursor_down) + * int _cuu1_cost; // cost of (cursor_up) + * int _cub_cost; // cost of (parm_cursor_left) + * int _cuf_cost; // cost of (parm_cursor_right) + * int _cud_cost; // cost of (parm_cursor_down) + * int _cuu_cost; // cost of (parm_cursor_up) + * int _hpa_cost; // cost of (column_address) + * int _vpa_cost; // cost of (row_address) + * + * The TABS_OK 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. + */ + +#include "curses.priv.h" +#include "term.h" + +#define NLMAPPING SP->_nl /* nl() on? */ +#define RAWFLAG SP->_raw /* raw() on? */ +#define CURRENT_ATTR SP->_current_attr /* current phys attribute */ +#define CURRENT_ROW SP->_cursrow /* phys cursor row */ +#define CURRENT_COLUMN SP->_curscol /* phys cursor column */ +#define REAL_ATTR SP->_current_attr /* phys current attribute */ +#define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x] /* desired state */ +#define BAUDRATE SP->_baudrate /* bits per second */ + +#include <string.h> +#include <ctype.h> +#include <stdlib.h> + +#ifdef TRACE +bool no_optimize; /* suppress optimization */ +#endif /* TRACE */ + +#ifdef MAIN +#include <sys/time.h> + +static bool profiling = FALSE; +static float diff; +#endif /* MAIN */ + +#define OPT_SIZE 512 + +static char *address_cursor; +static int carriage_return_length; +static int cursor_home_length; +static int cursor_to_ll_length; + +static void save_curs(void); +static void restore_curs(void); + +/**************************************************************************** + * + * Initialization/wrapup (including cost pre-computation) + * + ****************************************************************************/ + +#define INFINITY 1000000 /* too high to use */ + +static int cost(char *cap, int affcnt) +/* compute the cost of a given operation */ +{ + if (cap == (char *)NULL) + return(INFINITY); + else + { + char *cp; + float cum_cost = 0; + + for (cp = cap; *cp; cp++) + { + /* extract padding, either mandatory or required */ + if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) + { + float number = 0; + + for (cp += 2; *cp != '>'; cp++) + { + if (isdigit(*cp)) + number = number * 10 + (*cp - '0'); + else if (*cp == '.') + number += (*++cp - 10) / 10.0; + else if (*cp == '*') + number *= affcnt; + } + + cum_cost += number * 10; + } + else + cum_cost += SP->_char_padding; + } + + return((int)cum_cost); + } +} + +void _nc_mvcur_init(SCREEN *sp) +/* initialize the cost structure */ +{ + /* + * 9 = 7 bits + 1 parity + 1 stop. + */ + if (BAUDRATE != 0) + SP->_char_padding = (9 * 1000 * 10) / BAUDRATE; + else + SP->_char_padding = 9 * 1000 * 10 / 9600; /* use some default if baudrate == 0 */ + + /* non-parameterized local-motion strings */ + SP->_cr_cost = cost(carriage_return, 0); + SP->_home_cost = cost(cursor_home, 0); + SP->_ll_cost = cost(cursor_to_ll, 0); +#ifdef TABS_OK + SP->_ht_cost = cost(tab, 0); + SP->_cbt_cost = cost(back_tab, 0); +#endif /* TABS_OK */ + SP->_cub1_cost = cost(cursor_left, 0); + SP->_cuf1_cost = cost(cursor_right, 0); + SP->_cud1_cost = cost(cursor_down, 0); + SP->_cuu1_cost = cost(cursor_up, 0); + + /* + * Assumption: if the terminal has memory_relative addressing, the + * initialization strings or smcup will set single-page mode so we + * can treat it like absolute screen addressing. This seems to be true + * for all cursor_mem_address terminal types in the terminfo database. + */ + address_cursor = cursor_address ? cursor_address : cursor_mem_address; + + /* + * Parametrized local-motion strings. This static cost computation + * depends on the following assumptions: + * + * (1) They never have * padding. In the entire master terminfo database + * as of March 1995, only the obsolete Zenith Z-100 pc violates this. + * (Proportional padding is found mainly in insert, delete and scroll + * capabilities). + * + * (2) The average case of cup has two two-digit parameters. Strictly, + * the average case for a 24 * 80 screen has ((10*10*(1 + 1)) + + * (14*10*(1 + 2)) + (10*70*(2 + 1)) + (14*70*4)) / (24*80) = 3.458 + * digits of parameters. On a 25x80 screen the average is 3.6197. + * On larger screens the value gets much closer to 4. + * + * (3) The average case of cub/cuf/hpa has 2 digits of parameters + * (strictly, (((10 * 1) + (70 * 2)) / 80) = 1.8750). + * + * (4) The average case of cud/cuu/vpa has 2 digits of parameters + * (strictly, (((10 * 1) + (14 * 2)) / 24) = 1.5833). + * + * All these averages depend on the assumption that all parameter values + * are equally probable. + */ + SP->_cup_cost = cost(tparm(address_cursor, 23, 23), 1); + SP->_cub_cost = cost(tparm(parm_left_cursor, 23), 1); + SP->_cuf_cost = cost(tparm(parm_right_cursor, 23), 1); + SP->_cud_cost = cost(tparm(parm_down_cursor, 23), 1); + SP->_cuu_cost = cost(tparm(parm_up_cursor, 23), 1); + SP->_hpa_cost = cost(tparm(column_address, 23), 1); + SP->_vpa_cost = cost(tparm(row_address, 23), 1); + + /* initialize screen for cursor access */ + if (enter_ca_mode) + { + TPUTS_TRACE("enter_ca_mode"); + putp(enter_ca_mode); + } + + /* pre-compute some capability lengths */ + carriage_return_length = carriage_return ? strlen(carriage_return) : 0; + cursor_home_length = cursor_home ? strlen(cursor_home) : 0; + cursor_to_ll_length = cursor_to_ll ? strlen(cursor_to_ll) : 0; +} + +void _nc_mvcur_wrap(void) +/* wrap up cursor-addressing mode */ +{ + /* change_scroll_region may trash the cursor location */ + save_curs(); + if (change_scroll_region) + { + TPUTS_TRACE("change_scroll_region"); + putp(tparm(change_scroll_region, 0, screen_lines - 1)); + } + restore_curs(); + + if (exit_ca_mode) + { + TPUTS_TRACE("exit_ca_mode"); + putp(exit_ca_mode); + } +} + +/**************************************************************************** + * + * Optimized cursor movement + * + ****************************************************************************/ + +/* + * Perform repeated-append, returning cost + */ +static __inline int +repeated_append (int total, int num, int repeat, char *dst, char *src) +{ + register size_t src_len = strlen(src); + register size_t dst_len = 0; + + if (dst) + dst_len = strlen(dst); + if ((dst_len + repeat * src_len) < OPT_SIZE-1) { + total += (num * repeat); + if (dst) { + dst += dst_len; + while (repeat-- > 0) { + (void) strcpy(dst, src); + dst += src_len; + } + } + } else { + total = INFINITY; + } + return total; +} + +#ifndef NO_OPTIMIZE +#define NEXTTAB(fr) (fr + init_tabs - (fr % init_tabs)) +#define LASTTAB(fr) (fr - init_tabs + (fr % init_tabs)) + +/* Note: we'd like to inline this for speed, but GNU C barfs on the attempt. */ + +static int +relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw) +/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */ +{ + int n, vcost = 0, hcost = 0; + bool used_lf = FALSE; + + if (result) + result[0] = '\0'; + + if (to_y != from_y) + { + vcost = INFINITY; + + if (row_address) + { + if (result) + (void) strcpy(result, tparm(row_address, to_y)); + vcost = SP->_vpa_cost; + } + + if (to_y > from_y) + { + n = (to_y - from_y); + + if (parm_down_cursor && SP->_cud_cost < vcost) + { + if (result) + (void) strcpy(result, tparm(parm_down_cursor, n)); + vcost = SP->_cud_cost; + } + + if (cursor_down && (n * SP->_cud1_cost < vcost)) + { + if (result) + result[0] = '\0'; + if (cursor_down[0] == '\n') + used_lf = TRUE; + vcost = repeated_append(vcost, SP->_cud1_cost, n, result, cursor_down); + } + } + else /* (to_y < from_y) */ + { + n = (from_y - to_y); + + if (parm_up_cursor && SP->_cup_cost < vcost) + { + if (result) + (void) strcpy(result, tparm(parm_up_cursor, n)); + vcost = SP->_cup_cost; + } + + if (cursor_up && (n * SP->_cuu1_cost < vcost)) + { + if (result) + result[0] = '\0'; + vcost = repeated_append(vcost, SP->_cuu1_cost, n, result, cursor_up); + } + } + + if (vcost == INFINITY) + return(INFINITY); + } + + /* + * It may be that we're using a cud1 capability of \n with the + * side-effect of taking the cursor to column 0. Deal with this. + */ + if (used_lf && NLMAPPING && !RAWFLAG) + from_x = 0; + + if (result) + result += strlen(result); + + if (to_x != from_x) + { + char try[OPT_SIZE]; + + hcost = INFINITY; + + if (column_address) + { + if (result) + (void) strcpy(result, tparm(column_address, to_x)); + hcost = SP->_hpa_cost; + } + + if (to_x > from_x) + { + n = to_x - from_x; + + if (parm_right_cursor && SP->_cuf_cost < hcost) + { + if (result) + (void) strcpy(result, tparm(parm_right_cursor, n)); + hcost = SP->_cuf_cost; + } + + if (cursor_right) + { + int lhcost = 0; + + try[0] = '\0'; + +#ifdef TABS_OK + /* use hard tabs, if we have them, to do as much as possible */ + if (init_tabs > 0 && tab) + { + int nxt, fr; + + for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) + { + lhcost = repeated_append(lhcost, SP->_ht_cost, 1, try, tab); + if (lhcost == INFINITY) + break; + } + + n = to_x - fr; + from_x = fr; + } +#endif /* TABS_OK */ + +#if defined(REAL_ATTR) && defined(WANT_CHAR) + /* + * If we have no attribute changes, overwrite is cheaper. + * Note: must suppress this by passing in ovw = FALSE whenever + * WANT_CHAR would return invalid data. In particular, this + * is true between the time a hardware scroll has been done + * and the time the structure WANT_CHAR would access has been + * updated. + */ + if (ovw) + { + int i; + + for (i = 0; i < n; i++) + if ((WANT_CHAR(to_y, from_x + i) & A_ATTRIBUTES) != CURRENT_ATTR) + { + ovw = FALSE; + break; + } + } + if (ovw) + { + char *sp; + int i; + + sp = try + strlen(try); + + for (i = 0; i < n; i++) + *sp++ = WANT_CHAR(to_y, from_x + i); + *sp = '\0'; + lhcost += n * SP->_char_padding; + } + else +#endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */ + { + lhcost = repeated_append(lhcost, SP->_cuf1_cost, n, try, cursor_right); + } + + if (lhcost < hcost) + { + if (result) + (void) strcpy(result, try); + hcost = lhcost; + } + } + } + else /* (to_x < from_x) */ + { + n = from_x - to_x; + + if (parm_left_cursor && SP->_cub_cost < hcost) + { + if (result) + (void) strcpy(result, tparm(parm_left_cursor, n)); + hcost = SP->_cub_cost; + } + + if (cursor_left) + { + int lhcost = 0; + + try[0] = '\0'; + +#ifdef TABS_OK + 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); + if (lhcost == INFINITY) + break; + } + + n = to_x - fr; + } +#endif /* TABS_OK */ + + lhcost = repeated_append(lhcost, SP->_cub1_cost, n, try, cursor_left); + + if (lhcost < hcost) + { + if (result) + (void) strcpy(result, try); + hcost = lhcost; + } + } + } + + if (hcost == INFINITY) + return(INFINITY); + } + + return(vcost + hcost); +} +#endif /* !NO_OPTIMIZE */ + +/* + * With the machinery set up above, it's conceivable that + * onscreen_mvcur could be modified into a recursive function that does + * an alpha-beta search of motion space, as though it were a chess + * move tree, with the weight function being boolean and the search + * depth equated to length of string. However, this would jack up the + * computation cost a lot, especially on terminals without a cup + * capability constraining the search tree depth. So we settle for + * the simpler method below. + */ + +static __inline int +onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw) +/* onscreen move from (yold, xold) to (ynew, xnew) */ +{ + char use[OPT_SIZE], *sp; + int tactic = 0, newcost, usecost = INFINITY; + +#ifdef MAIN + struct timeval before, after; + + gettimeofday(&before, NULL); +#endif /* MAIN */ + + /* tactic #0: use direct cursor addressing */ + sp = tparm(address_cursor, ynew, xnew); + if (sp) + { + tactic = 0; + (void) strcpy(use, sp); + usecost = SP->_cup_cost; + +#ifdef TRACE + if (no_optimize) + xold = yold = -1; +#endif /* TRACE */ + + /* + * We may be able to tell in advance that the full optimization + * will probably not be worth its overhead. Also, don't try to + * use local movement if the current attribute is anything but + * A_NORMAL...there are just too many ways this can screw up + * (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)) + { +#ifdef MAIN + if (!profiling) + { + (void) fputs("nonlocal\n", stderr); + goto nonlocal; /* always run the optimizer if profiling */ + } +#else + goto nonlocal; +#endif /* MAIN */ + } + } + +#ifndef NO_OPTIMIZE + /* tactic #1: use local movement */ + if (yold != -1 && xold != -1 + && ((newcost=relative_move(NULL, yold, xold, ynew, xnew, ovw))!=INFINITY) + && newcost < usecost) + { + tactic = 1; + usecost = newcost; + } + + /* tactic #2: use carriage-return + local movement */ + if (yold < screen_lines - 1 && xold < screen_columns - 1) + { + if (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 #3: use home-cursor + local movement */ + if (cursor_home + && ((newcost=relative_move(NULL, 0, 0, ynew, xnew, ovw)) != INFINITY) + && SP->_home_cost + newcost < usecost) + { + tactic = 3; + usecost = SP->_home_cost + newcost; + } + + /* tactic #4: use home-down + local movement */ + if (cursor_to_ll + && ((newcost=relative_move(NULL, screen_lines-1, 0, ynew, xnew, ovw)) != INFINITY) + && SP->_ll_cost + newcost < usecost) + { + tactic = 4; + usecost = SP->_ll_cost + newcost; + } + + /* + * tactic #5: use left margin for wrap to right-hand side, + * 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 + && ((newcost=relative_move(NULL, yold-1, screen_columns-1, ynew, xnew, ovw)) != INFINITY) + && SP->_cr_cost + SP->_cub1_cost + newcost + newcost < usecost) + { + tactic = 5; + usecost = SP->_cr_cost + SP->_cub1_cost + newcost; + } + + /* + * These cases are ordered by estimated relative frequency. + */ + if (tactic) + { + if (tactic == 1) + (void) relative_move(use, yold, xold, ynew, xnew, ovw); + else if (tactic == 2) + { + (void) strcpy(use, carriage_return); + (void) relative_move(use + carriage_return_length, + yold,0,ynew,xnew, ovw); + } + else if (tactic == 3) + { + (void) strcpy(use, cursor_home); + (void) relative_move(use + cursor_home_length, + 0, 0, ynew, xnew, ovw); + } + else if (tactic == 4) + { + (void) strcpy(use, cursor_to_ll); + (void) relative_move(use + cursor_to_ll_length, + screen_lines-1, 0, ynew, xnew, ovw); + } + else /* if (tactic == 5) */ + { + use[0] = '\0'; + if (xold > 0) + (void) strcat(use, carriage_return); + (void) strcat(use, cursor_left); + (void) relative_move(use + strlen(use), + yold-1, screen_columns-1, ynew, xnew, ovw); + } + } +#endif /* !NO_OPTIMIZE */ + +#ifdef MAIN + gettimeofday(&after, NULL); + diff = after.tv_usec - before.tv_usec + + (after.tv_sec - before.tv_sec) * 1000000; + if (!profiling) + (void) fprintf(stderr, "onscreen: %d msec, %f 28.8Kbps char-equivalents\n", + (int)diff, diff/288); +#endif /* MAIN */ + + nonlocal: + if (usecost != INFINITY) + { + TPUTS_TRACE("mvcur"); + tputs(use, 1, _nc_outch); + return(OK); + } + else + return(ERR); +} + +int mvcur(int yold, int xold, int ynew, int xnew) +/* optimized cursor move from (yold, xold) to (ynew, xnew) */ +{ + TR(TRACE_MOVE, ("mvcur(%d,%d,%d,%d) called", yold, xold, ynew, xnew)); + + if (yold == ynew && xold == xnew) + return(OK); + + /* + * Most work here is rounding for terminal boundaries getting the + * column position implied by wraparound or the lack thereof and + * rolling up the screen to get ynew on the screen. + */ + + if (xnew >= screen_columns) + { + ynew += xnew / screen_columns; + xnew %= screen_columns; + } + if (xold >= screen_columns) + { + int l; + + l = (xold + 1) / screen_columns; + yold += l; + xold %= screen_columns; + if (!auto_right_margin) + { + while (l > 0) { + if (newline) + { + TPUTS_TRACE("newline"); + tputs(newline, 0, _nc_outch); + } + else + putchar('\n'); + l--; + } + xold = 0; + } + if (yold > screen_lines - 1) + { + ynew -= yold - (screen_lines - 1); + yold = screen_lines - 1; + } + } + +#ifdef CURSES_OVERRUN /* not used, it takes us out of sync with curscr */ + /* + * The destination line is offscreen. Try to scroll the screen to + * bring it onscreen. Note: this is not a documented feature of the + * API. It's here for compatibility with archaic curses code, a + * feature no one seems to have actually used in a long time. + */ + if (ynew >= screen_lines) + { + if (mvcur_scrolln((ynew - (screen_lines - 1)), 0, screen_lines - 1, screen_lines - 1) == OK) + ynew = screen_lines - 1; + else + return(ERR); + } +#endif /* CURSES_OVERRUN */ + + /* destination location is on screen now */ + 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 + * + ****************************************************************************/ + +int _nc_mvcur_scrolln(int n, int top, int bot, int maxy) +/* scroll region from top to bot by n lines */ +{ + int i; + + TR(TRACE_MOVE, ("mvcur_scrolln(%d, %d, %d, %d)", n, top, bot, maxy)); + + save_curs(); + + /* + * 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 modern terminals and (b) using them avoids bouncing an + * unchanged bottom section of the screen up and down, which is + * visually nasty. + */ + if (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_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); + restore_curs(); + return(OK); + } + + /* Scroll up the block. */ + if (parm_index && top == 0) + { + onscreen_mvcur(oy, ox, bot, 0, TRUE); + TPUTS_TRACE("parm_index"); + tputs(tparm(parm_index, n, 0), n, _nc_outch); + } + else if (parm_delete_line) + { + onscreen_mvcur(oy, ox, top, 0, TRUE); + TPUTS_TRACE("parm_delete_line"); + tputs(tparm(parm_delete_line, n, 0), n, _nc_outch); + } + else if (delete_line) + { + onscreen_mvcur(oy, ox, top, 0, TRUE); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("parm_index"); + tputs(delete_line, 0, _nc_outch); + } + } + else if (scroll_forward && top == 0) + { + onscreen_mvcur(oy, ox, bot, 0, TRUE); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("scroll_forward"); + tputs(scroll_forward, 0, _nc_outch); + } + } + else + return(ERR); + + /* Push down the bottom region. */ + if (parm_insert_line) + { + onscreen_mvcur(top, 0, bot - n + 1, 0, FALSE); + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(parm_insert_line, n, 0), n, _nc_outch); + } + else if (insert_line) + { + onscreen_mvcur(top, 0, bot - n + 1, 0, FALSE); + for (i = 0; i < n; i++) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + } + else + return(ERR); + restore_curs(); + } + else /* (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_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); + restore_curs(); + return(OK); + } + + /* Preserve the bottom lines. */ + onscreen_mvcur(oy, ox, bot + n + 1, 0, TRUE); + if (parm_rindex && bot == maxy) + { + TPUTS_TRACE("parm_rindex"); + tputs(tparm(parm_rindex, -n, 0), -n, _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 = n; i < 0; i++) + { + TPUTS_TRACE("delete_line"); + tputs(delete_line, 0, _nc_outch); + } + else if (scroll_reverse && bot == maxy) + for (i = n; i < 0; i++) + { + TPUTS_TRACE("scroll_reverse"); + tputs(scroll_reverse, 0, _nc_outch); + } + else + return(ERR); + + /* Scroll the block down. */ + if (parm_insert_line) + { + onscreen_mvcur(bot + n + 1, 0, top, 0, FALSE); + TPUTS_TRACE("parm_insert_line"); + tputs(tparm(parm_insert_line, -n, 0), -n, _nc_outch); + } + else if (insert_line) + { + onscreen_mvcur(bot + n + 1, 0, top, 0, FALSE); + for (i = n; i < 0; i++) + { + TPUTS_TRACE("insert_line"); + tputs(insert_line, 0, _nc_outch); + } + } + else + return(ERR); + restore_curs(); + } + + return(OK); +} + +#ifdef MAIN +/**************************************************************************** + * + * Movement optimizer test code + * + ****************************************************************************/ + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <string.h> +#include <stdlib.h> +#include "tic.h" +#include "dump_entry.h" + +char *_nc_progname = "mvcur"; + +static unsigned long xmits; + +int tputs(const char *string, int affcnt, int (*outc)(int)) +/* stub tputs() that dumps sequences in a visible form */ +{ + if (profiling) + xmits += strlen(string); + else + (void) fputs(_nc_visbuf(string), stdout); + return(OK); +} + +int putp(const char *string) +{ + return(tputs(string, 1, _nc_outch)); +} + +int _nc_outch(int ch) +{ + putc(ch, stdout); + return OK; +} + +static char tname[BUFSIZ]; + +static void load_term(void) +{ + (void) setupterm(tname, STDOUT_FILENO, NULL); +} + +static int roll(int n) +{ + int i, j; + + i = (RAND_MAX / n) * n; + while ((j = rand()) >= i) + continue; + return (j % n); +} + +int main(int argc, char *argv[]) +{ + (void) strcpy(tname, getenv("TERM")); + load_term(); + _nc_setupscreen(lines, columns); + baudrate(); + + _nc_mvcur_init(SP); +#if HAVE_SETVBUF || HAVE_SETBUFFER + /* + * Undo the effects of our optimization hack, otherwise our interactive + * prompts don't flush properly. + */ +#if HAVE_SETVBUF + (void) setvbuf(SP->_ofp, malloc(BUFSIZ), _IOLBF, BUFSIZ); +#elif HAVE_SETBUFFER + (void) setbuffer(SP->_ofp, malloc(BUFSIZ), BUFSIZ); +#endif +#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ + + (void) puts("The mvcur tester. Type ? for help"); + + fputs("smcup:", stdout); + putchar('\n'); + + for (;;) + { + int fy, fx, ty, tx, n, i; + char buf[BUFSIZ], capname[BUFSIZ]; + + (void) fputs("> ", stdout); + (void) fgets(buf, sizeof(buf), stdin); + + if (buf[0] == '?') + { +(void) puts("? -- display this help message"); +(void) puts("fy fx ty tx -- (4 numbers) display (fy,fx)->(ty,tx) move"); +(void) puts("s[croll] n t b m -- display scrolling sequence"); +(void) printf("r[eload] -- reload terminal info for %s\n", + getenv("TERM")); +(void) puts("l[oad] <term> -- load terminal info for type <term>"); +(void) puts("nl -- assume NL -> CR/LF when computing (default)"); +(void) puts("nonl -- don't assume NL -> CR/LF when computing"); +(void) puts("d[elete] <cap> -- delete named capability"); +(void) puts("i[nspect] -- display terminal capabilities"); +(void) puts("c[ost] -- dump cursor-optimization cost table"); +(void) puts("o[optimize] -- toggle movement optimization"); +(void) puts("t[orture] <num> -- torture-test with <num> random moves"); +(void) puts("q[uit] -- quit the program"); + } + else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) + { + struct timeval before, after; + + putchar('"'); + + gettimeofday(&before, NULL); + mvcur(fy, fx, ty, tx); + gettimeofday(&after, NULL); + + printf("\" (%ld msec)\n", + 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) + { + struct timeval before, after; + + putchar('"'); + + gettimeofday(&before, NULL); + _nc_mvcur_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); + } + else if (buf[0] == 'r') + { + (void) strcpy(tname, getenv("TERM")); + load_term(); + } + else if (sscanf(buf, "l %s", tname) == 1) + { + load_term(); + } + else if (strncmp(buf, "nl", 2) == 0) + { + NLMAPPING = TRUE; + (void) puts("NL -> CR/LF will be assumed."); + } + else if (strncmp(buf, "nonl", 4) == 0) + { + NLMAPPING = FALSE; + (void) puts("NL -> CR/LF will not be assumed."); + } + else if (sscanf(buf, "d %s", capname) == 1) + { + struct name_table_entry const *np = _nc_find_entry(capname, + _nc_info_hash_table); + + if (np == NULL) + (void) printf("No such capability as \"%s\"\n", capname); + else + { + switch(np->nte_type) + { + case BOOLEAN: + cur_term->type.Booleans[np->nte_index] = FALSE; + (void) printf("Boolean capability `%s' (%d) turned off.\n", + np->nte_name, np->nte_index); + break; + + case NUMBER: + cur_term->type.Numbers[np->nte_index] = -1; + (void) printf("Number capability `%s' (%d) set to -1.\n", + np->nte_name, np->nte_index); + break; + + case STRING: + cur_term->type.Strings[np->nte_index] = (char *)NULL; + (void) printf("String capability `%s' (%d) deleted.\n", + np->nte_name, np->nte_index); + break; + } + } + } + else if (buf[0] == 'i') + { + dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0); + dump_entry(&cur_term->type, NULL); + putchar('\n'); + } + else if (buf[0] == 'o') + { + if (no_optimize) + { + no_optimize = FALSE; + (void) puts("Optimization is now on."); + } + else + { + no_optimize = TRUE; + (void) puts("Optimization is now off."); + } + } + /* + * You can use the `t' test to profile and tune the movement + * optimizer. Use iteration values in three digits or more. + * At above 5000 iterations the profile timing averages are stable + * to within a millisecond or three. + * + * The `overhead' field of the report will help you pick a + * COMPUTE_OVERHEAD figure appropriate for your processor and + * expected line speed. The `total estimated time' is + * computation time plus a character-transmission time + * estimate computed from the number of transmits and the baud + * rate. + * + * Use this together with the `o' command to get a read on the + * optimizer's effectiveness. Compare the total estimated times + * for `t' runs of the same length in both optimized and un-optimized + * modes. As long as the optimized times are less, the optimizer + * is winning. + */ + else if (sscanf(buf, "t %d", &n) == 1) + { + float cumtime = 0, perchar; + int speeds[] = {2400, 9600, 14400, 19200, 28800, 38400, 0}; + + srand((unsigned)(getpid() + time((time_t *)0))); + profiling = TRUE; + xmits = 0; + for (i = 0; i < n; i++) + { + /* + * This does a move test between two random locations, + * Random moves probably short-change the optimizer, + * which will work better on the short moves probably + * typical of doupdate()'s usage pattern. Still, + * until we have better data... + */ +#ifdef FIND_COREDUMP + int from_y = roll(lines); + int to_y = roll(lines); + int from_x = roll(columns); + int to_x = roll(columns); + + printf("(%d,%d) -> (%d,%d)\n", from_y, from_x, to_y, to_x); + mvcur(from_y, from_x, to_y, to_x); +#else + mvcur(roll(lines), roll(columns), roll(lines), roll(columns)); +#endif /* FIND_COREDUMP */ + if (diff) + cumtime += diff; + } + profiling = FALSE; + + /* + * Average milliseconds per character optimization time. + * This is the key figure to watch when tuning the optimizer. + */ + perchar = cumtime / n; + + (void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n", + n, xmits, (int)cumtime, perchar); + + for (i = 0; speeds[i]; i++) + { + /* + * Total estimated time for the moves, computation and + * transmission both. Transmission time is an estimate + * assuming 9 bits/char, 8 bits + 1 stop bit. + */ + float totalest = cumtime + xmits * 9 * 1e6 / speeds[i]; + + /* + * Per-character optimization overhead in character transmits + * at the current speed. Round this to the nearest integer + * to figure COMPUTE_OVERHEAD for the speed. + */ + float overhead = speeds[i] * perchar / 1e6; + + (void) printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n", + speeds[i], overhead, totalest); + } + } + else if (buf[0] == 'c') + { + (void) printf("char padding: %d\n", SP->_char_padding); + (void) printf("cr cost: %d\n", SP->_cr_cost); + (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 + (void) printf("ht cost: %d\n", SP->_ht_cost); + (void) printf("cbt cost: %d\n", SP->_cbt_cost); +#endif /* TABS_OK */ + (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); + (void) printf("cuu1 cost: %d\n", SP->_cuu1_cost); + (void) printf("cub cost: %d\n", SP->_cub_cost); + (void) printf("cuf cost: %d\n", SP->_cuf_cost); + (void) printf("cud cost: %d\n", SP->_cud_cost); + (void) printf("cuu cost: %d\n", SP->_cuu_cost); + (void) printf("hpa cost: %d\n", SP->_hpa_cost); + (void) printf("vpa cost: %d\n", SP->_vpa_cost); + } + else if (buf[0] == 'x' || buf[0] == 'q') + break; + else + (void) puts("Invalid command."); + } + + (void) fputs("rmcup:", stdout); + _nc_mvcur_wrap(); + putchar('\n'); + + return(0); +} + +#endif /* MAIN */ + +/* lib_mvcur.c ends here */ diff --git a/lib/libcurses/lib_mvwin.c b/lib/libcurses/lib_mvwin.c new file mode 100644 index 00000000000..f84f6941239 --- /dev/null +++ b/lib/libcurses/lib_mvwin.c @@ -0,0 +1,55 @@ + +/*************************************************************************** +* 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_mvwin.c +** +** The routine mvwin(). +** +*/ + +#include "curses.priv.h" + +int mvwin(WINDOW *win, int by, int bx) +{ + T(("mvwin(%p,%d,%d) called", win, by, bx)); + + if (win->_flags & _SUBWIN) + return(ERR); + + if (by + win->_maxy > screen_lines - 1 + || bx + win->_maxx > screen_columns - 1 + || by < 0 + || bx < 0) + return(ERR); + + /* + * 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; + return touchwin(win); +} diff --git a/lib/libcurses/lib_newterm.c b/lib/libcurses/lib_newterm.c new file mode 100644 index 00000000000..b2551b56764 --- /dev/null +++ b/lib/libcurses/lib_newterm.c @@ -0,0 +1,189 @@ + +/*************************************************************************** +* 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_newterm.c +** +** The newterm() function. +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include "term.h" /* clear_screen, cup & friends, cur_term */ + +/* This should moved to TERMINAL */ +static filter_mode = FALSE; + +void filter(void) +{ + filter_mode = TRUE; +} + +SCREEN * newterm(const char *term, FILE *ofp, FILE *ifp) +{ +int errret; +#ifdef TRACE +char *t = getenv("NCURSES_TRACE"); + + if (t) + trace(strtol(t, 0, 0)); +#endif + + T(("newterm(\"%s\",%p,%p) called", term, ofp, ifp)); + + /* this loads the capability entry, then sets LINES and COLS */ + if (setupterm(term, fileno(ofp), &errret) != 1) + return NULL; + + /* optional optimization hack -- do before any output to ofp */ +#if HAVE_SETVBUF || HAVE_SETBUFFER + { + /* + * If the output file descriptor is connected to a tty + * (the typical case) it will probably be line-buffered. + * Keith Bostic pointed out that we don't want this; it + * hoses people running over networks by forcing out a + * bunch of small packets instead of one big one, so + * screen updates on ptys look jerky. Restore block + * buffering to prevent this minor lossage. + * + * The buffer size is a compromise. Ideally we'd like a + * buffer that can hold the maximum possible update size + * (the whole screen plus cup commands to change lines as + * it's painted). On a modern 66-line xterm this can + * become excessive. So we min it with the amount of data + * we think we can get through two Ethernet packets + * (maximum packet size - 100 for TCP/IP overhead). + * + * Why two ethernet packets? It used to be one, on the theory + * that said packets define the maximum size of atomic update. + * But that's less than the 2000 chars on a 25 x 80 screen, and + * we don't want local updates to flicker either. Two packet + * lengths will handle up to a 35 x 80 screen. + * + * The magic '6' is the estimated length of the end-of-line + * cup sequence to go to the next line. It's generous. We + * used to mess with the buffering in init_mvcur() after cost + * computation, but that lost the sequences emitted by init_acs() + * in setupscreen(). + * + * "The setvbuf function may be used only after the stream pointed + * to by stream as been associated with an open file and before any + * other operation is performed on the stream." (ISO 7.9.5.6.) + * + * Grrrr... + */ + unsigned int bufsiz = min(LINES * (COLS + 6), 2800); + +#if HAVE_SETVBUF + /* + * If your code core-dumps here, you are probably running + * some bastard offspring of an SVR3 on which the setvbuffer(3) + * arguments are reversed. Autoconf has a test macro for this + * but I have too much else to do to figure out how it works. + * Send us a patch if you care. + */ + (void) setvbuf(ofp, malloc(bufsiz), _IOFBF, bufsiz); +#elif HAVE_SETBUFFER + (void) setbuffer(ofp, malloc(bufsiz), (int)bufsiz); +#endif + } +#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ + + /* implement filter mode */ + if (filter_mode) { + LINES = 1; + +#ifdef init_tabs + if (init_tabs != -1) + TABSIZE = init_tabs; + else +#endif /* init_tabs */ + TABSIZE = 8; + + 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; + + cursor_home = carriage_return; +#endif /* clear_screen */ + } + + /* if we must simulate soft labels, grab off the line to be used */ +#ifdef num_labels + if (num_labels <= 0) +#endif /* num_labels */ + if (_slk_init) + ripoffline(-1, slk_initialize); + + /* this actually allocates the screen structure */ + if (_nc_setupscreen(LINES, COLS) == ERR) + return NULL; + +#ifdef num_labels + /* if the terminal type has real soft labels, set those up */ + if (_slk_init && num_labels > 0) + slk_initialize(stdscr, COLS); +#endif /* num_labels */ + + SP->_ifd = fileno(ifp); + SP->_checkfd = fileno(ifp); + typeahead(fileno(ifp)); + SP->_ofp = ofp; +#ifdef TERMIOS + SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && + !(cur_term->Ottyb.c_iflag & ISTRIP)); +#else + SP->_use_meta = FALSE; +#endif + SP->_endwin = FALSE; + + baudrate(); /* sets a field in the SP structure */ + + /* compute movement costs so we can do better move optimization */ + _nc_mvcur_init(SP); + +#if 0 + /* initialize soft labels */ + if (_slk_init) + if (num_labels <= 0) + ripoffline(-1, slk_initialize); + else + slk_initialize(stdscr, COLS); +#endif + _nc_signal_handler(TRUE); + + /* open a connection to the screen's associated mouse, if any */ + _nc_mouse_init(SP); + + T(("newterm returns %p", SP)); + + return(SP); +} + diff --git a/lib/libcurses/lib_newwin.c b/lib/libcurses/lib_newwin.c new file mode 100644 index 00000000000..0fd8d16db36 --- /dev/null +++ b/lib/libcurses/lib_newwin.c @@ -0,0 +1,193 @@ + +/*************************************************************************** +* 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_newwin.c +** +** The routines newwin(), subwin() and their dependent +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> + +WINDOW * newwin(int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +chtype *ptr; +int i, j; + + T(("newwin(%d,%d,%d,%d) called", num_lines, num_columns, begy, begx)); + + if (num_lines == 0) + num_lines = screen_lines - begy; + if (num_columns == 0) + num_columns = screen_columns - begx; + + if (num_columns + begx > SP->_columns || num_lines + begy > SP->_lines) + return NULL; + + if ((win = _nc_makenew(num_lines, num_columns, begy, begx)) == NULL) + return NULL; + + for (i = 0; i < num_lines; i++) { + if ((win->_line[i].text = (chtype *) calloc((unsigned)num_columns, sizeof(chtype))) == NULL) { + for (j = 0; j < i; j++) + free(win->_line[j].text); + + free(win->_line); + free(win); + + return NULL; + } + else + for (ptr = win->_line[i].text; ptr < win->_line[i].text + num_columns; ) + *ptr++ = ' '; + } + + T(("newwin: returned window is %p", win)); + + return(win); +} + +WINDOW * derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) +{ +WINDOW *win; +int i; + + T(("derwin(%p, %d,%d,%d,%d) called", orig, num_lines, num_columns, begy, begx)); + + /* + ** make sure window fits inside the original one + */ + if ( begy < 0 || begx < 0) + return NULL; + if ( begy + num_lines > orig->_maxy + 1 + || begx + num_columns > orig->_maxx + 1) + return NULL; + + if (num_lines == 0) + num_lines = orig->_maxy - begy; + + if (num_columns == 0) + num_columns = orig->_maxx - begx; + + if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy, orig->_begx + begx)) == NULL) + return NULL; + + win->_pary = begy; + win->_parx = begx; + win->_attrs = orig->_attrs; + win->_bkgd = orig->_bkgd; + + for (i = 0; i < num_lines; i++) + win->_line[i].text = &orig->_line[begy++].text[begx]; + + win->_flags = _SUBWIN; + win->_parent = orig; + + T(("derwin: returned window is %p", win)); + + return(win); +} + + +WINDOW *subwin(WINDOW *w, int l, int c, int y, int x) +{ + T(("subwin(%p, %d, %d, %d, %d) called", w, l, c, y, x)); + T(("parent has begy = %d, begx = %d", w->_begy, w->_begx)); + + return derwin(w, l, c, y - w->_begy, x - w->_begx); +} + +WINDOW * +_nc_makenew(int num_lines, int num_columns, int begy, int begx) +{ +int i; +WINDOW *win; + + T(("_nc_makenew(%d,%d,%d,%d)", num_lines, num_columns, begy, begx)); + + if (num_lines <= 0 || num_columns <= 0) + return NULL; + + if ((win = (WINDOW *) calloc(1, sizeof(WINDOW))) == NULL) + return NULL; + + if ((win->_line = (struct ldat *) calloc((unsigned)num_lines, sizeof (struct ldat))) == NULL) { + free(win); + return NULL; + } + + win->_curx = 0; + win->_cury = 0; + win->_maxy = num_lines - 1; + win->_maxx = num_columns - 1; + win->_begy = begy; + win->_begx = begx; + + win->_flags = 0; + win->_attrs = A_NORMAL; + win->_bkgd = A_NORMAL; + + win->_clear = (num_lines == screen_lines && num_columns == screen_columns); + win->_idlok = FALSE; + win->_idcok = TRUE; + win->_scroll = FALSE; + win->_leaveok = FALSE; + win->_use_keypad = FALSE; + win->_delay = -1; + win->_immed = FALSE; + win->_sync = 0; + win->_parx = -1; + win->_pary = -1; + win->_parent = (WINDOW *)NULL; + + win->_regtop = 0; + win->_regbottom = num_lines - 1; + + win->_pad._pad_y = -1; + win->_pad._pad_x = -1; + win->_pad._pad_top = -1; + win->_pad._pad_bottom = -1; + win->_pad._pad_left = -1; + win->_pad._pad_right = -1; + + for (i = 0; i < num_lines; i++) + { + win->_line[i].firstchar = win->_line[i].lastchar = _NOCHANGE; + win->_line[i].oldindex = i; + } + + if (begx + num_columns == screen_columns) { + win->_flags |= _ENDLINE; + + if (begx == 0 && num_lines == screen_lines && begy == 0) + win->_flags |= _FULLWIN; + + if (begy + num_lines == screen_lines) + win->_flags |= _SCROLLWIN; + } + + return(win); +} diff --git a/lib/libcurses/lib_options.c b/lib/libcurses/lib_options.c new file mode 100644 index 00000000000..c2a73db8a7d --- /dev/null +++ b/lib/libcurses/lib_options.c @@ -0,0 +1,364 @@ + +/*************************************************************************** +* 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_options.c +** +** The routines to handle option setting. +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include "term.h" /* keypad_xmit, keypad_local, meta_on, meta_off */ + /* cursor_visible,cursor_normal,cursor_invisible */ + +int has_ic(void) +{ + T(("has_ic() called")); + return (insert_character || parm_ich) + && (delete_character || parm_dch); +} + +int has_il(void) +{ + T(("has_il() called")); + return (insert_line || parm_insert_line) + && (delete_line || parm_delete_line); +} + +int idlok(WINDOW *win, bool flag) +{ + T(("idlok(%p,%d) called", win, flag)); + + win->_idlok = flag && (has_il() || change_scroll_region); + return OK; +} + + +int idcok(WINDOW *win, bool flag) +{ + T(("idcok(%p,%d) called", win, flag)); + + win->_idcok = flag && has_ic(); + + return OK; +} + + +int clearok(WINDOW *win, bool flag) +{ + T(("clearok(%p,%d) called", win, flag)); + + if (win == curscr) + newscr->_clear = flag; + else + win->_clear = flag; + return OK; +} + + +int immedok(WINDOW *win, bool flag) +{ + T(("immedok(%p,%d) called", win, flag)); + + win->_immed = flag; + return OK; +} + +int leaveok(WINDOW *win, bool flag) +{ + T(("leaveok(%p,%d) called", win, flag)); + + win->_leaveok = flag; + if (flag == TRUE) + curs_set(0); + else + curs_set(1); + return OK; +} + + +int scrollok(WINDOW *win, bool flag) +{ + T(("scrollok(%p,%d) called", win, flag)); + + win->_scroll = flag; + return OK; +} + +int halfdelay(int t) +{ + T(("halfdelay(%d) called", t)); + + if (t < 1 || t > 255) + return ERR; + + cbreak(); + SP->_cbreak = t+1; + return OK; +} + +int nodelay(WINDOW *win, bool flag) +{ + T(("nodelay(%p,%d) called", win, flag)); + + if (flag == TRUE) + win->_delay = 0; + else win->_delay = -1; + return OK; +} + +int notimeout(WINDOW *win, bool f) +{ + T(("notimout(%p,%d) called", win, f)); + + win->_notimeout = f; + return OK; +} + +int wtimeout(WINDOW *win, int delay) +{ + T(("wtimeout(%p,%d) called", win, delay)); + + win->_delay = delay; + return 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 (SP->_keytry == UNINITIALISED) + init_keytry(); + return OK; +} + +int keypad(WINDOW *win, bool flag) +{ + T(("keypad(%p,%d) called", win, flag)); + + win->_use_keypad = flag; + return (_nc_keypad(flag)); +} + + +int meta(WINDOW *win, bool flag) +{ + T(("meta(%p,%d) called", win, flag)); + + SP->_use_meta = flag; + + if (flag && meta_on) + { + TPUTS_TRACE("meta_on"); + putp(meta_on); + } + else if (! flag && meta_off) + { + TPUTS_TRACE("meta_off"); + putp(meta_off); + } + return OK; +} + +/* curs_set() moved here to narrow the kernel interface */ + +int curs_set(int vis) +{ +int cursor = SP->_cursor; + + T(("curs_set(%d)", vis)); + + if (vis < 0 || vis > 2) + return ERR; + + switch(vis) { + case 2: + if (cursor_visible) + { + TPUTS_TRACE("cursor_visible"); + putp(cursor_visible); + } + break; + case 1: + if (cursor_normal) + { + TPUTS_TRACE("cursor_normal"); + putp(cursor_normal); + } + break; + case 0: + if (cursor_invisible) + { + TPUTS_TRACE("cursor_invisible"); + putp(cursor_invisible); + } + break; + } + SP->_cursor = vis; + return cursor; +} + +/* +** init_keytry() +** +** Construct the try for the current terminal's keypad keys. +** +*/ + + +static struct try *newtry; + +static void init_keytry(void) +{ + newtry = NULL; + +#include "keys.tries" + + SP->_keytry = newtry; +} + + +static void add_to_try(char *str, short code) +{ +static bool out_of_memory = FALSE; +struct try *ptr, *savedptr; + + if (! str || out_of_memory) + return; + + if (newtry != NULL) { + ptr = savedptr = newtry; + + for (;;) { + while (ptr->ch != (unsigned char) *str + && ptr->sibling != NULL) + ptr = ptr->sibling; + + if (ptr->ch == (unsigned char) *str) { + if (*(++str)) { + if (ptr->child != NULL) + ptr = ptr->child; + else + break; + } else { + ptr->value = code; + return; + } + } else { + if ((ptr->sibling = (struct try *) malloc(sizeof *ptr)) == NULL) { + out_of_memory = TRUE; + return; + } + + savedptr = ptr = ptr->sibling; + ptr->child = ptr->sibling = NULL; + if (*str == '\200') + ptr->ch = '\0'; + else + ptr->ch = (unsigned char) *str; + str++; + ptr->value = (short) NULL; + + break; + } + } /* end for (;;) */ + } else { /* newtry == NULL :: First sequence to be added */ + savedptr = ptr = newtry = (struct try *) malloc(sizeof *ptr); + + if (ptr == NULL) { + out_of_memory = TRUE; + return; + } + + ptr->child = ptr->sibling = NULL; + if (*str == '\200') + ptr->ch = '\0'; + else + ptr->ch = (unsigned char) *str; + str++; + ptr->value = (short) NULL; + } + + /* at this point, we are adding to the try. ptr->child == NULL */ + + while (*str) { + ptr->child = (struct try *) malloc(sizeof *ptr); + + ptr = ptr->child; + + if (ptr == NULL) { + out_of_memory = TRUE; + + ptr = savedptr; + while (ptr != NULL) { + savedptr = ptr->child; + free(ptr); + ptr = savedptr; + } + + return; + } + + ptr->child = ptr->sibling = NULL; + if (*str == '\200') + ptr->ch = '\0'; + else + ptr->ch = (unsigned char) *str; + str++; + ptr->value = (short) NULL; + } + + ptr->value = code; + return; +} + +int typeahead(int fd) +{ + + T(("typeahead(%d) called", fd)); + SP->_checkfd = fd; + return OK; +} + diff --git a/lib/libcurses/lib_overlay.c b/lib/libcurses/lib_overlay.c new file mode 100644 index 00000000000..867c2e178d5 --- /dev/null +++ b/lib/libcurses/lib_overlay.c @@ -0,0 +1,135 @@ + +/*************************************************************************** +* 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_overlay.c +** +** The routines overlay(), copywin(), and overwrite(). +** +*/ + +#include "curses.priv.h" + +static void overlap(const WINDOW *const s, WINDOW *const d, int const flag) +{ +int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; + + T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d", + s->_begy, s->_begx, s->_maxy, s->_maxx, + d->_begy, d->_begx, d->_maxy, d->_maxx)); + sminrow = max(s->_begy, d->_begy) - s->_begy; + smincol = max(s->_begx, d->_begx) - s->_begx; + dminrow = max(s->_begy, d->_begy) - d->_begy; + dmincol = max(s->_begx, d->_begx) - d->_begx; + dmaxrow = min(s->_maxy+s->_begy, d->_maxy+d->_begy) - d->_begy; + dmaxcol = min(s->_maxx+s->_begx, d->_maxx+d->_begx) - d->_begx; + + copywin(s, d, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, flag); +} + +/* +** +** overlay(win1, win2) +** +** +** overlay() writes the overlapping area of win1 behind win2 +** on win2 non-destructively. +** +**/ + +int overlay(const WINDOW *win1, WINDOW *win2) +{ + overlap(win1, win2, TRUE); + return OK; +} + +/* +** +** overwrite(win1, win2) +** +** +** overwrite() writes the overlapping area of win1 behind win2 +** on win2 destructively. +** +**/ + +int overwrite(const WINDOW *win1, WINDOW *win2) +{ + overlap(win1, win2, FALSE); + return OK; +} + +int copywin(const WINDOW *src, WINDOW *dst, + int sminrow, int smincol, + int dminrow, int dmincol, int dmaxrow, int dmaxcol, + int over) +{ +int sx, sy, dx, dy; +int touched; + + T(("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)", + src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); + + /* make sure rectangle exists in source */ + if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) || + (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) { + return ERR; + } + + T(("rectangle exists in source")); + + /* make sure rectangle fits in destination */ + if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) { + return ERR; + } + + T(("rectangle fits in destination")); + + for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) { + touched=0; + for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++) + { + if (over) + { + if (((src->_line[sy].text[sx] & A_CHARTEXT)!=' ') && + (dst->_line[dy].text[dx]!=src->_line[sy].text[sx])) + { + dst->_line[dy].text[dx] = src->_line[sy].text[sx]; + touched=1; + } + } + else { + if (dst->_line[dy].text[dx] != src->_line[sy].text[sx]) + { + dst->_line[dy].text[dx] = src->_line[sy].text[sx]; + touched=1; + } + } + } + if (touched) + { + touchline(dst,0,getmaxy(dst)); + } + } + T(("finished copywin")); + return OK; +} diff --git a/lib/libcurses/lib_pad.c b/lib/libcurses/lib_pad.c new file mode 100644 index 00000000000..392305f658d --- /dev/null +++ b/lib/libcurses/lib_pad.c @@ -0,0 +1,258 @@ + +/*************************************************************************** +* 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_pad.c + * newpad -- create a new pad + * pnoutrefresh -- refresh a pad, no update + * pechochar -- add a char to a pad and refresh + */ + +#include "curses.priv.h" + +#include <stdlib.h> +#include <errno.h> + +#if !HAVE_EXTERN_ERRNO +extern int errno; +#endif + +WINDOW *newpad(int l, int c) +{ +WINDOW *win; +chtype *ptr; +int i, j; + + T(("newpad(%d, %d) called", l, c)); + + if (l <= 0 || c <= 0) + return NULL; + + if ((win = _nc_makenew(l,c,0,0)) == NULL) + return NULL; + + win->_flags |= _ISPAD; + + for (i = 0; i < l; i++) { + win->_line[i].oldindex = _NEWINDEX; + if ((win->_line[i].text = (chtype *) calloc((size_t)c, sizeof(chtype))) == NULL) { + for (j = 0; j < i; j++) + free(win->_line[j].text); + + free(win->_line); + free(win); + + errno = ENOMEM; + return NULL; + } + else + for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ) + *ptr++ = ' '; + } + + T(("newpad: returned window is %p", win)); + + return(win); +} + +WINDOW *subpad(WINDOW *orig, int l, int c, int begy, int begx) +{ +WINDOW *win; + + T(("subpad(%d, %d) called", l, c)); + + if ((win = derwin(orig, l, c, begy, begx)) == NULL) + return NULL; + + win->_flags |= _ISPAD; + + T(("subpad: returned window is %p", win)); + + return(win); +} + +int prefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ + T(("prefresh() called")); + if (pnoutrefresh(win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) != ERR + && doupdate() != ERR) { + return OK; + } + return ERR; +} + +int pnoutrefresh(WINDOW *win, int pminrow, int pmincol, + int sminrow, int smincol, int smaxrow, int smaxcol) +{ +short i, j; +short m, n; +short pmaxrow; +short pmaxcol; +short displaced; +bool wide; + + T(("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d) called", + win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); + + if (win == 0) + return ERR; + + if (!(win->_flags & _ISPAD)) + return ERR; + + /* negative values are interpreted as zero */ + if (pminrow < 0) pminrow = 0; + if (pmincol < 0) pmincol = 0; + if (sminrow < 0) sminrow = 0; + if (smincol < 0) smincol = 0; + + if (smaxrow > screen_lines + || smaxcol > screen_columns + || sminrow > smaxrow + || smincol > smaxcol) + return ERR; + + pmaxrow = pminrow + smaxrow - sminrow; + pmaxcol = pmincol + smaxcol - smincol; + + T((" pminrow + smaxrow - sminrow %d, win->_maxy %d", pmaxrow, win->_maxy)); + T((" pmincol + smaxcol - smincol %d, win->_maxx %d", pmaxcol, win->_maxx)); + if ((pmaxrow > win->_maxy) + || (pmaxcol > win->_maxx)) + return ERR; + + T(("pad being refreshed")); + + if (win->_pad._pad_y >= 0) { + displaced = pminrow - win->_pad._pad_y + -(sminrow - win->_pad._pad_top); + T(("pad being shifted by %d line(s)", displaced)); + } else + displaced = 0; + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the pad to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the pad "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * 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)); + + for (i = pminrow, m = sminrow; i <= pmaxrow; i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + + if (nline->firstchar == _NOCHANGE) + nline->firstchar = nline->lastchar = n; + else if (n < nline->firstchar) + nline->firstchar = n; + else if (n > nline->lastchar) + nline->lastchar = n; + } + } + + if (wide) { + int nind = m + displaced; + if (oline->oldindex < 0 + || nind < sminrow + || nind > smaxrow) + nind = _NEWINDEX; + + nline->oldindex = nind; + } + oline->firstchar = oline->lastchar = _NOCHANGE; + oline->oldindex = i; + } + + /* + * Clean up debris from scrolling or resizing the pad, so we do not + * accidentally pick up the index value during the next call to this + * procedure. The only rows that should have an index value are those + * that are displayed during this cycle. + */ + 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; + + win->_begx = smincol; + win->_begy = sminrow; + + if (win->_clear) { + win->_clear = FALSE; + newscr->_clear = TRUE; + } + + /* + * Use the pad's current position, if it will be visible. + * If not, don't do anything; it's not an error. + */ + if (win->_leaveok == FALSE + && win->_cury >= pminrow + && win->_curx >= pmincol + && win->_cury <= pmaxrow + && win->_curx <= pmaxcol) { + newscr->_cury = win->_cury - pminrow + win->_begy; + newscr->_curx = win->_curx - pmincol + win->_begx; + } + win->_flags &= ~_HASMOVED; + + /* + * Update our cache of the line-numbers that we displayed from the pad. + * We will use this on subsequent calls to this function to derive + * values to stuff into 'oldindex[]' -- for scrolling optimization. + */ + win->_pad._pad_y = pminrow; + win->_pad._pad_x = pmincol; + win->_pad._pad_top = sminrow; + win->_pad._pad_left = smincol; + win->_pad._pad_bottom = smaxrow; + win->_pad._pad_right = smaxcol; + + return OK; +} + +int pechochar(WINDOW *pad, chtype ch) +{ + T(("echochar(%p, %lx)", pad, ch)); + + if (pad->_flags & _ISPAD) + return ERR; + + waddch(curscr, ch); + doupdate(); + return OK; +} + diff --git a/lib/libcurses/lib_printw.c b/lib/libcurses/lib_printw.c new file mode 100644 index 00000000000..22ad9c7cd8b --- /dev/null +++ b/lib/libcurses/lib_printw.c @@ -0,0 +1,93 @@ + +/*************************************************************************** +* 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_printw.c +** +** The routines printw(), wprintw() and friends. +** +*/ + +#include "curses.priv.h" + +int printw(const char *fmt, ...) +{ +va_list argp; +char buf[BUFSIZ]; + + T(("printw(\"%s\",...) called", fmt)); + + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + return(waddstr(stdscr, buf)); +} + + + +int wprintw(WINDOW *win, const char *fmt, ...) +{ +va_list argp; +char buf[BUFSIZ]; + + T(("wprintw(%p,\"%s\",...) called", win, fmt)); + + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + return(waddstr(win, buf)); +} + + + +int mvprintw(int y, int x, const char *fmt, ...) +{ +va_list argp; +char buf[BUFSIZ]; + + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + return(move(y, x) == OK ? waddstr(stdscr, buf) : ERR); +} + + + +int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) +{ +va_list argp; +char buf[BUFSIZ]; + + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + return(wmove(win, y, x) == OK ? waddstr(win, buf) : ERR); +} + +int vwprintw(WINDOW *win, const char *fmt, va_list argp) +{ +char buf[BUFSIZ]; + + vsprintf(buf, fmt, argp); + return(waddstr(win, buf)); +} diff --git a/lib/libcurses/lib_raw.c b/lib/libcurses/lib_raw.c new file mode 100644 index 00000000000..1971f9651bf --- /dev/null +++ b/lib/libcurses/lib_raw.c @@ -0,0 +1,322 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +/* + * raw.c + * + * Routines: + * raw() + * echo() + * nl() + * cbreak() + * noraw() + * noecho() + * nonl() + * nocbreak() + * qiflush() + * noqiflush() + * intrflush() + * + */ + +#include "curses.priv.h" +#include "term.h" /* cur_term */ + +/* + * COOKED_INPUT defines the collection of input mode bits to be + * cleared when entering raw mode, then re-set by noraw(). + * + * We used to clear ISTRIP and INPCK when going to raw mode. Keith + * Bostic says that's wrong, because those are hardware bits that the + * user has to get right in his/her initial environment -- he says + * curses can't do any good by clearing these, and may do harm. In + * 1995's world of 8N1 connections over error-correcting modems, all + * the parity-check stuff is pretty nearly irrelevant anyway. + * + * What's supposed to happen when noraw() executes has never been very + * well-defined. Yes, it should reset ISIG/ICANON/OPOST (historical + * practice is for it to attempt to take the driver back to cooked + * mode, rather going to some half-baked cbreak-like intermediate + * level). + * + * We make a design choice here to turn off CR/LF translation a la BSD + * when raw() is enabled, on the theory that a programmer requesting + * raw() ideally wants an 8-bit data stream that's been messed with as + * little as possible. The man pages document this. + * + * We originally opted for the simplest way to handle noraw(); just set all + * the flags we cleared. Unfortunately, having noraw() set IGNCR + * turned out to be too painful. So raw() now clears the COOKED_INPUT + * flags, but also clears (ICRNL|INLCR|IGNCR) which noraw() doesn't + * restore. + * + * Unfortunately, this means noraw() may still force some COOKED_INPUT + * flags on that the user had initially cleared via stty. It'll all + * come out in the wash when endwin() restores the user's original + * input bits (we hope...) + * + */ +#define COOKED_INPUT (IXON|IGNBRK|BRKINT|PARMRK) + +int raw(void) +{ + T(("raw() called")); + + SP->_raw = TRUE; + SP->_cbreak = TRUE; + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG|IEXTEN); + cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT|ICRNL|INLCR|IGNCR); + cur_term->Nttyb.c_oflag &= ~(OPOST); + cur_term->Nttyb.c_cc[VMIN] = 1; + cur_term->Nttyb.c_cc[VTIME] = 0; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags |= RAW; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + +int cbreak(void) +{ + T(("cbreak() called")); + + SP->_cbreak = TRUE; + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~ICANON; + cur_term->Nttyb.c_lflag |= ISIG; + cur_term->Nttyb.c_cc[VMIN] = 1; + cur_term->Nttyb.c_cc[VTIME] = 0; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags |= CBREAK; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + +int echo(void) +{ + T(("echo() called")); + + SP->_echo = TRUE; + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag |= ECHO; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags |= ECHO; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + + +int nl(void) +{ + T(("nl() called")); + + SP->_nl = TRUE; + +#ifdef TERMIOS + /* the code used to set IXON|IXOFF here, Ghod knows why... */ + cur_term->Nttyb.c_iflag |= ICRNL; + cur_term->Nttyb.c_oflag |= OPOST|ONLCR; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags |= CRMOD; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + + +int qiflush(void) +{ + T(("qiflush() called")); + + /* + * Note: this implementation may be wrong. See the comment under + * intrflush(). + */ + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag &= ~(NOFLSH); + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + return ERR; +#endif +} + + +int noraw(void) +{ + T(("noraw() called")); + + SP->_raw = FALSE; + SP->_cbreak = FALSE; + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag |= ISIG|ICANON|IEXTEN; + cur_term->Nttyb.c_iflag |= COOKED_INPUT; + cur_term->Nttyb.c_oflag |= OPOST; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK); + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif + +} + + +int nocbreak(void) +{ + T(("nocbreak() called")); + + SP->_cbreak = 0; + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag |= ICANON; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags &= ~CBREAK; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + +int noecho(void) +{ + T(("noecho() called")); + + SP->_echo = FALSE; + +#ifdef TERMIOS + /* + * Turn off ECHONL to avoid having \n still be echoed when + * cooked mode is in effect (that is, ICANON is on). + */ + cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL); + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags &= ~ECHO; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + + +int nonl(void) +{ + T(("nonl() called")); + + SP->_nl = FALSE; + +#ifdef TERMIOS + cur_term->Nttyb.c_iflag &= ~ICRNL; + cur_term->Nttyb.c_oflag &= ~ONLCR; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + cur_term->Nttyb.sg_flags &= ~CRMOD; + stty(cur_term->Filedes, &cur_term->Nttyb); + return OK; +#endif +} + +int noqiflush(void) +{ + T(("noqiflush() called")); + + /* + * Note: this implementation may be wrong. See the comment under + * intrflush(). + */ + +#ifdef TERMIOS + cur_term->Nttyb.c_lflag |= NOFLSH; + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + return ERR; +#endif +} + +int intrflush(WINDOW *win, bool flag) +{ + T(("intrflush() called")); + + /* + * This call does the same thing as the qiflush()/noqiflush() + * pair. We know for certain that SVr3 intrflush() tweaks the + * NOFLSH bit; on the other hand, the match (in the SVr4 man + * pages) between the language describing NOFLSH in termio(7) + * and the language describing qiflush()/noqiflush() in + * curs_inopts(3x) is too exact to be coincidence. + */ + +#ifdef TERMIOS + if (flag) + cur_term->Nttyb.c_lflag &= ~(NOFLSH); + else + cur_term->Nttyb.c_lflag |= (NOFLSH); + if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1) + return ERR; + else + return OK; +#else + return ERR; +#endif +} + diff --git a/lib/libcurses/lib_refresh.c b/lib/libcurses/lib_refresh.c new file mode 100644 index 00000000000..1dfa1a94355 --- /dev/null +++ b/lib/libcurses/lib_refresh.c @@ -0,0 +1,141 @@ + +/*************************************************************************** +* 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_refresh.c + * + * The routines wredrawln(), wrefresh() and wnoutrefresh(). + * + */ + +#include "curses.priv.h" + +int wredrawln(WINDOW *win, int beg, int num) +{ + T(("wredrawln(%p,%d,%d) called", win, beg, num)); + touchline(win, beg, num); + wrefresh(win); + return OK; +} + +int wrefresh(WINDOW *win) +{ + T(("wrefresh(%p) called", win)); + + if (win == curscr) + curscr->_clear = TRUE; + else + wnoutrefresh(win); + return(doupdate()); +} + +int wnoutrefresh(WINDOW *win) +{ +short i, j; +short begx = win->_begx; +short begy = win->_begy; +short m, n; +bool wide; + + T(("wnoutrefresh(%p) called", win)); + + /* + * If 'newscr' has a different background than the window that we're + * trying to refresh, we'll have to copy the whole thing. + */ + if (win->_bkgd != newscr->_bkgd) { + touchwin(win); + newscr->_bkgd = win->_bkgd; + } + + /* merge in change information from all subwindows of this window */ + wsyncdown(win); + + /* + * For pure efficiency, we'd want to transfer scrolling information + * from the window to newscr whenever the window is wide enough that + * its update will dominate the cost of the update for the horizontal + * band of newscr that it occupies. Unfortunately, this threshold + * tends to be complex to estimate, and in any case scrolling the + * whole band and rewriting the parts outside win's image would look + * really ugly. So. What we do is consider the window "wide" if it + * either (a) occupies the whole width of newscr, or (b) occupies + * all but at most one column on either vertical edge of the screen + * (this caters to fussy people who put boxes around full-screen + * windows). Note that changing this formula will not break any code, + * merely change the costs of various update cases. + */ + wide = (begx <= 1 && win->_maxx >= (newscr->_maxx - 1)); + + win->_flags &= ~_HASMOVED; + + /* + * Microtweaking alert! This double loop is one of the genuine + * hot spots in the code. Even gcc doesn't seem to do enough + * common-subexpression chunking to make it really tense, + * so we'll force the issue. + */ + for (i = 0, m = begy; i <= win->_maxy && m <= newscr->_maxy; i++, m++) { + register struct ldat *nline = &newscr->_line[m]; + register struct ldat *oline = &win->_line[i]; + + if (oline->firstchar != _NOCHANGE) { + + for (j = oline->firstchar, n = j + begx; j <= oline->lastchar; j++, n++) { + if (oline->text[j] != nline->text[n]) { + nline->text[n] = oline->text[j]; + + if (nline->firstchar == _NOCHANGE) + nline->firstchar = nline->lastchar = n; + else if (n < nline->firstchar) + nline->firstchar = n; + else if (n > nline->lastchar) + nline->lastchar = n; + } + } + + } + + if (wide) { + int oind = oline->oldindex; + + nline->oldindex = (oind == _NEWINDEX) ? _NEWINDEX : begy + oind; + } + + oline->firstchar = oline->lastchar = _NOCHANGE; + oline->oldindex = i; + } + + if (win->_clear) { + win->_clear = FALSE; +#if 0 + newscr->_clear = TRUE; +#endif + } + + if (! win->_leaveok) { + newscr->_cury = win->_cury + win->_begy; + newscr->_curx = win->_curx + win->_begx; + } + return(OK); +} diff --git a/lib/libcurses/lib_resize.c b/lib/libcurses/lib_resize.c new file mode 100644 index 00000000000..b1052f042d4 --- /dev/null +++ b/lib/libcurses/lib_resize.c @@ -0,0 +1,152 @@ + +/*************************************************************************** +* 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))) + 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 new file mode 100644 index 00000000000..02d1814ba63 --- /dev/null +++ b/lib/libcurses/lib_scanw.c @@ -0,0 +1,88 @@ + +/*************************************************************************** +* 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_scanw.c +** +** The routines scanw(), wscanw() and friends. +** +*/ + +#include "curses.priv.h" +#include <stdio.h> + +#if !HAVE_VSSCANF +extern int vsscanf(const char *str, const char *format, ...); +#endif + +int vwscanw(WINDOW *win, const char *fmt, va_list argp) +{ +char buf[BUFSIZ]; + + if (wgetstr(win, buf) == ERR) + return(ERR); + + return(vsscanf(buf, fmt, argp)); +} + +int scanw(const char *fmt, ...) +{ +va_list ap; + + T(("scanw(\"%s\",...) called", fmt)); + + va_start(ap, fmt); + return(vwscanw(stdscr, fmt, ap)); +} + +int wscanw(WINDOW *win, const char *fmt, ...) +{ +va_list ap; + + T(("wscanw(%p,\"%s\",...) called", win, fmt)); + + va_start(ap, fmt); + return(vwscanw(win, fmt, ap)); +} + + + +int mvscanw(int y, int x, const char *fmt, ...) +{ +va_list ap; + + va_start(ap, fmt); + return(move(y, x) == OK ? vwscanw(stdscr, fmt, ap) : ERR); +} + + + +int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...) +{ +va_list ap; + + va_start(ap, fmt); + return(wmove(win, y, x) == OK ? vwscanw(win, fmt, ap) : ERR); +} + + diff --git a/lib/libcurses/lib_screen.c b/lib/libcurses/lib_screen.c new file mode 100644 index 00000000000..73b4e63b14e --- /dev/null +++ b/lib/libcurses/lib_screen.c @@ -0,0 +1,171 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + +#include "curses.priv.h" + +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <time.h> +#include "term.h" /* exit_ca_mode, non_rev_rmcup */ + +static time_t dumptime; + +WINDOW *getwin(FILE *filep) +{ + WINDOW try, *nwin; + int n; + + (void) fread(&try, sizeof(WINDOW), 1, filep); + if (ferror(filep)) + return (WINDOW *)NULL; + + if ((nwin = newwin(try._maxy+1, try._maxx+1, 0, 0)) == (WINDOW *)NULL) + return (WINDOW *)NULL; + + /* + * We deliberately do not restore the _parx, _pary, or _parent + * 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->_flags = try._flags; + + 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; + + for (n = 0; n < nwin->_maxy + 1; n++) + { + (void) fread(nwin->_line[n].text, + sizeof(chtype), (size_t)(nwin->_maxx + 1), filep); + if (ferror(filep)) + { + delwin(nwin); + return((WINDOW *)NULL); + } + } + touchwin(nwin); + + return nwin; +} + +int putwin(WINDOW *win, FILE *filep) +{ + int n; + + (void) fwrite(win, sizeof(WINDOW), 1, filep); + if (ferror(filep)) + return 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)) + return(ERR); + } + + return(OK); +} + +int scr_restore(const char *file) +{ + FILE *fp; + + if ((fp = fopen(file, "r")) == (FILE *)NULL) + return ERR; + else + { + delwin(newscr); + newscr = getwin(fp); + (void) fclose(fp); + return OK; + } +} + +int scr_dump(const char *file) +{ + FILE *fp; + + if ((fp = fopen(file, "w")) == (FILE *)NULL) + return ERR; + else + { + (void) putwin(newscr, fp); + (void) fclose(fp); + dumptime = time((time_t *)0); + return OK; + } +} + +int scr_init(const char *file) +{ + FILE *fp; + struct stat stb; + +#ifdef exit_ca_mode + if (exit_ca_mode && non_rev_rmcup) + return(ERR); +#endif /* exit_ca_mode */ + + if ((fp = fopen(file, "r")) == (FILE *)NULL) + return ERR; + else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) + return ERR; + else + { + delwin(curscr); + curscr = getwin(fp); + (void) fclose(fp); + return OK; + } +} + +int scr_set(const char *file) +{ + if (scr_init(file) == ERR) + return(ERR); + else + { + delwin(newscr); + newscr = dupwin(curscr); + return(OK); + } +} + + diff --git a/lib/libcurses/lib_scroll.c b/lib/libcurses/lib_scroll.c new file mode 100644 index 00000000000..d8350a38344 --- /dev/null +++ b/lib/libcurses/lib_scroll.c @@ -0,0 +1,110 @@ + +/*************************************************************************** +* 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_scroll.c +** +** The routine wscrl(win, n). +** positive n scroll the window up (ie. move lines down) +** negative n scroll the window down (ie. move lines up) +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include <string.h> + +void _nc_scroll_window(WINDOW *win, int const n, short const top, short const bottom) +{ +int line, j; +chtype blank = _nc_render(win, ' ', BLANK); + + TR(TRACE_MOVE, ("_nc_scroll_window(%p, %d, %d, %d)", win, n, top,bottom)); + + /* + * This used to do a line-text pointer-shuffle instead of text copies. + * That (a) doesn't work when the window is derived and doesn't have + * its own storage, (b) doesn't save you a lot on modern machines + * anyway. Your typical memcpy implementations are coded in + * assembler using a tight BLT loop; for the size of copies we're + * talking here, the total execution time is dominated by the one-time + * setup cost. So there is no point in trying to be excessively + * clever -- esr. + */ + + /* shift n lines downwards */ + if (n < 0) { + for (line = bottom; line >= top-n; line--) { + memcpy(win->_line[line].text, + win->_line[line+n].text, + (size_t)(sizeof(chtype) * (win->_maxx+1))); + 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; + } + } + + /* shift n lines upwards */ + if (n > 0) { + for (line = top; line <= bottom-n; line++) { + memcpy(win->_line[line].text, + win->_line[line+n].text, + (size_t)(sizeof(chtype) * (win->_maxx+1))); + 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; + } + } +} + +int +wscrl(WINDOW *win, int n) +{ + T(("wscrl(%p,%d) called", win, n)); + + if (! win->_scroll) + return ERR; + + if (n == 0) + return OK; + + if ((n > (win->_regbottom - win->_regtop)) || + (-n > (win->_regbottom - win->_regtop))) + return ERR; + + _nc_scroll_window(win, n, win->_regtop, win->_regbottom); + touchline(win, win->_regtop, (int)(win->_regbottom - win->_regtop + 1)); + + _nc_synchook(win); + return OK; +} diff --git a/lib/libcurses/lib_scrreg.c b/lib/libcurses/lib_scrreg.c new file mode 100644 index 00000000000..6a741304dbe --- /dev/null +++ b/lib/libcurses/lib_scrreg.c @@ -0,0 +1,47 @@ + +/*************************************************************************** +* 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_scrreg.c +** +** The routine wsetscrreg(). +** +*/ + +#include "curses.priv.h" + +int wsetscrreg(WINDOW *win, int top, int bottom) +{ + T(("wsetscrreg(%p,%d,%d) called", win, top, bottom)); + + if (top >= 0 && top <= win->_maxy && + bottom >= 0 && bottom <= win->_maxy && + bottom > top) + { + win->_regtop = (short)top; + win->_regbottom = (short)bottom; + + return(OK); + } else + return(ERR); +} diff --git a/lib/libcurses/lib_set_term.c b/lib/libcurses/lib_set_term.c new file mode 100644 index 00000000000..6df38903072 --- /dev/null +++ b/lib/libcurses/lib_set_term.c @@ -0,0 +1,141 @@ + +/*************************************************************************** +* 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_set_term.c +** +** The routine set_term(). +** +*/ + +#include "curses.priv.h" +#include <stdlib.h> +#include "term.h" /* cur_term */ + +struct screen * set_term(struct screen *screen) +{ +struct screen *oldSP; + + T(("set_term(%p) called", screen)); + + oldSP = SP; + _nc_set_screen(screen); + + cur_term = SP->_term; + curscr = SP->_curscr; + newscr = SP->_newscr; + stdscr = SP->_stdscr; + + return(oldSP); +} + +void delscreen(SCREEN *sp) +{ + free(sp); +} + +struct ripoff_t +{ + int line; + int (*hook)(WINDOW *, int); +} +rippedoff[5], *rsp = rippedoff; + +int _nc_setupscreen(short slines, short const scolumns) +/* OS-independent screen initializations */ +{ +int stolen, topstolen; + + if (!_nc_alloc_screen()) + return ERR; + + SP->_term = cur_term; + SP->_lines = slines; + SP->_columns = scolumns; + SP->_cursrow = -1; + SP->_curscol = -1; + SP->_keytry = UNINITIALISED; + SP->_nl = TRUE; + SP->_raw = FALSE; + SP->_cbreak = FALSE; + SP->_echo = TRUE; + SP->_fifohead = -1; + SP->_fifotail = 0; + SP->_fifopeek = 0; + SP->_endwin = TRUE; + SP->_ofp = stdout; /* (may be overridden later) */ + SP->_coloron = 0; + + init_acs(); + + T(("creating newscr")); + if ((newscr = newwin(slines, scolumns, 0, 0)) == (WINDOW *)NULL) + return ERR; + + T(("creating curscr")); + if ((curscr = newwin(slines, scolumns, 0, 0)) == (WINDOW *)NULL) + return ERR; + + SP->_newscr = newscr; + SP->_curscr = curscr; + + newscr->_clear = TRUE; + curscr->_clear = FALSE; + + stolen = topstolen = 0; + for (rsp = rippedoff; rsp->line; rsp++) { + if (rsp->hook) + if (rsp->line < 0) + rsp->hook(newwin(1,scolumns, slines-1,0), scolumns); + else + rsp->hook(newwin(1,scolumns, topstolen++,0), scolumns); + --slines; + stolen++; + } + + T(("creating stdscr")); + if ((stdscr = newwin(LINES = slines, scolumns, topstolen, 0)) == NULL) + return ERR; + SP->_stdscr = stdscr; + + def_shell_mode(); + def_prog_mode(); + + return OK; +} + +int +ripoffline(int line, int (*init)(WINDOW *, int)) +{ + if (line == 0) + return(OK); + + if (rsp >= rippedoff + sizeof(rippedoff)/sizeof(rippedoff[0])) + return(ERR); + + rsp->line = line; + rsp->hook = init; + rsp++; + + return(OK); +} diff --git a/lib/libcurses/lib_slk.c b/lib/libcurses/lib_slk.c new file mode 100644 index 00000000000..973a3ab6ae3 --- /dev/null +++ b/lib/libcurses/lib_slk.c @@ -0,0 +1,328 @@ + +/*************************************************************************** +* 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_slk.c + * Soft key routines. + */ + +#include "curses.priv.h" +#include <string.h> +#include <stdlib.h> +#include "term.h" /* num_labels, label_*, plab_norm */ + +#define MAX_SKEY 8 /* count of soft keys */ +#define MAX_SKEY_LEN 8 /* max length of soft key text */ + +/* + * We'd like to move these into the screen context structure, but cannot, + * because slk_init() is called before initscr()/newterm(). + */ +int _slk_init; /* TRUE if slk_init() called */ + +static int _slk_format; /* format specified in slk_init() */ +static chtype _slk_attr = A_STANDOUT; /* soft label attribute */ +static int maxlab; /* number of labels */ +static int maxlen; /* maximum length of label */ + +/* + * Fetch the label text. + */ + +char * +slk_label(int n) +{ + T(("slk_label(%d)", n)); + + if (SP->_slk == NULL || n < 1 || n > MAX_SKEY) + 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 < MAX_SKEY; i++) { + if (slk->dirty || slk->ent[i].dirty) { + if (slk->ent[i].visible) { +#ifdef num_labels + if (num_labels > 0) + { + TPUTS_TRACE("plab_norm"); + putp(tparm(plab_norm, i, slk->win,slk->ent[i].form_text)); + } + else +#endif /* num_labels */ + { + wmove(slk->win,0,slk->ent[i].x); + wattrset(slk->win,_slk_attr); + waddstr(slk->win,slk->ent[i].form_text); + wattrset(slk->win,A_NORMAL); + } + } + 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; + 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; + + T(("slk_set(%d, \"%s\", %d)", i, str, format)); + + if (slk == NULL || i < 1 || i > maxlab || format < 0 || format > 2) + return(ERR); + if (str == NULL) + str = ""; + --i; + (void) strncpy(slk->ent[i].text, str, (unsigned)maxlen); + memset(slk->ent[i].form_text,' ', (unsigned)maxlen); + slk->ent[i].text[maxlen] = 0; + slk->ent[i].form_text[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+(MAX_SKEY_LEN-len)/2, + slk->ent[i].text, + len); + break; + case 2: /* right-justified */ + memcpy(slk->ent[i].form_text+MAX_SKEY_LEN-len, + slk->ent[i].text, + len); + break; + } + 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; + werase(SP->_slk->win); + return wrefresh(SP->_slk->win); +} + +/* + * Initialize soft labels. + * Called from newterm() + */ + +int +slk_initialize(WINDOW *stwin, int cols) +{ +SLK *slk; +int i, x; + + T(("slk_initialize()")); + + if ((SP->_slk = slk = (SLK*) calloc(1,sizeof(SLK))) == NULL) + return(OK); + +#ifdef num_labels + maxlab = (num_labels > 0) ? num_labels : MAX_SKEY; + maxlen = (num_labels > 0) ? label_width * label_height : MAX_SKEY_LEN; +#else + maxlab = MAX_SKEY; + maxlen = MAX_SKEY_LEN; +#endif /* num_labels */ + + for (i = 0; i < MAX_SKEY; i++) { + memset(slk->ent[i].form_text, ' ', (unsigned)maxlen); + slk->ent[i].visible = i < maxlab; + } + if (_slk_format == 1) { /* 4-4 */ + int gap = cols - (MAX_SKEY * MAX_SKEY_LEN) - 6; + + if (gap < 1) + gap = 1; + for (i = x = 0; i < MAX_SKEY; i++) { + slk->ent[i].x = x; + x += MAX_SKEY_LEN; + x += (i == 3) ? gap : 1; + } + } + else { /* 0 -> 3-2-3 */ + int gap = (cols - (MAX_SKEY * MAX_SKEY_LEN) - 5) / 2; + + if (gap < 1) + gap = 1; + for (i = x = 0; i < MAX_SKEY; i++) { + slk->ent[i].x = x; + x += MAX_SKEY_LEN; + x += (i == 2 || i == 4) ? gap : 1; + } + } + slk->dirty = TRUE; + if ((slk->win = stwin) == NULL) + { + free(slk); + return(ERR); + } + + return(OK); +} + +/* + * Initialize soft labels. Called by the user before initscr(). + */ + +int +slk_init(int format) +{ + if (format < 0 || format > 1) + return(ERR); + _slk_format = format; + _slk_init = TRUE; + return(OK); +} + +/* Functions to manipulate the soft-label attribute */ + +int +slk_attrset(attr_t attr) +{ + _slk_attr = attr; + return(OK); +} + +int +slk_attron(attr_t attr) +{ + _slk_attr |= attr; + return(OK); +} + +int +slk_attroff(attr_t attr) +{ + _slk_attr &=~ attr; + return(OK); +} + diff --git a/lib/libcurses/lib_touch.c b/lib/libcurses/lib_touch.c new file mode 100644 index 00000000000..b2b29ac5859 --- /dev/null +++ b/lib/libcurses/lib_touch.c @@ -0,0 +1,64 @@ + +/*************************************************************************** +* 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_touch.c +** +** The routines untouchwin(), +** wtouchln(), +** is_linetouched() +** is_wintouched(). +** +*/ + +#include "curses.priv.h" + +int is_linetouched(WINDOW *win, int line) +{ + if (line > win->_maxy || line < 0) + return ERR; + if (win->_line[line].firstchar != _NOCHANGE) return TRUE; + return FALSE; +} + +int is_wintouched(WINDOW *win) +{ +int i; + + for (i = 0; i <= win->_maxy; i++) + if (win->_line[i].firstchar != _NOCHANGE) + return TRUE; + return FALSE; +} + +int wtouchln(WINDOW *win, int y, int n, int changed) +{ +int i; + + T(("wtouchln(%p,%d,%d,%d)", win, y, n, changed)); + + for (i = y; i < y+n; i++) { + win->_line[i].firstchar = changed ? 0 : _NOCHANGE; + win->_line[i].lastchar = changed ? win->_maxx : _NOCHANGE; + } + return OK; +} + diff --git a/lib/libcurses/lib_tstp.c b/lib/libcurses/lib_tstp.c new file mode 100644 index 00000000000..73be68af51c --- /dev/null +++ b/lib/libcurses/lib_tstp.c @@ -0,0 +1,252 @@ + +/*************************************************************************** +* 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_tstp.c +** +** The routine _nc_signal_handler(). +** +*/ + +#include "curses.priv.h" + +#include <signal.h> +#include <stdlib.h> + +#if HAVE_SIGACTION +#if !HAVE_TYPE_SIGACTION +typedef struct sigaction sigaction_t; +#endif +#else +#include "SigAction.h" +#endif + +#ifdef SVR4_ACTION +#define _POSIX_SOURCE +#endif + +/* + * Note: This code is fragile! Its problem is that different OSs + * handle restart of system calls interrupted by signals differently. + * The ncurses code needs signal-call restart to happen -- otherwise, + * interrupted wgetch() calls will return FAIL, probably making the + * application think the input stream has ended and it should + * terminate. In particular, you know you have this problem if, when + * you suspend an ncurses-using lynx with ^Z and resume, it dies + * immediately. + * + * Default behavior of POSIX sigaction(2) is not to restart + * interrupted system calls, but Linux's sigaction does it anyway (at + * least, on and after the 1.1.47 I (esr) use). Thus this code works + * OK under Linux. The 4.4BSD sigaction(2) supports a (non-portable) + * SA_RESTART flag that forces the right behavior. Thus, this code + * should work OK under BSD/OS, NetBSD, and FreeBSD (let us know if it + * does not). + * + * Stock System Vs (and anything else using a strict-POSIX + * sigaction(2) without SA_RESTART) may have a problem. Possible + * solutions: + * + * sigvec restarts by default (SV_INTERRUPT flag to not restart) + * signal restarts by default in SVr4 (assuming you link with -lucb) + * and BSD, but not SVr3. + * sigset restarts, but is only available under SVr4/Solaris. + * + * The signal(3) call is mandated by the ANSI standard, and its + * interaction with sigaction(2) is described in the POSIX standard + * (3.3.4.2, page 72,line 934). According to section 8.1, page 191, + * however, signal(3) itself is not required by POSIX.1. And POSIX is + * silent on whether it is required to restart signals. + * + * So. The present situation is, we use sigaction(2) with no + * guarantee of restart anywhere but on Linux and BSD. We could + * switch to signal(3) and collar Linux, BSD, and SVr4. Any way + * we slice it, System V UNIXes older than SVr4 will probably lose + * (this may include XENIX). + * + * This implementation will probably be changed to use signal(3) in + * the future. If nothing else, it's simpler... + */ + +#ifdef SIGTSTP +static void tstp(int dummy) +{ + sigset_t mask, omask; + sigaction_t act, oact; + + T(("tstp() called")); + + /* + * The user may have changed the prog_mode tty bits, so save them. + */ + def_prog_mode(); + + /* + * Block window change and timer signals. The latter + * is because applications use timers to decide when + * to repaint the screen. + */ + (void)sigemptyset(&mask); + (void)sigaddset(&mask, SIGALRM); +#ifdef SIGWINCH + (void)sigaddset(&mask, SIGWINCH); +#endif + (void)sigprocmask(SIG_BLOCK, &mask, &omask); + + /* + * End window mode, which also resets the terminal state to the + * original (pre-curses) modes. + */ + endwin(); + + /* Unblock SIGTSTP. */ + (void)sigemptyset(&mask); + (void)sigaddset(&mask, SIGTSTP); + (void)sigprocmask(SIG_UNBLOCK, &mask, NULL); + + /* Now we want to resend SIGSTP to this process and suspend it */ + act.sa_handler = SIG_DFL; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + sigaction(SIGTSTP, &act, &oact); + kill(getpid(), SIGTSTP); + + /* Process gets suspended...time passes...process resumes */ + + T(("SIGCONT received")); + sigaction(SIGTSTP, &oact, NULL); + flushinp(); + + /* + * If the user modified the tty state while suspended, he wants + * those changes to stick. So save the new "default" terminal state. + */ + def_shell_mode(); + + /* + * This relies on the fact that doupdate() will restore the + * program-mode tty state, and issue enter_ca_mode if need be. + */ + doupdate(); + + /* Reset the signals. */ + (void)sigprocmask(SIG_SETMASK, &omask, NULL); +} +#endif /* defined(SIGTSTP) */ + +static void cleanup(int sig) +{ + /* + * Actually, doing any sort of I/O from within an signal handler is + * "unsafe". But we'll _try_ to clean up the screen and terminal + * settings on the way out. + */ + if (sig == SIGINT + || sig == SIGQUIT) { + sigaction_t act; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = SIG_IGN; + if (sigaction(sig, &act, (sigaction_t *)0) == 0) { + endwin(); + } + } + exit(1); +} + +/* + * If the given signal is still in its default state, set it to the given + * handler. + */ +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) { + (void)sigaction(sig, act, (sigaction_t *)0); + return TRUE; + } + return FALSE; +} + +/* + * This is invoked once at the beginning (e.g., from 'initscr()'), to + * initialize the signal catchers, and thereafter when spawning a shell (and + * returning) to disable/enable the SIGTSTP (i.e., ^Z) catcher. + * + * If the application has already set one of the signals, we'll not modify it + * (during initialization). + * + * The XSI document implies that we shouldn't keep the SIGTSTP handler if + * the caller later changes its mind, but that doesn't seem correct. + */ +void _nc_signal_handler(bool enable) +{ +#ifdef SIGTSTP /* Xenix 2.x doesn't have this */ +static sigaction_t act, oact; +static int ignore; + + if (!ignore) + { + if (!enable) + { + act.sa_handler = SIG_IGN; + sigaction(SIGTSTP, &act, &oact); + } + else if (act.sa_handler) + { + sigaction(SIGTSTP, &oact, NULL); + } + else /*initialize */ + { + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_RESTART + act.sa_flags |= SA_RESTART; +#endif /* SA_RESTART */ + + act.sa_handler = cleanup; + CatchIfDefault(SIGINT, &act); + CatchIfDefault(SIGTERM, &act); + + act.sa_handler = tstp; + if (!CatchIfDefault(SIGTSTP, &act)) + ignore = TRUE; + } + } +#else + if (enable) + { + static sigaction_t act; + act.sa_handler = cleanup; + CatchIfDefault(SIGINT, &act); + CatchIfDefault(SIGTERM, &act); + } +#endif +} diff --git a/lib/libcurses/lib_twait.c b/lib/libcurses/lib_twait.c new file mode 100644 index 00000000000..c9dee4e07be --- /dev/null +++ b/lib/libcurses/lib_twait.c @@ -0,0 +1,118 @@ + +/*************************************************************************** +* 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_twait.c +** +** The routine _nc_timed_wait(). +** +*/ + +#include "curses.priv.h" + +#include <sys/types.h> /* some systems can't live without this */ +#include <string.h> + +#if HAVE_SYS_TIME_H && ! SYSTEM_LOOKS_LIKE_SCO +#include <sys/time.h> +#endif + +#if HAVE_UNISTD_H +#include <unistd.h> +#endif + +#if HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif + +/* + * We want to define GOOD_SELECT if the last argument of select(2) is + * modified to indicate time left. The code will deal gracefully with + * the other case, this is just an optimization to reduce the number + * of system calls per input event. + * + * In general, expect System-V-like UNIXes to have this behavior and BSD-like + * ones to not have it. Check your manual page. If it doesn't explicitly + * say the last argument is modified, assume it's not. + * + * (We'd really like configure to autodetect this, but writing a proper test + * turns out to be hard.) + */ +#if defined(linux) +#define GOOD_SELECT +#endif + +#if !HAVE_USLEEP +int usleep(unsigned int usec) +{ +struct timeval tval; + + tval.tv_sec = usec / 1000000; + tval.tv_usec = usec % 1000000; + select(0, NULL, NULL, NULL, &tval); + +} +#endif + +int _nc_timed_wait(int fd, int wait, int *timeleft) +{ +int result; +struct timeval ntimeout; +static fd_set set; +#if !defined(GOOD_SELECT) && HAVE_GETTIMEOFDAY +struct timeval starttime, returntime; + + gettimeofday(&starttime, NULL); +#endif + + FD_ZERO(&set); + FD_SET(fd, &set); + + /* the units of wait are milliseconds */ + ntimeout.tv_sec = wait / 1000; + ntimeout.tv_usec = (wait % 1000) * 1000; + + T(("start twait: sec = %ld, usec = %ld", ntimeout.tv_sec, ntimeout.tv_usec)); + + result = select(fd+1, &set, NULL, NULL, &ntimeout); + +#if !defined(GOOD_SELECT) && HAVE_GETTIMEOFDAY + gettimeofday(&returntime, NULL); + ntimeout.tv_sec -= (returntime.tv_sec - starttime.tv_sec); + ntimeout.tv_usec -= (returntime.tv_usec - starttime.tv_usec); + if (ntimeout.tv_usec < 0 && ntimeout.tv_sec > 0) { + ntimeout.tv_sec--; + ntimeout.tv_usec += 1000000; + } + if (ntimeout.tv_sec < 0) + ntimeout.tv_sec = ntimeout.tv_usec = 0; +#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, sec = %ld, usec = %ld (%d msec)", + result, ntimeout.tv_sec, ntimeout.tv_usec, + timeleft ? *timeleft : -1)); + + return(result); +} diff --git a/lib/libcurses/lib_unctrl.c b/lib/libcurses/lib_unctrl.c new file mode 100644 index 00000000000..2511ecfb0e8 --- /dev/null +++ b/lib/libcurses/lib_unctrl.c @@ -0,0 +1,47 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + + + +#include <unctrl.h> + +char *unctrl(register chtype uch) +{ + static char buffer[3] = "^x"; + + if ((uch & 0x60) != 0 && uch != 0x7F) { + /* + * Printable character. Simply return the character as a one-character + * string. + */ + buffer[1] = uch; + return &buffer[1]; + } + /* + * 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; + +} diff --git a/lib/libcurses/lib_vidattr.c b/lib/libcurses/lib_vidattr.c new file mode 100644 index 00000000000..8c6ffc8a35a --- /dev/null +++ b/lib/libcurses/lib_vidattr.c @@ -0,0 +1,275 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + +/* + * vidputs(newmode, outc) + * + * newmode is taken to be the logical 'or' of the symbols in curses.h + * representing graphic renditions. The teminal is set to be in all of + * the given modes, if possible. + * + * if the new attribute is normal + * if exit-alt-char-set exists + * emit it + * emit exit-attribute-mode + * else if set-attributes exists + * use it to set exactly what you want + * else + * if exit-attribute-mode exists + * turn off everything + * else + * turn off those which can be turned off and aren't in + * newmode. + * turn on each mode which should be on and isn't, one by one + * + * NOTE that this algorithm won't achieve the desired mix of attributes + * in some cases, but those are probably just those cases in which it is + * actually impossible, anyway, so... + */ + +#include "curses.priv.h" +#include <string.h> +#include "term.h" + +int vidputs(attr_t newmode, int (*outc)(int)) +{ +static attr_t previous_attr; +attr_t turn_on, turn_off; + + T(("vidputs(%lx) called %s", newmode, _traceattr(newmode))); + + /* this allows us to go on whether or not newterm() has been called */ + if (SP) + previous_attr = SP->_current_attr; + + T(("previous attribute was %s", _traceattr(previous_attr))); + + turn_off = (~newmode & previous_attr) & (chtype)(~A_COLOR); + turn_on = (newmode & ~previous_attr) & (chtype)(~A_COLOR); + + if (newmode == previous_attr) + return OK; + if (newmode == A_NORMAL) { + if((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) { + TPUTS_TRACE("exit_alt_charset_mode"); + tputs(exit_alt_charset_mode, 1, outc); + previous_attr &= ~A_ALTCHARSET; + } + if (previous_attr & A_COLOR) { + TPUTS_TRACE("orig_pair"); + tputs(orig_pair, 1, outc); + } + if (previous_attr) { + TPUTS_TRACE("exit_attribute_mode"); + tputs(exit_attribute_mode, 1, outc); + } + + } else if (set_attributes) { + if (turn_on || turn_off) { + TPUTS_TRACE("set_attributes"); + tputs(tparm(set_attributes, + (newmode & A_STANDOUT) != 0, + (newmode & A_UNDERLINE) != 0, + (newmode & A_REVERSE) != 0, + (newmode & A_BLINK) != 0, + (newmode & A_DIM) != 0, + (newmode & A_BOLD) != 0, + (newmode & A_INVIS) != 0, + (newmode & A_PROTECT) != 0, + (newmode & A_ALTCHARSET) != 0), 1, outc); + /* + * Setting attributes in this way tends to unset the + * ones (such as color) that weren't specified. + */ + turn_off |= A_COLOR; + } + } else { + + T(("turning %s off", _traceattr(turn_off))); + + if ((turn_off & A_ALTCHARSET) && exit_alt_charset_mode) { + TPUTS_TRACE("exit_alt_charset_mode"); + tputs(exit_alt_charset_mode, 1, outc); + turn_off &= ~A_ALTCHARSET; + } + + if ((turn_off & A_UNDERLINE) && exit_underline_mode) { + TPUTS_TRACE("exit_underline_mode"); + tputs(exit_underline_mode, 1, outc); + turn_off &= ~A_UNDERLINE; + } + + if ((turn_off & A_STANDOUT) && exit_standout_mode) { + TPUTS_TRACE("exit_standout_mode"); + tputs(exit_standout_mode, 1, outc); + turn_off &= ~A_STANDOUT; + } + + if (turn_off && exit_attribute_mode) { + TPUTS_TRACE("exit_attribute_mode"); + tputs(exit_attribute_mode, 1, outc); + turn_on |= (newmode & (chtype)(~A_COLOR)); + turn_off |= A_COLOR; + } + + T(("turning %s on", _traceattr(turn_on))); + + if ((turn_on & A_ALTCHARSET) && enter_alt_charset_mode) { + TPUTS_TRACE("enter_alt_charset_mode"); + tputs(enter_alt_charset_mode, 1, outc); + } + + if ((turn_on & A_BLINK) && enter_blink_mode) { + TPUTS_TRACE("enter_blink_mode"); + tputs(enter_blink_mode, 1, outc); + } + + if ((turn_on & A_BOLD) && enter_bold_mode) { + TPUTS_TRACE("enter_bold_mode"); + tputs(enter_bold_mode, 1, outc); + } + + if ((turn_on & A_DIM) && enter_dim_mode) { + TPUTS_TRACE("enter_dim_mode"); + tputs(enter_dim_mode, 1, outc); + } + + if ((turn_on & A_REVERSE) && enter_reverse_mode) { + TPUTS_TRACE("enter_reverse_mode"); + tputs(enter_reverse_mode, 1, outc); + } + + if ((turn_on & A_STANDOUT) && enter_standout_mode) { + TPUTS_TRACE("enter_standout_mode"); + tputs(enter_standout_mode, 1, outc); + } + + if ((turn_on & A_PROTECT) && enter_protected_mode) { + TPUTS_TRACE("enter_protected_mode"); + tputs(enter_protected_mode, 1, outc); + } + + if ((turn_on & A_INVIS) && enter_secure_mode) { + TPUTS_TRACE("enter_secure_mode"); + tputs(enter_secure_mode, 1, outc); + } + + if ((turn_on & A_UNDERLINE) && enter_underline_mode) { + TPUTS_TRACE("enter_underline_mode"); + tputs(enter_underline_mode, 1, outc); + } + + if ((turn_on & A_HORIZONTAL) && enter_horizontal_hl_mode) { + TPUTS_TRACE("enter_horizontal_hl_mode"); + tputs(enter_horizontal_hl_mode, 1, outc); + } + + if ((turn_on & A_LEFT) && enter_left_hl_mode) { + TPUTS_TRACE("enter_left_hl_mode"); + tputs(enter_left_hl_mode, 1, outc); + } + + if ((turn_on & A_LOW) && enter_low_hl_mode) { + TPUTS_TRACE("enter_low_hl_mode"); + tputs(enter_low_hl_mode, 1, outc); + } + + if ((turn_on & A_RIGHT) && enter_right_hl_mode) { + TPUTS_TRACE("enter_right_hl_mode"); + tputs(enter_right_hl_mode, 1, outc); + } + + if ((turn_on & A_TOP) && enter_top_hl_mode) { + TPUTS_TRACE("enter_top_hl_mode"); + tputs(enter_top_hl_mode, 1, outc); + } + + if ((turn_on & A_VERTICAL) && enter_vertical_hl_mode) { + TPUTS_TRACE("enter_vertical_hl_mode"); + tputs(enter_vertical_hl_mode, 1, outc); + } + } + + /* if there is no crrent screen, assume we *can* do color */ + if (!SP || SP->_coloron) { + int pair = PAIR_NUMBER(newmode); + int current_pair = PAIR_NUMBER(previous_attr); + + T(("old pair = %d -- new pair = %d", current_pair, pair)); + if (pair != current_pair || (turn_off && pair)) { + _nc_do_color(pair, outc); + } + } + + if (SP) + SP->_current_attr = newmode; + + T(("vidputs finished")); + return OK; +} + +#undef vidattr + +int vidattr(attr_t newmode) +{ + + T(("vidattr(%lx) called", newmode)); + + return(vidputs(newmode, _nc_outch)); +} + +attr_t termattrs(void) +{ + int attrs = A_NORMAL; + + if (enter_alt_charset_mode) + attrs |= A_ALTCHARSET; + + if (enter_blink_mode) + attrs |= A_BLINK; + + if (enter_bold_mode) + attrs |= A_BOLD; + + if (enter_dim_mode) + attrs |= A_DIM; + + if (enter_reverse_mode) + attrs |= A_REVERSE; + + if (enter_standout_mode) + attrs |= A_STANDOUT; + + if (enter_protected_mode) + attrs |= A_PROTECT; + + if (enter_secure_mode) + attrs |= A_INVIS; + + if (enter_underline_mode) + attrs |= A_UNDERLINE; + + if (SP->_coloron) + attrs |= A_COLOR; + + return(attrs); +} + diff --git a/lib/libcurses/lib_window.c b/lib/libcurses/lib_window.c new file mode 100644 index 00000000000..3e9f58af704 --- /dev/null +++ b/lib/libcurses/lib_window.c @@ -0,0 +1,173 @@ + +/*************************************************************************** +* 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_window.c +** +** +*/ + +#include "curses.priv.h" +#include <string.h> + +void _nc_synchook(WINDOW *win) +/* hook to be called after each window change */ +{ + if (win->_immed) wrefresh(win); + if (win->_sync) wsyncup(win); +} + +int mvderwin(WINDOW *win, int y, int x) +/* move a derived window */ +{ + WINDOW *orig = win->_parent; + int i; + + if (orig) + { + if (win->_parx==x && win->_pary==y) + return OK; + if (x<0 || y<0) + return ERR; + if ( (x+getmaxx(win) > getmaxx(orig)) || + (y+getmaxy(win) > getmaxy(orig)) ) + return ERR; + } + else + return ERR; + wsyncup(win); + win->_parx = x; + win->_pary = y; + for(i=0;i<getmaxy(win);i++) + win->_line[i].text = &(orig->_line[y++].text[x]); + return OK; +} + +int syncok(WINDOW *win, bool bf) +/* enable/disable automatic wsyncup() on each change to window */ +{ + if (win) { + win->_sync = bf; + return(OK); + } else + return(ERR); +} + +void wsyncup(WINDOW *win) +/* mark changed every cell in win's ancestors that is changed in win */ +{ + WINDOW *wp; + + if (win->_parent) + for (wp = win; wp->_parent; wp = wp->_parent) + { + int i; + WINDOW *pp = wp->_parent; + + for (i = 0; i <= wp->_maxy; i++) + { + if (pp->_line[wp->_pary + i].firstchar >= 0 + && pp->_line[wp->_pary + i].firstchar < wp->_line[i].firstchar) + wp->_line[i].firstchar = pp->_line[wp->_pary + i].firstchar; + if (pp->_line[wp->_pary + i].lastchar > wp->_line[i].lastchar) + wp->_line[i].lastchar = pp->_line[wp->_pary + i].lastchar; + } + } +} + +void wsyncdown(WINDOW *win) +/* mark changed every cell in win that is changed in any of its ancestors */ +{ + WINDOW *wp; + + if (win->_parent) + for (wp = win; wp->_parent; wp = wp->_parent) + { + int i; + WINDOW *pp = wp->_parent; + + for (i = 0; i <= wp->_maxy; i++) + { + if (wp->_line[i].firstchar >= 0 + && wp->_line[i].firstchar < pp->_line[wp->_pary + i].firstchar) + pp->_line[wp->_pary + i].firstchar = wp->_line[i].firstchar; + if (wp->_line[i].lastchar > pp->_line[wp->_pary + i].lastchar) + pp->_line[wp->_pary + i].lastchar = wp->_line[i].lastchar; + } + } +} + +void wcursyncup(WINDOW *win) +/* sync the cursor in all derived windows to its value in the base window */ +{ + WINDOW *wp; + for( wp = win; wp && wp->_parent; wp = wp->_parent ) { + wmove( wp->_parent, wp->_pary + wp->_cury, wp->_parx + wp->_curx ); + } +} + +WINDOW *dupwin(WINDOW *win) +/* make an exact duplicate of the given window */ +{ +WINDOW *nwin; +size_t linesize; +int i; + + T(("dupwin(%p) called", win)); + + if ((nwin = newwin(win->_maxy + 1, win->_maxx + 1, win->_begy, win->_begx)) == NULL) + return NULL; + + nwin->_curx = win->_curx; + nwin->_cury = win->_cury; + nwin->_maxy = win->_maxy; + nwin->_maxx = win->_maxx; + nwin->_begy = win->_begy; + nwin->_begx = win->_begx; + + nwin->_flags = win->_flags; + nwin->_attrs = win->_attrs; + nwin->_bkgd = win->_bkgd; + + nwin->_clear = win->_clear; + nwin->_scroll = win->_scroll; + nwin->_leaveok = win->_leaveok; + nwin->_use_keypad = win->_use_keypad; + 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->_regtop = win->_regtop; + nwin->_regbottom = win->_regbottom; + + linesize = (win->_maxx + 1) * sizeof(chtype); + for (i = 0; i <= nwin->_maxy; i++) { + memcpy(nwin->_line[i].text, win->_line[i].text, linesize); + nwin->_line[i].firstchar = win->_line[i].firstchar; + nwin->_line[i].lastchar = win->_line[i].lastchar; + } + + return nwin; +} + diff --git a/lib/libcurses/unctrl.h b/lib/libcurses/unctrl.h new file mode 100644 index 00000000000..a503aa76a8f --- /dev/null +++ b/lib/libcurses/unctrl.h @@ -0,0 +1,45 @@ + +/*************************************************************************** +* 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. * +* * +***************************************************************************/ + +/* + * unctrl.h + * + * 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. + * + */ +#ifndef _UNCTRL_H +#define _UNCTRL_H 1 +#define NCURSES_VERSION "1.9.9e" + +#ifndef _CHTYPE_T_ +#define _CHTYPE_T_ unsigned long +typedef _CHTYPE_T_ chtype; +#endif + +extern char *unctrl(chtype); + +#endif /* _UNCTRL_H */ diff --git a/lib/libcurses/EXAMPLES/ex1.c b/lib/libocurses/EXAMPLES/ex1.c index 76da41b4d9b..76da41b4d9b 100644 --- a/lib/libcurses/EXAMPLES/ex1.c +++ b/lib/libocurses/EXAMPLES/ex1.c diff --git a/lib/libocurses/Makefile b/lib/libocurses/Makefile new file mode 100644 index 00000000000..46ac540346b --- /dev/null +++ b/lib/libocurses/Makefile @@ -0,0 +1,24 @@ +# @(#)Makefile 8.2 (Berkeley) 1/2/94 + +CFLAGS+=#-DTFILE=\"/dev/ttyp0\" +CFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR} +LIB= ocurses +SRCS= addbytes.c addch.c addnstr.c box.c clear.c clrtobot.c clrtoeol.c \ + cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c delwin.c \ + erase.c fullname.c getch.c getstr.c id_subwins.c idlok.c initscr.c \ + insch.c insertln.c longname.c move.c mvwin.c newwin.c overlay.c \ + overwrite.c printw.c putchar.c refresh.c scanw.c scroll.c setterm.c \ + standout.c toucholap.c touchwin.c tscroll.c tstp.c tty.c unctrl.c +MAN= ocurses.3 + +includes: + -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/ocurses.h > \ + /dev/null 2>&1 || \ + install -c -o ${BINOWN} -g ${BINGRP} -m 444 curses.h \ + ${DESTDIR}/usr/include/ocurses.h + +.if make(install) +SUBDIR+= PSD.doc +.endif + +.include <bsd.lib.mk> diff --git a/lib/libcurses/PSD.doc/Makefile b/lib/libocurses/PSD.doc/Makefile index 2ab371e08c0..2ab371e08c0 100644 --- a/lib/libcurses/PSD.doc/Makefile +++ b/lib/libocurses/PSD.doc/Makefile diff --git a/lib/libcurses/PSD.doc/Master b/lib/libocurses/PSD.doc/Master index 12db62b9bfa..12db62b9bfa 100644 --- a/lib/libcurses/PSD.doc/Master +++ b/lib/libocurses/PSD.doc/Master diff --git a/lib/libcurses/PSD.doc/appen.A b/lib/libocurses/PSD.doc/appen.A index a40c95d7891..a40c95d7891 100644 --- a/lib/libcurses/PSD.doc/appen.A +++ b/lib/libocurses/PSD.doc/appen.A diff --git a/lib/libcurses/PSD.doc/appen.B b/lib/libocurses/PSD.doc/appen.B index 0f89fa551bb..0f89fa551bb 100644 --- a/lib/libcurses/PSD.doc/appen.B +++ b/lib/libocurses/PSD.doc/appen.B diff --git a/lib/libcurses/PSD.doc/appen.C b/lib/libocurses/PSD.doc/appen.C index 65bef2bcb98..65bef2bcb98 100644 --- a/lib/libcurses/PSD.doc/appen.C +++ b/lib/libocurses/PSD.doc/appen.C diff --git a/lib/libcurses/PSD.doc/c_macros b/lib/libocurses/PSD.doc/c_macros index ba6ebbc1922..ba6ebbc1922 100644 --- a/lib/libcurses/PSD.doc/c_macros +++ b/lib/libocurses/PSD.doc/c_macros diff --git a/lib/libcurses/PSD.doc/doc.I b/lib/libocurses/PSD.doc/doc.I index 2345aba9b1c..2345aba9b1c 100644 --- a/lib/libcurses/PSD.doc/doc.I +++ b/lib/libocurses/PSD.doc/doc.I diff --git a/lib/libcurses/PSD.doc/doc.II b/lib/libocurses/PSD.doc/doc.II index 1f6880247bc..1f6880247bc 100644 --- a/lib/libcurses/PSD.doc/doc.II +++ b/lib/libocurses/PSD.doc/doc.II diff --git a/lib/libcurses/PSD.doc/doc.III b/lib/libocurses/PSD.doc/doc.III index 7d710d49dbc..7d710d49dbc 100644 --- a/lib/libcurses/PSD.doc/doc.III +++ b/lib/libocurses/PSD.doc/doc.III diff --git a/lib/libcurses/PSD.doc/doc.IV b/lib/libocurses/PSD.doc/doc.IV index 717a9863abb..717a9863abb 100644 --- a/lib/libcurses/PSD.doc/doc.IV +++ b/lib/libocurses/PSD.doc/doc.IV diff --git a/lib/libcurses/PSD.doc/ex1.c b/lib/libocurses/PSD.doc/ex1.c index 02ed9b936bd..02ed9b936bd 100644 --- a/lib/libcurses/PSD.doc/ex1.c +++ b/lib/libocurses/PSD.doc/ex1.c diff --git a/lib/libcurses/PSD.doc/ex2.c b/lib/libocurses/PSD.doc/ex2.c index 13e8f2990b9..13e8f2990b9 100644 --- a/lib/libcurses/PSD.doc/ex2.c +++ b/lib/libocurses/PSD.doc/ex2.c diff --git a/lib/libcurses/PSD.doc/fns.doc b/lib/libocurses/PSD.doc/fns.doc index 0fa89abd3f7..0fa89abd3f7 100644 --- a/lib/libcurses/PSD.doc/fns.doc +++ b/lib/libocurses/PSD.doc/fns.doc diff --git a/lib/libcurses/PSD.doc/intro.0 b/lib/libocurses/PSD.doc/intro.0 index c95b49d4782..c95b49d4782 100644 --- a/lib/libcurses/PSD.doc/intro.0 +++ b/lib/libocurses/PSD.doc/intro.0 diff --git a/lib/libcurses/PSD.doc/intro.1 b/lib/libocurses/PSD.doc/intro.1 index a86d7571ade..a86d7571ade 100644 --- a/lib/libcurses/PSD.doc/intro.1 +++ b/lib/libocurses/PSD.doc/intro.1 diff --git a/lib/libcurses/PSD.doc/intro.2 b/lib/libocurses/PSD.doc/intro.2 index d98c0c76198..d98c0c76198 100644 --- a/lib/libcurses/PSD.doc/intro.2 +++ b/lib/libocurses/PSD.doc/intro.2 diff --git a/lib/libcurses/PSD.doc/intro.3 b/lib/libocurses/PSD.doc/intro.3 index d0ba9a2ab7b..d0ba9a2ab7b 100644 --- a/lib/libcurses/PSD.doc/intro.3 +++ b/lib/libocurses/PSD.doc/intro.3 diff --git a/lib/libcurses/PSD.doc/intro.4 b/lib/libocurses/PSD.doc/intro.4 index 9e529822c5d..9e529822c5d 100644 --- a/lib/libcurses/PSD.doc/intro.4 +++ b/lib/libocurses/PSD.doc/intro.4 diff --git a/lib/libcurses/PSD.doc/intro.5 b/lib/libocurses/PSD.doc/intro.5 index d0f96575b4b..d0f96575b4b 100644 --- a/lib/libcurses/PSD.doc/intro.5 +++ b/lib/libocurses/PSD.doc/intro.5 diff --git a/lib/libcurses/PSD.doc/intro.6 b/lib/libocurses/PSD.doc/intro.6 index 7c4560dc33a..7c4560dc33a 100644 --- a/lib/libcurses/PSD.doc/intro.6 +++ b/lib/libocurses/PSD.doc/intro.6 diff --git a/lib/libcurses/PSD.doc/life.c b/lib/libocurses/PSD.doc/life.c index 72febba29ae..72febba29ae 100644 --- a/lib/libcurses/PSD.doc/life.c +++ b/lib/libocurses/PSD.doc/life.c diff --git a/lib/libcurses/PSD.doc/macros b/lib/libocurses/PSD.doc/macros index b7f3abf793e..b7f3abf793e 100644 --- a/lib/libcurses/PSD.doc/macros +++ b/lib/libocurses/PSD.doc/macros diff --git a/lib/libcurses/PSD.doc/twinkle1.c b/lib/libocurses/PSD.doc/twinkle1.c index 7d3d00db203..7d3d00db203 100644 --- a/lib/libcurses/PSD.doc/twinkle1.c +++ b/lib/libocurses/PSD.doc/twinkle1.c diff --git a/lib/libcurses/PSD.doc/twinkle2.c b/lib/libocurses/PSD.doc/twinkle2.c index 0a25590fcde..0a25590fcde 100644 --- a/lib/libcurses/PSD.doc/twinkle2.c +++ b/lib/libocurses/PSD.doc/twinkle2.c diff --git a/lib/libcurses/PSD.doc/win_st.c b/lib/libocurses/PSD.doc/win_st.c index 7790f6ca632..7790f6ca632 100644 --- a/lib/libcurses/PSD.doc/win_st.c +++ b/lib/libocurses/PSD.doc/win_st.c diff --git a/lib/libcurses/addbytes.c b/lib/libocurses/addbytes.c index 6dd8bf959b5..6dd8bf959b5 100644 --- a/lib/libcurses/addbytes.c +++ b/lib/libocurses/addbytes.c diff --git a/lib/libcurses/addch.c b/lib/libocurses/addch.c index d5f30014c02..d5f30014c02 100644 --- a/lib/libcurses/addch.c +++ b/lib/libocurses/addch.c diff --git a/lib/libcurses/addnstr.c b/lib/libocurses/addnstr.c index 92a6e681a54..92a6e681a54 100644 --- a/lib/libcurses/addnstr.c +++ b/lib/libocurses/addnstr.c diff --git a/lib/libcurses/box.c b/lib/libocurses/box.c index 191e37cfd82..191e37cfd82 100644 --- a/lib/libcurses/box.c +++ b/lib/libocurses/box.c diff --git a/lib/libcurses/clear.c b/lib/libocurses/clear.c index 54c0b30d3cf..54c0b30d3cf 100644 --- a/lib/libcurses/clear.c +++ b/lib/libocurses/clear.c diff --git a/lib/libcurses/clrtobot.c b/lib/libocurses/clrtobot.c index 81ee6a4603a..81ee6a4603a 100644 --- a/lib/libcurses/clrtobot.c +++ b/lib/libocurses/clrtobot.c diff --git a/lib/libcurses/clrtoeol.c b/lib/libocurses/clrtoeol.c index 44fc190fee3..44fc190fee3 100644 --- a/lib/libcurses/clrtoeol.c +++ b/lib/libocurses/clrtoeol.c diff --git a/lib/libcurses/cr_put.c b/lib/libocurses/cr_put.c index ada2df5ca1e..ada2df5ca1e 100644 --- a/lib/libcurses/cr_put.c +++ b/lib/libocurses/cr_put.c diff --git a/lib/libcurses/ctrace.c b/lib/libocurses/ctrace.c index 4f53906cc5e..4f53906cc5e 100644 --- a/lib/libcurses/ctrace.c +++ b/lib/libocurses/ctrace.c diff --git a/lib/libcurses/cur_hash.c b/lib/libocurses/cur_hash.c index ed47fe37333..ed47fe37333 100644 --- a/lib/libcurses/cur_hash.c +++ b/lib/libocurses/cur_hash.c diff --git a/lib/libcurses/curses.c b/lib/libocurses/curses.c index 07cbb5b4afd..07cbb5b4afd 100644 --- a/lib/libcurses/curses.c +++ b/lib/libocurses/curses.c diff --git a/lib/libocurses/curses.h b/lib/libocurses/curses.h new file mode 100644 index 00000000000..cee7f96e013 --- /dev/null +++ b/lib/libocurses/curses.h @@ -0,0 +1,341 @@ +/* + * Copyright (c) 1981, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)curses.h 8.4 (Berkeley) 8/10/94 + */ + +#ifndef _CURSES_H_ +#define _CURSES_H_ + +#include <sys/types.h> +#include <sys/cdefs.h> + +#include <stdio.h> + +/* + * The following #defines and #includes are present for backward + * compatibility only. They should not be used in future code. + * + * START BACKWARD COMPATIBILITY ONLY. + */ +#ifndef _CURSES_PRIVATE +#define bool char +#define reg register + +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef FALSE +#define FALSE (0) +#endif + +#define _puts(s) tputs(s, 0, __cputchar) +#define _putchar(c) __cputchar(c) + +/* Old-style terminal modes access. */ +#define baudrate() (cfgetospeed(&__baset)) +#define crmode() cbreak() +#define erasechar() (__baset.c_cc[VERASE]) +#define killchar() (__baset.c_cc[VKILL]) +#define nocrmode() nocbreak() +#define ospeed (cfgetospeed(&__baset)) +#endif /* _CURSES_PRIVATE */ + +extern char GT; /* Gtty indicates tabs. */ +extern char NONL; /* Term can't hack LF doing a CR. */ +extern char UPPERCASE; /* Terminal is uppercase only. */ + +extern int My_term; /* Use Def_term regardless. */ +extern char *Def_term; /* Default terminal type. */ + +/* Termcap capabilities. */ +extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, + PC, UL, XB, XN, XT, XS, XX; +extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, + *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, + *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, + *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, + *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, + *VE, *al, *dl, *sf, *sr, + *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, + *RIGHT_PARM; + +/* END BACKWARD COMPATIBILITY ONLY. */ + +/* 8-bit ASCII characters. */ +#define unctrl(c) __unctrl[(c) & 0xff] +#define unctrllen(ch) __unctrllen[(ch) & 0xff] + +extern char *__unctrl[256]; /* Control strings. */ +extern char __unctrllen[256]; /* Control strings length. */ + +/* + * A window an array of __LINE structures pointed to by the 'lines' pointer. + * A line is an array of __LDATA structures pointed to by the 'line' pointer. + * + * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new + * fields are added -- padding fields with *constant values* should ensure + * that the compiler will not generate any padding when storing an array of + * __LDATA structures. This is to enable consistent use of memcmp, and memcpy + * for comparing and copying arrays. + */ +typedef struct { + char ch; /* the actual character */ + +#define __STANDOUT 0x01 /* Added characters are standout. */ + char attr; /* attributes of character */ +} __LDATA; + +#define __LDATASIZE (sizeof(__LDATA)) + +typedef struct { +#define __ISDIRTY 0x01 /* Line is dirty. */ +#define __ISPASTEOL 0x02 /* Cursor is past end of line */ +#define __FORCEPAINT 0x04 /* Force a repaint of the line */ + unsigned int flags; + unsigned int hash; /* Hash value for the line. */ + size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ + size_t firstch, lastch; /* First and last changed columns. */ + __LDATA *line; /* Pointer to the line text. */ +} __LINE; + +typedef struct __window { /* Window structure. */ + struct __window *nextp, *orig; /* Subwindows list and parent. */ + size_t begy, begx; /* Window home. */ + size_t cury, curx; /* Current x, y coordinates. */ + size_t maxy, maxx; /* Maximum values for curx, cury. */ + short ch_off; /* x offset for firstch/lastch. */ + __LINE **lines; /* Array of pointers to the lines */ + __LINE *lspace; /* line space (for cleanup) */ + __LDATA *wspace; /* window space (for cleanup) */ + +#define __ENDLINE 0x001 /* End of screen. */ +#define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ +#define __FULLWIN 0x004 /* Window is a screen. */ +#define __IDLINE 0x008 /* Insert/delete sequences. */ +#define __SCROLLWIN 0x010 /* Last char will scroll window. */ +#define __SCROLLOK 0x020 /* Scrolling ok. */ +#define __CLEAROK 0x040 /* Clear on next refresh. */ +#define __WSTANDOUT 0x080 /* Standout window */ +#define __LEAVEOK 0x100 /* If curser left */ + unsigned int flags; +} WINDOW; + +/* Curses external declarations. */ +extern WINDOW *curscr; /* Current screen. */ +extern WINDOW *stdscr; /* Standard screen. */ + +extern struct termios __orig_termios; /* Terminal state before curses */ +extern struct termios __baset; /* Our base terminal state */ +extern int __tcaction; /* If terminal hardware set. */ + +extern int COLS; /* Columns on the screen. */ +extern int LINES; /* Lines on the screen. */ + +extern char *ttytype; /* Full name of current terminal. */ + +#define ERR (0) /* Error return. */ +#define OK (1) /* Success return. */ + +/* Standard screen pseudo functions. */ +#define addbytes(s, n) __waddbytes(stdscr, s, n, 0) +#define addch(ch) waddch(stdscr, ch) +#define addnstr(s, n) waddnstr(stdscr, s, n) +#define addstr(s) __waddbytes(stdscr, s, strlen(s), 0) +#define clear() wclear(stdscr) +#define clrtobot() wclrtobot(stdscr) +#define clrtoeol() wclrtoeol(stdscr) +#define delch() wdelch(stdscr) +#define deleteln() wdeleteln(stdscr) +#define erase() werase(stdscr) +#define getch() wgetch(stdscr) +#define getstr(s) wgetstr(stdscr, s) +#define inch() winch(stdscr) +#define insch(ch) winsch(stdscr, ch) +#define insertln() winsertln(stdscr) +#define move(y, x) wmove(stdscr, y, x) +#define refresh() wrefresh(stdscr) +#define standend() wstandend(stdscr) +#define standout() wstandout(stdscr) +#define waddbytes(w, s, n) __waddbytes(w, s, n, 0) +#define waddstr(w, s) __waddbytes(w, s, strlen(s), 0) + +/* Standard screen plus movement pseudo functions. */ +#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) +#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) +#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) +#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) +#define mvdelch(y, x) mvwdelch(stdscr, y, x) +#define mvgetch(y, x) mvwgetch(stdscr, y, x) +#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) +#define mvinch(y, x) mvwinch(stdscr, y, x) +#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) +#define mvwaddbytes(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) +#define mvwaddch(w, y, x, ch) \ + (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) +#define mvwaddnstr(w, y, x, s, n) \ + (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) +#define mvwaddstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0)) +#define mvwdelch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wdelch(w)) +#define mvwgetch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : wgetch(w)) +#define mvwgetstr(w, y, x, s) \ + (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) +#define mvwinch(w, y, x) \ + (wmove(w, y, x) == ERR ? ERR : winch(w)) +#define mvwinsch(w, y, x, c) \ + (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) + +/* Psuedo functions. */ +#define clearok(w, bf) \ + ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK)) +#define flushok(w, bf) \ + ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH)) +#define getyx(w, y, x) \ + (y) = (w)->cury, (x) = (w)->curx +#define leaveok(w, bf) \ + ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK)) +#define scrollok(w, bf) \ + ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK)) +#define winch(w) \ + ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177) + +/* Public function prototypes. */ +__BEGIN_DECLS +int box __P((WINDOW *, int, int)); +int cbreak __P((void)); +int delwin __P((WINDOW *)); +int echo __P((void)); +int endwin __P((void)); +char *fullname __P((char *, char *)); +char *getcap __P((char *)); +int gettmode __P((void)); +void idlok __P((WINDOW *, int)); +WINDOW *initscr __P((void)); +char *longname __P((char *, char *)); +int mvcur __P((int, int, int, int)); +int mvprintw __P((int, int, const char *, ...)); +int mvscanw __P((int, int, const char *, ...)); +int mvwin __P((WINDOW *, int, int)); +int mvwprintw __P((WINDOW *, int, int, const char *, ...)); +int mvwscanw __P((WINDOW *, int, int, const char *, ...)); +WINDOW *newwin __P((int, int, int, int)); +int nl __P((void)); +int nocbreak __P((void)); +int noecho __P((void)); +int nonl __P((void)); +int noraw __P((void)); +int overlay __P((WINDOW *, WINDOW *)); +int overwrite __P((WINDOW *, WINDOW *)); +int printw __P((const char *, ...)); +int raw __P((void)); +int resetty __P((void)); +int savetty __P((void)); +int scanw __P((const char *, ...)); +int scroll __P((WINDOW *)); +int setterm __P((char *)); +int sscans __P((WINDOW *, const char *, ...)); +WINDOW *subwin __P((WINDOW *, int, int, int, int)); +int suspendwin __P((void)); +int touchline __P((WINDOW *, int, int, int)); +int touchoverlap __P((WINDOW *, WINDOW *)); +int touchwin __P((WINDOW *)); +int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); +int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); +int waddch __P((WINDOW *, int)); +int waddnstr __P((WINDOW *, const char *, int)); +int wclear __P((WINDOW *)); +int wclrtobot __P((WINDOW *)); +int wclrtoeol __P((WINDOW *)); +int wdelch __P((WINDOW *)); +int wdeleteln __P((WINDOW *)); +int werase __P((WINDOW *)); +int wgetch __P((WINDOW *)); +int wgetstr __P((WINDOW *, char *)); +int winsch __P((WINDOW *, int)); +int winsertln __P((WINDOW *)); +int wmove __P((WINDOW *, int, int)); +int wprintw __P((WINDOW *, const char *, ...)); +int wrefresh __P((WINDOW *)); +int wscanw __P((WINDOW *, const char *, ...)); +int wstandend __P((WINDOW *)); +int wstandout __P((WINDOW *)); +int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); + +/* Private functions that are needed for user programs prototypes. */ +void __cputchar __P((int)); +int __waddbytes __P((WINDOW *, const char *, int, int)); +__END_DECLS + +/* Private functions. */ +#ifdef _CURSES_PRIVATE +void __CTRACE __P((const char *, ...)); +unsigned int __hash __P((char *, int)); +void __id_subwins __P((WINDOW *)); +int __mvcur __P((int, int, int, int, int)); +void __restore_stophandler __P((void)); +void __set_stophandler __P((void)); +void __set_subwin __P((WINDOW *, WINDOW *)); +void __startwin __P((void)); +void __stop_signal_handler __P((int)); +void __swflags __P((WINDOW *)); +int __touchline __P((WINDOW *, int, int, int, int)); +int __touchwin __P((WINDOW *)); +char *__tscroll __P((const char *, int, int)); +int __waddch __P((WINDOW *, __LDATA *)); + +/* Private #defines. */ +#define min(a,b) (a < b ? a : b) +#define max(a,b) (a > b ? a : b) + +/* Private externs. */ +extern int __echoit; +extern int __endwin; +extern int __pfast; +extern int __rawmode; +extern int __noqch; +#endif + +/* Termcap functions. */ +__BEGIN_DECLS +int tgetent __P((char *, char *)); +int tgetnum __P((char *)); +int tgetflag __P((char *)); +char *tgetstr __P((char *, char **)); +char *tgoto __P((char *, int, int)); +void tputs __P((char *, int, void (*)(int))); +__END_DECLS + +#endif /* !_CURSES_H_ */ diff --git a/lib/libcurses/delch.c b/lib/libocurses/delch.c index b9cdc3140ed..b9cdc3140ed 100644 --- a/lib/libcurses/delch.c +++ b/lib/libocurses/delch.c diff --git a/lib/libcurses/deleteln.c b/lib/libocurses/deleteln.c index 4cb08ea3794..4cb08ea3794 100644 --- a/lib/libcurses/deleteln.c +++ b/lib/libocurses/deleteln.c diff --git a/lib/libcurses/delwin.c b/lib/libocurses/delwin.c index 7310db8588c..7310db8588c 100644 --- a/lib/libcurses/delwin.c +++ b/lib/libocurses/delwin.c diff --git a/lib/libcurses/erase.c b/lib/libocurses/erase.c index 42ca68a35a6..42ca68a35a6 100644 --- a/lib/libcurses/erase.c +++ b/lib/libocurses/erase.c diff --git a/lib/libcurses/fullname.c b/lib/libocurses/fullname.c index 3d05e5d6ef8..3d05e5d6ef8 100644 --- a/lib/libcurses/fullname.c +++ b/lib/libocurses/fullname.c diff --git a/lib/libcurses/getch.c b/lib/libocurses/getch.c index 6108229708d..6108229708d 100644 --- a/lib/libcurses/getch.c +++ b/lib/libocurses/getch.c diff --git a/lib/libcurses/getstr.c b/lib/libocurses/getstr.c index daf8e61b7fd..daf8e61b7fd 100644 --- a/lib/libcurses/getstr.c +++ b/lib/libocurses/getstr.c diff --git a/lib/libcurses/id_subwins.c b/lib/libocurses/id_subwins.c index 3528348ff46..3528348ff46 100644 --- a/lib/libcurses/id_subwins.c +++ b/lib/libocurses/id_subwins.c diff --git a/lib/libcurses/idlok.c b/lib/libocurses/idlok.c index 4d3bb592697..4d3bb592697 100644 --- a/lib/libcurses/idlok.c +++ b/lib/libocurses/idlok.c diff --git a/lib/libcurses/initscr.c b/lib/libocurses/initscr.c index 1af8b6f34ea..1af8b6f34ea 100644 --- a/lib/libcurses/initscr.c +++ b/lib/libocurses/initscr.c diff --git a/lib/libcurses/insch.c b/lib/libocurses/insch.c index 36cc0dee894..36cc0dee894 100644 --- a/lib/libcurses/insch.c +++ b/lib/libocurses/insch.c diff --git a/lib/libcurses/insertln.c b/lib/libocurses/insertln.c index c2179f0f187..c2179f0f187 100644 --- a/lib/libcurses/insertln.c +++ b/lib/libocurses/insertln.c diff --git a/lib/libcurses/longname.c b/lib/libocurses/longname.c index fd54630f161..fd54630f161 100644 --- a/lib/libcurses/longname.c +++ b/lib/libocurses/longname.c diff --git a/lib/libcurses/move.c b/lib/libocurses/move.c index 1e22fb0648d..1e22fb0648d 100644 --- a/lib/libcurses/move.c +++ b/lib/libocurses/move.c diff --git a/lib/libcurses/mvwin.c b/lib/libocurses/mvwin.c index 1471b27e186..1471b27e186 100644 --- a/lib/libcurses/mvwin.c +++ b/lib/libocurses/mvwin.c diff --git a/lib/libcurses/newwin.c b/lib/libocurses/newwin.c index 8f09cbf7966..8f09cbf7966 100644 --- a/lib/libcurses/newwin.c +++ b/lib/libocurses/newwin.c diff --git a/lib/libocurses/ocurses.3 b/lib/libocurses/ocurses.3 new file mode 100644 index 00000000000..ea0093b61ad --- /dev/null +++ b/lib/libocurses/ocurses.3 @@ -0,0 +1,197 @@ +.\" Copyright (c) 1985, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)curses.3 8.1 (Berkeley) 6/4/93 +.\" +.Dd June 4, 1993 +.Dt CURSES 3 +.Os BSD 4 +.Sh NAME +.Nm curses +.Nd screen functions with ``optimal'' cursor motion +.Sh SYNOPSIS +.Nm cc +.Op Ar flags +.Ar files +.Fl lcurses ltermcap +.Op Ar libraries +.Sh DESCRIPTION +These routines give the user a method of updating screens with reasonable +optimization. They keep an image of the current screen, +and the user sets up an image of a new one. Then the +.Fn refresh +tells the routines to make the current screen look like the new one. +In order to initialize the routines, the routine +.Fn initscr +must be called before any of the other routines that deal with windows and +screens are used. The routine +.Fn endwin +should be called before exiting. +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr getenv 3 , +.Xr tty 4 , +.Xr termcap 5 +.Rs +.%T Screen Updating and Cursor Movement Optimization: A Library Package +.%A Ken Arnold +.Re +.Sh AUTHOR +.An Ken Arnold +.Sh FUNCTIONS +.Bl -column "subwin(win,lines,cols,begin_y,begin_x) " +.It addch(ch) add a character to +.Em stdscr +.It addstr(str) add a string to +.Em stdscr +.It box(win,vert,hor) draw a box around a window +.It cbreak() set cbreak mode +.It clear() clear +.Em stdscr +.It clearok(scr,boolf) set clear flag for +.Em scr +.It clrtobot() clear to bottom on +.Em stdscr +.It clrtoeol() clear to end of line on +.Em stdscr +.It delch() delete a character +.It deleteln() delete a line +.It delwin(win) delete +.Em stdscr +.It echo() set echo mode +.It endwin() end window modes +.It erase() erase +.Em stdscr +.It flusok(win,boolf) set flush-on-refresh flag for +.Em win +.It getch() get a char through +.Em stdscr +.It getcap(name) get terminal capability +.Em name +.It getstr(str) get a string through +.Em stdscr +.It gettmode() get tty modes +.It getyx(win,y,x) get (y,x) co-ordinates +.It inch() get char at current (y,x) co-ordinates +.It initscr() initialize screens +.It insch(c) insert a char +.It insertln() insert a line +.It leaveok(win,boolf) set leave flag for +.Em stdscr +.It longname(termbuf,name) get long name from +.Em termbuf +.It move(y,x) move to (y,x) on +.Em stdscr +.It mvcur(lasty,lastx,newy,newx) actually move cursor +.It newwin(lines,cols,begin_y,begin_x)\ create a new window +.It nl() set newline mapping +.It nocbreak() unset cbreak mode +.It noecho() unset echo mode +.It nonl() unset newline mapping +.It noraw() unset raw mode +.It overlay(win1,win2) overlay win1 on win2 +.It overwrite(win1,win2) overwrite win1 on top of win2 +.It printw(fmt,arg1,arg2,...) printf on +.Em stdscr +.It raw() set raw mode +.It refresh() make current screen look like +.Em stdscr +.It resetty() reset tty flags to stored value +.It savetty() stored current tty flags +.It scanw(fmt,arg1,arg2,...) scanf through +.Em stdscr +.It scroll(win) scroll +.Em win +one line +.It scrollok(win,boolf) set scroll flag +.It setterm(name) set term variables for name +.It standend() end standout mode +.It standout() start standout mode +.It subwin(win,lines,cols,begin_y,begin_x)\ create a subwindow +.It touchline(win,y,sx,ex) mark line +.Em y +.Em sx +through +.Em sy +as changed +.It touchoverlap(win1,win2) mark overlap of +.Em win1 +on +.Em win2 +as changed +.It touchwin(win) \*(lqchange\*(rq all of +.Em win +.It unctrl(ch) printable version of +.Em ch +.It waddch(win,ch) add char to +.Em win +.It waddstr(win,str) add string to +.Em win +.It wclear(win) clear +.Em win +.It wclrtobot(win) clear to bottom of +.Em win +.It wclrtoeol(win) clear to end of line on +.Em win +.It wdelch(win) delete char from +.Em win +.It wdeleteln(win) delete line from +.Em win +.It werase(win) erase +.Em win +.It wgetch(win) get a char through +.Em win +.It wgetstr(win,str) get a string through +.Em win +.It winch(win) get char at current (y,x) in +.Em win +.It winsch(win,c) insert char into +.Em win +.It winsertln(win) insert line into +.Em win +.It wmove(win,y,x) set current (y,x) co-ordinates on +.Em win +.It wprintw(win,fmt,arg1,arg2,...)\ printf on +.Em win +.It wrefresh(win) make screen look like +.Em win +.It wscanw(win,fmt,arg1,arg2,...)\ scanf through +.Em win +.It wstandend(win) end standout mode on +.Em win +.It wstandout(win) start standout mode on +.Em win +.El +.Sh HISTORY +The +.Nm +package appeared in +.Bx 4.0 . diff --git a/lib/libcurses/overlay.c b/lib/libocurses/overlay.c index 9f35c79e3fb..9f35c79e3fb 100644 --- a/lib/libcurses/overlay.c +++ b/lib/libocurses/overlay.c diff --git a/lib/libcurses/overwrite.c b/lib/libocurses/overwrite.c index e2d91bd0a8c..e2d91bd0a8c 100644 --- a/lib/libcurses/overwrite.c +++ b/lib/libocurses/overwrite.c diff --git a/lib/libcurses/printw.c b/lib/libocurses/printw.c index ae6ea49dabf..ae6ea49dabf 100644 --- a/lib/libcurses/printw.c +++ b/lib/libocurses/printw.c diff --git a/lib/libcurses/putchar.c b/lib/libocurses/putchar.c index 2ed5bb4755c..2ed5bb4755c 100644 --- a/lib/libcurses/putchar.c +++ b/lib/libocurses/putchar.c diff --git a/lib/libcurses/refresh.c b/lib/libocurses/refresh.c index 3271bd9101e..3271bd9101e 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libocurses/refresh.c diff --git a/lib/libcurses/scanw.c b/lib/libocurses/scanw.c index d8d79fd2355..d8d79fd2355 100644 --- a/lib/libcurses/scanw.c +++ b/lib/libocurses/scanw.c diff --git a/lib/libcurses/scroll.c b/lib/libocurses/scroll.c index 8aad91c0285..8aad91c0285 100644 --- a/lib/libcurses/scroll.c +++ b/lib/libocurses/scroll.c diff --git a/lib/libcurses/setterm.c b/lib/libocurses/setterm.c index 1d134903c11..1d134903c11 100644 --- a/lib/libcurses/setterm.c +++ b/lib/libocurses/setterm.c diff --git a/lib/libcurses/shlib_version b/lib/libocurses/shlib_version index c6e3f4d3fc0..c6e3f4d3fc0 100644 --- a/lib/libcurses/shlib_version +++ b/lib/libocurses/shlib_version diff --git a/lib/libcurses/standout.c b/lib/libocurses/standout.c index 8851d63d446..8851d63d446 100644 --- a/lib/libcurses/standout.c +++ b/lib/libocurses/standout.c diff --git a/lib/libcurses/toucholap.c b/lib/libocurses/toucholap.c index 955c204147f..955c204147f 100644 --- a/lib/libcurses/toucholap.c +++ b/lib/libocurses/toucholap.c diff --git a/lib/libcurses/touchwin.c b/lib/libocurses/touchwin.c index 36f487e5b8f..36f487e5b8f 100644 --- a/lib/libcurses/touchwin.c +++ b/lib/libocurses/touchwin.c diff --git a/lib/libcurses/tscroll.c b/lib/libocurses/tscroll.c index 359b3969c63..359b3969c63 100644 --- a/lib/libcurses/tscroll.c +++ b/lib/libocurses/tscroll.c diff --git a/lib/libcurses/tstp.c b/lib/libocurses/tstp.c index 07debf42fe1..07debf42fe1 100644 --- a/lib/libcurses/tstp.c +++ b/lib/libocurses/tstp.c diff --git a/lib/libcurses/tty.c b/lib/libocurses/tty.c index d04586d853f..d04586d853f 100644 --- a/lib/libcurses/tty.c +++ b/lib/libocurses/tty.c diff --git a/lib/libcurses/unctrl.c b/lib/libocurses/unctrl.c index ff52230b2e9..ff52230b2e9 100644 --- a/lib/libcurses/unctrl.c +++ b/lib/libocurses/unctrl.c |