changed file() to call setfile() with proper arg for isedit;
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index 9b8135e..9d163ac 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.4 %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,48 @@ 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;
+       char *file, *disp, *cmd;
        int f, *msgvec, lc, cc, t;
        FILE *obuf;
        struct stat statb;
 
        int f, *msgvec, lc, cc, t;
        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;
@@ -142,7 +164,8 @@ save(str)
                }
                lc += t;
                cc += msize(mp);
                }
                lc += t;
                cc += msize(mp);
-               mp->m_flag |= MSAVED;
+               if (mark)
+                       mp->m_flag |= MSAVED;
        }
        fflush(obuf);
        if (ferror(obuf))
        }
        fflush(obuf);
        if (ferror(obuf))
@@ -279,13 +302,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");
@@ -382,3 +411,33 @@ 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;
+       clobber1(times);
+}
+
+/*
+ * Clobber the stack.
+ */
+clobber1(n)
+{
+       char buf[512];
+       register char *cp;
+
+       if (n <= 0)
+               return;
+       for (cp = buf; cp < &buf[512]; *cp++ = 0xFF)
+               ;
+       clobber1(n - 1);
+}