date and time created 83/06/20 21:39:48 by sam
[unix-history] / usr / src / usr.bin / tip / remote.c
CommitLineData
6b46907f 1/* remote.c 4.6 83/06/15 */
8274ea85
BJ
2# include "tip.h"
3
6b46907f
RC
4static char *sccsid = "@(#)remote.c 4.6 %G%";
5
8274ea85
BJ
6/*
7 * Attributes to be gleened from remote host description
8 * data base.
9 */
10static char **caps[] = {
6b46907f
RC
11 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
12 &ES, &EX, &FO, &RC, &RE, &PA
8274ea85
BJ
13};
14
15static char *capstrings[] = {
6b46907f
RC
16 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
17 "di", "es", "ex", "fo", "rc", "re", "pa", 0
8274ea85
BJ
18};
19
20char *rgetstr();
21
22static
23getremcap(host)
24 register char *host;
25{
26 int stat;
27 char tbuf[BUFSIZ];
28 static char buf[BUFSIZ/2];
29 char *bp = buf;
30 register char **p, ***q;
31
32 if ((stat = rgetent(tbuf, host)) <= 0) {
33 fprintf(stderr, stat == 0 ?
34 "tip: unknown host %s\n" :
35 "tip: can't open host description file\n", host);
36 exit(3);
37 }
38
39 for (p = capstrings, q = caps; *p != NULL; p++, q++)
3f48242d
SL
40 if (**q == NULL)
41 **q = rgetstr(*p, &bp);
42 if (!BR && (BR = rgetnum("br")) < 0)
8274ea85
BJ
43 BR = DEFBR;
44 if ((FS = rgetnum("fs")) < 0)
45 FS = DEFFS;
3f48242d
SL
46 if (DU < 0)
47 DU = 0;
48 else
49 DU = rgetflag("du");
8274ea85
BJ
50 if (DV == NOSTR) {
51 fprintf(stderr, "%s: missing device spec\n", host);
52 exit(3);
53 }
54 if (DU && CU == NOSTR)
55 CU = DV;
56 if (DU && PN == NOSTR) {
57 fprintf(stderr, "%s: missing phone number\n", host);
58 exit(3);
59 }
6b46907f
RC
60
61 HD = rgetflag("hd");
62
3e90c816
SL
63 /*
64 * This effectively eliminates the "hw" attribute
65 * from the description file
66 */
67 if (!HW)
68 HW = (CU == NOSTR) || (DU && equal(DV, CU));
8274ea85 69 HO = host;
6b46907f
RC
70 /*
71 * see if uppercase mode should be turned on initially
72 */
73 if (rgetflag("ra")) boolean(value(RAISE)) = 1;
74 if (rgetflag("ec")) boolean(value(ECHOCHECK)) = 1;
75 if (rgetflag("be")) boolean(value(BEAUTIFY)) = 1;
76 if (rgetflag("nb")) boolean(value(BEAUTIFY)) = 0;
77 if (rgetflag("sc")) boolean(value(SCRIPT)) = 1;
78 if (rgetflag("tb")) boolean(value(TABEXPAND)) = 1;
79 if (rgetflag("vb")) boolean(value(VERBOSE)) = 1;
80 if (rgetflag("nv")) boolean(value(VERBOSE)) = 0;
81 if (rgetflag("ta")) boolean(value(TAND)) = 1;
82 if (rgetflag("nt")) boolean(value(TAND)) = 0;
83 if (rgetflag("rw")) boolean(value(RAWFTP)) = 1;
84 if (rgetflag("hd")) boolean(value(HALFDUPLEX)) = 1;
85 if (*RE == NULL) RE = (char *)"tip.record";
86 if (*EX == NULL) EX = (char *)"\t\n\b\f";
87 if (ES != NOSTR) vstring("es",ES);
88 if (FO != NOSTR) vstring("fo",FO);
89 if (PR != NOSTR) vstring("pr",PR);
90 if (RC != NOSTR) vstring("rc",RC);
91 if ((DL = rgetnum("dl")) < 0) DL = 0;
92 if ((CL = rgetnum("cl")) < 0) CL = 0;
93 if ((ET = rgetnum("et")) < 0) ET = 10;
8274ea85
BJ
94}
95
96char *
97getremote(host)
98 char *host;
99{
100 register char *cp;
101 static char *next;
102 static int lookedup = 0;
103
104 if (!lookedup) {
105 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
106 fprintf(stderr, "tip: no host specified\n");
107 exit(3);
108 }
109 getremcap(host);
110 next = DV;
111 lookedup++;
112 }
113 /*
114 * We return a new device each time we're called (to allow
115 * a rotary action to be simulated)
116 */
117 if (next == NOSTR)
3f48242d 118 return (NOSTR);
8274ea85
BJ
119 if ((cp = index(next, ',')) == NULL) {
120 DV = next;
121 next = NOSTR;
122 } else {
123 *cp++ = '\0';
124 DV = next;
125 next = cp;
126 }
3f48242d 127 return (DV);
8274ea85 128}