1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-11-12 23:56:51 -05:00

Review newmlargt interface and obsolete mlreplyt.

This commit is contained in:
Renaud 2015-09-29 10:25:36 +08:00
parent ce4d105794
commit 198980b81f
3 changed files with 35 additions and 41 deletions

61
input.c
View File

@ -102,35 +102,36 @@ static int nextarg( const char *prompt, char *buf, int size, int terminator) {
return gettokval( buf, size) ;
}
static newarg_t *newnextarg( const char *prompt, int size, int terminator) {
newarg_t *argp ;
static int newnextarg( char **outbufref, const char *prompt, int size,
int terminator) {
int status ;
char *buf ;
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 ;
/* 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 ;
}
buf = malloc( size) ;
if( buf == NULL)
status = FALSE ;
else {
status = getstring( prompt, buf, size, terminator) ;
if( TRUE != status) {
free( buf) ;
buf = NULL ;
}
}
} else {
buf = getnewtokval() ;
status = (buf == NULL) ? FALSE : TRUE ;
}
return argp ;
*outbufref = buf ;
return status ;
}
/*
@ -145,12 +146,8 @@ int mlreply( const char *prompt, char *buf, int nbuf) {
return nextarg( prompt, buf, nbuf, nlc) ;
}
int mlreplyt( const char *prompt, char *buf, int nbuf) {
return nextarg( prompt, buf, nbuf, metac) ;
}
newarg_t *newmlargt( const char *prompt, int size) {
return newnextarg( prompt, size, metac) ;
int newmlargt( char **outbufref, const char *prompt, int size) {
return newnextarg( outbufref, prompt, size, metac) ;
}
/*

View File

@ -4,11 +4,6 @@
#include "bind.h"
typedef struct {
int status ;
char *buf ;
} newarg_t ;
typedef enum {
STOP, PLAY, RECORD
} kbdstate ;
@ -29,8 +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 mlreplyt( const char *prompt, char *buf, int nbuf) ;
newarg_t *newmlargt( const char *prompt, int size) ;
int newmlargt( char **outbufref, const char *prompt, int size) ;
int ectoc( int c) ;
fn_t getname( void) ;
int tgetc( void) ;

View File

@ -705,6 +705,7 @@ static int readpattern(char *prompt, char *apat, int srch)
{
int status;
char tpat[NPAT + 20];
char *dynpat ; /* dynamically allocated pattern buffer */
setprompt( tpat, NPAT / 2, prompt, apat) ;
@ -713,9 +714,11 @@ static int readpattern(char *prompt, char *apat, int srch)
* Then, if it's the search string, make a reversed pattern.
* *Then*, make the meta-pattern, if we are defined that way.
*/
status = mlreplyt( tpat, tpat, NPAT) ;
status = newmlargt( &dynpat, tpat, NPAT) ;
if( status == TRUE) {
strcpy(apat, tpat);
strncpy( apat, dynpat, NPAT - 1) ;
apat[ NPAT - 1] = 0 ;
free( dynpat) ;
if (srch) { /* If we are doing the search string. */
/* Reverse string copy, and remember
* the length for substitution purposes.