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