home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / telecom / uucp_442 / src / dmail / range.c < prev    next >
C/C++ Source or Header  |  1990-02-02  |  3KB  |  171 lines

  1.  
  2. /*
  3.  * RANGE.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/dmail/RCS/range.c,v 1.1 90/02/02 12:03:54 dillon Exp Locker: dillon $
  6.  *
  7.  *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
  8.  *
  9.  *  Global Routines:    REWIND_RANGE()
  10.  *            GET_RANGE()
  11.  *            SINGLE_POSITION()
  12.  *
  13.  *  Static Routines:    None.
  14.  *
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include "dmail.h"
  20.  
  21.  
  22. static int range_ac;
  23. static int in, start, end;
  24.  
  25. struct RANOP {
  26.     char *name;
  27.     int status, kstatus;
  28. };
  29.  
  30. static struct RANOP Ranop[] = {
  31.     "all",  0,              0,
  32.     "tag",  ST_TAG,         ST_DELETED,
  33.     "wri",  ST_STORED,      ST_DELETED,
  34.     "del",  ST_DELETED,     0,
  35.     "mar",  ST_READ,        ST_DELETED,
  36.     "unt",  0,              ST_DELETED | ST_TAG,
  37.     "unw",  0,              ST_DELETED | ST_STORED,
  38.     "und",  0,              ST_DELETED,
  39.     "unm",  0,              ST_DELETED | ST_READ,
  40.     NULL ,  0,            0 };
  41.  
  42. void
  43. rewind_range(beg)
  44. {
  45.     Silence = 0;
  46.     range_ac = beg;
  47.  
  48.     if (range_ac >= ac) {
  49.     start = (Current >= 0) ? Entry[Current].no : 0;
  50.     end   = start;
  51.     in    = 1;
  52.     } else {
  53.     in    = 0;
  54.     }
  55. }
  56.  
  57.  
  58. get_range()
  59. {
  60.     register char *ptr;
  61.     register int i;
  62.     static int status;        /* Status items required            */
  63.     static int kstatus;     /* Status items which cannot be present */
  64.  
  65. again:
  66.     if (in  &&  start <= end) {
  67.     i = indexof(start++);
  68.     if (i < 0  || (Entry[i].status & status) != status ||
  69.         (Entry[i].status & kstatus))
  70.         goto again;
  71.     return (start - 1);
  72.     }
  73.     in = status = kstatus = 0;
  74.     if (range_ac >= ac)
  75.     return (0);
  76.     ptr = av[range_ac++];
  77.     if (*ptr == '-') {
  78.     if (xstrncmp (ptr, "-s", 2) == 0) {
  79.         Silence = 1;
  80.         goto again;
  81.     }
  82.     start = 1;
  83.     ++ptr;
  84.     goto dash;
  85.     }
  86.     if (*ptr < '0'  ||  *ptr > '9') {
  87.     start = 1;
  88.     end = 0;
  89.     for (i = 0; Ranop[i].name; ++i) {
  90.         if (xstrncmp (ptr, Ranop[i].name, 3) == 0) {
  91.         status = Ranop[i].status;
  92.         kstatus = Ranop[i].kstatus;
  93.         goto imprange;
  94.         }
  95.     }
  96.     goto again;
  97.     }
  98.     start = atoi(ptr);
  99.     while (*(++ptr)) {
  100.     if (*ptr == '-') {
  101.         ++ptr;
  102.         goto dash;
  103.     }
  104.     }
  105.     if (range_ac >= ac)
  106.     return (start);
  107.     if (*av[range_ac] == '-') {
  108.     ptr = av[range_ac++] + 1;
  109.     goto dash;
  110.     }
  111.     return (start);
  112. dash:
  113.     if (*ptr) {
  114.     end = atoi(ptr);
  115.     goto imprange;
  116.     }
  117.     if (range_ac >= ac) {
  118.     end = 0;
  119.     goto imprange;
  120.     }
  121.     end = atoi(av[range_ac++]);
  122. imprange:
  123.     if (end == 0) {
  124.     end = indexof (0);
  125.     if (end < 0)
  126.         return (0);
  127.     end = Entry[end].no;
  128.     }
  129.     if (start > end) {
  130.     printf ("Bad Range: %s\n", av[range_ac - 1]);
  131.     return (0);
  132.     }
  133.     in = 1;
  134.     goto again;
  135. }
  136.  
  137.  
  138. single_position()
  139. {
  140.     int old = Current;
  141.  
  142.     switch (ac) {
  143.     case 1:
  144.     break;
  145.     case 2:
  146.     if (*av[1] == '\0' || (*av[1] == ' ' && strlen(av[1]) == 1))
  147.         break;
  148.     Current = indexof (atoi(av[1]));
  149.     if (Current < 0) {
  150.         Current = old;
  151.         puts ("Out of Range, 0 will take you to the last entry");
  152.         return (-1);
  153.     }
  154.     break;
  155.     default:
  156.     puts ("Range not implemented (yet?)");
  157.     return (-1);
  158.     }
  159.     while (Current < Entries  &&  Entry[Current].no == 0)
  160.     ++Current;
  161.     if (Current >= Entries) {
  162.     Current = old;
  163.     puts ("No More Messages");
  164.     return (-1);
  165.     }
  166.     position_current();
  167.     return (1);
  168. }
  169.  
  170.  
  171.