changed alloca to salloc since no alloca on pdp-11's, generally
[unix-history] / usr / src / usr.bin / mail / fio.c
index 78a5683..8fb39d2 100644 (file)
@@ -10,7 +10,7 @@
  * File I/O.
  */
 
  * File I/O.
  */
 
-static char *SccsId = "@(#)fio.c       1.10 %G%";
+static char *SccsId = "@(#)fio.c       2.10 %G%";
 
 /*
  * Set up the input pointers while copying the mail file into
 
 /*
  * Set up the input pointers while copying the mail file into
@@ -42,7 +42,7 @@ setptr(ibuf)
                cp = linebuf;
                c = getc(ibuf);
                while (c != EOF && c != '\n') {
                cp = linebuf;
                c = getc(ibuf);
                while (c != EOF && c != '\n') {
-                       if (cp - linebuf >= BUFSIZ - 1) {
+                       if (cp - linebuf >= LINESIZE - 1) {
                                ungetc(c, ibuf);
                                *cp = 0;
                                break;
                                ungetc(c, ibuf);
                                *cp = 0;
                                break;
@@ -292,25 +292,33 @@ edstop()
 {
        register int gotcha, c;
        register struct message *mp;
 {
        register int gotcha, c;
        register struct message *mp;
-       FILE *obuf, *ibuf;
+       FILE *obuf, *ibuf, *readstat;
        struct stat statb;
        struct stat statb;
-       char tempname[30];
+       char tempname[30], *id;
        int (*sigs[3])();
 
        if (readonly)
                return;
        int (*sigs[3])();
 
        if (readonly)
                return;
-       sigsave(sigs, SIG_IGN);
+       holdsigs();
+       if (Tflag != NOSTR) {
+               if ((readstat = fopen(Tflag, "w")) == NULL)
+                       Tflag = NOSTR;
+       }
        for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW) {
                        mp->m_flag &= ~MNEW;
                        mp->m_flag |= MSTATUS;
                }
        for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW) {
                        mp->m_flag &= ~MNEW;
                        mp->m_flag |= MSTATUS;
                }
-               if (mp->m_flag & (MODIFY|MDELETED|MSTATUS)) {
+               if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
                        gotcha++;
                        gotcha++;
-                       break;
+               if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
+                       if ((id = hfield("article-id", mp)) != NOSTR)
+                               fprintf(readstat, "%s\n", id);
                }
        }
                }
        }
-       if (!gotcha)
+       if (Tflag != NOSTR)
+               fclose(readstat);
+       if (!gotcha || Tflag != NOSTR)
                goto done;
        ibuf = NULL;
        if (stat(editfile, &statb) >= 0 && statb.st_size > mailsize) {
                goto done;
        ibuf = NULL;
        if (stat(editfile, &statb) >= 0 && statb.st_size > mailsize) {
@@ -318,16 +326,17 @@ edstop()
                mktemp(tempname);
                if ((obuf = fopen(tempname, "w")) == NULL) {
                        perror(tempname);
                mktemp(tempname);
                if ((obuf = fopen(tempname, "w")) == NULL) {
                        perror(tempname);
-                       sigret(sigs);
+                       relsesigs();
                        reset(0);
                }
                if ((ibuf = fopen(editfile, "r")) == NULL) {
                        perror(editfile);
                        fclose(obuf);
                        remove(tempname);
                        reset(0);
                }
                if ((ibuf = fopen(editfile, "r")) == NULL) {
                        perror(editfile);
                        fclose(obuf);
                        remove(tempname);
-                       sigret(sigs);
+                       relsesigs();
                        reset(0);
                }
                        reset(0);
                }
+               fseek(ibuf, mailsize, 0);
                while ((c = getc(ibuf)) != EOF)
                        putc(c, obuf);
                fclose(ibuf);
                while ((c = getc(ibuf)) != EOF)
                        putc(c, obuf);
                fclose(ibuf);
@@ -335,7 +344,7 @@ edstop()
                if ((ibuf = fopen(tempname, "r")) == NULL) {
                        perror(tempname);
                        remove(tempname);
                if ((ibuf = fopen(tempname, "r")) == NULL) {
                        perror(tempname);
                        remove(tempname);
-                       sigret(sigs);
+                       relsesigs();
                        reset(0);
                }
                remove(tempname);
                        reset(0);
                }
                remove(tempname);
@@ -344,7 +353,7 @@ edstop()
        flush();
        if ((obuf = fopen(editfile, "w")) == NULL) {
                perror(editfile);
        flush();
        if ((obuf = fopen(editfile, "w")) == NULL) {
                perror(editfile);
-               sigret(sigs);
+               relsesigs();
                reset(0);
        }
        c = 0;
                reset(0);
        }
        c = 0;
@@ -352,9 +361,9 @@ edstop()
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
-               if (send(mp, obuf) < 0) {
+               if (send(mp, obuf, 0) < 0) {
                        perror(editfile);
                        perror(editfile);
-                       sigret(sigs);
+                       relsesigs();
                        reset(0);
                }
        }
                        reset(0);
                }
        }
@@ -367,7 +376,7 @@ edstop()
        fflush(obuf);
        if (ferror(obuf)) {
                perror(editfile);
        fflush(obuf);
        if (ferror(obuf)) {
                perror(editfile);
-               sigret(sigs);
+               relsesigs();
                reset(0);
        }
        fclose(obuf);
                reset(0);
        }
        fclose(obuf);
@@ -380,31 +389,29 @@ edstop()
        flush();
 
 done:
        flush();
 
 done:
-       sigret(sigs);
+       relsesigs();
 }
 
 /*
 }
 
 /*
- * Save signals SIGHUP - SIGQUIT in sigs, set them all to action.
+ * Hold signals SIGHUP - SIGQUIT.
  */
  */
