losing input when switching from CBREAK to COOKED in SunOS-4

Johan Widen jw at sics.se
Thu Feb 15 16:08:36 AEST 1990


>>>>> In article <4904 at brazos.Rice.edu>, jw at sics.se (Johan Widen) writes:
| X-Sun-Spots-Digest: Volume 9, Issue 41, message 4
| I have a problem with typeahead in my interactions with tcsh on SunOS-4.
| The input buffer seems to be flushed when the shell switches from CBREAK
| to COOKED. I remember that this was the case in older versions of UNIX
| (like v7) and I seem to remember someone mentioning that this "feature"
| was put back into SunOS-4 for some reason.

I got the following response from guy at auspex.com (Guy Harris)

| It was.  The problem is that with a streams-based tty driver, when in
| cooked mode each line must be a single streams message and the stream
| head must be in "message-nondiscard" mode, so that a "read" gets no more
| than one line (which is the standard UNIX behavior and is, I think,
| documented).  In uncooked mode, you send stuff up as soon as it arrives,
| basically, and run in "byte-stream" mode, so that the input looks like a
| stream of characters with no delimiters.
|
| Unfortunately, this means that mode generated when in "uncooked" mode
| looks, if read when in "cooked" mode, like a bunch of tiny lines with ^D
| typed at the end of them, which confuses the living hell out of many
| programs reading the input - including the C shell with file name
| completion.
|
| The flushing is unfortunate, and wouldn't have been put it had it not
| been necessary, but the alternative was worse (file name completion was
| basically unusable).  If somebody has a good way of getting the data
| queued up at the stream head reprocessed by the "line discipline"
| streams module without doing violence the the entire streams mechanism,
| Sun (and AT&T, since the SunOS 4.x tty driver is the basis of the S5R4
| tty driver) would probably love to hear about it.... 

This seems to be a tough problem. I implemented a partial workaround for
tcsh. The idea is stolen from bash: just before switching into CBREAK do a
FIONREAD ioctl to check if there is an input record that can be read in
cooked mode. If so, then we stay in cooked mode, read the line, execute
the command and start over again. We thus try to avoid going into CBREAK
mode.

This works well for the case of traditional type ahead: the user types new
commands/whatever while a command is running.

However, it is still not possible to paste several lines at the shell
prompt. All lines except the first will be lost, as the shell is initially
in CBREAK mode.

Johan Widen
SICS, PO Box 1263, S-164 28 KISTA, SWEDEN	Internet: jw at sics.se
Tel: +46 8 752 15 32	Ttx: 812 61 54 SICS S	Fax: +46 8 751 72 30



More information about the Comp.sys.sun mailing list