file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index 14a59e3..7f1af26 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.5 (Berkeley) %G%";
-#endif /* notdef */
+#ifndef lint
+static char sccsid[] = "@(#)cmd1.c     5.19 (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);
@@ -184,7 +153,7 @@ printhead(mesg)
        int subjlen;
 
        mp = &message[mesg-1];
        int subjlen;
 
        mp = &message[mesg-1];
-       readline(setinput(mp), headline);
+       (void) readline(setinput(mp), headline, LINESIZE);
        if ((subjline = hfield("subject", mp)) == NOSTR)
                subjline = hfield("subj", mp);
        /*
        if ((subjline = hfield("subject", mp)) == NOSTR)
                subjline = hfield("subj", mp);
        /*
@@ -298,7 +267,6 @@ type1(msgvec, doign, page)
 {
        register *ip;
        register struct message *mp;
 {
        register *ip;
        register struct message *mp;
-       register int mesg;
        register char *cp;
        int nlines;
        int brokpipe();
        register char *cp;
        int nlines;
        int brokpipe();
@@ -308,22 +276,23 @@ 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);
        }
-       if (intty && outtty && (page || (cp = value("crt")) != NOSTR)) {
+       if (value("interactive") != NOSTR &&
+           (page || (cp = value("crt")) != NOSTR)) {
                nlines = 0;
                if (!page) {
                        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++)
                                nlines += message[*ip - 1].m_lines;
                }
                nlines = 0;
                if (!page) {
                        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++)
                                nlines += message[*ip - 1].m_lines;
                }
-               if (page || nlines > atoi(cp)) {
+               if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) {
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
-                               cp = MORE;
-                       obuf = popen(cp, "w");
+                               cp = _PATH_MORE;
+                       obuf = Popen(cp, "w");
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
@@ -334,17 +303,16 @@ type1(msgvec, doign, page)
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
-               mesg = *ip;
-               touch(mesg);
-               mp = &message[mesg-1];
+               mp = &message[*ip - 1];
+               touch(mp);
                dot = mp;
                if (value("quiet") == NOSTR)
                dot = mp;
                if (value("quiet") == NOSTR)
-                       fprintf(obuf, "Message %d:\n", mesg);
-               send(mp, obuf, doign);
+                       fprintf(obuf, "Message %d:\n", *ip);
+               (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);
@@ -371,7 +339,6 @@ top(msgvec)
 {
        register int *ip;
        register struct message *mp;
 {
        register int *ip;
        register struct message *mp;
-       register int mesg;
        int c, topl, lines, lineb;
        char *valtop, linebuf[LINESIZE];
        FILE *ibuf;
        int c, topl, lines, lineb;
        char *valtop, linebuf[LINESIZE];
        FILE *ibuf;
@@ -385,18 +352,17 @@ top(msgvec)
        }
        lineb = 1;
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
        }
        lineb = 1;
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
-               mesg = *ip;
-               touch(mesg);
-               mp = &message[mesg-1];
+               mp = &message[*ip - 1];
+               touch(mp);
                dot = mp;
                if (value("quiet") == NOSTR)
                dot = mp;
                if (value("quiet") == NOSTR)
-                       printf("Message %2d:\n", mesg);
+                       printf("Message %d:\n", *ip);
                ibuf = setinput(mp);
                c = mp->m_lines;
                if (!lineb)
                        printf("\n");
                for (lines = 0; lines < c && lines <= topl; lines++) {
                ibuf = setinput(mp);
                c = mp->m_lines;
                if (!lineb)
                        printf("\n");
                for (lines = 0; lines < c && lines <= topl; lines++) {
-                       if (readline(ibuf, linebuf) < 0)
+                       if (readline(ibuf, linebuf, LINESIZE) < 0)
                                break;
                        puts(linebuf);
                        lineb = blankline(linebuf);
                                break;
                        puts(linebuf);
                        lineb = blankline(linebuf);
@@ -409,7 +375,6 @@ top(msgvec)
  * Touch all the given messages so that they will
  * get mboxed.
  */
  * Touch all the given messages so that they will
  * get mboxed.
  */
-
 stouch(msgvec)
        int msgvec[];
 {
 stouch(msgvec)
        int msgvec[];
 {
@@ -446,25 +411,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);
-       }
-       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 1;
        }
        }
-       return(0);
+       if ((cmd = value("LISTER")) == NOSTR)
+               cmd = "ls";
+       (void) run_command(cmd, 0, -1, -1, dirname, NOSTR);
+       return 0;
 }
 }