termio under SysV (kbdhit() and getch())

John Campbell jdc at naucse.UUCP
Thu Mar 2 04:16:24 AEST 1989


In a previous article, I wrote:
: 
: I'm trying to implement getch(), getche(), and kbdhit() 
: 
: snippet for getch():
:       term_s.c_lflag &= ~ICANON;
:       term_s.c_cc[VEOF] = 1;  /* One character reads */
:       term_s.c_cc[VEOL] = 0x7f;  /* 12.7 seconds (best?) */
:       if (ioctl (fileno(keyboard), TCSETA, &term_s) < 0) Fail;
: 
: Question 1: Does 0 or -1 work as a "special" infinite value here?

It turns out I misread the documentation.  Unlike another (to remain
unamed) operating system I use, the MIN time is not the timeout value
of the read, but rather the required number of 1/10 seconds the read
must take!  Anyone want to tell me how useful this is?  The other
interpretation I've made use of (under the mystery operating system)
to implement automatic paging, etc.  Anyway, Question 1 is no longer
an issue--the reads always block, regardless of the MIN value.
 
: As for kbdhit() (returns 1 if there is anything in the typeahead
: buffer):
:       term_s.c_cc[VEOL] = 1;  /* .1 second read */
:       if (ioctl (fileno(keyboard), TCSETA, &term_s) < 0) Fail;
: all I could think of doing was read with a .1 second time limit and see
: if anything came in (and, of course, push it back if nothing did). 
: 
: Question 2: Can anyone think of a better (more direct way) of finding out
:             if anything is in the typeahead under SysV unix?

And the bad news is that I no longer have a valid plan for implementing
a peek into the typeahead buffer at all!  Anyone know if this can be done
under SysV?  (And, of course, how it is done?)

Thanks to all, patience requested of some, for who knows who else might be
as confused as I appear to be?
-- 
	John Campbell               ...!arizona!naucse!jdc
                                    CAMPBELL at NAUVAX.bitnet
	unix?  Sure send me a dozen, all different colors.



More information about the Comp.sys.att mailing list