home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part01 / autosub.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  1.9 KB  |  86 lines

  1. /*
  2.  * $Id: autosub.c,v 4.4 1991/09/09 20:18:23 sob Exp sob $
  3.  *
  4.  * $Log: autosub.c,v $
  5.  * Revision 4.4  1991/09/09  20:18:23  sob
  6.  * release 4.4
  7.  *
  8.  *
  9.  *
  10.  */
  11. /* This software is Copyright 1991 by Stan Barber. 
  12.  *
  13.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  14.  * use this software as long as: there is no monetary profit gained
  15.  * specifically from the use or reproduction of this software, it is not
  16.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  17.  * included prominently in any copy made. 
  18.  *
  19.  * The author make no claims as to the fitness or correctness of this software
  20.  * for any use whatsoever, and it is provided as is. Any use of this software
  21.  * is at the user's own risk. 
  22.  */
  23.  
  24. #include "EXTERN.h"
  25. #include "common.h"
  26. #include "search.h"
  27. #include "ngsrch.h"
  28. #include "util.h"
  29. #include "INTERN.h"
  30. #include "autosub.h"
  31.  
  32. /* Consider the newsgroup specified, and return:    */
  33. /* : if we should autosubscribe to it            */
  34. /* ! if we should autounsubscribe to it            */
  35. /* \0 if we should ask the user.            */
  36. int
  37. auto_subscribe(ng)
  38. char *ng;
  39. {
  40.     char *s;
  41.  
  42.     if((s = getval("AUTOSUBSCRIBE", (char *)NULL))
  43.     && matchlist(s, ng)) return ':';
  44.     if((s = getval("AUTOUNSUBSCRIBE", (char *)NULL))
  45.     && matchlist(s, ng)) return '!';
  46.     return 0;
  47. }
  48.  
  49. bool
  50. matchlist(patlist, s)
  51. char *patlist;
  52. char *s;
  53. {
  54.     COMPEX ilcompex;
  55.     char *p;
  56.     char *err;
  57.     bool result;
  58.     bool tmpresult;
  59.  
  60.     result = FALSE;
  61.     init_compex(&ilcompex);
  62.     while(patlist && *patlist) {
  63.  
  64.     if(*patlist == '!') {
  65.         patlist++;
  66.         tmpresult = FALSE;
  67.     } else tmpresult = TRUE;
  68.  
  69.     if(p = index(patlist, ',')) *p = '\0';
  70.         /* compile regular expression */
  71.     err = ng_comp(&ilcompex,patlist,TRUE,TRUE);
  72.     if(p) *p++ = ',';
  73.  
  74.     if(err != Nullch) {
  75.         printf("\n%s\n", err) FLUSH;
  76.         finalize(1);
  77.     }
  78.     
  79.     if (execute(&ilcompex,s) != Nullch)
  80.         result = tmpresult;
  81.     patlist = p;
  82.     }
  83.     free_compex(&ilcompex);
  84.     return result;
  85. }
  86.