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