#!/bin/sh
# This is `vwcurses.03' (part 3 of a multipart archive).
# Do not concatenate these parts, unpack them in order with `/bin/sh'.
# File `vw_curses/curses/delwin.c' is being continued...
#
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if test ! -r _sharseq.tmp; then
  echo 'Please unpack part 1 first!'
  exit 1
fi
shar_sequence=`cat _sharseq.tmp`
if test "$shar_sequence" != 3; then
  echo "Please unpack part $shar_sequence next!"
  exit 1
fi
if test ! -f _sharnew.tmp; then
  echo 'x - still skipping vw_curses/curses/delwin.c'
else
  echo 'x - continuing file vw_curses/curses/delwin.c'
  sed 's/^X//' << 'SHAR_EOF' >> 'vw_curses/curses/delwin.c' &&
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)delwin.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
# include	"curses.ext"
X
/*
X *	This routine deletes a window and releases it back to the system.
X *
X */
delwin(win)
reg WINDOW	*win; {
X
X	int	err;
X
X	curses_P();
X
X        err=redelwin(win);
X	if (err == ERR) {
X	    curses_V();
X	    return ERR;
X	}
X
X	free(win);
X
X	curses_V();
X	return OK;
}
X
/*
X * We do everything except free(win) here, which is nice for renewwin().
X */
redelwin(win)
reg WINDOW	*win; {
X
X	reg int		i;
X	reg WINDOW	*wp, *np;
X
X	curses_P();
X
X	if (win == NULL) {
X	    curses_V();
X	    return ERR;
X	}
X
X	if (win->_orig == NULL) {
X		/*
X		 * If we are the original window, delete the space for
X		 * all the subwindows, and the array of space as well.
X		 */
X		for (i = 0; i < win->_maxy && win->_y[i]; i++)
X			free(win->_y[i]);
X		free(win->_firstch);
X		free(win->_lastch);
X		wp = win->_nextp;
X		while (wp != win) {
X			np = wp->_nextp;
X			delwin(wp);
X			wp = np;
X		}
X	}
X	else {
X		/*
X		 * If we are a subwindow, take ourselves out of the
X		 * list.  NOTE: if we are a subwindow, the minimum list
X		 * is orig followed by this subwindow, so there are
X		 * always at least two windows in the list.
X		 */
X		for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
X			continue;
X		wp->_nextp = win->_nextp;
X	}
X	free(win->_y);
X
X	curses_V();
X	return OK;
}
SHAR_EOF
  echo 'File vw_curses/curses/delwin.c is complete' &&
  $shar_touch -am 0627091195 'vw_curses/curses/delwin.c' &&
  chmod 0644 'vw_curses/curses/delwin.c' ||
  echo 'restore of vw_curses/curses/delwin.c failed'
  shar_count="`wc -c < 'vw_curses/curses/delwin.c'`"
  test 2170 -eq "$shar_count" ||
    echo "vw_curses/curses/delwin.c: original size 2170, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/initscr.c ==============
if test -f 'vw_curses/curses/initscr.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/initscr.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/initscr.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/initscr.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)initscr.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
# include	"curses.ext"
#ifndef VxWorks
# include	<signal.h>
extern char	*getenv();
#endif
X
/*
X *	This routine initializes the current and standard screen.
X *
X */
WINDOW *
initscr() {
X
X	reg char	*sp;
X	int		tstp();
X	int 		nfd;
X
X	if (curses_seminit() == ERR) {
X		return (WINDOW *)ERR;
X        }
X	curses_P();
# ifdef DEBUG
X	fprintf(outf, "INITSCR()\n");
# endif
X	if (My_term) {
X		if (setterm(Def_term) == ERR) {
X			return (WINDOW *)ERR;
X        	}
X        }
X	else {
X		for (_tty_ch = 0; _tty_ch < nfd; _tty_ch++)
X			if (isatty(_tty_ch))
X				break;
X		gettmode();
#ifndef VxWorks
X		if ((sp = getenv("TERM")) == NULL)
#endif
X			sp = Def_term;
X		if (setterm(sp) == ERR) {
X			return (WINDOW *)ERR;
X        	}
# ifdef DEBUG
X		fprintf(outf, "INITSCR: term = %s\n", sp);
# endif
X	}
X	_puts(TI);
X	_puts(VS);
# ifdef SIGTSTP
X	signal(SIGTSTP, tstp);
# endif
X	if (curscr != NULL) {
# ifdef DEBUG
X		fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
# endif
X		delwin(curscr);
X	}
# ifdef DEBUG
X	fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
# endif
X	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR) {
X		curses_V();
X		return (WINDOW *)ERR;
X        }
X	clearok(curscr, TRUE);
X	curscr->_flags &= ~_FULLLINE;
X	if (stdscr != NULL) {
# ifdef DEBUG
X		fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
# endif
X		delwin(stdscr);
X	}
X	stdscr = newwin(LINES, COLS, 0, 0);
X	curses_V();
X	return stdscr;
}
SHAR_EOF
  $shar_touch -am 0627100095 'vw_curses/curses/initscr.c' &&
  chmod 0644 'vw_curses/curses/initscr.c' ||
  echo 'restore of vw_curses/curses/initscr.c failed'
  shar_count="`wc -c < 'vw_curses/curses/initscr.c'`"
  test 2299 -eq "$shar_count" ||
    echo "vw_curses/curses/initscr.c: original size 2299, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/overwrite.c ==============
