Curses question

Jerre Bowen bowen at wanda.SGI.COM
Tue Nov 27 09:29:16 AEST 1990


Michael Hart writes:
> 
> Anyway, the prog quits with a ctl-C, and is supposed to clear the
> screen.  I've tried werase(stdscr), wclear(stdscr), and with & without
> a wrefresh(stdscr).  Am I being brain-dead, or is something funky
> with curses on SGI?
> 
> #include <curses.h>
> 
> main()
> {
> 	char *theStr = "Hello, World!  Using Curses!!\n";
> 	chtype theInput;
> 	int repCtr = 0;
> 
> /*	some curses initialization items first 
> 	init the curses code
> 	call character mode for input (cbreak)
> 	set noecho
> 	set to clear input buffer on an interrupt intrflus
> */
> 	initscr();
> 	cbreak();
> 	noecho();
> 	intrflush();
> 	nodelay(stdscr,TRUE);
> 	scrollok(stdscr,TRUE);
> 
> 	theInput = wgetch(stdscr);
> 	while ( theInput != KEY_END) {
> 		addstr(theStr);
> 		repCtr++;
> 		wprintw(stdscr,"%d \n",repCtr);
> 		theInput = wgetch(stdscr);
> 	}
> 	wclear(stdscr);
> 	wrefresh(stdscr);
> 	endwin();
> }

> Michael G. Hart   hart at blackjack.dt.navy.mil /  mhart at oasys.dt.navy.mil
> 

	cbreak() mode delivers characters to the program one by one, but
interrupt characters still cause signals to be sent the program, so when
you <ctrl>-c the program (as you say above if I understand correctly)
the process is terminated unnaturally via a SIGINT and therefore never
hits the wclear() and etc.  You must catch SIGINT (using sigset(), for
example) if you intend to use <ctrl>-c as the termination sequence.  I
think there are other bugs in this program, however, just glancing at
the curses man page--initscr() needs some parameters and I don't think
using KEY_END is legit without first initializing the keypad.


	Jerre Bowen
	bowen at sgi.com



More information about the Comp.lang.c mailing list