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