xref: /original-bsd/usr.bin/tip/remote.c (revision 6c57d260)
1 /*	remote.c	4.1	81/05/09	*/
2 # include "tip.h"
3 
4 /*
5  * Attributes to be gleened from remote host description
6  *   data base.
7  */
8 static char **caps[] = {
9 	&AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN
10 };
11 
12 static char *capstrings[] = {
13 	"at", "dv", "cm", "cu", "el", "ie", "oe", "pn", 0
14 };
15 
16 char *rgetstr();
17 
18 static
19 getremcap(host)
20 	register char *host;
21 {
22 	int stat;
23 	char tbuf[BUFSIZ];
24 	static char buf[BUFSIZ/2];
25 	char *bp = buf;
26 	register char **p, ***q;
27 
28 	if ((stat = rgetent(tbuf, host)) <= 0) {
29 		fprintf(stderr, stat == 0 ?
30 			"tip: unknown host %s\n" :
31 			"tip: can't open host description file\n", host);
32 		exit(3);
33 	}
34 
35 	for (p = capstrings, q = caps; *p != NULL; p++, q++)
36 		**q = rgetstr(*p, &bp);
37 	if ((BR = rgetnum("br")) < 0)
38 		BR = DEFBR;
39 	if ((FS = rgetnum("fs")) < 0)
40 		FS = DEFFS;
41 	DU = rgetflag("du");
42 	if (DV == NOSTR) {
43 		fprintf(stderr, "%s: missing device spec\n", host);
44 		exit(3);
45 	}
46 	if (DU && CU == NOSTR)
47 		CU = DV;
48 	if (DU && PN == NOSTR) {
49 		fprintf(stderr, "%s: missing phone number\n", host);
50 		exit(3);
51 	}
52 	HO = host;
53 }
54 
55 char *
56 getremote(host)
57 	char *host;
58 {
59 	register char *cp;
60 	static char *next;
61 	static int lookedup = 0;
62 
63 	if (!lookedup) {
64 		if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
65 			fprintf(stderr, "tip: no host specified\n");
66 			exit(3);
67 		}
68 		getremcap(host);
69 		next = DV;
70 		lookedup++;
71 	}
72 	/*
73 	 * We return a new device each time we're called (to allow
74 	 *   a rotary action to be simulated)
75 	 */
76 	if (next == NOSTR)
77 		return(NOSTR);
78 	if ((cp = index(next, ',')) == NULL) {
79 		DV = next;
80 		next = NOSTR;
81 	} else {
82 		*cp++ = '\0';
83 		DV = next;
84 		next = cp;
85 	}
86 	return(DV);
87 }
88