4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / collect.c
index 2e6da16..73a0d98 100644 (file)
@@ -1,22 +1,12 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -27,7 +17,7 @@ static char sccsid[] = "@(#)collect.c 5.17 (Berkeley) %G%";
  */
 
 #include "rcv.h"
  */
 
 #include "rcv.h"
-#include <sys/stat.h>
+#include "extern.h"
 
 /*
  * Read a message from standard output and return a read file to it
 
 /*
  * Read a message from standard output and return a read file to it
@@ -40,11 +30,11 @@ static char sccsid[] = "@(#)collect.c       5.17 (Berkeley) %G%";
  * away on dead.letter.
  */
 
  * away on dead.letter.
  */
 
-static int     (*saveint)();           /* Previous SIGINT value */
-static int     (*savehup)();           /* Previous SIGHUP value */
-static int     (*savetstp)();          /* Previous SIGTSTP value */
-static int     (*savettou)();          /* Previous SIGTTOU value */
-static int     (*savettin)();          /* Previous SIGTTIN value */
+static sig_t   saveint;                /* Previous SIGINT value */
+static sig_t   savehup;                /* Previous SIGHUP value */
+static sig_t   savetstp;               /* Previous SIGTSTP value */
+static sig_t   savettou;               /* Previous SIGTTOU value */
+static sig_t   savettin;               /* Previous SIGTTIN value */
 static FILE    *collf;                 /* File for saving away */
 static int     hadintr;                /* Have seen one SIGINT so far */
 
 static FILE    *collf;                 /* File for saving away */
 static int     hadintr;                /* Have seen one SIGINT so far */
 
@@ -55,15 +45,16 @@ static      jmp_buf collabort;              /* To end collection with error */
 FILE *
 collect(hp, printheaders)
        struct header *hp;
 FILE *
 collect(hp, printheaders)
        struct header *hp;
+       int printheaders;
 {
        FILE *fbuf;
        int lc, cc, escape, eofcount;
 {
        FILE *fbuf;
        int lc, cc, escape, eofcount;
-       int collint(), collhup(), collstop();
        register int c, t;
        char linebuf[LINESIZE], *cp;
        extern char tempMail[];
        char getsub;
        int omask;
        register int c, t;
        char linebuf[LINESIZE], *cp;
        extern char tempMail[];
        char getsub;
        int omask;
+       void collint(), collhup(), collstop();
 
        collf = NULL;
        /*
 
        collf = NULL;
        /*
@@ -79,13 +70,13 @@ collect(hp, printheaders)
        savettou = signal(SIGTTOU, collstop);
        savettin = signal(SIGTTIN, collstop);
        if (setjmp(collabort) || setjmp(colljmp)) {
        savettou = signal(SIGTTOU, collstop);
        savettin = signal(SIGTTIN, collstop);
        if (setjmp(collabort) || setjmp(colljmp)) {
-               remove(tempMail);
+               rm(tempMail);
                goto err;
        }
        sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
 
        noreset++;
                goto err;
        }
        sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
 
        noreset++;
-       if ((collf = fopen(tempMail, "w+")) == NULL) {
+       if ((collf = Fopen(tempMail, "w+")) == NULL) {
                perror(tempMail);
                goto err;
        }
                perror(tempMail);
                goto err;
        }
@@ -257,7 +248,7 @@ cont:
                                printf("%s: Directory\n", cp);
                                break;
                        }
                                printf("%s: Directory\n", cp);
                                break;
                        }
-                       if ((fbuf = fopen(cp, "r")) == NULL) {
+                       if ((fbuf = Fopen(cp, "r")) == NULL) {
                                perror(cp);
                                break;
                        }
                                perror(cp);
                                break;
                        }
@@ -268,12 +259,12 @@ cont:
                        while (readline(fbuf, linebuf, LINESIZE) >= 0) {
                                lc++;
                                if ((t = putline(collf, linebuf)) < 0) {
                        while (readline(fbuf, linebuf, LINESIZE) >= 0) {
                                lc++;
                                if ((t = putline(collf, linebuf)) < 0) {
-                                       fclose(fbuf);
+                                       Fclose(fbuf);
                                        goto err;
                                }
                                cc += t;
                        }
                                        goto err;
                                }
                                cc += t;
                        }
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        printf("%d/%d\n", lc, cc);
                        break;
                case 'w':
                        printf("%d/%d\n", lc, cc);
                        break;
                case 'w':
@@ -306,13 +297,13 @@ cont:
                                goto err;
                        goto cont;
                case '?':
                                goto err;
                        goto cont;
                case '?':
-                       if ((fbuf = fopen(THELPFILE, "r")) == NULL) {
-                               perror(THELPFILE);
+                       if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
+                               perror(_PATH_TILDE);
                                break;
                        }
                        while ((t = getc(fbuf)) != EOF)
                                (void) putchar(t);
                                break;
                        }
                        while ((t = getc(fbuf)) != EOF)
                                (void) putchar(t);
-                       fclose(fbuf);
+                       Fclose(fbuf);
                        break;
                case 'p':
                        /*
                        break;
                case 'p':
                        /*
@@ -348,7 +339,7 @@ cont:
        goto out;
 err:
        if (collf != NULL) {
        goto out;
 err:
        if (collf != NULL) {
-               fclose(collf);
+               Fclose(collf);
                collf = NULL;
        }
 out:
                collf = NULL;
        }
 out:
@@ -368,10 +359,11 @@ out:
 /*
  * Write a file, ex-like if f set.
  */
 /*
  * Write a file, ex-like if f set.
  */
-
+int
 exwrite(name, fp, f)
        char name[];
        FILE *fp;
 exwrite(name, fp, f)
        char name[];
        FILE *fp;
+       int f;
 {
        register FILE *of;
        register int c;
 {
        register FILE *of;
        register int c;
@@ -389,7 +381,7 @@ exwrite(name, fp, f)
                fprintf(stderr, "File exists\n");
                return(-1);
        }
                fprintf(stderr, "File exists\n");
                return(-1);
        }
-       if ((of = fopen(name, "w")) == NULL) {
+       if ((of = Fopen(name, "w")) == NULL) {
                perror(NOSTR);
                return(-1);
        }
                perror(NOSTR);
                return(-1);
        }
@@ -402,11 +394,11 @@ exwrite(name, fp, f)
                (void) putc(c, of);
                if (ferror(of)) {
                        perror(name);
                (void) putc(c, of);
                if (ferror(of)) {
                        perror(name);
-                       fclose(of);
+                       Fclose(of);
                        return(-1);
                }
        }
                        return(-1);
                }
        }