-sigsave(sigs, action)
-       int (*sigs[])();
+holdsigs()
 {
        register int i;
 
        for (i = SIGHUP; i <= SIGQUIT; i++)
 {
        register int i;
 
        for (i = SIGHUP; i <= SIGQUIT; i++)
-               sigs[i - SIGHUP] = sigset(i, action);
+               sighold(i);
 }
 
 /*
 }
 
 /*
- * Restore SIGHUP - SIGQUIT from sigs.
+ * Release signals SIGHUP - SIGQUIT
  */
  */
-sigret(sigs)
-       int (*sigs[])();
+relsesigs()
 {
        register int i;
 {
        register int i;
-       
+
        for (i = SIGHUP; i <= SIGQUIT; i++)
        for (i = SIGHUP; i <= SIGQUIT; i++)
-               sigset(i, sigs[i - SIGHUP]);
+               sigrelse(i);
 }
 
 /*
 }
 
 /*
@@ -489,6 +496,10 @@ expand(name)
        int s, pivec[2], (*sigint)();
        struct stat sbuf;
 
        int s, pivec[2], (*sigint)();
        struct stat sbuf;
 
+       if (name[0] == '+' && getfold(cmdbuf) >= 0) {
+               sprintf(xname, "%s/%s", cmdbuf, name + 1);
+               return(expand(savestr(xname)));
+       }
        if (!anyof(name, "~{[*?$`'\"\\"))
                return(name);
        if (pipe(pivec) < 0) {
        if (!anyof(name, "~{[*?$`'\"\\"))
                return(name);
        if (pipe(pivec) < 0) {
@@ -497,6 +508,7 @@ expand(name)
        }
        sprintf(cmdbuf, "echo %s", name);
        if ((pid = vfork()) == 0) {
        }
        sprintf(cmdbuf, "echo %s", name);
        if ((pid = vfork()) == 0) {
+               sigchild();
                Shell = value("SHELL");
                if (Shell == NOSTR)
                        Shell = SHELL;
                Shell = value("SHELL");
                if (Shell == NOSTR)
                        Shell = SHELL;
@@ -550,6 +562,23 @@ err:
        return(NOSTR);
 }
 
        return(NOSTR);
 }
 
+/*
+ * Determine the current folder directory name.
+ */
+getfold(name)
+       char *name;
+{
+       char *folder;
+
+       if ((folder = value("folder")) == NOSTR)
+               return(-1);
+       if (*folder == '/')
+               strcpy(name, folder);
+       else
+               sprintf(name, "%s/%s", homedir, folder);
+       return(0);
+}
+
 /*
  * A nicer version of Fdopen, which allows us to fclose
  * without losing the open file.
 /*
  * A nicer version of Fdopen, which allows us to fclose
  * without losing the open file.