interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / galaxy / stars.om

557 lines · 8798 bytes Raw Blame History
1om2
2note stars.om: the galaxy's stars and merges from the Radicle registry. Its own program.
3note stars RIDS.md STORAGE/ [repos.tsv]
4note Reads the FIRST table of RIDS.md (header "| repo | RID | default branch"), the table forged's
5note allow-list uses, and writes stars.tsv in the working directory (tmp, sync, rename):
6note R name tier one line per row whose name and RID are well formed, whose storage folder
7note STORAGE/<rid> exists and which is not on the deny list
8note M repo head note the 8 rows with the latest UTC column, newest first
9note tier is "core" when column 4 of repos.tsv says so for that name, else "rest".
10note Exit 0 written, 1 usage, 2 RIDS.md unreadable or without the table, 3 write failed.
11note At most 400 rows are listed (the page draws at most 400 stars) and the merges are chosen from the
12note first 128 listed rows, so stars.tsv is at most 8*281 + 400*72 = 31,048 bytes, under the 32,768
13note bytes galaxy-live reads. The crypto repositories are never listed, whatever the table says.
14const SCAP ulong 400
15global rb uchar 262144
16global rbl ulong 1
17global tb uchar 65536
18global tbl ulong 1
19global sp uchar 1024
20global spl ulong 1
21global pa uchar 1100
22global wb uchar 65536
23global wbl ulong 1
24global rs ulong 128
25global re ulong 128
26global ru ulong 128
27global rd ulong 128
28global rn ulong 1
29global pl uchar 64
30global rk ulong 1
31text thd "| repo | RID | default branch"
32text dn1 "omega-pearl"
33text dn2 "aien-crypto"
34text dr1 "rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ"
35text tcor "core"
36text tres "rest"
37text fout "stars.tsv"
38text ftmp "stars.tsv.tmp"
39note ---- output buffer
40fn wab c uchar to void
41o = get wbl 0
42if lt o 65535
43put wb o c
44put wbl 0 add o 1
45end
46end
47fn wa t view uchar * to void
48for i ulong len t bound 64
49wab get t i
50end
51end
52note was: at most cap bytes of rb a..b; a control byte or tab becomes a space
53fn was a ulong b ulong cap ulong to void
54e = b
55if lt b a
56ret
57end
58if gt sub b a cap
59e = add a cap
60end
61i = a
62while lt i e bound 262144
63c = get rb i
64if lt c 32
65c = uchar 32
66end
67wab c
68i = add i 1
69end
70end
71note ---- scanning rb; every index stays inside 0..rbl
72fn reol a ulong to ulong
73lim = get rbl 0
74i = a
75while lt i lim bound 262144
76if eq get rb i 10
77ret i
78end
79i = add i 1
80end
81ret lim
82end
83fn rbar a ulong e ulong to ulong
84i = a
85while lt i e bound 262144
86if eq get rb i 124
87ret i
88end
89i = add i 1
90end
91ret e
92end
93note rbk: the k-th bar of the row s..e counting the leading one as 0; e when the row has fewer
94fn rbk s ulong e ulong k ulong to ulong
95p = s
96j = ulong 0
97while lt j k bound 16
98p = rbar add p 1 e
99j = add j 1
100end
101ret p
102end
103note rlb: the last bar before e in the row s..e, or s
104fn rlb s ulong e ulong to ulong
105i = e
106while gt i s bound 262144
107if eq get rb sub i 1 124
108ret sub i 1
109end
110i = sub i 1
111end
112ret s
113end
114fn rtl a ulong e ulong to ulong
115i = a
116while lt i e bound 262144
117if ne get rb i 32
118ret i
119end
120i = add i 1
121end
122ret e
123end
124fn rtr a ulong e ulong to ulong
125i = e
126while gt i a bound 262144
127if ne get rb sub i 1 32
128ret i
129end
130i = sub i 1
131end
132ret a
133end
134fn ralnum c uchar to bool
135if and ge c 97 le c 122
136ret true
137end
138if and ge c 65 le c 90
139ret true
140end
141ret and ge c 48 le c 57
142end
143fn rnameok a ulong b ulong to bool
144if ge a b
145ret false
146end
147if gt sub b a 64
148ret false
149end
150i = a
151while lt i b bound 64
152c = get rb i
153if not ralnum c
154if not or or eq c 45 eq c 46 eq c 95
155ret false
156end
157end
158i = add i 1
159end
160ret true
161end
162note rridok: "rad:" then 20 to 56 letters and digits
163fn rridok a ulong b ulong to bool
164if lt b a
165ret false
166end
167n = sub b a
168if or lt n 24 gt n 60
169ret false
170end
171if ne get rb a 114
172ret false
173end
174if ne get rb add a 1 97
175ret false
176end
177if ne get rb add a 2 100
178ret false
179end
180if ne get rb add a 3 58
181ret false
182end
183i = add a 4
184while lt i b bound 64
185if not ralnum get rb i
186ret false
187end
188i = add i 1
189end
190ret true
191end
192fn rspeq a ulong b ulong t view uchar * to bool
193n = len t
194if lt b a
195ret false
196end
197if ne sub b a n
198ret false
199end
200i = ulong 0
201while lt i n bound 64
202if ne get rb add a i get t i
203ret false
204end
205i = add i 1
206end
207ret true
208end
209fn rdeny na ulong nb ulong ra ulong rz ulong to bool
210if rspeq na nb dn1
211ret true
212end
213if rspeq na nb dn2
214ret true
215end
216ret rspeq ra rz dr1
217end
218note rstore: STORAGE/<rid without "rad:"> exists
219fn rstore ra ulong rz ulong to bool
220n = get spl 0
221i = ulong 0
222while lt i n bound 1024
223put pa i get sp i
224i = add i 1
225end
226j = add ra 4
227while lt j rz bound 64
228put pa n get rb j
229n = add n 1
230j = add j 1
231end
232ret eq faccess pa 0 n 0 0
233end
234note ---- tiers: repos.tsv lines "name<TAB>rid<TAB>head<TAB>tier..."
235fn tfind a ulong e ulong c uchar to ulong
236i = a
237while lt i e bound 65536
238if eq get tb i c
239ret i
240end
241i = add i 1
242end
243ret e
244end
245fn tnameq a ulong b ulong s ulong f ulong to bool
246if ne sub b a sub f s
247ret false
248end
249n = sub b a
250i = ulong 0
251while lt i n bound 64
252if ne get rb add a i get tb add s i
253ret false
254end
255i = add i 1
256end
257ret true
258end
259note tcore: repos.tsv gives the name a..b (in rb) the tier "core"
260fn tcore a ulong b ulong to bool
261lim = get tbl 0
262s = ulong 0
263while lt s lim bound 65536
264e = tfind s lim 10
265f = tfind s e 9
266if tnameq a b s f
267t = tfind add f 1 e 9
268t = tfind add t 1 e 9
269t = add t 1
270if le add t 4 e
271if eq get tb t 99
272if eq get tb add t 1 111
273if eq get tb add t 2 114
274if eq get tb add t 3 101
275if eq add t 4 e
276ret true
277end
278ret eq get tb add t 4 9
279end
280end
281end
282end
283end
284ret false
285end
286s = add e 1
287end
288ret false
289end
290note ---- rows
291note rrow: one table row s..e. A listed row prints its R line and is remembered for the merges.
292fn rrow s ulong e ulong to void
293b1 = rbk s e 1
294b2 = rbk s e 2
295na = rtl add s 1 b1
296nb = rtr na b1
297ra = rtl add b1 1 b2
298rz = rtr ra b2
299if not rnameok na nb
300ret
301end
302if not rridok ra rz
303ret
304end
305if rdeny na nb ra rz
306ret
307end
308if not rstore ra rz
309ret
310end
311k = get rk 0
312if ge k SCAP
313ret
314end
315put rk 0 add k 1
316wab 82
317wab 9
318was na nb 64
319wab 9
320if tcore na nb
321wa tcor
322else
323wa tres
324end
325wab 10
326n = get rn 0
327if lt n 128
328put rs n s
329put re n e
330f1 = rlb s e
331f0 = rlb s f1
332u = rtl add f0 1 f1
333put ru n 0
334if ge sub rtr u f1 u 20
335if eq get rb u 50
336put ru n u
337end
338end
339put rd n 0
340put rn 0 add n 1
341end
342end
343note rlt: the 20-byte UTC stamp at a sorts before the one at b
344fn rlt a ulong b ulong to bool
345i = ulong 0
346while lt i 20 bound 20
347x = get rb add a i
348y = get rb add b i
349if lt x y
350ret true
351end
352if gt x y
353ret false
354end
355i = add i 1
356end
357ret false
358end
359fn rmerge i ulong to void
360s = get rs i
361e = get re i
362b1 = rbk s e 1
363b3 = rbk s e 3
364b4 = rbk s e 4
365f0 = rlb s rlb s e
366na = rtl add s 1 b1
367wab 77
368wab 9
369was na rtr na b1 64
370wab 9
371h = rtl add b3 1 b4
372was h rtr h b4 12
373wab 9
374t = rtl add b4 1 f0
375if gt f0 b4
376was t rtr t f0 200
377end
378wab 10
379end
380note rtop: print up to 8 remembered rows, latest UTC first
381fn rtop to void
382n = get rn 0
383k = ulong 0
384while lt k 8 bound 8
385best = ulong 128
386i = ulong 0
387while lt i n bound 128
388if eq get rd i 0
389u = get ru i
390if gt u 0
391if eq best 128
392best = i
393else
394if rlt get ru best u
395best = i
396end
397end
398end
399end
400i = add i 1
401end
402if lt best 128
403rmerge best
404put rd best 1
405end
406k = add k 1
407end
408end
409note rtable: the start of the first row after the header line, or rbl
410fn rtable to ulong
411lim = get rbl 0
412s = ulong 0
413while lt s lim bound 262144
414e = reol s
415if ge sub e s len thd
416if rspeq s add s len thd thd
417ret add e 1
418end
419end
420s = add e 1
421end
422ret lim
423end
424fn rrows start ulong to void
425lim = get rbl 0
426s = start
427while lt s lim bound 262144
428e = reol s
429if ge s e
430ret
431end
432if ne get rb s 124
433ret
434end
435if lt add s 1 e
436if ne get rb add s 1 45
437rrow s e
438end
439end
440s = add e 1
441end
442end
443note ---- files
444fn ldr to bool
445n = argread 1 pa 0 1023
446if le n 0
447ret false
448end
449fd = int fopen pa 0 ulong n 0 0
450if lt fd 0
451ret false
452end
453m = ulong 0
454k = long 1
455while gt k 0 bound 262145
456k = read fd rb m sub 262144 m
457if gt k 0
458m = add m ulong k
459end
460end
461r = fclose fd
462put rbl 0 m
463ret true
464end
465fn ldt to void
466put tbl 0 0
467n = argread 3 pa 0 1023
468if le n 0
469ret
470end
471fd = int fopen pa 0 ulong n 0 0
472if lt fd 0
473ret
474end
475m = ulong 0
476k = long 1
477while gt k 0 bound 65537
478k = read fd tb m sub 65536 m
479if gt k 0
480m = add m ulong k
481end
482end
483r = fclose fd
484put tbl 0 m
485end
486fn wren to bool
487la = len ftmp
488lb = len fout
489put pl 0 2
490put pl 1 0
491put pl 2 uchar la
492put pl 3 0
493i = ulong 0
494while lt i la bound 28
495put pl add 4 i get ftmp i
496i = add i 1
497end
498o = add 4 la
499put pl o uchar lb
500put pl add o 1 0
501k = ulong 0
502while lt k lb bound 28
503put pl add add o 2 k get fout k
504k = add k 1
505end
506ret eq renames pl 0 add add o 2 lb 0 0
507end
508fn wout to bool
509fd = int fopen ftmp 0 len ftmp 577 420
510if lt fd 0
511ret false
512end
513n = get wbl 0
514o = ulong 0
515ok = true
516while lt o n bound 65536
517k = write fd wb o sub n o
518if le k 0
519ok = false
520o = n
521else
522o = add o ulong k
523end
524end
525r = fsync fd
526r = fclose fd
527if not ok
528ret false
529end
530ret wren
531end
532fn main to int
533if lt argcnt 3
534ret 1
535end
536if not ldr
537ret 2
538end
539n = argread 2 sp 0 1023
540if le n 0
541ret 1
542end
543put spl 0 ulong n
544if ge argcnt 4
545ldt
546end
547t = rtable
548if ge t get rbl 0
549ret 2
550end
551rrows t
552rtop
553if wout
554ret 0
555end
556ret 3
557end