[net.sources] New Curses from Berkeley

lepreau (05/12/83)

Relay-Version:version B 3/9/83; site harpo.UUCP
Message-ID:<1582@utah-cs.UUCP>
Date:Thu, 12-May-83 00:17:29 EDT

Apparently Ken Arnold's posting of the new curses didn't make it to much
of the net, including here, so he has asked me to post it from here to
avoid possible problems at the Berkeley end of Usenet.  He expresses his
apologies to those of you who get this twice.

Note: this is in Berkeley archive format, and needs only this leading
garbage removed, not any trailing \n's.
---------------------------------------
!<arch>
Makefile        421036356   162   10    100644  2419      `
#
# cursor package maker
#
# %W% (Berkeley) %G%
#
HEADERS=curses.h unctrl.h curses.ext
CFILES=	box.c clear.c initscr.c endwin.c mvprintw.c mvscanw.c mvwin.c \
	newwin.c overlay.c overwrite.c printw.c scanw.c refresh.c \
	touchwin.c erase.c clrtobot.c clrtoeol.c cr_put.c cr_tty.c \
	longname.c delwin.c insertln.c deleteln.c scroll.c getstr.c \
	getch.c addstr.c addch.c move.c curses.c unctrl.c standout.c \
	tstp.c insch.c delch.c

OBJS=	box.o clear.o initscr.o endwin.o mvprintw.o mvscanw.o mvwin.o \
	newwin.o overlay.o overwrite.o printw.o scanw.o refresh.o \
	touchwin.o erase.o clrtobot.o clrtoeol.o cr_put.o cr_tty.o \
	longname.o delwin.o insertln.o deleteln.o scroll.o getstr.o \
	getch.o addstr.o addch.o move.o curses.o unctrl.o standout.o \
	tstp.o insch.o delch.o

POBJS=	box.p clear.p initscr.p endwin.p mvprintw.p mvscanw.p mvwin.p \
	newwin.p overlay.p overwrite.p printw.p scanw.p refresh.p \
	touchwin.p erase.p clrtobot.p clrtoeol.p cr_put.p cr_tty.p \
	longname.p delwin.p insertln.p deleteln.p scroll.p getstr.p \
	getch.p addstr.p addch.p move.p curses.p unctrl.p standout.p \
	tstp.p insch.p delch.p


CTAGS=	ctags
CC=	cc
LINT=	lint
LPASS1=	/usr/lib/lint/lint1
AR=	ar
RM=	rm
LN=	ln
CFL=
CFLAGS=	-O ${CFL}
LDFLAGS=-n
.SUFFIXES: .p

.c.p:
	rm -f x.c
	ln $*.c x.c
	${CC} ${CFLAGS} -p -c x.c
	mv x.o $*.p

.DEFAULT:
	sccs get $@

libcurses: ${HEADERS} crlib

crlib: ${OBJS}
	${AR} rv crlib $?
	ranlib crlib

pcrlib: ${POBJS}
	rm -f x.c
	${AR} rv pcrlib $?
	ranlib pcrlib

test:	crlib test.o
	${CC} ${LDFLAGS} ${CFLAGS} -o test test.o -lcurses -ltermlib

cat.o:	curses.h
	${CC} -c ${CFLAGS} cat.c

new:	cleanup ctags
	${CC} -c ${CFLAGS} ${CFILES}
	${AR} qv crlib ${OBJS}
	${RM} /ya/staff/arnold/=eye/crlib /ya/staff/arnold/=hacks/crlib \
	      /ya/staff/arnold/=eye/curses.h /ya/staff/arnold/=hacks/curses.h

clean:
	rm ${OBJS} crlib

ctags:
	${CTAGS} ${CFILES} curses.h

lint:
	${LINT} -hxb ${CFL} ${CFILES} -lcurses > lint.out

lpr:
	-pr curses.h ${CFILES} | lpr
	-lpq

tp:
	tp crm0 Makefile tags ${HEADERS} ${CFILES} llib-lcurses

tar:
	tar crvf curses.tar Makefile tags ${HEADERS} ${CFILES} llib-lcurses

ar:
	ar crv curses.ar Makefile tags ${HEADERS} ${CFILES} llib-lcurses

llib-lcurses.ln: llib-lcurses
	-(/lib/cpp -C -Dlint llib-lcurses | ${LPASS1} > llib-lcurses.ln ) 2>&1 | grep -v warning

install:
	install -c crlib ${DESTDIR}/usr/lib/libcurses.a
	ranlib ${DESTDIR}/usr/lib/libcurses.a

tags            417660719   162   10    100644  5534      `
CTRL	cr_ex.h	?^# define	CTRL(c)	('c' & 037)$?
Mtest	test.c	/^main() {$/
VOID	curses.h	?^# define	VOID(x)	(__void__ = (int) (x))$?
_putchar	cr_put.c	?^_putchar(c)$?
_puts	curses.h	?^# define	_puts(s)	tputs(s, 0, _putchar);$?
_sprintw	printw.c	?^_sprintw(win, fmt, args)$?
_sscans	scanw.c	?^_sscans(win, fmt, args)$?
addch	curses.h	?^# define	addch(ch)	VOID(waddch(stdscr, ch))$?
addstr	curses.h	?^# define	addstr(str)	VOID(waddstr(stdscr, str))$?
box	box.c	?^box(win, vert, hor)$?
clear	curses.h	?^# define	clear()		VOID(wclear(stdscr))$?
clearok	curses.h	?^#define	clearok(win,bf)	 (win->_clear = bf)$?
clrtobot	curses.h	?^# define	clrtobot()	VOID(wclrtobot(stdscr))$?
clrtoeol	curses.h	?^# define	clrtoeol()	VOID(wclrtoeol(stdscr))$?
crmode	curses.h	?^#define crmode() (_tty.sg_flags |= CBREAK, _rawmod?
delch	curses.h	?^# define	delch()		VOID(wdelch(stdscr))$?
deleteln	curses.h	?^# define	deleteln()	VOID(wdeleteln(stdscr))$?
delwin	delwin.c	?^delwin(win)$?
do_touch	touchwin.c	/^do_touch(win)$/
domvcur	refresh.c	?^domvcur(oy, ox, ny, nx)$?
echo	curses.h	?^#define echo()	 (_tty.sg_flags |= ECHO, _echoit = ?
endwin	endwin.c	?^endwin()$?
erase	curses.h	?^# define	erase()		VOID(werase(stdscr))$?
fgoto	cr_put.c	?^fgoto() {$?
flushok	curses.h	?^#define flushok(win,bf)	 (bf ? (win->_flags |= _FL?
getcap	cr_tty.c	?^getcap(name)$?
getch	curses.h	?^# define	getch()		VOID(wgetch(stdscr))$?
getstr	curses.h	?^# define	getstr(str)	VOID(wgetstr(stdscr, str))$?
gettmode	cr_tty.c	?^gettmode() {$?
getyx	curses.h	?^#define	getyx(win,y,x)	 y = win->_cury, x = win->_?
inch	curses.h	?^# define	inch()		VOID(winch(stdscr))$?
initscr	initscr.c	?^initscr() {$?
insch	curses.h	?^# define	insch(c)	VOID(winsch(stdscr,c))$?
insertln	curses.h	?^# define	insertln()	VOID(winsertln(stdscr))$?
leaveok	curses.h	?^#define	leaveok(win,bf)	 (win->_leave = bf)$?
longname	longname.c	?^longname(bp, def)$?
makech	refresh.c	?^makech(win, wy)$?
makenew	newwin.c	?^makenew(num_lines, num_cols, begy, begx)$?
max	overlay.c	?^# define	max(a,b)	(a < b ? a : b)$?
min	overlay.c	?^# define	min(a,b)	(a < b ? a : b)$?
move	curses.h	?^# define	move(y, x)	VOID(wmove(stdscr, y, x))$?
mvaddch	curses.h	?^#define	mvaddch(y,x,ch)		mvwaddch(stdscr,y,x,ch)$?
mvaddstr	curses.h	?^#define	mvaddstr(y,x,str)	mvwaddstr(stdscr,y,x,str?
mvcur	cr_put.c	?^mvcur(ly, lx, y, x)$?
mvdelch	curses.h	?^#define	mvdelch(y,x)		mvwdelch(stdscr,y,x)$?
mvgetch	curses.h	?^#define	mvgetch(y,x)		mvwgetch(stdscr,y,x)$?
mvgetstr	curses.h	?^#define	mvgetstr(y,x)		mvwgetstr(stdscr,y,x)$?
mvinch	curses.h	?^#define	mvinch(y,x)		mvwinch(stdscr,y,x)$?
mvinsch	curses.h	?^#define	mvinsch(y,x,c)		mvwinsch(stdscr,y,x,c)$?
mvprintw	mvprintw.c	?^mvprintw(y, x, fmt, args)$?
mvscanw	mvscanw.c	?^mvscanw(y, x, fmt, args)$?
mvwaddch	curses.h	?^#define	mvwaddch(win,y,x,ch)	VOID(wmove(win,y,x)==?
mvwaddstr	curses.h	?^#define	mvwaddstr(win,y,x,str)	VOID(wmove(win,y,x)?
mvwdelch	curses.h	?^#define	mvwdelch(win,y,x)	VOID(wmove(win,y,x) == E?
mvwgetch	curses.h	?^#define	mvwgetch(win,y,x)	VOID(wmove(win,y,x)==ERR?
mvwgetstr	curses.h	?^#define	mvwgetstr(win,y,x)	VOID(wmove(win,y,x)==ER?
mvwin	mvwin.c	?^mvwin(win, by, bx)$?
mvwinch	curses.h	?^#define	mvwinch(win,y,x)	VOID(wmove(win,y,x) == ER?
mvwinsch	curses.h	?^#define	mvwinsch(win,y,x,c)	VOID(wmove(win,y,x) ==?
mvwprintw	mvprintw.c	?^mvwprintw(win, y, x, fmt, args)$?
mvwscanw	mvscanw.c	?^mvwscanw(win, y, x, fmt, args)$?
newwin	newwin.c	?^newwin(num_lines, num_cols, begy, begx)$?
nl	curses.h	?^#define nl()	 (_tty.sg_flags |= CRMOD,_pfast = _ra?
nocrmode	curses.h	?^#define nocrmode() (_tty.sg_flags &= ~CBREAK,_rawm?
noecho	curses.h	?^#define noecho() (_tty.sg_flags &= ~ECHO, _echoit ?
nonl	curses.h	?^#define nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast =?
noraw	curses.h	?^#define noraw()	 (_tty.sg_flags&=~RAW,_rawmode=FAL?
overlay	overlay.c	?^overlay(win1, win2)$?
overwrite	overwrite.c	?^overwrite(win1, win2)$?
plod	cr_put.c	?^plod(cnt)$?
plodput	cr_put.c	?^plodput(c)$?
printw	printw.c	?^printw(fmt, args)$?
putpad	cr_put.c	?^putpad(cp)$?
raw	curses.h	?^#define raw()	 (_tty.sg_flags|=RAW, _pfast=_rawmod?
refresh	curses.h	?^# define	refresh()	VOID(wrefresh(stdscr))$?
resetty	curses.h	?^#define	resetty() (_tty.sg_flags = _res_flg, stty(?
savetty	curses.h	?^#define	savetty() (gtty(_tty_ch, &_tty), _res_flg ?
scanw	scanw.c	?^scanw(fmt, args)$?
scroll	scroll.c	?^scroll(win)$?
scrollok	curses.h	?^#define	scrollok(win,bf) (win->_scroll = bf)$?
set_ch	addch.c	/^set_ch(win, y, x, ch)$/
setterm	cr_tty.c	?^setterm(type)$?
standend	curses.h	?^# define	standend()	VOID(wstandend(stdscr))$?
standout	curses.h	?^# define	standout()	VOID(wstandout(stdscr))$?
subwin	newwin.c	?^subwin(orig, num_lines, num_cols, begy, begx)$?
touchwin	touchwin.c	/^touchwin(win)$/
tstp	tstp.c	?^tstp() {$?
waddch	addch.c	/^waddch(win, c)$/
waddstr	addstr.c	?^waddstr(win,str)$?
wclear	clear.c	?^wclear(win)$?
wclrtobot	clrtobot.c	?^wclrtobot(win)$?
wclrtoeol	clrtoeol.c	?^wclrtoeol(win)$?
wdelch	delch.c	?^wdelch(win)$?
wdeleteln	deleteln.c	?^wdeleteln(win)$?
werase	erase.c	?^werase(win)$?
wgetch	getch.c	?^wgetch(win)$?
wgetstr	getstr.c	?^wgetstr(win,str)$?
winch	curses.h	?^#define	winch(win)	 (win->_y[win->_cury][win->_cur?
winsch	insch.c	?^winsch(win, c)$?
winsertln	insertln.c	?^winsertln(win)$?
wmove	move.c	?^wmove(win, y, x)$?
wprintw	printw.c	?^wprintw(win, fmt, args)$?
wrefresh	refresh.c	?^wrefresh(win)$?
wscanw	scanw.c	?^wscanw(win, fmt, args)$?
wstandend	standout.c	?^wstandend(win)$?
wstandout	standout.c	?^wstandout(win)$?
zap	cr_tty.c	?^zap() {$?
curses.h        417656900   162   10    100755  4339      `
/* 2/2/83 (Berkeley) @(#)curses.h	1.11 */
# ifndef WINDOW

# include	<stdio.h>

# include	<sgtty.h>

# define	bool	char
# define	reg	register

# define	TRUE	(1)
# define	FALSE	(0)
# define	ERR	(0)
# define	OK	(1)

# define	_ENDLINE	001
# define	_FULLWIN	002
# define	_SCROLLWIN	004
# define	_FLUSH		010
# define	_STANDOUT	0200
# define	_NOCHANGE	-1

# define	_puts(s)	tputs(s, 0, _putchar);

typedef	struct sgttyb	SGTTY;

/*
 * Capabilities from termcap
 */

extern bool     AM, BS, CA, DA, DB, EO, GT, HZ, IN, MI, MS, NC, OS, UL,
		XN;
extern char     *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *DC, *DL, *DM,
		*DO, *ED, *EI, *HO, *IC, *IM, *IP, *LL, *MA, *ND, *NL,
		*SE, *SF, *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US,
		*VB, *VE, *VS, PC;

/*
 * From the tty modes...
 */

extern bool	NONL, UPPERCASE, normtty, _pfast;

struct _win_st {
	short		_cury, _curx;
	short		_maxy, _maxx;
	short		_begy, _begx;
	short		_flags;
	bool		_clear;
	bool		_leave;
	bool		_scroll;
	char		**_y;
	short		*_firstch;
	short		*_lastch;
	struct _win_st	*_nextp, *_orig;
};

# define	WINDOW	struct _win_st

extern bool	My_term, _echoit, _rawmode, _endwin;

extern char	*Def_term, ttytype[];

extern int	LINES, COLS, _tty_ch, _res_flg;

extern SGTTY	_tty;

extern WINDOW	*stdscr, *curscr;

/*
 *	Define VOID to stop lint from generating "null effect"
 * comments.
 */
# ifdef lint
int	__void__;
# define	VOID(x)	(__void__ = (int) (x))
# else
# define	VOID(x)	(x)
# endif

/*
 * psuedo functions for standard screen
 */
# define	addch(ch)	VOID(waddch(stdscr, ch))
# define	getch()		VOID(wgetch(stdscr))
# define	addstr(str)	VOID(waddstr(stdscr, str))
# define	getstr(str)	VOID(wgetstr(stdscr, str))
# define	move(y, x)	VOID(wmove(stdscr, y, x))
# define	clear()		VOID(wclear(stdscr))
# define	erase()		VOID(werase(stdscr))
# define	clrtobot()	VOID(wclrtobot(stdscr))
# define	clrtoeol()	VOID(wclrtoeol(stdscr))
# define	insertln()	VOID(winsertln(stdscr))
# define	deleteln()	VOID(wdeleteln(stdscr))
# define	refresh()	VOID(wrefresh(stdscr))
# define	inch()		VOID(winch(stdscr))
# define	insch(c)	VOID(winsch(stdscr,c))
# define	delch()		VOID(wdelch(stdscr))
# define	standout()	VOID(wstandout(stdscr))
# define	standend()	VOID(wstandend(stdscr))

/*
 * mv functions
 */
#define	mvwaddch(win,y,x,ch)	VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
#define	mvwgetch(win,y,x)	VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
#define	mvwaddstr(win,y,x,str)	VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
#define mvwgetstr(win,y,x,str)  VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
#define	mvwinch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
#define	mvwdelch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
#define	mvwinsch(win,y,x,c)	VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
#define	mvaddch(y,x,ch)		mvwaddch(stdscr,y,x,ch)
#define	mvgetch(y,x)		mvwgetch(stdscr,y,x)
#define	mvaddstr(y,x,str)	mvwaddstr(stdscr,y,x,str)
#define mvgetstr(y,x,str)       mvwgetstr(stdscr,y,x,str)
#define	mvinch(y,x)		mvwinch(stdscr,y,x)
#define	mvdelch(y,x)		mvwdelch(stdscr,y,x)
#define	mvinsch(y,x,c)		mvwinsch(stdscr,y,x,c)

/*
 * psuedo functions
 */

#define	clearok(win,bf)	 (win->_clear = bf)
#define	leaveok(win,bf)	 (win->_leave = bf)
#define	scrollok(win,bf) (win->_scroll = bf)
#define flushok(win,bf)	 (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
#define	getyx(win,y,x)	 y = win->_cury, x = win->_curx
#define	winch(win)	 (win->_y[win->_cury][win->_curx] & 0177)

#define raw()	 (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, stty(_tty_ch,&_tty))
#define noraw()	 (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),stty(_tty_ch,&_tty))
#define crmode() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, stty(_tty_ch,&_tty))
#define nocrmode() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,stty(_tty_ch,&_tty))
#define echo()	 (_tty.sg_flags |= ECHO, _echoit = TRUE, stty(_tty_ch, &_tty))
#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, stty(_tty_ch, &_tty))
#define nl()	 (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
#define nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
#define	savetty() (gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
#define	resetty() (_tty.sg_flags = _res_flg, stty(_tty_ch, &_tty))

WINDOW	*initscr(), *newwin(), *subwin();
char	*longname(), *getcap();

# endif

unctrl.h        417658020   162   10    100444  128       `
/*
 * unctrl.h
 *
 * 2/17/82 (Berkeley) @(#)unctrl.h	1.2
 */

extern char	*_unctrl[];

# define	unctrl(ch)	(_unctrl[ch & 0177])
curses.ext      417658046   162   10    100444  364       `
/*
 * External variables for the library
 *
 * @(#)curses.ext	1.2 (Berkeley) 3/5/81
 */

/* LINTLIBRARY */

# include	"curses.h"
# include	"unctrl.h"

extern bool	_echoit, _rawmode, My_term, _endwin;

extern char	ttytype[], *_unctrl[];

extern int	_tty_ch, LINES, COLS;

extern SGTTY	_tty;

char		_putchar();

#ifdef DEBUG
# define	outf	_outf

FILE		*outf;
#endif
box.c           417658024   162   10    100444  645       `
# include	"curses.ext"

/*
 *	This routine draws a box around the given window with "vert"
 * as the vertical delimiting char, and "hor", as the horizontal one.
 *
 * 2/16/82 (Berkeley) @(#)box.c	1.2
 */
box(win, vert, hor)
reg WINDOW	*win;
char		vert, hor; {

	reg int		i;
	reg int		endy, endx;
	reg char	*fp, *lp;

	endx = win->_maxx;
	endy = win->_maxy - 1;
	fp = win->_y[0];
	lp = win->_y[endy];
	for (i = 0; i < endx; i++)
		fp[i] = lp[i] = hor;
	endx--;
	for (i = 0; i <= endy; i++)
		win->_y[i][0] = (win->_y[i][endx] = vert);
	if (!win->_scroll && (win->_flags&_SCROLLWIN))
		fp[0] = fp[endx] = lp[0] = lp[endx] = ' ';
	touchwin(win);
}

clear.c         417658027   162   10    100444  405       `
# include	"curses.ext"

/*
 *	This routine clears the window.
 *
 * 1/26/81 (Berkeley) @(#)clear.c	1.1
 */
wclear(win)
reg WINDOW	*win; {

	if (win == curscr) {
# ifdef DEBUG
		fprintf(outf,"WCLEAR: win == curscr\n");
		fprintf(outf,"WCLEAR: curscr = %d\n",curscr);
		fprintf(outf,"WCLEAR: stdscr = %d\n",stdscr);
# endif
		clear();
		return refresh();
	}
	werase(win);
	win->_clear = TRUE;
	return OK;
}

initscr.c       417658037   162   10    100444  1039      `
# include	"curses.ext"
# include	<signal.h>

extern char	*getenv();

/*
 *	This routine initializes the current and standard screen.
 *
 * 3/6/81 (Berkeley) @(#)initscr.c	1.2
 */
WINDOW *
initscr() {

	reg char	*sp;
	int		tstp();

# ifdef DEBUG
	fprintf(outf, "INITSCR()\n");
# endif
	if (!My_term && isatty(2)) {
		_tty_ch = 2;
		gettmode();
		if ((sp = getenv("TERM")) == NULL)
			sp = Def_term;
		setterm(sp);
# ifdef DEBUG
		fprintf(outf, "INITSCR: term = %s\n", sp);
# endif
	}
	else
		setterm(Def_term);
	_puts(TI);
	_puts(VS);
# ifdef SIGTSTP
	signal(SIGTSTP, tstp);
# endif
	if (curscr != NULL) {
# ifdef DEBUG
		fprintf(outf, "INITSCR: curscr = 0%o\n", curscr);
# endif
		delwin(curscr);
	}
# ifdef DEBUG
	fprintf(outf, "LINES = %d, COLS = %d\n", LINES, COLS);
# endif
	if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
		return ERR;
	curscr->_clear = TRUE;
	if (stdscr != NULL) {
# ifdef DEBUG
		fprintf(outf, "INITSCR: stdscr = 0%o\n", stdscr);
# endif
		delwin(stdscr);
	}
	stdscr = newwin(LINES, COLS, 0, 0);
	return stdscr;
}

endwin.c        417658039   162   10    100444  266       `
/*
 * Clean things up before exiting
 *
 * 1/26/81 (Berkeley) %W
 */

# include	"curses.ext"

endwin()
{
	resetty();
	_puts(VE);
	_puts(TE);
	if (curscr) {
		if (curscr->_flags & _STANDOUT) {
			_puts(SE);
			curscr->_flags &= ~_STANDOUT;
		}
		_endwin = TRUE;
	}
}
mvprintw.c      417658032   162   10    100444  481       `
# include	"curses.ext"

/*
 * implement the mvprintw commands.  Due to the variable number of
 * arguments, they cannot be macros.  Sigh....
 *
 * 1/26/81 (Berkeley) @(#)mvprintw.c	1.1
 */

mvprintw(y, x, fmt, args)
reg int		y, x;
char		*fmt;
int		args; {

	return move(y, x) == OK ? _sprintw(stdscr, fmt, &args) : ERR;
}

mvwprintw(win, y, x, fmt, args)
reg WINDOW	*win;
reg int		y, x;
char		*fmt;
int		args; {

	return wmove(win, y, x) == OK ? _sprintw(win, fmt, &args) : ERR;
}

mvscanw.c       417658041   162   10    100444  483       `
# include	"curses.ext"

/*
 * implement the mvscanw commands.  Due to the variable number of
 * arguments, they cannot be macros.  Another sigh....
 *
 * 1/26/81 (Berkeley) @(#)mvscanw.c	1.1
 */

mvscanw(y, x, fmt, args)
reg int		y, x;
char		*fmt;
int		args; {

	return move(y, x) == OK ? _sscanw(stdscr, fmt, &args) : ERR;
}

mvwscanw(win, y, x, fmt, args)
reg WINDOW	*win;
reg int		y, x;
char		*fmt;
int		args; {

	return wmove(win, y, x) == OK ? _sscanw(win, fmt, &args) : ERR;
}

mvwin.c         417658044   162   10    100444  311       `
# include	"curses.ext"

/*
 * relocate the starting position of a window
 *
 * 1/26/81 (Berkeley) @(#)mvwin.c	1.1
 */

mvwin(win, by, bx)
reg WINDOW	*win;
reg int		by, bx; {

	if (by + win->_maxy > LINES || bx + win->_maxx > COLS)
		return ERR;
	win->_begy = by;
	win->_begx = bx;
	touchwin(win);
	return OK;
}

newwin.c        418075975   162   10    100644  3998      `
/*
 * allocate space for and set up defaults for a new window
 *
 * %G% (Berkeley) %W%
 */

# include	"curses.ext"

short	*calloc();
WINDOW	*malloc();

static WINDOW	*makenew();

# undef		nl	/* don't need it here, and it interferes	*/

WINDOW *
newwin(num_lines, num_cols, begy, begx)
int	num_lines, num_cols, begy, begx;
{
	reg WINDOW	*win;
	reg char	*sp;
	reg int		i, by, bx, nl, nc;

	by = begy;
	bx = begx;
	nl = num_lines;
	nc = num_cols;

	if (nl == 0)
		nl = LINES - by;
	if (nc == 0)
		nc = COLS - bx;
	if ((win = makenew(nl, nc, by, bx)) == NULL)
		return ERR;
	for (i = 0; i < nl; i++)
		if ((win->_y[i] = (char *) calloc(nc, sizeof (char))) == NULL) {
			reg int		j;

			for (j = 0; j < i; j++)
				cfree(win->_y[j]);
			cfree(win->_firstch);
			cfree(win->_lastch);
			cfree(win->_y);
			cfree(win);
			return ERR;
		}
		else
			for (sp = win->_y[i]; sp < win->_y[i] + nc; )
				*sp++ = ' ';
	win->_nextp = win;
	return win;
}

WINDOW *
subwin(orig, num_lines, num_cols, begy, begx)
reg WINDOW	*orig;
int		num_lines, num_cols, begy, begx; {

	reg int		i;
	reg WINDOW	*win;
	reg int		by, bx, nl, nc;
	reg int		j, k;

	by = begy;
	bx = begx;
	nl = num_lines;
	nc = num_cols;

	/*
	 * make sure window fits inside the original one
	 */
# ifdef	DEBUG
	fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
# endif
	if (by < orig->_begy || bx < orig->_begx
	    || by + nl > orig->_maxy + orig->_begy
	    || bx + nc > orig->_maxx + orig->_begx) {
		fprintf(stderr, "returning ERR (1)\n");
		fprintf(stderr, "SUBWIN(begx = %d, begy = %d,maxx = %d, maxy = %d, nl = %d, nc = %d, by = %d, bx = %d)\n", orig->_begx,orig->_begy,orig->_maxx,orig->_maxy, nl, nc, by, bx);
		return ERR;
	}
	if (nl == 0)
		nl = orig->_maxy + orig->_begy - by;
	if (nc == 0)
		nc = orig->_maxx + orig->_begx - bx;
	if ((win = makenew(nl, nc, by, bx)) == NULL) {
		fprintf(stderr, "returning ERR (2)\n");
		return ERR;
	}
	j = by - orig->_begy;
	k = bx - orig->_begx;
	for (i = 0; i < nl; i++)
		win->_y[i] = &orig->_y[j++][k];
	win->_nextp = orig->_nextp;
	orig->_nextp = win;
	win->_orig = orig;
	return win;
}

/*
 *	This routine sets up a window buffer and returns a pointer to it.
 */
static WINDOW *
makenew(num_lines, num_cols, begy, begx)
int	num_lines, num_cols, begy, begx; {

	reg int		i;
	reg WINDOW	*win;
	reg int		by, bx, nl, nc;

	by = begy;
	bx = begx;
	nl = num_lines;
	nc = num_cols;

# ifdef	DEBUG
	fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
# endif
	if ((win = (WINDOW *) calloc(1, sizeof (WINDOW))) == NULL)
		return NULL;
# ifdef DEBUG
	fprintf(outf, "MAKENEW: nl = %d\n", nl);
# endif
	if ((win->_y = (char **) calloc(nl, sizeof (char *))) == NULL) {
		cfree(win);
		return NULL;
	}
	if ((win->_firstch = calloc(nl, sizeof (short))) == NULL) {
		cfree(win);
		cfree(win->_y);
		return NULL;
	}
	if ((win->_lastch = calloc(nl, sizeof (short))) == NULL) {
		cfree(win);
		cfree(win->_y);
		cfree(win->_firstch);
		return NULL;
	}
# ifdef DEBUG
	fprintf(outf, "MAKENEW: nc = %d\n", nc);
# endif
	win->_cury = win->_curx = 0;
	win->_clear = (nl == LINES && nc == COLS);
	win->_maxy = nl;
	win->_maxx = nc;
	win->_begy = by;
	win->_begx = bx;
	win->_flags = 0;
	win->_scroll = win->_leave = FALSE;
	for (i = 0; i < nl; i++)
		win->_firstch[i] = win->_lastch[i] = _NOCHANGE;
	if (bx + nc == COLS) {
		win->_flags |= _ENDLINE;
		if (bx == 0 && nl == LINES && by == 0)
			win->_flags |= _FULLWIN;
		if (by + nl == LINES)
			win->_flags |= _SCROLLWIN;
	}
# ifdef DEBUG
	fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
	fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
	fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
	fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
	fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
	fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
	fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
	fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
# endif
	return win;
}
overlay.c       417658028   162   10    100444  862       `
# include	"curses.ext"
# include	<ctype.h>

# define	min(a,b)	(a < b ? a : b)
# define	max(a,b)	(a > b ? a : b)

/*
 *	This routine writes win1 on win2 non-destructively.
 *
 * 11/5/82 (Berkeley) @(#)overlay.c	1.4
 */
overlay(win1, win2)
reg WINDOW	*win1, *win2; {

	reg char	*sp, *end;
	reg int		x, y, endy, endx, starty, startx;

# ifdef DEBUG
	fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
# endif
	starty = max(win1->_begy, win2->_begy) - win1->_begy;
	startx = max(win1->_begx, win2->_begx) - win1->_begx;
	endy = min(win1->_maxy, win2->_maxy) - win1->_begy - 1;
	endx = min(win1->_maxx, win2->_maxx) - win1->_begx - 1;
	for (y = starty; y < endy; y++) {
		end = &win1->_y[y][endx];
		x = startx + win1->_begx;
		for (sp = &win1->_y[y][startx]; sp <= end; sp++) {
			if (!isspace(*sp))
				mvwaddch(win2, y + win1->_begy, x, *sp);
			x++;
		}
	}
}
overwrite.c     417899759   7     10    100444  745       `
# include	"curses.ext"

# define	min(a,b)	(a < b ? a : b)

/*
 *	This routine writes win1 on win2 destructively.
 *
 * 3/27/83 (Berkeley) @(#)overwrite.c	1.3
 */
overwrite(win1, win2)
reg WINDOW	*win1, *win2; {

	reg int		x, y, minx, miny, startx, starty;

# ifdef DEBUG
	fprintf(outf, "OVERWRITE(0%o, 0%o);\n", win1, win2);
# endif
	miny = min(win1->_maxy, win2->_maxy);
	minx = min(win1->_maxx, win2->_maxx);
# ifdef DEBUG
	fprintf(outf, "OVERWRITE:\tminx = %d,  miny = %d\n", minx, miny);
# endif
	starty = win1->_begy - win2->_begy;
	startx = win1->_begx - win2->_begx;
	if (startx < 0)
		startx = 0;
	for (y = 0; y < miny; y++)
		if (wmove(win2, y + starty, startx) != ERR)
			for (x = 0; x < minx; x++)
				waddch(win2, win1->_y[y][x]);
}

printw.c        417658035   162   10    100444  1009      `
/*
 * printw and friends
 *
 * 1/26/81 (Berkeley) @(#)printw.c	1.1
 */

# include	"curses.ext"

/*
 *	This routine implements a printf on the standard screen.
 */
printw(fmt, args)
char	*fmt;
int	args; {

	return _sprintw(stdscr, fmt, &args);
}

/*
 *	This routine implements a printf on the given window.
 */
wprintw(win, fmt, args)
WINDOW	*win;
char	*fmt;
int	args; {

	return _sprintw(win, fmt, &args);
}
/*
 *	This routine actually executes the printf and adds it to the window
 *
 *	This is really a modified version of "sprintf".  As such,
 * it assumes that sprintf interfaces with the other printf functions
 * in a certain way.  If this is not how your system works, you
 * will have to modify this routine to use the interface that your
 * "sprintf" uses.
 */
_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);
}

scanw.c         417658030   162   10    100444  1008      `
/*
 * scanw and friends
 *
 * 1/26/81 (Berkeley) @(#)scanw.c	1.1
 */

# include	"curses.ext"

/*
 *	This routine implements a scanf on the standard screen.
 */
scanw(fmt, args)
char	*fmt;
int	args; {

	return _sscans(stdscr, fmt, &args);
}
/*
 *	This routine implements a scanf on the given window.
 */
wscanw(win, fmt, args)
WINDOW	*win;
char	*fmt;
int	args; {

	return _sscans(win, fmt, &args);
}
/*
 *	This routine actually executes the scanf from the window.
 *
 *	This is really a modified version of "sscanf".  As such,
 * it assumes that sscanf interfaces with the other scanf functions
 * in a certain way.  If this is not how your system works, you
 * will have to modify this routine to use the interface that your
 * "sscanf" uses.
 */
_sscans(win, fmt, args)
WINDOW	*win;
char	*fmt;
int	*args; {

	char	buf[100];
	FILE	junk;

	junk._flag = _IOREAD|_IOSTRG;
	junk._base = junk._ptr = buf;
	if (wgetstr(win, buf) == ERR)
		return ERR;
	junk._cnt = strlen(buf);
	return _doscan(&junk, fmt, args);
}
refresh.c       417658019   162   10    100444  4998      `
/*
 * make the current screen look like "win" over the area coverd by
 * win.
 *
 * 3/27/83 (Berkeley) @(#)refresh.c	1.6
 */

# include	"curses.ext"

# ifdef DEBUG
# define	STATIC
# else
# define	STATIC	static
# endif

STATIC short	ly, lx;

STATIC bool	curwin;

WINDOW	*_win = NULL;

wrefresh(win)
reg WINDOW	*win;
{
	reg short	wy;
	reg int		retval;

	/*
	 * make sure were in visual state
	 */
	if (_endwin) {
		_puts(VS);
		_puts(TI);
		_endwin = FALSE;
	}

	/*
	 * initialize loop parameters
	 */

	ly = curscr->_cury;
	lx = curscr->_curx;
	wy = 0;
	_win = win;
	curwin = (win == curscr);

	if (win->_clear || curscr->_clear || curwin) {
		if ((win->_flags & _FULLWIN) || curscr->_clear) {
			_puts(CL);
			ly = lx = curscr->_curx = curscr->_cury = 0;
			curscr->_clear = FALSE;
			if (!curwin)
				werase(curscr);
			touchwin(win);
		}
		win->_clear = FALSE;
	}
	if (!CA) {
		if (win->_curx != 0)
			putchar('\n');
		if (!curwin)
			werase(curscr);
	}
# ifdef DEBUG
	fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin);
	fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n");
# endif
	for (wy = 0; wy < win->_maxy; wy++) {
# ifdef DEBUG
		fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy], win->_lastch[wy]);
# endif
		if (win->_firstch[wy] != _NOCHANGE)
			if (makech(win, wy) == ERR)
				return ERR;
			else
				win->_firstch[wy] = _NOCHANGE;
	}
	if (win->_leave) {
		curscr->_cury = ly;
		curscr->_curx = lx;
		ly -= win->_begy;
		lx -= win->_begx;
		if (ly >= 0 && ly < win->_maxy && lx >= 0 && lx < win->_maxx) {
			win->_cury = ly;
			win->_curx = lx;
		}
		else
			win->_cury = win->_curx = 0;
	}
	else {
		domvcur(ly, lx, win->_cury+win->_begy, win->_curx+win->_begx);
		curscr->_cury = win->_cury + win->_begy;
		curscr->_curx = win->_curx + win->_begx;
	}
	retval = OK;
ret:
	_win = NULL;
	fflush(stdout);
	return retval;
}

/*
 * make a change on the screen
 */
STATIC
makech(win, wy)
reg WINDOW	*win;
short		wy;
{
	reg char	*nsp, *csp, *ce;
	reg short	wx, lch, y;
	reg int		nlsp, clsp;	/* last space in lines		*/

	wx = win->_firstch[wy];
	y = wy + win->_begy;
	lch = win->_lastch[wy];
	if (curwin)
		csp = " ";
	else
		csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
	nsp = &win->_y[wy][wx];
	if (CE && !curwin) {
		for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
			if (ce <= win->_y[wy])
				break;
		nlsp = ce - win->_y[wy];
	}
	if (!curwin)
		ce = CE;
	else
		ce = NULL;
	while (wx <= lch) {
		if (*nsp != *csp) {
			domvcur(ly, lx, y, wx + win->_begx);
# ifdef DEBUG
			fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx);
# endif
			ly = y;
			lx = wx + win->_begx;
			while (*nsp != *csp && wx <= lch) {
				if (ce != NULL && wx >= nlsp && *nsp == ' ') {
					/*
					 * check for clear to end-of-line
					 */
					ce = &curscr->_y[ly][COLS - 1];
					while (*ce == ' ')
						if (ce-- <= csp)
							break;
					clsp = ce - curscr->_y[ly] - win->_begx;
# ifdef DEBUG
					fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp);
# endif
					if (clsp - nlsp >= strlen(CE)
					    && clsp < win->_maxx) {
# ifdef DEBUG
						fprintf(outf, "MAKECH: using CE\n");
# endif
						_puts(CE);
						lx = wx + win->_begx;
						while (wx++ <= clsp)
							*csp++ = ' ';
						goto ret;
					}
					ce = NULL;
				}
				/*
				 * enter/exit standout mode as appropriate
				 */
				if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) {
					if (*nsp & _STANDOUT) {
						_puts(SO);
						curscr->_flags |= _STANDOUT;
					}
					else {
						_puts(SE);
						curscr->_flags &= ~_STANDOUT;
					}
				}
				wx++;
				if (wx >= win->_maxx && wy == win->_maxy - 1)
					if (win->_scroll) {
					    if ((curscr->_flags&_STANDOUT) &&
					        (win->_flags & _ENDLINE))
						    if (!MS) {
							_puts(SE);
							curscr->_flags &= ~_STANDOUT;
						    }
					    if (!curwin)
						putchar((*csp = *nsp) & 0177);
					    else
						putchar(*nsp & 0177);
					    scroll(win);
					    if (win->_flags&_FULLWIN && !curwin)
						scroll(curscr);
					    ly = win->_begy+win->_cury;
					    lx = win->_begx+win->_curx;
					    return OK;
					}
					else if (win->_flags&_SCROLLWIN) {
					    lx = --wx;
					    return ERR;
					}
				if (!curwin)
					putchar((*csp++ = *nsp) & 0177);
				else
					putchar(*nsp & 0177);
				if (UC && (*nsp & _STANDOUT)) {
					putchar('\b');
					_puts(UC);
				}
				nsp++;
			}
# ifdef DEBUG
			fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx);
