iain@estevax.UUCP (Hr Iain Lea) (04/02/91)
I have been given the task of porting a BSD program to SYSV. I have run into a problem with the terminal io. I need to set RAW, CBREAK and unset ECHO using termio. We have no SYSV docs at the moment so can anyone post/send an example? Thanx Iain PS. Is there a BSD to SYSV porting guide available on the net ?
decot@hpisod2.cup.hp.com (Dave Decot) (04/09/91)
/* Routines for managing nonechoing, one-character-at-a-time tty reads */
/* Dave Decot, hpda!decot, 851023 */
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#ifdef BSD
# include <sgtty.h>
#else /* not BSD */
# include <termio.h>
#endif
quit()
{
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, SIG_IGN);
normal();
exit(0);
}
setup()
{
signal(SIGQUIT, quit);
signal(SIGHUP, quit);
signal(SIGTERM, quit);
cbreak();
}
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;
}
}