botched copyright
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index aaedb05..b7e1eae 100644 (file)
@@ -1,4 +1,13 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)cmd1.c      5.2 (Berkeley) %G%";
+#endif not lint
+
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
 
@@ -8,8 +17,6 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      2.10 %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.
@@ -55,6 +62,36 @@ headers(msgvec)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Set the list of alternate names for out host.
+ */
+local(namelist)
+       char **namelist;
+{
+       register int c;
+       register char **ap, **ap2, *cp;
+
+       c = argcount(namelist) + 1;
+       if (c == 1) {
+               if (localnames == 0)
+                       return(0);
+               for (ap = localnames; *ap; ap++)
+                       printf("%s ", *ap);
+               printf("\n");
+               return(0);
+       }
+       if (localnames != 0)
+               cfree((char *) localnames);
+       localnames = (char **) calloc(c, sizeof (char *));
+       for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
+               cp = (char *) calloc(strlen(*ap) + 1, sizeof (char));
+               strcpy(cp, *ap);
+               *ap2 = cp;
+       }
+       *ap2 = 0;
+       return(0);
+}
+
 /*
  * Scroll to the next/previous screen
  */
 /*
  * Scroll to the next/previous screen
  */
@@ -106,6 +143,9 @@ screensize()
 {
        register char *cp;
        register int s;
 {
        register char *cp;
        register int s;
+#ifdef TIOCGWINSZ
+       struct winsize ws;
+#endif
 
        if ((cp = value("screen")) != NOSTR) {
                s = atoi(cp);
 
        if ((cp = value("screen")) != NOSTR) {
                s = atoi(cp);
@@ -116,6 +156,10 @@ screensize()
                s = 5;
        else if (baud == B1200)
                s = 10;
                s = 5;
        else if (baud == B1200)
                s = 10;
+#ifdef TIOCGWINSZ
+       else if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) == 0 && ws.ws_row != 0)
+               s = ws.ws_row - 4;
+#endif
        else
                s = 20;
        return(s);
        else
                s = 20;
        return(s);
@@ -230,6 +274,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.
  */
@@ -237,7 +300,7 @@ type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 1));
+       return(type1(msgvec, 1, 0));
 }
 
 /*
 }
 
 /*
@@ -247,7 +310,7 @@ Type(msgvec)
        int *msgvec;
 {
 
        int *msgvec;
 {
 
-       return(type1(msgvec, 0));
+       return(type1(msgvec, 0, 0));
 }
 
 /*
 }
 
 /*
@@ -255,7 +318,7 @@ Type(msgvec)
  */
 jmp_buf        pipestop;
 
  */
 jmp_buf        pipestop;
 
-type1(msgvec, doign)
+type1(msgvec, doign, page)
        int *msgvec;
 {
        register *ip;
        int *msgvec;
 {
        register *ip;
@@ -275,10 +338,13 @@ type1(msgvec, doign)
                sigset(SIGPIPE, SIG_DFL);
                return(0);
        }
                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)) {
+       if (intty && outtty && (page || (cp = value("crt")) != NOSTR)) {
+               if (!page) {
+                       nlines = 0;
+                       for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++)
+                               nlines += message[*ip - 1].m_lines;
+               }
+               if (page || nlines > atoi(cp)) {
                        obuf = popen(MORE, "w");
                        if (obuf == NULL) {
                                perror(MORE);
                        obuf = popen(MORE, "w");
                        if (obuf == NULL) {
                                perror(MORE);
@@ -312,9 +378,7 @@ type1(msgvec, doign)
 
 brokpipe()
 {
 
 brokpipe()
 {
-# ifdef VMUNIX
-       sigrelse(SIGPIPE);
-# else
+# ifndef VMUNIX
        signal(SIGPIPE, brokpipe);
 # endif
        longjmp(pipestop, 1);
        signal(SIGPIPE, brokpipe);
 # endif
        longjmp(pipestop, 1);
@@ -431,8 +495,7 @@ folders()
        case 0:
                sigchild();
                execlp("ls", "ls", dirname, 0);
        case 0:
                sigchild();
                execlp("ls", "ls", dirname, 0);
-               clrbuf(stdout);
-               exit(1);
+               _exit(1);
 
        case -1:
                perror("fork");
 
        case -1:
                perror("fork");