rationalized handling of child processes, cleaned up mail1 some more
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index 761fcb6..825da0d 100644 (file)
@@ -3,20 +3,23 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * 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.
+ * 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.
  */
 
  */
 
-#ifdef notdef
-static char sccsid[] = "@(#)cmd1.c     5.9 (Berkeley) %G%";
-#endif /* notdef */
+#ifndef lint
+static char sccsid[] = "@(#)cmd1.c     5.15 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "rcv.h"
 
 #include "rcv.h"
-#include <sys/stat.h>
-#include <sys/wait.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -60,7 +63,6 @@ headers(msgvec)
                if (flag++ >= size)
                        break;
                printhead(mesg);
                if (flag++ >= size)
                        break;
                printhead(mesg);
-               sreset();
        }
        if (flag == 0) {
                printf("No more mail.\n");
        }
        if (flag == 0) {
                printf("No more mail.\n");
@@ -69,40 +71,9 @@ headers(msgvec)
        return(0);
 }
 
        return(0);
 }
 
-/*
- * Set the list of alternate names for out host.
- */
-local(namelist)
-       char **namelist;
-{
-       register int c;
-       register char **ap, **ap2, *cp;
-
-       c = argcount(namelist) + 1;
-       if (c == 1) {
-               if (localnames == 0)
-                       return(0);
-               for (ap = localnames; *ap; ap++)
-                       printf("%s ", *ap);
-               printf("\n");
-               return(0);
-       }
-       if (localnames != 0)
-               cfree((char *) localnames);
-       localnames = (char **) calloc((unsigned) c, sizeof (char *));
-       for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
-               cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char));
-               strcpy(cp, *ap);
-               *ap2 = cp;
-       }
-       *ap2 = 0;
-       return(0);
-}
-
 /*
  * Scroll to the next/previous screen
  */
 /*
  * Scroll to the next/previous screen
  */
-
 scroll(arg)
        char arg[];
 {
 scroll(arg)
        char arg[];
 {
@@ -161,10 +132,8 @@ from(msgvec)
 {
        register int *ip;
 
 {
        register int *ip;
 
-       for (ip = msgvec; *ip != NULL; ip++) {
+       for (ip = msgvec; *ip != NULL; ip++)
                printhead(*ip);
                printhead(*ip);
-               sreset();
-       }
        if (--ip >= msgvec)
                dot = &message[*ip - 1];
        return(0);
        if (--ip >= msgvec)
                dot = &message[*ip - 1];
        return(0);
@@ -308,7 +277,7 @@ type1(msgvec, doign, page)
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
                        pipef = NULL;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
                        pipef = NULL;
-                       pclose(obuf);
+                       Pclose(obuf);
                }
                signal(SIGPIPE, SIG_DFL);
                return(0);
                }
                signal(SIGPIPE, SIG_DFL);
                return(0);
@@ -324,7 +293,7 @@ type1(msgvec, doign, page)
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
                                cp = MORE;
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
                                cp = MORE;
-                       obuf = popen(cp, "w");
+                       obuf = Popen(cp, "w");
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
@@ -341,11 +310,11 @@ type1(msgvec, doign, page)
                dot = mp;
                if (value("quiet") == NOSTR)
                        fprintf(obuf, "Message %d:\n", mesg);
                dot = mp;
                if (value("quiet") == NOSTR)
                        fprintf(obuf, "Message %d:\n", mesg);
-               send(mp, obuf, doign ? ignore : 0);
+               (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
        if (obuf != stdout) {
                pipef = NULL;
        }
        if (obuf != stdout) {
                pipef = NULL;
-               pclose(obuf);
+               Pclose(obuf);
        }
        signal(SIGPIPE, SIG_DFL);
        return(0);
        }
        signal(SIGPIPE, SIG_DFL);
        return(0);
@@ -447,25 +416,14 @@ mboxit(msgvec)
 folders()
 {
        char dirname[BUFSIZ];
 folders()
 {
        char dirname[BUFSIZ];
-       int pid, e;
-       union wait s;
+       char *cmd;
 
        if (getfold(dirname) < 0) {
                printf("No value set for \"folder\"\n");
 
        if (getfold(dirname) < 0) {
                printf("No value set for \"folder\"\n");
-               return(-1);
+               return -1;
        }
        }
-       switch ((pid = fork())) {
-       case 0:
-               execlp("ls", "ls", dirname, 0);
-               _exit(1);
-
-       case -1:
-               perror("fork");
-               return(-1);
-
-       default:
-               while ((e = wait(&s)) != -1 && e != pid)
-                       ;
-       }
-       return(0);
+       if ((cmd = value("LISTER")) == NOSTR)
+               cmd = "ls";
+       (void) run_command(cmd, 0, -1, -1, dirname, NOSTR);
+       return 0;
 }
 }