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