1 /* remote.c 4.5 81/11/29 */ 2 # include "tip.h" 3 4 /* 5 * Attributes to be gleened from remote host description 6 * data base. 7 */ 8 static char **caps[] = { 9 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN 10 }; 11 12 static char *capstrings[] = { 13 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", 0 14 }; 15 16 char *rgetstr(); 17 18 static 19 getremcap(host) 20 register char *host; 21 { 22 int stat; 23 char tbuf[BUFSIZ]; 24 static char buf[BUFSIZ/2]; 25 char *bp = buf; 26 register char **p, ***q; 27 28 if ((stat = rgetent(tbuf, host)) <= 0) { 29 fprintf(stderr, stat == 0 ? 30 "tip: unknown host %s\n" : 31 "tip: can't open host description file\n", host); 32 exit(3); 33 } 34 35 for (p = capstrings, q = caps; *p != NULL; p++, q++) 36 if (**q == NULL) 37 **q = rgetstr(*p, &bp); 38 if (!BR && (BR = rgetnum("br")) < 0) 39 BR = DEFBR; 40 if ((FS = rgetnum("fs")) < 0) 41 FS = DEFFS; 42 if (DU < 0) 43 DU = 0; 44 else 45 DU = rgetflag("du"); 46 if (DV == NOSTR) { 47 fprintf(stderr, "%s: missing device spec\n", host); 48 exit(3); 49 } 50 if (DU && CU == NOSTR) 51 CU = DV; 52 if (DU && PN == NOSTR) { 53 fprintf(stderr, "%s: missing phone number\n", host); 54 exit(3); 55 } 56 /* 57 * This effectively eliminates the "hw" attribute 58 * from the description file 59 */ 60 if (!HW) 61 HW = (CU == NOSTR) || (DU && equal(DV, CU)); 62 HO = host; 63 } 64 65 char * 66 getremote(host) 67 char *host; 68 { 69 register char *cp; 70 static char *next; 71 static int lookedup = 0; 72 73 if (!lookedup) { 74 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { 75 fprintf(stderr, "tip: no host specified\n"); 76 exit(3); 77 } 78 getremcap(host); 79 next = DV; 80 lookedup++; 81 } 82 /* 83 * We return a new device each time we're called (to allow 84 * a rotary action to be simulated) 85 */ 86 if (next == NOSTR) 87 return (NOSTR); 88 if ((cp = index(next, ',')) == NULL) { 89 DV = next; 90 next = NOSTR; 91 } else { 92 *cp++ = '\0'; 93 DV = next; 94 next = cp; 95 } 96 return (DV); 97 } 98