Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jul 2002 15:08:00 -0700 (PDT)
From:      bruno schwander <bruno@tinkerbox.org>
To:        Cyrille Lefevre <cyrille.lefevre@laposte.net>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: termios guru ?
Message-ID:  <Pine.BSF.4.21.0207111505070.7694-100000@duron.bschwand.net>
In-Reply-To: <20020711215855.GB21234@gits.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
thanks, I see the idea but cfmakeraw has some other effects... newlines
output by the program are not translated, etc.

My main program now is the VMIN/VTIME stuff. The way irit tries to use is,
is basically to be able to do async stdin reading, but this does not
work. Whenever I try those settings, no input is ever read by the
program. It fgetc() constantly returns -1.

Any idea why ?

bruno

On Thu, 11 Jul 2002, Cyrille Lefevre wrote:

> On Wed, Jul 10, 2002 at 09:13:18PM -0700, bruno schwander wrote:
> > I making a port (not much really) of Irit
> > (http://www.cs.technion.ac.il/~irit/) a modelling environment.
> > 
> > I am having some problems with terminal handling, so all termios guru out
> > there, please help ! :-)
> > 
> > At stratup, irit does the following
> > 
> > Termio.c_cc[VEOF] = 0;  /* MIN = 0, no minimal length to wait for. */
> > Termio.c_cc[VEOL] = 1;  /* TIME - 1 tenth of a second as time o
> > 
> > which seems wrong, I think it should be
> > 
> > Termio.c_cc[VMIN] = 0;  /* MIN = 0, no minimal length to wait for. */
> > Termio.c_cc[VTIME] = 1;  /* TIME - 1 tenth of a second as time o
> 
> VMIN == VEOF and VTIME == VEOL.
> 
> > then later:
> > 
> > Termio.c_lflag &= ~ICANON;
> 
> take a look at cfmakeraw(3) which is BSD specific, but that's
> not important since it's a port *to* BSD :)
> 
> more +/cfmakeraw /usr/src/lib/libc/gen/termios.c
> 
> cfmakeraw(t)
>         struct termios *t;
> {
> 
>         t->c_iflag &= ~(IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR);
>         t->c_iflag |= IGNBRK;
>         t->c_oflag &= ~OPOST;
>         t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN);
>         t->c_cflag &= ~(CSIZE|PARENB);
>         t->c_cflag |= CS8|CREAD;
>         t->c_cc[VMIN] = 1;
>         t->c_cc[VTIME] = 0;
> }
> 
> so, a short answer could be, as Bernd Walter suggested :
> 
> int
> settty(raw)
> 	int raw;
> {
> 	static int init;
> 	static struct termios old;
>         struct termios buf, *new;
> 
> 	if (!init) {
> 		if (tcgetattr(STDIN_FILENO, &old) < 0) {
> 			printf("tcgetattr failed: %s\n", strerror(errno));
> 			return(1);
> 		}
> 		init++;
> 	}
> 	if (raw) {
> 		if (init < 2) {
> 			cfmakeraw(&buf);
> 			init++;
> 		}
> 		new = buf;
> 	} else
> 		new = old;
>         if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) < 0) {
>                 printf("tcsetattr failed: %s\n", strerror(errno));
>                 return(1);
>         }   
> 	return(0);
> }
> 
> Cyrille.
> -- 
> Cyrille Lefevre                 mailto:cyrille.lefevre@laposte.net
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0207111505070.7694-100000>