2013-05-20 01:16:08 -04:00
|
|
|
/* exec.c -- implements exec.h */
|
|
|
|
#include "exec.h"
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* exec.c
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* This file is for functions dealing with execution of
|
|
|
|
* commands, command lines, buffers, files and startup files.
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* written 1986 by Daniel Lawrence
|
|
|
|
* modified by Petri Kutvonen
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2010-11-14 21:10:03 -05:00
|
|
|
#include <stdio.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
|
2013-05-28 01:25:14 -04:00
|
|
|
#include "buffer.h"
|
2013-05-28 01:04:39 -04:00
|
|
|
#include "bind.h"
|
2013-05-28 02:57:03 -04:00
|
|
|
#include "display.h"
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "estruct.h"
|
2013-05-28 01:35:09 -04:00
|
|
|
#include "eval.h"
|
2013-05-25 00:28:17 -04:00
|
|
|
#include "file.h"
|
2013-06-10 06:14:09 -04:00
|
|
|
#include "flook.h"
|
2013-05-28 02:46:44 -04:00
|
|
|
#include "input.h"
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "line.h"
|
2013-10-10 00:33:13 -04:00
|
|
|
#include "random.h"
|
2013-09-20 06:10:30 -04:00
|
|
|
#include "window.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 04:56:47 -04:00
|
|
|
|
2015-01-13 03:42:14 -05:00
|
|
|
static char *execstr = NULL ; /* pointer to string to execute */
|
2015-01-09 04:53:29 -05:00
|
|
|
boolean clexec = FALSE ; /* command line execution flag */
|
2013-10-09 21:55:03 -04:00
|
|
|
|
2013-10-08 04:56:47 -04:00
|
|
|
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* Directive definitions */
|
2013-09-23 08:29:49 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
#define DIF 0
|
|
|
|
#define DELSE 1
|
|
|
|
#define DENDIF 2
|
|
|
|
#define DGOTO 3
|
|
|
|
#define DRETURN 4
|
|
|
|
#define DENDM 5
|
|
|
|
#define DWHILE 6
|
|
|
|
#define DENDWHILE 7
|
|
|
|
#define DBREAK 8
|
|
|
|
#define DFORCE 9
|
2013-09-23 08:29:49 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
#define NUMDIRS 10
|
2013-09-23 08:29:49 -04:00
|
|
|
|
|
|
|
/* The !WHILE directive in the execution language needs to
|
|
|
|
* stack references to pending whiles. These are stored linked
|
|
|
|
* to each currently open procedure via a linked list of
|
|
|
|
* the following structure.
|
|
|
|
*/
|
|
|
|
struct while_block {
|
2015-01-09 04:53:29 -05:00
|
|
|
struct line *w_begin; /* ptr to !while statement */
|
|
|
|
struct line *w_end; /* ptr to the !endwhile statement */
|
|
|
|
int w_type; /* block type */
|
|
|
|
struct while_block *w_next; /* next while */
|
2013-09-23 08:29:49 -04:00
|
|
|
};
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
#define BTWHILE 1
|
|
|
|
#define BTBREAK 2
|
2013-09-23 08:29:49 -04:00
|
|
|
|
2013-06-06 00:08:23 -04:00
|
|
|
/* directive name table:
|
2015-01-09 04:53:29 -05:00
|
|
|
This holds the names of all the directives.... */
|
2013-06-06 00:08:23 -04:00
|
|
|
|
|
|
|
static const char *dname[] = {
|
2015-01-09 04:53:29 -05:00
|
|
|
"if", "else", "endif",
|
|
|
|
"goto", "return", "endm",
|
|
|
|
"while", "endwhile", "break",
|
|
|
|
"force"
|
2013-06-06 00:08:23 -04:00
|
|
|
};
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
static char golabel[ NSTRING] = "" ; /* current line to go to */
|
|
|
|
static int execlevel = 0 ; /* execution IF level */
|
|
|
|
static struct buffer *bstore = NULL ; /* buffer to store macro text to */
|
|
|
|
static int mstore = FALSE ; /* storing text to macro flag */
|
2013-09-26 08:06:36 -04:00
|
|
|
|
2013-09-23 08:29:49 -04:00
|
|
|
static int dobuf( struct buffer *bp) ;
|
|
|
|
static void freewhile( struct while_block *wp) ;
|
2015-08-31 23:29:08 -04:00
|
|
|
static int macarg( char *tok, int toksz) ;
|
2013-09-23 08:29:49 -04:00
|
|
|
|
2015-01-02 01:20:07 -05:00
|
|
|
void ue_system( const char *cmd) {
|
2015-01-09 04:53:29 -05:00
|
|
|
int ret ;
|
2015-01-02 01:20:07 -05:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
ret = system( cmd) ;
|
|
|
|
if( ret == -1) {
|
|
|
|
/* some actual handling needed here */
|
|
|
|
}
|
2015-01-02 01:20:07 -05:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
2010-11-14 21:10:03 -05:00
|
|
|
* Execute a named command even if it is not bound.
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
|
|
|
int namedcmd(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
fn_t kfunc; /* ptr to the requexted function to bind to */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* prompt the user to type a named command */
|
|
|
|
mlwrite(": ");
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* and now get the function name to execute */
|
|
|
|
kfunc = getname();
|
|
|
|
if (kfunc == NULL) {
|
|
|
|
mlwrite("(No such function)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* and then execute the command */
|
|
|
|
return kfunc(f, n);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2014-06-06 03:09:08 -04:00
|
|
|
static int docmd( char *cline) ;
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* execcmd:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Execute a command line command to be typed in
|
|
|
|
* by the user
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f, n; default Flag and Numeric argument
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-10-05 01:27:45 -04:00
|
|
|
int execcmd( int f, int n) {
|
|
|
|
int status ; /* status return */
|
|
|
|
char *cmdstr ; /* string holding command to execute */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* get the line wanted */
|
2015-10-05 01:27:45 -04:00
|
|
|
status = newmlarg( &cmdstr, ": ", 0) ;
|
|
|
|
if( status != TRUE)
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-10-05 01:27:45 -04:00
|
|
|
execlevel = 0 ;
|
2015-03-25 23:04:36 -04:00
|
|
|
while( status == TRUE && n-- > 0)
|
2017-05-05 20:51:02 -04:00
|
|
|
status = docmd( cmdstr) ;
|
2015-03-25 23:04:36 -04:00
|
|
|
|
2017-05-05 20:51:02 -04:00
|
|
|
free( cmdstr) ;
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* docmd:
|
2015-01-09 04:53:29 -05:00
|
|
|
* take a passed string as a command line and translate
|
|
|
|
* it to be executed as a command. This function will be
|
|
|
|
* used by execute-command-line and by all source and
|
|
|
|
* startup files. Lastflag/thisflag is also updated.
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* format of the command line is:
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* {# arg} <command-name> {<argument string(s)>}
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* char *cline; command line to execute
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2014-06-06 03:09:08 -04:00
|
|
|
static int docmd( char *cline) {
|
2015-01-09 04:53:29 -05:00
|
|
|
int f; /* default argument flag */
|
|
|
|
int n; /* numeric repeat value */
|
|
|
|
fn_t fnc; /* function to execute */
|
|
|
|
int status; /* return status of function */
|
|
|
|
boolean oldcle ; /* old contents of clexec flag */
|
|
|
|
char *oldestr; /* original exec string */
|
|
|
|
char tkn[NSTRING]; /* next token off of command line */
|
|
|
|
|
|
|
|
/* if we are scanning and not executing..go back here */
|
|
|
|
if (execlevel)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
oldestr = execstr; /* save last ptr to string to execute */
|
|
|
|
execstr = cline; /* and set this one as current */
|
|
|
|
|
|
|
|
/* first set up the default command values */
|
|
|
|
f = FALSE;
|
|
|
|
n = 1;
|
|
|
|
lastflag = thisflag;
|
|
|
|
thisflag = 0;
|
|
|
|
|
|
|
|
status = macarg( tkn, sizeof tkn) ;
|
|
|
|
if( status != TRUE) { /* and grab the first token */
|
|
|
|
execstr = oldestr;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process leadin argument */
|
|
|
|
if( !is_it_cmd( tkn)) {
|
|
|
|
f = TRUE;
|
2015-08-31 23:29:08 -04:00
|
|
|
/* macarg already includes a getval, skip for now
|
|
|
|
strncpy( tkn, getval( tkn), sizeof tkn - 1) ;
|
|
|
|
tkn[ sizeof tkn - 1] = '\0' ;
|
|
|
|
*/
|
2015-01-09 04:53:29 -05:00
|
|
|
n = atoi(tkn);
|
|
|
|
|
|
|
|
/* and now get the command to execute */
|
|
|
|
status = macarg( tkn, sizeof tkn) ;
|
|
|
|
if( status != TRUE) {
|
|
|
|
execstr = oldestr;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and match the token to see if it exists */
|
|
|
|
if ((fnc = fncmatch(tkn)) == NULL) {
|
|
|
|
mlwrite("(No such Function)");
|
|
|
|
execstr = oldestr;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the arguments and go execute the command */
|
|
|
|
oldcle = clexec; /* save old clexec flag */
|
|
|
|
clexec = TRUE; /* in cline execution */
|
|
|
|
status = (*fnc) (f, n); /* call the function */
|
|
|
|
cmdstatus = status; /* save the status */
|
|
|
|
clexec = oldcle; /* restore clexec flag */
|
|
|
|
execstr = oldestr;
|
|
|
|
return status;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
2015-09-27 07:19:55 -04:00
|
|
|
* new token:
|
2015-01-09 04:53:29 -05:00
|
|
|
* chop a token off a string
|
|
|
|
* return a pointer past the token
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-09-27 07:19:55 -04:00
|
|
|
* char *src in, source string
|
|
|
|
* char **tokref out, destination of newly allocated token string
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-09-27 07:19:55 -04:00
|
|
|
static char *newtoken( char *src, char **tokref) {
|
|
|
|
boolean quotef ; /* is the current string quoted? */
|
|
|
|
char *tok ; /* allocated string */
|
|
|
|
int size ; /* allocated size */
|
|
|
|
int idx = 0 ; /* insertion point into token string */
|
|
|
|
|
|
|
|
tok = malloc( NSTRING) ;
|
|
|
|
size = (tok == NULL) ? 0 : NSTRING ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* first scan past any whitespace in the source string */
|
|
|
|
while (*src == ' ' || *src == '\t')
|
|
|
|
++src;
|
|
|
|
|
|
|
|
/* scan through the source string */
|
|
|
|
quotef = FALSE;
|
|
|
|
while (*src) {
|
2015-09-27 07:19:55 -04:00
|
|
|
char c ; /* temporary character */
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* process special characters */
|
|
|
|
if (*src == '~') {
|
|
|
|
++src;
|
|
|
|
if (*src == 0)
|
|
|
|
break;
|
|
|
|
switch (*src++) {
|
|
|
|
case 'r':
|
|
|
|
c = 13;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
c = 10;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
c = 9;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
c = 8;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
c = 12;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c = *(src - 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* check for the end of the token */
|
|
|
|
if (quotef) {
|
|
|
|
if (*src == '"')
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (*src == ' ' || *src == '\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set quote mode if quote found */
|
|
|
|
if (*src == '"')
|
|
|
|
quotef = TRUE;
|
|
|
|
|
|
|
|
/* record the character */
|
|
|
|
c = *src++;
|
|
|
|
}
|
2015-09-27 07:19:55 -04:00
|
|
|
|
|
|
|
if( idx < size - 1)
|
|
|
|
tok[ idx++] = c ;
|
|
|
|
else if( size > 1) {
|
|
|
|
char *tmptok ;
|
|
|
|
|
|
|
|
tmptok = malloc( size + 32) ;
|
|
|
|
if( tmptok == NULL)
|
|
|
|
size = 0 ;
|
|
|
|
else {
|
|
|
|
memcpy( tmptok, tok, idx) ;
|
|
|
|
free( tok) ;
|
|
|
|
tok = tmptok ;
|
|
|
|
size += 32 ;
|
|
|
|
tok[ idx++] = c ;
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 04:53:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* terminate the token and exit */
|
|
|
|
if (*src)
|
|
|
|
++src;
|
2015-09-27 07:19:55 -04:00
|
|
|
|
2017-05-05 20:51:02 -04:00
|
|
|
if( tok != NULL)
|
|
|
|
tok[ idx] = 0 ;
|
2015-09-27 07:19:55 -04:00
|
|
|
|
2017-05-05 20:51:02 -04:00
|
|
|
*tokref = tok ;
|
2015-01-09 04:53:29 -05:00
|
|
|
return src;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-09-27 07:19:55 -04:00
|
|
|
static char *token( char *srcstr, char *tok, int maxtoksize) {
|
|
|
|
char *newtok ;
|
|
|
|
|
|
|
|
srcstr = newtoken( srcstr, &newtok) ;
|
|
|
|
if( newtok == NULL)
|
|
|
|
tok[ 0] = 0 ;
|
|
|
|
else {
|
|
|
|
strncpy( tok, newtok, maxtoksize - 1) ;
|
|
|
|
tok[ maxtoksize - 1] = 0 ;
|
|
|
|
free( newtok) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return srcstr ;
|
|
|
|
}
|
|
|
|
|
2015-01-13 03:42:14 -05:00
|
|
|
void gettoken( char *tok, int maxtoksize) {
|
|
|
|
execstr = token( execstr, tok, maxtoksize) ;
|
|
|
|
}
|
|
|
|
|
2015-09-27 09:11:51 -04:00
|
|
|
static char *getnewtoken( void) {
|
|
|
|
char *tok ;
|
|
|
|
|
|
|
|
execstr = newtoken( execstr, &tok) ;
|
|
|
|
return tok ;
|
2015-09-27 07:19:55 -04:00
|
|
|
}
|
|
|
|
|
2015-08-25 04:34:15 -04:00
|
|
|
boolean gettokval( char *tok, int size) {
|
|
|
|
char *tmpbuf ;
|
|
|
|
|
|
|
|
/* grab token and advance past */
|
2015-09-27 09:11:51 -04:00
|
|
|
tmpbuf = getnewtoken() ;
|
2015-09-27 07:19:55 -04:00
|
|
|
if( tmpbuf == NULL)
|
|
|
|
return FALSE ;
|
2015-08-25 04:34:15 -04:00
|
|
|
|
|
|
|
/* evaluate it */
|
|
|
|
strncpy( tok, getval( tmpbuf), size - 1) ;
|
|
|
|
tok[ size - 1] = '\0' ;
|
|
|
|
free( tmpbuf) ;
|
|
|
|
return TRUE ;
|
|
|
|
}
|
|
|
|
|
2015-09-27 09:11:51 -04:00
|
|
|
char *getnewtokval( void) {
|
|
|
|
char *tmpbuf ;
|
|
|
|
char *tmpval ;
|
|
|
|
char *valbuf ;
|
|
|
|
|
|
|
|
/* grab token and advance past */
|
|
|
|
tmpbuf = getnewtoken() ;
|
|
|
|
if( tmpbuf == NULL)
|
|
|
|
return NULL ;
|
|
|
|
|
|
|
|
/* evaluate it */
|
|
|
|
tmpval = getval( tmpbuf) ;
|
|
|
|
valbuf = malloc( strlen( tmpval) + 1 ) ;
|
|
|
|
if( valbuf != NULL)
|
|
|
|
strcpy( valbuf, tmpval) ;
|
|
|
|
|
|
|
|
free( tmpbuf) ;
|
|
|
|
return valbuf ;
|
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* get a macro line argument
|
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* char *tok; buffer to place argument
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-08-31 23:29:08 -04:00
|
|
|
static int macarg( char *tok, int toksz) {
|
|
|
|
int status ;
|
|
|
|
boolean savcle ; /* buffer to store original clexec */
|
|
|
|
|
|
|
|
savcle = clexec ; /* save execution mode */
|
|
|
|
clexec = TRUE ; /* get the argument */
|
|
|
|
status = gettokval( tok, toksz) ;
|
|
|
|
clexec = savcle ; /* restore execution mode */
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* storemac:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Set up a macro buffer and flag to store all
|
|
|
|
* executed command lines there
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f; default flag
|
|
|
|
* int n; macro number to use
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
|
|
|
int storemac(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
struct buffer *bp; /* pointer to macro buffer */
|
|
|
|
bname_t bname ; /* name of buffer to use */
|
|
|
|
|
|
|
|
/* must have a numeric argument to this function */
|
|
|
|
if (f == FALSE) {
|
|
|
|
mlwrite("No macro specified");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* range check the macro number */
|
|
|
|
if (n < 1 || n > 40) {
|
|
|
|
mlwrite("Macro number out of range");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the macro buffer name */
|
|
|
|
strcpy(bname, "*Macro xx*");
|
|
|
|
bname[7] = '0' + (n / 10);
|
|
|
|
bname[8] = '0' + (n % 10);
|
|
|
|
|
|
|
|
/* set up the new macro buffer */
|
|
|
|
if ((bp = bfind(bname, TRUE, BFINVS)) == NULL) {
|
|
|
|
mlwrite("Can not create macro");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and make sure it is empty */
|
|
|
|
bclear(bp);
|
|
|
|
|
|
|
|
/* and set the macro store pointers to it */
|
|
|
|
mstore = TRUE;
|
|
|
|
bstore = bp;
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
#if PROC
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* storeproc:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Set up a procedure buffer and flag to store all
|
|
|
|
* executed command lines there
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f; default flag
|
|
|
|
* int n; macro number to use
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-10-05 01:27:45 -04:00
|
|
|
int storeproc( int f, int n) {
|
|
|
|
struct buffer *bp ; /* pointer to macro buffer */
|
|
|
|
int status ; /* return status */
|
|
|
|
bname_t bname ; /* name of buffer to use */
|
|
|
|
char *name ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* a numeric argument means its a numbered macro */
|
2015-10-05 01:27:45 -04:00
|
|
|
if( f == TRUE)
|
|
|
|
return storemac( f, n) ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* get the name of the procedure */
|
2015-10-05 01:27:45 -04:00
|
|
|
status = newmlarg( &name, "Procedure name: ", sizeof bname - 2) ;
|
|
|
|
if( status != TRUE)
|
|
|
|
return status ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* construct the macro buffer name */
|
2015-10-05 01:27:45 -04:00
|
|
|
bname[ 0] = '*';
|
|
|
|
strncpy( &bname[ 1], name, sizeof bname - 3) ;
|
|
|
|
bname[ sizeof bname - 2] = '\0' ;
|
|
|
|
strcat( bname, "*") ;
|
|
|
|
free( name) ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* set up the new macro buffer */
|
2015-10-05 01:27:45 -04:00
|
|
|
bp = bfind( bname, TRUE, BFINVS) ;
|
|
|
|
if( bp == NULL) {
|
|
|
|
mlwrite( "Can not create macro") ;
|
|
|
|
return FALSE ;
|
2015-01-09 04:53:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* and make sure it is empty */
|
2015-10-05 01:27:45 -04:00
|
|
|
bclear( bp) ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* and set the macro store pointers to it */
|
2015-10-05 01:27:45 -04:00
|
|
|
mstore = TRUE ;
|
|
|
|
bstore = bp ;
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* execproc:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Execute a procedure
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f, n; default flag and numeric arg
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-10-05 01:27:45 -04:00
|
|
|
int execproc( int f, int n) {
|
|
|
|
struct buffer *bp ; /* ptr to buffer to execute */
|
|
|
|
int status ; /* status return */
|
|
|
|
bname_t bufn ; /* name of buffer to execute */
|
|
|
|
char *name ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* find out what buffer the user wants to execute */
|
2015-10-05 01:27:45 -04:00
|
|
|
status = newmlarg( &name, "Execute procedure: ", sizeof bufn - 2) ;
|
|
|
|
if( status != TRUE)
|
|
|
|
return status ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* construct the buffer name */
|
2015-10-05 01:27:45 -04:00
|
|
|
bufn[ 0] = '*' ;
|
|
|
|
strncpy( &bufn[ 1], name, sizeof bufn - 3) ;
|
|
|
|
bufn[ sizeof bufn - 2] = '\0' ;
|
|
|
|
strcat( bufn, "*") ;
|
|
|
|
free( name) ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* find the pointer to that buffer */
|
2015-10-05 01:27:45 -04:00
|
|
|
bp = bfind( bufn, FALSE, 0) ;
|
|
|
|
if( bp == NULL) {
|
|
|
|
mlwrite( "No such procedure") ;
|
|
|
|
return FALSE ;
|
2015-01-09 04:53:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* and now execute it as asked */
|
2015-10-05 01:27:45 -04:00
|
|
|
while( status == TRUE && n-- > 0)
|
|
|
|
status = dobuf( bp) ;
|
|
|
|
|
2017-05-05 20:51:02 -04:00
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* execbuf:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Execute the contents of a buffer of commands
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f, n; default flag and numeric arg
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-10-05 01:27:45 -04:00
|
|
|
int execbuf( int f, int n) {
|
|
|
|
struct buffer *bp ; /* ptr to buffer to execute */
|
|
|
|
int status ; /* status return */
|
|
|
|
char *bufn ; /* name of buffer to execute */
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* find out what buffer the user wants to execute */
|
2015-10-05 01:27:45 -04:00
|
|
|
status = newmlarg( &bufn, "Execute buffer: ", sizeof( bname_t)) ;
|
|
|
|
if( status != TRUE)
|
|
|
|
return status ;
|
2015-01-09 04:53:29 -05:00
|
|
|
|
|
|
|
/* find the pointer to that buffer */
|
2015-10-05 01:27:45 -04:00
|
|
|
bp = bfind( bufn, FALSE, 0) ;
|
|
|
|
free( bufn) ;
|
|
|
|
if( bp == NULL) {
|
|
|
|
mlwrite( "No such buffer") ;
|
|
|
|
return FALSE ;
|
2015-01-09 04:53:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* and now execute it as asked */
|
2015-10-05 01:27:45 -04:00
|
|
|
while( status == TRUE && n-- > 0)
|
|
|
|
status = dobuf( bp) ;
|
|
|
|
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* dobuf:
|
2015-01-09 04:53:29 -05:00
|
|
|
* execute the contents of the buffer pointed to
|
|
|
|
* by the passed BP
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* Directives start with a "!" and include:
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* !endm End a macro
|
|
|
|
* !if (cond) conditional execution
|
|
|
|
* !else
|
|
|
|
* !endif
|
|
|
|
* !return Return (terminating current macro)
|
|
|
|
* !goto <label> Jump to a label in the current macro
|
|
|
|
* !force Force macro to continue...even if command fails
|
|
|
|
* !while (cond) Execute a loop if the condition is true
|
|
|
|
* !endwhile
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* Line Labels begin with a "*" as the first nonblank char, like:
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* *LBL01
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* struct buffer *bp; buffer to execute
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2013-09-23 08:29:49 -04:00
|
|
|
static int dobuf(struct buffer *bp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
int status; /* status return */
|
|
|
|
struct line *lp; /* pointer to line to execute */
|
|
|
|
struct line *hlp; /* pointer to line header */
|
|
|
|
struct line *glp; /* line to goto */
|
|
|
|
struct line *mp; /* Macro line storage temp */
|
|
|
|
int dirnum; /* directive index */
|
|
|
|
int linlen; /* length of line to execute */
|
|
|
|
int i; /* index */
|
|
|
|
int force; /* force TRUE result? */
|
|
|
|
struct window *wp; /* ptr to windows to scan */
|
|
|
|
struct while_block *whlist; /* ptr to !WHILE list */
|
|
|
|
struct while_block *scanner; /* ptr during scan */
|
|
|
|
struct while_block *whtemp; /* temporary ptr to a struct while_block */
|
|
|
|
char *einit; /* initial value of eline */
|
|
|
|
char *eline; /* text of line to execute */
|
|
|
|
char tkn[NSTRING]; /* buffer to evaluate an expresion in */
|
|
|
|
|
|
|
|
/* clear IF level flags/while ptr */
|
|
|
|
execlevel = 0;
|
|
|
|
whlist = NULL;
|
|
|
|
scanner = NULL;
|
|
|
|
|
|
|
|
/* scan the buffer to execute, building WHILE header blocks */
|
|
|
|
hlp = bp->b_linep;
|
|
|
|
lp = hlp->l_fp;
|
|
|
|
while (lp != hlp) {
|
|
|
|
/* scan the current line */
|
|
|
|
eline = lp->l_text;
|
|
|
|
i = lp->l_used;
|
|
|
|
|
|
|
|
/* trim leading whitespace */
|
|
|
|
while (i-- > 0 && (*eline == ' ' || *eline == '\t'))
|
|
|
|
++eline;
|
|
|
|
|
|
|
|
/* if theres nothing here, don't bother */
|
|
|
|
if (i <= 0)
|
|
|
|
goto nxtscan;
|
|
|
|
|
|
|
|
/* if is a while directive, make a block... */
|
|
|
|
if (eline[0] == '!' && eline[1] == 'w' && eline[2] == 'h') {
|
|
|
|
whtemp = (struct while_block *)malloc(sizeof(struct while_block));
|
|
|
|
if (whtemp == NULL) {
|
|
|
|
noram:mlwrite
|
|
|
|
("%%Out of memory during while scan");
|
|
|
|
failexit:freewhile
|
|
|
|
(scanner);
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
whtemp->w_begin = lp;
|
|
|
|
whtemp->w_type = BTWHILE;
|
|
|
|
whtemp->w_next = scanner;
|
|
|
|
scanner = whtemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if is a BREAK directive, make a block... */
|
|
|
|
if (eline[0] == '!' && eline[1] == 'b' && eline[2] == 'r') {
|
|
|
|
if (scanner == NULL) {
|
|
|
|
mlwrite
|
|
|
|
("%%!BREAK outside of any !WHILE loop");
|
|
|
|
goto failexit;
|
|
|
|
}
|
|
|
|
whtemp = (struct while_block *)malloc(sizeof(struct while_block));
|
|
|
|
if (whtemp == NULL)
|
|
|
|
goto noram;
|
|
|
|
whtemp->w_begin = lp;
|
|
|
|
whtemp->w_type = BTBREAK;
|
|
|
|
whtemp->w_next = scanner;
|
|
|
|
scanner = whtemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if it is an endwhile directive, record the spot... */
|
|
|
|
if (eline[0] == '!' && strncmp(&eline[1], "endw", 4) == 0) {
|
|
|
|
if (scanner == NULL) {
|
|
|
|
mlwrite
|
|
|
|
("%%!ENDWHILE with no preceding !WHILE in '%s'",
|
|
|
|
bp->b_bname);
|
|
|
|
goto failexit;
|
|
|
|
}
|
|
|
|
/* move top records from the scanner list to the
|
|
|
|
whlist until we have moved all BREAK records
|
|
|
|
and one WHILE record */
|
|
|
|
do {
|
|
|
|
scanner->w_end = lp;
|
|
|
|
whtemp = whlist;
|
|
|
|
whlist = scanner;
|
|
|
|
scanner = scanner->w_next;
|
|
|
|
whlist->w_next = whtemp;
|
|
|
|
} while (whlist->w_type == BTBREAK);
|
|
|
|
}
|
|
|
|
|
|
|
|
nxtscan: /* on to the next line */
|
|
|
|
lp = lp->l_fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* while and endwhile should match! */
|
|
|
|
if (scanner != NULL) {
|
|
|
|
mlwrite("%%!WHILE with no matching !ENDWHILE in '%s'",
|
|
|
|
bp->b_bname);
|
|
|
|
goto failexit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let the first command inherit the flags from the last one.. */
|
|
|
|
thisflag = lastflag;
|
|
|
|
|
|
|
|
/* starting at the beginning of the buffer */
|
|
|
|
hlp = bp->b_linep;
|
|
|
|
lp = hlp->l_fp;
|
|
|
|
while (lp != hlp) {
|
|
|
|
/* allocate eline and copy macro line to it */
|
|
|
|
linlen = lp->l_used;
|
|
|
|
if ((einit = eline = malloc(linlen + 1)) == NULL) {
|
|
|
|
mlwrite("%%Out of Memory during macro execution");
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
strncpy(eline, lp->l_text, linlen);
|
|
|
|
eline[linlen] = 0; /* make sure it ends */
|
|
|
|
|
|
|
|
/* trim leading whitespace */
|
|
|
|
while (*eline == ' ' || *eline == '\t')
|
|
|
|
++eline;
|
|
|
|
|
|
|
|
/* dump comments and blank lines */
|
2015-08-19 03:43:50 -04:00
|
|
|
if (*eline == ';' || *eline == '#' || *eline == 0)
|
2015-01-09 04:53:29 -05:00
|
|
|
goto onward;
|
|
|
|
|
|
|
|
#if DEBUGM
|
|
|
|
/* if $debug == TRUE, every line to execute
|
|
|
|
gets echoed and a key needs to be pressed to continue
|
|
|
|
^G will abort the command */
|
|
|
|
|
2015-01-15 01:36:19 -05:00
|
|
|
if( macbug) {
|
|
|
|
int c ;
|
|
|
|
|
|
|
|
/* debug macro name, if levels and lastly the line */
|
2015-06-12 05:05:43 -04:00
|
|
|
c = mdbugout( "<<<%s:%d:%s>>>", bp->b_bname, execlevel, eline) ;
|
2015-01-15 01:36:19 -05:00
|
|
|
if( c == abortc) {
|
|
|
|
freewhile( whlist) ;
|
|
|
|
return FALSE ;
|
|
|
|
} else if( c == metac) {
|
|
|
|
macbug = FALSE ;
|
|
|
|
}
|
2015-01-09 04:53:29 -05:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2015-01-09 04:53:29 -05:00
|
|
|
/* Parse directives here.... */
|
|
|
|
dirnum = -1;
|
|
|
|
if (*eline == '!') {
|
|
|
|
/* Find out which directive this is */
|
|
|
|
++eline;
|
|
|
|
for (dirnum = 0; dirnum < NUMDIRS; dirnum++)
|
|
|
|
if (strncmp(eline, dname[dirnum],
|
|
|
|
strlen(dname[dirnum])) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* and bitch if it's illegal */
|
|
|
|
if (dirnum == NUMDIRS) {
|
|
|
|
mlwrite("%%Unknown Directive");
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* service only the !ENDM macro here */
|
|
|
|
if (dirnum == DENDM) {
|
|
|
|
mstore = FALSE;
|
|
|
|
bstore = NULL;
|
|
|
|
goto onward;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore the original eline.... */
|
|
|
|
--eline;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if macro store is on, just salt this away */
|
|
|
|
if (mstore) {
|
|
|
|
/* allocate the space for the line */
|
|
|
|
linlen = strlen(eline);
|
|
|
|
if ((mp = lalloc(linlen)) == NULL) {
|
|
|
|
mlwrite
|
|
|
|
("Out of memory while storing macro");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the text into the new line */
|
|
|
|
for (i = 0; i < linlen; ++i)
|
|
|
|
lputc(mp, i, eline[i]);
|
|
|
|
|
|
|
|
/* attach the line to the end of the buffer */
|
|
|
|
bstore->b_linep->l_bp->l_fp = mp;
|
|
|
|
mp->l_bp = bstore->b_linep->l_bp;
|
|
|
|
bstore->b_linep->l_bp = mp;
|
|
|
|
mp->l_fp = bstore->b_linep;
|
|
|
|
goto onward;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
force = FALSE;
|
|
|
|
|
|
|
|
/* dump comments */
|
|
|
|
if (*eline == '*')
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
/* now, execute directives */
|
|
|
|
if (dirnum != -1) {
|
|
|
|
/* skip past the directive */
|
|
|
|
while (*eline && *eline != ' ' && *eline != '\t')
|
|
|
|
++eline;
|
|
|
|
execstr = eline;
|
|
|
|
|
|
|
|
switch (dirnum) {
|
|
|
|
case DIF: /* IF directive */
|
|
|
|
/* grab the value of the logical exp */
|
|
|
|
if (execlevel == 0) {
|
|
|
|
if( macarg( tkn, sizeof tkn) != TRUE)
|
|
|
|
goto eexec;
|
|
|
|
if (stol(tkn) == FALSE)
|
|
|
|
++execlevel;
|
|
|
|
} else
|
|
|
|
++execlevel;
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DWHILE: /* WHILE directive */
|
|
|
|
/* grab the value of the logical exp */
|
|
|
|
if (execlevel == 0) {
|
|
|
|
if( macarg( tkn, sizeof tkn) != TRUE)
|
|
|
|
goto eexec;
|
|
|
|
if (stol(tkn) == TRUE)
|
|
|
|
goto onward;
|
|
|
|
}
|
|
|
|
/* drop down and act just like !BREAK */
|
|
|
|
|
|
|
|
case DBREAK: /* BREAK directive */
|
|
|
|
if (dirnum == DBREAK && execlevel)
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
/* jump down to the endwhile */
|
|
|
|
/* find the right while loop */
|
|
|
|
whtemp = whlist;
|
|
|
|
while (whtemp) {
|
|
|
|
if (whtemp->w_begin == lp)
|
|
|
|
break;
|
|
|
|
whtemp = whtemp->w_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (whtemp == NULL) {
|
|
|
|
mlwrite
|
|
|
|
("%%Internal While loop error");
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the line pointer back.. */
|
|
|
|
lp = whtemp->w_end;
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DELSE: /* ELSE directive */
|
|
|
|
if (execlevel == 1)
|
|
|
|
--execlevel;
|
|
|
|
else if (execlevel == 0)
|
|
|
|
++execlevel;
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DENDIF: /* ENDIF directive */
|
|
|
|
if (execlevel)
|
|
|
|
--execlevel;
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DGOTO: /* GOTO directive */
|
|
|
|
/* .....only if we are currently executing */
|
|
|
|
if (execlevel == 0) {
|
|
|
|
/* grab label to jump to */
|
2015-09-27 07:19:55 -04:00
|
|
|
eline = token( eline, golabel, sizeof golabel) ;
|
2015-01-09 04:53:29 -05:00
|
|
|
linlen = strlen(golabel);
|
|
|
|
glp = hlp->l_fp;
|
|
|
|
while (glp != hlp) {
|
|
|
|
if (*glp->l_text == '*' &&
|
|
|
|
(strncmp
|
|
|
|
(&glp->l_text[1],
|
|
|
|
golabel,
|
|
|
|
linlen) == 0)) {
|
|
|
|
lp = glp;
|
|
|
|
goto onward;
|
|
|
|
}
|
|
|
|
glp = glp->l_fp;
|
|
|
|
}
|
|
|
|
mlwrite("%%No such label");
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DRETURN: /* RETURN directive */
|
|
|
|
if (execlevel == 0)
|
|
|
|
goto eexec;
|
|
|
|
goto onward;
|
|
|
|
|
|
|
|
case DENDWHILE: /* ENDWHILE directive */
|
|
|
|
if (execlevel) {
|
|
|
|
--execlevel;
|
|
|
|
goto onward;
|
|
|
|
} else {
|
|
|
|
/* find the right while loop */
|
|
|
|
whtemp = whlist;
|
|
|
|
while (whtemp) {
|
|
|
|
if (whtemp->w_type ==
|
|
|
|
BTWHILE
|
|
|
|
&& whtemp->w_end == lp)
|
|
|
|
break;
|
|
|
|
whtemp = whtemp->w_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (whtemp == NULL) {
|
|
|
|
mlwrite
|
|
|
|
("%%Internal While loop error");
|
|
|
|
freewhile(whlist);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the line pointer back.. */
|
|
|
|
lp = whtemp->w_begin->l_bp;
|
|
|
|
goto onward;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DFORCE: /* FORCE directive */
|
|
|
|
force = TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* execute the statement */
|
|
|
|
status = docmd(eline);
|
|
|
|
if (force) /* force the status */
|
|
|
|
status = TRUE;
|
|
|
|
|
|
|
|
/* check for a command error */
|
|
|
|
if (status != TRUE) {
|
|
|
|
/* look if buffer is showing */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_bufp == bp) {
|
|
|
|
/* and point it */
|
|
|
|
wp->w_dotp = lp;
|
|
|
|
wp->w_doto = 0;
|
|
|
|
wp->w_flag |= WFHARD;
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
/* in any case set the buffer . */
|
|
|
|
bp->b_dotp = lp;
|
|
|
|
bp->b_doto = 0;
|
|
|
|
free(einit);
|
|
|
|
execlevel = 0;
|
|
|
|
freewhile(whlist);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
onward: /* on to the next line */
|
|
|
|
free(einit);
|
|
|
|
lp = lp->l_fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
eexec: /* exit the current function */
|
|
|
|
execlevel = 0;
|
|
|
|
freewhile(whlist);
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* free a list of while block pointers
|
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* struct while_block *wp; head of structure to free
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2013-09-23 08:29:49 -04:00
|
|
|
static void freewhile(struct while_block *wp)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
if (wp->w_next)
|
|
|
|
freewhile(wp->w_next);
|
|
|
|
free(wp);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* execute a series of commands in a file
|
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f, n; default flag and numeric arg to pass on to file
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-10-05 01:27:45 -04:00
|
|
|
int execfile( int f, int n) {
|
|
|
|
int status ; /* return status of name query */
|
|
|
|
char *fname ; /* name of file to execute */
|
|
|
|
char *fspec ; /* full file spec */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2016-03-11 23:58:05 -05:00
|
|
|
status = newmlarg( &fname, "Execute file: ", 0) ;
|
2015-10-05 01:27:45 -04:00
|
|
|
if( status != TRUE)
|
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-10-05 01:27:45 -04:00
|
|
|
/* look up the path for the file */
|
|
|
|
fspec = flook( fname, FALSE) ; /* used to be TRUE, P.K. */
|
|
|
|
free( fname) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-10-05 01:27:45 -04:00
|
|
|
/* if it isn't around */
|
|
|
|
if( fspec == NULL)
|
|
|
|
return FALSE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-10-05 01:27:45 -04:00
|
|
|
/* otherwise, execute it */
|
|
|
|
while( status == TRUE && n-- > 0)
|
|
|
|
status = dofile( fspec) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2017-05-05 20:51:02 -04:00
|
|
|
return status ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* dofile:
|
2015-01-09 04:53:29 -05:00
|
|
|
* yank a file into a buffer and execute it
|
|
|
|
* if there are no errors, delete the buffer on exit
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* char *fname; file name to execute
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-01-16 08:12:27 -05:00
|
|
|
int dofile( const char *fname) {
|
2015-01-09 04:53:29 -05:00
|
|
|
struct buffer *bp; /* buffer to place file to exeute */
|
|
|
|
struct buffer *cb; /* temp to hold current buf while we read */
|
|
|
|
int status; /* results of various calls */
|
|
|
|
bname_t bname ; /* name of buffer */
|
|
|
|
|
|
|
|
makename(bname, fname); /* derive the name of the buffer */
|
|
|
|
unqname(bname); /* make sure we don't stomp things */
|
|
|
|
if ((bp = bfind(bname, TRUE, 0)) == NULL) /* get the needed buffer */
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
bp->b_mode = MDVIEW; /* mark the buffer as read only */
|
|
|
|
cb = curbp; /* save the old buffer */
|
|
|
|
curbp = bp; /* make this one current */
|
|
|
|
/* and try to read in the file to execute */
|
|
|
|
if ((status = readin(fname, FALSE)) != TRUE) {
|
|
|
|
curbp = cb; /* restore the current buffer */
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go execute it! */
|
|
|
|
curbp = cb; /* restore the current buffer */
|
|
|
|
if ((status = dobuf(bp)) != TRUE)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* if not displayed, remove the now unneeded buffer and exit */
|
|
|
|
if (bp->b_nwnd == 0)
|
|
|
|
zotbuf(bp);
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* cbuf:
|
2015-01-09 04:53:29 -05:00
|
|
|
* Execute the contents of a numbered buffer
|
2005-10-01 01:52:45 -04:00
|
|
|
*
|
2015-01-09 04:53:29 -05:00
|
|
|
* int f, n; default flag and numeric arg
|
|
|
|
* int bufnum; number of buffer to execute
|
2005-10-01 01:52:45 -04:00
|
|
|
*/
|
2015-01-14 04:16:33 -05:00
|
|
|
static int cbuf(int f, int n, int bufnum)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
struct buffer *bp; /* ptr to buffer to execute */
|
|
|
|
int status; /* status return */
|
|
|
|
static char bufname[] = "*Macro xx*";
|
|
|
|
|
|
|
|
/* make the buffer name */
|
|
|
|
bufname[7] = '0' + (bufnum / 10);
|
|
|
|
bufname[8] = '0' + (bufnum % 10);
|
|
|
|
|
|
|
|
/* find the pointer to that buffer */
|
|
|
|
if ((bp = bfind(bufname, FALSE, 0)) == NULL) {
|
|
|
|
mlwrite("Macro not defined");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and now execute it as asked */
|
|
|
|
while (n-- > 0)
|
|
|
|
if ((status = dobuf(bp)) != TRUE)
|
|
|
|
return status;
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf1(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 1);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf2(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 2);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf3(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 3);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf4(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 4);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf5(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 5);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf6(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 6);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf7(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 7);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf8(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 8);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf9(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 9);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf10(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 10);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf11(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 11);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf12(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 12);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf13(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 13);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf14(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 14);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf15(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 15);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf16(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 16);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf17(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 17);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf18(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 18);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf19(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 19);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf20(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 20);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf21(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 21);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf22(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 22);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf23(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 23);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf24(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 24);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf25(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 25);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf26(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 26);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf27(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 27);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf28(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 28);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf29(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 29);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf30(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 30);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf31(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 31);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf32(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 32);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf33(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 33);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf34(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 34);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf35(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 35);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf36(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 36);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf37(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 37);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf38(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 38);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf39(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 39);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int cbuf40(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-01-09 04:53:29 -05:00
|
|
|
return cbuf(f, n, 40);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|