Compare commits

...

3 Commits

Author SHA1 Message Date
Renaud 0c584e5490 Revise window flagging on line change.
Evaluation of Value of kill buffer and current line.
2021-09-15 13:15:31 +08:00
Renaud b244adf23a Revise fence handling in CMODE. 2021-09-15 11:55:23 +08:00
Renaud 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 */

435
line.c
View File

@ -54,35 +54,23 @@ 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 ;
} }
*cp = 0 ; *cp = 0 ;
/* and return the constructed value */ /* and return the constructed value */
return value; return value ;
} }
@ -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) {
{ if( curbp->b_nwnd != 1) /* Ensure hard. */
struct window *wp; flag = WFHARD ;
if (curbp->b_nwnd != 1) /* Ensure hard. */ if( (curbp->b_flag & BFCHG) == 0) { /* First change, so */
flag = WFHARD; flag |= WFMODE ; /* update mode lines. */
if ((curbp->b_flag & BFCHG) == 0) { /* First change, so */ curbp->b_flag |= BFCHG ;
flag |= WFMODE; /* update mode lines. */
curbp->b_flag |= BFCHG;
}
wp = wheadp;
while (wp != NULL) {
if (wp->w_bufp == curbp)
wp->w_flag |= flag;
wp = wp->w_wndp;
} }
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
if( wp->w_bufp == curbp)
wp->w_flag |= flag ;
} }
@ -309,81 +293,85 @@ 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)
return FALSE ; return FALSE ;
lp3 = lp1->l_bp; /* Previous line */ lp3 = lp1->l_bp ; /* Previous line */
lp3->l_fp = lp2; /* Link in */ lp3->l_fp = lp2 ; /* Link in */
lp2->l_fp = lp1; lp2->l_fp = lp1 ;
lp1->l_bp = lp2; lp1->l_bp = lp2 ;
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_doto = n; curwp->w_dotp = lp2 ;
return TRUE; curwp->w_doto = n ;
return TRUE ;
} }
doto = curwp->w_doto; /* Save for later. */
if (lp1->l_used + n > lp1->l_size) { /* Hard: reallocate */ int doto = curwp->w_doto ; /* Save for later. */
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)
return FALSE ; return FALSE ;
cp1 = &lp1->l_text[0]; cp1 = &lp1->l_text[ 0] ;
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;
while (cp1 != &lp1->l_text[lp1->l_used]) cp2 += n ;
*cp2++ = *cp1++; while( cp1 != &lp1->l_text[ lp1->l_used])
lp1->l_bp->l_fp = lp2; *cp2++ = *cp1++ ;
lp2->l_fp = lp1->l_fp;
lp1->l_fp->l_bp = lp2; lp1->l_bp->l_fp = lp2 ;
lp2->l_bp = lp1->l_bp; lp2->l_fp = lp1->l_fp ;
free((char *) lp1); lp1->l_fp->l_bp = lp2 ;
lp2->l_bp = lp1->l_bp ;
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 ;
cp2 = &lp1->l_text[lp1->l_used]; cp2 = &lp1->l_text[ lp1->l_used] ;
cp1 = cp2 - n; cp1 = cp2 - n ;
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 */
lp2->l_text[doto + i] = c; for( i = 0 ; i < n ; ++i) /* Add the characters */
wp = wheadp; /* Update windows */ lp2->l_text[ doto + i] = c ;
while (wp != NULL) {
if (wp->w_linep == lp1) /* Update windows */
wp->w_linep = lp2; for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if (wp->w_dotp == lp1) { if( wp->w_linep == lp1)
wp->w_dotp = lp2; wp->w_linep = lp2 ;
if (wp == curwp || wp->w_doto > doto)
wp->w_doto += n; if( wp->w_dotp == lp1) {
wp->w_dotp = lp2 ;
if( wp == curwp || wp->w_doto > doto)
wp->w_doto += n ;
} }
if (wp->w_markp == lp1) {
wp->w_markp = lp2; if( wp->w_markp == lp1) {
if (wp->w_marko > doto) wp->w_markp = lp2 ;
wp->w_marko += n; if( wp->w_marko > doto)
wp->w_marko += n ;
} }
wp = wp->w_wndp;
} }
return TRUE;
return TRUE ;
} }
boolean linsert( int n, unicode_t c) { boolean linsert( int n, unicode_t c) {
@ -565,101 +553,72 @@ 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. */ int doto = curwp->w_doto ;
if (chunk > n) int chunk = dotp->l_used - doto ; /* Size of chunk. */
chunk = n; if( chunk == 0) { /* End of line, merge. */
if (chunk == 0) { /* End of line, merge. */
#if SCROLLCODE #if SCROLLCODE
lchange(WFHARD | WFKILLS); lchange( WFHARD | WFKILLS) ;
#else #else
lchange(WFHARD); lchange( WFHARD) ;
#endif #endif
if (ldelnewline() == FALSE if( ldelnewline() == FALSE
|| (kflag != FALSE && kinsert('\n') == FALSE)) || (kflag != FALSE && kinsert( '\n') == FALSE))
return FALSE; return FALSE ;
--n;
continue;
}
lchange(WFEDIT);
cp1 = &dotp->l_text[doto]; /* Scrunch text. */
cp2 = cp1 + chunk;
if (kflag != FALSE) { /* Kill? */
while (cp1 != cp2) {
if (kinsert(*cp1) == FALSE)
return FALSE;
++cp1;
}
cp1 = &dotp->l_text[doto];
}
while (cp2 != &dotp->l_text[dotp->l_used])
*cp1++ = *cp2++;
dotp->l_used -= chunk;
wp = wheadp; /* Fix windows */
while (wp != NULL) {
if (wp->w_dotp == dotp && wp->w_doto >= doto) {
wp->w_doto -= chunk;
if (wp->w_doto < doto)
wp->w_doto = doto;
}
if (wp->w_markp == dotp && wp->w_marko >= doto) {
wp->w_marko -= chunk;
if (wp->w_marko < doto)
wp->w_marko = doto;
}
wp = wp->w_wndp;
}
n -= chunk;
}
return TRUE;
}
/* --n ;
* getctext: grab and return a string with the text of continue ;
* the current line } else if( chunk > n)
*/ chunk = n ;
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 */ lchange( WFEDIT) ;
lp = curwp->w_dotp; char *cp1 = &dotp->l_text[ doto] ; /* Scrunch text. */
size = lp->l_used; char *cp2 = cp1 + chunk ;
if( size >= rsize) { if( kflag != FALSE) { /* Kill? */
if( rsize) while( cp1 != cp2) {
free( rline) ; if( kinsert( *cp1) == FALSE)
return FALSE ;
++cp1 ;
}
rsize = size + 1 ; cp1 = &dotp->l_text[ doto] ;
rline = malloc( rsize) ;
if( rline == NULL) {
rsize = 0 ;
return "" ;
} }
while( cp2 != &dotp->l_text[ dotp->l_used])
*cp1++ = *cp2++ ;
dotp->l_used -= chunk ;
/* Fix windows */
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if( wp->w_dotp == dotp && wp->w_doto >= doto) {
wp->w_doto -= chunk ;
if( wp->w_doto < doto)
wp->w_doto = doto ;
}
if( wp->w_markp == dotp && wp->w_marko >= doto) {
wp->w_marko -= chunk ;
if( wp->w_marko < doto)
wp->w_marko = doto ;
}
}
n -= chunk ;
} }
/* copy it across */ return TRUE ;
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 /* 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,80 +629,86 @@ 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) {
cp1 = &lp1->l_text[lp1->l_used]; if( lp2->l_used <= lp1->l_size - lp1->l_used) {
cp2 = &lp2->l_text[0]; cp1 = &lp1->l_text[ lp1->l_used] ;
while (cp2 != &lp2->l_text[lp2->l_used]) cp2 = lp2->l_text ;
*cp1++ = *cp2++; while( cp2 != &lp2->l_text[ lp2->l_used])
wp = wheadp; *cp1++ = *cp2++ ;
while (wp != NULL) {
if (wp->w_linep == lp2) for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
wp->w_linep = lp1; if( wp->w_linep == lp2)
if (wp->w_dotp == lp2) { wp->w_linep = lp1 ;
wp->w_dotp = lp1;
wp->w_doto += lp1->l_used; if( wp->w_dotp == lp2) {
wp->w_dotp = lp1 ;
wp->w_doto += lp1->l_used ;
} }
if (wp->w_markp == lp2) {
wp->w_markp = lp1; if( wp->w_markp == lp2) {
wp->w_marko += lp1->l_used; wp->w_markp = lp1 ;
wp->w_marko += lp1->l_used ;
} }
wp = wp->w_wndp;
} }
lp1->l_used += lp2->l_used;
lp1->l_fp = lp2->l_fp; lp1->l_used += lp2->l_used ;
lp2->l_fp->l_bp = lp1; lp1->l_fp = lp2->l_fp ;
free((char *) lp2); lp2->l_fp->l_bp = lp1 ;
return TRUE; free( lp2) ;
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];
while (cp1 != &lp2->l_text[lp2->l_used]) cp1 = lp2->l_text ;
*cp2++ = *cp1++; while( cp1 != &lp2->l_text[ lp2->l_used])
lp1->l_bp->l_fp = lp3; *cp2++ = *cp1++ ;
lp3->l_fp = lp2->l_fp;
lp2->l_fp->l_bp = lp3; lp1->l_bp->l_fp = lp3 ;
lp3->l_bp = lp1->l_bp; lp3->l_fp = lp2->l_fp ;
wp = wheadp; lp2->l_fp->l_bp = lp3 ;
while (wp != NULL) { lp3->l_bp = lp1->l_bp ;
if (wp->w_linep == lp1 || wp->w_linep == lp2) for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
wp->w_linep = lp3; if( wp->w_linep == lp1 || wp->w_linep == lp2)
if (wp->w_dotp == lp1) wp->w_linep = lp3 ;
wp->w_dotp = lp3;
else if (wp->w_dotp == lp2) { if( wp->w_dotp == lp1)
wp->w_dotp = lp3; wp->w_dotp = lp3 ;
wp->w_doto += lp1->l_used; else if( wp->w_dotp == lp2) {
wp->w_dotp = lp3 ;
wp->w_doto += lp1->l_used ;
} }
if (wp->w_markp == lp1)
wp->w_markp = lp3; if( wp->w_markp == lp1)
else if (wp->w_markp == lp2) { wp->w_markp = lp3 ;
wp->w_markp = lp3; else if( wp->w_markp == lp2) {
wp->w_marko += lp1->l_used; wp->w_markp = lp3 ;
wp->w_marko += lp1->l_used ;
} }
wp = wp->w_wndp;
} }
free((char *) lp1);
free((char *) lp2); free( lp1) ;
return TRUE; free( lp2) ;
return TRUE ;
} }

8
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 */

