use shell="" instead of shell=none for no shell,
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index 987f17b..cdb94fb 100644 (file)
@@ -1,15 +1,22 @@
 /*
  * Copyright (c) 1980 Regents of the University of California.
 /*
  * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at 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'' without express or implied warranty.
  */
 
  */
 
-#ifndef lint
-static char *sccsid = "@(#)cmd2.c      5.2 (Berkeley) %G%";
-#endif not lint
+#ifdef notdef
+static char sccsid[] = "@(#)cmd2.c     5.6 (Berkeley) %G%";
+#endif /* notdef */
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
+#include <sys/wait.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -165,7 +172,7 @@ save1(str, mark)
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
-               if ((t = send(mp, obuf, 0)) < 0) {
+               if ((t = send(mp, obuf, saveignore)) < 0) {
                        perror(file);
                        fclose(obuf);
                        return(1);
                        perror(file);
                        fclose(obuf);
                        return(1);
@@ -230,8 +237,12 @@ swrite(str)
                touch(mesg);
                mp = &message[mesg-1];
                mesf = setinput(mp);
                touch(mesg);
                mp = &message[mesg-1];
                mesf = setinput(mp);
-               t = mp->m_lines - 2;
-               readline(mesf, linebuf);
+               t = mp->m_lines - 1;
+               while (t-- > 0) {
+                       readline(mesf, linebuf);
+                       if (blankline(linebuf))
+                               break;
+               }
                while (t-- > 0) {
                        fgets(linebuf, BUFSIZ, mesf);
                        fputs(linebuf, obuf);
                while (t-- > 0) {
                        fgets(linebuf, BUFSIZ, mesf);
                        fputs(linebuf, obuf);
@@ -271,7 +282,7 @@ snarf(linebuf, flag)
         * Strip away trailing blanks.
         */
 
         * Strip away trailing blanks.
         */
 
-       while (*cp == ' ' && cp > linebuf)
+       while (cp > linebuf && isspace(*cp))
                cp--;
        *++cp = 0;
 
                cp--;
        *++cp = 0;
 
@@ -279,13 +290,13 @@ snarf(linebuf, flag)
         * Now search for the beginning of the file name.
         */
 
         * Now search for the beginning of the file name.
         */
 
-       while (cp > linebuf && !any(*cp, "\t "))
+       while (cp > linebuf && !isspace(*cp))
                cp--;
        if (*cp == '\0') {
                printf("No file specified.\n");
                return(NOSTR);
        }
                cp--;
        if (*cp == '\0') {
                printf("No file specified.\n");
                return(NOSTR);
        }
-       if (any(*cp, " \t"))
+       if (isspace(*cp))
                *cp++ = 0;
        else
                *flag = 0;
                *cp++ = 0;
        else
                *flag = 0;
@@ -400,14 +411,13 @@ undelete(msgvec)
 core()
 {
        register int pid;
 core()
 {
        register int pid;
-       int status;
+       union wait status;
 
        if ((pid = vfork()) == -1) {
                perror("fork");
                return(1);
        }
        if (pid == 0) {
 
        if ((pid = vfork()) == -1) {
                perror("fork");
                return(1);
        }
        if (pid == 0) {
-               sigchild();
                abort();
                _exit(1);
        }
                abort();
                _exit(1);
        }
@@ -415,10 +425,11 @@ core()
        fflush(stdout);
        while (wait(&status) != pid)
                ;
        fflush(stdout);
        while (wait(&status) != pid)
                ;
-       if (status & 0200)
+       if (status.w_coredump)
                printf(" -- Core dumped\n");
        else
                printf("\n");
                printf(" -- Core dumped\n");
        else
                printf("\n");
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -458,66 +469,39 @@ clob1(n)
 retfield(list)
        char *list[];
 {
 retfield(list)
        char *list[];
 {
-       char field[BUFSIZ];
-       register int h;
-       register struct ignore *igp;
-       char **ap;
 
 
-       if (argcount(list) == 0)
-               return(retshow());
-       for (ap = list; *ap != 0; ap++) {
-               istrcpy(field, *ap);
-
-               if (member(field, retain))
-                       continue;
-
-               h = hash(field);
-               igp = (struct ignore *) calloc(1, sizeof (struct ignore));
-               igp->i_field = calloc(strlen(field) + 1, sizeof (char));
-               strcpy(igp->i_field, field);
-               igp->i_link = retain[h];
-               retain[h] = igp;
-               nretained++;
-       }
-       return(0);
+       return ignore1(list, ignore + 1, "retained");
 }
 
 /*
 }
 
 /*
- * Print out all currently retained fields.
+ * Add the given header fields to the ignored list.
+ * If no arguments, print the current list of ignored fields.
  */
  */
-retshow()
+igfield(list)
+       char *list[];
 {
 {
-       register int h, count;
-       struct ignore *igp;
-       char **ap, **ring;
-       int igcomp();
 
 
-       count = 0;
-       for (h = 0; h < HSHSIZE; h++)
-               for (igp = retain[h]; igp != 0; igp = igp->i_link)
-                       count++;
-       if (count == 0) {
-               printf("No fields currently being retained.\n");
-               return(0);
-       }
-       ring = (char **) salloc((count + 1) * sizeof (char *));
-       ap = ring;
-       for (h = 0; h < HSHSIZE; h++)
-               for (igp = retain[h]; igp != 0; igp = igp->i_link)
-                       *ap++ = igp->i_field;
-       *ap = 0;
-       qsort(ring, count, sizeof (char *), igcomp);
-       for (ap = ring; *ap != 0; ap++)
-               printf("%s\n", *ap);
-       return(0);
+       return ignore1(list, ignore, "ignored");
 }
 
 }
 
-/*
- * Add the given header fields to the ignored list.
- * If no arguments, print the current list of ignored fields.
- */
-igfield(list)
+saveretfield(list)
+       char *list[];
+{
+
+       return ignore1(list, saveignore + 1, "retained");
+}
+
+saveigfield(list)
+       char *list[];
+{
+
+       return ignore1(list, saveignore, "ignored");
+}
+
+ignore1(list, tab, which)
        char *list[];
        char *list[];
+       struct ignoretab *tab;
+       char *which;
 {
        char field[BUFSIZ];
        register int h;
 {
        char field[BUFSIZ];
        register int h;
@@ -525,49 +509,49 @@ igfield(list)
        char **ap;
 
        if (argcount(list) == 0)
        char **ap;
 
        if (argcount(list) == 0)
-               return(igshow());
+               return igshow(tab, which);
        for (ap = list; *ap != 0; ap++) {
        for (ap = list; *ap != 0; ap++) {
-               if (isign(*ap))
-                       continue;
                istrcpy(field, *ap);
                istrcpy(field, *ap);
+               if (member(field, tab))
+                       continue;
                h = hash(field);
                igp = (struct ignore *) calloc(1, sizeof (struct ignore));
                h = hash(field);
                igp = (struct ignore *) calloc(1, sizeof (struct ignore));
-               igp->i_field = calloc(strlen(field) + 1, sizeof (char));
+               igp->i_field = calloc((unsigned) strlen(field) + 1,
+                       sizeof (char));
                strcpy(igp->i_field, field);
                strcpy(igp->i_field, field);
-               igp->i_link = ignore[h];
-               ignore[h] = igp;
+               igp->i_link = tab->i_head[h];
+               tab->i_head[h] = igp;
+               tab->i_count++;
        }
        }
-       return(0);
+       return 0;
 }
 
 /*
 }
 
 /*
- * Print out all currently ignored fields.
+ * Print out all currently retained fields.
  */
  */
-igshow()
+igshow(tab, which)
+       struct ignoretab *tab;
+       char *which;
 {
 {
-       register int h, count;
+       register int h;
        struct ignore *igp;
        char **ap, **ring;
        int igcomp();
 
        struct ignore *igp;
        char **ap, **ring;
        int igcomp();
 
-       count = 0;
-       for (h = 0; h < HSHSIZE; h++)
-               for (igp = ignore[h]; igp != 0; igp = igp->i_link)
-                       count++;
-       if (count == 0) {
-               printf("No fields currently being ignored.\n");
-               return(0);
+       if (tab->i_count == 0) {
+               printf("No fields currently being %s.\n", which);
+               return 0;
        }
        }
-       ring = (char **) salloc((count + 1) * sizeof (char *));
+       ring = (char **) salloc((tab->i_count + 1) * sizeof (char *));
        ap = ring;
        for (h = 0; h < HSHSIZE; h++)
        ap = ring;
        for (h = 0; h < HSHSIZE; h++)
-               for (igp = ignore[h]; igp != 0; igp = igp->i_link)
+               for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link)
                        *ap++ = igp->i_field;
        *ap = 0;
                        *ap++ = igp->i_field;
        *ap = 0;
-       qsort(ring, count, sizeof (char *), igcomp);
+       qsort((char *) ring, tab->i_count, sizeof (char *), igcomp);
        for (ap = ring; *ap != 0; ap++)
                printf("%s\n", *ap);
        for (ap = ring; *ap != 0; ap++)
                printf("%s\n", *ap);
-       return(0);
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -577,5 +561,5 @@ igcomp(l, r)
        char **l, **r;
 {
 
        char **l, **r;
 {
 
-       return(strcmp(*l, *r));
+       return strcmp(*l, *r);
 }
 }