[comp.unix.questions] Problems with CURSES on Vax11/780

sdussin@dgis.dtic.dla.mil (Steve Dussinger) (11/30/89)

I am having some difficulty using CURSES on a VAX 11/780, and was
wondering if someone out there could give me some help.

The problem is, I have created a window (usnig newwin), that is
10 rows by 60 columns on a Vt100.  Into this window I attempt
to print a string of _exactly_ 600 characters, using:

	wprintw(window,"%s",buffer);

where window is of type WINDOW *, and buffer is of type char *.

When I attempt to print this 600-char string, I get a Segmentation
Violation.

The strange thing about this is, if I try to print the buffer 
above, one char at a time, using:

	wprintw(window,"%c",*buffer++);

The program works fine.

The other interesting thing is, when I initially built the program,
I used a smaller window.  In the smaller version printing the string
all at once worked fine, but when I increased the size of the window
and buffer, it all fell apart.

Does anyone out there have any idea what I'm doing wrong?? I can't
find anything wrong with the code, all my pointers are correct, and
the string I'm tryin to print is null-terminated and exactly 600
chars.  I'm starting to lose my mind, here. Somebody please help....


				Thanx in advance,

				   Steve Dussinger

sdussin@dgis.dtic.dla.mil
sdussin@dev.dtic.dla.mil

chris@mimsy.umd.edu (Chris Torek) (11/30/89)

In article <678@dgis.dtic.dla.mil> sdussin@dgis.dtic.dla.mil
(Steve Dussinger) writes:
>... to print a string of _exactly_ 600 characters, using:
>	wprintw(window,"%s",buffer);
>... When I attempt to print this 600-char string, I get a Segmentation
>Violation.

Do you suppose it might have something to do with this?

	_sprintw(win, fmt, args)
	WINDOW	*win;
	char	*fmt;
	int	*args; {

		FILE	junk;
		char	buf[512];

		junk._flag = _IOWRT + _IOSTRG;
		junk._ptr = buf;
		junk._cnt = 32767;
		_doprnt(fmt, args, &junk);
		putc('\0', &junk);
		return waddstr(win, buf);
	}

600 characters should fit comfortably in a 512 character buffer, right? :-(
(One wonders why Ken Arnold set _cnt to 32767 when he could tell that the
buffer size was only 512.  Had he tried 512, he would have discovered the
next bug, this one in _doprnt/fflush....)

This is why I changed it to:

	static int
	_winwrite(cookie, buf, n)
	void	*cookie;
	reg char *buf;
	int	n; {
		reg WINDOW *win = cookie;
		reg int c = n;
		while (--c >= 0) {
			if (waddch(win, *buf++) == ERR)
				return (-1);
		}
		return n;
	}

	_sprintw(win, fmt, args)
	WINDOW	*win;
	char	*fmt;
	int	*args; {			/* XXX */

		FILE	*f;

		if ((f = fwopen((void *)win, _winwrite)) == NULL)
			return ERR;
		(void) vfprintf(f, fmt, args);	/* XXX */
		return fclose(f) ? ERR : OK;
	}

Alas, this will not work anywhere else.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris