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