home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / telecom / uucp_442 / src / dmail / do_lists.c < prev    next >
C/C++ Source or Header  |  1991-01-06  |  4KB  |  233 lines

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