4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index d837963..e1f55aa 100644 (file)
@@ -1,25 +1,16 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/*-
+ * Copyright (c) 1980, 1993
+ *     The 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.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd1.c     5.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd1.c     8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
+#include "extern.h"
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -34,6 +25,7 @@ static char sccsid[] = "@(#)cmd1.c    5.18 (Berkeley) %G%";
 
 static int screen;
 
 
 static int screen;
 
+int
 headers(msgvec)
        int *msgvec;
 {
 headers(msgvec)
        int *msgvec;
 {
@@ -74,6 +66,7 @@ headers(msgvec)
 /*
  * Scroll to the next/previous screen
  */
 /*
  * Scroll to the next/previous screen
  */
+int
 scroll(arg)
        char arg[];
 {
 scroll(arg)
        char arg[];
 {
@@ -112,6 +105,7 @@ scroll(arg)
 /*
  * Compute screen size.
  */
 /*
  * Compute screen size.
  */
+int
 screensize()
 {
        int s;
 screensize()
 {
        int s;
@@ -126,7 +120,7 @@ screensize()
  * Print out the headlines for each message
  * in the passed message list.
  */
  * Print out the headlines for each message
  * in the passed message list.
  */
-
+int
 from(msgvec)
        int *msgvec;
 {
 from(msgvec)
        int *msgvec;
 {
@@ -143,14 +137,16 @@ from(msgvec)
  * Print out the header of a specific message.
  * This is a slight improvement to the standard one.
  */
  * Print out the header of a specific message.
  * This is a slight improvement to the standard one.
  */
-
+void
 printhead(mesg)
 printhead(mesg)
+       int mesg;
 {
        struct message *mp;
        char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind;
        char pbuf[BUFSIZ];
        struct headline hl;
        int subjlen;
 {
        struct message *mp;
        char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind;
        char pbuf[BUFSIZ];
        struct headline hl;
        int subjlen;
+       char *name;
 
        mp = &message[mesg-1];
        (void) readline(setinput(mp), headline, LINESIZE);
 
        mp = &message[mesg-1];
        (void) readline(setinput(mp), headline, LINESIZE);
@@ -172,21 +168,23 @@ 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, "%3d/%-4ld", mp->m_lines, mp->m_size);
+       sprintf(wcount, "%3d/%-5ld", mp->m_lines, mp->m_size);
        subjlen = screenwidth - 50 - strlen(wcount);
        subjlen = screenwidth - 50 - strlen(wcount);
+       name = value("show-rcpt") != NOSTR ?
+               skin(hfield("to", mp)) : nameof(mp, 0);
        if (subjline == NOSTR || subjlen < 0)           /* pretty pathetic */
                printf("%c%c%3d %-20.20s  %16.16s %s\n",
        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);
+                       curind, dispc, mesg, name, hl.l_date, wcount);
        else
                printf("%c%c%3d %-20.20s  %16.16s %s \"%.*s\"\n",
        else
                printf("%c%c%3d %-20.20s  %16.16s %s \"%.*s\"\n",
-                       curind, dispc, mesg, nameof(mp, 0), hl.l_date, wcount,
+                       curind, dispc, mesg, name, hl.l_date, wcount,
                        subjlen, subjline);
 }
 
 /*
  * Print out the value of dot.
  */
                        subjlen, subjline);
 }
 
 /*
  * Print out the value of dot.
  */
-
+int
 pdot()
 {
        printf("%d\n", dot - &message[0] + 1);
 pdot()
 {
        printf("%d\n", dot - &message[0] + 1);
@@ -196,7 +194,7 @@ pdot()
 /*
  * Print out all the possible commands.
  */
 /*
  * Print out all the possible commands.
  */
-
+int
 pcmdlist()
 {
        register struct cmd *cp;
 pcmdlist()
 {
        register struct cmd *cp;
@@ -221,6 +219,7 @@ pcmdlist()
 /*
  * Paginate messages, honor ignored fields.
  */
 /*
  * Paginate messages, honor ignored fields.
  */
+int
 more(msgvec)
        int *msgvec;
 {
 more(msgvec)
        int *msgvec;
 {
@@ -230,6 +229,7 @@ more(msgvec)
 /*
  * Paginate messages, even printing ignored fields.
  */
 /*
  * Paginate messages, even printing ignored fields.
  */
+int
 More(msgvec)
        int *msgvec;
 {
 More(msgvec)
        int *msgvec;
 {
@@ -240,6 +240,7 @@ More(msgvec)
 /*
  * Type out messages, honor ignored fields.
  */
 /*
  * Type out messages, honor ignored fields.
  */
+int
 type(msgvec)
        int *msgvec;
 {
 type(msgvec)
        int *msgvec;
 {
@@ -250,6 +251,7 @@ type(msgvec)
 /*
  * Type out messages, even printing ignored fields.
  */
 /*
  * Type out messages, even printing ignored fields.
  */
+int
 Type(msgvec)
        int *msgvec;
 {
 Type(msgvec)
        int *msgvec;
 {
@@ -261,26 +263,20 @@ Type(msgvec)
  * Type out the messages requested.
  */
 jmp_buf        pipestop;
  * Type out the messages requested.
  */
 jmp_buf        pipestop;
-
+int
 type1(msgvec, doign, page)
        int *msgvec;
 type1(msgvec, doign, page)
        int *msgvec;
+       int doign, page;
 {
        register *ip;
        register struct message *mp;
        register char *cp;
        int nlines;
 {
        register *ip;
        register struct message *mp;
        register char *cp;
        int nlines;
-       int brokpipe();
        FILE *obuf;
 
        obuf = stdout;
        FILE *obuf;
 
        obuf = stdout;
-       if (setjmp(pipestop)) {
-               if (obuf != stdout) {
-                       pipef = NULL;
-                       Pclose(obuf);
-               }
-               signal(SIGPIPE, SIG_DFL);
-               return(0);
-       }
+       if (setjmp(pipestop))
+               goto close_pipe;
        if (value("interactive") != NOSTR &&
            (page || (cp = value("crt")) != NOSTR)) {
                nlines = 0;
        if (value("interactive") != NOSTR &&
            (page || (cp = value("crt")) != NOSTR)) {
                nlines = 0;
@@ -291,15 +287,13 @@ type1(msgvec, doign, page)
                if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) {
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
                if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) {
                        cp = value("PAGER");
                        if (cp == NULL || *cp == '\0')
-                               cp = MORE;
+                               cp = _PATH_MORE;
                        obuf = Popen(cp, "w");
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
                        obuf = Popen(cp, "w");
                        if (obuf == NULL) {
                                perror(cp);
                                obuf = stdout;
-                       } else {
-                               pipef = obuf;
+                       } else
                                signal(SIGPIPE, brokpipe);
                                signal(SIGPIPE, brokpipe);
-                       }
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
                }
        }
        for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
@@ -310,20 +304,25 @@ type1(msgvec, doign, page)
                        fprintf(obuf, "Message %d:\n", *ip);
                (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
                        fprintf(obuf, "Message %d:\n", *ip);
                (void) send(mp, obuf, doign ? ignore : 0, NOSTR);
        }
+close_pipe:
        if (obuf != stdout) {
        if (obuf != stdout) {
-               pipef = NULL;
+               /*
+                * Ignore SIGPIPE so it can't cause a duplicate close.
+                */
+               signal(SIGPIPE, SIG_IGN);
                Pclose(obuf);
                Pclose(obuf);
+               signal(SIGPIPE, SIG_DFL);
        }
        }
-       signal(SIGPIPE, SIG_DFL);
        return(0);
 }
 
 /*
  * Respond to a broken pipe signal --
        return(0);
 }
 
 /*
  * Respond to a broken pipe signal --
- * probably caused by using quitting more.
+ * probably caused by quitting more.
  */
  */
-
-brokpipe()
+void
+brokpipe(signo)
+       int signo;
 {
        longjmp(pipestop, 1);
 }
 {
        longjmp(pipestop, 1);
 }
@@ -333,7 +332,7 @@ brokpipe()
  * The number of lines is taken from the variable "toplines"
  * and defaults to 5.
  */
  * The number of lines is taken from the variable "toplines"
  * and defaults to 5.
  */
-
+int
 top(msgvec)
        int *msgvec;
 {
 top(msgvec)
        int *msgvec;
 {
@@ -375,6 +374,7 @@ top(msgvec)
  * Touch all the given messages so that they will
  * get mboxed.
  */
  * Touch all the given messages so that they will
  * get mboxed.
  */
+int
 stouch(msgvec)
        int msgvec[];
 {
 stouch(msgvec)
        int msgvec[];
 {
@@ -391,7 +391,7 @@ stouch(msgvec)
 /*
  * Make sure all passed messages get mboxed.
  */
 /*
  * Make sure all passed messages get mboxed.
  */
-
+int
 mboxit(msgvec)
        int msgvec[];
 {
 mboxit(msgvec)
        int msgvec[];
 {
@@ -408,6 +408,7 @@ mboxit(msgvec)
 /*
  * List the folders the user currently has.
  */
 /*
  * List the folders the user currently has.
  */
+int
 folders()
 {
        char dirname[BUFSIZ];
 folders()
 {
        char dirname[BUFSIZ];
@@ -419,6 +420,6 @@ folders()
        }
        if ((cmd = value("LISTER")) == NOSTR)
                cmd = "ls";
        }
        if ((cmd = value("LISTER")) == NOSTR)
                cmd = "ls";
-       (void) run_command(cmd, 0, -1, -1, dirname, NOSTR);
+       (void) run_command(cmd, 0, -1, -1, dirname, NOSTR, NOSTR);
        return 0;
 }
        return 0;
 }