use shell="" instead of shell=none for no shell,
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index c6320dd..cdb94fb 100644 (file)
@@ -1,7 +1,22 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * 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.
+ */
+
+#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
@@ -9,8 +24,6 @@
  * More user commands.
  */
 
  * More user commands.
  */
 
-static char *SccsId = "@(#)cmd2.c      2.7 %G%";
-
 /*
  * If any arguments were given, go to the next applicable argument
  * following dot, otherwise, go to the next applicable message.
 /*
  * If any arguments were given, go to the next applicable argument
  * following dot, otherwise, go to the next applicable message.
@@ -122,7 +135,8 @@ save1(str, mark)
        register int *ip, mesg;
        register struct message *mp;
        char *file, *disp, *cmd;
        register int *ip, mesg;
        register struct message *mp;
        char *file, *disp, *cmd;
-       int f, *msgvec, lc, cc, t;
+       int f, *msgvec, lc, t;
+       long cc;
        FILE *obuf;
        struct stat statb;
 
        FILE *obuf;
        struct stat statb;
 
@@ -143,7 +157,7 @@ save1(str, mark)
        if ((file = expand(file)) == NOSTR)
                return(1);
        printf("\"%s\" ", file);
        if ((file = expand(file)) == NOSTR)
                return(1);
        printf("\"%s\" ", file);
-       flush();
+       fflush(stdout);
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
@@ -152,18 +166,19 @@ save1(str, mark)
                perror(NOSTR);
                return(1);
        }
                perror(NOSTR);
                return(1);
        }
-       cc = lc = 0;
+       cc = 0L;
+       lc = 0;
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                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);
                }
                lc += t;
                        perror(file);
                        fclose(obuf);
                        return(1);
                }
                lc += t;
-               cc += msize(mp);
+               cc += mp->m_size;
                if (mark)
                        mp->m_flag |= MSAVED;
        }
                if (mark)
                        mp->m_flag |= MSAVED;
        }
@@ -171,7 +186,7 @@ save1(str, mark)
        if (ferror(obuf))
                perror(file);
        fclose(obuf);
        if (ferror(obuf))
                perror(file);
        fclose(obuf);
-       printf("%s %d/%d\n", disp, lc, cc);
+       printf("%s %d/%ld\n", disp, lc, cc);
        return(0);
 }
 
        return(0);
 }
 
@@ -207,7 +222,7 @@ swrite(str)
        if (f && getmsglist(str, msgvec, 0) < 0)
                return(1);
        printf("\"%s\" ", file);
        if (f && getmsglist(str, msgvec, 0) < 0)
                return(1);
        printf("\"%s\" ", file);
-       flush();
+       fflush(stdout);
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
        if (stat(file, &statb) >= 0)
                disp = "[Appended]";
        else
@@ -222,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);
@@ -263,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;
 
@@ -271,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;
@@ -392,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);
        }
@@ -407,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;
 }
 
 /*
 }
 
 /*
@@ -443,6 +462,17 @@ clob1(n)
        clob1(n - 1);
 }
 
        clob1(n - 1);
 }
 
+/*
+ * Add the given header fields to the retained list.
+ * If no arguments, print the current list of retained fields.
+ */
+retfield(list)
+       char *list[];
+{
+
+       return ignore1(list, ignore + 1, "retained");
+}
+
 /*
  * Add the given header fields to the ignored list.
  * If no arguments, print the current list of ignored fields.
 /*
  * Add the given header fields to the ignored list.
  * If no arguments, print the current list of ignored fields.
@@ -450,40 +480,86 @@ clob1(n)
 igfield(list)
        char *list[];
 {
 igfield(list)
        char *list[];
 {
+
+       return ignore1(list, ignore, "ignored");
+}
+
+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[];
+       struct ignoretab *tab;
+       char *which;
+{
        char field[BUFSIZ];
        register int h;
        register struct ignore *igp;
        char **ap;
 
        if (argcount(list) == 0)
        char field[BUFSIZ];
        register int h;
        register struct ignore *igp;
        char **ap;
 
        if (argcount(list) == 0)
-               return(igshow());
+               return igshow(tab, which);
        for (ap = list; *ap != 0; ap++) {
                istrcpy(field, *ap);
        for (ap = list; *ap != 0; 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, did;
+       register int h;
        struct ignore *igp;
        struct ignore *igp;
+       char **ap, **ring;
+       int igcomp();
 
 
-       did = 0;
+       if (tab->i_count == 0) {
+               printf("No fields currently being %s.\n", which);
+               return 0;
+       }
+       ring = (char **) salloc((tab->i_count + 1) * sizeof (char *));
+       ap = ring;
        for (h = 0; h < HSHSIZE; h++)
        for (h = 0; h < HSHSIZE; h++)
-               for (igp = ignore[h]; igp != 0; igp = igp->i_link) {
-                       printf("%s\n", igp->i_field);
-                       did++;
-               }
-       if (!did)
-               printf("No fields currently being ignored.\n");
-       return(0);
+               for (igp = tab->i_head[h]; igp != 0; igp = igp->i_link)
+                       *ap++ = igp->i_field;
+       *ap = 0;
+       qsort((char *) ring, tab->i_count, sizeof (char *), igcomp);
+       for (ap = ring; *ap != 0; ap++)
+               printf("%s\n", *ap);
+       return 0;
+}
+
+/*
+ * Compare two names for sorting ignored field list.
+ */
+igcomp(l, r)
+       char **l, **r;
+{
+
+       return strcmp(*l, *r);
 }
 }