/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred."
 *
 */
/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: scroll.c 1.4 89/10/10 $@(#)curses:screen/scroll.c	1.5"
# include	"curses.ext"

/*
 *	This routine scrolls the window up a line.
 *
 */
scroll(win)
WINDOW *win;
{
	_tscroll(win, 1);
}

int
_tscroll(win, musttouch)
register WINDOW	*win;
int musttouch;
{
	register int	i;
	register chtype	*temp;
	register int	top, bot;
	extern void memSset();

#ifdef DEBUG
	if (win == stdscr) {
		if(outf) fprintf(outf, "scroll(stdscr, %d)\n", musttouch);
	} else if (win == curscr) {
		if(outf) fprintf(outf, "scroll(curscr, %d)\n", musttouch);
	} else {
		if(outf) fprintf(outf, "scroll(%x, %d)\n", win, musttouch);
	}
#endif
	if (!win->_scroll)
		return ERR;

	/* scroll the window lines themselves up */
	top = win->_tmarg;
	bot = win->_bmarg;
	temp = win->_y[top];
	for (i = top; i < bot; i++)
		win->_y[i] = win->_y[i+1];

	/* Put a blank line in the opened up space */
	memSset(temp, (chtype)' ', win->_maxx);
	win->_y[bot] = temp;
	if (win->_cury > 0)
		win->_cury--;
	win->_need_idl = TRUE;
# ifdef DEBUG
	if(outf) fprintf(outf, "SCROLL: win [0%o], curscr [0%o], top %d, bot %d\n",win,curscr, top, bot);
# endif
	if (win->_flags&_FULLWIN &&
	    win->_tmarg == 0 &&
	    win->_bmarg == win->_maxx - 1)
		_scrdown();
	else
		musttouch = 1;
	if (musttouch)
		touchwin(win);
	return OK;
}
