Curses bug in halfdelay() ?

Ken Weaverling weave at brahms.udel.edu
Mon Dec 24 11:21:06 AEST 1990


I am trying to get the halfdelay() routine in curses to implement a timeout
on a getch() call. It simply blocks and doesn't return. This same test program
I set up (included below) works fine on a Sun 4 using /usr/5bin/cc to compile.
I have tried cc and gcc on my box, but none work.

Machine and OS specifics:

Prime EXL 325, 386 Multibus II box
AT&T Unix Sys V 3.1 version 2

What I have tried to resolve problem:

Compiled on a Sun 4 with /usr/5bin/cc. Works as advertised
Tried sending an alarm (signal 14) to the process to see if some code in curses
set an alarm() and signal trap. No go, the program aborted with an Alarm Call
Read the manual over and over to see if I was missing something.


Since this works on a Sun, I doubt that the problem is with my code. So I'd
like to determine if the problem is limited to my machine, or is a bug that
appears in other 386 UNIX implementations.

Another question: If this is a bug and I have to give up hope on this, I was
planning on just using an alarm() for one second just before the call to 
getch(). Is there any problems that can crop up with this approach? 

I don't want to use nodelay() to stop blocking since I don't want to run
some tight CPU intensive loop looking for something to do. 

Thanks and Happy Whatever! (sample code next)


#include <curses.h>

main() {
  char linebuf[80];
  int keypress = 0;

  initscr();
  noecho();  /* I have also tried leaving this out and putting in cbreak() */
  halfdelay(20);
  addstr("Ready to do keyboard timeout test. Press q when done.");
  while (keypress != 'q') {
    addstr("\nEnter a key: ");
    keypress = getch();
    if (keypress == ERR) {
      addstr("\nYou did not respond in time!");
      refresh();
      sleep(1);
    }
    else {
      sprintf(linebuf, "\nYou pressed the %c key", keypress);
      addstr(linebuf);
      refresh();
      sleep(1);
    }
  }
  endwin();
}
-- 
>>>---> Ken Weaverling  >>>---->  weave at brahms.udel.edu



More information about the Comp.unix.sysv386 mailing list