summaryrefslogtreecommitdiff
path: root/lib/libcurses
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libcurses')
-rw-r--r--lib/libcurses/EXAMPLES/ex1.c112
-rw-r--r--lib/libcurses/Makefile24
-rw-r--r--lib/libcurses/PSD.doc/Makefile39
-rw-r--r--lib/libcurses/PSD.doc/Master54
-rw-r--r--lib/libcurses/PSD.doc/appen.A77
-rw-r--r--lib/libcurses/PSD.doc/appen.B201
-rw-r--r--lib/libcurses/PSD.doc/appen.C127
-rw-r--r--lib/libcurses/PSD.doc/c_macros70
-rw-r--r--lib/libcurses/PSD.doc/doc.I349
-rw-r--r--lib/libcurses/PSD.doc/doc.II142
-rw-r--r--lib/libcurses/PSD.doc/doc.III343
-rw-r--r--lib/libcurses/PSD.doc/doc.IV110
-rw-r--r--lib/libcurses/PSD.doc/ex1.c102
-rw-r--r--lib/libcurses/PSD.doc/ex2.c210
-rw-r--r--lib/libcurses/PSD.doc/fns.doc799
-rw-r--r--lib/libcurses/PSD.doc/intro.0106
-rw-r--r--lib/libcurses/PSD.doc/intro.1249
-rw-r--r--lib/libcurses/PSD.doc/intro.277
-rw-r--r--lib/libcurses/PSD.doc/intro.3228
-rw-r--r--lib/libcurses/PSD.doc/intro.469
-rw-r--r--lib/libcurses/PSD.doc/intro.587
-rw-r--r--lib/libcurses/PSD.doc/intro.644
-rw-r--r--lib/libcurses/PSD.doc/life.c163
-rw-r--r--lib/libcurses/PSD.doc/macros144
-rw-r--r--lib/libcurses/PSD.doc/twinkle1.c157
-rw-r--r--lib/libcurses/PSD.doc/twinkle2.c96
-rw-r--r--lib/libcurses/PSD.doc/win_st.c58
-rw-r--r--lib/libcurses/addbytes.c157
-rw-r--r--lib/libcurses/addch.c66
-rw-r--r--lib/libcurses/addnstr.c62
-rw-r--r--lib/libcurses/box.c78
-rw-r--r--lib/libcurses/clear.c53
-rw-r--r--lib/libcurses/clrtobot.c75
-rw-r--r--lib/libcurses/clrtoeol.c83
-rw-r--r--lib/libcurses/cr_put.c432
-rw-r--r--lib/libcurses/ctrace.c76
-rw-r--r--lib/libcurses/cur_hash.c62
-rw-r--r--lib/libcurses/curses.3197
-rw-r--r--lib/libcurses/curses.c74
-rw-r--r--lib/libcurses/curses.h341
-rw-r--r--lib/libcurses/delch.c63
-rw-r--r--lib/libcurses/deleteln.c82
-rw-r--r--lib/libcurses/delwin.c80
-rw-r--r--lib/libcurses/erase.c72
-rw-r--r--lib/libcurses/fullname.c60
-rw-r--r--lib/libcurses/getch.c75
-rw-r--r--lib/libcurses/getstr.c57
-rw-r--r--lib/libcurses/id_subwins.c65
-rw-r--r--lib/libcurses/idlok.c54
-rw-r--r--lib/libcurses/initscr.c95
-rw-r--r--lib/libcurses/insch.c74
-rw-r--r--lib/libcurses/insertln.c82
-rw-r--r--lib/libcurses/longname.c56
-rw-r--r--lib/libcurses/move.c62
-rw-r--r--lib/libcurses/mvwin.c77
-rw-r--r--lib/libcurses/newwin.c244
-rw-r--r--lib/libcurses/overlay.c82
-rw-r--r--lib/libcurses/overwrite.c76
-rw-r--r--lib/libcurses/printw.c200
-rw-r--r--lib/libcurses/putchar.c49
-rw-r--r--lib/libcurses/refresh.c827
-rw-r--r--lib/libcurses/scanw.c175
-rw-r--r--lib/libcurses/scroll.c71
-rw-r--r--lib/libcurses/setterm.c232
-rw-r--r--lib/libcurses/shlib_version2
-rw-r--r--lib/libcurses/standout.c67
-rw-r--r--lib/libcurses/toucholap.c77
-rw-r--r--lib/libcurses/touchwin.c120
-rw-r--r--lib/libcurses/tscroll.c139
-rw-r--r--lib/libcurses/tstp.c124
-rw-r--r--lib/libcurses/tty.c281
-rw-r--r--lib/libcurses/unctrl.c107
72 files changed, 9920 insertions, 0 deletions
diff --git a/lib/libcurses/EXAMPLES/ex1.c b/lib/libcurses/EXAMPLES/ex1.c
new file mode 100644
index 00000000000..76da41b4d9b
--- /dev/null
+++ b/lib/libcurses/EXAMPLES/ex1.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 1992, 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.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1992, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)ex1.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+#include <sys/types.h>
+#include <curses.h>
+#include <stdio.h>
+#include <signal.h>
+
+
+#define YSIZE 10
+#define XSIZE 20
+
+int quit();
+
+main()
+{
+ int i, j, c;
+ size_t len;
+ char id[100];
+ FILE *fp;
+ char *s;
+
+ initscr(); /* Always call initscr() first */
+ signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */
+ crmode(); /* We want cbreak mode */
+ noecho(); /* We want to have control of chars */
+ delwin(stdscr); /* Create our own stdscr */
+ stdscr = newwin(YSIZE, XSIZE, 10, 35);
+ flushok(stdscr, TRUE); /* Enable flushing of stdout */
+ scrollok(stdscr, TRUE); /* Enable scrolling */
+ erase(); /* Initially, clear the screen */
+
+ standout();
+ move(0,0);
+ while (1) {
+ c = getchar();
+ switch(c) {
+ case 'q': /* Quit on 'q' */
+ quit();
+ break;
+ case 's': /* Go into standout mode on 's' */
+ standout();
+ break;
+ case 'e': /* Exit standout mode on 'e' */
+ standend();
+ break;
+ case 'r': /* Force a refresh on 'r' */
+ wrefresh(curscr);
+ break;
+ default: /* By default output the character */
+ addch(c);
+ refresh();
+ }
+ }
+}
+
+
+int
+quit()
+{
+ erase(); /* Terminate by erasing the screen */
+ refresh();
+ endwin(); /* Always end with endwin() */
+ delwin(curscr); /* Return storage */
+ delwin(stdscr);
+ putchar('\n');
+ exit(0);
+}
+
+
+
+
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile
new file mode 100644
index 00000000000..905eec2aa2c
--- /dev/null
+++ b/lib/libcurses/Makefile
@@ -0,0 +1,24 @@
+# @(#)Makefile 8.2 (Berkeley) 1/2/94
+
+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
+
+beforeinstall:
+ -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
+
+.if make(install)
+SUBDIR+= PSD.doc
+.endif
+
+.include <bsd.lib.mk>
diff --git a/lib/libcurses/PSD.doc/Makefile b/lib/libcurses/PSD.doc/Makefile
new file mode 100644
index 00000000000..2ab371e08c0
--- /dev/null
+++ b/lib/libcurses/PSD.doc/Makefile
@@ -0,0 +1,39 @@
+# @(#)Makefile 8.2 (Berkeley) 5/23/94
+
+DIR= psd/19.curses
+SRCS= Master
+MACROS= -me
+EXTRA= appen.A appen.B appen.C c_macros doc.I doc.II doc.III \
+ doc.IV ex1.c ex2.c fns.doc intro.0 intro.1 intro.2 intro.3 \
+ intro.4 intro.5 intro.6 life.c macros twinkle1.c twinkle2.c \
+ win_st.c
+
+CLEANFILES+=win_st.gr twinkle1.gr twinkle2.gr life.gr intro.2.tbl appen.A.tbl \
+ ex1.gr ex2.gr
+
+.SUFFIXES:
+.SUFFIXES: .c .gr
+
+#
+# this section formats C input source into nice troffable (or nroffable)
+# versions. It uses the capabilites of "vgrind", which sets keywords in
+# bold font, and comments in italics.
+#
+
+# Don't re-run vgrind unless you want to patch the output files.
+VFONT= /usr/libexec/vfontedpr
+.c.gr:
+ ${VFONT} $*.c | grep -v "^'wh" > $*.gr
+
+paper.ps: ${SRCS}
+ soelim ${SRCS} | ${ROFF} > ${.TARGET}
+
+Master: twinkle1.gr ex1.gr ex2.gr fns.doc intro.5 intro.2.tbl intro.0 intro.1 \
+ intro.3 intro.4 intro.6 macros c_macros
+
+intro.2.tbl: intro.2
+ ${TBL} intro.2 > intro.2.tbl
+
+.include <bsd.doc.mk>
+
+
diff --git a/lib/libcurses/PSD.doc/Master b/lib/libcurses/PSD.doc/Master
new file mode 100644
index 00000000000..12db62b9bfa
--- /dev/null
+++ b/lib/libcurses/PSD.doc/Master
@@ -0,0 +1,54 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)Master 8.2 (Berkeley) 5/24/94
+.\"
+.ds Ln Screen Package
+.so macros
+.so c_macros
+.so intro.0
+.pn 3
+.bp
+.so intro.1
+.so intro.2.tbl
+.so intro.3
+.so intro.4
+.so intro.5
+.so intro.6
+.bp
+.so appen.A
+.pn 2
+.oh '\*(Ln''PSD:19-%'
+.eh 'PSD:19-%''\*(Ln'
+.bp
+.bi Contents
+.sp
+.xp
diff --git a/lib/libcurses/PSD.doc/appen.A b/lib/libcurses/PSD.doc/appen.A
new file mode 100644
index 00000000000..a40c95d7891
--- /dev/null
+++ b/lib/libcurses/PSD.doc/appen.A
@@ -0,0 +1,77 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)appen.A 8.1 (Berkeley) 6/8/93
+.\"
+.ie t .oh '\*(Ln Appendix A''PS1:19-%'
+.eh 'PS1:19-%''\*(Ln Appendix A'
+.el .he ''\fIAppendix A\fR''
+.bp
+.(x
+.ti 0
+.b "Appendix A"
+.)x
+.sh 1 "Examples" 1
+.pp
+Here we present a few examples
+of how to use the package.
+They attempt to be representative,
+though not comprehensive. Further examples can be found in the games section
+of the source tree and in various utilities that use the screen such as
+.i systat(1) .
+.pp
+The following examples are intended to demonstrate
+the basic structure of a program
+using the package. An additional, more comprehensive, program can be found in
+the source code in the
+\fIexamples\fP subdirectory.
+.sh 2 "Simple Character Output"
+.pp
+This program demonstrates how to set up a window and output characters to it.
+Also, it demonstrates how one might control the output to the window. If
+you run this program, you will get a demonstration of the character output
+chracteristics discussed in the above Character Output section.
+.(l I
+.so ex1.gr
+.)l
+.sh 2 "Twinkle"
+.pp
+This is a moderately simple program which prints
+patterns on the screen.
+It switches between patterns of asterisks,
+putting them on one by one in random order,
+and then taking them off in the same fashion.
+It is more efficient to write this
+using only the motion optimization,
+as is demonstrated below.
+.(l I
+.so twinkle1.gr
+.)l
diff --git a/lib/libcurses/PSD.doc/appen.B b/lib/libcurses/PSD.doc/appen.B
new file mode 100644
index 00000000000..0f89fa551bb
--- /dev/null
+++ b/lib/libcurses/PSD.doc/appen.B
@@ -0,0 +1,201 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)appen.B 8.1 (Berkeley) 6/8/93
+.\"
+.ie t .oh '\*(Ln Appendix B''PS1:19-%'
+.eh 'PS1:19-%''\*(Ln Appendix B'
+.el .he ''\fIAppendix B\fR''
+.bp
+.(x
+.ti 0
+.b "Appendix B"
+.)x
+.nr $1 0
+.sh 1 "The WINDOW structure"
+.pp
+The WINDOW structure is defined as follows:
+.(l I
+.so win_st.gr
+.)l
+.pp
+.Vn \*_cury \\*
+.(f
+\**
+All variables not normally accessed directly by the user
+are named with an initial
+.Bq \*_
+to avoid conflicts with the user's variables.
+.)f
+and
+.Vn \*_curx
+are the current \*y for the window.
+New characters added to the screen
+are added at this point.
+.Vn \*_maxy
+and
+.Vn \*_maxx
+are the maximum values allowed for
+.Vn \*_cury\*,\*_curx ). (
+.Vn \*_begy
+and
+.Vn \*_begx
+are the starting \*y on the terminal for the window,
+.i i.e. ,
+the window's home.
+.Vn \*_cury ,
+.Vn \*_curx ,
+.Vn \*_maxy ,
+and
+.Vn \*_maxx
+are measured relative to
+.Vn \*_begy\*,\*_begx ), (
+not the terminal's home.
+.pp
+.Vn \*_clear
+tells if a clear-screen sequence is to be generated
+on the next
+.Fn refresh
+call.
+This is only meaningful for screens.
+The initial clear-screen for the first
+.Fn refresh
+call is generated by initially setting clear to be TRUE for
+.Vn curscr ,
+which always generates a clear-screen if set,
+irrelevant of the dimensions of the window involved.
+.Vn \*_leave
+is TRUE if the current \*y and the cursor
+are to be left after the last character changed on the terminal,
+or not moved if there is no change.
+.Vn \*_scroll
+is TRUE
+if scrolling is allowed.
+.pp
+.Vn \*_y
+is a pointer to an array of lines which describe the terminal.
+Thus:
+.(l
+\*_y[i]
+.)l
+.lp
+is a pointer to the
+.Vn i th
+line, and
+.(l
+\*_y[i][j]
+.)l
+.lp
+is the
+.Vn j th
+character on the
+.Vn i th
+line.
+.Vn \*_flags
+can have one or more values
+or'd into it.
+.pp
+For windows that are not subwindows,
+.Vn \*_orig
+is
+NULL .
+For subwindows,
+it points to the main window
+to which the window is subsidiary.
+.Vn \*_nextp
+is a pointer in a circularly linked list
+of all the windows which are subwindows of the same main window,
+plus the main window itself.
+.pp
+.Vn \*_firstch
+and
+.Vn \*_lastch
+are
+.Fn malloc ed
+arrays which contain the index of the
+first and last changed characters
+on the line.
+.Vn \*_ch\*_off
+is the x offset for the window
+in the
+.Vn \*_firstch
+and
+.Vn \*_lastch
+arrays for this window.
+For main windows,
+this is always 0;
+for subwindows
+it is the difference between the starting point of the main window
+and that of the subindow,
+so that change markers can be set relative to the main window.
+This makes these markers global in scope.
+.pp
+All subwindows share the appropriate portions of
+.Vn _y ,
+.Vn _firstch ,
+.Vn _lastch ,
+and
+.Vn _insdel
+with their main window.
+.pp
+.b \*_ENDLINE
+says that the end of the line for this window
+is also the end of a screen.
+.b \*_FULLWIN
+says that this window is a screen.
+.b \*_SCROLLWIN
+indicates that the last character of this screen
+is at the lower right-hand corner of the terminal;
+.i i.e. ,
+if a character was put there,
+the terminal would scroll.
+.b \*_FULLLINE
+says that the width of a line is the same as the width of the terminal.
+If
+.b \*_FLUSH
+is set,
+it says that
+.Fn fflush "" "" stdout
+should be called at the end of each
+.Fn refresh
+.b \*_STANDOUT
+says that all characters added to the screen
+are in standout mode.
+.b \*_INSDEL
+is reserved for future use,
+and is set by
+.Fn idlok .
+.Vn \*_firstch
+is set to
+.b \*_NOCHANGE
+for lines on which there has been no change
+since the last
+.Fn refresh .
diff --git a/lib/libcurses/PSD.doc/appen.C b/lib/libcurses/PSD.doc/appen.C
new file mode 100644
index 00000000000..65bef2bcb98
--- /dev/null
+++ b/lib/libcurses/PSD.doc/appen.C
@@ -0,0 +1,127 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)appen.C 8.1 (Berkeley) 6/8/93
+.\"
+.ie t .oh '\*(Ln Appendix A''PS1:19-%'
+.eh 'PS1:19-%''\*(Ln Appendix A'
+.el .he ''\fIAppendix A\fR''
+.bp
+.(x
+.ti 0
+.b "Appendix A"
+.)x
+.sh 1 "Examples" 1
+.pp
+Here we present a few examples
+of how to use the package.
+They attempt to be representative,
+though not comprehensive. Further examples can be found in the games section
+of the source tree and in various utilities that use the screen such as
+.i systat(1) .
+.sh 2 "Screen Updating"
+.pp
+The following examples are intended to demonstrate
+the basic structure of a program
+using the screen updating sections of the package.
+Several of the programs require calculational sections
+which are irrelevant of to the example,
+and are therefore usually not included.
+It is hoped that the data structure definitions
+give enough of an idea to allow understanding
+of what the relevant portions do.
+.sh 3 "Simple Character Output"
+.pp
+This program demonstrates how to set up a window and output characters to it.
+Also, it demonstrates how one might control the output to the window. If
+you run this program, you will get a demonstration of the character output
+chracteristics discussed in the above Character Output section.
+.(l I
+.so t2.gr
+.)l
+.sh 3 "A Small Screen Manipulator"
+.pp
+The next example follows the lines of the previous one but extends then to
+demonstrate the various othe uses of the package. Make sure you understand
+how this program works as it encompasses most of anything you will
+need to do with the package.
+.(l I
+.so t3.gr
+.)l
+.sh 3 "Twinkle"
+.pp
+This is a moderately simple program which prints
+patterns on the screen.
+It switches between patterns of asterisks,
+putting them on one by one in random order,
+and then taking them off in the same fashion.
+It is more efficient to write this
+using only the motion optimization,
+as is demonstrated below.
+.(l I
+.so twinkle1.gr
+.)l
+.sh 3 "Life"
+.pp
+This program fragment models the famous computer pattern game of life
+(Scientific American, May, 1974).
+The calculational routines create a linked list of structures
+defining where each piece is.
+Nothing here claims to be optimal,
+merely demonstrative.
+This code, however,
+is a very good place to use the screen updating routines,
+as it allows them to worry about what the last position looked like,
+so you don't have to.
+It also demonstrates some of the input routines.
+.(l I
+.so life.gr
+.)l
+.sh 2 "Motion optimization"
+.pp
+The following example shows how motion optimization
+is written on its own.
+Programs which flit from one place to another without
+regard for what is already there
+usually do not need the overhead of both space and time
+associated with screen updating.
+They should instead use motion optimization.
+.sh 3 "Twinkle"
+.pp
+The
+.b twinkle
+program
+is a good candidate for simple motion optimization.
+Here is how it could be written
+(only the routines that have been changed are shown):
+.(l
+.so twinkle2.gr
+.)l
diff --git a/lib/libcurses/PSD.doc/c_macros b/lib/libcurses/PSD.doc/c_macros
new file mode 100644
index 00000000000..ba6ebbc1922
--- /dev/null
+++ b/lib/libcurses/PSD.doc/c_macros
@@ -0,0 +1,70 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)c_macros 8.1 (Berkeley) 6/4/93
+.\"
+'ie t 'ds _ \d\(mi\u
+'el 'ds _ _
+'tr *\(**
+'ps 9p
+'vs 10p
+'ds - \(mi
+'ds /* \\h'\\w' 'u-\\w'/'u'/*
+'bd B 3
+'bd S B 3
+'nr cm 0
+'nf
+'de ()
+'pn 1
+..
+'de +C
+'nr cm 1
+'ft 2
+'ds +K
+'ds -K
+..
+'de -C
+'nr cm 0
+'ft 1
+.ie t 'ds +K \f3
+.el 'ds +K \fI
+'ds -K \fP
+..
+'+C
+'-C
+'am +C
+'ne 3
+..
+'de -F
+'rm =f
+..
+'ft 1
+'lg 0
diff --git a/lib/libcurses/PSD.doc/doc.I b/lib/libcurses/PSD.doc/doc.I
new file mode 100644
index 00000000000..2345aba9b1c
--- /dev/null
+++ b/lib/libcurses/PSD.doc/doc.I
@@ -0,0 +1,349 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)doc.I 8.1 (Berkeley) 6/4/93
+.\"
+.Ds
+.Fd addch ch \*m
+char ch;
+.Fd waddch win\*,ch
+WINDOW *win;
+char ch;
+.De
+Add the character
+.Vn ch
+on the window
+at the current \*y.
+If the character is a newline
+(\'\en\')
+the line will be cleared to the end,
+and the current \*y will be changed to the
+beginning off the next line
+if newline mapping is on,
+or to the next line at the same x co-ordinate
+if it is off.
+A return
+(\'\er\')
+will move to the beginning of the line on the window.
+Tabs
+(\'\et\')
+will be expanded into spaces
+in the normal tabstop positions of
+every eight characters.
+\*(Es
+.Ds
+.Fd addstr str \*m
+char *str;
+.Fd waddstr win\*,str
+WINDOW *win;
+char *str;
+.De
+Add the string pointed to by
+.Vn str
+on the window at the current \*y.
+\*(Es
+In this case, it will put on as much as it can.
+.Ds
+.Fd box win\*,vert\*,hor
+WINDOW *win;
+char vert\*,hor;
+.De
+.Pp
+Draws a box around the window using
+.Vn vert
+as the character for drawing the vertical sides, and
+.Vn hor
+for drawing the horizontal lines.
+If scrolling is not allowed,
+and the window encompasses the lower right-hand corner of the terminal,
+the corners are left blank to avoid a scroll.
+.Ds
+.Fd clear "" \*m
+.Fd wclear win
+WINDOW *win;
+.De
+Resets the entire window to blanks.
+If
+.Vn win
+is a screen,
+this sets the clear flag,
+which will cause a clear-screen sequence to be sent
+on the next
+.Fn refresh
+call.
+This also moves the current \*y
+to (0\*,0).
+.Ds
+.Fd clearok scr\*,boolf \*m
+WINDOW *scr;
+bool boolf;
+.De
+Sets the clear flag for the screen
+.Vn scr .
+If
+.Vn boolf
+is TRUE,
+this will force a clear-screen to be printed on the next
+.Fn refresh ,
+or stop it from doing so if
+.Vn boolf
+is FALSE.
+This only works on screens,
+and,
+unlike
+.Fn clear ,
+does not alter the contents of the screen.
+If
+.Vn scr
+is
+.Vn curscr ,
+the next
+.Fn refresh
+call will cause a clear-screen,
+even if the window passed to
+.Fn refresh
+is not a screen.
+.Ds
+.Fd clrtobot "" \*m
+.Fd wclrtobot win
+WINDOW *win;
+.De
+Wipes the window clear from the current \*y to the bottom.
+This does not force a clear-screen sequence on the next refresh
+under any circumstances.
+\*(Nm
+.Ds
+.Fd clrtoeol "" \*m
+.Fd wclrtoeol win
+WINDOW *win;
+.De
+Wipes the window clear from the current \*y to the end of the line.
+\*(Nm
+.Ds
+.Fd delch
+.Fd wdelch win
+WINDOW *win;
+.De
+Delete the character at the current \*y.
+Each character after it on the line shifts to the left,
+and the last character becomes blank.
+.Ds
+.Fd deleteln
+.Fd wdeleteln win
+WINDOW *win;
+.De
+Delete the current line.
+Every line below the current one will move up,
+and the bottom line will become blank.
+The current \*y will remain unchanged.
+.Ds
+.Fd erase "" \*m
+.Fd werase win
+WINDOW *win;
+.De
+Erases the window to blanks without setting the clear flag.
+This is analagous to
+.Fn clear ,
+except that it never causes a clear-screen sequence to be generated
+on a
+.Fn refresh .
+\*(Nm
+.Ds
+.Fd flushok win\*,boolf \*m
+WINDOW *win;
+bool boolf;
+.De
+Normally,
+.Fn refresh
+.Fn fflush 's
+.Vn stdout
+when it is finished.
+.Fn flushok
+allows you to control this.
+if
+.Vn boolf
+is TRUE
+(\c
+.i i.e. ,
+non-zero)
+it will do the
+.Fn fflush ;
+if it is FALSE.
+it will not.
+.Ds
+.Fd idlok win\*,boolf
+WINDOW *win;
+bool boolf;
+.De
+Reserved for future use.
+This will eventually signal to
+.Fn refresh
+that it is all right to use the insert and delete line sequences
+when updating the window.
+.Ds
+.Fd insch c
+char c;
+.Fd winsch win\*,c
+WINDOW *win;
+char c;
+.De
+Insert
+.Vn c
+at the current \*y
+Each character after it shifts to the right,
+and the last character disappears.
+\*(Es
+.Ds
+.Fd insertln
+.Fd winsertln win
+WINDOW *win;
+.De
+Insert a line above the current one.
+Every line below the current line
+will be shifted down,
+and the bottom line will disappear.
+The current line will become blank,
+and the current \*y will remain unchanged.
+.Ds
+.Fd move y\*,x \*m
+int y\*,x;
+.Fd wmove win\*,y\*,x
+WINDOW *win;
+int y\*,x;
+.De
+Change the current \*y of the window to
+.Vn y\*,x ). (
+\*(Es
+.Ds
+.Fd overlay win1\*,win2
+WINDOW *win1\*,*win2;
+.De
+Overlay
+.Vn win1
+on
+.Vn win2 .
+The contents of
+.Vn win1 ,
+insofar as they fit,
+are placed on
+.Vn win2
+at their starting \*y.
+This is done non-destructively,
+i.e., blanks on
+.Vn win1
+leave the contents of the space on
+.Vn win2
+untouched.
+.Ds
+.Fd overwrite win1\*,win2
+WINDOW *win1\*,*win2;
+.De
+Overwrite
+.Vn win1
+on
+.Vn win2 .
+The contents of
+.Vn win1 ,
+insofar as they fit,
+are placed on
+.Vn win2
+at their starting \*y.
+This is done destructively,
+.i i.e. ,
+blanks on
+.Vn win1
+become blank on
+.Vn win2 .
+.Ds
+.Fd printw fmt\*,arg1\*,arg2\*,...
+char *fmt;
+.Fd wprintw win\*,fmt\*,arg1\*,arg2\*,...
+WINDOW *win;
+char *fmt;
+.De
+Performs a
+.Fn printf
+on the window starting at the current \*y.
+It uses
+.Fn addstr
+to add the string on the window.
+It is often advisable to use the field width options of
+.Fn printf
+to avoid leaving things on the window from earlier calls.
+\*(Es
+.Ds
+.Fd refresh "" \*m
+.Fd wrefresh win
+WINDOW *win;
+.De
+Synchronize the terminal screen with the desired window.
+If the window is not a screen,
+only that part covered by it is updated.
+\*(Es
+In this case, it will update whatever it can
+without causing the scroll.
+.sp
+As a special case,
+if
+.Fn wrefresh
+is called with the window
+.Vn curscr
+the screen is cleared
+and repainted as it is currently.
+This is very useful for allowing the redrawing of the screen
+when the user has garbage dumped on his terminal.
+.Ds
+.Fd standout "" \*m
+.Fd wstandout win
+WINDOW *win;
+.Fd standend "" \*m
+.Fd wstandend win
+WINDOW *win;
+.De
+Start and stop putting characters onto
+.i win
+in standout mode.
+.Fn standout
+causes any characters added to the window
+to be put in standout mode on the terminal
+(if it has that capability).
+.Fn standend
+stops this.
+The sequences
+.Vn SO
+and
+.Vn SE
+(or
+.Vn US
+and
+.Vn UE
+if they are not defined)
+are used (see Appendix A).
diff --git a/lib/libcurses/PSD.doc/doc.II b/lib/libcurses/PSD.doc/doc.II
new file mode 100644
index 00000000000..1f6880247bc
--- /dev/null
+++ b/lib/libcurses/PSD.doc/doc.II
@@ -0,0 +1,142 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)doc.II 8.1 (Berkeley) 6/4/93
+.\"
+.Ds
+.Fd cbreak "" \*m
+.Fd nocbreak "" \*m
+.Fd crmode "" \*m
+.Fd nocrmode "" \*m
+.De
+Set or unset the terminal to/from cbreak mode.
+The misnamed macros
+.Fn crmode
+and
+.Fn nocrmode
+are retained for backwards compatibility
+with ealier versions of the library.
+.Ds
+.Fd echo "" \*m
+.Fd noecho "" \*m
+.De
+Sets the terminal to echo or not echo characters.
+.Ds
+.Fd getch "" \*m
+.Fd wgetch win
+WINDOW *win;
+.De
+Gets a character from the terminal and (if necessary)
+echos it on the window.
+\*(Es
+Otherwise, the character gotten is returned.
+If
+.i noecho
+has been set, then the window is left unaltered.
+In order to retain control of the terminal,
+it is necessary to have one of
+.i noecho ,
+.i cbreak ,
+or
+.i rawmode
+set.
+If you do not set one,
+whatever routine you call to read characters will set
+.i cbreak
+for you,
+and then reset to the original mode when finished.
+.Ds
+.Fd getstr str \*m
+char *str;
+.Fd wgetstr win\*,str
+WINDOW *win;
+char *str;
+.De
+Get a string through the window
+and put it in the location pointed to by
+.Vn str ,
+which is assumed to be large enough to handle it.
+It sets tty modes if necessary,
+and then calls
+.Fn getch
+(or
+.Fn wgetch ) "" win
+to get the characters needed to fill in the string
+until a newline or EOF is encountered.
+The newline stripped off the string.
+\*(Es
+.Ds
+.Fd \*_putchar c
+char c;
+.De
+Put out a character using the
+.Fn putchar
+macro.
+This function is used to output every character
+that
+.b curses
+generates.
+Thus,
+it can be redefined by the user who wants to do non-standard things
+with the output.
+It is named with an initial \*(lq\*_\*(rq
+because it usually should be invisible to the programmer.
+.Ds
+.Fd raw "" \*m
+.Fd noraw "" \*m
+.De
+Set or unset the terminal to/from raw mode.
+On version 7
+.Un \**
+.(f
+\**
+.Un
+is a trademark of Bell Laboratories.
+.)f
+this also turns of newline mapping
+(see
+.Fn nl ).
+.Ds
+.Fd scanw fmt\*,arg1\*,arg2\*,...
+char *fmt;
+.Fd wscanw win\*,fmt\*,arg1\*,arg2\*,...
+WINDOW *win;
+char *fmt;
+.De
+Perform a
+.Fn scanf
+through the window using
+.Vn fmt .
+It does this using consecutive
+.Fn getch 's
+(or
+.Fn wgetch 's). "" win
+\*(Es
diff --git a/lib/libcurses/PSD.doc/doc.III b/lib/libcurses/PSD.doc/doc.III
new file mode 100644
index 00000000000..7d710d49dbc
--- /dev/null
+++ b/lib/libcurses/PSD.doc/doc.III
@@ -0,0 +1,343 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)doc.III 8.1 (Berkeley) 6/4/93
+.\"
+.Ds
+.Fd baudrate "" \*m
+.De
+Returns the output baud rate of the terminal.
+This is a system dependent constant
+(defined in
+.b <sys/tty.h>
+on BSD systems,
+which is included by
+.b <curses.h> ).
+.Ds
+.Fd delwin win
+WINDOW *win;
+.De
+Deletes the window from existence.
+All resources are freed for future use by
+.b calloc (3).
+If a window has a
+.Fn subwin
+allocated window inside of it,
+deleting the outer window
+the subwindow is not affected,
+even though this does invalidate it.
+Therefore,
+subwindows should be deleted before their
+outer windows are.
+.Ds
+.Fd endwin
+.De
+Finish up window routines before exit.
+This restores the terminal to the state it was before
+.Fn initscr
+(or
+.Fn gettmode
+and
+.Fn setterm )
+was called.
+It should always be called before exiting.
+It does not exit.
+This is especially useful for resetting tty stats
+when trapping rubouts via
+.b signal (2).
+.Ds
+.Fd erasechar "" \*m
+.De
+Returns the erase character
+for the terminal,
+.i i.e. ,
+the character used by the user to erase a single character from the input.
+.Ds
+.Fd getcap str "" "char *"
+char *str;
+.De
+Return a pointer to the
+.b termcap
+capability described by
+.Vn str
+(see
+.b termcap (5)
+for details).
+.Ds
+.Fd getyx win\*,y\*,x \*m
+WINDOW *win;
+int y\*,x;
+.De
+Puts the current \*y of
+.Vn win
+in the variables
+.Vn y
+and
+.Vn x .
+Since it is a macro,
+not a function,
+you do not pass the address
+of
+.Vn y
+and
+.Vn x .
+.Ds
+.Fd inch "" \*m
+.Fd winch win \*m
+WINDOW *win;
+.De
+Returns the character at the current \*(y
+on the given window.
+This does not make any changes to the window.
+.Ds
+.Fd initscr
+.De
+Initialize the screen routines.
+This must be called before any of the screen routines are used.
+It initializes the terminal-type data and such,
+and without it none of the routines can operate.
+If standard input is not a tty,
+it sets the specifications to the terminal
+whose name is pointed to by
+.Vn Def\*_term
+(initialy "dumb").
+If the boolean
+.Vn My\*_term
+is true,
+.Vn Def\*_term
+is always used.
+If the system supports the
+.b TIOCGWINSZ
+.Fn ioctl "" "" 2
+call,
+it is used to get the number of lines and columns for the terminal,
+otherwise it is taken from the
+.b termcap
+description.
+.Ds
+.Fd killchar "" \*m
+.De
+Returns the line kill character
+for the terminal,
+.i i.e. ,
+the character used by the user to erase an entire line from the input.
+.Ds
+.Fd leaveok win\*,boolf \*m
+WINDOW *win;
+bool boolf;
+.De
+Sets the boolean flag for leaving the cursor after the last change.
+If
+.Vn boolf
+is TRUE,
+the cursor will be left after the last update on the terminal,
+and the current \*y for
+.Vn win
+will be changed accordingly.
+If it is FALSE,
+it will be moved to the current \*y.
+This flag
+(initialy FALSE)
+retains its value until changed by the user.
+.Ds
+.Fd longname termbuf\*,name
+char *termbuf\*,*name;
+.Fd fullname termbuf\*,name
+char *termbuf\*,*name;
+.De
+.Fn longname
+fills in
+.Vn name
+with the long name of the terminal described by the
+.b termcap
+entry in
+.Vn termbuf .
+It is generally of little use,
+but is nice for telling the user in a readable format what terminal
+we think he has.
+This is available in the global variable
+.Vn ttytype .
+.Vn termbuf
+is usually set via the termlib routine
+.Fn tgetent .
+.Fn fullname
+is the same as
+.Fn longname ,
+except that it gives the fullest name given in the entry,
+which can be quite verbose.
+.Ds
+.Fd mvwin win\*,y\*,x
+WINDOW *win;
+int y, x;
+.De
+Move the home position of the window
+.Vn win
+from its current starting coordinates
+to
+.Vn y\*,x ). (
+If that would put part or all of the window
+off the edge of the terminal screen,
+.Fn mvwin
+returns ERR and does not change anything.
+For subwindows,
+.Fn mvwin
+also returns ERR if you attempt to move it off its main window.
+If you move a main window,
+all subwindows are moved along with it.
+.Ds
+.Fd newwin lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *"
+int lines\*,cols\*,begin\*_y\*,begin\*_x;
+.De
+Create a new window with
+.Vn lines
+lines and
+.Vn cols
+columns starting at position
+.Vn begin\*_y\*,begin\*_x ). (
+If either
+.Vn lines
+or
+.Vn cols
+is 0 (zero),
+that dimension will be set to
+.Vn "LINES \- begin\*_y" ) (
+or
+.Vn "COLS \- begin\*_x" ) (
+respectively.
+Thus, to get a new window of dimensions
+.Vn LINES
+\(mu
+.Vn COLS ,
+use
+.Fn newwin . "" 0\*,0\*,0\*,0
+.Ds
+.Fd nl "" \*m
+.Fd nonl "" \*m
+.De
+Set or unset the terminal to/from nl mode,
+.i i.e. ,
+start/stop the system from mapping
+.b <RETURN>
+to
+.b <LINE-FEED> .
+If the mapping is not done,
+.Fn refresh
+can do more optimization,
+so it is recommended, but not required, to turn it off.
+.Ds
+.Fd scrollok win\*,boolf \*m
+WINDOW *win;
+bool boolf;
+.De
+Set the scroll flag for the given window.
+If
+.Vn boolf
+is FALSE, scrolling is not allowed.
+This is its default setting.
+.Ds
+.Fd touchline win\*,y\*,startx\*,endx
+WINDOW *win;
+int y\*,startx\*,endx;
+.De
+This function performs a function similar to
+.Fn touchwin
+on a single line.
+It marks the first change for the given line
+to be
+.Vn startx ,
+if it is before the current first change mark,
+and
+the last change mark is set to be
+.Vn endx
+if it is currently less than
+.Vn endx .
+.Ds
+.Fd touchoverlap win1\*,win2
+WINDOW *win1, *win2;
+.De
+Touch the window
+.Vn win2
+in the area which overlaps with
+.Vn win1 .
+If they do not overlap,
+no changes are made.
+.Ds
+.Fd touchwin win
+WINDOW *win;
+.De
+Make it appear that the every location on the window
+has been changed.
+This is usually only needed for refreshes with overlapping windows.
+.Ds
+.Fd subwin win\*,lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *"
+WINDOW *win;
+int lines\*,cols\*,begin\*_y\*,begin\*_x;
+.De
+Create a new window with
+.Vn lines
+lines and
+.Vn cols
+columns starting at position
+.Vn begin\*_y\*,begin\*_x ) (
+inside the window
+.i win .
+This means that any change made to either window
+in the area covered
+by the subwindow will be made on both windows.
+.Vn begin\*_y\*,begin\*_x
+are specified relative to the overall screen,
+not the relative (0\*,0) of
+.Vn win .
+If either
+.Vn lines
+or
+.Vn cols
+is 0 (zero),
+that dimension will be set to
+.Vn "LINES \- begin\*_y" ) (
+or
+.Vn "COLS \- begin\*_x" ) (
+respectively.
+.Ds
+.Fd unctrl ch \*m
+char ch;
+.De
+This is actually a debug function for the library,
+but it is of general usefulness.
+It returns a string which is a representation of
+.Vn ch .
+Control characters become their upper-case equivalents preceded by a "^".
+Other letters stay just as they are.
+To use
+.Fn unctrl ,
+you may have to have
+.b #include\ <unctrl.h>
+in your file.
diff --git a/lib/libcurses/PSD.doc/doc.IV b/lib/libcurses/PSD.doc/doc.IV
new file mode 100644
index 00000000000..717a9863abb
--- /dev/null
+++ b/lib/libcurses/PSD.doc/doc.IV
@@ -0,0 +1,110 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)doc.IV 8.1 (Berkeley) 6/4/93
+.\"
+.Ds
+.Fd gettmode
+.De
+Get the tty stats.
+This is normally called by
+.Fn initscr .
+.Ds
+.Fd mvcur lasty\*,lastx\*,newy\*,newx
+int lasty\*,lastx\*,newy\*,newx;
+.De
+Moves the terminal's cursor from
+.Vn lasty\*,lastx ) (
+to
+.Vn newy\*,newx ) (
+in an approximation of optimal fashion.
+This routine uses the functions borrowed from
+.i ex
+version 2.6.
+It is possible to use this optimization
+without the benefit of the screen routines.
+With the screen routines, this should not be called by the user.
+.Fn move
+and
+.Fn refresh
+should be used to move the cursor position,
+so that the routines know what's going on.
+.Ds
+.Fd scroll win
+WINDOW *win;
+.De
+Scroll the window upward one line.
+This is normally not used by the user.
+.Ds
+.Fd savetty "" \*m
+.Fd resetty "" \*m
+.De
+.Fn savetty
+saves the current tty characteristic flags.
+.Fn resetty
+restores them to what
+.Fn savetty
+stored.
+These functions are performed automatically by
+.Fn initscr
+and
+.Fn endwin .
+.Ds
+.Fd setterm name
+char *name;
+.De
+Set the terminal characteristics to be those of the terminal named
+.Vn name ,
+getting the terminal size from the
+.b TIOCGWINSZ
+.Fn ioctl "" "" 2
+if it exists,
+otherwise from the environment.
+This is normally called by
+.Fn initscr .
+.Ds
+.Fd tstp
+.De
+If the new
+.b tty (4)
+driver is in use,
+this function
+will save the current tty state
+and then put the process to sleep.
+When the process gets restarted,
+it restores the tty state
+and then calls
+.Fn wrefresh "" "" curscr
+to redraw the screen.
+.Fn initscr
+sets the signal
+SIGTSTP
+to trap to this routine.
diff --git a/lib/libcurses/PSD.doc/ex1.c b/lib/libcurses/PSD.doc/ex1.c
new file mode 100644
index 00000000000..02ed9b936bd
--- /dev/null
+++ b/lib/libcurses/PSD.doc/ex1.c
@@ -0,0 +1,102 @@
+.\" Copyright (c) 1992, 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.
+.\"
+.\" @(#)ex1.c 8.1 (Berkeley) 6/8/93
+.\"
+#include <sys/types.h>
+#include <curses.h>
+#include <stdio.h>
+#include <signal.h>
+
+
+#define YSIZE 10
+#define XSIZE 20
+
+int quit();
+
+main()
+{
+ int i, j, c;
+ size_t len;
+ char id[100];
+ FILE *fp;
+ char *s;
+
+ initscr(); /* Always call initscr() first */
+ signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */
+ crmode(); /* We want cbreak mode */
+ noecho(); /* We want to have control of chars */
+ delwin(stdscr); /* Create our own stdscr */
+ stdscr = newwin(YSIZE, XSIZE, 10, 35);
+ flushok(stdscr, TRUE); /* Enable flushing of stdout */
+ scrollok(stdscr, TRUE); /* Enable scrolling */
+ erase(); /* Initially, clear the screen */
+
+ standout();
+ move(0,0);
+ while (1) {
+ c = getchar();
+ switch(c) {
+ case 'q': /* Quit on 'q' */
+ quit();
+ break;
+ case 's': /* Go into standout mode on 's' */
+ standout();
+ break;
+ case 'e': /* Exit standout mode on 'e' */
+ standend();
+ break;
+ case 'r': /* Force a refresh on 'r' */
+ wrefresh(curscr);
+ break;
+ default: /* By default output the character */
+ addch(c);
+ refresh();
+ }
+ }
+}
+
+
+int
+quit()
+{
+ erase(); /* Terminate by erasing the screen */
+ refresh();
+ endwin(); /* Always end with endwin() */
+ delwin(curscr); /* Return storage */
+ delwin(stdscr);
+ putchar('\n');
+ exit(0);
+}
+
+
+
+
diff --git a/lib/libcurses/PSD.doc/ex2.c b/lib/libcurses/PSD.doc/ex2.c
new file mode 100644
index 00000000000..13e8f2990b9
--- /dev/null
+++ b/lib/libcurses/PSD.doc/ex2.c
@@ -0,0 +1,210 @@
+.\" Copyright (c) 1992, 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.
+.\"
+.\" @(#)ex2.c 8.1 (Berkeley) 6/8/93
+.\"
+#include <curses.h>
+#include <stdio.h>
+#include <signal.h>
+
+#define YSIZE LINES
+#define XSIZE COLS
+
+static int quit();
+
+/*
+ * This program fills the screen up with characters and the allows the user to
+ * manipulate the text on the screen using some basic commands.
+ * Nothing fancy, just a demonstration of the elementary features of the
+ * curses(3) package.
+ */
+main()
+{
+ int i, j, c, n, d = 0;
+ char id[100];
+ int hh = 0;
+ int curx, cury, base, arg;
+
+ initscr();
+ signal(SIGINT, quit);
+ crmode();
+ noecho();
+ nonl();
+ delwin(stdscr);
+ stdscr = newwin(YSIZE, XSIZE, 0, 0);
+ flushok(stdscr, TRUE);
+ scrollok(stdscr, TRUE);
+ erase();
+ refresh();
+
+ move(0,0);
+ refresh();
+ for (i = 0; i < YSIZE + 2; i++) {
+ sprintf(id, "%d: ", i);
+ addstr(id);
+ for (j = 0; j < XSIZE - strlen(id); j++)
+ addch('0' + (i % 10));
+ }
+ c = getchar();
+ base = 2;
+ curx = cury = 0;
+ move(0, 0);
+ refresh();
+
+ /*
+ * The screen manipulator has the following commands:
+ * 'D' - clear to the end of the current line.
+ * 'B' - clear to the bottom of the screen.
+ * 'E' - erase the screen.
+ * 's' - enter standout mode.
+ * 'e' - exit standout mode.
+ * 'd' n - delete n lines below cursor line.
+ * 'i' n - insert n lines below cursor line.
+ * 'q' - quit.
+ * 'f' - move cursor one position to the right.
+ * 'b' - move cursor one position to the left.
+ * 'n' - move cursor one line down.
+ * 'p' - move cursor one line up.
+ * 'h' - home cusor.
+ * 'l' - force refresh.
+ * 'r' - simulate a carriage return.
+ *
+ * All other characters are ignored.
+ */
+ for(;;) {
+ switch(c = getchar()) {
+ case 'D':
+ clrtoeol();
+ refresh();
+ continue;
+ case 'B':
+ clrtobot();
+ refresh();
+ continue;
+ case 'E':
+ erase();
+ refresh();
+ continue;
+ case 's':
+ standout();
+ continue;
+ case 'e':
+ standend();
+ continue;
+ case 'd':
+ arg = getchar() - '0';
+ for (i = 0; i < arg; i++)
+ deleteln();
+ refresh();
+ continue;
+ case 'i':
+ arg = getchar() - '0';
+ for (i = 0; i < arg; i++)
+ insertln();
+ refresh();
+ continue;
+ case 'q':
+ quit();
+ case 'f':
+ if (curx < XSIZE - 1)
+ curx++;
+ else {
+ cury++;
+ curx = 0;
+ }
+ break;
+ case 'b':
+ if (curx == 0) {
+ cury--;
+ curx = XSIZE - 1;
+ } else
+ curx--;
+ break;
+ case 'n':
+ cury++;
+ break;
+ case 'p':
+ cury--;
+ break;
+ case 'h':
+ curx = cury = 0;
+ break;
+ case 'l':
+ wrefresh(curscr);
+ continue;
+ case 'r': /* return */
+ {
+ int x, y;
+ getyx(stdscr, y, x);
+ move(y+1, 0);
+ insertln();
+ move(y, x);
+ clrtoeol();
+ refresh();
+ continue;
+ }
+ default:
+ continue;
+ }
+
+ if (cury < 0) {
+ base--;
+ move(0, 0);
+ insertln();
+ sprintf(id, "%d: ", base);
+ addstr(id);
+ for (j = 0; j < XSIZE - strlen(id) - 2; j++)
+ addch('0' + (base % 10));
+ cury++;
+ } else if (cury >= YSIZE) {
+ move(0, 0);
+ deleteln();
+ move(YSIZE - 1, 0);
+ sprintf(id, "%d: ", base + YSIZE);
+ addstr(id);
+ for (j = 0; j < XSIZE - strlen(id) - 2; j++)
+ addch('0' + ((base + YSIZE) % 10));
+ cury--;
+ base++;
+ }
+ move(cury, curx);
+ refresh();
+ }
+}
+
+int
+quit()
+{
+ erase();
+ refresh();
+ endwin();
+ exit(0);
+}
diff --git a/lib/libcurses/PSD.doc/fns.doc b/lib/libcurses/PSD.doc/fns.doc
new file mode 100644
index 00000000000..0fa89abd3f7
--- /dev/null
+++ b/lib/libcurses/PSD.doc/fns.doc
@@ -0,0 +1,799 @@
+.\" Copyright (c) 1992, 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.
+.\"
+.\" @(#)fns.doc 8.2 (Berkeley) 6/1/94
+.\"
+.Ds
+.Fn addch "char ch" \(dg
+.De
+Add the character
+.Vn ch
+on the window
+at the current \*y.
+If the character is a newline
+(\'\en\')
+the line will be cleared to the end,
+and the current \*y will be changed to the
+beginning off the next line
+if newline mapping is on,
+or to the next line at the same x co-ordinate
+if it is off.
+A return
+(\'\er\')
+will move to the beginning of the line on the window.
+Tabs
+(\'\et\')
+will be expanded into spaces
+in the normal tabstop positions of
+every eight characters.
+\*(Es
+.Ds
+.Fn addstr "char *str" \(dg
+.De
+Add the string pointed to by
+.Vn str
+on the window at the current \*y.
+\*(Es
+In this case, it will put on as much as it can.
+.Ds
+.Fn baudrate "" \(dg
+.De
+Returns the output baud rate of the terminal.
+This is a system dependent constant
+(defined in
+.b <sys/tty.h>
+on BSD systems,
+which is included by
+.b <curses.h> ).
+.Ds
+.Fn box "WINDOW win" "char vert" "char hor"
+.De
+.Pp
+Draws a box around the window using
+.Vn vert
+as the character for drawing the vertical sides, and
+.Vn hor
+for drawing the horizontal lines.
+If scrolling is not allowed,
+and the window encompasses the lower right-hand corner of the terminal,
+the corners are left blank to avoid a scroll.
+.Ds
+.Fn cbreak "" \(dg
+.De
+Set or the terminal to cbreak mode.
+.Ds
+.Fn clear "" \(dg
+.De
+Resets the entire window to blanks.
+If
+.Vn win
+is a screen,
+this sets the clear flag,
+which will cause a clear-screen sequence to be sent
+on the next
+.Fn refresh
+call.
+This also moves the current \*y
+to (0\*,0).
+.Ds
+.Fn clearok "WINDOW *scr" "int boolf" \(dg
+.De
+Sets the clear flag for the screen
+.Vn scr .
+If
+.Vn boolf
+is non-zero,
+this will force a clear-screen to be printed on the next
+.Fn refresh ,
+or stop it from doing so if
+.Vn boolf
+is 0.
+This only works on screens,
+and,
+unlike
+.Fn clear ,
+does not alter the contents of the screen.
+If
+.Vn scr
+is
+.Vn curscr ,
+the next
+.Fn refresh
+call will cause a clear-screen,
+even if the window passed to
+.Fn refresh
+is not a screen.
+.Ds
+.Fn clrtobot "" \(dg
+.De
+Wipes the window clear from the current \*y to the bottom.
+This does not force a clear-screen sequence on the next refresh
+under any circumstances.
+\*(Nm
+.Ds
+.Fn clrtoeol "" \(dg
+.De
+Wipes the window clear from the current \*y to the end of the line.
+\*(Nm
+.Ds
+.Fn crmode "" \(dg
+.De
+Identical to
+.Fn cbreak .
+The misnamed macro
+.Fn crmode
+and
+.Fn nocrmode
+is retained for backwards compatibility
+with ealier versions of the library.
+.Ds
+.Fn delch ""
+.De
+Delete the character at the current \*y.
+Each character after it on the line shifts to the left,
+and the last character becomes blank.
+.Ds
+.Fn deleteln ""
+.De
+Delete the current line.
+Every line below the current one will move up,
+and the bottom line will become blank.
+The current \*y will remain unchanged.
+.Ds
+.Fn delwin "WINDOW *win"
+.De
+Deletes the window from existence.
+All resources are freed for future use by
+.b calloc (3).
+If a window has a
+.Fn subwin
+allocated window inside of it,
+deleting the outer window
+the subwindow is not affected,
+even though this does invalidate it.
+Therefore,
+subwindows should be deleted before their
+outer windows are.
+.Ds
+.Fn echo "" \(dg
+.De
+Sets the terminal to echo characters.
+.Ds
+.Fn endwin ""
+.De
+Finish up window routines before exit.
+This restores the terminal to the state it was before
+.Fn initscr
+(or
+.Fn gettmode
+and
+.Fn setterm )
+was called.
+It should always be called before exiting and before the final calls to
+.Fn delwin .
+It does not exit.
+This is especially useful for resetting tty stats
+when trapping rubouts via
+.b signal (2).
+.Ds
+.Fn erase "" \(dg
+.De
+Erases the window to blanks without setting the clear flag.
+This is analagous to
+.Fn clear ,
+except that it never causes a clear-screen sequence to be generated
+on a
+.Fn refresh .
+\*(Nm
+.Ds
+.Fn erasechar "" \(dg
+.De
+Returns the erase character
+for the terminal,
+.i i.e. ,
+the character used by the user to erase a single character from the input.
+.Ds
+.Fn flushok "WINDOW *win" "int boolf"
+.De
+Normally,
+.Fn refresh
+.Fn fflush 's
+.Vn stdout
+when it is finished.
+.Fn flushok
+allows you to control this.
+if
+.Vn boolf
+is non-zero
+(\c
+.i i.e. ,
+non-zero)
+it will do the
+.Fn fflush ,
+otherwise it will not.
+.Ds
+.Fn getch "" \(dg
+.De
+Gets a character from the terminal and (if necessary)
+echos it on the window.
+\*(Es
+Otherwise, the character gotten is returned.
+If
+.i noecho
+has been set, then the window is left unaltered.
+In order to retain control of the terminal,
+it is necessary to have one of
+.i noecho ,
+.i cbreak ,
+or
+.i rawmode
+set.
+If you do not set one,
+whatever routine you call to read characters will set
+.i cbreak
+for you,
+and then reset to the original mode when finished.
+.Ds
+.Fn getstr "char *str" \(dg
+.De
+Get a string through the window
+and put it in the location pointed to by
+.Vn str ,
+which is assumed to be large enough to handle it.
+It sets tty modes if necessary,
+and then calls
+.Fn getch
+(or
+.Fn wgetch )
+to get the characters needed to fill in the string
+until a newline or EOF is encountered.
+The newline stripped off the string.
+\*(Es
+.Ds
+.Fn gettmode ""
+.De
+Get the tty stats.
+This is normally called by
+.Fn initscr .
+.Ds
+.Fn getyx "WINDOW *win" "int y" "int x"
+.De
+Puts the current \*y of
+.Vn win
+in the variables
+.Vn y
+and
+.Vn x .
+Since it is a macro,
+not a function,
+you do not pass the address
+of
+.Vn y
+and
+.Vn x .
+.Ds
+.Fn idlok "WINDOW *win" "int boolf"
+.De
+Reserved for future use.
+This will eventually signal to
+.Fn refresh
+that it is all right to use the insert and delete line sequences
+when updating the window.
+.ne 1i
+.Ds
+.Fn inch "" \(dg
+.De
+Returns the character at the current position on the given window.
+This does not make any changes to the window.
+.Ds
+.Fn initscr ""
+.De
+Initialize the screen routines.
+This must be called before any of the screen routines are used.
+It initializes the terminal-type data and such,
+and without it none of the routines can operate.
+If standard input is not a tty,
+it sets the specifications to the terminal
+whose name is pointed to by
+.Vn Def\*_term
+(initially "dumb").
+If the boolean
+.Vn My\*_term
+is non-zero,
+.Vn Def\*_term
+is always used.
+If the system supports the
+.b TIOCGWINSZ
+.i ioctl(2)
+call,
+it is used to get the number of lines and columns for the terminal,
+otherwise it is taken from the
+.b termcap
+description.
+.Ds
+.Fn insch "char c"
+.De
+Insert
+.Vn c
+at the current \*y
+Each character after it shifts to the right,
+and the last character disappears.
+\*(Es
+.Ds
+.Fn insertln ""
+.De
+Insert a line above the current one.
+Every line below the current line
+will be shifted down,
+and the bottom line will disappear.
+The current line will become blank,
+and the current \*y will remain unchanged.
+.Ds
+.Fn killchar "" \(dg
+.De
+Returns the line kill character
+for the terminal,
+.i i.e. ,
+the character used by the user to erase an entire line from the input.
+.Ds
+.Fn leaveok "WINDOW *win" "int boolf" \(dg
+.De
+Sets the boolean flag for leaving the cursor after the last change.
+If
+.Vn boolf
+is non-zero,
+the cursor will be left after the last update on the terminal,
+and the current \*y for
+.Vn win
+will be changed accordingly.
+If
+.Vn boolf
+ is 0 the cursor will be moved to the current \*y.
+This flag
+(initially 0)
+retains its value until changed by the user.
+.Ds
+.Fn move "int y" "int x"
+.De
+Change the current \*y of the window to
+.Vn y\*,x ). (
+\*(Es
+.Ds
+.Fn mvcur "int lasty" "int lastx" "int newy" "int newx"
+.De
+Moves the terminal's cursor from
+.Vn lasty\*,lastx ) (
+to
+.Vn newy\*,newx ) (
+in an approximation of optimal fashion.
+This routine uses the functions borrowed from
+.i ex
+version 2.6.
+It is possible to use this optimization
+without the benefit of the screen routines.
+With the screen routines, this should not be called by the user.
+.Fn move
+and
+.Fn refresh
+should be used to move the cursor position,
+so that the routines know what's going on.
+.Ds
+.Fn mvprintw "int y" "int x" "const char *fmt" "..."
+.De
+Equivalent to:
+.(l
+move(y, x);
+printw(fmt, ...);
+.)l
+.Ds
+.Fn mvscanw "int y" "int x" "const char *fmt" "..."
+.De
+Equivalent to:
+.(l
+move(y, x);
+scanw(fmt, ...);
+.)l
+.Ds
+.Fn mvwin "WINDOW *win" "int y" "int x"
+.De
+Move the home position of the window
+.Vn win
+from its current starting coordinates
+to
+.Vn y\*,x ). (
+If that would put part or all of the window
+off the edge of the terminal screen,
+.Fn mvwin
+returns ERR and does not change anything.
+For subwindows,
+.Fn mvwin
+also returns ERR if you attempt to move it off its main window.
+If you move a main window,
+all subwindows are moved along with it.
+.Ds
+.Fn mvwprintw "WINDOW *win" "int y" "int x" "const char *fmt" "..."
+.De
+Equivalent to:
+.(l
+wmove(win, y, x);
+printw(fmt, ...);
+.)l
+.Ds
+.Fn mvwscanw "WINDOW *win" "int y" "int x" "const char *fmt" "..."
+.De
+Equivalent to:
+.(l
+wmove(win, y, x);
+scanw(fmt, ...);
+.)l
+.Ds
+.Ft "WINDOW *"
+.Fn newwin "int lines" "int cols" "int begin_y" "int begin_x"
+.De
+Create a new window with
+.Vn lines
+lines and
+.Vn cols
+columns starting at position
+.Vn begin\*_y\*,begin\*_x ). (
+If either
+.Vn lines
+or
+.Vn cols
+is 0 (zero),
+that dimension will be set to
+.Vn "LINES \- begin\*_y" ) (
+or
+.Vn "COLS \- begin\*_x" ) (
+respectively.
+Thus, to get a new window of dimensions
+.Vn LINES
+\(mu
+.Vn COLS ,
+use
+.Fn newwin 0 0 0 0 .
+.Ds
+.Fn nl "" \(dg
+.De
+Set the terminal to nl mode,
+.i i.e. ,
+start/stop the system from mapping
+.b <RETURN>
+to
+.b <LINE-FEED> .
+If the mapping is not done,
+.Fn refresh
+can do more optimization,
+so it is recommended, but not required, to turn it off.
+.Ds
+.Fn nocbreak "" \(dg
+.De
+Unset the terminal from cbreak mode.
+.Ds
+.Fn nocrmode "" \(dg
+.De
+Identical to
+.Fn nocbreak .
+The misnamed macro
+.Fn nocrmode
+is retained for backwards compatibility
+with ealier versions of the library.
+.Ds
+.Fn noecho "" \(dg
+.De
+Turn echoing of characters off.
+.Ds
+.Fn nonl "" \(dg
+.De
+Unset the terminal to from nl mode. See
+.Fn nl .
+.ne 1i
+.Ds
+.Fn noraw "" \(dg
+.De
+Unset the terminal from raw mode. See
+.Fn raw .
+.Ds
+.Fn overlay "WINDOW *win1" "WINDOW *win2"
+.De
+Overlay
+.Vn win1
+on
+.Vn win2 .
+The contents of
+.Vn win1 ,
+insofar as they fit,
+are placed on
+.Vn win2
+at their starting \*y.
+This is done non-destructively,
+i.e., blanks on
+.Vn win1
+leave the contents of the space on
+.Vn win2
+untouched. Note that all non-blank characters are overwritten
+destructively in the overlay.
+.Ds
+.Fn overwrite "WINDOW *win1" "WINDOW *win2"
+.De
+Overwrite
+.Vn win1
+on
+.Vn win2 .
+The contents of
+.Vn win1 ,
+insofar as they fit,
+are placed on
+.Vn win2
+at their starting \*y.
+This is done destructively,
+.i i.e. ,
+blanks on
+.Vn win1
+become blank on
+.Vn win2 .
+.Ds
+.Fn printw "char *fmt" "..."
+.De
+Performs a
+.Fn printf
+on the window starting at the current \*y.
+It uses
+.Fn addstr
+to add the string on the window.
+It is often advisable to use the field width options of
+.Fn printf
+to avoid leaving things on the window from earlier calls.
+\*(Es
+.Ds
+.Fn raw "" \(dg
+.De
+Set the terminal to raw mode.
+On version 7
+.Un \**
+.(f
+\**
+.Un
+is a trademark of Unix System Laboratories.
+.)f
+this also turns off newline mapping
+(see
+.Fn nl ).
+.Ds
+.Fn refresh "" \(dg
+.De
+Synchronize the terminal screen with the desired window.
+If the window is not a screen,
+only that part covered by it is updated.
+\*(Es
+In this case, it will update whatever it can
+without causing the scroll.
+.sp
+As a special case,
+if
+.Fn wrefresh
+is called with the window
+.Vn curscr
+the screen is cleared
+and repainted as it is currently.
+This is very useful for allowing the redrawing of the screen
+when the user has garbage dumped on his terminal.
+.Ds
+.Fn resetty "" \(dg
+.De
+.Fn resetty
+restores them to what
+.Fn savetty
+stored.
+These functions are performed automatically by
+.Fn initscr
+and
+.Fn endwin .
+This function should not be used by the user.
+.Ds
+.Fn savetty "" \(dg
+.De
+.Fn savetty
+saves the current tty characteristic flags. See
+.Fn resetty .
+This function should not be used by the user.
+.Ds
+.Fn scanw "char *fmt" "..."
+.De
+Perform a
+.Fn scanf
+through the window using
+.Vn fmt .
+It does this using consecutive calls to
+.Fn getch
+(or
+.Fn wgetch ).
+\*(Es
+.ne 1i
+.Ds
+.Fn scroll "WINDOW *win"
+.De
+Scroll the window upward one line.
+This is normally not used by the user.
+.Ds
+.Fn scrollok "WINDOW *win" "int boolf" \(dg
+.De
+Set the scroll flag for the given window.
+If
+.Vn boolf
+is 0, scrolling is not allowed.
+This is its default setting.
+.Ds
+.Fn standend "" \(dg
+.De
+End standout mode initiated by
+.Fn standout .
+.Ds
+.Fn standout "" \(dg
+.De
+Causes any characters added to the window
+to be put in standout mode on the terminal
+(if it has that capability).
+.Ds
+.Ft "WINDOW *"
+.Fn subwin "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x"
+.De
+Create a new window with
+.Vn lines
+lines and
+.Vn cols
+columns starting at position
+.Vn begin\*_y\*,begin\*_x ) (
+inside the window
+.i win .
+This means that any change made to either window
+in the area covered
+by the subwindow will be made on both windows.
+.Vn begin\*_y\*,begin\*_x
+are specified relative to the overall screen,
+not the relative (0\*,0) of
+.Vn win .
+If either
+.Vn lines
+or
+.Vn cols
+is 0 (zero),
+that dimension will be set to
+.Vn "LINES \- begin\*_y" ) (
+or
+.Vn "COLS \- begin\*_x" ) (
+respectively.
+.Ds
+.Fn touchline "WINDOW *win" "int y" "int startx" "int endx"
+.De
+This function performs a function similar to
+.Fn touchwin
+on a single line.
+It marks the first change for the given line
+to be
+.Vn startx ,
+if it is before the current first change mark,
+and
+the last change mark is set to be
+.Vn endx
+if it is currently less than
+.Vn endx .
+.Ds
+.Fn touchoverlap "WINDOW *win1" "WINDOW *win2"
+.De
+Touch the window
+.Vn win2
+in the area which overlaps with
+.Vn win1 .
+If they do not overlap,
+no changes are made.
+.Ds
+.Fn touchwin "WINDOW *win"
+.De
+Make it appear that the every location on the window
+has been changed.
+This is usually only needed for refreshes with overlapping windows.
+.Ds
+.Fn tstp
+.De
+This function
+will save the current tty state
+and then put the process to sleep.
+When the process gets restarted,
+it restores the saved tty state
+and then calls
+.Fn wrefresh "curscr"
+to redraw the screen.
+.Fn Initscr
+sets the signal
+SIGTSTP
+to trap to this routine.
+.Ds
+.Fn unctrl "char *ch" \(dg
+.De
+Returns a string which is an ASCII representation of
+.Vn ch .
+Characters are 8 bits long.
+.Ds
+.Fn unctrllen "char *ch" \(dg
+.De
+Returns the length of the ASCII representation of
+.Vn ch .
+.ne 1i
+.Ds
+.Fn vwprintw "WINDOW *win" "const char *fmt" "va_list ap"
+.De
+Identical to
+.Fn printw
+except that it takes both a window specification and a pointer to a variable
+length argument list.
+.Ds
+.Fn vwscanw "WINDOW *win" "const char *fmt" "va_list ap"
+.De
+Identical to
+.Fn scanw
+except that it takes both a window specification and a pointer to a variable
+length argument list.
+.Ds
+.Fn waddbytes "WINDOW *win" "char *str" "int len"
+.De
+This function is the low level character output function.
+.Vn Len
+characters of the string
+.Vn str
+are output to the current \*y position of the window specified by
+.Vn win.
+.sp 2
+.pp
+\fIThe following functions differ from the standard functions only in their
+specification of a window, rather than the use of the default
+.Vn stdscr.\fP
+.Ds
+.Fn waddch "WINDOW *win" "char ch"
+.Fn waddstr "WINDOW *win" "char *str"
+.Fn wclear "WINDOW *win"
+.Fn wclrtobot "WINDOW *win"
+.Fn wclrtoeol "WINDOW *win"
+.Fn wdelch "WINDOW *win"
+.Fn wdeleteln "WINDOW *win"
+.Fn werase "WINDOW *win"
+.Fn wgetch "WINDOW *win"
+.Fn wgetstr "WINDOW *win" "char *str"
+.Fn winch "WINDOW *win" \(dg
+.Fn winsch "WINDOW *win" "char c"
+.Fn winsertln "WINDOW *win"
+.Fn wmove "WINDOW *win" "int y" int x"
+.Fn wprintw "WINDOW *win" "char *fmt" "..."
+.Fn wrefresh "WINDOW *win"
+.Fn wscanw "WINDOW *win" "char *fmt" "..."
+.Fn wstandend "WINDOW *win"
+.Fn wstandout "WINDOW *win"
+.Dg
diff --git a/lib/libcurses/PSD.doc/intro.0 b/lib/libcurses/PSD.doc/intro.0
new file mode 100644
index 00000000000..c95b49d4782
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.0
@@ -0,0 +1,106 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.0 8.1 (Berkeley) 6/4/93
+.\"
+.tp
+.(l C
+.ps 12
+.ft B
+Screen Updating and Cursor Movement Optimization:
+.fl
+A Library Package
+.ft
+.ps
+.sp
+.i "Kenneth C. R. C. Arnold"
+.i "Elan Amir"
+.sp
+Computer Science Division
+Department of Electrical Engineering and Computer Science
+University of California, Berkeley
+Berkeley, California 94720
+.sp 3
+.bi ABSTRACT
+.sp 2
+.)l
+.(q
+.pp
+This document describes a package of C library functions
+which allow the user to:
+.ie t .ip \ \ \ \(bu
+.el .ip 1)
+update a screen with reasonable optimization,
+.ie t .ip \ \ \ \(bu
+.el .ip 2)
+get input from the terminal
+in a screen-oriented fashion,
+and
+.ie t .ip \ \ \ \(bu
+.el .ip 3)
+independent from the above, move the cursor optimally
+from one point to another.
+.pp
+These routines all use the
+\*(tc \*(db to describe the capabilities of the terminal.
+.)q
+.b Acknowledgements
+.pp
+This package would not exist
+without the work of Bill Joy,
+who,
+in writing his editor,
+created the capability to generally describe terminals,
+wrote the routines which read this \*(db,
+and, most importantly,
+those which implement optimal cursor movement,
+which routines I have simply lifted nearly intact.
+Doug Merritt and Kurt Shoens also were extremely important,
+as were both willing to waste time listening to me rant and rave.
+The help and/or support of
+Ken Abrams,
+Alan Char,
+Mark Horton,
+and
+Joe Kalash,
+was, and is,
+also greatly appreciated.
+.i "Ken Arnold 16 April 1986"
+.pp
+The help and/or support of Kirk McKusick and Keith Bostic (public vi!)
+was invaluable in bringing the package ``into the 90's'', which now
+includes completely new data structures and screen refresh optimization
+routines.
+.i "Elan Amir 29 December 1992"
+
+
+
+
diff --git a/lib/libcurses/PSD.doc/intro.1 b/lib/libcurses/PSD.doc/intro.1
new file mode 100644
index 00000000000..a86d7571ade
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.1
@@ -0,0 +1,249 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.1 8.1 (Berkeley) 6/4/93
+.\"
+.bp
+.sh 1 Overview
+.pp
+In making available the generalized terminal descriptions in \*(tc,
+much information was made available to the programmer,
+but little work was taken out of one's hands.
+The purpose of this package is to allow the C programmer
+to do the most common type of terminal dependent functions,
+those of movement optimization and optimal screen updating,
+without doing any of the dirty work,
+and with nearly as much ease as is necessary to simply print
+or read things.
+.sh 2 "Terminology"
+.pp
+In this document, the following terminology is used:
+.de Ip
+.sp
+.in 5n
+.ti 0n
+.b "\\$1" :
+..
+.Ip window
+An internal representation
+containing an image of what a section of the terminal screen may look like
+at some point in time.
+This subsection can either encompass the entire terminal screen,
+or any smaller portion down to a single character within that screen.
+.Ip terminal
+Sometimes called
+.b terminal
+.b screen .
+The package's idea of what the terminal's screen currently looks like,
+.i i.e. ,
+what the user sees now.
+This is a special
+.i screen :
+.Ip screen
+This is a subset of windows which are as large as the terminal screen,
+.i i.e. ,
+they start at the upper left hand corner
+and encompass the lower right hand corner.
+One of these,
+.Vn stdscr ,
+is automatically provided for the programmer.
+.rm Ip
+.sh 2 "Compiling Applications"
+.pp
+In order to use the library,
+it is necessary to have certain types and variables defined.
+Therefore, the programmer must have a line:
+.(l
+.b "#include <curses.h>"
+.)l
+at the top of the program source.
+Compilations should have the following form:
+.(l
+.ie t \fBcc\fR [ \fIflags\fR ] file ... \fB\-lcurses \-ltermcap\fR
+.el \fIcc\fR [ flags ] file ... \fI\-lcurses \-ltermcap\fR
+.)l
+.sh 2 "Screen Updating"
+.pp
+In order to update the screen optimally,
+it is necessary for the routines to know what the screen currently looks like
+and what the programmer wants it to look like next.
+For this purpose,
+a data type
+(structure)
+named
+.Vn WINDOW
+is defined
+which describes a window image to the routines,
+including its starting position on the screen
+(the \*y of the upper left hand corner)
+and its size.
+One of these
+(called
+.Vn curscr
+for
+.i "current screen" )
+is a screen image of what the terminal currently looks like.
+Another screen
+(called
+.Vn stdscr ,
+for
+.i "standard screen" )
+is provided
+by default
+to make changes on.
+.pp
+A window is a purely internal representation.
+It is used to build and store
+a potential image of a portion of the terminal.
+It doesn't bear any necessary relation
+to what is really on the terminal screen.
+It is more like an array of characters on which to make changes.
+.pp
+When one has a window which describes
+what some part the terminal should look like,
+the routine
+.Fn refresh
+(or
+.Fn wrefresh
+if the window is not
+.Vn stdscr )
+is called.
+.Fn Refresh
+makes the terminal,
+in the area covered by the window,
+look like that window.
+Note, therefore, that changing something on a window
+.i does
+.bi not
+.i "change the terminal" .
+Actual updates to the terminal screen
+are made only by calling
+.Fn refresh
+or
+.Fn wrefresh .
+This allows the programmer to maintain several different ideas
+of what a portion of the terminal screen should look like.
+Also, changes can be made to windows in any order,
+without regard to motion efficiency.
+Then, at will,
+the programmer can effectively say
+.q "make it look like this" ,
+and the package will execute the changes in an optimal way.
+.sh 2 "Naming Conventions"
+.pp
+As hinted above,
+the routines can use several windows,
+but two are always available:
+.Vn curscr ,
+which is the image of what the terminal looks like at present,
+and
+.Vn stdscr ,
+which is the image of what the programmer wants the terminal to look like next.
+The user should not access
+.Vn curscr
+directly.
+Changes should be made to
+the appropriate screen,
+and then the routine
+.Fn refresh
+(or
+.Fn wrefresh )
+should be called.
+.pp
+Many functions are set up to deal with
+.Vn stdscr
+as a default screen.
+For example, to add a character to
+.Vn stdscr ,
+one calls
+.Fn addch
+with the desired character.
+If a different window is to be used,
+the routine
+.Fn waddch
+(for
+.b w indow-specific
+.Fn addch )
+is provided\**.
+.(f
+\**
+Actually,
+.Fn addch
+is really a
+.q #define
+macro with arguments,
+as are most of the "functions" which act upon
+.Vn stdscr .
+.)f
+This convention of prepending function names with a
+.Bq w
+when they are to be applied to specific windows
+is consistent.
+The only routines which do
+.i not
+do this are those
+to which a window must always be specified.
+.pp
+In order to move the current \*y from one point to another,
+the routines
+.Fn move
+and
+.Fn wmove
+are provided.
+However,
+it is often desirable to first move and then perform some I/O operation.
+In order to avoid clumsiness,
+most I/O routines can be preceded by the prefix
+.Bq mv
+and the desired \*y can then be added to the arguments to the function.
+For example,
+the calls
+.(l
+move(y\*,x);
+addch(ch);
+.)l
+can be replaced by
+.(l
+mvaddch(y\*,x\*,ch);
+.)l
+and
+.(l
+wmove(win\*,y\*,x);
+waddch(win\*,ch);
+.)l
+can be replaced by
+.(l
+mvwaddch(win\*,y\*,x\*,ch);
+.)l
+Note that the window description pointer
+.Vn win ) (
+comes before the added \*y.
+If a window pointer is needed, it is always the first parameter passed.
diff --git a/lib/libcurses/PSD.doc/intro.2 b/lib/libcurses/PSD.doc/intro.2
new file mode 100644
index 00000000000..d98c0c76198
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.2
@@ -0,0 +1,77 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.2 8.1 (Berkeley) 6/4/93
+.\"
+.sh 1 Variables
+.pp
+Many variables which are used to describe the terminal environment
+are available to the programmer. They are:
+.(b
+.TS
+expand;
+lw(6m) lw(8n) lw(50n).
+type name description
+_
+WINDOW * curscr T{
+.fi
+current version of the screen (terminal screen).
+T}
+WINDOW * stdscr T{
+standard screen. Most updates are usually done here.
+T}
+char * Def\*_term T{
+default terminal type if type cannot be determined
+T}
+bool My\*_term T{
+use the terminal specification in \fIDef\*_term\fR as terminal,
+irrelevant of real terminal type
+T}
+char * ttytype T{
+full name of the current terminal.
+T}
+int LINES T{
+number of lines on the terminal
+T}
+int COLS T{
+number of columns on the terminal
+T}
+int ERR T{
+error flag returned by routines on a fail.
+T}
+int OK T{
+flag returned by routines upon success.
+T}
+.TE
+.fi
+.ev
+.)b
+.lp
diff --git a/lib/libcurses/PSD.doc/intro.3 b/lib/libcurses/PSD.doc/intro.3
new file mode 100644
index 00000000000..d0ba9a2ab7b
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.3
@@ -0,0 +1,228 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.3 8.1 (Berkeley) 6/4/93
+.\"
+.sh 1 Usage
+.pp
+This is a description of how to actually use the screen package.
+For simplicity, we assume all updating, reading, etc.
+is applied to
+.Vn stdscr ,
+although a different window can of course be specified.
+.sh 2 "Initialization"
+.pp
+In order to use the screen package,
+the routines must know about terminal characteristics,
+and the space for
+.Vn curscr
+and
+.Vn stdscr
+must be allocated.
+These functions are performed by
+.Fn initscr .
+Since it must allocate space for the windows,
+it can overflow core when attempting to do so.
+On this rather rare occasion,
+.Fn initscr
+returns ERR.
+.Fn Initscr
+must
+.bi always
+be called before any of the routines which affect windows are used.
+If it is not,
+the program will core dump as soon as either
+.Vn curscr
+or
+.Vn stdscr
+are referenced.
+However, it is usually best to wait to call it
+until after you are sure you will need it,
+like after checking for startup errors.
+Terminal status changing routines
+like
+.Fn nl
+and
+.Fn cbreak
+should be called after
+.Fn initscr .
+.pp
+After the initial window allocation done by
+.Fn initscr ,
+specific window characteristics can be set.
+Scrolling can be enabled by calling
+.Fn scrollok .
+If you want the cursor to be left after the last change, use
+.Fn leaveok .
+If this isn't done,
+.Fn refresh
+will move the cursor to the window's current \*y after updating it.
+Additional windows can be created by using the functions
+.Fn newwin
+and
+.Fn subwin .
+.Fn Delwin
+allows you to delete an exisiting window.
+The variables
+.Vn LINES
+and
+.Vn COLS
+control the size of the terminal. They are initially implicitly set by
+.Fn initscr ,
+but can be altered explicitly by the user followed by a call to
+.Fn initscr .
+Note that any call to
+.Fn initscr ,
+will always delete any existing
+.Vn stdscr
+and/or
+.Vn curscr
+before creating new ones so this change is best done before the initial call to
+.Fn initscr .
+.pp
+.sh 2 "Output"
+.pp
+The basic functions
+used to change what will go on a window are
+.Fn addch
+and
+.Fn move .
+.Fn Addch
+adds a character at the current \*y,
+returning ERR if it would cause the window to illegally scroll,
+.i i.e. ,
+printing a character in the lower right-hand corner
+of a terminal which automatically scrolls
+if scrolling is not allowed.
+.Fn Move
+changes the current \*y to whatever you want them to be.
+It returns ERR if you try to move off the window.
+As mentioned above, you can combine the two into
+.Fn mvaddch
+to do both things in one call.
+.pp
+The other output functions
+(such as
+.Fn addstr
+and
+.Fn printw )
+all call
+.Fn addch
+to add characters to the window.
+.pp
+After a change has been made to the window,
+you must call
+.Fn refresh .
+when you want the portion of the terminal covered by the window
+to reflect the change.
+In order to optimize finding changes,
+.Fn refresh
+assumes that any part of the window not changed
+since the last
+.Fn refresh
+of that window has not been changed on the terminal,
+.i i.e. ,
+that you have not refreshed a portion of the terminal
+with an overlapping window.
+If this is not the case,
+the routines
+.Fn touchwin ,
+.Fn touchline ,
+and
+.Fn touchoverlap
+are provided to make it look like a desired part of window has been changed,
+thus forcing
+.Fn refresh
+to check that whole subsection of the terminal for changes.
+.pp
+If you call
+.Fn wrefresh
+with
+.Vn curscr ,
+it will make the screen look like the image of
+.Vn curscr .
+This is useful for implementing a command
+which would redraw the screen in case it got messed up.
+.sh 2 Input
+.pp
+Input is essentially a mirror image of output.
+The complementary function to
+.Fn addch
+is
+.Fn getch
+which,
+if echo is set,
+will call
+.Fn addch
+to echo the character.
+Since the screen package needs to know what is on the terminal at all times,
+if characters are to be echoed,
+the tty must be in raw or cbreak mode.
+If it is not,
+.Fn getch
+sets it to be cbreak,
+and then reads in the character.
+.sh 2 "Termination"
+.pp
+In order to perform certain optimizations,
+and,
+on some terminals,
+to work at all,
+some things must be done
+before the screen routines start up.
+These functions are performed in
+.Fn getttmode
+and
+.Fn setterm ,
+which are called by
+.Fn initscr .
+In order to clean up after the routines,
+the routine
+.Fn endwin
+is provided.
+It restores tty modes to what they were
+when
+.Fn initscr
+was first called.
+The terminal state module uses the variable
+.Vn curses_termios
+to save the original terminal state which is then restored upon a call to
+.Fn endwin .
+Thus,
+anytime after the call to initscr,
+.Fn endwin
+should be called before exiting. Note however, that
+.Fn endwin
+should always be called
+.b before
+the final calls to
+.Fn delwin ,
+which free the storage of the windows.
diff --git a/lib/libcurses/PSD.doc/intro.4 b/lib/libcurses/PSD.doc/intro.4
new file mode 100644
index 00000000000..9e529822c5d
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.4
@@ -0,0 +1,69 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.4 8.1 (Berkeley) 6/4/93
+.\"
+.sh 1 "Cursor Movement Optimizations"
+.pp
+One of the most difficult things to do properly is motion optimization.
+After using
+.Fn gettmode
+and
+.Fn setterm
+to get the terminal descriptions,
+the function
+.Fn mvcur
+deals with this task.
+It usage is simple:
+simply tell it where you are now and where you want to go.
+For example
+.(l
+mvcur(0\*,0\*,LINES/2\*,COLS/2);
+.)l
+.lp
+would move the cursor from the home position (0\*,0)
+to the middle of the screen.
+If you wish to force absolute addressing,
+you can use the function
+.Fn tgoto
+from the
+.b termlib (7)
+routines,
+or you can tell
+.Fn mvcur
+that you are impossibly far away,
+For example,
+to absolutely address the lower left hand corner of the screen
+from anywhere
+just claim that you are in the upper right hand corner:
+.(l
+mvcur(0\*,COLS\-1\*,LINES\-1\*,0);
+.)l
diff --git a/lib/libcurses/PSD.doc/intro.5 b/lib/libcurses/PSD.doc/intro.5
new file mode 100644
index 00000000000..d0f96575b4b
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.5
@@ -0,0 +1,87 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.5 8.1 (Berkeley) 6/4/93
+.\"
+.sh 1 "Character Output and Scrolling"
+.pp
+The character output policy deals with the following problems. First,
+where is the location of the cursor after a character is printed, and
+secondly, when does the screen scroll if scrolling is enabled.
+.pp
+In the normal case the characters are output as expected, with the cursor
+occupying the position of the next character to be output. However, when the
+cursor is on the last column of the line, the cursor will remain on that
+position after the last character on the line is output and will only assume
+the position on the next line when the next character (the first on the next
+line) is output.
+.pp
+Likewise, if scrolling is enabled, a scroll will be invoked only when the
+first character on he first line past the bottom line of the window is
+output. If scrolling is not enabled the chracters will to be output to the
+bottom right corner of the window which is the cursor location.
+.pp
+This policy allows consistent behavior of the cursor at the boundary
+conditions. Furthermore, it prevents a scroll from happening before it is
+actually needed (the old package used to scroll when the bottom right position
+was output a character). As a precendent, it models the
+.i xterm
+character output conventions.
+.sh 1 "Terminal State Handling"
+.pp
+The variable
+.Vn curses_termios
+contains the terminal state of the terminal. Certain historical routines
+return information:
+.Fn baudrate ,
+.Fn erasechar ,
+.Fn killchar ,
+and
+.Fn ospeed .
+These routines are obsolete and exist only for backward compatibility. If
+you wish to use the information in the
+.Vn curses_termios
+structure, you should use the
+\fItsetattr\fP(3)
+routines.
+.sh 1 "Subwindows"
+.pp
+Subwindows are windows which do not have an independent text structure,
+.i i.e. ,
+they are windows whose text is a subset of the text of a larger window: the
+.i parent
+window. One consequence of this is that changes to either the parent or the
+child window are destructive to the other,
+.i i.e. ,
+a change to the subwindow is also a change to the parent window and a change
+to the parent window in the region defined by the subwindow is implicitly a
+change to the subwindow as well.
+Apart from this detail, subwindows function like any other window.
diff --git a/lib/libcurses/PSD.doc/intro.6 b/lib/libcurses/PSD.doc/intro.6
new file mode 100644
index 00000000000..7c4560dc33a
--- /dev/null
+++ b/lib/libcurses/PSD.doc/intro.6
@@ -0,0 +1,44 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)intro.6 8.1 (Berkeley) 6/4/93
+.\"
+.sh 1 "The Functions"
+.pp
+In the following definitions,
+.q \*m
+means that the
+.q function
+is really a
+.q #define
+macro with arguments.
+.ta 11m 17m 25m 33m 41m 49m 57m 65m 73m
+.so fns.doc
diff --git a/lib/libcurses/PSD.doc/life.c b/lib/libcurses/PSD.doc/life.c
new file mode 100644
index 00000000000..72febba29ae
--- /dev/null
+++ b/lib/libcurses/PSD.doc/life.c
@@ -0,0 +1,163 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)life.c 8.1 (Berkeley) 6/8/93
+.\"
+# include <curses.h>
+# include <signal.h>
+
+/*
+ * Run a life game. This is a demonstration program for
+ * the Screen Updating section of the -lcurses cursor package.
+ */
+
+typedef struct lst_st { /* linked list element */
+ int y, x; /* (y, x) position of piece */
+ struct lst_st *next, *last; /* doubly linked */
+} LIST;
+
+LIST *Head; /* head of linked list */
+
+int die();
+
+main(ac, av)
+int ac;
+char *av[];
+{
+ evalargs(ac, av); /* evaluate arguments */
+
+ initscr(); /* initialize screen package */
+ signal(SIGINT, die); /* set to restore tty stats */
+ cbreak(); /* set for char-by-char */
+ noecho(); /* input */
+ nonl(); /* for optimization */
+
+ getstart(); /* get starting position */
+ for (;;) {
+ prboard(); /* print out current board */
+ update(); /* update board position */
+ }
+}
+
+/*
+ * This is the routine which is called when rubout is hit.
+ * It resets the tty stats to their original values. This
+ * is the normal way of leaving the program.
+ */
+die()
+{
+ signal(SIGINT, SIG_IGN); /* ignore rubouts */
+ mvcur(0, COLS - 1, LINES - 1, 0); /* go to bottom of screen */
+ endwin(); /* set terminal to good state */
+ exit(0);
+}
+
+/*
+ * Get the starting position from the user. They keys u, i, o, j, l,
+ * m, ,, and . are used for moving their relative directions from the
+ * k key. Thus, u move diagonally up to the left, , moves directly down,
+ * etc. x places a piece at the current position, " " takes it away.
+ * The input can also be from a file. The list is built after the
+ * board setup is ready.
+ */
+getstart()
+{
+ reg char c;
+ reg int x, y;
+ auto char buf[100];
+
+ box(stdscr, '|', '_'); /* box in the screen */
+ move(1, 1); /* move to upper left corner */
+
+ for (;;) {
+ refresh(); /* print current position */
+ if ((c = getch()) == 'q')
+ break;
+ switch (c) {
+ case 'u':
+ case 'i':
+ case 'o':
+ case 'j':
+ case 'l':
+ case 'm':
+ case ',':
+ case '.':
+ adjustyx(c);
+ break;
+ case 'f':
+ mvaddstr(0, 0, "File name: ");
+ getstr(buf);
+ readfile(buf);
+ break;
+ case 'x':
+ addch('X');
+ break;
+ case ' ':
+ addch(' ');
+ break;
+ }
+ }
+
+ if (Head != NULL) /* start new list */
+ dellist(Head);
+ Head = malloc(sizeof (LIST));
+
+ /*
+ * loop through the screen looking for 'x's, and add a list
+ * element for each one
+ */
+ for (y = 1; y < LINES - 1; y++)
+ for (x = 1; x < COLS - 1; x++) {
+ move(y, x);
+ if (inch() == 'x')
+ addlist(y, x);
+ }
+}
+
+/*
+ * Print out the current board position from the linked list
+ */
+prboard() {
+
+ reg LIST *hp;
+
+ erase(); /* clear out last position */
+ box(stdscr, '|', '_'); /* box in the screen */
+
+ /*
+ * go through the list adding each piece to the newly
+ * blank board
+ */
+ for (hp = Head; hp; hp = hp->next)
+ mvaddch(hp->y, hp->x, 'X');
+
+ refresh();
+}
diff --git a/lib/libcurses/PSD.doc/macros b/lib/libcurses/PSD.doc/macros
new file mode 100644
index 00000000000..b7f3abf793e
--- /dev/null
+++ b/lib/libcurses/PSD.doc/macros
@@ -0,0 +1,144 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)macros 8.1 (Berkeley) 8/14/93
+.\"
+.\" this is the uncommented version. The commented one is in "macros.coms"
+.ie t .ds _ \d\(mi\u
+.el .ds _ _
+.ds , ,\
+.ds y (y\*,x) co-ordinates
+.ds db database
+.ie n .ds f \fI
+.el .ds f \fB
+.ds tc \*ftermcap\fP(5)
+.ds Es This returns ERR if it would cause the screen to scroll illegally.
+.ds Nm This has no associated \*(lq\fBmv\fP\*(rq command.
+.ie t .ds m \fB\s-2\(dg\s+2\fP
+.el .ds m [*]
+.\" .hy WINDOW
+.\".he ''\*(Ln''
+.\".fo ''\- % \-''
+.oh '\*(Ln''PS1:19-%'
+.eh 'PS1:19-%''\*(Ln'
+.de Un
+.b
+\s-2\\$2UNIX\\$1\s+2
+.ft
+..
+.de Ds
+.sp
+.lp
+.ev 1
+.nf
+.ft I
+.in 0
+.di Df
+..
+.de De
+.di
+.Df
+.ne \n(dn+2
+.ev
+.ip
+..
+.de Dg
+.di
+.Df
+.ne \n(dn+2
+.ev
+..
+.de Fd
+.br
+\&\\$4
+.fi
+.b
+\&\\$1(\\$2)
+.ft
+\&\\$3
+.br
+.nf
+..
+.de Vn
+\&\\$3\c
+.i "\\$1" \\$2
+..
+.de Bq
+.ie t \&\*(lq\fB\\$1\fP\*(rq
+.el \&\*(lq\fI\\$1\fP\*(rq
+..
+.de $0
+.(x
+.in \\n(Xs
+\\*($n \\$1
+.)x
+..
+.de $1
+.nr Xs 0
+..
+.de $2
+.nr Xs 3
+..
+.de $3
+.nr Xs 6
+..
+.de Fn
+.if \\n(.$==0 .tm error
+.nr ll 0
+.nr dg 0
+.ft R
+.if '\\$\\n(.$'.' .nr ll 1
+.if '\\$\\n(.$',' .nr ll 1
+.if '\\$\\n(.$')' .nr ll 1
+.if '\\$\\n(.$').' .nr ll 1
+.if '\\$\\n(.$';' .nr ll 1
+.if '\\$\\n(.$':' .nr ll 1
+.if '\\$\\n(.$'\'s' .nr ll 1
+.if '\\$\\n(.$'\(dg' .nr ll 1
+.\" .if '\\$\\n(.$'' .nr ll 1
+.nr al \\n(.$-\\n(ll
+.ds ot \f(CB\\$1\fP(
+.if \\n(al>1 .as ot \fI\\$2\fP
+.if \\n(al>2 .as ot ", \fI\\$3\fP
+.if \\n(al>3 .as ot ", \fI\\$4\fP
+.if \\n(al>4 .as ot ", \fI\\$5\fP
+.if \\n(al>5 .as ot ", \fI\\$6\fP
+.if \\n(al>6 .as ot ", \fI\\$7\fP
+.if \\n(al>7 .as ot ", \fI\\$8\fP
+.if \\n(al>8 .as ot ", \fI\\$9\fP
+.as ot )
+.if \\n(.$>1 \{\
+. if \\n(ll==0 .as ot ;
+. if '\\$\\n(.$'\(dg' .as ot ;
+.\}
+.if \\n(ll==1 .as ot \\$\\n(.$
+\\*(ot
+..
diff --git a/lib/libcurses/PSD.doc/twinkle1.c b/lib/libcurses/PSD.doc/twinkle1.c
new file mode 100644
index 00000000000..7d3d00db203
--- /dev/null
+++ b/lib/libcurses/PSD.doc/twinkle1.c
@@ -0,0 +1,157 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)twinkle1.c 8.1 (Berkeley) 6/8/93
+.\"
+# include <curses.h>
+# include <signal.h>
+
+/*
+ * the idea for this program was a product of the imagination of
+ * Kurt Schoens. Not responsible for minds lost or stolen.
+ */
+
+# define NCOLS 80
+# define NLINES 24
+# define MAXPATTERNS 4
+
+typedef struct {
+ int y, x;
+} LOCS;
+
+LOCS Layout[NCOLS * NLINES]; /* current board layout */
+
+int Pattern, /* current pattern number */
+ Numstars; /* number of stars in pattern */
+
+char *getenv();
+
+int die();
+
+main()
+{
+ srand(getpid()); /* initialize random sequence */
+
+ initscr();
+ signal(SIGINT, die);
+ noecho();
+ nonl();
+ leaveok(stdscr, TRUE);
+ scrollok(stdscr, FALSE);
+
+ for (;;) {
+ makeboard(); /* make the board setup */
+ puton('*'); /* put on '*'s */
+ puton(' '); /* cover up with ' 's */
+ }
+}
+
+/*
+ * On program exit, move the cursor to the lower left corner by
+ * direct addressing, since current location is not guaranteed.
+ * We lie and say we used to be at the upper right corner to guarantee
+ * absolute addressing.
+ */
+die()
+{
+ signal(SIGINT, SIG_IGN);
+ mvcur(0, COLS - 1, LINES - 1, 0);
+ endwin();
+ exit(0);
+}
+
+
+/*
+ * Make the current board setup. It picks a random pattern and
+ * calls ison() to determine if the character is on that pattern
+ * or not.
+ */
+makeboard()
+{
+ reg int y, x;
+ reg LOCS *lp;
+
+ Pattern = rand() % MAXPATTERNS;
+ lp = Layout;
+ for (y = 0; y < NLINES; y++)
+ for (x = 0; x < NCOLS; x++)
+ if (ison(y, x)) {
+ lp->y = y;
+ lp->x = x;
+ lp++;
+ }
+ Numstars = lp - Layout;
+}
+
+/*
+ * Return TRUE if (y, x) is on the current pattern.
+ */
+ison(y, x)
+reg int y, x; {
+
+ switch (Pattern) {
+ case 0: /* alternating lines */
+ return !(y & 01);
+ case 1: /* box */
+ if (x >= LINES && y >= NCOLS)
+ return FALSE;
+ if (y < 3 || y >= NLINES - 3)
+ return TRUE;
+ return (x < 3 || x >= NCOLS - 3);
+ case 2: /* holy pattern! */
+ return ((x + y) & 01);
+ case 3: /* bar across center */
+ return (y >= 9 && y <= 15);
+ }
+ /* NOTREACHED */
+}
+
+puton(ch)
+reg char ch;
+{
+ reg LOCS *lp;
+ reg int r;
+ reg LOCS *end;
+ LOCS temp;
+
+ end = &Layout[Numstars];
+ for (lp = Layout; lp < end; lp++) {
+ r = rand() % Numstars;
+ temp = *lp;
+ *lp = Layout[r];
+ Layout[r] = temp;
+ }
+
+ for (lp = Layout; lp < end; lp++) {
+ mvaddch(lp->y, lp->x, ch);
+ refresh();
+ }
+}
diff --git a/lib/libcurses/PSD.doc/twinkle2.c b/lib/libcurses/PSD.doc/twinkle2.c
new file mode 100644
index 00000000000..0a25590fcde
--- /dev/null
+++ b/lib/libcurses/PSD.doc/twinkle2.c
@@ -0,0 +1,96 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)twinkle2.c 8.1 (Berkeley) 6/8/93
+.\"
+extern int _putchar();
+
+main()
+{
+ reg char *sp;
+
+ srand(getpid()); /* initialize random sequence */
+
+ if (isatty(0)) {
+ gettmode();
+ if ((sp = getenv("TERM")) != NULL)
+ setterm(sp);
+ signal(SIGINT, die);
+ }
+ else {
+ printf("Need a terminal on %d\n", _tty_ch);
+ exit(1);
+ }
+ _puts(TI);
+ _puts(VS);
+
+ noecho();
+ nonl();
+ tputs(CL, NLINES, _putchar);
+ for (;;) {
+ makeboard(); /* make the board setup */
+ puton('*'); /* put on '*'s */
+ puton(' '); /* cover up with ' 's */
+ }
+}
+
+puton(ch)
+char ch;
+{
+ reg LOCS *lp;
+ reg int r;
+ reg LOCS *end;
+ LOCS temp;
+ static int lasty, lastx;
+
+ end = &Layout[Numstars];
+ for (lp = Layout; lp < end; lp++) {
+ r = rand() % Numstars;
+ temp = *lp;
+ *lp = Layout[r];
+ Layout[r] = temp;
+ }
+
+ for (lp = Layout; lp < end; lp++)
+ /* prevent scrolling */
+ if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
+ mvcur(lasty, lastx, lp->y, lp->x);
+ putchar(ch);
+ lasty = lp->y;
+ if ((lastx = lp->x + 1) >= NCOLS)
+ if (AM) {
+ lastx = 0;
+ lasty++;
+ }
+ else
+ lastx = NCOLS - 1;
+ }
+}
diff --git a/lib/libcurses/PSD.doc/win_st.c b/lib/libcurses/PSD.doc/win_st.c
new file mode 100644
index 00000000000..7790f6ca632
--- /dev/null
+++ b/lib/libcurses/PSD.doc/win_st.c
@@ -0,0 +1,58 @@
+.\" Copyright (c) 1980, 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.
+.\"
+.\" @(#)win_st.c 8.1 (Berkeley) 6/8/93
+.\"
+# define WINDOW struct _win_st
+
+struct _win_st {
+ short _cury, _curx;
+ short _maxy, _maxx;
+ short _begy, _begx;
+ short _flags;
+ short _ch_off;
+ bool _clear;
+ bool _leave;
+ bool _scroll;
+ char **_y;
+ short *_firstch;
+ short *_lastch;
+ struct _win_st *_nextp, *_orig;
+};
+
+# define _ENDLINE 001
+# define _FULLWIN 002
+# define _SCROLLWIN 004
+# define _FLUSH 010
+# define _FULLLINE 020
+# define _IDLINE 040
+# define _STANDOUT 0200
+# define _NOCHANGE -1
diff --git a/lib/libcurses/addbytes.c b/lib/libcurses/addbytes.c
new file mode 100644
index 00000000000..6dd8bf959b5
--- /dev/null
+++ b/lib/libcurses/addbytes.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 1987, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+#define SYNCH_IN {y = win->cury; x = win->curx;}
+#define SYNCH_OUT {win->cury = y; win->curx = x;}
+
+/*
+ * waddbytes --
+ * Add the character to the current position in the given window.
+ */
+int
+__waddbytes(win, bytes, count, so)
+ register WINDOW *win;
+ register const char *bytes;
+ register int count;
+ int so;
+{
+ static char blanks[] = " ";
+ register int c, newx, x, y;
+ char stand;
+ __LINE *lp;
+
+ SYNCH_IN;
+
+#ifdef DEBUG
+ __CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x);
+#endif
+ while (count--) {
+ c = *bytes++;
+ switch (c) {
+ case '\t':
+ SYNCH_OUT;
+ if (waddbytes(win, blanks, 8 - (x % 8)) == ERR)
+ return (ERR);
+ SYNCH_IN;
+ break;
+
+ default:
+#ifdef DEBUG
+ __CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
+#endif
+
+ lp = win->lines[y];
+ if (lp->flags & __ISPASTEOL) {
+ lp->flags &= ~__ISPASTEOL;
+newline: if (y == win->maxy - 1) {
+ if (win->flags & __SCROLLOK) {
+ SYNCH_OUT;
+ scroll(win);
+ SYNCH_IN;
+ lp = win->lines[y];
+ x = 0;
+ } else
+ return (ERR);
+ } else {
+ y++;
+ lp = win->lines[y];
+ x = 0;
+ }
+ if (c == '\n')
+ break;
+ }
+
+ stand = '\0';
+ if (win->flags & __WSTANDOUT || so)
+ stand |= __STANDOUT;
+#ifdef DEBUG
+ __CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
+ y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
+#endif
+ if (lp->line[x].ch != c ||
+ !(lp->line[x].attr & stand)) {
+ newx = x + win->ch_off;
+ if (!(lp->flags & __ISDIRTY)) {
+ lp->flags |= __ISDIRTY;
+ *lp->firstchp = *lp->lastchp = newx;
+ }
+ else if (newx < *lp->firstchp)
+ *lp->firstchp = newx;
+ else if (newx > *lp->lastchp)
+ *lp->lastchp = newx;
+#ifdef DEBUG
+ __CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
+ *lp->firstchp, *lp->lastchp,
+ *lp->firstchp - win->ch_off,
+ *lp->lastchp - win->ch_off);
+#endif
+ }
+ lp->line[x].ch = c;
+ if (stand)
+ lp->line[x].attr |= __STANDOUT;
+ else
+ lp->line[x].attr &= ~__STANDOUT;
+ if (x == win->maxx - 1)
+ lp->flags |= __ISPASTEOL;
+ else
+ x++;
+#ifdef DEBUG
+ __CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
+ y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
+#endif
+ break;
+ case '\n':
+ SYNCH_OUT;
+ wclrtoeol(win);
+ SYNCH_IN;
+ if (!NONL)
+ x = 0;
+ goto newline;
+ case '\r':
+ x = 0;
+ break;
+ case '\b':
+ if (--x < 0)
+ x = 0;
+ break;
+ }
+ }
+ SYNCH_OUT;
+ return (OK);
+}
diff --git a/lib/libcurses/addch.c b/lib/libcurses/addch.c
new file mode 100644
index 00000000000..d5f30014c02
--- /dev/null
+++ b/lib/libcurses/addch.c
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)addch.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * waddch --
+ * Add the character to the current position in the given window.
+ *
+ */
+int
+waddch(win, ch)
+ WINDOW *win;
+ int ch;
+{
+ __LDATA buf;
+
+ buf.ch = ch;
+ buf.attr = 0;
+ return (__waddch(win, &buf));
+}
+
+int
+__waddch(win, dp)
+ WINDOW *win;
+ __LDATA *dp;
+{
+ char buf[2];
+
+ buf[0] = dp->ch;
+ return (__waddbytes(win, buf, 1, dp->attr & __STANDOUT));
+}
diff --git a/lib/libcurses/addnstr.c b/lib/libcurses/addnstr.c
new file mode 100644
index 00000000000..92a6e681a54
--- /dev/null
+++ b/lib/libcurses/addnstr.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)addnstr.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * waddnstr --
+ * Add a string (at most n characters) to the given window
+ * starting at (_cury, _curx). If n is negative, add the
+ * entire string.
+ */
+int
+waddnstr(win, s, n)
+ WINDOW *win;
+ const char *s;
+ int n;
+{
+ size_t len;
+ const char *p;
+
+ if (n > 0)
+ for (p = s, len = 0; n-- && *p++; ++len);
+ else
+ len = strlen(s);
+ return (waddbytes(win, s, len));
+}
diff --git a/lib/libcurses/box.c b/lib/libcurses/box.c
new file mode 100644
index 00000000000..191e37cfd82
--- /dev/null
+++ b/lib/libcurses/box.c
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)box.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * box --
+ * Draw a box around the given window with "vert" as the vertical
+ * delimiting char, and "hor", as the horizontal one.
+ */
+int
+box(win, vert, hor)
+ register WINDOW *win;
+ int vert, hor;
+{
+ register int endy, endx, i;
+ register __LDATA *fp, *lp;
+
+ endx = win->maxx;
+ endy = win->maxy - 1;
+ fp = win->lines[0]->line;
+ lp = win->lines[endy]->line;
+ for (i = 0; i < endx; i++) {
+ fp[i].ch = lp[i].ch = hor;
+ fp[i].attr &= ~__STANDOUT;
+ lp[i].attr &= ~__STANDOUT;
+ }
+ endx--;
+ for (i = 0; i <= endy; i++) {
+ win->lines[i]->line[0].ch = vert;
+ win->lines[i]->line[endx].ch = vert;
+ win->lines[i]->line[0].attr &= ~__STANDOUT;
+ win->lines[i]->line[endx].attr &= ~__STANDOUT;
+ }
+ if (!(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN)) {
+ fp[0].ch = fp[endx].ch = lp[0].ch = lp[endx].ch = ' ';
+ fp[0].attr &= ~__STANDOUT;
+ fp[endx].attr &= ~__STANDOUT;
+ lp[0].attr &= ~__STANDOUT;
+ lp[endx].attr &= ~__STANDOUT;
+ }
+ __touchwin(win);
+ return (OK);
+}
diff --git a/lib/libcurses/clear.c b/lib/libcurses/clear.c
new file mode 100644
index 00000000000..54c0b30d3cf
--- /dev/null
+++ b/lib/libcurses/clear.c
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)clear.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wclear --
+ * Clear the window.
+ */
+int
+wclear(win)
+ register WINDOW *win;
+{
+ if (werase(win) == OK) {
+ win->flags |= __CLEAROK;
+ return (OK);
+ }
+ return (ERR);
+}
diff --git a/lib/libcurses/clrtobot.c b/lib/libcurses/clrtobot.c
new file mode 100644
index 00000000000..81ee6a4603a
--- /dev/null
+++ b/lib/libcurses/clrtobot.c
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)clrtobot.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wclrtobot --
+ * Erase everything on the window.
+ */
+int
+wclrtobot(win)
+ register WINDOW *win;
+{
+ register int minx, startx, starty, y;
+ register __LDATA *sp, *end, *maxx;
+
+ if (win->lines[win->cury]->flags & __ISPASTEOL) {
+ starty = win->cury + 1;
+ startx = 0;
+ } else {
+ starty = win->cury;
+ startx = win->curx;
+ }
+ for (y = starty; y < win->maxy; y++) {
+ minx = -1;
+ end = &win->lines[y]->line[win->maxx];
+ for (sp = &win->lines[y]->line[startx]; sp < end; sp++)
+ if (sp->ch != ' ' || sp->attr != 0) {
+ maxx = sp;
+ if (minx == -1)
+ minx = sp - win->lines[y]->line;
+ sp->ch = ' ';
+ sp->attr = 0;
+ }
+ if (minx != -1)
+ __touchline(win, y, minx, maxx - win->lines[y]->line,
+ 0);
+ startx = 0;
+ }
+ return (OK);
+}
diff --git a/lib/libcurses/clrtoeol.c b/lib/libcurses/clrtoeol.c
new file mode 100644
index 00000000000..44fc190fee3
--- /dev/null
+++ b/lib/libcurses/clrtoeol.c
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)clrtoeol.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wclrtoeol --
+ * Clear up to the end of line.
+ */
+int
+wclrtoeol(win)
+ register WINDOW *win;
+{
+ register int minx, x, y;
+ register __LDATA *end, *maxx, *sp;
+
+ y = win->cury;
+ x = win->curx;
+ if (win->lines[y]->flags & __ISPASTEOL) {
+ if (y < win->maxy - 1) {
+ y++;
+ x = 0;
+ } else
+ return (OK);
+ }
+ end = &win->lines[y]->line[win->maxx];
+ minx = -1;
+ maxx = &win->lines[y]->line[x];
+ for (sp = maxx; sp < end; sp++)
+ if (sp->ch != ' ' || sp->attr != 0) {
+ maxx = sp;
+ if (minx == -1)
+ minx = sp - win->lines[y]->line;
+ sp->ch = ' ';
+ sp->attr = 0;
+ }
+#ifdef DEBUG
+ __CTRACE("CLRTOEOL: minx = %d, maxx = %d, firstch = %d, lastch = %d\n",
+ minx, maxx - win->lines[y]->line, *win->lines[y]->firstchp,
+ *win->lines[y]->lastchp);
+#endif
+ /* Update firstch and lastch for the line. */
+ return (__touchline(win, y, x, win->maxx - 1, 0));
+}
+
+
+
+
+
diff --git a/lib/libcurses/cr_put.c b/lib/libcurses/cr_put.c
new file mode 100644
index 00000000000..ada2df5ca1e
--- /dev/null
+++ b/lib/libcurses/cr_put.c
@@ -0,0 +1,432 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)cr_put.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+#define HARDTABS 8
+
+/*
+ * Terminal driving and line formatting routines. Basic motion optimizations
+ * are done here as well as formatting lines (printing of control characters,
+ * line numbering and the like).
+ */
+
+/* Stub function for the users. */
+int
+mvcur(ly, lx, y, x)
+ int ly, lx, y, x;
+{
+ return (__mvcur(ly, lx, y, x, 0));
+}
+
+static void fgoto __P((int));
+static int plod __P((int, int));
+static void plodput __P((int));
+static int tabcol __P((int, int));
+
+static int outcol, outline, destcol, destline;
+
+/*
+ * Sync the position of the output cursor. 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 destline on the screen.
+ */
+int
+__mvcur(ly, lx, y, x, in_refresh)
+ int ly, lx, y, x, in_refresh;
+{
+#ifdef DEBUG
+ __CTRACE("mvcur: moving cursor from (%d, %d) to (%d, %d)\n",
+ ly, lx, y, x);
+#endif
+ destcol = x;
+ destline = y;
+ outcol = lx;
+ outline = ly;
+ fgoto(in_refresh);
+ return (OK);
+}
+
+static void
+fgoto(in_refresh)
+ int in_refresh;
+{
+ register int c, l;
+ register char *cgp;
+
+ if (destcol >= COLS) {
+ destline += destcol / COLS;
+ destcol %= COLS;
+ }
+ if (outcol >= COLS) {
+ l = (outcol + 1) / COLS;
+ outline += l;
+ outcol %= COLS;
+ if (AM == 0) {
+ while (l > 0) {
+ if (__pfast)
+ if (CR)
+ tputs(CR, 0, __cputchar);
+ else
+ putchar('\r');
+ if (NL)
+ tputs(NL, 0, __cputchar);
+ else
+ putchar('\n');
+ l--;
+ }
+ outcol = 0;
+ }
+ if (outline > LINES - 1) {
+ destline -= outline - (LINES - 1);
+ outline = LINES - 1;
+ }
+ }
+ if (destline >= LINES) {
+ l = destline;
+ destline = LINES - 1;
+ if (outline < LINES - 1) {
+ c = destcol;
+ if (__pfast == 0 && !CA)
+ destcol = 0;
+ fgoto(in_refresh);
+ destcol = c;
+ }
+ while (l >= LINES) {
+ /* The following linefeed (or simulation thereof) is
+ * supposed to scroll up the screen, since we are on
+ * the bottom line. We make the assumption that
+ * linefeed will scroll. If ns is in the capability
+ * list this won't work. We should probably have an
+ * sc capability but sf will generally take the place
+ * if it works.
+ *
+ * Superbee glitch: in the middle of the screen have
+ * to use esc B (down) because linefeed screws up in
+ * "Efficient Paging" (what a joke) mode (which is
+ * essential in some SB's because CRLF mode puts
+ * garbage in at end of memory), but you must use
+ * linefeed to scroll since down arrow won't go past
+ * memory end. I turned this off after recieving Paul
+ * Eggert's Superbee description which wins better.
+ */
+ if (NL /* && !XB */ && __pfast)
+ tputs(NL, 0, __cputchar);
+ else
+ putchar('\n');
+ l--;
+ if (__pfast == 0)
+ outcol = 0;
+ }
+ }
+ if (destline < outline && !(CA || UP))
+ destline = outline;
+ if (CA) {
+ cgp = tgoto(CM, destcol, destline);
+
+ /*
+ * Need this condition due to inconsistent behavior
+ * of backspace on the last column.
+ */
+ if (outcol != COLS - 1 && plod(strlen(cgp), in_refresh) > 0)
+ plod(0, in_refresh);
+ else
+ tputs(cgp, 0, __cputchar);
+ } else
+ plod(0, in_refresh);
+ outline = destline;
+ outcol = destcol;
+}
+/*
+ * Move (slowly) to destination.
+ * Hard thing here is using home cursor on really deficient terminals.
+ * Otherwise just use cursor motions, hacking use of tabs and overtabbing
+ * and backspace.
+ */
+
+static int plodcnt, plodflg;
+
+static void
+plodput(c)
+ int c;
+{
+ if (plodflg)
+ --plodcnt;
+ else
+ putchar(c);
+}
+
+static int
+plod(cnt, in_refresh)
+ int cnt, in_refresh;
+{
+ register int i, j, k, soutcol, soutline;
+
+ plodcnt = plodflg = cnt;
+ soutcol = outcol;
+ soutline = outline;
+ /*
+ * Consider homing and moving down/right from there, vs. moving
+ * directly with local motions to the right spot.
+ */
+ if (HO) {
+ /*
+ * i is the cost to home and tab/space to the right to get to
+ * the proper column. This assumes ND space costs 1 char. So
+ * i + destcol is cost of motion with home.
+ */
+ if (GT)
+ i = (destcol / HARDTABS) + (destcol % HARDTABS);
+ else
+ i = destcol;
+
+ /* j is cost to move locally without homing. */
+ if (destcol >= outcol) { /* if motion is to the right */
+ j = destcol / HARDTABS - outcol / HARDTABS;
+ if (GT && j)
+ j += destcol % HARDTABS;
+ else
+ j = destcol - outcol;
+ } else
+ /* leftward motion only works if we can backspace. */
+ if (outcol - destcol <= i && (BS || BC))
+ /* Cheaper to backspace. */
+ i = j = outcol - destcol;
+ else
+ /* Impossibly expensive. */
+ j = i + 1;
+
+ /* k is the absolute value of vertical distance. */
+ k = outline - destline;
+ if (k < 0)
+ k = -k;
+ j += k;
+
+ /* Decision. We may not have a choice if no UP. */
+ if (i + destline < j || (!UP && destline < outline)) {
+ /*
+ * Cheaper to home. Do it now and pretend it's a
+ * regular local motion.
+ */
+ tputs(HO, 0, plodput);
+ outcol = outline = 0;
+ } else if (LL) {
+ /*
+ * Quickly consider homing down and moving from there.
+ * Assume cost of LL is 2.
+ */
+ k = (LINES - 1) - destline;
+ if (i + k + 2 < j && (k <= 0 || UP)) {
+ tputs(LL, 0, plodput);
+ outcol = 0;
+ outline = LINES - 1;
+ }
+ }
+ } else
+ /* No home and no up means it's impossible. */
+ if (!UP && destline < outline)
+ return (-1);
+ if (GT)
+ i = destcol % HARDTABS + destcol / HARDTABS;
+ else
+ i = destcol;
+#ifdef notdef
+ if (BT && outcol > destcol &&
+ (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) {
+ j *= (k = strlen(BT));
+ if ((k += (destcol&7)) > 4)
+ j += 8 - (destcol&7);
+ else
+ j += k;
+ }
+ else
+#endif
+ j = outcol - destcol;
+
+ /*
+ * If we will later need a \n which will turn into a \r\n by the
+ * system or the terminal, then don't bother to try to \r.
+ */
+ if ((NONL || !__pfast) && outline < destline)
+ goto dontcr;
+
+ /*
+ * If the terminal will do a \r\n and there isn't room for it, then
+ * we can't afford a \r.
+ */
+ if (NC && outline >= destline)
+ goto dontcr;
+
+ /*
+ * If it will be cheaper, or if we can't back up, then send a return
+ * preliminarily.
+ */
+ if (j > i + 1 || outcol > destcol && !BS && !BC) {
+ /*
+ * BUG: this doesn't take the (possibly long) length of CR
+ * into account.
+ */
+ if (CR)
+ tputs(CR, 0, plodput);
+ else
+ plodput('\r');
+ if (NC) {
+ if (NL)
+ tputs(NL, 0, plodput);
+ else
+ plodput('\n');
+ outline++;
+ }
+ outcol = 0;
+ }
+
+dontcr: while (outline < destline) {
+ outline++;
+ if (NL)
+ tputs(NL, 0, plodput);
+ else
+ plodput('\n');
+ if (plodcnt < 0)
+ goto out;
+ if (NONL || __pfast == 0)
+ outcol = 0;
+ }
+ if (BT)
+ k = strlen(BT);
+ while (outcol > destcol) {
+ if (plodcnt < 0)
+ goto out;
+#ifdef notdef
+ if (BT && outcol - destcol > k + 4) {
+ tputs(BT, 0, plodput);
+ outcol--;
+ outcol &= ~7;
+ continue;
+ }
+#endif
+ outcol--;
+ if (BC)
+ tputs(BC, 0, plodput);
+ else
+ plodput('\b');
+ }
+ while (outline > destline) {
+ outline--;
+ tputs(UP, 0, plodput);
+ if (plodcnt < 0)
+ goto out;
+ }
+ if (GT && destcol - outcol > 1) {
+ for (;;) {
+ i = tabcol(outcol, HARDTABS);
+ if (i > destcol)
+ break;
+ if (TA)
+ tputs(TA, 0, plodput);
+ else
+ plodput('\t');
+ outcol = i;
+ }
+ if (destcol - outcol > 4 && i < COLS && (BC || BS)) {
+ if (TA)
+ tputs(TA, 0, plodput);
+ else
+ plodput('\t');
+ outcol = i;
+ while (outcol > destcol) {
+ outcol--;
+ if (BC)
+ tputs(BC, 0, plodput);
+ else
+ plodput('\b');
+ }
+ }
+ }
+ while (outcol < destcol) {
+ /*
+ * Move one char to the right. We don't use ND space because
+ * it's better to just print the char we are moving over.
+ */
+ if (in_refresh)
+ if (plodflg) /* Avoid a complex calculation. */
+ plodcnt--;
+ else {
+ i = curscr->lines[outline]->line[outcol].ch;
+ if ((curscr->lines[outline]->line[outcol].attr
+ & __STANDOUT) ==
+ (curscr->flags & __WSTANDOUT))
+ putchar(i);
+ else
+ goto nondes;
+ }
+ else
+nondes: if (ND)
+ tputs(ND, 0, plodput);
+ else
+ plodput(' ');
+ outcol++;
+ if (plodcnt < 0)
+ goto out;
+ }
+
+out: if (plodflg) {
+ outcol = soutcol;
+ outline = soutline;
+ }
+ return (plodcnt);
+}
+
+/*
+ * Return the column number that results from being in column col and
+ * hitting a tab, where tabs are set every ts columns. Work right for
+ * the case where col > COLS, even if ts does not divide COLS.
+ */
+static int
+tabcol(col, ts)
+ int col, ts;
+{
+ int offset;
+
+ if (col >= COLS) {
+ offset = COLS * (col / COLS);
+ col -= offset;
+ } else
+ offset = 0;
+ return (col + ts - (col % ts) + offset);
+}
diff --git a/lib/libcurses/ctrace.c b/lib/libcurses/ctrace.c
new file mode 100644
index 00000000000..4f53906cc5e
--- /dev/null
+++ b/lib/libcurses/ctrace.c
@@ -0,0 +1,76 @@
+/*-
+ * Copyright (c) 1992, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ctrace.c 8.2 (Berkeley) 10/5/93";
+#endif /* not lint */
+
+#ifdef DEBUG
+#include <stdio.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#ifndef TFILE
+#define TFILE "__curses.out"
+#endif
+
+static FILE *tracefp; /* Curses debugging file descriptor. */
+
+void
+#ifdef __STDC__
+__CTRACE(const char *fmt, ...)
+#else
+__CTRACE(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ if (tracefp == NULL)
+ tracefp = fopen(TFILE, "w");
+ if (tracefp == NULL)
+ return;
+ (void)vfprintf(tracefp, fmt, ap);
+ va_end(ap);
+ (void)fflush(tracefp);
+}
+#endif
diff --git a/lib/libcurses/cur_hash.c b/lib/libcurses/cur_hash.c
new file mode 100644
index 00000000000..ed47fe37333
--- /dev/null
+++ b/lib/libcurses/cur_hash.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1992, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+#include <sys/types.h>
+
+
+/*
+ * __hash() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436.
+ */
+u_int
+__hash(s, len)
+ char *s;
+ int len;
+{
+ register u_int h, g, i;
+
+ h = 0;
+ i = 0;
+ while (i < len) {
+ h = (h << 4) + s[i];
+ if (g = h & 0xf0000000) {
+ h = h ^ (g >> 24);
+ h = h ^ g;
+ }
+ i++;
+ }
+ return h;
+}
diff --git a/lib/libcurses/curses.3 b/lib/libcurses/curses.3
new file mode 100644
index 00000000000..ea0093b61ad
--- /dev/null
+++ b/lib/libcurses/curses.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/curses.c b/lib/libcurses/curses.c
new file mode 100644
index 00000000000..07cbb5b4afd
--- /dev/null
+++ b/lib/libcurses/curses.c
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)curses.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/* Private. */
+int __echoit = 1; /* If stty indicates ECHO. */
+int __pfast;
+int __rawmode = 0; /* If stty indicates RAW mode. */
+int __noqch = 0; /*
+ * If terminal doesn't have
+ * insert/delete line capabilities
+ * for quick change on refresh.
+ */
+char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, PC,
+ UL, XB, XN, XT, XS, XX;
+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;
+/*
+ * Public.
+ *
+ * XXX
+ * UPPERCASE isn't used by libcurses, and is left for backward
+ * compatibility only.
+ */
+WINDOW *curscr; /* Current screen. */
+WINDOW *stdscr; /* Standard screen. */
+int COLS; /* Columns on the screen. */
+int LINES; /* Lines on the screen. */
+int My_term = 0; /* Use Def_term regardless. */
+char *Def_term = "unknown"; /* Default terminal type. */
+char GT; /* Gtty indicates tabs. */
+char NONL; /* Term can't hack LF doing a CR. */
+char UPPERCASE; /* Terminal is uppercase only. */
diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h
new file mode 100644
index 00000000000..6862b67a7d8
--- /dev/null
+++ b/lib/libcurses/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 */
+ u_int flags;
+ u_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 */
+ u_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 *, ...));
+u_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/libcurses/delch.c
new file mode 100644
index 00000000000..b9cdc3140ed
--- /dev/null
+++ b/lib/libcurses/delch.c
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)delch.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * wdelch --
+ * Do an insert-char on the line, leaving (cury, curx) unchanged.
+ */
+int
+wdelch(win)
+ register WINDOW *win;
+{
+ register __LDATA *end, *temp1, *temp2;
+
+ end = &win->lines[win->cury]->line[win->maxx - 1];
+ temp1 = &win->lines[win->cury]->line[win->curx];
+ temp2 = temp1 + 1;
+ while (temp1 < end) {
+ (void)memcpy(temp1, temp2, sizeof(__LDATA));
+ temp1++, temp2++;
+ }
+ temp1->ch = ' ';
+ temp1->attr = 0;
+ __touchline(win, win->cury, win->curx, win->maxx - 1, 0);
+ return (OK);
+}
diff --git a/lib/libcurses/deleteln.c b/lib/libcurses/deleteln.c
new file mode 100644
index 00000000000..4cb08ea3794
--- /dev/null
+++ b/lib/libcurses/deleteln.c
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)deleteln.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * wdeleteln --
+ * Delete a line from the screen. It leaves (cury, curx) unchanged.
+ */
+int
+wdeleteln(win)
+ register WINDOW *win;
+{
+ register int y, i;
+ register __LINE *temp;
+
+#ifdef DEBUG
+ __CTRACE("deleteln: (%0.2o)\n", win);
+#endif
+ temp = win->lines[win->cury];
+ for (y = win->cury; y < win->maxy - 1; y++) {
+ win->lines[y]->flags &= ~__ISPASTEOL;
+ win->lines[y + 1]->flags &= ~__ISPASTEOL;
+ if (win->orig == NULL)
+ win->lines[y] = win->lines[y + 1];
+ else
+ (void) memcpy(win->lines[y]->line,
+ win->lines[y + 1]->line,
+ win->maxx * __LDATASIZE);
+ __touchline(win, y, 0, win->maxx - 1, 0);
+ }
+
+ if (win->orig == NULL)
+ win->lines[y] = temp;
+ else
+ temp = win->lines[y];
+
+ for(i = 0; i < win->maxx; i++) {
+ temp->line[i].ch = ' ';
+ temp->line[i].attr = 0;
+ }
+ __touchline(win, y, 0, win->maxx - 1, 0);
+ if (win->orig == NULL)
+ __id_subwins(win);
+ return (OK);
+}
diff --git a/lib/libcurses/delwin.c b/lib/libcurses/delwin.c
new file mode 100644
index 00000000000..7310db8588c
--- /dev/null
+++ b/lib/libcurses/delwin.c
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)delwin.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <stdlib.h>
+
+#include "curses.h"
+
+/*
+ * delwin --
+ * Delete a window and release it back to the system.
+ */
+int
+delwin(win)
+ register WINDOW *win;
+{
+
+ register WINDOW *wp, *np;
+
+ if (win->orig == NULL) {
+ /*
+ * If we are the original window, delete the space for all
+ * the subwindows, the line space and the window space.
+ */
+ free(win->lspace);
+ free(win->wspace);
+ free(win->lines);
+ wp = win->nextp;
+ while (wp != win) {
+ np = wp->nextp;
+ delwin(wp);
+ wp = np;
+ }
+ } else {
+ /*
+ * If we are a subwindow, take ourselves out of the list.
+ * NOTE: if we are a subwindow, the minimum list is orig
+ * followed by this subwindow, so there are always at least
+ * two windows in the list.
+ */
+ for (wp = win->nextp; wp->nextp != win; wp = wp->nextp)
+ continue;
+ wp->nextp = win->nextp;
+ }
+ free(win);
+ return (OK);
+}
diff --git a/lib/libcurses/erase.c b/lib/libcurses/erase.c
new file mode 100644
index 00000000000..42ca68a35a6
--- /dev/null
+++ b/lib/libcurses/erase.c
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)erase.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * werase --
+ * Erases everything on the window.
+ */
+int
+werase(win)
+ register WINDOW *win;
+{
+
+ register int minx, y;
+ register __LDATA *sp, *end, *start, *maxx;
+
+#ifdef DEBUG
+ __CTRACE("werase: (%0.2o)\n", win);
+#endif
+ for (y = 0; y < win->maxy; y++) {
+ minx = -1;
+ start = win->lines[y]->line;
+ end = &start[win->maxx];
+ for (sp = start; sp < end; sp++)
+ if (sp->ch != ' ' || sp->attr != 0) {
+ maxx = sp;
+ if (minx == -1)
+ minx = sp - start;
+ sp->ch = ' ';
+ sp->attr = 0;
+ }
+ if (minx != -1)
+ __touchline(win, y, minx, maxx - win->lines[y]->line,
+ 0);
+ }
+ return (OK);
+}
diff --git a/lib/libcurses/fullname.c b/lib/libcurses/fullname.c
new file mode 100644
index 00000000000..3d05e5d6ef8
--- /dev/null
+++ b/lib/libcurses/fullname.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1981, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)fullname.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+/*
+ * fullname --
+ * This routine fills in "def" with the full name of the terminal.
+ * This is assumed to be the last name in the list of aliases.
+ */
+char *
+fullname(bp, def)
+ register char *bp, *def;
+{
+ register char *cp;
+
+ *def = '\0'; /* In case no name. */
+
+ while (*bp && *bp != ':') {
+ cp = def; /* Start of answer. */
+ while (*bp && *bp != ':' && *bp != '|')
+ *cp++ = *bp++; /* Copy name over. */
+ *cp = '\0'; /* Zero end of name. */
+ if (*bp == '|')
+ bp++; /* Skip over '|' if that is case. */
+ }
+ return (def);
+}
diff --git a/lib/libcurses/getch.c b/lib/libcurses/getch.c
new file mode 100644
index 00000000000..6108229708d
--- /dev/null
+++ b/lib/libcurses/getch.c
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wgetch --
+ * Read in a character from the window.
+ */
+int
+wgetch(win)
+ register WINDOW *win;
+{
+ register int inp, weset;
+
+ if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN)
+ && win->curx == win->maxx - 1 && win->cury == win->maxy - 1)
+ return (ERR);
+#ifdef DEBUG
+ __CTRACE("wgetch: __echoit = %d, __rawmode = %d\n",
+ __echoit, __rawmode);
+#endif
+ if (__echoit && !__rawmode) {
+ cbreak();
+ weset = 1;
+ } else
+ weset = 0;
+
+ inp = getchar();
+#ifdef DEBUG
+ __CTRACE("wgetch got '%s'\n", unctrl(inp));
+#endif
+ if (__echoit) {
+ mvwaddch(curscr,
+ win->cury + win->begy, win->curx + win->begx, inp);
+ waddch(win, inp);
+ }
+ if (weset)
+ nocbreak();
+ return (inp);
+}
diff --git a/lib/libcurses/getstr.c b/lib/libcurses/getstr.c
new file mode 100644
index 00000000000..daf8e61b7fd
--- /dev/null
+++ b/lib/libcurses/getstr.c
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wgetstr --
+ * Get a string starting at (cury, curx).
+ */
+int
+wgetstr(win, str)
+ register WINDOW *win;
+ register char *str;
+{
+ while ((*str = wgetch(win)) != ERR && *str != '\n')
+ str++;
+ if (*str == ERR) {
+ *str = '\0';
+ return (ERR);
+ }
+ *str = '\0';
+ return (OK);
+}
diff --git a/lib/libcurses/id_subwins.c b/lib/libcurses/id_subwins.c
new file mode 100644
index 00000000000..3528348ff46
--- /dev/null
+++ b/lib/libcurses/id_subwins.c
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)id_subwins.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * __id_subwins --
+ * Re-sync the pointers to lines for all the subwindows.
+ */
+void
+__id_subwins(orig)
+ register WINDOW *orig;
+{
+ register WINDOW *win;
+ register int oy, realy, y;
+
+ realy = orig->begy + orig->cury;
+ for (win = orig->nextp; win != orig; win = win->nextp) {
+ /*
+ * If the window ends before our current position, don't need
+ * to do anything.
+ */
+ if (win->begy + win->maxy <= realy)
+ continue;
+
+ oy = orig->cury;
+ for (y = realy - win->begy; y < win->maxy; y++, oy++)
+ win->lines[y]->line =
+ &orig->lines[oy]->line[win->ch_off];
+ }
+}
diff --git a/lib/libcurses/idlok.c b/lib/libcurses/idlok.c
new file mode 100644
index 00000000000..4d3bb592697
--- /dev/null
+++ b/lib/libcurses/idlok.c
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)idlok.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * idlok --
+ * Turn on and off using insert/deleteln sequences for the
+ * given window.
+ */
+void
+idlok(win, bf)
+ WINDOW *win;
+ int bf;
+{
+ if (bf)
+ win->flags |= __IDLINE;
+ else
+ win->flags &= ~__IDLINE;
+}
diff --git a/lib/libcurses/initscr.c b/lib/libcurses/initscr.c
new file mode 100644
index 00000000000..1af8b6f34ea
--- /dev/null
+++ b/lib/libcurses/initscr.c
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)initscr.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <signal.h>
+#include <stdlib.h>
+
+#include "curses.h"
+
+/*
+ * initscr --
+ * Initialize the current and standard screen.
+ */
+WINDOW *
+initscr()
+{
+ register char *sp;
+
+#ifdef DEBUG
+ __CTRACE("initscr\n");
+#endif
+ __echoit = 1;
+ __pfast = __rawmode = __noqch = 0;
+
+ if (gettmode() == ERR)
+ return (NULL);
+
+ /*
+ * If My_term is set, or can't find a terminal in the environment,
+ * use Def_term.
+ */
+ if (My_term || (sp = getenv("TERM")) == NULL)
+ sp = Def_term;
+ if (setterm(sp) == ERR)
+ return (NULL);
+
+ /* Need either homing or cursor motion for refreshes */
+ if (!HO && !CM)
+ return (NULL);
+
+ if (curscr != NULL)
+ delwin(curscr);
+ if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
+ return (NULL);
+ clearok(curscr, 1);
+
+ if (stdscr != NULL)
+ delwin(stdscr);
+ if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
+ delwin(curscr);
+ return (NULL);
+ }
+
+ __set_stophandler();
+
+#ifdef DEBUG
+ __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
+#endif
+ __startwin();
+
+ return (stdscr);
+}
diff --git a/lib/libcurses/insch.c b/lib/libcurses/insch.c
new file mode 100644
index 00000000000..36cc0dee894
--- /dev/null
+++ b/lib/libcurses/insch.c
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * winsch --
+ * Do an insert-char on the line, leaving (cury, curx) unchanged.
+ */
+int
+winsch(win, ch)
+ register WINDOW *win;
+ int ch;
+{
+
+ register __LDATA *end, *temp1, *temp2;
+
+ end = &win->lines[win->cury]->line[win->curx];
+ temp1 = &win->lines[win->cury]->line[win->maxx - 1];
+ temp2 = temp1 - 1;
+ while (temp1 > end) {
+ (void)memcpy(temp1, temp2, sizeof(__LDATA));
+ temp1--, temp2--;
+ }
+ temp1->ch = ch;
+ temp1->attr &= ~__STANDOUT;
+ __touchline(win, win->cury, win->curx, win->maxx - 1, 0);
+ if (win->cury == LINES - 1 &&
+ (win->lines[LINES - 1]->line[COLS - 1].ch != ' ' ||
+ win->lines[LINES -1]->line[COLS - 1].attr != 0))
+ if (win->flags & __SCROLLOK) {
+ wrefresh(win);
+ scroll(win);
+ win->cury--;
+ } else
+ return (ERR);
+ return (OK);
+}
diff --git a/lib/libcurses/insertln.c b/lib/libcurses/insertln.c
new file mode 100644
index 00000000000..c2179f0f187
--- /dev/null
+++ b/lib/libcurses/insertln.c
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)insertln.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * winsertln --
+ * Do an insert-line on the window, leaving (cury, curx) unchanged.
+ */
+int
+winsertln(win)
+ register WINDOW *win;
+{
+
+ register int y, i;
+ register __LINE *temp;
+
+#ifdef DEBUG
+ __CTRACE("insertln: (%0.2o)\n", win);
+#endif
+ if (win->orig == NULL)
+ temp = win->lines[win->maxy - 1];
+ for (y = win->maxy - 1; y > win->cury; --y) {
+ win->lines[y]->flags &= ~__ISPASTEOL;
+ win->lines[y - 1]->flags &= ~__ISPASTEOL;
+ if (win->orig == NULL)
+ win->lines[y] = win->lines[y - 1];
+ else
+ (void)memcpy(win->lines[y]->line,
+ win->lines[y - 1]->line,
+ win->maxx * __LDATASIZE);
+ __touchline(win, y, 0, win->maxx - 1, 0);
+ }
+ if (win->orig == NULL)
+ win->lines[y] = temp;
+ else
+ temp = win->lines[y];
+ for(i = 0; i < win->maxx; i++) {
+ temp->line[i].ch = ' ';
+ temp->line[i].attr = 0;
+ }
+ __touchline(win, y, 0, win->maxx - 1, 0);
+ if (win->orig == NULL)
+ __id_subwins(win);
+ return (OK);
+}
diff --git a/lib/libcurses/longname.c b/lib/libcurses/longname.c
new file mode 100644
index 00000000000..fd54630f161
--- /dev/null
+++ b/lib/libcurses/longname.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1981, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)longname.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+/*
+ * longname --
+ * Fill in "def" with the long name of the terminal.
+ */
+char *
+longname(bp, def)
+ register char *bp, *def;
+{
+ register char *cp;
+
+ while (*bp && *bp != ':' && *bp != '|')
+ bp++;
+ if (*bp == '|') {
+ for (cp = def, ++bp; *bp && *bp != ':' && *bp != '|';)
+ *cp++ = *bp++;
+ *cp = '\0';
+ }
+ return (def);
+}
diff --git a/lib/libcurses/move.c b/lib/libcurses/move.c
new file mode 100644
index 00000000000..1e22fb0648d
--- /dev/null
+++ b/lib/libcurses/move.c
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)move.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wmove --
+ * Moves the cursor to the given point.
+ */
+int
+wmove(win, y, x)
+ register WINDOW *win;
+ register int y, x;
+{
+
+#ifdef DEBUG
+ __CTRACE("wmove: (%d, %d)\n", y, x);
+#endif
+ if (x < 0 || y < 0)
+ return (ERR);
+ if (x >= win->maxx || y >= win->maxy)
+ return (ERR);
+ win->curx = x;
+ win->lines[win->cury]->flags &= ~__ISPASTEOL;
+ win->cury = y;
+ win->lines[y]->flags &= ~__ISPASTEOL;
+ return (OK);
+}
diff --git a/lib/libcurses/mvwin.c b/lib/libcurses/mvwin.c
new file mode 100644
index 00000000000..1471b27e186
--- /dev/null
+++ b/lib/libcurses/mvwin.c
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)mvwin.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * mvwin --
+ * Relocate the starting position of a window.
+ */
+int
+mvwin(win, by, bx)
+ register WINDOW *win;
+ register int by, bx;
+{
+ register WINDOW *orig;
+ register int dy, dx;
+
+ if (by + win->maxy > LINES || bx + win->maxx > COLS)
+ return (ERR);
+ dy = by - win->begy;
+ dx = bx - win->begx;
+ orig = win->orig;
+ if (orig == NULL) {
+ orig = win;
+ do {
+ win->begy += dy;
+ win->begx += dx;
+ __swflags(win);
+ win = win->nextp;
+ } while (win != orig);
+ } else {
+ if (by < orig->begy || win->maxy + dy > orig->maxy)
+ return (ERR);
+ if (bx < orig->begx || win->maxx + dx > orig->maxx)
+ return (ERR);
+ win->begy = by;
+ win->begx = bx;
+ __swflags(win);
+ __set_subwin(orig, win);
+ }
+ __touchwin(win);
+ return (OK);
+}
diff --git a/lib/libcurses/newwin.c b/lib/libcurses/newwin.c
new file mode 100644
index 00000000000..8f09cbf7966
--- /dev/null
+++ b/lib/libcurses/newwin.c
@@ -0,0 +1,244 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
+#endif /* not lint */
+
+#include <stdlib.h>
+
+#include "curses.h"
+
+#undef nl /* Don't need it here, and it interferes. */
+
+static WINDOW *__makenew __P((int, int, int, int, int));
+
+void __set_subwin __P((WINDOW *, WINDOW *));
+
+/*
+ * newwin --
+ * Allocate space for and set up defaults for a new window.
+ */
+WINDOW *
+newwin(nl, nc, by, bx)
+ register int nl, nc, by, bx;
+{
+ register WINDOW *win;
+ register __LINE *lp;
+ register int i, j;
+ register __LDATA *sp;
+
+ if (nl == 0)
+ nl = LINES - by;
+ if (nc == 0)
+ nc = COLS - bx;
+
+ if ((win = __makenew(nl, nc, by, bx, 0)) == NULL)
+ return (NULL);
+
+ win->nextp = win;
+ win->ch_off = 0;
+ win->orig = NULL;
+
+#ifdef DEBUG
+ __CTRACE("newwin: win->ch_off = %d\n", win->ch_off);
+#endif
+
+ for (i = 0; i < nl; i++) {
+ lp = win->lines[i];
+ lp->flags = 0;
+ for (sp = lp->line, j = 0; j < nc; j++, sp++) {
+ sp->ch = ' ';
+ sp->attr = 0;
+ }
+ lp->hash = __hash((char *) lp->line, nc * __LDATASIZE);
+ }
+ return (win);
+}
+
+WINDOW *
+subwin(orig, nl, nc, by, bx)
+ register WINDOW *orig;
+ register int by, bx, nl, nc;
+{
+ int i;
+ __LINE *lp;
+ register WINDOW *win;
+
+ /* Make sure window fits inside the original one. */
+#ifdef DEBUG
+ __CTRACE("subwin: (%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
+#endif
+ if (by < orig->begy || bx < orig->begx
+ || by + nl > orig->maxy + orig->begy
+ || bx + nc > orig->maxx + orig->begx)
+ return (NULL);
+ if (nl == 0)
+ nl = orig->maxy + orig->begy - by;
+ if (nc == 0)
+ nc = orig->maxx + orig->begx - bx;
+ if ((win = __makenew(nl, nc, by, bx, 1)) == NULL)
+ return (NULL);
+ win->nextp = orig->nextp;
+ orig->nextp = win;
+ win->orig = orig;
+
+ /* Initialize flags here so that refresh can also use __set_subwin. */
+ for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++)
+ lp->flags = 0;
+ __set_subwin(orig, win);
+ return (win);
+}
+
+/*
+ * This code is shared with mvwin().
+ */
+void
+__set_subwin(orig, win)
+ register WINDOW *orig, *win;
+{
+ int i;
+ __LINE *lp, *olp;
+
+ win->ch_off = win->begx - orig->begx;
+ /* Point line pointers to line space. */
+ for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) {
+ win->lines[i] = lp;
+ olp = orig->lines[i + win->begy];
+ lp->line = &olp->line[win->begx];
+ lp->firstchp = &olp->firstch;
+ lp->lastchp = &olp->lastch;
+ lp->hash = __hash((char *) lp->line, win->maxx * __LDATASIZE);
+ }
+
+#ifdef DEBUG
+ __CTRACE("__set_subwin: win->ch_off = %d\n", win->ch_off);
+#endif
+}
+
+/*
+ * __makenew --
+ * Set up a window buffer and returns a pointer to it.
+ */
+static WINDOW *
+__makenew(nl, nc, by, bx, sub)
+ register int by, bx, nl, nc;
+ int sub;
+{
+ register WINDOW *win;
+ register __LINE *lp;
+ int i;
+
+
+#ifdef DEBUG
+ __CTRACE("makenew: (%d, %d, %d, %d)\n", nl, nc, by, bx);
+#endif
+ if ((win = malloc(sizeof(*win))) == NULL)
+ return (NULL);
+#ifdef DEBUG
+ __CTRACE("makenew: nl = %d\n", nl);
+#endif
+
+ /*
+ * Set up line pointer array and line space.
+ */
+ if ((win->lines = malloc (nl * sizeof(__LINE *))) == NULL) {
+ free(win);
+ return NULL;
+ }
+ if ((win->lspace = malloc (nl * sizeof(__LINE))) == NULL) {
+ free (win);
+ free (win->lines);
+ return NULL;
+ }
+
+ /* Don't allocate window and line space if it's a subwindow */
+ if (!sub) {
+ /*
+ * Allocate window space in one chunk.
+ */
+ if ((win->wspace =
+ malloc(nc * nl * sizeof(__LDATA))) == NULL) {
+ free(win->lines);
+ free(win->lspace);
+ free(win);
+ return NULL;
+ }
+
+ /*
+ * Point line pointers to line space, and lines themselves into
+ * window space.
+ */
+ for (lp = win->lspace, i = 0; i < nl; i++, lp++) {
+ win->lines[i] = lp;
+ lp->line = &win->wspace[i * nc];
+ lp->firstchp = &lp->firstch;
+ lp->lastchp = &lp->lastch;
+ lp->firstch = 0;
+ lp->lastch = 0;
+ }
+ }
+#ifdef DEBUG
+ __CTRACE("makenew: nc = %d\n", nc);
+#endif
+ win->cury = win->curx = 0;
+ win->maxy = nl;
+ win->maxx = nc;
+
+ win->begy = by;
+ win->begx = bx;
+ win->flags = 0;
+ __swflags(win);
+#ifdef DEBUG
+ __CTRACE("makenew: win->flags = %0.2o\n", win->flags);
+ __CTRACE("makenew: win->maxy = %d\n", win->maxy);
+ __CTRACE("makenew: win->maxx = %d\n", win->maxx);
+ __CTRACE("makenew: win->begy = %d\n", win->begy);
+ __CTRACE("makenew: win->begx = %d\n", win->begx);
+#endif
+ return (win);
+}
+
+void
+__swflags(win)
+ register WINDOW *win;
+{
+ win->flags &= ~(__ENDLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK);
+ if (win->begx + win->maxx == COLS) {
+ win->flags |= __ENDLINE;
+ if (win->begx == 0 && win->maxy == LINES && win->begy == 0)
+ win->flags |= __FULLWIN;
+ if (win->begy + win->maxy == LINES)
+ win->flags |= __SCROLLWIN;
+ }
+}
diff --git a/lib/libcurses/overlay.c b/lib/libcurses/overlay.c
new file mode 100644
index 00000000000..9f35c79e3fb
--- /dev/null
+++ b/lib/libcurses/overlay.c
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)overlay.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <ctype.h>
+
+#include "curses.h"
+
+/*
+ * overlay --
+ * Writes win1 on win2 non-destructively.
+ */
+int
+overlay(win1, win2)
+ register WINDOW *win1, *win2;
+{
+
+ register int x, y, y1, y2, endy, endx, starty, startx;
+ register __LDATA *sp, *end;
+
+#ifdef DEBUG
+ __CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2);
+#endif
+ starty = max(win1->begy, win2->begy);
+ startx = max(win1->begx, win2->begx);
+ endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
+ endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
+#ifdef DEBUG
+ __CTRACE("overlay: from (%d,%d) to (%d,%d)\n",
+ starty, startx, endy, endx);
+#endif
+ if (starty >= endy || startx >= endx)
+ return (OK);
+ y1 = starty - win1->begy;
+ y2 = starty - win2->begy;
+ for (y = starty; y < endy; y++, y1++, y2++) {
+ end = &win1->lines[y1]->line[endx - win1->begx];
+ x = startx - win2->begx;
+ for (sp = &win1->lines[y1]->line[startx - win1->begx];
+ sp < end; sp++) {
+ if (!isspace(sp->ch)) {
+ wmove(win2, y2, x);
+ __waddch(win2, sp);
+ }
+ x++;
+ }
+ }
+ return (OK);
+}
diff --git a/lib/libcurses/overwrite.c b/lib/libcurses/overwrite.c
new file mode 100644
index 00000000000..e2d91bd0a8c
--- /dev/null
+++ b/lib/libcurses/overwrite.c
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)overwrite.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <ctype.h>
+#include <string.h>
+
+#include "curses.h"
+
+/*
+ * overwrite --
+ * Writes win1 on win2 destructively.
+ */
+int
+overwrite(win1, win2)
+ register WINDOW *win1, *win2;
+{
+ register int x, y, endy, endx, starty, startx;
+
+#ifdef DEBUG
+ __CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
+#endif
+ starty = max(win1->begy, win2->begy);
+ startx = max(win1->begx, win2->begx);
+ endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
+ endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
+ if (starty >= endy || startx >= endx)
+ return (OK);
+#ifdef DEBUG
+ __CTRACE("overwrite: from (%d, %d) to (%d, %d)\n",
+ starty, startx, endy, endx);
+#endif
+ x = endx - startx;
+ for (y = starty; y < endy; y++) {
+ (void)memcpy(
+ &win2->lines[y - win2->begy]->line[startx - win2->begx],
+ &win1->lines[y - win1->begy]->line[startx - win1->begx],
+ x * __LDATASIZE);
+ __touchline(win2, y, startx - win2->begx, endx - win2->begx,
+ 0);
+ }
+ return (OK);
+}
diff --git a/lib/libcurses/printw.c b/lib/libcurses/printw.c
new file mode 100644
index 00000000000..ae6ea49dabf
--- /dev/null
+++ b/lib/libcurses/printw.c
@@ -0,0 +1,200 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#include "curses.h"
+
+/*
+ * printw and friends.
+ *
+ * These routines make nonportable assumptions about varargs if __STDC__
+ * is not in effect.
+ */
+
+static int __winwrite __P((void *, const char *, int));
+
+/*
+ * printw --
+ * Printf on the standard screen.
+ */
+int
+#ifdef __STDC__
+printw(const char *fmt, ...)
+#else
+printw(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwprintw(stdscr, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * wprintw --
+ * Printf on the given window.
+ */
+int
+#ifdef __STDC__
+wprintw(WINDOW * win, const char *fmt, ...)
+#else
+wprintw(win, fmt, va_alist)
+ WINDOW *win;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwprintw(win, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * mvprintw, mvwprintw --
+ * Implement the mvprintw commands. Due to the variable number of
+ * arguments, they cannot be macros. Sigh....
+ */
+int
+#ifdef __STDC__
+mvprintw(register int y, register int x, const char *fmt, ...)
+#else
+mvprintw(y, x, fmt, va_alist)
+ register int y, x;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ if (move(y, x) != OK)
+ return (ERR);
+ ret = vwprintw(stdscr, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+int
+#ifdef __STDC__
+mvwprintw(register WINDOW * win, register int y, register int x,
+ const char *fmt, ...)
+#else
+mvwprintw(win, y, x, fmt, va_alist)
+ register WINDOW *win;
+ register int y, x;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ if (wmove(win, y, x) != OK)
+ return (ERR);
+
+ ret = vwprintw(win, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * Internal write-buffer-to-window function.
+ */
+static int
+__winwrite(cookie, buf, n)
+ void *cookie;
+ register const char *buf;
+ int n;
+{
+ register WINDOW *win;
+ register int c;
+
+ for (c = n, win = cookie; --c >= 0;)
+ if (waddch(win, *buf++) == ERR)
+ return (-1);
+ return (n);
+}
+
+/*
+ * vwprintw --
+ * This routine actually executes the printf and adds it to the window.
+ */
+int
+vwprintw(win, fmt, ap)
+ WINDOW *win;
+ const char *fmt;
+ va_list ap;
+{
+ FILE *f;
+
+ if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL)
+ return (ERR);
+ (void)vfprintf(f, fmt, ap);
+ return (fclose(f) ? ERR : OK);
+}
diff --git a/lib/libcurses/putchar.c b/lib/libcurses/putchar.c
new file mode 100644
index 00000000000..2ed5bb4755c
--- /dev/null
+++ b/lib/libcurses/putchar.c
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)putchar.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+void
+__cputchar(ch)
+ int ch;
+{
+
+#ifdef DEBUG
+ __CTRACE("__cputchar: %s\n", unctrl(ch));
+#endif
+ (void)putchar(ch);
+}
diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c
new file mode 100644
index 00000000000..3271bd9101e
--- /dev/null
+++ b/lib/libcurses/refresh.c
@@ -0,0 +1,827 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94";
+#endif /* not lint */
+
+#include <string.h>
+
+#include "curses.h"
+
+static int curwin;
+static short ly, lx;
+
+static void domvcur __P((int, int, int, int));
+static int makech __P((WINDOW *, int));
+static void quickch __P((WINDOW *));
+static void scrolln __P((WINDOW *, int, int, int, int, int));
+
+/*
+ * wrefresh --
+ * Make the current screen look like "win" over the area coverd by
+ * win.
+ */
+int
+wrefresh(win)
+ register WINDOW *win;
+{
+ register __LINE *wlp;
+ register int retval;
+ register short wy;
+ int dnum;
+
+ /* Initialize loop parameters. */
+ ly = curscr->cury;
+ lx = curscr->curx;
+ wy = 0;
+ curwin = (win == curscr);
+
+ if (!curwin)
+ for (wy = 0; wy < win->maxy; wy++) {
+ wlp = win->lines[wy];
+ if (wlp->flags & __ISDIRTY)
+ wlp->hash = __hash((char *)wlp->line,
+ win->maxx * __LDATASIZE);
+ }
+
+ if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) {
+ if ((win->flags & __FULLWIN) || curscr->flags & __CLEAROK) {
+ tputs(CL, 0, __cputchar);
+ ly = 0;
+ lx = 0;
+ if (!curwin) {
+ curscr->flags &= ~__CLEAROK;
+ curscr->cury = 0;
+ curscr->curx = 0;
+ werase(curscr);
+ }
+ __touchwin(win);
+ }
+ win->flags &= ~__CLEAROK;
+ }
+ if (!CA) {
+ if (win->curx != 0)
+ putchar('\n');
+ if (!curwin)
+ werase(curscr);
+ }
+#ifdef DEBUG
+ __CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin);
+ __CTRACE("wrefresh: \tfirstch\tlastch\n");
+#endif
+
+#ifndef NOQCH
+ if ((win->flags & __FULLWIN) && !curwin) {
+ /*
+ * Invoke quickch() only if more than a quarter of the lines
+ * in the window are dirty.
+ */
+ for (wy = 0, dnum = 0; wy < win->maxy; wy++)
+ if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT))
+ dnum++;
+ if (!__noqch && dnum > (int) win->maxy / 4)
+ quickch(win);
+ }
+#endif
+
+#ifdef DEBUG
+{ int i, j;
+ __CTRACE("#####################################\n");
+ for (i = 0; i < curscr->maxy; i++) {
+ __CTRACE("C: %d:", i);
+ __CTRACE(" 0x%x \n", curscr->lines[i]->hash);
+ for (j = 0; j < curscr->maxx; j++)
+ __CTRACE("%c",
+ curscr->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ for (j = 0; j < curscr->maxx; j++)
+ __CTRACE("%x",
+ curscr->lines[i]->line[j].attr);
+ __CTRACE("\n");
+ __CTRACE("W: %d:", i);
+ __CTRACE(" 0x%x \n", win->lines[i]->hash);
+ __CTRACE(" 0x%x ", win->lines[i]->flags);
+ for (j = 0; j < win->maxx; j++)
+ __CTRACE("%c",
+ win->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ for (j = 0; j < win->maxx; j++)
+ __CTRACE("%x",
+ win->lines[i]->line[j].attr);
+ __CTRACE("\n");
+ }
+}
+#endif /* DEBUG */
+
+ for (wy = 0; wy < win->maxy; wy++) {
+#ifdef DEBUG
+ __CTRACE("%d\t%d\t%d\n",
+ wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);
+#endif
+ if (!curwin)
+ curscr->lines[wy]->hash = win->lines[wy]->hash;
+ if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) {
+ if (makech(win, wy) == ERR)
+ return (ERR);
+ else {
+ if (*win->lines[wy]->firstchp >= win->ch_off)
+ *win->lines[wy]->firstchp = win->maxx +
+ win->ch_off;
+ if (*win->lines[wy]->lastchp < win->maxx +
+ win->ch_off)
+ *win->lines[wy]->lastchp = win->ch_off;
+ if (*win->lines[wy]->lastchp <
+ *win->lines[wy]->firstchp) {
+#ifdef DEBUG
+ __CTRACE("wrefresh: line %d notdirty \n", wy);
+#endif
+ win->lines[wy]->flags &= ~__ISDIRTY;
+ }
+ }
+
+ }
+#ifdef DEBUG
+ __CTRACE("\t%d\t%d\n", *win->lines[wy]->firstchp,
+ *win->lines[wy]->lastchp);
+#endif
+ }
+
+#ifdef DEBUG
+ __CTRACE("refresh: ly=%d, lx=%d\n", ly, lx);
+#endif
+
+ if (win == curscr)
+ domvcur(ly, lx, win->cury, win->curx);
+ else {
+ if (win->flags & __LEAVEOK) {
+ curscr->cury = ly;
+ curscr->curx = lx;
+ ly -= win->begy;
+ lx -= win->begx;
+ if (ly >= 0 && ly < win->maxy && lx >= 0 &&
+ lx < win->maxx) {
+ win->cury = ly;
+ win->curx = lx;
+ } else
+ win->cury = win->curx = 0;
+ } else {
+ domvcur(ly, lx, win->cury + win->begy,
+ win->curx + win->begx);
+ curscr->cury = win->cury + win->begy;
+ curscr->curx = win->curx + win->begx;
+ }
+ }
+ retval = OK;
+
+ (void)fflush(stdout);
+ return (retval);
+}
+
+/*
+ * makech --
+ * Make a change on the screen.
+ */
+static int
+makech(win, wy)
+ register WINDOW *win;
+ int wy;
+{
+ static __LDATA blank = {' ', 0};
+ __LDATA *nsp, *csp, *cp, *cep;
+ u_int force;
+ int clsp, nlsp; /* Last space in lines. */
+ int lch, wx, y;
+ char *ce;
+
+ /* Is the cursor still on the end of the last line? */
+ if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) {
+ domvcur(ly, lx, ly + 1, 0);
+ ly++;
+ lx = 0;
+ }
+ wx = *win->lines[wy]->firstchp - win->ch_off;
+ if (wx < 0)
+ wx = 0;
+ else if (wx >= win->maxx)
+ return (OK);
+ lch = *win->lines[wy]->lastchp - win->ch_off;
+ if (lch < 0)
+ return (OK);
+ else if (lch >= (int) win->maxx)
+ lch = win->maxx - 1;
+ y = wy + win->begy;
+
+ if (curwin)
+ csp = &blank;
+ else
+ csp = &curscr->lines[wy + win->begy]->line[wx + win->begx];
+
+ nsp = &win->lines[wy]->line[wx];
+ force = win->lines[wy]->flags & __FORCEPAINT;
+ win->lines[wy]->flags &= ~__FORCEPAINT;
+ if (CE && !curwin) {
+ for (cp = &win->lines[wy]->line[win->maxx - 1];
+ cp->ch == ' ' && cp->attr == 0; cp--)
+ if (cp <= win->lines[wy]->line)
+ break;
+ nlsp = cp - win->lines[wy]->line;
+ }
+ if (!curwin)
+ ce = CE;
+ else
+ ce = NULL;
+
+ if (force) {
+ if (CM)
+ tputs(tgoto(CM, lx, ly), 0, __cputchar);
+ else {
+ tputs(HO, 0, __cputchar);
+ __mvcur(0, 0, ly, lx, 1);
+ }
+ }
+
+ while (wx <= lch) {
+ if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
+ if (wx <= lch) {
+ while (wx <= lch &&
+ memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
+ nsp++;
+ if (!curwin)
+ ++csp;
+ ++wx;
+ }
+ continue;
+ }
+ break;
+ }
+ domvcur(ly, lx, y, wx + win->begx);
+
+#ifdef DEBUG
+ __CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n",
+ wx, ly, lx, y, wx + win->begx, force);
+#endif
+ ly = y;
+ lx = wx + win->begx;
+ while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0)
+ && wx <= lch) {
+
+ if (ce != NULL &&
+ win->maxx + win->begx == curscr->maxx &&
+ wx >= nlsp && nsp->ch == ' ' && nsp->attr == 0) {
+ /* Check for clear to end-of-line. */
+ cep = &curscr->lines[wy]->line[win->maxx - 1];
+ while (cep->ch == ' ' && cep->attr == 0)
+ if (cep-- <= csp)
+ break;
+ clsp = cep - curscr->lines[wy]->line -
+ win->begx * __LDATASIZE;
+#ifdef DEBUG
+ __CTRACE("makech: clsp = %d, nlsp = %d\n", clsp, nlsp);
+#endif
+ if ((clsp - nlsp >= strlen(CE)
+ && clsp < win->maxx * __LDATASIZE) ||
+ wy == win->maxy - 1) {
+ if (curscr->flags & __WSTANDOUT) {
+ tputs(SE, 0, __cputchar);
+ curscr->flags &= ~__WSTANDOUT;
+ }
+ tputs(CE, 0, __cputchar);
+ lx = wx + win->begx;
+ while (wx++ <= clsp) {
+ csp->ch = ' ';
+ csp->attr = 0;
+ csp++;
+ }
+ return (OK);
+ }
+ ce = NULL;
+ }
+
+ /*
+ * Enter/exit standout mode as appropriate.
+ * XXX
+ * Should use UC if SO/SE not available.
+ */
+ if (nsp->attr & __STANDOUT) {
+ if (!(curscr->flags & __WSTANDOUT) &&
+ SO != NULL && SE != NULL) {
+ tputs(SO, 0, __cputchar);
+ curscr->flags |= __WSTANDOUT;
+ }
+ } else
+ if (curscr->flags & __WSTANDOUT &&
+ SE != NULL) {
+ tputs(SE, 0, __cputchar);
+ curscr->flags &= ~__WSTANDOUT;
+ }
+
+ wx++;
+ if (wx >= win->maxx && wy == win->maxy - 1 && !curwin)
+ if (win->flags & __SCROLLOK) {
+ if (curscr->flags & __WSTANDOUT
+ && win->flags & __ENDLINE)
+ if (!MS) {
+ tputs(SE, 0,
+ __cputchar);
+ curscr->flags &=
+ ~__WSTANDOUT;
+ }
+ if (!(win->flags & __SCROLLWIN)) {
+ if (!curwin) {
+ csp->attr = nsp->attr;
+ putchar(csp->ch = nsp->ch);
+ } else
+ putchar(nsp->ch);
+ }
+ if (wx + win->begx < curscr->maxx) {
+ domvcur(ly, wx + win->begx,
+ win->begy + win->maxy - 1,
+ win->begx + win->maxx - 1);
+ }
+ ly = win->begy + win->maxy - 1;
+ lx = win->begx + win->maxx - 1;
+ return (OK);
+ }
+ if (wx < win->maxx || wy < win->maxy - 1 ||
+ !(win->flags & __SCROLLWIN)) {
+ if (!curwin) {
+ csp->attr = nsp->attr;
+ putchar(csp->ch = nsp->ch);
+ csp++;
+ } else
+ putchar(nsp->ch);
+ }
+#ifdef DEBUG
+ __CTRACE("makech: putchar(%c)\n", nsp->ch & 0177);
+#endif
+ if (UC && (nsp->attr & __STANDOUT)) {
+ putchar('\b');
+ tputs(UC, 0, __cputchar);
+ }
+ nsp++;
+#ifdef DEBUG
+ __CTRACE("makech: 2: wx = %d, lx = %d\n", wx, lx);
+#endif
+ }
+ if (lx == wx + win->begx) /* If no change. */
+ break;
+ lx = wx + win->begx;
+ if (lx >= COLS && AM)
+ lx = COLS - 1;
+ else if (wx >= win->maxx) {
+ domvcur(ly, lx, ly, win->maxx + win->begx - 1);
+ lx = win->maxx + win->begx - 1;
+ }
+
+#ifdef DEBUG
+ __CTRACE("makech: 3: wx = %d, lx = %d\n", wx, lx);
+#endif
+ }
+
+ /* Don't leave the screen in standout mode. */
+ if (curscr->flags & __WSTANDOUT) {
+ tputs(SE, 0, __cputchar);
+ curscr->flags &= ~__WSTANDOUT;
+ }
+ return (OK);
+}
+
+/*
+ * domvcur --
+ * Do a mvcur, leaving standout mode if necessary.
+ */
+static void
+domvcur(oy, ox, ny, nx)
+ int oy, ox, ny, nx;
+{
+ if (curscr->flags & __WSTANDOUT && !MS) {
+ tputs(SE, 0, __cputchar);
+ curscr->flags &= ~__WSTANDOUT;
+ }
+
+ __mvcur(oy, ox, ny, nx, 1);
+}
+
+/*
+ * Quickch() attempts to detect a pattern in the change of the window
+ * in order to optimize the change, e.g., scroll n lines as opposed to
+ * repainting the screen line by line.
+ */
+
+static void
+quickch(win)
+ WINDOW *win;
+{
+#define THRESH (int) win->maxy / 4
+
+ register __LINE *clp, *tmp1, *tmp2;
+ register int bsize, curs, curw, starts, startw, i, j;
+ int n, target, cur_period, bot, top, sc_region;
+ __LDATA buf[1024];
+ u_int blank_hash;
+
+ /*
+ * Find how many lines from the top of the screen are unchanged.
+ */
+ for (top = 0; top < win->maxy; top++)
+ if (win->lines[top]->flags & __FORCEPAINT ||
+ win->lines[top]->hash != curscr->lines[top]->hash
+ || memcmp(win->lines[top]->line,
+ curscr->lines[top]->line,
+ win->maxx * __LDATASIZE) != 0)
+ break;
+ else
+ win->lines[top]->flags &= ~__ISDIRTY;
+ /*
+ * Find how many lines from bottom of screen are unchanged.
+ */
+ for (bot = win->maxy - 1; bot >= 0; bot--)
+ if (win->lines[bot]->flags & __FORCEPAINT ||
+ win->lines[bot]->hash != curscr->lines[bot]->hash
+ || memcmp(win->lines[bot]->line,
+ curscr->lines[bot]->line,
+ win->maxx * __LDATASIZE) != 0)
+ break;
+ else
+ win->lines[bot]->flags &= ~__ISDIRTY;
+
+#ifdef NO_JERKINESS
+ /*
+ * If we have a bottom unchanged region return. Scrolling the
+ * bottom region up and then back down causes a screen jitter.
+ * This will increase the number of characters sent to the screen
+ * but it looks better.
+ */
+ if (bot < win->maxy - 1)
+ return;
+#endif /* NO_JERKINESS */
+
+ /*
+ * Search for the largest block of text not changed.
+ * Invariants of the loop:
+ * - Startw is the index of the beginning of the examined block in win.
+ * - Starts is the index of the beginning of the examined block in
+ * curscr.
+ * - Curs is the index of one past the end of the exmined block in win.
+ * - Curw is the index of one past the end of the exmined block in
+ * curscr.
+ * - bsize is the current size of the examined block.
+ */
+ for (bsize = bot - top; bsize >= THRESH; bsize--) {
+ for (startw = top; startw <= bot - bsize; startw++)
+ for (starts = top; starts <= bot - bsize;
+ starts++) {
+ for (curw = startw, curs = starts;
+ curs < starts + bsize; curw++, curs++)
+ if (win->lines[curw]->flags &
+ __FORCEPAINT ||
+ (win->lines[curw]->hash !=
+ curscr->lines[curs]->hash ||
+ memcmp(win->lines[curw]->line,
+ curscr->lines[curs]->line,
+ win->maxx * __LDATASIZE) != 0))
+ break;
+ if (curs == starts + bsize)
+ goto done;
+ }
+ }
+ done:
+ /* Did not find anything */
+ if (bsize < THRESH)
+ return;
+
+#ifdef DEBUG
+ __CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n",
+ bsize, starts, startw, curw, curs, top, bot);
+#endif
+
+ /*
+ * Make sure that there is no overlap between the bottom and top
+ * regions and the middle scrolled block.
+ */
+ if (bot < curs)
+ bot = curs - 1;
+ if (top > starts)
+ top = starts;
+
+ n = startw - starts;
+
+#ifdef DEBUG
+ __CTRACE("#####################################\n");
+ for (i = 0; i < curscr->maxy; i++) {
+ __CTRACE("C: %d:", i);
+ __CTRACE(" 0x%x \n", curscr->lines[i]->hash);
+ for (j = 0; j < curscr->maxx; j++)
+ __CTRACE("%c",
+ curscr->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ for (j = 0; j < curscr->maxx; j++)
+ __CTRACE("%x",
+ curscr->lines[i]->line[j].attr);
+ __CTRACE("\n");
+ __CTRACE("W: %d:", i);
+ __CTRACE(" 0x%x \n", win->lines[i]->hash);
+ __CTRACE(" 0x%x ", win->lines[i]->flags);
+ for (j = 0; j < win->maxx; j++)
+ __CTRACE("%c",
+ win->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ for (j = 0; j < win->maxx; j++)
+ __CTRACE("%x",
+ win->lines[i]->line[j].attr);
+ __CTRACE("\n");
+ }
+#endif
+
+ /* So we don't have to call __hash() each time */
+ for (i = 0; i < win->maxx; i++) {
+ buf[i].ch = ' ';
+ buf[i].attr = 0;
+ }
+ blank_hash = __hash((char *) buf, win->maxx * __LDATASIZE);
+
+ /*
+ * Perform the rotation to maintain the consistency of curscr.
+ * This is hairy since we are doing an *in place* rotation.
+ * Invariants of the loop:
+ * - I is the index of the current line.
+ * - Target is the index of the target of line i.
+ * - Tmp1 points to current line (i).
+ * - Tmp2 and points to target line (target);
+ * - Cur_period is the index of the end of the current period.
+ * (see below).
+ *
+ * There are 2 major issues here that make this rotation non-trivial:
+ * 1. Scrolling in a scrolling region bounded by the top
+ * and bottom regions determined (whose size is sc_region).
+ * 2. As a result of the use of the mod function, there may be a
+ * period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and
+ * 0 to 2, which then causes all odd lines not to be rotated.
+ * To remedy this, an index of the end ( = beginning) of the
+ * current 'period' is kept, cur_period, and when it is reached,
+ * the next period is started from cur_period + 1 which is
+ * guaranteed not to have been reached since that would mean that
+ * all records would have been reached. (think about it...).
+ *
+ * Lines in the rotation can have 3 attributes which are marked on the
+ * line so that curscr is consistent with the visual screen.
+ * 1. Not dirty -- lines inside the scrolled block, top region or
+ * bottom region.
+ * 2. Blank lines -- lines in the differential of the scrolling
+ * region adjacent to top and bot regions
+ * depending on scrolling direction.
+ * 3. Dirty line -- all other lines are marked dirty.
+ */
+ sc_region = bot - top + 1;
+ i = top;
+ tmp1 = curscr->lines[top];
+ cur_period = top;
+ for (j = top; j <= bot; j++) {
+ target = (i - top + n + sc_region) % sc_region + top;
+ tmp2 = curscr->lines[target];
+ curscr->lines[target] = tmp1;
+ /* Mark block as clean and blank out scrolled lines. */
+ clp = curscr->lines[target];
+#ifdef DEBUG
+ __CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
+ n, startw, curw, i, target);
+#endif
+ if ((target >= startw && target < curw) || target < top
+ || target > bot) {
+#ifdef DEBUG
+ __CTRACE("-- notdirty");
+#endif
+ win->lines[target]->flags &= ~__ISDIRTY;
+ } else if ((n > 0 && target >= top && target < top + n) ||
+ (n < 0 && target <= bot && target > bot + n)) {
+ if (clp->hash != blank_hash || memcmp(clp->line,
+ buf, win->maxx * __LDATASIZE) !=0) {
+ (void)memcpy(clp->line, buf,
+ win->maxx * __LDATASIZE);
+#ifdef DEBUG
+ __CTRACE("-- blanked out: dirty");
+#endif
+ clp->hash = blank_hash;
+ __touchline(win, target, 0, win->maxx - 1, 0);
+ } else {
+ __touchline(win, target, 0, win->maxx - 1, 0);
+#ifdef DEBUG
+ __CTRACE(" -- blank line already: dirty");
+#endif
+ }
+ } else {
+#ifdef DEBUG
+ __CTRACE(" -- dirty");
+#endif
+ __touchline(win, target, 0, win->maxx - 1, 0);
+ }
+#ifdef DEBUG
+ __CTRACE("\n");
+#endif
+ if (target == cur_period) {
+ i = target + 1;
+ tmp1 = curscr->lines[i];
+ cur_period = i;
+ } else {
+ tmp1 = tmp2;
+ i = target;
+ }
+ }
+#ifdef DEBUG
+ __CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
+ for (i = 0; i < curscr->maxy; i++) {
+ __CTRACE("C: %d:", i);
+ for (j = 0; j < curscr->maxx; j++)
+ __CTRACE("%c",
+ curscr->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ __CTRACE("W: %d:", i);
+ for (j = 0; j < win->maxx; j++)
+ __CTRACE("%c", win->lines[i]->line[j].ch);
+ __CTRACE("\n");
+ }
+#endif
+ if (n != 0) {
+ WINDOW *wp;
+ scrolln(win, starts, startw, curs, bot, top);
+ /*
+ * Need to repoint any subwindow lines to the rotated
+ * line structured.
+ */
+ for (wp = win->nextp; wp != win; wp = wp->nextp)
+ __set_subwin(win, wp);
+ }
+}
+
+/*
+ * scrolln --
+ * Scroll n lines, where n is starts - startw.
+ */
+static void
+scrolln(win, starts, startw, curs, bot, top)
+ WINDOW *win;
+ int starts, startw, curs, bot, top;
+{
+ int i, oy, ox, n;
+
+ oy = curscr->cury;
+ ox = curscr->curx;
+ n = starts - startw;
+
+ /*
+ * XXX
+ * The initial tests that set __noqch don't let us reach here unless
+ * we have either CS + HO + SF/sf/SR/sr, or AL + DL. SF/sf and SR/sr
+ * scrolling can only shift the entire scrolling region, not just a
+ * part of it, which means that the quickch() routine is going to be
+ * sadly disappointed in us if we don't have CS as well.
+ *
+ * If CS, HO and SF/sf are set, can use the scrolling region. Because
+ * the cursor position after CS is undefined, we need HO which gives us
+ * the ability to move to somewhere without knowledge of the current
+ * location of the cursor. Still call __mvcur() anyway, to update its
+ * idea of where the cursor is.
+ *
+ * When the scrolling region has been set, the cursor has to be at the
+ * last line of the region to make the scroll happen.
+ *
+ * Doing SF/SR or AL/DL appears faster on the screen than either sf/sr
+ * or al/dl, and, some terminals have AL/DL, sf/sr, and CS, but not
+ * SF/SR. So, if we're scrolling almost all of the screen, try and use
+ * AL/DL, otherwise use the scrolling region. The "almost all" is a
+ * shameless hack for vi.
+ */
+ if (n > 0) {
+ if (CS != NULL && HO != NULL && (SF != NULL ||
+ (AL == NULL || DL == NULL ||
+ top > 3 || bot + 3 < win->maxy) && sf != NULL)) {
+ tputs(__tscroll(CS, top, bot + 1), 0, __cputchar);
+ __mvcur(oy, ox, 0, 0, 1);
+ tputs(HO, 0, __cputchar);
+ __mvcur(0, 0, bot, 0, 1);
+ if (SF != NULL)
+ tputs(__tscroll(SF, n, 0), 0, __cputchar);
+ else
+ for (i = 0; i < n; i++)
+ tputs(sf, 0, __cputchar);
+ tputs(__tscroll(CS, 0, win->maxy), 0, __cputchar);
+ __mvcur(bot, 0, 0, 0, 1);
+ tputs(HO, 0, __cputchar);
+ __mvcur(0, 0, oy, ox, 1);
+ return;
+ }
+
+ /* Scroll up the block. */
+ if (SF != NULL && top == 0) {
+ __mvcur(oy, ox, bot, 0, 1);
+ tputs(__tscroll(SF, n, 0), 0, __cputchar);
+ } else if (DL != NULL) {
+ __mvcur(oy, ox, top, 0, 1);
+ tputs(__tscroll(DL, n, 0), 0, __cputchar);
+ } else if (dl != NULL) {
+ __mvcur(oy, ox, top, 0, 1);
+ for (i = 0; i < n; i++)
+ tputs(dl, 0, __cputchar);
+ } else if (sf != NULL && top == 0) {
+ __mvcur(oy, ox, bot, 0, 1);
+ for (i = 0; i < n; i++)
+ tputs(sf, 0, __cputchar);
+ } else
+ abort();
+
+ /* Push down the bottom region. */
+ __mvcur(top, 0, bot - n + 1, 0, 1);
+ if (AL != NULL)
+ tputs(__tscroll(AL, n, 0), 0, __cputchar);
+ else if (al != NULL)
+ for (i = 0; i < n; i++)
+ tputs(al, 0, __cputchar);
+ else
+ abort();
+ __mvcur(bot - n + 1, 0, oy, ox, 1);
+ } else {
+ /*
+ * !!!
+ * n < 0
+ *
+ * If CS, HO and SR/sr are set, can use the scrolling region.
+ * See the above comments for details.
+ */
+ if (CS != NULL && HO != NULL && (SR != NULL ||
+ (AL == NULL || DL == NULL ||
+ top > 3 || bot + 3 < win->maxy) && sr != NULL)) {
+ tputs(__tscroll(CS, top, bot + 1), 0, __cputchar);
+ __mvcur(oy, ox, 0, 0, 1);
+ tputs(HO, 0, __cputchar);
+ __mvcur(0, 0, top, 0, 1);
+
+ if (SR != NULL)
+ tputs(__tscroll(SR, -n, 0), 0, __cputchar);
+ else
+ for (i = n; i < 0; i++)
+ tputs(sr, 0, __cputchar);
+ tputs(__tscroll(CS, 0, win->maxy), 0, __cputchar);
+ __mvcur(top, 0, 0, 0, 1);
+ tputs(HO, 0, __cputchar);
+ __mvcur(0, 0, oy, ox, 1);
+ return;
+ }
+
+ /* Preserve the bottom lines. */
+ __mvcur(oy, ox, bot + n + 1, 0, 1);
+ if (SR != NULL && bot == win->maxy)
+ tputs(__tscroll(SR, -n, 0), 0, __cputchar);
+ else if (DL != NULL)
+ tputs(__tscroll(DL, -n, 0), 0, __cputchar);
+ else if (dl != NULL)
+ for (i = n; i < 0; i++)
+ tputs(dl, 0, __cputchar);
+ else if (sr != NULL && bot == win->maxy)
+ for (i = n; i < 0; i++)
+ tputs(sr, 0, __cputchar);
+ else
+ abort();
+
+ /* Scroll the block down. */
+ __mvcur(bot + n + 1, 0, top, 0, 1);
+ if (AL != NULL)
+ tputs(__tscroll(AL, -n, 0), 0, __cputchar);
+ else if (al != NULL)
+ for (i = n; i < 0; i++)
+ tputs(al, 0, __cputchar);
+ else
+ abort();
+ __mvcur(top, 0, oy, ox, 1);
+ }
+}
diff --git a/lib/libcurses/scanw.c b/lib/libcurses/scanw.c
new file mode 100644
index 00000000000..d8d79fd2355
--- /dev/null
+++ b/lib/libcurses/scanw.c
@@ -0,0 +1,175 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+/*
+ * scanw and friends.
+ */
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#include "curses.h"
+
+/*
+ * scanw --
+ * Implement a scanf on the standard screen.
+ */
+int
+#ifdef __STDC__
+scanw(const char *fmt, ...)
+#else
+scanw(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwscanw(stdscr, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * wscanw --
+ * Implements a scanf on the given window.
+ */
+int
+#ifdef __STDC__
+wscanw(WINDOW *win, const char *fmt, ...)
+#else
+wscanw(win, fmt, va_alist)
+ WINDOW *win;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwscanw(win, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * mvscanw, mvwscanw --
+ * Implement the mvscanw commands. Due to the variable number of
+ * arguments, they cannot be macros. Another sigh....
+ */
+int
+#ifdef __STDC__
+mvscanw(register int y, register int x, const char *fmt,...)
+#else
+mvscanw(y, x, fmt, va_alist)
+ register int y, x;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+ if (move(y, x) != OK)
+ return (ERR);
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwscanw(stdscr, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+int
+#ifdef __STDC__
+mvwscanw(register WINDOW * win, register int y, register int x,
+ const char *fmt, ...)
+#else
+mvwscanw(win, y, x, fmt, va_alist)
+ register WINDOW *win;
+ register int y, x;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int ret;
+
+ if (move(y, x) != OK)
+ return (ERR);
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ ret = vwscanw(win, fmt, ap);
+ va_end(ap);
+ return (ret);
+}
+
+/*
+ * vwscanw --
+ * This routine actually executes the scanf from the window.
+ */
+int
+vwscanw(win, fmt, ap)
+ WINDOW *win;
+ const char *fmt;
+ va_list ap;
+{
+
+ char buf[1024];
+
+ return (wgetstr(win, buf) == OK ?
+ vsscanf(buf, fmt, ap) : ERR);
+}
diff --git a/lib/libcurses/scroll.c b/lib/libcurses/scroll.c
new file mode 100644
index 00000000000..8aad91c0285
--- /dev/null
+++ b/lib/libcurses/scroll.c
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)scroll.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * scroll --
+ * Scroll the window up a line.
+ */
+int
+scroll(win)
+ register WINDOW *win;
+{
+ register int oy, ox;
+
+#ifdef DEBUG
+ __CTRACE("scroll: (%0.2o)\n", win);
+#endif
+
+ if (!(win->flags & __SCROLLOK))
+ return (ERR);
+
+ getyx(win, oy, ox);
+ wmove(win, 0, 0);
+ wdeleteln(win);
+ wmove(win, oy, ox);
+
+ if (win == curscr) {
+ putchar('\n');
+ if (!NONL)
+ win->curx = 0;
+#ifdef DEBUG
+ __CTRACE("scroll: win == curscr\n");
+#endif
+ }
+ return (OK);
+}
diff --git a/lib/libcurses/setterm.c b/lib/libcurses/setterm.c
new file mode 100644
index 00000000000..1d134903c11
--- /dev/null
+++ b/lib/libcurses/setterm.c
@@ -0,0 +1,232 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)setterm.c 8.7 (Berkeley) 7/27/94";
+#endif /* not lint */
+
+#include <sys/ioctl.h> /* TIOCGWINSZ on old systems. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "curses.h"
+
+static void zap __P((void));
+
+static char *sflags[] = {
+ /* am bs da eo hc in mi ms */
+ &AM, &BS, &DA, &EO, &HC, &IN, &MI, &MS,
+ /* nc ns os ul xb xn xt xs xx */
+ &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS, &XX
+ };
+
+static char *_PC,
+ **sstrs[] = {
+ /* AL bc bt cd ce cl cm cr cs */
+ &AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
+ /* dc DL dm do ed ei k0 k1 k2 */
+ &DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
+ /* k3 k4 k5 k6 k7 k8 k9 ho ic */
+ &K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
+ /* im ip kd ke kh kl kr ks ku */
+ &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
+ /* ll ma nd nl pc rc sc se SF */
+ &LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
+ /* so SR ta te ti uc ue up us */
+ &SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
+ /* vb vs ve al dl sf sr AL */
+ &VB, &VS, &VE, &al, &dl, &sf, &sr, &AL_PARM,
+ /* DL UP DO LE */
+ &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM,
+ /* RI */
+ &RIGHT_PARM,
+ };
+
+static char *aoftspace; /* Address of _tspace for relocation */
+static char tspace[2048]; /* Space for capability strings */
+
+char *ttytype;
+
+int
+setterm(type)
+ register char *type;
+{
+ static char genbuf[1024];
+ static char __ttytype[1024];
+ register int unknown;
+ struct winsize win;
+ char *p;
+
+#ifdef DEBUG
+ __CTRACE("setterm: (\"%s\")\nLINES = %d, COLS = %d\n",
+ type, LINES, COLS);
+#endif
+ if (type[0] == '\0')
+ type = "xx";
+ unknown = 0;
+ if (tgetent(genbuf, type) != 1) {
+ unknown++;
+ strcpy(genbuf, "xx|dumb:");
+ }
+#ifdef DEBUG
+ __CTRACE("setterm: tty = %s\n", type);
+#endif
+
+ /* Try TIOCGWINSZ, and, if it fails, the termcap entry. */
+ if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1 &&
+ win.ws_row != 0 && win.ws_col != 0) {
+ LINES = win.ws_row;
+ COLS = win.ws_col;
+ } else {
+ LINES = tgetnum("li");
+ COLS = tgetnum("co");
+ }
+
+ /* POSIX 1003.2 requires that the environment override. */
+ if ((p = getenv("LINES")) != NULL)
+ LINES = strtol(p, NULL, 10);
+ if ((p = getenv("COLUMNS")) != NULL)
+ COLS = strtol(p, NULL, 10);
+
+ /*
+ * Want cols > 4, otherwise things will fail.
+ */
+ if (COLS <= 4)
+ return (ERR);
+
+#ifdef DEBUG
+ __CTRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS);
+#endif
+ aoftspace = tspace;
+ zap(); /* Get terminal description. */
+
+ /* If we can't tab, we can't backtab, either. */
+ if (!GT)
+ BT = NULL;
+
+ /*
+ * Test for cursor motion capbility.
+ *
+ * XXX
+ * This is truly stupid -- tgoto returns "OOPS" if it can't
+ * do cursor motions.
+ */
+ if (tgoto(CM, 0, 0)[0] == 'O') {
+ CA = 0;
+ CM = 0;
+ } else
+ CA = 1;
+
+ PC = _PC ? _PC[0] : 0;
+ aoftspace = tspace;
+ ttytype = longname(genbuf, __ttytype);
+
+ /* If no scrolling commands, no quick change. */
+ __noqch =
+ (CS == NULL || HO == NULL ||
+ SF == NULL && sf == NULL || SR == NULL && sr == NULL) &&
+ (AL == NULL && al == NULL || DL == NULL && dl == NULL);
+
+ return (unknown ? ERR : OK);
+}
+
+/*
+ * zap --
+ * Gets all the terminal flags from the termcap database.
+ */
+static void
+zap()
+{
+ register char *namp, ***sp;
+ register char **fp;
+ char tmp[3];
+#ifdef DEBUG
+ register char *cp;
+#endif
+ tmp[2] = '\0';
+
+ namp = "ambsdaeohcinmimsncnsosulxbxnxtxsxx";
+ fp = sflags;
+ do {
+ *tmp = *namp;
+ *(tmp + 1) = *(namp + 1);
+ *(*fp++) = tgetflag(tmp);
+#ifdef DEBUG
+ __CTRACE("2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
+#endif
+ namp += 2;
+
+ } while (*namp);
+ namp = "ALbcbtcdceclcmcrcsdcDLdmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscseSFsoSRtatetiucueupusvbvsvealdlsfsrALDLUPDOLERI";
+ sp = sstrs;
+ do {
+ *tmp = *namp;
+ *(tmp + 1) = *(namp + 1);
+ *(*sp++) = tgetstr(tmp, &aoftspace);
+#ifdef DEBUG
+ __CTRACE("2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
+ if (*sp[-1] != NULL) {
+ for (cp = *sp[-1]; *cp; cp++)
+ __CTRACE("%s", unctrl(*cp));
+ __CTRACE("\"\n");
+ }
+#endif
+ namp += 2;
+ } while (*namp);
+ if (XS)
+ SO = SE = NULL;
+ else {
+ if (tgetnum("sg") > 0)
+ SO = NULL;
+ if (tgetnum("ug") > 0)
+ US = NULL;
+ if (!SO && US) {
+ SO = US;
+ SE = UE;
+ }
+ }
+}
+
+/*
+ * getcap --
+ * Return a capability from termcap.
+ */
+char *
+getcap(name)
+ char *name;
+{
+ return (tgetstr(name, &aoftspace));
+}
diff --git a/lib/libcurses/shlib_version b/lib/libcurses/shlib_version
new file mode 100644
index 00000000000..c6e3f4d3fc0
--- /dev/null
+++ b/lib/libcurses/shlib_version
@@ -0,0 +1,2 @@
+major=2
+minor=1
diff --git a/lib/libcurses/standout.c b/lib/libcurses/standout.c
new file mode 100644
index 00000000000..8851d63d446
--- /dev/null
+++ b/lib/libcurses/standout.c
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)standout.c 8.3 (Berkeley) 8/10/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * wstandout
+ * Enter standout mode.
+ */
+int
+wstandout(win)
+ WINDOW *win;
+{
+ /*
+ * If standout/standend strings, or can underline, set the
+ * screen standout bit.
+ */
+ if (SO != NULL && SE != NULL || UC != NULL)
+ win->flags |= __WSTANDOUT;
+ return (1);
+}
+
+/*
+ * wstandend --
+ * Exit standout mode.
+ */
+int
+wstandend(win)
+ WINDOW *win;
+{
+ win->flags &= ~__WSTANDOUT;
+ return (1);
+}
diff --git a/lib/libcurses/toucholap.c b/lib/libcurses/toucholap.c
new file mode 100644
index 00000000000..955c204147f
--- /dev/null
+++ b/lib/libcurses/toucholap.c
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)toucholap.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * touchoverlap --
+ * Touch, on win2, the part that overlaps with win1.
+ */
+int
+touchoverlap(win1, win2)
+ register WINDOW *win1, *win2;
+{
+ register int y, endy, endx, starty, startx;
+
+#ifdef DEBUG
+ __CTRACE("touchoverlap: (%0.2o, %0.2o);\n", win1, win2);
+#endif
+ starty = max(win1->begy, win2->begy);
+ startx = max(win1->begx, win2->begx);
+ endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
+ endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
+#ifdef DEBUG
+ __CTRACE("touchoverlap: from (%d,%d) to (%d,%d)\n",
+ starty, startx, endy, endx);
+ __CTRACE("touchoverlap: win1 (%d,%d) to (%d,%d)\n",
+ win1->begy, win1->begx, win1->begy + win1->maxy,
+ win1->begx + win1->maxx);
+ __CTRACE("touchoverlap: win2 (%d,%d) to (%d,%d)\n",
+ win2->begy, win2->begx, win2->begy + win2->maxy,
+ win2->begx + win2->maxx);
+#endif
+ if (starty >= endy || startx >= endx)
+ return (OK);
+ starty -= win2->begy;
+ startx -= win2->begx;
+ endy -= win2->begy;
+ endx -= win2->begx;
+ for (--endx, y = starty; y < endy; y++)
+ __touchline(win2, y, startx, endx, 0);
+ return (OK);
+}
+
diff --git a/lib/libcurses/touchwin.c b/lib/libcurses/touchwin.c
new file mode 100644
index 00000000000..36f487e5b8f
--- /dev/null
+++ b/lib/libcurses/touchwin.c
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)touchwin.c 8.2 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+/*
+ * touchline --
+ * Touch a given line.
+ */
+int
+touchline(win, y, sx, ex)
+ WINDOW *win;
+ register int y, sx, ex;
+{
+ return (__touchline(win, y, sx, ex, 1));
+}
+
+
+/*
+ * touchwin --
+ * Make it look like the whole window has been changed.
+ */
+int
+touchwin(win)
+ register WINDOW *win;
+{
+ register int y, maxy;
+
+#ifdef DEBUG
+ __CTRACE("touchwin: (%0.2o)\n", win);
+#endif
+ maxy = win->maxy;
+ for (y = 0; y < maxy; y++)
+ __touchline(win, y, 0, win->maxx - 1, 1);
+ return (OK);
+}
+
+
+int
+__touchwin(win)
+ register WINDOW *win;
+{
+ register int y, maxy;
+
+#ifdef DEBUG
+ __CTRACE("touchwin: (%0.2o)\n", win);
+#endif
+ maxy = win->maxy;
+ for (y = 0; y < maxy; y++)
+ __touchline(win, y, 0, win->maxx - 1, 0);
+ return (OK);
+}
+
+int
+__touchline(win, y, sx, ex, force)
+ register WINDOW *win;
+ register int y, sx, ex;
+ int force;
+{
+#ifdef DEBUG
+ __CTRACE("touchline: (%0.2o, %d, %d, %d, %d)\n", win, y, sx, ex, force);
+ __CTRACE("touchline: first = %d, last = %d\n",
+ *win->lines[y]->firstchp, *win->lines[y]->lastchp);
+#endif
+ if (force)
+ win->lines[y]->flags |= __FORCEPAINT;
+ sx += win->ch_off;
+ ex += win->ch_off;
+ if (!(win->lines[y]->flags & __ISDIRTY)) {
+ win->lines[y]->flags |= __ISDIRTY;
+ *win->lines[y]->firstchp = sx;
+ *win->lines[y]->lastchp = ex;
+ } else {
+ if (*win->lines[y]->firstchp > sx)
+ *win->lines[y]->firstchp = sx;
+ if (*win->lines[y]->lastchp < ex)
+ *win->lines[y]->lastchp = ex;
+ }
+#ifdef DEBUG
+ __CTRACE("touchline: first = %d, last = %d\n",
+ *win->lines[y]->firstchp, *win->lines[y]->lastchp);
+#endif
+ return (OK);
+}
+
+
diff --git a/lib/libcurses/tscroll.c b/lib/libcurses/tscroll.c
new file mode 100644
index 00000000000..359b3969c63
--- /dev/null
+++ b/lib/libcurses/tscroll.c
@@ -0,0 +1,139 @@
+/*-
+ * Copyright (c) 1992, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)tscroll.c 8.4 (Berkeley) 7/27/94";
+#endif /* not lint */
+
+#include "curses.h"
+
+#define MAXRETURNSIZE 64
+
+/*
+ * Routine to perform scrolling. Derived from tgoto.c in tercamp(3)
+ * library. Cap is a string containing printf type escapes to allow
+ * scrolling. The following escapes are defined for substituting n:
+ *
+ * %d as in printf
+ * %2 like %2d
+ * %3 like %3d
+ * %. gives %c hacking special case characters
+ * %+x like %c but adding x first
+ *
+ * The codes below affect the state but don't use up a value.
+ *
+ * %>xy if value > x add y
+ * %i increments n
+ * %% gives %
+ * %B BCD (2 decimal digits encoded in one byte)
+ * %D Delta Data (backwards bcd)
+ *
+ * all other characters are ``self-inserting''.
+ */
+char *
+__tscroll(cap, n1, n2)
+ const char *cap;
+ int n1, n2;
+{
+ static char result[MAXRETURNSIZE];
+ int c, n;
+ char *dp;
+
+ if (cap == NULL)
+ goto err;
+ for (n = n1, dp = result; (c = *cap++) != '\0';) {
+ if (c != '%') {
+ *dp++ = c;
+ continue;
+ }
+ switch (c = *cap++) {
+ case 'n':
+ n ^= 0140;
+ continue;
+ case 'd':
+ if (n < 10)
+ goto one;
+ if (n < 100)
+ goto two;
+ /* FALLTHROUGH */
+ case '3':
+ *dp++ = (n / 100) | '0';
+ n %= 100;
+ /* FALLTHROUGH */
+ case '2':
+two: *dp++ = n / 10 | '0';
+one: *dp++ = n % 10 | '0';
+ n = n2;
+ continue;
+ case '>':
+ if (n > *cap++)
+ n += *cap++;
+ else
+ cap++;
+ continue;
+ case '+':
+ n += *cap++;
+ /* FALLTHROUGH */
+ case '.':
+ *dp++ = n;
+ continue;
+ case 'i':
+ n++;
+ continue;
+ case '%':
+ *dp++ = c;
+ continue;
+ case 'B':
+ n = (n / 10 << 4) + n % 10;
+ continue;
+ case 'D':
+ n = n - 2 * (n % 16);
+ continue;
+ /*
+ * XXX
+ * System V terminfo files have lots of extra gunk.
+ * The only one we've seen in scrolling strings is
+ * %pN, and it seems to work okay if we ignore it.
+ */
+ case 'p':
+ ++cap;
+ continue;
+ default:
+ goto err;
+ }
+ }
+ *dp = '\0';
+ return (result);
+
+err: return("curses: __tscroll failed");
+}
diff --git a/lib/libcurses/tstp.c b/lib/libcurses/tstp.c
new file mode 100644
index 00000000000..07debf42fe1
--- /dev/null
+++ b/lib/libcurses/tstp.c
@@ -0,0 +1,124 @@
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94";
+#endif /* not lint */
+
+#include <errno.h>
+#include <signal.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "curses.h"
+
+/*
+ * stop_signal_handler --
+ * Handle stop signals.
+ */
+void
+__stop_signal_handler(signo)
+ int signo;
+{
+ struct termios save;
+ sigset_t oset, set;
+
+ /* Get the current terminal state (which the user may have changed). */
+ if (tcgetattr(STDIN_FILENO, &save))
+ return;
+
+ /*
+ * Block window change and timer signals. The latter is because
+ * applications use timers to decide when to repaint the screen.
+ */
+ (void)sigemptyset(&set);
+ (void)sigaddset(&set, SIGALRM);
+ (void)sigaddset(&set, SIGWINCH);
+ (void)sigprocmask(SIG_BLOCK, &set, &oset);
+
+ /*
+ * End the window, which also resets the terminal state to the
+ * original modes.
+ */
+ endwin();
+
+ /* Unblock SIGTSTP. */
+ (void)sigemptyset(&set);
+ (void)sigaddset(&set, SIGTSTP);
+ (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
+
+ /* Stop ourselves. */
+ __restore_stophandler();
+ (void)kill(0, SIGTSTP);
+
+ /* Time passes ... */
+
+ /* Reset the curses SIGTSTP signal handler. */
+ __set_stophandler();
+
+ /* save the new "default" terminal state */
+ (void)tcgetattr(STDIN_FILENO, &__orig_termios);
+
+ /* Reset the terminal state to the mode just before we stopped. */
+ (void)tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, &save);
+
+ /* Restart the screen. */
+ __startwin();
+
+ /* Repaint the screen. */
+ wrefresh(curscr);
+
+ /* Reset the signals. */
+ (void)sigprocmask(SIG_SETMASK, &oset, NULL);
+}
+
+static void (*otstpfn)() = SIG_DFL;
+
+/*
+ * Set the TSTP handler.
+ */
+void
+__set_stophandler()
+{
+ otstpfn = signal(SIGTSTP, __stop_signal_handler);
+}
+
+/*
+ * Restore the TSTP handler.
+ */
+void
+__restore_stophandler()
+{
+ (void)signal(SIGTSTP, otstpfn);
+}
diff --git a/lib/libcurses/tty.c b/lib/libcurses/tty.c
new file mode 100644
index 00000000000..d04586d853f
--- /dev/null
+++ b/lib/libcurses/tty.c
@@ -0,0 +1,281 @@
+/*-
+ * Copyright (c) 1992, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)tty.c 8.5 (Berkeley) 8/13/94";
+#endif /* not lint */
+
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include "curses.h"
+
+/*
+ * In general, curses should leave tty hardware settings alone (speed, parity,
+ * word size). This is most easily done in BSD by using TCSASOFT on all
+ * tcsetattr calls. On other systems, it would be better to get and restore
+ * those attributes at each change, or at least when stopped and restarted.
+ * See also the comments in getterm().
+ */
+#ifdef TCSASOFT
+int __tcaction = 1; /* Ignore hardware settings. */
+#else
+int __tcaction = 0;
+#endif
+
+struct termios __orig_termios, __baset;
+static struct termios cbreakt, rawt, *curt;
+static int useraw;
+
+#ifndef OXTABS
+#ifdef XTABS /* SMI uses XTABS. */
+#define OXTABS XTABS
+#else
+#define OXTABS 0
+#endif
+#endif
+
+/*
+ * gettmode --
+ * Do terminal type initialization.
+ */
+int
+gettmode()
+{
+ useraw = 0;
+
+ if (tcgetattr(STDIN_FILENO, &__orig_termios))
+ return (ERR);
+
+ __baset = __orig_termios;
+ __baset.c_oflag &= ~OXTABS;
+
+ GT = 0; /* historical. was used before we wired OXTABS off */
+ NONL = (__baset.c_oflag & ONLCR) == 0;
+
+ /*
+ * XXX
+ * System V and SMI systems overload VMIN and VTIME, such that
+ * VMIN is the same as the VEOF element, and VTIME is the same
+ * as the VEOL element. This means that, if VEOF was ^D, the
+ * default VMIN is 4. Majorly stupid.
+ */
+ cbreakt = __baset;
+ cbreakt.c_lflag &= ~ICANON;
+ cbreakt.c_cc[VMIN] = 1;
+ cbreakt.c_cc[VTIME] = 0;
+
+ rawt = cbreakt;
+ rawt.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL|IXON);
+ rawt.c_oflag &= ~OPOST;
+ rawt.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+
+ /*
+ * In general, curses should leave hardware-related settings alone.
+ * This includes parity and word size. Older versions set the tty
+ * to 8 bits, no parity in raw(), but this is considered to be an
+ * artifact of the old tty interface. If it's desired to change
+ * parity and word size, the TCSASOFT bit has to be removed from the
+ * calls that switch to/from "raw" mode.
+ */
+ if (!__tcaction) {
+ rawt.c_iflag &= ~ISTRIP;
+ rawt.c_cflag &= ~(CSIZE|PARENB);
+ rawt.c_cflag |= CS8;
+ }
+
+ curt = &__baset;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+raw()
+{
+ useraw = __pfast = __rawmode = 1;
+ curt = &rawt;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+noraw()
+{
+ useraw = __pfast = __rawmode = 0;
+ curt = &__baset;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+cbreak()
+{
+
+ __rawmode = 1;
+ curt = useraw ? &rawt : &cbreakt;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+nocbreak()
+{
+
+ __rawmode = 0;
+ curt = useraw ? &rawt : &__baset;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+echo()
+{
+ rawt.c_lflag |= ECHO;
+ cbreakt.c_lflag |= ECHO;
+ __baset.c_lflag |= ECHO;
+
+ __echoit = 1;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+noecho()
+{
+ rawt.c_lflag &= ~ECHO;
+ cbreakt.c_lflag &= ~ECHO;
+ __baset.c_lflag &= ~ECHO;
+
+ __echoit = 0;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+nl()
+{
+ rawt.c_iflag |= ICRNL;
+ rawt.c_oflag |= ONLCR;
+ cbreakt.c_iflag |= ICRNL;
+ cbreakt.c_oflag |= ONLCR;
+ __baset.c_iflag |= ICRNL;
+ __baset.c_oflag |= ONLCR;
+
+ __pfast = __rawmode;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+int
+nonl()
+{
+ rawt.c_iflag &= ~ICRNL;
+ rawt.c_oflag &= ~ONLCR;
+ cbreakt.c_iflag &= ~ICRNL;
+ cbreakt.c_oflag &= ~ONLCR;
+ __baset.c_iflag &= ~ICRNL;
+ __baset.c_oflag &= ~ONLCR;
+
+ __pfast = 1;
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
+}
+
+void
+__startwin()
+{
+ static char *stdbuf;
+ static size_t len;
+
+ (void)fflush(stdout);
+
+ /*
+ * Some C libraries default to a 1K buffer when talking to a tty.
+ * With a larger screen, especially across a network, we'd like
+ * to get it to all flush in a single write. Make it twice as big
+ * as just the characters (so that we have room for cursor motions
+ * and standout information) but no more than 8K.
+ */
+ if (stdbuf == NULL) {
+ if ((len = LINES * COLS * 2) > 8192)
+ len = 8192;
+ if ((stdbuf = malloc(len)) == NULL)
+ len = 0;
+ }
+ (void)setvbuf(stdout, stdbuf, _IOFBF, len);
+
+ tputs(TI, 0, __cputchar);
+ tputs(VS, 0, __cputchar);
+}
+
+int
+endwin()
+{
+ __restore_stophandler();
+
+ if (curscr != NULL) {
+ if (curscr->flags & __WSTANDOUT) {
+ tputs(SE, 0, __cputchar);
+ curscr->flags &= ~__WSTANDOUT;
+ }
+ __mvcur(curscr->cury, curscr->cury, curscr->maxy - 1, 0, 0);
+ }
+
+ (void)tputs(VE, 0, __cputchar);
+ (void)tputs(TE, 0, __cputchar);
+ (void)fflush(stdout);
+ (void)setvbuf(stdout, NULL, _IOLBF, 0);
+
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, &__orig_termios) ? ERR : OK);
+}
+
+/*
+ * The following routines, savetty and resetty are completely useless and
+ * are left in only as stubs. If people actually use them they will almost
+ * certainly screw up the state of the world.
+ */
+static struct termios savedtty;
+int
+savetty()
+{
+ return (tcgetattr(STDIN_FILENO, &savedtty) ? ERR : OK);
+}
+
+int
+resetty()
+{
+ return (tcsetattr(STDIN_FILENO, __tcaction ?
+ TCSASOFT | TCSADRAIN : TCSADRAIN, &savedtty) ? ERR : OK);
+}
diff --git a/lib/libcurses/unctrl.c b/lib/libcurses/unctrl.c
new file mode 100644
index 00000000000..ff52230b2e9
--- /dev/null
+++ b/lib/libcurses/unctrl.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 1981, 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)unctrl.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+char *__unctrl[256] = {
+ "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G",
+ "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O",
+ "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
+ "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_",
+ " ", "!", "\"", "#", "$", "%", "&", "'",
+ "(", ")", "*", "+", ",", "-", ".", "/",
+ "0", "1", "2", "3", "4", "5", "6", "7",
+ "8", "9", ":", ";", "<", "=", ">", "?",
+ "@", "A", "B", "C", "D", "E", "F", "G",
+ "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W",
+ "X", "Y", "Z", "[", "\\", "]", "^", "_",
+ "`", "a", "b", "c", "d", "e", "f", "g",
+ "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w",
+ "x", "y", "z", "{", "|", "}", "~", "^?",
+
+ "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87",
+ "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e", "0x8f",
+ "0x90", "0x91", "0x92", "0x93", "0x94", "0x95", "0x96", "0x97",
+ "0x98", "0x99", "0x9a", "0x9b", "0x9c", "0x9d", "0x9e", "0x9f",
+ "0xa0", "0xa1", "0xa2", "0xa3", "0xa4", "0xa5", "0xa6", "0xa7",
+ "0xa8", "0xa9", "0xaa", "0xab", "0xac", "0xad", "0xae", "0xaf",
+ "0xb0", "0xb1", "0xb2", "0xb3", "0xb4", "0xb5", "0xb6", "0xb7",
+ "0xb8", "0xb9", "0xba", "0xbb", "0xbc", "0xbd", "0xbe", "0xbf",
+ "0xc0", "0xc1", "0xc2", "0xc3", "0xc4", "0xc5", "0xc6", "0xc7",
+ "0xc8", "0xc9", "0xca", "0xcb", "0xcc", "0xcd", "0xce", "0xcf",
+ "0xd0", "0xd1", "0xd2", "0xd3", "0xd4", "0xd5", "0xd6", "0xd7",
+ "0xd8", "0xd9", "0xda", "0xdb", "0xdc", "0xdd", "0xde", "0xdf",
+ "0xe0", "0xe1", "0xe2", "0xe3", "0xe4", "0xe5", "0xe6", "0xe7",
+ "0xe8", "0xe9", "0xea", "0xeb", "0xec", "0xed", "0xee", "0xef",
+ "0xf0", "0xf1", "0xf2", "0xf3", "0xf4", "0xf5", "0xf6", "0xf7",
+ "0xf8", "0xf9", "0xfa", "0xfb", "0xfc", "0xfd", "0xfe", "0xff",
+};
+
+char __unctrllen[256] = {
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 2,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 4, 4,
+};