1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-11-16 09:36:29 -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

41
input.c
View File

@ -102,11 +102,11 @@ 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) {
@ -115,22 +115,23 @@ static newarg_t *newnextarg( const char *prompt, int size, int terminator) {
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 ;
buf = malloc( size) ;
if( buf == NULL)
status = FALSE ;
else {
status = getstring( prompt, buf, size, terminator) ;
if( TRUE != status) {
free( buf) ;
buf = NULL ;
}
}
} else
argp->status = FALSE ;
} else {
argp->buf = getnewtokval() ;
argp->status = (argp->buf == NULL) ? FALSE : TRUE ;
}
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.