use sigmask() macro instead of defining twice.
[unix-history] / usr / src / usr.bin / mail / collect.c
index 080518f..ff16daf 100644 (file)
@@ -1,4 +1,6 @@
-#
+#ifndef lint
+static char sccsid[] = "@(#)collect.c  2.17 (Berkeley) %G%";
+#endif
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -7,8 +9,6 @@
  * ~ escapes.
  */
 
  * ~ escapes.
  */
 
-static char *SccsId = "@(#)collect.c   2.11 %G%";
-
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
 
@@ -48,6 +48,7 @@ collect(hp)
        extern char tempMail[];
        int notify();
        extern collintsig(), collhupsig();
        extern char tempMail[];
        int notify();
        extern collintsig(), collhupsig();
+       char getsub;
 
        noreset++;
        ibuf = obuf = NULL;
 
        noreset++;
        ibuf = obuf = NULL;
@@ -58,9 +59,9 @@ collect(hp)
        hadintr = 0;
 # ifdef VMUNIX
        if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
        hadintr = 0;
 # ifdef VMUNIX
        if ((savesig = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
-               sigset(SIGINT, hf ? intack : collrub), sighold(SIGINT);
+               sigset(SIGINT, hf ? intack : collrub), sigblock(mask(SIGINT));
        if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
        if ((savehup = sigset(SIGHUP, SIG_IGN)) != SIG_IGN)
-               sigset(SIGHUP, collrub), sighold(SIGHUP);
+               sigset(SIGHUP, collrub), sigblock(mask(SIGHUP));
        savecont = sigset(SIGCONT, collcont);
 # else VMUNIX
        savesig = signal(SIGINT, SIG_IGN);
        savecont = sigset(SIGCONT, collcont);
 # else VMUNIX
        savesig = signal(SIGINT, SIG_IGN);
@@ -89,31 +90,35 @@ collect(hp)
         */
 
        t = GTO|GSUBJECT|GCC|GNL;
         */
 
        t = GTO|GSUBJECT|GCC|GNL;
-       c = 0;
+       getsub = 0;
        if (intty && sflag == NOSTR && hp->h_subject == NOSTR && value("ask"))
        if (intty && sflag == NOSTR && hp->h_subject == NOSTR && value("ask"))
-               t &= ~GNL, c++;
+               t &= ~GNL, getsub++;
        if (hp->h_seq != 0) {
                puthead(hp, stdout, t);
                fflush(stdout);
        }
        if (hp->h_seq != 0) {
                puthead(hp, stdout, t);
                fflush(stdout);
        }
-       if (c)
-               grabh(hp, GSUBJECT);
        escape = ESCAPE;
        if ((cp = value("escape")) != NOSTR)
                escape = *cp;
        eof = 0;
        for (;;) {
        escape = ESCAPE;
        if ((cp = value("escape")) != NOSTR)
                escape = *cp;
        eof = 0;
        for (;;) {
+               int omask = sigblock(0) &~ (mask(SIGINT)|mask(SIGHUP));
+
                setjmp(coljmp);
 # ifdef VMUNIX
                setjmp(coljmp);
 # ifdef VMUNIX
-               sigrelse(SIGINT);
-               sigrelse(SIGHUP);
+               sigsetmask(omask);
 # else VMUNIX
                if (savesig != SIG_IGN)
                        signal(SIGINT, hf ? intack : collintsig);
                if (savehup != SIG_IGN)
                        signal(SIGHUP, collhupsig);
 # endif VMUNIX
 # else VMUNIX
                if (savesig != SIG_IGN)
                        signal(SIGINT, hf ? intack : collintsig);
                if (savehup != SIG_IGN)
                        signal(SIGHUP, collhupsig);
 # endif VMUNIX
-               flush();
+               fflush(stdout);
+               if (getsub) {
+                       grabh(hp, GSUBJECT);
+                       getsub = 0;
+                       continue;
+               }
                if (readline(stdin, linebuf) <= 0) {
                        if (intty && value("ignoreeof") != NOSTR) {
                                if (++eof > 35)
                if (readline(stdin, linebuf) <= 0) {
                        if (intty && value("ignoreeof") != NOSTR) {
                                if (++eof > 35)
@@ -275,7 +280,7 @@ collect(hp)
                                break;
                        }
                        printf("\"%s\" ", cp);
                                break;
                        }
                        printf("\"%s\" ", cp);
-                       flush();
+                       fflush(stdout);
                        lc = 0;
                        cc = 0;
                        while (readline(fbuf, linebuf) > 0) {
                        lc = 0;
                        cc = 0;
                        while (readline(fbuf, linebuf) > 0) {
@@ -332,7 +337,7 @@ collect(hp)
 
                case '?':
                        if ((fbuf = fopen(THELPFILE, "r")) == NULL) {
 
                case '?':
                        if ((fbuf = fopen(THELPFILE, "r")) == NULL) {
-                               printf("No help just now.\n");
+                               perror(THELPFILE);
                                break;
                        }
                        t = getc(fbuf);
                                break;
                        }
                        t = getc(fbuf);
@@ -389,7 +394,6 @@ collect(hp)
                        ibuf = newi;
                        printf("(continue)\n");
                        break;
                        ibuf = newi;
                        printf("(continue)\n");
                        break;
-                       break;
                }
        }
 eofl:
                }
        }
 eofl:
@@ -399,6 +403,7 @@ eofl:
        sigset(SIGHUP, savehup);
 # ifdef VMUNIX
        sigset(SIGCONT, savecont);
        sigset(SIGHUP, savehup);
 # ifdef VMUNIX
        sigset(SIGCONT, savecont);
+       sigsetmask(0);
 # endif VMUNIX
        noreset = 0;
        return(ibuf);
 # endif VMUNIX
        noreset = 0;
        return(ibuf);
@@ -412,6 +417,7 @@ err:
        sigset(SIGHUP, savehup);
 # ifdef VMUNIX
        sigset(SIGCONT, savecont);
        sigset(SIGHUP, savehup);
 # ifdef VMUNIX
        sigset(SIGCONT, savecont);
+       sigsetmask(0);
 # endif VMUNIX
        noreset = 0;
        return(NULL);
 # endif VMUNIX
        noreset = 0;
        return(NULL);
@@ -492,14 +498,14 @@ mesedit(ibuf, obuf, c)
        int pid, s;
        FILE *fbuf;
        register int t;
        int pid, s;
        FILE *fbuf;
        register int t;
-       int (*sig)(), (*scont)(), foonly();
+       int (*sig)(), (*scont)(), signull();
        struct stat sbuf;
        extern char tempMail[], tempEdit[];
        register char *edit;
 
        sig = sigset(SIGINT, SIG_IGN);
 # ifdef VMUNIX
        struct stat sbuf;
        extern char tempMail[], tempEdit[];
        register char *edit;
 
        sig = sigset(SIGINT, SIG_IGN);
 # ifdef VMUNIX
-       scont = sigset(SIGCONT, foonly);
+       scont = sigset(SIGCONT, signull);
 # endif VMUNIX
        if (stat(tempEdit, &sbuf) >= 0) {
                printf("%s: file exists\n", tempEdit);
 # endif VMUNIX
        if (stat(tempEdit, &sbuf) >= 0) {
                printf("%s: file exists\n", tempEdit);
@@ -579,13 +585,6 @@ out:
        return(obuf);
 }
 
        return(obuf);
 }
 
-/*
- * Currently, Berkeley virtual VAX/UNIX will not let you change the
- * disposition of SIGCONT, except to trap it somewhere new.
- * Hence, sigset(SIGCONT, foonly) is used to ignore continue signals.
- */
-foonly() {}
-
 /*
  * Pipe the message through the command.
  * Old message is on stdin of command;
 /*
  * Pipe the message through the command.
  * Old message is on stdin of command;
@@ -702,7 +701,7 @@ forward(ms, obuf, f)
                touch(*ip);
                printf(" %d", *ip);
                if (f == 'm') {
                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);
                        }
                                perror(tempMail);
                                return(-1);
                        }
@@ -723,28 +722,30 @@ forward(ms, obuf, f)
  * on error.
  */
 
  * on error.
  */
 
+long
 transmit(mailp, obuf)
        struct message *mailp;
        FILE *obuf;
 {
        register struct message *mp;
 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);
        FILE *ibuf;
 
        mp = mailp;
        ibuf = setinput(mp);
-       c = msize(mp);
+       c = mp->m_size;
        n = c;
        bol = 1;
        n = c;
        bol = 1;
-       while (c-- > 0) {
+       while (c-- > 0L) {
                if (bol) {
                        bol = 0;
                        putc('\t', obuf);
                        n++;
                        if (ferror(obuf)) {
                                perror("/tmp");
                if (bol) {
                        bol = 0;
                        putc('\t', obuf);
                        n++;
                        if (ferror(obuf)) {
                                perror("/tmp");
-                               return(-1);
+                               return(-1L);
                        }
                }
                ch = getc(ibuf);
                        }
                }
                ch = getc(ibuf);
@@ -753,7 +754,7 @@ transmit(mailp, obuf)
                putc(ch, obuf);
                if (ferror(obuf)) {
                        perror("/tmp");
                putc(ch, obuf);
                if (ferror(obuf)) {
                        perror("/tmp");
-                       return(-1);
+                       return(-1L);
                }
        }
        return(n);
                }
        }
        return(n);
@@ -798,11 +799,8 @@ collrub(s)
 
        if (s == SIGINT && hadintr == 0) {
                hadintr++;
 
        if (s == SIGINT && hadintr == 0) {
                hadintr++;
-               clrbuf(stdout);
-               printf("\n(Interrupt -- one more to kill letter)\n");
-# ifdef VMUNIX
-               sigrelse(s);
-# endif VMUNIX
+               fflush(stdout);
+               fprintf(stderr, "\n(Interrupt -- one more to kill letter)\n");
                longjmp(coljmp, 1);
        }
        fclose(newo);
                longjmp(coljmp, 1);
        }
        fclose(newo);