Xref: utzoo comp.sys.att:5705 comp.unix.questions:11952 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!noao!arizona!naucse!jdc From: jdc@naucse.UUCP (John Campbell) Newsgroups: comp.sys.att,comp.unix.questions Subject: Re: termio under SysV (kbdhit() and getch()) Summary: Wierd! Bizzare! (I made a bad assumption...) Keywords: typeahead peek, timeout on reads Message-ID: <1182@naucse.UUCP> Date: 1 Mar 89 18:16:24 GMT References: <1174@naucse.UUCP> Distribution: usa Organization: Northern Arizona University, Flagstaff, AZ Lines: 40 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@NAUVAX.bitnet unix? Sure send me a dozen, all different colors.