[comp.sys.hp] CBREAK mode

sukmi@cs.psu.edu (Sukmi Lim) (02/19/90)

I was in the middle of installing rn on HP9000 series 300 running HP-UX6.5.
I've got a syntax error saying "CBREAK not defined."
I understand CBREAK is defined in ioctl.h on BSD Unix.
But it was not the case on our machine.  But, I know CBREAK mode is supported
on HP machine.  Could anyone tell me the mode which is equivalent to CBREAK
mode?  Thank you in advance.

sukmi
-------------------------
Please reply to:
  sukmi@psuvax1.cs.psu.edu

ps@tut.fi (Pertti Suomela) (02/20/90)

In article <E*k*m6@cs.psu.edu> sukmi@cs.psu.edu (Sukmi Lim) writes:

> on HP machine.  Could anyone tell me the mode which is equivalent to CBREAK
> mode?  Thank you in advance.

Try TIOCBREAK.
--
	 Pertti Suomela		Tampere University of Technology
				Control Engineering Laboratory	
	    ps@tut.fi		PO Box 527, SF-33101 Tampere, Finland
	ps@fintut.bitnet	Work: +358-31-162650, Fax: +358-31-162340

tml@hemuli.tik.vtt.fi (Tor Lillqvist) (02/20/90)

In article <PS.90Feb20094925@sparrow.tut.fi> ps@tut.fi (Pertti Suomela) writes:
>In article <E*k*m6@cs.psu.edu> sukmi@cs.psu.edu (Sukmi Lim) writes:
>> on HP machine.  Could anyone tell me the mode which is equivalent to CBREAK
>> mode?  Thank you in advance.

>Try TIOCBREAK.

Nope.  TIOCBREAK simulates a BREAK condition on a PTY (at least,
that's what I think the text in pty(7) means).  CBREAK on BSD is a
"half-cooked" mode, similar to -icanon.
-- 
Tor Lillqvist,
working, but not speaking, for the Technical Research Centre of Finland

raveling@isi.edu (Paul Raveling) (02/21/90)

In article <E*k*m6@cs.psu.edu>, sukmi@cs.psu.edu (Sukmi Lim) writes:
> I was in the middle of installing rn on HP9000 series 300 running HP-UX6.5.
> I've got a syntax error saying "CBREAK not defined."
> I understand CBREAK is defined in ioctl.h on BSD Unix.
> But it was not the case on our machine.  But, I know CBREAK mode is supported
> on HP machine.  Could anyone tell me the mode which is equivalent to CBREAK
> mode?  Thank you in advance.

	Appended below are cbreak() and normal() functions,
	which are equivalent to setting or clearing CBREAK, respectively.

	Credit for these goes to Dave Decot.  This copy came from
	an article on this newsgroup in the dim past, but the same code
	keeps on working like a champ as time goes by.


----------------
Paul Raveling
Raveling@isi.edu

--------------------------------  Cut Here  ---------------------------------
/* Routines for managing nonechoing, one-character-at-a-time tty reads */

/* Dave Decot, hpda!decot, 851023 */

/* cbreak() - sets terminal up for one-char-at-a-time reads */
/* normal() - restores terminal to initial state */


#include <stdio.h>
#include <signal.h>
#include <sys/types.h>

#ifndef hpux		/* BSD style */
#   include <sgtty.h>
#else hpux		/* HP-UX style (and other System V systems) */
#   include <termio.h>
#endif hpux


static int tty_mode = 0;

#ifdef TCGETA
    static struct termio orig_tty;
    static struct termio new_tty;
#else
    static struct sgttyb orig_tty;
    static struct sgttyb new_tty;
#endif


cbreak()
{
    if (tty_mode == 0)
    {
#ifdef TCGETA
	ioctl(0, TCGETA, &orig_tty);
#else
	ioctl(0, TIOCGETP, &orig_tty);
#endif
	tty_mode = 1;
	new_tty = orig_tty;
    }

#ifdef ICANON
    new_tty.c_lflag &= ~(ICANON | ECHO);
    new_tty.c_cc[VMIN] = 1;
    new_tty.c_cc[VTIME] = 0;
    ioctl(0, TCSETA, &new_tty);
#else
    new_tty.sg_flags |= CBREAK;
    new_tty.sg_flags &= ~ECHO;
    ioctl(0, TIOCSETN, &new_tty);
#endif
}


normal()
{
    if (tty_mode == 1)
    {
#ifdef TCSETA
	ioctl(0, TCSETA, &orig_tty);
#else
	ioctl(0, TIOCSETN, &orig_tty);
#endif
	new_tty = orig_tty;
    }
}

decot@hpisod2.HP.COM (Dave Decot) (02/21/90)

Clearing ICANON and setting the c_cc[VMIN] and c_cc[VTIME] "characters" to 0
causes behavior similar to BSD's CBREAK mode.

Dave Decot

decot@hpisod2.HP.COM (Dave Decot) (02/23/90)

Note that the routine cbreak() also turns off echoing.  If you don't want
to do that, delete the portions that clear the ECHO flags (you usually
do if you want to prevent the screen from getting messed up, so that's
why this function also does that).

Dave