diff options
author | 2015-11-14 23:43:26 +0000 | |
---|---|---|
committer | 2015-11-14 23:43:26 +0000 | |
commit | 226e3677e5e50789fc7df5da295f18f230fcfb22 (patch) | |
tree | 27de3e0a23c7c6c6c081ab9437d1ea4315080a70 | |
parent | Copy the parts of libocurses that are needed directly to here. We (diff) | |
download | wireguard-openbsd-226e3677e5e50789fc7df5da295f18f230fcfb22.tar.xz wireguard-openbsd-226e3677e5e50789fc7df5da295f18f230fcfb22.zip |
Copy the parts of libocurses that are needed directly to here. We
continue using the libocurses varient, since it is smaller.
tested by guenther, ok millert
-rw-r--r-- | distrib/special/more/pathnames.h | 36 | ||||
-rw-r--r-- | distrib/special/more/termcap.c | 214 | ||||
-rw-r--r-- | distrib/special/more/tgoto.c | 220 | ||||
-rw-r--r-- | distrib/special/more/tputs.c | 120 |
4 files changed, 590 insertions, 0 deletions
diff --git a/distrib/special/more/pathnames.h b/distrib/special/more/pathnames.h new file mode 100644 index 00000000000..c7696f469d3 --- /dev/null +++ b/distrib/special/more/pathnames.h @@ -0,0 +1,36 @@ +/* $OpenBSD: pathnames.h,v 1.3 2015/11/14 23:43:26 deraadt 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. 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_TERMCAP "/usr/share/misc/termcap" +#define _PATH_DEF (".termcap " _PATH_TERMCAP) diff --git a/distrib/special/more/termcap.c b/distrib/special/more/termcap.c new file mode 100644 index 00000000000..59f6abfef78 --- /dev/null +++ b/distrib/special/more/termcap.c @@ -0,0 +1,214 @@ +/* $OpenBSD: termcap.c,v 1.1 2015/11/14 23:43:26 deraadt 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. 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. + */ + +#define PBUFSIZ 512 /* max length of filename path */ +#define PVECSIZ 32 /* max number of names in path */ + +#include <stdio.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <limits.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[PATH_MAX]; /* 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; + + cp = issetugid() ? NULL : 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 == NULL) { + strlcpy(pathbuf, _PATH_TERMCAP, sizeof(pathbuf)); + } else if (!cp || *cp != '/') { /* TERMCAP holds an entry */ + if ((termpath = getenv("TERMPATH")) != NULL) + strlcpy(pathbuf, termpath, sizeof(pathbuf)); + else if ((home = getenv("HOME")) == NULL || *home == '\0' || + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", home, + _PATH_DEF) >= sizeof(pathbuf)) + strlcpy(pathbuf, _PATH_DEF, sizeof(pathbuf)); + } else { /* user-defined path in TERMCAP */ + /* still can be tokenized */ + strlcpy(pathbuf, cp, sizeof(pathbuf)); + } + *fname++ = pathbuf; /* tokenize path into vector of names */ + + /* split pathbuf into a vector of paths */ + p = pathbuf; + 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) { + strlcpy(bp, dummy, 1024); + 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; + + strlcpy(*area, s, 1024); + *area += i + 1; + return (s); +} diff --git a/distrib/special/more/tgoto.c b/distrib/special/more/tgoto.c new file mode 100644 index 00000000000..044acdfe5f6 --- /dev/null +++ b/distrib/special/more/tgoto.c @@ -0,0 +1,220 @@ +/* $OpenBSD: tgoto.c,v 1.1 2015/11/14 23:43:26 deraadt 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. 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. + */ + +#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 == '\n') + && (oncol || UP)) /* Assumption: backspace works */ + /* + * Loop needed because newline happens + * to be the successor of tab. + */ + do { + if (strlcat(added, oncol ? + (BC ? BC : "\b") : UP, + sizeof(added)) >= sizeof(added)) + goto toohard; + 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 (strlcpy(dp, added, sizeof(result) - (dp - result)) + >= sizeof(result) - (dp - result)) + goto toohard; + return (result); +} diff --git a/distrib/special/more/tputs.c b/distrib/special/more/tputs.c new file mode 100644 index 00000000000..7ed2a94f3b0 --- /dev/null +++ b/distrib/special/more/tputs.c @@ -0,0 +1,120 @@ +/* $OpenBSD: tputs.c,v 1.1 2015/11/14 23:43:26 deraadt 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. 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. + */ + +#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)(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); +} |