10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
5*549Smuffin
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate */
110Sstevel@tonic-gate
12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
130Sstevel@tonic-gate
140Sstevel@tonic-gate #include "tip.h"
150Sstevel@tonic-gate
160Sstevel@tonic-gate /*
170Sstevel@tonic-gate * Attributes to be gleened from remote host description
180Sstevel@tonic-gate * data base.
190Sstevel@tonic-gate */
200Sstevel@tonic-gate static char **caps[] = {
210Sstevel@tonic-gate &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
220Sstevel@tonic-gate &ES, &EX, &FO, &RC, &RE, &PA
230Sstevel@tonic-gate };
240Sstevel@tonic-gate
250Sstevel@tonic-gate static char *capstrings[] = {
260Sstevel@tonic-gate "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
270Sstevel@tonic-gate "di", "es", "ex", "fo", "rc", "re", "pa", 0
280Sstevel@tonic-gate };
290Sstevel@tonic-gate
30*549Smuffin extern char *rgetstr(char *, char **);
310Sstevel@tonic-gate
32*549Smuffin static void
getremcap(char * host)33*549Smuffin getremcap(char *host)
340Sstevel@tonic-gate {
350Sstevel@tonic-gate int stat;
360Sstevel@tonic-gate char tbuf[BUFSIZ];
370Sstevel@tonic-gate static char buf[BUFSIZ/2];
380Sstevel@tonic-gate char *bp = buf;
39*549Smuffin char **p, ***q;
400Sstevel@tonic-gate
410Sstevel@tonic-gate if ((stat = rgetent(tbuf, host, sizeof (tbuf))) <= 0) {
420Sstevel@tonic-gate if (DV ||
430Sstevel@tonic-gate host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) {
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate * If the user specifies a device on the commandline,
460Sstevel@tonic-gate * don't trust it.
470Sstevel@tonic-gate */
480Sstevel@tonic-gate if (host[0] == '/')
490Sstevel@tonic-gate trusted_device = 0;
500Sstevel@tonic-gate CU = DV;
510Sstevel@tonic-gate HO = host;
520Sstevel@tonic-gate HW = 1;
530Sstevel@tonic-gate DU = 0;
540Sstevel@tonic-gate if (!BR)
550Sstevel@tonic-gate BR = DEFBR;
560Sstevel@tonic-gate FS = DEFFS;
570Sstevel@tonic-gate RE = (char *)"tip.record";
580Sstevel@tonic-gate EX = (char *)"\t\n\b\f";
590Sstevel@tonic-gate DL = 0;
600Sstevel@tonic-gate CL = 0;
610Sstevel@tonic-gate ET = 10;
620Sstevel@tonic-gate return;
630Sstevel@tonic-gate }
64*549Smuffin (void) fprintf(stderr, stat == 0 ?
65*549Smuffin "tip: unknown host %s\n" :
66*549Smuffin "tip: can't open host description file\n", host);
670Sstevel@tonic-gate exit(3);
680Sstevel@tonic-gate }
690Sstevel@tonic-gate
700Sstevel@tonic-gate for (p = capstrings, q = caps; *p != NULL; p++, q++)
710Sstevel@tonic-gate if (**q == NULL)
720Sstevel@tonic-gate **q = rgetstr(*p, &bp);
730Sstevel@tonic-gate if (!BR && (BR = rgetnum("br")) < 0)
740Sstevel@tonic-gate BR = DEFBR;
750Sstevel@tonic-gate if ((FS = rgetnum("fs")) < 0)
760Sstevel@tonic-gate FS = DEFFS;
770Sstevel@tonic-gate if (DU < 0)
780Sstevel@tonic-gate DU = 0;
790Sstevel@tonic-gate else
800Sstevel@tonic-gate DU = rgetflag("du");
810Sstevel@tonic-gate if (DV == NOSTR) {
82*549Smuffin (void) fprintf(stderr, "%s: missing device spec\n", host);
830Sstevel@tonic-gate exit(3);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate if (DU && CU == NOSTR)
860Sstevel@tonic-gate CU = DV;
870Sstevel@tonic-gate if (DU && PN == NOSTR) {
88*549Smuffin (void) fprintf(stderr, "%s: missing phone number\n", host);
890Sstevel@tonic-gate exit(3);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate DB = rgetflag("db");
920Sstevel@tonic-gate
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate * This effectively eliminates the "hw" attribute
950Sstevel@tonic-gate * from the description file
960Sstevel@tonic-gate */
970Sstevel@tonic-gate if (!HW)
980Sstevel@tonic-gate HW = (CU == NOSTR) || (DU && equal(DV, CU));
990Sstevel@tonic-gate HO = host;
1000Sstevel@tonic-gate /*
1010Sstevel@tonic-gate * see if uppercase mode should be turned on initially
1020Sstevel@tonic-gate */
1030Sstevel@tonic-gate if (rgetflag("ra"))
1040Sstevel@tonic-gate boolean(value(RAISE)) = 1;
1050Sstevel@tonic-gate if (rgetflag("ec"))
1060Sstevel@tonic-gate boolean(value(ECHOCHECK)) = 1;
1070Sstevel@tonic-gate if (rgetflag("be"))
1080Sstevel@tonic-gate boolean(value(BEAUTIFY)) = 1;
1090Sstevel@tonic-gate if (rgetflag("nb"))
1100Sstevel@tonic-gate boolean(value(BEAUTIFY)) = 0;
1110Sstevel@tonic-gate if (rgetflag("sc"))
1120Sstevel@tonic-gate boolean(value(SCRIPT)) = 1;
1130Sstevel@tonic-gate if (rgetflag("tb"))
1140Sstevel@tonic-gate boolean(value(TABEXPAND)) = 1;
1150Sstevel@tonic-gate if (rgetflag("vb"))
1160Sstevel@tonic-gate boolean(value(VERBOSE)) = 1;
1170Sstevel@tonic-gate if (rgetflag("nv"))
1180Sstevel@tonic-gate boolean(value(VERBOSE)) = 0;
1190Sstevel@tonic-gate if (rgetflag("ta"))
1200Sstevel@tonic-gate boolean(value(TAND)) = 1;
1210Sstevel@tonic-gate if (rgetflag("nt"))
1220Sstevel@tonic-gate boolean(value(TAND)) = 0;
1230Sstevel@tonic-gate if (rgetflag("rw"))
1240Sstevel@tonic-gate boolean(value(RAWFTP)) = 1;
1250Sstevel@tonic-gate if (rgetflag("hd"))
1260Sstevel@tonic-gate boolean(value(HALFDUPLEX)) = 1;
1270Sstevel@tonic-gate if (rgetflag("hf"))
1280Sstevel@tonic-gate boolean(value(HARDWAREFLOW)) = 1;
1290Sstevel@tonic-gate if (RE == NULL)
1300Sstevel@tonic-gate RE = (char *)"tip.record";
1310Sstevel@tonic-gate if (EX == NULL)
1320Sstevel@tonic-gate EX = (char *)"\t\n\b\f";
1330Sstevel@tonic-gate if (ES != NOSTR)
134*549Smuffin (void) vstring("es", ES);
1350Sstevel@tonic-gate if (FO != NOSTR)
136*549Smuffin (void) vstring("fo", FO);
1370Sstevel@tonic-gate if (PR != NOSTR)
138*549Smuffin (void) vstring("pr", PR);
1390Sstevel@tonic-gate if (RC != NOSTR)
140*549Smuffin (void) vstring("rc", RC);
1410Sstevel@tonic-gate if ((DL = rgetnum("dl")) < 0)
1420Sstevel@tonic-gate DL = 0;
1430Sstevel@tonic-gate if ((CL = rgetnum("cl")) < 0)
1440Sstevel@tonic-gate CL = 0;
1450Sstevel@tonic-gate if ((ET = rgetnum("et")) < 0)
1460Sstevel@tonic-gate ET = 10;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate char *
getremote(char * host)150*549Smuffin getremote(char *host)
1510Sstevel@tonic-gate {
152*549Smuffin char *cp;
1530Sstevel@tonic-gate static char *next;
1540Sstevel@tonic-gate static int lookedup = 0;
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate if (!lookedup) {
1570Sstevel@tonic-gate if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
158*549Smuffin (void) fprintf(stderr, "tip: no host specified\n");
1590Sstevel@tonic-gate exit(3);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate getremcap(host);
1620Sstevel@tonic-gate next = DV;
1630Sstevel@tonic-gate lookedup++;
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate * We return a new device each time we're called (to allow
1670Sstevel@tonic-gate * a rotary action to be simulated)
1680Sstevel@tonic-gate */
1690Sstevel@tonic-gate if (next == NOSTR)
1700Sstevel@tonic-gate return (NOSTR);
1710Sstevel@tonic-gate if ((cp = strchr(next, ',')) == NULL) {
1720Sstevel@tonic-gate DV = next;
1730Sstevel@tonic-gate next = NOSTR;
1740Sstevel@tonic-gate } else {
1750Sstevel@tonic-gate *cp++ = '\0';
1760Sstevel@tonic-gate DV = next;
1770Sstevel@tonic-gate next = cp;
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate return (DV);
1800Sstevel@tonic-gate }
181