1 /* remote.c 4.3 81/07/13 */ 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 **q = rgetstr(*p, &bp); 37 if ((BR = rgetnum("br")) < 0) 38 BR = DEFBR; 39 if ((FS = rgetnum("fs")) < 0) 40 FS = DEFFS; 41 DU = rgetflag("du"); 42 HW = rgetflag("hw"); 43 if (DV == NOSTR) { 44 fprintf(stderr, "%s: missing device spec\n", host); 45 exit(3); 46 } 47 if (DU && CU == NOSTR) 48 CU = DV; 49 if (DU && PN == NOSTR) { 50 fprintf(stderr, "%s: missing phone number\n", host); 51 exit(3); 52 } 53 /* 54 * This effectively eliminates the "hw" attribute 55 * from the description file 56 */ 57 if (!HW) 58 HW = (CU == NOSTR) || (DU && equal(DV, CU)); 59 HO = host; 60 } 61 62 char * 63 getremote(host) 64 char *host; 65 { 66 register char *cp; 67 static char *next; 68 static int lookedup = 0; 69 70 if (!lookedup) { 71 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { 72 fprintf(stderr, "tip: no host specified\n"); 73 exit(3); 74 } 75 getremcap(host); 76 next = DV; 77 lookedup++; 78 } 79 /* 80 * We return a new device each time we're called (to allow 81 * a rotary action to be simulated) 82 */ 83 if (next == NOSTR) 84 return(NOSTR); 85 if ((cp = index(next, ',')) == NULL) { 86 DV = next; 87 next = NOSTR; 88 } else { 89 *cp++ = '\0'; 90 DV = next; 91 next = cp; 92 } 93 return(DV); 94 } 95