Xref: utzoo comp.unix.questions:22770 comp.unix.wizards:22367 Path: utzoo!attcan!uunet!samsung!umich!yale!mintaka!bloom-beacon!news From: drk@athena.mit.edu (David R Kohr) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Problem with nodelay() in curses(3v) in Sun/OS 4.0.3. Message-ID: <1990Jun8.002108.11536@athena.mit.edu> Date: 8 Jun 90 00:21:08 GMT Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 77 I'm having a problem with the System V curses(3v) provided with Sun/OS 4.0.3. In particular, the nodelay() function, when given the argument TRUE to turn off waiting for a keypress (so that mvgetch() becomes non-blocking), seems simply not to work as advertised. The following program is supposed to read a character from the terminal, then display the character, number of repetitions through the loop, and number of times no character was present to be read. It stops when 'q' is pressed. The program works fine when the call "nodelay(stdscr, FALSE);" is used: mvgetch() waits for a keypress, as it should. But the call "nodelay(stdscr, TRUE);" causes funny things to happen: a lot of the repetitions through the loop aren't displayed, and when you first press a character, the program "hangs" (no more displays at all), but it's really still going through the loop, since if you stop the process with ^Z, you get an updated display showing a higher number of repetitions than before. Also, even if you do press 'q', the program can't be stopped unless you kill it with ^C. The halfdelay() function also doesn't work properly: if I substitute "halfdelay(n);" for the nodelay() call, where n is anything between 1 and 255, mvgetch() still blocks (just like with "nodelay(stdscr, TRUE);"), rather than using a timeout like it's supposed to. I compiled the program with /usr/5bin/cc, so I think all the right headers and libraries were used. Here's the program: --------------- #include /* Main function: repeatedly read character, displaying character read, iteration number, and number of instances of no character present, at end of each iteration. If character is 'q', end loop. */ void main() { int lastc = 0, /* Last char read from keyboard */ reps = 0, /* Repetitions of loop */ errs = 0; /* Occurences of ERR */ initscr(); cbreak(); noecho(); nodelay(stdscr, TRUE); /* Here's the call. */ while (lastc != 'q') { if ((lastc = mvgetch(1, 1)) == ERR) errs++; mvprintw(2, 1, "Last character: %x ('%c')", lastc, lastc & 0xFF); mvprintw(3, 1, "Repetition number: %d", ++reps); mvprintw(4, 1, "Occurrences of ERR: %d", errs); refresh(); } endwin(); } --------------- If anyone can show me how to get this to work, I'd be much obliged. Otherwise, if someone could explain to me how to do a non-blocking test for a keypress (i.e., mvgetch() in nodelay(stdscr, TRUE) mode) using the Berkeley curses(3x) package supplied with Sun/OS, that would probably solve my problem also. Thanks in advance, -- David R. Kohr M.I.T. Lincoln Laboratory Group 45 ("Radars 'R' Us") email: DRK@ATHENA.MIT.EDU (preferred) or KOHR@LL.LL.MIT.EDU phone: (617)981-0775 (work) or (617)527-3908 (home)