if test -f 'vw_curses/curses/overwrite.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/overwrite.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/overwrite.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/overwrite.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)overwrite.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
# include	"curses.ext"
# include	<ctype.h>
X
#ifndef min
# define	min(a,b)	((a) < (b) ? (a) : (b))
# define	max(a,b)	((a) > (b) ? (a) : (b))
#endif
X
/*
X *	This routine writes win1 on win2 destructively.
X *
X */
overwrite(win1, win2)
reg WINDOW	*win1, *win2; {
X
X	reg char	*sp, *end;
X	reg int		x, y, endy, endx, starty, startx;
X
X	curses_P();
X
X	if (win1 == NULL || win2 == NULL) {
X	    curses_V();
X	    return ERR;
X	}
X
# ifdef DEBUG
X	fprintf(outf, "OVERWRITE(%0.2o, %0.2o);\n", win1, win2);
# endif
X	starty = max(win1->_begy, win2->_begy);
X	startx = max(win1->_begx, win2->_begx);
X	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);
X	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
X	if (starty >= endy || startx >= endx) {
X		curses_V();
X		return;
X        }
# ifdef DEBUG
X	fprintf(outf, "OVERWRITE:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
# endif
X	x = endx - startx;
X	for (y = starty; y < endy; y++) {
X		bcopy(&win1->_y[y - win1->_begy][startx - win1->_begx],
X		      &win2->_y[y - win2->_begy][startx - win2->_begx], x);
X		touchline(win2, y - win2->_begy, startx - win2->_begx, endx - win2->_begx-1);         /* had bug: second parm was just 'y', and -1 omitted! */
X	}
X
X	curses_V();
X	return OK;
}
SHAR_EOF
  $shar_touch -am 0627091195 'vw_curses/curses/overwrite.c' &&
  chmod 0644 'vw_curses/curses/overwrite.c' ||
  echo 'restore of vw_curses/curses/overwrite.c failed'
  shar_count="`wc -c < 'vw_curses/curses/overwrite.c'`"
  test 2164 -eq "$shar_count" ||
    echo "vw_curses/curses/overwrite.c: original size 2164, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/scanw.c ==============
if test -f 'vw_curses/curses/scanw.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/scanw.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/scanw.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/scanw.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)scanw.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
/*
X * scanw and friends
X *
X */
# include       <stdarg.h>
# include	"curses.ext"
X
/*
X *	This routine implements a scanf on the standard screen.
X */
scanw(char *fmt, ...)
{
X
X        void *args[10];
X        void *tmp;
X        int count = 0;
X        va_list ap;
X
X        va_start(ap, fmt);
X        while ((tmp = va_arg(ap, void *)) && (count < 10))
X            {
X                args[count] = tmp;
X                count++;
X            }
X        va_end(ap);
X	return _sscans(stdscr, fmt, args);
}
/*
X *	This routine implements a scanf on the given window.
X */
wscanw(WINDOW *win, const char *fmt, ...)
{
X        void *args[10];
X        void *tmp;
X        int count = 0;
X        va_list ap;
X
X        va_start(ap, fmt);
X        while ((tmp = va_arg(ap, void *)) && (count < 10))
X            {
X                args[count] = tmp;
X                count++;
X            }
X        va_end(ap);
X	return _sscans(win, fmt, args);
}
/*
X *	This routine actually executes the scanf from the window.
X *
X *	This is really a modified version of "sscanf".  As such,
X * it assumes that sscanf interfaces with the other scanf functions
X * in a certain way.  If this is not how your system works, you
X * will have to modify this routine to use the interface that your
X * "sscanf" uses.
X *	Note: do not add semaphore locking here! wgetch() must be able
X *            to release semaphore for blocking read.
X */
_sscans(WINDOW *win, char *fmt, void **args)
{
X	uchar_t	buf[100];
X
#ifdef VxWorks
X	if (wgetstr(win, buf) == ERR)
X		return ERR;
X
X        sscanf(buf,fmt,args[0],args[1],args[2],args[3],args[4],args[5],args[6],
X               args[7],args[8],args[9]);
#else
X        FILE	junk;
X                
X	junk._flag = _IOREAD|_IOSTRG;
X	junk._base = junk._ptr = buf;
X	if (wgetstr(win, buf) == ERR)
X		return ERR;
X	junk._cnt = strlen(buf);
X	return _doscan(&junk, fmt, args);
#endif
}
SHAR_EOF
  $shar_touch -am 0627104895 'vw_curses/curses/scanw.c' &&
  chmod 0644 'vw_curses/curses/scanw.c' ||
  echo 'restore of vw_curses/curses/scanw.c failed'
  shar_count="`wc -c < 'vw_curses/curses/scanw.c'`"
  test 2770 -eq "$shar_count" ||
    echo "vw_curses/curses/scanw.c: original size 2770, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/toucholap.c ==============
