mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-19 07:46:24 -05:00
Merge branch 'execute'
This commit is contained in:
commit
fa96d9e63e
6
Makefile
6
Makefile
@ -43,7 +43,7 @@ ifeq ($(uname_S),Darwin)
|
|||||||
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
|
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
|
||||||
endif
|
endif
|
||||||
ifeq ($(uname_S),CYGWIN)
|
ifeq ($(uname_S),CYGWIN)
|
||||||
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
|
DEFINES=-DAUTOCONF -DCYGWIN -DPOSIX -DSYSV -DPROGRAM=$(PROGRAM)
|
||||||
LIBS=-lcurses
|
LIBS=-lcurses
|
||||||
endif
|
endif
|
||||||
ifeq ($(uname_S),MINGW32)
|
ifeq ($(uname_S),MINGW32)
|
||||||
@ -176,7 +176,7 @@ names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \
|
|||||||
line.h retcode.h utf8.h display.h estruct.h eval.h exec.h file.h \
|
line.h retcode.h utf8.h display.h estruct.h eval.h exec.h file.h \
|
||||||
isearch.h region.h random.h search.h spawn.h window.h defines.h word.h
|
isearch.h region.h random.h search.h spawn.h window.h defines.h word.h
|
||||||
pklock.o: pklock.c estruct.h pklock.h
|
pklock.o: pklock.c estruct.h pklock.h
|
||||||
posix.o: posix.c
|
posix.o: posix.c termio.h estruct.h retcode.h utf8.h
|
||||||
random.o: random.c random.h basic.h buffer.h crypt.h line.h retcode.h \
|
random.o: random.c random.h basic.h buffer.h crypt.h line.h retcode.h \
|
||||||
utf8.h display.h estruct.h execute.h input.h bind.h search.h terminal.h \
|
utf8.h display.h estruct.h execute.h input.h bind.h search.h terminal.h \
|
||||||
defines.h window.h
|
defines.h window.h
|
||||||
@ -190,7 +190,7 @@ spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h retcode.h \
|
|||||||
terminal.h window.h
|
terminal.h window.h
|
||||||
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
|
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
|
||||||
termio.h
|
termio.h
|
||||||
termio.o: termio.c termio.h estruct.h retcode.h utf8.h
|
termio.o: termio.c
|
||||||
utf8.o: utf8.c utf8.h
|
utf8.o: utf8.c utf8.h
|
||||||
window.o: window.c window.h defines.h buffer.h crypt.h line.h retcode.h \
|
window.o: window.c window.h defines.h buffer.h crypt.h line.h retcode.h \
|
||||||
utf8.h basic.h display.h estruct.h execute.h terminal.h wrapper.h
|
utf8.h basic.h display.h estruct.h execute.h terminal.h wrapper.h
|
||||||
|
13
basic.c
13
basic.c
@ -90,21 +90,22 @@ int gotoeol(int f, int n)
|
|||||||
*
|
*
|
||||||
* @n: The specified line position at the current buffer.
|
* @n: The specified line position at the current buffer.
|
||||||
*/
|
*/
|
||||||
int gotoline(int f, int n)
|
int gotoline( int f, int n) {
|
||||||
{
|
|
||||||
int status ;
|
|
||||||
char arg[ NSTRING] ; /* Buffer to hold argument. */
|
|
||||||
|
|
||||||
/* Get an argument if one doesnt exist. */
|
/* Get an argument if one doesnt exist. */
|
||||||
if( f == FALSE) {
|
if( f == FALSE) {
|
||||||
status = mlreply( "Line to GOTO: ", arg, sizeof arg) ;
|
int status ;
|
||||||
|
char *arg ; /* Buffer to hold argument. */
|
||||||
|
|
||||||
|
status = newmlarg( &arg, "Line to GOTO: ", 0) ;
|
||||||
if( status != TRUE) {
|
if( status != TRUE) {
|
||||||
mloutstr( "(Aborted)") ;
|
mloutstr( "(Aborted)") ;
|
||||||
return status ;
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = atoi( arg) ;
|
n = atoi( arg) ;
|
||||||
|
free( arg) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle the case where the user may be passed something like this:
|
/* Handle the case where the user may be passed something like this:
|
||||||
* em filename +
|
* em filename +
|
||||||
* In this case we just go to the end of the buffer.
|
* In this case we just go to the end of the buffer.
|
||||||
|
36
bind.c
36
bind.c
@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "estruct.h"
|
#include "estruct.h"
|
||||||
@ -273,23 +274,24 @@ static int unbindchar( unsigned c) {
|
|||||||
* bring up a fake buffer and list the key bindings
|
* bring up a fake buffer and list the key bindings
|
||||||
* into it with view mode
|
* into it with view mode
|
||||||
*/
|
*/
|
||||||
int desbind(int f, int n)
|
int desbind( int f, int n) {
|
||||||
#if APROP
|
#if APROP
|
||||||
{
|
return buildlist( "") ;
|
||||||
buildlist( "") ;
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int apro(int f, int n)
|
/* Apropos (List functions that match a substring) */
|
||||||
{ /* Apropos (List functions that match a substring) */
|
int apro( int f, int n) {
|
||||||
char mstring[NSTRING]; /* string to match cmd names to */
|
char *mstring ; /* string to match cmd names to */
|
||||||
int status ; /* status return */
|
int status ; /* status return */
|
||||||
|
|
||||||
status = mlreply("Apropos string: ", mstring, NSTRING - 1);
|
status = newmlarg( &mstring, "Apropos string: ", 0) ;
|
||||||
if (status == ABORT)
|
if( status == TRUE) {
|
||||||
return status;
|
status = buildlist( mstring) ;
|
||||||
|
free( mstring) ;
|
||||||
|
} else if( status == FALSE)
|
||||||
|
status = buildlist( "") ; /* build list of all commands */
|
||||||
|
|
||||||
return buildlist( mstring) ;
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -297,9 +299,8 @@ int apro(int f, int n)
|
|||||||
*
|
*
|
||||||
* char *mstring; match string if a partial list, "" matches all
|
* char *mstring; match string if a partial list, "" matches all
|
||||||
*/
|
*/
|
||||||
static int buildlist( char *mstring)
|
static int buildlist( char *mstring) {
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
struct window *wp; /* scanning pointer to windows */
|
struct window *wp; /* scanning pointer to windows */
|
||||||
struct key_tab *ktp; /* pointer into the command table */
|
struct key_tab *ktp; /* pointer into the command table */
|
||||||
struct name_bind *nptr; /* pointer into the name binding table */
|
struct name_bind *nptr; /* pointer into the name binding table */
|
||||||
@ -439,12 +440,15 @@ static unsigned int getckey( int mflag) {
|
|||||||
|
|
||||||
/* check to see if we are executing a command line */
|
/* check to see if we are executing a command line */
|
||||||
if( clexec) {
|
if( clexec) {
|
||||||
char tok[ NSTRING] ; /* command incoming */
|
char *tok ; /* command incoming */
|
||||||
|
|
||||||
if( TRUE != macarg( tok, sizeof tok)) /* get the next token */
|
tok = getnewtokval() ; /* get the next token */
|
||||||
|
if( tok == NULL)
|
||||||
c = 0 ; /* return dummy key on failure */
|
c = 0 ; /* return dummy key on failure */
|
||||||
else
|
else {
|
||||||
c = stock( tok) ;
|
c = stock( tok) ;
|
||||||
|
free( tok) ;
|
||||||
|
}
|
||||||
} else { /* or the normal way */
|
} else { /* or the normal way */
|
||||||
if( mflag)
|
if( mflag)
|
||||||
c = get1key() ;
|
c = get1key() ;
|
||||||
|
64
buffer.c
64
buffer.c
@ -55,16 +55,23 @@ static void l_to_a( char *buf, int width, long num) ;
|
|||||||
* if the use count is 0. Otherwise, they come
|
* if the use count is 0. Otherwise, they come
|
||||||
* from some other window.
|
* from some other window.
|
||||||
*/
|
*/
|
||||||
int usebuffer(int f, int n)
|
int usebuffer( int f, int n) {
|
||||||
{
|
|
||||||
struct buffer *bp ;
|
struct buffer *bp ;
|
||||||
int s;
|
int status ;
|
||||||
bname_t bufn ;
|
char *bufn ;
|
||||||
|
|
||||||
if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE)
|
/* Get buffer name */
|
||||||
return s;
|
status = newmlarg( &bufn, "Use buffer: ", sizeof( bname_t)) ;
|
||||||
if ((bp = bfind(bufn, TRUE, 0)) == NULL)
|
if( status != TRUE)
|
||||||
|
return status ;
|
||||||
|
|
||||||
|
/* Find buffer in list */
|
||||||
|
bp = bfind( bufn, TRUE, 0) ;
|
||||||
|
free( bufn) ;
|
||||||
|
if( bp == NULL)
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
|
/* Switch to buffer */
|
||||||
return swbuffer( bp) ;
|
return swbuffer( bp) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,18 +171,25 @@ int swbuffer(struct buffer *bp)
|
|||||||
* if the buffer has been changed). Then free the header
|
* if the buffer has been changed). Then free the header
|
||||||
* line and the buffer header. Bound to "C-X K".
|
* line and the buffer header. Bound to "C-X K".
|
||||||
*/
|
*/
|
||||||
int killbuffer(int f, int n)
|
int killbuffer( int f, int n) {
|
||||||
{
|
|
||||||
struct buffer *bp ;
|
struct buffer *bp ;
|
||||||
int s;
|
int status ;
|
||||||
bname_t bufn ;
|
char *bufn ;
|
||||||
|
|
||||||
if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE)
|
/* Get buffer name */
|
||||||
return s;
|
status = newmlarg( &bufn, "Kill buffer: ", sizeof( bname_t)) ;
|
||||||
if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
|
if( status != TRUE)
|
||||||
|
return status ;
|
||||||
|
|
||||||
|
/* Find buffer in list */
|
||||||
|
bp = bfind( bufn, FALSE, 0) ;
|
||||||
|
free( bufn) ;
|
||||||
|
if( bp == NULL) /* Easy if unknown. */
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
|
|
||||||
if( bp->b_flag & BFINVS) /* Deal with special buffers */
|
if( bp->b_flag & BFINVS) /* Deal with special buffers */
|
||||||
return TRUE ; /* by doing nothing. */
|
return TRUE ; /* by doing nothing. */
|
||||||
|
|
||||||
return zotbuf( bp) ;
|
return zotbuf( bp) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,28 +229,34 @@ int zotbuf(struct buffer *bp)
|
|||||||
*
|
*
|
||||||
* int f, n; default Flag & Numeric arg
|
* int f, n; default Flag & Numeric arg
|
||||||
*/
|
*/
|
||||||
int namebuffer(int f, int n)
|
int namebuffer( int f, int n) {
|
||||||
{
|
|
||||||
struct buffer *bp ; /* pointer to scan through all buffers */
|
struct buffer *bp ; /* pointer to scan through all buffers */
|
||||||
bname_t bufn ; /* buffer to hold buffer name */
|
int status ;
|
||||||
|
char *bufn ; /* buffer to hold buffer name */
|
||||||
|
|
||||||
/* prompt for and get the new buffer name */
|
/* prompt for and get the new buffer name */
|
||||||
ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) !=
|
ask:
|
||||||
TRUE)
|
status = newmlarg( &bufn, "Change buffer name to: ", sizeof( bname_t)) ;
|
||||||
return FALSE;
|
if( status != TRUE)
|
||||||
|
return status ;
|
||||||
|
|
||||||
/* and check for duplicates */
|
/* and check for duplicates */
|
||||||
bp = bheadp ;
|
bp = bheadp ;
|
||||||
while( bp != NULL) {
|
while( bp != NULL) {
|
||||||
if( bp != curbp) {
|
if( bp != curbp) {
|
||||||
/* if the names the same */
|
/* retry if the names are the same */
|
||||||
if (strcmp(bufn, bp->b_bname) == 0)
|
if( strcmp( bufn, bp->b_bname) == 0) {
|
||||||
|
free( bufn) ;
|
||||||
goto ask ; /* try again */
|
goto ask ; /* try again */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bp = bp->b_bufp ; /* onward */
|
bp = bp->b_bufp ; /* onward */
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
|
strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
|
||||||
|
free( bufn) ;
|
||||||
|
|
||||||
curwp->w_flag |= WFMODE ; /* make mode line replot */
|
curwp->w_flag |= WFMODE ; /* make mode line replot */
|
||||||
mloutstr( "") ; /* erase message line */
|
mloutstr( "") ; /* erase message line */
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
|
4
ebind.c
4
ebind.c
@ -301,8 +301,8 @@ struct key_tab keytab[NBINDS] = {
|
|||||||
{META | 'R', sreplace}
|
{META | 'R', sreplace}
|
||||||
,
|
,
|
||||||
#if PKCODE
|
#if PKCODE
|
||||||
{META | 'S', forwsearch}
|
{META | 'S', forwhunt}
|
||||||
, /* alternative P.K. */
|
,
|
||||||
#else
|
#else
|
||||||
#if BSD
|
#if BSD
|
||||||
{META | 'S', bktoshell}
|
{META | 'S', bktoshell}
|
||||||
|
157
eval.c
157
eval.c
@ -312,9 +312,9 @@ void varinit(void)
|
|||||||
*/
|
*/
|
||||||
static char *gtfun( char *fname) {
|
static char *gtfun( char *fname) {
|
||||||
unsigned fnum ; /* index to function to eval */
|
unsigned fnum ; /* index to function to eval */
|
||||||
char argx[ 512] ; /* last argument, fixed sized allocation */
|
|
||||||
char *arg1 ; /* value of first argument */
|
char *arg1 ; /* value of first argument */
|
||||||
char *arg2 ; /* value of second argument */
|
char *arg2 ; /* value of second argument */
|
||||||
|
char *arg3 ; /* last argument */
|
||||||
char *retstr ; /* return value */
|
char *retstr ; /* return value */
|
||||||
int low, high ; /* binary search indexes */
|
int low, high ; /* binary search indexes */
|
||||||
|
|
||||||
@ -342,27 +342,26 @@ static char *gtfun( char *fname) {
|
|||||||
if (fnum == ARRAY_SIZE(funcs))
|
if (fnum == ARRAY_SIZE(funcs))
|
||||||
return errorm;
|
return errorm;
|
||||||
|
|
||||||
arg1 = arg2 = NULL ;
|
arg1 = arg2 = arg3 = NULL ;
|
||||||
|
assert( clexec == TRUE) ; /* means macarg can be replaced by gettokval */
|
||||||
/* if needed, retrieve the first argument */
|
/* if needed, retrieve the first argument */
|
||||||
if (funcs[fnum].f_type >= MONAMIC) {
|
if (funcs[fnum].f_type >= MONAMIC) {
|
||||||
if( macarg( argx, sizeof argx) != TRUE)
|
arg1 = getnewtokval() ;
|
||||||
|
if( arg1 == NULL)
|
||||||
return errorm;
|
return errorm;
|
||||||
|
|
||||||
/* if needed, retrieve the second argument */
|
/* if needed, retrieve the second argument */
|
||||||
if (funcs[fnum].f_type >= DYNAMIC) {
|
if (funcs[fnum].f_type >= DYNAMIC) {
|
||||||
arg1 = malloc( strlen( argx) + 1) ;
|
arg2 = getnewtokval() ;
|
||||||
strcpy( arg1, argx) ;
|
if( arg2 == NULL) {
|
||||||
if( macarg( argx, sizeof argx) != TRUE) {
|
|
||||||
free( arg1) ;
|
free( arg1) ;
|
||||||
return errorm;
|
return errorm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if needed, retrieve the third argument */
|
/* if needed, retrieve the third argument */
|
||||||
if (funcs[fnum].f_type >= TRINAMIC) {
|
if (funcs[fnum].f_type >= TRINAMIC) {
|
||||||
arg2 = malloc( strlen( argx) + 1) ;
|
arg3 = getnewtokval() ;
|
||||||
strcpy( arg2, argx) ;
|
if( arg3 == NULL) {
|
||||||
if( macarg( argx, sizeof argx) != TRUE) {
|
|
||||||
free( arg1) ;
|
free( arg1) ;
|
||||||
free( arg2) ;
|
free( arg2) ;
|
||||||
return errorm;
|
return errorm;
|
||||||
@ -376,30 +375,30 @@ static char *gtfun( char *fname) {
|
|||||||
int sz ;
|
int sz ;
|
||||||
|
|
||||||
case UFADD | DYNAMIC:
|
case UFADD | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) + atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) + atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSUB | DYNAMIC:
|
case UFSUB | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) - atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) - atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTIMES | DYNAMIC:
|
case UFTIMES | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) * atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) * atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFDIV | DYNAMIC:
|
case UFDIV | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( arg2) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMOD | DYNAMIC:
|
case UFMOD | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( arg2) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFNEG | MONAMIC:
|
case UFNEG | MONAMIC:
|
||||||
retstr = i_to_a( -atoi( argx)) ;
|
retstr = i_to_a( -atoi( arg1)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFCAT | DYNAMIC: {
|
case UFCAT | DYNAMIC: {
|
||||||
int sz1 ;
|
int sz1 ;
|
||||||
|
|
||||||
sz1 = strlen( arg1) ;
|
sz1 = strlen( arg1) ;
|
||||||
sz = sz1 + strlen( argx) + 1 ;
|
sz = sz1 + strlen( arg2) + 1 ;
|
||||||
if( sz > ressize) {
|
if( sz > ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz) ;
|
result = malloc( sz) ;
|
||||||
@ -407,12 +406,12 @@ static char *gtfun( char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
strcpy( result, arg1) ;
|
strcpy( result, arg1) ;
|
||||||
strcpy( &result[ sz1], argx) ;
|
strcpy( &result[ sz1], arg2) ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
case UFLEFT | DYNAMIC:
|
case UFLEFT | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( arg2) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
@ -424,7 +423,7 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFRIGHT | DYNAMIC:
|
case UFRIGHT | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( arg2) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
@ -434,7 +433,7 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
|
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMID | TRINAMIC:
|
case UFMID | TRINAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( arg3) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
@ -446,28 +445,28 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFNOT | MONAMIC:
|
case UFNOT | MONAMIC:
|
||||||
retstr = ltos( stol( argx) == FALSE) ;
|
retstr = ltos( stol( arg1) == FALSE) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEQUAL | DYNAMIC:
|
case UFEQUAL | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) == atoi( argx)) ;
|
retstr = ltos( atoi( arg1) == atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLESS | DYNAMIC:
|
case UFLESS | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) < atoi( argx)) ;
|
retstr = ltos( atoi( arg1) < atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFGREATER | DYNAMIC:
|
case UFGREATER | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) > atoi( argx)) ;
|
retstr = ltos( atoi( arg1) > atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSEQUAL | DYNAMIC:
|
case UFSEQUAL | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) == 0) ;
|
retstr = ltos( strcmp( arg1, arg2) == 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSLESS | DYNAMIC:
|
case UFSLESS | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) < 0) ;
|
retstr = ltos( strcmp( arg1, arg2) < 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSGREAT | DYNAMIC:
|
case UFSGREAT | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) > 0) ;
|
retstr = ltos( strcmp( arg1, arg2) > 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFIND | MONAMIC:
|
case UFIND | MONAMIC:
|
||||||
retstr = getval( argx) ;
|
retstr = getval( arg1) ;
|
||||||
sz = strlen( retstr) + 1 ;
|
sz = strlen( retstr) + 1 ;
|
||||||
if( sz > ressize) {
|
if( sz > ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -478,42 +477,42 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = strcpy( result, retstr) ;
|
retstr = strcpy( result, retstr) ;
|
||||||
break ;
|
break ;
|
||||||
case UFAND | DYNAMIC:
|
case UFAND | DYNAMIC:
|
||||||
retstr = ltos( stol( arg1) && stol( argx)) ;
|
retstr = ltos( stol( arg1) && stol( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFOR | DYNAMIC:
|
case UFOR | DYNAMIC:
|
||||||
retstr = ltos( stol( arg1) || stol( argx)) ;
|
retstr = ltos( stol( arg1) || stol( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLENGTH | MONAMIC:
|
case UFLENGTH | MONAMIC:
|
||||||
retstr = i_to_a( strlen( argx)) ;
|
retstr = i_to_a( strlen( arg1)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFUPPER | MONAMIC:
|
case UFUPPER | MONAMIC:
|
||||||
sz = strlen( argx) ;
|
sz = strlen( arg1) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
retstr = mkupper( result, argx) ;
|
retstr = mkupper( result, arg1) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLOWER | MONAMIC:
|
case UFLOWER | MONAMIC:
|
||||||
sz = strlen( argx) ;
|
sz = strlen( arg1) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( result, argx) ; /* result is at least as long as argx */
|
strcpy( result, arg1) ; /* result is at least as long as arg1 */
|
||||||
retstr = mklower( result) ;
|
retstr = mklower( result) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTRUTH | MONAMIC:
|
case UFTRUTH | MONAMIC:
|
||||||
retstr = ltos( atoi( argx) == 42) ;
|
retstr = ltos( atoi( arg1) == 42) ;
|
||||||
break ;
|
break ;
|
||||||
case UFASCII | MONAMIC: {
|
case UFASCII | MONAMIC: {
|
||||||
unicode_t c ;
|
unicode_t c ;
|
||||||
|
|
||||||
utf8_to_unicode( argx, 0, 4, &c) ;
|
utf8_to_unicode( arg1, 0, 4, &c) ;
|
||||||
retstr = i_to_a( c) ;
|
retstr = i_to_a( c) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +520,7 @@ static char *gtfun( char *fname) {
|
|||||||
case UFCHR | MONAMIC: {
|
case UFCHR | MONAMIC: {
|
||||||
unicode_t c ;
|
unicode_t c ;
|
||||||
|
|
||||||
c = atoi( argx) ;
|
c = atoi( arg1) ;
|
||||||
if( c > 0x10FFFF)
|
if( c > 0x10FFFF)
|
||||||
retstr = errorm ;
|
retstr = errorm ;
|
||||||
else {
|
else {
|
||||||
@ -538,7 +537,7 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFRND | MONAMIC:
|
case UFRND | MONAMIC:
|
||||||
sz = abs( atoi( argx)) ;
|
sz = abs( atoi( arg1)) ;
|
||||||
if( sz == 0)
|
if( sz == 0)
|
||||||
sz = ernd() ;
|
sz = ernd() ;
|
||||||
else
|
else
|
||||||
@ -547,14 +546,14 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = i_to_a( sz) ;
|
retstr = i_to_a( sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFABS | MONAMIC:
|
case UFABS | MONAMIC:
|
||||||
retstr = i_to_a( abs( atoi( argx))) ;
|
retstr = i_to_a( abs( atoi( arg1))) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSINDEX | DYNAMIC:
|
case UFSINDEX | DYNAMIC:
|
||||||
retstr = i_to_a( sindex( arg1, argx)) ;
|
retstr = i_to_a( sindex( arg1, arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFENV | MONAMIC:
|
case UFENV | MONAMIC:
|
||||||
#if ENVFUNC
|
#if ENVFUNC
|
||||||
retstr = getenv( argx) ;
|
retstr = getenv( arg1) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
retstr = "" ;
|
retstr = "" ;
|
||||||
#else
|
#else
|
||||||
@ -562,36 +561,39 @@ static char *gtfun( char *fname) {
|
|||||||
#endif
|
#endif
|
||||||
break ;
|
break ;
|
||||||
case UFBIND | MONAMIC:
|
case UFBIND | MONAMIC:
|
||||||
retstr = transbind( argx) ;
|
retstr = transbind( arg1) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEXIST | MONAMIC:
|
case UFEXIST | MONAMIC:
|
||||||
retstr = ltos( fexist( argx)) ;
|
retstr = ltos( fexist( arg1)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFFIND | MONAMIC:
|
case UFFIND | MONAMIC:
|
||||||
retstr = flook( argx, TRUE) ;
|
retstr = flook( arg1, TRUE) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
retstr = "" ;
|
retstr = "" ;
|
||||||
break ;
|
break ;
|
||||||
case UFBAND | DYNAMIC:
|
case UFBAND | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) & atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) & atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBOR | DYNAMIC:
|
case UFBOR | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) | atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) | atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBXOR | DYNAMIC:
|
case UFBXOR | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) ^ atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) ^ atoi( arg2)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBNOT | DYNAMIC:
|
case UFBNOT | MONAMIC:
|
||||||
retstr = i_to_a( ~atoi( argx)) ;
|
retstr = i_to_a( ~atoi( arg1)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFXLATE | TRINAMIC:
|
case UFXLATE | TRINAMIC:
|
||||||
retstr = xlat( arg1, arg2, argx) ;
|
retstr = xlat( arg1, arg2, arg3) ;
|
||||||
break ;
|
break ;
|
||||||
default:
|
default:
|
||||||
assert( FALSE) ; /* never should get here */
|
assert( FALSE) ; /* never should get here */
|
||||||
retstr = errorm ;
|
retstr = errorm ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( arg3)
|
||||||
|
free( arg3) ;
|
||||||
|
|
||||||
if( arg2)
|
if( arg2)
|
||||||
free( arg2) ;
|
free( arg2) ;
|
||||||
|
|
||||||
@ -767,11 +769,11 @@ int setvar(int f, int n)
|
|||||||
int status; /* status return */
|
int status; /* status return */
|
||||||
struct variable_description vd; /* variable num/type */
|
struct variable_description vd; /* variable num/type */
|
||||||
char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */
|
char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */
|
||||||
char value[ 2 * NSTRING] ; /* value to set variable to */
|
char *value ; /* value to set variable to */
|
||||||
|
|
||||||
/* first get the variable to set.. */
|
/* first get the variable to set.. */
|
||||||
if (clexec == FALSE) {
|
if (clexec == FALSE) {
|
||||||
status = mlreply( "Variable to set: ", var, sizeof var) ;
|
status = getstring( "Variable to set: ", var, sizeof var, nlc) ;
|
||||||
if (status != TRUE)
|
if (status != TRUE)
|
||||||
return status;
|
return status;
|
||||||
} else { /* macro line argument */
|
} else { /* macro line argument */
|
||||||
@ -790,11 +792,15 @@ int setvar(int f, int n)
|
|||||||
|
|
||||||
/* get the value for that variable */
|
/* get the value for that variable */
|
||||||
if( f == TRUE) {
|
if( f == TRUE) {
|
||||||
|
value = malloc( NSTRING) ;
|
||||||
|
if( value == NULL)
|
||||||
|
return FALSE ;
|
||||||
|
|
||||||
/* a bit overcautious here in using strncpy */
|
/* a bit overcautious here in using strncpy */
|
||||||
strncpy( value, i_to_a( n), sizeof value - 1) ;
|
strncpy( value, i_to_a( n), NSTRING - 1) ;
|
||||||
value[ sizeof value - 1] = '\0' ;
|
value[ NSTRING - 1] = '\0' ;
|
||||||
} else {
|
} else {
|
||||||
status = mlreply( "Value: ", value, sizeof value);
|
status = newmlarg( &value, "Value: ", 0) ;
|
||||||
if (status != TRUE)
|
if (status != TRUE)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -812,6 +818,7 @@ int setvar(int f, int n)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* and return it */
|
/* and return it */
|
||||||
|
free( value) ;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,9 +896,7 @@ fvar:
|
|||||||
var[4] = 0;
|
var[4] = 0;
|
||||||
if (strcmp(&var[1], "ind") == 0) {
|
if (strcmp(&var[1], "ind") == 0) {
|
||||||
/* grab token, and eval it */
|
/* grab token, and eval it */
|
||||||
gettoken( var, size) ;
|
if( TRUE == gettokval( var, size))
|
||||||
strncpy( var, getval( var), size - 1) ;
|
|
||||||
var[ size - 1] = '\0' ;
|
|
||||||
goto fvar ;
|
goto fvar ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1117,15 +1122,9 @@ static int gettyp( char *token) {
|
|||||||
/* grab the first char (this is all we need) */
|
/* grab the first char (this is all we need) */
|
||||||
c = *token;
|
c = *token;
|
||||||
|
|
||||||
/* no blanks!!! */
|
|
||||||
if (c == 0)
|
|
||||||
return TKNUL;
|
|
||||||
|
|
||||||
/* a numeric literal? */
|
|
||||||
if( (c >= '0' && c <= '9') || c == '-')
|
|
||||||
return TKLIT;
|
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 0: /* no blanks!!! */
|
||||||
|
return TKNUL ;
|
||||||
case '"':
|
case '"':
|
||||||
return TKSTR;
|
return TKSTR;
|
||||||
|
|
||||||
@ -1133,7 +1132,7 @@ static int gettyp( char *token) {
|
|||||||
return TKDIR;
|
return TKDIR;
|
||||||
case '@':
|
case '@':
|
||||||
return TKARG;
|
return TKARG;
|
||||||
case '#':
|
case '=':
|
||||||
return TKBUF;
|
return TKBUF;
|
||||||
case '$':
|
case '$':
|
||||||
return TKENV;
|
return TKENV;
|
||||||
@ -1145,6 +1144,10 @@ static int gettyp( char *token) {
|
|||||||
return TKLBL;
|
return TKLBL;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
/* a numeric literal? */
|
||||||
|
if( (c >= '0' && c <= '9') || c == '-')
|
||||||
|
return TKLIT;
|
||||||
|
else
|
||||||
return TKCMD;
|
return TKCMD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1174,7 +1177,7 @@ char *getval(char *token)
|
|||||||
strcpy(token, getval(&token[1]));
|
strcpy(token, getval(&token[1]));
|
||||||
distmp = discmd; /* echo it always! */
|
distmp = discmd; /* echo it always! */
|
||||||
discmd = TRUE;
|
discmd = TRUE;
|
||||||
status = getstring(token, buf, NSTRING, ctoec('\n'));
|
status = getstring( token, buf, NSTRING, nlc) ;
|
||||||
discmd = distmp;
|
discmd = distmp;
|
||||||
if (status == ABORT)
|
if (status == ABORT)
|
||||||
return errorm;
|
return errorm;
|
||||||
@ -1432,15 +1435,17 @@ int clrmes( int f, int n) {
|
|||||||
*/
|
*/
|
||||||
int writemsg( int f, int n) {
|
int writemsg( int f, int n) {
|
||||||
int status ;
|
int status ;
|
||||||
char buf[ NSTRING] ; /* buffer to recieve message into */
|
char *buf ; /* buffer to receive message into */
|
||||||
|
|
||||||
status = mlreply( "Message to write: ", buf, sizeof buf - 1) ;
|
|
||||||
if( status != TRUE)
|
|
||||||
return status ;
|
|
||||||
|
|
||||||
|
status = newmlarg( &buf, "Message to write: ", 0) ;
|
||||||
|
if( status == TRUE) {
|
||||||
/* write the message out */
|
/* write the message out */
|
||||||
mlforce( buf) ;
|
mlforce( buf) ;
|
||||||
return TRUE ;
|
free( buf) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* end of eval.c */
|
||||||
|
235
exec.c
235
exec.c
@ -79,6 +79,7 @@ static int mstore = FALSE ; /* storing text to macro flag */
|
|||||||
|
|
||||||
static int dobuf( struct buffer *bp) ;
|
static int dobuf( struct buffer *bp) ;
|
||||||
static void freewhile( struct while_block *wp) ;
|
static void freewhile( struct while_block *wp) ;
|
||||||
|
static int macarg( char *tok, int toksz) ;
|
||||||
|
|
||||||
void ue_system( const char *cmd) {
|
void ue_system( const char *cmd) {
|
||||||
int ret ;
|
int ret ;
|
||||||
@ -119,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 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +181,10 @@ static int docmd( char *cline) {
|
|||||||
/* process leadin argument */
|
/* process leadin argument */
|
||||||
if( !is_it_cmd( tkn)) {
|
if( !is_it_cmd( tkn)) {
|
||||||
f = TRUE;
|
f = TRUE;
|
||||||
|
/* macarg already includes a getval, skip for now
|
||||||
strncpy( tkn, getval( tkn), sizeof tkn - 1) ;
|
strncpy( tkn, getval( tkn), sizeof tkn - 1) ;
|
||||||
tkn[ sizeof tkn - 1] = '\0' ;
|
tkn[ sizeof tkn - 1] = '\0' ;
|
||||||
|
*/
|
||||||
n = atoi(tkn);
|
n = atoi(tkn);
|
||||||
|
|
||||||
/* and now get the command to execute */
|
/* and now get the command to execute */
|
||||||
@ -209,16 +213,21 @@ static int docmd( char *cline) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* token:
|
* new token:
|
||||||
* chop a token off a string
|
* chop a token off a string
|
||||||
* return a pointer past the token
|
* return a pointer past the token
|
||||||
*
|
*
|
||||||
* char *src, *tok; source string, destination token string
|
* char *src in, source string
|
||||||
* int size; maximum size of token
|
* char **tokref out, destination of newly allocated token string
|
||||||
*/
|
*/
|
||||||
static char *token( char *src, char *tok, int size) {
|
static char *newtoken( char *src, char **tokref) {
|
||||||
int quotef; /* is the current string quoted? */
|
boolean quotef ; /* is the current string quoted? */
|
||||||
char c; /* temporary character */
|
char *tok ; /* allocated string */
|
||||||
|
int size ; /* allocated size */
|
||||||
|
int idx = 0 ; /* insertion point into token string */
|
||||||
|
|
||||||
|
tok = malloc( NSTRING) ;
|
||||||
|
size = (tok == NULL) ? 0 : NSTRING ;
|
||||||
|
|
||||||
/* first scan past any whitespace in the source string */
|
/* first scan past any whitespace in the source string */
|
||||||
while (*src == ' ' || *src == '\t')
|
while (*src == ' ' || *src == '\t')
|
||||||
@ -227,6 +236,8 @@ static char *token( char *src, char *tok, int size) {
|
|||||||
/* scan through the source string */
|
/* scan through the source string */
|
||||||
quotef = FALSE;
|
quotef = FALSE;
|
||||||
while (*src) {
|
while (*src) {
|
||||||
|
char c ; /* temporary character */
|
||||||
|
|
||||||
/* process special characters */
|
/* process special characters */
|
||||||
if (*src == '~') {
|
if (*src == '~') {
|
||||||
++src;
|
++src;
|
||||||
@ -251,9 +262,6 @@ static char *token( char *src, char *tok, int size) {
|
|||||||
default:
|
default:
|
||||||
c = *(src - 1);
|
c = *(src - 1);
|
||||||
}
|
}
|
||||||
if (--size > 0) {
|
|
||||||
*tok++ = c;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* check for the end of the token */
|
/* check for the end of the token */
|
||||||
if (quotef) {
|
if (quotef) {
|
||||||
@ -270,70 +278,114 @@ static char *token( char *src, char *tok, int size) {
|
|||||||
|
|
||||||
/* record the character */
|
/* record the character */
|
||||||
c = *src++;
|
c = *src++;
|
||||||
if (--size > 0)
|
}
|
||||||
*tok++ = c;
|
|
||||||
|
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 ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* terminate the token and exit */
|
/* terminate the token and exit */
|
||||||
if (*src)
|
if (*src)
|
||||||
++src;
|
++src;
|
||||||
*tok = 0;
|
|
||||||
|
if( tok != NULL)
|
||||||
|
tok[ idx] = 0 ;
|
||||||
|
|
||||||
|
*tokref = tok ;
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
}
|
||||||
|
|
||||||
void gettoken( char *tok, int maxtoksize) {
|
void gettoken( char *tok, int maxtoksize) {
|
||||||
execstr = token( execstr, tok, maxtoksize) ;
|
execstr = token( execstr, tok, maxtoksize) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *getnewtoken( void) {
|
||||||
|
char *tok ;
|
||||||
|
|
||||||
|
execstr = newtoken( execstr, &tok) ;
|
||||||
|
return tok ;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean gettokval( char *tok, int size) {
|
||||||
|
char *tmpbuf ;
|
||||||
|
|
||||||
|
/* grab token and advance past */
|
||||||
|
tmpbuf = getnewtoken() ;
|
||||||
|
if( tmpbuf == NULL)
|
||||||
|
return FALSE ;
|
||||||
|
|
||||||
|
/* evaluate it */
|
||||||
|
strncpy( tok, getval( tmpbuf), size - 1) ;
|
||||||
|
tok[ size - 1] = '\0' ;
|
||||||
|
free( tmpbuf) ;
|
||||||
|
return TRUE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get a macro line argument
|
* get a macro line argument
|
||||||
*
|
*
|
||||||
* char *tok; buffer to place argument
|
* char *tok; buffer to place argument
|
||||||
*/
|
*/
|
||||||
int macarg( char *tok, int toksz)
|
static int macarg( char *tok, int toksz) {
|
||||||
{
|
|
||||||
boolean savcle ; /* buffer to store original clexec */
|
|
||||||
int status ;
|
int status ;
|
||||||
|
boolean savcle ; /* buffer to store original clexec */
|
||||||
|
|
||||||
savcle = clexec ; /* save execution mode */
|
savcle = clexec ; /* save execution mode */
|
||||||
clexec = TRUE ; /* get the argument */
|
clexec = TRUE ; /* get the argument */
|
||||||
status = nextarg("", tok, toksz, ctoec('\n'));
|
status = gettokval( tok, toksz) ;
|
||||||
clexec = savcle ; /* restore execution mode */
|
clexec = savcle ; /* restore execution mode */
|
||||||
return status ;
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nextarg:
|
|
||||||
* get the next argument
|
|
||||||
*
|
|
||||||
* const char *prompt; prompt to use if we must be interactive
|
|
||||||
* char *buffer; buffer to put token into
|
|
||||||
* int size; size of the buffer
|
|
||||||
* int terminator; terminating char to be used on interactive fetch
|
|
||||||
*/
|
|
||||||
int nextarg(const char *prompt, char *buffer, int size, int terminator)
|
|
||||||
{
|
|
||||||
char *tmpbuf ;
|
|
||||||
|
|
||||||
/* if we are interactive, go get it! */
|
|
||||||
if (clexec == FALSE)
|
|
||||||
return getstring(prompt, buffer, size, terminator);
|
|
||||||
|
|
||||||
tmpbuf = malloc( size) ;
|
|
||||||
if( tmpbuf == NULL)
|
|
||||||
return FALSE ;
|
|
||||||
|
|
||||||
/* grab token and advance past */
|
|
||||||
gettoken( tmpbuf, size) ;
|
|
||||||
|
|
||||||
/* evaluate it */
|
|
||||||
strncpy( buffer, getval( tmpbuf), size - 1) ;
|
|
||||||
buffer[ size - 1] = '\0' ;
|
|
||||||
free( tmpbuf) ;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* storemac:
|
* storemac:
|
||||||
* Set up a macro buffer and flag to store all
|
* Set up a macro buffer and flag to store all
|
||||||
@ -388,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 ;
|
||||||
}
|
}
|
||||||
@ -428,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
|
||||||
|
|
||||||
@ -463,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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -635,7 +697,7 @@ static int dobuf(struct buffer *bp)
|
|||||||
++eline;
|
++eline;
|
||||||
|
|
||||||
/* dump comments and blank lines */
|
/* dump comments and blank lines */
|
||||||
if (*eline == ';' || *eline == 0)
|
if (*eline == ';' || *eline == '#' || *eline == 0)
|
||||||
goto onward;
|
goto onward;
|
||||||
|
|
||||||
#if DEBUGM
|
#if DEBUGM
|
||||||
@ -782,10 +844,8 @@ static int dobuf(struct buffer *bp)
|
|||||||
case DGOTO: /* GOTO directive */
|
case DGOTO: /* GOTO directive */
|
||||||
/* .....only if we are currently executing */
|
/* .....only if we are currently executing */
|
||||||
if (execlevel == 0) {
|
if (execlevel == 0) {
|
||||||
|
|
||||||
/* grab label to jump to */
|
/* grab label to jump to */
|
||||||
eline =
|
eline = token( eline, golabel, sizeof golabel) ;
|
||||||
token( eline, golabel, sizeof golabel) ;
|
|
||||||
linlen = strlen(golabel);
|
linlen = strlen(golabel);
|
||||||
glp = hlp->l_fp;
|
glp = hlp->l_fp;
|
||||||
while (glp != hlp) {
|
while (glp != hlp) {
|
||||||
@ -900,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 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
5
exec.h
5
exec.h
@ -15,13 +15,12 @@ int execproc( int f, int n) ;
|
|||||||
extern boolean clexec ; /* command line execution flag */
|
extern boolean clexec ; /* command line execution flag */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ue_system( const char *cmd) ;
|
void ue_system( const char *cmd) ;
|
||||||
int namedcmd( int f, int n) ;
|
int namedcmd( int f, int n) ;
|
||||||
int execcmd( int f, int n) ;
|
int execcmd( int f, int n) ;
|
||||||
void gettoken( char *tok, int maxtoksize) ;
|
void gettoken( char *tok, int maxtoksize) ;
|
||||||
int macarg( char *tok, int toksz) ;
|
boolean gettokval( char *tok, int maxtoksize) ;
|
||||||
int nextarg( const char *prompt, char *buffer, int size, int terminator) ;
|
char *getnewtokval( void) ;
|
||||||
int storemac( int f, int n) ;
|
int storemac( int f, int n) ;
|
||||||
int execbuf( int f, int n) ;
|
int execbuf( int f, int n) ;
|
||||||
int execfile( int f, int n) ;
|
int execfile( int f, int n) ;
|
||||||
|
163
file.c
163
file.c
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -73,16 +74,20 @@ boolean resterr( void) {
|
|||||||
* "read a file into the current buffer" code.
|
* "read a file into the current buffer" code.
|
||||||
* Bound to "C-X C-R".
|
* Bound to "C-X C-R".
|
||||||
*/
|
*/
|
||||||
int fileread(int f, int n)
|
int fileread( int f, int n) {
|
||||||
{
|
int status ;
|
||||||
int s;
|
char *fname ;
|
||||||
fname_t fname ;
|
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
|
|
||||||
return s;
|
status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
|
||||||
return readin(fname, TRUE);
|
if( status == TRUE) {
|
||||||
|
status = readin( fname, TRUE) ;
|
||||||
|
free( fname) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -92,19 +97,25 @@ int fileread(int f, int n)
|
|||||||
* "insert a file into the current buffer" code.
|
* "insert a file into the current buffer" code.
|
||||||
* Bound to "C-X C-I".
|
* Bound to "C-X C-I".
|
||||||
*/
|
*/
|
||||||
int insfile(int f, int n)
|
int insfile( int f, int n) {
|
||||||
{
|
int status ;
|
||||||
int s;
|
char *fname ;
|
||||||
fname_t fname ;
|
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
|
|
||||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly() ; /* we are in read only mode */
|
return rdonly() ; /* we are in read only mode */
|
||||||
if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
|
|
||||||
return s;
|
status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
|
||||||
if ((s = ifile(fname)) != TRUE)
|
if( status == TRUE) {
|
||||||
return s;
|
status = ifile( fname) ;
|
||||||
|
free( fname) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( status != TRUE)
|
||||||
|
return status ;
|
||||||
|
|
||||||
return reposition( TRUE, -1) ;
|
return reposition( TRUE, -1) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,30 +128,38 @@ int insfile(int f, int n)
|
|||||||
* text, and switch to the new buffer.
|
* text, and switch to the new buffer.
|
||||||
* Bound to C-X C-F.
|
* Bound to C-X C-F.
|
||||||
*/
|
*/
|
||||||
int filefind(int f, int n)
|
int filefind( int f, int n) {
|
||||||
{
|
char *fname ; /* file user wishes to find */
|
||||||
fname_t fname ; /* file user wishes to find */
|
int status ; /* status return */
|
||||||
int s; /* status return */
|
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
|
|
||||||
return s;
|
status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
|
||||||
return getfile(fname, TRUE);
|
if( status == TRUE) {
|
||||||
|
status = getfile( fname, TRUE) ;
|
||||||
|
free( fname) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int viewfile(int f, int n)
|
return status ;
|
||||||
{ /* visit a file in VIEW mode */
|
}
|
||||||
fname_t fname ; /* file user wishes to find */
|
|
||||||
int s; /* status return */
|
int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||||
struct window *wp; /* scan for windows that need updating */
|
char *fname ; /* file user wishes to find */
|
||||||
|
int status ; /* status return */
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
|
|
||||||
return s;
|
status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
|
||||||
s = getfile(fname, FALSE);
|
if( status == TRUE) {
|
||||||
if (s) { /* if we succeed, put it in view mode */
|
status = getfile(fname, FALSE) ;
|
||||||
|
free( fname) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( status == TRUE) { /* if we succeed, put it in view mode */
|
||||||
|
struct window *wp ; /* scan for windows that need updating */
|
||||||
|
|
||||||
curwp->w_bufp->b_mode |= MDVIEW ;
|
curwp->w_bufp->b_mode |= MDVIEW ;
|
||||||
|
|
||||||
/* scan through and update mode lines of all windows */
|
/* scan through and update mode lines of all windows */
|
||||||
@ -150,7 +169,8 @@ int viewfile(int f, int n)
|
|||||||
wp = wp->w_wndp ;
|
wp = wp->w_wndp ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CRYPT
|
#if CRYPT
|
||||||
@ -165,24 +185,25 @@ void cryptbufferkey( struct buffer *bp) {
|
|||||||
* int f; default flag
|
* int f; default flag
|
||||||
* int n; numeric argument
|
* int n; numeric argument
|
||||||
*/
|
*/
|
||||||
int set_encryption_key(int f, int n)
|
int set_encryption_key( int f, int n) {
|
||||||
{
|
|
||||||
int status ; /* return status */
|
int status ; /* return status */
|
||||||
int odisinp; /* original vlaue of disinp */
|
int odisinp ; /* original value of disinp */
|
||||||
ekey_t key ; /* new encryption string */
|
char *key ; /* new encryption string */
|
||||||
|
|
||||||
/* turn command input echo off */
|
/* turn command input echo off */
|
||||||
odisinp = disinp ;
|
odisinp = disinp ;
|
||||||
disinp = FALSE ;
|
disinp = FALSE ;
|
||||||
|
|
||||||
/* get the string to use as an encrytion string */
|
/* get the string to use as an encrytion string */
|
||||||
status = mlreply("Encryption String: ", key, sizeof key - 1);
|
status = newmlarg( &key, "Encryption String: ", sizeof( ekey_t)) ;
|
||||||
disinp = odisinp ;
|
disinp = odisinp ;
|
||||||
if( status != TRUE)
|
if( status != TRUE)
|
||||||
return status ;
|
return status ;
|
||||||
|
|
||||||
/* save it off and encrypt it*/
|
/* save it off and encrypt it*/
|
||||||
strcpy(curbp->b_key, key);
|
strncpy( curbp->b_key, key, sizeof( ekey_t) - 1) ;
|
||||||
|
curbp->b_key[ sizeof( ekey_t) - 1] = '\0' ;
|
||||||
|
free( key) ;
|
||||||
cryptbufferkey( curbp) ;
|
cryptbufferkey( curbp) ;
|
||||||
|
|
||||||
mloutstr( "") ; /* clear the message line */
|
mloutstr( "") ; /* clear the message line */
|
||||||
@ -253,15 +274,22 @@ int getfile( const char *fname, boolean lockfl)
|
|||||||
}
|
}
|
||||||
makename(bname, fname); /* New buffer name. */
|
makename(bname, fname); /* New buffer name. */
|
||||||
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
|
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
|
||||||
|
char *new_bname ;
|
||||||
|
|
||||||
/* old buffer name conflict code */
|
/* old buffer name conflict code */
|
||||||
s = mlreply("Buffer name: ", bname, sizeof bname);
|
s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
|
||||||
if( s == ABORT) /* ^G to just quit */
|
if( s == ABORT) /* ^G to just quit */
|
||||||
return s ;
|
return s ;
|
||||||
if (s == FALSE) { /* CR to clobber it */
|
else if (s == FALSE) { /* CR to clobber it */
|
||||||
makename( bname, fname) ;
|
makename( bname, fname) ;
|
||||||
break ;
|
break ;
|
||||||
|
} else { /* TRUE */
|
||||||
|
strncpy( bname, new_bname, sizeof bname - 1) ;
|
||||||
|
bname[ sizeof bname - 1] = '\0' ;
|
||||||
|
free( new_bname) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
|
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
|
||||||
mloutstr( "Cannot create buffer") ;
|
mloutstr( "Cannot create buffer") ;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -495,27 +523,35 @@ void unqname(char *name)
|
|||||||
* is more compatable with Gosling EMACS than
|
* is more compatable with Gosling EMACS than
|
||||||
* with ITS EMACS. Bound to "C-X C-W".
|
* with ITS EMACS. Bound to "C-X C-W".
|
||||||
*/
|
*/
|
||||||
int filewrite(int f, int n)
|
int filewrite( int f, int n) {
|
||||||
{
|
int status ;
|
||||||
struct window *wp;
|
char *fname ;
|
||||||
int s;
|
|
||||||
fname_t fname ;
|
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
|
|
||||||
return s;
|
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
|
||||||
if ((s = writeout(fname)) == TRUE) {
|
if( status == TRUE) {
|
||||||
strcpy(curbp->b_fname, fname);
|
status = writeout( fname) ;
|
||||||
|
if( status == TRUE) {
|
||||||
|
struct window *wp ;
|
||||||
|
|
||||||
|
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||||
|
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||||
curbp->b_flag &= ~BFCHG ;
|
curbp->b_flag &= ~BFCHG ;
|
||||||
wp = wheadp ; /* Update mode lines. */
|
wp = wheadp ; /* Update mode lines. */
|
||||||
while( wp != NULL) {
|
while( wp != NULL) {
|
||||||
if( wp->w_bufp == curbp)
|
if( wp->w_bufp == curbp)
|
||||||
wp->w_flag |= WFMODE ;
|
wp->w_flag |= WFMODE ;
|
||||||
|
|
||||||
wp = wp->w_wndp ;
|
wp = wp->w_wndp ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
|
free( fname) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -622,26 +658,33 @@ int writeout( const char *fn)
|
|||||||
* as needing an update. You can type a blank line at the
|
* as needing an update. You can type a blank line at the
|
||||||
* prompt if you wish.
|
* prompt if you wish.
|
||||||
*/
|
*/
|
||||||
int filename(int f, int n)
|
int filename( int f, int n) {
|
||||||
{
|
|
||||||
struct window *wp ;
|
struct window *wp ;
|
||||||
int s;
|
int status ;
|
||||||
fname_t fname ;
|
char *fname ;
|
||||||
|
|
||||||
if( restflag) /* don't allow this command if restricted */
|
if( restflag) /* don't allow this command if restricted */
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
|
|
||||||
return s;
|
status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
|
||||||
if (s == FALSE)
|
if( status == ABORT)
|
||||||
strcpy(curbp->b_fname, "");
|
return status ;
|
||||||
else
|
else if( status == FALSE)
|
||||||
strcpy(curbp->b_fname, fname);
|
curbp->b_fname[ 0] = '\0' ;
|
||||||
|
else { /* TRUE */
|
||||||
|
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||||
|
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||||
|
free( fname) ;
|
||||||
|
}
|
||||||
|
|
||||||
wp = wheadp ; /* Update mode lines. */
|
wp = wheadp ; /* Update mode lines. */
|
||||||
while( wp != NULL) {
|
while( wp != NULL) {
|
||||||
if( wp->w_bufp == curbp)
|
if( wp->w_bufp == curbp)
|
||||||
wp->w_flag |= WFMODE ;
|
wp->w_flag |= WFMODE ;
|
||||||
|
|
||||||
wp = wp->w_wndp ;
|
wp = wp->w_wndp ;
|
||||||
}
|
}
|
||||||
|
|
||||||
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
|
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
69
input.c
69
input.c
@ -52,7 +52,9 @@ int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
|
|||||||
int reptc = CONTROL | 'U' ; /* current universal repeat char */
|
int reptc = CONTROL | 'U' ; /* current universal repeat char */
|
||||||
int abortc = CONTROL | 'G' ; /* current abort command char */
|
int abortc = CONTROL | 'G' ; /* current abort command char */
|
||||||
|
|
||||||
static const int quotec = 0x11 ; /* quote char during mlreply() */
|
const int nlc = CONTROL | 'J' ; /* end of input char */
|
||||||
|
|
||||||
|
static const int quotec = 0x11 ; /* quote char during getstring() */
|
||||||
|
|
||||||
static void outstring( char *s) ;
|
static void outstring( char *s) ;
|
||||||
|
|
||||||
@ -83,6 +85,47 @@ int mlyesno( const char *prompt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* newnextarg:
|
||||||
|
* get the next argument
|
||||||
|
*
|
||||||
|
* char **outbufref ; buffer to put token into
|
||||||
|
* const char *prompt ; prompt to use if we must be interactive
|
||||||
|
* int size ; size of the buffer
|
||||||
|
* int terminator ; terminating char to be used on interactive fetch
|
||||||
|
*/
|
||||||
|
static int newnextarg( char **outbufref, const char *prompt, int size,
|
||||||
|
int terminator) {
|
||||||
|
int status ;
|
||||||
|
char *buf ;
|
||||||
|
|
||||||
|
/* 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 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
*outbufref = buf ;
|
||||||
|
return status ;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a prompt into the message line, then read back a response. Keep
|
* Write a prompt into the message line, then read back a response. Keep
|
||||||
* track of the physical position of the cursor. If we are in a keyboard
|
* track of the physical position of the cursor. If we are in a keyboard
|
||||||
@ -91,14 +134,12 @@ int mlyesno( const char *prompt)
|
|||||||
* return. Handle erase, kill, and abort keys.
|
* return. Handle erase, kill, and abort keys.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int mlreply( const char *prompt, char *buf, int nbuf)
|
int newmlarg( char **outbufref, const char *prompt, int size) {
|
||||||
{
|
return newnextarg( outbufref, prompt, size, nlc) ;
|
||||||
return nextarg(prompt, buf, nbuf, ctoec('\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlreplyt(const char *prompt, char *buf, int nbuf, int eolchar)
|
int newmlargt( char **outbufref, const char *prompt, int size) {
|
||||||
{
|
return newnextarg( outbufref, prompt, size, metac) ;
|
||||||
return nextarg(prompt, buf, nbuf, eolchar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -115,18 +156,6 @@ int ectoc(int c)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* ctoec:
|
|
||||||
* character to extended character
|
|
||||||
* pull out the CONTROL and SPEC prefixes (if possible)
|
|
||||||
*/
|
|
||||||
int ctoec(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0x00 && c <= 0x1F)
|
|
||||||
c = CONTROL | (c + '@');
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get a command name from the command line. Command completion means
|
* get a command name from the command line. Command completion means
|
||||||
* that pressing a <SPACE> will attempt to complete an unfinished command
|
* that pressing a <SPACE> will attempt to complete an unfinished command
|
||||||
@ -147,7 +176,7 @@ fn_t getname(void)
|
|||||||
|
|
||||||
/* if we are executing a command line get the next arg and match it */
|
/* if we are executing a command line get the next arg and match it */
|
||||||
if (clexec) {
|
if (clexec) {
|
||||||
if( macarg( buf, sizeof buf) != TRUE)
|
if( TRUE != gettokval( buf, sizeof buf))
|
||||||
return NULL;
|
return NULL;
|
||||||
return fncmatch(&buf[0]);
|
return fncmatch(&buf[0]);
|
||||||
}
|
}
|
||||||
|
7
input.h
7
input.h
@ -14,17 +14,18 @@ extern int kbdm[] ; /* Holds kayboard macro data */
|
|||||||
extern int *kbdptr ; /* current position in keyboard buf */
|
extern int *kbdptr ; /* current position in keyboard buf */
|
||||||
extern int *kbdend ; /* ptr to end of the keyboard */
|
extern int *kbdend ; /* ptr to end of the keyboard */
|
||||||
extern int disinp ; /* display input characters */
|
extern int disinp ; /* display input characters */
|
||||||
|
|
||||||
extern int metac; /* current meta character */
|
extern int metac; /* current meta character */
|
||||||
extern int ctlxc; /* current control X prefix char */
|
extern int ctlxc; /* current control X prefix char */
|
||||||
extern int reptc; /* current universal repeat char */
|
extern int reptc; /* current universal repeat char */
|
||||||
extern int abortc; /* current abort command char */
|
extern int abortc; /* current abort command char */
|
||||||
|
extern const int nlc ; /* end of input char */
|
||||||
|
|
||||||
|
|
||||||
int mlyesno( const char *prompt) ;
|
int mlyesno( const char *prompt) ;
|
||||||
int mlreply( const char *prompt, char *buf, int nbuf) ;
|
int newmlarg( char **outbufref, const char *prompt, int size) ;
|
||||||
int mlreplyt( const char *prompt, char *buf, int nbuf, int eolchar) ;
|
int newmlargt( char **outbufref, const char *prompt, int size) ;
|
||||||
int ectoc( int c) ;
|
int ectoc( int c) ;
|
||||||
int ctoec( int c) ;
|
|
||||||
fn_t getname( void) ;
|
fn_t getname( void) ;
|
||||||
int tgetc( void) ;
|
int tgetc( void) ;
|
||||||
int get1key( void) ;
|
int get1key( void) ;
|
||||||
|
16
line.c
16
line.c
@ -619,14 +619,24 @@ char *getctext(void)
|
|||||||
int size; /* length of line to return */
|
int size; /* length of line to return */
|
||||||
char *sp; /* string pointer into line */
|
char *sp; /* string pointer into line */
|
||||||
char *dp; /* string pointer into returned line */
|
char *dp; /* string pointer into returned line */
|
||||||
static char rline[NSTRING]; /* line to return */
|
static int rsize = 0 ;
|
||||||
|
static char *rline ; /* line to return */
|
||||||
|
|
||||||
/* find the contents of the current line and its length */
|
/* find the contents of the current line and its length */
|
||||||
lp = curwp->w_dotp;
|
lp = curwp->w_dotp;
|
||||||
sp = lp->l_text;
|
sp = lp->l_text;
|
||||||
size = lp->l_used;
|
size = lp->l_used;
|
||||||
if (size >= NSTRING)
|
if( size >= rsize) {
|
||||||
size = NSTRING - 1;
|
if( rsize)
|
||||||
|
free( rline) ;
|
||||||
|
|
||||||
|
rsize = size + 1 ;
|
||||||
|
rline = malloc( rsize) ;
|
||||||
|
if( rline == NULL) {
|
||||||
|
rsize = 0 ;
|
||||||
|
return "" ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* copy it across */
|
/* copy it across */
|
||||||
dp = rline;
|
dp = rline;
|
||||||
|
17
main.c
17
main.c
@ -124,7 +124,7 @@ static void usage( void) {
|
|||||||
" +<n> start at line <n>\n"
|
" +<n> start at line <n>\n"
|
||||||
" --help display this help and exit\n"
|
" --help display this help and exit\n"
|
||||||
" --version output version information and exit\n"
|
" --version output version information and exit\n"
|
||||||
" @cmdfile execute command file\n"
|
" @cmdfile execute startup file\n"
|
||||||
" -a|A process error file\n"
|
" -a|A process error file\n"
|
||||||
" -e|E edit file\n"
|
" -e|E edit file\n"
|
||||||
" -g|G<n> go to line <n>\n"
|
" -g|G<n> go to line <n>\n"
|
||||||
@ -134,6 +134,8 @@ static void usage( void) {
|
|||||||
" -r|R restrictive use\n"
|
" -r|R restrictive use\n"
|
||||||
" -s|S<string> search string\n"
|
" -s|S<string> search string\n"
|
||||||
" -v|V view file\n"
|
" -v|V view file\n"
|
||||||
|
" -x|Xcmdfile\n"
|
||||||
|
" -x|X cmdfile execute command file\n"
|
||||||
, stdout) ;
|
, stdout) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +255,19 @@ int main(int argc, char **argv)
|
|||||||
case 'v': /* -v for View File */
|
case 'v': /* -v for View File */
|
||||||
case 'V':
|
case 'V':
|
||||||
viewflag = TRUE;
|
viewflag = TRUE;
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
case 'X':
|
||||||
|
if( argv[ carg][ 2]) { /* -Xfilename */
|
||||||
|
if( startup( &argv[ carg][ 2]) == TRUE)
|
||||||
|
startflag = TRUE ; /* don't execute emacs.rc */
|
||||||
|
} else if( argv[ carg + 1]) { /* -X filename */
|
||||||
|
if( startup( &argv[ carg + 1][ 0]) == TRUE)
|
||||||
|
startflag = TRUE ; /* don't execute emacs.rc */
|
||||||
|
|
||||||
|
carg += 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
default: /* unknown switch */
|
default: /* unknown switch */
|
||||||
/* ignore this for now */
|
/* ignore this for now */
|
||||||
|
76
random.c
76
random.c
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "basic.h"
|
#include "basic.h"
|
||||||
@ -943,7 +944,7 @@ static int adjustmode( int kind, int global) {
|
|||||||
unsigned i ; /* loop index */
|
unsigned i ; /* loop index */
|
||||||
int status; /* error return on input */
|
int status; /* error return on input */
|
||||||
char prompt[50]; /* string to prompt user with */
|
char prompt[50]; /* string to prompt user with */
|
||||||
char cbuf[ NSTRING] ; /* buffer to recieve mode name into */
|
char *cbuf ; /* buffer to recieve mode name into */
|
||||||
|
|
||||||
/* build the proper prompt string */
|
/* build the proper prompt string */
|
||||||
if (global)
|
if (global)
|
||||||
@ -958,7 +959,7 @@ static int adjustmode( int kind, int global) {
|
|||||||
|
|
||||||
/* prompt the user and get an answer */
|
/* prompt the user and get an answer */
|
||||||
|
|
||||||
status = mlreply( prompt, cbuf, sizeof cbuf - 1) ;
|
status = newmlarg( &cbuf, prompt, 0) ;
|
||||||
if (status != TRUE)
|
if (status != TRUE)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@ -986,6 +987,7 @@ static int adjustmode( int kind, int global) {
|
|||||||
curwp->w_flag |= WFCOLR;
|
curwp->w_flag |= WFCOLR;
|
||||||
#endif
|
#endif
|
||||||
mlerase();
|
mlerase();
|
||||||
|
free( cbuf) ;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1008,11 +1010,13 @@ static int adjustmode( int kind, int global) {
|
|||||||
if (global == 0)
|
if (global == 0)
|
||||||
upmode();
|
upmode();
|
||||||
mlerase(); /* erase the junk */
|
mlerase(); /* erase the junk */
|
||||||
|
free( cbuf) ;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mlwrite("No such mode!");
|
mlwrite("No such mode!");
|
||||||
|
free( cbuf) ;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1183,32 +1187,36 @@ int fmatch(int ch)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
|
||||||
|
int status ; /* status return code */
|
||||||
|
char *tstring ; /* string to add */
|
||||||
|
|
||||||
|
/* ask for string to insert */
|
||||||
|
status = newmlargt( &tstring, prompt, 0) ; /* grab as big a token as screen allow */
|
||||||
|
if( tstring == NULL)
|
||||||
|
return status ;
|
||||||
|
|
||||||
|
if( f == FALSE)
|
||||||
|
n = 1 ;
|
||||||
|
else if( n < 0)
|
||||||
|
n = -n ;
|
||||||
|
|
||||||
|
/* insert it */
|
||||||
|
while( n-- && status == TRUE)
|
||||||
|
status = fun( tstring) ;
|
||||||
|
|
||||||
|
free( tstring) ;
|
||||||
|
return status ;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ask for and insert a string into the current
|
* ask for and insert a string into the current
|
||||||
* buffer at the current point
|
* buffer at the current point
|
||||||
*
|
*
|
||||||
* int f, n; ignored arguments
|
* int f, n; ignored arguments
|
||||||
*/
|
*/
|
||||||
int istring(int f, int n)
|
int istring( int f, int n) {
|
||||||
{
|
return iovstring( f, n, "String to insert<META>: ", linstr) ;
|
||||||
int status; /* status return code */
|
|
||||||
char tstring[ 512] ; /* string to add */
|
|
||||||
|
|
||||||
/* ask for string to insert */
|
|
||||||
status =
|
|
||||||
mlreplyt("String to insert<META>: ", tstring, sizeof tstring - 1, metac) ;
|
|
||||||
if (status != TRUE)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
if (f == FALSE)
|
|
||||||
n = 1;
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
|
|
||||||
/* insert it */
|
|
||||||
while (n-- && (status = linstr(tstring)));
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1217,24 +1225,8 @@ int istring(int f, int n)
|
|||||||
*
|
*
|
||||||
* int f, n; ignored arguments
|
* int f, n; ignored arguments
|
||||||
*/
|
*/
|
||||||
int ovstring(int f, int n)
|
int ovstring( int f, int n) {
|
||||||
{
|
return iovstring( f, n, "String to overwrite<META>: ", lover) ;
|
||||||
int status; /* status return code */
|
|
||||||
char tstring[ NSTRING + 1] ; /* string to add */
|
|
||||||
|
|
||||||
/* ask for string to insert */
|
|
||||||
status =
|
|
||||||
mlreplyt( "String to overwrite<META>: ", tstring, NSTRING, metac) ;
|
|
||||||
if (status != TRUE)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
if (f == FALSE)
|
|
||||||
n = 1;
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
n = -n;
|
|
||||||
|
|
||||||
/* insert it */
|
|
||||||
while (n-- && (status = lover(tstring)));
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* end of random.c */
|
||||||
|
8
search.c
8
search.c
@ -705,6 +705,7 @@ static int readpattern(char *prompt, char *apat, int srch)
|
|||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
char tpat[NPAT + 20];
|
char tpat[NPAT + 20];
|
||||||
|
char *dynpat ; /* dynamically allocated pattern buffer */
|
||||||
|
|
||||||
setprompt( tpat, NPAT / 2, prompt, apat) ;
|
setprompt( tpat, NPAT / 2, prompt, apat) ;
|
||||||
|
|
||||||
@ -713,8 +714,11 @@ static int readpattern(char *prompt, char *apat, int srch)
|
|||||||
* Then, if it's the search string, make a reversed pattern.
|
* Then, if it's the search string, make a reversed pattern.
|
||||||
* *Then*, make the meta-pattern, if we are defined that way.
|
* *Then*, make the meta-pattern, if we are defined that way.
|
||||||
*/
|
*/
|
||||||
if ((status = mlreplyt(tpat, tpat, NPAT, metac)) == TRUE) {
|
status = newmlargt( &dynpat, tpat, NPAT) ;
|
||||||
strcpy(apat, tpat);
|
if( status == TRUE) {
|
||||||
|
strncpy( apat, dynpat, NPAT - 1) ;
|
||||||
|
apat[ NPAT - 1] = 0 ;
|
||||||
|
free( dynpat) ;
|
||||||
if (srch) { /* If we are doing the search string. */
|
if (srch) { /* If we are doing the search string. */
|
||||||
/* Reverse string copy, and remember
|
/* Reverse string copy, and remember
|
||||||
* the length for substitution purposes.
|
* the length for substitution purposes.
|
||||||
|
174
spawn.c
174
spawn.c
@ -145,51 +145,24 @@ void rtfrmshell(void)
|
|||||||
* character to be typed, then mark the screen as garbage so a full repaint is
|
* character to be typed, then mark the screen as garbage so a full repaint is
|
||||||
* done. Bound to "C-X !".
|
* done. Bound to "C-X !".
|
||||||
*/
|
*/
|
||||||
int spawn(int f, int n)
|
int spawn( int f, int n) {
|
||||||
{
|
|
||||||
int s ;
|
int s ;
|
||||||
char line[NLINE];
|
char *line ;
|
||||||
|
|
||||||
/* don't allow this command if restricted */
|
/* don't allow this command if restricted */
|
||||||
if( restflag)
|
if( restflag)
|
||||||
return resterr();
|
return resterr();
|
||||||
|
|
||||||
#if VMS
|
|
||||||
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
||||||
return s;
|
|
||||||
movecursor(term.t_nrow, 0);
|
|
||||||
TTflush();
|
|
||||||
s = sys(line); /* Run the command. */
|
|
||||||
if (clexec == FALSE) {
|
|
||||||
mlwrite("\r\n\n(End)"); /* Pause. */
|
|
||||||
TTflush();
|
|
||||||
tgetc();
|
|
||||||
}
|
|
||||||
sgarbf = TRUE;
|
|
||||||
return s;
|
|
||||||
#endif
|
|
||||||
#if MSDOS
|
|
||||||
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
||||||
return s;
|
|
||||||
movecursor(term.t_nrow, 0);
|
|
||||||
TTkclose();
|
|
||||||
shellprog(line);
|
|
||||||
TTkopen();
|
|
||||||
/* if we are interactive, pause here */
|
|
||||||
if (clexec == FALSE) {
|
|
||||||
mlwrite("\r\n(End)");
|
|
||||||
tgetc();
|
|
||||||
}
|
|
||||||
sgarbf = TRUE;
|
|
||||||
return TRUE;
|
|
||||||
#endif
|
|
||||||
#if V7 | USG | BSD
|
#if V7 | USG | BSD
|
||||||
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
s = newmlarg( &line, "!", 0) ;
|
||||||
|
if( s != TRUE)
|
||||||
return s ;
|
return s ;
|
||||||
|
|
||||||
TTflush();
|
TTflush();
|
||||||
TTclose(); /* stty to old modes */
|
TTclose(); /* stty to old modes */
|
||||||
TTkclose();
|
TTkclose();
|
||||||
ue_system( line) ;
|
ue_system( line) ;
|
||||||
|
free( line) ;
|
||||||
fflush(stdout); /* to be sure P.K. */
|
fflush(stdout); /* to be sure P.K. */
|
||||||
TTopen();
|
TTopen();
|
||||||
|
|
||||||
@ -211,51 +184,25 @@ int spawn(int f, int n)
|
|||||||
* done. Bound to "C-X $".
|
* done. Bound to "C-X $".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int execprg(int f, int n)
|
int execprg( int f, int n) {
|
||||||
{
|
|
||||||
int s ;
|
int s ;
|
||||||
char line[NLINE];
|
char *line ;
|
||||||
|
|
||||||
/* don't allow this command if restricted */
|
/* don't allow this command if restricted */
|
||||||
if( restflag)
|
if( restflag)
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
|
|
||||||
#if VMS
|
|
||||||
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
||||||
return s;
|
|
||||||
TTflush();
|
|
||||||
s = sys(line); /* Run the command. */
|
|
||||||
mlwrite("\r\n\n(End)"); /* Pause. */
|
|
||||||
TTflush();
|
|
||||||
tgetc();
|
|
||||||
sgarbf = TRUE;
|
|
||||||
return s;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MSDOS
|
|
||||||
if ((s = mlreply("$", line, NLINE)) != TRUE)
|
|
||||||
return s;
|
|
||||||
movecursor(term.t_nrow, 0);
|
|
||||||
TTkclose();
|
|
||||||
execprog(line);
|
|
||||||
TTkopen();
|
|
||||||
/* if we are interactive, pause here */
|
|
||||||
if (clexec == FALSE) {
|
|
||||||
mlwrite("\r\n(End)");
|
|
||||||
tgetc();
|
|
||||||
}
|
|
||||||
sgarbf = TRUE;
|
|
||||||
return TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if V7 | USG | BSD
|
#if V7 | USG | BSD
|
||||||
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
s = newmlarg( &line, "$", 0) ;
|
||||||
|
if( s != TRUE)
|
||||||
return s ;
|
return s ;
|
||||||
|
|
||||||
TTputc('\n'); /* Already have '\r' */
|
TTputc('\n'); /* Already have '\r' */
|
||||||
TTflush();
|
TTflush();
|
||||||
TTclose(); /* stty to old modes */
|
TTclose(); /* stty to old modes */
|
||||||
TTkclose();
|
TTkclose();
|
||||||
ue_system( line) ;
|
ue_system( line) ;
|
||||||
|
free( line) ;
|
||||||
fflush(stdout); /* to be sure P.K. */
|
fflush(stdout); /* to be sure P.K. */
|
||||||
TTopen();
|
TTopen();
|
||||||
mlwrite( "(End)") ; /* Pause. */
|
mlwrite( "(End)") ; /* Pause. */
|
||||||
@ -270,49 +217,33 @@ int execprg(int f, int n)
|
|||||||
* Pipe a one line command into a window
|
* Pipe a one line command into a window
|
||||||
* Bound to ^X @
|
* Bound to ^X @
|
||||||
*/
|
*/
|
||||||
int pipecmd(int f, int n)
|
int pipecmd( int f, int n) {
|
||||||
{
|
|
||||||
int s ; /* return status from CLI */
|
int s ; /* return status from CLI */
|
||||||
struct window *wp ; /* pointer to new window */
|
struct window *wp ; /* pointer to new window */
|
||||||
struct buffer *bp ; /* pointer to buffer to zot */
|
struct buffer *bp ; /* pointer to buffer to zot */
|
||||||
char line[NLINE]; /* command line send to shell */
|
char *mlarg ;
|
||||||
|
char *line ; /* command line send to shell */
|
||||||
static char bname[] = "command" ;
|
static char bname[] = "command" ;
|
||||||
|
|
||||||
static char filnam[ NSTRING] = "command" ;
|
static char filnam[ NSTRING] = "command" ;
|
||||||
|
|
||||||
#if MSDOS
|
|
||||||
char *tmp;
|
|
||||||
FILE *fp;
|
|
||||||
int len;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* don't allow this command if restricted */
|
/* don't allow this command if restricted */
|
||||||
if( restflag)
|
if( restflag)
|
||||||
return resterr() ;
|
return resterr() ;
|
||||||
|
|
||||||
#if MSDOS
|
|
||||||
if ((tmp = getenv("TMP")) == NULL
|
|
||||||
&& (tmp = getenv("TEMP")) == NULL)
|
|
||||||
strcpy(filnam, "command");
|
|
||||||
else {
|
|
||||||
strcpy(filnam, tmp);
|
|
||||||
len = strlen(tmp);
|
|
||||||
if (len <= 0 || filnam[len - 1] != '\\'
|
|
||||||
&& filnam[len - 1] != '/')
|
|
||||||
strcat(filnam, "\\");
|
|
||||||
strcat(filnam, "command");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if VMS
|
|
||||||
mlwrite("Not available under VMS");
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get the command to pipe in */
|
/* get the command to pipe in */
|
||||||
if ((s = mlreply("@", line, NLINE)) != TRUE)
|
s = newmlarg( &mlarg, "@", 0) ;
|
||||||
|
if( s != TRUE)
|
||||||
return s ;
|
return s ;
|
||||||
|
|
||||||
|
line = malloc( strlen( mlarg) + strlen( filnam) + 2) ;
|
||||||
|
if( line == NULL) {
|
||||||
|
free( mlarg) ;
|
||||||
|
return FALSE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy( line, mlarg) ;
|
||||||
|
free( mlarg) ;
|
||||||
|
|
||||||
/* get rid of the command output buffer if it exists */
|
/* get rid of the command output buffer if it exists */
|
||||||
if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
|
if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
|
||||||
/* try to make sure we are off screen */
|
/* try to make sure we are off screen */
|
||||||
@ -332,26 +263,12 @@ int pipecmd(int f, int n)
|
|||||||
}
|
}
|
||||||
wp = wp->w_wndp;
|
wp = wp->w_wndp;
|
||||||
}
|
}
|
||||||
if (zotbuf(bp) != TRUE)
|
|
||||||
|
|
||||||
|
if( zotbuf( bp) != TRUE) {
|
||||||
|
free( line) ;
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
}
|
}
|
||||||
#if MSDOS
|
|
||||||
strcat(line, " >>");
|
|
||||||
strcat(line, filnam);
|
|
||||||
movecursor(term.t_nrow, 0);
|
|
||||||
TTkclose();
|
|
||||||
shellprog(line);
|
|
||||||
TTkopen();
|
|
||||||
sgarbf = TRUE;
|
|
||||||
if ((fp = fopen(filnam, "r")) == NULL) {
|
|
||||||
s = FALSE;
|
|
||||||
} else {
|
|
||||||
fclose(fp);
|
|
||||||
s = TRUE;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if V7 | USG | BSD
|
#if V7 | USG | BSD
|
||||||
TTflush();
|
TTflush();
|
||||||
TTclose(); /* stty to old modes */
|
TTclose(); /* stty to old modes */
|
||||||
@ -359,6 +276,7 @@ int pipecmd(int f, int n)
|
|||||||
strcat( line, ">") ;
|
strcat( line, ">") ;
|
||||||
strcat( line, filnam) ;
|
strcat( line, filnam) ;
|
||||||
ue_system( line) ;
|
ue_system( line) ;
|
||||||
|
free( line) ;
|
||||||
TTopen();
|
TTopen();
|
||||||
TTkopen();
|
TTkopen();
|
||||||
TTflush();
|
TTflush();
|
||||||
@ -394,11 +312,11 @@ int pipecmd(int f, int n)
|
|||||||
* filter a buffer through an external DOS program
|
* filter a buffer through an external DOS program
|
||||||
* Bound to ^X #
|
* Bound to ^X #
|
||||||
*/
|
*/
|
||||||
int filter_buffer(int f, int n)
|
int filter_buffer( int f, int n) {
|
||||||
{
|
|
||||||
int s ; /* return status from CLI */
|
int s ; /* return status from CLI */
|
||||||
struct buffer *bp ; /* pointer to buffer to zot */
|
struct buffer *bp ; /* pointer to buffer to zot */
|
||||||
char line[NLINE]; /* command line send to shell */
|
char *mlarg ;
|
||||||
|
char *line ; /* command line send to shell */
|
||||||
fname_t tmpnam ; /* place to store real file name */
|
fname_t tmpnam ; /* place to store real file name */
|
||||||
static char bname1[] = "fltinp" ;
|
static char bname1[] = "fltinp" ;
|
||||||
|
|
||||||
@ -412,15 +330,20 @@ int filter_buffer(int f, int n)
|
|||||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||||
return rdonly() ; /* we are in read only mode */
|
return rdonly() ; /* we are in read only mode */
|
||||||
|
|
||||||
#if VMS
|
|
||||||
mlwrite("Not available under VMS");
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get the filter name and its args */
|
/* get the filter name and its args */
|
||||||
if ((s = mlreply("#", line, NLINE)) != TRUE)
|
s = newmlarg( &mlarg, "#", 0) ;
|
||||||
|
if( s != TRUE)
|
||||||
return s ;
|
return s ;
|
||||||
|
|
||||||
|
line = malloc( strlen( mlarg) + 16 + 1) ;
|
||||||
|
if( line == NULL) {
|
||||||
|
free( mlarg) ;
|
||||||
|
return FALSE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy( line, mlarg) ;
|
||||||
|
free( mlarg) ;
|
||||||
|
|
||||||
/* setup the proper file names */
|
/* setup the proper file names */
|
||||||
bp = curbp;
|
bp = curbp;
|
||||||
strcpy(tmpnam, bp->b_fname); /* save the original name */
|
strcpy(tmpnam, bp->b_fname); /* save the original name */
|
||||||
@ -430,17 +353,9 @@ int filter_buffer(int f, int n)
|
|||||||
if( writeout( filnam1) != TRUE) {
|
if( writeout( filnam1) != TRUE) {
|
||||||
mlwrite( "(Cannot write filter file)") ;
|
mlwrite( "(Cannot write filter file)") ;
|
||||||
strcpy( bp->b_fname, tmpnam) ;
|
strcpy( bp->b_fname, tmpnam) ;
|
||||||
|
free( line) ;
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
}
|
}
|
||||||
#if MSDOS
|
|
||||||
strcat(line, " <fltinp >fltout");
|
|
||||||
movecursor(term.t_nrow - 1, 0);
|
|
||||||
TTkclose();
|
|
||||||
shellprog(line);
|
|
||||||
TTkopen();
|
|
||||||
sgarbf = TRUE;
|
|
||||||
s = TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if V7 | USG | BSD
|
#if V7 | USG | BSD
|
||||||
TTputc('\n'); /* Already have '\r' */
|
TTputc('\n'); /* Already have '\r' */
|
||||||
@ -449,6 +364,7 @@ int filter_buffer(int f, int n)
|
|||||||
TTkclose();
|
TTkclose();
|
||||||
strcat(line, " <fltinp >fltout");
|
strcat(line, " <fltinp >fltout");
|
||||||
ue_system( line) ;
|
ue_system( line) ;
|
||||||
|
free( line) ;
|
||||||
TTopen();
|
TTopen();
|
||||||
TTkopen();
|
TTkopen();
|
||||||
TTflush();
|
TTflush();
|
||||||
|
@ -10,6 +10,7 @@ insert-string %mypath
|
|||||||
newline
|
newline
|
||||||
insert-string &cat "Length of $PATH: " &len $PATH
|
insert-string &cat "Length of $PATH: " &len $PATH
|
||||||
newline
|
newline
|
||||||
|
insert-string &cat "Length of %mypath: " &cat &len %mypath ~n
|
||||||
; Insert string with escaped characters
|
; Insert string with escaped characters
|
||||||
insert-string "hello, world~n"
|
insert-string "hello, world~n"
|
||||||
newline
|
newline
|
||||||
@ -35,6 +36,9 @@ set %expect &len %nam
|
|||||||
newline
|
newline
|
||||||
set %nam &cat %nam %nam
|
set %nam &cat %nam %nam
|
||||||
set %expect &tim %expect 2
|
set %expect &tim %expect 2
|
||||||
|
!if ¬ &les %expect 1024
|
||||||
|
!break
|
||||||
|
!endif
|
||||||
!endwhile
|
!endwhile
|
||||||
insert-string %nam
|
insert-string %nam
|
||||||
newline
|
newline
|
||||||
|
@ -12,6 +12,6 @@
|
|||||||
# define PROGRAM_NAME_PFX "\xC2"
|
# define PROGRAM_NAME_PFX "\xC2"
|
||||||
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
|
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
|
||||||
|
|
||||||
# define VERSION "4.2.0"
|
# define VERSION "4.2.1"
|
||||||
|
|
||||||
#endif /* VERSION_H_ */
|
#endif /* VERSION_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user