89
spawn.c
View File

@ -169,97 +169,88 @@ 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) ;
/* try to make sure we are off screen */ if( bp != NULL) {
wp = wheadp; /* try to make sure we are off screen */
while (wp != NULL) { for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp) {
if (wp->w_bufp == bp) { if( wp->w_bufp == bp) {
#if PKCODE #if PKCODE
if (wp == curwp) if( wp == curwp)
delwind(FALSE, 1); delwind( FALSE, 1) ;
else else
onlywind(FALSE, 1); onlywind( FALSE, 1) ;
break; break ;
#else #else
onlywind(FALSE, 1); onlywind( FALSE, 1) ;
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();
sgarbf = TRUE; sgarbf = TRUE;
s = TRUE; s = TRUE;
#else #else
if (s != TRUE) if( s != TRUE)
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)
return FALSE ;
/* and read the stuff in */ /* make this window in VIEW mode, update all mode lines */
if (getfile(filnam, FALSE) == FALSE) curwp->w_bufp->b_mode |= MDVIEW ;
return FALSE; for( wp = wheadp ; wp != NULL ; wp = wp->w_wndp)
wp->w_flag |= WFMODE ;
/* make this window in VIEW mode, update all mode lines */ /* and get rid of the temporary file */
curwp->w_bufp->b_mode |= MDVIEW; unlink( filnam) ;
wp = wheadp; return TRUE ;
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
/* and get rid of the temporary file */
unlink(filnam);
return TRUE;
} }