Commit | Line | Data |
---|---|---|
051b1e55 | 1 | /* |
abfba3de KB |
2 | * Copyright (c) 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
c9686c12 | 4 | * |
22629db9 | 5 | * |
0d740705 | 6 | * %sccs.include.redist.c% |
051b1e55 DF |
7 | */ |
8 | ||
05862919 | 9 | #ifndef lint |
597dd923 | 10 | static char copyright[] = |
abfba3de KB |
11 | "@(#) Copyright (c) 1992, 1993\n\ |
12 | The Regents of the University of California. All rights reserved.\n"; | |
c9686c12 | 13 | #endif /* not lint */ |
8274ea85 | 14 | |
0d740705 | 15 | #ifndef lint |
abfba3de | 16 | static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) %G%"; |
0d740705 | 17 | #endif /* not lint */ |
6b46907f | 18 | |
0b4bd5f2 KB |
19 | #include <stdio.h> |
20 | #include <stdlib.h> | |
21 | ||
22 | #include "pathnames.h" | |
23 | #include "tip.h" | |
24 | ||
8274ea85 BJ |
25 | /* |
26 | * Attributes to be gleened from remote host description | |
27 | * data base. | |
28 | */ | |
29 | static char **caps[] = { | |
6b46907f RC |
30 | &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, |
31 | &ES, &EX, &FO, &RC, &RE, &PA | |
8274ea85 BJ |
32 | }; |
33 | ||
34 | static char *capstrings[] = { | |
6b46907f RC |
35 | "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", |
36 | "di", "es", "ex", "fo", "rc", "re", "pa", 0 | |
8274ea85 BJ |
37 | }; |
38 | ||
22629db9 EA |
39 | static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; |
40 | ||
41 | #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) | |
8274ea85 BJ |
42 | |
43 | static | |
44 | getremcap(host) | |
45 | register char *host; | |
46 | { | |
8274ea85 | 47 | register char **p, ***q; |
22629db9 EA |
48 | char *bp; |
49 | char *rempath; | |
50 | int stat; | |
8274ea85 | 51 | |
22629db9 EA |
52 | rempath = getenv("REMOTE"); |
53 | if (rempath != NULL) | |
54 | if (*rempath != '/') | |
55 | /* we have an entry */ | |
56 | cgetset(rempath); | |
57 | else { /* we have a path */ | |
58 | db_array[1] = rempath; | |
59 | db_array[2] = _PATH_REMOTE; | |
60 | } | |
61 | ||
62 | if ((stat = cgetent(&bp, db_array, host)) < 0) { | |
eef2b2c1 MK |
63 | if (DV || |
64 | host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { | |
65 | CU = DV; | |
66 | HO = host; | |
67 | HW = 1; | |
68 | DU = 0; | |
69 | if (!BR) | |
70 | BR = DEFBR; | |
71 | FS = DEFFS; | |
72 | return; | |
73 | } | |
22629db9 EA |
74 | switch(stat) { |
75 | case -1: | |
76 | fprintf(stderr, "tip: unknown host %s\n", host); | |
77 | break; | |
78 | case -2: | |
79 | fprintf(stderr, | |
80 | "tip: can't open host description file\n"); | |
81 | break; | |
82 | case -3: | |
83 | fprintf(stderr, | |
84 | "tip: possible reference loop in host description file\n"); | |
85 | break; | |
86 | } | |
8274ea85 BJ |
87 | exit(3); |
88 | } | |
89 | ||
90 | for (p = capstrings, q = caps; *p != NULL; p++, q++) | |
3f48242d | 91 | if (**q == NULL) |
22629db9 EA |
92 | cgetstr(bp, *p, *q); |
93 | if (!BR && (cgetnum(bp, "br", &BR) == -1)) | |
8274ea85 | 94 | BR = DEFBR; |
22629db9 | 95 | if (cgetnum(bp, "fs", &FS) == -1) |
8274ea85 | 96 | FS = DEFFS; |
3f48242d SL |
97 | if (DU < 0) |
98 | DU = 0; | |
99 | else | |
22629db9 | 100 | DU = cgetflag("du"); |
8274ea85 BJ |
101 | if (DV == NOSTR) { |
102 | fprintf(stderr, "%s: missing device spec\n", host); | |
103 | exit(3); | |
104 | } | |
105 | if (DU && CU == NOSTR) | |
106 | CU = DV; | |
107 | if (DU && PN == NOSTR) { | |
108 | fprintf(stderr, "%s: missing phone number\n", host); | |
109 | exit(3); | |
110 | } | |
6b46907f | 111 | |
22629db9 | 112 | HD = cgetflag("hd"); |
6b46907f | 113 | |
3e90c816 SL |
114 | /* |
115 | * This effectively eliminates the "hw" attribute | |
116 | * from the description file | |
117 | */ | |
118 | if (!HW) | |
119 | HW = (CU == NOSTR) || (DU && equal(DV, CU)); | |
8274ea85 | 120 | HO = host; |
6b46907f RC |
121 | /* |
122 | * see if uppercase mode should be turned on initially | |
123 | */ | |
22629db9 | 124 | if (cgetflag("ra")) |
05862919 | 125 | boolean(value(RAISE)) = 1; |
22629db9 | 126 | if (cgetflag("ec")) |
05862919 | 127 | boolean(value(ECHOCHECK)) = 1; |
22629db9 | 128 | if (cgetflag("be")) |
05862919 | 129 | boolean(value(BEAUTIFY)) = 1; |
22629db9 | 130 | if (cgetflag("nb")) |
05862919 | 131 | boolean(value(BEAUTIFY)) = 0; |
22629db9 | 132 | if (cgetflag("sc")) |
05862919 | 133 | boolean(value(SCRIPT)) = 1; |
22629db9 | 134 | if (cgetflag("tb")) |
05862919 | 135 | boolean(value(TABEXPAND)) = 1; |
22629db9 | 136 | if (cgetflag("vb")) |
05862919 | 137 | boolean(value(VERBOSE)) = 1; |
22629db9 | 138 | if (cgetflag("nv")) |
05862919 | 139 | boolean(value(VERBOSE)) = 0; |
22629db9 | 140 | if (cgetflag("ta")) |
05862919 | 141 | boolean(value(TAND)) = 1; |
22629db9 | 142 | if (cgetflag("nt")) |
05862919 | 143 | boolean(value(TAND)) = 0; |
22629db9 | 144 | if (cgetflag("rw")) |
05862919 | 145 | boolean(value(RAWFTP)) = 1; |
22629db9 | 146 | if (cgetflag("hd")) |
05862919 | 147 | boolean(value(HALFDUPLEX)) = 1; |
9479d9a4 | 148 | if (RE == NOSTR) |
05862919 | 149 | RE = (char *)"tip.record"; |
9479d9a4 | 150 | if (EX == NOSTR) |
05862919 SL |
151 | EX = (char *)"\t\n\b\f"; |
152 | if (ES != NOSTR) | |
153 | vstring("es", ES); | |
154 | if (FO != NOSTR) | |
155 | vstring("fo", FO); | |
156 | if (PR != NOSTR) | |
157 | vstring("pr", PR); | |
158 | if (RC != NOSTR) | |
159 | vstring("rc", RC); | |
22629db9 | 160 | if (cgetnum(bp, "dl", &DL) == -1) |
05862919 | 161 | DL = 0; |
22629db9 | 162 | if (cgetnum(bp, "cl", &CL) == -1) |
05862919 | 163 | CL = 0; |
22629db9 | 164 | if (cgetnum(bp, "et", &ET) == -1) |
05862919 | 165 | ET = 10; |
8274ea85 BJ |
166 | } |
167 | ||
168 | char * | |
169 | getremote(host) | |
170 | char *host; | |
171 | { | |
172 | register char *cp; | |
173 | static char *next; | |
174 | static int lookedup = 0; | |
175 | ||
176 | if (!lookedup) { | |
177 | if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { | |
178 | fprintf(stderr, "tip: no host specified\n"); | |
179 | exit(3); | |
180 | } | |
181 | getremcap(host); | |
182 | next = DV; | |
183 | lookedup++; | |
184 | } | |
185 | /* | |
186 | * We return a new device each time we're called (to allow | |
187 | * a rotary action to be simulated) | |
188 | */ | |
189 | if (next == NOSTR) | |
3f48242d | 190 | return (NOSTR); |
8274ea85 BJ |
191 | if ((cp = index(next, ',')) == NULL) { |
192 | DV = next; | |
193 | next = NOSTR; | |
194 | } else { | |
195 | *cp++ = '\0'; | |
196 | DV = next; | |
197 | next = cp; | |
198 | } | |
3f48242d | 199 | return (DV); |
8274ea85 | 200 | } |