Release to Heidi Stettner
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index f1ad2a8..c3350ee 100644 (file)
@@ -8,10 +8,11 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      1.1 %G%";
+static char *SccsId = "@(#)cmd1.c      2.1 %G%";
 
 /*
  * Print the current active headings.
 
 /*
  * Print the current active headings.
+ * Don't change dot if invoker didn't give an argument.
  */
 
 static int screen;
  */
 
 static int screen;
@@ -34,7 +35,8 @@ headers(msgvec)
                mp = &message[0];
        flag = 0;
        mesg = mp - &message[0];
                mp = &message[0];
        flag = 0;
        mesg = mp - &message[0];
-       dot = mp;
+       if (dot != &message[n-1])
+               dot = mp;
        for (; mp < &message[msgCount]; mp++) {
                mesg++;
                if (mp->m_flag & MDELETED)
        for (; mp < &message[msgCount]; mp++) {
                mesg++;
                if (mp->m_flag & MDELETED)
@@ -118,7 +120,7 @@ printhead(mesg)
 {
        struct message *mp;
        FILE *ibuf;
 {
        struct message *mp;
        FILE *ibuf;
-       char headline[LINESIZE], wcount[10], *subjline, dispc;
+       char headline[LINESIZE], wcount[10], *subjline, dispc, curind;
        char pbuf[BUFSIZ];
        int s;
        struct headline hl;
        char pbuf[BUFSIZ];
        int s;
        struct headline hl;
@@ -137,11 +139,18 @@ printhead(mesg)
 
        if (subjline != NOSTR && strlen(subjline) > 28)
                subjline[29] = '\0';
 
        if (subjline != NOSTR && strlen(subjline) > 28)
                subjline[29] = '\0';
+       curind = dot == mp ? '>' : ' ';
        dispc = ' ';
        if (mp->m_flag & MSAVED)
                dispc = '*';
        if (mp->m_flag & MPRESERVE)
                dispc = 'P';
        dispc = ' ';
        if (mp->m_flag & MSAVED)
                dispc = '*';
        if (mp->m_flag & MPRESERVE)
                dispc = 'P';
+       if ((mp->m_flag & (MREAD|MNEW)) == MNEW)
+               dispc = 'N';
+       if ((mp->m_flag & (MREAD|MNEW)) == 0)
+               dispc = 'U';
+       if (mp->m_flag & MBOX)
+               dispc = 'M';
        parse(headline, &hl, pbuf);
        sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size);
        s = strlen(wcount);
        parse(headline, &hl, pbuf);
        sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size);
        s = strlen(wcount);
@@ -150,11 +159,11 @@ printhead(mesg)
                s++, *cp++ = ' ';
        *cp = '\0';
        if (subjline != NOSTR)
                s++, *cp++ = ' ';
        *cp = '\0';
        if (subjline != NOSTR)
-               printf("%c%3d %-8s %16.16s %s \"%s\"\n", dispc, mesg,
-                   nameof(mp), hl.l_date, wcount, subjline);
+               printf("%c%c%3d %-8s %16.16s %s \"%s\"\n", curind, dispc, mesg,
+                   nameof(mp, 0), hl.l_date, wcount, subjline);
        else
        else
-               printf("%c%3d %-8s %16.16s %s\n", dispc, mesg,
-                   nameof(mp), hl.l_date, wcount);
+               printf("%c%c%3d %-8s %16.16s %s\n", curind, dispc, mesg,
+                   nameof(mp, 0), hl.l_date, wcount);
 }
 
 /*
 }
 
 /*
@@ -196,37 +205,83 @@ pcmdlist()
  * Type out the messages requested.
  */
 
  * Type out the messages requested.
  */
 
+jmp_buf        pipestop;
+
 type(msgvec)
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
        register int mesg;
 type(msgvec)
        int *msgvec;
 {
        register *ip;
        register struct message *mp;
        register int mesg;
-       int c;
-       FILE *ibuf;
-
+       register char *cp;
+       int c, nlines;
+       int brokpipe();
+       FILE *ibuf, *obuf;
+
+       obuf = stdout;
+       if (setjmp(pipestop)) {
+               if (obuf != stdout) {
+                       pclose(obuf);
+                       pipef = NULL;
+               }
+               sigset(SIGPIPE, SIG_DFL);
+               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 (obuf == NULL) {
+                               perror(MORE);
+                               obuf = stdout;
+                       }
+                       else {
+                               pipef = obuf;
+                               sigset(SIGPIPE, brokpipe);
+                       }
+               }
+       }
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
        for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
                mesg = *ip;
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
-               print(mp);
+               print(mp, obuf);
+       }
+       if (obuf != stdout) {
+               pclose(obuf);
+               pipef = NULL;
        }
        }
+       sigset(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Respond to a broken pipe signal --
+ * probably caused by using quitting more.
+ */
+
+brokpipe()
+{
+
+       longjmp(pipestop, 1);
+       sigrelse(SIGPIPE);
+}
+
 /*
  * Print the indicated message on standard output.
  */
 
 /*
  * Print the indicated message on standard output.
  */
 
-print(mp)
+print(mp, obuf)
        register struct message *mp;
        register struct message *mp;
+       FILE *obuf;
 {
 
        if (value("quiet") == NOSTR)
 {
 
        if (value("quiet") == NOSTR)
-               printf("Message %2d:\n", mp - &message[0] + 1);
+               fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1);
        touch(mp - &message[0] + 1);
        touch(mp - &message[0] + 1);
-       send(mp, stdout);
+       send(mp, obuf);
 }
 
 /*
 }
 
 /*
@@ -285,8 +340,25 @@ stouch(msgvec)
        register int *ip;
 
        for (ip = msgvec; *ip != 0; ip++) {
        register int *ip;
 
        for (ip = msgvec; *ip != 0; ip++) {
-               touch(*ip);
                dot = &message[*ip-1];
                dot = &message[*ip-1];
+               dot->m_flag |= MTOUCH;
+               dot->m_flag &= ~MPRESERVE;
+       }
+       return(0);
+}
+
+/*
+ * Make sure all passed messages get mboxed.
+ */
+
+mboxit(msgvec)
+       int msgvec[];
+{
+       register int *ip;
+
+       for (ip = msgvec; *ip != 0; ip++) {
+               dot = &message[*ip-1];
+               dot->m_flag |= MTOUCH|MBOX;
                dot->m_flag &= ~MPRESERVE;
        }
        return(0);
                dot->m_flag &= ~MPRESERVE;
        }
        return(0);