-       fclose(of);
+       Fclose(of);
        printf("%d/%ld\n", lc, cc);
        fflush(stdout);
        return(0);
        printf("%d/%ld\n", lc, cc);
        fflush(stdout);
        return(0);
@@ -416,16 +408,18 @@ exwrite(name, fp, f)
  * Edit the message being collected on fp.
  * On return, make the edit file the new temp file.
  */
  * Edit the message being collected on fp.
  * On return, make the edit file the new temp file.
  */
+void
 mesedit(fp, c)
        FILE *fp;
 mesedit(fp, c)
        FILE *fp;
+       int c;
 {
 {
-       int (*sigint)() = signal(SIGINT, SIG_IGN);
+       sig_t sigint = signal(SIGINT, SIG_IGN);
        FILE *nf = run_editor(fp, (off_t)-1, c, 0);
 
        if (nf != NULL) {
        FILE *nf = run_editor(fp, (off_t)-1, c, 0);
 
        if (nf != NULL) {
-               fseek(nf, (off_t)0, 2);
+               fseek(nf, 0L, 2);
                collf = nf;
                collf = nf;
-               fclose(fp);
+               Fclose(fp);
        }
        (void) signal(SIGINT, sigint);
 }
        }
        (void) signal(SIGINT, sigint);
 }
@@ -436,15 +430,16 @@ mesedit(fp, c)
  * New message collected from stdout.
  * Sh -c must return 0 to accept the new message.
  */
  * New message collected from stdout.
  * Sh -c must return 0 to accept the new message.
  */
