interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / quiet / qn1dig.om

428 lines · 6821 bytes Raw Blame History
1note quiet/qn1dig.om: one digest file per subscriber, rewritten when an event is appended.
2note A page read does not call qnregen. Caps: the newest 64 KiB of events, 32 lines, no clock.
3text tqev "quiet/events"
4text tqsb "quiet/subs"
5text tqod "quiet/out/"
6text tqdir "quiet"
7text tqoutdir "quiet/out"
8text tqdv1 "QUIET-DIGEST v1\n"
9text tqsk "subscriber="
10text tqak "agent="
11text tqrk "repo="
12text tqck "count="
13text tqkind "patch"
14text tqnl "\n"
15global qndd uchar 512
16global qnddl ulong 1
17global qnev uchar 65536
18global qnevl ulong 1
19global qnsub uchar 8192
20global qnsl ulong 1
21global qnline uchar 256
22global qnlinel ulong 1
23global qnhold uchar 256
24global qnholn ulong 1
25global qnout uchar 8192
26global qnol ulong 1
27global qnovf ulong 1
28global qnt0 ulong 1
29global qnt1 ulong 1
30global qnfa ulong 1
31global qnfn ulong 1
32global qnra ulong 1
33global qnrn ulong 1
34fn qnsetd p view uchar * n ulong to void
35put qnddl 0 0
36if or eq n 0 gt n 512
37ret
38end
39for i ulong n bound 512
40put qndd i get p i
41end
42put qnddl 0 n
43end
44fn qnsetg to void
45qnsetd tfdata len tfdata
46end
47fn qnpfx t view uchar * to void
48fpb
49for i ulong get qnddl 0 bound 512
50fpc get qndd i
51end
52fpt t
53end
54fn qnmk to void
55qnpfx tqdir
56x = makedir fpth 0 get fpthl 0 448
57qnpfx tqoutdir
58x = makedir fpth 0 get fpthl 0 448
59end
60fn qnread to bool
61r = frdall
62if lt r 0
63put fxol 0 0
64ret false
65end
66ret true
67end
68fn qnapp to bool
69qnmk
70qnpfx tqev
71fd = fopen fpth 0 get fpthl 0 525377 384
72if lt fd 0
73ret false
74end
75left = get qnlinel 0
76off = ulong 0
77ok = true
78while gt left 0 bound 256
79k = write int fd qnline off left
80if le k 0
81ok = false
82left = ulong 0
83end
84if gt k 0
85off = add off ulong k
86left = sub left ulong k
87end
88end
89x = fsync int fd
90x = fclose int fd
91ret ok
92end
93fn qncc c uchar to void
94n = get qnol 0
95if lt n 8191
96put qnout n c
97put qnol 0 add n 1
98end
99if ge n 8191
100put qnovf 0 1
101end
102end
103fn qnct t view uchar * to void
104for i ulong len t bound 64
105qncc get t i
106end
107end
108fn qnhcs a ulong n ulong to void
109for i ulong n bound 64
110qncc get qnhold add a i
111end
112end
113fn qntok k ulong to bool
114p = ulong 0
115seen = ulong 0
116while lt p get qnlinel 0 bound 256
117while and lt p get qnlinel 0 eq get qnline p 32 bound 256
118p = add p 1
119end
120q = p
121while and lt q get qnlinel 0 ne get qnline q 32 bound 256
122q = add q 1
123end
124if gt q p
125if eq seen k
126put qnt0 0 p
127put qnt1 0 q
128ret true
129end
130seen = add seen 1
131end
132p = q
133end
134ret false
135end
136fn qneq a ulong n ulong t view uchar * to bool
137if ne n len t
138ret false
139end
140for i ulong n bound 64
141if ne get qnline add a i get t i
142ret false
143end
144end
145ret true
146end
147fn qnstar a ulong n ulong to bool
148if ne n 1
149ret false
150end
151ret eq get qnhold a 42
152end
153fn qnholdline to void
154n = get qnlinel 0
155if gt n 256
156n = ulong 256
157end
158for i ulong n bound 256
159put qnhold i get qnline i
160end
161put qnholn 0 n
162end
163fn qncopyline s ulong e ulong to void
164n = sub e s
165if gt n 255
166n = ulong 255
167end
168for i ulong n bound 256
169put qnline i get qnev add s i
170end
171put qnlinel 0 n
172end
173fn qnsame a ulong n ulong b ulong m ulong to bool
174if ne n m
175ret false
176end
177for i ulong n bound 64
178if ne get qnline add a i get qnhold add b i
179ret false
180end
181end
182ret true
183end
184fn qnmatch to bool
185if not qntok 0
186ret false
187end
188if not qneq get qnt0 0 sub get qnt1 0 get qnt0 0 tqkind
189ret false
190end
191if not qntok 1
192ret false
193end
194er = get qnt0 0
195en = sub get qnt1 0 er
196if not qntok 2
197ret false
198end
199ea = get qnt0 0
200eal = sub get qnt1 0 ea
201if not qnstar get qnra 0 get qnrn 0
202if not qnsame er en get qnra 0 get qnrn 0
203ret false
204end
205end
206if not qnstar get qnfa 0 get qnfn 0
207if not qnsame ea eal get qnfa 0 get qnfn 0
208ret false
209end
210end
211ret true
212end
213fn qnuserok a ulong n ulong to bool
214if or eq n 0 gt n 39
215ret false
216end
217for i ulong n bound 39
218c = get qnhold add a i
219ok = false
220if and ge c 48 le c 57
221ok = true
222end
223if and ge c 97 le c 122
224ok = true
225end
226if eq c 45
227ok = true
228end
229if not ok
230ret false
231end
232end
233ret true
234end
235fn qnwriteu a ulong n ulong to bool
236qnpfx tqod
237for i ulong n bound 39
238fpc get qnhold add a i
239end
240fd = fopen fpth 0 get fpthl 0 524865 384
241if lt fd 0
242ret false
243end
244left = get qnol 0
245off = ulong 0
246ok = true
247while gt left 0 bound 8192
248k = write int fd qnout off left
249if le k 0
250ok = false
251left = ulong 0
252end
253if gt k 0
254off = add off ulong k
255left = sub left ulong k
256end
257end
258x = fsync int fd
259x = fclose int fd
260ret ok
261end
262fn qnnum v ulong to void
263if ge v 10
264qnnum div v 10
265end
266qncc add 48 uchar rem v 10
267end
268note qnscan: walk the event lines; count the matching ones, and when emit is true append the
269note matching lines numbered from skip on (the newest 32 when there are more)
270fn qnscan emit bool skip ulong to ulong
271cnt = ulong 0
272p = ulong 0
273while lt p get qnevl 0 bound 65536
274e = p
275while lt e get qnevl 0 bound 65536
276if eq get qnev e 10
277break
278end
279e = add e 1
280end
281qncopyline p e
282if qnmatch
283if and emit ge cnt skip
284qnnum cnt
285qncc 32
286for i ulong get qnlinel 0 bound 256
287qncc get qnline i
288end
289qncc 10
290end
291cnt = add cnt 1
292end
293if lt e get qnevl 0
294p = add e 1
295end
296if ge e get qnevl 0
297p = e
298end
299end
300ret cnt
301end
302fn qnfinish ua ulong un ulong to bool
303put qnol 0 0
304put qnovf 0 0
305total = qnscan false 0
306put qnol 0 0
307qnct tqdv1
308qnct tqsk
309qnhcs ua un
310qnct tqnl
311qnct tqak
312qnhcs get qnfa 0 get qnfn 0
313qnct tqnl
314qnct tqrk
315qnhcs get qnra 0 get qnrn 0
316qnct tqnl
317qnct tqck
318qnnum total
319qncc 10
320skip = ulong 0
321if gt total 32
322skip = sub total 32
323end
324k = qnscan true skip
325if eq get qnovf 0 1
326ret false
327end
328ret qnwriteu ua un
329end
330fn qnone to bool
331qnholdline
332if not qntok 0
333ret false
334end
335ua = get qnt0 0
336un = sub get qnt1 0 ua
337if not qnuserok ua un
338ret false
339end
340if not qntok 1
341ret false
342end
343put qnfa 0 get qnt0 0
344put qnfn 0 sub get qnt1 0 get qnt0 0
345if not qntok 2
346ret false
347end
348put qnra 0 get qnt0 0
349put qnrn 0 sub get qnt1 0 get qnt0 0
350note a filter word is at most 39 bytes when forged wrote the line (qnokg). A longer one, from a
351note hand-edited file, is refused here: qnhcs and qnsame loop over it under bound 64.
352if or gt get qnfn 0 39 gt get qnrn 0 39
353ret false
354end
355ret qnfinish ua un
356end
357note qntail: start of the newest 64 KiB of fxo (n bytes), at a line start
358fn qntail n ulong to ulong
359if le n 65536
360ret 0
361end
362s = sub n 65536
363if eq get fxo sub s 1 10
364ret s
365end
366while lt s n bound 65536
367if eq get fxo s 10
368ret add s 1
369end
370s = add s 1
371end
372ret n
373end
374fn qnregen to bool
375qnmk
376put qnevl 0 0
377qnpfx tqev
378if qnread
379n = get fxol 0
380s = qntail n
381m = sub n s
382for i ulong m bound 65536
383put qnev i get fxo add s i
384end
385put qnevl 0 m
386end
387qnpfx tqsb
388if not qnread
389put qnsl 0 0
390ret true
391end
392n = get fxol 0
393if gt n 8192
394n = ulong 8192
395end
396for i ulong n bound 8192
397put qnsub i get fxo i
398end
399put qnsl 0 n
400p = ulong 0
401ok = true
402while lt p get qnsl 0 bound 8192
403e = p
404while lt e get qnsl 0 bound 8192
405if eq get qnsub e 10
406break
407end
408e = add e 1
409end
410m = sub e p
411if and gt m 0 le m 255
412for i ulong m bound 256
413put qnline i get qnsub add p i
414end
415put qnlinel 0 m
416if not qnone
417ok = false
418end
419end
420if lt e get qnsl 0
421p = add e 1
422end
423if ge e get qnsl 0
424p = e
425end
426end
427ret ok
428end