home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / trn_12.zip / src / autosub.c < prev    next >
C/C++ Source or Header  |  1993-12-04  |  2KB  |  89 lines

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