# endif
			if (lx == wx + win->_begx)	/* if no change */
				break;
			lx = wx + win->_begx;
		}
		else if (wx < lch)
			while (*nsp == *csp) {
				nsp++;
				if (!curwin)
					csp++;
				++wx;
			}
		else
			break;
# ifdef DEBUG
		fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
# endif
	}
ret:
	return OK;
}

/*
 * perform a mvcur, leaving standout mode if necessary
 */
static
domvcur(oy, ox, ny, nx)
int	oy, ox, ny, nx; {

	if (curscr->_flags & _STANDOUT && !MS) {
		_puts(SE);
		curscr->_flags &= ~_STANDOUT;
	}
	mvcur(oy, ox, ny, nx);
}
touchwin.c      417660942   162   10    100644  486       `
# include	"curses.ext"

/*
 * make it look like the whole window has been changed.
 *
 * %G% (Berkeley) %W%
 */
touchwin(win)
reg WINDOW	*win;
{
	reg WINDOW	*wp;

	do_touch(win);
	for (wp = win->_nextp; wp != win; wp = wp->_nextp)
		do_touch(wp);
}

/*
 * do_touch:
 *	Touch the window
 */
static
do_touch(win)
reg WINDOW	*win; {

	reg int		y, maxy, maxx;

	maxy = win->_maxy;
	maxx = win->_maxx - 1;
	for (y = 0; y < maxy; y++) {
		win->_firstch[y] = 0;
		win->_lastch[y] = maxx;
	}
}
erase.c         417658031   162   10    100444  782       `
# include	"curses.ext"

