* Routines to execute other programs.
* Necessarily very OS dependent.
extern int screen_trashed
;
* Pass the specified command to a shell to be executed.
* Like plain "system()", but handles resetting terminal modes, etc.
register char *curr_filename
;
* Print the command which is to be executed,
* unless the command starts with a "-".
* Close the current input file.
curr_filename
= get_filename(curr_ifile
);
* De-initialize the terminal and take out of raw mode.
flush(); /* Make sure the deinit chars get out */
* Restore signals to their defaults.
* Force standard input to be the user's terminal
* (the normal standard input), even if less's standard input
inp2
= open("CON", O_TEXT
|O_RDONLY
);
if (open("/dev/tty", 0) < 0)
* Pass the command to the system to be executed.
* If we have a SHELL environment variable, use
* <$SHELL -c "command"> instead of just <command>.
* If the command is empty, just invoke a shell.
if ((shell
= getenv("SHELL")) != NULL
&& *shell
!= '\0')
p
= (char *) ecalloc(strlen(shell
) + strlen(cmd
) + 7,
sprintf(p
, "%s -c \"%s\"", shell
, cmd
);
* Restore standard input, reset signals, raw mode, etc.
* Reopen the current input file.
(void) edit(curr_filename
, 0);
#if defined(SIGWINCH) || defined(SIGWIND)
* Since we were ignoring window change signals while we executed
* the system command, we must assume the window changed.
* Warning: this leaves a signal pending (in "sigs"),
* so psignals() should be called soon after lsystem().
* Pipe a section of the input file into the given shell command.
* The section to be piped is the section "between" the current
* position and the position marked by the given letter.
* The "current" position means the top line displayed if the mark
* is after the current screen, or the bottom line displayed if
* the mark is before the current screen.
* If the mark is on the current screen, the whole screen is displayed.
POSITION mpos
, tpos
, bpos
;
* mpos = the marked position.
* bpos = bottom of screen.
if (mpos
== NULL_POSITION
)
if (tpos
== NULL_POSITION
)
return (pipe_data(cmd
, tpos
, bpos
));
return (pipe_data(cmd
, mpos
, tpos
));
else if (bpos
== NULL_POSITION
)
return (pipe_data(cmd
, tpos
, bpos
));
return (pipe_data(cmd
, tpos
, mpos
));
* Create a pipe to the given shell command.
* Feed it the file contents between the positions spos and epos.
pipe_data(cmd
, spos
, epos
)
* This is structured much like lsystem().
* Since we're running a shell program, we must be careful
* to perform the necessary deinitialization before running
* the command, and reinitialization after it.
error("Cannot seek to start position", NULL_PARG
);
if ((f
= popen(cmd
, "w")) == NULL
)
error("Cannot create pipe", NULL_PARG
);
SIGNAL(SIGPIPE
, SIG_IGN
);
while (epos
== NULL_POSITION
|| spos
++ <= epos
)
* Read a character from the file and give it to the pipe.
* Finish up the last line.
while (c
!= '\n' && c
!= EOI
)
SIGNAL(SIGPIPE
, SIG_DFL
);
#if defined(SIGWINCH) || defined(SIGWIND)
/* {{ Probably don't need this here. }} */