[comp.unix.xenix] Curses Problem

ray@madnix.UUCP (Ray P. Hill) (12/13/88)

Curses Experts:

	Why does the following curses code sample produce a different output
	on UNIX systems?

	Some machines produce and map both windows while others map both
	windows to the same location on the screen. Our VAX, Sun3, 386i, and
	286 XENIX machines work correctly (2 windows), while 386 XENIX and
	Pyramid (AT&T universe) work incorrectly (1 window).

	|-----|			|-----|
	|     |			|     |
	|  |-----| = Working	|     | = Broken
	|  |     |		|     |
	|--|     |		|-----|
 	   |     |
  	   |-----|

	Can someone show me how to make this code sample work?

						Thanks.
						Ray Hill
						ray@madnix
---- Cut Here ----
echo x - test.c
cat > "test.c" << '//E*O*F test.c//'
/*  COMPILE WITH:
 *  cc -O -o test test.c -lcurses -ltermcap
 */

#include	<curses.h>

main()
  {
  WINDOW	*win;

  initscr();
  win = newwin(10, 10, 0, 0);
  box(win, '|', '-');
  overwrite(win, stdscr);
  win = newwin(10, 10, 5, 5);
  box(win, '|', '-');
  overwrite(win, stdscr);
  move(16, 0);
  refresh();
  endwin();
  }
//E*O*F test.c//

exit 0
-- 
UUCP: {harvard|rutgers|ucbvax}!uwvax!astroatc!nicmad!madnix!ray
                                 {decvax|att}!      !
                               {uunet|ncoast}!marque!

dean@violet.berkeley.edu (Dean Pentcheff) (12/14/88)

In article <263@madnix.UUCP> ray@madnix.UUCP (Ray P. Hill) writes:
>	Why does the following curses code sample produce a different output
>	on UNIX systems?
>	Some machines produce and map both windows while others map both
>	windows to the same location on the screen. Our VAX, Sun3, 386i, and
>	286 XENIX machines work correctly (2 windows), while 386 XENIX and
>	Pyramid (AT&T universe) work incorrectly (1 window).
>
> [ code including overwrite()... ]

A couple of weeks ago I spent some time testing overwrite()
extensively.  I checked it on BSD 4.3 running on a VAX, AT&T System
V/R2 (Microport SV/AT 2.2.1L) running on an AT clone, and MS-DOS (using
Bjorn Larsson's PCurses and the Turbo C 1.5 compiler).  I found that
overwrite() was broken (though with subtle differences) on both BSD and
System V.  It worked correctly only on PCurses.  I got a note from a
fellow at AT&T who said that they knew about the bug in earlier System
Vs, and the problem was completely corrected in the forthcoming System
V release (V4, is it?).

Anyway, I concluded that overwrite() (and probably overlay()) are too
commonly broken to allow portability.  This is a sucky answer, but:
your code is right, the library is bugged, and I think you should avoid
using overwrite().

-Dean

Dean Pentcheff        dean@violet.berkeley.edu
----------------------------------------------
As an adolescent I aspired to lasting fame, I craved factual certainty, and I
thirsted for a meaningful vision of human life - so I became a scientist.  This
is like becoming an archbishop so you can meet girls.               M. Cartmill

andre@targon.UUCP (andre) (12/14/88)

In article <263@madnix.UUCP> ray@madnix.UUCP (Ray P. Hill) writes:
>	Why does the following curses code sample produce a different output
>	on UNIX systems?
Because some implementations are not correct, the berkeley curses manual
speaks of overwrite at the same x y coordinates, but the terminfo curses
manual just speaks of overwriting. On the system I am on, a Pyramid only
the row information is used. The 'broken' picture becomes:
|------|
|      |
|------|
|      |
|      |
|------|

>/*  COMPILE WITH:
> *  cc -O -o test test.c -lcurses -ltermcap
> */
Making the name 'test' was a joke, right?

The way I 'solved' the wrong behaviour of the pyramid curses was to
make a subwin on the screen I wanted to overwrite with the same dimensions
& the same position as the source window. This will work on all curses'es

    WINDOW *w, *subw;
    initscr();
    w = newwin(10, 10, 5, 5);
    subw = subwin(stdscr, 10, 10, 5, 5);
    box(w, 0, 0);
    overwrite(w, subw);

Or, if you know the size and position of all windows in your application
you can use a function like:

    my_overwrite(src, dest, lines, cols, orgy, orgx)
    WINDOW *src, *dest;
    int lines, cols, orgy, orgx);
    {
	    WINDOW *sub = subwin(dest, lines, cols, orgy, orgx);

	    if (sub)
	    {
		overwrite(src, sub);
		delwin(sub);
	    }
    }

By the way, beware of overwrite with curscr.

	Hope this helps, Andre

-- 
~----~ |m    AAA         DDDD  It's not the kill, but the thrill of the chase.
~|d1|~@--   AA AAvv   vvDD  DD        Segment registers are for worms.
~----~  &  AAAAAAAvv vvDD  DD
~~~~~~ -- AAA   AAAvvvDDDDDD        Andre van Dalen, uunet!mcvax!targon!andre