X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/3095e901c9460cc57063aba07d9535085da7b8fe..647d0ea2dedf292593f7d95d287d445c297ccca2:/usr/src/usr.bin/tip/remcap.c diff --git a/usr/src/usr.bin/tip/remcap.c b/usr/src/usr.bin/tip/remcap.c index 38a81cda62..c57356940c 100644 --- a/usr/src/usr.bin/tip/remcap.c +++ b/usr/src/usr.bin/tip/remcap.c @@ -1,29 +1,66 @@ -/* remcap.c 4.2 81/05/20 */ -/* Copyright (c) 1979 Regents of the University of California */ -#define BUFSIZ 1024 -#define MAXHOP 32 /* max number of tc= indirections */ +/* + * Copyright (c) 1983 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[] = "@(#)remcap.c 5.5 (Berkeley) 2/2/91"; +#endif /* not lint */ -#include -#include "local/uparm.h" /* * remcap - routines for dealing with the remote host data base * - * Made from termcap with the following defines. + * derived from termcap */ -#define REMOTE /* special for tip */ +#include +#include +#include +#include "pathnames.h" + +#ifndef BUFSIZ +#define BUFSIZ 1024 +#endif +#define MAXHOP 32 /* max number of tc= indirections */ -#ifdef REMOTE #define tgetent rgetent #define tnchktc rnchktc #define tnamatch rnamatch #define tgetnum rgetnum #define tgetflag rgetflag #define tgetstr rgetstr -#undef E_TERMCAP -#define E_TERMCAP "/etc/remote" -#define V6 /* don't look in environment */ +#define E_TERMCAP RM = _PATH_REMOTE +#define V_TERMCAP "REMOTE" +#define V_TERM "HOST" + char *RM; -#endif /* * termcap - routines for dealing with the terminal capability data base @@ -45,6 +82,7 @@ char *tskip(); char *tgetstr(); char *tdecode(); char *getenv(); +static char *remotefile; /* * Get an entry for terminal name in buffer bp, @@ -54,17 +92,46 @@ char *getenv(); tgetent(bp, name) char *bp, *name; { - register char *cp; + char lbuf[BUFSIZ], *cp, *p; + int rc1, rc2; + + remotefile = cp = getenv(V_TERMCAP); + if (cp == (char *)0 || strcmp(cp, _PATH_REMOTE) == 0) { + remotefile = cp = _PATH_REMOTE; + return (getent(bp, name, cp)); + } else { + if ((rc1 = getent(bp, name, cp)) != 1) + *bp = '\0'; + remotefile = cp = _PATH_REMOTE; + rc2 = getent(lbuf, name, cp); + if (rc1 != 1 && rc2 != 1) + return (rc2); + if (rc2 == 1) { + p = lbuf; + if (rc1 == 1) + while (*p++ != ':') + ; + if (strlen(bp) + strlen(p) > BUFSIZ) { + write(2, "Remcap entry too long\n", 23); + return (-1); + } + strcat(bp, p); + } + tbuf = bp; + return (1); + } +} + +getent(bp, name, cp) + char *bp, *name, *cp; +{ register int c; register int i = 0, cnt = 0; - char ibuf[BUFSIZ]; - char *cp2; + char ibuf[BUFSIZ], *cp2; int tf; tbuf = bp; tf = 0; -#ifndef V6 - cp = getenv("TERMCAP"); /* * TERMCAP can have one of two things in it. It can be the * name of a file to use instead of /etc/termcap. In this @@ -74,26 +141,17 @@ tgetent(bp, name) */ if (cp && *cp) { if (*cp!='/') { - cp2 = getenv("TERM"); - if (cp2==(char *) 0 || strcmp(name,cp2)==0) { + cp2 = getenv(V_TERM); + if (cp2 == (char *)0 || strcmp(name,cp2) == 0) { strcpy(bp,cp); - return(tnchktc()); - } else { - tf = open(E_TERMCAP, 0); - } + return (tnchktc()); + } else + tf = open(E_TERMCAP, O_RDONLY); } else - tf = open(cp, 0); + tf = open(RM = cp, O_RDONLY); } - if (tf==0) - tf = open(E_TERMCAP, 0); -#else -#ifdef REMOTE - if ((RM = getenv("REMOTE")) == (char *)0) - RM = E_TERMCAP; - tf = open(RM, 0); -#endif - tf = open(E_TERMCAP, 0); -#endif + if (tf == 0) + tf = open(E_TERMCAP, O_RDONLY); if (tf < 0) return (-1); for (;;) { @@ -109,14 +167,14 @@ tgetent(bp, name) } c = ibuf[i++]; if (c == '\n') { - if (cp > bp && cp[-1] == '\\'){ + if (cp > bp && cp[-1] == '\\') { cp--; continue; } break; } if (cp >= bp+BUFSIZ) { - write(2,"Termcap entry too long\n", 23); + write(2,"Remcap entry too long\n", 23); break; } else *cp++ = c; @@ -128,7 +186,7 @@ tgetent(bp, name) */ if (tnamatch(name)) { close(tf); - return(tnchktc()); + return (tnchktc()); } } } @@ -147,38 +205,43 @@ tnchktc() char tcbuf[BUFSIZ]; char *holdtbuf = tbuf; int l; + char *cp; p = tbuf + strlen(tbuf) - 2; /* before the last colon */ while (*--p != ':') if (p MAXHOP) { write(2, "Infinite tc= loop\n", 18); return (0); } - if (tgetent(tcbuf, tcname) != 1) - return(0); - for (q=tcbuf; *q != ':'; q++) + if (getent(tcbuf, tcname, remotefile) != 1) { + if (strcmp(remotefile, _PATH_REMOTE) == 0) + return (0); + else if (getent(tcbuf, tcname, _PATH_REMOTE) != 1) + return (0); + } + for (q = tcbuf; *q++ != ':'; ) ; l = p - holdtbuf + strlen(q); if (l > BUFSIZ) { - write(2, "Termcap entry too long\n", 23); - q[BUFSIZ - (p-tbuf)] = 0; + write(2, "Remcap entry too long\n", 23); + q[BUFSIZ - (p-holdtbuf)] = 0; } - strcpy(p, q+1); + strcpy(p, q); tbuf = holdtbuf; - return(1); + return (1); } /* @@ -194,7 +257,7 @@ tnamatch(np) Bp = tbuf; if (*Bp == '#') - return(0); + return (0); for (;;) { for (Np = np; *Np && *Bp == *Np; Bp++, Np++) continue; @@ -246,7 +309,7 @@ tgetnum(id) if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) continue; if (*bp == '@') - return(-1); + return (-1); if (*bp != '#') continue; bp++; @@ -279,7 +342,7 @@ tgetflag(id) if (!*bp || *bp == ':') return (1); else if (*bp == '@') - return(0); + return (0); } } } @@ -305,7 +368,7 @@ tgetstr(id, area) if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1]) continue; if (*bp == '@') - return(0); + return (0); if (*bp != '=') continue; bp++;