1*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 3*7c478bd9Sstevel@tonic-gate 4*7c478bd9Sstevel@tonic-gate 5*7c478bd9Sstevel@tonic-gate /* 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 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 /* 12*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983 - 1999 by Sun Microsystems, Inc. 13*7c478bd9Sstevel@tonic-gate * All rights reserved. 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */ 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate /* 19*7c478bd9Sstevel@tonic-gate ** TSET -- set terminal modes 20*7c478bd9Sstevel@tonic-gate ** 21*7c478bd9Sstevel@tonic-gate ** This program does sophisticated terminal initialization. 22*7c478bd9Sstevel@tonic-gate ** I recommend that you include it in your .profile or .login 23*7c478bd9Sstevel@tonic-gate ** file to initialize whatever terminal you are on. 24*7c478bd9Sstevel@tonic-gate ** 25*7c478bd9Sstevel@tonic-gate ** There are several features: 26*7c478bd9Sstevel@tonic-gate ** 27*7c478bd9Sstevel@tonic-gate ** A special file or sequence (as controlled by the termcap file) 28*7c478bd9Sstevel@tonic-gate ** is sent to the terminal. 29*7c478bd9Sstevel@tonic-gate ** 30*7c478bd9Sstevel@tonic-gate ** Mode bits are set on a per-terminal_type basis (much better 31*7c478bd9Sstevel@tonic-gate ** than UNIX itself). This allows special delays, automatic 32*7c478bd9Sstevel@tonic-gate ** tabs, etc. 33*7c478bd9Sstevel@tonic-gate ** 34*7c478bd9Sstevel@tonic-gate ** Erase and Kill characters can be set to whatever you want. 35*7c478bd9Sstevel@tonic-gate ** Default is to change erase to control-H on a terminal which 36*7c478bd9Sstevel@tonic-gate ** can overstrike, and leave it alone on anything else. Kill 37*7c478bd9Sstevel@tonic-gate ** is always left alone unless specifically requested. These 38*7c478bd9Sstevel@tonic-gate ** characters can be represented as "^X" meaning control-X; 39*7c478bd9Sstevel@tonic-gate ** X is any character. 40*7c478bd9Sstevel@tonic-gate ** 41*7c478bd9Sstevel@tonic-gate ** Terminals which are dialups or plugboard types can be aliased 42*7c478bd9Sstevel@tonic-gate ** to whatever type you may have in your home or office. Thus, 43*7c478bd9Sstevel@tonic-gate ** if you know that when you dial up you will always be on a 44*7c478bd9Sstevel@tonic-gate ** TI 733, you can specify that fact to tset. You can represent 45*7c478bd9Sstevel@tonic-gate ** a type as "?type". This will ask you what type you want it 46*7c478bd9Sstevel@tonic-gate ** to be -- if you reply with just a newline, it will default 47*7c478bd9Sstevel@tonic-gate ** to the type given. 48*7c478bd9Sstevel@tonic-gate ** 49*7c478bd9Sstevel@tonic-gate ** The current terminal type can be queried. 50*7c478bd9Sstevel@tonic-gate ** 51*7c478bd9Sstevel@tonic-gate ** Usage: 52*7c478bd9Sstevel@tonic-gate ** tset [-] [-EC] [-eC] [-kC] [-iC] [-s] [-h] [-u] [-r] 53*7c478bd9Sstevel@tonic-gate ** [-m [ident] [test baudrate] :type] 54*7c478bd9Sstevel@tonic-gate ** [-Q] [-I] [-S] [type] 55*7c478bd9Sstevel@tonic-gate ** 56*7c478bd9Sstevel@tonic-gate ** In systems with environments, use: 57*7c478bd9Sstevel@tonic-gate ** eval `tset -s ...` 58*7c478bd9Sstevel@tonic-gate ** Actually, this doesn't work in old csh's. 59*7c478bd9Sstevel@tonic-gate ** Instead, use: 60*7c478bd9Sstevel@tonic-gate ** tset -s ... > tset.tmp 61*7c478bd9Sstevel@tonic-gate ** source tset.tmp 62*7c478bd9Sstevel@tonic-gate ** rm tset.tmp 63*7c478bd9Sstevel@tonic-gate ** or: 64*7c478bd9Sstevel@tonic-gate ** set noglob 65*7c478bd9Sstevel@tonic-gate ** set term=(`tset -S ....`) 66*7c478bd9Sstevel@tonic-gate ** setenv TERM $term[1] 67*7c478bd9Sstevel@tonic-gate ** setenv TERMCAP "$term[2]" 68*7c478bd9Sstevel@tonic-gate ** unset term 69*7c478bd9Sstevel@tonic-gate ** unset noglob 70*7c478bd9Sstevel@tonic-gate ** 71*7c478bd9Sstevel@tonic-gate ** Positional Parameters: 72*7c478bd9Sstevel@tonic-gate ** type -- the terminal type to force. If this is 73*7c478bd9Sstevel@tonic-gate ** specified, initialization is for this 74*7c478bd9Sstevel@tonic-gate ** terminal type. 75*7c478bd9Sstevel@tonic-gate ** 76*7c478bd9Sstevel@tonic-gate ** Flags: 77*7c478bd9Sstevel@tonic-gate ** - -- report terminal type. Whatever type is 78*7c478bd9Sstevel@tonic-gate ** decided on is reported. If no other flags 79*7c478bd9Sstevel@tonic-gate ** are stated, the only affect is to write 80*7c478bd9Sstevel@tonic-gate ** the terminal type on the standard output. 81*7c478bd9Sstevel@tonic-gate ** -r -- report to user in addition to other flags. 82*7c478bd9Sstevel@tonic-gate ** -EC -- set the erase character to C on all terminals 83*7c478bd9Sstevel@tonic-gate ** except those which cannot backspace (e.g., 84*7c478bd9Sstevel@tonic-gate ** a TTY 33). C defaults to control-H. 85*7c478bd9Sstevel@tonic-gate ** -eC -- set the erase character to C on all terminals. 86*7c478bd9Sstevel@tonic-gate ** C defaults to control-H. If not specified, 87*7c478bd9Sstevel@tonic-gate ** the erase character is untouched; however, if 88*7c478bd9Sstevel@tonic-gate ** not specified and the erase character is NULL 89*7c478bd9Sstevel@tonic-gate ** (zero byte), the erase character is set to CERASE. 90*7c478bd9Sstevel@tonic-gate ** -kC -- set the kill character to C on all terminals. 91*7c478bd9Sstevel@tonic-gate ** Default for C is control-U. If not specified, 92*7c478bd9Sstevel@tonic-gate ** the kill character is untouched; however, if 93*7c478bd9Sstevel@tonic-gate ** not specified and the kill character is NULL 94*7c478bd9Sstevel@tonic-gate ** (zero byte), the kill character is set to CKILL. 95*7c478bd9Sstevel@tonic-gate ** -iC -- set the interrupt character to C on all terminals. 96*7c478bd9Sstevel@tonic-gate ** Default for C is control-C. If not specified, the 97*7c478bd9Sstevel@tonic-gate ** interrupt character is untouched; however, if 98*7c478bd9Sstevel@tonic-gate ** not specified and the interrupt character is NULL 99*7c478bd9Sstevel@tonic-gate ** (zero byte), the interrupt character is set to 100*7c478bd9Sstevel@tonic-gate ** control-C. 101*7c478bd9Sstevel@tonic-gate ** -qC -- reserved for setable quit character. 102*7c478bd9Sstevel@tonic-gate ** -m -- map the system identified type to some user 103*7c478bd9Sstevel@tonic-gate ** specified type. The mapping can be baud rate 104*7c478bd9Sstevel@tonic-gate ** dependent. This replaces the old -d, -p flags. 105*7c478bd9Sstevel@tonic-gate ** (-d type -> -m dialup:type) 106*7c478bd9Sstevel@tonic-gate ** (-p type -> -m plug:type) 107*7c478bd9Sstevel@tonic-gate ** Syntax: -m identifier [test baudrate] :type 108*7c478bd9Sstevel@tonic-gate ** where: ``identifier'' is terminal type found in 109*7c478bd9Sstevel@tonic-gate ** /etc/ttys for this port, (abscence of an identifier 110*7c478bd9Sstevel@tonic-gate ** matches any identifier); ``test'' may be any combination 111*7c478bd9Sstevel@tonic-gate ** of > = < ! @; ``baudrate'' is as with stty(1); 112*7c478bd9Sstevel@tonic-gate ** ``type'' is the actual terminal type to use if the 113*7c478bd9Sstevel@tonic-gate ** mapping condition is met. Multiple maps are scanned 114*7c478bd9Sstevel@tonic-gate ** in order and the first match prevails. 115*7c478bd9Sstevel@tonic-gate ** -n -- If the new tty driver from UCB is available, this flag 116*7c478bd9Sstevel@tonic-gate ** will activate the new options for erase and kill 117*7c478bd9Sstevel@tonic-gate ** processing. This will be different for printers 118*7c478bd9Sstevel@tonic-gate ** and crt's. For crts, if the baud rate is < 1200 then 119*7c478bd9Sstevel@tonic-gate ** erase and kill don't remove characters from the screen. 120*7c478bd9Sstevel@tonic-gate ** -h -- don't read htmp file. Normally the terminal type 121*7c478bd9Sstevel@tonic-gate ** is determined by reading the htmp file or the 122*7c478bd9Sstevel@tonic-gate ** environment (unless some mapping is specified). 123*7c478bd9Sstevel@tonic-gate ** This forces a read of the ttytype file -- useful 124*7c478bd9Sstevel@tonic-gate ** when htmp is somehow wrong. (V6 only) 125*7c478bd9Sstevel@tonic-gate ** -u -- don't update htmp. It seemed like this should 126*7c478bd9Sstevel@tonic-gate ** be put in. Note that htmp is never actually 127*7c478bd9Sstevel@tonic-gate ** written if there are no changes, so don't bother 128*7c478bd9Sstevel@tonic-gate ** bother using this for efficiency reasons alone. 129*7c478bd9Sstevel@tonic-gate ** -s -- output setenv commands for TERM. This can be 130*7c478bd9Sstevel@tonic-gate ** used with 131*7c478bd9Sstevel@tonic-gate ** `tset -s ...` 132*7c478bd9Sstevel@tonic-gate ** and is to be prefered to: 133*7c478bd9Sstevel@tonic-gate ** setenv TERM `tset - ...` 134*7c478bd9Sstevel@tonic-gate ** because -s sets the TERMCAP variable also. 135*7c478bd9Sstevel@tonic-gate ** -S -- Similar to -s but outputs 2 strings suitable for 136*7c478bd9Sstevel@tonic-gate ** use in csh .login files as follows: 137*7c478bd9Sstevel@tonic-gate ** set noglob 138*7c478bd9Sstevel@tonic-gate ** set term=(`tset -S .....`) 139*7c478bd9Sstevel@tonic-gate ** setenv TERM $term[1] 140*7c478bd9Sstevel@tonic-gate ** setenv TERMCAP "$term[2]" 141*7c478bd9Sstevel@tonic-gate ** unset term 142*7c478bd9Sstevel@tonic-gate ** unset noglob 143*7c478bd9Sstevel@tonic-gate ** -Q -- be quiet. don't output 'Erase set to' etc. 144*7c478bd9Sstevel@tonic-gate ** -I -- don't do terminal initialization (is & if 145*7c478bd9Sstevel@tonic-gate ** strings). 146*7c478bd9Sstevel@tonic-gate ** -v -- On virtual terminal systems, don't set up a 147*7c478bd9Sstevel@tonic-gate ** virtual terminal. Otherwise tset will tell 148*7c478bd9Sstevel@tonic-gate ** the operating system what kind of terminal you 149*7c478bd9Sstevel@tonic-gate ** are on (if it is a known terminal) and fix up 150*7c478bd9Sstevel@tonic-gate ** the output of -s to use virtual terminal sequences. 151*7c478bd9Sstevel@tonic-gate ** 152*7c478bd9Sstevel@tonic-gate ** Files: 153*7c478bd9Sstevel@tonic-gate ** /etc/ttys 154*7c478bd9Sstevel@tonic-gate ** contains a terminal id -> terminal type 155*7c478bd9Sstevel@tonic-gate ** mapping; used when any user mapping is specified, 156*7c478bd9Sstevel@tonic-gate ** or the environment doesn't have TERM set. 157*7c478bd9Sstevel@tonic-gate ** /etc/termcap 158*7c478bd9Sstevel@tonic-gate ** a terminal_type -> terminal_capabilities 159*7c478bd9Sstevel@tonic-gate ** mapping. 160*7c478bd9Sstevel@tonic-gate ** 161*7c478bd9Sstevel@tonic-gate ** Return Codes: 162*7c478bd9Sstevel@tonic-gate ** -1 -- couldn't open termcap. 163*7c478bd9Sstevel@tonic-gate ** 1 -- bad terminal type, or standard output not tty. 164*7c478bd9Sstevel@tonic-gate ** 0 -- ok. 165*7c478bd9Sstevel@tonic-gate ** 166*7c478bd9Sstevel@tonic-gate ** Defined Constants: 167*7c478bd9Sstevel@tonic-gate ** DIALUP -- the type code for a dialup port. 168*7c478bd9Sstevel@tonic-gate ** PLUGBOARD -- the type code for a plugboard port. 169*7c478bd9Sstevel@tonic-gate ** ARPANET -- the type code for an arpanet port. 170*7c478bd9Sstevel@tonic-gate ** BACKSPACE -- control-H, the default for -e. 171*7c478bd9Sstevel@tonic-gate ** CNTL('U') -- control-U, the default for -k. 172*7c478bd9Sstevel@tonic-gate ** OLDERASE -- the ancient default erase character. 173*7c478bd9Sstevel@tonic-gate ** FILEDES -- the file descriptor to do the operation 174*7c478bd9Sstevel@tonic-gate ** on, nominally 1 or 2. 175*7c478bd9Sstevel@tonic-gate ** STDOUT -- the standard output file descriptor. 176*7c478bd9Sstevel@tonic-gate ** UIDMASK -- the bit pattern to mask with the getuid() 177*7c478bd9Sstevel@tonic-gate ** call to get just the user id. 178*7c478bd9Sstevel@tonic-gate ** GTTYN -- defines file containing generalized ttynames 179*7c478bd9Sstevel@tonic-gate ** and compiles code to look there. 180*7c478bd9Sstevel@tonic-gate ** 181*7c478bd9Sstevel@tonic-gate ** Requires: 182*7c478bd9Sstevel@tonic-gate ** Routines to handle htmp, ttys, and termcap. 183*7c478bd9Sstevel@tonic-gate ** 184*7c478bd9Sstevel@tonic-gate ** Compilation Flags: 185*7c478bd9Sstevel@tonic-gate ** OLDFLAGS -- must be defined to compile code for any of 186*7c478bd9Sstevel@tonic-gate ** the -d, -p, or -a flags. 187*7c478bd9Sstevel@tonic-gate ** OLDDIALUP -- accept the -d flag. 188*7c478bd9Sstevel@tonic-gate ** OLDPLUGBOARD -- accept the -p flag. 189*7c478bd9Sstevel@tonic-gate ** OLDARPANET -- accept the -a flag. 190*7c478bd9Sstevel@tonic-gate ** V6 -- if clear, use environments, not htmp. 191*7c478bd9Sstevel@tonic-gate ** also use TIOCSETN rather than stty to avoid flushing 192*7c478bd9Sstevel@tonic-gate ** GTTYN -- if set, compiles code to look at /etc/ttys. 193*7c478bd9Sstevel@tonic-gate ** 194*7c478bd9Sstevel@tonic-gate ** Trace Flags: 195*7c478bd9Sstevel@tonic-gate ** none 196*7c478bd9Sstevel@tonic-gate ** 197*7c478bd9Sstevel@tonic-gate ** Diagnostics: 198*7c478bd9Sstevel@tonic-gate ** Bad flag 199*7c478bd9Sstevel@tonic-gate ** An incorrect option was specified. 200*7c478bd9Sstevel@tonic-gate ** Too few args 201*7c478bd9Sstevel@tonic-gate ** more command line arguments are required. 202*7c478bd9Sstevel@tonic-gate ** Unexpected arg 203*7c478bd9Sstevel@tonic-gate ** wrong type of argument was encountered. 204*7c478bd9Sstevel@tonic-gate ** Cannot open ... 205*7c478bd9Sstevel@tonic-gate ** The specified file could not be openned. 206*7c478bd9Sstevel@tonic-gate ** Type ... unknown 207*7c478bd9Sstevel@tonic-gate ** An unknown terminal type was specified. 208*7c478bd9Sstevel@tonic-gate ** Cannot update htmp 209*7c478bd9Sstevel@tonic-gate ** Cannot update htmp file when the standard 210*7c478bd9Sstevel@tonic-gate ** output is not a terminal. 211*7c478bd9Sstevel@tonic-gate ** Erase set to ... 212*7c478bd9Sstevel@tonic-gate ** Telling that the erase character has been 213*7c478bd9Sstevel@tonic-gate ** set to the specified character. 214*7c478bd9Sstevel@tonic-gate ** Kill set to ... 215*7c478bd9Sstevel@tonic-gate ** Ditto for kill 216*7c478bd9Sstevel@tonic-gate ** Erase is ... Kill is ... 217*7c478bd9Sstevel@tonic-gate ** Tells that the erase/kill characters were 218*7c478bd9Sstevel@tonic-gate ** wierd before, but they are being left as-is. 219*7c478bd9Sstevel@tonic-gate ** Not a terminal 220*7c478bd9Sstevel@tonic-gate ** Set if FILEDES is not a terminal. 221*7c478bd9Sstevel@tonic-gate ** 222*7c478bd9Sstevel@tonic-gate ** Compilation Instructions: 223*7c478bd9Sstevel@tonic-gate ** cc -n -O tset.c -ltermlib 224*7c478bd9Sstevel@tonic-gate ** mv a.out tset 225*7c478bd9Sstevel@tonic-gate ** chown bin tset 226*7c478bd9Sstevel@tonic-gate ** chmod 4755 tset 227*7c478bd9Sstevel@tonic-gate ** 228*7c478bd9Sstevel@tonic-gate ** where 'bin' should be whoever owns the 'htmp' file. 229*7c478bd9Sstevel@tonic-gate ** If 'htmp' is 666, then tset need not be setuid. 230*7c478bd9Sstevel@tonic-gate ** 231*7c478bd9Sstevel@tonic-gate ** For version 6 the compile command should be: 232*7c478bd9Sstevel@tonic-gate ** cc -n -O -I/usr/include/retrofit tset.c -ltermlib -lretro -lS 233*7c478bd9Sstevel@tonic-gate ** 234*7c478bd9Sstevel@tonic-gate ** 235*7c478bd9Sstevel@tonic-gate ** History: 236*7c478bd9Sstevel@tonic-gate ** 1/81 -- Added alias checking for mapping identifiers. 237*7c478bd9Sstevel@tonic-gate ** 7/80 -- '-S' added. '-m' mapping added. TERMCAP string 238*7c478bd9Sstevel@tonic-gate ** cleaned up. 239*7c478bd9Sstevel@tonic-gate ** 3/80 -- Changed to use tputs. Prc & flush added. 240*7c478bd9Sstevel@tonic-gate ** 10/79 -- '-s' option extended to handle TERMCAP 241*7c478bd9Sstevel@tonic-gate ** variable, set noglob, quote the entry, 242*7c478bd9Sstevel@tonic-gate ** and know about the Bourne shell. Terminal 243*7c478bd9Sstevel@tonic-gate ** initialization moved to before any information 244*7c478bd9Sstevel@tonic-gate ** output so screen clears would not screw you. 245*7c478bd9Sstevel@tonic-gate ** '-Q' option added. 246*7c478bd9Sstevel@tonic-gate ** 8/79 -- '-' option alone changed to only output 247*7c478bd9Sstevel@tonic-gate ** type. '-s' option added. 'VERSION7' 248*7c478bd9Sstevel@tonic-gate ** changed to 'V6' for compatibility. 249*7c478bd9Sstevel@tonic-gate ** 12/78 -- modified for eventual migration to VAX/UNIX, 250*7c478bd9Sstevel@tonic-gate ** so the '-' option is changed to output only 251*7c478bd9Sstevel@tonic-gate ** the terminal type to STDOUT instead of 252*7c478bd9Sstevel@tonic-gate ** FILEDES. 253*7c478bd9Sstevel@tonic-gate ** 9/78 -- '-' and '-p' options added (now fully 254*7c478bd9Sstevel@tonic-gate ** compatible with ttytype!), and spaces are 255*7c478bd9Sstevel@tonic-gate ** permitted between the -d and the type. 256*7c478bd9Sstevel@tonic-gate ** 8/78 -- The sense of -h and -u were reversed, and the 257*7c478bd9Sstevel@tonic-gate ** -f flag is dropped -- same effect is available 258*7c478bd9Sstevel@tonic-gate ** by just stating the terminal type. 259*7c478bd9Sstevel@tonic-gate ** 10/77 -- Written. 260*7c478bd9Sstevel@tonic-gate */ 261*7c478bd9Sstevel@tonic-gate 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate #define index strchr 264*7c478bd9Sstevel@tonic-gate #define rindex strrchr 265*7c478bd9Sstevel@tonic-gate #define curerase modes.c_cc[VERASE] 266*7c478bd9Sstevel@tonic-gate #define curkill modes.c_cc[VKILL] 267*7c478bd9Sstevel@tonic-gate #define curintr modes.c_cc[VINTR] 268*7c478bd9Sstevel@tonic-gate #define olderase oldmodes.c_cc[VERASE] 269*7c478bd9Sstevel@tonic-gate #define oldkill oldmodes.c_cc[VKILL] 270*7c478bd9Sstevel@tonic-gate #define oldintr oldmodes.c_cc[VINTR] 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate #include <stdio.h> 273*7c478bd9Sstevel@tonic-gate #include <termio.h> 274*7c478bd9Sstevel@tonic-gate #include <signal.h> 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate #define YES 1 278*7c478bd9Sstevel@tonic-gate #define NO 0 279*7c478bd9Sstevel@tonic-gate #undef CNTL 280*7c478bd9Sstevel@tonic-gate #define CNTL(c) ((c)&037) 281*7c478bd9Sstevel@tonic-gate #define BACKSPACE (CNTL('H')) 282*7c478bd9Sstevel@tonic-gate #define isdigit(c) (c >= '0' && c <= '9') 283*7c478bd9Sstevel@tonic-gate #define isalnum(c) (c > ' ' && (index("<@=>!:|\177", c) == NULL)) 284*7c478bd9Sstevel@tonic-gate #define OLDERASE '#' 285*7c478bd9Sstevel@tonic-gate 286*7c478bd9Sstevel@tonic-gate /* default special characters */ 287*7c478bd9Sstevel@tonic-gate #ifndef CERASE 288*7c478bd9Sstevel@tonic-gate #define CERASE '\177' 289*7c478bd9Sstevel@tonic-gate #endif 290*7c478bd9Sstevel@tonic-gate #ifndef CKILL 291*7c478bd9Sstevel@tonic-gate #define CKILL CNTL('U') 292*7c478bd9Sstevel@tonic-gate #endif 293*7c478bd9Sstevel@tonic-gate #ifndef CINTR 294*7c478bd9Sstevel@tonic-gate #define CINTR CNTL('C') 295*7c478bd9Sstevel@tonic-gate #endif 296*7c478bd9Sstevel@tonic-gate #ifndef CDSUSP 297*7c478bd9Sstevel@tonic-gate #define CQUIT 034 /* FS, ^\ */ 298*7c478bd9Sstevel@tonic-gate #define CSTART CNTL('Q') 299*7c478bd9Sstevel@tonic-gate #define CSTOP CNTL('S') 300*7c478bd9Sstevel@tonic-gate #define CEOF CNTL('D') 301*7c478bd9Sstevel@tonic-gate #define CEOT CEOF 302*7c478bd9Sstevel@tonic-gate #define CBRK 0377 303*7c478bd9Sstevel@tonic-gate #define CSUSP CNTL('Z') 304*7c478bd9Sstevel@tonic-gate #define CDSUSP CNTL('Y') 305*7c478bd9Sstevel@tonic-gate #define CRPRNT CNTL('R') 306*7c478bd9Sstevel@tonic-gate #define CFLUSH CNTL('O') 307*7c478bd9Sstevel@tonic-gate #define CWERASE CNTL('W') 308*7c478bd9Sstevel@tonic-gate #define CLNEXT CNTL('V') 309*7c478bd9Sstevel@tonic-gate #endif 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate #define FILEDES 2 /* do gtty/stty on this descriptor */ 312*7c478bd9Sstevel@tonic-gate #define STDOUT 1 /* output of -s/-S to this descriptor */ 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate #define UIDMASK -1 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate #define USAGE "usage: tset [-] [-rsIQS] [-eC] [-kC] [-iC] [-m [ident][test speed]:type] [type]\n" 317*7c478bd9Sstevel@tonic-gate 318*7c478bd9Sstevel@tonic-gate #define OLDFLAGS 319*7c478bd9Sstevel@tonic-gate #define DIALUP "dialup" 320*7c478bd9Sstevel@tonic-gate #define OLDDIALUP "sd" 321*7c478bd9Sstevel@tonic-gate #define PLUGBOARD "plugboard" 322*7c478bd9Sstevel@tonic-gate #define OLDPLUGBOARD "sp" 323*7c478bd9Sstevel@tonic-gate /*** 324*7c478bd9Sstevel@tonic-gate #define ARPANET "arpanet" 325*7c478bd9Sstevel@tonic-gate #define OLDARPANET "sa" 326*7c478bd9Sstevel@tonic-gate /***/ 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate #define DEFTYPE "unknown" 329*7c478bd9Sstevel@tonic-gate 330*7c478bd9Sstevel@tonic-gate #define NOTTY 'x' 331*7c478bd9Sstevel@tonic-gate 332*7c478bd9Sstevel@tonic-gate /* 333*7c478bd9Sstevel@tonic-gate * Baud Rate Conditionals 334*7c478bd9Sstevel@tonic-gate */ 335*7c478bd9Sstevel@tonic-gate #define ANY 0 336*7c478bd9Sstevel@tonic-gate #define GT 1 337*7c478bd9Sstevel@tonic-gate #define EQ 2 338*7c478bd9Sstevel@tonic-gate #define LT 4 339*7c478bd9Sstevel@tonic-gate #define GE (GT|EQ) 340*7c478bd9Sstevel@tonic-gate #define LE (LT|EQ) 341*7c478bd9Sstevel@tonic-gate #define NE (GT|LT) 342*7c478bd9Sstevel@tonic-gate #define ALL (GT|EQ|LT) 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate #define NMAP 10 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate struct map { 349*7c478bd9Sstevel@tonic-gate char *Ident; 350*7c478bd9Sstevel@tonic-gate char Test; 351*7c478bd9Sstevel@tonic-gate char Speed; 352*7c478bd9Sstevel@tonic-gate char *Type; 353*7c478bd9Sstevel@tonic-gate } map[NMAP]; 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate struct map *Map = map; 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate /* This should be available in an include file */ 358*7c478bd9Sstevel@tonic-gate struct 359*7c478bd9Sstevel@tonic-gate { 360*7c478bd9Sstevel@tonic-gate char *string; 361*7c478bd9Sstevel@tonic-gate int speed; 362*7c478bd9Sstevel@tonic-gate int baudrate; 363*7c478bd9Sstevel@tonic-gate } speeds[] = { 364*7c478bd9Sstevel@tonic-gate "0", B0, 0, 365*7c478bd9Sstevel@tonic-gate "50", B50, 50, 366*7c478bd9Sstevel@tonic-gate "75", B75, 75, 367*7c478bd9Sstevel@tonic-gate "110", B110, 110, 368*7c478bd9Sstevel@tonic-gate "134", B134, 134, 369*7c478bd9Sstevel@tonic-gate "134.5",B134, 134, 370*7c478bd9Sstevel@tonic-gate "150", B150, 150, 371*7c478bd9Sstevel@tonic-gate "200", B200, 200, 372*7c478bd9Sstevel@tonic-gate "300", B300, 300, 373*7c478bd9Sstevel@tonic-gate "600", B600, 600, 374*7c478bd9Sstevel@tonic-gate "1200", B1200, 1200, 375*7c478bd9Sstevel@tonic-gate "1800", B1800, 1800, 376*7c478bd9Sstevel@tonic-gate "2400", B2400, 2400, 377*7c478bd9Sstevel@tonic-gate "4800", B4800, 4800, 378*7c478bd9Sstevel@tonic-gate "9600", B9600, 9600, 379*7c478bd9Sstevel@tonic-gate "19200",EXTA, 19200, 380*7c478bd9Sstevel@tonic-gate "exta", EXTA, 19200, 381*7c478bd9Sstevel@tonic-gate "extb", EXTB, 38400, 382*7c478bd9Sstevel@tonic-gate "57600",B57600, 57600, 383*7c478bd9Sstevel@tonic-gate "76800",B76800, 76800, 384*7c478bd9Sstevel@tonic-gate "115200",B115200,115200, 385*7c478bd9Sstevel@tonic-gate "153600",B153600,153600, 386*7c478bd9Sstevel@tonic-gate "230400",B230400,230400, 387*7c478bd9Sstevel@tonic-gate "307200",B307200,307200, 388*7c478bd9Sstevel@tonic-gate "460800",B460800,460800, 389*7c478bd9Sstevel@tonic-gate 0, 390*7c478bd9Sstevel@tonic-gate }; 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate signed char Erase_char; /* new erase character */ 393*7c478bd9Sstevel@tonic-gate char Kill_char; /* new kill character */ 394*7c478bd9Sstevel@tonic-gate char Intr_char; /* new interrupt character */ 395*7c478bd9Sstevel@tonic-gate char Specialerase; /* set => Erase_char only on terminals with backspace */ 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate char Ttyid = NOTTY; /* terminal identifier */ 398*7c478bd9Sstevel@tonic-gate char *TtyType; /* type of terminal */ 399*7c478bd9Sstevel@tonic-gate char *DefType; /* default type if none other computed */ 400*7c478bd9Sstevel@tonic-gate char *NewType; /* mapping identifier based on old flags */ 401*7c478bd9Sstevel@tonic-gate int Mapped; /* mapping has been specified */ 402*7c478bd9Sstevel@tonic-gate int Dash_u; /* don't update htmp */ 403*7c478bd9Sstevel@tonic-gate int Dash_h; /* don't read htmp */ 404*7c478bd9Sstevel@tonic-gate int DoSetenv; /* output setenv commands */ 405*7c478bd9Sstevel@tonic-gate int BeQuiet; /* be quiet */ 406*7c478bd9Sstevel@tonic-gate int NoInit; /* don't output initialization string */ 407*7c478bd9Sstevel@tonic-gate int IsReset; /* invoked as reset */ 408*7c478bd9Sstevel@tonic-gate int Report; /* report current type */ 409*7c478bd9Sstevel@tonic-gate int Ureport; /* report to user */ 410*7c478bd9Sstevel@tonic-gate int RepOnly; /* report only */ 411*7c478bd9Sstevel@tonic-gate int CmndLine; /* output full command lines (-s option) */ 412*7c478bd9Sstevel@tonic-gate int Ask; /* ask user for termtype */ 413*7c478bd9Sstevel@tonic-gate int DoVirtTerm = YES; /* Set up a virtual terminal */ 414*7c478bd9Sstevel@tonic-gate int PadBaud; /* Min rate of padding needed */ 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate #define CAPBUFSIZ 1024 417*7c478bd9Sstevel@tonic-gate char Capbuf[CAPBUFSIZ]; /* line from /etc/termcap for this TtyType */ 418*7c478bd9Sstevel@tonic-gate char *Ttycap; /* termcap line from termcap or environ */ 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate char Aliasbuf[128]; 421*7c478bd9Sstevel@tonic-gate char *Alias[16]; 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate extern char *strcpy(); 424*7c478bd9Sstevel@tonic-gate extern char *index(); 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate struct delay 427*7c478bd9Sstevel@tonic-gate { 428*7c478bd9Sstevel@tonic-gate int d_delay; 429*7c478bd9Sstevel@tonic-gate int d_bits; 430*7c478bd9Sstevel@tonic-gate }; 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate #include "tset.delays.h" 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate struct termio mode; 435*7c478bd9Sstevel@tonic-gate struct termio oldmode; 436*7c478bd9Sstevel@tonic-gate struct termios modes; 437*7c478bd9Sstevel@tonic-gate struct termios oldmodes; 438*7c478bd9Sstevel@tonic-gate int istermios; 439*7c478bd9Sstevel@tonic-gate 440*7c478bd9Sstevel@tonic-gate char reset(); /* Routine for checking&resetting chars */ 441*7c478bd9Sstevel@tonic-gate int prc(); 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate main(argc, argv) 444*7c478bd9Sstevel@tonic-gate int argc; 445*7c478bd9Sstevel@tonic-gate char *argv[]; 446*7c478bd9Sstevel@tonic-gate { 447*7c478bd9Sstevel@tonic-gate char buf[CAPBUFSIZ]; 448*7c478bd9Sstevel@tonic-gate char termbuf[32]; 449*7c478bd9Sstevel@tonic-gate auto char *bufp; 450*7c478bd9Sstevel@tonic-gate register char *p; 451*7c478bd9Sstevel@tonic-gate char *command; 452*7c478bd9Sstevel@tonic-gate register int i; 453*7c478bd9Sstevel@tonic-gate int Break; 454*7c478bd9Sstevel@tonic-gate int Not; 455*7c478bd9Sstevel@tonic-gate char *nextarg(); 456*7c478bd9Sstevel@tonic-gate char *mapped(); 457*7c478bd9Sstevel@tonic-gate extern char *rindex(); 458*7c478bd9Sstevel@tonic-gate struct winsize win; 459*7c478bd9Sstevel@tonic-gate extern char *getenv(); 460*7c478bd9Sstevel@tonic-gate extern char *tgetstr(); 461*7c478bd9Sstevel@tonic-gate char bs_char; 462*7c478bd9Sstevel@tonic-gate int csh; 463*7c478bd9Sstevel@tonic-gate int settle = NO; 464*7c478bd9Sstevel@tonic-gate void setmode(); 465*7c478bd9Sstevel@tonic-gate extern char PC; 466*7c478bd9Sstevel@tonic-gate extern short ospeed; 467*7c478bd9Sstevel@tonic-gate 468*7c478bd9Sstevel@tonic-gate if ((istermios = ioctl(FILEDES, TCGETS, (char *)&modes)) < 0) { 469*7c478bd9Sstevel@tonic-gate if (ioctl(FILEDES, TCGETA, (char *)&mode) < 0) 470*7c478bd9Sstevel@tonic-gate { 471*7c478bd9Sstevel@tonic-gate prs("Not a terminal\n"); 472*7c478bd9Sstevel@tonic-gate exit(1); 473*7c478bd9Sstevel@tonic-gate } 474*7c478bd9Sstevel@tonic-gate bmove((char *)&mode, (char *)&oldmode, sizeof mode); 475*7c478bd9Sstevel@tonic-gate modes.c_lflag = oldmodes.c_lflag = mode.c_lflag; 476*7c478bd9Sstevel@tonic-gate modes.c_oflag = oldmodes.c_oflag = mode.c_oflag; 477*7c478bd9Sstevel@tonic-gate modes.c_iflag = oldmodes.c_iflag = mode.c_iflag; 478*7c478bd9Sstevel@tonic-gate modes.c_cflag = oldmodes.c_cflag = mode.c_cflag; 479*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 480*7c478bd9Sstevel@tonic-gate modes.c_cc[i] = oldmodes.c_cc[i] = mode.c_cc[i]; 481*7c478bd9Sstevel@tonic-gate } else 482*7c478bd9Sstevel@tonic-gate bmove((char *)&modes, (char *)&oldmodes, sizeof modes); 483*7c478bd9Sstevel@tonic-gate ospeed = cfgetospeed(&modes); 484*7c478bd9Sstevel@tonic-gate (void) signal(SIGINT, setmode); 485*7c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, setmode); 486*7c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, setmode); 487*7c478bd9Sstevel@tonic-gate 488*7c478bd9Sstevel@tonic-gate if (command = rindex(argv[0], '/')) 489*7c478bd9Sstevel@tonic-gate command++; 490*7c478bd9Sstevel@tonic-gate else 491*7c478bd9Sstevel@tonic-gate command = argv[0]; 492*7c478bd9Sstevel@tonic-gate if (sequal(command, "reset") ) 493*7c478bd9Sstevel@tonic-gate { 494*7c478bd9Sstevel@tonic-gate /* 495*7c478bd9Sstevel@tonic-gate * Reset the teletype mode bits to a sensible state. 496*7c478bd9Sstevel@tonic-gate * Copied from the program by Kurt Shoens & Mark Horton. 497*7c478bd9Sstevel@tonic-gate * Very useful after crapping out in raw. 498*7c478bd9Sstevel@tonic-gate */ 499*7c478bd9Sstevel@tonic-gate if ((istermios = ioctl(FILEDES, TCGETS, (char *)&modes)) < 0) { 500*7c478bd9Sstevel@tonic-gate (void) ioctl(FILEDES, TCGETA, (char *)&mode); 501*7c478bd9Sstevel@tonic-gate modes.c_lflag = mode.c_lflag; 502*7c478bd9Sstevel@tonic-gate modes.c_oflag = mode.c_oflag; 503*7c478bd9Sstevel@tonic-gate modes.c_iflag = mode.c_iflag; 504*7c478bd9Sstevel@tonic-gate modes.c_cflag = mode.c_cflag; 505*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 506*7c478bd9Sstevel@tonic-gate modes.c_cc[i] = mode.c_cc[i]; 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate curerase = reset(curerase, CERASE); 509*7c478bd9Sstevel@tonic-gate curkill = reset(curkill, CKILL); 510*7c478bd9Sstevel@tonic-gate curintr = reset(curintr, CINTR); 511*7c478bd9Sstevel@tonic-gate modes.c_cc[VQUIT] = reset(modes.c_cc[VQUIT], CQUIT); 512*7c478bd9Sstevel@tonic-gate modes.c_cc[VEOF] = reset(modes.c_cc[VEOF], CEOF); 513*7c478bd9Sstevel@tonic-gate 514*7c478bd9Sstevel@tonic-gate modes.c_iflag |= (BRKINT|ISTRIP|ICRNL|IXON); 515*7c478bd9Sstevel@tonic-gate modes.c_iflag &= ~(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF); 516*7c478bd9Sstevel@tonic-gate modes.c_oflag |= (OPOST|ONLCR); 517*7c478bd9Sstevel@tonic-gate modes.c_oflag &= ~(OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL| 518*7c478bd9Sstevel@tonic-gate NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); 519*7c478bd9Sstevel@tonic-gate modes.c_cflag |= (CS7|CREAD); 520*7c478bd9Sstevel@tonic-gate modes.c_cflag &= ~(PARODD|CLOCAL); 521*7c478bd9Sstevel@tonic-gate modes.c_lflag |= (ISIG|ICANON|ECHO|ECHOK); 522*7c478bd9Sstevel@tonic-gate modes.c_lflag &= ~(XCASE|ECHONL|NOFLSH); 523*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 524*7c478bd9Sstevel@tonic-gate mode.c_lflag = modes.c_lflag; 525*7c478bd9Sstevel@tonic-gate mode.c_oflag = modes.c_oflag; 526*7c478bd9Sstevel@tonic-gate mode.c_iflag = modes.c_iflag; 527*7c478bd9Sstevel@tonic-gate mode.c_cflag = modes.c_cflag; 528*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 529*7c478bd9Sstevel@tonic-gate mode.c_cc[i] = modes.c_cc[i]; 530*7c478bd9Sstevel@tonic-gate (void) ioctl(FILEDES, TCSETAW, (char *)&mode); 531*7c478bd9Sstevel@tonic-gate } else 532*7c478bd9Sstevel@tonic-gate (void) ioctl(FILEDES, TCSETSW, (char *)&modes); 533*7c478bd9Sstevel@tonic-gate Dash_u = YES; 534*7c478bd9Sstevel@tonic-gate BeQuiet = YES; 535*7c478bd9Sstevel@tonic-gate IsReset = YES; 536*7c478bd9Sstevel@tonic-gate } 537*7c478bd9Sstevel@tonic-gate else if (argc == 2 && sequal(argv[1], "-")) 538*7c478bd9Sstevel@tonic-gate { 539*7c478bd9Sstevel@tonic-gate RepOnly = YES; 540*7c478bd9Sstevel@tonic-gate Dash_u = YES; 541*7c478bd9Sstevel@tonic-gate } 542*7c478bd9Sstevel@tonic-gate argc--; 543*7c478bd9Sstevel@tonic-gate 544*7c478bd9Sstevel@tonic-gate /* scan argument list and collect flags */ 545*7c478bd9Sstevel@tonic-gate while (--argc >= 0) 546*7c478bd9Sstevel@tonic-gate { 547*7c478bd9Sstevel@tonic-gate p = *++argv; 548*7c478bd9Sstevel@tonic-gate if (*p == '-') 549*7c478bd9Sstevel@tonic-gate { 550*7c478bd9Sstevel@tonic-gate if (*++p == NULL) 551*7c478bd9Sstevel@tonic-gate Report = YES; /* report current terminal type */ 552*7c478bd9Sstevel@tonic-gate else while (*p) switch (*p++) 553*7c478bd9Sstevel@tonic-gate { 554*7c478bd9Sstevel@tonic-gate 555*7c478bd9Sstevel@tonic-gate case 'r': /* report to user */ 556*7c478bd9Sstevel@tonic-gate Ureport = YES; 557*7c478bd9Sstevel@tonic-gate continue; 558*7c478bd9Sstevel@tonic-gate 559*7c478bd9Sstevel@tonic-gate case 'E': /* special erase: operate on all but TTY33 */ 560*7c478bd9Sstevel@tonic-gate Specialerase = YES; 561*7c478bd9Sstevel@tonic-gate /* explicit fall-through to -e case */ 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate case 'e': /* erase character */ 564*7c478bd9Sstevel@tonic-gate if (*p == NULL) 565*7c478bd9Sstevel@tonic-gate Erase_char = -1; 566*7c478bd9Sstevel@tonic-gate else 567*7c478bd9Sstevel@tonic-gate { 568*7c478bd9Sstevel@tonic-gate if (*p == '^' && p[1] != NULL) 569*7c478bd9Sstevel@tonic-gate if (*++p == '?') 570*7c478bd9Sstevel@tonic-gate Erase_char = '\177'; 571*7c478bd9Sstevel@tonic-gate else 572*7c478bd9Sstevel@tonic-gate Erase_char = CNTL(*p); 573*7c478bd9Sstevel@tonic-gate else 574*7c478bd9Sstevel@tonic-gate Erase_char = *p; 575*7c478bd9Sstevel@tonic-gate p++; 576*7c478bd9Sstevel@tonic-gate } 577*7c478bd9Sstevel@tonic-gate continue; 578*7c478bd9Sstevel@tonic-gate 579*7c478bd9Sstevel@tonic-gate case 'i': /* interrupt character */ 580*7c478bd9Sstevel@tonic-gate if (*p == NULL) 581*7c478bd9Sstevel@tonic-gate Intr_char = CNTL('C'); 582*7c478bd9Sstevel@tonic-gate else 583*7c478bd9Sstevel@tonic-gate { 584*7c478bd9Sstevel@tonic-gate if (*p == '^' && p[1] != NULL) 585*7c478bd9Sstevel@tonic-gate if (*++p == '?') 586*7c478bd9Sstevel@tonic-gate Intr_char = '\177'; 587*7c478bd9Sstevel@tonic-gate else 588*7c478bd9Sstevel@tonic-gate Intr_char = CNTL(*p); 589*7c478bd9Sstevel@tonic-gate else 590*7c478bd9Sstevel@tonic-gate Intr_char = *p; 591*7c478bd9Sstevel@tonic-gate p++; 592*7c478bd9Sstevel@tonic-gate } 593*7c478bd9Sstevel@tonic-gate continue; 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate case 'k': /* kill character */ 596*7c478bd9Sstevel@tonic-gate if (*p == NULL) 597*7c478bd9Sstevel@tonic-gate Kill_char = CNTL('U'); 598*7c478bd9Sstevel@tonic-gate else 599*7c478bd9Sstevel@tonic-gate { 600*7c478bd9Sstevel@tonic-gate if (*p == '^' && p[1] != NULL) 601*7c478bd9Sstevel@tonic-gate if (*++p == '?') 602*7c478bd9Sstevel@tonic-gate Kill_char = '\177'; 603*7c478bd9Sstevel@tonic-gate else 604*7c478bd9Sstevel@tonic-gate Kill_char = CNTL(*p); 605*7c478bd9Sstevel@tonic-gate else 606*7c478bd9Sstevel@tonic-gate Kill_char = *p; 607*7c478bd9Sstevel@tonic-gate p++; 608*7c478bd9Sstevel@tonic-gate } 609*7c478bd9Sstevel@tonic-gate continue; 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate # ifdef OLDFLAGS 612*7c478bd9Sstevel@tonic-gate # ifdef OLDDIALUP 613*7c478bd9Sstevel@tonic-gate case 'd': /* dialup type */ 614*7c478bd9Sstevel@tonic-gate NewType = DIALUP; 615*7c478bd9Sstevel@tonic-gate goto mapold; 616*7c478bd9Sstevel@tonic-gate # endif 617*7c478bd9Sstevel@tonic-gate 618*7c478bd9Sstevel@tonic-gate # ifdef OLDPLUGBOARD 619*7c478bd9Sstevel@tonic-gate case 'p': /* plugboard type */ 620*7c478bd9Sstevel@tonic-gate NewType = PLUGBOARD; 621*7c478bd9Sstevel@tonic-gate goto mapold; 622*7c478bd9Sstevel@tonic-gate # endif 623*7c478bd9Sstevel@tonic-gate 624*7c478bd9Sstevel@tonic-gate # ifdef OLDARPANET 625*7c478bd9Sstevel@tonic-gate case 'a': /* arpanet type */ 626*7c478bd9Sstevel@tonic-gate Newtype = ARPANET; 627*7c478bd9Sstevel@tonic-gate goto mapold; 628*7c478bd9Sstevel@tonic-gate # endif 629*7c478bd9Sstevel@tonic-gate 630*7c478bd9Sstevel@tonic-gate mapold: Map->Ident = NewType; 631*7c478bd9Sstevel@tonic-gate Map->Test = ALL; 632*7c478bd9Sstevel@tonic-gate if (*p == NULL) 633*7c478bd9Sstevel@tonic-gate { 634*7c478bd9Sstevel@tonic-gate p = nextarg(argc--, argv++); 635*7c478bd9Sstevel@tonic-gate } 636*7c478bd9Sstevel@tonic-gate Map->Type = p; 637*7c478bd9Sstevel@tonic-gate Map++; 638*7c478bd9Sstevel@tonic-gate Mapped = YES; 639*7c478bd9Sstevel@tonic-gate p = ""; 640*7c478bd9Sstevel@tonic-gate continue; 641*7c478bd9Sstevel@tonic-gate # endif 642*7c478bd9Sstevel@tonic-gate 643*7c478bd9Sstevel@tonic-gate case 'm': /* map identifier to type */ 644*7c478bd9Sstevel@tonic-gate /* This code is very loose. Almost no 645*7c478bd9Sstevel@tonic-gate ** syntax checking is done!! However, 646*7c478bd9Sstevel@tonic-gate ** illegal syntax will only produce 647*7c478bd9Sstevel@tonic-gate ** weird results. 648*7c478bd9Sstevel@tonic-gate */ 649*7c478bd9Sstevel@tonic-gate if (*p == NULL) 650*7c478bd9Sstevel@tonic-gate { 651*7c478bd9Sstevel@tonic-gate p = nextarg(argc--, argv++); 652*7c478bd9Sstevel@tonic-gate } 653*7c478bd9Sstevel@tonic-gate if (isalnum(*p)) 654*7c478bd9Sstevel@tonic-gate { 655*7c478bd9Sstevel@tonic-gate Map->Ident = p; /* identifier */ 656*7c478bd9Sstevel@tonic-gate while (isalnum(*p)) p++; 657*7c478bd9Sstevel@tonic-gate } 658*7c478bd9Sstevel@tonic-gate else 659*7c478bd9Sstevel@tonic-gate Map->Ident = ""; 660*7c478bd9Sstevel@tonic-gate Break = NO; 661*7c478bd9Sstevel@tonic-gate Not = NO; 662*7c478bd9Sstevel@tonic-gate while (!Break) switch (*p) 663*7c478bd9Sstevel@tonic-gate { 664*7c478bd9Sstevel@tonic-gate case NULL: 665*7c478bd9Sstevel@tonic-gate p = nextarg(argc--, argv++); 666*7c478bd9Sstevel@tonic-gate continue; 667*7c478bd9Sstevel@tonic-gate 668*7c478bd9Sstevel@tonic-gate case ':': /* mapped type */ 669*7c478bd9Sstevel@tonic-gate *p++ = NULL; 670*7c478bd9Sstevel@tonic-gate Break = YES; 671*7c478bd9Sstevel@tonic-gate continue; 672*7c478bd9Sstevel@tonic-gate 673*7c478bd9Sstevel@tonic-gate case '>': /* conditional */ 674*7c478bd9Sstevel@tonic-gate Map->Test |= GT; 675*7c478bd9Sstevel@tonic-gate *p++ = NULL; 676*7c478bd9Sstevel@tonic-gate continue; 677*7c478bd9Sstevel@tonic-gate 678*7c478bd9Sstevel@tonic-gate case '<': /* conditional */ 679*7c478bd9Sstevel@tonic-gate Map->Test |= LT; 680*7c478bd9Sstevel@tonic-gate *p++ = NULL; 681*7c478bd9Sstevel@tonic-gate continue; 682*7c478bd9Sstevel@tonic-gate 683*7c478bd9Sstevel@tonic-gate case '=': /* conditional */ 684*7c478bd9Sstevel@tonic-gate case '@': 685*7c478bd9Sstevel@tonic-gate Map->Test |= EQ; 686*7c478bd9Sstevel@tonic-gate *p++ = NULL; 687*7c478bd9Sstevel@tonic-gate continue; 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate case '!': /* invert conditions */ 690*7c478bd9Sstevel@tonic-gate Not = ~Not; 691*7c478bd9Sstevel@tonic-gate *p++ = NULL; 692*7c478bd9Sstevel@tonic-gate continue; 693*7c478bd9Sstevel@tonic-gate 694*7c478bd9Sstevel@tonic-gate case 'B': /* Baud rate */ 695*7c478bd9Sstevel@tonic-gate p++; 696*7c478bd9Sstevel@tonic-gate /* intentional fallthru */ 697*7c478bd9Sstevel@tonic-gate default: 698*7c478bd9Sstevel@tonic-gate if (isdigit(*p) || *p == 'e') 699*7c478bd9Sstevel@tonic-gate { 700*7c478bd9Sstevel@tonic-gate Map->Speed = baudrate(p); 701*7c478bd9Sstevel@tonic-gate while (isalnum(*p) || *p == '.') 702*7c478bd9Sstevel@tonic-gate p++; 703*7c478bd9Sstevel@tonic-gate } 704*7c478bd9Sstevel@tonic-gate else 705*7c478bd9Sstevel@tonic-gate Break = YES; 706*7c478bd9Sstevel@tonic-gate continue; 707*7c478bd9Sstevel@tonic-gate } 708*7c478bd9Sstevel@tonic-gate if (Not) /* invert sense of test */ 709*7c478bd9Sstevel@tonic-gate { 710*7c478bd9Sstevel@tonic-gate Map->Test = (~(Map->Test))&ALL; 711*7c478bd9Sstevel@tonic-gate } 712*7c478bd9Sstevel@tonic-gate if (*p == NULL) 713*7c478bd9Sstevel@tonic-gate { 714*7c478bd9Sstevel@tonic-gate p = nextarg(argc--, argv++); 715*7c478bd9Sstevel@tonic-gate } 716*7c478bd9Sstevel@tonic-gate Map->Type = p; 717*7c478bd9Sstevel@tonic-gate p = ""; 718*7c478bd9Sstevel@tonic-gate Map++; 719*7c478bd9Sstevel@tonic-gate Mapped = YES; 720*7c478bd9Sstevel@tonic-gate continue; 721*7c478bd9Sstevel@tonic-gate 722*7c478bd9Sstevel@tonic-gate case 'h': /* don't get type from htmp or env */ 723*7c478bd9Sstevel@tonic-gate Dash_h = YES; 724*7c478bd9Sstevel@tonic-gate continue; 725*7c478bd9Sstevel@tonic-gate 726*7c478bd9Sstevel@tonic-gate case 'u': /* don't update htmp */ 727*7c478bd9Sstevel@tonic-gate Dash_u = YES; 728*7c478bd9Sstevel@tonic-gate continue; 729*7c478bd9Sstevel@tonic-gate 730*7c478bd9Sstevel@tonic-gate case 's': /* output setenv commands */ 731*7c478bd9Sstevel@tonic-gate DoSetenv = YES; 732*7c478bd9Sstevel@tonic-gate CmndLine = YES; 733*7c478bd9Sstevel@tonic-gate continue; 734*7c478bd9Sstevel@tonic-gate 735*7c478bd9Sstevel@tonic-gate case 'S': /* output setenv strings */ 736*7c478bd9Sstevel@tonic-gate DoSetenv = YES; 737*7c478bd9Sstevel@tonic-gate CmndLine = NO; 738*7c478bd9Sstevel@tonic-gate continue; 739*7c478bd9Sstevel@tonic-gate 740*7c478bd9Sstevel@tonic-gate case 'Q': /* be quiet */ 741*7c478bd9Sstevel@tonic-gate BeQuiet = YES; 742*7c478bd9Sstevel@tonic-gate continue; 743*7c478bd9Sstevel@tonic-gate 744*7c478bd9Sstevel@tonic-gate case 'I': /* no initialization */ 745*7c478bd9Sstevel@tonic-gate NoInit = YES; 746*7c478bd9Sstevel@tonic-gate continue; 747*7c478bd9Sstevel@tonic-gate 748*7c478bd9Sstevel@tonic-gate case 'A': /* Ask user */ 749*7c478bd9Sstevel@tonic-gate Ask = YES; 750*7c478bd9Sstevel@tonic-gate continue; 751*7c478bd9Sstevel@tonic-gate 752*7c478bd9Sstevel@tonic-gate case 'v': /* no virtual terminal */ 753*7c478bd9Sstevel@tonic-gate DoVirtTerm = NO; 754*7c478bd9Sstevel@tonic-gate continue; 755*7c478bd9Sstevel@tonic-gate 756*7c478bd9Sstevel@tonic-gate default: 757*7c478bd9Sstevel@tonic-gate *p-- = NULL; 758*7c478bd9Sstevel@tonic-gate fatal("Bad flag -", p); 759*7c478bd9Sstevel@tonic-gate } 760*7c478bd9Sstevel@tonic-gate } 761*7c478bd9Sstevel@tonic-gate else 762*7c478bd9Sstevel@tonic-gate { 763*7c478bd9Sstevel@tonic-gate /* terminal type */ 764*7c478bd9Sstevel@tonic-gate DefType = p; 765*7c478bd9Sstevel@tonic-gate } 766*7c478bd9Sstevel@tonic-gate } 767*7c478bd9Sstevel@tonic-gate 768*7c478bd9Sstevel@tonic-gate if (DefType) 769*7c478bd9Sstevel@tonic-gate { 770*7c478bd9Sstevel@tonic-gate if (Mapped) 771*7c478bd9Sstevel@tonic-gate { 772*7c478bd9Sstevel@tonic-gate Map->Ident = ""; /* means "map any type" */ 773*7c478bd9Sstevel@tonic-gate Map->Test = ALL; /* at all baud rates */ 774*7c478bd9Sstevel@tonic-gate Map->Type = DefType; /* to the default type */ 775*7c478bd9Sstevel@tonic-gate } 776*7c478bd9Sstevel@tonic-gate else 777*7c478bd9Sstevel@tonic-gate TtyType = DefType; 778*7c478bd9Sstevel@tonic-gate } 779*7c478bd9Sstevel@tonic-gate 780*7c478bd9Sstevel@tonic-gate /* 781*7c478bd9Sstevel@tonic-gate * Get rid of $TERMCAP, if it's there, so we get a real 782*7c478bd9Sstevel@tonic-gate * entry from /etc/termcap. This prevents us from being 783*7c478bd9Sstevel@tonic-gate * fooled by out of date stuff in the environment, and 784*7c478bd9Sstevel@tonic-gate * makes tabs work right on CB/Unix. 785*7c478bd9Sstevel@tonic-gate */ 786*7c478bd9Sstevel@tonic-gate bufp = getenv("TERMCAP"); 787*7c478bd9Sstevel@tonic-gate if (bufp && *bufp != '/') 788*7c478bd9Sstevel@tonic-gate (void) strcpy(bufp-8, "NOTHING"); /* overwrite only "TERMCAP" */ 789*7c478bd9Sstevel@tonic-gate /* get current idea of terminal type from environment */ 790*7c478bd9Sstevel@tonic-gate if (!Dash_h && TtyType == 0) 791*7c478bd9Sstevel@tonic-gate TtyType = getenv("TERM"); 792*7c478bd9Sstevel@tonic-gate 793*7c478bd9Sstevel@tonic-gate if (!RepOnly && Ttyid == NOTTY && (TtyType == 0 || !Dash_h)) 794*7c478bd9Sstevel@tonic-gate Ttyid = ttyname(FILEDES); 795*7c478bd9Sstevel@tonic-gate 796*7c478bd9Sstevel@tonic-gate /* If still undefined, use DEFTYPE */ 797*7c478bd9Sstevel@tonic-gate if (TtyType == 0) 798*7c478bd9Sstevel@tonic-gate { 799*7c478bd9Sstevel@tonic-gate TtyType = DEFTYPE; 800*7c478bd9Sstevel@tonic-gate } 801*7c478bd9Sstevel@tonic-gate 802*7c478bd9Sstevel@tonic-gate /* check for dialup or other mapping */ 803*7c478bd9Sstevel@tonic-gate if (Mapped) 804*7c478bd9Sstevel@tonic-gate { 805*7c478bd9Sstevel@tonic-gate if (!(Alias[0] && isalias(TtyType))) 806*7c478bd9Sstevel@tonic-gate if (tgetent(Capbuf, TtyType) > 0) 807*7c478bd9Sstevel@tonic-gate makealias(Capbuf); 808*7c478bd9Sstevel@tonic-gate TtyType = mapped(TtyType); 809*7c478bd9Sstevel@tonic-gate } 810*7c478bd9Sstevel@tonic-gate 811*7c478bd9Sstevel@tonic-gate /* TtyType now contains a pointer to the type of the terminal */ 812*7c478bd9Sstevel@tonic-gate /* If the first character is '?', ask the user */ 813*7c478bd9Sstevel@tonic-gate if (TtyType[0] == '?') 814*7c478bd9Sstevel@tonic-gate { 815*7c478bd9Sstevel@tonic-gate Ask = YES; 816*7c478bd9Sstevel@tonic-gate TtyType++; 817*7c478bd9Sstevel@tonic-gate if (TtyType[0] == '\0') 818*7c478bd9Sstevel@tonic-gate TtyType = DEFTYPE; 819*7c478bd9Sstevel@tonic-gate } 820*7c478bd9Sstevel@tonic-gate if (Ask) 821*7c478bd9Sstevel@tonic-gate { 822*7c478bd9Sstevel@tonic-gate ask: 823*7c478bd9Sstevel@tonic-gate prs("TERM = ("); 824*7c478bd9Sstevel@tonic-gate prs(TtyType); 825*7c478bd9Sstevel@tonic-gate prs(") "); 826*7c478bd9Sstevel@tonic-gate flush(); 827*7c478bd9Sstevel@tonic-gate 828*7c478bd9Sstevel@tonic-gate /* read the terminal. If not empty, set type */ 829*7c478bd9Sstevel@tonic-gate i = read(2, termbuf, sizeof termbuf - 1); 830*7c478bd9Sstevel@tonic-gate if (i > 0) 831*7c478bd9Sstevel@tonic-gate { 832*7c478bd9Sstevel@tonic-gate if (termbuf[i - 1] == '\n') 833*7c478bd9Sstevel@tonic-gate i--; 834*7c478bd9Sstevel@tonic-gate termbuf[i] = '\0'; 835*7c478bd9Sstevel@tonic-gate if (termbuf[0] != '\0') 836*7c478bd9Sstevel@tonic-gate TtyType = termbuf; 837*7c478bd9Sstevel@tonic-gate } 838*7c478bd9Sstevel@tonic-gate } 839*7c478bd9Sstevel@tonic-gate 840*7c478bd9Sstevel@tonic-gate /* get terminal capabilities */ 841*7c478bd9Sstevel@tonic-gate if (!(Alias[0] && isalias(TtyType))) { 842*7c478bd9Sstevel@tonic-gate switch (tgetent(Capbuf, TtyType)) 843*7c478bd9Sstevel@tonic-gate { 844*7c478bd9Sstevel@tonic-gate case -1: 845*7c478bd9Sstevel@tonic-gate prs("Cannot find termcap\n"); 846*7c478bd9Sstevel@tonic-gate flush(); 847*7c478bd9Sstevel@tonic-gate exit(-1); 848*7c478bd9Sstevel@tonic-gate 849*7c478bd9Sstevel@tonic-gate case 0: 850*7c478bd9Sstevel@tonic-gate prs("Type "); 851*7c478bd9Sstevel@tonic-gate prs(TtyType); 852*7c478bd9Sstevel@tonic-gate prs(" unknown\n"); 853*7c478bd9Sstevel@tonic-gate flush(); 854*7c478bd9Sstevel@tonic-gate if (DoSetenv) 855*7c478bd9Sstevel@tonic-gate { 856*7c478bd9Sstevel@tonic-gate TtyType = DEFTYPE; 857*7c478bd9Sstevel@tonic-gate Alias[0] = '\0'; 858*7c478bd9Sstevel@tonic-gate goto ask; 859*7c478bd9Sstevel@tonic-gate } 860*7c478bd9Sstevel@tonic-gate else 861*7c478bd9Sstevel@tonic-gate exit(1); 862*7c478bd9Sstevel@tonic-gate } 863*7c478bd9Sstevel@tonic-gate } 864*7c478bd9Sstevel@tonic-gate Ttycap = Capbuf; 865*7c478bd9Sstevel@tonic-gate 866*7c478bd9Sstevel@tonic-gate if (!RepOnly) 867*7c478bd9Sstevel@tonic-gate { 868*7c478bd9Sstevel@tonic-gate /* determine erase and kill characters */ 869*7c478bd9Sstevel@tonic-gate if (Specialerase && !tgetflag("bs")) 870*7c478bd9Sstevel@tonic-gate Erase_char = 0; 871*7c478bd9Sstevel@tonic-gate bufp = buf; 872*7c478bd9Sstevel@tonic-gate p = tgetstr("kb", &bufp); 873*7c478bd9Sstevel@tonic-gate if (p == NULL || p[1] != '\0') 874*7c478bd9Sstevel@tonic-gate p = tgetstr("bc", &bufp); 875*7c478bd9Sstevel@tonic-gate if (p != NULL && p[1] == '\0') 876*7c478bd9Sstevel@tonic-gate bs_char = p[0]; 877*7c478bd9Sstevel@tonic-gate else if (tgetflag("bs")) 878*7c478bd9Sstevel@tonic-gate bs_char = BACKSPACE; 879*7c478bd9Sstevel@tonic-gate else 880*7c478bd9Sstevel@tonic-gate bs_char = 0; 881*7c478bd9Sstevel@tonic-gate /* 882*7c478bd9Sstevel@tonic-gate * The next statement can't be fixed, because now users 883*7c478bd9Sstevel@tonic-gate * depend on keeping their erase character as DEL if the 884*7c478bd9Sstevel@tonic-gate * system set it there. People who want backspace have 885*7c478bd9Sstevel@tonic-gate * to say tset -e. 886*7c478bd9Sstevel@tonic-gate */ 887*7c478bd9Sstevel@tonic-gate if (Erase_char == 0 && !tgetflag("os") && curerase == OLDERASE) 888*7c478bd9Sstevel@tonic-gate { 889*7c478bd9Sstevel@tonic-gate if (tgetflag("bs") || bs_char != 0) 890*7c478bd9Sstevel@tonic-gate Erase_char = -1; 891*7c478bd9Sstevel@tonic-gate } 892*7c478bd9Sstevel@tonic-gate if (Erase_char < 0) 893*7c478bd9Sstevel@tonic-gate Erase_char = (bs_char != 0) ? bs_char : BACKSPACE; 894*7c478bd9Sstevel@tonic-gate 895*7c478bd9Sstevel@tonic-gate if (curerase == 0) 896*7c478bd9Sstevel@tonic-gate curerase = CERASE; 897*7c478bd9Sstevel@tonic-gate if (Erase_char != 0) 898*7c478bd9Sstevel@tonic-gate curerase = Erase_char; 899*7c478bd9Sstevel@tonic-gate 900*7c478bd9Sstevel@tonic-gate if (curintr == 0) 901*7c478bd9Sstevel@tonic-gate curintr = CINTR; 902*7c478bd9Sstevel@tonic-gate if (Intr_char != 0) 903*7c478bd9Sstevel@tonic-gate curintr = Intr_char; 904*7c478bd9Sstevel@tonic-gate 905*7c478bd9Sstevel@tonic-gate if (curkill == 0) 906*7c478bd9Sstevel@tonic-gate curkill = CKILL; 907*7c478bd9Sstevel@tonic-gate if (Kill_char != 0) 908*7c478bd9Sstevel@tonic-gate curkill = Kill_char; 909*7c478bd9Sstevel@tonic-gate 910*7c478bd9Sstevel@tonic-gate /* set modes */ 911*7c478bd9Sstevel@tonic-gate PadBaud = tgetnum("pb"); /* OK if fails */ 912*7c478bd9Sstevel@tonic-gate for (i=0; speeds[i].string; i++) 913*7c478bd9Sstevel@tonic-gate if (speeds[i].baudrate == PadBaud) { 914*7c478bd9Sstevel@tonic-gate PadBaud = speeds[i].speed; 915*7c478bd9Sstevel@tonic-gate break; 916*7c478bd9Sstevel@tonic-gate } 917*7c478bd9Sstevel@tonic-gate setdelay("dC", CRdelay, CRbits, &modes.c_oflag); 918*7c478bd9Sstevel@tonic-gate setdelay("dN", NLdelay, NLbits, &modes.c_oflag); 919*7c478bd9Sstevel@tonic-gate setdelay("dB", BSdelay, BSbits, &modes.c_oflag); 920*7c478bd9Sstevel@tonic-gate setdelay("dF", FFdelay, FFbits, &modes.c_oflag); 921*7c478bd9Sstevel@tonic-gate setdelay("dT", TBdelay, TBbits, &modes.c_oflag); 922*7c478bd9Sstevel@tonic-gate setdelay("dV", VTdelay, VTbits, &modes.c_oflag); 923*7c478bd9Sstevel@tonic-gate 924*7c478bd9Sstevel@tonic-gate if (tgetflag("UC") || (command[0] & 0140) == 0100) { 925*7c478bd9Sstevel@tonic-gate modes.c_iflag |= IUCLC; 926*7c478bd9Sstevel@tonic-gate modes.c_oflag |= OLCUC; 927*7c478bd9Sstevel@tonic-gate modes.c_cflag |= XCASE; 928*7c478bd9Sstevel@tonic-gate } 929*7c478bd9Sstevel@tonic-gate else if (tgetflag("LC")) { 930*7c478bd9Sstevel@tonic-gate modes.c_iflag &= ~IUCLC; 931*7c478bd9Sstevel@tonic-gate modes.c_oflag &= ~OLCUC; 932*7c478bd9Sstevel@tonic-gate modes.c_cflag &= ~XCASE; 933*7c478bd9Sstevel@tonic-gate } 934*7c478bd9Sstevel@tonic-gate modes.c_iflag &= ~(PARMRK|INPCK); 935*7c478bd9Sstevel@tonic-gate modes.c_lflag |= ICANON; 936*7c478bd9Sstevel@tonic-gate if (tgetflag("EP")) { 937*7c478bd9Sstevel@tonic-gate modes.c_iflag |= INPCK; 938*7c478bd9Sstevel@tonic-gate modes.c_cflag |= PARENB; 939*7c478bd9Sstevel@tonic-gate modes.c_cflag &= ~PARODD; 940*7c478bd9Sstevel@tonic-gate } 941*7c478bd9Sstevel@tonic-gate if (tgetflag("OP")) { 942*7c478bd9Sstevel@tonic-gate modes.c_iflag |= INPCK; 943*7c478bd9Sstevel@tonic-gate modes.c_cflag |= PARENB; 944*7c478bd9Sstevel@tonic-gate modes.c_cflag |= PARODD; 945*7c478bd9Sstevel@tonic-gate } 946*7c478bd9Sstevel@tonic-gate 947*7c478bd9Sstevel@tonic-gate modes.c_oflag |= ONLCR; 948*7c478bd9Sstevel@tonic-gate modes.c_iflag |= ICRNL; 949*7c478bd9Sstevel@tonic-gate modes.c_lflag |= ECHO; 950*7c478bd9Sstevel@tonic-gate modes.c_oflag |= TAB3; 951*7c478bd9Sstevel@tonic-gate if (tgetflag("NL")) { /* new line, not line feed */ 952*7c478bd9Sstevel@tonic-gate modes.c_oflag &= ~ONLCR; 953*7c478bd9Sstevel@tonic-gate modes.c_iflag &= ~ICRNL; 954*7c478bd9Sstevel@tonic-gate } 955*7c478bd9Sstevel@tonic-gate if (tgetflag("HD")) /* half duplex */ 956*7c478bd9Sstevel@tonic-gate modes.c_lflag &= ~ECHO; 957*7c478bd9Sstevel@tonic-gate if (tgetflag("pt")) /* print tabs */ 958*7c478bd9Sstevel@tonic-gate modes.c_oflag &= ~TAB3; 959*7c478bd9Sstevel@tonic-gate 960*7c478bd9Sstevel@tonic-gate modes.c_lflag |= (ECHOE|ECHOK); 961*7c478bd9Sstevel@tonic-gate if (tgetflag("hc")) 962*7c478bd9Sstevel@tonic-gate { /** set printer modes **/ 963*7c478bd9Sstevel@tonic-gate modes.c_lflag &= ~ECHOE; 964*7c478bd9Sstevel@tonic-gate } 965*7c478bd9Sstevel@tonic-gate 966*7c478bd9Sstevel@tonic-gate /* get pad character */ 967*7c478bd9Sstevel@tonic-gate bufp = buf; 968*7c478bd9Sstevel@tonic-gate if (tgetstr("pc", &bufp) != 0) 969*7c478bd9Sstevel@tonic-gate PC = buf[0]; 970*7c478bd9Sstevel@tonic-gate 971*7c478bd9Sstevel@tonic-gate /* output startup string */ 972*7c478bd9Sstevel@tonic-gate if (!NoInit) 973*7c478bd9Sstevel@tonic-gate { 974*7c478bd9Sstevel@tonic-gate if (oldmodes.c_oflag&(TAB3|ONLCR|OCRNL|ONLRET)) 975*7c478bd9Sstevel@tonic-gate { 976*7c478bd9Sstevel@tonic-gate oldmodes.c_oflag &= (TAB3|ONLCR|OCRNL|ONLRET); 977*7c478bd9Sstevel@tonic-gate setmode(-1); 978*7c478bd9Sstevel@tonic-gate } 979*7c478bd9Sstevel@tonic-gate if (settabs()) { 980*7c478bd9Sstevel@tonic-gate settle = YES; 981*7c478bd9Sstevel@tonic-gate flush(); 982*7c478bd9Sstevel@tonic-gate } 983*7c478bd9Sstevel@tonic-gate bufp = buf; 984*7c478bd9Sstevel@tonic-gate if (IsReset && tgetstr("rs", &bufp) != 0 || 985*7c478bd9Sstevel@tonic-gate tgetstr("is", &bufp) != 0) 986*7c478bd9Sstevel@tonic-gate { 987*7c478bd9Sstevel@tonic-gate tputs(buf, 0, prc); 988*7c478bd9Sstevel@tonic-gate settle = YES; 989*7c478bd9Sstevel@tonic-gate flush(); 990*7c478bd9Sstevel@tonic-gate } 991*7c478bd9Sstevel@tonic-gate bufp = buf; 992*7c478bd9Sstevel@tonic-gate if (IsReset && tgetstr("rf", &bufp) != 0 || 993*7c478bd9Sstevel@tonic-gate tgetstr("if", &bufp) != 0) 994*7c478bd9Sstevel@tonic-gate { 995*7c478bd9Sstevel@tonic-gate cat(buf); 996*7c478bd9Sstevel@tonic-gate settle = YES; 997*7c478bd9Sstevel@tonic-gate } 998*7c478bd9Sstevel@tonic-gate if (settle) 999*7c478bd9Sstevel@tonic-gate { 1000*7c478bd9Sstevel@tonic-gate prc('\r'); 1001*7c478bd9Sstevel@tonic-gate if (IsReset) 1002*7c478bd9Sstevel@tonic-gate prc('\n'); /* newline too */ 1003*7c478bd9Sstevel@tonic-gate flush(); 1004*7c478bd9Sstevel@tonic-gate sleep(1); /* let terminal settle down */ 1005*7c478bd9Sstevel@tonic-gate } 1006*7c478bd9Sstevel@tonic-gate } 1007*7c478bd9Sstevel@tonic-gate 1008*7c478bd9Sstevel@tonic-gate setmode(0); /* set new modes, if they've changed */ 1009*7c478bd9Sstevel@tonic-gate 1010*7c478bd9Sstevel@tonic-gate /* set up environment for the shell we are using */ 1011*7c478bd9Sstevel@tonic-gate /* (this code is rather heuristic, checking for $SHELL */ 1012*7c478bd9Sstevel@tonic-gate /* ending in the 3 characters "csh") */ 1013*7c478bd9Sstevel@tonic-gate csh = NO; 1014*7c478bd9Sstevel@tonic-gate if (DoSetenv) 1015*7c478bd9Sstevel@tonic-gate { 1016*7c478bd9Sstevel@tonic-gate char *sh; 1017*7c478bd9Sstevel@tonic-gate 1018*7c478bd9Sstevel@tonic-gate if ((sh = getenv("SHELL")) && (i = strlen(sh)) >= 3) 1019*7c478bd9Sstevel@tonic-gate { 1020*7c478bd9Sstevel@tonic-gate if ((csh = sequal(&sh[i-3], "csh")) && CmndLine) 1021*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "set noglob;\n", 12); 1022*7c478bd9Sstevel@tonic-gate } 1023*7c478bd9Sstevel@tonic-gate if (!csh) 1024*7c478bd9Sstevel@tonic-gate /* running Bourne shell */ 1025*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "export TERMCAP TERM;\n", 21); 1026*7c478bd9Sstevel@tonic-gate } 1027*7c478bd9Sstevel@tonic-gate } 1028*7c478bd9Sstevel@tonic-gate 1029*7c478bd9Sstevel@tonic-gate /* report type if appropriate */ 1030*7c478bd9Sstevel@tonic-gate if (DoSetenv || Report || Ureport) 1031*7c478bd9Sstevel@tonic-gate { 1032*7c478bd9Sstevel@tonic-gate /* if type is the short name, find first alias (if any) */ 1033*7c478bd9Sstevel@tonic-gate makealias(Ttycap); 1034*7c478bd9Sstevel@tonic-gate if (sequal(TtyType, Alias[0]) && Alias[1]) { 1035*7c478bd9Sstevel@tonic-gate TtyType = Alias[1]; 1036*7c478bd9Sstevel@tonic-gate } 1037*7c478bd9Sstevel@tonic-gate 1038*7c478bd9Sstevel@tonic-gate if (DoSetenv) 1039*7c478bd9Sstevel@tonic-gate { 1040*7c478bd9Sstevel@tonic-gate if (csh) 1041*7c478bd9Sstevel@tonic-gate { 1042*7c478bd9Sstevel@tonic-gate if (CmndLine) 1043*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "setenv TERM ", 12); 1044*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, TtyType, strlen(TtyType)); 1045*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, " ", 1); 1046*7c478bd9Sstevel@tonic-gate if (CmndLine) 1047*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, ";\n", 2); 1048*7c478bd9Sstevel@tonic-gate } 1049*7c478bd9Sstevel@tonic-gate else 1050*7c478bd9Sstevel@tonic-gate { 1051*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "TERM=", 5); 1052*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, TtyType, strlen(TtyType)); 1053*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, ";\n", 2); 1054*7c478bd9Sstevel@tonic-gate } 1055*7c478bd9Sstevel@tonic-gate } 1056*7c478bd9Sstevel@tonic-gate else if (Report) 1057*7c478bd9Sstevel@tonic-gate { 1058*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, TtyType, strlen(TtyType)); 1059*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "\n", 1); 1060*7c478bd9Sstevel@tonic-gate } 1061*7c478bd9Sstevel@tonic-gate if (Ureport) 1062*7c478bd9Sstevel@tonic-gate { 1063*7c478bd9Sstevel@tonic-gate prs("Terminal type is "); 1064*7c478bd9Sstevel@tonic-gate prs(TtyType); 1065*7c478bd9Sstevel@tonic-gate prs("\n"); 1066*7c478bd9Sstevel@tonic-gate flush(); 1067*7c478bd9Sstevel@tonic-gate } 1068*7c478bd9Sstevel@tonic-gate 1069*7c478bd9Sstevel@tonic-gate if (DoSetenv) 1070*7c478bd9Sstevel@tonic-gate { 1071*7c478bd9Sstevel@tonic-gate if (csh) 1072*7c478bd9Sstevel@tonic-gate { 1073*7c478bd9Sstevel@tonic-gate if (CmndLine) 1074*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "setenv TERMCAP '", 16); 1075*7c478bd9Sstevel@tonic-gate } 1076*7c478bd9Sstevel@tonic-gate else 1077*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "TERMCAP='", 9); 1078*7c478bd9Sstevel@tonic-gate wrtermcap(Ttycap); 1079*7c478bd9Sstevel@tonic-gate if (csh) 1080*7c478bd9Sstevel@tonic-gate { 1081*7c478bd9Sstevel@tonic-gate if (CmndLine) 1082*7c478bd9Sstevel@tonic-gate { 1083*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "';\n", 3); 1084*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "unset noglob;\n", 14); 1085*7c478bd9Sstevel@tonic-gate } 1086*7c478bd9Sstevel@tonic-gate } 1087*7c478bd9Sstevel@tonic-gate else 1088*7c478bd9Sstevel@tonic-gate (void) write(STDOUT, "';\n", 3); 1089*7c478bd9Sstevel@tonic-gate } 1090*7c478bd9Sstevel@tonic-gate } 1091*7c478bd9Sstevel@tonic-gate 1092*7c478bd9Sstevel@tonic-gate if (RepOnly) 1093*7c478bd9Sstevel@tonic-gate exit(0); 1094*7c478bd9Sstevel@tonic-gate 1095*7c478bd9Sstevel@tonic-gate /* tell about changing erase, kill and interrupt characters */ 1096*7c478bd9Sstevel@tonic-gate reportek("Erase", curerase, olderase, CERASE); 1097*7c478bd9Sstevel@tonic-gate reportek("Kill", curkill, oldkill, CKILL); 1098*7c478bd9Sstevel@tonic-gate reportek("Interrupt", curintr, oldintr, CINTR); 1099*7c478bd9Sstevel@tonic-gate 1100*7c478bd9Sstevel@tonic-gate exit(0); 1101*7c478bd9Sstevel@tonic-gate } 1102*7c478bd9Sstevel@tonic-gate 1103*7c478bd9Sstevel@tonic-gate /* 1104*7c478bd9Sstevel@tonic-gate * Set the hardware tabs on the terminal, using the ct (clear all tabs), 1105*7c478bd9Sstevel@tonic-gate * st (set one tab) and ch (horizontal cursor addressing) capabilities. 1106*7c478bd9Sstevel@tonic-gate * This is done before if and is, so they can patch in case we blow this. 1107*7c478bd9Sstevel@tonic-gate */ 1108*7c478bd9Sstevel@tonic-gate settabs() 1109*7c478bd9Sstevel@tonic-gate { 1110*7c478bd9Sstevel@tonic-gate char caps[100]; 1111*7c478bd9Sstevel@tonic-gate char *capsp = caps; 1112*7c478bd9Sstevel@tonic-gate char *clear_tabs, *set_tab, *set_column, *set_pos; 1113*7c478bd9Sstevel@tonic-gate char *tg_out, *tgoto(); 1114*7c478bd9Sstevel@tonic-gate int c; 1115*7c478bd9Sstevel@tonic-gate extern char *tgetstr(); 1116*7c478bd9Sstevel@tonic-gate int lines, columns; 1117*7c478bd9Sstevel@tonic-gate 1118*7c478bd9Sstevel@tonic-gate clear_tabs = tgetstr("ct", &capsp); 1119*7c478bd9Sstevel@tonic-gate set_tab = tgetstr("st", &capsp); 1120*7c478bd9Sstevel@tonic-gate set_column = tgetstr("ch", &capsp); 1121*7c478bd9Sstevel@tonic-gate if (set_column == 0) 1122*7c478bd9Sstevel@tonic-gate set_pos = tgetstr("cm", &capsp); 1123*7c478bd9Sstevel@tonic-gate 1124*7c478bd9Sstevel@tonic-gate if (clear_tabs && set_tab) { 1125*7c478bd9Sstevel@tonic-gate prc('\r'); /* force to be at left margin */ 1126*7c478bd9Sstevel@tonic-gate tputs(clear_tabs, 0, prc); 1127*7c478bd9Sstevel@tonic-gate } 1128*7c478bd9Sstevel@tonic-gate if (set_tab) { 1129*7c478bd9Sstevel@tonic-gate columns = tgetnum("co"); 1130*7c478bd9Sstevel@tonic-gate lines = tgetnum("li"); 1131*7c478bd9Sstevel@tonic-gate for (c=0; c<columns; c += 8) { 1132*7c478bd9Sstevel@tonic-gate /* get to that column. */ 1133*7c478bd9Sstevel@tonic-gate tg_out = "OOPS"; /* also returned by tgoto */ 1134*7c478bd9Sstevel@tonic-gate if (set_column) 1135*7c478bd9Sstevel@tonic-gate tg_out = tgoto(set_column, 0, c); 1136*7c478bd9Sstevel@tonic-gate if (*tg_out == 'O' && set_pos) 1137*7c478bd9Sstevel@tonic-gate tg_out = tgoto(set_pos, c, lines-1); 1138*7c478bd9Sstevel@tonic-gate if (*tg_out != 'O') 1139*7c478bd9Sstevel@tonic-gate tputs(tg_out, 1, prc); 1140*7c478bd9Sstevel@tonic-gate else if (c != 0) { 1141*7c478bd9Sstevel@tonic-gate prc(' '); prc(' '); prc(' '); prc(' '); 1142*7c478bd9Sstevel@tonic-gate prc(' '); prc(' '); prc(' '); prc(' '); 1143*7c478bd9Sstevel@tonic-gate } 1144*7c478bd9Sstevel@tonic-gate /* set the tab */ 1145*7c478bd9Sstevel@tonic-gate tputs(set_tab, 0, prc); 1146*7c478bd9Sstevel@tonic-gate } 1147*7c478bd9Sstevel@tonic-gate prc('\r'); 1148*7c478bd9Sstevel@tonic-gate return 1; 1149*7c478bd9Sstevel@tonic-gate } 1150*7c478bd9Sstevel@tonic-gate return 0; 1151*7c478bd9Sstevel@tonic-gate } 1152*7c478bd9Sstevel@tonic-gate 1153*7c478bd9Sstevel@tonic-gate void setmode(flag) 1154*7c478bd9Sstevel@tonic-gate int flag; 1155*7c478bd9Sstevel@tonic-gate /* flag serves several purposes: 1156*7c478bd9Sstevel@tonic-gate * if called as the result of a signal, flag will be > 0. 1157*7c478bd9Sstevel@tonic-gate * if called from terminal init, flag == -1 means reset "oldmode". 1158*7c478bd9Sstevel@tonic-gate * called with flag == 0 at end of normal mode processing. 1159*7c478bd9Sstevel@tonic-gate */ 1160*7c478bd9Sstevel@tonic-gate { 1161*7c478bd9Sstevel@tonic-gate struct termio *ttymode; 1162*7c478bd9Sstevel@tonic-gate struct termios *ttymodes; 1163*7c478bd9Sstevel@tonic-gate register int i; 1164*7c478bd9Sstevel@tonic-gate 1165*7c478bd9Sstevel@tonic-gate ttymode = (struct termio *)0; 1166*7c478bd9Sstevel@tonic-gate ttymodes = (struct termios *)0; 1167*7c478bd9Sstevel@tonic-gate 1168*7c478bd9Sstevel@tonic-gate if (flag < 0) { /* unconditionally reset oldmode (called from init) */ 1169*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 1170*7c478bd9Sstevel@tonic-gate oldmode.c_lflag = oldmodes.c_lflag; 1171*7c478bd9Sstevel@tonic-gate oldmode.c_oflag = oldmodes.c_oflag; 1172*7c478bd9Sstevel@tonic-gate oldmode.c_iflag = oldmodes.c_iflag; 1173*7c478bd9Sstevel@tonic-gate oldmode.c_cflag = oldmodes.c_cflag; 1174*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 1175*7c478bd9Sstevel@tonic-gate oldmode.c_cc[i] = oldmodes.c_cc[i]; 1176*7c478bd9Sstevel@tonic-gate ttymode = &oldmode; 1177*7c478bd9Sstevel@tonic-gate } else 1178*7c478bd9Sstevel@tonic-gate ttymodes = &oldmodes; 1179*7c478bd9Sstevel@tonic-gate } else { 1180*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 1181*7c478bd9Sstevel@tonic-gate oldmode.c_lflag = oldmodes.c_lflag; 1182*7c478bd9Sstevel@tonic-gate oldmode.c_oflag = oldmodes.c_oflag; 1183*7c478bd9Sstevel@tonic-gate oldmode.c_iflag = oldmodes.c_iflag; 1184*7c478bd9Sstevel@tonic-gate oldmode.c_cflag = oldmodes.c_cflag; 1185*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 1186*7c478bd9Sstevel@tonic-gate oldmode.c_cc[i] = oldmodes.c_cc[i]; 1187*7c478bd9Sstevel@tonic-gate mode.c_lflag = modes.c_lflag; 1188*7c478bd9Sstevel@tonic-gate mode.c_oflag = modes.c_oflag; 1189*7c478bd9Sstevel@tonic-gate mode.c_iflag = modes.c_iflag; 1190*7c478bd9Sstevel@tonic-gate mode.c_cflag = modes.c_cflag; 1191*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 1192*7c478bd9Sstevel@tonic-gate mode.c_cc[i] = modes.c_cc[i]; 1193*7c478bd9Sstevel@tonic-gate if (!bequal((char *)&mode, (char *)&oldmode, sizeof mode)) 1194*7c478bd9Sstevel@tonic-gate ttymode = &mode; 1195*7c478bd9Sstevel@tonic-gate } else if (!bequal((char *)&modes, (char *)&oldmodes, 1196*7c478bd9Sstevel@tonic-gate sizeof modes)) 1197*7c478bd9Sstevel@tonic-gate ttymodes = &modes; 1198*7c478bd9Sstevel@tonic-gate } 1199*7c478bd9Sstevel@tonic-gate 1200*7c478bd9Sstevel@tonic-gate if (ttymode) 1201*7c478bd9Sstevel@tonic-gate { 1202*7c478bd9Sstevel@tonic-gate (void) ioctl(FILEDES, TCSETAW, (char *)ttymode); 1203*7c478bd9Sstevel@tonic-gate } else if (ttymodes) { 1204*7c478bd9Sstevel@tonic-gate (void) ioctl(FILEDES, TCSETSW, (char *)ttymodes); 1205*7c478bd9Sstevel@tonic-gate } 1206*7c478bd9Sstevel@tonic-gate if (flag > 0) /* trapped signal */ 1207*7c478bd9Sstevel@tonic-gate exit(1); 1208*7c478bd9Sstevel@tonic-gate } 1209*7c478bd9Sstevel@tonic-gate 1210*7c478bd9Sstevel@tonic-gate reportek(name, new, old, def) 1211*7c478bd9Sstevel@tonic-gate char *name; 1212*7c478bd9Sstevel@tonic-gate char old; 1213*7c478bd9Sstevel@tonic-gate char new; 1214*7c478bd9Sstevel@tonic-gate char def; 1215*7c478bd9Sstevel@tonic-gate { 1216*7c478bd9Sstevel@tonic-gate register char o; 1217*7c478bd9Sstevel@tonic-gate register char n; 1218*7c478bd9Sstevel@tonic-gate register char *p; 1219*7c478bd9Sstevel@tonic-gate char buf[32]; 1220*7c478bd9Sstevel@tonic-gate char *bufp; 1221*7c478bd9Sstevel@tonic-gate extern char *tgetstr(); 1222*7c478bd9Sstevel@tonic-gate 1223*7c478bd9Sstevel@tonic-gate if (BeQuiet) 1224*7c478bd9Sstevel@tonic-gate return; 1225*7c478bd9Sstevel@tonic-gate o = old; 1226*7c478bd9Sstevel@tonic-gate n = new; 1227*7c478bd9Sstevel@tonic-gate 1228*7c478bd9Sstevel@tonic-gate if (o == n && n == def) 1229*7c478bd9Sstevel@tonic-gate return; 1230*7c478bd9Sstevel@tonic-gate prs(name); 1231*7c478bd9Sstevel@tonic-gate if (o == n) 1232*7c478bd9Sstevel@tonic-gate prs(" is "); 1233*7c478bd9Sstevel@tonic-gate else 1234*7c478bd9Sstevel@tonic-gate prs(" set to "); 1235*7c478bd9Sstevel@tonic-gate bufp = buf; 1236*7c478bd9Sstevel@tonic-gate if (tgetstr("kb", &bufp) > (char *)0 && n == buf[0] && buf[1] == NULL) 1237*7c478bd9Sstevel@tonic-gate prs("Backspace\n"); 1238*7c478bd9Sstevel@tonic-gate else if (n == 0177) 1239*7c478bd9Sstevel@tonic-gate prs("Delete\n"); 1240*7c478bd9Sstevel@tonic-gate else 1241*7c478bd9Sstevel@tonic-gate { 1242*7c478bd9Sstevel@tonic-gate if (n < 040) 1243*7c478bd9Sstevel@tonic-gate { 1244*7c478bd9Sstevel@tonic-gate prs("Ctrl-"); 1245*7c478bd9Sstevel@tonic-gate n ^= 0100; 1246*7c478bd9Sstevel@tonic-gate } 1247*7c478bd9Sstevel@tonic-gate p = "x\n"; 1248*7c478bd9Sstevel@tonic-gate p[0] = n; 1249*7c478bd9Sstevel@tonic-gate prs(p); 1250*7c478bd9Sstevel@tonic-gate } 1251*7c478bd9Sstevel@tonic-gate flush(); 1252*7c478bd9Sstevel@tonic-gate } 1253*7c478bd9Sstevel@tonic-gate 1254*7c478bd9Sstevel@tonic-gate 1255*7c478bd9Sstevel@tonic-gate 1256*7c478bd9Sstevel@tonic-gate 1257*7c478bd9Sstevel@tonic-gate setdelay(cap, dtab, bits, flags) 1258*7c478bd9Sstevel@tonic-gate char *cap; 1259*7c478bd9Sstevel@tonic-gate struct delay dtab[]; 1260*7c478bd9Sstevel@tonic-gate int bits; 1261*7c478bd9Sstevel@tonic-gate short *flags; 1262*7c478bd9Sstevel@tonic-gate { 1263*7c478bd9Sstevel@tonic-gate register int i; 1264*7c478bd9Sstevel@tonic-gate register struct delay *p; 1265*7c478bd9Sstevel@tonic-gate extern short ospeed; 1266*7c478bd9Sstevel@tonic-gate 1267*7c478bd9Sstevel@tonic-gate /* see if this capability exists at all */ 1268*7c478bd9Sstevel@tonic-gate i = tgetnum(cap); 1269*7c478bd9Sstevel@tonic-gate if (i < 0) 1270*7c478bd9Sstevel@tonic-gate i = 0; 1271*7c478bd9Sstevel@tonic-gate /* No padding at speeds below PadBaud */ 1272*7c478bd9Sstevel@tonic-gate if (PadBaud > ospeed) 1273*7c478bd9Sstevel@tonic-gate i = 0; 1274*7c478bd9Sstevel@tonic-gate 1275*7c478bd9Sstevel@tonic-gate /* clear out the bits, replace with new ones */ 1276*7c478bd9Sstevel@tonic-gate *flags &= ~bits; 1277*7c478bd9Sstevel@tonic-gate 1278*7c478bd9Sstevel@tonic-gate /* scan dtab for first entry with adequate delay */ 1279*7c478bd9Sstevel@tonic-gate for (p = dtab; p->d_delay >= 0; p++) 1280*7c478bd9Sstevel@tonic-gate { 1281*7c478bd9Sstevel@tonic-gate if (p->d_delay >= i) 1282*7c478bd9Sstevel@tonic-gate { 1283*7c478bd9Sstevel@tonic-gate p++; 1284*7c478bd9Sstevel@tonic-gate break; 1285*7c478bd9Sstevel@tonic-gate } 1286*7c478bd9Sstevel@tonic-gate } 1287*7c478bd9Sstevel@tonic-gate 1288*7c478bd9Sstevel@tonic-gate /* use last entry if none will do */ 1289*7c478bd9Sstevel@tonic-gate *flags |= (--p)->d_bits; 1290*7c478bd9Sstevel@tonic-gate } 1291*7c478bd9Sstevel@tonic-gate 1292*7c478bd9Sstevel@tonic-gate 1293*7c478bd9Sstevel@tonic-gate prs(s) 1294*7c478bd9Sstevel@tonic-gate char *s; 1295*7c478bd9Sstevel@tonic-gate { 1296*7c478bd9Sstevel@tonic-gate while (*s != '\0') 1297*7c478bd9Sstevel@tonic-gate prc(*s++); 1298*7c478bd9Sstevel@tonic-gate } 1299*7c478bd9Sstevel@tonic-gate 1300*7c478bd9Sstevel@tonic-gate 1301*7c478bd9Sstevel@tonic-gate char OutBuf[256]; 1302*7c478bd9Sstevel@tonic-gate int OutPtr; 1303*7c478bd9Sstevel@tonic-gate 1304*7c478bd9Sstevel@tonic-gate prc(c) 1305*7c478bd9Sstevel@tonic-gate char c; 1306*7c478bd9Sstevel@tonic-gate { 1307*7c478bd9Sstevel@tonic-gate OutBuf[OutPtr++] = c; 1308*7c478bd9Sstevel@tonic-gate if (OutPtr >= sizeof OutBuf) 1309*7c478bd9Sstevel@tonic-gate flush(); 1310*7c478bd9Sstevel@tonic-gate } 1311*7c478bd9Sstevel@tonic-gate 1312*7c478bd9Sstevel@tonic-gate flush() 1313*7c478bd9Sstevel@tonic-gate { 1314*7c478bd9Sstevel@tonic-gate if (OutPtr > 0) 1315*7c478bd9Sstevel@tonic-gate (void) write(2, OutBuf, OutPtr); 1316*7c478bd9Sstevel@tonic-gate OutPtr = 0; 1317*7c478bd9Sstevel@tonic-gate } 1318*7c478bd9Sstevel@tonic-gate 1319*7c478bd9Sstevel@tonic-gate 1320*7c478bd9Sstevel@tonic-gate cat(file) 1321*7c478bd9Sstevel@tonic-gate char *file; 1322*7c478bd9Sstevel@tonic-gate { 1323*7c478bd9Sstevel@tonic-gate register int fd; 1324*7c478bd9Sstevel@tonic-gate register int i; 1325*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 1326*7c478bd9Sstevel@tonic-gate 1327*7c478bd9Sstevel@tonic-gate fd = open(file, 0); 1328*7c478bd9Sstevel@tonic-gate if (fd < 0) 1329*7c478bd9Sstevel@tonic-gate { 1330*7c478bd9Sstevel@tonic-gate prs("Cannot open "); 1331*7c478bd9Sstevel@tonic-gate prs(file); 1332*7c478bd9Sstevel@tonic-gate prs("\n"); 1333*7c478bd9Sstevel@tonic-gate flush(); 1334*7c478bd9Sstevel@tonic-gate return; 1335*7c478bd9Sstevel@tonic-gate } 1336*7c478bd9Sstevel@tonic-gate 1337*7c478bd9Sstevel@tonic-gate while ((i = read(fd, buf, BUFSIZ)) > 0) 1338*7c478bd9Sstevel@tonic-gate (void) write(FILEDES, buf, i); 1339*7c478bd9Sstevel@tonic-gate 1340*7c478bd9Sstevel@tonic-gate (void) close(fd); 1341*7c478bd9Sstevel@tonic-gate } 1342*7c478bd9Sstevel@tonic-gate 1343*7c478bd9Sstevel@tonic-gate 1344*7c478bd9Sstevel@tonic-gate 1345*7c478bd9Sstevel@tonic-gate bmove(from, to, length) 1346*7c478bd9Sstevel@tonic-gate char *from; 1347*7c478bd9Sstevel@tonic-gate char *to; 1348*7c478bd9Sstevel@tonic-gate int length; 1349*7c478bd9Sstevel@tonic-gate { 1350*7c478bd9Sstevel@tonic-gate register char *p, *q; 1351*7c478bd9Sstevel@tonic-gate register int i; 1352*7c478bd9Sstevel@tonic-gate 1353*7c478bd9Sstevel@tonic-gate i = length; 1354*7c478bd9Sstevel@tonic-gate p = from; 1355*7c478bd9Sstevel@tonic-gate q = to; 1356*7c478bd9Sstevel@tonic-gate 1357*7c478bd9Sstevel@tonic-gate while (i-- > 0) 1358*7c478bd9Sstevel@tonic-gate *q++ = *p++; 1359*7c478bd9Sstevel@tonic-gate } 1360*7c478bd9Sstevel@tonic-gate 1361*7c478bd9Sstevel@tonic-gate 1362*7c478bd9Sstevel@tonic-gate 1363*7c478bd9Sstevel@tonic-gate bequal(a, b, len) /* must be same thru len chars */ 1364*7c478bd9Sstevel@tonic-gate char *a; 1365*7c478bd9Sstevel@tonic-gate char *b; 1366*7c478bd9Sstevel@tonic-gate int len; 1367*7c478bd9Sstevel@tonic-gate { 1368*7c478bd9Sstevel@tonic-gate register char *p, *q; 1369*7c478bd9Sstevel@tonic-gate register int i; 1370*7c478bd9Sstevel@tonic-gate 1371*7c478bd9Sstevel@tonic-gate i = len; 1372*7c478bd9Sstevel@tonic-gate p = a; 1373*7c478bd9Sstevel@tonic-gate q = b; 1374*7c478bd9Sstevel@tonic-gate 1375*7c478bd9Sstevel@tonic-gate while ((*p == *q) && --i > 0) 1376*7c478bd9Sstevel@tonic-gate { 1377*7c478bd9Sstevel@tonic-gate p++; q++; 1378*7c478bd9Sstevel@tonic-gate } 1379*7c478bd9Sstevel@tonic-gate return ((*p == *q) && i >= 0); 1380*7c478bd9Sstevel@tonic-gate } 1381*7c478bd9Sstevel@tonic-gate 1382*7c478bd9Sstevel@tonic-gate sequal(a, b) /* must be same thru NULL */ 1383*7c478bd9Sstevel@tonic-gate char *a; 1384*7c478bd9Sstevel@tonic-gate char *b; 1385*7c478bd9Sstevel@tonic-gate { 1386*7c478bd9Sstevel@tonic-gate register char *p = a, *q = b; 1387*7c478bd9Sstevel@tonic-gate 1388*7c478bd9Sstevel@tonic-gate while (*p && *q && (*p == *q)) 1389*7c478bd9Sstevel@tonic-gate { 1390*7c478bd9Sstevel@tonic-gate p++; q++; 1391*7c478bd9Sstevel@tonic-gate } 1392*7c478bd9Sstevel@tonic-gate return (*p == *q); 1393*7c478bd9Sstevel@tonic-gate } 1394*7c478bd9Sstevel@tonic-gate 1395*7c478bd9Sstevel@tonic-gate makealias(buf) 1396*7c478bd9Sstevel@tonic-gate char *buf; 1397*7c478bd9Sstevel@tonic-gate { 1398*7c478bd9Sstevel@tonic-gate register int i; 1399*7c478bd9Sstevel@tonic-gate register char *a; 1400*7c478bd9Sstevel@tonic-gate register char *b; 1401*7c478bd9Sstevel@tonic-gate 1402*7c478bd9Sstevel@tonic-gate Alias[0] = a = Aliasbuf; 1403*7c478bd9Sstevel@tonic-gate b = buf; 1404*7c478bd9Sstevel@tonic-gate i = 1; 1405*7c478bd9Sstevel@tonic-gate while (*b && *b != ':') { 1406*7c478bd9Sstevel@tonic-gate if (*b == '|') { 1407*7c478bd9Sstevel@tonic-gate *a++ = NULL; 1408*7c478bd9Sstevel@tonic-gate Alias[i++] = a; 1409*7c478bd9Sstevel@tonic-gate b++; 1410*7c478bd9Sstevel@tonic-gate } 1411*7c478bd9Sstevel@tonic-gate else 1412*7c478bd9Sstevel@tonic-gate *a++ = *b++; 1413*7c478bd9Sstevel@tonic-gate } 1414*7c478bd9Sstevel@tonic-gate *a = NULL; 1415*7c478bd9Sstevel@tonic-gate Alias[i] = NULL; 1416*7c478bd9Sstevel@tonic-gate # ifdef DEB 1417*7c478bd9Sstevel@tonic-gate for(i = 0; Alias[i]; printf("A:%s\n", Alias[i++])); 1418*7c478bd9Sstevel@tonic-gate # endif 1419*7c478bd9Sstevel@tonic-gate } 1420*7c478bd9Sstevel@tonic-gate 1421*7c478bd9Sstevel@tonic-gate isalias(ident) /* is ident same as one of the aliases? */ 1422*7c478bd9Sstevel@tonic-gate char *ident; 1423*7c478bd9Sstevel@tonic-gate { 1424*7c478bd9Sstevel@tonic-gate char **a = Alias; 1425*7c478bd9Sstevel@tonic-gate 1426*7c478bd9Sstevel@tonic-gate if (*a) 1427*7c478bd9Sstevel@tonic-gate while (*a) 1428*7c478bd9Sstevel@tonic-gate if (sequal(ident, *a)) 1429*7c478bd9Sstevel@tonic-gate return(YES); 1430*7c478bd9Sstevel@tonic-gate else 1431*7c478bd9Sstevel@tonic-gate a++; 1432*7c478bd9Sstevel@tonic-gate return(NO); 1433*7c478bd9Sstevel@tonic-gate } 1434*7c478bd9Sstevel@tonic-gate 1435*7c478bd9Sstevel@tonic-gate 1436*7c478bd9Sstevel@tonic-gate /* 1437*7c478bd9Sstevel@tonic-gate * routine to output the string for the environment TERMCAP variable 1438*7c478bd9Sstevel@tonic-gate */ 1439*7c478bd9Sstevel@tonic-gate #define WHITE(c) (c == ' ' || c == '\t') 1440*7c478bd9Sstevel@tonic-gate char delcap[128][2]; 1441*7c478bd9Sstevel@tonic-gate int ncap = 0; 1442*7c478bd9Sstevel@tonic-gate 1443*7c478bd9Sstevel@tonic-gate wrtermcap(bp) 1444*7c478bd9Sstevel@tonic-gate char *bp; 1445*7c478bd9Sstevel@tonic-gate { 1446*7c478bd9Sstevel@tonic-gate char buf[CAPBUFSIZ]; 1447*7c478bd9Sstevel@tonic-gate char *p = buf; 1448*7c478bd9Sstevel@tonic-gate char *tp; 1449*7c478bd9Sstevel@tonic-gate char *putbuf(); 1450*7c478bd9Sstevel@tonic-gate int space, empty; 1451*7c478bd9Sstevel@tonic-gate 1452*7c478bd9Sstevel@tonic-gate /* discard names with blanks */ 1453*7c478bd9Sstevel@tonic-gate /** May not be desireable ? **/ 1454*7c478bd9Sstevel@tonic-gate while (*bp && *bp != ':') { 1455*7c478bd9Sstevel@tonic-gate if (*bp == '|') { 1456*7c478bd9Sstevel@tonic-gate tp = bp+1; 1457*7c478bd9Sstevel@tonic-gate space = NO; 1458*7c478bd9Sstevel@tonic-gate while (*tp && *tp != '|' && *tp != ':') { 1459*7c478bd9Sstevel@tonic-gate space = (space || WHITE(*tp) ); 1460*7c478bd9Sstevel@tonic-gate tp++; 1461*7c478bd9Sstevel@tonic-gate } 1462*7c478bd9Sstevel@tonic-gate if (space) { 1463*7c478bd9Sstevel@tonic-gate bp = tp; 1464*7c478bd9Sstevel@tonic-gate continue; 1465*7c478bd9Sstevel@tonic-gate } 1466*7c478bd9Sstevel@tonic-gate } 1467*7c478bd9Sstevel@tonic-gate *p++ = *bp++; 1468*7c478bd9Sstevel@tonic-gate } 1469*7c478bd9Sstevel@tonic-gate /**/ 1470*7c478bd9Sstevel@tonic-gate 1471*7c478bd9Sstevel@tonic-gate while (*bp) { 1472*7c478bd9Sstevel@tonic-gate switch (*bp) { 1473*7c478bd9Sstevel@tonic-gate case ':': /* discard empty, cancelled or dupl fields */ 1474*7c478bd9Sstevel@tonic-gate tp = bp+1; 1475*7c478bd9Sstevel@tonic-gate empty = YES; 1476*7c478bd9Sstevel@tonic-gate while (*tp && *tp != ':') { 1477*7c478bd9Sstevel@tonic-gate empty = (empty && WHITE(*tp) ); 1478*7c478bd9Sstevel@tonic-gate tp++; 1479*7c478bd9Sstevel@tonic-gate } 1480*7c478bd9Sstevel@tonic-gate if (empty || cancelled(bp+1)) { 1481*7c478bd9Sstevel@tonic-gate bp = tp; 1482*7c478bd9Sstevel@tonic-gate continue; 1483*7c478bd9Sstevel@tonic-gate } 1484*7c478bd9Sstevel@tonic-gate break; 1485*7c478bd9Sstevel@tonic-gate 1486*7c478bd9Sstevel@tonic-gate case ' ': /* no spaces in output */ 1487*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\040"); 1488*7c478bd9Sstevel@tonic-gate bp++; 1489*7c478bd9Sstevel@tonic-gate continue; 1490*7c478bd9Sstevel@tonic-gate 1491*7c478bd9Sstevel@tonic-gate case '!': /* the shell thinks this is history */ 1492*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\041"); 1493*7c478bd9Sstevel@tonic-gate bp++; 1494*7c478bd9Sstevel@tonic-gate continue; 1495*7c478bd9Sstevel@tonic-gate 1496*7c478bd9Sstevel@tonic-gate case ',': /* the shell thinks this is history */ 1497*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\054"); 1498*7c478bd9Sstevel@tonic-gate bp++; 1499*7c478bd9Sstevel@tonic-gate continue; 1500*7c478bd9Sstevel@tonic-gate 1501*7c478bd9Sstevel@tonic-gate case '"': /* no quotes in output */ 1502*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\042"); 1503*7c478bd9Sstevel@tonic-gate bp++; 1504*7c478bd9Sstevel@tonic-gate continue; 1505*7c478bd9Sstevel@tonic-gate 1506*7c478bd9Sstevel@tonic-gate case '\'': /* no quotes in output */ 1507*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\047"); 1508*7c478bd9Sstevel@tonic-gate bp++; 1509*7c478bd9Sstevel@tonic-gate continue; 1510*7c478bd9Sstevel@tonic-gate 1511*7c478bd9Sstevel@tonic-gate case '`': /* no back quotes in output */ 1512*7c478bd9Sstevel@tonic-gate p = putbuf(p, "\\140"); 1513*7c478bd9Sstevel@tonic-gate bp++; 1514*7c478bd9Sstevel@tonic-gate continue; 1515*7c478bd9Sstevel@tonic-gate 1516*7c478bd9Sstevel@tonic-gate case '\\': 1517*7c478bd9Sstevel@tonic-gate case '^': /* anything following is OK */ 1518*7c478bd9Sstevel@tonic-gate *p++ = *bp++; 1519*7c478bd9Sstevel@tonic-gate } 1520*7c478bd9Sstevel@tonic-gate *p++ = *bp++; 1521*7c478bd9Sstevel@tonic-gate } 1522*7c478bd9Sstevel@tonic-gate *p++ = ':'; /* we skipped the last : with the : lookahead hack */ 1523*7c478bd9Sstevel@tonic-gate (void) write (STDOUT, buf, p-buf); 1524*7c478bd9Sstevel@tonic-gate } 1525*7c478bd9Sstevel@tonic-gate 1526*7c478bd9Sstevel@tonic-gate cancelled(cap) 1527*7c478bd9Sstevel@tonic-gate char *cap; 1528*7c478bd9Sstevel@tonic-gate { 1529*7c478bd9Sstevel@tonic-gate register int i; 1530*7c478bd9Sstevel@tonic-gate 1531*7c478bd9Sstevel@tonic-gate for (i = 0; i < ncap; i++) 1532*7c478bd9Sstevel@tonic-gate { 1533*7c478bd9Sstevel@tonic-gate if (cap[0] == delcap[i][0] && cap[1] == delcap[i][1]) 1534*7c478bd9Sstevel@tonic-gate return (YES); 1535*7c478bd9Sstevel@tonic-gate } 1536*7c478bd9Sstevel@tonic-gate /* delete a second occurrance of the same capability */ 1537*7c478bd9Sstevel@tonic-gate delcap[ncap][0] = cap[0]; 1538*7c478bd9Sstevel@tonic-gate delcap[ncap][1] = cap[1]; 1539*7c478bd9Sstevel@tonic-gate ncap++; 1540*7c478bd9Sstevel@tonic-gate return (cap[2] == '@'); 1541*7c478bd9Sstevel@tonic-gate } 1542*7c478bd9Sstevel@tonic-gate 1543*7c478bd9Sstevel@tonic-gate char * 1544*7c478bd9Sstevel@tonic-gate putbuf(ptr, str) 1545*7c478bd9Sstevel@tonic-gate char *ptr; 1546*7c478bd9Sstevel@tonic-gate char *str; 1547*7c478bd9Sstevel@tonic-gate { 1548*7c478bd9Sstevel@tonic-gate char buf[20]; 1549*7c478bd9Sstevel@tonic-gate 1550*7c478bd9Sstevel@tonic-gate while (*str) { 1551*7c478bd9Sstevel@tonic-gate switch (*str) { 1552*7c478bd9Sstevel@tonic-gate case '\033': 1553*7c478bd9Sstevel@tonic-gate ptr = putbuf(ptr, "\\E"); 1554*7c478bd9Sstevel@tonic-gate str++; 1555*7c478bd9Sstevel@tonic-gate break; 1556*7c478bd9Sstevel@tonic-gate default: 1557*7c478bd9Sstevel@tonic-gate if (*str <= ' ') { 1558*7c478bd9Sstevel@tonic-gate (void) sprintf(buf, "\\%03o", *str); 1559*7c478bd9Sstevel@tonic-gate ptr = putbuf(ptr, buf); 1560*7c478bd9Sstevel@tonic-gate str++; 1561*7c478bd9Sstevel@tonic-gate } else 1562*7c478bd9Sstevel@tonic-gate *ptr++ = *str++; 1563*7c478bd9Sstevel@tonic-gate } 1564*7c478bd9Sstevel@tonic-gate } 1565*7c478bd9Sstevel@tonic-gate return (ptr); 1566*7c478bd9Sstevel@tonic-gate } 1567*7c478bd9Sstevel@tonic-gate 1568*7c478bd9Sstevel@tonic-gate 1569*7c478bd9Sstevel@tonic-gate baudrate(p) 1570*7c478bd9Sstevel@tonic-gate char *p; 1571*7c478bd9Sstevel@tonic-gate { 1572*7c478bd9Sstevel@tonic-gate char buf[8]; 1573*7c478bd9Sstevel@tonic-gate int i = 0; 1574*7c478bd9Sstevel@tonic-gate 1575*7c478bd9Sstevel@tonic-gate while (i < 7 && (isalnum(*p) || *p == '.')) 1576*7c478bd9Sstevel@tonic-gate buf[i++] = *p++; 1577*7c478bd9Sstevel@tonic-gate buf[i] = NULL; 1578*7c478bd9Sstevel@tonic-gate for (i=0; speeds[i].string; i++) 1579*7c478bd9Sstevel@tonic-gate if (sequal(speeds[i].string, buf)) 1580*7c478bd9Sstevel@tonic-gate return (speeds[i].speed); 1581*7c478bd9Sstevel@tonic-gate return (-1); 1582*7c478bd9Sstevel@tonic-gate } 1583*7c478bd9Sstevel@tonic-gate 1584*7c478bd9Sstevel@tonic-gate char * 1585*7c478bd9Sstevel@tonic-gate mapped(type) 1586*7c478bd9Sstevel@tonic-gate char *type; 1587*7c478bd9Sstevel@tonic-gate { 1588*7c478bd9Sstevel@tonic-gate extern short ospeed; 1589*7c478bd9Sstevel@tonic-gate int match; 1590*7c478bd9Sstevel@tonic-gate 1591*7c478bd9Sstevel@tonic-gate # ifdef DEB 1592*7c478bd9Sstevel@tonic-gate printf ("spd:%d\n", ospeed); 1593*7c478bd9Sstevel@tonic-gate prmap(); 1594*7c478bd9Sstevel@tonic-gate # endif 1595*7c478bd9Sstevel@tonic-gate Map = map; 1596*7c478bd9Sstevel@tonic-gate while (Map->Ident) 1597*7c478bd9Sstevel@tonic-gate { 1598*7c478bd9Sstevel@tonic-gate if (*(Map->Ident) == NULL || sequal(Map->Ident, type) || isalias(Map->Ident)) 1599*7c478bd9Sstevel@tonic-gate { 1600*7c478bd9Sstevel@tonic-gate match = NO; 1601*7c478bd9Sstevel@tonic-gate switch (Map->Test) 1602*7c478bd9Sstevel@tonic-gate { 1603*7c478bd9Sstevel@tonic-gate case ANY: /* no test specified */ 1604*7c478bd9Sstevel@tonic-gate case ALL: 1605*7c478bd9Sstevel@tonic-gate match = YES; 1606*7c478bd9Sstevel@tonic-gate break; 1607*7c478bd9Sstevel@tonic-gate 1608*7c478bd9Sstevel@tonic-gate case GT: 1609*7c478bd9Sstevel@tonic-gate match = (ospeed > Map->Speed); 1610*7c478bd9Sstevel@tonic-gate break; 1611*7c478bd9Sstevel@tonic-gate 1612*7c478bd9Sstevel@tonic-gate case GE: 1613*7c478bd9Sstevel@tonic-gate match = (ospeed >= Map->Speed); 1614*7c478bd9Sstevel@tonic-gate break; 1615*7c478bd9Sstevel@tonic-gate 1616*7c478bd9Sstevel@tonic-gate case EQ: 1617*7c478bd9Sstevel@tonic-gate match = (ospeed == Map->Speed); 1618*7c478bd9Sstevel@tonic-gate break; 1619*7c478bd9Sstevel@tonic-gate 1620*7c478bd9Sstevel@tonic-gate case LE: 1621*7c478bd9Sstevel@tonic-gate match = (ospeed <= Map->Speed); 1622*7c478bd9Sstevel@tonic-gate break; 1623*7c478bd9Sstevel@tonic-gate 1624*7c478bd9Sstevel@tonic-gate case LT: 1625*7c478bd9Sstevel@tonic-gate match = (ospeed < Map->Speed); 1626*7c478bd9Sstevel@tonic-gate break; 1627*7c478bd9Sstevel@tonic-gate 1628*7c478bd9Sstevel@tonic-gate case NE: 1629*7c478bd9Sstevel@tonic-gate match = (ospeed != Map->Speed); 1630*7c478bd9Sstevel@tonic-gate break; 1631*7c478bd9Sstevel@tonic-gate } 1632*7c478bd9Sstevel@tonic-gate if (match) 1633*7c478bd9Sstevel@tonic-gate return (Map->Type); 1634*7c478bd9Sstevel@tonic-gate } 1635*7c478bd9Sstevel@tonic-gate Map++; 1636*7c478bd9Sstevel@tonic-gate } 1637*7c478bd9Sstevel@tonic-gate /* no match found; return given type */ 1638*7c478bd9Sstevel@tonic-gate return (type); 1639*7c478bd9Sstevel@tonic-gate } 1640*7c478bd9Sstevel@tonic-gate 1641*7c478bd9Sstevel@tonic-gate # ifdef DEB 1642*7c478bd9Sstevel@tonic-gate prmap() 1643*7c478bd9Sstevel@tonic-gate { 1644*7c478bd9Sstevel@tonic-gate Map = map; 1645*7c478bd9Sstevel@tonic-gate while (Map->Ident) 1646*7c478bd9Sstevel@tonic-gate { 1647*7c478bd9Sstevel@tonic-gate printf ("%s t:%d s:%d %s\n", 1648*7c478bd9Sstevel@tonic-gate Map->Ident, Map->Test, Map->Speed, Map->Type); 1649*7c478bd9Sstevel@tonic-gate Map++; 1650*7c478bd9Sstevel@tonic-gate } 1651*7c478bd9Sstevel@tonic-gate } 1652*7c478bd9Sstevel@tonic-gate # endif 1653*7c478bd9Sstevel@tonic-gate 1654*7c478bd9Sstevel@tonic-gate char * 1655*7c478bd9Sstevel@tonic-gate nextarg(argc, argv) 1656*7c478bd9Sstevel@tonic-gate int argc; 1657*7c478bd9Sstevel@tonic-gate char *argv[]; 1658*7c478bd9Sstevel@tonic-gate { 1659*7c478bd9Sstevel@tonic-gate if (argc <= 0) 1660*7c478bd9Sstevel@tonic-gate fatal ("Too few args: ", *argv); 1661*7c478bd9Sstevel@tonic-gate if (*(*++argv) == '-') 1662*7c478bd9Sstevel@tonic-gate fatal ("Unexpected arg: ", *argv); 1663*7c478bd9Sstevel@tonic-gate return (*argv); 1664*7c478bd9Sstevel@tonic-gate } 1665*7c478bd9Sstevel@tonic-gate 1666*7c478bd9Sstevel@tonic-gate fatal (mesg, obj) 1667*7c478bd9Sstevel@tonic-gate char *mesg; 1668*7c478bd9Sstevel@tonic-gate char *obj; 1669*7c478bd9Sstevel@tonic-gate { 1670*7c478bd9Sstevel@tonic-gate prs (mesg); 1671*7c478bd9Sstevel@tonic-gate prs (obj); 1672*7c478bd9Sstevel@tonic-gate prc ('\n'); 1673*7c478bd9Sstevel@tonic-gate prs (USAGE); 1674*7c478bd9Sstevel@tonic-gate flush(); 1675*7c478bd9Sstevel@tonic-gate exit(1); 1676*7c478bd9Sstevel@tonic-gate } 1677*7c478bd9Sstevel@tonic-gate 1678*7c478bd9Sstevel@tonic-gate 1679*7c478bd9Sstevel@tonic-gate /* 1680*7c478bd9Sstevel@tonic-gate * Stolen from /usr/src/ucb/reset.c, which this mod obsoletes. 1681*7c478bd9Sstevel@tonic-gate */ 1682*7c478bd9Sstevel@tonic-gate char 1683*7c478bd9Sstevel@tonic-gate reset(ch, def) 1684*7c478bd9Sstevel@tonic-gate char ch; 1685*7c478bd9Sstevel@tonic-gate int def; 1686*7c478bd9Sstevel@tonic-gate { 1687*7c478bd9Sstevel@tonic-gate 1688*7c478bd9Sstevel@tonic-gate if (ch == 0 || (ch&0377) == 0377) 1689*7c478bd9Sstevel@tonic-gate return def; 1690*7c478bd9Sstevel@tonic-gate return ch; 1691*7c478bd9Sstevel@tonic-gate } 1692