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