interplane.Get Omega
Read in your language

babel

aien-dev/babel

Brought by drakestapleton

branch main Branches Tags History

babel / src / 65-exclude.om

365 lines · 6678 bytes Raw Blame History
1note babel 75-exclude: the --exclude manifest. One "<path> <reason>" per line; blank lines and lines
2note starting with # are ignored. <path> is relative to the walked root and is an exact path or a
3note directory prefix (a trailing / is optional); globs are refused. A matched walked file or skipped
4note entry stays in the completion denominator with verdict EXCLUDED and the manifest's reason.
5note Source babel recognises (and so every split item) can never be excluded, hidden or symlinked or
6note not. A line without a reason, an entry that matches nothing, a glob or an entry that names source
7note is diagnosed with its line number, and babel exits 2 before writing anything.
8global Ex0 ulong 1
9global Exn ulong 1
10global Exa0 ulong 1
11global Exan ulong 1
12global Exr0 ulong 1
13global Exrn ulong 1
14global Exh uchar 32
15note entries: path Me0/Men, reason Mr0/Mrn (pool), manifest line Mln, matches Mht
16global Me0 ulong 256
17global Men ulong 256
18global Mr0 ulong 256
19global Mrn ulong 256
20global Mln ulong 256
21global Mht ulong 256
22global Nme ulong 1
23note per walked file / skipped entry: matching entry + 1 (0 none)
24global Fex ulong 2048
25global Skx ulong 2048
26note the manifest itself when it lies in the walked tree: file index + 1, skipped index + 1
27global Mfi ulong 1
28global Msk ulong 1
29global Nexe ulong 1
30text EMh "babel: --exclude "
31text EMl " line "
32text EMc ": "
33text EMa " -> "
34text EMrd "cannot be read"
35text EMcp "has more than 256 entries"
36text EMnr "entry has no reason (each line is <path> <reason>): "
37text EMgl "globs are not supported (an exact path or a dir/ prefix): "
38text EMst "entry matches nothing in the walked tree (stale manifest): "
39text EMsr "entry names source babel splits, which cannot be excluded: "
40
41note --exclude given: read, hash, parse and match the manifest against the walk of root Pl[d, d+dn);
42note false after reporting every problem
43fn exload d ulong dn ulong to bool
44put Nexe 0 0
45if eq get Exn 0 0
46ret true
47end
48m = mark
49absob get Ex0 0 get Exn 0
50put Exa0 0 psave m sub mark m
51put Exan 0 sub mark m
52e = mark
53r = hfile m e
54if ge r 0
55for i ulong 32
56put Exh i get Hash i
57end
58r = rfile m e
59end
60reset m
61if lt r 0
62exdiag 0 EMrd 0 0
63ret false
64end
65exrel d dn
66if not exparse
67exdiag 0 EMcp 0 0
68ret false
69end
70exmatch
71ret eq get Nexe 0 0
72end
73
74note the manifest's path relative to the walked root Pl[d, d+dn), when it lies inside it (else Exrn 0)
75fn exrel d ulong dn ulong to void
76put Exrn 0 0
77a = get Exa0 0
78an = get Exan 0
79if le an add dn 1
80ret
81end
82if not pleq a dn d dn
83ret
84end
85if ne get Pl add a dn 47
86ret
87end
88put Exr0 0 add a add dn 1
89put Exrn 0 sub an add dn 1
90end
91
92note split Fb[0, Fn) into lines; false when the entry table is full
93fn exparse to bool
94put Nme 0 0
95n = get Fn 0
96s = ulong 0
97lno = ulong 1
98while lt s n bound 999999
99k = s
100while lt k n bound 999999
101if eq get Fb k 10
102break
103end
104k = add k 1
105end
106if not exline s k lno
107ret false
108end
109s = add k 1
110lno = add lno 1
111end
112ret true
113end
114
115fn exws c uchar to bool
116if eq c 32
117ret true
118end
119if eq c 9
120ret true
121end
122ret eq c 13
123end
124
125note one line Fb[a, b): trimmed, comment or blank skipped, else <path> and <reason> recorded
126fn exline a ulong b ulong lno ulong to bool
127s = a
128while lt s b bound 999999
129if not exws get Fb s
130break
131end
132s = add s 1
133end
134e = b
135while gt e s bound 999999
136if not exws get Fb sub e 1
137break
138end
139e = sub e 1
140end
141if ge s e
142ret true
143end
144if eq get Fb s 35
145ret true
146end
147p = s
148while lt p e bound 999999
149if exws get Fb p
150break
151end
152p = add p 1
153end
154q = p
155while lt q e bound 999999
156if not exws get Fb q
157break
158end
159q = add q 1
160end
161ret exadd s p q e lno
162end
163
164note record entry path Fb[s, p) ("./" prefix and trailing "/" removed) and reason Fb[q, e)
165fn exadd s ulong p ulong q ulong e ulong lno ulong to bool
166i = get Nme 0
167if ge i 256
168ret false
169end
170a = s
171if gt sub p a 2
172if eq get Fb a 46
173if eq get Fb add a 1 47
174a = add a 2
175end
176end
177end
178z = p
179while gt sub z a 1 bound 4096
180if ne get Fb sub z 1 47
181break
182end
183z = sub z 1
184end
185m = mark
186bfb a sub z a
187put Me0 i psave m sub mark m
188put Men i sub mark m
189reset m
190bfb q sub e q
191put Mr0 i psave m sub mark m
192put Mrn i sub mark m
193reset m
194put Mln i lno
195put Mht i 0
196put Nme 0 add i 1
197ret true
198end
199
200note match every entry against the walked files and the skipped entries
201fn exmatch to void
202put Mfi 0 0
203put Msk 0 0
204for f ulong get Nf 0
205put Fex f 0
206if gt get Exrn 0 0
207if pleq get F0 f get Fl f get Exr0 0 get Exrn 0
208put Mfi 0 add f 1
209end
210end
211end
212for i ulong get Nsk 0
213put Skx i 0
214if gt get Exrn 0 0
215if pleq get Sk0 i get Skl i get Exr0 0 get Exrn 0
216put Msk 0 add i 1
217end
218end
219end
220for e ulong get Nme 0
221exent e
222end
223end
224
225fn exent e ulong to void
226if eq get Mrn e 0
227exdiag add e 1 EMnr 0 0
228ret
229end
230if exglob e
231exdiag add e 1 EMgl 0 0
232ret
233end
234for f ulong get Nf 0
235if exhit e get F0 f get Fl f
236exfile e f
237end
238end
239for i ulong get Nsk 0
240if exhit e get Sk0 i get Skl i
241exsk e i
242end
243end
244if eq get Mht e 0
245exdiag add e 1 EMst 0 0
246end
247end
248
249note entry e covers walked file f, unless f is source (diagnosed) or the manifest itself
250fn exfile e ulong f ulong to void
251put Mht e add get Mht e 1
252if ne get Flg f 0
253exdiag add e 1 EMsr get F0 f get Fl f
254ret
255end
256if eq get Mfi 0 add f 1
257ret
258end
259if eq get Fex f 0
260put Fex f add e 1
261end
262end
263
264note entry e covers skipped entry i, unless its name is source (hidden or symlinked source)
265fn exsk e ulong i ulong to void
266put Mht e add get Mht e 1
267if ne langof get Sk0 i get Skl i 0
268exdiag add e 1 EMsr get Sk0 i get Skl i
269ret
270end
271if eq get Msk 0 add i 1
272ret
273end
274if eq get Skx i 0
275put Skx i add e 1
276end
277end
278
279note path Pl[o, o+n) is the entry or lies below it
280fn exhit e ulong o ulong n ulong to bool
281a = get Me0 e
282k = get Men e
283if eq k 0
284ret false
285end
286if pleq o n a k
287ret true
288end
289if le n k
290ret false
291end
292if not pleq o k a k
293ret false
294end
295ret eq get Pl add o k 47
296end
297
298fn exglob e ulong to bool
299a = get Me0 e
300for i ulong get Men e
301c = get Pl add a i
302if eq c 42
303ret true
304end
305if eq c 63
306ret true
307end
308if eq c 91
309ret true
310end
311end
312ret false
313end
314
315note "babel: --exclude FILE[ line N]: <msg>[<entry>][ -> <path>]" on stderr; ln1 = entry index + 1 (0: whole file)
316fn exdiag ln1 ulong s view uchar * o ulong n ulong to void
317m = mark
318bs EMh
319bpl get Ex0 0 get Exn 0
320if gt ln1 0
321bs EMl
322bu get Mln sub ln1 1
323end
324bs EMc
325bs s
326if gt ln1 0
327e = sub ln1 1
328bpl get Me0 e get Men e
329end
330if gt n 0
331bs EMa
332bpl o n
333end
334bc 10
335flush 2 m
336put Nexe 0 add get Nexe 0 1
337end
338
339note first k bytes of the manifest's sha256 in hex
340fn exhex k ulong to void
341for i ulong k
342c = get Exh i
343bhex ulong shr c 4
344bhex ulong and c 15
345end
346end
347
348text CxA "{\"path\": "
349text CxB ", \"sha256\": \""
350text CxC "\", \"walked_as\": "
351text CxN "null"
352
353fn exjson to void
354if eq get Exn 0 0
355bs CxN
356ret
357end
358bs CxA
359bjq get Ex0 0 get Exn 0
360bs CxB
361exhex 32
362bs CxC
363bqnull get Exr0 0 get Exrn 0
364bc 125
365end