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

next in thread | previous in thread | raw e-mail | index | archive | help
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?20020711215855.GB21234>