/*
 *	This routine erases everything on the window.
 *
 * 1/27/81 (Berkeley) @(#)erase.c	1.2
 */
werase(win)
reg WINDOW	*win; {

	reg int		y;
	reg char	*sp, *end, *start, *maxx;
	reg int		minx;

# ifdef DEBUG
	fprintf(outf, "WERASE(%0.2o)\n", win);
# endif
	for (y = 0; y < win->_maxy; y++) {
		minx = _NOCHANGE;
		start = win->_y[y];
		end = &start[win->_maxx];
		for (sp = start; sp < end; sp++)
			if (*sp != ' ') {
				maxx = sp;
				if (minx == _NOCHANGE)
					minx = sp - start;
				*sp = ' ';
			}
		if (minx != _NOCHANGE) {
			if (win->_firstch[y] > minx
			     || win->_firstch[y] == _NOCHANGE)
				win->_firstch[y] = minx;
			if (win->_lastch[y] < maxx - win->_y[y])
				win->_lastch[y] = maxx - win->_y[y];
		}
	}
	win->_curx = win->_cury = 0;
}
clrtobot.c      417658033   162   10    100444  773       `
# include	"curses.ext"

/*
 *	This routine erases everything on the window.
 *
 * 1/26/81 (Berkeley) @(#)clrtobot.c	1.1
 */
wclrtobot(win)
reg WINDOW	*win; {

	reg int		y;
	reg char	*sp, *end, *maxx;
	reg int		startx, minx;

	startx = win->_curx;
	for (y = win->_cury; y < win->_maxy; y++) {
		minx = _NOCHANGE;
		end = &win->_y[y][win->_maxx];
		for (sp = &win->_y[y][startx]; sp < end; sp++)
			if (*sp != ' ') {
				maxx = sp;
				if (minx == _NOCHANGE)
					minx = sp - win->_y[y];
				*sp = ' ';
			}
		if (minx != _NOCHANGE) {
			if (win->_firstch[y] > minx
			     || win->_firstch[y] == _NOCHANGE)
				win->_firstch[y] = minx;
			if (win->_lastch[y] < maxx - win->_y[y])
				win->_lastch[y] = maxx - win->_y[y];
		}
		startx = 0;
	}
	win->_curx = win->_cury = 0;
}

clrtoeol.c      417658026   162   10    100444  892       `
# include	"curses.ext"

