diff --git a/input.c b/input.c index 5731ccd..e642a7a 100644 --- a/input.c +++ b/input.c @@ -102,24 +102,35 @@ static int nextarg( const char *prompt, char *buf, int size, int terminator) { return gettokval( buf, size) ; } -static char *newnextarg( const char *prompt, int terminator) { - /* if we are interactive, go get it! */ - if( clexec == FALSE) { - char *buf ; - int size ; +static newarg_t *newnextarg( const char *prompt, int size, int terminator) { + newarg_t *argp ; - size = term.t_ncol + 1 ; - buf = malloc( size) ; - if( buf != NULL) { - if( TRUE != getstring( prompt, buf, size, terminator)) { - free( buf) ; - buf = NULL ; - } - } - - return buf ; - } else - return getnewtokval() ; + argp = malloc( sizeof( newarg_t)) ; + if( argp != NULL) { + /* if we are interactive, go get it! */ + if( clexec == FALSE) { + if( size <= 1) { + size = term.t_ncol - strlen( prompt) + 1 ; + 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 ; + } + } + + return argp ; } /* @@ -138,8 +149,8 @@ int mlreplyt( const char *prompt, char *buf, int nbuf) { return nextarg( prompt, buf, nbuf, metac) ; } -char *newmlreplyt( const char *prompt) { - return newnextarg( prompt, metac) ; +newarg_t *newmlargt( const char *prompt, int size) { + return newnextarg( prompt, size, metac) ; } /* diff --git a/input.h b/input.h index f163c8d..85c1ef4 100644 --- a/input.h +++ b/input.h @@ -4,6 +4,11 @@ #include "bind.h" +typedef struct { + int status ; + char *buf ; +} newarg_t ; + typedef enum { STOP, PLAY, RECORD } kbdstate ; @@ -25,7 +30,7 @@ extern const int nlc ; /* end of input char */ int mlyesno( const char *prompt) ; int mlreply( const char *prompt, char *buf, int nbuf) ; int mlreplyt( const char *prompt, char *buf, int nbuf) ; -char *newmlreplyt( const char *prompt) ; +newarg_t *newmlargt( const char *prompt, int size) ; int ectoc( int c) ; fn_t getname( void) ; int tgetc( void) ; diff --git a/random.c b/random.c index 1dcc0bb..742c465 100644 --- a/random.c +++ b/random.c @@ -1185,22 +1185,28 @@ int fmatch(int ch) } static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { + newarg_t *argp ; int status ; /* status return code */ char *tstring ; /* string to add */ /* ask for string to insert */ - tstring = newmlreplyt( prompt) ; - if( tstring == NULL) + argp = newmlargt( prompt, 0) ; /* grab as big a token as screen allow */ + if( argp == NULL) return FALSE ; + status = argp->status ; + tstring = argp->buf ; + free( argp) ; + if( tstring == NULL) + return status ; + if( f == FALSE) n = 1 ; else if( n < 0) n = -n ; /* insert it */ - status = TRUE ; - while( n-- && status) + while( n-- && status == TRUE) status = fun( tstring) ; free( tstring) ;