sbtop -= lines * (cols+1); if (sbtop < text) sbtop = text; scroll_size += scroll_top - sbtop; scroll_top = sbtop; update_sbar();
if (scroll_size >= 0 && !recursive) { newscr = scrtop + lines * (cols+1);  if (newscr > sbbot && botline == rows-1) {   i = (rows+savelines)/10;   if ( i<savelines-1) { recursive ++; scroll(topline, botline, i, sb); recursive --;  newscr = scrtop - i * (cols+1); if (scrtop_is_disptop) disptop = newscr; scrtop = newscr; }  newscr = scrtop + lines * (cols+1); }  if (newscr <= sbbot) { if (scrtop_is_disptop) disptop = newscr; scrtop = newscr;  if (botline == rows-1 ) for (i = 0; i < size; i++) scrtop[i+scroll_size] = erase_char;  update_sbar(); fix_cpos;  if (botline != rows-1) {  scroll(botline-lines+1, rows-1, -lines, 0); } return ; }    if (savelines <= 400) { sbtop -= lines * (cols+1); if (sbtop < text) sbtop = text; scroll_size += scroll_top - sbtop; scroll_top = sbtop;  update_sbar(); } } else {   sbtop -= lines * (cols+1); if (sbtop < text) sbtop = text; scroll_size += scroll_top - sbtop; scroll_top = sbtop;  update_sbar(); }
static void scroll (int topline, int botline, int lines, int sb) {    unsigned long *scroll_top;    int scroll_size, size, i;    scroll_top = scrtop + topline*(cols+1);    size = (lines < 0 ? -lines : lines) * (cols+1);    scroll_size = (botline - topline + 1) * (cols+1) - size;    if (lines > 0 && topline == 0 && alt_which == 0 && sb) {	/*	 * Since we're going to scroll the top line and we're on the 	 * scrolling screen let's also affect the scrollback buffer.	 */	sbtop -= lines * (cols+1);	if (sbtop < text)	    sbtop = text;	scroll_size += scroll_top - sbtop;	scroll_top = sbtop;	update_sbar();    }    if (scroll_size < 0) {	size += scroll_size;	scroll_size = 0;    }    if (lines > 0) {	if (scroll_size)	    memmove (scroll_top, scroll_top + size, scroll_size*TSIZE);	for (i = 0; i < size; i++)	    scroll_top[i+scroll_size] = erase_char;	if (selstart > scroll_top &&	    selstart < scroll_top + size + scroll_size) {	    selstart -= size;	    if (selstart < scroll_top)		selstart = scroll_top;	}	if (selend > scroll_top &&	    selend < scroll_top + size + scroll_size) {	    selend -= size;	    if (selend < scroll_top)		selend = scroll_top;	}    } else {	if (scroll_size)	    memmove (scroll_top + size, scroll_top, scroll_size*TSIZE);	for (i = 0; i < size; i++)	    scroll_top[i] = erase_char;	if (selstart > scroll_top &&	    selstart < scroll_top + size + scroll_size) {	    selstart += size;	    if (selstart > scroll_top + size + scroll_size)		selstart = scroll_top + size + scroll_size;	}	if (selend > scroll_top &&	    selend < scroll_top + size + scroll_size) {	    selend += size;	    if (selend > scroll_top + size + scroll_size)		selend = scroll_top + size + scroll_size;	}    }}