/*
 *	This routine clears up to the end of line
 *
 * 3/5/81 (Berkeley) @(#)clrtoeol.c	1.2
 */
wclrtoeol(win)
reg WINDOW	*win; {

	reg char	*sp, *end;
	reg int		y, x;
	reg char	*maxx;
	reg int		minx;

	y = win->_cury;
	x = win->_curx;
	end = &win->_y[y][win->_maxx];
	minx = _NOCHANGE;
	maxx = &win->_y[y][x];
	for (sp = maxx; sp < end; sp++)
		if (*sp != ' ') {
			maxx = sp;
			if (minx == _NOCHANGE)
				minx = sp - win->_y[y];
			*sp = ' ';
		}
	/*
	 * update firstch and lastch for the line
	 */
# ifdef DEBUG
	fprintf(outf, "CLRTOEOL: minx = %d, maxx = %d, firstch = %d, lastch = %d\n", minx, maxx - win->_y[y], win->_firstch[y], win->_lastch[y]);
# endif
	if (minx != _NOCHANGE) {
		if (win->_firstch[y] > minx || win->_firstch[y] == _NOCHANGE)
			win->_firstch[y] = minx;
		if (win->_lastch[y] < maxx - win->_y[y])
			win->_lastch[y] = maxx - win->_y[y];
	}
}
cr_put.c        417658038   162   10    100444  8081      `
# include	"curses.ext"

# define	HARDTABS	8

extern char	*tgoto();
int		plodput();

/*
 * Terminal driving and line formatting routines.
 * Basic motion optimizations are done here as well
 * as formatting of lines (printing of control characters,
 * line numbering and the like).
 *
 * 3/27/83 (Berkeley) @(#)cr_put.c	1.4
 */

/*
 * Sync the position of the output cursor.
 * Most work here is rounding for terminal boundaries getting the
 * column position implied by wraparound or the lack thereof and
 * rolling up the screen to get destline on the screen.
 */

static int	outcol, outline, destcol, destline;

WINDOW		*_win;

mvcur(ly, lx, y, x)
int	ly, lx, y, x; {

#ifdef DEBUG
	fprintf(outf, "MVCUR: moving cursor from (%d,%d) to (%d,%d)\n", ly, lx, y, x);
#endif
	destcol = x;
	destline = y;
	outcol = lx;
	outline = ly;
	fgoto();
}

char
_putchar(c)
reg char	c; {

	putchar(c);
#ifdef DEBUG
	fprintf(outf, "_PUTCHAR(%s)\n", unctrl(c));
#endif
}

fgoto()
{
	reg char	*cgp;
	reg int		l, c;

	if (destcol > COLS - 1) {
		destline += destcol / COLS;
		destcol %= COLS;
	}
	if (outcol > COLS - 1) {
		l = (outcol + 1) / COLS;
		outline += l;
		outcol %= COLS;
		if (AM == 0) {
			while (l > 0) {
				if (_pfast)
					if (CR)
						tputs(CR, 0, _putchar);
					else
						_putchar('\r');
				if (NL)
					tputs(NL, 0, _putchar);
				else
					_putchar('\n');
				l--;
			}
			outcol = 0;
		}
		if (outline > LINES - 1) {
			destline -= outline - (LINES - 1);
			outline = LINES - 1;
		}
	}
	if (destline > LINES - 1) {
		l = destline;
		destline = LINES - 1;
		if (outline < LINES - 1) {
			c = destcol;
			if (_pfast == 0 && !CA)
				destcol = 0;
			fgoto();
			destcol = c;
		}
		while (l > LINES - 1) {
			/*
			 * The following linefeed (or simulation thereof)
			 * is supposed to scroll up the screen, since we
			 * are on the bottom line.  We make the assumption
			 * that linefeed will scroll.  If ns is in the
			 * capability list this won't work.  We should
			 * probably have an sc capability but sf will
			 * generally take the place if it works.
			 *
			 * Superbee glitch:  in the middle of the screen we
			 * have to use esc B (down) because linefeed screws up
			 * in "Efficient Paging" (what a joke) mode (which is
			 * essential in some SB's because CRLF mode puts garbage
			 * in at end of memory), but you must use linefeed to
			 * scroll since down arrow won't go past memory end.
			 * I turned this off after recieving Paul Eggert's
			 * Superbee description which wins better.
			 */
			if (NL /* && !XB */ && _pfast)
				tputs(NL, 0, _putchar);
			else
				_putchar('\n');
			l--;
			if (_pfast == 0)
				outcol = 0;
		}
	}
	if (destline < outline && !(CA || UP))
		destline = outline;
	if (CA)
	{
		cgp = tgoto(CM, destcol, destline);
		if (plod(strlen(cgp)) > 0)
			plod(0);
		else
			tputs(cgp, 0, _putchar);
	}
	else
		plod(0);
	outline = destline;
	outcol = destcol;
}

/*
 * Move (slowly) to destination.
 * Hard thing here is using home cursor on really deficient terminals.
 * Otherwise just use cursor motions, hacking use of tabs and overtabbing
 * and backspace.
 */

static int plodcnt, plodflg;

plodput(c)
{
	if (plodflg)
		plodcnt--;
	else
		_putchar(c);
}

plod(cnt)
{
	register int i, j, k;
	register int soutcol, soutline;

	plodcnt = plodflg = cnt;
	soutcol = outcol;
	soutline = outline;
	/*
	 * Consider homing and moving down/right from there, vs moving
	 * directly with local motions to the right spot.
	 */
	if (HO) {
		/*
		 * i is the cost to home and tab/space to the right to
		 * get to the proper column.  This assumes ND space costs
		 * 1 char.  So i+destcol is cost of motion with home.
		 */
		if (GT)
			i = (destcol / HARDTABS) + (destcol % HARDTABS);
		else
			i = destcol;
		/*
		 * j is cost to move locally without homing
		 */
		if (destcol >= outcol) {	/* if motion is to the right */
			j = destcol / HARDTABS - outcol / HARDTABS;
			if (GT && j)
				j += destcol % HARDTABS;
			else
				j = destcol - outcol;
		}
		else
			/* leftward motion only works if we can backspace. */
			if (outcol - destcol <= i && (BS || BC))
				i = j = outcol - destcol; /* cheaper to backspace */
			else
				j = i + 1; /* impossibly expensive */

		/* k is the absolute value of vertical distance */
		k = outline - destline;
		if (k < 0)
			k = -k;
		j += k;

		/*
		 * Decision.  We may not have a choice if no UP.
		 */
		if (i + destline < j || (!UP && destline < outline)) {
			/*
			 * Cheaper to home.  Do it now and pretend it's a
			 * regular local motion.
			 */
			tputs(HO, 0, plodput);
			outcol = outline = 0;
		}
		else if (LL) {
			/*
			 * Quickly consider homing down and moving from there.
			 * Assume cost of LL is 2.
			 */
			k = (LINES - 1) - destline;
			if (i + k + 2 < j && (k<=0 || UP)) {
				tputs(LL, 0, plodput);
				outcol = 0;
				outline = LINES - 1;
			}
		}
	}
	else
	/*
	 * No home and no up means it's impossible.
	 */
		if (!UP && destline < outline)
			return -1;
	if (GT)
		i = destcol % HARDTABS + destcol / HARDTABS;
	else
		i = destcol;
/*
	if (BT && outcol > destcol && (j = (((outcol+7) & ~7) - destcol - 1) >> 3)) {
		j *= (k = strlen(BT));
		if ((k += (destcol&7)) > 4)
			j += 8 - (destcol&7);
		else
			j += k;
	}
	else
*/
		j = outcol - destcol;
	/*
	 * If we will later need a \n which will turn into a \r\n by
	 * the system or the terminal, then don't bother to try to \r.
	 */
	if ((NONL || !_pfast) && outline < destline)
		goto dontcr;
	/*
	 * If the terminal will do a \r\n and there isn't room for it,
	 * then we can't afford a \r.
	 */
	if (NC && outline >= destline)
		goto dontcr;
	/*
	 * If it will be cheaper, or if we can't back up, then send
	 * a return preliminarily.
	 */
	if (j > i + 1 || outcol > destcol && !BS && !BC) {
		/*
		 * BUG: this doesn't take the (possibly long) length
		 * of CR into account.
		 */
		if (CR)
			tputs(CR, 0, plodput);
		else
			plodput('\r');
		if (NC) {
			if (NL)
				tputs(NL, 0, plodput);
			else
				plodput('\n');
			outline++;
		}
		outcol = 0;
	}
dontcr:
	while (outline < destline) {
		outline++;
		if (NL && _pfast)
			tputs(NL, 0, plodput);
		else
			plodput('\n');
		if (plodcnt < 0)
			goto out;
		if (NONL || _pfast == 0)
			outcol = 0;
	}
	if (BT)
		k = strlen(BT);
	while (outcol > destcol) {
		if (plodcnt < 0)
			goto out;
/*
		if (BT && outcol - destcol > k + 4) {
			tputs(BT, 0, plodput);
			outcol--;
			outcol &= ~7;
			continue;
		}
*/
		outcol--;
		if (BC)
			tputs(BC, 0, plodput);
		else
			plodput('\b');
	}
	while (outline > destline) {
		outline--;
		tputs(UP, 0, plodput);
		if (plodcnt < 0)
			goto out;
	}
	if (GT && destcol - outcol > 1) {
		for (;;) {
			i = tabcol(outcol, HARDTABS);
			if (i > destcol)
				break;
			if (TA)
				tputs(TA, 0, plodput);
			else
				plodput('\t');
			outcol = i;
		}
		if (destcol - outcol > 4 && i < COLS && (BC || BS)) {
			if (TA)
				tputs(TA, 0, plodput);
			else
				plodput('\t');
			outcol = i;
			while (outcol > destcol) {
				outcol--;
				if (BC)
					tputs(BC, 0, plodput);
				else
					plodput('\b');
			}
		}
	}
	while (outcol < destcol) {
		/*
		 * move one char to the right.  We don't use ND space
		 * because it's better to just print the char we are
		 * moving over.
		 */
		if (_win != NULL)
			if (plodflg)	/* avoid a complex calculation */
				plodcnt--;
			else {
				i = curscr->_y[outline][outcol];
				if ((i&_STANDOUT) == (curscr->_flags&_STANDOUT))
					putchar(i);
				else
					goto nondes;
			}
		else
nondes:
		     if (ND)
			tputs(ND, 0, plodput);
		else
			plodput(' ');
		outcol++;
		if (plodcnt < 0)
			goto out;
	}
out:
	if (plodflg) {
		outcol = soutcol;
		outline = soutline;
	}
	return(plodcnt);
}

/*
 * Return the column number that results from being in column col and
 * hitting a tab, where tabs are set every ts columns.  Work right for
 * the case where col > COLS, even if ts does not divide COLS.
 */
tabcol(col, ts)
int col, ts;
{
	int offset, result;

	if (col >= COLS) {
		offset = COLS * (col / COLS);
		col -= offset;
	}
	else
		offset = 0;
	return col + ts - (col % ts) + offset;
}

cr_tty.c        417658047   162   10    100444  3503      `
/*
 * Terminal initialization routines.
 *
 * 3/27/83 (Berkeley) @(#)cr_tty.c	1.12
 */

