BSD 4_3_Tahoe release
[unix-history] / usr / src / ucb / Mail / cmd1.c
index 3e044fc..7083e56 100644 (file)
@@ -1,6 +1,22 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * 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.
+ */
+
+#ifdef notdef
+static char sccsid[] = "@(#)cmd1.c     5.5 (Berkeley) 2/18/88";
+#endif /* notdef */
+
 #include "rcv.h"
 #include <sys/stat.h>
 #include "rcv.h"
 #include <sys/stat.h>
+#include <sys/wait.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -8,8 +24,6 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      2.10 1/29/83";
-
 /*
  * 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.
@@ -75,9 +89,9 @@ local(namelist)
        }
        if (localnames != 0)
                cfree((char *) localnames);
        }
        if (localnames != 0)
                cfree((char *) localnames);
-       localnames = (char **) calloc(c, sizeof (char *));
+       localnames = (char **) calloc((unsigned) c, sizeof (char *));
        for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
        for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
-               cp = (char *) calloc(strlen(*ap) + 1, sizeof (char));
+               cp = (char *) calloc((unsigned) strlen(*ap) + 1, sizeof (char));
                strcpy(cp, *ap);
                *ap2 = cp;
        }
                strcpy(cp, *ap);
                *ap2 = cp;
        }
@@ -125,30 +139,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;
 }
 
 /*
 }
 
 /*
@@ -178,26 +178,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)
+       readline(setinput(mp), headline);
+       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 +203,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 +249,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 +275,7 @@ type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 1));
+       return(type1(msgvec, 1, 0));
 }
 
 /*
 }
 
 /*
@@ -277,7 +285,7 @@ Type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 0));
+       return(type1(msgvec, 0, 0));
 }
 
 /*
 }
 
 /*
@@ -285,16 +293,16 @@ Type(msgvec)
  */
 jmp_buf        pipestop;
 
  */
 jmp_buf        pipestop;
 
-type1(msgvec, doign)
+type1(msgvec, doign, page)
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
        register int mesg;
        register char *cp;
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
        register int mesg;
        register char *cp;
-       int c, nlines;
+       int nlines;
        int brokpipe();
        int brokpipe();
-       FILE *ibuf, *obuf;
+       FILE *obuf;
 
        obuf = stdout;
        if (setjmp(pipestop)) {
 
        obuf = stdout;
        if (setjmp(pipestop)) {
@@ -302,36 +310,43 @@ type1(msgvec, doign)
                        pipef = NULL;
                        pclose(obuf);
                }
                        pipef = NULL;
                        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 (intty && outtty && (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 > atoi(cp)) {
+                       cp = value("PAGER");
+                       if (cp == NULL || *cp == '\0')
+                               cp = 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++) {
+       for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
-               print(mp, obuf, doign);
+               if (value("quiet") == NOSTR)
+                       fprintf(obuf, "Message %d:\n", mesg);
+               send(mp, obuf, doign);
        }
        if (obuf != stdout) {
                pipef = NULL;
                pclose(obuf);
        }
        }
        if (obuf != stdout) {
                pipef = NULL;
                pclose(obuf);
        }
-       sigset(SIGPIPE, SIG_DFL);
+       signal(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
@@ -342,29 +357,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"
@@ -401,7 +396,7 @@ top(msgvec)
                if (!lineb)
                        printf("\n");
                for (lines = 0; lines < c && lines <= topl; lines++) {
                if (!lineb)
                        printf("\n");
                for (lines = 0; lines < c && lines <= topl; lines++) {
-                       if (readline(ibuf, linebuf) <= 0)
+                       if (readline(ibuf, linebuf) < 0)
                                break;
                        puts(linebuf);
                        lineb = blankline(linebuf);
                                break;
                        puts(linebuf);
                        lineb = blankline(linebuf);
@@ -450,8 +445,9 @@ mboxit(msgvec)
  */
 folders()
 {
  */
 folders()
 {
-       char dirname[BUFSIZ], cmd[BUFSIZ];
-       int pid, s, e;
+       char dirname[BUFSIZ];
+       int pid, e;
+       union wait s;
 
        if (getfold(dirname) < 0) {
                printf("No value set for \"folder\"\n");
 
        if (getfold(dirname) < 0) {
                printf("No value set for \"folder\"\n");
@@ -459,10 +455,8 @@ folders()
        }
        switch ((pid = fork())) {
        case 0:
        }
        switch ((pid = fork())) {
        case 0:
-               sigchild();
                execlp("ls", "ls", dirname, 0);
                execlp("ls", "ls", dirname, 0);
-               clrbuf(stdout);
-               exit(1);
+               _exit(1);
 
        case -1:
                perror("fork");
 
        case -1:
                perror("fork");