From owner-freebsd-hackers Thu Jul 11 14:59: 4 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5007337B400 for ; Thu, 11 Jul 2002 14:59:00 -0700 (PDT) Received: from smtp.noos.fr (aragon.noos.net [212.198.2.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3CAD543E09 for ; Thu, 11 Jul 2002 14:58:59 -0700 (PDT) (envelope-from root@gits.dyndns.org) Received: (qmail 4994134 invoked by uid 0); 11 Jul 2002 21:58:57 -0000 Received: from unknown (HELO gits.gits.dyndns.org) ([212.198.229.153]) (envelope-sender ) by 212.198.2.75 (qmail-ldap-1.03) with SMTP for ; 11 Jul 2002 21:58:57 -0000 Received: from gits.gits.dyndns.org (c075sowzlprhdjsf@localhost [127.0.0.1]) by gits.gits.dyndns.org (8.12.5/8.12.5) with ESMTP id g6BLwuTL022813; Thu, 11 Jul 2002 23:58:56 +0200 (CEST) (envelope-from root@gits.dyndns.org) Received: (from root@localhost) by gits.gits.dyndns.org (8.12.5/8.12.5/Submit) id g6BLwtcv022812; Thu, 11 Jul 2002 23:58:55 +0200 (CEST) (envelope-from root) Date: Thu, 11 Jul 2002 23:58:55 +0200 From: Cyrille Lefevre To: bruno schwander Cc: hackers@FreeBSD.ORG Subject: Re: termios guru ? Message-ID: <20020711215855.GB21234@gits.dyndns.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.99i Organization: ACME X-Face: V|+c;4!|B?E%BE^{E6);aI.[< List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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