changed to version 2.1
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index 16fb424..fe84684 100644 (file)
@@ -8,10 +8,11 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      1.3 %G%";
+static char *SccsId = "@(#)cmd1.c      1.9 %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,15 +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) == 0)
-               dispc = 'U';
-       if (mp->m_flag & MNEW)
+       if ((mp->m_flag & (MREAD|MNEW)) == MNEW)
                dispc = 'N';
                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);
@@ -154,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);
 }
 
 /*
 }
 
 /*
@@ -219,7 +224,7 @@ type(msgvec)
                        pclose(obuf);
                        pipef = NULL;
                }
                        pclose(obuf);
                        pipef = NULL;
                }
-               signal(SIGPIPE, SIG_DFL);
+               sigset(SIGPIPE, SIG_DFL);
                return(0);
        }
        if (intty && outtty && (cp = value("crt")) != NOSTR) {
                return(0);
        }
        if (intty && outtty && (cp = value("crt")) != NOSTR) {
@@ -233,7 +238,7 @@ type(msgvec)
                        }
                        else {
                                pipef = obuf;
                        }
                        else {
                                pipef = obuf;
-                               signal(SIGPIPE, brokpipe);
+                               sigset(SIGPIPE, brokpipe);
                        }
                }
        }
                        }
                }
        }
@@ -244,11 +249,11 @@ type(msgvec)
                dot = mp;
                print(mp, obuf);
        }
                dot = mp;
                print(mp, obuf);
        }
-       signal(SIGPIPE, SIG_DFL);
        if (obuf != stdout) {
                pclose(obuf);
                pipef = NULL;
        }
        if (obuf != stdout) {
                pclose(obuf);
                pipef = NULL;
        }
+       sigset(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
@@ -260,8 +265,8 @@ type(msgvec)
 brokpipe()
 {
 
 brokpipe()
 {
 
-       signal(SIGPIPE, SIG_IGN);
        longjmp(pipestop, 1);
        longjmp(pipestop, 1);
+       sigrelse(SIGPIPE);
 }
 
 /*
 }
 
 /*
@@ -335,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);