xref: /titanic_53/usr/src/cmd/bnu/line.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1995 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /* This is a new line.c, which consists of line.c and culine.c
34*7c478bd9Sstevel@tonic-gate  * merged together.
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include "uucp.h"
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate static struct sg_spds {
40*7c478bd9Sstevel@tonic-gate 	int	sp_val,
41*7c478bd9Sstevel@tonic-gate 		sp_name;
42*7c478bd9Sstevel@tonic-gate } spds[] = {
43*7c478bd9Sstevel@tonic-gate 	{  50,   B50},
44*7c478bd9Sstevel@tonic-gate 	{  75,   B75},
45*7c478bd9Sstevel@tonic-gate 	{ 110,  B110},
46*7c478bd9Sstevel@tonic-gate 	{ 134,  B134},
47*7c478bd9Sstevel@tonic-gate 	{ 150,  B150},
48*7c478bd9Sstevel@tonic-gate 	{ 200,  B200},
49*7c478bd9Sstevel@tonic-gate 	{ 300,  B300},
50*7c478bd9Sstevel@tonic-gate 	{ 600,  B600},
51*7c478bd9Sstevel@tonic-gate 	{1200, B1200},
52*7c478bd9Sstevel@tonic-gate 	{1800, B1800},
53*7c478bd9Sstevel@tonic-gate 	{2400, B2400},
54*7c478bd9Sstevel@tonic-gate 	{4800, B4800},
55*7c478bd9Sstevel@tonic-gate 	{9600, B9600},
56*7c478bd9Sstevel@tonic-gate #ifdef EXTA
57*7c478bd9Sstevel@tonic-gate 	{19200,	EXTA},
58*7c478bd9Sstevel@tonic-gate #endif
59*7c478bd9Sstevel@tonic-gate #ifdef B19200
60*7c478bd9Sstevel@tonic-gate 	{19200,	B19200},
61*7c478bd9Sstevel@tonic-gate #endif
62*7c478bd9Sstevel@tonic-gate #ifdef B38400
63*7c478bd9Sstevel@tonic-gate 	{38400,	B38400},
64*7c478bd9Sstevel@tonic-gate #endif
65*7c478bd9Sstevel@tonic-gate 	{57600, B57600},
66*7c478bd9Sstevel@tonic-gate 	{76800, B76800},
67*7c478bd9Sstevel@tonic-gate 	{115200, B115200},
68*7c478bd9Sstevel@tonic-gate 	{153600, B153600},
69*7c478bd9Sstevel@tonic-gate 	{230400, B230400},
70*7c478bd9Sstevel@tonic-gate 	{307200, B307200},
71*7c478bd9Sstevel@tonic-gate 	{460800, B460800},
72*7c478bd9Sstevel@tonic-gate 	{0,    0}
73*7c478bd9Sstevel@tonic-gate };
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate #define PACKSIZE	64
76*7c478bd9Sstevel@tonic-gate #define HEADERSIZE	6
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate GLOBAL int
79*7c478bd9Sstevel@tonic-gate      packsize = PACKSIZE,
80*7c478bd9Sstevel@tonic-gate     xpacksize = PACKSIZE;
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate #define SNDFILE	'S'
83*7c478bd9Sstevel@tonic-gate #define RCVFILE 'R'
84*7c478bd9Sstevel@tonic-gate #define RESET	'X'
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate #ifdef PKSPEEDUP
87*7c478bd9Sstevel@tonic-gate GLOBAL int linebaudrate;	/* for speedup hook in pk1.c */
88*7c478bd9Sstevel@tonic-gate #endif /*  PKSPEEDUP  */
89*7c478bd9Sstevel@tonic-gate static int Saved_line;		/* was savline() successful?	*/
90*7c478bd9Sstevel@tonic-gate static int Saved_termios;	/* was termios saved?	*/
91*7c478bd9Sstevel@tonic-gate GLOBAL int
92*7c478bd9Sstevel@tonic-gate 	Oddflag = 0,	/* Default is no parity */
93*7c478bd9Sstevel@tonic-gate 	Evenflag = 0,	/* Default is no parity */
94*7c478bd9Sstevel@tonic-gate 	Duplex = 1,	/* Default is full duplex */
95*7c478bd9Sstevel@tonic-gate 	Terminal = 0,	/* Default is no terminal */
96*7c478bd9Sstevel@tonic-gate 	term_8bit = -1,	/* Default to terminal setting or 8 bit */
97*7c478bd9Sstevel@tonic-gate 	line_8bit = -1;	/* Default is same as terminal */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate static char *P_PARITY  = "Parity option error\r\n";
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate #ifdef ATTSVTTY
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate static struct termio Savettyb;
104*7c478bd9Sstevel@tonic-gate static struct termios Savettybs;
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * set speed/echo/mode...
107*7c478bd9Sstevel@tonic-gate  *	tty 	-> terminal name
108*7c478bd9Sstevel@tonic-gate  *	spwant 	-> speed
109*7c478bd9Sstevel@tonic-gate  *	type	-> type
110*7c478bd9Sstevel@tonic-gate  *
111*7c478bd9Sstevel@tonic-gate  *	if spwant == 0, speed is untouched
112*7c478bd9Sstevel@tonic-gate  *	type is unused, but needed for compatibility
113*7c478bd9Sstevel@tonic-gate  *
114*7c478bd9Sstevel@tonic-gate  * return:
115*7c478bd9Sstevel@tonic-gate  *	none
116*7c478bd9Sstevel@tonic-gate  */
117*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
118*7c478bd9Sstevel@tonic-gate GLOBAL void
119*7c478bd9Sstevel@tonic-gate fixline(tty, spwant, type)
120*7c478bd9Sstevel@tonic-gate int	tty, spwant, type;
121*7c478bd9Sstevel@tonic-gate {
122*7c478bd9Sstevel@tonic-gate 	register struct sg_spds	*ps;
123*7c478bd9Sstevel@tonic-gate 	struct termio		ttbuf;
124*7c478bd9Sstevel@tonic-gate 	struct termios		ttbufs;
125*7c478bd9Sstevel@tonic-gate 	int			speed = -1;
126*7c478bd9Sstevel@tonic-gate 	int			i, istermios, ospeed;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "fixline(%d, ", tty);
129*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "%d)\n", spwant);
130*7c478bd9Sstevel@tonic-gate 	if ((istermios = (*Ioctl)(tty, TCGETS, &ttbufs)) < 0) {
131*7c478bd9Sstevel@tonic-gate 		if ((*Ioctl)(tty, TCGETA, &ttbuf) != 0) {
132*7c478bd9Sstevel@tonic-gate 			return;
133*7c478bd9Sstevel@tonic-gate 		} else {
134*7c478bd9Sstevel@tonic-gate 			ttbufs.c_lflag = ttbuf.c_lflag;
135*7c478bd9Sstevel@tonic-gate 			ttbufs.c_oflag = ttbuf.c_oflag;
136*7c478bd9Sstevel@tonic-gate 			ttbufs.c_iflag = ttbuf.c_iflag;
137*7c478bd9Sstevel@tonic-gate 			ttbufs.c_cflag = ttbuf.c_cflag;
138*7c478bd9Sstevel@tonic-gate 			for(i = 0; i < NCC; i++)
139*7c478bd9Sstevel@tonic-gate 				ttbufs.c_cc[i] = ttbuf.c_cc[i];
140*7c478bd9Sstevel@tonic-gate 	    	}
141*7c478bd9Sstevel@tonic-gate 	}
142*7c478bd9Sstevel@tonic-gate 	if (spwant > 0) {
143*7c478bd9Sstevel@tonic-gate 		for (ps = spds; ps->sp_val; ps++)
144*7c478bd9Sstevel@tonic-gate 			if (ps->sp_val == spwant) {
145*7c478bd9Sstevel@tonic-gate 				speed = ps->sp_name;
146*7c478bd9Sstevel@tonic-gate 				break;
147*7c478bd9Sstevel@tonic-gate 			}
148*7c478bd9Sstevel@tonic-gate 		if ( speed < 0 )
149*7c478bd9Sstevel@tonic-gate 		    DEBUG(5, "speed (%d) not supported\n", spwant);
150*7c478bd9Sstevel@tonic-gate 		ASSERT(speed >= 0, "BAD SPEED", "", spwant);
151*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag &= 0xffff0000;
152*7c478bd9Sstevel@tonic-gate 		cfsetospeed(&ttbufs, speed);
153*7c478bd9Sstevel@tonic-gate 	} else { /* determine the current speed setting */
154*7c478bd9Sstevel@tonic-gate 		ospeed = cfgetospeed(&ttbufs);
155*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag &= 0xffff0000;
156*7c478bd9Sstevel@tonic-gate 		cfsetospeed(&ttbufs, ospeed);
157*7c478bd9Sstevel@tonic-gate 		for (ps = spds; ps->sp_val; ps++)
158*7c478bd9Sstevel@tonic-gate 			if (ps->sp_name == ospeed) {
159*7c478bd9Sstevel@tonic-gate 				spwant = ps->sp_val;
160*7c478bd9Sstevel@tonic-gate 				break;
161*7c478bd9Sstevel@tonic-gate 			}
162*7c478bd9Sstevel@tonic-gate 	}
163*7c478bd9Sstevel@tonic-gate 	ttbufs.c_iflag &= 0xffff0000;
164*7c478bd9Sstevel@tonic-gate 	ttbufs.c_oflag &= 0xffff0000;
165*7c478bd9Sstevel@tonic-gate 	ttbufs.c_lflag &= 0xffff0000;
166*7c478bd9Sstevel@tonic-gate #ifdef PKSPEEDUP
167*7c478bd9Sstevel@tonic-gate 	linebaudrate = spwant;
168*7c478bd9Sstevel@tonic-gate #endif /*  PKSPEEDUP  */
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate #ifdef NO_MODEM_CTRL
171*7c478bd9Sstevel@tonic-gate 	/*   CLOCAL may cause problems on pdp11s with DHs */
172*7c478bd9Sstevel@tonic-gate 	if (type == D_DIRECT) {
173*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "fixline - direct\n%s", "");
174*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag |= CLOCAL;
175*7c478bd9Sstevel@tonic-gate 	} else
176*7c478bd9Sstevel@tonic-gate #endif /* NO_MODEM_CTRL */
177*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag &= ~CLOCAL;
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	if ( !EQUALS(Progname, "uucico") ) {
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 		/* set attributes associated with -h, -t, -e, and -o options */
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 		ttbufs.c_iflag = (IGNPAR | IGNBRK | IXON | IXOFF);
184*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cc[VEOF] = '\1';
185*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag |= ( CREAD | (speed ? HUPCL : 0));
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 		if ( line_8bit ) {
188*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_cflag |= CS8;
189*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_iflag &= ~ISTRIP;
190*7c478bd9Sstevel@tonic-gate 		} else {
191*7c478bd9Sstevel@tonic-gate 		    if (Evenflag) {			/*even parity -e */
192*7c478bd9Sstevel@tonic-gate 			ttbufs.c_cflag &= ~PARODD;
193*7c478bd9Sstevel@tonic-gate 		    } else if(Oddflag) {		/*odd parity -o */
194*7c478bd9Sstevel@tonic-gate 			ttbufs.c_cflag |= PARODD;
195*7c478bd9Sstevel@tonic-gate 		    }
196*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_cflag |= CS7|PARENB;
197*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_iflag |= ISTRIP;
198*7c478bd9Sstevel@tonic-gate 		}
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 		if(!Duplex)				/*half duplex -h */
201*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_iflag &= ~(IXON | IXOFF);
202*7c478bd9Sstevel@tonic-gate 		if(Terminal)				/* -t */
203*7c478bd9Sstevel@tonic-gate 		    ttbufs.c_oflag |= (OPOST | ONLCR);
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	} else { /* non-uucico */
206*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cflag |= (CS8 | CREAD | (speed ? HUPCL : 0));
207*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cc[VMIN] = HEADERSIZE;
208*7c478bd9Sstevel@tonic-gate 		ttbufs.c_cc[VTIME] = 1;
209*7c478bd9Sstevel@tonic-gate 	}
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 	if (istermios < 0) {
212*7c478bd9Sstevel@tonic-gate 		ttbuf.c_lflag = ttbufs.c_lflag;
213*7c478bd9Sstevel@tonic-gate 		ttbuf.c_oflag = ttbufs.c_oflag;
214*7c478bd9Sstevel@tonic-gate 		ttbuf.c_iflag = ttbufs.c_iflag;
215*7c478bd9Sstevel@tonic-gate 		ttbuf.c_cflag = ttbufs.c_cflag;
216*7c478bd9Sstevel@tonic-gate 		for(i = 0; i < NCC; i++)
217*7c478bd9Sstevel@tonic-gate 			ttbuf.c_cc[i] = ttbufs.c_cc[i];
218*7c478bd9Sstevel@tonic-gate 		ASSERT((*Ioctl)(tty, TCSETAW, &ttbuf) >= 0,
219*7c478bd9Sstevel@tonic-gate 	    	    "RETURN FROM fixline ioctl", "", errno);
220*7c478bd9Sstevel@tonic-gate 	} else {
221*7c478bd9Sstevel@tonic-gate 		ASSERT((*Ioctl)(tty, TCSETSW, &ttbufs) >= 0,
222*7c478bd9Sstevel@tonic-gate 	    	    "RETURN FROM fixline ioctl", "", errno);
223*7c478bd9Sstevel@tonic-gate 	}
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	return;
226*7c478bd9Sstevel@tonic-gate }
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate GLOBAL void
229*7c478bd9Sstevel@tonic-gate sethup(dcf)
230*7c478bd9Sstevel@tonic-gate int	dcf;
231*7c478bd9Sstevel@tonic-gate {
232*7c478bd9Sstevel@tonic-gate 	struct termio ttbuf;
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(dcf, TCGETA, &ttbuf) != 0)
235*7c478bd9Sstevel@tonic-gate 		return;
236*7c478bd9Sstevel@tonic-gate 	if (!(ttbuf.c_cflag & HUPCL)) {
237*7c478bd9Sstevel@tonic-gate 		ttbuf.c_cflag |= HUPCL;
238*7c478bd9Sstevel@tonic-gate 		(void) (*Ioctl)(dcf, TCSETAW, &ttbuf);
239*7c478bd9Sstevel@tonic-gate 	}
240*7c478bd9Sstevel@tonic-gate 	return;
241*7c478bd9Sstevel@tonic-gate }
242*7c478bd9Sstevel@tonic-gate 
243*7c478bd9Sstevel@tonic-gate GLOBAL void
244*7c478bd9Sstevel@tonic-gate ttygenbrk(fn)
245*7c478bd9Sstevel@tonic-gate register int	fn;
246*7c478bd9Sstevel@tonic-gate {
247*7c478bd9Sstevel@tonic-gate 	if (isatty(fn))
248*7c478bd9Sstevel@tonic-gate 		(void) (*Ioctl)(fn, TCSBRK, 0);
249*7c478bd9Sstevel@tonic-gate 	return;
250*7c478bd9Sstevel@tonic-gate }
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate /*
254*7c478bd9Sstevel@tonic-gate  * optimize line setting for sending or receiving files
255*7c478bd9Sstevel@tonic-gate  * return:
256*7c478bd9Sstevel@tonic-gate  *	none
257*7c478bd9Sstevel@tonic-gate  */
258*7c478bd9Sstevel@tonic-gate GLOBAL void
259*7c478bd9Sstevel@tonic-gate setline(type)
260*7c478bd9Sstevel@tonic-gate register char	type;
261*7c478bd9Sstevel@tonic-gate {
262*7c478bd9Sstevel@tonic-gate 	static struct termio tbuf;
263*7c478bd9Sstevel@tonic-gate 	static struct termios tbufs;
264*7c478bd9Sstevel@tonic-gate 	int i, vtime, istermios, ospeed;
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 	DEBUG(2, "setline - %c\n", type);
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	if ((istermios = (*Ioctl)(Ifn, TCGETS, &tbufs)) < 0) {
269*7c478bd9Sstevel@tonic-gate 		if ((*Ioctl)(Ifn, TCGETA, &tbuf) != 0) {
270*7c478bd9Sstevel@tonic-gate 			return;
271*7c478bd9Sstevel@tonic-gate 		} else {
272*7c478bd9Sstevel@tonic-gate 			tbufs.c_lflag = tbuf.c_lflag;
273*7c478bd9Sstevel@tonic-gate 			tbufs.c_oflag = tbuf.c_oflag;
274*7c478bd9Sstevel@tonic-gate 			tbufs.c_iflag = tbuf.c_iflag;
275*7c478bd9Sstevel@tonic-gate 			tbufs.c_cflag = tbuf.c_cflag;
276*7c478bd9Sstevel@tonic-gate 			for(i = 0; i < NCC; i++)
277*7c478bd9Sstevel@tonic-gate 				tbufs.c_cc[i] = tbuf.c_cc[i];
278*7c478bd9Sstevel@tonic-gate 		}
279*7c478bd9Sstevel@tonic-gate 	}
280*7c478bd9Sstevel@tonic-gate 	switch (type) {
281*7c478bd9Sstevel@tonic-gate 	case RCVFILE:
282*7c478bd9Sstevel@tonic-gate 		ospeed = cfgetospeed(&tbufs);
283*7c478bd9Sstevel@tonic-gate 		switch (ospeed) {
284*7c478bd9Sstevel@tonic-gate #ifdef B19200
285*7c478bd9Sstevel@tonic-gate 		case B19200:
286*7c478bd9Sstevel@tonic-gate #else
287*7c478bd9Sstevel@tonic-gate #ifdef EXTA
288*7c478bd9Sstevel@tonic-gate 		case EXTA:
289*7c478bd9Sstevel@tonic-gate #endif
290*7c478bd9Sstevel@tonic-gate #endif
291*7c478bd9Sstevel@tonic-gate #ifdef B38400
292*7c478bd9Sstevel@tonic-gate 		case B38400:
293*7c478bd9Sstevel@tonic-gate #endif
294*7c478bd9Sstevel@tonic-gate 		case B57600:
295*7c478bd9Sstevel@tonic-gate 		case B76800:
296*7c478bd9Sstevel@tonic-gate 		case B115200:
297*7c478bd9Sstevel@tonic-gate 		case B153600:
298*7c478bd9Sstevel@tonic-gate 		case B230400:
299*7c478bd9Sstevel@tonic-gate 		case B307200:
300*7c478bd9Sstevel@tonic-gate 		case B460800:
301*7c478bd9Sstevel@tonic-gate 		case B9600:
302*7c478bd9Sstevel@tonic-gate 			vtime = 1;
303*7c478bd9Sstevel@tonic-gate 			break;
304*7c478bd9Sstevel@tonic-gate 		case B4800:
305*7c478bd9Sstevel@tonic-gate 			vtime = 4;
306*7c478bd9Sstevel@tonic-gate 			break;
307*7c478bd9Sstevel@tonic-gate 		default:
308*7c478bd9Sstevel@tonic-gate 			vtime = 8;
309*7c478bd9Sstevel@tonic-gate 			break;
310*7c478bd9Sstevel@tonic-gate 		}
311*7c478bd9Sstevel@tonic-gate 		if (tbufs.c_cc[VMIN] != packsize ||
312*7c478bd9Sstevel@tonic-gate 		    tbufs.c_cc[VTIME] != vtime) {
313*7c478bd9Sstevel@tonic-gate 		    tbufs.c_cc[VMIN] = packsize;
314*7c478bd9Sstevel@tonic-gate 		    tbufs.c_cc[VTIME] = vtime;
315*7c478bd9Sstevel@tonic-gate 		    if (istermios < 0) {
316*7c478bd9Sstevel@tonic-gate 			tbuf.c_lflag = tbufs.c_lflag;
317*7c478bd9Sstevel@tonic-gate 			tbuf.c_oflag = tbufs.c_oflag;
318*7c478bd9Sstevel@tonic-gate 			tbuf.c_iflag = tbufs.c_iflag;
319*7c478bd9Sstevel@tonic-gate 			tbuf.c_cflag = tbufs.c_cflag;
320*7c478bd9Sstevel@tonic-gate 			for(i = 0; i < NCC; i++)
321*7c478bd9Sstevel@tonic-gate 				tbuf.c_cc[i] = tbufs.c_cc[i];
322*7c478bd9Sstevel@tonic-gate 		        if ( (*Ioctl)(Ifn, TCSETAW, &tbuf) != 0 )
323*7c478bd9Sstevel@tonic-gate 			    DEBUG(4, "setline Ioctl failed errno=%d\n", errno);
324*7c478bd9Sstevel@tonic-gate 		    } else {
325*7c478bd9Sstevel@tonic-gate 		        if ( (*Ioctl)(Ifn, TCSETSW, &tbufs) != 0 )
326*7c478bd9Sstevel@tonic-gate 			    DEBUG(4, "setline Ioctl failed errno=%d\n", errno);
327*7c478bd9Sstevel@tonic-gate 		    }
328*7c478bd9Sstevel@tonic-gate 		}
329*7c478bd9Sstevel@tonic-gate 		break;
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 	case SNDFILE:
332*7c478bd9Sstevel@tonic-gate 	case RESET:
333*7c478bd9Sstevel@tonic-gate 		if (tbufs.c_cc[VMIN] != HEADERSIZE) {
334*7c478bd9Sstevel@tonic-gate 		    tbufs.c_cc[VMIN] = HEADERSIZE;
335*7c478bd9Sstevel@tonic-gate 		    if (istermios < 0) {
336*7c478bd9Sstevel@tonic-gate 			tbuf.c_lflag = tbufs.c_lflag;
337*7c478bd9Sstevel@tonic-gate 			tbuf.c_oflag = tbufs.c_oflag;
338*7c478bd9Sstevel@tonic-gate 			tbuf.c_iflag = tbufs.c_iflag;
339*7c478bd9Sstevel@tonic-gate 			tbuf.c_cflag = tbufs.c_cflag;
340*7c478bd9Sstevel@tonic-gate 			for(i = 0; i < NCC; i++)
341*7c478bd9Sstevel@tonic-gate 				tbuf.c_cc[i] = tbufs.c_cc[i];
342*7c478bd9Sstevel@tonic-gate 		    	if ( (*Ioctl)(Ifn, TCSETAW, &tbuf) != 0 )
343*7c478bd9Sstevel@tonic-gate 			    DEBUG(4, "setline Ioctl failed errno=%d\n", errno);
344*7c478bd9Sstevel@tonic-gate 		    } else {
345*7c478bd9Sstevel@tonic-gate 		        if ( (*Ioctl)(Ifn, TCSETSW, &tbufs) != 0 )
346*7c478bd9Sstevel@tonic-gate 			    DEBUG(4, "setline Ioctl failed errno=%d\n", errno);
347*7c478bd9Sstevel@tonic-gate 		    }
348*7c478bd9Sstevel@tonic-gate 		}
349*7c478bd9Sstevel@tonic-gate 		break;
350*7c478bd9Sstevel@tonic-gate 	}
351*7c478bd9Sstevel@tonic-gate 	return;
352*7c478bd9Sstevel@tonic-gate }
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate GLOBAL int
355*7c478bd9Sstevel@tonic-gate savline()
356*7c478bd9Sstevel@tonic-gate {
357*7c478bd9Sstevel@tonic-gate 	if ((Saved_termios = (*Ioctl)(0, TCGETS, &Savettybs)) < 0) {
358*7c478bd9Sstevel@tonic-gate 	    if ( (*Ioctl)(0, TCGETA, &Savettyb) != 0 ) {
359*7c478bd9Sstevel@tonic-gate 		Saved_line = FALSE;
360*7c478bd9Sstevel@tonic-gate 	    } else {
361*7c478bd9Sstevel@tonic-gate 		Saved_line = TRUE;
362*7c478bd9Sstevel@tonic-gate 		Savettyb.c_cflag = (Savettyb.c_cflag & ~CS8) | CS7 | PARENB;
363*7c478bd9Sstevel@tonic-gate 		Savettyb.c_oflag |= OPOST;
364*7c478bd9Sstevel@tonic-gate 		Savettyb.c_lflag |= (ISIG|ICANON|ECHO);
365*7c478bd9Sstevel@tonic-gate 	    }
366*7c478bd9Sstevel@tonic-gate 	} else {
367*7c478bd9Sstevel@tonic-gate 		Saved_line = TRUE;
368*7c478bd9Sstevel@tonic-gate 		Savettybs.c_cflag = (Savettybs.c_cflag & ~CS8) | CS7 | PARENB;
369*7c478bd9Sstevel@tonic-gate 		Savettybs.c_oflag |= OPOST;
370*7c478bd9Sstevel@tonic-gate 		Savettybs.c_lflag |= (ISIG|ICANON|ECHO);
371*7c478bd9Sstevel@tonic-gate 	}
372*7c478bd9Sstevel@tonic-gate 	return(0);
373*7c478bd9Sstevel@tonic-gate }
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate #ifdef SYTEK
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate /*
378*7c478bd9Sstevel@tonic-gate  *	sytfixline(tty, spwant)	set speed/echo/mode...
379*7c478bd9Sstevel@tonic-gate  *	int tty, spwant;
380*7c478bd9Sstevel@tonic-gate  *
381*7c478bd9Sstevel@tonic-gate  *	return codes:  none
382*7c478bd9Sstevel@tonic-gate  */
383*7c478bd9Sstevel@tonic-gate 
384*7c478bd9Sstevel@tonic-gate GLOBAL void
385*7c478bd9Sstevel@tonic-gate sytfixline(tty, spwant)
386*7c478bd9Sstevel@tonic-gate int tty, spwant;
387*7c478bd9Sstevel@tonic-gate {
388*7c478bd9Sstevel@tonic-gate 	struct termio ttbuf;
389*7c478bd9Sstevel@tonic-gate 	struct termios ttbufs;
390*7c478bd9Sstevel@tonic-gate 	struct sg_spds *ps;
391*7c478bd9Sstevel@tonic-gate 	int speed = -1;
392*7c478bd9Sstevel@tonic-gate 	int i, ret, istermios;
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate 	if ((istermios = (*Ioctl)(tty, TCGETS, &ttbufs)) < 0) {
395*7c478bd9Sstevel@tonic-gate 		if ( (*Ioctl)(tty, TCGETA, &ttbuf) != 0 ) {
396*7c478bd9Sstevel@tonic-gate 			return;
397*7c478bd9Sstevel@tonic-gate 		} else {
398*7c478bd9Sstevel@tonic-gate 			ttbufs.c_lflag = ttbuf.c_lflag;
399*7c478bd9Sstevel@tonic-gate 			ttbufs.c_oflag = ttbuf.c_oflag;
400*7c478bd9Sstevel@tonic-gate 			ttbufs.c_iflag = ttbuf.c_iflag;
401*7c478bd9Sstevel@tonic-gate 			ttbufs.c_cflag = ttbuf.c_cflag;
402*7c478bd9Sstevel@tonic-gate 			for(i = 0; i < NCC; i++)
403*7c478bd9Sstevel@tonic-gate 				ttbufs.c_cc[i] = ttbuf.c_cc[i];
404*7c478bd9Sstevel@tonic-gate 		}
405*7c478bd9Sstevel@tonic-gate 	}
406*7c478bd9Sstevel@tonic-gate 	for (ps = spds; ps->sp_val >= 0; ps++)
407*7c478bd9Sstevel@tonic-gate 		if (ps->sp_val == spwant)
408*7c478bd9Sstevel@tonic-gate 			speed = ps->sp_name;
409*7c478bd9Sstevel@tonic-gate 	DEBUG(4, "sytfixline - speed= %d\n", speed);
410*7c478bd9Sstevel@tonic-gate 	ASSERT(speed >= 0, "BAD SPEED", "", spwant);
411*7c478bd9Sstevel@tonic-gate 	ttbufs.c_iflag &= 0xffff0000;
412*7c478bd9Sstevel@tonic-gate 	ttbufs.c_oflag &= 0xffff0000;
413*7c478bd9Sstevel@tonic-gate 	ttbufs.c_lflag &= 0xffff0000;
414*7c478bd9Sstevel@tonic-gate 	ttbufs.c_cflag &= 0xffff0000;
415*7c478bd9Sstevel@tonic-gate 	cfsetospeed(&ttbufs, speed);
416*7c478bd9Sstevel@tonic-gate 	ttbufs.c_cflag |= (CS8|CLOCAL);
417*7c478bd9Sstevel@tonic-gate 	ttbufs.c_cc[VMIN] = 6;
418*7c478bd9Sstevel@tonic-gate 	ttbufs.c_cc[VTIME] = 1;
419*7c478bd9Sstevel@tonic-gate 	if (istermios < 0) {
420*7c478bd9Sstevel@tonic-gate 		ttbuf.c_lflag = ttbufs.c_lflag;
421*7c478bd9Sstevel@tonic-gate 		ttbuf.c_oflag = ttbufs.c_oflag;
422*7c478bd9Sstevel@tonic-gate 		ttbuf.c_iflag = ttbufs.c_iflag;
423*7c478bd9Sstevel@tonic-gate 		ttbuf.c_cflag = ttbufs.c_cflag;
424*7c478bd9Sstevel@tonic-gate 		for(i = 0; i < NCC; i++)
425*7c478bd9Sstevel@tonic-gate 			ttbuf.c_cc[i] = ttbufs.c_cc[i];
426*7c478bd9Sstevel@tonic-gate 		ret = (*Ioctl)(tty, TCSETAW, &ttbuf);
427*7c478bd9Sstevel@tonic-gate 	} else
428*7c478bd9Sstevel@tonic-gate 		ret = (*Ioctl)(tty, TCSETAWS &ttbufs);
429*7c478bd9Sstevel@tonic-gate 	ASSERT(ret >= 0, "RETURN FROM sytfixline", "", ret);
430*7c478bd9Sstevel@tonic-gate 	return;
431*7c478bd9Sstevel@tonic-gate }
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate GLOBAL void
434*7c478bd9Sstevel@tonic-gate sytfix2line(tty)
435*7c478bd9Sstevel@tonic-gate int tty;
436*7c478bd9Sstevel@tonic-gate {
437*7c478bd9Sstevel@tonic-gate 	struct termio ttbuf;
438*7c478bd9Sstevel@tonic-gate 	int ret;
439*7c478bd9Sstevel@tonic-gate 
440*7c478bd9Sstevel@tonic-gate 	if ( (*Ioctl)(tty, TCGETA, &ttbuf) != 0 )
441*7c478bd9Sstevel@tonic-gate 		return;
442*7c478bd9Sstevel@tonic-gate 	ttbuf.c_cflag &= ~CLOCAL;
443*7c478bd9Sstevel@tonic-gate 	ttbuf.c_cflag |= CREAD|HUPCL;
444*7c478bd9Sstevel@tonic-gate 	ret = (*Ioctl)(tty, TCSETAW, &ttbuf);
445*7c478bd9Sstevel@tonic-gate 	ASSERT(ret >= 0, "RETURN FROM sytfix2line", "", ret);
446*7c478bd9Sstevel@tonic-gate 	return;
447*7c478bd9Sstevel@tonic-gate }
448*7c478bd9Sstevel@tonic-gate 
449*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */
450*7c478bd9Sstevel@tonic-gate 
451*7c478bd9Sstevel@tonic-gate GLOBAL int
452*7c478bd9Sstevel@tonic-gate restline()
453*7c478bd9Sstevel@tonic-gate {
454*7c478bd9Sstevel@tonic-gate 	if ( Saved_line == TRUE ) {
455*7c478bd9Sstevel@tonic-gate 		if (Saved_termios < 0)
456*7c478bd9Sstevel@tonic-gate 			return((*Ioctl)(0, TCSETAW, &Savettyb));
457*7c478bd9Sstevel@tonic-gate 		else
458*7c478bd9Sstevel@tonic-gate 			return((*Ioctl)(0, TCSETSW, &Savettybs));
459*7c478bd9Sstevel@tonic-gate 	}
460*7c478bd9Sstevel@tonic-gate 	return(0);
461*7c478bd9Sstevel@tonic-gate }
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate #else /* !ATTSVTTY */
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate static struct sgttyb Savettyb;
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate /*
468*7c478bd9Sstevel@tonic-gate  *	fixline(tty, spwant, type)	set speed/echo/mode...
469*7c478bd9Sstevel@tonic-gate  *	int tty, spwant;
470*7c478bd9Sstevel@tonic-gate  *
471*7c478bd9Sstevel@tonic-gate  *	if spwant == 0, speed is untouched
472*7c478bd9Sstevel@tonic-gate  *	type is unused, but needed for compatibility
473*7c478bd9Sstevel@tonic-gate  *
474*7c478bd9Sstevel@tonic-gate  *	return codes:  none
475*7c478bd9Sstevel@tonic-gate  */
476*7c478bd9Sstevel@tonic-gate 
477*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
478*7c478bd9Sstevel@tonic-gate GLOBAL void
479*7c478bd9Sstevel@tonic-gate fixline(tty, spwant, type)
480*7c478bd9Sstevel@tonic-gate int tty, spwant, type;
481*7c478bd9Sstevel@tonic-gate {
482*7c478bd9Sstevel@tonic-gate 	struct sgttyb	ttbuf;
483*7c478bd9Sstevel@tonic-gate 	struct sg_spds	*ps;
484*7c478bd9Sstevel@tonic-gate 	int		 speed = -1;
485*7c478bd9Sstevel@tonic-gate 
486*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "fixline(%d, ", tty);
487*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "%d)\n", spwant);
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(tty, TIOCGETP, &ttbuf) != 0)
490*7c478bd9Sstevel@tonic-gate 		return;
491*7c478bd9Sstevel@tonic-gate 	if (spwant > 0) {
492*7c478bd9Sstevel@tonic-gate 		for (ps = spds; ps->sp_val; ps++)
493*7c478bd9Sstevel@tonic-gate 			if (ps->sp_val == spwant) {
494*7c478bd9Sstevel@tonic-gate 				speed = ps->sp_name;
495*7c478bd9Sstevel@tonic-gate 				break;
496*7c478bd9Sstevel@tonic-gate 			}
497*7c478bd9Sstevel@tonic-gate 		ASSERT(speed >= 0, "BAD SPEED", "", spwant);
498*7c478bd9Sstevel@tonic-gate 		ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed;
499*7c478bd9Sstevel@tonic-gate 	} else {
500*7c478bd9Sstevel@tonic-gate 		for (ps = spds; ps->sp_val; ps++)
501*7c478bd9Sstevel@tonic-gate 			if (ps->sp_name == ttbuf.sg_ispeed) {
502*7c478bd9Sstevel@tonic-gate 				spwant = ps->sp_val;
503*7c478bd9Sstevel@tonic-gate 				break;
504*7c478bd9Sstevel@tonic-gate 			}
505*7c478bd9Sstevel@tonic-gate 		ASSERT(spwant >= 0, "BAD SPEED", "", ttbuf.sg_ispeed);
506*7c478bd9Sstevel@tonic-gate 	}
507*7c478bd9Sstevel@tonic-gate 	ttbuf.sg_flags = (ANYP | RAW);
508*7c478bd9Sstevel@tonic-gate #ifdef PKSPEEDUP
509*7c478bd9Sstevel@tonic-gate 	linebaudrate = spwant;
510*7c478bd9Sstevel@tonic-gate #endif /*  PKSPEEDUP  */
511*7c478bd9Sstevel@tonic-gate 	(void) (*Ioctl)(tty, TIOCSETP, &ttbuf);
512*7c478bd9Sstevel@tonic-gate 	(void) (*Ioctl)(tty, TIOCHPCL, STBNULL);
513*7c478bd9Sstevel@tonic-gate 	(void) (*Ioctl)(tty, TIOCEXCL, STBNULL);
514*7c478bd9Sstevel@tonic-gate 	return;
515*7c478bd9Sstevel@tonic-gate }
516*7c478bd9Sstevel@tonic-gate 
517*7c478bd9Sstevel@tonic-gate GLOBAL void
518*7c478bd9Sstevel@tonic-gate sethup(dcf)
519*7c478bd9Sstevel@tonic-gate int	dcf;
520*7c478bd9Sstevel@tonic-gate {
521*7c478bd9Sstevel@tonic-gate 	if (isatty(dcf))
522*7c478bd9Sstevel@tonic-gate 		(void) (*Ioctl)(dcf, TIOCHPCL, STBNULL);
523*7c478bd9Sstevel@tonic-gate 	return;
524*7c478bd9Sstevel@tonic-gate }
525*7c478bd9Sstevel@tonic-gate 
526*7c478bd9Sstevel@tonic-gate /*
527*7c478bd9Sstevel@tonic-gate  *	genbrk		send a break
528*7c478bd9Sstevel@tonic-gate  *
529*7c478bd9Sstevel@tonic-gate  *	return codes;  none
530*7c478bd9Sstevel@tonic-gate  */
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate GLOBAL void
533*7c478bd9Sstevel@tonic-gate ttygenbrk(fn)
534*7c478bd9Sstevel@tonic-gate {
535*7c478bd9Sstevel@tonic-gate 	if (isatty(fn)) {
536*7c478bd9Sstevel@tonic-gate 		(void) (*Ioctl)(fn, TIOCSBRK, 0);
537*7c478bd9Sstevel@tonic-gate #ifndef V8
538*7c478bd9Sstevel@tonic-gate 		nap(HZ/10);				/* 0.1 second break */
539*7c478bd9Sstevel@tonic-gate 		(void) (*Ioctl)(fn, TIOCCBRK, 0);
540*7c478bd9Sstevel@tonic-gate #endif
541*7c478bd9Sstevel@tonic-gate 	}
542*7c478bd9Sstevel@tonic-gate 	return;
543*7c478bd9Sstevel@tonic-gate }
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate /*
546*7c478bd9Sstevel@tonic-gate  * V7 and RT aren't smart enough for this -- linebaudrate is the best
547*7c478bd9Sstevel@tonic-gate  * they can do.
548*7c478bd9Sstevel@tonic-gate  */
549*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
550*7c478bd9Sstevel@tonic-gate GLOBAL void
551*7c478bd9Sstevel@tonic-gate setline(dummy) { }
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate GLOBAL int
554*7c478bd9Sstevel@tonic-gate savline()
555*7c478bd9Sstevel@tonic-gate {
556*7c478bd9Sstevel@tonic-gate 	if (  (*Ioctl)(0, TIOCGETP, &Savettyb) != 0 )
557*7c478bd9Sstevel@tonic-gate 		Saved_line = FALSE;
558*7c478bd9Sstevel@tonic-gate 	else {
559*7c478bd9Sstevel@tonic-gate 		Saved_line = TRUE;
560*7c478bd9Sstevel@tonic-gate 		Savettyb.sg_flags |= ECHO;
561*7c478bd9Sstevel@tonic-gate 		Savettyb.sg_flags &= ~RAW;
562*7c478bd9Sstevel@tonic-gate 	}
563*7c478bd9Sstevel@tonic-gate 	return(0);
564*7c478bd9Sstevel@tonic-gate }
565*7c478bd9Sstevel@tonic-gate 
566*7c478bd9Sstevel@tonic-gate GLOBAL int
567*7c478bd9Sstevel@tonic-gate restline()
568*7c478bd9Sstevel@tonic-gate {
569*7c478bd9Sstevel@tonic-gate 	if ( Saved_line == TRUE )
570*7c478bd9Sstevel@tonic-gate 		return((*Ioctl)(0, TIOCSETP, &Savettyb));
571*7c478bd9Sstevel@tonic-gate 	return(0);
572*7c478bd9Sstevel@tonic-gate }
573*7c478bd9Sstevel@tonic-gate #endif
574