1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-09-30 01:05:54 -04: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

49
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) {
/* if we are interactive, go get it! */ newarg_t *argp ;
if( clexec == FALSE) {
char *buf ;
int size ;
size = term.t_ncol + 1 ; argp = malloc( sizeof( newarg_t)) ;
buf = malloc( size) ; if( argp != NULL) {
if( buf != NULL) { /* if we are interactive, go get it! */
if( TRUE != getstring( prompt, buf, size, terminator)) { if( clexec == FALSE) {
free( buf) ; if( size <= 1) {
buf = NULL ; size = term.t_ncol - strlen( prompt) + 1 ;
} if( size < 24)
} size = 24 ;
}
return buf ;
} else argp->buf = malloc( size) ;
return getnewtokval() ; 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) ; 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) ;