* Problems with curses (D.U. 3.2C)
@ 1997-09-17 4:00 W. Robert J. Funnell
0 siblings, 0 replies; only message in thread
From: W. Robert J. Funnell @ 1997-09-17 4:00 UTC (permalink / raw)
I've been trying to implement a C function under Digital Unix which
will use curses to emulate some old VMS Fortran single-character
keyboard-input subroutine. I want to be able to mix blocking and
non-blocking input, and be able to check whether any input is ready to
be read. I've implemented these functions by using nodelay() to turn
blocking on/off, and by using getwch/ungetwch to read a character and
then put it back into the queue. In the test programme appended below,
things seem to work properly until I check for input using the
getwch/ungetwch functions. After that, curses does not return to wait
mode, although it does successfully return to wait mode earlier in the
programme.
I have doubts about mixing wide characters with regular ones, but
there doesn't seem to be an unget function for regular characters in
the curses included with Digital Unix 3.2C. In any case, I tried to
implement the checking functionality by using a regular getch and
saving the character, and the problem remained.
When I looked at the values returned by the nodelay() functions, even
the ones that seem to work return ERR (-1) instead of OK (0), or
sometimes seem to return character codes.
I've installed ncurses and linked the same test programme (replacing
getwch/ungetwch by getch/ungetch) to that library and then it works
fine.
Does anyone see something wrong in my code, or know about bugs in
the Digital Unix curses library?
Thanks.
- W. Robert J. Funnell, Ph.D., Eng., Assoc. Prof.
Dept. BioMedical Engineering
McGill University
R.Funnell@med.mcgill.ca
------------------------------------------------------------------------------
#include <curses.h>
void main() {
char chr;
int wchr; /* wide character for getwch/ungetwch */
int iret;
initscr(); /* initialize curses */
cbreak(); /* allow immediate access to chars typed */
noecho(); /* turn off automatic echo */
mvaddstr(2,3, "TESTING NO-WAIT MODE" );
refresh();
do {
iret = nodelay(stdscr,TRUE); /* suppress wait for kbd input */
mvprintw(2,30,"iret=%i",iret); refresh();
chr = getch(); /* get char if there is one */
iret = nodelay(stdscr,FALSE);/* turn waiting back on */
mvprintw(2,40,"iret=%i",iret); refresh();
} while ( chr == ERR );
mvprintw(3,3, "The character pressed was %s",&chr); refresh();
mvaddstr(4,3, "TESTING WAIT MODE" );
refresh();
chr = getch(); /* wait for char to be typed */
mvprintw(5,3, "The character pressed was %s",&chr); refresh();
/* check until a char is available, then retrieve it in wait mode */
/* and continue retrieving until 'Q' is pressed */
mvaddstr(6,3, "Testing check mode" ); refresh();
do {
iret = nodelay(stdscr,TRUE); /* suppress wait for kbd input */
mvprintw(6,30,"iret=%i",iret); refresh();
wchr = getwch(); /* get wide char if there is one */
} while ( wchr == ERR );
ungetwch(wchr); /* put it back on queue */
nodelay(stdscr,FALSE); /* turn waiting back on */
mvprintw(6,40,"iret=%i",iret); refresh();
mvaddstr(7,3, "Testing wait mode" ); refresh();
chr = getch();
mvprintw(8,3, "The character pressed was %s",&chr); refresh();
chr = getch();
mvprintw(9,3, "The character pressed was %s",&chr); refresh();
chr = getch();
mvprintw(10,3, "The character pressed was %s",&chr); refresh();
/* terminate */
mvaddstr(11,3, "Terminating "); refresh();
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-09-17 4:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-09-17 4:00 Problems with curses (D.U. 3.2C) W. Robert J. Funnell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox