Modified to use perror() to report open failure on THELPFILE
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index 9b8135e..35dedb0 100644 (file)
@@ -9,7 +9,7 @@
  * More user commands.
  */
 
  * More user commands.
  */
 
-static char *SccsId = "@(#)cmd2.c      1.4 %G%";
+static char *SccsId = "@(#)cmd2.c      2.10 %G%";
 
 /*
  * If any arguments were given, go to the next applicable argument
 
 /*
  * If any arguments were given, go to the next applicable argument
@@ -92,26 +92,49 @@ hitit:
 }
 
 /*
 }
 
 /*
- * Save the indicated messages at the end of the passed file name.
+ * Save a message in a file.  Mark the message as saved
+ * so we can discard when the user quits.
  */
  */
-
 save(str)
        char str[];
 {
 save(str)
        char str[];
 {
+
+       return(save1(str, 1));
+}
+
+/*
+ * Copy a message to a file without affected its saved-ness
+ */
+copycmd(str)
+       char str[];
+{
+
+       return(save1(str, 0));
+}
+
+/*
+ * Save/copy the indicated messages at the end of the passed file name.
+ * If mark is true, mark the message "saved."
+ */
+save1(str, mark)
+       char str[];
+{
        register int *ip, mesg;
        register struct message *mp;
        register int *ip, mesg;
        register struct message *mp;
-       char *file, *disp;
-       int f, *msgvec, lc, cc, t;
+       char *file, *disp, *cmd;
+       int f, *msgvec, lc, t;
+       long cc;
        FILE *obuf;
        struct stat statb;
 
        FILE *obuf;
        struct stat statb;
 
+       cmd = mark ? "save" : "copy";
        msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
        if ((file = snarf(str, &f)) == NOSTR)
                return(1);
        if (!f) {
                *msgvec = first(0, MMNORM);
                if (*msgvec == NULL) {
        msgvec = (int *) salloc((msgCount + 2) * sizeof *msgvec);
        if ((file = snarf(str, &f)) == NOSTR)
                return(1);
        if (!f) {
                *msgvec = first(0, MMNORM);
                if (*msgvec == NULL) {
-                       printf("No messages to save.\n");
+                       printf("No messages to %s.\n", cmd);
                        return(1);
                }
                msgvec[1] = NULL;
                        return(1);
                }
                msgvec[1] = NULL;
@@ -130,25 +153,27 @@ save(str)
                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) {
+               if ((t = send(mp, obuf, 0)) < 0) {
                        perror(file);
                        fclose(obuf);
                        return(1);
                }
                lc += t;
                        perror(file);
                        fclose(obuf);
                        return(1);
                }
                lc += t;
-               cc += msize(mp);
-               mp->m_flag |= MSAVED;
+               cc += mp->m_size;
+               if (mark)
+                       mp->m_flag |= MSAVED;
        }
        fflush(obuf);
        if (ferror(obuf))
                perror(file);
        fclose(obuf);
        }
        fflush(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);
 }
 
@@ -279,13 +304,19 @@ deltype(msgvec)
        int msgvec[];
 {
        int list[2];
        int msgvec[];
 {
        int list[2];
+       int lastdot;
 
 
+       lastdot = dot - &message[0] + 1;
        if (delm(msgvec) >= 0) {
                list[0] = dot - &message[0];
                list[0]++;
        if (delm(msgvec) >= 0) {
                list[0] = dot - &message[0];
                list[0]++;
-               touch(list[0]);
-               list[1] = NULL;
-               return(type(list));
+               if (list[0] > lastdot) {
+                       touch(list[0]);
+                       list[1] = NULL;
+                       return(type(list));
+               }
+               printf("At EOF\n");
+               return(0);
        }
        else {
                printf("No more messages\n");
        }
        else {
                printf("No more messages\n");
@@ -370,6 +401,7 @@ core()
                return(1);
        }
        if (pid == 0) {
                return(1);
        }
        if (pid == 0) {
+               sigchild();
                abort();
                _exit(1);
        }
                abort();
                _exit(1);
        }
@@ -382,3 +414,101 @@ core()
        else
                printf("\n");
 }
        else
                printf("\n");
 }
+
+/*
+ * Clobber as many bytes of stack as the user requests.
+ */
+clobber(argv)
+       char **argv;
+{
+       register int times;
+
+       if (argv[0] == 0)
+               times = 1;
+       else
+               times = (atoi(argv[0]) + 511) / 512;
+       clob1(times);
+}
+
+/*
+ * Clobber the stack.
+ */
+clob1(n)
+{
+       char buf[512];
+       register char *cp;
+
+       if (n <= 0)
+               return;
+       for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
+               ;
+       clob1(n - 1);
+}
+
+/*
+ * Add the given header fields to the ignored list.
+ * If no arguments, print the current list of ignored fields.
+ */
+igfield(list)
+       char *list[];
+{
+       char field[BUFSIZ];
+       register int h;
+       register struct ignore *igp;
+       char **ap;
+
+       if (argcount(list) == 0)
+               return(igshow());
+       for (ap = list; *ap != 0; ap++) {
+               if (isign(*ap))
+                       continue;
+               istrcpy(field, *ap);
+               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 = ignore[h];
+               ignore[h] = igp;
+       }
+       return(0);
+}
+
+/*
+ * Print out all currently ignored fields.
+ */
+igshow()
+{
+       register int h, count;
+       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);
+       }
+       ring = (char **) salloc((count + 1) * sizeof (char *));
+       ap = ring;
+       for (h = 0; h < HSHSIZE; h++)
+               for (igp = ignore[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);
+}
+
+/*
+ * Compare two names for sorting ignored field list.
+ */
+igcomp(l, r)
+       char **l, **r;
+{
+
+       return(strcmp(*l, *r));
+}