Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Jun 1997 12:29:58 -0400 (EDT)
From:      Tim Vanderhoek <hoek@hwcn.org>
To:        MARK SAYER <MSAYER@cuscal.com.au>
Cc:        "'freebsd-hackers@freebsd.org'" <freebsd-hackers@FreeBSD.ORG>
Subject:   RE: BSD io
Message-ID:  <Pine.GSO.3.96.970625113624.11321B-100000@james.freenet.hamilton.on.ca>
In-Reply-To: <199706250208.TAA23288@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 25 Jun 1997, MARK SAYER wrote:

> I have been looking for this for ages. I resorted to using ncurses, but
> then I was stuck with using ncurses window management (yuk). So, I tried
> the code below and it doesn't seem to work as promised. I just want the
> program to trap 1 keypress and continue execution.

Ok, that's what it will do...  Alternatively, you twiddle it such
that getchar() returns immediately regardless of wether there's
input available or not (although I don't know what return value
it uses in the latter case).


> #include <termios.h>
> #include <stdio.h>
> 
> struct termios old, new;
> 
> main()
> {
> char c;

Since I see J'oerg read this, I'm surprised he didn't beat-up on
you for not making this an int c;...  :)  (It's better as an int,
of course)

> tcgetattr (fileno(stdin), &old); new = old;
> 
> new.c_iflag &=~(ICANON|ECHO);

It doesn't help that you changed the above from

new.c_lflag &=
to
new.c_iflag &=

...

> tcsetattr (fileno(stdin), TCSANOW, &new);
> 
> c = getc(stdin);
> 
> tcsetattr (fileno(stdin), TCSANOW, &old);
> }


> All it seems to do is stop trapping my CR key??                

That's because c_iflag controls, what you used, is for input
flags, but c_lflag is for local flags, what I used in the code
you tried to copy.  :)

Additionally, there're also c_cflags, c_oflags for control and
ouput options, respectively.  termios(4) lists all the flags.
Various /usr/include/* files also describe some.

 
> 168: {9} ./a.out
> 
> a^M^M^M^Mò

Disabling IEXTEN won't really solve your problem.  Just change
c_iflags to c_lflags...


> Any ideas?

Yes.  See above.


--
Outnumbered?  Maybe.  Outspoken?  Never!
tIM...HOEk





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