* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)ex_unix.c 7.5 (Berkeley) %G%";
* Unix escapes, filtering
* First part of a shell escape,
* parse the line, expanding # and % and ! and printing if implied.
char printub
, puxb
[UXBSIZE
+ sizeof (int)];
if (c
== '\n' || c
== EOF
)
error("Incomplete shell escape command@- use 'shell' to get a shell");
if (any(peekchar(), "%#!"))
if (up
>= &uxb
[UXBSIZE
]) {
error("Command too long");
error("No previous command@to substitute for !");
error("No alternate filename@to substitute for #");
error("No filename@to substitute for %%");
} while (c
== '"' || c
== '|' || !endcmd(c
));
if (warn
&& hush
== 0 && chng
&& xchng
!= chng
&& value(WARN
) && dol
> zero
) {
printf(mesg("[No write]|[No write since last change]"));
error("No previous command@to repeat");
if (inopen
&& Outchar
!= termchar
) {
* Do the real work for execution of a shell escape.
* Mode is like the number passed to open system calls
* and indicates filtering. If input is implied, newstdin
* must have been setup already.
unixex(opt
, up
, newstdin
, mode
)
signal(SIGTSTP
, SIG_DFL
);
if ((mode
& 1) && pipe(pvec
) < 0) {
/* Newstdin should be io so it will be closed */
error("Can't make pipe for filter");
error("No more processes");
signal(SIGQUIT
, oldquit
);
execl(svalue(SHELL
), "sh", opt
, up
, (char *) 0);
printf("No %s!\n", svalue(SHELL
));
* Wait for the command to complete.
* F is for restoration of tty mode if from open/visual.
* C flags suppression of printing.
if (!inopen
&& c
&& hush
== 0) {
* Setup a pipeline for the filtration implied by mode
* which is like a open number. If input is required to
* the filter, then a child editor is created to write it.
* If output is catch it from io which is created by unixex.
ttymode f
; /* mjm: was register */
register int lines
= lineDOL();
error("Can't make pipe");
error("No more processes");
f
= unixex("-c", uxb
, (mode
& 2) ? pvec
[0] : 0, mode
);
undap1
= undap2
= addr2
+1;
if (fstat(io
, &statb
) < 0)
bsize
= statb
.st_blksize
;
ignore(append(getfile
, addr2
));
vudump("after append in filter");
* Set up to do a recover, getting io to be a pipe from
error(" Can't make pipe for recovery");
error(" Can't fork to execute recovery");
execl(EXRECOVER
, "exrecover", svalue(DIRECTORY
), file
, (char *) 0);
error(" No recovery routine");
* Wait for the process (pid an external) to complete.
while (rpid
!= pid
&& rpid
!= -1);
status
= (status
>> 8) & 0377;
* The end of a recover operation. If the process
* exits non-zero, force not edited; otherwise force
if (pid
== rpid
&& status
!= 0)