remote.c revision 1.8 1 1.8 ross /* $NetBSD: remote.c,v 1.8 1998/08/25 20:59:41 ross Exp $ */
2 1.3 jtc
3 1.1 cgd /*
4 1.3 jtc * Copyright (c) 1992, 1993
5 1.3 jtc * The Regents of the University of California. All rights reserved.
6 1.3 jtc *
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer.
13 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer in the
15 1.1 cgd * documentation and/or other materials provided with the distribution.
16 1.1 cgd * 3. All advertising materials mentioning features or use of this software
17 1.1 cgd * must display the following acknowledgement:
18 1.1 cgd * This product includes software developed by the University of
19 1.1 cgd * California, Berkeley and its contributors.
20 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
21 1.1 cgd * may be used to endorse or promote products derived from this software
22 1.1 cgd * without specific prior written permission.
23 1.1 cgd *
24 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 cgd * SUCH DAMAGE.
35 1.1 cgd */
36 1.1 cgd
37 1.7 lukem #include <sys/cdefs.h>
38 1.1 cgd #ifndef lint
39 1.7 lukem __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
40 1.7 lukem The Regents of the University of California. All rights reserved.\n");
41 1.3 jtc #endif /* not lint */
42 1.3 jtc
43 1.3 jtc #ifndef lint
44 1.3 jtc #if 0
45 1.3 jtc static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93";
46 1.3 jtc #endif
47 1.8 ross __RCSID("$NetBSD: remote.c,v 1.8 1998/08/25 20:59:41 ross Exp $");
48 1.1 cgd #endif /* not lint */
49 1.1 cgd
50 1.3 jtc #include "pathnames.h"
51 1.3 jtc #include "tip.h"
52 1.1 cgd
53 1.1 cgd /*
54 1.1 cgd * Attributes to be gleened from remote host description
55 1.1 cgd * data base.
56 1.1 cgd */
57 1.1 cgd static char **caps[] = {
58 1.1 cgd &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
59 1.1 cgd &ES, &EX, &FO, &RC, &RE, &PA
60 1.1 cgd };
61 1.1 cgd
62 1.1 cgd static char *capstrings[] = {
63 1.1 cgd "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
64 1.1 cgd "di", "es", "ex", "fo", "rc", "re", "pa", 0
65 1.1 cgd };
66 1.1 cgd
67 1.3 jtc static char *db_array[3] = { _PATH_REMOTE, 0, 0 };
68 1.3 jtc
69 1.3 jtc #define cgetflag(f) (cgetcap(bp, f, ':') != NULL)
70 1.1 cgd
71 1.7 lukem static void getremcap __P((char *));
72 1.7 lukem
73 1.7 lukem static void
74 1.1 cgd getremcap(host)
75 1.7 lukem char *host;
76 1.1 cgd {
77 1.7 lukem char **p, ***q;
78 1.3 jtc char *bp;
79 1.3 jtc char *rempath;
80 1.3 jtc int stat;
81 1.3 jtc
82 1.3 jtc rempath = getenv("REMOTE");
83 1.8 ross if (rempath != NULL) {
84 1.3 jtc if (*rempath != '/')
85 1.3 jtc /* we have an entry */
86 1.3 jtc cgetset(rempath);
87 1.3 jtc else { /* we have a path */
88 1.3 jtc db_array[1] = rempath;
89 1.3 jtc db_array[2] = _PATH_REMOTE;
90 1.3 jtc }
91 1.8 ross }
92 1.3 jtc if ((stat = cgetent(&bp, db_array, host)) < 0) {
93 1.1 cgd if (DV ||
94 1.7 lukem (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) {
95 1.1 cgd CU = DV;
96 1.1 cgd HO = host;
97 1.1 cgd HW = 1;
98 1.1 cgd DU = 0;
99 1.1 cgd if (!BR)
100 1.1 cgd BR = DEFBR;
101 1.1 cgd FS = DEFFS;
102 1.1 cgd return;
103 1.1 cgd }
104 1.3 jtc switch(stat) {
105 1.3 jtc case -1:
106 1.3 jtc fprintf(stderr, "tip: unknown host %s\n", host);
107 1.3 jtc break;
108 1.3 jtc case -2:
109 1.3 jtc fprintf(stderr,
110 1.3 jtc "tip: can't open host description file\n");
111 1.3 jtc break;
112 1.3 jtc case -3:
113 1.3 jtc fprintf(stderr,
114 1.3 jtc "tip: possible reference loop in host description file\n");
115 1.3 jtc break;
116 1.3 jtc }
117 1.1 cgd exit(3);
118 1.1 cgd }
119 1.1 cgd
120 1.1 cgd for (p = capstrings, q = caps; *p != NULL; p++, q++)
121 1.1 cgd if (**q == NULL)
122 1.3 jtc cgetstr(bp, *p, *q);
123 1.3 jtc if (!BR && (cgetnum(bp, "br", &BR) == -1))
124 1.1 cgd BR = DEFBR;
125 1.3 jtc if (cgetnum(bp, "fs", &FS) == -1)
126 1.1 cgd FS = DEFFS;
127 1.1 cgd if (DU < 0)
128 1.1 cgd DU = 0;
129 1.1 cgd else
130 1.3 jtc DU = cgetflag("du");
131 1.7 lukem if (DV == NULL) {
132 1.1 cgd fprintf(stderr, "%s: missing device spec\n", host);
133 1.1 cgd exit(3);
134 1.1 cgd }
135 1.7 lukem if (DU && CU == NULL)
136 1.1 cgd CU = DV;
137 1.7 lukem if (DU && PN == NULL) {
138 1.1 cgd fprintf(stderr, "%s: missing phone number\n", host);
139 1.1 cgd exit(3);
140 1.1 cgd }
141 1.1 cgd
142 1.3 jtc HD = cgetflag("hd");
143 1.1 cgd
144 1.1 cgd /*
145 1.1 cgd * This effectively eliminates the "hw" attribute
146 1.1 cgd * from the description file
147 1.1 cgd */
148 1.1 cgd if (!HW)
149 1.7 lukem HW = (CU == NULL) || (DU && equal(DV, CU));
150 1.1 cgd HO = host;
151 1.1 cgd /*
152 1.1 cgd * see if uppercase mode should be turned on initially
153 1.1 cgd */
154 1.3 jtc if (cgetflag("ra"))
155 1.4 cgd setboolean(value(RAISE), 1);
156 1.3 jtc if (cgetflag("ec"))
157 1.4 cgd setboolean(value(ECHOCHECK), 1);
158 1.3 jtc if (cgetflag("be"))
159 1.4 cgd setboolean(value(BEAUTIFY), 1);
160 1.3 jtc if (cgetflag("nb"))
161 1.4 cgd setboolean(value(BEAUTIFY), 0);
162 1.3 jtc if (cgetflag("sc"))
163 1.4 cgd setboolean(value(SCRIPT), 1);
164 1.3 jtc if (cgetflag("tb"))
165 1.4 cgd setboolean(value(TABEXPAND), 1);
166 1.3 jtc if (cgetflag("vb"))
167 1.4 cgd setboolean(value(VERBOSE), 1);
168 1.3 jtc if (cgetflag("nv"))
169 1.4 cgd setboolean(value(VERBOSE), 0);
170 1.3 jtc if (cgetflag("ta"))
171 1.4 cgd setboolean(value(TAND), 1);
172 1.3 jtc if (cgetflag("nt"))
173 1.4 cgd setboolean(value(TAND), 0);
174 1.3 jtc if (cgetflag("rw"))
175 1.4 cgd setboolean(value(RAWFTP), 1);
176 1.3 jtc if (cgetflag("hd"))
177 1.4 cgd setboolean(value(HALFDUPLEX), 1);
178 1.5 mellon if (cgetflag("dc"))
179 1.6 mellon DC = 1;
180 1.7 lukem if (RE == NULL)
181 1.1 cgd RE = (char *)"tip.record";
182 1.7 lukem if (EX == NULL)
183 1.1 cgd EX = (char *)"\t\n\b\f";
184 1.7 lukem if (ES != NULL)
185 1.1 cgd vstring("es", ES);
186 1.7 lukem if (FO != NULL)
187 1.1 cgd vstring("fo", FO);
188 1.7 lukem if (PR != NULL)
189 1.1 cgd vstring("pr", PR);
190 1.7 lukem if (RC != NULL)
191 1.1 cgd vstring("rc", RC);
192 1.3 jtc if (cgetnum(bp, "dl", &DL) == -1)
193 1.1 cgd DL = 0;
194 1.3 jtc if (cgetnum(bp, "cl", &CL) == -1)
195 1.1 cgd CL = 0;
196 1.3 jtc if (cgetnum(bp, "et", &ET) == -1)
197 1.1 cgd ET = 10;
198 1.1 cgd }
199 1.1 cgd
200 1.1 cgd char *
201 1.1 cgd getremote(host)
202 1.1 cgd char *host;
203 1.1 cgd {
204 1.7 lukem char *cp;
205 1.1 cgd static char *next;
206 1.1 cgd static int lookedup = 0;
207 1.1 cgd
208 1.1 cgd if (!lookedup) {
209 1.7 lukem if (host == NULL && (host = getenv("HOST")) == NULL) {
210 1.1 cgd fprintf(stderr, "tip: no host specified\n");
211 1.1 cgd exit(3);
212 1.1 cgd }
213 1.1 cgd getremcap(host);
214 1.1 cgd next = DV;
215 1.1 cgd lookedup++;
216 1.1 cgd }
217 1.1 cgd /*
218 1.1 cgd * We return a new device each time we're called (to allow
219 1.1 cgd * a rotary action to be simulated)
220 1.1 cgd */
221 1.7 lukem if (next == NULL)
222 1.7 lukem return (NULL);
223 1.7 lukem if ((cp = strchr(next, ',')) == NULL) {
224 1.1 cgd DV = next;
225 1.7 lukem next = NULL;
226 1.1 cgd } else {
227 1.1 cgd *cp++ = '\0';
228 1.1 cgd DV = next;
229 1.1 cgd next = cp;
230 1.1 cgd }
231 1.1 cgd return (DV);
232 1.1 cgd }
233