[comp.unix.programmer] BSD ioctl question

davis@pacific.mps.ohio-state.edu ("John E. Davis") (04/09/91)

Hi,

  This is a BSD unix question.  I to read a character in RAW mode from, say,
file descriptor 2.  Raw turns off all input/output processing.  However, I
only want input processing turned off.  This is not the same as CBREAK.
CBREAK still does input processing on the special characters ^Z (stop),
^\ (quit), etc... which I want turned off.  So my question is this:  from
within a C program how do I accomplish the above objective?

Currently I have:
{          .
          .
          .

#define TTY_DESCR 2
extern int ioctl(int, int, ...);

#include <sgtty.h>
struct sgttyb   OLDTTY;

          .
          .

void init_io()
{          
    struct sgttyb newtty;

    ioctl(TTY_DESCR, TIOCGETP, &OLDTTY);
    newtty = OLDTTY;
    newtty.sg_flags |= CBREAK;  
    newtty.sg_flags &= ~(ECHO | XTABS);
    
    ioctl(TTY_DESCR, TIOCSETP, &newtty);
}

Here I use CBREAK mode but I want to allow all input characters to pass
through unprocessed and I want output processing.  What are the necessaary
changes?  Note: I did RTFM but all it talked about was termio which our system
does not have (although for some stupid reason the man pages think so).

A related question (perhaps the same question): It seems that from the shell,
I can type `stty -isig' to turn off input processing on the interrupt
characters (^Z, etc..).  In BSD, how do I accomplish this with an ioctl?

Thanks,      
--
John

  bitnet: davis@ohstpy
internet: davis@pacific.mps.ohio-state.edu

torek@elf.ee.lbl.gov (Chris Torek) (04/09/91)

In article <DAVIS.91Apr9055635@pacific.mps.ohio-state.edu>
davis@pacific.mps.ohio-state.edu  (John E. Davis) writes:
>I [want] to read [an arbitrary 8 bit data] character ... from, say,
>file descriptor 2.  Raw [mode would work except that it] turns off all
>input/output processing. ... I only want input processing turned off.

>from within a C program how do I accomplish the above objective?

>A related question (perhaps the same question): It seems that from the shell,
>I can type `stty -isig' to turn off input processing on the interrupt
>characters (^Z, etc..).  In BSD, how do I accomplish this with an ioctl?

In BSD, you start by reading about termios.  If you have `stty -isig'
you have POSIX termios.

In general, you want CS8 (8 data bits), optional parity, ISIG and ICANON
turned off, and OPOST turned on.

If you have a BSD system without `stty -isig' and without TIOCGETA etc.,
you can fake 8-bit input without disabling output processing by setting
LLITIN in the `local mode word', CBREAK in the sgtty flags, and also
turning off all the special characters (struct tchars, struct ltchars).
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov

guy@auspex.auspex.com (Guy Harris) (04/11/91)

In article <DAVIS.91Apr9055635@pacific.mps.ohio-state.edu>
davis@pacific.mps.ohio-state.edu  (John E. Davis) writes:
>  This is a BSD unix question.  I to read a character in RAW mode from, say,
>file descriptor 2.  Raw turns off all input/output processing.  However, I
>only want input processing turned off.  This is not the same as CBREAK.
>CBREAK still does input processing on the special characters ^Z (stop),
>^\ (quit), etc... which I want turned off.  So my question is this:  from
>within a C program how do I accomplish the above objective?

Well, it depends on what you do, and what you don't, want turned off. 
It also depends on what flavor of tty driver your OS has; you say "BSD
UNIX", but also say

>Note: I did RTFM but all it talked about was termio which our system
>does not have (although for some stupid reason the man pages think so).
>
>A related question (perhaps the same question): It seems that from the shell,
>I can type `stty -isig' to turn off input processing on the interrupt
>characters (^Z, etc..).

Given that you can type "stty -isig" from the shell, I'm skeptical of
your claim that your system doesn't have "termio", because ISIG is a
"termio"ism.  The explanations I can think of are:

	1) your system has "termios", but not "termio";

	2) your system has picked up some "termio"/"termios"isms, but
	   not others.

Precisely what OS are you running?  If it's a BSD release prior to
4.3-reno, I'm curious how it got "isig".  If it's 4.3-reno, it doesn't
have "termio", but it *does* have "termios".

>In BSD, how do I accomplish this with an ioctl?

Well, if your system really truly genuinely doesn't have "termio" *or*
"termios", the way you'd do it would be to go into CBREAK mode *and*
"disable" the interrupt characters - and the XON/XOFF characters, if you
want them "disabled" as well.  To "disable" them, set them to '\377'
using the TIOCGETC/TIOCSETC and TIOCGLTC/TIOCSLTC "ioctl"s; "disable" is
in quotes because that doesn't really disable them, it merely sets them
to a value unlikely to be seen (if you have 8-bit input turned on, they
are, at best, unlikely, not impossible; if you have 8-bit input turned
off, they are impossible).

If your system *does* have "termio" or "termios", then turn ISIG off to
disable all the interrupt characters (^C, ^Z, ^\), and turn IXON off to
disable the XON/XOFF characters.  You may also want to turn IEXTEN off,
as that may be necessary to disable the literal-next (^V) and
flush-output (^O) characters.

In article <11914@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes:
>In general, you want CS8 (8 data bits), optional parity, ISIG and ICANON
>turned off, and OPOST turned on.

Well, I'm not sure he said he wanted 8-bit input....

>If you have a BSD system without `stty -isig' and without TIOCGETA etc.,
>you can fake 8-bit input without disabling output processing by setting
>LLITIN in the `local mode word',

Setting *what*?  "I see no LLITIN here."  Do you mean "PASS8"?

torek@elf.ee.lbl.gov (Chris Torek) (04/11/91)

>In article <11914@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes:
>>If you have [an old] BSD system ... you can fake 8-bit input without
>>disabling output processing by setting LLITIN in the `local mode word',

In article <7114@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>Setting *what*?  "I see no LLITIN here."  Do you mean "PASS8"?

Oops, right.

(PASS8 appeared in either 4.3 or 4.3-tahoe.  `litout' mode had been around
for quite some time before that, and I always thought of pass8 as `litin'.)
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov