-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexclude.b
64 lines (55 loc) · 1.16 KB
/
exclude.b
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
implement Exclude;
include "exclude.m";
include "sys.m";
sys: Sys;
include "bufio.m";
bufio: Bufio;
Iobuf: import bufio;
include "filepat.m";
filepat: Filepat;
stderr: ref Sys->FD;
REPOPATH: string;
#int is flag for pattern negation: 0 for normal pattern; 1 is for negated
#where string is pattern
patterns: list of (int, string) = nil;
init(args: list of string)
{
sys = load Sys Sys->PATH;
bufio = load Bufio Bufio->PATH;
filepat = load Filepat Filepat->PATH;
stderr = sys->fildes(2);
REPOPATH = hd args;
ibuf := bufio->open(REPOPATH + EXCLUDEPATH, Bufio->OREAD);
if(ibuf == nil)
{
sys->fprint(stderr, "excude file couldn't be found\n");
return;
}
while((s := ibuf.gets('\n')) != "")
{
negated := 0;
if(s[0] == '#' || s[0] == '\n') continue;
if(s[0] == '!')
{
negated = 1;
s = s[1:];
}
s = s[:len s - 1];
if(s[len s - 1] == '/')
s[len s] = '*';
patterns = (negated, s) :: patterns;
}
}
excluded(path: string): int
{
ret := 0;
for(l := patterns; l != nil; l = tl l)
{
elem := hd l;
if(!elem.t0 && filepat->match(elem.t1, path))
ret = 1;
else if(elem.t0 && filepat->match(elem.t1, path))
ret = 0;
}
return ret;
}