summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1998-07-23 21:10:24 +0000
committermillert <millert@openbsd.org>1998-07-23 21:10:24 +0000
commita7461f95094201bce298ef3f475cfb5396c9cad3 (patch)
tree78764db7dc388b9d92cca0ec3e16eba04b6cc4b4
parentportable bootstrap thing; lidl@eng.us.uu.net (diff)
downloadwireguard-openbsd-a7461f95094201bce298ef3f475cfb5396c9cad3.tar.xz
wireguard-openbsd-a7461f95094201bce298ef3f475cfb5396c9cad3.zip
unified libtermcap/libocurses
-rw-r--r--lib/libocurses/Makefile22
-rw-r--r--lib/libocurses/TEST/tc1.c63
-rw-r--r--lib/libocurses/TEST/tc2.c90
-rw-r--r--lib/libocurses/TEST/tc3.c112
-rw-r--r--lib/libocurses/ocurses.37
-rw-r--r--lib/libocurses/pathnames.h39
-rw-r--r--lib/libocurses/shlib_version4
-rw-r--r--lib/libocurses/termcap.c232
-rw-r--r--lib/libocurses/tgoto.c232
-rw-r--r--lib/libocurses/tputs.c133
10 files changed, 923 insertions, 11 deletions
diff --git a/lib/libocurses/Makefile b/lib/libocurses/Makefile
index e748ce0d7a0..19d9d0790fd 100644
--- a/lib/libocurses/Makefile
+++ b/lib/libocurses/Makefile
@@ -1,7 +1,8 @@
-# @(#)Makefile 8.2 (Berkeley) 1/2/94
+# $OpenBSD: Makefile,v 1.4 1998/07/23 21:10:24 millert Exp $
CFLAGS+=#-DTFILE=\"/dev/ttyp0\"
CFLAGS+=-D_CURSES_PRIVATE -I${.CURDIR}
+CFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D
LIB= ocurses
SRCS= addbytes.c addch.c addnstr.c box.c clear.c clrtobot.c clrtoeol.c \
cr_put.c ctrace.c cur_hash.c curses.c delch.c deleteln.c delwin.c \
@@ -9,16 +10,23 @@ SRCS= addbytes.c addch.c addnstr.c box.c clear.c clrtobot.c clrtoeol.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
+SRCS+= termcap.c tgoto.c tputs.c
MAN= ocurses.3
-includes:
- -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/ocurses.h > \
- /dev/null 2>&1 || \
- ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 curses.h \
- ${DESTDIR}/usr/include/ocurses.h
-
.if make(install)
SUBDIR+= PSD.doc
.endif
+includes:
+ -cd ${.CURDIR}; cmp -s curses.h ${DESTDIR}/usr/include/ocurses.h || \
+ ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
+ curses.h ${DESTDIR}/usr/include/ocurses.h
+
+# Link libtermcap to libocurses so we don't break people's Makefiles
+afterinstall:
+ -cd ${DESTDIR}/usr/lib; \
+ for i in ${_LIBS}; do \
+ ln -f $$i `echo $$i | sed 's/ocurses/termcap/'`; \
+ done
+
.include <bsd.lib.mk>
diff --git a/lib/libocurses/TEST/tc1.c b/lib/libocurses/TEST/tc1.c
new file mode 100644
index 00000000000..fd0870adc67
--- /dev/null
+++ b/lib/libocurses/TEST/tc1.c
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 1983, 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) 1983, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)tc1.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+/*
+ * tc1 [term]
+ * dummy program to test termlib.
+ * gets entry, counts it, and prints it.
+ */
+#include <stdio.h>
+char buf[1024];
+char *getenv();
+
+main(argc, argv) char **argv; {
+ char *p;
+ int rc;
+
+ if (argc < 2)
+ p = getenv("TERM");
+ else
+ p = argv[1];
+ rc = tgetent(buf,p);
+ printf("tgetent returns %d, len=%d, text=\n'%s'\n",rc,strlen(buf),buf);
+}
diff --git a/lib/libocurses/TEST/tc2.c b/lib/libocurses/TEST/tc2.c
new file mode 100644
index 00000000000..1db9d0027e5
--- /dev/null
+++ b/lib/libocurses/TEST/tc2.c
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 1983, 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) 1983, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)tc2.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+/*
+ * tc2 [term]
+ * Dummy program to test out termlib.
+ * Commands are "tcc\n" where t is type (s for string, f for flag,
+ * or n for number) and cc is the name of the capability.
+ */
+#include <stdio.h>
+char buf[1024];
+char *getenv(), *tgetstr();
+
+main(argc, argv) char **argv; {
+ char *p, *q;
+ int rc;
+ char b[3], c;
+ char area[200];
+
+ if (argc < 2)
+ p = getenv("TERM");
+ else
+ p = argv[1];
+ rc = tgetent(buf,p);
+ for (;;) {
+ c = getchar();
+ if (c < 0)
+ exit(0);
+ b[0] = getchar();
+ if (b[0] < ' ')
+ exit(0);
+ b[1] = getchar();
+ b[2] = 0;
+ getchar();
+ switch(c) {
+ case 'f':
+ printf("%s: %d\n",b,tgetflag(b));
+ break;
+ case 'n':
+ printf("%s: %d\n",b,tgetnum(b));
+ break;
+ case 's':
+ q = area;
+ printf("%s: %s\n",b,tgetstr(b,&q));
+ break;
+ default:
+ exit(0);
+ }
+ }
+}
diff --git a/lib/libocurses/TEST/tc3.c b/lib/libocurses/TEST/tc3.c
new file mode 100644
index 00000000000..3935e10d18e
--- /dev/null
+++ b/lib/libocurses/TEST/tc3.c
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 1983, 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) 1983, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)tc3.c 8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
+
+/*
+ * tc3 [term]
+ * Dummy program to test out termlib. Input two numbers (row and col)
+ * and it prints out the tgoto string generated.
+ */
+#include <stdio.h>
+char buf[1024];
+char *getenv(), *tgetstr();
+char *rdchar();
+char *tgoto();
+char *CM;
+char cmbuff[30];
+char *x;
+char *UP;
+char *tgout;
+
+main(argc, argv) char **argv; {
+ char *p;
+ int rc;
+ int row, col;
+
+ if (argc < 2)
+ p = getenv("TERM");
+ else
+ p = argv[1];
+ rc = tgetent(buf,p);
+ x = cmbuff;
+ UP = tgetstr("up", &x);
+ printf("UP = %x = ", UP); pr(UP); printf("\n");
+ if (UP && *UP==0)
+ UP = 0;
+ CM = tgetstr("cm", &x);
+ printf("CM = "); pr(CM); printf("\n");
+ for (;;) {
+ if (scanf("%d %d", &row, &col) < 2)
+ exit(0);
+ tgout = tgoto(CM, col, row);
+ pr(tgout);
+ printf("\n");
+ }
+}
+
+pr(p)
+register char *p;
+{
+ for (; *p; p++)
+ printf("%s", rdchar(*p));
+}
+
+/*
+ * rdchar() returns a readable representation of an ASCII character
+ * using ^ for control, ' for meta.
+ */
+#include <ctype.h>
+char *rdchar(c)
+char c;
+{
+ static char ret[4];
+ register char *p = ret;
+
+ if ((c&0377) > 0177)
+ *p++ = '\'';
+ c &= 0177;
+ if (!isprint(c))
+ *p++ = '^';
+ *p++ = (isprint(c) ? c : c^0100);
+ *p = 0;
+ return (ret);
+}
diff --git a/lib/libocurses/ocurses.3 b/lib/libocurses/ocurses.3
index ea0093b61ad..c12dca6a7b5 100644
--- a/lib/libocurses/ocurses.3
+++ b/lib/libocurses/ocurses.3
@@ -1,3 +1,5 @@
+.\" $OpenBSD
+.\"
.\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
@@ -32,7 +34,7 @@
.\" @(#)curses.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
-.Dt CURSES 3
+.Dt OCURSES 3
.Os BSD 4
.Sh NAME
.Nm curses
@@ -41,7 +43,7 @@
.Nm cc
.Op Ar flags
.Ar files
-.Fl lcurses ltermcap
+.Fl locurses
.Op Ar libraries
.Sh DESCRIPTION
These routines give the user a method of updating screens with reasonable
@@ -58,6 +60,7 @@ should be called before exiting.
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr getenv 3 ,
+.Xr termcap 3
.Xr tty 4 ,
.Xr termcap 5
.Rs
diff --git a/lib/libocurses/pathnames.h b/lib/libocurses/pathnames.h
new file mode 100644
index 00000000000..a10b561095e
--- /dev/null
+++ b/lib/libocurses/pathnames.h
@@ -0,0 +1,39 @@
+/* $OpenBSD: pathnames.h,v 1.1 1998/07/23 21:10:26 millert Exp $ */
+/* $NetBSD: pathnames.h,v 1.3 1995/02/27 10:18:43 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989, 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.
+ *
+ * @(#)pathnames.h 8.1 (Berkeley) 6/4/93
+ */
+
+#define _PATH_DEF ".termcap /usr/share/misc/termcap"
diff --git a/lib/libocurses/shlib_version b/lib/libocurses/shlib_version
index c6e3f4d3fc0..012c14171d3 100644
--- a/lib/libocurses/shlib_version
+++ b/lib/libocurses/shlib_version
@@ -1,2 +1,2 @@
-major=2
-minor=1
+major=3
+minor=0
diff --git a/lib/libocurses/termcap.c b/lib/libocurses/termcap.c
new file mode 100644
index 00000000000..81cf7b6379e
--- /dev/null
+++ b/lib/libocurses/termcap.c
@@ -0,0 +1,232 @@
+/* $OpenBSD: termcap.c,v 1.1 1998/07/23 21:10:28 millert Exp $ */
+/* $NetBSD: termcap.c,v 1.7 1995/06/05 19:45:52 pk Exp $ */
+
+/*
+ * 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93";
+#else
+static char rcsid[] = "$OpenBSD: termcap.c,v 1.1 1998/07/23 21:10:28 millert Exp $";
+#endif
+#endif /* not lint */
+
+#define PBUFSIZ 512 /* max length of filename path */
+#define PVECSIZ 32 /* max number of names in path */
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <curses.h>
+#include "pathnames.h"
+
+/*
+ * termcap - routines for dealing with the terminal capability data base
+ *
+ * BUG: Should use a "last" pointer in tbuf, so that searching
+ * for capabilities alphabetically would not be a n**2/2
+ * process when large numbers of capabilities are given.
+ * Note: If we add a last pointer now we will screw up the
+ * tc capability. We really should compile termcap.
+ *
+ * Essentially all the work here is scanning and decoding escapes
+ * in string capabilities. We don't use stdio because the editor
+ * doesn't, and because living w/o it is not hard.
+ */
+
+static char *tbuf; /* termcap buffer */
+
+/*
+ * Get an entry for terminal name in buffer bp from the termcap file.
+ */
+int
+tgetent(bp, name)
+ char *bp, *name;
+{
+ register char *p;
+ register char *cp;
+ char *dummy;
+ char **fname;
+ char *home;
+ int i;
+ char pathbuf[MAXPATHLEN]; /* holds raw path of filenames */
+ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
+ char **pvec; /* holds usable tail of path vector */
+ char *termpath;
+
+ fname = pathvec;
+ pvec = pathvec;
+ tbuf = bp;
+ p = pathbuf;
+ cp = getenv("TERMCAP");
+ /*
+ * TERMCAP can have one of two things in it. It can be the name
+ * of a file to use instead of /usr/share/misc/termcap. In this
+ * case it better start with a "/". Or it can be an entry to
+ * use so we don't have to read the file. In this case it
+ * has to already have the newlines crunched out. If TERMCAP
+ * does not hold a file name then a path of names is searched
+ * instead. The path is found in the TERMPATH variable, or becomes
+ * "$HOME/.termcap /usr/share/misc/termcap" if no TERMPATH exists.
+ */
+ if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */
+ if ((termpath = getenv("TERMPATH")) != NULL)
+ strncpy(pathbuf, termpath, sizeof(pathbuf) - 1);
+ else {
+ if ((home = getenv("HOME")) != NULL) {
+ /* set up default */
+ /* $HOME first */
+ strncpy(pathbuf, home, sizeof(pathbuf) - 1 -
+ strlen(_PATH_DEF) - 1);
+ pathbuf[sizeof(pathbuf) - 1 -
+ strlen(_PATH_DEF) - 1] = '\0';
+ p += strlen(pathbuf); /* path, looking in */
+ *p++ = '/';
+ } /* if no $HOME look in current directory */
+ strncpy(p, _PATH_DEF, sizeof(pathbuf) -1 -
+ (p - pathbuf));
+ }
+ }
+ else /* user-defined name in TERMCAP */
+ strncpy(pathbuf, cp, sizeof(pathbuf) - 1); /* still can be tokenized */
+ pathbuf[sizeof(pathbuf) - 1] = '\0';
+
+ *fname++ = pathbuf; /* tokenize path into vector of names */
+ while (*++p)
+ if (*p == ' ' || *p == ':') {
+ *p = '\0';
+ while (*++p)
+ if (*p != ' ' && *p != ':')
+ break;
+ if (*p == '\0')
+ break;
+ *fname++ = p;
+ if (fname >= pathvec + PVECSIZ) {
+ fname--;
+ break;
+ }
+ }
+ *fname = (char *) 0; /* mark end of vector */
+ if (cp && *cp && *cp != '/')
+ if (cgetset(cp) < 0)
+ return (-2);
+
+ dummy = NULL;
+ i = cgetent(&dummy, pathvec, name);
+
+ if (i == 0 && bp != NULL) {
+ strncpy(bp, dummy, 1023);
+ bp[1023] = '\0';
+ if ((cp = strrchr(bp, ':')) != NULL)
+ if (cp[1] != '\0')
+ cp[1] = '\0';
+ }
+ else if (i == 0 && bp == NULL)
+ tbuf = dummy;
+ else if (dummy != NULL)
+ free(dummy);
+
+ /* no tc reference loop return code in libterm XXX */
+ if (i == -3)
+ return (-1);
+ return (i + 1);
+}
+
+/*
+ * Return the (numeric) option id.
+ * Numeric options look like
+ * li#80
+ * i.e. the option string is separated from the numeric value by
+ * a # character. If the option is not found we return -1.
+ * Note that we handle octal numbers beginning with 0.
+ */
+int
+tgetnum(id)
+ char *id;
+{
+ long num;
+
+ if (cgetnum(tbuf, id, &num) == 0)
+ return (num);
+ else
+ return (-1);
+}
+
+/*
+ * Handle a flag option.
+ * Flag options are given "naked", i.e. followed by a : or the end
+ * of the buffer. Return 1 if we find the option, or 0 if it is
+ * not given.
+ */
+int
+tgetflag(id)
+ char *id;
+{
+ return (cgetcap(tbuf, id, ':') != NULL);
+}
+
+/*
+ * Get a string valued option.
+ * These are given as
+ * cl=^Z
+ * Much decoding is done on the strings, and the strings are
+ * placed in area, which is a ref parameter which is updated.
+ * No checking on area overflow.
+ */
+char *
+tgetstr(id, area)
+ char *id, **area;
+{
+ char ids[3];
+ char *s;
+ int i;
+
+ /*
+ * XXX
+ * This is for all the boneheaded programs that relied on tgetstr
+ * to look only at the first 2 characters of the string passed...
+ */
+ *ids = *id;
+ ids[1] = id[1];
+ ids[2] = '\0';
+
+ if ((i = cgetstr(tbuf, ids, &s)) < 0)
+ return NULL;
+
+ strcpy(*area, s);
+ *area += i + 1;
+ return (s);
+}
diff --git a/lib/libocurses/tgoto.c b/lib/libocurses/tgoto.c
new file mode 100644
index 00000000000..5c7a43f9b39
--- /dev/null
+++ b/lib/libocurses/tgoto.c
@@ -0,0 +1,232 @@
+/* $OpenBSD: tgoto.c,v 1.1 1998/07/23 21:10:28 millert Exp $ */
+/* $NetBSD: tgoto.c,v 1.5 1995/06/05 19:45:54 pk Exp $ */
+
+/*
+ * 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tgoto.c 8.1 (Berkeley) 6/4/93";
+#else
+static char rcsid[] = "$OpenBSD: tgoto.c,v 1.1 1998/07/23 21:10:28 millert Exp $";
+#endif
+#endif /* not lint */
+
+#include <string.h>
+#include <curses.h>
+
+#define CTRL(c) ((c) & 037)
+
+#define MAXRETURNSIZE 64
+
+char *UP;
+char *BC;
+
+/*
+ * Routine to perform cursor addressing.
+ * CM is a string containing printf type escapes to allow
+ * cursor addressing. We start out ready to print the destination
+ * line, and switch each time we print row or column.
+ * The following escapes are defined for substituting row/column:
+ *
+ * %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
+ * %r reverses row/column
+ * %i increments row/column (for one origin indexing)
+ * %% gives %
+ * %B BCD (2 decimal digits encoded in one byte)
+ * %D Delta Data (backwards bcd)
+ *
+ * all other characters are ``self-inserting''.
+ */
+char *
+tgoto(CM, destcol, destline)
+ char *CM;
+ int destcol, destline;
+{
+ static char result[MAXRETURNSIZE];
+ static char added[10];
+ char *cp = CM;
+ register char *dp = result;
+ register int c;
+ int oncol = 0;
+ register int which = destline;
+
+ if (cp == 0) {
+toohard:
+ /*
+ * ``We don't do that under BOZO's big top''
+ */
+ return ("OOPS");
+ }
+ added[0] = 0;
+ while ((c = *cp++) != '\0') {
+ if (c != '%') {
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = c;
+ continue;
+ }
+ switch (c = *cp++) {
+
+#ifdef CM_N
+ case 'n':
+ destcol ^= 0140;
+ destline ^= 0140;
+ goto setwhich;
+#endif
+
+ case 'd':
+ if (which < 10)
+ goto one;
+ if (which < 100)
+ goto two;
+ /* fall into... */
+
+ case '3':
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = (which / 100) | '0';
+ which %= 100;
+ /* fall into... */
+
+ case '2':
+two:
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = which / 10 | '0';
+one:
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = which % 10 | '0';
+swap:
+ oncol = 1 - oncol;
+setwhich:
+ which = oncol ? destcol : destline;
+ continue;
+
+#ifdef CM_GT
+ case '>':
+ if (which > *cp++)
+ which += *cp++;
+ else
+ cp++;
+ continue;
+#endif
+
+ case '+':
+ which += *cp++;
+ /* fall into... */
+
+ case '.':
+ /*
+ * This code is worth scratching your head at for a
+ * while. The idea is that various weird things can
+ * happen to nulls, EOT's, tabs, and newlines by the
+ * tty driver, arpanet, and so on, so we don't send
+ * them if we can help it.
+ *
+ * Tab is taken out to get Ann Arbors to work, otherwise
+ * when they go to column 9 we increment which is wrong
+ * because bcd isn't continuous. We should take out
+ * the rest too, or run the thing through more than
+ * once until it doesn't make any of these, but that
+ * would make termlib (and hence pdp-11 ex) bigger,
+ * and also somewhat slower. This requires all
+ * programs which use termlib to stty tabs so they
+ * don't get expanded. They should do this anyway
+ * because some terminals use ^I for other things,
+ * like nondestructive space.
+ */
+ if (which == 0 || which == CTRL('d') || /* which == '\t' || */ which == '\n') {
+ if (oncol || UP) /* Assumption: backspace works */
+ /*
+ * Loop needed because newline happens
+ * to be the successor of tab.
+ */
+ do {
+ if (strlen(added) + 1 >= sizeof(added))
+ goto toohard;
+ strcat(added, oncol ? (BC ? BC : "\b") : UP);
+ which++;
+ } while (which == '\n');
+ }
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = which;
+ goto swap;
+
+ case 'r':
+ oncol = 1;
+ goto setwhich;
+
+ case 'i':
+ destcol++;
+ destline++;
+ which++;
+ continue;
+
+ case '%':
+ if (dp >= &result[MAXRETURNSIZE])
+ goto toohard;
+ *dp++ = c;
+ continue;
+
+#ifdef CM_B
+ case 'B':
+ which = (which/10 << 4) + which%10;
+ continue;
+#endif
+
+#ifdef CM_D
+ case 'D':
+ which = which - 2 * (which%16);
+ continue;
+#endif
+
+ default:
+ goto toohard;
+ }
+ }
+ if (dp - result + strlen(added) >= MAXRETURNSIZE - 1)
+ goto toohard;
+ strcpy(dp, added);
+ return (result);
+}
diff --git a/lib/libocurses/tputs.c b/lib/libocurses/tputs.c
new file mode 100644
index 00000000000..fd8e7cfaff7
--- /dev/null
+++ b/lib/libocurses/tputs.c
@@ -0,0 +1,133 @@
+/* $OpenBSD: tputs.c,v 1.1 1998/07/23 21:10:28 millert Exp $ */
+/* $NetBSD: tputs.c,v 1.5 1995/06/06 08:14:37 pk Exp $ */
+
+/*
+ * 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.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)tputs.c 8.1 (Berkeley) 6/4/93";
+#else
+static char rcsid[] = "$OpenBSD: tputs.c,v 1.1 1998/07/23 21:10:28 millert Exp $";
+#endif
+#endif /* not lint */
+
+#include <sgtty.h>
+#include <ctype.h>
+#include <curses.h>
+#undef ospeed
+
+/*
+ * The following array gives the number of tens of milliseconds per
+ * character for each speed as returned by gtty. Thus since 300
+ * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
+ */
+static
+short tmspc10[] = {
+ 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
+};
+
+short ospeed;
+char PC;
+
+/*
+ * Put the character string cp out, with padding.
+ * The number of affected lines is affcnt, and the routine
+ * used to output one character is outc.
+ */
+void
+tputs(cp, affcnt, outc)
+ register char *cp;
+ int affcnt;
+ void (*outc) __P((int));
+{
+ register int i = 0;
+ register int mspc10;
+
+ if (cp == 0)
+ return;
+
+ /*
+ * Convert the number representing the delay.
+ */
+ if (isdigit(*cp)) {
+ do
+ i = i * 10 + *cp++ - '0';
+ while (isdigit(*cp));
+ }
+ i *= 10;
+ if (*cp == '.') {
+ cp++;
+ if (isdigit(*cp))
+ i += *cp - '0';
+ /*
+ * Only one digit to the right of the decimal point.
+ */
+ while (isdigit(*cp))
+ cp++;
+ }
+
+ /*
+ * If the delay is followed by a `*', then
+ * multiply by the affected lines count.
+ */
+ if (*cp == '*')
+ cp++, i *= affcnt;
+
+ /*
+ * The guts of the string.
+ */
+ while (*cp)
+ (*outc)(*cp++);
+
+ /*
+ * If no delay needed, or output speed is
+ * not comprehensible, then don't try to delay.
+ */
+ if (i == 0)
+ return;
+ if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
+ return;
+
+ /*
+ * Round up by a half a character frame,
+ * and then do the delay.
+ * Too bad there are no user program accessible programmed delays.
+ * Transmitting pad characters slows many
+ * terminals down and also loads the system.
+ */
+ mspc10 = tmspc10[ospeed];
+ i += mspc10 / 2;
+ for (i /= mspc10; i > 0; i--)
+ (*outc)(PC);
+}