1 /* autosub.c
2  */
3 /* This software is copyrighted as detailed in the LICENSE file. */
4 
5 
6 #include "EXTERN.h"
7 #include "common.h"
8 #include "search.h"
9 #include "list.h"
10 #include "ngdata.h"
11 #include "ngsrch.h"
12 #include "env.h"
13 #include "util.h"
14 #include "util2.h"
15 #include "final.h"
16 #include "INTERN.h"
17 #include "autosub.h"
18 
19 /* Consider the newsgroup specified, and return:	*/
20 /* : if we should autosubscribe to it			*/
21 /* ! if we should autounsubscribe to it			*/
22 /* \0 if we should ask the user.			*/
23 int
auto_subscribe(name)24 auto_subscribe(name)
25 char* name;
26 {
27     char* s;
28 
29     if((s = getval("AUTOSUBSCRIBE", (char*)NULL)) && matchlist(s, name))
30 	return ':';
31     if((s = getval("AUTOUNSUBSCRIBE", (char*)NULL)) && matchlist(s, name))
32 	return '!';
33     return 0;
34 }
35 
36 bool
matchlist(patlist,s)37 matchlist(patlist, s)
38 char* patlist;
39 char* s;
40 {
41     COMPEX ilcompex;
42     char* p;
43     char* err;
44     bool result;
45     bool tmpresult;
46 
47     result = FALSE;
48     init_compex(&ilcompex);
49     while(patlist && *patlist) {
50 	if (*patlist == '!') {
51 	    patlist++;
52 	    tmpresult = FALSE;
53 	} else
54 	    tmpresult = TRUE;
55 
56 	if ((p = index(patlist, ',')) != NULL)
57 	    *p = '\0';
58         /* compile regular expression */
59 	err = ng_comp(&ilcompex,patlist,TRUE,TRUE);
60 	if (p)
61 	    *p++ = ',';
62 
63 	if (err != NULL) {
64 	    printf("\n%s\n", err) FLUSH;
65 	    finalize(1);
66 	}
67 
68 	if (execute(&ilcompex,s) != NULL)
69 	    result = tmpresult;
70 	patlist = p;
71     }
72     free_compex(&ilcompex);
73     return result;
74 }
75