1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * 6 * %sccs.include.redist.c% 7 */ 8 9 #ifndef lint 10 static char copyright[] = 11 "@(#) Copyright (c) 1992 The Regents of the University of California.\n\ 12 All rights reserved.\n"; 13 #endif /* not lint */ 14 15 #ifndef lint 16 static char sccsid[] = "@(#)remote.c 5.9 (Berkeley) 09/16/92"; 17 #endif /* not lint */ 18 19 /* 20 * Attributes to be gleened from remote host description 21 * data base. 22 */ 23 static char **caps[] = { 24 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI, 25 &ES, &EX, &FO, &RC, &RE, &PA 26 }; 27 28 static char *capstrings[] = { 29 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr", 30 "di", "es", "ex", "fo", "rc", "re", "pa", 0 31 }; 32 33 static char *db_array[3] = { _PATH_REMOTE, 0, 0 }; 34 35 #define cgetflag(f) (cgetcap(bp, f, ':') != NULL) 36 37 static 38 getremcap(host) 39 register char *host; 40 { 41 register char **p, ***q; 42 char *bp; 43 char *rempath; 44 int stat; 45 46 rempath = getenv("REMOTE"); 47 if (rempath != NULL) 48 if (*rempath != '/') 49 /* we have an entry */ 50 cgetset(rempath); 51 else { /* we have a path */ 52 db_array[1] = rempath; 53 db_array[2] = _PATH_REMOTE; 54 } 55 56 if ((stat = cgetent(&bp, db_array, host)) < 0) { 57 if (DV || 58 host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) { 59 CU = DV; 60 HO = host; 61 HW = 1; 62 DU = 0; 63 if (!BR) 64 BR = DEFBR; 65 FS = DEFFS; 66 return; 67 } 68 switch(stat) { 69 case -1: 70 fprintf(stderr, "tip: unknown host %s\n", host); 71 break; 72 case -2: 73 fprintf(stderr, 74 "tip: can't open host description file\n"); 75 break; 76 case -3: 77 fprintf(stderr, 78 "tip: possible reference loop in host description file\n"); 79 break; 80 } 81 exit(3); 82 } 83 84 for (p = capstrings, q = caps; *p != NULL; p++, q++) 85 if (**q == NULL) 86 cgetstr(bp, *p, *q); 87 if (!BR && (cgetnum(bp, "br", &BR) == -1)) 88 BR = DEFBR; 89 if (cgetnum(bp, "fs", &FS) == -1) 90 FS = DEFFS; 91 if (DU < 0) 92 DU = 0; 93 else 94 DU = cgetflag("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 = cgetflag("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 (cgetflag("ra")) 119 boolean(value(RAISE)) = 1; 120 if (cgetflag("ec")) 121 boolean(value(ECHOCHECK)) = 1; 122 if (cgetflag("be")) 123 boolean(value(BEAUTIFY)) = 1; 124 if (cgetflag("nb")) 125 boolean(value(BEAUTIFY)) = 0; 126 if (cgetflag("sc")) 127 boolean(value(SCRIPT)) = 1; 128 if (cgetflag("tb")) 129 boolean(value(TABEXPAND)) = 1; 130 if (cgetflag("vb")) 131 boolean(value(VERBOSE)) = 1; 132 if (cgetflag("nv")) 133 boolean(value(VERBOSE)) = 0; 134 if (cgetflag("ta")) 135 boolean(value(TAND)) = 1; 136 if (cgetflag("nt")) 137 boolean(value(TAND)) = 0; 138 if (cgetflag("rw")) 139 boolean(value(RAWFTP)) = 1; 140 if (cgetflag("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 (cgetnum(bp, "dl", &DL) == -1) 155 DL = 0; 156 if (cgetnum(bp, "cl", &CL) == -1) 157 CL = 0; 158 if (cgetnum(bp, "et", &ET) == -1) 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