Commit | Line | Data |
---|---|---|
e6d184aa WD |
1 | This adds the ability to put rules into a filter/include/exclude file |
2 | in last-match-wins order. All you need to do is to start the file with | |
3 | this line: | |
4 | ||
5 | [last-match] | |
6 | ||
9a7eef96 WD |
7 | --- old/exclude.c |
8 | +++ new/exclude.c | |
9 | @@ -76,6 +76,7 @@ static BOOL parent_dirscan = False; | |
e6d184aa WD |
10 | static struct filter_struct **mergelist_parents; |
11 | static int mergelist_cnt = 0; | |
12 | static int mergelist_size = 0; | |
13 | +static int reversing_rules = 0; | |
14 | ||
15 | /* Each filter_list_struct describes a singly-linked list by keeping track | |
16 | * of both the head and tail pointers. The list is slightly unusual in that | |
9a7eef96 | 17 | @@ -244,6 +245,9 @@ static void add_rule(struct filter_list_ |
e6d184aa WD |
18 | if (!listp->tail) { |
19 | ret->next = listp->head; | |
20 | listp->head = listp->tail = ret; | |
21 | + } else if (reversing_rules) { | |
22 | + ret->next = listp->head; | |
23 | + listp->head = ret; | |
24 | } else { | |
25 | ret->next = listp->tail->next; | |
26 | listp->tail->next = ret; | |
9a7eef96 WD |
27 | @@ -970,6 +974,7 @@ void parse_filter_file(struct filter_lis |
28 | char line[BIGPATHBUFLEN]; | |
e6d184aa WD |
29 | char *eob = line + sizeof line - 1; |
30 | int word_split = mflags & MATCHFLG_WORD_SPLIT; | |
31 | + int save_reversing_rules = reversing_rules; | |
32 | ||
33 | if (!fname || !*fname) | |
34 | return; | |
9a7eef96 | 35 | @@ -1005,6 +1010,7 @@ void parse_filter_file(struct filter_lis |
e6d184aa WD |
36 | } |
37 | dirbuf[dirbuf_len] = '\0'; | |
38 | ||
39 | + reversing_rules = 0; | |
40 | while (1) { | |
41 | char *s = line; | |
42 | int ch, overflow = 0; | |
9a7eef96 | 43 | @@ -1030,6 +1036,10 @@ void parse_filter_file(struct filter_lis |
e6d184aa WD |
44 | s = line; |
45 | } | |
46 | *s = '\0'; | |
47 | + if (*line == '[' && strcmp(line+1, "last-match]") == 0) { | |
48 | + reversing_rules = 1; | |
49 | + continue; | |
50 | + } | |
51 | /* Skip an empty token and (when line parsing) comments. */ | |
52 | if (*line && (word_split || (*line != ';' && *line != '#'))) | |
53 | parse_rule(listp, line, mflags, xflags); | |
9a7eef96 | 54 | @@ -1037,6 +1047,7 @@ void parse_filter_file(struct filter_lis |
e6d184aa WD |
55 | break; |
56 | } | |
57 | fclose(fp); | |
58 | + reversing_rules = save_reversing_rules; | |
59 | } | |
60 | ||
61 | /* If the "for_xfer" flag is set, the prefix is made compatible with the |