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