if test -f 'vw_curses/curses/toucholap.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/toucholap.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/toucholap.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/toucholap.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)toucholap.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
# include	"curses.ext"
X
#ifndef min
# define	min(a,b)	((a) < (b) ? (a) : (b))
# define	max(a,b)	((a) > (b) ? (a) : (b))
#endif
X
/*
X *	Touch, on win2, the part that overlaps with win1.
X *
X */
touchoverlap(win1, win2)
reg WINDOW	*win1, *win2; {
X
X	reg int		x, y, endy, endx, starty, startx;
X
X	curses_P();
X
X	if (win1 == NULL || win2 == NULL) {
X	    curses_V();
X	    return ERR;
X	}
X
# ifdef DEBUG
X	fprintf(outf, "TOUCHOVERLAP(%0.2o, %0.2o);\n", win1, win2);
# endif
X	starty = max(win1->_begy, win2->_begy);
X	startx = max(win1->_begx, win2->_begx);
X	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);
X	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
# ifdef DEBUG
X	fprintf(outf, "TOUCHOVERLAP:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
X	fprintf(outf, "TOUCHOVERLAP:win1 (%d,%d) to (%d,%d)\n", win1->_begy, win1->_begx, win1->_begy + win1->_maxy, win1->_begx + win1->_maxx);
X	fprintf(outf, "TOUCHOVERLAP:win2 (%d,%d) to (%d,%d)\n", win2->_begy, win2->_begx, win2->_begy + win2->_maxy, win2->_begx + win2->_maxx);
# endif
X	if (starty >= endy || startx >= endx) {
X		curses_V();
X		return ERR;
X        }
X	starty -= win2->_begy;
X	startx -= win2->_begx;
X	endy -= win2->_begy;
X	endx -= win2->_begx;
X	endx--;
X	for (y = starty; y < endy; y++)
X		touchline(win2, y, startx, endx);
X
X	curses_V();
X	return OK;
}
SHAR_EOF
  $shar_touch -am 0627091195 'vw_curses/curses/toucholap.c' &&
  chmod 0644 'vw_curses/curses/toucholap.c' ||
  echo 'restore of vw_curses/curses/toucholap.c failed'
  shar_count="`wc -c < 'vw_curses/curses/toucholap.c'`"
  test 2261 -eq "$shar_count" ||
    echo "vw_curses/curses/toucholap.c: original size 2261, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/cr_tty.c ==============
if test -f 'vw_curses/curses/cr_tty.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/cr_tty.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/cr_tty.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/cr_tty.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)cr_tty.c	5.4 (Berkeley) 6/30/88";
#endif /* not lint */
X
/*
X * Terminal initialization routines.
X *
X */
X
# include	"curses.ext"
X
static bool	*sflags[] = {
X			&AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI,
X			&MS, &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS,
X			&XX
X		};
X
static char	*_PC;
static char	**sstrs[] = {
X			&AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
X			&DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
X			&K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
X			&IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
X			&LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
X			&SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
X			&VB, &VS, &VE, &AL_PARM, &DL_PARM, &UP_PARM,
X			&DOWN_PARM, &LEFT_PARM, &RIGHT_PARM,
X		};
static char	*tgoto();
X
char		_tspace[2048];		/* Space for capability strings */
X
static char	*aoftspace;		/* Address of _tspace for relocation */
X
static int	destcol, destline;
X
/*
X *	This routine does terminal type initialization routines, and
X * calculation of flags at entry.  It is almost entirely stolen from
X * Bill Joy's ex version 2.6.
X */
short	ospeed = -1;
X
gettmode() {
X
#ifndef VxWorks
X	if (gtty(_tty_ch, &_tty) < 0)
X		return;
X	savetty();
X	if (stty(_tty_ch, &_tty) < 0)
X		_tty.sg_flags = _res_flg;
X	ospeed = _tty.sg_ospeed;
X	_res_flg = _tty.sg_flags;
X	UPPERCASE = (_tty.sg_flags & LCASE) != 0;
X	GT = ((_tty.sg_flags & XTABS) == 0);
X	NONL = ((_tty.sg_flags & CRMOD) == 0);
X	_tty.sg_flags &= ~XTABS;
X	stty(_tty_ch, &_tty);
#else
X	savetty();
X	ospeed = baudrate();
X	UPPERCASE = FALSE;
X	GT = FALSE;
X	NONL = FALSE;
X	resetty();
#endif
# ifdef DEBUG
X	fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
X	fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
X	fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
X	fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
# endif
}
X
setterm(type)
reg char	*type; {
X
X	reg int		unknown;
X	static char	genbuf[1024];
# ifdef TIOCGWINSZ
X	struct winsize win;
# endif
X
# ifdef DEBUG
X	fprintf(outf, "SETTERM(\"%s\")\n", type);
X	fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
# endif
X	if (type[0] == '\0')
X		type = "xx";
X	unknown = FALSE;
X	if (tgetent(genbuf, type) != 1) {
X		unknown++;
X		strcpy(genbuf, "xx|dumb:");
X	}
# ifdef DEBUG
X	fprintf(outf, "SETTERM: tty = %s\n", type);
# endif
# ifdef TIOCGWINSZ
X	if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) {
X		if (LINES == 0)
X			LINES = win.ws_row;
X		if (COLS == 0)
X			COLS = win.ws_col;
X	}
# endif
X
X	if (LINES == 0)
X		LINES = tgetnum("li");
X	if (LINES <= 5)
X		LINES = 24;
X
X	if (COLS == 0)
X		COLS = tgetnum("co");
X	if (COLS <= 4)
X		COLS = 80;
X
# ifdef DEBUG
X	fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
# endif
X	aoftspace = _tspace;
X	zap();			/* get terminal description		*/
X
X	/*
X	 * Handle funny termcap capabilities
X	 */
X	if (CS && SC && RC) AL=DL="";
X	if (AL_PARM && AL==NULL) AL="";
X	if (DL_PARM && DL==NULL) DL="";
X	if (IC && IM==NULL) IM="";
X	if (IC && EI==NULL) EI="";
X	if (!GT) BT=NULL;	/* If we can't tab, we can't backtab either */
X
X	if (tgoto(CM, destcol, destline)[0] == 'O')
X		CA = FALSE, CM = 0;
X	else
X		CA = TRUE;
X
X	PC = _PC ? _PC[0] : FALSE;
X	aoftspace = _tspace;
X	strncpy(ttytype, longname(genbuf, type), sizeof(ttytype) - 1);
X	ttytype[sizeof(ttytype) - 1] = '\0';
X	if (unknown)
X		return ERR;
X	return OK;
}
X
/*
X *	This routine gets all the terminal flags from the termcap database
X */
X
zap()
{
X	register char	*namp;
X	register bool	**fp;
X	register char	***sp;
#ifdef	DEBUG
X	register char	*cp;
#endif
X	extern char	*tgetstr();
X
X	namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxsxx";
X	fp = sflags;
X	do {
X		*(*fp++) = tgetflag(namp);
#ifdef DEBUG
X		fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
#endif
X		namp += 2;
X	} while (*namp);
X	namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
X	sp = sstrs;
X	do {
X		*(*sp++) = tgetstr(namp, &aoftspace);
#ifdef DEBUG
X		fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
X		if (*sp[-1] != NULL) {
X			for (cp = *sp[-1]; *cp; cp++)
X				fprintf(outf, "%s", unctrl(*cp));
X			fprintf(outf, "\"\n");
X		}
#endif
X		namp += 2;
X	} while (*namp);
X	if (XS)
X		SO = SE = NULL;
X	else {
X		if (tgetnum("sg") > 0)
X			SO = NULL;
X		if (tgetnum("ug") > 0)
X			US = NULL;
X		if (!SO && US) {
X			SO = US;
X			SE = UE;
X		}
X	}
}
X
/*
X * return a capability from termcap
X */
char *
getcap(name)
char *name;
{
X	char *tgetstr();
X
X	return tgetstr(name, &aoftspace);
}
SHAR_EOF
  $shar_touch -am 0627094795 'vw_curses/curses/cr_tty.c' &&
  chmod 0644 'vw_curses/curses/cr_tty.c' ||
  echo 'restore of vw_curses/curses/cr_tty.c failed'
  shar_count="`wc -c < 'vw_curses/curses/cr_tty.c'`"
  test 5313 -eq "$shar_count" ||
    echo "vw_curses/curses/cr_tty.c: original size 5313, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/newwin.c ==============
