file reorg, pathnames.h, paths.h
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index fe84684..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      1.9 %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.
@@ -22,15 +39,17 @@ headers(msgvec)
 {
        register int n, mesg, flag;
        register struct message *mp;
 {
        register int n, mesg, flag;
        register struct message *mp;
+       int size;
 
 
+       size = screensize();
        n = msgvec[0];
        if (n != 0)
        n = msgvec[0];
        if (n != 0)
-               screen = (n-1)/SCREEN;
+               screen = (n-1)/size;
        if (screen < 0)
                screen = 0;
        if (screen < 0)
                screen = 0;
-       mp = &message[screen * SCREEN];
+       mp = &message[screen * size];
        if (mp >= &message[msgCount])
        if (mp >= &message[msgCount])
-               mp = &message[msgCount - SCREEN];
+               mp = &message[msgCount - size];
        if (mp < &message[0])
                mp = &message[0];
        flag = 0;
        if (mp < &message[0])
                mp = &message[0];
        flag = 0;
@@ -41,10 +60,9 @@ headers(msgvec)
                mesg++;
                if (mp->m_flag & MDELETED)
                        continue;
                mesg++;
                if (mp->m_flag & MDELETED)
                        continue;
-               if (flag++ >= SCREEN)
+               if (flag++ >= size)
                        break;
                printhead(mesg);
                        break;
                printhead(mesg);
-               sreset();
        }
        if (flag == 0) {
                printf("No more mail.\n");
        }
        if (flag == 0) {
                printf("No more mail.\n");
@@ -56,20 +74,20 @@ headers(msgvec)
 /*
  * Scroll to the next/previous screen
  */
 /*
  * Scroll to the next/previous screen
  */
-
 scroll(arg)
        char arg[];
 {
 scroll(arg)
        char arg[];
 {
-       register int s;
+       register int s, size;
        int cur[1];
 
        cur[0] = 0;
        int cur[1];
 
        cur[0] = 0;
+       size = screensize();
        s = screen;
        switch (*arg) {
        case 0:
        case '+':
                s++;
        s = screen;
        switch (*arg) {
        case 0:
        case '+':
                s++;
-               if (s*SCREEN > msgCount) {
+               if (s * size > msgCount) {
                        printf("On last screenful of messages\n");
                        return(0);
                }
                        printf("On last screenful of messages\n");
                        return(0);
                }
@@ -91,6 +109,18 @@ scroll(arg)
        return(headers(cur));
 }
 
        return(headers(cur));
 }
 
+/*
+ * Compute screen size.
+ */
+screensize()
+{
+       int s;
+       char *cp;
+
+       if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0)
+               return s;
+       return screenheight - 4;
+}
 
 /*
  * Print out the headlines for each message
 
 /*
  * Print out the headlines for each message
@@ -102,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);
@@ -119,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)
@@ -152,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/%d", 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);
 }
 
 /*
 }
 
 /*
@@ -202,58 +219,102 @@ pcmdlist()
 }
 
 /*
 }
 
 /*
- * Type out the messages requested.
+ * Paginate messages, honor ignored fields.
  */
  */
+more(msgvec)
+       int *msgvec;
+{
+       return (type1(msgvec, 1, 1));
+}
 
 
-jmp_buf        pipestop;
+/*
+ * Paginate messages, even printing ignored fields.
+ */
+More(msgvec)
+       int *msgvec;
+{
+
+       return (type1(msgvec, 0, 1));
+}
 
 
+/*
+ * Type out messages, honor ignored fields.
+ */
 type(msgvec)
        int *msgvec;
 {
 type(msgvec)
        int *msgvec;
 {
+
+       return(type1(msgvec, 1, 0));
+}
+
+/*
+ * Type out messages, even printing ignored fields.
+ */
+Type(msgvec)
+       int *msgvec;
+{
+
+       return(type1(msgvec, 0, 0));
+}
+
+/*
+ * Type out the messages requested.
+ */
+jmp_buf        pipestop;
+
+type1(msgvec, doign, page)
+       int *msgvec;
+{
        register *ip;
        register struct message *mp;
        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) {
 
        obuf = stdout;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
-                       pclose(obuf);
                        pipef = NULL;
                        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 (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);
+               if (value("quiet") == NOSTR)
+                       fprintf(obuf, "Message %d:\n", *ip);
+               (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
        if (obuf != stdout) {
        }
        if (obuf != stdout) {
-               pclose(obuf);
                pipef = NULL;
                pipef = NULL;
+               Pclose(obuf);
        }
        }
-       sigset(SIGPIPE, SIG_DFL);
+       signal(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
@@ -264,24 +325,7 @@ type(msgvec)
 
 brokpipe()
 {
 
 brokpipe()
 {
-
        longjmp(pipestop, 1);
        longjmp(pipestop, 1);
-       sigrelse(SIGPIPE);
-}
-
-/*
- * Print the indicated message on standard output.
- */
-
-print(mp, obuf)
-       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);
 }
 
 /*
 }
 
 /*
@@ -295,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;
@@ -309,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);
@@ -333,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[];
 {
@@ -363,3 +404,21 @@ mboxit(msgvec)
        }
        return(0);
 }
        }
        return(0);
 }
+
+/*
+ * List the folders the user currently has.
+ */
+folders()
+{
+       char dirname[BUFSIZ];
+       char *cmd;
+
+       if (getfold(dirname) < 0) {
+               printf("No value set for \"folder\"\n");
+               return 1;
+       }
+       if ((cmd = value("LISTER")) == NOSTR)
+               cmd = "ls";
+       (void) run_command(cmd, 0, -1, -1, dirname, NOSTR);
+       return 0;
+}