X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/2d55c063c5da576af47e19e5619cad7e936fe350..61fec9fc73ce1a323a68f4bd6c6d96e3e73a5433:/usr/src/usr.bin/mail/collect.c diff --git a/usr/src/usr.bin/mail/collect.c b/usr/src/usr.bin/mail/collect.c index 4f101df9b2..a7ed484acf 100644 --- a/usr/src/usr.bin/mail/collect.c +++ b/usr/src/usr.bin/mail/collect.c @@ -7,7 +7,7 @@ * ~ escapes. */ -static char *SccsId = "@(#)collect.c 1.4 %G%"; +static char *SccsId = "@(#)collect.c 2.13 %G%"; #include "rcv.h" #include @@ -27,7 +27,9 @@ static char *SccsId = "@(#)collect.c 1.4 %G%"; static int (*savesig)(); /* Previous SIGINT value */ static int (*savehup)(); /* Previous SIGHUP value */ +# ifdef VMUNIX static int (*savecont)(); /* Previous SIGCONT value */ +# endif VMUNIX static FILE *newi; /* File for saving away */ static FILE *newo; /* Output side of same */ static int hf; /* Ignore interrups */ @@ -40,24 +42,30 @@ collect(hp) struct header *hp; { FILE *ibuf, *fbuf, *obuf; - int lc, cc, escape, collrub(), intack(), stopdot, collhup, collcont(); + int lc, cc, escape, collrub(), intack(), collhup, collcont(), eof; register int c, t; char linebuf[LINESIZE], *cp; extern char tempMail[]; + int notify(); + extern collintsig(), collhupsig(); noreset++; - stopdot = (value("dot") != NOSTR) && intty; ibuf = obuf = NULL; if (value("ignore") != NOSTR) hf = 1; else hf = 0; hadintr = 0; +# ifdef VMUNIX if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN) sigset(SIGINT, hf ? intack : collrub), sighold(SIGINT); if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN) - sigset(SIGHUP, collrub), sighold(SIGINT); + sigset(SIGHUP, collrub), sighold(SIGHUP); savecont = sigset(SIGCONT, collcont); +# else VMUNIX + savesig = signal(SIGINT, SIG_IGN); + savehup = signal(SIGHUP, SIG_IGN); +# endif VMUNIX newi = NULL; newo = NULL; if ((obuf = fopen(tempMail, "w")) == NULL) { @@ -93,18 +101,35 @@ collect(hp) escape = ESCAPE; if ((cp = value("escape")) != NOSTR) escape = *cp; + eof = 0; for (;;) { setjmp(coljmp); +# ifdef VMUNIX sigrelse(SIGINT); sigrelse(SIGHUP); +# else VMUNIX + if (savesig != SIG_IGN) + signal(SIGINT, hf ? intack : collintsig); + if (savehup != SIG_IGN) + signal(SIGHUP, collhupsig); +# endif VMUNIX flush(); - if (readline(stdin, linebuf) <= 0) + if (readline(stdin, linebuf) <= 0) { + if (intty && value("ignoreeof") != NOSTR) { + if (++eof > 35) + break; + printf("Use \".\" to terminate letter\n", + escape); + continue; + } break; + } + eof = 0; hadintr = 0; - if (stopdot && equal(".", linebuf)) + if (intty && equal(".", linebuf) && + (value("dot") != NOSTR || value("ignoreeof") != NOSTR)) break; - if (linebuf[0] != escape || - (!intty && value("henry") == NOSTR)) { + if (linebuf[0] != escape || rflag != NOSTR) { if ((t = putline(obuf, linebuf)) < 0) goto err; continue; @@ -150,13 +175,14 @@ collect(hp) */ execute(&linebuf[2], 1); + printf("(continue)\n"); break; case '.': /* * Simulate end of file on input. */ - goto eof; + goto eofl; case 'q': case 'Q': @@ -306,7 +332,7 @@ collect(hp) case '?': if ((fbuf = fopen(THELPFILE, "r")) == NULL) { - printf("No help just now.\n"); + perror(THELPFILE); break; } t = getc(fbuf); @@ -366,11 +392,14 @@ collect(hp) break; } } -eof: +eofl: fclose(obuf); rewind(ibuf); sigset(SIGINT, savesig); sigset(SIGHUP, savehup); +# ifdef VMUNIX + sigset(SIGCONT, savecont); +# endif VMUNIX noreset = 0; return(ibuf); @@ -381,7 +410,9 @@ err: fclose(obuf); sigset(SIGINT, savesig); sigset(SIGHUP, savehup); +# ifdef VMUNIX sigset(SIGCONT, savecont); +# endif VMUNIX noreset = 0; return(NULL); } @@ -417,7 +448,7 @@ exwrite(name, ibuf, f) printf("\"%s\" ", name); fflush(stdout); } - if (stat(name, &junk) >= 0) { + if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) { if (!f) fprintf(stderr, "%s: ", name); fprintf(stderr, "File exists\n", name); @@ -461,12 +492,15 @@ mesedit(ibuf, obuf, c) int pid, s; FILE *fbuf; register int t; - int (*sig)(); + int (*sig)(), (*scont)(), signull(); struct stat sbuf; extern char tempMail[], tempEdit[]; register char *edit; sig = sigset(SIGINT, SIG_IGN); +# ifdef VMUNIX + scont = sigset(SIGCONT, signull); +# endif VMUNIX if (stat(tempEdit, &sbuf) >= 0) { printf("%s: file exists\n", tempEdit); goto out; @@ -494,6 +528,7 @@ mesedit(ibuf, obuf, c) edit = c == 'e' ? EDITOR : VISUAL; pid = vfork(); if (pid == 0) { + sigchild(); if (sig != SIG_IGN) sigsys(SIGINT, SIG_DFL); execl(edit, edit, tempEdit, 0); @@ -507,7 +542,7 @@ mesedit(ibuf, obuf, c) } while (wait(&s) != pid) ; - if (s != 0) { + if ((s & 0377) != 0) { printf("Fatal error in \"%s\"\n", edit); remove(tempEdit); goto out; @@ -536,6 +571,9 @@ mesedit(ibuf, obuf, c) fix: perror(tempEdit); out: +# ifdef VMUNIX + sigset(SIGCONT, scont); +# endif VMUNIX sigset(SIGINT, sig); newi = ibuf; return(obuf); @@ -585,6 +623,7 @@ mespipe(ibuf, obuf, cmd) * stdout = new message. */ + sigchild(); close(0); dup(fileno(ibuf)); close(1); @@ -631,7 +670,6 @@ err: * the message temporary. The flag argument is 'm' if we * should shift over and 'f' if not. */ - forward(ms, obuf, f) char ms[]; FILE *obuf; @@ -657,12 +695,12 @@ forward(ms, obuf, f) touch(*ip); printf(" %d", *ip); if (f == 'm') { - if (transmit(&message[*ip-1], obuf) < 0) { + if (transmit(&message[*ip-1], obuf) < 0L) { perror(tempMail); return(-1); } } else - if (send(&message[*ip-1], obuf) < 0) { + if (send(&message[*ip-1], obuf, 0) < 0) { perror(tempMail); return(-1); } @@ -678,28 +716,30 @@ forward(ms, obuf, f) * on error. */ +long transmit(mailp, obuf) struct message *mailp; FILE *obuf; { register struct message *mp; - register int c, ch; - int n, bol; + register int ch; + long c, n; + int bol; FILE *ibuf; mp = mailp; ibuf = setinput(mp); - c = msize(mp); + c = mp->m_size; n = c; bol = 1; - while (c-- > 0) { + while (c-- > 0L) { if (bol) { bol = 0; putc('\t', obuf); n++; if (ferror(obuf)) { perror("/tmp"); - return(-1); + return(-1L); } } ch = getc(ibuf); @@ -708,7 +748,7 @@ transmit(mailp, obuf) putc(ch, obuf); if (ferror(obuf)) { perror("/tmp"); - return(-1); + return(-1L); } } return(n); @@ -732,18 +772,32 @@ collcont(s) * were previously set anyway. */ +# ifndef VMUNIX +collintsig() +{ + signal(SIGINT, SIG_IGN); + collrub(SIGINT); +} + +collhupsig() +{ + signal(SIGHUP, SIG_IGN); + collrub(SIGHUP); +} +# endif VMUNIX + collrub(s) { register FILE *dbuf; register int c; - if (s == SIGINT) - sigset(SIGCONT, collrub); if (s == SIGINT && hadintr == 0) { hadintr++; clrbuf(stdout); printf("\n(Interrupt -- one more to kill letter)\n"); - sigset(s, collrub); +# ifdef VMUNIX + sigrelse(s); +# endif VMUNIX longjmp(coljmp, 1); } fclose(newo); @@ -761,7 +815,9 @@ done: fclose(newi); sigset(SIGINT, savesig); sigset(SIGHUP, savehup); +# ifdef VMUNIX sigset(SIGCONT, savecont); +# endif VMUNIX if (rcvmode) { if (s == SIGHUP) hangup(SIGHUP); @@ -779,7 +835,6 @@ done: intack(s) { - sigrelse(SIGCONT); puts("@"); fflush(stdout); clearerr(stdin);