From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,adf053bb61e56cb4,start X-Google-Attributes: gidfee84,public From: FUNNELL@bmeucl.medcor.mcgill.ca (W. Robert J. Funnell) Subject: Problems with curses (D.U. 3.2C) Date: 1997/09/17 Message-ID: <5vphlv$q8d@sifon.cc.mcgill.ca>#1/1 X-Deja-AN: 273357435 Distribution: world X-News-Reader: VMS NEWS v1.25 Organization: McGill University Faculty of Medicine - Biomedical Engineering Newsgroups: comp.unix.osf.osf1 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 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(); }