home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / Mail / cmd1.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  5KB  |  306 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. #include "rcv.h"
  4. #include <sys/stat.h>
  5.  
  6. /*
  7.  * Mail -- a mail program
  8.  *
  9.  * User commands.
  10.  */
  11.  
  12. /*
  13.  * Print the current active headings.
  14.  */
  15.  
  16. headers(argv)
  17.     char **argv;
  18. {
  19.     register int mesg, flag;
  20.     register struct message *mp;
  21.     char c, *str;
  22.     static screen;
  23.  
  24.     str = argv[0];
  25.     if (argcount(argv) == 0)
  26.         c = 0;
  27.     else
  28.         c = str[0];
  29.     if (c) {
  30.         switch (c) {
  31.         case '0':
  32.             /*
  33.              * Go back to top.
  34.              */
  35.             screen = 0;
  36.             break;
  37.  
  38.         case '+':
  39.             /*
  40.              * scroll down.
  41.              */
  42.             screen++;
  43.             break;
  44.  
  45.         case '-':
  46.             /*
  47.              * scroll up.
  48.              */
  49.             screen--;
  50.             break;
  51.         }
  52.         if (screen < 0)
  53.             screen = 0;
  54.     }
  55.     mp = &message[screen * SCREEN];
  56.     if (mp > &message[msgCount])
  57.         mp = &message[msgCount - SCREEN];
  58.     if (mp < &message[0])
  59.         mp = &message[0];
  60.     flag = 0;
  61.     mesg = mp - &message[0];
  62.     dot = mp;
  63.     for (; mp < &message[msgCount]; mp++) {
  64.         mesg++;
  65.         if (mp->m_flag & MDELETED)
  66.             continue;
  67.         if (flag++ >= SCREEN)
  68.             break;
  69.         printhead(mesg);
  70.         sreset();
  71.     }
  72.     if (flag == 0) {
  73.         printf("No more messages.\n");
  74.         return(1);
  75.     }
  76.     return(0);
  77. }
  78.  
  79. /*
  80.  * Print out the headlines for each message
  81.  * in the passed message list.
  82.  */
  83.  
  84. from(msgvec)
  85.     int *msgvec;
  86. {
  87.     register int *ip;
  88.  
  89.     for (ip = msgvec; *ip != NULL; ip++) {
  90.         printhead(*ip);
  91.         sreset();
  92.     }
  93.     if (--ip >= msgvec)
  94.         dot = &message[*ip - 1];
  95.     return(0);
  96. }
  97.  
  98. /*
  99.  * Print out the header of a specific message.
  100.  * This is a slight improvement to the standard one.
  101.  */
  102.  
  103. printhead(mesg)
  104. {
  105.     struct message *mp;
  106.     FILE *ibuf;
  107.     char headline[LINESIZE], wcount[10], *subjline, dispc;
  108.     int s;
  109.     struct headline hl;
  110.     register char *cp;
  111.  
  112.     mp = &message[mesg-1];
  113.     ibuf = setinput(mp);
  114.     readline(ibuf, headline);
  115.     subjline = hfield("subj", mp);
  116.  
  117.     /*
  118.      * Bletch!
  119.      */
  120.  
  121.     if (subjline != NOSTR)
  122.         subjline[29] = '\0';
  123.     if (mp->m_flag & MSAVED)
  124.         dispc = '*';
  125.     else if (mp->m_flag & MPRESERVED)
  126.         dispc = 'P';
  127.     else
  128.         dispc = ' ';
  129.     parse(headline, &hl);
  130.     sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size);
  131.     s = strlen(wcount);
  132.     cp = wcount + s;
  133.     while (s < 7)
  134.         s++, *cp++ = ' ';
  135.     *cp = '\0';
  136.     if (subjline != NOSTR)
  137.         printf("%c%3d %-8s %16.16s %s \"%s\"\n", dispc, mesg,
  138.             hl.l_from, hl.l_date, wcount, subjline);
  139.     else
  140.         printf("%c%3d %-8s %16.16s %s\n", dispc, mesg,
  141.             hl.l_from, hl.l_date, wcount);
  142. }
  143.  
  144. /*
  145.  * Print out the value of dot.
  146.  */
  147.  
  148. pdot()
  149. {
  150.     printf("%d\n", dot - &message[0] + 1);
  151.     return(0);
  152. }
  153.  
  154. /*
  155.  * Print out all the possible commands.
  156.  */
  157.  
  158. pcmdlist()
  159. {
  160.     register struct cmd *cp;
  161.     register int cc;
  162.     extern struct cmd cmdtab[];
  163.  
  164.     printf("Commands are:\n");
  165.     for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) {
  166.         cc += strlen(cp->c_name) + 2;
  167.         if (cc > 72) {
  168.             printf("\n");
  169.             cc = strlen(cp->c_name) + 2;
  170.         }
  171.         if ((cp+1)->c_name != NOSTR)
  172.             printf("%s, ", cp->c_name);
  173.         else
  174.             printf("%s\n", cp->c_name);
  175.     }
  176.     return(0);
  177. }
  178.  
  179. /*
  180.  * Go to the previous message and type it.
  181.  * If at the top, just bitch.
  182.  */
  183.  
  184. previous(argv)
  185.     char **argv;
  186. {
  187.     register struct message *mp;
  188.     register int c;
  189.     int list[2];
  190.  
  191.     c = 1;
  192.     if (argcount(argv) != 0)
  193.         c = atoi(argv[0]);
  194.     while (c--) {
  195.         mp = dot;
  196.         mp--;
  197.         if (mp < &message[0]) {
  198.             printf("Nonzero address required\n");
  199.             return(0);
  200.         }
  201.         dot = mp;
  202.     }
  203.     list[0] = dot - &message[0] + 1;
  204.     list[1] = NULL;
  205.     return(type(list));
  206. }
  207.  
  208. /*
  209.  * Type out the messages requested.
  210.  */
  211.  
  212. type(msgvec)
  213.     int *msgvec;
  214. {
  215.     register *ip;
  216.     register struct message *mp;
  217.     register int mesg;
  218.     int c;
  219.     FILE *ibuf;
  220.  
  221.     for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  222.         mesg = *ip;
  223.         touch(mesg);
  224.         mp = &message[mesg-1];
  225.         dot = mp;
  226.         print(mp);
  227.     }
  228.     return(0);
  229. }
  230.  
  231. /*
  232.  * Print the indicated message on standard output.
  233.  */
  234.  
  235. print(mp)
  236.     register struct message *mp;
  237. {
  238.  
  239.     if (value("quiet") == NOSTR)
  240.         printf("Message %2d:\n", mp - &message[0] + 1);
  241.     touch(mp - &message[0] + 1);
  242.     send(mp, stdout);
  243. }
  244.  
  245. /*
  246.  * Print the top so many lines of each desired message.
  247.  * The number of lines is taken from the variable "toplines"
  248.  * and defaults to 5.
  249.  */
  250.  
  251. top(msgvec)
  252.     int *msgvec;
  253. {
  254.     register int *ip;
  255.     register struct message *mp;
  256.     register int mesg;
  257.     int c, topl, lines, lineb;
  258.     char *valtop, linebuf[LINESIZE];
  259.     FILE *ibuf;
  260.  
  261.     topl = 5;
  262.     valtop = value("toplines");
  263.     if (valtop != NOSTR) {
  264.         topl = atoi(valtop);
  265.         if (topl < 0 || topl > 10000)
  266.             topl = 5;
  267.     }
  268.     lineb = 1;
  269.     for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
  270.         mesg = *ip;
  271.         touch(mesg);
  272.         mp = &message[mesg-1];
  273.         dot = mp;
  274.         if (value("quiet") == NOSTR)
  275.             printf("Message %2d:\n", mesg);
  276.         ibuf = setinput(mp);
  277.         c = mp->m_lines;
  278.         if (!lineb)
  279.             printf("\n");
  280.         for (lines = 0; lines < c && lines <= topl; lines++) {
  281.             if (readline(ibuf, linebuf) <= 0)
  282.                 break;
  283.             puts(linebuf);
  284.             lineb = blankline(linebuf);
  285.         }
  286.     }
  287.     return(0);
  288. }
  289.  
  290. /*
  291.  * Touch all the given messages so that they will
  292.  * get mboxed.
  293.  */
  294.  
  295. stouch(msgvec)
  296.     int msgvec[];
  297. {
  298.     register int *ip;
  299.  
  300.     for (ip = msgvec; *ip != 0; ip++) {
  301.         touch(*ip);
  302.         dot = &message[*ip-1];
  303.     }
  304.     return(0);
  305. }
  306.