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:
parent
3ffa8967ef
commit
ce4d105794
49
input.c
49
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) ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
7
input.h
7
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) ;
|
||||
|
14
random.c
14
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) ;
|
||||
|
Loading…
Reference in New Issue
Block a user