Buffer commands based on newmlarg (replacement of mlreply).

This commit is contained in:
Renaud 2015-10-01 09:11:54 +08:00
parent db30d6d734
commit b86ceeaf5e
1 changed files with 61 additions and 41 deletions

102
buffer.c
View File

@ -55,17 +55,24 @@ static void l_to_a( char *buf, int width, long num) ;
* if the use count is 0. Otherwise, they come * if the use count is 0. Otherwise, they come
* from some other window. * from some other window.
*/ */
int usebuffer(int f, int n) int usebuffer( int f, int n) {
{ struct buffer *bp ;
struct buffer *bp; int status ;
int s; char *bufn ;
bname_t bufn ;
if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE) /* Get buffer name */
return s; status = newmlarg( &bufn, "Use buffer: ", sizeof( bname_t)) ;
if ((bp = bfind(bufn, TRUE, 0)) == NULL) if( status != TRUE)
return FALSE; return status ;
return swbuffer(bp);
/* Find buffer in list */
bp = bfind( bufn, TRUE, 0) ;
free( bufn) ;
if( bp == NULL)
return FALSE ;
/* Switch to buffer */
return swbuffer( bp) ;
} }
/* /*
@ -164,19 +171,26 @@ int swbuffer(struct buffer *bp)
* if the buffer has been changed). Then free the header * if the buffer has been changed). Then free the header
* line and the buffer header. Bound to "C-X K". * line and the buffer header. Bound to "C-X K".
*/ */
int killbuffer(int f, int n) int killbuffer( int f, int n) {
{ struct buffer *bp ;
struct buffer *bp; int status ;
int s; char *bufn ;
bname_t bufn ;
if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE) /* Get buffer name */
return s; status = newmlarg( &bufn, "Kill buffer: ", sizeof( bname_t)) ;
if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */ if( status != TRUE)
return TRUE; return status ;
if (bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE; /* by doing nothing. */ /* Find buffer in list */
return zotbuf(bp); bp = bfind( bufn, FALSE, 0) ;
free( bufn) ;
if( bp == NULL) /* Easy if unknown. */
return TRUE ;
if( bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE ; /* by doing nothing. */
return zotbuf( bp) ;
} }
/* /*
@ -215,31 +229,37 @@ int zotbuf(struct buffer *bp)
* *
* int f, n; default Flag & Numeric arg * int f, n; default Flag & Numeric arg
*/ */
int namebuffer(int f, int n) int namebuffer( int f, int n) {
{ struct buffer *bp ; /* pointer to scan through all buffers */
struct buffer *bp; /* pointer to scan through all buffers */ int status ;
bname_t bufn ; /* buffer to hold buffer name */ char *bufn ; /* buffer to hold buffer name */
/* prompt for and get the new buffer name */ /* prompt for and get the new buffer name */
ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) != ask:
TRUE) status = newmlarg( &bufn, "Change buffer name to: ", sizeof( bname_t)) ;
return FALSE; if( status != TRUE)
return status ;
/* and check for duplicates */ /* and check for duplicates */
bp = bheadp; bp = bheadp ;
while (bp != NULL) { while( bp != NULL) {
if (bp != curbp) { if( bp != curbp) {
/* if the names the same */ /* retry if the names are the same */
if (strcmp(bufn, bp->b_bname) == 0) if( strcmp( bufn, bp->b_bname) == 0) {
goto ask; /* try again */ free( bufn) ;
goto ask ; /* try again */
}
} }
bp = bp->b_bufp; /* onward */
bp = bp->b_bufp ; /* onward */
} }
strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */ strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
curwp->w_flag |= WFMODE; /* make mode line replot */ free( bufn) ;
curwp->w_flag |= WFMODE ; /* make mode line replot */
mloutstr( "") ; /* erase message line */ mloutstr( "") ; /* erase message line */
return TRUE; return TRUE ;
} }
/* /*