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

Revise pipe-command.

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

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