if test -f 'vw_curses/curses/newwin.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/newwin.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/newwin.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/newwin.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)newwin.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
/*
X * allocate space for and set up defaults for a new window
X *
X */
X
# include	"curses.ext"
X
char	*malloc();
X
# define	SMALLOC	(short *) malloc
X
static WINDOW	*makenew();
static WINDOW	*remakenew();
X
# undef		nl	/* don't need it here, and it interferes	*/
X
WINDOW *
newwin(num_lines, num_cols, begy, begx)
int	num_lines, num_cols, begy, begx;
{
X   return renewwin(num_lines, num_cols, begy, begx, NULL);
}
X
WINDOW *
renewwin(num_lines, num_cols, begy, begx, win)
int	num_lines, num_cols, begy, begx;
WINDOW  *win;
{
X	reg char	*sp;
X	reg int		i, by, bx, nl, nc;
X	reg int		j;
X
X        curses_P();
X	by = begy;
X	bx = begx;
X	nl = num_lines;
X	nc = num_cols;
X
X	if (nl == 0)
X		nl = LINES - by;
X	if (nc == 0)
X		nc = COLS - bx;
X	if ((win = remakenew(nl, nc, by, bx, win)) == NULL) {
X                curses_V();
X		return (WINDOW *)ERR;
X        }
X	if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) {
X		free(win->_y);
X		free(win);
X                curses_V();
X		return (WINDOW *)ERR;
X	}
X	if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) {
X		free(win->_y);
X		free(win->_firstch);
X		free(win);
X                curses_V();
X		return (WINDOW *)ERR;
X	}
X	win->_nextp = win;
X	for (i = 0; i < nl; i++) {
X		win->_firstch[i] = _NOCHANGE;
X		win->_lastch[i] = _NOCHANGE;
X	}
X	for (i = 0; i < nl; i++)
X		if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) {
X			for (j = 0; j < i; j++)
X				free(win->_y[j]);
X			free(win->_firstch);
X			free(win->_lastch);
X			free(win->_y);
X			free(win);
X                	curses_V();
X			return (WINDOW *)ERR;
X		}
X		else
X			for (sp = win->_y[i]; sp < win->_y[i] + nc; )
X				*sp++ = ' ';
X	win->_ch_off = 0;
X	win->_orig = NULL;     /* bug fixed: this line was forgotten! */
# ifdef DEBUG
X	fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off);
# endif
X        curses_V();
X	return win;
}
X
WINDOW *
subwin(orig, num_lines, num_cols, begy, begx)
reg WINDOW	*orig;
int		num_lines, num_cols, begy, begx;
{
X	reg int		i;
X	reg WINDOW	*win;
X	reg int		by, bx, nl, nc;
X
X        curses_P();
X	by = begy;
X	bx = begx;
X	nl = num_lines;
X	nc = num_cols;
X
X	/*
X	 * make sure window fits inside the original one
X	 */
# ifdef	DEBUG
X	fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
# endif
X	if (by < orig->_begy || bx < orig->_begx
X	    || by + nl > orig->_maxy + orig->_begy
X	    || bx + nc > orig->_maxx + orig->_begx) {
X                curses_V();
X		return (WINDOW *)ERR;
X        }
X	if (nl == 0)
X		nl = orig->_maxy + orig->_begy - by;
X	if (nc == 0)
X		nc = orig->_maxx + orig->_begx - bx;
X	if ((win = makenew(nl, nc, by, bx)) == NULL) {
X                curses_V();
X		return (WINDOW *)ERR;
X        }
X	win->_nextp = orig->_nextp;
X	orig->_nextp = win;
X	win->_orig = orig;
X	_set_subwin_(orig, win);
X        curses_V();
X	return win;
}
X
/*
X * this code is shared with mvwin()
X */
_set_subwin_(orig, win)
register WINDOW	*orig, *win;
{
X	register int	i, j, k;
X
X	j = win->_begy - orig->_begy;
X	k = win->_begx - orig->_begx;
X	win->_ch_off = k;
# ifdef DEBUG
X	fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off);
# endif
X	win->_firstch = &orig->_firstch[j];
X	win->_lastch = &orig->_lastch[j];
X	for (i = 0; i < win->_maxy; i++, j++)
X		win->_y[i] = &orig->_y[j][k];
X
}
X
/*
X *	This routine sets up a window buffer and returns a pointer to it.
X *      It returns NULL on error.
X */
static WINDOW *
makenew(num_lines, num_cols, begy, begx)
int	num_lines, num_cols, begy, begx;
{
X   return remakenew(num_lines, num_cols, begy, begx, NULL);
}
X
static WINDOW *
remakenew(num_lines, num_cols, begy, begx, win)
int	num_lines, num_cols, begy, begx;
WINDOW  *win;
X {
X
X	reg int		i;
X	reg int		by, bx, nl, nc;
X
X	by = begy;
X	bx = begx;
X	nl = num_lines;
X	nc = num_cols;
X
# ifdef	DEBUG
X	fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
# endif
X        if (win==NULL) {
X		if ((win = (WINDOW *) malloc(sizeof *win)) == NULL)
X			return NULL;
X        }
X        else {
X        	redelwin(win);       /* doesn't free(win) */
X        }
# ifdef DEBUG
X	fprintf(outf, "MAKENEW: nl = %d\n", nl);
# endif
X	if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) {
X		free(win);
X		return NULL;
X	}
# ifdef DEBUG
X	fprintf(outf, "MAKENEW: nc = %d\n", nc);
# endif
X	win->_cury = win->_curx = 0;
X	win->_clear = FALSE;
X	win->_maxy = nl;
X	win->_maxx = nc;
X	win->_begy = by;
X	win->_begx = bx;
X	win->_flags = _FLUSH;     /* default to flush on refresh */
X	win->_scroll = win->_leave = FALSE;
X	_swflags_(win);
# ifdef DEBUG
X	fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
X	fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
X	fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
X	fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
X	fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
X	fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
X	fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
X	fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
# endif
X	return win;
}
X
_swflags_(win)
register WINDOW	*win;
{
X	win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN);
X	if (win->_begx + win->_maxx == COLS) {
X		win->_flags |= _ENDLINE;
X		if (win->_begx == 0) {
X			if (AL && DL)
X				win->_flags |= _FULLLINE;
X			if (win->_maxy == LINES && win->_begy == 0)
X				win->_flags |= _FULLWIN;
X		}
X		if (win->_begy + win->_maxy == LINES)
X			win->_flags |= _SCROLLWIN;
X	}
}
SHAR_EOF
  $shar_touch -am 0627100095 'vw_curses/curses/newwin.c' &&
  chmod 0644 'vw_curses/curses/newwin.c' ||
  echo 'restore of vw_curses/curses/newwin.c failed'
  shar_count="`wc -c < 'vw_curses/curses/newwin.c'`"
  test 6268 -eq "$shar_count" ||
    echo "vw_curses/curses/newwin.c: original size 6268, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/refresh.c ==============
