Abusing `curses' WINDOW structure

Guy Harris guy at sun.uucp
Wed Sep 24 16:42:28 AEST 1986


> I'm writing a program which uses the curses library, and need to
> include a "print screen" type of utility.  Rather than reproducing
> my display logic in order to print a text file image, I was thinking
> of simply copying the screen from stdscr->_y directly into my textfile
> (adding newlines where appropriate). ...
> Now, my machine uses termcap, and this seems to work OK.  The question
> is, is the WINDOW structure different in the terminfo implementation?
> And if so, can the routine above be rewritten and made to work?

"Abusing" is right!  Assuming you "know" what an unadvertised data structure
of a package looks like is a great way to get into trouble.

Yes, the window structure is different, although that sort of thing will
sort of work.  Don't do it, though.  There is a macro "winch" that returns
the "character" at the current position on the screen.  Use that instead.
"character" is in quotes, because it masks out the character attributes in
the 4BSD "curses" but not the S5 "curses".  You should mask the result of
that operation with 0177 if you just want the character.  (Note that your
sample code would not work properly for characters in standout mode; the raw
data in the screen buffer has high bits set if the character has an
attribute turned on.)

This stuff is documented both in the 4.2BSD and the S5 "curses"
documentation.  Please, people, before you decide you have no choice but to
sneak around the back door of a facility, check out the documentation - in
painful detail, if need be - first!
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list