1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-04 09:16:39 -05:00

Revise pipe-command.

This commit is contained in:
Renaud 2021-09-15 11:51:12 +08:00
parent 991283b912
commit 860bace701

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) ;