if test -f 'vw_curses/curses/refresh.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/refresh.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/refresh.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/refresh.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)refresh.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
/*
X * make the current screen look like "win" over the area coverd by
X * win.
X */
X
# include	"curses.ext"
X
# ifdef DEBUG
# define	STATIC
# else
# define	STATIC	static
# endif
X
STATIC short	ly, lx;
X
STATIC bool	curwin;
X
WINDOW	*_win = NULL;
X
wrefresh(win)
reg WINDOW	*win;
/*
X * Changed to not abort if get error from makech().
X */
{
X	reg short	wy;
X	reg int		retval;
X	reg WINDOW	*orig;
X
X	curses_P();
X
X	if (win == NULL) {
X	    curses_V();
X	    return ERR;
X	}
X
X        retval = OK;
X
X	/*
X	 * make sure we're in visual state
X	 */
X	if (_endwin) {
X		_puts(VS);
X		_puts(TI);
X		_endwin = FALSE;
X	}
X
X	/*
X	 * initialize loop parameters
X	 */
X
X	ly = curscr->_cury;
X	lx = curscr->_curx;
X	wy = 0;
X	_win = win;
X	curwin = (win == curscr);
X
X	if (win->_clear || curscr->_clear || curwin) {
X		if ((win->_flags & _FULLWIN) || curscr->_clear) {
X			_puts(CL);
X			ly = 0;
X			lx = 0;
X			if (!curwin) {
X				curscr->_clear = FALSE;
X				curscr->_cury = 0;
X				curscr->_curx = 0;
X				werase(curscr);
X			}
X			touchwin(win);
X		}
X		win->_clear = FALSE;
X	}
X	if (!CA) {
X		if (win->_curx != 0)
X			_putchar('\n');
X		if (!curwin)
X			werase(curscr);
X	}
# ifdef DEBUG
X	fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin);
X	fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n");
# endif
X	for (wy = 0; wy < win->_maxy; wy++) {
# ifdef DEBUG
X		fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy],
X			win->_lastch[wy]);
# endif
X		if (win->_firstch[wy] != _NOCHANGE) {
X			if (makech(win, wy) == ERR) {
X                                retval = ERR;
X			}
X			if (win->_firstch[wy] >= win->_ch_off)
X				win->_firstch[wy] = win->_maxx +
X						    win->_ch_off;
X			if (win->_lastch[wy] < win->_maxx +
X					       win->_ch_off)
X				win->_lastch[wy] = win->_ch_off;
X			if (win->_lastch[wy] < win->_firstch[wy])
X				win->_firstch[wy] = _NOCHANGE;
X		}
# ifdef DEBUG
X		fprintf(outf, "\t%d\t%d\n", win->_firstch[wy],
X			win->_lastch[wy]);
# endif
X	}
X
X	if (win == curscr)
X		domvcur(ly, lx, win->_cury, win->_curx);
X	else {
X		if (win->_leave) {
X			curscr->_cury = ly;
X			curscr->_curx = lx;
X			ly -= win->_begy;
X			lx -= win->_begx;
X			if (ly >= 0 && ly < win->_maxy && lx >= 0 &&
X			    lx < win->_maxx) {
X				win->_cury = ly;
X				win->_curx = lx;
X			}
X			else
X				win->_cury = win->_curx = 0;
X		}
X		else {
X			domvcur(ly, lx, win->_cury + win->_begy,
X				win->_curx + win->_begx);
X			curscr->_cury = win->_cury + win->_begy;
X			curscr->_curx = win->_curx + win->_begx;
X		}
X	}
X
X	_win = NULL;
X	if (win->_flags & _FLUSH)
X		fflush(stdout);
X
X	curses_V();
X	return retval;
}
X
/*
X * make a change on the screen
X */
STATIC
makech(win, wy)
reg WINDOW	*win;
short		wy;
{
X	reg char	*nsp, *csp, *ce;
X	reg short	wx, lch, y;
X	reg int		nlsp, clsp;	/* last space in lines		*/
X
X	wx = win->_firstch[wy] - win->_ch_off;
X	if (wx >= win->_maxx)
X		return OK;
X	else if (wx < 0)
X		wx = 0;
X	lch = win->_lastch[wy] - win->_ch_off;
X	if (lch < 0)
X		return OK;
X	else if (lch >= win->_maxx)
X		lch = win->_maxx - 1;;
X	y = wy + win->_begy;
X
X	if (curwin)
X		csp = " ";
X	else
X		csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
X
X	nsp = &win->_y[wy][wx];
X	if (CE && !curwin) {
X		for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
X			if (ce <= win->_y[wy])
X				break;
X		nlsp = ce - win->_y[wy];
X	}
X
X	if (!curwin)
X		ce = CE;
X	else
X		ce = NULL;
X
X	while (wx <= lch) {
X		if (*nsp != *csp) {
X			domvcur(ly, lx, y, wx + win->_begx);
# ifdef DEBUG
X			fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx);
# endif	
X			ly = y;
X			lx = wx + win->_begx;
X			while (*nsp != *csp && wx <= lch) {
X				if (ce != NULL && wx >= nlsp && *nsp == ' ') {
X					/*
X					 * check for clear to end-of-line
X					 */
X					ce = &curscr->_y[ly][COLS - 1];
X					while (*ce == ' ')
X						if (ce-- <= csp)
X							break;
X					clsp = ce - curscr->_y[ly] - win->_begx;
# ifdef DEBUG
X					fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp);
# endif
X					if (clsp - nlsp >= strlen(CE)
X					    && clsp < win->_maxx) {
# ifdef DEBUG
X						fprintf(outf, "MAKECH: using CE\n");
# endif
X						_puts(CE);
X						lx = wx + win->_begx;
X						while (wx++ <= clsp)
X							*csp++ = ' ';
X						return OK;
X					}
X					ce = NULL;
X				}
X				/*
X				 * enter/exit standout mode as appropriate
X				 */
X				if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) {
X					if (*nsp & _STANDOUT) {
X						_puts(SO);
X						curscr->_flags |= _STANDOUT;
X					}
X					else {
X						_puts(SE);
X						curscr->_flags &= ~_STANDOUT;
X					}
X				}
X				wx++;
X				if (wx >= win->_maxx && wy == win->_maxy - 1) {
X					if (win->_scroll) {
X					    if ((curscr->_flags&_STANDOUT) &&
X					        (win->_flags & _ENDLINE))
X						    if (!MS) {
X							_puts(SE);
X							curscr->_flags &= ~_STANDOUT;
X						    }
X					    if (!curwin)
X						_putchar((*csp = *nsp) & 0177);
X					    else
X						_putchar(*nsp & 0177);
X					    if (win->_flags&_FULLWIN && !curwin)
X						scroll(curscr);
X					    ly = win->_begy+win->_cury;
X					    lx = win->_begx+win->_curx;
X					    return OK;
X					}
X					else if (win->_flags&_SCROLLWIN) {
X					    lx = --wx;
X					    return ERR;
X					}
X				}
X				if (!curwin)
X					_putchar((*csp++ = *nsp) & 0177);
X				else
X					_putchar(*nsp & 0177);
# ifdef FULLDEBUG
X				fprintf(outf,
X					"MAKECH:putchar(%c)\n", *nsp & 0177);
# endif
X				if (UC && (*nsp & _STANDOUT)) {
X					_putchar('\b');
X					_puts(UC);
X				}
X				nsp++;
X			}
# ifdef DEBUG
X			fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx);
# endif	
X			if (lx == wx + win->_begx)	/* if no change */
X				break;
X			lx = wx + win->_begx;
X			if (lx >= COLS && AM) {
X				lx = 0;
X				ly++;
X				/*
X				 * xn glitch: chomps a newline after auto-wrap.
X				 * we just feed it now and forget about it.
X				 */
X				if (XN) {
X					_putchar('\n');
X					_putchar('\r');
X				}
X			}
X		}
X		else if (wx <= lch)
X			while (*nsp == *csp && wx <= lch) {
X				nsp++;
X				if (!curwin)
X					csp++;
X				++wx;
X			}
X		else
X			break;
# ifdef DEBUG
X		fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
# endif	
X	}
X	return OK;
}
X
/*
X * perform a mvcur, leaving standout mode if necessary
X */
STATIC
domvcur(oy, ox, ny, nx)
int	oy, ox, ny, nx; {
X
X	if (curscr->_flags & _STANDOUT && !MS) {
X		_puts(SE);
X		curscr->_flags &= ~_STANDOUT;
X	}
X	mvcur(oy, ox, ny, nx);
}
SHAR_EOF
  $shar_touch -am 0627091195 'vw_curses/curses/refresh.c' &&
  chmod 0644 'vw_curses/curses/refresh.c' ||
  echo 'restore of vw_curses/curses/refresh.c failed'
  shar_count="`wc -c < 'vw_curses/curses/refresh.c'`"
  test 7088 -eq "$shar_count" ||
    echo "vw_curses/curses/refresh.c: original size 7088, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= vw_curses/curses/cr_put.c ==============
