file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index 942d5db..7f1af26 100644 (file)
@@ -1,6 +1,25 @@
-#
+/*
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)cmd1.c     5.19 (Berkeley) %G%";
+#endif /* not lint */
+
 #include "rcv.h"
 #include "rcv.h"
-#include <sys/stat.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -8,8 +27,6 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      2.10 %G%";
-
 /*
  * Print the current active headings.
  * Don't change dot if invoker didn't give an argument.
 /*
  * Print the current active headings.
  * Don't change dot if invoker didn't give an argument.
@@ -46,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");
@@ -55,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(c, sizeof (char *));
-       for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
-               cp = (char *) calloc(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[];
 {
@@ -125,30 +110,16 @@ scroll(arg)
 }
 
 /*
 }
 
 /*
- * Compute what the screen size should be.
- * We use the following algorithm:
- *     If user specifies with screen option, use that.
- *     If baud rate < 1200, use  5
- *     If baud rate = 1200, use 10
- *     If baud rate > 1200, use 20
+ * Compute screen size.
  */
 screensize()
 {
  */
 screensize()
 {
-       register char *cp;
-       register int s;
+       int s;
+       char *cp;
 
 
-       if ((cp = value("screen")) != NOSTR) {
-               s = atoi(cp);
-               if (s > 0)
-                       return(s);
-       }
-       if (baud < B1200)
-               s = 5;
-       else if (baud == B1200)
-               s = 10;
-       else
-               s = 20;
-       return(s);
+       if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0)
+               return s;
+       return screenheight - 4;
 }
 
 /*
 }
 
 /*
@@ -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);
@@ -178,26 +147,18 @@ from(msgvec)
 printhead(mesg)
 {
        struct message *mp;
 printhead(mesg)
 {
        struct message *mp;
-       FILE *ibuf;
-       char headline[LINESIZE], wcount[10], *subjline, dispc, curind;
+       char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind;
        char pbuf[BUFSIZ];
        char pbuf[BUFSIZ];
-       int s;
        struct headline hl;
        struct headline hl;
-       register char *cp;
+       int subjlen;
 
        mp = &message[mesg-1];
 
        mp = &message[mesg-1];
-       ibuf = setinput(mp);
-       readline(ibuf, headline);
-       subjline = hfield("subject", mp);
-       if (subjline == NOSTR)
+       (void) readline(setinput(mp), headline, LINESIZE);
+       if ((subjline = hfield("subject", mp)) == NOSTR)
                subjline = hfield("subj", mp);
                subjline = hfield("subj", mp);
-
        /*
         * Bletch!
         */
        /*
         * Bletch!
         */
-
-       if (subjline != NOSTR && strlen(subjline) > 28)
-               subjline[29] = '\0';
        curind = dot == mp ? '>' : ' ';
        dispc = ' ';
        if (mp->m_flag & MSAVED)
        curind = dot == mp ? '>' : ' ';
        dispc = ' ';
        if (mp->m_flag & MSAVED)
@@ -211,18 +172,15 @@ printhead(mesg)
        if (mp->m_flag & MBOX)
                dispc = 'M';
        parse(headline, &hl, pbuf);
        if (mp->m_flag & MBOX)
                dispc = 'M';
        parse(headline, &hl, pbuf);
-       sprintf(wcount, " %d/%ld", mp->m_lines, mp->m_size);
-       s = strlen(wcount);
-       cp = wcount + s;
-       while (s < 7)
-               s++, *cp++ = ' ';
-       *cp = '\0';
-       if (subjline != NOSTR)
-               printf("%c%c%3d %-8s %16.16s %s \"%s\"\n", curind, dispc, mesg,
-                   nameof(mp, 0), hl.l_date, wcount, subjline);
+       sprintf(wcount, "%3d/%-4ld", mp->m_lines, mp->m_size);
+       subjlen = screenwidth - 50 - strlen(wcount);
+       if (subjline == NOSTR || subjlen < 0)           /* pretty pathetic */
+               printf("%c%c%3d %-20.20s  %16.16s %s\n",
+                       curind, dispc, mesg, nameof(mp, 0), hl.l_date, wcount);
        else
        else
