Home | History | Annotate | Line # | Download | only in tip
remote.c revision 1.1
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1983 The Regents of the University of California.
      3  1.1  cgd  * All rights reserved.
      4  1.1  cgd  *
      5  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1  cgd  * modification, are permitted provided that the following conditions
      7  1.1  cgd  * are met:
      8  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1  cgd  *    must display the following acknowledgement:
     15  1.1  cgd  *	This product includes software developed by the University of
     16  1.1  cgd  *	California, Berkeley and its contributors.
     17  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1  cgd  *    may be used to endorse or promote products derived from this software
     19  1.1  cgd  *    without specific prior written permission.
     20  1.1  cgd  *
     21  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  cgd  * SUCH DAMAGE.
     32  1.1  cgd  */
     33  1.1  cgd 
     34  1.1  cgd #ifndef lint
     35  1.1  cgd static char sccsid[] = "@(#)remote.c	5.5 (Berkeley) 6/1/90";
     36  1.1  cgd #endif /* not lint */
     37  1.1  cgd 
     38  1.1  cgd # include "tip.h"
     39  1.1  cgd 
     40  1.1  cgd /*
     41  1.1  cgd  * Attributes to be gleened from remote host description
     42  1.1  cgd  *   data base.
     43  1.1  cgd  */
     44  1.1  cgd static char **caps[] = {
     45  1.1  cgd 	&AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
     46  1.1  cgd 	&ES, &EX, &FO, &RC, &RE, &PA
     47  1.1  cgd };
     48  1.1  cgd 
     49  1.1  cgd static char *capstrings[] = {
     50  1.1  cgd 	"at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
     51  1.1  cgd 	"di", "es", "ex", "fo", "rc", "re", "pa", 0
     52  1.1  cgd };
     53  1.1  cgd 
     54  1.1  cgd char *rgetstr();
     55  1.1  cgd 
     56  1.1  cgd static
     57  1.1  cgd getremcap(host)
     58  1.1  cgd 	register char *host;
     59  1.1  cgd {
     60  1.1  cgd 	int stat;
     61  1.1  cgd 	char tbuf[BUFSIZ];
     62  1.1  cgd 	static char buf[BUFSIZ/2];
     63  1.1  cgd 	char *bp = buf;
     64  1.1  cgd 	register char **p, ***q;
     65  1.1  cgd 
     66  1.1  cgd 	if ((stat = rgetent(tbuf, host)) <= 0) {
     67  1.1  cgd 		if (DV ||
     68  1.1  cgd 		    host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) {
     69  1.1  cgd 			CU = DV;
     70  1.1  cgd 			HO = host;
     71  1.1  cgd 			HW = 1;
     72  1.1  cgd 			DU = 0;
     73  1.1  cgd 			if (!BR)
     74  1.1  cgd 				BR = DEFBR;
     75  1.1  cgd 			FS = DEFFS;
     76  1.1  cgd 			return;
     77  1.1  cgd 		}
     78  1.1  cgd 		fprintf(stderr, stat == 0 ?
     79  1.1  cgd 			"tip: unknown host %s\n" :
     80  1.1  cgd 			"tip: can't open host description file\n", host);
     81  1.1  cgd 		exit(3);
     82  1.1  cgd 	}
     83  1.1  cgd 
     84  1.1  cgd 	for (p = capstrings, q = caps; *p != NULL; p++, q++)
     85  1.1  cgd 		if (**q == NULL)
     86  1.1  cgd 			**q = rgetstr(*p, &bp);
     87  1.1  cgd 	if (!BR && (BR = rgetnum("br")) < 0)
     88  1.1  cgd 		BR = DEFBR;
     89  1.1  cgd 	if ((FS = rgetnum("fs")) < 0)
     90  1.1  cgd 		FS = DEFFS;
     91  1.1  cgd 	if (DU < 0)
     92  1.1  cgd 		DU = 0;
     93  1.1  cgd 	else
     94  1.1  cgd 		DU = rgetflag("du");
     95  1.1  cgd 	if (DV == NOSTR) {
     96  1.1  cgd 		fprintf(stderr, "%s: missing device spec\n", host);
     97  1.1  cgd 		exit(3);
     98  1.1  cgd 	}
     99  1.1  cgd 	if (DU && CU == NOSTR)
    100  1.1  cgd 		CU = DV;
    101  1.1  cgd 	if (DU && PN == NOSTR) {
    102  1.1  cgd 		fprintf(stderr, "%s: missing phone number\n", host);
    103  1.1  cgd 		exit(3);
    104  1.1  cgd 	}
    105  1.1  cgd 
    106  1.1  cgd 	HD = rgetflag("hd");
    107  1.1  cgd 
    108  1.1  cgd 	/*
    109  1.1  cgd 	 * This effectively eliminates the "hw" attribute
    110  1.1  cgd 	 *   from the description file
    111  1.1  cgd 	 */
    112  1.1  cgd 	if (!HW)
    113  1.1  cgd 		HW = (CU == NOSTR) || (DU && equal(DV, CU));
    114  1.1  cgd 	HO = host;
    115  1.1  cgd 	/*
    116  1.1  cgd 	 * see if uppercase mode should be turned on initially
    117  1.1  cgd 	 */
    118  1.1  cgd 	if (rgetflag("ra"))
    119  1.1  cgd 		boolean(value(RAISE)) = 1;
    120  1.1  cgd 	if (rgetflag("ec"))
    121  1.1  cgd 		boolean(value(ECHOCHECK)) = 1;
    122  1.1  cgd 	if (rgetflag("be"))
    123  1.1  cgd 		boolean(value(BEAUTIFY)) = 1;
    124  1.1  cgd 	if (rgetflag("nb"))
    125  1.1  cgd 		boolean(value(BEAUTIFY)) = 0;
    126  1.1  cgd 	if (rgetflag("sc"))
    127  1.1  cgd 		boolean(value(SCRIPT)) = 1;
    128  1.1  cgd 	if (rgetflag("tb"))
    129  1.1  cgd 		boolean(value(TABEXPAND)) = 1;
    130  1.1  cgd 	if (rgetflag("vb"))
    131  1.1  cgd 		boolean(value(VERBOSE)) = 1;
    132  1.1  cgd 	if (rgetflag("nv"))
    133  1.1  cgd 		boolean(value(VERBOSE)) = 0;
    134  1.1  cgd 	if (rgetflag("ta"))
    135  1.1  cgd 		boolean(value(TAND)) = 1;
    136  1.1  cgd 	if (rgetflag("nt"))
    137  1.1  cgd 		boolean(value(TAND)) = 0;
    138  1.1  cgd 	if (rgetflag("rw"))
    139  1.1  cgd 		boolean(value(RAWFTP)) = 1;
    140  1.1  cgd 	if (rgetflag("hd"))
    141  1.1  cgd 		boolean(value(HALFDUPLEX)) = 1;
    142  1.1  cgd 	if (RE == NOSTR)
    143  1.1  cgd 		RE = (char *)"tip.record";
    144  1.1  cgd 	if (EX == NOSTR)
    145  1.1  cgd 		EX = (char *)"\t\n\b\f";
    146  1.1  cgd 	if (ES != NOSTR)
    147  1.1  cgd 		vstring("es", ES);
    148  1.1  cgd 	if (FO != NOSTR)
    149  1.1  cgd 		vstring("fo", FO);
    150  1.1  cgd 	if (PR != NOSTR)
    151  1.1  cgd 		vstring("pr", PR);
    152  1.1  cgd 	if (RC != NOSTR)
    153  1.1  cgd 		vstring("rc", RC);
    154  1.1  cgd 	if ((DL = rgetnum("dl")) < 0)
    155  1.1  cgd 		DL = 0;
    156  1.1  cgd 	if ((CL = rgetnum("cl")) < 0)
    157  1.1  cgd 		CL = 0;
    158  1.1  cgd 	if ((ET = rgetnum("et")) < 0)
    159  1.1  cgd 		ET = 10;
    160  1.1  cgd }
    161  1.1  cgd 
    162  1.1  cgd char *
    163  1.1  cgd getremote(host)
    164  1.1  cgd 	char *host;
    165  1.1  cgd {
    166  1.1  cgd 	register char *cp;
    167  1.1  cgd 	static char *next;
    168  1.1  cgd 	static int lookedup = 0;
    169  1.1  cgd 
    170  1.1  cgd 	if (!lookedup) {
    171  1.1  cgd 		if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
    172  1.1  cgd 			fprintf(stderr, "tip: no host specified\n");
    173  1.1  cgd 			exit(3);
    174  1.1  cgd 		}
    175  1.1  cgd 		getremcap(host);
    176  1.1  cgd 		next = DV;
    177  1.1  cgd 		lookedup++;
    178  1.1  cgd 	}
    179  1.1  cgd 	/*
    180  1.1  cgd 	 * We return a new device each time we're called (to allow
    181  1.1  cgd 	 *   a rotary action to be simulated)
    182  1.1  cgd 	 */
    183  1.1  cgd 	if (next == NOSTR)
    184  1.1  cgd 		return (NOSTR);
    185  1.1  cgd 	if ((cp = index(next, ',')) == NULL) {
    186  1.1  cgd 		DV = next;
    187  1.1  cgd 		next = NOSTR;
    188  1.1  cgd 	} else {
    189  1.1  cgd 		*cp++ = '\0';
    190  1.1  cgd 		DV = next;
    191  1.1  cgd 		next = cp;
    192  1.1  cgd 	}
    193  1.1  cgd 	return (DV);
    194  1.1  cgd }
    195