xref: /original-bsd/usr.bin/tip/remote.c (revision 1f3a482a)
1 /*	remote.c	4.2	81/06/16	*/
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 	HW = rgetflag("hw");
43 	if (DV == NOSTR) {
44 		fprintf(stderr, "%s: missing device spec\n", host);
45 		exit(3);
46 	}
47 	if (DU && CU == NOSTR)
48 		CU = DV;
49 	if (DU && PN == NOSTR) {
50 		fprintf(stderr, "%s: missing phone number\n", host);
51 		exit(3);
52 	}
53 	HO = host;
54 }
55 
56 char *
57 getremote(host)
58 	char *host;
59 {
60 	register char *cp;
61 	static char *next;
62 	static int lookedup = 0;
63 
64 	if (!lookedup) {
65 		if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
66 			fprintf(stderr, "tip: no host specified\n");
67 			exit(3);
68 		}
69 		getremcap(host);
70 		next = DV;
71 		lookedup++;
72 	}
73 	/*
74 	 * We return a new device each time we're called (to allow
75 	 *   a rotary action to be simulated)
76 	 */
77 	if (next == NOSTR)
78 		return(NOSTR);
79 	if ((cp = index(next, ',')) == NULL) {
80 		DV = next;
81 		next = NOSTR;
82 	} else {
83 		*cp++ = '\0';
84 		DV = next;
85 		next = cp;
86 	}
87 	return(DV);
88 }
89