# include	"curses.ext"

static bool	*sflags[]	= {
			&AM, &BS, &EO, &HZ, &IN, &MI, &MS, &NC, &OS, &UL, &XN
		};

static char	*xPC,
		**sstrs[]	= {
			&AL, &BC, &BT, &CD,  &CE, &CL, &CM, &CR, &DC,
			&DL, &DM, &DO, &ED,  &EI, &HO, &IC, &IM, &IP,
			&LL, &MA, &ND, &NL, &xPC, &SE, &SF, &SO, &SR,
			&TA, &TE, &TI, &UC,  &UE, &UP, &US, &VB, &VS,
			&VE
		},
		*tgoto();

static char	tspace[256],		/* Space for capability strings */
		*aoftspace;		/* Address of tspace for relocation */

static int	destcol, destline;

/*
 *	This routine does terminal type initialization routines, and
 * calculation of flags at entry.  It is almost entirely stolen from
 * Bill Joy's ex version 2.6.
 */
short	ospeed = -1;

gettmode() {

	if (gtty(_tty_ch, &_tty) < 0)
		return;
	savetty();
	if (stty(_tty_ch, &_tty) < 0)
		_tty.sg_flags = _res_flg;
	ospeed = _tty.sg_ospeed;
	_res_flg = _tty.sg_flags;
	UPPERCASE = (_tty.sg_flags & LCASE) != 0;
	GT = ((_tty.sg_flags & XTABS) == 0);
	NONL = ((_tty.sg_flags & CRMOD) == 0);
	_tty.sg_flags &= ~XTABS;
	stty(_tty_ch, &_tty);
# ifdef DEBUG
	fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
	fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
	fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
	fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
# endif
}

