char    line[128];
char    line[NBUFN+128];
static BUFFER  *makelist	__P((void));/* * Attach a buffer to a window. The values of dot and mark come * from the buffer if the use count is 0. Otherwise, they come * from some other window.  *scratch* is the default alternate * buffer. *//* ARGSUSED */intusebuffer(f, n)	int     f, n;{	BUFFER *bp;	int     s;	char    bufn[NBUFN];	/* Get buffer to use from user */	if ((curbp->b_altb == NULL)	    && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL))		s = eread("Switch to buffer: ", bufn, NBUFN, EFNEW | EFBUF);	else		s = eread("Switch to buffer: (default %s) ", bufn, NBUFN,			  EFNEW | EFBUF, curbp->b_altb->b_bname);	if (s == ABORT)		return s;	if (s == FALSE && curbp->b_altb != NULL)		bp = curbp->b_altb;	else if ((bp = bfind(bufn, TRUE)) == NULL)		return FALSE;	/* and put it in current window */	curbp = bp;	return showbuffer(bp, curwp, WFFORCE | WFHARD);}/* * pop to buffer asked for by the user. *//* ARGSUSED */intpoptobuffer(f, n)	int     f, n;{	BUFFER *bp;	MGWIN  *wp;	int     s;	char    bufn[NBUFN];	/* Get buffer to use from user */	if ((curbp->b_altb == NULL)	    && ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL))		s = eread("Switch to buffer in other window: ", bufn, NBUFN,			  EFNEW | EFBUF);	else		s = eread("Switch to buffer in other window: (default %s) ",			bufn, NBUFN, EFNEW | EFBUF, curbp->b_altb->b_bname);	if (s == ABORT)		return s;	if (s == FALSE && curbp->b_altb != NULL)		bp = curbp->b_altb;	else if ((bp = bfind(bufn, TRUE)) == NULL)		return FALSE;	/* and put it in a new window */	if ((wp = popbuf(bp)) == NULL)		return FALSE;	curbp = bp;	curwp = wp;	return TRUE;}/* * Dispose of a buffer, by name. * Ask for the name. Look it up (don't get too * upset if it isn't there at all!). Clear the buffer (ask * if the buffer has been changed). Then free the header * line and the buffer header. Bound to "C-X K". *//* ARGSUSED */intkillbuffer(f, n)	int     f, n;{	BUFFER *bp;	BUFFER *bp1;	BUFFER *bp2;	MGWIN  *wp;	int     s;	char    bufn[NBUFN];	if ((s = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF,		       curbp->b_bname)) == ABORT)		return (s);	else if (s == FALSE)		bp = curbp;	else if ((bp = bfind(bufn, FALSE)) == NULL)		return FALSE;	/*	 * Find some other buffer to display. try the alternate buffer,	 * then the first different buffer in the buffer list.  If there's	 * only one buffer, create buffer *scratch* and make it the alternate	 * buffer.  Return if *scratch* is only buffer...	 */	if ((bp1 = bp->b_altb) == NULL) {		bp1 = (bp == bheadp) ? bp->b_bufp : bheadp;		if (bp1 == NULL) {			/* only one buffer. see if it's *scratch* */			if (bp == bfind("*scratch*", FALSE))				return FALSE;			/* create *scratch* for alternate buffer */			if ((bp1 = bfind("*scratch*", TRUE)) == NULL)				return FALSE;		}	}	if (bclear(bp) != TRUE)		return TRUE;	for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) {		if (wp->w_bufp == bp) {			bp2 = bp1->b_altb;	/* save alternate buffer */			if (showbuffer(bp1, wp, WFMODE | WFFORCE | WFHARD))				bp1->b_altb = bp2;			else				bp1 = bp2;		}	}	if (bp == curbp)		curbp = bp1;	free(bp->b_linep);			/* Release header line.  */	bp2 = NULL;				/* Find the header.	 */	bp1 = bheadp;	while (bp1 != bp) {		if (bp1->b_altb == bp)			bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;		bp2 = bp1;		bp1 = bp1->b_bufp;	}	bp1 = bp1->b_bufp;			/* Next one in chain.	 */	if (bp2 == NULL)			/* Unlink it.		 */		bheadp = bp1;	else		bp2->b_bufp = bp1;	while (bp1 != NULL) {			/* Finish with altb's	 */		if (bp1->b_altb == bp)			bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb;		bp1 = bp1->b_bufp;	}	free(bp->b_bname);			/* Release name block	 */	free(bp);				/* Release buffer block */	return TRUE;}/* * Save some buffers - just call anycb with the arg flag. *//* ARGSUSED */intsavebuffers(f, n)	int f, n;{	if (anycb(f) == ABORT)		return ABORT;	return TRUE;}/* * Display the buffer list. This is done * in two parts. The "makelist" routine figures out * the text, and puts it in a buffer. "popbuf" * then pops the data onto the screen. Bound to * "C-X C-B". *//* ARGSUSED */intlistbuffers(f, n)	int f, n;{	BUFFER *bp;	MGWIN  *wp;	if ((bp = makelist()) == NULL || (wp = popbuf(bp)) == NULL)		return FALSE;	wp->w_dotp = bp->b_dotp;/* fix up if window already on screen */	wp->w_doto = bp->b_doto;	return TRUE;}/* * This routine rebuilds the text for the * list buffers command. Return TRUE if * everything works. Return FALSE if there * is an error (if there is no memory). */static BUFFER *makelist(){	char   *cp1;	char   *cp2;	int     c;	BUFFER *bp;	LINE   *lp;	RSIZE   nbytes;	BUFFER *blp;	char    b[6 + 1];	char    line[128];	if ((blp = bfind("*Buffer List*", TRUE)) == NULL)		return NULL;	if (bclear(blp) != TRUE)		return NULL;	blp->b_flag &= ~BFCHG;		/* Blow away old.	 */	(VOID) strcpy(line, " MR Buffer");	cp1 = line + 10;	while (cp1 < line + 4 + NBUFN + 1)		*cp1++ = ' ';	(VOID) strcpy(cp1, "Size   File");	if (addline(blp, line) == FALSE)		return NULL;	(VOID) strcpy(line, " -- ------");	cp1 = line + 10;	while (cp1 < line + 4 + NBUFN + 1)		*cp1++ = ' ';	(VOID) strcpy(cp1, "----   ----");	if (addline(blp, line) == FALSE)		return NULL;	bp = bheadp;				/* For all buffers	 */	while (bp != NULL) {		cp1 = &line[0];			/* Start at left edge	 */		*cp1++ = (bp == curbp) ? '.' : ' ';		*cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ';		*cp1++ = ' ';			/* Gap.			 */		*cp1++ = ' ';		cp2 = &bp->b_bname[0];		/* Buffer name		 */		while ((c = *cp2++) != 0)			*cp1++ = c;		while (cp1 < &line[4 + NBUFN + 1])			*cp1++ = ' ';		nbytes = 0;			/* Count bytes in buf.	 */		if (bp != blp) {			lp = lforw(bp->b_linep);			while (lp != bp->b_linep) {				nbytes += llength(lp) + 1;				lp = lforw(lp);			}			if (nbytes)				nbytes--;	/* no bonus newline	 */		}		(VOID) itor(b, 6, nbytes);	/* 6 digit buffer size. */		cp2 = &b[0];		while ((c = *cp2++) != 0)			*cp1++ = c;		*cp1++ = ' ';			/* Gap..		 */		cp2 = &bp->b_fname[0];		/* File name		 */		if (*cp2 != 0) {			while ((c = *cp2++) != 0) {				if (cp1 < &line[128 - 1])					*cp1++ = c;			}		}		*cp1 = 0;	/* Add to the buffer.	 */		if (addline(blp, line) == FALSE)			return NULL;		bp = bp->b_bufp;	}	blp->b_dotp = lforw(blp->b_linep);	/* put dot at beginning of						 * buffer */	blp->b_doto = 0;	return blp;				/* All done		 */}