[net.sources] Windows bug fixes

chris@umcp-cs.UUCP (07/15/83)

The first (& hopefully only, but I doubt it) windows bug reports have
been been received.  The following bugs have been discovered by
greg@crystal (Greg Johnson):

1.  WBinschars doesn't work.  Neither does WBdelchars.  [Hm, I must
have missed those; I thought I had tested everything.  Sigh.]

2.  The documentation for Wsetmargins is incorrect.  [Setmargins
changed about a month before the release, but the documentation
didn't.]

Here are the fixed source files binschars.c and bdelchars.c.  Also
included is a new version of init.c, which defaults to homing the
cursor after refreshes, a note that the version number in open.c should
be changed to 1.04, and a diff listing for the documentation to correct
#2 and note the changed default on real-cursor positioning.

Keep the news coming, good or bad!

				- Chris

: Run this shell script with "sh" not "csh"
PATH=:/bin:/usr/bin:/usr/ucb
export PATH
all=FALSE
if [ $1x = -ax ]; then
	all=TRUE
fi
/bin/echo 'Extracting bdelchars.c'
sed 's/^X//' <<'//go.sysin dd *' >bdelchars.c
X#include "win.h"
X
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X
X/* Delete n chars from buffer at cursor */
XWBdelchars (w, n)
XWin *w;
Xint n;
X{
X	register Buf *b;
X	register Ch *cp, *ct, *cend;
X	int blank;
X
X	if (n < 0)
X		return -1;
X	if (n == 0)
X		return 0;
X	b = w -> w_textbuf;
X	if (n + b -> b_cursor.col > b -> b_ncols)
X		n = b -> b_ncols - b -> b_cursor.col;
X	blank = ' ' | (w -> w_mode << NBPB);
X
X	ct = b -> b_contents + b -> b_cursor.row * b -> b_ncols;
X	cend = ct + b -> b_ncols;
X	ct += b -> b_cursor.col;
X	cp = ct + n;
X	while (cp < cend)
X		ct++ -> ch_all = cp++ -> ch_all;
X	while (ct < cend)
X		ct++ -> ch_all = blank;
X	b -> b_nmodw = -1;
X	return 0;
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 bdelchars.c
	/bin/echo -n '	'; /bin/ls -ld bdelchars.c
fi
/bin/echo 'Extracting binschars.c'
sed 's/^X//' <<'//go.sysin dd *' >binschars.c
X#include "win.h"
X
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X
X/* Insert n blanks in buffer at cursor */
XWBinschars (w, n)
XWin *w;
Xint n;
X{
X	register Buf *b;
X	register Ch *cp, *ct, *start;
X	int blank;
X
X	if (n < 0)
X		return -1;
X	if (n == 0)
X		return 0;
X	b = w -> w_textbuf;
X	if (n + b -> b_cursor.col > b -> b_ncols)
X		n = b -> b_ncols - b -> b_cursor.col;
X	blank = ' ' | (w -> w_mode << NBPB);
X
X	ct = b -> b_contents + b -> b_cursor.row * b -> b_ncols;
X	start = ct + b -> b_cursor.col;
X	ct += b -> b_ncols;
X	cp = ct - n;
X	while (cp > start)
X		(--ct) -> ch_all = (--cp) -> ch_all;
X	while (ct > start)
X		(--ct) -> ch_all = blank;
X	b -> b_nmodw = -1;
X	return 0;
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 binschars.c
	/bin/echo -n '	'; /bin/ls -ld binschars.c
fi
/bin/echo 'Extracting init.c'
sed 's/^X//' <<'//go.sysin dd *' >init.c
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X/* 	Original code copyright (c) 1981,1980 James Gosling	*/
X
X/* ACT 11-Nov-1982 modified for window package */
X/* ACT 14-Jul-1983 changed to default to homing cursor */
X
X#include "win.h"
X#include "display.h"
X#include <sys/ioctl.h>
X#include <sgtty.h>
X#include <stdio.h>
X#include <signal.h>
X
Xstruct sgttyb WOld;		/* The initial tty mode bits */
Xint	WTtyFd;			/* File descriptor for stty/gtty */
Xint	(*sigset())();
Xextern	Wexit (), Wsuspend ();
X
X/* Init window system.  If settings == 1, use previous settings.  If
X   settings == 0, use default settings.  Otherwise use "settings" settings.
X   If nomagic != 0, don't catch stop, interrupt, and terminate signals.
X   RETURNS: 0 if OK to continue using window system, anything else to
X   indicate that the CRT is unusable. */
XWinit (settings, nomagic)
Xstruct sgttyb *settings;
X{
X    static struct sgttyb   sg;
X    int rv;
X    static int beenhere;
X    extern char _sobuf[];
X
X    WTtyFd = 0;
X
X    /* I dont know how system specific this is, but here goes: */
X    if ((stdout->_flag & (_IOLBF|_IONBF)) == 0 && stdout->_base == NULL)
X	setbuf (stdout, _sobuf);
X
X    /* I should use isatty, but it just does a gtty anyway, so why bother? */
X    /* Note: if both of these fail then "we ain't talkin' to no terminal" */
X    /* NOTE: STRUCTURE ASSIGNMENT */
X
X    if (gtty (0, &WOld) < 0)
X	gtty (WTtyFd = 1, &WOld);
X    if (settings) {
X	if (settings != (struct sgttyb *) 1)
X	    sg = *settings;
X	sg.sg_ispeed = WOld.sg_ispeed;/* My, how suspicious we are */
X	sg.sg_ospeed = WOld.sg_ospeed;
X    }
X    else
X	sg = WOld;
X    sg.sg_flags = (sg.sg_flags & ~(ECHO | CRMOD | XTABS)) | CBREAK;
X    ioctl (WTtyFd, TIOCSETN, &sg);
X    if (!nomagic /*|| SigMagic*/) {
X	SigMagic = 1;
X	sigset (SIGINT, Wexit);
X	sigset (SIGTSTP, Wsuspend);
X	sigset (SIGTERM, Wexit);
X    }
X    ScreenGarbaged = 1;
X
X    /* I wish I didn't have to set everything up yet, but since WDterm_init()
X       expects to be in un-user-usable mode I have to.  Oh well. */
X    /* NOTE: WDterm_init () may only fail on first attempts! */
X    if (rv = WDterm_init ()) {	/* Then we cant run on this terminal */
X	if (SigMagic) {		/* Wonder if this is really necessary? */
X	    sigignore (SIGTSTP);
X	    sigignore (SIGINT);
X	}
X	ioctl (WTtyFd, TIOCSETN, &WOld);
X	if (SigMagic) {
X	    sigset (SIGTSTP, SIG_DFL);
X	    sigset (SIGINT, SIG_DFL);
X	}
X	return rv;
X    }
X    if (W_tt.t_window) (*W_tt.t_window) (0);
X    WindowsActive++;
X    if (!beenhere) {		/* New!! (Be the first on your block!) */
X	beenhere++;
X	if (!WSetRealCursor && !WRCurRow && !WRCurCol)
X	    WSetRealCursor++;	/* Default to homing the cursor.  The idea
X				   here is to get that nasty real cursor
X				   out of the way. */
X    }
X    return 0;
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 init.c
	/bin/echo -n '	'; /bin/ls -ld init.c
fi
/bin/echo 'open.c sccsid: version is now 1.04'
/bin/echo 'Extracting doc_diff'
sed 's/^X//' <<'//go.sysin dd *' >doc_diff
X*** windows.nr.bak	Tue Jul 12 08:18:18 1983
X--- windows.nr	Thu Jul 14 01:54:01 1983
X***************
X*** 529,534
X  If \fBWinit\fR does not return zero, nothing has been done, and none of the
X  other functions should be called.  (\fBWinit\fR will return the same value
X  if called again, so if it said "Ok" once it won't change its mind.)
X  .ff
X  \fBWsuspend ()\fR
X  .fe
X
X--- 529,541 -----
X  If \fBWinit\fR does not return zero, nothing has been done, and none of the
X  other functions should be called.  (\fBWinit\fR will return the same value
X  if called again, so if it said "Ok" once it won't change its mind.)
X+ .pp
X+ The first call to \fBWinit\fR will normally set the variable
X+ \fBWSetRealCursor\fR to one, so that the terminal's real cursor will be
X+ left in the upper left hand corner of the display screen, where it is
X+ presumably out of the way.  However, if any of the variables
X+ \fBWSetRealCursor\fR, \fBWRCurRow\fR, or \fBWRCurCol\fR are set, this first call
X+ will not set \fBWSetRealCursor\fR.
X  .ff
X  \fBWsuspend ()\fR
X  .fe
X***************
X*** 1184,1190
X  function is probably not very useful, but is the only way to change the
X  default frames.
X  .ff
X! \fBWsetmargins (\fIw\fB,\fR \fIinxorg\fB,\fR \fIinxext\fB,\fR \fIinyorg\fB,\fR \fIinyext\fB)
X  Win *\fIw\fB;
X  int\fR \fIinxorg\fB,\fR \fIinxext\fB,\fR \fIinyorg\fB,\fR \fIinyext\fB;\fR
X  .fe
X
X--- 1191,1197 -----
X  function is probably not very useful, but is the only way to change the
X  default frames.
X  .ff
X! \fBWsetmargins (\fIw\fB,\fR \fIinxorg\fB,\fR \fIinyorg\fB,\fR \fIinxext\fB,\fR \fIinyext\fB)
X  Win *\fIw\fB;
X  int\fR \fIinxorg\fB,\fR \fIinyorg\fB,\fR \fIinxext\fB,\fR \fIinyext\fB;\fR
X  .fe
X***************
X*** 1186,1192
X  .ff
X  \fBWsetmargins (\fIw\fB,\fR \fIinxorg\fB,\fR \fIinxext\fB,\fR \fIinyorg\fB,\fR \fIinyext\fB)
X  Win *\fIw\fB;
X! int\fR \fIinxorg\fB,\fR \fIinxext\fB,\fR \fIinyorg\fB,\fR \fIinyext\fB;\fR
X  .fe
X  Sets the margins to the specified values.  \fIInxorg\fR and \fIinyorg\fR
X  specify at what x and y values (relative to the window origin at (0,
X
X--- 1193,1199 -----
X  .ff
X  \fBWsetmargins (\fIw\fB,\fR \fIinxorg\fB,\fR \fIinyorg\fB,\fR \fIinxext\fB,\fR \fIinyext\fB)
X  Win *\fIw\fB;
X! int\fR \fIinxorg\fB,\fR \fIinyorg\fB,\fR \fIinxext\fB,\fR \fIinyext\fB;\fR
X  .fe
X  Sets the margins to the specified values.  \fIInxorg\fR and \fIinyorg\fR
X  specify at what x and y values (relative to the window origin at (0,
X***************
X*** 1723,1733
X  terminal's cursor to a particular row and column after an update is
X  complete.  If not set, the cursor will be left after the last character
X  written.  Often this is immediately following the window cursor, thus
X! making a window appear to have two cursors.  If set, the terminal's
X! cursor will be moved to line \fBWRCurRow\fR, column \fBWRCurCol\fR.  In fact,
X! it is sometimes useful to hide the window's cursor and use the real
X! terminal's cursor.  The following macro may be used to set the
X! variables \fBWRCurRow\fR and \fBWRCurCol\fR to \fIw\fR's window cursor position:
X  .sp
X  .nf
X  .ls 1
X
X--- 1730,1742 -----
X  terminal's cursor to a particular row and column after an update is
X  complete.  If not set, the cursor will be left after the last character
X  written.  Often this is immediately following the window cursor, thus
X! making a window appear to have two cursors.  This looks very odd and is
X! the reason for the foofooraw in \fBWinit\fR to put the cursor at (0, 0).
X! When \fBWSetRealCursor\fR is set, the terminal's cursor will be moved to
X! line \fBWRCurRow\fR, column \fBWRCurCol\fR.  In fact, it is sometimes useful to
X! hide the window's cursor and use the real terminal's cursor.  The
X! following macro may be used to set the variables \fBWRCurRow\fR and
X! \fBWRCurCol\fR to \fIw\fR's window cursor position:
X  .sp
X  .nf
X  .ls 1
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 doc_diff
	/bin/echo -n '	'; /bin/ls -ld doc_diff
fi
-- 
In-Real-Life:	Chris Torek, Univ of MD Comp Sci
UUCP:		{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:		chris@umcp-cs
ARPA:		chris.umcp-cs@UDel-Relay