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:[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to