home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / dmail / do_lists.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-13  |  4.2 KB  |  258 lines

  1. /*
  2.  *  DO_LISTS.C
  3.  *
  4.  *  (C) Copyright 1985-1990 by Matthew Dillon,    All Rights Reserved.
  5.  *
  6.  *  Global Routines:    DO_SETLIST()
  7.  *            DO_LIST()
  8.  *            DO_SELECT()
  9.  *            DO_DEFER()
  10.  *
  11.  *  Static Routines:    None.
  12.  *
  13.  *    LIST associated commands.
  14.  *
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include "dmail.h"
  21.  
  22. Prototype int  do_setlist (char *str,      int com);
  23. Prototype int  do_rlist   (char *garbage, int com);
  24. Prototype int  do_list      (char *garbage, int com);
  25. Prototype int  do_select  (char *str,      int mode);
  26. Prototype int  do_defer   (char *garbage, int com);
  27.  
  28. int
  29. do_setlist (char *str, int com)
  30. {
  31.     int i, fw, idx, localecho = 1;
  32.     int sac = 1;
  33.  
  34.     push_break();
  35.     if (ac > sac && strcmp (av[sac], "-s") == 0) {
  36.     ++sac;
  37.     localecho = 0;
  38.     }
  39.     hold_load();
  40.     if (ac > sac) {
  41.     Listsize = 0;
  42.     for (i = sac; i < ac; ++i) {
  43.         fw = atoi(av[i]);
  44.         if (fw > 4096)
  45.         fw = 4096;
  46.         if (fw < 0    ||  (*av[i] < '0'  ||  *av[i] > '9'))
  47.         fw = 20;
  48.         else
  49.         ++i;
  50.         if (i >= ac)
  51.         continue;
  52.         idx = get_extra_ovr (av[i]);
  53.         if (idx < 0) {
  54.         printf ("To many entries, cannot load: %s\n", av[i]);
  55.         fflush (stdout);
  56.         continue;
  57.         }
  58.         header[Listsize] = idx;
  59.         width[Listsize] = fw;
  60.         ++Listsize;
  61.     }
  62.     }
  63.     nohold_load();
  64.     pop_break();
  65.     if (localecho) {
  66.     puts ("");
  67.     printf ("Entry   Width   Field\n\n");
  68.     for (i = 0; i < Listsize; ++i)
  69.         printf ("%-6d   %-5d   %s\n", i, width[i], Find[header[i]].search);
  70.     puts ("");
  71.     }
  72.     return (1);
  73. }
  74.  
  75.  
  76. /*
  77.  * Pre-position #   0 >     Current article
  78.  *            1 -     Read already
  79.  */
  80.  
  81. int
  82. do_rlist (char *garbage, int com)
  83. {
  84.     int
  85.         num = 20,
  86.         istart = Current,
  87.         iend = Current,
  88.         dir = 1,
  89.         try;
  90.     char
  91.         buf [64];
  92.  
  93.     if (av [1])
  94.         num = atoi (av [1]);
  95.  
  96.     if (num < 0) {
  97.         dir = -1;
  98.         num = -num;
  99.     }
  100.  
  101.     for (try = 0; try < 2 && num; ++try, (dir = -dir)) {
  102.         int i;
  103.         if (dir < 0) {
  104.             for (i = Current; i >= 0 && num; --i) {
  105.                 if (Entry [i].no && !(Entry [i].status & ST_DELETED)) {
  106.                     istart = i;
  107.                     --num;
  108.                 }
  109.             }
  110.         }
  111.         else {
  112.             for (i = Current; i < Entries && num; ++i) {
  113.                 if (Entry [i].no && !(Entry [i].status & ST_DELETED)) {
  114.                     iend = i;
  115.                     --num;
  116.                 }
  117.             }
  118.         }
  119.     }
  120.  
  121.     if (istart != iend) {
  122.         sprintf (buf, "%d-%d", Entry [istart].no, Entry [iend].no);
  123.         ac = 2;
  124.         av[1] = buf;
  125.         return do_list (NULL, 0);
  126.     }
  127.  
  128.     return -1;
  129. }
  130.  
  131. int
  132. do_list (char *garbage, int com)
  133. {
  134.     int
  135.         i,
  136.         j;
  137.     static char
  138.         curr [10] = { "    " };
  139.  
  140.     if (ac == 1) {
  141.         av [1] = "all";
  142.         ++ac;
  143.     }
  144.  
  145.     if (push_base ()) {
  146.         push_break ();
  147.         pop_base ();
  148.         PAGER ((char *) -1);
  149.         pop_break ();
  150.         return -1;
  151.     }
  152.  
  153.     PAGER (0);
  154.     FPAGER ("\n         ");
  155.     for (j = 0; j < Listsize; ++j) {
  156.         if (width [j]) {
  157.             sprintf (Puf, "%-*.*s",
  158.                 2 + width [j],
  159.                 2 + width [j],
  160.                 Find [header [j]].search);
  161.             FPAGER (Puf);
  162.         }
  163.     }
  164.  
  165.     FPAGER ("\n");
  166.     rewind_range (1);
  167.     while (i = get_range ()) {
  168.         i = indexof (i);
  169.         if (Entry [i].no  &&  ((Entry [i].status & ST_DELETED) == 0)) {
  170.             curr [0] = (Entry [i].status & ST_TAG) ? 'T' : ' ';
  171.             curr [1] = (i == Current) ? '>' : ' ';
  172.             curr [2] = (Entry [i].status & ST_READ)    ? 'r' : ' ';
  173.             curr [3] = (Entry [i].status & ST_STORED)  ? 'w' : ' ';
  174.             sprintf (Puf, "%s%-3d", curr, Entry [i].no);
  175.             FPAGER (Puf);
  176.             for (j = 0; j < Listsize; ++j) {
  177.                 if (width [j]) {
  178.                     sprintf(Puf, "  %-*.*s",
  179.                         width [j],
  180.                         width [j],
  181.                         Entry [i].fields [header [j]]);
  182.                 FPAGER (Puf);
  183.                 }
  184.             }
  185.             FPAGER ("\n");
  186.         }
  187.     }
  188.  
  189.     FPAGER ("\n");
  190.     PAGER ((char *) -1);
  191.     pop_base ();
  192.     return 1;
  193. }
  194.  
  195. int
  196. do_select (char *str, int mode)
  197. {
  198.     int
  199.         ret = 1,
  200.         localecho = 1,
  201.         avi = 1,
  202.         scr;
  203.  
  204.     if (ac == 1)
  205.         return 1;
  206.  
  207.     SelAll = 0;
  208.  
  209.     if (strcmp (av [avi], "-s") == 0) {
  210.         localecho = 0;
  211.         ++avi;
  212.         --ac;
  213.     }
  214.  
  215.     switch (ac) {
  216.         case 2:
  217.             SelAll = 1;
  218.             if (localecho)
  219.                 puts ("SELECT ALL");
  220.             ret = m_select (Nulav, mode);
  221.             break;
  222.  
  223.         case 1:
  224.             break;
  225.  
  226.         default:
  227.             ret = m_select (av + avi, mode);
  228.             scr = indexof (0);
  229.             if (scr > 0  &&  localecho)
  230.                 printf ("%d  Entries selected\n", Entry [scr].no);
  231.             break;
  232.     }
  233.  
  234.     if (ret < 0  &&  localecho) {
  235.         puts ("Null field");
  236.         return -1;
  237.     }
  238.  
  239.     return 1;
  240. }
  241.  
  242. int
  243. do_defer (char *garbage, int com)
  244. {
  245.     register int
  246.         i,
  247.         j;
  248.  
  249.     push_break ();
  250.     j = 1;
  251.     for (i = 0; i < Entries; ++i) {
  252.         if (Entry [i].no)
  253.             Entry [i].no = (Entry [i].status & ST_READ) ? 0 : j++;
  254.     }
  255.     pop_break ();
  256.     return 1;
  257. }
  258.