if test -f 'vw_curses/curses/cr_put.c' && test X"$1" != X"-c"; then
  echo 'x - skipping vw_curses/curses/cr_put.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting vw_curses/curses/cr_put.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'vw_curses/curses/cr_put.c' &&
/*
X * Copyright (c) 1981 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
#ifndef lint
static char sccsid[] = "@(#)cr_put.c	5.3 (Berkeley) 6/30/88";
#endif /* not lint */
X
# include	"curses.ext"
X
# define	HARDTABS	8
X
extern char	*tgoto();
int		plodput();
X
/*
X * Terminal driving and line formatting routines.
X * Basic motion optimizations are done here as well
X * as formatting of lines (printing of control characters,
X * line numbering and the like).
X */
X
/*
X * Sync the position of the output cursor.
X * Most work here is rounding for terminal boundaries getting the
X * column position implied by wraparound or the lack thereof and
X * rolling up the screen to get destline on the screen.
X */
X
static int	outcol, outline, destcol, destline;
X
WINDOW		*_win;
X
mvcur(ly, lx, y, x)
int	ly, lx, y, x; {
X
X	curses_P();
#ifdef DEBUG
X	fprintf(outf, "MVCUR: moving cursor from (%d,%d) to (%d,%d)\n", ly, lx, y, x);
#endif
X	destcol = x;
X	destline = y;
X	outcol = lx;
X	outline = ly;
X	fgoto();
X	curses_V();
}
X
fgoto()
{
X	reg char	*cgp;
X	reg int		l, c;
X
X	if (destcol >= COLS) {
X		destline += destcol / COLS;
X		destcol %= COLS;
X	}
X	if (outcol >= COLS) {
X		l = (outcol + 1) / COLS;
X		outline += l;
X		outcol %= COLS;
X		if (AM == 0) {
X			while (l > 0) {
X				if (_pfast)
X					if (CR)
X						_puts(CR);
X					else
X						_putchar('\r');
X				if (NL)
X					_puts(NL);
X				else
X					_putchar('\n');
X				l--;
X			}
X			outcol = 0;
X		}
X		if (outline > LINES - 1) {
X			destline -= outline - (LINES - 1);
X			outline = LINES - 1;
X		}
X	}
X	if (destline >= LINES) {
X		l = destline;
X		destline = LINES - 1;
X		if (outline < LINES - 1) {
X			c = destcol;
X			if (_pfast == 0 && !CA)
X				destcol = 0;
X			fgoto();
X			destcol = c;
X		}
X		while (l >= LINES) {
X			/*
X			 * The following linefeed (or simulation thereof)
X			 * is supposed to scroll up the screen, since we
X			 * are on the bottom line.  We make the assumption
X			 * that linefeed will scroll.  If ns is in the
X			 * capability list this won't work.  We should
X			 * probably have an sc capability but sf will
X			 * generally take the place if it works.
X			 *
X			 * Superbee glitch:  in the middle of the screen we
X			 * have to use esc B (down) because linefeed screws up
X			 * in "Efficient Paging" (what a joke) mode (which is
X			 * essential in some SB's because CRLF mode puts garbage
X			 * in at end of memory), but you must use linefeed to
X			 * scroll since down arrow won't go past memory end.
X			 * I turned this off after recieving Paul Eggert's
X			 * Superbee description which wins better.
X			 */
X			if (NL /* && !XB */ && _pfast)
X				_puts(NL);
X			else
X				_putchar('\n');
X			l--;
X			if (_pfast == 0)
X				outcol = 0;
X		}
X	}
X	if (destline < outline && !(CA || UP))
X		destline = outline;
X	if (CA) {
X		cgp = tgoto(CM, destcol, destline);
X		if (plod(strlen(cgp)) > 0)
X			plod(0);
X		else
X			tputs(cgp, 0, _putchar);
X	}
X	else
X		plod(0);
X	outline = destline;
X	outcol = destcol;
}
X
/*
X * Move (slowly) to destination.
X * Hard thing here is using home cursor on really deficient terminals.
X * Otherwise just use cursor motions, hacking use of tabs and overtabbing
X * and backspace.
X */
X
static int plodcnt, plodflg;
X
plodput(c)
{
X	if (plodflg)
X		plodcnt--;
X	else
X		_putchar(c);
}
X
plod(cnt)
{
X	register int i, j, k;
X	register int soutcol, soutline;
X
X	plodcnt = plodflg = cnt;
X	soutcol = outcol;
X	soutline = outline;
X	/*
X	 * Consider homing and moving down/right from there, vs moving
X	 * directly with local motions to the right spot.
X	 */
X	if (HO) {
X		/*
X		 * i is the cost to home and tab/space to the right to
X		 * get to the proper column.  This assumes ND space costs
X		 * 1 char.  So i+destcol is cost of motion with home.
X		 */
X		if (GT)
X			i = (destcol / HARDTABS) + (destcol % HARDTABS);
X		else
X			i = destcol;
X		/*
X		 * j is cost to move locally without homing
X		 */
X		if (destcol >= outcol) {	/* if motion is to the right */
X			j = destcol / HARDTABS - outcol / HARDTABS;
X			if (GT && j)
X				j += destcol % HARDTABS;
X			else
X				j = destcol - outcol;
X		}
X		else
X			/* leftward motion only works if we can backspace. */
X			if (outcol - destcol <= i && (BS || BC))
X				i = j = outcol - destcol; /* cheaper to backspace */
X			else
X				j = i + 1; /* impossibly expensive */
X
X		/* k is the absolute value of vertical distance */
X		k = outline - destline;
X		if (k < 0)
X			k = -k;
X		j += k;
X
X		/*
X		 * Decision.  We may not have a choice if no UP.
X		 */
X		if (i + destline < j || (!UP && destline < outline)) {
X			/*
X			 * Cheaper to home.  Do it now and pretend it's a
X			 * regular local motion.
X			 */
X			tputs(HO, 0, plodput);
X			outcol = outline = 0;
X		}
X		else if (LL) {
X			/*
X			 * Quickly consider homing down and moving from there.
X			 * Assume cost of LL is 2.
X			 */
X			k = (LINES - 1) - destline;
X			if (i + k + 2 < j && (k<=0 || UP)) {
X				tputs(LL, 0, plodput);
X				outcol = 0;
X				outline = LINES - 1;
X			}
X		}
X	}
X	else
X	/*
X	 * No home and no up means it's impossible.
X	 */
X		if (!UP && destline < outline)
X			return -1;
X	if (GT)
X		i = destcol % HARDTABS + destcol / HARDTABS;
X	else
X		i = destcol;
/*
X	if (BT && outcol > destcol && (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) {
X		j *= (k = strlen(BT));
X		if ((k += (destcol&7)) > 4)
X			j += 8 - (destcol&7);
X		else
X			j += k;
X	}
X	else
*/
X		j = outcol - destcol;
X	/*
X	 * If we will later need a \n which will turn into a \r\n by
X	 * the system or the terminal, then don't bother to try to \r.
X	 */
X	if ((NONL || !_pfast) && outline < destline)
X		goto dontcr;
X	/*
X	 * If the terminal will do a \r\n and there isn't room for it,
X	 * then we can't afford a \r.
X	 */
X	if (NC && outline >= destline)
X		goto dontcr;
X	/*
X	 * If it will be cheaper, or if we can't back up, then send
X	 * a return preliminarily.
X	 */
X	if (j > i + 1 || outcol > destcol && !BS && !BC) {
X		/*
X		 * BUG: this doesn't take the (possibly long) length
X		 * of CR into account.
X		 */
X		if (CR)
X			tputs(CR, 0, plodput);
X		else
X			plodput('\r');
X		if (NC) {
X			if (NL)
X				tputs(NL, 0, plodput);
X			else
X				plodput('\n');
X			outline++;
X		}
X		outcol = 0;
X	}
dontcr:
X	while (outline < destline) {
X		outline++;
X		if (NL)
X			tputs(NL, 0, plodput);
X		else
X			plodput('\n');
X		if (plodcnt < 0)
X			goto out;
X		if (NONL || _pfast == 0)
X			outcol = 0;
X	}
X	if (BT)
X		k = strlen(BT);
X	while (outcol > destcol) {
X		if (plodcnt < 0)
X			goto out;
SHAR_EOF
  : || echo 'restore of vw_curses/curses/cr_put.c failed'
fi
echo 'End of archive part 3'
echo 'File vw_curses/curses/cr_put.c is continued in part 4'
echo 4 > _sharseq.tmp
exit 0
