386BSD 0.1 development
[unix-history] / usr / src / usr.bin / mail / cmd2.c
index 2ac4306..9efbe4f 100644 (file)
@@ -2,21 +2,37 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd2.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd2.c     5.14 (Berkeley) 6/25/90";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -138,7 +154,7 @@ save1(str, mark, cmd, ignore)
        char *cmd;
        struct ignoretab *ignore;
 {
        char *cmd;
        struct ignoretab *ignore;
 {
-       register int *ip, mesg;
+       register int *ip;
        register struct message *mp;
        char *file, *disp;
        int f, *msgvec;
        register struct message *mp;
        char *file, *disp;
        int f, *msgvec;
@@ -165,17 +181,16 @@ save1(str, mark, cmd, ignore)
                disp = "[Appended]";
        else
                disp = "[New file]";
                disp = "[Appended]";
        else
                disp = "[New file]";
-       if ((obuf = fopen(file, "a")) == NULL) {
+       if ((obuf = Fopen(file, "a")) == NULL) {
                perror(NOSTR);
                return(1);
        }
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                perror(NOSTR);
                return(1);
        }
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
-               mesg = *ip;
-               touch(mesg);
-               mp = &message[mesg-1];
+               mp = &message[*ip - 1];
+               touch(mp);
                if (send(mp, obuf, ignore, NOSTR) < 0) {
                        perror(file);
                if (send(mp, obuf, ignore, NOSTR) < 0) {
                        perror(file);
-                       fclose(obuf);
+                       Fclose(obuf);
                        return(1);
                }
                if (mark)
                        return(1);
                }
                if (mark)
@@ -184,7 +199,7 @@ save1(str, mark, cmd, ignore)
        fflush(obuf);
        if (ferror(obuf))
                perror(file);
        fflush(obuf);
        if (ferror(obuf))
                perror(file);
-       fclose(obuf);
+       Fclose(obuf);
        printf("%s\n", disp);
        return(0);
 }
        printf("%s\n", disp);
        return(0);
 }
@@ -252,7 +267,8 @@ snarf(linebuf, flag)
 delete(msgvec)
        int msgvec[];
 {
 delete(msgvec)
        int msgvec[];
 {
-       return(delm(msgvec));
+       delm(msgvec);
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -267,20 +283,16 @@ deltype(msgvec)
 
        lastdot = dot - &message[0] + 1;
        if (delm(msgvec) >= 0) {
 
        lastdot = dot - &message[0] + 1;
        if (delm(msgvec) >= 0) {
-               list[0] = dot - &message[0];
-               list[0]++;
+               list[0] = dot - &message[0] + 1;
                if (list[0] > lastdot) {
                if (list[0] > lastdot) {
-                       touch(list[0]);
+                       touch(dot);
                        list[1] = NULL;
                        return(type(list));
                }
                printf("At EOF\n");
                        list[1] = NULL;
                        return(type(list));
                }
                printf("At EOF\n");
-               return(0);
-       }
-       else {
+       } else
                printf("No more messages\n");
                printf("No more messages\n");
-               return(0);
-       }
+       return(0);
 }
 
 /*
 }
 
 /*
@@ -293,17 +305,16 @@ delm(msgvec)
        int *msgvec;
 {
        register struct message *mp;
        int *msgvec;
 {
        register struct message *mp;
-       register *ip, mesg;
+       register *ip;
        int last;
 
        last = NULL;
        for (ip = msgvec; *ip != NULL; ip++) {
        int last;
 
        last = NULL;
        for (ip = msgvec; *ip != NULL; ip++) {
-               mesg = *ip;
-               touch(mesg);
-               mp = &message[mesg-1];
+               mp = &message[*ip - 1];
+               touch(mp);
                mp->m_flag |= MDELETED|MTOUCH;
                mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX);
                mp->m_flag |= MDELETED|MTOUCH;
                mp->m_flag &= ~(MPRESERVE|MSAVED|MBOX);
-               last = mesg;
+               last = *ip;
        }
        if (last != NULL) {
                dot = &message[last-1];
        }
        if (last != NULL) {
                dot = &message[last-1];
@@ -333,17 +344,15 @@ undelete(msgvec)
        int *msgvec;
 {
        register struct message *mp;
        int *msgvec;
 {
        register struct message *mp;
-       register *ip, mesg;
-
-       for (ip = msgvec; ip-msgvec < msgCount; ip++) {
-               mesg = *ip;
-               if (mesg == 0)
-                       return;
-               touch(mesg);
-               mp = &message[mesg-1];
+       register *ip;
+
+       for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
+               mp = &message[*ip - 1];
+               touch(mp);
                dot = mp;
                mp->m_flag &= ~MDELETED;
        }
                dot = mp;
                mp->m_flag &= ~MDELETED;
        }
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -352,25 +361,24 @@ undelete(msgvec)
 
 core()
 {
 
 core()
 {
-       register int pid;
-       union wait status;
+       int pid;
+       extern union wait wait_status;
 
 
-       if ((pid = vfork()) == -1) {
+       switch (pid = vfork()) {
+       case -1:
                perror("fork");
                return(1);
                perror("fork");
                return(1);
-       }
-       if (pid == 0) {
+       case 0:
                abort();
                _exit(1);
        }
        printf("Okie dokie");
        fflush(stdout);
                abort();
                _exit(1);
        }
        printf("Okie dokie");
        fflush(stdout);
-       while (wait(&status) != pid)
-               ;
-       if (status.w_coredump)
-               printf(" -- Core dumped\n");
+       wait_child(pid);
+       if (wait_status.w_coredump)
+               printf(" -- Core dumped.\n");
        else
        else
-               printf("\n");
+               printf(" -- Can't dump core.\n");
        return 0;
 }
 
        return 0;
 }
 
@@ -387,6 +395,7 @@ clobber(argv)
        else
                times = (atoi(argv[0]) + 511) / 512;
        clob1(times);
        else
                times = (atoi(argv[0]) + 511) / 512;
        clob1(times);
+       return 0;
 }
 
 /*
 }
 
 /*
@@ -450,7 +459,7 @@ ignore1(list, tab, which)
        register struct ignore *igp;
        char **ap;
 
        register struct ignore *igp;
        char **ap;
 
-       if (argcount(list) == 0)
+       if (*list == NOSTR)
                return igshow(tab, which);
        for (ap = list; *ap != 0; ap++) {
                istrcpy(field, *ap);
                return igshow(tab, which);
        for (ap = list; *ap != 0; ap++) {
                istrcpy(field, *ap);