From 7f5f0dd7b39cff04aa28db867f2c33d17a03d00f Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 29 Sep 2015 10:43:19 +0800 Subject: [PATCH] Introduce newmlarg as alternative to mlreply. Rewrite gotoline accordingly. --- basic.c | 21 +++++++++++---------- input.c | 4 ++++ input.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/basic.c b/basic.c index 430f887..6a76ebd 100644 --- a/basic.c +++ b/basic.c @@ -90,25 +90,26 @@ int gotoeol(int f, int n) * * @n: The specified line position at the current buffer. */ -int gotoline(int f, int n) -{ - int status ; - char arg[ NSTRING] ; /* Buffer to hold argument. */ - +int gotoline( int f, int n) { /* Get an argument if one doesnt exist. */ if( f == FALSE) { - status = mlreply( "Line to GOTO: ", arg, sizeof arg) ; + int status ; + char *arg ; /* Buffer to hold argument. */ + + status = newmlarg( &arg, "Line to GOTO: ", 0) ; if( status != TRUE) { mloutstr( "(Aborted)") ; return status ; } n = atoi( arg) ; + free( arg) ; } - /* Handle the case where the user may be passed something like this: - * em filename + - * In this case we just go to the end of the buffer. - */ + + /* Handle the case where the user may be passed something like this: + * em filename + + * In this case we just go to the end of the buffer. + */ if (n == 0) return gotoeob(f, n); diff --git a/input.c b/input.c index 3de8278..9b8b13f 100644 --- a/input.c +++ b/input.c @@ -146,6 +146,10 @@ int mlreply( const char *prompt, char *buf, int nbuf) { return nextarg( prompt, buf, nbuf, nlc) ; } +int newmlarg( char **outbufref, const char *prompt, int size) { + return newnextarg( outbufref, prompt, size, nlc) ; +} + int newmlargt( char **outbufref, const char *prompt, int size) { return newnextarg( outbufref, prompt, size, metac) ; } diff --git a/input.h b/input.h index 67714e6..b65f81c 100644 --- a/input.h +++ b/input.h @@ -24,6 +24,7 @@ extern const int nlc ; /* end of input char */ int mlyesno( const char *prompt) ; int mlreply( const char *prompt, char *buf, int nbuf) ; +int newmlarg( char **outbufref, const char *prompt, int size) ; int newmlargt( char **outbufref, const char *prompt, int size) ; int ectoc( int c) ; fn_t getname( void) ;