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