1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-11-15 17:16:48 -05:00

Compare commits

...

3 Commits

Author SHA1 Message Date
0c584e5490 Revise window flagging on line change.
Evaluation of Value of kill buffer and current line.
2021-09-15 13:15:31 +08:00
b244adf23a Revise fence handling in CMODE. 2021-09-15 11:55:23 +08:00
860bace701 Revise pipe-command. 2021-09-15 11:51:12 +08:00
5 changed files with 284 additions and 313 deletions

32
eval.c
View File

@ -259,7 +259,7 @@ typedef struct {
static void findvar( char *var, variable_description *vd, int size) ; static void findvar( char *var, variable_description *vd, int size) ;
static int svar( variable_description *var, char *value) ; static int svar( variable_description *var, char *value) ;
static char *i_to_a( int i) ; static const char *i_to_a( int i) ;
/* /*
* putctext: * putctext:
@ -616,11 +616,37 @@ static char *gtusr( char *vname) {
} }
/* getctext: grab and return a string with the text of the current line */
static const char *getctext( void) {
static int rsize = 0 ;
static char *rline = NULL ; /* line to return */
/* find the contents of the current line and its length */
line_p lp = curwp->w_dotp ; /* line to copy */
int size = lp->l_used ; /* length of line to return */
if( size >= rsize) {
/* extend storage */
int newsize = size + 1 ;
char *newstr = realloc( rline, newsize) ;
if( newstr == NULL)
return "" ;
rline = newstr ;
rsize = newsize ;
}
/* copy it across */
memcpy( rline, lp->l_text, size) ;
rline[ size] = 0 ;
return rline ;
}
/* gtenv() /* gtenv()
* *
* char *vname; name of environment variable to retrieve * char *vname; name of environment variable to retrieve
*/ */
static char *gtenv( char *vname) { static const char *gtenv( char *vname) {
unsigned vnum ; /* ordinal number of var referenced */ unsigned vnum ; /* ordinal number of var referenced */
/* scan the list, looking for the referenced name */ /* scan the list, looking for the referenced name */
@ -1085,7 +1111,7 @@ static int svar( variable_description *var, char *value)
* *
* int i; integer to translate to a string * int i; integer to translate to a string
*/ */
static char *i_to_a( int i) { static const char *i_to_a( int i) {
unsigned u ; unsigned u ;
int sign ; /* sign of resulting number */ int sign ; /* sign of resulting number */
/* returns result string: sign digits null */ /* returns result string: sign digits null */

View File

@ -55,10 +55,7 @@ static int inspound( int n) {
static int insbrace( int n, int c) { static int insbrace( int n, int c) {
int ch ; /* last character before input */ int ch ; /* last character before input */
int oc ; /* caractere oppose a c */ int oc ; /* caractere oppose a c */
int i, count ;
int target ; /* column brace should go after */ int target ; /* column brace should go after */
struct line *oldlp ;
int oldoff ;
/* if not called with {, acts as insertion */ /* if not called with {, acts as insertion */
if( c == '}') if( c == '}')
@ -67,16 +64,17 @@ static int insbrace( int n, int c) {
return linsert( n, c) ; return linsert( n, c) ;
/* scan to see if all preceding spaces are white spaces, if not, insert */ /* scan to see if all preceding spaces are white spaces, if not, insert */
for( i = curwp->w_doto - 1 ; i >= 0 ; --i) { for( int i = curwp->w_doto - 1 ; i >= 0 ; --i) {
ch = lgetc( curwp->w_dotp, i) ; ch = lgetc( curwp->w_dotp, i) ;
if( ch != ' ' && ch != '\t') if( ch != ' ' && ch != '\t')
return linsert( n, c) ; return linsert( n, c) ;
} }
oldlp = curwp->w_dotp ; /* save the original cursor position */
oldoff = curwp->w_doto ; line_p oldlp = curwp->w_dotp ;
int oldoff = curwp->w_doto ;
count = 1 ; int count = 1 ;
do { do {
if( boundary( curwp->w_dotp, curwp->w_doto, REVERSE)) { if( boundary( curwp->w_dotp, curwp->w_doto, REVERSE)) {
/* at beginning of buffer, no match to be found */ /* at beginning of buffer, no match to be found */
@ -132,10 +130,6 @@ static int insbrace( int n, int c) {
* char ch; fence type to match against * char ch; fence type to match against
*/ */
static void fmatch( int ch) { static void fmatch( int ch) {
struct line *oldlp ; /* original line pointer */
int oldoff ; /* and offset */
struct line *toplp ; /* top line in current window */
int count ; /* current fence level count */
int opench ; /* open fence */ int opench ; /* open fence */
/* $tpause <= 0 disable fmatch */ /* $tpause <= 0 disable fmatch */
@ -146,8 +140,8 @@ static void fmatch( int ch) {
update( FALSE) ; update( FALSE) ;
/* save the original cursor position */ /* save the original cursor position */
oldlp = curwp->w_dotp ; line_p oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto ; int oldoff = curwp->w_doto ;
/* setup proper open fence for passed close fence */ /* setup proper open fence for passed close fence */
if( ch == ')') if( ch == ')')
@ -158,11 +152,11 @@ static void fmatch( int ch) {
opench = '[' ; opench = '[' ;
/* find the top line and set up for scan */ /* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp ; line_p toplp = curwp->w_linep->l_bp ;
backchar( FALSE, 1) ; /* . was after the }, move back */ backchar( FALSE, 1) ; /* . was after the }, move back */
/* scan back until we find it, or reach past the top of the window */ /* scan back until we find it, or reach past the top of the window */
count = 1 ; int count = 1 ; /* current fence level count */
do { do {
/* At beginning of window or buffer, no match to be found */ /* At beginning of window or buffer, no match to be found */
if( curwp->w_dotp == toplp if( curwp->w_dotp == toplp
@ -209,17 +203,14 @@ static void fmatch( int ch) {
* int f, n; not used * int f, n; not used
*/ */
BINDABLE( getfence) { BINDABLE( getfence) {
struct line *oldlp; /* original line pointer */
int oldoff; /* and offset */
int sdir; /* direction of search (1/-1) */ int sdir; /* direction of search (1/-1) */
int count; /* current fence level count */
char ch; /* fence type to match against */ char ch; /* fence type to match against */
char ofence; /* open fence */ char ofence; /* open fence */
char c; /* current character in scan */ char c; /* current character in scan */
/* save the original cursor position */ /* save the original cursor position */
oldlp = curwp->w_dotp; line_p oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto; int oldoff = curwp->w_doto ;
/* get the current character */ /* get the current character */
if (oldoff == llength(oldlp)) if (oldoff == llength(oldlp))
@ -259,7 +250,7 @@ BINDABLE( getfence) {
} }
/* scan until we find a match, or reach the end of file */ /* scan until we find a match, or reach the end of file */
count = 1 ; int count = 1 ; /* current fence level count */
do { do {
if( boundary( curwp->w_dotp, curwp->w_doto, sdir)) { if( boundary( curwp->w_dotp, curwp->w_doto, sdir)) {
/* at buffer limit, no match to be found */ /* at buffer limit, no match to be found */

187
line.c
View File

@ -54,27 +54,15 @@ static char *value = NULL ; /* temp buffer for value */
/* /*
* return some of the contents of the kill buffer * return some of the contents of the kill buffer
*/ */
char *getkill( void) { const char *getkill( void) {
kill_p kp ; /* no kill buffer or no memory .... just return a null string */
char *cp ; if( kbufh == NULL
|| (value = realloc( value, klen + 1)) == NULL)
if (kbufh == NULL)
/* no kill buffer....just a null string */
return "" ; return "" ;
if( value != NULL) char *cp = value ;
free( value) ; for( kill_p kp = kbufh ; kp != NULL ; kp = kp->d_next) {
int size = (kp->d_next != NULL) ? KBLOCK : kused ;
value = (char *) malloc( klen + 1) ;
cp = value ;
for( kp = kbufh ; kp != NULL ; kp = kp->d_next) {
int size ;
if( kp->d_next != NULL)
size = KBLOCK ;
else
size = kused ;
memcpy( cp, kp->d_chunk, size) ; memcpy( cp, kp->d_chunk, size) ;
cp += size ; cp += size ;
} }
@ -240,29 +228,25 @@ void lfree( line_p lp) {
free( lp) ; free( lp) ;
} }
/*
* This routine gets called when a character is changed in place in the current /* This routine gets called when a character is changed in place in the current
* buffer. It updates all of the required flags in the buffer and window * buffer. It updates all of the required flags in the buffer and window
* system. The flag used is passed as an argument; if the buffer is being * system. The flag used is passed as an argument; if the buffer is being
* displayed in more than 1 window we change EDIT t HARD. Set MODE if the * displayed in more than 1 window we change EDIT to HARD. Set MODE if the
* mode line needs to be updated (the "*" has to be set). * mode line needs to be updated (the "*" has to be set).
*/ */
void lchange(int flag) void lchange( int flag) {
{
struct window *wp;
if( curbp->b_nwnd != 1) /* Ensure hard. */ if( curbp->b_nwnd != 1) /* Ensure hard. */
flag = WFHARD ; flag = WFHARD ;
if( (curbp->b_flag & BFCHG) == 0) { /* First change, so */ if( (curbp->b_flag & BFCHG) == 0) { /* First change, so */
flag |= WFMODE ; /* update mode lines. */ flag |= WFMODE ; /* update mode lines. */
curbp->b_flag |= BFCHG ; curbp->b_flag |= BFCHG ;
} }
wp = wheadp;
while (wp != NULL) { for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
if( wp->w_bufp == curbp) if( wp->w_bufp == curbp)
wp->w_flag |= flag ; wp->w_flag |= flag ;
wp = wp->w_wndp;
}
} }
@ -309,20 +293,16 @@ boolean linstr( char *instr) {
boolean linsert_byte( int n, int c) { boolean linsert_byte( int n, int c) {
char *cp1; char *cp1;
char *cp2; char *cp2;
line_p lp1, lp2, lp3 ; line_p lp2, lp3 ;
int doto;
int i ; int i ;
struct window *wp;
assert( (curbp->b_mode & MDVIEW) == 0) ; assert( (curbp->b_mode & MDVIEW) == 0) ;
lchange( WFEDIT) ; lchange( WFEDIT) ;
lp1 = curwp->w_dotp; /* Current line */ line_p lp1 = curwp->w_dotp ; /* Current line */
if( lp1 == curbp->b_linep) { /* At the end: special */ if( lp1 == curbp->b_linep) { /* At the end: special */
if (curwp->w_doto != 0) { if( curwp->w_doto != 0)
mloutstr( "bug: linsert") ; return mloutfail( "bug: linsert") ;
return FALSE;
}
lp2 = lalloc( n) ; /* Allocate new line */ lp2 = lalloc( n) ; /* Allocate new line */
if( lp2 == NULL) if( lp2 == NULL)
@ -335,11 +315,13 @@ boolean linsert_byte( int n, int c) {
lp2->l_bp = lp3 ; lp2->l_bp = lp3 ;
for( i = 0 ; i < n ; ++i) for( i = 0 ; i < n ; ++i)
lp2->l_text[ i] = c ; lp2->l_text[ i] = c ;
curwp->w_dotp = lp2 ; curwp->w_dotp = lp2 ;
curwp->w_doto = n ; curwp->w_doto = n ;
return TRUE ; return TRUE ;
} }
doto = curwp->w_doto; /* Save for later. */
int doto = curwp->w_doto ; /* Save for later. */
if( lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */ if( lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */
lp2 = lalloc( lp1->l_used + n) ; lp2 = lalloc( lp1->l_used + n) ;
if( lp2 == NULL) if( lp2 == NULL)
@ -349,14 +331,16 @@ boolean linsert_byte( int n, int c) {
cp2 = &lp2->l_text[ 0] ; cp2 = &lp2->l_text[ 0] ;
while( cp1 != &lp1->l_text[ doto]) while( cp1 != &lp1->l_text[ doto])
*cp2++ = *cp1++ ; *cp2++ = *cp1++ ;
cp2 += n ; cp2 += n ;
while( cp1 != &lp1->l_text[ lp1->l_used]) while( cp1 != &lp1->l_text[ lp1->l_used])
*cp2++ = *cp1++ ; *cp2++ = *cp1++ ;
lp1->l_bp->l_fp = lp2 ; lp1->l_bp->l_fp = lp2 ;
lp2->l_fp = lp1->l_fp ; lp2->l_fp = lp1->l_fp ;
lp1->l_fp->l_bp = lp2 ; lp1->l_fp->l_bp = lp2 ;
lp2->l_bp = lp1->l_bp ; lp2->l_bp = lp1->l_bp ;
free((char *) lp1); free( lp1) ;
} else { /* Easy: in place */ } else { /* Easy: in place */
lp2 = lp1 ; /* Pretend new line */ lp2 = lp1 ; /* Pretend new line */
lp2->l_used += n ; lp2->l_used += n ;
@ -365,24 +349,28 @@ boolean linsert_byte( int n, int c) {
while( cp1 != &lp1->l_text[ doto]) while( cp1 != &lp1->l_text[ doto])
*--cp2 = *--cp1 ; *--cp2 = *--cp1 ;
} }
for( i = 0 ; i < n ; ++i) /* Add the characters */ for( i = 0 ; i < n ; ++i) /* Add the characters */
lp2->l_text[ doto + i] = c ; lp2->l_text[ doto + i] = c ;
wp = wheadp; /* Update windows */
while (wp != NULL) { /* Update windows */
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if( wp->w_linep == lp1) if( wp->w_linep == lp1)
wp->w_linep = lp2 ; wp->w_linep = lp2 ;
if( wp->w_dotp == lp1) { if( wp->w_dotp == lp1) {
wp->w_dotp = lp2 ; wp->w_dotp = lp2 ;
if( wp == curwp || wp->w_doto > doto) if( wp == curwp || wp->w_doto > doto)
wp->w_doto += n ; wp->w_doto += n ;
} }
if( wp->w_markp == lp1) { if( wp->w_markp == lp1) {
wp->w_markp = lp2 ; wp->w_markp = lp2 ;
if( wp->w_marko > doto) if( wp->w_marko > doto)
wp->w_marko += n ; wp->w_marko += n ;
} }
wp = wp->w_wndp;
} }
return TRUE ; return TRUE ;
} }
@ -565,23 +553,15 @@ boolean ldelchar( long n, boolean kill_f) {
* int kflag; put killed text in kill buffer flag * int kflag; put killed text in kill buffer flag
*/ */
boolean ldelete( long n, boolean kflag) { boolean ldelete( long n, boolean kflag) {
char *cp1;
char *cp2;
line_p dotp;
int doto;
int chunk;
struct window *wp;
assert( !(curbp->b_mode & MDVIEW)) ; assert( !(curbp->b_mode & MDVIEW)) ;
while( n > 0) { while( n > 0) {
dotp = curwp->w_dotp; line_p dotp = curwp->w_dotp ;
doto = curwp->w_doto;
if( dotp == curbp->b_linep) /* Hit end of buffer. */ if( dotp == curbp->b_linep) /* Hit end of buffer. */
return FALSE ; return FALSE ;
chunk = dotp->l_used - doto; /* Size of chunk. */
if (chunk > n) int doto = curwp->w_doto ;
chunk = n; int chunk = dotp->l_used - doto ; /* Size of chunk. */
if( chunk == 0) { /* End of line, merge. */ if( chunk == 0) { /* End of line, merge. */
#if SCROLLCODE #if SCROLLCODE
lchange( WFHARD | WFKILLS) ; lchange( WFHARD | WFKILLS) ;
@ -591,75 +571,54 @@ boolean ldelete( long n, boolean kflag) {
if( ldelnewline() == FALSE if( ldelnewline() == FALSE
|| (kflag != FALSE && kinsert( '\n') == FALSE)) || (kflag != FALSE && kinsert( '\n') == FALSE))
return FALSE ; return FALSE ;
--n ; --n ;
continue ; continue ;
} } else if( chunk > n)
chunk = n ;
lchange( WFEDIT) ; lchange( WFEDIT) ;
cp1 = &dotp->l_text[doto]; /* Scrunch text. */ char *cp1 = &dotp->l_text[ doto] ; /* Scrunch text. */
cp2 = cp1 + chunk; char *cp2 = cp1 + chunk ;
if( kflag != FALSE) { /* Kill? */ if( kflag != FALSE) { /* Kill? */
while( cp1 != cp2) { while( cp1 != cp2) {
if( kinsert( *cp1) == FALSE) if( kinsert( *cp1) == FALSE)
return FALSE ; return FALSE ;
++cp1 ; ++cp1 ;
} }
cp1 = &dotp->l_text[ doto] ; cp1 = &dotp->l_text[ doto] ;
} }
while( cp2 != &dotp->l_text[ dotp->l_used]) while( cp2 != &dotp->l_text[ dotp->l_used])
*cp1++ = *cp2++ ; *cp1++ = *cp2++ ;
dotp->l_used -= chunk ; dotp->l_used -= chunk ;
wp = wheadp; /* Fix windows */
while (wp != NULL) { /* Fix windows */
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if( wp->w_dotp == dotp && wp->w_doto >= doto) { if( wp->w_dotp == dotp && wp->w_doto >= doto) {
wp->w_doto -= chunk ; wp->w_doto -= chunk ;
if( wp->w_doto < doto) if( wp->w_doto < doto)
wp->w_doto = doto ; wp->w_doto = doto ;
} }
if( wp->w_markp == dotp && wp->w_marko >= doto) { if( wp->w_markp == dotp && wp->w_marko >= doto) {
wp->w_marko -= chunk ; wp->w_marko -= chunk ;
if( wp->w_marko < doto) if( wp->w_marko < doto)
wp->w_marko = doto ; wp->w_marko = doto ;
} }
wp = wp->w_wndp;
} }
n -= chunk ; n -= chunk ;
} }
return TRUE ; return TRUE ;
} }
/*
* getctext: grab and return a string with the text of
* the current line
*/
char *getctext( void) {
line_p lp ; /* line to copy */
int size; /* length of line to return */
static int rsize = 0 ;
static char *rline ; /* line to return */
/* find the contents of the current line and its length */ /* Delete a newline. Join the current line with the next line. If the next line
lp = curwp->w_dotp;
size = lp->l_used;
if( size >= rsize) {
if( rsize)
free( rline) ;
rsize = size + 1 ;
rline = malloc( rsize) ;
if( rline == NULL) {
rsize = 0 ;
return "" ;
}
}
/* copy it across */
memcpy( rline, lp->l_text, size) ;
rline[ size] = 0 ;
return rline ;
}
/*
* Delete a newline. Join the current line with the next line. If the next line
* is the magic header line always return TRUE; merging the last line with the * is the magic header line always return TRUE; merging the last line with the
* header line can be thought of as always being a successful operation, even * header line can be thought of as always being a successful operation, even
* if nothing is done, and this makes the kill buffer work "right". Easy cases * if nothing is done, and this makes the kill buffer work "right". Easy cases
@ -670,79 +629,85 @@ char *getctext( void) {
static int ldelnewline( void) { static int ldelnewline( void) {
char *cp1; char *cp1;
char *cp2; char *cp2;
line_p lp1, lp2, lp3 ; window_p wp ;
struct window *wp;
assert( (curbp->b_mode & MDVIEW) == 0) ; assert( (curbp->b_mode & MDVIEW) == 0) ;
lp1 = curwp->w_dotp; line_p lp1 = curwp->w_dotp ;
lp2 = lp1->l_fp; line_p lp2 = lp1->l_fp ;
if( lp2 == curbp->b_linep) { /* At the buffer end. */ if( lp2 == curbp->b_linep) { /* At the buffer end. */
if( lp1->l_used == 0) /* Blank line. */ if( lp1->l_used == 0) /* Blank line. */
lfree( lp1) ; lfree( lp1) ;
return TRUE ; return TRUE ;
} }
if( lp2->l_used <= lp1->l_size - lp1->l_used) { if( lp2->l_used <= lp1->l_size - lp1->l_used) {
cp1 = &lp1->l_text[ lp1->l_used] ; cp1 = &lp1->l_text[ lp1->l_used] ;
cp2 = &lp2->l_text[0]; cp2 = lp2->l_text ;
while( cp2 != &lp2->l_text[ lp2->l_used]) while( cp2 != &lp2->l_text[ lp2->l_used])
*cp1++ = *cp2++ ; *cp1++ = *cp2++ ;
wp = wheadp;
while (wp != NULL) { for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if( wp->w_linep == lp2) if( wp->w_linep == lp2)
wp->w_linep = lp1 ; wp->w_linep = lp1 ;
if( wp->w_dotp == lp2) { if( wp->w_dotp == lp2) {
wp->w_dotp = lp1 ; wp->w_dotp = lp1 ;
wp->w_doto += lp1->l_used ; wp->w_doto += lp1->l_used ;
} }
if( wp->w_markp == lp2) { if( wp->w_markp == lp2) {
wp->w_markp = lp1 ; wp->w_markp = lp1 ;
wp->w_marko += lp1->l_used ; wp->w_marko += lp1->l_used ;
} }
wp = wp->w_wndp;
} }
lp1->l_used += lp2->l_used ; lp1->l_used += lp2->l_used ;
lp1->l_fp = lp2->l_fp ; lp1->l_fp = lp2->l_fp ;
lp2->l_fp->l_bp = lp1 ; lp2->l_fp->l_bp = lp1 ;
free((char *) lp2); free( lp2) ;
return TRUE ; return TRUE ;
} }
lp3 = lalloc( lp1->l_used + lp2->l_used) ; line_p lp3 = lalloc( lp1->l_used + lp2->l_used) ;
if( lp3 == NULL) if( lp3 == NULL)
return FALSE ; return FALSE ;
cp1 = &lp1->l_text[0]; cp1 = lp1->l_text ;
cp2 = &lp3->l_text[0]; cp2 = lp3->l_text ;
while( cp1 != &lp1->l_text[ lp1->l_used]) while( cp1 != &lp1->l_text[ lp1->l_used])
*cp2++ = *cp1++ ; *cp2++ = *cp1++ ;
cp1 = &lp2->l_text[0];
cp1 = lp2->l_text ;
while( cp1 != &lp2->l_text[ lp2->l_used]) while( cp1 != &lp2->l_text[ lp2->l_used])
*cp2++ = *cp1++ ; *cp2++ = *cp1++ ;
lp1->l_bp->l_fp = lp3 ; lp1->l_bp->l_fp = lp3 ;
lp3->l_fp = lp2->l_fp ; lp3->l_fp = lp2->l_fp ;
lp2->l_fp->l_bp = lp3 ; lp2->l_fp->l_bp = lp3 ;
lp3->l_bp = lp1->l_bp ; lp3->l_bp = lp1->l_bp ;
wp = wheadp; for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
while (wp != NULL) {
if( wp->w_linep == lp1 || wp->w_linep == lp2) if( wp->w_linep == lp1 || wp->w_linep == lp2)
wp->w_linep = lp3 ; wp->w_linep = lp3 ;
if( wp->w_dotp == lp1) if( wp->w_dotp == lp1)
wp->w_dotp = lp3 ; wp->w_dotp = lp3 ;
else if( wp->w_dotp == lp2) { else if( wp->w_dotp == lp2) {
wp->w_dotp = lp3 ; wp->w_dotp = lp3 ;
wp->w_doto += lp1->l_used ; wp->w_doto += lp1->l_used ;
} }
if( wp->w_markp == lp1) if( wp->w_markp == lp1)
wp->w_markp = lp3 ; wp->w_markp = lp3 ;
else if( wp->w_markp == lp2) { else if( wp->w_markp == lp2) {
wp->w_markp = lp3 ; wp->w_markp = lp3 ;
wp->w_marko += lp1->l_used ; wp->w_marko += lp1->l_used ;
} }
wp = wp->w_wndp;
} }
free((char *) lp1);
free((char *) lp2); free( lp1) ;
free( lp2) ;
return TRUE ; return TRUE ;
} }

6
line.h
View File

@ -29,15 +29,12 @@ typedef struct line {
extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */ extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */
char *getkill( void) ;
/* Bindable functions */ /* Bindable functions */
BBINDABLE( backchar) ; BBINDABLE( backchar) ;
BBINDABLE( forwchar) ; BBINDABLE( forwchar) ;
BINDABLE( insspace) ; BINDABLE( insspace) ;
BINDABLE( yank) ; BINDABLE( yank) ;
void lfree( line_p lp) ;
void lchange( int flag) ; void lchange( int flag) ;
boolean linstr( char *instr) ; boolean linstr( char *instr) ;
boolean linsert( int n, unicode_t c) ; boolean linsert( int n, unicode_t c) ;
@ -47,10 +44,11 @@ boolean lnewline( void) ;
boolean ldelete( long n, boolean kflag) ; boolean ldelete( long n, boolean kflag) ;
boolean ldelchar( long n, boolean kflag) ; boolean ldelchar( long n, boolean kflag) ;
int lgetchar( unicode_t *cref) ; int lgetchar( unicode_t *cref) ;
char *getctext( void) ;
void kdelete( void) ; void kdelete( void) ;
int kinsert( int c) ; int kinsert( int c) ;
line_p lalloc( int minsize) ; /* Allocate a line of at least minsize chars. */ line_p lalloc( int minsize) ; /* Allocate a line of at least minsize chars. */
void lfree( line_p lp) ; /* free a line, updating buffers and windows */
const char *getkill( void) ; /* get value of $kill */
boolean rdonly( void) ; /* Read Only error message */ boolean rdonly( void) ; /* Read Only error message */

51
spawn.c
View File

@ -169,40 +169,38 @@ BINDABLE( execprg) {
/* Pipe a one line command into a window /* Pipe a one line command into a window
* Bound to ^X @ * Bound to pipe-command ^X @
*/ */
BINDABLE( pipecmd) { BINDABLE( pipecmd) {
int s ; /* return status from CLI */ window_p wp ; /* pointer to new window */
struct window *wp ; /* pointer to new window */
buffer_p bp ; /* pointer to buffer to zot */
char *mlarg ; char *mlarg ;
char *line ; /* command line send to shell */ const char filnam[] = "command" ;
static char bname[] = "command" ;
static char filnam[ NSTRING] = "command" ;
/* don't allow this command if restricted */ /* don't allow this command if restricted */
if( restflag) if( restflag)
return resterr() ; return resterr() ;
/* get the command to pipe in */ /* get the command to pipe in */
s = newmlarg( &mlarg, "@", 0) ; int s = newmlarg( &mlarg, "pipe-command: ", 0) ;
if( s != TRUE) if( s != TRUE)
return s ; return s ;
line = malloc( strlen( mlarg) + strlen( filnam) + 2) ; char *cmdline = malloc( strlen( mlarg) + strlen( filnam) + 4) ;
if( line == NULL) { if( cmdline == NULL) {
free( mlarg) ; free( mlarg) ;
return FALSE ; return FALSE ;
} }
strcpy( line, mlarg) ; strcpy( cmdline, mlarg) ;
free( mlarg) ; free( mlarg) ;
strcat( cmdline, " > ") ;
strcat( cmdline, filnam) ;
/* 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) { buffer_p bp = bfind( filnam, FALSE, 0) ;
if( bp != NULL) {
/* try to make sure we are off screen */ /* try to make sure we are off screen */
wp = wheadp; for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
while (wp != NULL) {
if( wp->w_bufp == bp) { if( wp->w_bufp == bp) {
#if PKCODE #if PKCODE
if( wp == curwp) if( wp == curwp)
@ -215,22 +213,20 @@ BINDABLE( pipecmd) {
break ; break ;
#endif #endif
} }
wp = wp->w_wndp;
} }
if( zotbuf( bp) != TRUE) { if( zotbuf( bp) != TRUE) {
free( line) ; free( cmdline) ;
return FALSE ; return FALSE ;
} }
} }
#if USG | BSD #if USG | BSD
TTflush(); TTflush();
TTclose(); /* stty to old modes */ TTclose(); /* stty to old modes */
TTkclose(); TTkclose();
strcat( line, ">") ; ue_system( cmdline) ;
strcat( line, filnam) ; free( cmdline) ;
ue_system( line) ;
free( line) ;
TTopen(); TTopen();
TTkopen(); TTkopen();
TTflush(); TTflush();
@ -241,21 +237,16 @@ BINDABLE( pipecmd) {
return s; return s;
#endif #endif
/* split the current window to make room for the command output */ /* split the current window to make room for the command output
if (splitwind(FALSE, 1) == FALSE) ** and read the stuff in */
return FALSE; if( splitwind( FALSE, 1) == FALSE
|| getfile( filnam, FALSE) == FALSE)
/* and read the stuff in */
if (getfile(filnam, FALSE) == FALSE)
return FALSE ; return FALSE ;
/* make this window in VIEW mode, update all mode lines */ /* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW ; curwp->w_bufp->b_mode |= MDVIEW ;
wp = wheadp; for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
while (wp != NULL) {
wp->w_flag |= WFMODE ; wp->w_flag |= WFMODE ;
wp = wp->w_wndp;
}
/* and get rid of the temporary file */ /* and get rid of the temporary file */
unlink( filnam) ; unlink( filnam) ;