1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 07:16:23 -05:00

Allow either dynamic or pre-defined input size from message line.

Insure to capture ABORT status when doing input from message line.
This commit is contained in:
Renaud 2015-09-28 17:46:00 +08:00
parent 3ffa8967ef
commit ce4d105794
3 changed files with 46 additions and 24 deletions

41
input.c
View File

@ -102,24 +102,35 @@ static int nextarg( const char *prompt, char *buf, int size, int terminator) {
return gettokval( buf, size) ; return gettokval( buf, size) ;
} }
static char *newnextarg( const char *prompt, int terminator) { static newarg_t *newnextarg( const char *prompt, int size, int terminator) {
newarg_t *argp ;
argp = malloc( sizeof( newarg_t)) ;
if( argp != NULL) {
/* if we are interactive, go get it! */ /* if we are interactive, go get it! */
if( clexec == FALSE) { if( clexec == FALSE) {
char *buf ; if( size <= 1) {
int size ; size = term.t_ncol - strlen( prompt) + 1 ;
if( size < 24)
size = term.t_ncol + 1 ; size = 24 ;
buf = malloc( size) ;
if( buf != NULL) {
if( TRUE != getstring( prompt, buf, size, terminator)) {
free( buf) ;
buf = NULL ;
}
} }
return buf ; 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 } else
return getnewtokval() ; 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) ; return nextarg( prompt, buf, nbuf, metac) ;
} }
char *newmlreplyt( const char *prompt) { newarg_t *newmlargt( const char *prompt, int size) {
return newnextarg( prompt, metac) ; return newnextarg( prompt, size, metac) ;
} }
/* /*

View File

@ -4,6 +4,11 @@
#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 ;
@ -25,7 +30,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 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) ; int ectoc( int c) ;
fn_t getname( void) ; fn_t getname( void) ;
int tgetc( void) ; int tgetc( void) ;

View File

@ -1185,22 +1185,28 @@ int fmatch(int ch)
} }
static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
newarg_t *argp ;
int status ; /* status return code */ int status ; /* status return code */
char *tstring ; /* string to add */ char *tstring ; /* string to add */
/* ask for string to insert */ /* ask for string to insert */
tstring = newmlreplyt( prompt) ; argp = newmlargt( prompt, 0) ; /* grab as big a token as screen allow */
if( tstring == NULL) if( argp == NULL)
return FALSE ; return FALSE ;
status = argp->status ;
tstring = argp->buf ;
free( argp) ;
if( tstring == NULL)
return status ;
if( f == FALSE) if( f == FALSE)
n = 1 ; n = 1 ;
else if( n < 0) else if( n < 0)
n = -n ; n = -n ;
/* insert it */ /* insert it */
status = TRUE ; while( n-- && status == TRUE)
while( n-- && status)
status = fun( tstring) ; status = fun( tstring) ;
free( tstring) ; free( tstring) ;