interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / sync.om

3656 lines · 59057 bytes Raw Blame History
1note research/sync.om: research-sync, its own seeded Omega program (composed after om/tls/sha2.om).
2note It runs outside the forged sandbox, beside the research agent: forged has no network. It turns
3note requests that signed-in Radicle keys queued (research/route.om) and public metadata into registry
4note lines for authors other than the registry's own (README.md "Other authors"). Every byte it
5note reads from a repository, from Zenodo or from the queue is untrusted: each field is checked,
6note decoded to one line, cut to the README's limits and written only through these checks.
7note research-sync zenodo ORCID DID DATE AUTHOR stdin: jflat lines of Zenodo search responses
8note research-sync repo RID DID DATE AUTHOR [COMMIT SHA256 | plan] stdin: jflat lines of .zenodo.json, "@tree", git ls-tree -l
9note research-sync text stdin: plain text; stdout: one paragraph a line
10note research-sync queue ADDDIR/ STATE ALLOW REMOVE REGDIR/ stdout: the accepted requests
11note research-sync layout raw|selected stdin: one catalog; stdout: lossless bound bundles
12note research-sync gather REMOVE SHELFLIST stdin: an author's raw catalogs; stdout: what may be shown
13note research-sync compact ADDDIR/ STATE called under the shared queue.lock
14note research-sync onshelf SHELFLIST RID DID exit 0 when the shelf lists RID as brought by DID
15note research-sync bind SEQ TEXTDIR/ stdin: one import's catalog; stdout: it with R and T
16note zenodo and repo write registry lines on stdout, one "slug <tab> source" line per work
17note whose full text may be copied on descriptor 3, and one line per refusal or dropped link on
18note stderr. A record is listed only when its creators carry ORCID (zenodo mode); full text only when
19note the licence is on the open list (kopen). Exit 0 done, 1 refused (stderr says why), 2 usage or
20note input this program does not accept (over 8 MiB, an argument that is not well formed).
21global ib uchar 8388608
22global ibl ulong 1
23global ob uchar 4194304
24global obl ulong 1
25global oof ulong 1
26global tb uchar 65536
27global tbl ulong 1
28global lb uchar 65536
29global lbl ulong 1
30global av uchar 4096
31global avl ulong 8
32global sg uchar 80
33global sgl ulong 1
34global hs ulong 1
35global he ulong 1
36global hpl ulong 1
37global gn ulong 4
38global rb uchar 65536
39global rbl ulong 1
40global rerr ulong 1
41global pfail ulong 1
42global lamb ulong 1
43text mpolicy "refused: POLICY_READ: allow/remove file read, type or size error"
44global qb uchar 65536
45global pth uchar 1100
46global pthl ulong 1
47global pt2 uchar 1100
48global rpk uchar 2300
49note gather's bundles, one cell each: an 8 MiB input holds at most 2796203 W lines of 3 bytes
50global gbw ulong 2796203
51global gbe ulong 2796203
52global gbp ulong 2796203
53global gbg ulong 2796203
54global gbs ulong 2796203
55global gbk ulong 2796203
56global gbl ulong 2796203
57global gbsel uchar 2796203
58note gxs: start of the first X line of gather's input (ibl when absent). Bundles after it are
59note auxiliary evidence: they deny and close copies of selected work but are never selected.
60global gxs ulong 1
61global dg uchar 32
62text khits "/hits/hits/"
63text kmeta "/metadata"
64text knone ""
65text kid "/id"
66text kdoi "/doi"
67text kcdoi "/conceptdoi"
68text ktitle "/title"
69text kdesc "/description"
70text kdate "/publication_date"
71text klic "/license/id"
72text klics "/license"
73text ksub "/resource_type/subtype"
74text ktyp "/resource_type/type"
75text kupt "/upload_type"
76text kput "/publication_type"
77text kver "/version"
78text kvix "/relations/version/0/index"
79text kcor "/creators/*/orcid"
80text kcnm "/creators/*/name"
81text kkw "/keywords/*"
82text kri "/related_identifiers/*/identifier"
83text krr "/related_identifiers/*/relation"
84text kfk "/files/*/key"
85text kfs "/files/*/size"
86text kfl "/files/*/links/self"
87text kopen " cc-by-4.0 cc-by-sa-4.0 cc0-1.0 cc-by-3.0 cc-by-sa-3.0 "
88text khttps "https://"
89text kzrec "https://zenodo.org/records/"
90text kzen "Zenodo"
91text krad "Radicle"
92text krp "rad:"
93text kart "article"
94text kjart "journal-article"
95text ktree "@tree"
96text kos "O\tid\t"
97text kon "O\tname\t"
98text koo "O\torcid\t"
99text koa "O\tadded-by\t"
100text koc "O\tchecked\t"
101text kov "O\tvia\t"
102text kzv "zenodo"
103text krv "radicle"
104text ksep "; "
105text kand " and "
106text kmode1 "zenodo"
107text kmode2 "repo"
108text kmode3 "text"
109text kmode4 "queue"
110text kmode5 "gather"
111text kmode6 "onshelf"
112text kmode9 "policies"
113text kmode8 "compact"
114text kmode7 "identify"
115text kplan "plan"
116text kq "queue"
117text kxt ".tmp"
118text kaut "a/"
119text kkey "key-"
120text khex "0123456789abcdef"
121text kzpre "10.5281/zenodo."
122text kst1 "open"
123text kst2 "stored"
124text kst3 "held"
125text kpaper1 "paper.md"
126text kpaper2 "paper.txt"
127text kpaper3 "paper.pdf"
128text klic1 "LICENSE"
129text klic2 "LICENSE.md"
130text klic3 "LICENSE.txt"
131text klic4 "LICENCE"
132text klic5 "COPYING"
133text mref "refused "
134text mown " the Zenodo record does not name ORCID iD "
135text mown2 " among its creators"
136text mmany " more than 200 records for one author"
137text mnoid "a record without a record number"
138text mnot " has no title"
139text mlink "dropped link "
140text mlink2 " (not https)"
141text mlisted "listed "
142text mrefd " refused "
143text mbig "research-sync: input is 8388608 bytes or longer\n"
144text mfull "research-sync: output is 4194304 bytes or longer\n"
145text mrt "refused: .zenodo.json has no title"
146text mrc "refused: .zenodo.json names no creator"
147text mrl "refused: .zenodo.json names no license"
148text mrf "refused: the repository has no LICENSE file at its top level"
149text mrp "refused: the repository has no paper.md, paper.txt or paper.pdf at its top level"
150text mqbad "refused: a malformed queue line"
151text mqallow "refused: the key is not allowed to add work (the shelf's allow file)"
152text mqrem "refused: the operator's remove file names this key, repository, ORCID iD or DOI"
153text kdidp "did:key:z"
154text kblob "100"
155text k10 "10."
156text krec "record"
157text kwt "W\t"
158text kpt "P\t"
159text kone "1"
160text kmode10 "bind"
161text ktxt ".txt"
162text kamb "ambiguous"
163text kobject "{"
164text karray "["
165text kemptyo "{}"
166text kemptya "[]"
167text mmeta " invalid or ambiguous metadata container"
168text mprofile "refused: MIXED_PROFILE_LAYOUT: normalise header selections before appending raw imports"
169text kbr "R\t"
170text kbt "T\t"
171text mamb " has ambiguous or invalid licence/metadata fields; no full text"
172text kmode11 "layout"
173text kraw "raw"
174text ksel "selected"
175text kni "I\t"
176text knn "N\t"
177text kzero "0"
178text knid "id\t"
179text knname "name\t"
180text kob "O\t"
181text korc "orcid\t"
182text kna "added-by\t"
183text knc "checked\t"
184text knv "via\t"
185text mlayout "refused: LAYOUT_INPUT: raw layout takes one raw catalog; N, I and X records are not raw"
186text mbind "refused: PROFILE_BINDING: a bundle's N/I facts are missing, repeated or name another slug"
187text munbound "refused: SELECTED_PROFILE_UNBOUND: this selection lacks complete per-bundle profile facts; rebuild it from retained raw catalogs (layout raw each file, then one gather); do not infer association from shared O"
188text maux "refused: AUX_LAYOUT: evidence after the X line must be laid-out bundles without O lines"
189note ---- output: stdout (ob), descriptor 3 (tb), stderr (lb)
190fn emb c uchar to void
191o = get obl 0
192if lt o 4194304
193put ob o c
194put obl 0 add o 1
195else
196put oof 0 1
197end
198end
199fn em t view uchar * to void
200for i ulong len t bound 65536
201emb get t i
202end
203end
204fn emn v ulong to void
205d = new uchar 20 0
206n = ulong 0
207x = v
208if eq x 0
209emb 48
210end
211while gt x 0 bound 20
212put d n uchar add 48 rem x 10
213x = div x 10
214n = add n 1
215end
216while gt n 0 bound 20
217n = sub n 1
218emb get d n
219end
220end
221fn emr a ulong b ulong to void
222i = a
223while lt i b bound 8388608
224emb get ib i
225i = add i 1
226end
227end
228fn tbb c uchar to void
229o = get tbl 0
230if lt o 65536
231put tb o c
232put tbl 0 add o 1
233else
234put oof 0 1
235end
236end
237fn lgb c uchar to void
238o = get lbl 0
239if lt o 65000
240put lb o c
241put lbl 0 add o 1
242end
243end
244fn lgt t view uchar * to void
245for i ulong len t bound 4096
246lgb get t i
247end
248end
249fn lgn v ulong to void
250d = new uchar 20 0
251n = ulong 0
252x = v
253if eq x 0
254lgb 48
255end
256while gt x 0 bound 20
257put d n uchar add 48 rem x 10
258x = div x 10
259n = add n 1
260end
261while gt n 0 bound 20
262n = sub n 1
263lgb get d n
264end
265end
266note lgr: ib[a, b) into the log as printable ASCII (anything else becomes ?), at most 200 bytes
267fn lgr a ulong b ulong to void
268e = b
269if gt sub b a 200
270e = add a 200
271end
272i = a
273while lt i e bound 200
274c = get ib i
275if or lt c 32 gt c 126
276c = uchar 63
277end
278lgb c
279i = add i 1
280end
281end
282fn flush fd int b view uchar * n ulong to bool
283o = ulong 0
284while lt o n bound 8388608
285k = write fd b o sub n o
286if le k 0
287ret false
288end
289o = add o ulong k
290end
291ret true
292end
293note Global arrays cannot be passed to user functions at the pinned compiler. Stream local windows.
294fn flushg fd int n ulong to bool
295b = new uchar 4096 0
296o = ulong 0
297while lt o n bound 4194304
298m = sub n o
299if gt m 4096
300m = ulong 4096
301end
302for i ulong m bound 4096
303if eq fd 1
304put b i get ob add o i
305end
306if eq fd 2
307put b i get lb add o i
308end
309if eq fd 3
310put b i get tb add o i
311end
312end
313if not flush fd b m
314ret false
315end
316o = add o m
317end
318ret true
319end
320fn done rc int to int
321x = flushg 2 get lbl 0
322if ne get oof 0 0
323x = flush 2 mfull len mfull
324ret 2
325end
326if not flushg 1 get obl 0
327ret 2
328end
329if gt get tbl 0 0
330if not flushg 3 get tbl 0
331ret 2
332end
333end
334ret rc
335end
336note ---- arguments: argument k into av[512 k, ...), its length into avl k
337fn arg k ulong to ulong
338b = new uchar 512 0
339n = argread k b 0 500
340if or le n 0 ge n 500
341put avl k 0
342ret 0
343end
344m = ulong n
345o = mul k 512
346for i ulong m bound 512
347put av add o i get b i
348end
349put avl k m
350ret m
351end
352fn ava k ulong i ulong to uchar
353ret get av add mul k 512 i
354end
355fn ema k ulong to void
356for i ulong get avl k bound 512
357emb ava k i
358end
359end
360fn lga k ulong to void
361for i ulong get avl k bound 512
362lgb ava k i
363end
364end
365fn argeq k ulong t view uchar * to bool
366if ne get avl k len t
367ret false
368end
369for i ulong len t bound 64
370if ne ava k i get t i
371ret false
372end
373end
374ret true
375end
376note shl1: move arguments 2.. down one slot (the mode word leaves slot 1)
377fn shl1 to void
378for k ulong 6
379for i ulong get avl add k 2 bound 512
380put av add mul add k 1 512 i ava add k 2 i
381end
382put avl add k 1 get avl add k 2
383end
384put avl 7 0
385end
386note ---- checks on bytes
387fn isdig c uchar to bool
388ret and ge c 48 le c 57
389end
390fn islow c uchar to bool
391ret and ge c 97 le c 122
392end
393fn lowc c uchar to uchar
394if and ge c 65 le c 90
395ret uchar add c 32
396end
397ret c
398end
399fn b58 c uchar to bool
400if isdig c
401ret ne c 48
402end
403if and ge c 65 le c 90
404ret and ne c 73 ne c 79
405end
406if islow c
407ret ne c 108
408end
409ret false
410end
411note orcok: argument k is an ORCID iD: dddd-dddd-dddd-dddX with its ISO 7064 11,2 check character
412fn orcok k ulong to bool
413if ne get avl k 19
414ret false
415end
416t = ulong 0
417for i ulong 19
418c = ava k i
419if or eq i 4 or eq i 9 eq i 14
420if ne c 45
421ret false
422end
423else
424if lt i 18
425if not isdig c
426ret false
427end
428t = mul add t ulong sub c 48 2
429end
430end
431end
432r = rem sub 12 rem t 11 11
433c = ava k 18
434if eq r 10
435ret eq c 88
436end
437ret eq c uchar add 48 r
438end
439note didok: argument k is did:key:z followed by 1 to 87 base58 characters
440fn didok k ulong to bool
441n = get avl k
442if or lt n 10 gt n 96
443ret false
444end
445for i ulong 9
446if ne ava k i get kdidp i
447ret false
448end
449end
450for i ulong sub n 9 bound 96
451if not b58 ava k add 9 i
452ret false
453end
454end
455ret true
456end
457note ridok: argument k is z followed by 19 to 43 base58 characters (the shelf's rule, rad: dropped)
458fn ridok k ulong to bool
459n = get avl k
460if or lt n 20 gt n 44
461ret false
462end
463if ne ava k 0 122
464ret false
465end
466for i ulong n bound 44
467if not b58 ava k i
468ret false
469end
470end
471ret true
472end
473note autok: argument k is an author id: 1 to 64 bytes of a-z, 0-9 and -
474fn autok k ulong to bool
475n = get avl k
476if or eq n 0 gt n 64
477ret false
478end
479for i ulong n bound 64
480c = ava k i
481if not or or isdig c islow c eq c 45
482ret false
483end
484end
485ret true
486end
487fn dateok k ulong to bool
488if ne get avl k 10
489ret false
490end
491for i ulong 10
492c = ava k i
493if or eq i 4 eq i 7
494if ne c 45
495ret false
496end
497else
498if not isdig c
499ret false
500end
501end
502end
503ret true
504end
505note ---- the input
506fn rdin to bool
507n = ulong 0
508k = long 1
509while gt k 0 bound 8388608
510if ge n 8388607
511ret false
512end
513k = read 0 ib n sub 8388607 n
514if gt k 0
515n = add n ulong k
516end
517end
518put ibl 0 n
519ret true
520end
521fn eol a ulong to ulong
522i = a
523n = get ibl 0
524while lt i n bound 8388608
525if eq get ib i 10
526ret i
527end
528i = add i 1
529end
530ret n
531end
532fn tabat a ulong e ulong to ulong
533i = a
534while lt i e bound 8388608
535if eq get ib i 9
536ret i
537end
538i = add i 1
539end
540ret e
541end
542fn lpre a ulong e ulong t view uchar * to bool
543n = len t
544if lt e a
545ret false
546end
547if lt sub e a n
548ret false
549end
550for i ulong n bound 256
551if ne get ib add a i get t i
552ret false
553end
554end
555ret true
556end
557fn reqt a ulong b ulong t view uchar * to bool
558if lt b a
559ret false
560end
561if ne sub b a len t
562ret false
563end
564ret lpre a b t
565end
566fn feqr a ulong b ulong c ulong d ulong to bool
567if or lt b a lt d c
568ret false
569end
570if ne sub b a sub d c
571ret false
572end
573i = ulong 0
574while lt i sub b a bound 8388608
575if ne get ib add a i get ib add c i
576ret false
577end
578i = add i 1
579end
580ret true
581end
582note sfield: start of field f (0 based) of the line ib[a, e); e when the line has fewer fields
583fn sfield a ulong e ulong f ulong to ulong
584p = a
585j = ulong 0
586while lt j f bound 16
587while lt p e bound 8388608
588if eq get ib p 9
589break
590end
591p = add p 1
592end
593if ge p e
594ret e
595end
596p = add p 1
597j = add j 1
598end
599ret p
600end
601note ---- jflat paths. A hit is the run of lines whose path starts /hits/hits/<n>/ (zenodo) or the
602note whole input up to "@tree" (repo). hpl is the length of the hit prefix of each line.
603note pmat: the path ib[p, e) is pre followed by pat, where * in pat stands for a decimal index of
604note 1 to 12 digits: k when k < 1000000, any index otherwise. The matched index (0 without *), or -1.
605fn pindex p ulong e ulong k ulong to ulong
606q = p
607v = ulong 0
608while lt q e bound 8388608
609c = get ib q
610if not isdig c
611break
612end
613if ge sub q p 12
614ret get ibl 0
615end
616v = add mul v 10 ulong sub c 48
617q = add q 1
618end
619if eq q p
620ret get ibl 0
621end
622if and lt k 1000000 ne v k
623ret get ibl 0
624end
625put gn 3 v
626ret q
627end
628fn pmat p ulong pre view uchar * pat view uchar * k ulong to long
629e = tabat p eol p
630q = p
631for i ulong len pre bound 64
632if ge q e
633ret -1
634end
635if ne get ib q get pre i
636ret -1
637end
638q = add q 1
639end
640got = long 0
641for i ulong len pat bound 128
642if eq get pat i 42
643q = pindex q e k
644if ge q get ibl 0
645ret -1
646end
647got = long get gn 3
648else
649if ge q e
650ret -1
651end
652if ne get ib q get pat i
653ret -1
654end
655q = add q 1
656end
657end
658if ne q e
659ret -1
660end
661ret got
662end
663note hfind: the first line at or after s in the hit whose path matches; he when none
664fn hfind s ulong pre view uchar * pat view uchar * k ulong to ulong
665l = s
666e = get he 0
667while lt l e bound 8388608
668ln = eol l
669t = tabat l ln
670if lt t ln
671if ge pmat add l get hpl 0 pre pat k 0
672ret l
673end
674end
675l = add ln 1
676end
677ret e
678end
679note hidx: the index the line l matched (pmat again)
680fn hidx l ulong pre view uchar * pat view uchar * to ulong
681ln = eol l
682t = tabat l ln
683r = pmat add l get hpl 0 pre pat 1000000
684if lt r 0
685ret 0
686end
687ret ulong r
688end
689fn vala l ulong to ulong
690ln = eol l
691t = tabat l ln
692if lt t ln
693ret add t 1
694end
695ret ln
696end
697fn valb l ulong to ulong
698ret eol l
699end
700fn hval pre view uchar * pat view uchar * to ulong
701ret hfind get hs 0 pre pat 0
702end
703note ---- one field. emv writes the jflat value ib[a, b) as one registry field: \n and \t become a
704note space, \\ a backslash, other control bytes are dropped, runs of spaces become one, no space at
705note either end, at most cap bytes and never part of a UTF-8 character (a malformed byte becomes ?).
706note The bytes written.
707fn u8len a ulong b ulong to ulong
708c = get ib a
709if lt c 128
710ret 1
711end
712n = ulong 0
713lo = uchar 128
714hi = uchar 191
715if and ge c 194 le c 223
716n = ulong 2
717end
718if and ge c 224 le c 239
719n = ulong 3
720if eq c 224
721lo = uchar 160
722end
723if eq c 237
724hi = uchar 159
725end
726end
727if and ge c 240 le c 244
728n = ulong 4
729if eq c 240
730lo = uchar 144
731end
732if eq c 244
733hi = uchar 143
734end
735end
736if or eq n 0 gt add a n b
737ret 0
738end
739d = get ib add a 1
740if or lt d lo gt d hi
741ret 0
742end
743for j ulong sub n 2 bound 4
744d = get ib add add a 2 j
745if or lt d 128 gt d 191
746ret 0
747end
748end
749ret n
750end
751note Preserve markup as text. The builder escapes it for each output format. No HTML is trusted.
752fn emv a ulong b ulong cap ulong to ulong
753w = ulong 0
754pend = false
755i = a
756while lt i b bound 8388608
757c = get ib i
758n = ulong 1
759if eq c 92
760if lt add i 1 b
761n = ulong 2
762c = get ib add i 1
763if or eq c 110 eq c 116
764c = uchar 32
765end
766end
767end
768if or le c 32 eq c 127
769if gt w 0
770pend = true
771end
772else
773k = ulong 1
774if ge c 128
775k = u8len i b
776if eq k 0
777c = uchar 63
778k = ulong 1
779else
780n = k
781end
782end
783if pend
784if gt add add w k 1 cap
785ret w
786end
787emb 32
788w = add w 1
789pend = false
790end
791if gt add w k cap
792ret w
793end
794if ge c 128
795emr i add i k
796else
797emb c
798end
799w = add w k
800end
801i = add i n
802end
803ret w
804end
805note urlok: ib[a, b) is an https URL of at most 400 printable bytes without quote, angle bracket,
806note backslash or backtick
807fn urlok a ulong b ulong to bool
808if lt b a
809ret false
810end
811if or gt sub b a 400 le sub b a len khttps
812ret false
813end
814if not lpre a b khttps
815ret false
816end
817i = a
818while lt i b bound 400
819c = get ib i
820if or le c 32 ge c 127
821ret false
822end
823if or or eq c 34 eq c 39 or or eq c 60 eq c 62 or eq c 92 eq c 96
824ret false
825end
826i = add i 1
827end
828ret true
829end
830note doiok: ib[a, b) is a DOI: 10.<digits>/<1 to 90 printable bytes without quote, angle bracket,
831note backslash or space>
832fn doiok a ulong b ulong to bool
833if lt b a
834ret false
835end
836if or lt sub b a 6 gt sub b a 120
837ret false
838end
839if not lpre a b k10
840ret false
841end
842i = add a 3
843s = i
844while lt i b bound 120
845if not isdig get ib i
846break
847end
848i = add i 1
849end
850if or eq i s ge i b
851ret false
852end
853if ne get ib i 47
854ret false
855end
856i = add i 1
857if or eq i b gt sub b i 90
858ret false
859end
860while lt i b bound 120
861c = get ib i
862if or le c 32 ge c 127
863ret false
864end
865if or or eq c 34 eq c 39 or or eq c 60 eq c 62 eq c 92
866ret false
867end
868i = add i 1
869end
870ret true
871end
872fn vdate a ulong b ulong to bool
873if lt b a
874ret false
875end
876if ne sub b a 10
877ret false
878end
879for i ulong 10
880c = get ib add a i
881if or eq i 4 eq i 7
882if ne c 45
883ret false
884end
885else
886if not isdig c
887ret false
888end
889end
890end
891ret true
892end
893fn alldig a ulong b ulong to bool
894if le b a
895ret false
896end
897if gt sub b a 12
898ret false
899end
900i = a
901while lt i b bound 12
902if not isdig get ib i
903ret false
904end
905i = add i 1
906end
907ret true
908end
909fn dnum a ulong b ulong to ulong
910v = ulong 0
911i = a
912while lt i b bound 12
913v = add mul v 10 ulong sub get ib i 48
914i = add i 1
915end
916ret v
917end
918note emw: ib[a, b) lowercased, keeping a-z 0-9 . - only, at most cap bytes (licence, kind, relation)
919fn emw a ulong b ulong cap ulong to void
920w = ulong 0
921i = a
922while lt i b bound 8388608
923c = lowc get ib i
924if or or isdig c islow c or eq c 45 eq c 46
925if lt w cap
926emb c
927w = add w 1
928end
929end
930i = add i 1
931end
932end
933note isopen: the licence id ib[a, b) (any case) is on the open list kopen
934fn isopen a ulong b ulong to bool
935if le b a
936ret false
937end
938n = sub b a
939if gt n 32
940ret false
941end
942m = len kopen
943s = ulong 0
944while lt add s add n 1 m bound 256
945if eq get kopen s 32
946hit = true
947for i ulong n bound 32
948if ne lowc get ib add a i get kopen add add s 1 i
949hit = false
950break
951end
952end
953if hit
954if eq get kopen add add s 1 n 32
955ret true
956end
957end
958end
959s = add s 1
960end
961ret false
962end
963note Count container occurrences too: duplicate licence objects with disjoint children must not
964note disappear when flattened. One ordinary object marker plus one id is one decision, not two.
965fn badcontainer a ulong b ulong to bool
966if or reqt a b kobject reqt a b karray
967ret true
968end
969ret or reqt a b kemptyo reqt a b kemptya
970end
971fn metacount to ulong
972n = ulong 0
973l = hfind get hs 0 knone kmeta 0
974while lt l get he 0 bound 8388608
975if not reqt vala l valb l kobject
976ret 2
977end
978n = add n 1
979l = hfind add eol l 1 knone kmeta 0
980end
981ret n
982end
983fn lcount pre view uchar * to ulong
984if gt len pre 0
985if gt metacount 1
986ret 2
987end
988end
989n = ulong 0
990l = hfind get hs 0 pre klic 0
991while lt l get he 0 bound 8388608
992if badcontainer vala l valb l
993ret 2
994end
995n = add n 1
996l = hfind add eol l 1 pre klic 0
997end
998objects = ulong 0
999scalars = ulong 0
1000l = hfind get hs 0 pre klics 0
1001while lt l get he 0 bound 8388608
1002a = vala l
1003b = valb l
1004if reqt a b kobject
1005objects = add objects 1
1006else
1007if badcontainer a b
1008ret 2
1009end
1010scalars = add scalars 1
1011end
1012l = hfind add eol l 1 pre klics 0
1013end
1014if gt objects 1
1015ret 2
1016end
1017if eq objects 1
1018if gt scalars 0
1019ret 2
1020end
1021ret n
1022end
1023if and gt len pre 0 gt scalars 0
1024ret 2
1025end
1026ret add n scalars
1027end
1028note ---- the slug: the title lowercased, a-z and 0-9 kept, any other run one -, at most 40 bytes,
1029note then - and the suffix (a record number, or r and the first letters of a repository id)
1030fn sgc c uchar to void
1031n = get sgl 0
1032if lt n 80
1033put sg n c
1034put sgl 0 add n 1
1035end
1036end
1037fn mkslug a ulong b ulong to void
1038put sgl 0 0
1039dash = false
1040i = a
1041while lt i b bound 8388608
1042c = lowc get ib i
1043if or isdig c islow c
1044if and dash gt get sgl 0 0
1045if ge get sgl 0 39
1046break
1047end
1048sgc 45
1049end
1050dash = false
1051sgc c
1052if ge get sgl 0 40
1053break
1054end
1055else
1056dash = true
1057end
1058i = add i 1
1059end
1060if eq get sgl 0 0
1061for j ulong len krec
1062sgc get krec j
1063end
1064end
1065sgc 45
1066end
1067fn ems to void
1068for i ulong get sgl 0 bound 80
1069emb get sg i
1070end
1071end
1072fn tbs to void
1073for i ulong get sgl 0 bound 80
1074tbb get sg i
1075end
1076end
1077note lhead: start a registry line "ty <tab> slug <tab>"
1078fn lhead ty uchar to void
1079emb ty
1080emb 9
1081ems
1082emb 9
1083end
1084note ---- the common part of a work (both modes): pre is /metadata (zenodo) or empty (repo)
1085fn names sep view uchar * pre view uchar * to void
1086l = hfind get hs 0 pre kcnm 1000000
1087n = ulong 0
1088while lt l get he 0 bound 8388608
1089if ge n 64
1090break
1091end
1092if gt n 0
1093em sep
1094end
1095x = emv vala l valb l 120
1096n = add n 1
1097l = hfind add eol l 1 pre kcnm 1000000
1098end
1099end
1100fn kwords pre view uchar * to void
1101l = hfind get hs 0 pre kkw 1000000
1102n = ulong 0
1103while lt l get he 0 bound 8388608
1104if ge n 16
1105break
1106end
1107lhead 75
1108x = emv vala l valb l 80
1109emb 10
1110n = add n 1
1111l = hfind add eol l 1 pre kkw 1000000
1112end
1113end
1114note links: L lines for related identifiers that are https URLs (at most 16); the rest is logged
1115fn links pre view uchar * to void
1116l = hfind get hs 0 pre kri 1000000
1117n = ulong 0
1118while lt l get he 0 bound 8388608
1119k = hidx l pre kri
1120a = vala l
1121b = valb l
1122if urlok a b
1123if lt n 16
1124r = hfind get hs 0 pre krr k
1125lhead 76
1126if lt r get he 0
1127emw vala r valb r 32
1128end
1129emb 9
1130emr a b
1131emb 10
1132n = add n 1
1133end
1134else
1135lgt mlink
1136lgr a b
1137lgt mlink2
1138lgb 10
1139end
1140l = hfind add eol l 1 pre kri 1000000
1141end
1142end
1143note abstr: the A line and the S line (the abstract's first 300 bytes, cut at a space after 200)
1144fn abstr pre view uchar * to void
1145l = hfind get hs 0 pre kdesc 0
1146if ge l get he 0
1147ret
1148end
1149lhead 65
1150s = get obl 0
1151w = emv vala l valb l 12000
1152emb 10
1153if or eq w 0 ne get oof 0 0
1154ret
1155end
1156lhead 83
1157m = w
1158if gt m 300
1159c = ulong 300
1160while gt c 200 bound 300
1161if eq get ob add s c 32
1162break
1163end
1164c = sub c 1
1165end
1166while gt c 0 bound 300
1167if ne and get ob add s c 192 128
1168break
1169end
1170c = sub c 1
1171end
1172m = c
1173end
1174for i ulong m bound 300
1175emb get ob add s i
1176end
1177emb 10
1178end
1179note ---- zenodo mode
1180note zowner: the creator name line of the creator whose orcid is the claimed iD (slot 2), else he
1181fn zowner to ulong
1182l = hfind get hs 0 kmeta kcor 1000000
1183while lt l get he 0 bound 8388608
1184a = vala l
1185b = valb l
1186if eq sub b a get avl 2
1187same = true
1188for i ulong get avl 2 bound 19
1189if ne get ib add a i ava 2 i
1190same = false
1191end
1192end
1193if same
1194k = hidx l kmeta kcor
1195ret hfind get hs 0 kmeta kcnm k
1196end
1197end
1198l = hfind add eol l 1 kmeta kcor 1000000
1199end
1200ret get he 0
1201end
1202note fext: the file name ib[a, b) ends in .pdf, .txt or .md (any case)
1203fn fext a ulong b ulong to bool
1204if le sub b a 4
1205ret false
1206end
1207x1 = lowc get ib sub b 4
1208x2 = lowc get ib sub b 3
1209x3 = lowc get ib sub b 2
1210x4 = lowc get ib sub b 1
1211if and and eq x1 46 eq x2 112 and eq x3 100 eq x4 102
1212ret true
1213end
1214if and and eq x1 46 eq x2 116 and eq x3 120 eq x4 116
1215ret true
1216end
1217ret and eq x2 46 and eq x3 109 eq x4 100
1218end
1219note zfiles: F lines for files with an https link (at most 16); with an open licence, one T line
1220note on descriptor 3 for the first .pdf, .txt or .md file of at most 8 decimal digits of bytes
1221fn tbr a ulong b ulong to void
1222i = a
1223while lt i b bound 8388608
1224tbb get ib i
1225i = add i 1
1226end
1227end
1228fn zfiles opn bool to void
1229l = hfind get hs 0 knone kfk 1000000
1230n = ulong 0
1231t = false
1232while lt l get he 0 bound 8388608
1233k = hidx l knone kfk
1234u = hfind get hs 0 knone kfl k
1235z = hfind get hs 0 knone kfs k
1236if lt u get he 0
1237ua = vala u
1238ub = valb u
1239if urlok ua ub
1240if lt n 16
1241lhead 70
1242x = emv vala l valb l 200
1243emb 9
1244if lt z get he 0
1245if alldig vala z valb z
1246emr vala z valb z
1247end
1248end
1249emb 9
1250emr ua ub
1251emb 10
1252n = add n 1
1253end
1254if and opn not t
1255ok = fext vala l valb l
1256if lt z get he 0
1257if not alldig vala z valb z
1258ok = false
1259else
1260if gt sub valb z vala z 8
1261ok = false
1262end
1263end
1264end
1265if ok
1266tbs
1267tbb 9
1268tbr ua ub
1269tbb 10
1270t = true
1271end
1272end
1273else
1274lgt mlink
1275lgr ua ub
1276lgt mlink2
1277lgb 10
1278end
1279end
1280l = hfind add eol l 1 knone kfk 1000000
1281end
1282end
1283note zhit: one search hit. 1 listed, 0 refused.
1284note A per-author namespace binds paper paths and cached text to the author catalog. A public
1285note coauthored record can be listed under each matching ORCID without duplicate work keys.
1286fn zauthor to void
1287b = new uchar 128 0
1288d = new uchar 32 0
1289n = get avl 5
1290for i ulong n bound 64
1291put b i ava 5 i
1292end
1293x = sha2_digest 256 view part b 0 n d
1294put sgl 0 0
1295sgc 122
1296for i ulong 16
1297c = get d i
1298sgc get khex ulong shr c 4
1299sgc get khex ulong and c 15
1300end
1301sgc 45
1302end
1303fn zhit nl ulong to ulong
1304l = hval knone kid
1305if ge l get he 0
1306lgt mref
1307lgt mnoid
1308lgb 10
1309ret 0
1310end
1311ra = vala l
1312rb2 = valb l
1313if not alldig ra rb2
1314lgt mref
1315lgt mnoid
1316lgb 10
1317ret 0
1318end
1319if gt metacount 1
1320lgt mref
1321lgr ra rb2
1322lgt mmeta
1323lgb 10
1324ret 0
1325end
1326ow = zowner
1327if ge ow get he 0
1328lgt mref
1329lgr ra rb2
1330lgt mown
1331lga 2
1332lgt mown2
1333lgb 10
1334ret 0
1335end
1336if ge nl 200
1337lgt mref
1338lgr ra rb2
1339lgt mmany
1340lgb 10
1341ret 0
1342end
1343tl = hval kmeta ktitle
1344if ge tl get he 0
1345lgt mref
1346lgr ra rb2
1347lgt mnot
1348lgb 10
1349ret 0
1350end
1351if eq nl 0
1352put gn 1 vala ow
1353put gn 2 valb ow
1354end
1355zauthor
1356i = ra
1357while lt i rb2 bound 12
1358sgc get ib i
1359i = add i 1
1360end
1361put lamb 0 lcount kmeta
1362lc = hval kmeta klic
1363opn = false
1364if lt lc get he 0
1365opn = isopen vala lc valb lc
1366end
1367if gt get lamb 0 1
1368opn = false
1369lgt mref
1370lgr ra rb2
1371lgt mamb
1372lgb 10
1373end
1374note W: slug, thread (none), date, kind, venue, DOI of all versions, DOI of this version, version,
1375note number of versions, on ORCID (0: not checked here), licence, title
1376lhead 87
1377emb 9
1378d = hval kmeta kdate
1379if lt d get he 0
1380if vdate vala d valb d
1381emr vala d valb d
1382end
1383end
1384emb 9
1385k = hval kmeta ksub
1386if ge k get he 0
1387k = hval kmeta ktyp
1388end
1389if lt k get he 0
1390if reqt vala k valb k kart
1391em kjart
1392else
1393emw vala k valb k 32
1394end
1395end
1396emb 9
1397em kzen
1398emb 9
1399d = hval knone kcdoi
1400if lt d get he 0
1401if doiok vala d valb d
1402emr vala d valb d
1403end
1404end
1405emb 9
1406d = hval knone kdoi
1407if lt d get he 0
1408if doiok vala d valb d
1409emr vala d valb d
1410end
1411end
1412emb 9
1413d = hval kmeta kver
1414if lt d get he 0
1415x = emv vala d valb d 48
1416end
1417emb 9
1418d = hval kmeta kvix
1419nv = ulong 1
1420if lt d get he 0
1421if alldig vala d valb d
1422if le sub valb d vala d 6
1423nv = add dnum vala d valb d 1
1424end
1425end
1426end
1427emn nv
1428emb 9
1429emb 48
1430emb 9
1431if gt get lamb 0 1
1432em kamb
1433else
1434if lt lc get he 0
1435emw vala lc valb lc 32
1436end
1437end
1438emb 9
1439x = emv vala tl valb tl 400
1440emb 10
1441abstr kmeta
1442lhead 67
1443names ksep kmeta
1444emb 10
1445lhead 66
1446names kand kmeta
1447emb 10
1448kwords kmeta
1449links kmeta
1450zfiles opn
1451note P: slug, how, the key that asked, the date, the source, 1 when the licence is on the open list
1452lhead 80
1453em kzv
1454emb 9
1455ema 3
1456emb 9
1457ema 4
1458emb 9
1459em kzrec
1460emr ra rb2
1461emb 9
1462if opn
1463emb 49
1464else
1465emb 48
1466end
1467emb 10
1468ret 1
1469end
1470fn zend s ulong w ulong to ulong
1471lim = get ibl 0
1472t = add eol s 1
1473while lt t lim bound 8388608
1474te = eol t
1475same = lpre t te khits
1476if same
1477if le sub te t w
1478same = false
1479end
1480end
1481if same
1482same = feqr t add t w s add s w
1483if ne get ib add t w 47
1484same = false
1485end
1486end
1487if not same
1488break
1489end
1490t = add te 1
1491end
1492if gt t lim
1493t = lim
1494end
1495ret t
1496end
1497fn zmode to int
1498if not orcok 2
1499ret 2
1500end
1501if not didok 3
1502ret 2
1503end
1504if not dateok 4
1505ret 2
1506end
1507if not autok 5
1508ret 2
1509end
1510if not rdin
1511x = flush 2 mbig len mbig
1512ret 2
1513end
1514put hpl 0 0
1515lim = get ibl 0
1516nl = ulong 0
1517nr = ulong 0
1518s = ulong 0
1519while lt s lim bound 8388608
1520e = eol s
1521nx = add e 1
1522if lpre s e khits
1523p = add s len khits
1524q = p
1525while lt q e bound 8388608
1526if not isdig get ib q
1527break
1528end
1529if ge sub q p 12
1530break
1531end
1532q = add q 1
1533end
1534if and gt q p lt q e
1535if eq get ib q 47
1536w = sub q s
1537put hpl 0 w
1538put hs 0 s
1539t = zend s w
1540put he 0 t
1541r = zhit nl
1542nl = add nl r
1543if eq r 0
1544nr = add nr 1
1545end
1546nx = t
1547end
1548end
1549end
1550s = nx
1551end
1552if gt nl 0
1553em kos
1554ema 5
1555emb 10
1556em kon
1557x = emv get gn 1 get gn 2 120
1558emb 10
1559em koo
1560ema 2
1561emb 10
1562em koa
1563ema 3
1564emb 10
1565em koc
1566ema 4
1567emb 10
1568em kov
1569em kzv
1570emb 10
1571end
1572lgt mlisted
1573lgn nl
1574lgt mrefd
1575lgn nr
1576lgb 10
1577ret done 0
1578end
1579note ---- repo mode: .zenodo.json (jflat) then @tree and git ls-tree -l HEAD
1580note tname: the ls-tree line l names a top-level blob called t
1581note git ls-tree -l ends the metadata part with a decimal blob size. Apply the same 8 MiB
1582note foreign file transport boundary before copying or decoding repository paper bytes.
1583fn tbytes l ulong to bool
1584e = tabat l eol l
1585a = e
1586while gt a l bound 8388608
1587c = get ib sub a 1
1588if eq c 32
1589break
1590end
1591a = sub a 1
1592end
1593if not alldig a e
1594ret false
1595end
1596n = dnum a e
1597ret and gt n 0 lt n 8388608
1598end
1599fn tname l ulong t view uchar * to bool
1600ln = eol l
1601x = tabat l ln
1602if ge x ln
1603ret false
1604end
1605if not reqt add x 1 ln t
1606ret false
1607end
1608if not lpre l ln kblob
1609ret false
1610end
1611ret tbytes l
1612end
1613fn tfind s ulong t view uchar * to bool
1614l = s
1615lim = get ibl 0
1616while lt l lim bound 8388608
1617if tname l t
1618ret true
1619end
1620l = add eol l 1
1621end
1622ret false
1623end
1624fn tbt t view uchar * to void
1625for i ulong len t bound 64
1626tbb get t i
1627end
1628end
1629note A repository slug ends with 128 bits of SHA-256 of its complete RID, not a colliding RID prefix.
1630fn rsuffix to void
1631b = new uchar 128 0
1632d = new uchar 32 0
1633n = get avl 2
1634for i ulong n bound 44
1635put b i ava 2 i
1636end
1637put b n 9
1638n = add n 1
1639for i ulong get avl 5 bound 64
1640put b add n i ava 5 i
1641end
1642n = add n get avl 5
1643x = sha2_digest 256 view part b 0 n d
1644if gt get sgl 0 30
1645put sgl 0 30
1646put sg 29 45
1647end
1648sgc 114
1649for i ulong 16
1650v = get d i
1651sgc get khex ulong shr v 4
1652sgc get khex ulong and v 15
1653end
1654end
1655fn hexarg k ulong n ulong to bool
1656if ne get avl k n
1657ret false
1658end
1659for i ulong n bound 64
1660c = ava k i
1661if not or isdig c and ge c 97 le c 102
1662ret false
1663end
1664end
1665ret true
1666end
1667fn rmode to int
1668if not ridok 2
1669ret 2
1670end
1671if not didok 3
1672ret 2
1673end
1674if not dateok 4
1675ret 2
1676end
1677if not autok 5
1678ret 2
1679end
1680if not rdin
1681x = flush 2 mbig len mbig
1682ret 2
1683end
1684lim = get ibl 0
1685t = ulong 0
1686while lt t lim bound 8388608
1687if reqt t eol t ktree
1688break
1689end
1690t = add eol t 1
1691end
1692if gt t lim
1693t = lim
1694end
1695put hs 0 0
1696put he 0 t
1697put hpl 0 0
1698ts = lim
1699if lt t lim
1700ts = add eol t 1
1701end
1702tl = hval knone ktitle
1703if ge tl get he 0
1704lgt mrt
1705lgb 10
1706ret done 1
1707end
1708nm = hfind 0 knone kcnm 1000000
1709if ge nm get he 0
1710lgt mrc
1711lgb 10
1712ret done 1
1713end
1714lc = hval knone klic
1715if ge lc get he 0
1716lc = hval knone klics
1717end
1718if ge lc get he 0
1719lgt mrl
1720lgb 10
1721ret done 1
1722end
1723put lamb 0 lcount knone
1724hasl = or or tfind ts klic1 tfind ts klic2 or or tfind ts klic3 tfind ts klic4 tfind ts klic5
1725if not hasl
1726lgt mrf
1727lgb 10
1728ret done 1
1729end
1730pf = ulong 0
1731if tfind ts kpaper3
1732pf = ulong 3
1733end
1734if tfind ts kpaper2
1735pf = ulong 2
1736end
1737if tfind ts kpaper1
1738pf = ulong 1
1739end
1740if eq pf 0
1741lgt mrp
1742lgb 10
1743ret done 1
1744end
1745opn = isopen vala lc valb lc
1746if gt get lamb 0 1
1747opn = false
1748lgt mamb
1749lgb 10
1750end
1751mkslug vala tl valb tl
1752rsuffix
1753lhead 87
1754emb 9
1755d = hval knone kdate
1756dk = false
1757if lt d get he 0
1758if vdate vala d valb d
1759emr vala d valb d
1760dk = true
1761end
1762end
1763if not dk
1764ema 4
1765end
1766emb 9
1767k = hval knone kput
1768if ge k get he 0
1769k = hval knone kupt
1770end
1771if lt k get he 0
1772if reqt vala k valb k kart
1773em kjart
1774else
1775emw vala k valb k 32
1776end
1777end
1778emb 9
1779em krad
1780emb 9
1781emb 9
1782d = hval knone kdoi
1783if lt d get he 0
1784if doiok vala d valb d
1785emr vala d valb d
1786end
1787end
1788emb 9
1789d = hval knone kver
1790if lt d get he 0
1791x = emv vala d valb d 48
1792end
1793emb 9
1794emb 49
1795emb 9
1796emb 48
1797emb 9
1798if gt get lamb 0 1
1799em kamb
1800else
1801emw vala lc valb lc 32
1802end
1803emb 9
1804x = emv vala tl valb tl 400
1805emb 10
1806abstr knone
1807lhead 67
1808names ksep knone
1809emb 10
1810lhead 66
1811names kand knone
1812emb 10
1813kwords knone
1814links knone
1815lhead 80
1816em krv
1817emb 9
1818ema 3
1819emb 9
1820ema 4
1821emb 9
1822em krp
1823ema 2
1824emb 9
1825if opn
1826emb 49
1827else
1828emb 48
1829end
1830emb 10
1831if or opn argeq 6 kplan
1832tbs
1833tbb 9
1834if eq pf 1
1835tbt kpaper1
1836end
1837if eq pf 2
1838tbt kpaper2
1839end
1840if eq pf 3
1841tbt kpaper3
1842end
1843if argeq 6 kplan
1844tbb 9
1845if opn
1846tbb 49
1847else
1848tbb 48
1849end
1850end
1851tbb 10
1852end
1853em kos
1854ema 5
1855emb 10
1856em kon
1857x = emv vala nm valb nm 120
1858emb 10
1859em koa
1860ema 3
1861emb 10
1862em koc
1863ema 4
1864emb 10
1865em kov
1866em krv
1867emb 10
1868if eq argcnt 8
1869if not hexarg 6 40
1870ret 2
1871end
1872if not hexarg 7 64
1873ret 2
1874end
1875lhead 71
1876ema 6
1877emb 9
1878ema 7
1879emb 10
1880end
1881ret done 0
1882end
1883note ---- text mode: paragraphs (separated by a blank line or a form feed) become one line each;
1884note line ends inside a paragraph, tabs and other control bytes become a space; runs of spaces
1885note become one; a malformed UTF-8 byte becomes ?; at most 262,144 bytes are written (whole
1886note paragraphs where they fit: the paragraph that would pass the limit and the rest are left oc).
1887fn tmode to int
1888if not rdin
1889x = flush 2 mbig len mbig
1890ret 2
1891end
1892lim = get ibl 0
1893i = ulong 0
1894ps = get obl 0
1895pw = ulong 0
1896nlc = ulong 0
1897pend = false
1898stop = false
1899while lt i lim bound 8388608
1900c = get ib i
1901brk = false
1902if eq c 12
1903brk = true
1904end
1905if eq c 10
1906nlc = add nlc 1
1907if ge nlc 2
1908brk = true
1909end
1910else
1911if and ne c 13 and ne c 32 ne c 9
1912nlc = ulong 0
1913end
1914end
1915if brk
1916if gt pw 0
1917emb 10
1918if gt get obl 0 262144
1919put obl 0 ps
1920stop = true
1921break
1922end
1923ps = get obl 0
1924end
1925pw = ulong 0
1926pend = false
1927i = add i 1
1928else
1929if or le c 32 eq c 127
1930if gt pw 0
1931pend = true
1932end
1933i = add i 1
1934else
1935k = ulong 1
1936if ge c 128
1937k = u8len i lim
1938end
1939if pend
1940emb 32
1941pend = false
1942end
1943if eq k 0
1944emb 63
1945k = ulong 1
1946else
1947emr i add i k
1948end
1949pw = add pw k
1950i = add i k
1951end
1952end
1953end
1954if and not stop gt pw 0
1955emb 10
1956if gt get obl 0 262144
1957put obl 0 ps
1958end
1959end
1960ret done 0
1961end
1962note ---- small file reads into rb (allow, remove, an author's registry), at most 65,535 bytes
1963fn ldarg k ulong to void
1964n = get avl k
1965for i ulong n bound 512
1966put pth i ava k i
1967end
1968put pthl 0 n
1969end
1970fn rregular fd int to bool
1971st = new uchar 128 0
1972r = fstat fd st 0 128
1973if ne r 0
1974ret false
1975end
1976m = or ulong get st 16 shl ulong get st 17 8
1977ret eq and m 61440 32768
1978end
1979note Absence is permitted for remove, but any other open/read/type/overflow failure is fatal.
1980fn rload to bool
1981one = new uchar 1 0
1982put rerr 0 0
1983put rbl 0 0
1984fd = fopen pth 0 get pthl 0 559104 0
1985if lt fd 0
1986if ne fd -2
1987put rerr 0 1
1988end
1989ret false
1990end
1991if not rregular int fd
1992x = fclose int fd
1993put rerr 0 1
1994ret false
1995end
1996n = ulong 0
1997k = long 1
1998while gt k 0 bound 65536
1999if eq n 65535
2000k = read int fd one 0 1
2001if ne k 0
2002put rerr 0 1
2003end
2004break
2005end
2006k = read int fd rb n sub 65535 n
2007if lt k 0
2008put rerr 0 1
2009end
2010if gt k 0
2011n = add n ulong k
2012end
2013end
2014x = fclose int fd
2015if ne get rerr 0 0
2016ret false
2017end
2018put rbl 0 n
2019ret true
2020end
2021fn reol a ulong to ulong
2022n = get rbl 0
2023e = a
2024while lt e n bound 65536
2025if eq get rb e 10
2026ret e
2027end
2028e = add e 1
2029end
2030ret n
2031end
2032note rstart: the start of the value of an rb line that may begin with rad:
2033fn rstart a ulong e ulong pre bool to ulong
2034if pre
2035if gt sub e a 4
2036x = and eq get rb a 114 eq get rb add a 1 97
2037y = and eq get rb add a 2 100 eq get rb add a 3 58
2038if and x y
2039ret add a 4
2040end
2041end
2042end
2043ret a
2044end
2045note rhas: a line of rb is exactly argument k (pre: also with rad: in front)
2046fn rhas k ulong pre bool to bool
2047n = get rbl 0
2048a = ulong 0
2049m = get avl k
2050if eq m 0
2051ret false
2052end
2053while lt a n bound 65536
2054e = reol a
2055b = rstart a e pre
2056if eq sub e b m
2057same = true
2058for i ulong m bound 512
2059if ne get rb add b i ava k i
2060same = false
2061end
2062end
2063if same
2064ret true
2065end
2066end
2067a = add e 1
2068end
2069ret false
2070end
2071note rbhas: a line of rb is ib[a, b) (pre: also with rad: in front)
2072fn rbeq y ulong a ulong m ulong to bool
2073for i ulong m bound 8388608
2074x = get rb add y i
2075z = get ib add a i
2076if ne x z
2077ret false
2078end
2079end
2080ret true
2081end
2082fn rbhas a ulong b ulong pre bool to bool
2083if pre
2084if lpre a b krp
2085a = add a 4
2086end
2087end
2088n = get rbl 0
2089if le b a
2090ret false
2091end
2092m = sub b a
2093x = ulong 0
2094while lt x n bound 65536
2095e = reol x
2096y = rstart x e pre
2097if eq sub e y m
2098same = rbeq y a m
2099if same
2100ret true
2101end
2102end
2103x = add e 1
2104end
2105ret false
2106end
2107fn rstar to bool
2108n = get rbl 0
2109a = ulong 0
2110while lt a n bound 65536
2111e = reol a
2112if eq sub e a 1
2113if eq get rb a 42
2114ret true
2115end
2116end
2117a = add e 1
2118end
2119ret false
2120end
2121note ---- the shelf list (rows: rid, state, did, ...), read a row at a time. listed: a row for the
2122note rid in slot 0 (with or without rad:) in state open, stored or held, brought by the did in slot 7
2123fn roweq r view uchar 1024 s ulong e ulong t view uchar * to bool
2124if ne sub e s len t
2125ret false
2126end
2127for i ulong len t bound 16
2128if ne get r add s i get t i
2129ret false
2130end
2131end
2132ret true
2133end
2134fn rowst r view uchar 1024 s ulong e ulong to bool
2135if roweq r s e kst1
2136ret true
2137end
2138if roweq r s e kst2
2139ret true
2140end
2141ret roweq r s e kst3
2142end
2143fn rowok r view uchar 1024 n ulong to bool
2144p = ulong 0
2145if gt n 4
2146if and and eq get r 0 114 eq get r 1 97 and eq get r 2 100 eq get r 3 58
2147p = ulong 4
2148end
2149end
2150m = get avl 0
2151if or eq m 0 lt sub n p m
2152ret false
2153end
2154for i ulong m bound 512
2155if ne get r add p i ava 0 i
2156ret false
2157end
2158end
2159q = add p m
2160if ge q n
2161ret false
2162end
2163if ne get r q 9
2164ret false
2165end
2166q = add q 1
2167s = q
2168while lt q n bound 1024
2169if eq get r q 9
2170break
2171end
2172q = add q 1
2173end
2174if not rowst r s q
2175ret false
2176end
2177if ge q n
2178ret false
2179end
2180q = add q 1
2181d = get avl 7
2182if or eq d 0 lt sub n q d
2183ret false
2184end
2185for i ulong d bound 512
2186if ne get r add q i ava 7 i
2187ret false
2188end
2189end
2190e = add q d
2191if lt e n
2192ret eq get r e 9
2193end
2194ret true
2195end
2196fn listed lk ulong to bool
2197ldarg lk
2198fd = fopen pth 0 get pthl 0 557056 0
2199if lt fd 0
2200ret false
2201end
2202b = new uchar 4096 0
2203line = new uchar 1024 0
2204got = false
2205ll = ulong 0
2206over = false
2207k = long 1
2208while gt k 0 bound 9223372036854775807
2209k = read int fd b 0 4096
2210if gt k 0
2211for i ulong ulong k bound 4096
2212c = get b i
2213if eq c 10
2214if not over
2215if rowok line ll
2216got = true
2217end
2218end
2219ll = ulong 0
2220over = false
2221else
2222if lt ll 1024
2223put line ll c
2224ll = add ll 1
2225else
2226over = true
2227end
2228end
2229end
2230end
2231end
2232x = fclose int fd
2233if and gt ll 0 not over
2234if rowok line ll
2235got = true
2236end
2237end
2238ret got
2239end
2240note ---- the queue (written by forged: a less trusted process). Lines:
2241note Z <tab> did <tab> ORCID iD <tab> DOI (empty or 10.5281/zenodo.<digits>)
2242note P <tab> did <tab> rid <tab> ORCID iD (may be empty)
2243note Accepted requests go to stdout with the author id they are filed under as the last field:
2244note the ORCID iD lowercased, or key- and the first 16 hex characters of SHA-256 over the did (a
2245note repository brought without an ORCID iD that this key added). Refusals go to stderr.
2246note Slots: 1 add dir, 2 state, 3 allow, 4 remove, 5 reg dir; a line's fields go to 0 (rid or DOI),
2247note 6 (ORCID iD) and 7 (did).
2248fn getoff to ulong
2249ldarg 2
2250b = new uchar 24 0
2251fd = fopen pth 0 get pthl 0 524288 0
2252if lt fd 0
2253ret 0
2254end
2255k = read int fd b 0 20
2256x = fclose int fd
2257v = ulong 0
2258if gt k 0
2259for i ulong ulong k bound 20
2260c = get b i
2261if isdig c
2262v = add mul v 10 ulong sub c 48
2263end
2264end
2265end
2266ret v
2267end
2268fn pmove n ulong m ulong to bool
2269put rpk 0 2
2270put rpk 1 0
2271put rpk 2 uchar and m 255
2272put rpk 3 uchar shr m 8
2273for i ulong m bound 1100
2274put rpk add 4 i get pt2 i
2275end
2276o = add 4 m
2277put rpk o uchar and n 255
2278put rpk add o 1 uchar shr n 8
2279for i ulong n bound 1100
2280put rpk add add o 2 i get pth i
2281end
2282ret eq renames rpk 0 add add o 2 n 0 0
2283end
2284fn putoff v ulong to bool
2285ldarg 2
2286n = get pthl 0
2287for i ulong n bound 1100
2288put pt2 i get pth i
2289end
2290for i ulong len kxt
2291put pt2 add n i get kxt i
2292end
2293m = add n len kxt
2294c = new uchar 24 0
2295d = new uchar 24 0
2296k = ulong 0
2297x = v
2298while gt x 0 bound 20
2299put c k uchar add 48 rem x 10
2300x = div x 10
2301k = add k 1
2302end
2303if eq k 0
2304put c 0 48
2305k = ulong 1
2306end
2307for j ulong k bound 20
2308put d j get c sub sub k 1 j
2309end
2310put d k 10
2311r = unlink pt2 0 m
2312fd = fopen pt2 0 m 557249 384
2313if lt fd 0
2314ret false
2315end
2316w = write int fd d 0 add k 1
2317r = fsync int fd
2318y = fclose int fd
2319if ne w long add k 1
2320ret false
2321end
2322ret pmove n m
2323end
2324note qfld: field f (0 based) of the queue line qb[a, e) into argument slot k; false when the line
2325note has fewer fields or the field is over 500 bytes
2326fn qcopy p ulong q ulong k ulong to void
2327o = mul k 512
2328for i ulong sub q p bound 512
2329c = get qb add p i
2330put av add o i c
2331end
2332put avl k sub q p
2333end
2334fn qfld a ulong e ulong f ulong k ulong to bool
2335p = a
2336j = ulong 0
2337while lt j f bound 8
2338while lt p e bound 65536
2339if eq get qb p 9
2340break
2341end
2342p = add p 1
2343end
2344if ge p e
2345ret false
2346end
2347p = add p 1
2348j = add j 1
2349end
2350q = p
2351while lt q e bound 65536
2352if eq get qb q 9
2353break
2354end
2355q = add q 1
2356end
2357if gt sub q p 500
2358ret false
2359end
2360qcopy p q k
2361ret true
2362end
2363fn nfld a ulong e ulong to ulong
2364n = ulong 1
2365i = a
2366while lt i e bound 65536
2367if eq get qb i 9
2368n = add n 1
2369end
2370i = add i 1
2371end
2372ret n
2373end
2374note zdoiok: argument k is empty or 10.5281/zenodo.<1 to 12 digits>
2375fn zdoiok k ulong to bool
2376n = get avl k
2377if eq n 0
2378ret true
2379end
2380m = len kzpre
2381if or le n m gt n add m 12
2382ret false
2383end
2384for i ulong m bound 32
2385if ne ava k i get kzpre i
2386ret false
2387end
2388end
2389for i ulong sub n m bound 12
2390if not isdig ava k add m i
2391ret false
2392end
2393end
2394ret true
2395end
2396note kdid: key- and 16 hex characters of SHA-256 over the did (slot 7)
2397fn kdid to void
2398b = new uchar 128 0
2399d = new uchar 32 0
2400n = get avl 7
2401for i ulong n bound 96
2402put b i ava 7 i
2403end
2404r = sha2_digest 256 view part b 0 n d
2405em kkey
2406for i ulong 8
2407v = get d i
2408emb get khex ulong shr v 4
2409emb get khex ulong and v 15
2410end
2411end
2412fn qrefuse m view uchar * to void
2413lgt m
2414lgb 10
2415end
2416note qline: one queue line qb[a, e)
2417fn qline a ulong e ulong to void
2418if lt sub e a 3
2419qrefuse mqbad
2420ret
2421end
2422ty = get qb a
2423ok = or eq ty 90 eq ty 80
2424if ok
2425ok = eq get qb add a 1 9
2426end
2427if ok
2428ok = eq nfld a e 4
2429end
2430if ok
2431ok = qfld a e 1 7
2432end
2433if ok
2434ok = didok 7
2435end
2436if ok
2437if eq ty 90
2438ok = qfld a e 2 6
2439if ok
2440if gt get avl 6 0
2441ok = orcok 6
2442end
2443end
2444if ok
2445ok = qfld a e 3 0
2446end
2447if ok
2448ok = zdoiok 0
2449if eq add get avl 6 get avl 0 0
2450ok = false
2451end
2452end
2453else
2454ok = qfld a e 3 6
2455if ok
2456if gt get avl 6 0
2457ok = orcok 6
2458end
2459end
2460if ok
2461ok = qfld a e 2 0
2462end
2463if ok
2464ok = ridok 0
2465end
2466end
2467end
2468if not ok
2469qrefuse mqbad
2470ret
2471end
2472note the shelf's allow file names the key or *; no file: no key may add
2473ldarg 3
2474if not rload
2475if ne get rerr 0 0
2476qrefuse mpolicy
2477put pfail 0 1
2478ret
2479end
2480qrefuse mqallow
2481ret
2482end
2483if not or rstar rhas 7 false
2484qrefuse mqallow
2485ret
2486end
2487ldarg 4
2488rloaded = rload
2489if ne get rerr 0 0
2490qrefuse mpolicy
2491put pfail 0 1
2492ret
2493end
2494if rloaded
2495if or or rhas 7 false rhas 0 true rhas 6 false
2496qrefuse mqrem
2497ret
2498end
2499end
2500emb ty
2501emb 9
2502ema 7
2503emb 9
2504if eq ty 90
2505ema 6
2506emb 9
2507ema 0
2508else
2509ema 0
2510emb 9
2511ema 6
2512end
2513emb 9
2514if gt get avl 6 0
2515for i ulong 19
2516emb lowc ava 6 i
2517end
2518else
2519kdid
2520end
2521emb 10
2522end
2523fn qmode to int
2524for k ulong 5
2525if eq get avl add k 1 0
2526ret 2
2527end
2528end
2529n = get avl 1
2530if ne ava 1 sub n 1 47
2531ret 2
2532end
2533if ne ava 5 sub get avl 5 1 47
2534ret 2
2535end
2536for i ulong n bound 512
2537put pth i ava 1 i
2538end
2539for i ulong len kq
2540put pth add n i get kq i
2541end
2542put pthl 0 add n len kq
2543fd = fopen pth 0 get pthl 0 524288 0
2544if lt fd 0
2545ret done 0
2546end
2547off = getoff
2548k = pread int fd qb 0 65536 long off
2549x = fclose int fd
2550if le k 0
2551ret done 0
2552end
2553m = ulong k
2554a = ulong 0
2555while lt a m bound 65536
2556e = a
2557while lt e m bound 65536
2558if eq get qb e 10
2559break
2560end
2561e = add e 1
2562end
2563if ge e m
2564if and eq a 0 eq m 65536
2565a = m
2566end
2567break
2568end
2569qline a e
2570a = add e 1
2571end
2572if ne get pfail 0 0
2573put obl 0 0
2574ret done 1
2575end
2576if not putoff add off a
2577ret done 1
2578end
2579ret done 0
2580end
2581note ---- onshelf: exit 0 when the shelf list (slot 1) lists RID (slot 2) as brought by DID (slot 3)
2582fn smode to int
2583if not ridok 2
2584ret 2
2585end
2586if not didok 3
2587ret 2
2588end
2589for i ulong get avl 2 bound 512
2590put av i ava 2 i
2591end
2592put avl 0 get avl 2
2593for i ulong get avl 3 bound 512
2594put av add 3584 i ava 3 i
2595end
2596put avl 7 get avl 3
2597if listed 1
2598ret 0
2599end
2600ret 1
2601end
2602note ---- per-import bundles end at the next W or O. Never join provenance by slug globally.
2603fn slugok a ulong b ulong to bool
2604if or le b a gt sub b a 64
2605ret false
2606end
2607for i ulong sub b a bound 64
2608c = get ib add a i
2609if not or or isdig c islow c eq c 45
2610ret false
2611end
2612end
2613ret true
2614end
2615fn wserial a ulong b ulong to ulong
2616if or le b a gt sub b a 19
2617ret 18446744073709551615
2618end
2619if eq get ib a 48
2620ret 18446744073709551615
2621end
2622v = ulong 0
2623for i ulong sub b a bound 19
2624c = get ib add a i
2625if not isdig c
2626ret 18446744073709551615
2627end
2628v = add mul v 10 ulong sub c 48
2629end
2630ret v
2631end
2632fn gend s ulong to ulong
2633t = add eol s 1
2634while lt t get ibl 0 bound 8388608
2635c = get ib t
2636if or or eq c 87 eq c 79 eq c 88
2637ret t
2638end
2639t = add eol t 1
2640end
2641ret get ibl 0
2642end
2643note Canonical raw/gather output has a trailing O block; header-only legacy input is the fallback.
2644note gmode rejects mixed header/trailing input before this association can cross imports.
2645fn gprofile s ulong to ulong
2646t = add eol s 1
2647while lt t get ibl 0 bound 8388608
2648if eq get ib t 88
2649break
2650end
2651if eq get ib t 79
2652ret t
2653end
2654t = add eol t 1
2655end
2656t = ulong 0
2657while lt t s bound 8388608
2658if eq get ib t 79
2659ret t
2660end
2661if eq get ib t 87
2662break
2663end
2664t = add eol t 1
2665end
2666ret get ibl 0
2667end
2668fn goval s ulong key view uchar * to ulong
2669t = s
2670while lt t get ibl 0 bound 8388608
2671e = eol t
2672if ne get ib t 79
2673break
2674end
2675if lpre t e key
2676ret add t len key
2677end
2678t = add e 1
2679end
2680ret get ibl 0
2681end
2682fn gsameslug s ulong t ulong to bool
2683ret feqr add s 2 tabat add s 2 eol s add t 2 tabat add t 2 eol t
2684end
2685note Exactly one matching fact inside this bundle, ibl means absent, ibl+1 ambiguous.
2686fn gfact s ulong ty uchar to ulong
2687t = add eol s 1
2688v = get ibl 0
2689lim = gend s
2690while lt t lim bound 8388608
2691if eq get ib t ty
2692if not gsameslug s t
2693ret add get ibl 0 1
2694end
2695if lt v get ibl 0
2696ret add get ibl 0 1
2697end
2698v = t
2699end
2700t = add eol t 1
2701end
2702ret v
2703end
2704note N: slug, static O key, value, scoped inside the W bundle. I: slug, original P.open.
2705note P.open stays conservative across repeated selected-only gathers. I preserves the own
2706note decision without reopening aggregate-closed text; a successful full raw selection can reopen it.
2707note N is private association data, never inferred from the shared selected O profile.
2708fn gnfirst s ulong to ulong
2709t = add eol s 1
2710lim = gend s
2711while lt t lim bound 8388608
2712if eq get ib t 78
2713ret t
2714end
2715t = add eol t 1
2716end
2717ret get ibl 0
2718end
2719fn gnval s ulong key view uchar * to ulong
2720t = gnfirst s
2721lim = gend s
2722while lt t lim bound 8388608
2723if eq get ib t 78
2724a = sfield t eol t 2
2725if lpre a eol t key
2726ret add a len key
2727end
2728end
2729t = add eol t 1
2730end
2731ret get ibl 0
2732end
2733fn gorcid s ulong to ulong
2734if lt gnfirst s get ibl 0
2735ret gnval s korc
2736end
2737ret goval gprofile s koo
2738end
2739note Association validation is structural; publisher still validates the public profile values.
2740fn gbound s ulong to bool
2741if ge gnfirst s get ibl 0
2742ret eq gfact s 73 get ibl 0
2743end
2744il = gfact s 73
2745if ge il get ibl 0
2746ret false
2747end
2748v = sfield il eol il 2
2749if ne sub eol il v 1
2750ret false
2751end
2752if not or reqt v eol il kone reqt v eol il kzero
2753ret false
2754end
2755t = add eol s 1
2756lim = gend s
2757while lt t lim bound 8388608
2758if eq get ib t 78
2759if not gsameslug s t
2760ret false
2761end
2762a = sfield t eol t 2
2763b = tabat a eol t
2764if or ge b eol t eq a b
2765ret false
2766end
2767if or lpre a eol t kna or lpre a eol t knc lpre a eol t knv
2768ret false
2769end
2770u = add eol s 1
2771while lt u t bound 8388608
2772if eq get ib u 78
2773c = sfield u eol u 2
2774if feqr a b c tabat c eol u
2775ret false
2776end
2777end
2778u = add eol u 1
2779end
2780end
2781t = add eol t 1
2782end
2783ret and lt gnval s knid get ibl 0 lt gnval s knname get ibl 0
2784end
2785fn gbindings to bool
2786s = ulong 0
2787while lt s get ibl 0 bound 8388608
2788if eq get ib s 87
2789if not gbound s
2790ret false
2791end
2792end
2793s = add eol s 1
2794end
2795ret true
2796end
2797fn gorig s ulong pl ulong to ulong
2798t = gfact s 73
2799if lt t get ibl 0
2800ret sfield t eol t 2
2801end
2802ret sfield pl eol pl 6
2803end
2804fn gnhead s ulong to void
2805em knn
2806a = add s 2
2807emr a tabat a eol s
2808emb 9
2809end
2810fn gattach s ulong to void
2811t = gnfirst s
2812if lt t get ibl 0
2813lim = gend s
2814while lt t lim bound 8388608
2815if eq get ib t 78
2816emr t eol t
2817emb 10
2818end
2819t = add eol t 1
2820end
2821else
2822t = gprofile s
2823while lt t get ibl 0 bound 8388608
2824e = eol t
2825if ne get ib t 79
2826break
2827end
2828if not or lpre t e koa or lpre t e koc lpre t e kov
2829gnhead s
2830emr add t 2 e
2831emb 10
2832end
2833t = add e 1
2834end
2835end
2836pl = gfact s 80
2837if lt pl get ibl 0
2838em kni
2839a = add s 2
2840emr a tabat a eol s
2841emb 9
2842v = gorig s pl
2843emr v eol v
2844emb 10
2845end
2846end
2847note Older repo serializers put G after the final O profile. Gather moves the chosen G into its bundle.
2848fn gsource s ulong to ulong
2849v = gfact s 71
2850if ne v get ibl 0
2851ret v
2852end
2853t = gend s
2854if lt t get ibl 0
2855if eq get ib t 79
2856while lt t get ibl 0 bound 8388608
2857if or eq get ib t 87 eq get ib t 88
2858break
2859end
2860if eq get ib t 71
2861if gsameslug s t
2862if lt v get ibl 0
2863ret add get ibl 0 1
2864end
2865v = t
2866end
2867end
2868t = add eol t 1
2869end
2870end
2871end
2872ret v
2873end
2874fn shelfok a ulong b ulong c ulong d ulong to bool
2875x = a
2876if lpre a b krp
2877x = add a 4
2878end
2879if or gt sub b x 44 gt sub d c 96
2880ret false
2881end
2882for i ulong sub b x bound 44
2883put av i get ib add x i
2884end
2885put avl 0 sub b x
2886for i ulong sub d c bound 96
2887put av add 3584 i get ib add c i
2888end
2889put avl 7 sub d c
2890ret listed 2
2891end
2892fn gremoved s ulong k ulong pre bool to bool
2893e = eol s
2894a = sfield s e k
2895ret rbhas a tabat a e pre
2896end
2897fn gexplicit s ulong pl ulong to bool
2898if or gremoved s 1 false or gremoved s 6 false gremoved s 7 false
2899ret true
2900end
2901if lt pl get ibl 0
2902ret gremoved pl 5 true
2903end
2904ret false
2905end
2906fn geligible s ulong pl ulong to bool
2907if ge pl get ibl 0
2908ret false
2909end
2910if ne get gn 1 0
2911if gremoved pl 3 false
2912ret false
2913end
2914v = gorcid s
2915if lt v get ibl 0
2916if rbhas v eol v false
2917ret false
2918end
2919end
2920end
2921pe = eol pl
2922how = sfield pl pe 2
2923if reqt how tabat how pe krv
2924src = sfield pl pe 5
2925dd = sfield pl pe 3
2926ret shelfok src tabat src pe dd tabat dd pe
2927end
2928ret true
2929end
2930fn gtvalid t ulong to bool
2931if eq t get ibl 0
2932ret true
2933end
2934if gt t get ibl 0
2935ret false
2936end
2937e = eol t
2938a = sfield t e 2
2939if eq sub e a 1
2940ret eq get ib a 45
2941end
2942if ne sub e a 64
2943ret false
2944end
2945for i ulong 64
2946c = get ib add a i
2947if not or isdig c and ge c 97 le c 102
2948ret false
2949end
2950end
2951ret true
2952end
2953fn gscan to ulong
2954n = ulong 0
2955s = ulong 0
2956while lt s get ibl 0 bound 8388608
2957if eq get ib s 87
2958put gbw n s
2959put gbe n gend s
2960pl = gfact s 80
2961put gbp n pl
2962put gbg n gsource s
2963put gbs n 0
2964put gbk n 0
2965put gbl n 0
2966a = add s 2
2967if slugok a tabat a eol s
2968if geligible s pl
2969if le get gbg n get ibl 0
2970r = gfact s 82
2971t = gfact s 84
2972if and le r get ibl 0 gtvalid t
2973seq = ulong 0
2974if lt r get ibl 0
2975v = sfield r eol r 2
2976seq = wserial v eol r
2977end
2978if ne seq 18446744073709551615
2979put gbs n seq
2980put gbk n 1
2981v = sfield pl eol pl 6
2982if reqt v eol pl kone
2983put gbl n 1
2984end
2985end
2986end
2987end
2988end
2989end
2990n = add n 1
2991end
2992s = add eol s 1
2993end
2994ret n
2995end
2996note Each copy is filtered before dedup/licence aggregation; explicit work/source takedowns span copies.
2997fn gpick i ulong n ulong to ulong
2998s = get gbw i
2999win = n
3000for j ulong n bound 2796203
3001if gsameslug s get gbw j
3002if ne get gn 1 0
3003if gexplicit get gbw j get gbp j
3004ret n
3005end
3006end
3007if ge get gbw j get gxs 0
3008continue
3009end
3010if ne get gbk j 0
3011if eq win n
3012win = j
3013else
3014if ge get gbs j get gbs win
3015win = j
3016end
3017end
3018end
3019end
3020end
3021ret win
3022end
3023fn gopen i ulong n ulong to bool
3024for j ulong n bound 2796203
3025if ne get gbk j 0
3026if gsameslug get gbw i get gbw j
3027if eq get gbl j 0
3028ret false
3029end
3030end
3031end
3032end
3033ret true
3034end
3035fn gemit i ulong n ulong to void
3036s = get gbw i
3037t = s
3038while lt t get gbe i bound 8388608
3039e = eol t
3040c = get ib t
3041if not or eq c 78 eq c 73
3042if eq c 80
3043v = sfield t e 6
3044emr t v
3045if gopen i n
3046emb 49
3047else
3048emb 48
3049end
3050else
3051emr t e
3052end
3053emb 10
3054end
3055t = add e 1
3056end
3057gattach s
3058g = get gbg i
3059if lt g get ibl 0
3060if ge g get gbe i
3061emr g eol g
3062emb 10
3063end
3064end
3065end
3066fn gemprofile i ulong to void
3067s = get gbw i
3068pl = get gbp i
3069t = gnfirst s
3070if lt t get ibl 0
3071lim = gend s
3072while lt t lim bound 8388608
3073if eq get ib t 78
3074em kob
3075v = sfield t eol t 2
3076emr v eol t
3077emb 10
3078end
3079t = add eol t 1
3080end
3081else
3082t = gprofile s
3083while lt t get ibl 0 bound 8388608
3084e = eol t
3085if ne get ib t 79
3086break
3087end
3088if not or lpre t e koa or lpre t e koc lpre t e kov
3089emr t e
3090emb 10
3091end
3092t = add e 1
3093end
3094end
3095em koa
3096v = sfield pl eol pl 3
3097emr v tabat v eol pl
3098emb 10
3099em koc
3100v = sfield pl eol pl 4
3101emr v tabat v eol pl
3102emb 10
3103em kov
3104v = sfield pl eol pl 2
3105emr v tabat v eol pl
3106emb 10
3107end
3108note Legacy header-only input is accepted, but header plus later raw profile is ambiguous.
3109fn gmixed to bool
3110header = false
3111works = false
3112s = ulong 0
3113while lt s get ibl 0 bound 8388608
3114c = get ib s
3115if eq c 87
3116works = true
3117end
3118if eq c 79
3119if works
3120if header
3121ret true
3122end
3123else
3124header = true
3125end
3126end
3127s = add eol s 1
3128end
3129ret false
3130end
3131fn gmode to int
3132if not rdin
3133x = flush 2 mbig len mbig
3134ret 2
3135end
3136if gmixed
3137lgt mprofile
3138lgb 10
3139ret done 1
3140end
3141if not gbindings
3142lgt mbind
3143lgb 10
3144ret done 1
3145end
3146put gxs 0 get ibl 0
3147saux = ulong 0
3148while lt saux get ibl 0 bound 8388608
3149if eq get ib saux 88
3150if lt get gxs 0 get ibl 0
3151lgt maux
3152lgb 10
3153ret done 1
3154end
3155put gxs 0 saux
3156else
3157if lt get gxs 0 saux
3158if eq get ib saux 79
3159lgt maux
3160lgb 10
3161ret done 1
3162end
3163if eq get ib saux 87
3164if ge gnfirst saux get ibl 0
3165lgt maux
3166lgb 10
3167ret done 1
3168end
3169end
3170end
3171end
3172saux = add eol saux 1
3173end
3174put gn 1 0
3175ldarg 1
3176if rload
3177put gn 1 1
3178end
3179if ne get rerr 0 0
3180lgt mpolicy
3181lgb 10
3182ret done 1
3183end
3184n = gscan
3185profile = n
3186for i ulong n bound 2796203
3187put gbsel i 0
3188if eq gpick i n i
3189put gbsel i 1
3190if eq profile n
3191profile = i
3192else
3193if ge get gbs i get gbs profile
3194profile = i
3195end
3196end
3197end
3198end
3199if eq profile n
3200ret done 0
3201end
3202s = ulong 0
3203while lt s get ibl 0 bound 8388608
3204if eq get ib s 72
3205emr s eol s
3206emb 10
3207end
3208s = add eol s 1
3209end
3210for i ulong n bound 2796203
3211if ne get gbsel i 0
3212gemit i n
3213end
3214end
3215gemprofile profile
3216ret done 0
3217end
3218note ---- layout: one raw catalog, or a selected catalog with explicit bundle associations.
3219note It neither reads policy nor picks, removes, deduplicates or changes a P.open flag.
3220note Selected input always requires explicit N/I facts. Old selections cannot establish exact
3221note association from shared O; rebuild from retained raw catalogs. Legacy raw headers convert alone.
3222fn lcopy s ulong to void
3223t = s
3224lim = gend s
3225while lt t lim bound 8388608
3226c = get ib t
3227if not or eq c 78 eq c 73
3228emr t eol t
3229emb 10
3230end
3231t = add eol t 1
3232end
3233gattach s
3234end
3235fn lmode to int
3236if not or argeq 1 kraw argeq 1 ksel
3237ret 2
3238end
3239if not rdin
3240x = flush 2 mbig len mbig
3241ret 2
3242end
3243if gmixed
3244lgt mprofile
3245lgb 10
3246ret done 1
3247end
3248if not gbindings
3249lgt mbind
3250lgb 10
3251ret done 1
3252end
3253nw = ulong 0
3254nn = ulong 0
3255blocks = ulong 0
3256waso = false
3257s = ulong 0
3258while lt s get ibl 0 bound 8388608
3259c = get ib s
3260if eq c 87
3261nw = add nw 1
3262if lt gnfirst s get ibl 0
3263nn = add nn 1
3264end
3265end
3266if eq c 79
3267if not waso
3268blocks = add blocks 1
3269end
3270waso = true
3271else
3272waso = false
3273end
3274if eq c 88
3275lgt mlayout
3276lgb 10
3277ret done 1
3278end
3279if argeq 1 kraw
3280if or eq c 78 eq c 73
3281lgt mlayout
3282lgb 10
3283ret done 1
3284end
3285end
3286s = add eol s 1
3287end
3288if argeq 1 kraw
3289if or gt blocks 1 and gt nw 0 eq blocks 0
3290lgt mlayout
3291lgb 10
3292ret done 1
3293end
3294else
3295if ne nn nw
3296lgt munbound
3297lgb 10
3298ret done 1
3299end
3300end
3301s = ulong 0
3302while lt s get ibl 0 bound 8388608
3303if eq get ib s 87
3304lcopy s
3305s = gend s
3306continue
3307end
3308if ne get ib s 79
3309emr s eol s
3310emb 10
3311end
3312s = add eol s 1
3313end
3314ret done 0
3315end
3316note ---- bind: descriptors are derived only from this import's fresh alias, never old hashed cache.
3317fn seqok to bool
3318n = get avl 1
3319if or eq n 0 gt n 19
3320ret false
3321end
3322if eq ava 1 0 48
3323ret false
3324end
3325for i ulong n bound 19
3326if not isdig ava 1 i
3327ret false
3328end
3329end
3330ret true
3331end
3332fn bhash s ulong to bool
3333b = new uchar 4096 0
3334ctx = new ulong 40 0
3335d = new uchar 32 0
3336n = get avl 2
3337for i ulong n bound 512
3338put pth i ava 2 i
3339end
3340a = add s 2
3341z = tabat a eol s
3342for i ulong sub z a bound 64
3343put pth add n i get ib add a i
3344end
3345n = add n sub z a
3346for i ulong len ktxt
3347put pth add n i get ktxt i
3348end
3349n = add n len ktxt
3350fd = fopen pth 0 n 559104 0
3351if lt fd 0
3352ret false
3353end
3354ok = rregular int fd
3355sha256_init ctx
3356total = ulong 0
3357k = long 1
3358while and ok gt k 0 bound 262145
3359k = read int fd b 0 4096
3360if lt k 0
3361ok = false
3362end
3363if gt k 0
3364total = add total ulong k
3365if gt total 262144
3366ok = false
3367else
3368sha256_update ctx view part b 0 ulong k
3369end
3370end
3371end
3372x = fclose int fd
3373if or not ok eq total 0
3374ret false
3375end
3376sha256_final ctx d
3377for i ulong 32
3378put dg i get d i
3379end
3380ret true
3381end
3382fn bemit s ulong to void
3383em kbr
3384a = add s 2
3385z = tabat a eol s
3386emr a z
3387emb 9
3388ema 1
3389emb 10
3390em kbt
3391emr a z
3392emb 9
3393if bhash s
3394for i ulong 32
3395c = get dg i
3396emb get khex ulong shr c 4
3397emb get khex ulong and c 15
3398end
3399tbr a z
3400tbb 9
3401for i ulong 32
3402c = get dg i
3403tbb get khex ulong shr c 4
3404tbb get khex ulong and c 15
3405end
3406tbb 10
3407else
3408emb 45
3409end
3410emb 10
3411end
3412fn bmode to int
3413if not seqok
3414ret 2
3415end
3416if eq get avl 2 0
3417ret 2
3418end
3419if ne ava 2 sub get avl 2 1 47
3420ret 2
3421end
3422if not rdin
3423ret 2
3424end
3425s = ulong 0
3426active = get ibl 0
3427while lt s get ibl 0 bound 8388608
3428e = eol s
3429c = get ib s
3430if or eq c 87 eq c 79
3431if lt active get ibl 0
3432bemit active
3433active = get ibl 0
3434end
3435end
3436if eq c 87
3437a = add s 2
3438if not slugok a tabat a e
3439ret 2
3440end
3441active = s
3442end
3443if not or eq c 82 eq c 84
3444emr s e
3445emb 10
3446end
3447s = add e 1
3448end
3449if lt active get ibl 0
3450bemit active
3451end
3452ret done 0
3453end
3454note identify: single Zenodo record jflat lines; the first well-formed creator ORCID iD
3455fn imode to int
3456if not rdin
3457ret 2
3458end
3459put hs 0 0
3460put he 0 get ibl 0
3461put hpl 0 0
3462l = hfind 0 kmeta kcor 1000000
3463while lt l get he 0 bound 8388608
3464a = vala l
3465b = valb l
3466if eq sub b a 19
3467for i ulong 19
3468put av add 1024 i get ib add a i
3469end
3470put avl 2 19
3471if orcok 2
3472emr a b
3473emb 10
3474ret done 0
3475end
3476end
3477l = hfind add eol l 1 kmeta kcor 1000000
3478end
3479ret 1
3480end
3481note compact runs while the caller holds ADD/queue.lock, shared with forged. It copies only the
3482note unread tail, fsyncs, writes cursor 0, then atomically replaces queue. A crash before rename can
3483note replay already-handled requests (safe, idempotent imports), but cannot skip an unread request.
3484fn qpaths to ulong
3485n = get avl 1
3486for i ulong n bound 512
3487put pth i ava 1 i
3488end
3489for i ulong len kq
3490put pth add n i get kq i
3491end
3492n = add n len kq
3493put pthl 0 n
3494for i ulong n bound 1100
3495put pt2 i get pth i
3496end
3497for i ulong len kxt
3498put pt2 add n i get kxt i
3499end
3500ret n
3501end
3502fn qtail src int dest int off ulong to bool
3503b = new uchar 4096 0
3504k = long 1
3505o = off
3506while gt k 0 bound 9223372036854775807
3507k = pread src b 0 4096 long o
3508if lt k 0
3509ret false
3510end
3511if gt k 0
3512if not flush dest b ulong k
3513ret false
3514end
3515o = add o ulong k
3516end
3517end
3518ret true
3519end
3520fn cmode to int
3521if eq get avl 1 0
3522ret 2
3523end
3524if ne ava 1 sub get avl 1 1 47
3525ret 2
3526end
3527off = getoff
3528if eq off 0
3529ret 0
3530end
3531n = qpaths
3532fd = fopen pth 0 n 557056 0
3533if lt fd 0
3534ret 1
3535end
3536m = add n len kxt
3537x = unlink pt2 0 m
3538tmp = fopen pt2 0 m 557249 384
3539if lt tmp 0
3540x = fclose int fd
3541ret 1
3542end
3543ok = qtail int fd int tmp off
3544x = fsync int tmp
3545if ne x 0
3546ok = false
3547end
3548x = fclose int fd
3549x = fclose int tmp
3550if not ok
3551ret 1
3552end
3553if not putoff 0
3554ret 1
3555end
3556n = qpaths
3557if not pmove n add n len kxt
3558ret 1
3559end
3560ret 0
3561end
3562note Validate configured policy IO even with an empty queue/catalog. Absence is distinct from error.
3563fn pmode to int
3564ldarg 1
3565loaded = rload
3566if ne get rerr 0 0
3567qrefuse mpolicy
3568ret done 1
3569end
3570ldarg 2
3571loaded = rload
3572if ne get rerr 0 0
3573qrefuse mpolicy
3574ret done 1
3575end
3576ret 0
3577end
3578fn main to int
3579c = argcnt
3580if lt c 2
3581ret 2
3582end
3583for k ulong 7
3584if lt add k 1 ulong c
3585x = arg add k 1
3586end
3587end
3588if argeq 1 kmode11
3589if ne c 3
3590ret 2
3591end
3592shl1
3593ret lmode
3594end
3595if argeq 1 kmode10
3596if ne c 4
3597ret 2
3598end
3599shl1
3600ret bmode
3601end
3602if argeq 1 kmode1
3603if ne c 6
3604ret 2
3605end
3606ret zmode
3607end
3608if argeq 1 kmode2
3609if not or eq c 6 or eq c 7 eq c 8
3610ret 2
3611end
3612ret rmode
3613end
3614if argeq 1 kmode9
3615if ne c 4
3616ret 2
3617end
3618shl1
3619ret pmode
3620end
3621if argeq 1 kmode8
3622if ne c 4
3623ret 2
3624end
3625shl1
3626ret cmode
3627end
3628if argeq 1 kmode7
3629ret imode
3630end
3631if argeq 1 kmode3
3632ret tmode
3633end
3634if argeq 1 kmode4
3635if ne c 7
3636ret 2
3637end
3638shl1
3639ret qmode
3640end
3641if argeq 1 kmode5
3642if ne c 4
3643ret 2
3644end
3645shl1
3646ret gmode
3647end
3648if argeq 1 kmode6
3649if ne c 5
3650ret 2
3651end
3652shl1
3653ret smode
3654end
3655ret 2
3656end