Update ex_unix.c

fix rpm build
This commit is contained in:
deepend-tildeclub 2024-10-10 14:05:42 -06:00 committed by GitHub
parent 0d7b306269
commit 297a2b4a52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 279 additions and 279 deletions

558
ex_unix.c
View File

@ -7,7 +7,7 @@
* *
* *
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -19,8 +19,8 @@
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software * 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement: * must display the following acknowledgement:
* This product includes software developed by the University of * This product includes software developed by the University of
* California, Berkeley and its contributors. * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors * 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
@ -71,13 +71,13 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef lint #ifndef lint
#ifdef DOSCCS #ifdef DOSCCS
static char sccsid[] = "@(#)ex_unix.c 1.16 (gritter) 11/23/04"; static char sccsid[] = "@(#)ex_unix.c 1.16 (gritter) 11/23/04";
#endif #endif
#endif #endif
/* from ex_unix.c 7.6 (Berkeley) 10/22/85 */ /* from ex_unix.c 7.6 (Berkeley) 10/22/85 */
#include "ex.h" #include "ex.h"
#include "ex_temp.h" #include "ex_temp.h"
@ -93,118 +93,118 @@ static char sccsid[] = "@(#)ex_unix.c 1.16 (gritter) 11/23/04";
* First part of a shell escape, * First part of a shell escape,
* parse the line, expanding # and % and ! and printing if implied. * parse the line, expanding # and % and ! and printing if implied.
*/ */
void void
unix0(int warn) unix0(int warn)
{ {
register char *up, *fp; register char *up, *fp;
register short c; register short c;
char printub, puxb[UXBSIZE + sizeof (int)]; char printub, puxb[UXBSIZE + sizeof (int)];
printub = 0; printub = 0;
CP(puxb, uxb); CP(puxb, uxb);
c = getchar(); c = getchar();
if (c == '\n' || c == EOF) if (c == '\n' || c == EOF)
error(catgets(catd, 1, 192, error(catgets(catd, 1, 192,
"Incomplete shell escape command@- use 'shell' to get a shell")); "Incomplete shell escape command@- use 'shell' to get a shell"));
up = uxb; up = uxb;
do { do {
switch (c) { switch (c) {
case '\\': case '\\':
if (any(peekchar(), "%#!")) if (any(peekchar(), "%#!"))
c = getchar(); c = getchar();
default: default:
if (up >= &uxb[UXBSIZE]) { if (up >= &uxb[UXBSIZE]) {
tunix: tunix:
uxb[0] = 0; uxb[0] = 0;
error(catgets(catd, 1, 193, error(catgets(catd, 1, 193,
"Command too long")); "Command too long"));
} }
*up++ = c; *up++ = c;
break; break;
case '!': case '!':
fp = puxb; fp = puxb;
if (*fp == 0) { if (*fp == 0) {
uxb[0] = 0; uxb[0] = 0;
error(catgets(catd, 1, 194, error(catgets(catd, 1, 194,
"No previous command@to substitute for !")); "No previous command@to substitute for !"));
} }
printub++; printub++;
while (*fp) { while (*fp) {
if (up >= &uxb[UXBSIZE]) if (up >= &uxb[UXBSIZE])
goto tunix; goto tunix;
*up++ = *fp++; *up++ = *fp++;
} }
break; break;
case '#': case '#':
fp = altfile; fp = altfile;
if (*fp == 0) { if (*fp == 0) {
uxb[0] = 0; uxb[0] = 0;
error(catgets(catd, 1, 195, error(catgets(catd, 1, 195,
"No alternate filename@to substitute for #")); "No alternate filename@to substitute for #"));
} }
goto uexp; goto uexp;
case '%': case '%':
fp = savedfile; fp = savedfile;
if (*fp == 0) { if (*fp == 0) {
uxb[0] = 0; uxb[0] = 0;
error(catgets(catd, 1, 196, error(catgets(catd, 1, 196,
"No filename@to substitute for %%")); "No filename@to substitute for %%"));
} }
uexp: uexp:
printub++; printub++;
while (*fp) { while (*fp) {
if (up >= &uxb[UXBSIZE]) if (up >= &uxb[UXBSIZE])
goto tunix; goto tunix;
#ifndef BIT8 #ifndef BIT8
*up++ = *fp++ | QUOTE; *up++ = *fp++ | QUOTE;
#else #else
*up++ = *fp++; *up++ = *fp++;
#endif #endif
} }
break; break;
} }
c = getchar(); c = getchar();
} while (c == '"' || c == '|' || !endcmd(c)); } while (c == '"' || c == '|' || !endcmd(c));
if (c == EOF) if (c == EOF)
ungetchar(c); ungetchar(c);
*up = 0; *up = 0;
if (!inopen) if (!inopen)
resetflav(); resetflav();
if (warn) if (warn)
ckaw(); ckaw();
if (warn && hush == 0 && chng && xchng != chng && value(WARN) && dol > zero) { if (warn && hush == 0 && chng && xchng != chng && value(WARN) && dol > zero) {
xchng = chng; xchng = chng;
vnfl(); vnfl();
printf(mesg(catgets(catd, 1, 197, printf("%s",mesg(catgets(catd, 1, 197,
"[No write]|[No write since last change]"))); "[No write]|[No write since last change]")));
noonl(); noonl();
flush(); flush();
} else } else
warn = 0; warn = 0;
if (printub) { if (printub) {
if (uxb[0] == 0) if (uxb[0] == 0)
error(catgets(catd, 1, 198, error(catgets(catd, 1, 198,
"No previous command@to repeat")); "No previous command@to repeat"));
if (inopen) { if (inopen) {
splitw++; splitw++;
vclean(); vclean();
vgoto(WECHO, 0); vgoto(WECHO, 0);
} }
if (warn) if (warn)
vnfl(); vnfl();
if (hush == 0) if (hush == 0)
lprintf("!%s", uxb); lprintf("!%s", uxb);
if (inopen && Outchar != termchar) { if (inopen && Outchar != termchar) {
vclreol(); vclreol();
vgoto(WECHO, 0); vgoto(WECHO, 0);
} else } else
putnl(); putnl();
flush(); flush();
} }
} }
/* /*
@ -213,79 +213,79 @@ uexp:
* and indicates filtering. If input is implied, newstdin * and indicates filtering. If input is implied, newstdin
* must have been setup already. * must have been setup already.
*/ */
struct termios struct termios
unixex(char *opt, char *up, int newstdin, int mode) unixex(char *opt, char *up, int newstdin, int mode)
{ {
int pvec[2]; int pvec[2];
struct termios f; struct termios f;
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
#ifdef SIGTSTP #ifdef SIGTSTP
if (dosusp) if (dosusp)
signal(SIGTSTP, SIG_DFL); signal(SIGTSTP, SIG_DFL);
#endif #endif
if (inopen) if (inopen)
f = setty(normf); f = setty(normf);
if ((mode & 1) && pipe(pvec) < 0) { if ((mode & 1) && pipe(pvec) < 0) {
/* Newstdin should be io so it will be closed */ /* Newstdin should be io so it will be closed */
if (inopen) if (inopen)
setty(f); setty(f);
error(catgets(catd, 1, 199, "Can't make pipe for filter")); error(catgets(catd, 1, 199, "Can't make pipe for filter"));
} }
#ifndef VFORK #ifndef VFORK
pid = fork(); pid = fork();
#else #else
pid = vfork(); pid = vfork();
#endif #endif
if (pid < 0) { if (pid < 0) {
if (mode & 1) { if (mode & 1) {
close(pvec[0]); close(pvec[0]);
close(pvec[1]); close(pvec[1]);
} }
setrupt(); setrupt();
error(catgets(catd, 1, 200, "No more processes")); error(catgets(catd, 1, 200, "No more processes"));
} }
if (pid == 0) { if (pid == 0) {
if (mode & 2) { if (mode & 2) {
close(0); close(0);
dup(newstdin); dup(newstdin);
close(newstdin); close(newstdin);
} }
if (mode & 1) { if (mode & 1) {
close(pvec[0]); close(pvec[0]);
close(1); close(1);
dup(pvec[1]); dup(pvec[1]);
if (inopen) { if (inopen) {
close(2); close(2);
dup(1); dup(1);
} }
close(pvec[1]); close(pvec[1]);
} }
if (io) if (io)
close(io); close(io);
if (tfile) if (tfile)
close(tfile); close(tfile);
#ifndef VMUNIX #ifndef VMUNIX
close(erfile); close(erfile);
#endif #endif
signal(SIGHUP, oldhup); signal(SIGHUP, oldhup);
signal(SIGQUIT, oldquit); signal(SIGQUIT, oldquit);
#ifdef SIGXFSZ #ifdef SIGXFSZ
signal(SIGXFSZ, oldxfsz); signal(SIGXFSZ, oldxfsz);
#endif #endif
if (ruptible) if (ruptible)
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
execl(svalue(SHELL), "sh", opt, up, (char *)0); execl(svalue(SHELL), "sh", opt, up, (char *)0);
printf(catgets(catd, 1, 201, "No %s!\n"), svalue(SHELL)); printf(catgets(catd, 1, 201, "No %s!\n"), svalue(SHELL));
error(NOSTR); error(NOSTR);
} }
if (mode & 1) { if (mode & 1) {
io = pvec[0]; io = pvec[0];
close(pvec[1]); close(pvec[1]);
} }
if (newstdin) if (newstdin)
close(newstdin); close(newstdin);
return (f); return (f);
} }
/* /*
@ -293,24 +293,24 @@ unixex(char *opt, char *up, int newstdin, int mode)
* F is for restoration of tty mode if from open/visual. * F is for restoration of tty mode if from open/visual.
* C flags suppression of printing. * C flags suppression of printing.
*/ */
void void
unixwt(int c, struct termios f) unixwt(int c, struct termios f)
{ {
waitfor(); waitfor();
#ifdef SIGTSTP #ifdef SIGTSTP
if (dosusp) if (dosusp)
signal(SIGTSTP, onsusp); signal(SIGTSTP, onsusp);
#endif #endif
if (inopen) if (inopen)
setty(f); setty(f);
setrupt(); setrupt();
if (!inopen && c && hush == 0) { if (!inopen && c && hush == 0) {
printf("!\n"); printf("!\n");
flush(); flush();
termreset(); termreset();
gettmode(); gettmode();
} }
} }
/* /*
@ -319,118 +319,118 @@ unixwt(int c, struct termios f)
* the filter, then a child editor is created to write it. * the filter, then a child editor is created to write it.
* If output is catch it from io which is created by unixex. * If output is catch it from io which is created by unixex.
*/ */
void void
filter(register int mode) filter(register int mode)
{ {
static int pvec[2]; static int pvec[2];
struct termios f; /* mjm: was register */ struct termios f; /* mjm: was register */
register int lines = lineDOL(); register int lines = lineDOL();
struct stat statb; struct stat statb;
mode++; mode++;
if (mode & 2) { if (mode & 2) {
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
if (pipe(pvec) < 0) if (pipe(pvec) < 0)
error(catgets(catd, 1, 202, "Can't make pipe")); error(catgets(catd, 1, 202, "Can't make pipe"));
pid = fork(); pid = fork();
io = pvec[0]; io = pvec[0];
if (pid < 0) { if (pid < 0) {
setrupt(); setrupt();
close(pvec[1]); close(pvec[1]);
error(catgets(catd, 1, 203, "No more processes")); error(catgets(catd, 1, 203, "No more processes"));
} }
if (pid == 0) { if (pid == 0) {
setrupt(); setrupt();
io = pvec[1]; io = pvec[1];
close(pvec[0]); close(pvec[0]);
putfile(1); putfile(1);
exitex(0); exitex(0);
} }
close(pvec[1]); close(pvec[1]);
io = pvec[0]; io = pvec[0];
setrupt(); setrupt();
} }
f = unixex("-c", uxb, (mode & 2) ? pvec[0] : 0, mode); f = unixex("-c", uxb, (mode & 2) ? pvec[0] : 0, mode);
if (mode == 3) { if (mode == 3) {
delete(0); delete(0);
addr2 = addr1 - 1; addr2 = addr1 - 1;
} else if (mode == 1) } else if (mode == 1)
deletenone(); deletenone();
if (mode & 1) { if (mode & 1) {
if(FIXUNDO) if(FIXUNDO)
undap1 = undap2 = addr2+1; undap1 = undap2 = addr2+1;
if (fstat(io, &statb) < 0 || statb.st_blksize > LBSIZE) if (fstat(io, &statb) < 0 || statb.st_blksize > LBSIZE)
bsize = LBSIZE; bsize = LBSIZE;
else { else {
bsize = statb.st_blksize; bsize = statb.st_blksize;
if (bsize <= 0) if (bsize <= 0)
bsize = LBSIZE; bsize = LBSIZE;
} }
ignore(append(getfile, addr2)); ignore(append(getfile, addr2));
#ifdef TRACE #ifdef TRACE
if (trace) if (trace)
vudump("after append in filter"); vudump("after append in filter");
#endif #endif
} }
close(io); close(io);
io = -1; io = -1;
unixwt(!inopen, f); unixwt(!inopen, f);
netchHAD(lines); netchHAD(lines);
} }
/* /*
* Set up to do a recover, getting io to be a pipe from * Set up to do a recover, getting io to be a pipe from
* the recover process. * the recover process.
*/ */
void void
recover(void) recover(void)
{ {
static int pvec[2]; static int pvec[2];
if (pipe(pvec) < 0) if (pipe(pvec) < 0)
error(catgets(catd, 1, 204, " Can't make pipe for recovery")); error(catgets(catd, 1, 204, " Can't make pipe for recovery"));
pid = fork(); pid = fork();
io = pvec[0]; io = pvec[0];
if (pid < 0) { if (pid < 0) {
close(pvec[1]); close(pvec[1]);
error(catgets(catd, 1, 205, " Can't fork to execute recovery")); error(catgets(catd, 1, 205, " Can't fork to execute recovery"));
} }
if (pid == 0) { if (pid == 0) {
close(2); close(2);
dup(1); dup(1);
close(1); close(1);
dup(pvec[1]); dup(pvec[1]);
close(pvec[1]); close(pvec[1]);
execl(EXRECOVER, "exrecover", svalue(DIRECTORY), file, (char *) 0); execl(EXRECOVER, "exrecover", svalue(DIRECTORY), file, (char *) 0);
close(1); close(1);
dup(2); dup(2);
error(catgets(catd, 1, 206, " No recovery routine")); error(catgets(catd, 1, 206, " No recovery routine"));
} }
close(pvec[1]); close(pvec[1]);
} }
/* /*
* Wait for the process (pid an external) to complete. * Wait for the process (pid an external) to complete.
*/ */
void void
waitfor(void) waitfor(void)
{ {
int stat = 0; int stat = 0;
pid_t wpid; pid_t wpid;
do { do {
wpid = wait(&stat); wpid = wait(&stat);
if (wpid == pid) { if (wpid == pid) {
status = stat; status = stat;
rpid = wpid; rpid = wpid;
} }
} while (wpid != -1); } while (wpid != -1);
if (status) { if (status) {
if (WIFEXITED(status)) if (WIFEXITED(status))
status = WEXITSTATUS(status); status = WEXITSTATUS(status);
else else
status = 0; status = 0;
} }
} }
/* /*
@ -438,13 +438,13 @@ waitfor(void)
* exits non-zero, force not edited; otherwise force * exits non-zero, force not edited; otherwise force
* a write. * a write.
*/ */
void void
revocer(void) revocer(void)
{ {
waitfor(); waitfor();
if (pid == rpid && status != 0) if (pid == rpid && status != 0)
edited = 0; edited = 0;
else else
change(); change();
} }