home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / vn.jan.88 / part03 / userlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-30  |  2.1 KB  |  117 lines

  1. /*
  2. ** vn news reader.
  3. **
  4. ** userlist.c - generate user's list of articles
  5. **
  6. ** see copyright disclaimer / history in vn.c source file
  7. */
  8.  
  9. #include <stdio.h>
  10. #include "tune.h"
  11. #include "node.h"
  12. #include "page.h"
  13. #include "vn.h"
  14.  
  15. extern PAGE Page;
  16. extern char *List_sep;
  17.  
  18. static char Pattern[MAX_C] = "";
  19.  
  20. /*
  21.     generate user list of articles - either article numbers
  22.     are input directly (numeric list), or input is a search
  23.     string - invoke regular expression library and examine titles
  24.     search string "*" reserved for marked articles.  Strings may
  25.     be prefixed with '!' for negation.
  26. */
  27. userlist (list)
  28. char *list;
  29. {
  30.     int i,j,anum[RECLEN/2],acount;
  31.     char neg, *s, sbuf[MAX_C+1], *reg, *regex(), *regcmp(), *index(), *strtok();
  32.  
  33.     user_str (sbuf,"Articles or title search string : ",1,Pattern);
  34.     if (sbuf[0] == '!')
  35.     {
  36.         neg = '!';
  37.         s = sbuf+1;
  38.     }
  39.     else
  40.     {
  41.         neg = '\0';
  42.         s = sbuf;
  43.     }
  44.     for (i=0; s[i] != '\0'; ++i)
  45.     {
  46.         if (index(List_sep,s[i]) == NULL)
  47.         {
  48.             if (s[i] < '0' || s[i] > '9')
  49.                 break;
  50.         }
  51.     }
  52.     acount = 0;
  53.  
  54.     if (s[i] == '\0')
  55.     {
  56.         for (s = strtok(s,List_sep); s != NULL; s = strtok(NULL,List_sep))
  57.         {
  58.             anum[acount] = atoi(s);
  59.             ++acount;
  60.         }
  61.     }
  62.     else
  63.     {
  64.         /* we save old input only if NOT a list of article numbers */
  65.         strcpy(Pattern,sbuf);
  66.         if (s[0] == ART_MARK)
  67.         {
  68.             for (i=0; i < Page.h.artnum; ++i)
  69.             {
  70.                 if (Page.b[i].art_mark == ART_MARK)
  71.                 {
  72.                     anum[acount] = Page.b[i].art_id;
  73.                     ++acount;
  74.                 }
  75.             }
  76.         }
  77.         else
  78.         {
  79.             reg = regcmp(s,(char *) 0);
  80.             if (reg != NULL)
  81.             {
  82.                 for (i=0; i < Page.h.artnum; ++i)
  83.                 {
  84.                     if (regex(reg,Page.b[i].art_t) != NULL)
  85.                     {
  86.                         anum[acount] = Page.b[i].art_id;
  87.                         ++acount;
  88.                     }
  89.                 }
  90.                 regfree (reg);
  91.             }
  92.             else
  93.                 preinfo ("bad regular expression syntax");
  94.         }
  95.     }
  96.  
  97.     /* algorithm is inefficient, but we're only handling a few numbers */
  98.     *list = '\0';
  99.     for (i=0; i < Page.h.artnum; ++i)
  100.     {
  101.         for (j=0; j < acount && anum[j] != Page.b[i].art_id; ++j)
  102.             ;
  103.         if (neg == '!')
  104.         {
  105.             if (j < acount)
  106.                 continue;
  107.         }
  108.         else
  109.         {
  110.             if (j >= acount)
  111.                 continue;
  112.         }
  113.         sprintf (list,"%d ",Page.b[i].art_id);
  114.         list += strlen(list);
  115.     }
  116. }
  117.