do chmod last in install
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index fe84684..f15eabf 100644 (file)
@@ -8,7 +8,7 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      1.9 %G%";
+static char *SccsId = "@(#)cmd1.c      2.3 %G%";
 
 /*
  * Print the current active headings.
 
 /*
  * Print the current active headings.
@@ -22,15 +22,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,7 +43,7 @@ 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);
                sreset();
                        break;
                printhead(mesg);
                sreset();
@@ -60,16 +62,17 @@ headers(msgvec)
 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 +94,32 @@ scroll(arg)
        return(headers(cur));
 }
 
        return(headers(cur));
 }
 
+/*
+ * Compute what the screen size should be.
+ * We use the following algorithm:
+ *     If user specifies with screen option, use that.
+ *     If baud rate < 1200, use  5
+ *     If baud rate = 1200, use 10
+ *     If baud rate > 1200, use 20
+ */
+screensize()
+{
+       register char *cp;
+       register int s;
+
+       if ((cp = value("screen")) != NOSTR) {
+               s = atoi(cp);
+               if (s > 0)
+                       return(s);
+       }
+       if (baud < B1200)
+               s = 5;
+       else if (baud == B1200)
+               s = 10;
+       else
+               s = 20;
+       return(s);
+}
 
 /*
  * Print out the headlines for each message
 
 /*
  * Print out the headlines for each message
@@ -221,8 +250,8 @@ type(msgvec)
        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);
                return(0);
                }
                sigset(SIGPIPE, SIG_DFL);
                return(0);
@@ -250,8 +279,8 @@ type(msgvec)
                print(mp, obuf);
        }
        if (obuf != stdout) {
                print(mp, obuf);
        }
        if (obuf != stdout) {
-               pclose(obuf);
                pipef = NULL;
                pipef = NULL;
+               pclose(obuf);
        }
        sigset(SIGPIPE, SIG_DFL);
        return(0);
        }
        sigset(SIGPIPE, SIG_DFL);
        return(0);
@@ -265,8 +294,8 @@ type(msgvec)
 brokpipe()
 {
 
 brokpipe()
 {
 
-       longjmp(pipestop, 1);
        sigrelse(SIGPIPE);
        sigrelse(SIGPIPE);
+       longjmp(pipestop, 1);
 }
 
 /*
 }
 
 /*