register Size_t mincols;
register size_t mincols;
Reallocate(sbuf, sbufaddr, nrow, ncol, oldrow, oldcol)    ScrnBuf *sbuf;    Char **sbufaddr;    int nrow, ncol, oldrow, oldcol;{	register ScrnBuf base;	register Char *tmp;	register int i, j, k, minrows;	register Size_t mincols;	Char *oldbuf;	int move_down = 0, move_up = 0;	size_t entries = MAX_PTRS * nrow;	size_t length  = BUF_PTRS * nrow * ncol;	if (sbuf == NULL || *sbuf == NULL) {		return 0;	}	oldbuf = *sbufaddr;	/*	 * Special case if oldcol == ncol - straight forward realloc and	 * update of the additional lines in sbuf	 *	 * FIXME: this is a good idea, but doesn't seem to be implemented.	 * -gildea	 */	/* 	 * realloc sbuf, the pointers to all the lines.	 * If the screen shrinks, remove lines off the top of the buffer	 * if resizeGravity resource says to do so.	 */	if (nrow < oldrow	 && term->misc.resizeGravity == SouthWestGravity) {	    /* Remove lines off the top of the buffer if necessary. */	    move_up = (oldrow - nrow)		        - (term->screen.max_row - term->screen.cur_row);	    if (move_up < 0)		move_up = 0;	    /* Overlapping memmove here! */	    memmove( *sbuf, *sbuf + (move_up * MAX_PTRS),		  MAX_PTRS * (oldrow - move_up) * sizeof((*sbuf)[0]) );	}	*sbuf = (ScrnBuf) realloc((char *) (*sbuf), entries * sizeof(char *));	if (*sbuf == 0)	    SysError(ERROR_RESIZE);	base = *sbuf;	/* 	 *  create the new buffer space and copy old buffer contents there	 *  line by line.	 */	if ((tmp = (Char *)calloc(length, sizeof(Char))) == 0)		SysError(ERROR_SREALLOC);	*sbufaddr = tmp;	minrows = (oldrow < nrow) ? oldrow : nrow;	mincols = (oldcol < ncol) ? oldcol : ncol;	if (nrow > oldrow	 && term->misc.resizeGravity == SouthWestGravity) {	    /* move data down to bottom of expanded screen */	    move_down = Min(nrow - oldrow, term->screen.savedlines);	    tmp += (ncol * move_down * BUF_PTRS);	}	for (i = k = 0; i < minrows; i++) {		k += BUF_HEAD;		for (j = BUF_HEAD; j < MAX_PTRS; j++) {			memcpy(tmp, base[k++], mincols);			tmp += ncol;		}	}	/*	 * update the pointers in sbuf	 */	for (i = k = 0, tmp = *sbufaddr; i < nrow; i++) {		for (j = 0; j < BUF_HEAD; j++)			base[k++] = 0;		for (j = BUF_HEAD; j < MAX_PTRS; j++) {			base[k++] = tmp;			tmp += ncol;		}	}        /* Now free the old buffer */	free(oldbuf);	return move_down ? move_down : -move_up; /* convert to rows */}