Commit | Line | Data |
---|---|---|
051b1e55 | 1 | /* |
c9686c12 KB |
2 | * Copyright (c) 1983 The Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
051b1e55 DF |
16 | */ |
17 | ||
05862919 | 18 | #ifndef lint |
c9686c12 KB |
19 | static char sccsid[] = "@(#)remote.c 5.4 (Berkeley) %G%"; |
20 | #endif /* not lint */ | |
8274ea85 | 21 | |
05862919 | 22 | # include "tip.h" |
6b46907f | 23 | |
8274ea85 BJ |
24 | /* |
25 | * Attributes to be gleened from remote host description | |
26 | * data base. | |
27 | */ | |
28 | static char **caps[] = { | |
6b46907f RC |
29 | &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, |
30 | &ES, &EX, &FO, &RC, &RE, &PA | |
8274ea85 BJ |
31 | }; |
32 | ||
33 | static char *capstrings[] = { | |
6b46907f RC |
34 | "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", |
35 | "di", "es", "ex", "fo", "rc", "re", "pa", 0 | |
8274ea85 BJ |
36 | }; |
37 | ||
38 | char *rgetstr(); | |
39 | ||
40 | static | |
41 | getremcap(host) | |
42 | register char *host; | |
43 | { | |
44 | int stat; | |
45 | char tbuf[BUFSIZ]; | |
46 | static char buf[BUFSIZ/2]; | |
47 | char *bp = buf; | |
48 | register char **p, ***q; | |
49 | ||
50 | if ((stat = rgetent(tbuf, host)) <= 0) { | |
eef2b2c1 MK |
51 | if (DV || |
52 | host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { | |
53 | CU = DV; | |
54 | HO = host; | |
55 | HW = 1; | |
56 | DU = 0; | |
57 | if (!BR) | |
58 | BR = DEFBR; | |
59 | FS = DEFFS; | |
60 | return; | |
61 | } | |
8274ea85 BJ |
62 | fprintf(stderr, stat == 0 ? |
63 | "tip: unknown host %s\n" : | |
64 | "tip: can't open host description file\n", host); | |
65 | exit(3); | |
66 | } | |
67 | ||
68 | for (p = capstrings, q = caps; *p != NULL; p++, q++) | |
3f48242d SL |
69 | if (**q == NULL) |
70 | **q = rgetstr(*p, &bp); | |
71 | if (!BR && (BR = rgetnum("br")) < 0) | |
8274ea85 BJ |
72 | BR = DEFBR; |
73 | if ((FS = rgetnum("fs")) < 0) | |
74 | FS = DEFFS; | |
3f48242d SL |
75 | if (DU < 0) |
76 | DU = 0; | |
77 | else | |
78 | DU = rgetflag("du"); | |
8274ea85 BJ |
79 | if (DV == NOSTR) { |
80 | fprintf(stderr, "%s: missing device spec\n", host); | |
81 | exit(3); | |
82 | } | |
83 | if (DU && CU == NOSTR) | |
84 | CU = DV; | |
85 | if (DU && PN == NOSTR) { | |
86 | fprintf(stderr, "%s: missing phone number\n", host); | |
87 | exit(3); | |
88 | } | |
6b46907f RC |
89 | |
90 | HD = rgetflag("hd"); | |
91 | ||
3e90c816 SL |
92 | /* |
93 | * This effectively eliminates the "hw" attribute | |
94 | * from the description file | |
95 | */ | |
96 | if (!HW) | |
97 | HW = (CU == NOSTR) || (DU && equal(DV, CU)); | |
8274ea85 | 98 | HO = host; |
6b46907f RC |
99 | /* |
100 | * see if uppercase mode should be turned on initially | |
101 | */ | |
05862919 SL |
102 | if (rgetflag("ra")) |
103 | boolean(value(RAISE)) = 1; | |
104 | if (rgetflag("ec")) | |
105 | boolean(value(ECHOCHECK)) = 1; | |
106 | if (rgetflag("be")) | |
107 | boolean(value(BEAUTIFY)) = 1; | |
108 | if (rgetflag("nb")) | |
109 | boolean(value(BEAUTIFY)) = 0; | |
110 | if (rgetflag("sc")) | |
111 | boolean(value(SCRIPT)) = 1; | |
112 | if (rgetflag("tb")) | |
113 | boolean(value(TABEXPAND)) = 1; | |
114 | if (rgetflag("vb")) | |
115 | boolean(value(VERBOSE)) = 1; | |
116 | if (rgetflag("nv")) | |
117 | boolean(value(VERBOSE)) = 0; | |
118 | if (rgetflag("ta")) | |
119 | boolean(value(TAND)) = 1; | |
120 | if (rgetflag("nt")) | |
121 | boolean(value(TAND)) = 0; | |
122 | if (rgetflag("rw")) | |
123 | boolean(value(RAWFTP)) = 1; | |
124 | if (rgetflag("hd")) | |
125 | boolean(value(HALFDUPLEX)) = 1; | |
9479d9a4 | 126 | if (RE == NOSTR) |
05862919 | 127 | RE = (char *)"tip.record"; |
9479d9a4 | 128 | if (EX == NOSTR) |
05862919 SL |
129 | EX = (char *)"\t\n\b\f"; |
130 | if (ES != NOSTR) | |
131 | vstring("es", ES); | |
132 | if (FO != NOSTR) | |
133 | vstring("fo", FO); | |
134 | if (PR != NOSTR) | |
135 | vstring("pr", PR); | |
136 | if (RC != NOSTR) | |
137 | vstring("rc", RC); | |
138 | if ((DL = rgetnum("dl")) < 0) | |
139 | DL = 0; | |
140 | if ((CL = rgetnum("cl")) < 0) | |
141 | CL = 0; | |
142 | if ((ET = rgetnum("et")) < 0) | |
143 | ET = 10; | |
8274ea85 BJ |
144 | } |
145 | ||
146 | char * | |
147 | getremote(host) | |
148 | char *host; | |
149 | { | |
150 | register char *cp; | |
151 | static char *next; | |
152 | static int lookedup = 0; | |
153 | ||
154 | if (!lookedup) { | |
155 | if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { | |
156 | fprintf(stderr, "tip: no host specified\n"); | |
157 | exit(3); | |
158 | } | |
159 | getremcap(host); | |
160 | next = DV; | |
161 | lookedup++; | |
162 | } | |
163 | /* | |
164 | * We return a new device each time we're called (to allow | |
165 | * a rotary action to be simulated) | |
166 | */ | |
167 | if (next == NOSTR) | |
3f48242d | 168 | return (NOSTR); |
8274ea85 BJ |
169 | if ((cp = index(next, ',')) == NULL) { |
170 | DV = next; | |
171 | next = NOSTR; | |
172 | } else { | |
173 | *cp++ = '\0'; | |
174 | DV = next; | |
175 | next = cp; | |
176 | } | |
3f48242d | 177 | return (DV); |
8274ea85 | 178 | } |