1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-20 01:15:22 +00:00

Exec commands based on newmlarg (replacement of mlreply).

This commit is contained in:
Renaud 2015-10-05 13:27:45 +08:00
parent b59a47bb3a
commit bcba236265

84
exec.c
View File

@ -120,19 +120,20 @@ static int docmd( char *cline) ;
* *
* int f, n; default Flag and Numeric argument * int f, n; default Flag and Numeric argument
*/ */
int execcmd(int f, int n) int execcmd( int f, int n) {
{
int status ; /* status return */ int status ; /* status return */
char cmdstr[NSTRING]; /* string holding command to execute */ char *cmdstr ; /* string holding command to execute */
/* get the line wanted */ /* get the line wanted */
if ((status = mlreply(": ", cmdstr, NSTRING)) != TRUE) status = newmlarg( &cmdstr, ": ", 0) ;
if( status != TRUE)
return status ; return status ;
execlevel = 0 ; execlevel = 0 ;
while( status == TRUE && n-- > 0) while( status == TRUE && n-- > 0)
status = docmd( cmdstr) ; status = docmd( cmdstr) ;
free( cmdstr) ;
return status ; return status ;
} }
@ -439,27 +440,31 @@ int storemac(int f, int n)
* int f; default flag * int f; default flag
* int n; macro number to use * int n; macro number to use
*/ */
int storeproc(int f, int n) int storeproc( int f, int n) {
{
struct buffer *bp ; /* pointer to macro buffer */ struct buffer *bp ; /* pointer to macro buffer */
int status ; /* return status */ int status ; /* return status */
bname_t bname ; /* name of buffer to use */ bname_t bname ; /* name of buffer to use */
char *name ;
/* a numeric argument means its a numbered macro */ /* a numeric argument means its a numbered macro */
if( f == TRUE) if( f == TRUE)
return storemac( f, n) ; return storemac( f, n) ;
/* get the name of the procedure */ /* get the name of the procedure */
if ((status = status = newmlarg( &name, "Procedure name: ", sizeof bname - 2) ;
mlreply("Procedure name: ", &bname[1], sizeof bname - 2)) != TRUE) if( status != TRUE)
return status ; return status ;
/* construct the macro buffer name */ /* construct the macro buffer name */
bname[ 0] = '*'; bname[ 0] = '*';
strncpy( &bname[ 1], name, sizeof bname - 3) ;
bname[ sizeof bname - 2] = '\0' ;
strcat( bname, "*") ; strcat( bname, "*") ;
free( name) ;
/* set up the new macro buffer */ /* set up the new macro buffer */
if ((bp = bfind(bname, TRUE, BFINVS)) == NULL) { bp = bfind( bname, TRUE, BFINVS) ;
if( bp == NULL) {
mlwrite( "Can not create macro") ; mlwrite( "Can not create macro") ;
return FALSE ; return FALSE ;
} }
@ -479,32 +484,36 @@ int storeproc(int f, int n)
* *
* int f, n; default flag and numeric arg * int f, n; default flag and numeric arg
*/ */
int execproc(int f, int n) int execproc( int f, int n) {
{
struct buffer *bp ; /* ptr to buffer to execute */ struct buffer *bp ; /* ptr to buffer to execute */
int status ; /* status return */ int status ; /* status return */
char bufn[NBUFN + 2]; /* name of buffer to execute */ bname_t bufn ; /* name of buffer to execute */
char *name ;
/* find out what buffer the user wants to execute */ /* find out what buffer the user wants to execute */
if ((status = status = newmlarg( &name, "Execute procedure: ", sizeof bufn - 2) ;
mlreply("Execute procedure: ", &bufn[1], NBUFN)) != TRUE) if( status != TRUE)
return status ; return status ;
/* construct the buffer name */ /* construct the buffer name */
bufn[ 0] = '*' ; bufn[ 0] = '*' ;
strncpy( &bufn[ 1], name, sizeof bufn - 3) ;
bufn[ sizeof bufn - 2] = '\0' ;
strcat( bufn, "*") ; strcat( bufn, "*") ;
free( name) ;
/* find the pointer to that buffer */ /* find the pointer to that buffer */
if ((bp = bfind(bufn, FALSE, 0)) == NULL) { bp = bfind( bufn, FALSE, 0) ;
if( bp == NULL) {
mlwrite( "No such procedure") ; mlwrite( "No such procedure") ;
return FALSE ; return FALSE ;
} }
/* and now execute it as asked */ /* and now execute it as asked */
while (n-- > 0) while( status == TRUE && n-- > 0)
if ((status = dobuf(bp)) != TRUE) status = dobuf( bp) ;
return status ; return status ;
return TRUE;
} }
#endif #endif
@ -514,27 +523,29 @@ int execproc(int f, int n)
* *
* int f, n; default flag and numeric arg * int f, n; default flag and numeric arg
*/ */
int execbuf(int f, int n) int execbuf( int f, int n) {
{
struct buffer *bp ; /* ptr to buffer to execute */ struct buffer *bp ; /* ptr to buffer to execute */
int status ; /* status return */ int status ; /* status return */
bname_t bufn ; /* name of buffer to execute */ char *bufn ; /* name of buffer to execute */
/* find out what buffer the user wants to execute */ /* find out what buffer the user wants to execute */
if ((status = mlreply("Execute buffer: ", bufn, sizeof bufn)) != TRUE) status = newmlarg( &bufn, "Execute buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ; return status ;
/* find the pointer to that buffer */ /* find the pointer to that buffer */
if ((bp = bfind(bufn, FALSE, 0)) == NULL) { bp = bfind( bufn, FALSE, 0) ;
free( bufn) ;
if( bp == NULL) {
mlwrite( "No such buffer") ; mlwrite( "No such buffer") ;
return FALSE ; return FALSE ;
} }
/* and now execute it as asked */ /* and now execute it as asked */
while (n-- > 0) while( status == TRUE && n-- > 0)
if ((status = dobuf(bp)) != TRUE) status = dobuf( bp) ;
return status ; return status ;
return TRUE;
} }
/* /*
@ -949,31 +960,28 @@ static void freewhile(struct while_block *wp)
* *
* int f, n; default flag and numeric arg to pass on to file * int f, n; default flag and numeric arg to pass on to file
*/ */
int execfile(int f, int n) int execfile( int f, int n) {
{
int status ; /* return status of name query */ int status ; /* return status of name query */
char fname[NSTRING]; /* name of file to execute */ char *fname ; /* name of file to execute */
char *fspec ; /* full file spec */ char *fspec ; /* full file spec */
if ((status = status = newmlarg( &fname, "File to execute: ", 0) ;
mlreply("File to execute: ", fname, NSTRING - 1)) != TRUE) if( status != TRUE)
return status ; return status ;
#if 1
/* look up the path for the file */ /* look up the path for the file */
fspec = flook(fname, FALSE); /* used to by TRUE, P.K. */ fspec = flook( fname, FALSE) ; /* used to be TRUE, P.K. */
free( fname) ;
/* if it isn't around */ /* if it isn't around */
if( fspec == NULL) if( fspec == NULL)
return FALSE ; return FALSE ;
#endif
/* otherwise, execute it */ /* otherwise, execute it */
while (n-- > 0) while( status == TRUE && n-- > 0)
if ((status = dofile(fspec)) != TRUE) status = dofile( fspec) ;
return status;
return TRUE; return status ;
} }
/* /*