line[i] = erase_char;
line[j] = erase_char;
void term_size(int newrows, int newcols, int newsavelines) {    tree234 *newsb, *newscreen, *newalt;    unsigned long *newdisp, *newwant, *oldline, *line;    int i, j, ccols;    int posn, oldposn, furthest_back, oldsbsize;    int save_alt_which = alt_which;    if (newrows == rows && newcols == cols && newsavelines == savelines)	return;			       /* nothing to do */    deselect();    swap_screen(0);    alt_t = marg_t = 0;    alt_b = marg_b = newrows - 1;    newsb = newtree234(NULL);    newscreen = newtree234(NULL);    ccols = (cols < newcols ? cols : newcols);    oldsbsize = scrollback ? count234(scrollback) : 0;    furthest_back = newrows - rows - oldsbsize;    if (furthest_back > 0)	furthest_back = 0;    if (furthest_back < -newsavelines)	furthest_back = -newsavelines;    for (posn = newrows; posn-- > furthest_back ;) {	oldposn = posn - newrows + rows;	if (rows == -1 || oldposn < -oldsbsize) {	    line = smalloc(TSIZE * (newcols + 1));	    for (j = 0; j < newcols; j++)		line[j] = erase_char;	    line[newcols] = 0;	} else {	    oldline = (oldposn >= 0 ?		       delpos234(screen, count234(screen)-1) :		       delpos234(scrollback, count234(scrollback)-1));	    if (newcols != cols) {		line = smalloc(TSIZE * (newcols + 1));		for (j = 0; j < ccols; j++)		    line[j] = oldline[j];		for (j = ccols; j < newcols; j++)		    line[j] = erase_char;		line[newcols] = oldline[cols] & LATTR_MODE;		sfree(oldline);	    } else {		line = oldline;	    }	}	if (posn >= 0)	    addpos234(newscreen, line, 0);	else	    addpos234(newsb, line, 0);    }    disptop = 0;    if (scrollback) freetree234(scrollback);    if (screen) freetree234(screen);    scrollback = newsb;    screen = newscreen;    newdisp = smalloc (newrows*(newcols+1)*TSIZE);    for (i=0; i<newrows*(newcols+1); i++)	newdisp[i] = ATTR_INVALID;    sfree (disptext);    disptext = newdisp;    newwant = smalloc (newrows*(newcols+1)*TSIZE);    for (i=0; i<newrows*(newcols+1); i++)	newwant[i] = ATTR_INVALID;    sfree (wanttext);    wanttext = newwant;    newalt = newtree234(NULL);    for (i=0; i<newrows; i++) {	line = smalloc(TSIZE * (newcols+1));	for (j = 0; j <= newcols; j++)	    line[i] = erase_char;	addpos234(newalt, line, i);    }    if (alt_screen) {	while (NULL != (line = delpos234(alt_screen, 0)))	    sfree(line);	freetree234(alt_screen);    }    alt_screen = newalt;    sfree (selspace);    selspace = smalloc ( (newrows+newsavelines) * (newcols+sizeof(sel_nl)) );    tabs = srealloc (tabs, newcols*sizeof(*tabs));    {	int i;	for (i = (cols > 0 ? cols : 0); i < newcols; i++)	    tabs[i] = (i % 8 == 0 ? TRUE : FALSE);    }    if (rows > 0)	curs.y += newrows - rows;    if (curs.y < 0)	curs.y = 0;    if (curs.y >= newrows)	curs.y = newrows-1;    if (curs.x >= newcols)	curs.x = newcols-1;    alt_x = alt_y = 0;    wrapnext = alt_wnext = FALSE;    rows = newrows;    cols = newcols;    savelines = newsavelines;    fix_cpos;    swap_screen(save_alt_which);    update_sbar();    term_update();}