setterm(type)
reg char	*type; {

	reg int		unknown;
	static char	genbuf[1024];

# ifdef DEBUG
	fprintf(outf, "SETTERM(\"%s\")\n", type);
	fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
# endif
	if (type[0] == '\0')
		type = "xx";
	unknown = FALSE;
	if (tgetent(genbuf, type) != 1) {
		unknown++;
		strcpy(genbuf, "xx|dumb:");
	}
# ifdef DEBUG
	fprintf(outf, "SETTERM: tty = %s\n", type);
# endif
	if (LINES == 0)
		LINES = tgetnum("li");
	if (LINES <= 5)
		LINES = 24;
	else if (LINES > 48)
		LINES = 48;

	if (COLS == 0)
		COLS = tgetnum("co");
	if (COLS <= 4)
		COLS = 80;
	else if (COLS > 1000)
		COLS = 1000;
# ifdef DEBUG
	fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
# endif
	aoftspace = tspace;
	zap();			/* get terminal description		*/
	if (tgoto(CM, destcol, destline)[0] == 'O')
		CA = FALSE, CM = 0;
	else
		CA = TRUE;
	PC = xPC ? xPC[0] : FALSE;
	aoftspace = tspace;
	strcpy(ttytype, longname(genbuf, type));
	if (unknown)
		return ERR;
	return OK;
}
/*
 *	This routine gets all the terminal flags from the termcap database
 */
zap() {

	reg bool	**fp;
	reg char	*namp, ***sp;
	reg int		SG, UG;
	extern char	*tgetstr();

	/*
	 * get boolean flags
	 */
 	namp = "ambseohzinmimsncosulxn\0\0";
# ifdef FULLDEBUG
	fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
# endif
	fp = sflags;
	do {
		*(*fp++) = tgetflag(namp);
# ifdef FULLDEBUG
		fprintf(outf, "ZAP: %.2s = %d", namp, *(*(fp - 1)));
# endif
		namp += 2;
	} while (*namp);

	/*
	 * get string values
	 */
	namp = "albcbtcdceclcmcrdcdldmdoedeihoicimipllmandnlpcsesfsosrtatetiucueupusvbvsve";
# ifdef FULLDEBUG
	fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
# endif
	sp = sstrs;
	do {
		*(*sp++) = tgetstr(namp, &aoftspace);
# ifdef FULLDEBUG
		fprintf(outf, "ZAP: %.2s = \"%s\"\n", namp, *(*(sp-1)));
# endif
		namp += 2;
	} while (*namp);
	SG = tgetnum("sg");
	UG = tgetnum("ug");
	if ((SG > 0 || !SO) && (UG <= 0 && US)) {
		SO = US;
		SE = UE;
	}
}

/*
 * return a capability from termcap
 */
char *
getcap(name)
char *name;
{
	char *tgetstr();

	return tgetstr(name, &aoftspace);
}

longname.c      417658040   162   10    100444  385       `
# define	reg	register

/*
 *	This routine fills in "def" with the long name of the terminal.
 *
 * 1/26/81 (Berkeley) @(#)longname.c	1.1
 */
char *
longname(bp, def)
reg char	*bp, *def; {

	reg char	*cp;

	while (*bp && *bp != ':' && *bp != '|')
		bp++;
	if (*bp == '|') {
		bp++;
		cp = bp;
		while (*cp && *cp != ':' && *cp != '|')
			cp++;
		*cp = 0;
		return bp;
	}
	return def;
}

delwin.c        418531132   162   10    100444  939       `
# include	"curses.ext"

/*
 *	This routine deletes a window and releases it back to the system.
 *
 * 4/6/83 (Berkeley) @(#)delwin.c	1.5
 */
