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

John Campbell jdc at naucse.UUCP
Wed Mar 1 02:58:53 AEST 1989


I'm trying to implement some getch(), getche(), and kbdhit() type
routines under SysV (on a 3b1 actually).  I've done the following
kind of thing:

snippet for getch():

      if (ioctl (fileno(keyboard), TCGETA, &term_s) < 0) Fail;
      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;
      term_state = 2;  /* getche state */
   }
   i = getc(keyboard);
which works well enough, except I would like the time limit (MIN)
stored in .c_cc[VEOL] to really be infinite.

Question 1: Does 0 or -1 work as a "special" infinite value here?


As for kbdhit() (returns 1 if there is anything in the typeahead
buffer):

      if (ioctl (fileno(keyboard), TCGETA, &term_s) < 0) Fail;
      term_s.c_lflag &= ~ICANON;
      term_s.c_cc[VEOF] = 1;  /* One character reads */
      term_s.c_cc[VEOL] = 1;  /* .1 second read */
      if (ioctl (fileno(keyboard), TCSETA, &term_s) < 0) Fail;
      term_state = 3;  /* getche state */
   }
/* Well, all I can think to do is read, and push back... */
   i = getc(keyboard); 
   ungetc(i,keyboard);
   if (i > 0)  {   /* Assume EOF is < 0... */

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?


	John Campbell               ...!arizona!naucse!jdc
                                    CAMPBELL at NAUVAX.bitnet
	unix?  Sure send me a dozen, all different colors.
-- 
	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