1: #ifndef lint
2: static char *sccsid = "@(#)ngmatch.c 1.3 (Berkeley) 2/6/88";
3: #endif
4:
5: #include "common.h"
6:
7: /*
8: * nntpngmatch -- match a list of newsgroup specifiers with a list of
9: * given newsgroups. A pointer to the routine which determines a match is
10: * also given. This allows us to do regular expression handling for RFC
11: * 977's NEWNEWS, and more efficient "strncmps" for the access file, which
12: * must be checked often.
13: *
14: * This is NOT the same routine as ngmatch in the news software. Pity.
15: *
16: * Parameters: "nglist" is the list of group specifiers (limited
17: * regexp) to match against.
18: * "ngcount" is the number of groups in nglist.
19: * "matchlist" is the list of newsgroups to match against.
20: * "matchcount" is number of groups in matchlist.
21: *
22: * Returns: 1 if the named newsgroup is in the list.
23: * 0 otherwise.
24: */
25:
26: ngmatch(func, dflt, ngspec, ngspeccount, matchlist, matchcount)
27: int (*func)();
28: int dflt;
29: char **ngspec;
30: int ngspeccount;
31: char **matchlist;
32: int matchcount;
33: {
34: register int i, j;
35: register int match;
36: register char *cp;
37:
38: if (ngspeccount == 0)
39: return (1);
40:
41: match = dflt;
42:
43: for (i = 0; i < matchcount; ++i) {
44: if (cp = index(matchlist[i], '/'))
45: *cp = '\0';
46: for (j = 0; j < ngspeccount; ++j) {
47: if (ngspec[j][0] == '!') { /* Handle negation */
48: if ((*func)(ngspec[j]+1, matchlist[i])) {
49: match = 0;
50: }
51: } else {
52: if ((*func)(ngspec[j], matchlist[i])) {
53: match = 1;
54: }
55: }
56: }
57: }
58:
59: return (match);
60: }
61:
62:
63: /*
64: * restreql -- A small regular expression string equivalnce routine.
65: * Thanks and a tip of the hat to Nick Lai, <lai@shadow.berkeley.edu>
66: * for this time saving device.
67: *
68: * Parameters: "w" is an asterisk-broadened regexp,
69: * "s" is a non-regexp string.
70: * Returns: 1 if match, 0 otherwise.
71: *
72: * Side effects: None.
73: */
74:
75: restreql(w, s)
76: register char *w;
77: register char *s;
78: {
79:
80: while (*s && *w) {
81: switch (*w) {
82: case '*':
83: for (w++; *s; s++)
84: if (restreql(w, s))
85: return 1;
86: break;
87: default:
88: if (*w != *s)
89: return 0;
90: w++, s++;
91: break;
92: }
93: }
94: if (*s)
95: return 0;
96: while (*w)
97: if (*w++ != '*')
98: return 0;
99:
100: return 1;
101: }
102:
103:
104: /*
105: * s1strneql -- see if s1 is equivalent to s2 up to the length of s1.
106: * Return non-zero if so, 0 otherwise.
107: */
108:
109: s1strneql(s1, s2)
110: register char *s1;
111: register char *s2;
112: {
113: return (!strncmp(s1, s2, strlen(s1)));
114: }
Defined functions
Defined variables
sccsid
defined in line
2;
never used