delwin(win)
reg WINDOW	*win; {

	reg int		i;
	reg WINDOW	*wp, *np;

	if (win->_orig == NULL) {
		/*
		 * If we are the original window, delete the space for
		 * all the subwindows, and the array of space as well.
		 */
		for (i = 0; i < win->_maxy && win->_y[i]; i++)
			cfree(win->_y[i]);
		wp = win->_nextp;
		while (wp != win) {
			np = wp->_nextp;
			delwin(wp);
			wp = np;
		}
	}
	else {
		/*
		 * If we are a subwindow, take ourself out of the
		 * list.  NOTE: if we are a subwindow, the minimum list
		 * is orig followed by this subwindow, so there are
		 * always at least two windows in the list.
		 */
		for (wp = win->_nextp; wp->_nextp != win; wp = wp->_nextp)
			continue;
		wp->_nextp = win->_nextp;
	}
	cfree(win->_y);
	cfree(win->_firstch);
	cfree(win->_lastch);
	cfree(win);
}

insertln.c      417658043   162   10    100444  778       `
# include	"curses.ext"

/*
 *	This routine performs an insert-line on the window, leaving
 * (_cury,_curx) unchanged.
 *
 * 4/17/81 (Berkeley) @(#)insertln.c	1.4
 */
winsertln(win)
reg WINDOW	*win; {

	reg char	*temp;
	reg int		y;
	reg char	*end;

	temp = win->_y[win->_maxy-1];
	win->_firstch[win->_cury] = 0;
	win->_lastch[win->_cury] = win->_maxx - 1;
	for (y = win->_maxy - 1; y > win->_cury; --y) {
		win->_y[y] = win->_y[y-1];
		win->_firstch[y] = 0;
		win->_lastch[y] = win->_maxx - 1;
	}
	for (end = &temp[win->_maxx]; temp < end; )
		*temp++ = ' ';
	win->_y[win->_cury] = temp - win->_maxx;
	if (win->_cury == LINES - 1 && win->_y[LINES-1][COLS-1] != ' ')
		if (win->_scroll) {
			wrefresh(win);
			scroll(win);
			win->_cury--;
		}
		else
			return ERR;
	return OK;
}
deleteln.c      417658021   162   10    100444  522       `
# include	"curses.ext"

/*
 *	This routine deletes a line from the screen.  It leaves
 * (_cury,_curx) unchanged.
 *
 * 5/11/81 (Berkeley) @(#)deleteln.c	1.4
 */
wdeleteln(win)
reg WINDOW	*win; {

	reg char	*temp;
	reg int		y;
	reg char	*end;

	temp = win->_y[win->_cury];
	for (y = win->_cury; y < win->_maxy - 1; y++) {
		win->_y[y] = win->_y[y+1];
		win->_firstch[y] = 0;
		win->_lastch[y] = win->_maxx - 1;
	}
	for (end = &temp[win->_maxx]; temp < end; )
		*temp++ = ' ';
	win->_y[win->_maxy-1] = temp - win->_maxx;
}
scroll.c        417658041   162   10    100444  673       `
# include	"curses.ext"

/*
 *	This routine scrolls the window up a line.
 *
 * 5/11/81 (Berkeley) @(#)scroll.c	1.2
 */
scroll(win)
reg WINDOW	*win; {

	reg char	*sp;
	reg int		i;
	reg char	*temp;

	if (!win->_scroll)
		return ERR;
	temp = win->_y[0];
	for (i = 0; i < win->_maxy - 2; i++)
		win->_y[i] = win->_y[i+1];
	for (sp = temp; sp - temp < win->_maxx; )
		*sp++ = ' ';
	win->_y[win->_maxy - 1] = temp;
	win->_cury--;
	if (win == curscr) {
		putchar('\n');
		if (!NONL)
			win->_curx = 0;
# ifdef DEBUG
		fprintf(outf, "SCROLL: win == curscr\n");
# endif
	}
# ifdef DEBUG
	else
		fprintf(outf, "SCROLL: win [0%o] != curscr [0%o]\n",win,curscr);
# endif
	return OK;
}

getstr.c        417658021   162   10    100444  325       `
# include	"curses.ext"

/*
 *	This routine gets a string starting at (_cury,_curx)
 *
 * 4/29/81 (Berkeley) @(#)getstr.c	1.3
 */
wgetstr(win,str)
reg WINDOW	*win;
reg char	*str; {

	while ((*str = wgetch(win)) != ERR && *str != '\n');
		str++;
	if (*str == ERR) {
		*str = '\0';
		return ERR;
	}
	*str = '\0';
	return OK;
}

getch.c         417658036   162   10    100444  716       `
# include	"curses.ext"

/*
 *	This routine reads in a character from the window.
 *
 * 5/11/81 (Berkeley) @(#)getch.c	1.2
 */
wgetch(win)
reg WINDOW	*win; {

	reg bool	weset = FALSE;
	reg char	inp;

	if (!win->_scroll && (win->_flags&_FULLWIN)
	    && win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
		return ERR;
# ifdef DEBUG
	fprintf(outf, "WGETCH: _echoit = %c, _rawmode = %c\n", _echoit ? 'T' : 'F', _rawmode ? 'T' : 'F');
# endif
	if (_echoit && !_rawmode) {
		raw();
		weset++;
	}
	inp = getchar();
# ifdef DEBUG
	fprintf(outf,"WGETCH got '%s'\n",unctrl(inp));
# endif
	if (_echoit) {
		mvwaddch(curscr, win->_cury, win->_curx, inp);
		waddch(win, inp);
	}
	if (weset)
		noraw();
	return inp;
}
addstr.c        417658033   162   10    100444  322       `
# include	"curses.ext"

/*
 *	This routine adds a string starting at (_cury,_curx)
 *
 * 1/26/81 (Berkeley) @(#)addstr.c	1.1
 */
waddstr(win,str)
reg WINDOW	*win;
reg char	*str;
{
# ifdef DEBUG
	fprintf(outf, "WADDSTR(\"%s\")\n", str);
# endif
	while (*str)
		if (waddch(win, *str++) == ERR)
			return ERR;
	return OK;
}
addch.c         417659089   162   10    100644  1873      `
# include	"curses.ext"

/*
 *	This routine adds the character to the current position
 *
 * %G% (Berkeley) %W%
 */
waddch(win, c)
reg WINDOW	*win;
char		c;
{
	reg int		x, y;
	reg WINDOW	*wp;

	x = win->_curx;
	y = win->_cury;
# ifdef FULLDEBUG
	fprintf(outf, "ADDCH('%c') at (%d, %d)\n", c, y, x);
# endif
	if (y >= win->_maxy || x >= win->_maxx || y < 0 || x < 0)
		return ERR;
	switch (c) {
	  case '\t':
	  {
		reg int		newx;

		for (newx = x + (8 - (x & 07)); x < newx; x++)
			if (waddch(win, ' ') == ERR)
				return ERR;
		return OK;
	  }

	  default:
# ifdef FULLDEBUG
		fprintf(outf, "ADDCH: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
# endif
		if (win->_flags & _STANDOUT)
			c |= _STANDOUT;
		set_ch(win, y, x, c);
		for (wp = win->_nextp; wp != win; wp = wp->_nextp)
			set_ch(wp, y, x, c);
		win->_y[y][x++] = c;
		if (x >= win->_maxx) {
			x = 0;
newline:
			if (++y >= win->_maxy)
				if (win->_scroll) {
					wrefresh(win);
					scroll(win);
					--y;
				}
				else
					return ERR;
		}
# ifdef FULLDEBUG
		fprintf(outf, "ADDCH: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
# endif
		break;
	  case '\n':
		wclrtoeol(win);
		if (!NONL)
			x = 0;
		goto newline;
	  case '\r':
		x = 0;
		break;
	  case '\b':
		if (--x < 0)
			x = 0;
		break;
	}
	win->_curx = x;
	win->_cury = y;
	return OK;
}

/*
 * set_ch:
 *	Set the first and last change flags for this window.
 */
static
set_ch(win, y, x, ch)
reg WINDOW	*win;
int		y, x; {

	if (win->_orig != NULL) {
		y += win->_begy - win->_orig->_begy;
		x += win->_begx - win->_orig->_begx;
	}
	if (win->_y[y][x] != ch) {
		if (win->_firstch[y] == _NOCHANGE)
			win->_firstch[y] = win->_lastch[y] = x;
		else if (x < win->_firstch[y])
			win->_firstch[y] = x;
		else if (x > win->_lastch[y])
			win->_lastch[y] = x;
	}
}

move.c          417658365   162   10    100444  344       `
# include	"curses.ext"

/*
 *	This routine moves the cursor to the given point
 *
 * @(#)move.c	1.1 (Berkeley) 3/27/83
 */
wmove(win, y, x)
reg WINDOW	*win;
reg int		y, x; {

# ifdef DEBUG
	fprintf(outf, "MOVE to (%d, %d)\n", y, x);
# endif
	if (x >= win->_maxx || y >= win->_maxy)
		return ERR;
	win->_curx = x;
	win->_cury = y;
	return OK;
}
curses.c        417659562   162   10    100644  1040      `
/*
 * Define global variables
 *
 * %W% (Berkeley) %G%
 */
# include	"curses.h"

bool	_echoit		= TRUE,	/* set if stty indicates ECHO		*/
	_rawmode	= FALSE,/* set if stty indicates RAW mode	*/
	My_term		= FALSE,/* set if user specifies terminal type	*/
	_endwin		= FALSE;/* set if endwin has been called	*/

char	ttytype[10],		/* long name of tty			*/
	*Def_term	= "unknown";	/* default terminal type	*/

int	_tty_ch		= 1,	/* file channel which is a tty		*/
	LINES,			/* number of lines allowed on screen	*/
	COLS,			/* number of columns allowed on screen	*/
	_res_flg;		/* sgtty flags for reseting later	*/

WINDOW	*stdscr		= NULL,
	*curscr		= NULL;

# ifdef DEBUG
FILE	*outf;			/* debug output file			*/
# endif

SGTTY	_tty;			/* tty modes				*/

bool	AM, BS, CA, DA, DB, EO, GT, HZ, IN, MI, MS, NC, OS, UL, XN,
	NONL, UPPERCASE, normtty, _pfast;

char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *DC, *DL, *DM, *DO,
	*ED, *EI, *HO, *IC, *IM, *IP, *LL, *MA, *ND, *NL, *SE, *SF,
	*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VE, *VS, PC;
unctrl.c        417658023   162   10    100444  859       `
/*
 * define unctrl codes for each character
 *
 * 1/26/81 (Berkeley) @(#)unctrl.c	1.1
 */

