1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 07:16:23 -05:00

Merge branch 'execute'

This commit is contained in:
Renaud 2015-10-05 14:22:39 +08:00
commit fa96d9e63e
18 changed files with 732 additions and 632 deletions

View File

@ -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
endif
ifeq ($(uname_S),CYGWIN)
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
DEFINES=-DAUTOCONF -DCYGWIN -DPOSIX -DSYSV -DPROGRAM=$(PROGRAM)
LIBS=-lcurses
endif
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 \
isearch.h region.h random.h search.h spawn.h window.h defines.h word.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 \
utf8.h display.h estruct.h execute.h input.h bind.h search.h terminal.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
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.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
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

13
basic.c
View File

@ -90,21 +90,22 @@ int gotoeol(int f, int n)
*
* @n: The specified line position at the current buffer.
*/
int gotoline(int f, int n)
{
int status ;
char arg[ NSTRING] ; /* Buffer to hold argument. */
int gotoline( int f, int n) {
/* Get an argument if one doesnt exist. */
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) {
mloutstr( "(Aborted)") ;
return status ;
}
n = atoi( arg) ;
free( arg) ;
}
/* Handle the case where the user may be passed something like this:
* em filename +
* In this case we just go to the end of the buffer.

38
bind.c
View File

@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "estruct.h"
@ -273,23 +274,24 @@ static int unbindchar( unsigned c) {
* bring up a fake buffer and list the key bindings
* into it with view mode
*/
int desbind(int f, int n)
int desbind( int f, int n) {
#if APROP
{
buildlist( "") ;
return TRUE;
return buildlist( "") ;
}
int apro(int f, int n)
{ /* Apropos (List functions that match a substring) */
char mstring[NSTRING]; /* string to match cmd names to */
int status; /* status return */
/* Apropos (List functions that match a substring) */
int apro( int f, int n) {
char *mstring ; /* string to match cmd names to */
int status ; /* status return */
status = mlreply("Apropos string: ", mstring, NSTRING - 1);
if (status == ABORT)
return status;
status = newmlarg( &mstring, "Apropos string: ", 0) ;
if( status == TRUE) {
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
*/
static int buildlist( char *mstring)
static int buildlist( char *mstring) {
#endif
{
struct window *wp; /* scanning pointer to windows */
struct key_tab *ktp; /* pointer into the command 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 */
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 */
else
else {
c = stock( tok) ;
free( tok) ;
}
} else { /* or the normal way */
if( mflag)
c = get1key() ;

102
buffer.c
View File

@ -55,17 +55,24 @@ static void l_to_a( char *buf, int width, long num) ;
* if the use count is 0. Otherwise, they come
* from some other window.
*/
int usebuffer(int f, int n)
{
struct buffer *bp;
int s;
bname_t bufn ;
int usebuffer( int f, int n) {
struct buffer *bp ;
int status ;
char *bufn ;
if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE)
return s;
if ((bp = bfind(bufn, TRUE, 0)) == NULL)
return FALSE;
return swbuffer(bp);
/* Get buffer name */
status = newmlarg( &bufn, "Use buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* Find buffer in list */
bp = bfind( bufn, TRUE, 0) ;
free( bufn) ;
if( bp == NULL)
return FALSE ;
/* Switch to buffer */
return swbuffer( bp) ;
}
/*
@ -164,19 +171,26 @@ int swbuffer(struct buffer *bp)
* if the buffer has been changed). Then free the header
* line and the buffer header. Bound to "C-X K".
*/
int killbuffer(int f, int n)
{
struct buffer *bp;
int s;
bname_t bufn ;
int killbuffer( int f, int n) {
struct buffer *bp ;
int status ;
char *bufn ;
if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE)
return s;
if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
return TRUE;
if (bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE; /* by doing nothing. */
return zotbuf(bp);
/* Get buffer name */
status = newmlarg( &bufn, "Kill buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* Find buffer in list */
bp = bfind( bufn, FALSE, 0) ;
free( bufn) ;
if( bp == NULL) /* Easy if unknown. */
return TRUE ;
if( bp->b_flag & BFINVS) /* Deal with special buffers */
return TRUE ; /* by doing nothing. */
return zotbuf( bp) ;
}
/*
@ -215,31 +229,37 @@ int zotbuf(struct buffer *bp)
*
* int f, n; default Flag & Numeric arg
*/
int namebuffer(int f, int n)
{
struct buffer *bp; /* pointer to scan through all buffers */
bname_t bufn ; /* buffer to hold buffer name */
int namebuffer( int f, int n) {
struct buffer *bp ; /* pointer to scan through all buffers */
int status ;
char *bufn ; /* buffer to hold buffer name */
/* prompt for and get the new buffer name */
ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) !=
TRUE)
return FALSE;
/* prompt for and get the new buffer name */
ask:
status = newmlarg( &bufn, "Change buffer name to: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* and check for duplicates */
bp = bheadp;
while (bp != NULL) {
if (bp != curbp) {
/* if the names the same */
if (strcmp(bufn, bp->b_bname) == 0)
goto ask; /* try again */
/* and check for duplicates */
bp = bheadp ;
while( bp != NULL) {
if( bp != curbp) {
/* retry if the names are the same */
if( strcmp( bufn, bp->b_bname) == 0) {
free( bufn) ;
goto ask ; /* try again */
}
bp = bp->b_bufp; /* onward */
}
strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */
curwp->w_flag |= WFMODE; /* make mode line replot */
bp = bp->b_bufp ; /* onward */
}
strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
free( bufn) ;
curwp->w_flag |= WFMODE ; /* make mode line replot */
mloutstr( "") ; /* erase message line */
return TRUE;
return TRUE ;
}
/*

View File

@ -301,8 +301,8 @@ struct key_tab keytab[NBINDS] = {
{META | 'R', sreplace}
,
#if PKCODE
{META | 'S', forwsearch}
, /* alternative P.K. */
{META | 'S', forwhunt}
,
#else
#if BSD
{META | 'S', bktoshell}

161
eval.c
View File

@ -312,9 +312,9 @@ void varinit(void)
*/
static char *gtfun( char *fname) {
unsigned fnum ; /* index to function to eval */
char argx[ 512] ; /* last argument, fixed sized allocation */
char *arg1 ; /* value of first argument */
char *arg2 ; /* value of second argument */
char *arg3 ; /* last argument */
char *retstr ; /* return value */
int low, high ; /* binary search indexes */
@ -342,27 +342,26 @@ static char *gtfun( char *fname) {
if (fnum == ARRAY_SIZE(funcs))
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 (funcs[fnum].f_type >= MONAMIC) {
if( macarg( argx, sizeof argx) != TRUE)
arg1 = getnewtokval() ;
if( arg1 == NULL)
return errorm;
/* if needed, retrieve the second argument */
if (funcs[fnum].f_type >= DYNAMIC) {
arg1 = malloc( strlen( argx) + 1) ;
strcpy( arg1, argx) ;
if( macarg( argx, sizeof argx) != TRUE) {
arg2 = getnewtokval() ;
if( arg2 == NULL) {
free( arg1) ;
return errorm;
}
/* if needed, retrieve the third argument */
if (funcs[fnum].f_type >= TRINAMIC) {
arg2 = malloc( strlen( argx) + 1) ;
strcpy( arg2, argx) ;
if( macarg( argx, sizeof argx) != TRUE) {
arg3 = getnewtokval() ;
if( arg3 == NULL) {
free( arg1) ;
free( arg2) ;
return errorm;
@ -376,30 +375,30 @@ static char *gtfun( char *fname) {
int sz ;
case UFADD | DYNAMIC:
retstr = i_to_a( atoi( arg1) + atoi( argx)) ;
retstr = i_to_a( atoi( arg1) + atoi( arg2)) ;
break ;
case UFSUB | DYNAMIC:
retstr = i_to_a( atoi( arg1) - atoi( argx)) ;
retstr = i_to_a( atoi( arg1) - atoi( arg2)) ;
break ;
case UFTIMES | DYNAMIC:
retstr = i_to_a( atoi( arg1) * atoi( argx)) ;
retstr = i_to_a( atoi( arg1) * atoi( arg2)) ;
break ;
case UFDIV | DYNAMIC:
sz = atoi( argx) ;
sz = atoi( arg2) ;
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
break ;
case UFMOD | DYNAMIC:
sz = atoi( argx) ;
sz = atoi( arg2) ;
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
break ;
case UFNEG | MONAMIC:
retstr = i_to_a( -atoi( argx)) ;
retstr = i_to_a( -atoi( arg1)) ;
break ;
case UFCAT | DYNAMIC: {
int sz1 ;
sz1 = strlen( arg1) ;
sz = sz1 + strlen( argx) + 1 ;
sz = sz1 + strlen( arg2) + 1 ;
if( sz > ressize) {
free( result) ;
result = malloc( sz) ;
@ -407,12 +406,12 @@ static char *gtfun( char *fname) {
}
strcpy( result, arg1) ;
strcpy( &result[ sz1], argx) ;
strcpy( &result[ sz1], arg2) ;
retstr = result ;
}
break ;
case UFLEFT | DYNAMIC:
sz = atoi( argx) ;
sz = atoi( arg2) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
@ -424,7 +423,7 @@ static char *gtfun( char *fname) {
retstr = result ;
break ;
case UFRIGHT | DYNAMIC:
sz = atoi( argx) ;
sz = atoi( arg2) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
@ -434,7 +433,7 @@ static char *gtfun( char *fname) {
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
break ;
case UFMID | TRINAMIC:
sz = atoi( argx) ;
sz = atoi( arg3) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
@ -446,28 +445,28 @@ static char *gtfun( char *fname) {
retstr = result ;
break ;
case UFNOT | MONAMIC:
retstr = ltos( stol( argx) == FALSE) ;
retstr = ltos( stol( arg1) == FALSE) ;
break ;
case UFEQUAL | DYNAMIC:
retstr = ltos( atoi( arg1) == atoi( argx)) ;
retstr = ltos( atoi( arg1) == atoi( arg2)) ;
break ;
case UFLESS | DYNAMIC:
retstr = ltos( atoi( arg1) < atoi( argx)) ;
retstr = ltos( atoi( arg1) < atoi( arg2)) ;
break ;
case UFGREATER | DYNAMIC:
retstr = ltos( atoi( arg1) > atoi( argx)) ;
retstr = ltos( atoi( arg1) > atoi( arg2)) ;
break ;
case UFSEQUAL | DYNAMIC:
retstr = ltos( strcmp( arg1, argx) == 0) ;
retstr = ltos( strcmp( arg1, arg2) == 0) ;
break ;
case UFSLESS | DYNAMIC:
retstr = ltos( strcmp( arg1, argx) < 0) ;
retstr = ltos( strcmp( arg1, arg2) < 0) ;
break ;
case UFSGREAT | DYNAMIC:
retstr = ltos( strcmp( arg1, argx) > 0) ;
retstr = ltos( strcmp( arg1, arg2) > 0) ;
break ;
case UFIND | MONAMIC:
retstr = getval( argx) ;
retstr = getval( arg1) ;
sz = strlen( retstr) + 1 ;
if( sz > ressize) {
free( result) ;
@ -478,42 +477,42 @@ static char *gtfun( char *fname) {
retstr = strcpy( result, retstr) ;
break ;
case UFAND | DYNAMIC:
retstr = ltos( stol( arg1) && stol( argx)) ;
retstr = ltos( stol( arg1) && stol( arg2)) ;
break ;
case UFOR | DYNAMIC:
retstr = ltos( stol( arg1) || stol( argx)) ;
retstr = ltos( stol( arg1) || stol( arg2)) ;
break ;
case UFLENGTH | MONAMIC:
retstr = i_to_a( strlen( argx)) ;
retstr = i_to_a( strlen( arg1)) ;
break ;
case UFUPPER | MONAMIC:
sz = strlen( argx) ;
sz = strlen( arg1) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
retstr = mkupper( result, argx) ;
retstr = mkupper( result, arg1) ;
break ;
case UFLOWER | MONAMIC:
sz = strlen( argx) ;
sz = strlen( arg1) ;
if( sz >= ressize) {
free( result) ;
result = malloc( 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) ;
break ;
case UFTRUTH | MONAMIC:
retstr = ltos( atoi( argx) == 42) ;
retstr = ltos( atoi( arg1) == 42) ;
break ;
case UFASCII | MONAMIC: {
unicode_t c ;
utf8_to_unicode( argx, 0, 4, &c) ;
utf8_to_unicode( arg1, 0, 4, &c) ;
retstr = i_to_a( c) ;
}
@ -521,7 +520,7 @@ static char *gtfun( char *fname) {
case UFCHR | MONAMIC: {
unicode_t c ;
c = atoi( argx) ;
c = atoi( arg1) ;
if( c > 0x10FFFF)
retstr = errorm ;
else {
@ -538,7 +537,7 @@ static char *gtfun( char *fname) {
retstr = result ;
break ;
case UFRND | MONAMIC:
sz = abs( atoi( argx)) ;
sz = abs( atoi( arg1)) ;
if( sz == 0)
sz = ernd() ;
else
@ -547,14 +546,14 @@ static char *gtfun( char *fname) {
retstr = i_to_a( sz) ;
break ;
case UFABS | MONAMIC:
retstr = i_to_a( abs( atoi( argx))) ;
retstr = i_to_a( abs( atoi( arg1))) ;
break ;
case UFSINDEX | DYNAMIC:
retstr = i_to_a( sindex( arg1, argx)) ;
retstr = i_to_a( sindex( arg1, arg2)) ;
break ;
case UFENV | MONAMIC:
#if ENVFUNC
retstr = getenv( argx) ;
retstr = getenv( arg1) ;
if( retstr == NULL)
retstr = "" ;
#else
@ -562,36 +561,39 @@ static char *gtfun( char *fname) {
#endif
break ;
case UFBIND | MONAMIC:
retstr = transbind( argx) ;
retstr = transbind( arg1) ;
break ;
case UFEXIST | MONAMIC:
retstr = ltos( fexist( argx)) ;
retstr = ltos( fexist( arg1)) ;
break ;
case UFFIND | MONAMIC:
retstr = flook( argx, TRUE) ;
retstr = flook( arg1, TRUE) ;
if( retstr == NULL)
retstr = "" ;
break ;
case UFBAND | DYNAMIC:
retstr = i_to_a( atoi( arg1) & atoi( argx)) ;
retstr = i_to_a( atoi( arg1) & atoi( arg2)) ;
break ;
case UFBOR | DYNAMIC:
retstr = i_to_a( atoi( arg1) | atoi( argx)) ;
retstr = i_to_a( atoi( arg1) | atoi( arg2)) ;
break ;
case UFBXOR | DYNAMIC:
retstr = i_to_a( atoi( arg1) ^ atoi( argx)) ;
retstr = i_to_a( atoi( arg1) ^ atoi( arg2)) ;
break ;
case UFBNOT | DYNAMIC:
retstr = i_to_a( ~atoi( argx)) ;
case UFBNOT | MONAMIC:
retstr = i_to_a( ~atoi( arg1)) ;
break ;
case UFXLATE | TRINAMIC:
retstr = xlat( arg1, arg2, argx) ;
retstr = xlat( arg1, arg2, arg3) ;
break ;
default:
assert( FALSE) ; /* never should get here */
retstr = errorm ;
}
if( arg3)
free( arg3) ;
if( arg2)
free( arg2) ;
@ -767,11 +769,11 @@ int setvar(int f, int n)
int status; /* status return */
struct variable_description vd; /* variable num/type */
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.. */
if (clexec == FALSE) {
status = mlreply( "Variable to set: ", var, sizeof var) ;
status = getstring( "Variable to set: ", var, sizeof var, nlc) ;
if (status != TRUE)
return status;
} else { /* macro line argument */
@ -790,11 +792,15 @@ int setvar(int f, int n)
/* get the value for that variable */
if( f == TRUE) {
value = malloc( NSTRING) ;
if( value == NULL)
return FALSE ;
/* a bit overcautious here in using strncpy */
strncpy( value, i_to_a( n), sizeof value - 1) ;
value[ sizeof value - 1] = '\0' ;
strncpy( value, i_to_a( n), NSTRING - 1) ;
value[ NSTRING - 1] = '\0' ;
} else {
status = mlreply( "Value: ", value, sizeof value);
status = newmlarg( &value, "Value: ", 0) ;
if (status != TRUE)
return status;
}
@ -812,6 +818,7 @@ int setvar(int f, int n)
#endif
/* and return it */
free( value) ;
return status;
}
@ -889,10 +896,8 @@ fvar:
var[4] = 0;
if (strcmp(&var[1], "ind") == 0) {
/* grab token, and eval it */
gettoken( var, size) ;
strncpy( var, getval( var), size - 1) ;
var[ size - 1] = '\0' ;
goto fvar;
if( TRUE == gettokval( var, size))
goto fvar ;
}
}
@ -1117,15 +1122,9 @@ static int gettyp( char *token) {
/* grab the first char (this is all we need) */
c = *token;
/* no blanks!!! */
if (c == 0)
return TKNUL;
/* a numeric literal? */
if( (c >= '0' && c <= '9') || c == '-')
return TKLIT;
switch (c) {
case 0: /* no blanks!!! */
return TKNUL ;
case '"':
return TKSTR;
@ -1133,7 +1132,7 @@ static int gettyp( char *token) {
return TKDIR;
case '@':
return TKARG;
case '#':
case '=':
return TKBUF;
case '$':
return TKENV;
@ -1145,6 +1144,10 @@ static int gettyp( char *token) {
return TKLBL;
default:
/* a numeric literal? */
if( (c >= '0' && c <= '9') || c == '-')
return TKLIT;
else
return TKCMD;
}
}
@ -1174,7 +1177,7 @@ char *getval(char *token)
strcpy(token, getval(&token[1]));
distmp = discmd; /* echo it always! */
discmd = TRUE;
status = getstring(token, buf, NSTRING, ctoec('\n'));
status = getstring( token, buf, NSTRING, nlc) ;
discmd = distmp;
if (status == ABORT)
return errorm;
@ -1431,16 +1434,18 @@ int clrmes( int f, int n) {
* int f, n; arguments ignored
*/
int writemsg( int f, int n) {
int status;
char buf[ NSTRING] ; /* buffer to recieve message into */
status = mlreply( "Message to write: ", buf, sizeof buf - 1) ;
if( status != TRUE)
return status ;
int status ;
char *buf ; /* buffer to receive message into */
status = newmlarg( &buf, "Message to write: ", 0) ;
if( status == TRUE) {
/* write the message out */
mlforce( buf) ;
return TRUE ;
free( buf) ;
}
return status ;
}
/* end of eval.c */

319
exec.c
View File

@ -79,6 +79,7 @@ static int mstore = FALSE ; /* storing text to macro flag */
static int dobuf( struct buffer *bp) ;
static void freewhile( struct while_block *wp) ;
static int macarg( char *tok, int toksz) ;
void ue_system( const char *cmd) {
int ret ;
@ -119,19 +120,20 @@ static int docmd( char *cline) ;
*
* int f, n; default Flag and Numeric argument
*/
int execcmd(int f, int n)
{
int status; /* status return */
char cmdstr[NSTRING]; /* string holding command to execute */
int execcmd( int f, int n) {
int status ; /* status return */
char *cmdstr ; /* string holding command to execute */
/* get the line wanted */
if ((status = mlreply(": ", cmdstr, NSTRING)) != TRUE)
return status;
status = newmlarg( &cmdstr, ": ", 0) ;
if( status != TRUE)
return status ;
execlevel = 0;
execlevel = 0 ;
while( status == TRUE && n-- > 0)
status = docmd( cmdstr) ;
free( cmdstr) ;
return status ;
}
@ -179,8 +181,10 @@ static int docmd( char *cline) {
/* process leadin argument */
if( !is_it_cmd( tkn)) {
f = TRUE;
/* macarg already includes a getval, skip for now
strncpy( tkn, getval( tkn), sizeof tkn - 1) ;
tkn[ sizeof tkn - 1] = '\0' ;
*/
n = atoi(tkn);
/* 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
* return a pointer past the token
*
* char *src, *tok; source string, destination token string
* int size; maximum size of token
* char *src in, source string
* char **tokref out, destination of newly allocated token string
*/
static char *token( char *src, char *tok, int size) {
int quotef; /* is the current string quoted? */
char c; /* temporary character */
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 ;
/* first scan past any whitespace in the source string */
while (*src == ' ' || *src == '\t')
@ -227,6 +236,8 @@ static char *token( char *src, char *tok, int size) {
/* scan through the source string */
quotef = FALSE;
while (*src) {
char c ; /* temporary character */
/* process special characters */
if (*src == '~') {
++src;
@ -251,9 +262,6 @@ static char *token( char *src, char *tok, int size) {
default:
c = *(src - 1);
}
if (--size > 0) {
*tok++ = c;
}
} else {
/* check for the end of the token */
if (quotef) {
@ -270,68 +278,112 @@ static char *token( char *src, char *tok, int size) {
/* record the character */
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 */
if (*src)
++src;
*tok = 0;
if( tok != NULL)
tok[ idx] = 0 ;
*tokref = tok ;
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) {
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
*
* char *tok; buffer to place argument
*/
int macarg( char *tok, int toksz)
{
static int macarg( char *tok, int toksz) {
int status ;
boolean savcle ; /* buffer to store original clexec */
int status;
savcle = clexec; /* save execution mode */
clexec = TRUE; /* get the argument */
status = nextarg("", tok, toksz, ctoec('\n'));
clexec = savcle; /* restore execution mode */
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;
savcle = clexec ; /* save execution mode */
clexec = TRUE ; /* get the argument */
status = gettokval( tok, toksz) ;
clexec = savcle ; /* restore execution mode */
return status ;
}
/*
@ -388,38 +440,42 @@ int storemac(int f, int n)
* int f; default flag
* int n; macro number to use
*/
int storeproc(int f, int n)
{
struct buffer *bp; /* pointer to macro buffer */
int status; /* return status */
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 ;
/* a numeric argument means its a numbered macro */
if (f == TRUE)
return storemac(f, n);
if( f == TRUE)
return storemac( f, n) ;
/* get the name of the procedure */
if ((status =
mlreply("Procedure name: ", &bname[1], sizeof bname - 2)) != TRUE)
return status;
status = newmlarg( &name, "Procedure name: ", sizeof bname - 2) ;
if( status != TRUE)
return status ;
/* construct the macro buffer name */
bname[0] = '*';
strcat(bname, "*");
bname[ 0] = '*';
strncpy( &bname[ 1], name, sizeof bname - 3) ;
bname[ sizeof bname - 2] = '\0' ;
strcat( bname, "*") ;
free( name) ;
/* set up the new macro buffer */
if ((bp = bfind(bname, TRUE, BFINVS)) == NULL) {
mlwrite("Can not create macro");
return FALSE;
bp = bfind( bname, TRUE, BFINVS) ;
if( bp == NULL) {
mlwrite( "Can not create macro") ;
return FALSE ;
}
/* and make sure it is empty */
bclear(bp);
bclear( bp) ;
/* and set the macro store pointers to it */
mstore = TRUE;
bstore = bp;
return TRUE;
mstore = TRUE ;
bstore = bp ;
return TRUE ;
}
/*
@ -428,32 +484,36 @@ int storeproc(int f, int n)
*
* int f, n; default flag and numeric arg
*/
int execproc(int f, int n)
{
struct buffer *bp; /* ptr to buffer to execute */
int status; /* status return */
char bufn[NBUFN + 2]; /* name of buffer to execute */
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 ;
/* find out what buffer the user wants to execute */
if ((status =
mlreply("Execute procedure: ", &bufn[1], NBUFN)) != TRUE)
return status;
status = newmlarg( &name, "Execute procedure: ", sizeof bufn - 2) ;
if( status != TRUE)
return status ;
/* construct the buffer name */
bufn[0] = '*';
strcat(bufn, "*");
bufn[ 0] = '*' ;
strncpy( &bufn[ 1], name, sizeof bufn - 3) ;
bufn[ sizeof bufn - 2] = '\0' ;
strcat( bufn, "*") ;
free( name) ;
/* find the pointer to that buffer */
if ((bp = bfind(bufn, FALSE, 0)) == NULL) {
mlwrite("No such procedure");
return FALSE;
bp = bfind( bufn, FALSE, 0) ;
if( bp == NULL) {
mlwrite( "No such procedure") ;
return FALSE ;
}
/* and now execute it as asked */
while (n-- > 0)
if ((status = dobuf(bp)) != TRUE)
return status;
return TRUE;
while( status == TRUE && n-- > 0)
status = dobuf( bp) ;
return status ;
}
#endif
@ -463,27 +523,29 @@ int execproc(int f, int n)
*
* int f, n; default flag and numeric arg
*/
int execbuf(int f, int n)
{
struct buffer *bp; /* ptr to buffer to execute */
int status; /* status return */
bname_t bufn ; /* name of buffer to execute */
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 */
/* find out what buffer the user wants to execute */
if ((status = mlreply("Execute buffer: ", bufn, sizeof bufn)) != TRUE)
return status;
status = newmlarg( &bufn, "Execute buffer: ", sizeof( bname_t)) ;
if( status != TRUE)
return status ;
/* find the pointer to that buffer */
if ((bp = bfind(bufn, FALSE, 0)) == NULL) {
mlwrite("No such buffer");
return FALSE;
bp = bfind( bufn, FALSE, 0) ;
free( bufn) ;
if( bp == NULL) {
mlwrite( "No such buffer") ;
return FALSE ;
}
/* and now execute it as asked */
while (n-- > 0)
if ((status = dobuf(bp)) != TRUE)
return status;
return TRUE;
while( status == TRUE && n-- > 0)
status = dobuf( bp) ;
return status ;
}
/*
@ -635,7 +697,7 @@ static int dobuf(struct buffer *bp)
++eline;
/* dump comments and blank lines */
if (*eline == ';' || *eline == 0)
if (*eline == ';' || *eline == '#' || *eline == 0)
goto onward;
#if DEBUGM
@ -782,10 +844,8 @@ static int dobuf(struct buffer *bp)
case DGOTO: /* GOTO directive */
/* .....only if we are currently executing */
if (execlevel == 0) {
/* grab label to jump to */
eline =
token( eline, golabel, sizeof golabel) ;
eline = token( eline, golabel, sizeof golabel) ;
linlen = strlen(golabel);
glp = hlp->l_fp;
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 execfile(int f, int n)
{
int status; /* return status of name query */
char fname[NSTRING]; /* name of file to execute */
char *fspec; /* full file spec */
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 */
if ((status =
mlreply("File to execute: ", fname, NSTRING - 1)) != TRUE)
return status;
status = newmlarg( &fname, "File to execute: ", 0) ;
if( status != TRUE)
return status ;
#if 1
/* look up the path for the file */
fspec = flook(fname, FALSE); /* used to by TRUE, P.K. */
/* look up the path for the file */
fspec = flook( fname, FALSE) ; /* used to be TRUE, P.K. */
free( fname) ;
/* if it isn't around */
if (fspec == NULL)
return FALSE;
/* if it isn't around */
if( fspec == NULL)
return FALSE ;
#endif
/* otherwise, execute it */
while (n-- > 0)
if ((status = dofile(fspec)) != TRUE)
return status;
/* otherwise, execute it */
while( status == TRUE && n-- > 0)
status = dofile( fspec) ;
return TRUE;
return status ;
}
/*

5
exec.h
View File

@ -15,13 +15,12 @@ int execproc( int f, int n) ;
extern boolean clexec ; /* command line execution flag */
void ue_system( const char *cmd) ;
int namedcmd( int f, int n) ;
int execcmd( int f, int n) ;
void gettoken( char *tok, int maxtoksize) ;
int macarg( char *tok, int toksz) ;
int nextarg( const char *prompt, char *buffer, int size, int terminator) ;
boolean gettokval( char *tok, int maxtoksize) ;
char *getnewtokval( void) ;
int storemac( int f, int n) ;
int execbuf( int f, int n) ;
int execfile( int f, int n) ;

253
file.c
View File

@ -12,6 +12,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -73,16 +74,20 @@ boolean resterr( void) {
* "read a file into the current buffer" code.
* Bound to "C-X C-R".
*/
int fileread(int f, int n)
{
int s;
fname_t fname ;
int fileread( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
return s;
return readin(fname, TRUE);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Read file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = readin( fname, TRUE) ;
free( fname) ;
}
return status ;
}
/*
@ -92,20 +97,26 @@ int fileread(int f, int n)
* "insert a file into the current buffer" code.
* Bound to "C-X C-I".
*/
int insfile(int f, int n)
{
int s;
fname_t fname ;
int insfile( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = ifile(fname)) != TRUE)
return s;
return reposition(TRUE, -1);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
status = newmlarg( &fname, "Insert file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = ifile( fname) ;
free( fname) ;
}
if( status != TRUE)
return status ;
return reposition( TRUE, -1) ;
}
/*
@ -117,40 +128,49 @@ int insfile(int f, int n)
* text, and switch to the new buffer.
* Bound to C-X C-F.
*/
int filefind(int f, int n)
{
fname_t fname ; /* file user wishes to find */
int s; /* status return */
int filefind( int f, int n) {
char *fname ; /* file user wishes to find */
int status ; /* status return */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
return s;
return getfile(fname, TRUE);
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Find file: ", sizeof( fname_t)) ;
if( status == TRUE) {
status = getfile( fname, TRUE) ;
free( fname) ;
}
return status ;
}
int viewfile(int f, int n)
{ /* visit a file in VIEW mode */
fname_t fname ; /* file user wishes to find */
int s; /* status return */
struct window *wp; /* scan for windows that need updating */
int viewfile( int f, int n) { /* visit a file in VIEW mode */
char *fname ; /* file user wishes to find */
int status ; /* status return */
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
return s;
s = getfile(fname, FALSE);
if (s) { /* if we succeed, put it in view mode */
curwp->w_bufp->b_mode |= MDVIEW;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "View file: ", sizeof( fname_t)) ;
if( status == TRUE) {
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 ;
/* scan through and update mode lines of all windows */
wp = wheadp;
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
wp = wheadp ;
while( wp != NULL) {
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
}
return s;
return status ;
}
#if CRYPT
@ -165,28 +185,29 @@ void cryptbufferkey( struct buffer *bp) {
* int f; default flag
* int n; numeric argument
*/
int set_encryption_key(int f, int n)
{
int status; /* return status */
int odisinp; /* original vlaue of disinp */
ekey_t key ; /* new encryption string */
int set_encryption_key( int f, int n) {
int status ; /* return status */
int odisinp ; /* original value of disinp */
char *key ; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
odisinp = disinp ;
disinp = FALSE ;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, sizeof key - 1);
disinp = odisinp;
if (status != TRUE)
return status;
status = newmlarg( &key, "Encryption String: ", sizeof( ekey_t)) ;
disinp = odisinp ;
if( status != TRUE)
return status ;
/* 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) ;
mloutstr( "") ; /* clear the message line */
return TRUE;
return TRUE ;
}
static int resetkey(void)
@ -253,15 +274,22 @@ int getfile( const char *fname, boolean lockfl)
}
makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) {
char *new_bname ;
/* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, sizeof bname);
if (s == ABORT) /* ^G to just quit */
return s;
if (s == FALSE) { /* CR to clobber it */
makename(bname, fname);
break;
s = newmlarg( &new_bname, "Buffer name: ", sizeof( bname_t)) ;
if( s == ABORT) /* ^G to just quit */
return s ;
else if (s == FALSE) { /* CR to clobber it */
makename( bname, fname) ;
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) {
mloutstr( "Cannot create buffer") ;
return FALSE;
@ -495,27 +523,35 @@ void unqname(char *name)
* is more compatable with Gosling EMACS than
* with ITS EMACS. Bound to "C-X C-W".
*/
int filewrite(int f, int n)
{
struct window *wp;
int s;
fname_t fname ;
int filewrite( int f, int n) {
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
return s;
if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname);
curbp->b_flag &= ~BFCHG;
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
if( status == TRUE) {
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 ;
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
}
return s;
free( fname) ;
}
return status ;
}
/*
@ -622,28 +658,35 @@ int writeout( const char *fn)
* as needing an update. You can type a blank line at the
* prompt if you wish.
*/
int filename(int f, int n)
{
struct window *wp;
int s;
fname_t fname ;
int filename( int f, int n) {
struct window *wp ;
int status ;
char *fname ;
if (restflag) /* don't allow this command if restricted */
return resterr();
if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
return s;
if (s == FALSE)
strcpy(curbp->b_fname, "");
else
strcpy(curbp->b_fname, fname);
wp = wheadp; /* Update mode lines. */
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
if( restflag) /* don't allow this command if restricted */
return resterr() ;
status = newmlarg( &fname, "Name: ", sizeof( fname_t)) ;
if( status == ABORT)
return status ;
else if( status == FALSE)
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) ;
}
curbp->b_mode &= ~MDVIEW; /* no longer read only mode */
return TRUE;
wp = wheadp ; /* Update mode lines. */
while( wp != NULL) {
if( wp->w_bufp == curbp)
wp->w_flag |= WFMODE ;
wp = wp->w_wndp ;
}
curbp->b_mode &= ~MDVIEW ; /* no longer read only mode */
return TRUE ;
}
/*

69
input.c
View File

@ -52,7 +52,9 @@ int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
int reptc = CONTROL | 'U' ; /* current universal repeat 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) ;
@ -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
* 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.
*/
int mlreply( const char *prompt, char *buf, int nbuf)
{
return nextarg(prompt, buf, nbuf, ctoec('\n'));
int newmlarg( char **outbufref, const char *prompt, int size) {
return newnextarg( outbufref, prompt, size, nlc) ;
}
int mlreplyt(const char *prompt, char *buf, int nbuf, int eolchar)
{
return nextarg(prompt, buf, nbuf, eolchar);
int newmlargt( char **outbufref, const char *prompt, int size) {
return newnextarg( outbufref, prompt, size, metac) ;
}
/*
@ -115,18 +156,6 @@ int ectoc(int 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
* 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 (clexec) {
if( macarg( buf, sizeof buf) != TRUE)
if( TRUE != gettokval( buf, sizeof buf))
return NULL;
return fncmatch(&buf[0]);
}

View File

@ -14,17 +14,18 @@ extern int kbdm[] ; /* Holds kayboard macro data */
extern int *kbdptr ; /* current position in keyboard buf */
extern int *kbdend ; /* ptr to end of the keyboard */
extern int disinp ; /* display input characters */
extern int metac; /* current meta character */
extern int ctlxc; /* current control X prefix char */
extern int reptc; /* current universal repeat char */
extern int abortc; /* current abort command char */
extern const int nlc ; /* end of input char */
int mlyesno( const char *prompt) ;
int mlreply( const char *prompt, char *buf, int nbuf) ;
int mlreplyt( const char *prompt, char *buf, int nbuf, int eolchar) ;
int newmlarg( char **outbufref, const char *prompt, int size) ;
int newmlargt( char **outbufref, const char *prompt, int size) ;
int ectoc( int c) ;
int ctoec( int c) ;
fn_t getname( void) ;
int tgetc( void) ;
int get1key( void) ;

16
line.c
View File

@ -619,14 +619,24 @@ char *getctext(void)
int size; /* length of line to return */
char *sp; /* string pointer into 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 */
lp = curwp->w_dotp;
sp = lp->l_text;
size = lp->l_used;
if (size >= NSTRING)
size = NSTRING - 1;
if( size >= rsize) {
if( rsize)
free( rline) ;
rsize = size + 1 ;
rline = malloc( rsize) ;
if( rline == NULL) {
rsize = 0 ;
return "" ;
}
}
/* copy it across */
dp = rline;

17
main.c
View File

@ -124,7 +124,7 @@ static void usage( void) {
" +<n> start at line <n>\n"
" --help display this help 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"
" -e|E edit file\n"
" -g|G<n> go to line <n>\n"
@ -134,6 +134,8 @@ static void usage( void) {
" -r|R restrictive use\n"
" -s|S<string> search string\n"
" -v|V view file\n"
" -x|Xcmdfile\n"
" -x|X cmdfile execute command file\n"
, stdout) ;
}
@ -254,6 +256,19 @@ int main(int argc, char **argv)
case 'V':
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 ;
default: /* unknown switch */
/* ignore this for now */
break;

View File

@ -12,6 +12,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic.h"
@ -943,7 +944,7 @@ static int adjustmode( int kind, int global) {
unsigned i ; /* loop index */
int status; /* error return on input */
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 */
if (global)
@ -958,7 +959,7 @@ static int adjustmode( int kind, int global) {
/* prompt the user and get an answer */
status = mlreply( prompt, cbuf, sizeof cbuf - 1) ;
status = newmlarg( &cbuf, prompt, 0) ;
if (status != TRUE)
return status;
@ -986,6 +987,7 @@ static int adjustmode( int kind, int global) {
curwp->w_flag |= WFCOLR;
#endif
mlerase();
free( cbuf) ;
return TRUE;
}
}
@ -1008,11 +1010,13 @@ static int adjustmode( int kind, int global) {
if (global == 0)
upmode();
mlerase(); /* erase the junk */
free( cbuf) ;
return TRUE;
}
}
mlwrite("No such mode!");
free( cbuf) ;
return FALSE;
}
@ -1183,32 +1187,36 @@ int fmatch(int ch)
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
* buffer at the current point
*
* int f, n; ignored arguments
*/
int istring(int f, int n)
{
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;
int istring( int f, int n) {
return iovstring( f, n, "String to insert<META>: ", linstr) ;
}
/*
@ -1217,24 +1225,8 @@ int istring(int f, int n)
*
* int f, n; ignored arguments
*/
int ovstring(int f, int n)
{
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;
int ovstring( int f, int n) {
return iovstring( f, n, "String to overwrite<META>: ", lover) ;
}
/* end of random.c */

View File

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

236
spawn.c
View File

@ -145,51 +145,24 @@ void rtfrmshell(void)
* character to be typed, then mark the screen as garbage so a full repaint is
* done. Bound to "C-X !".
*/
int spawn(int f, int n)
{
int s;
char line[NLINE];
int spawn( int f, int n) {
int s ;
char *line ;
/* don't allow this command if restricted */
if (restflag)
if( restflag)
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 ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
s = newmlarg( &line, "!", 0) ;
if( s != TRUE)
return s ;
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
ue_system( line) ;
free( line) ;
fflush(stdout); /* to be sure P.K. */
TTopen();
@ -211,51 +184,25 @@ int spawn(int f, int n)
* done. Bound to "C-X $".
*/
int execprg(int f, int n)
{
int s;
char line[NLINE];
int execprg( int f, int n) {
int s ;
char *line ;
/* don't allow this command if restricted */
if (restflag)
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( restflag)
return resterr() ;
#if V7 | USG | BSD
if ((s = mlreply("!", line, NLINE)) != TRUE)
return s;
s = newmlarg( &line, "$", 0) ;
if( s != TRUE)
return s ;
TTputc('\n'); /* Already have '\r' */
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
ue_system( line) ;
free( line) ;
fflush(stdout); /* to be sure P.K. */
TTopen();
mlwrite( "(End)") ; /* Pause. */
@ -270,48 +217,32 @@ int execprg(int f, int n)
* Pipe a one line command into a window
* Bound to ^X @
*/
int pipecmd(int f, int n)
{
int s; /* return status from CLI */
struct window *wp; /* pointer to new window */
struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */
static char bname[] = "command";
static char filnam[NSTRING] = "command";
#if MSDOS
char *tmp;
FILE *fp;
int len;
#endif
int pipecmd( int f, int n) {
int s ; /* return status from CLI */
struct window *wp ; /* pointer to new window */
struct buffer *bp ; /* pointer to buffer to zot */
char *mlarg ;
char *line ; /* command line send to shell */
static char bname[] = "command" ;
static char filnam[ NSTRING] = "command" ;
/* don't allow this command if restricted */
if (restflag)
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
if( restflag)
return resterr() ;
/* get the command to pipe in */
if ((s = mlreply("@", line, NLINE)) != TRUE)
return s;
s = newmlarg( &mlarg, "@", 0) ;
if( s != TRUE)
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 */
if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
@ -332,33 +263,20 @@ int pipecmd(int f, int n)
}
wp = wp->w_wndp;
}
if (zotbuf(bp) != TRUE)
return FALSE;
if( zotbuf( bp) != TRUE) {
free( line) ;
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
TTflush();
TTclose(); /* stty to old modes */
TTkclose();
strcat(line, ">");
strcat(line, filnam);
strcat( line, ">") ;
strcat( line, filnam) ;
ue_system( line) ;
free( line) ;
TTopen();
TTkopen();
TTflush();
@ -394,32 +312,37 @@ int pipecmd(int f, int n)
* filter a buffer through an external DOS program
* Bound to ^X #
*/
int filter_buffer(int f, int n)
{
int s; /* return status from CLI */
struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */
int filter_buffer( int f, int n) {
int s ; /* return status from CLI */
struct buffer *bp ; /* pointer to buffer to zot */
char *mlarg ;
char *line ; /* command line send to shell */
fname_t tmpnam ; /* place to store real file name */
static char bname1[] = "fltinp";
static char bname1[] = "fltinp" ;
static char filnam1[] = "fltinp";
static char filnam2[] = "fltout";
static char filnam1[] = "fltinp" ;
static char filnam2[] = "fltout" ;
/* don't allow this command if restricted */
if (restflag)
return resterr();
if( restflag)
return resterr() ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
#if VMS
mlwrite("Not available under VMS");
return FALSE;
#endif
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
/* get the filter name and its args */
if ((s = mlreply("#", line, NLINE)) != TRUE)
return s;
s = newmlarg( &mlarg, "#", 0) ;
if( s != TRUE)
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 */
bp = curbp;
@ -427,20 +350,12 @@ int filter_buffer(int f, int n)
strcpy(bp->b_fname, bname1); /* set it to our new one */
/* write it out, checking for errors */
if (writeout(filnam1) != TRUE) {
if( writeout( filnam1) != TRUE) {
mlwrite( "(Cannot write filter file)") ;
strcpy(bp->b_fname, tmpnam);
return FALSE;
strcpy( bp->b_fname, tmpnam) ;
free( line) ;
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
TTputc('\n'); /* Already have '\r' */
@ -449,6 +364,7 @@ int filter_buffer(int f, int n)
TTkclose();
strcat(line, " <fltinp >fltout");
ue_system( line) ;
free( line) ;
TTopen();
TTkopen();
TTflush();

View File

@ -10,6 +10,7 @@ insert-string %mypath
newline
insert-string &cat "Length of $PATH: " &len $PATH
newline
insert-string &cat "Length of %mypath: " &cat &len %mypath ~n
; Insert string with escaped characters
insert-string "hello, world~n"
newline
@ -35,6 +36,9 @@ set %expect &len %nam
newline
set %nam &cat %nam %nam
set %expect &tim %expect 2
!if &not &les %expect 1024
!break
!endif
!endwhile
insert-string %nam
newline

View File

@ -12,6 +12,6 @@
# define PROGRAM_NAME_PFX "\xC2"
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
# define VERSION "4.2.0"
# define VERSION "4.2.1"
#endif /* VERSION_H_ */