CBREAK in S5/~ICANON in V7/4.x

Mark Horton mark at cbosgd.UUCP
Wed Jul 24 14:34:23 AEST 1985


This is all pretty confusing to most people, I'll bet.  It's even
more confusing if you do what I suspect the origional poster did:
look up stty in their manual (and in /usr/include/sgtty.h) and
notice that CBREAK and TANDEM just aren't there, and neither is
TIOCSETN.  Chances are that the program they are trying to port
from V7/4BSD to SIII/SV uses these.

What's going on here is this.  sgtty is the interface to the
tty driver used in V6 and V7.  4BSD is upward compatible with
this interface, although CBERAK and TIOCSETN were in V7.
System III changed the interface radically - it's now possible
to get much more detailed control of the tty driver, although
it's now at a lower level.  (Instead of turning on CBREAK, you
have to clear ICANON and set VMIN and VTIME, being sure to save
the old values for when you come back.)  SIII/SV have an upward
compatibility package in sgtty, which is how SIII (called UNIX 3.0
at the time) could be upward compatible with the previous release,
UNIX 2.0.  However, UNIX 2.0 was not the same as V7, in particular
it didn't hvae CBREAK or TIOCSETN.  So to this day, the compatibility
package doesn't have them either.

The compatibility package has other problems.  For example, when you
use it, it clears your ECHOE bit, which will annoy most people.
So it's strongly recommended that you don't use the compatibility
package, instead ifdef the program to handle either the SV or V7
tty drivers.

If you're hopelessly confused by all this, don't worry.  There is a
package that handles all this stuff for you.  It's called curses.
You can ask curses for CBREAK mode, for example, by calling
	crmode();
You can turn off echo by calling
	noecho();
These calls do the appropriate thing on either 4.2BSD or System V.
There are a lot more portability features in the System V curses;
these are not all present in the 4.2 curses, but SV curses will
run on 4.2 if you have the appropriate licenses.

In general, if you're writing a program that wants to turn off echo
and get characters one at a time, chances are it's screen oriented.
I encourage you to use curses, your application will be more portable.
(There are curses implementions for 4.2BSD, System V, MS DOS, and QNX.)



More information about the Comp.unix.wizards mailing list