use of SGTTY.H and stuff involving IOCTLs

Dave Ciemiewicz ciemo at bananapc.wpd.sgi.com
Tue Dec 19 16:09:03 AEST 1989


In article <22483 at ut-emx.UUCP>, russo at chaos.utexas.edu (Thomas Russo) writes:
> 
> I've been trying to port a program which uses facilities of sgtty.h,
> namely it uses the sgttyb structure to set CBREAK mode and turn off
> echoing with a call to ioctl like this:
> 
> ioerr = ioctl(fileno(stdin), TIOCGETP, &tty_orig);	
> 		/* get std input characteristics */
> ...
> 		ttybuf = tty_new = tty_orig;						/* make a copy of tty control
structure */
> 		tty_new.sg_flags = (tty_new.sg_flags & ~ECHO & ~CRMOD)
> 			| CBREAK;
> ...
> 		ioctl(fileno(stdin), TIOCSETP, &tty_new);
> 			/* set flags  */
> 
> Is there any slick way to take out this kind of
> incompatibility when porting to the iris4d?   I can't find any
> reference to CBREAK mode in the FM so RTFM is so far no good. 
> Also, repeated reference is made to requests like TIOCSET[CP] and the
> like, and I have no way of knowing what the correct functions are on
> the iris.   Any hints?
> 
> 
> 
> Thomas Russo
> Center for Nonlinear Dynamics, University of Texas at Austin          
> russo at chaos.utexas.edu or phib421 at utchpc.bitnet
> ------

You should be using termio instead of sgtty.  As I understand it, sgtty is
rather archaic (and unsupported in some environments) and termio should be
used instead.  See termio(7) for many details.

For instance, your code should be something like:

	#include "termio.h"
	...
	ioerr = ioctl(fileno(stdin), TCGETA, &tty_orig);
	...
	tty_new.c_iflag &= ~ECHO;

	/* CRMOD emulation */
	tty_new.c_iflag &= ~ICRNL;
	tty_new.c_oflag &= ~OCRNL;

	/* CBREAK or 4.3BSD RAW mode emulation (see termio(7) man page
	** discussion of ICANON)
	*/
	tty_new.c_iflag &= ~ICANON;
	tty_new.c_cc[VMIN] = 1;		/* MIN characters */
	tty_new.c_cc[VTIME] = 1;	/* TIME in tenths of seconds */
	...

TIOC[GS]ETP were used to get and set the parameters.  Try matching
functionality
by looking at the termio man page and looking at any BSD source if it is
available to you.  The TCGETA and TCSETA[WF] commands are their corresponding
commands.

TIOCSETC was used to set the special characters.  termio.c_cc[] is used to
get and set the special control character settings.  Use TCSETA (or the
TCSETAW or TCSETAF variants) to set different character bindings (and control
when the bindings are set with respect to current output buffer).

I hope this is all correct, I haven't tried it.  I read termio(7) and looked
at some BSD game source to figure this one out.

If you have 4.3 BSD code available to you, look for code "#ifdef USG" which
ifdefs termio versus sgtty variations in code.

						--- Ciemo



More information about the Comp.sys.sgi mailing list