-               printf("%c%c%3d %-8s %16.16s %s\n", curind, dispc, mesg,
-                   nameof(mp, 0), hl.l_date, wcount);
+               printf("%c%c%3d %-20.20s  %16.16s %s \"%.*s\"\n",
+                       curind, dispc, mesg, nameof(mp, 0), hl.l_date, wcount,
+                       subjlen, subjline);
 }
 
 /*
 }
 
 /*
@@ -260,6 +218,25 @@ pcmdlist()
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Paginate messages, honor ignored fields.
+ */
+more(msgvec)
+       int *msgvec;
+{
+       return (type1(msgvec, 1, 1));
+}
+
+/*
+ * Paginate messages, even printing ignored fields.
+ */
+More(msgvec)
+       int *msgvec;
+{
+
+       return (type1(msgvec, 0, 1));
+}
+
 /*
  * Type out messages, honor ignored fields.
  */
 /*
  * Type out messages, honor ignored fields.
  */
@@ -267,7 +244,7 @@ type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 1));
+       return(type1(msgvec, 1, 0));
 }
 
 /*
 }
 
 /*
@@ -277,7 +254,7 @@ Type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 0));
+       return(type1(msgvec, 0, 0));
 }
 
 /*
 }
 
 /*
@@ -285,53 +262,59 @@ Type(msgvec)
  */
 jmp_buf        pipestop;
 
  */
 jmp_buf        pipestop;
 
-type1(msgvec, doign)
+type1(msgvec, doign, page)
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
-       register int mesg;
        register char *cp;
        register char *cp;
-       int c, nlines;
+       int nlines;
        int brokpipe();
        int brokpipe();
-       FILE *ibuf, *obuf;
+       FILE *obuf;
 
        obuf = stdout;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
                        pipef = NULL;
 
        obuf = stdout;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
                        pipef = NULL;
-                       pclose(obuf);
+                       Pclose(obuf);
                }
                }
-               sigset(SIGPIPE, SIG_DFL);
+               signal(SIGPIPE, SIG_DFL);
                return(0);
        }
                return(0);
        }
-       if (intty && outtty && (cp = value("crt")) != NOSTR) {
-               for (ip = msgvec, nlines = 0; *ip && ip-msgvec < msgCount; ip++)
-                       nlines += message[*ip - 1].m_lines;
-               if (nlines > atoi(cp)) {
-                       obuf = popen(MORE, "w");
+       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;
+               }
+               if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) {
+                       cp = value("PAGER");
+                       if (cp == NULL || *cp == '\0')
+                               cp = _PATH_MORE;
+                       obuf = Popen(cp, "w");
                        if (obuf == NULL) {
                        if (obuf == NULL) {
-                               perror(MORE);
+                               perror(cp);
                                obuf = stdout;
                                obuf = stdout;
-                       }
-                       else {
+                       } else {
                                pipef = obuf;
                                pipef = obuf;
-                               sigset(SIGPIPE, brokpipe);
+                               signal(SIGPIPE, brokpipe);
                        }
                }
        }
                        }
                }
        }
-       for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
-               mesg = *ip;
-               touch(mesg);
-               mp = &message[mesg-1];
+       for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
+               mp = &message[*ip - 1];
+               touch(mp);
                dot = mp;
                dot = mp;
-               print(mp, obuf, doign);
+               if (value("quiet") == NOSTR)
+                       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);
        }
        }
-       sigset(SIGPIPE, SIG_DFL);
+       signal(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
@@ -342,29 +325,9 @@ type1(msgvec, doign)
 
 brokpipe()
 {
 
 brokpipe()
 {
-# ifdef VMUNIX
-       sigrelse(SIGPIPE);
-# else
-       signal(SIGPIPE, brokpipe);
-# endif
        longjmp(pipestop, 1);
 }
 
        longjmp(pipestop, 1);
 }
 
-/*
- * Print the indicated message on standard output.
- */
-
-print(mp, obuf, doign)
-       register struct message *mp;
-       FILE *obuf;
-{
-
-       if (value("quiet") == NOSTR)
-               fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1);
-       touch(mp - &message[0] + 1);
-       send(mp, obuf, doign);
-}
-
 /*
  * Print the top so many lines of each desired message.
  * The number of lines is taken from the variable "toplines"
 /*
  * Print the top so many lines of each desired message.
  * The number of lines is taken from the variable "toplines"
@@ -376,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;
@@ -390,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);
@@ -414,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[];
 {
@@ -450,27 +410,15 @@ mboxit(msgvec)
  */
 folders()
 {
  */
 folders()
 {
-       char dirname[BUFSIZ], cmd[BUFSIZ];
-       int pid, s, e;
+       char dirname[BUFSIZ];
+       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:
-               sigchild();
-               execlp("ls", "ls", dirname, 0);
-               clrbuf(stdout);
-               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;
 }
 }