+void
 mespipe(fp, cmd)
        FILE *fp;
        char cmd[];
 {
        FILE *nf;
 mespipe(fp, cmd)
        FILE *fp;
        char cmd[];
 {
        FILE *nf;
-       int (*sigint)() = signal(SIGINT, SIG_IGN);
+       sig_t sigint = signal(SIGINT, SIG_IGN);
        extern char tempEdit[];
 
        extern char tempEdit[];
 
-       if ((nf = fopen(tempEdit, "w+")) == NULL) {
+       if ((nf = Fopen(tempEdit, "w+")) == NULL) {
                perror(tempEdit);
                goto out;
        }
                perror(tempEdit);
                goto out;
        }
@@ -453,13 +448,14 @@ mespipe(fp, cmd)
         * stdin = current message.
         * stdout = new message.
         */
         * stdin = current message.
         * stdout = new message.
         */
-       if (run_command(cmd, 0, fileno(fp), fileno(nf), NOSTR) < 0) {
-               (void) fclose(nf);
+       if (run_command(cmd,
+           0, fileno(fp), fileno(nf), NOSTR, NOSTR, NOSTR) < 0) {
+               (void) Fclose(nf);
                goto out;
        }
        if (fsize(nf) == 0) {
                fprintf(stderr, "No bytes from \"%s\" !?\n", cmd);
                goto out;
        }
        if (fsize(nf) == 0) {
                fprintf(stderr, "No bytes from \"%s\" !?\n", cmd);
-               (void) fclose(nf);
+               (void) Fclose(nf);
                goto out;
        }
        /*
                goto out;
        }
        /*
@@ -467,7 +463,7 @@ mespipe(fp, cmd)
         */
        (void) fseek(nf, 0L, 2);
        collf = nf;
         */
        (void) fseek(nf, 0L, 2);
        collf = nf;
-       (void) fclose(fp);
+       (void) Fclose(fp);
 out:
        (void) signal(SIGINT, sigint);
 }
 out:
        (void) signal(SIGINT, sigint);
 }
@@ -480,9 +476,11 @@ out:
  * the message temporary.  The flag argument is 'm' if we
  * should shift over and 'f' if not.
  */
  * the message temporary.  The flag argument is 'm' if we
  * should shift over and 'f' if not.
  */
+int
 forward(ms, fp, f)
        char ms[];
        FILE *fp;
 forward(ms, fp, f)
        char ms[];
        FILE *fp;
+       int f;
 {
        register int *msgvec;
        extern char tempMail[];
 {
        register int *msgvec;
        extern char tempMail[];
@@ -504,7 +502,7 @@ forward(ms, fp, f)
        }
        if (f == 'f' || f == 'F')
                tabst = NOSTR;
        }
        if (f == 'f' || f == 'F')
                tabst = NOSTR;
-       else if ((tabst = value("tabstr")) == NOSTR)
+       else if ((tabst = value("indentprefix")) == NOSTR)
                tabst = "\t";
        ig = isupper(f) ? NULL : ignore;
        printf("Interpolating:");
                tabst = "\t";
        ig = isupper(f) ? NULL : ignore;
        printf("Interpolating:");
@@ -526,9 +524,11 @@ forward(ms, fp, f)
  * Print (continue) when continued after ^Z.
  */
 /*ARGSUSED*/
  * Print (continue) when continued after ^Z.
  */
 /*ARGSUSED*/
+void
 collstop(s)
 collstop(s)
+       int s;
 {
 {
-       int (*old_action)() = signal(s, SIG_DFL);
+       sig_t old_action = signal(s, SIG_DFL);
 
        sigsetmask(sigblock(0) & ~sigmask(s));
        kill(0, s);
 
        sigsetmask(sigblock(0) & ~sigmask(s));
        kill(0, s);
@@ -546,7 +546,9 @@ collstop(s)
  * Then jump out of the collection loop.
  */
 /*ARGSUSED*/
  * Then jump out of the collection loop.
  */
 /*ARGSUSED*/
+void
 collint(s)
 collint(s)
+       int s;
 {
        /*
         * the control flow is subtle, because we can be called from ~q.
 {
        /*
         * the control flow is subtle, because we can be called from ~q.
@@ -568,7 +570,9 @@ collint(s)
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
+void
 collhup(s)
 collhup(s)
+       int s;
 {
        rewind(collf);
        savedeadletter(collf);
 {
        rewind(collf);
        savedeadletter(collf);
@@ -579,6 +583,7 @@ collhup(s)
        exit(1);
 }
 
        exit(1);
 }
 
+void
 savedeadletter(fp)
        register FILE *fp;
 {
 savedeadletter(fp)
        register FILE *fp;
 {
@@ -590,12 +595,12 @@ savedeadletter(fp)
                return;
        cp = getdeadletter();
        c = umask(077);
                return;
        cp = getdeadletter();
        c = umask(077);
-       dbuf = fopen(cp, "a");
+       dbuf = Fopen(cp, "a");
        (void) umask(c);
        if (dbuf == NULL)
                return;
        while ((c = getc(fp)) != EOF)
                (void) putc(c, dbuf);
        (void) umask(c);
        if (dbuf == NULL)
                return;
        while ((c = getc(fp)) != EOF)
                (void) putc(c, dbuf);
-       fclose(dbuf);
+       Fclose(dbuf);
        rewind(fp);
 }
        rewind(fp);
 }