/* LINTLIBRARY */
char	*_unctrl[]	= {	/* unctrl codes for ttys		*/
	"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K",
	"^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
	"^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_",
	" ", "!", "\"", "#", "$",  "%", "&", "'", "(", ")", "*", "+", ",", "-",
	".", "/", "0",  "1", "2",  "3", "4", "5", "6", "7", "8", "9", ":", ";",
	"<", "=", ">",  "?", "@",  "A", "B", "C", "D", "E", "F", "G", "H", "I",
	"J", "K", "L",  "M", "N",  "O", "P", "Q", "R", "S", "T", "U", "V", "W",
	"X", "Y", "Z",  "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e",
	"f", "g", "h",  "i", "j",  "k", "l", "m", "n", "o", "p", "q", "r", "s",
	"t", "u", "v",  "w", "x",  "y", "z", "{", "|", "}", "~", "^?"
};

standout.c      417658029   162   10    100444  453       `
/*
 * routines dealing with entering and exiting standout mode
 *
 * 1/26/81 (Berkeley) @(#)standout.c	1.1
 */

# include	"curses.ext"

/*
 * enter standout mode
 */
char *
wstandout(win)
reg WINDOW	*win;
{
	if (!SO && !UC)
		return FALSE;

	win->_flags |= _STANDOUT;
	return (SO ? SO : UC);
}

/*
 * exit standout mode
 */
char *
wstandend(win)
reg WINDOW	*win;
{
	if (!SO && !UC)
		return FALSE;

	win->_flags &= ~_STANDOUT;
	return (SE ? SE : UC);
}

tstp.c          419662752   162   10    100644  391       `
# include	<signal.h>

# include	"curses.ext"

/*
 * handle stop and start signals
 *
 * %G% (Berkeley) %W%
 */
tstp() {

# ifdef SIGTSTP

	SGTTY	tty;
# ifdef DEBUG
	if (outf)
		fflush(outf);
# endif
	tty = _tty;
	mvcur(0, COLS - 1, LINES - 1, 0);
	endwin();
	fflush(stdout);
	kill(0, SIGTSTP);
	signal(SIGTSTP, tstp);
	_tty = tty;
	stty(_tty_ch, &_tty);
	wrefresh(curscr);
# endif	SIGTSTP
}

insch.c         417658042   162   10    100444  769       `
# include	"curses.ext"

/*
 *	This routine performs an insert-char on the line, leaving
 * (_cury,_curx) unchanged.
 *
 * @(#)insch.c	1.2 (Berkeley) 4/17/81
 */
winsch(win, c)
reg WINDOW	*win;
char		c; {

	reg char	*temp1, *temp2;
	reg char	*end;

	end = &win->_y[win->_cury][win->_curx];
	temp1 = &win->_y[win->_cury][win->_maxx - 1];
	temp2 = temp1 - 1;
	while (temp1 > end)
		*temp1-- = *temp2--;
	*temp1 = c;
	win->_lastch[win->_cury] = win->_maxx - 1;
	if (win->_firstch[win->_cury] == _NOCHANGE ||
	    win->_firstch[win->_cury] > win->_curx)
		win->_firstch[win->_cury] = win->_curx;
	if (win->_cury == LINES - 1 && win->_y[LINES-1][COLS-1] != ' ')
		if (win->_scroll) {
			wrefresh(win);
			scroll(win);
			win->_cury--;
		}
		else
			return ERR;
	return OK;
}

delch.c         417658034   162   10    100444  595       `
# include	"curses.ext"

/*
 *	This routine performs an insert-char on the line, leaving
 * (_cury,_curx) unchanged.
 *
 * @(#)delch.c	1.2 (Berkeley) 5/11/81
 */
wdelch(win)
reg WINDOW	*win; {

	reg char	*temp1, *temp2;
	reg char	*end;

	end = &win->_y[win->_cury][win->_maxx - 1];
	temp1 = &win->_y[win->_cury][win->_curx];
	temp2 = temp1 + 1;
	while (temp1 < end)
		*temp1++ = *temp2++;
	*temp1 = ' ';
	win->_lastch[win->_cury] = win->_maxx - 1;
	if (win->_firstch[win->_cury] == _NOCHANGE ||
	    win->_firstch[win->_cury] > win->_curx)
		win->_firstch[win->_cury] = win->_curx;
	return OK;
}

llib-lcurses    417658045   162   10    100444  3369      `
/* @(#)llib-lcurses	1.5 (Berkeley) 3/27/83 */

/* LINTLIBRARY */
# include	"curses.h"

/*
 * Fake declarations; all of these are declared as externs in curses.h,
 * but lint needs something a little more solid than that
 */

bool	AM, BS, CA, DA, DB, EO, GT, HZ, IN, MI, MS, NC, OS, UL, XN;

char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *DC, *DL, *DM, *DO, *ED,
	*EI, *HO, *IC, *IM, *IP, *LL, *MA, *ND, *SE, *SF, *SO, *SR,
	*TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VE, *VS, PC;

/*
 * From the tty modes...
 */

bool	NONL, UPPERCASE, normtty, _pfast;

# define	WINDOW	struct _win_st

bool	My_term, _echoit, _rawmode, _endwin;

char	*Def_term, ttytype[];

int	LINES, COLS, _tty_ch, _res_flg;

SGTTY	_tty;

WINDOW	*stdscr, *curscr;

	box(win,vert,hor) WINDOW *win; int vert, hor; {}
	delwin(win) WINDOW *win; {}
	endwin() {}
	gettmode() {}
WINDOW *initscr() {
	AL = AL;
	AM = AM;
	BC = BC;
	BS = BS;
	BT = BT;
	CA = CA;
	CD = CD;
	CE = CE;
	CL = CL;
	CM = CM;
	DA = DA;
	DB = DB;
	DC = DC;
	DL = DL;
	DM = DM;
	DO = DO;
	ED = ED;
	EO = EO;
	EI = EI;
	GT = GT;
	HO = HO;
	HZ = HZ;
	IC = IC;
	IN = IN;
	IM = IM;
	IP = IP;
	LL = LL;
	MA = MA;
	MI = MI;
	NC = NC;
	ND = ND;
	OS = OS;
	PC = PC;
	SE = SE;
	SF = SF;
	SO = SO;
	SR = SR;
	TA = TA;
	TE = TE;
	TI = TI;
	UC = UC;
	UE = UE;
	UL = UL;
	UP = UP;
	US = US;
	VB = VB;
	VE = VE;
	VS = VS;
	XN = XN;
	NONL = NONL;
	UPPERCASE = UPPERCASE;
	normtty = normtty;
	_pfast = _pfast;
	_tty = _tty;
	My_term = My_term;
	_echoit = _echoit;
	_rawmode = _rawmode;
	LINES = LINES;
	COLS = COLS;
	_tty_ch = _tty_ch;
	_res_flg = _res_flg;
	stdscr = stdscr;
	curscr = curscr;
	_echoit = _echoit;
	_rawmode = _rawmode;
	_tty_ch = _tty_ch;
	return (WINDOW *) 0;
}
char *	longname(bp, def) char *bp, *def; { return bp; }
	mvcur(ly,lx,y,x) int ly, lx, y, x; { }
/* VARARGS3 */
	mvprintw(y,x,fmt) int y, x; char *fmt; { return 0; }
/* VARARGS3 */
	mvscanw(y,x,fmt) int y, x; char *fmt; { return 0; }
/* VARARGS4 */
	mvwprintw(win,y,x,fmt) WINDOW *win; int y, x; char *fmt; { return 0; }
/* VARARGS4 */
	mvwscanw(win,y,x,fmt) WINDOW *win; int y, x; char *fmt; { return 0; }
WINDOW *newwin(Nl, Nc, by, bx) int Nl, Nc, by, bx; { return (WINDOW *) 0; }
	overlay(win1, win2) WINDOW *win1, *win2; { }
	overwrite(win1, win2) WINDOW *win1, *win2; { }
/* VARARGS1 */
	printw(fmt) char *fmt; { return 0; }
/* VARARGS1 */
	scanw(fmt) char *fmt; { return 0; }
	scroll(win) WINDOW *win; { return 0; }
	setterm(type) char *type; { return 0; }
WINDOW *subwin(o, Nl, Nc, by, bx) WINDOW *o; int Nl, Nc, by, bx; { return o; }
	waddch(win,ch) WINDOW *win; char ch; { return 0; }
	waddstr(win,str) WINDOW *win; char *str; { return 0; }
	wclear(win) WINDOW *win; { return 0; }
	wclrtobot(win) WINDOW *win; { return 0; }
	wclrtoeol(win) WINDOW *win; { return 0; }
	wdeleteln(win) WINDOW *win; { return 0; }
	werase(win) WINDOW *win; { return 0; }
	wgetch(win) WINDOW *win; { return '0'; }
	wgetstr(win,str) WINDOW *win; char *str; { return 0; }
	winsertln(win) WINDOW *win; { return 0; }
	wmove(win,y,x) WINDOW *win; int y, x; { return 0; }
/* VARARGS2 */
	wprintw(win,fmt) WINDOW *win; char *fmt; { return 0; }
	wrefresh(win) WINDOW *win; { return 0; }
/* VARARGS2 */
	wscanw(win,fmt) WINDOW *win; char *fmt; { return 0; }
	/* These really return char *'s but this will do. */
int	wstandout(win) WINDOW *win; { return 0; }
int	wstandend(win) WINDOW *win; { return 0; }