Review newmlargt interface and obsolete mlreplyt.

This commit is contained in:
Renaud 2015-09-29 10:25:36 +08:00
parent ce4d105794
commit 198980b81f
3 changed files with 35 additions and 41 deletions

61
input.c
View File

@ -102,35 +102,36 @@ static int nextarg( const char *prompt, char *buf, int size, int terminator) {
return gettokval( buf, size) ; return gettokval( buf, size) ;
} }
static newarg_t *newnextarg( const char *prompt, int size, int terminator) { static int newnextarg( char **outbufref, const char *prompt, int size,
newarg_t *argp ; int terminator) {
int status ;
char *buf ;
argp = malloc( sizeof( newarg_t)) ; /* if we are interactive, go get it! */
if( argp != NULL) { if( clexec == FALSE) {
/* if we are interactive, go get it! */ if( size <= 1) {
if( clexec == FALSE) { size = term.t_ncol - strlen( prompt) + 1 ;
if( size <= 1) { if( size < 24)
size = term.t_ncol - strlen( prompt) + 1 ; size = 24 ;
if( size < 24)
size = 24 ;
}
argp->buf = malloc( size) ;
if( argp->buf != NULL) {
argp->status = getstring( prompt, argp->buf, size, terminator) ;
if( TRUE != argp->status) {
free( argp->buf) ;
argp->buf = NULL ;
}
} else
argp->status = FALSE ;
} else {
argp->buf = getnewtokval() ;
argp->status = (argp->buf == NULL) ? FALSE : TRUE ;
} }
buf = malloc( size) ;
if( buf == NULL)
status = FALSE ;
else {
status = getstring( prompt, buf, size, terminator) ;
if( TRUE != status) {
free( buf) ;
buf = NULL ;
}
}
} else {
buf = getnewtokval() ;
status = (buf == NULL) ? FALSE : TRUE ;
} }
return argp ; *outbufref = buf ;
return status ;
} }
/* /*
@ -145,12 +146,8 @@ int mlreply( const char *prompt, char *buf, int nbuf) {
return nextarg( prompt, buf, nbuf, nlc) ; return nextarg( prompt, buf, nbuf, nlc) ;
} }
int mlreplyt( const char *prompt, char *buf, int nbuf) { int newmlargt( char **outbufref, const char *prompt, int size) {
return nextarg( prompt, buf, nbuf, metac) ; return newnextarg( outbufref, prompt, size, metac) ;
}
newarg_t *newmlargt( const char *prompt, int size) {
return newnextarg( prompt, size, metac) ;
} }
/* /*

View File

@ -4,11 +4,6 @@
#include "bind.h" #include "bind.h"
typedef struct {
int status ;
char *buf ;
} newarg_t ;
typedef enum { typedef enum {
STOP, PLAY, RECORD STOP, PLAY, RECORD
} kbdstate ; } kbdstate ;
@ -29,8 +24,7 @@ extern const int nlc ; /* end of input char */
int mlyesno( const char *prompt) ; int mlyesno( const char *prompt) ;
int mlreply( const char *prompt, char *buf, int nbuf) ; int mlreply( const char *prompt, char *buf, int nbuf) ;
int mlreplyt( const char *prompt, char *buf, int nbuf) ; int newmlargt( char **outbufref, const char *prompt, int size) ;
newarg_t *newmlargt( const char *prompt, int size) ;
int ectoc( int c) ; int ectoc( int c) ;
fn_t getname( void) ; fn_t getname( void) ;
int tgetc( void) ; int tgetc( void) ;

View File

@ -705,6 +705,7 @@ static int readpattern(char *prompt, char *apat, int srch)
{ {
int status; int status;
char tpat[NPAT + 20]; char tpat[NPAT + 20];
char *dynpat ; /* dynamically allocated pattern buffer */
setprompt( tpat, NPAT / 2, prompt, apat) ; setprompt( tpat, NPAT / 2, prompt, apat) ;
@ -713,9 +714,11 @@ static int readpattern(char *prompt, char *apat, int srch)
* Then, if it's the search string, make a reversed pattern. * Then, if it's the search string, make a reversed pattern.
* *Then*, make the meta-pattern, if we are defined that way. * *Then*, make the meta-pattern, if we are defined that way.
*/ */
status = mlreplyt( tpat, tpat, NPAT) ; status = newmlargt( &dynpat, tpat, NPAT) ;
if( status == TRUE) { if( status == TRUE) {
strcpy(apat, tpat); strncpy( apat, dynpat, NPAT - 1) ;
apat[ NPAT - 1] = 0 ;
free( dynpat) ;
if (srch) { /* If we are doing the search string. */ if (srch) { /* If we are doing the search string. */
/* Reverse string copy, and remember /* Reverse string copy, and remember
* the length for substitution purposes. * the length for substitution purposes.