interplane.Get Omega
Read in your language

interplane.io

Source of interplane.io: a Rust generator that renders the page from the protocol repository's public record, deployed hourly from the Spark.

Brought by drakestapleton

branch main Branches Tags History

interplane.io / native / site.om

6639 lines · 117591 bytes Raw Blame History
1text trcgate "translation-check"
2text trcsp "headers-check"
3note SPDX-License-Identifier: AGPL-3.0-or-later
4note native/site.om: builder and policy checker for interplane.io and hopbot.org, in seeded Omega.
5note Composed after native/lib/sha2.om with a leading om2 line (scripts/build-native.sh).
6note site build OUT HOPOUT release mode: assemble, check and write both sites; both directories must be new
7note site verify OUT HOPOUT re-check written output: the exact file set this source builds, every digest,
8note policy, local links, fragments, and the receipts chain from the output bytes
9note site build --test-data OUT HOPOUT, site verify --test-data OUT HOPOUT
10note the only mode that accepts made-up data; every page carries a TEST DATA banner
11note and each output root a TEST-DATA file, which the publisher refuses
12note site contrast print the button colour arithmetic from public/style.css
13note Run from the repository root. Exit 0 pass, 1 refused, 2 usage. A trap (exit 101..114) is also a refusal.
14note Inputs: content/routes.txt names every page and file. A page is a front-matter block, a line
15note of three dashes, then HTML that is placed in the site layout. Placeholders are {{name}},
16note {{#flag}}..{{/flag}} (kept when the flag is set) and {{^flag}}..{{/flag}} (kept when it is not).
17note Optional inputs: content/hop.release.txt (the Hop page and the hopbot.org output) and
18note content/receipts/ledger.tsv with content/receipts/payload/<sha256>.txt (the receipts page).
19note content/hop.copy.txt holds one line, "describes <commit>": the Hop commit the Hop page wording was
20note written against. A release build refuses Hop data whose commit is another one.
21note content/live.txt holds one line, "map yes" or "map no". Absent or no: the flag map stays unset
22note and every link to the forge map is left out.
23note Required input: content/papers.snapshot (the papers page, papers.json and papers.bib), written
24note by scripts/fetch-papers.sh. Optional: content/papers.sources (source links on Interplane).
25note Optional: page routes under /zh-CN/ (Simplified Chinese twins of English routes), placed in
26note content/_layout.zh-CN.html and content/_layout-hopbot.zh-CN.html; see "Simplified Chinese pages".
27note This is a bounded policy checker for reviewed sources. It is not an HTML sanitizer.
28
29const TOP ulong 0
30const OBN ulong 1
31const NV ulong 2
32const NR ulong 3
33const PBL ulong 4
34const R0L ulong 5
35const R1L ulong 6
36const FHOP ulong 7
37const FRC ulong 8
38const SITE ulong 9
39const LCHK ulong 10
40const FLEN ulong 11
41const NREC ulong 12
42const CXO ulong 13
43const CXL ulong 14
44const MANL ulong 15
45const NFILE ulong 16
46const NPAGE ulong 17
47const L0O ulong 18
48const L0N ulong 19
49const L1O ulong 20
50const L1N ulong 21
51const NVB ulong 22
52const TOPB ulong 23
53const SIOK ulong 24
54const OWNO ulong 25
55const OWNL ulong 26
56const LDGO ulong 28
57const LDGN ulong 29
58const NFLD ulong 30
59const BADC ulong 31
60const PERM ulong 32
61const TESTD ulong 33
62const DRY ulong 34
63const FINS ulong 35
64const PAYO ulong 36
65const MNO ulong 37
66const MNL ulong 38
67const DRO ulong 39
68const DRL ulong 40
69const NSD ulong 41
70const PST ulong 42
71const PNR ulong 43
72const PDECL ulong 44
73const PFO ulong 45
74const POO ulong 46
75const PNRESP ulong 47
76const PHE ulong 48
77const PSO ulong 49
78const PSHA ulong 50
79const PATT ulong 51
80const PNSRC ulong 52
81const MEMSZ ulong 12582912
82const OBSZ ulong 4194304
83const FCAP ulong 2097153
84const RTCAP ulong 500
85
86global mem uchar 12582912
87global obuf uchar 4194304
88global st ulong 64
89global vars ulong 2048
90global rt ulong 4096
91global rcs ulong 4096
92global fb ulong 32
93global pb uchar 2048
94global sy uchar 1024
95global hx uchar 64
96global ph uchar 64
97global man uchar 524288
98global root0 uchar 512
99global root1 uchar 512
100global lum ulong 256
101global arg uchar 64
102global dbuf uchar 4096
103global nst ulong 256
104global pr ulong 2048
105
106text tusage "usage: site build [--test-data] OUT HOPOUT | site verify [--test-data] OUT HOPOUT | site contrast\n"
107text ctestd "--test-data"
108text ktestd "test_data"
109text ftestd "TEST-DATA"
110text ttestd "TEST DATA. This directory was built with --test-data. Its Hop values and receipts may be made up. Never publish it.\n"
111text fhins "content/hop.install.sh"
112text fhcopy "content/hop.copy.txt"
113text tdescr "describes "
114text erhcopy "content/hop.copy.txt must hold one line, describes COMMIT, and COMMIT must be the commit in content/hop.release.txt: the Hop page wording is written against one Hop commit"
115text mhcopy "hop copy: the page wording is pinned to the release commit\n"
116text mhcopyt "hop copy: not compared with the release commit in TEST DATA mode\n"
117text khins "hop_install"
118text nins "hop.install_sha256"
119text hkins "install_sha256"
120text kinst "install"
121text fhead "content/receipts/head.txt"
122text fvsh "content/receipts-page/verify.sh"
123text vrvsh "receipts.verify_sh"
124text vhok1 "hop_ok1"
125text vhok2 "hop_ok2"
126text vhok3 "hop_ok3"
127text vhok4 "hop_ok4"
128text vhbadge "hop_badge"
129text vhdbase "hop.download_base"
130text pfix "fixture"
131text pfixu "FIXTURE"
132text pfixd "fixture-desk"
133text hip "https://interplane.io/"
134text hhb "https://hopbot.org/"
135text ttm "(TM)"
136text ptml "(tm)"
137text vtmeta "meta"
138text vtlink "link"
139text vtbr "br"
140text vtimg "img"
141text vthr "hr"
142text vtwbr "wbr"
143text vtinput "input"
144text vtsource "source"
145text vtcol "col"
146text erhins "content/hop.install.sh and the keys install_sha256 and install_base go together, the SHA-256 of the file must equal install_sha256, and zip_name must be Hop-VERSION.zip, the name the installer fetches from install_base"
147text finsout "install.sh"
148text rinst "/install.sh"
149text thopp "Hop-"
150text xzipx ".zip"
151text errel "release mode refuses made-up data: a repeated-digit fingerprint, the word fixture, or an address outside interplane.io and hopbot.org. Test data needs --test-data"
152text erhead "content/receipts/head.txt must hold the head of the ledger: 64 hex digits and a line feed"
153text erset "output differs from what this source builds: a file is missing, extra, changed or not a plain file"
154text ernest "HTML elements are not properly nested or closed"
155text mtest "TEST DATA mode: every page carries the banner and each output root a TEST-DATA file; never publish this output\n"
156text minsno "install: content/hop.install.sh is absent; the terminal install section and /install.sh are omitted\n"
157text minsyes "install: content/hop.install.sh matches install_sha256; hopbot.org gets /install.sh, copied as it is (the one file the content scan skips)\n"
158text mbadge "badge: rows backed by a receipt that holds the same value: "
159text mbadgeof " of 3\n"
160text tfail "site: refused: "
161text tnl "\n"
162text tin " in: "
163text tnear " near: "
164text tsp " "
165text tslash "/"
166text tindex "index.html"
167text cbuild "build"
168text cverify "verify"
169text ccontr "contrast"
170
171text erread "missing, empty, oversized or unreadable file"
172text erwrite "output write failed"
173text erdir "output directory must be new and its parent must exist"
174text erarg "invalid output path"
175text erfull "input does not fit the builder memory"
176text erbig "generated output is too large"
177text erpath "path is too long"
178text ervars "too many placeholders"
179text ertag "placeholder is not closed"
180text erunk "unknown placeholder"
181text erblock "conditional block is not closed"
182text erdeep "placeholders nest too deeply"
183text erfront "page needs a front-matter block ending with a line of three dashes"
184text erhtml "incomplete HTML document, title or local stylesheet"
185text ermark "malformed or forbidden markup (script, style block, frame, object or animation)"
186text erattr "forbidden or malformed attribute (inline style, event handler, srcset or similar)"
187text erurl "forbidden URL: outside resources, plain http and unsafe local paths are refused"
188text erlink "local link target is missing from the output"
189text erfrag "link fragment has no matching id in its target"
190text ercss "forbidden CSS: outside resource, import, escape, or a colour outside the root tokens"
191text ertext "control byte or non-ASCII byte in a site text file"
192text eremail "email address in site output"
193text erpriv "private host name or path in site output"
194text erdash "em dash, en dash, numeric character reference or registered-mark entity"
195text ersuper "the phrase is allowed only in the one sentence that says SI does not mean it"
196text ertm "the first Sovereign Intelligence on a page needs the trade mark sign, and never a registered mark"
197text erroute "content/routes.txt has a malformed line"
198text erdupr "content/routes.txt names the same address on the same site twice"
199text erfullr "content/routes.txt has more rows than the route table holds (RTCAP 500); raise RTCAP and size rt to 8 times it"
200text eryard "content/yard.snapshot.tsv has a malformed line"
201text erhop "content/hop.release.txt has a missing, unknown or malformed key"
202text erlive "content/live.txt takes exactly one line, map yes or map no"
203text erhopr "receipt_seqs names a record that the receipts ledger does not hold"
204text erledg "receipts ledger does not verify"
205text erpayl "receipts payload file is missing or its SHA-256 does not equal its name"
206text ercon "button colour contrast is below 4.5 to 1, or a button token pair is missing"
207text erman "output file differs from the manifest"
208text errobot "robots.txt for interplane.io differs from the pinned crawl rules"
209
210text tdoctype "<!doctype html>"
211text thtmlo "<html"
212text thtmle "</html>"
213text theade "</head>"
214text tbodyo "<body"
215text tbodye "</body>"
216text ttitleo "<title>"
217text ttitlee "</title>"
218text tstylea "href=\"/public/style.css\""
219text trelst "stylesheet"
220text tgscript "script"
221text tgiframe "iframe"
222text tgobject "object"
223text tgembed "embed"
224text tgapplet "applet"
225text tgframe "frame"
226text tgfrset "frameset"
227text tgbase "base"
228text tgstyle "style"
229text tgforgn "foreignobject"
230text tganim "animate"
231text tganimt "animatetransform"
232text tganimm "animatemotion"
233text tgset "set"
234text tgform "form"
235text tga "a"
236text tglink "link"
237text tasrc "src"
238text taposter "poster"
239text tabackg "background"
240text tahref "href"
241text taxhref "xlink:href"
242text tasrcset "srcset"
243text tasrcdoc "srcdoc"
244text tahttpeq "http-equiv"
245text taaction "action"
246text taformac "formaction"
247text taping "ping"
248text tahidden "hidden"
249text taopen "open"
250text tachk "checked"
251text tareq "required"
252text tadown "download"
253text tadis "disabled"
254text thttps "https://"
255text tbase0 "https://interplane.io/"
256text tbase1 "https://hopbot.org/"
257text tcmo "<!--"
258text tcme "-->"
259
260text cimport "@import"
261text curl "url("
262text cimgset "image-set("
263text cproto "//"
264text chttp "http:"
265text cjs "javascript:"
266text cmoz "-moz-binding"
267text cexpr "expression("
268text cbehav "behavior:"
269text crgb "rgb("
270text crgba "rgba("
271text chsl "hsl("
272text chsla "hsla("
273text croot ":root{"
274text cface "@font-face{"
275text cbtn "--btn-"
276text cink "-ink:#"
277text csbg "-bg"
278text cshov "-hover"
279text cspress "-press"
280
281text pmailto "mailto:"
282text phome "/home/"
283text pusers "/users/"
284text pvarwww "/var/www"
285text ptmp "/tmp/"
286text prootd "/root/"
287text ptilde "~/"
288text ptsnet ".ts.net"
289text plocalh "localhost"
290text ploop "127.0.0.1"
291text pcgnat "100.64."
292text plan "192.168."
293text ptail "tail987627"
294text pspark "spark-b87b"
295text pfile "file://"
296text pmdash "&mdash;"
297text pndash "&ndash;"
298text pnumref "&#"
299text preg "&reg;"
300text psup1 "super intelligence"
301text psup2 "superintelligence"
302text psup3 "super-intelligence"
303text psupok "sovereign intelligence&trade;, not "
304text psi "sovereign intelligence"
305text psireg "sovereign intelligence(r)"
306text ptrade "&trade;"
307
308text froutes "content/routes.txt"
309text flay0 "content/_layout.html"
310text flay1 "content/_layout-hopbot.html"
311text fyard "content/yard.snapshot.tsv"
312text fhop "content/hop.release.txt"
313text flive "content/live.txt"
314text kmap "map"
315text lmapyes "map yes"
316text lmapno "map no"
317text fledger "content/receipts/ledger.tsv"
318text fpayd "content/receipts/payload/"
319text fcss "public/style.css"
320text ftxt ".txt"
321text frobots "robots.txt"
322text fsitemap "sitemap.xml"
323text fmanif "manifest.sha256"
324text fledout "receipts/ledger.tsv"
325text fpayout "receipts/payload/"
326
327text kpage "page"
328text kcss "css"
329text ksvg "svg"
330text kraw "raw"
331text kmain "main"
332text khopbot "hopbot"
333text khop "hop"
334text krcpt "receipts"
335text kasof "asof"
336text kowner "owner"
337
338text vtitle "title"
339text vcanon "canonical"
340text vroute "route"
341text vmain "main"
342text vip "ip"
343text vipurl "https://interplane.io"
344text vone "1"
345text vismain "is_main"
346text vishop "is_hopbot"
347text vyrows "yard.rows"
348text vycount "yard.count"
349text vyasof "yard.asof"
350text vysha "yard.sha256"
351text vrrows "receipts.rows"
352text vrcount "receipts.count"
353text vrhead "receipts.head"
354text vrlast "receipts.last_payload"
355text vrlseq "receipts.last_seq"
356text vhoppre "hop."
357text vhrepro "hop_repro"
358text vhverif "hop_verify"
359text vhbase "hop.install_base"
360text vhbased "https://hopbot.org"
361text vhr1 "hop.r1"
362text vhr2 "hop.r2"
363text vhr3 "hop.r3"
364text vhr4 "hop.r4"
365text vhshort "hop.commit_short"
366
367text hkver "version"
368text hkcommit "commit"
369text hkrid "rid"
370text hkzip "zip_name"
371text hkzsha "zip_sha256"
372text hkesha "exe_sha256"
373text hkbuilt "built"
374text hkmacos "macos"
375text hkdl "download_url"
376text hksrc "source_url"
377text hkrepro "reproducible"
378text hkcheck "checked_utc"
379text hkseqs "receipt_seqs"
380text hkverif "hop_verify"
381text hkbase "install_base"
382text tyes "yes"
383text tno "no"
384text tgenesis "GENESIS"
385
386text hamp "&amp;"
387text hlt "&lt;"
388text hgt "&gt;"
389text hquot "&quot;"
390text y1 "<li class=\"yard-row\"><a class=\"yard-name\" href=\"https://interplane.io/"
391text y2 "\">"
392text y4 "</a><span class=\"yard-head mono\">head "
393text y5 "</span><span class=\"yard-date\">recorded "
394text y6 "</span></li>\n"
395text r1 "<tr id=\"r"
396text r2 "\"><td data-label=\"Record\">"
397text r3 "</td><td data-label=\"Time (UTC)\">"
398text r4 "</td><td data-label=\"Kind\">"
399text r5 "</td><td data-label=\"Who\">"
400text r6 "</td><td data-label=\"What\">"
401text r7 "</td><td data-label=\"Evidence file\"><a class=\"mono\" href=\"/receipts/payload/"
402text r8 ".txt\">"
403text r9 "</a></td></tr>\n"
404text s1 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"
405text s2 " <url><loc>"
406text s3 "</loc></url>\n"
407text s4 "</urlset>\n"
408
409note ---- retired Chinese copies, and texts shared with the translation unit
410text tzhb "/zh"
411text erzh "translated copies are retired: a route under /zh-, /zh/ or /zh is refused; readers translate pages with their own tools (see /translate/)"
412text erlang "a page needs <html lang=\"en\">"
413text hlen "<html lang=\"en\">"
414text zhead "</head>"
415text zfoot "</div></footer>"
416text zen "en"
417text probots "ad930287db6907604886f6bd7bbd00511b1ee4e8255916c562151eb6f33a2b23"
418
419text mhopno "hop: content/hop.release.txt is absent; the /hop/ page and the hopbot.org output are omitted\n"
420text mhopyes "hop: release data found; building /hop/ and the hopbot.org output\n"
421text mrcno "receipts: content/receipts/ledger.tsv is absent; the /receipts/ page and its links are omitted\n"
422text mrcyes "receipts: ledger verifies; records "
423text mmapno "map: content/live.txt does not say map yes; every link to the forge map is left out\n"
424text mmapyes "map: content/live.txt says map yes; the links to the forge map are built\n"
425text mrchead " head "
426text myard "yard: public projects "
427text mysha " snapshot sha256 "
428text mbuilt0 "built interplane.io: pages "
429text mbuilt1 "built hopbot.org: pages "
430text mfiles " files "
431text mmsha " manifest sha256 "
432text mbpass "BUILD PASS: assembled, checked, written and re-read\n"
433text mvpass "VERIFY PASS: the output is exactly the file set this source builds; digests, policy, links, fragments and the receipts chain hold\n"
434text mver0 "verified interplane.io: files "
435text mver1 "verified hopbot.org: files "
436text mc1 "contrast "
437text mc2 " on "
438text mc3 "\n channels 0..255: background "
439text mc4 ", text "
440text mc5 "\n linear value x 1e9 (table from the WCAG 2.1 sRGB formula): background "
441text mc6 "\n luminance x 1e13 = 2126 R + 7152 G + 722 B: background "
442text mc7 "\n ratio = (lighter + 0.05) / (darker + 0.05) = "
443text mc8 " (rounded down), needed 4.50: "
444text mcpass "PASS\n"
445text mcfail "FAIL\n"
446text mcsum "contrast pairs checked: "
447text tdot "."
448text thash "#"
449text tcomma ", "
450text ktpl "tpl"
451text rcontrib "/contribute/"
452text pperm "publishing is permanent"
453text erperm "the contribute page must exist and carry the notice: Publishing is permanent"
454text vpages "pages"
455text vdesc "description"
456text fllms "llms.txt"
457text promptdir "/agents/prompts/"
458text erprompt "agent prompt must be one nonempty line of plain text followed by a line feed"
459text lexplore "explore"
460text lexplorej "explore.json"
461text lowner "drakestapleton"
462text lownerp "drakestapleton/"
463text lledger "receipts/ledger.tsv"
464text lpayp "receipts/payload/"
465text pl1 "- ["
466text pl2 "]("
467text pl3 "): "
468text erllms "llms.txt names an interplane.io path that is neither in the built output nor a verified forge route"
469text erllmp "llms.txt does not list every page and data file of the site"
470text tcbrace "}"
471text tbadl "BAD line "
472text nver "hop.version"
473text nrid "hop.rid"
474text nzsha "hop.zip_sha256"
475text nbuilt "hop.built"
476text ndl "hop.download_url"
477text nrepro "hop.reproducible"
478text nseqs "hop.receipt_seqs"
479text xhtml ".html"
480text xsvg ".svg"
481text ncommit "hop.commit"
482text nesha "hop.exe_sha256"
483text nsrc "hop.source_url"
484text nverif "hop.hop_verify"
485text xcss ".css"
486text xotf ".otf"
487text tfonts "/public/fonts/"
488text kdata "data"
489text kfont "font"
490text erfont "a font route must hold an OpenType file: the bytes OTTO first"
491text kpng "png"
492text xpng ".png"
493text tpubl "/public/"
494text erpng "a png route must hold a PNG file: the eight PNG signature bytes first"
495text kgzip "gzip"
496text xgzip ".tar.gz"
497text odloads "omega/downloads/"
498text ergzip "a gzip route must start with a gzip header"
499text odloadsums "omega-3086ed3ca106.sha256"
500text odloadpin "b30366023e11969408948ae21847cffc6739326c626d73670c3f8d79ccd29842"
501text erodload "Omega downloads must match the pinned checksum file and its registered routes"
502text erodextra "Omega download directory must contain only the three pinned release routes"
503text odcommit "3086ed3ca1061b2625a48d175cd5ac990e783655"
504text odhome "/omega/"
505text odtitle "<h2 id=\"downloads\">package details</h2>"
506text odhref "href=\"/omega/downloads/"
507text odend "\" download"
508text odguide "compiler preview and installer for 64-bit arm linux: https://interplane.io/omega/"
509text odkarch "omega.archive"
510text odkinst "omega.installer"
511text odksums "omega.checksums"
512text odkcommit "omega.commit"
513text erodcopy "Omega download page must name its pinned compiler and offer all three release files"
514text erodguide "llms.txt must list the Omega compiler preview and installer"
515text kforge "forge"
516text kdash "-"
517text nzip "hop.zip_name"
518text ncheck "hop.checked_utc"
519text nmacos "hop.macos"
520
521note ---- accessors: one global load per expression keeps every function inside the register pool
522
523fn mg i ulong to uchar
524ret get mem i
525end
526
527fn og i ulong to uchar
528ret get obuf i
529end
530
531fn sg k ulong to ulong
532ret get st k
533end
534
535fn fg k ulong to ulong
536ret get fb k
537end
538
539fn rg k ulong to ulong
540ret get rt k
541end
542
543fn vg k ulong to ulong
544ret get vars k
545end
546
547fn cg k ulong to ulong
548ret get rcs k
549end
550
551note ---- terminal output
552
553fn sayfd fd int t view uchar * to void
554p = ulong 0
555while lt p len t bound 1048576
556k = write fd t p sub len t p
557if le k 0
558exit 1
559end
560p = add p ulong k
561end
562end
563
564fn say t view uchar * to void
565sayfd 1 t
566end
567
568fn sayerr t view uchar * to void
569sayfd 2 t
570end
571
572fn saym off ulong n ulong to void
573p = ulong 0
574while lt p n bound 16777216
575k = write 1 mem add off p sub n p
576if le k 0
577exit 1
578end
579p = add p ulong k
580end
581end
582
583fn sayob off ulong n ulong to void
584p = ulong 0
585while lt p n bound 16777216
586k = write 1 obuf add off p sub n p
587if le k 0
588exit 1
589end
590p = add p ulong k
591end
592end
593
594fn sayhx to void
595k = write 1 hx 0 64
596if ne k 64
597exit 1
598end
599end
600
601fn sayn v ulong to void
602d = new uchar 20 0
603i = ulong 20
604x = v
605if eq x 0
606i = 19
607put d 19 48
608end
609while gt x 0 bound 20
610i = sub i 1
611put d i uchar add 48 rem x 10
612x = div x 10
613end
614k = write 1 d i sub 20 i
615if le k 0
616exit 1
617end
618end
619
620fn die m view uchar * to void
621sayerr tfail
622sayerr m
623sayerr tnl
624n = sg CXL
625if gt n 0
626sayerr tin
627k = write 2 mem sg CXO n
628sayerr tnl
629end
630exit 1
631end
632
633fn dieat m view uchar * pos ulong to void
634sayerr tfail
635sayerr m
636sayerr tnl
637n = sg CXL
638if gt n 0
639sayerr tin
640k = write 2 mem sg CXO n
641sayerr tnl
642end
643sayerr tnear
644lim = sg OBN
645s = pos
646if gt s 24
647s = sub s 24
648else
649s = 0
650end
651e = add pos 72
652if gt e lim
653e = lim
654end
655i = s
656while lt i e bound 128
657c = og i
658if or lt c 32 gt c 126
659c = 32
660end
661put sy sub i s c
662i = add i 1
663end
664if gt e s
665k = write 2 sy 0 sub e s
666end
667sayerr tnl
668exit 1
669end
670
671note ---- path buffer pb
672
673fn pbset t view uchar * to void
674for j ulong len t bound 2048
675put pb j get t j
676end
677put st PBL len t
678end
679
680fn pbadd t view uchar * to void
681n = sg PBL
682if gt add n len t 2000
683die erpath
684end
685for j ulong len t bound 2048
686put pb add n j get t j
687end
688put st PBL add n len t
689end
690
691fn pbaddm off ulong k ulong to void
692n = sg PBL
693if gt add n k 2000
694die erpath
695end
696for j ulong k bound 2048
697put pb add n j mg add off j
698end
699put st PBL add n k
700end
701
702fn pbroot site ulong to void
703note pb = the site's output root, with no trailing slash
704if eq site 0
705n = sg R0L
706for j ulong n bound 512
707put pb j get root0 j
708end
709put st PBL n
710else
711n = sg R1L
712for j ulong n bound 512
713put pb j get root1 j
714end
715put st PBL n
716end
717end
718
719fn rootlen site ulong to ulong
720if eq site 0
721ret sg R0L
722end
723ret sg R1L
724end
725
726note ---- files
727
728fn isfile to bool
729fd = fopen pb 0 sg PBL 34816 0
730if lt fd 0
731ret false
732end
733r = fclose int fd
734ret true
735end
736
737fn slurp to ulong
738note loads the regular file named by pb into the arena; returns its offset, st FLEN its length.
739note readlnk gives -22 for a path that is not a symbolic link; 34816 is O_RDONLY, O_NONBLOCK and
740note O_NOFOLLOW on Linux AArch64, so a final-component link or a FIFO cannot stand in for a file.
741p = readlnk pb 0 sg PBL sy 0 1024
742if ne p -22
743die erread
744end
745fd = fopen pb 0 sg PBL 34816 0
746if lt fd 0
747die erread
748end
749base = sg TOP
750if gt add base FCAP MEMSZ
751die erfull
752end
753tot = ulong 0
754k = long 1
755while gt k 0 bound 4194304
756if ge tot FCAP
757break
758end
759k = read int fd mem add base tot sub FCAP tot
760if gt k 0
761tot = add tot ulong k
762end
763end
764r = fclose int fd
765if lt k 0
766die erread
767end
768if or eq tot 0 ge tot FCAP
769die erread
770end
771put st TOP add base tot
772put st FLEN tot
773ret base
774end
775
776fn wrraw to void
777note writes obuf to the new file named by pb. 193 is O_WRONLY, O_CREAT and O_EXCL.
778fd = fopen pb 0 sg PBL 193 420
779if lt fd 0
780die erwrite
781end
782p = ulong 0
783n = sg OBN
784while lt p n bound 4194304
785k = write int fd obuf p sub n p
786if le k 0
787r = fclose int fd
788die erwrite
789end
790p = add p ulong k
791end
792r = fsync int fd
793if ne r 0
794die erwrite
795end
796r = fclose int fd
797if ne r 0
798die erwrite
799end
800end
801
802fn mkpar site ulong to void
803note creates every directory above the file named by pb, below the site root
804n = sg PBL
805i = add rootlen site 1
806while lt i n bound 2048
807if eq get pb i 47
808k = makedir pb 0 i 493
809if lt k 0
810if ne k -17
811die erdir
812end
813end
814end
815i = add i 1
816end
817end
818
819note ---- output buffer obuf
820
821fn ob c uchar to void
822n = sg OBN
823if ge n OBSZ
824die erbig
825end
826put obuf n c
827put st OBN add n 1
828end
829
830fn ot t view uchar * to void
831for j ulong len t bound 1048576
832ob get t j
833end
834end
835
836fn om off ulong n ulong to void
837for j ulong n bound 16777216
838ob mg add off j
839end
840end
841
842fn oesc off ulong n ulong to void
843for j ulong n bound 16777216
844c = mg add off j
845if eq c 38
846ot hamp
847else
848if eq c 60
849ot hlt
850else
851if eq c 62
852ot hgt
853else
854if eq c 34
855ot hquot
856else
857ob c
858end
859end
860end
861end
862end
863end
864
865fn onum v ulong to void
866d = new uchar 20 0
867i = ulong 20
868x = v
869if eq x 0
870i = 19
871put d 19 48
872end
873while gt x 0 bound 20
874i = sub i 1
875put d i uchar add 48 rem x 10
876x = div x 10
877end
878while lt i 20 bound 20
879ob get d i
880i = add i 1
881end
882end
883
884fn ohx to void
885for j ulong 64
886ob get hx j
887end
888end
889
890fn stash to ulong
891note moves obuf into the arena; returns its offset, st FLEN its length
892base = sg TOP
893n = sg OBN
894if gt add base n MEMSZ
895die erfull
896end
897for j ulong n bound 16777216
898put mem add base j og j
899end
900put st TOP add base n
901put st FLEN n
902put st OBN 0
903ret base
904end
905
906fn keep t view uchar * to ulong
907base = sg TOP
908if gt add base len t MEMSZ
909die erfull
910end
911for j ulong len t bound 1048576
912put mem add base j get t j
913end
914put st TOP add base len t
915ret base
916end
917
918note ---- SHA-256 (native/lib/sha2.om) of arena or output bytes, as 64 hex digits in hx
919
920fn hexc v ulong to uchar
921if lt v 10
922ret uchar add 48 v
923end
924ret uchar add 87 v
925end
926
927fn hxput d view uchar 32 to void
928for j ulong 32
929b = ulong get d j
930put hx mul j 2 hexc shr b 4
931put hx add mul j 2 1 hexc and b 15
932end
933end
934
935fn hashm off ulong n ulong to void
936c = new ulong 40 0
937t = new uchar 4096 0
938d = new uchar 32 0
939sha256_init c
940done = ulong 0
941while lt done n bound 16777216
942k = sub n done
943if gt k 4096
944k = 4096
945end
946for j ulong k bound 4096
947put t j mg add add off done j
948end
949sha256_update c part t 0 k
950done = add done k
951end
952sha256_final c d
953hxput d
954end
955
956fn hasho to void
957c = new ulong 40 0
958t = new uchar 4096 0
959d = new uchar 32 0
960sha256_init c
961n = sg OBN
962done = ulong 0
963while lt done n bound 16777216
964k = sub n done
965if gt k 4096
966k = 4096
967end
968for j ulong k bound 4096
969put t j og add done j
970end
971sha256_update c part t 0 k
972done = add done k
973end
974sha256_final c d
975hxput d
976end
977
978fn hxkeep to ulong
979note copies hx into the arena; returns its offset (64 bytes)
980base = sg TOP
981if gt add base 64 MEMSZ
982die erfull
983end
984for j ulong 64
985put mem add base j get hx j
986end
987put st TOP add base 64
988ret base
989end
990
991fn hxis off ulong to bool
992note hx equals the 64 arena bytes at off
993for j ulong 64
994if ne get hx j mg add off j
995ret false
996end
997end
998ret true
999end
1000
1001note ---- placeholders
1002
1003fn mcmp a ulong b ulong n ulong to bool
1004for j ulong n bound 16777216
1005if ne mg add a j mg add b j
1006ret false
1007end
1008end
1009ret true
1010end
1011
1012fn mist off ulong n ulong t view uchar * to bool
1013note arena bytes off..off+n equal the text t
1014if ne n len t
1015ret false
1016end
1017for j ulong n bound 1048576
1018if ne mg add off j get t j
1019ret false
1020end
1021end
1022ret true
1023end
1024
1025fn mistf off ulong t view uchar * fold bool to bool
1026note the arena bytes at off start with the text t; fold compares their lower case with t
1027for j ulong len t bound 4096
1028c = mg add off j
1029if fold
1030c = low c
1031end
1032if ne c get t j
1033ret false
1034end
1035end
1036ret true
1037end
1038
1039fn mhas off ulong n ulong t view uchar * fold bool to bool
1040note arena off..off+n holds the text t somewhere
1041pl = len t
1042if gt pl n
1043ret false
1044end
1045last = sub n pl
1046i = ulong 0
1047while le i last bound 4194304
1048if mistf add off i t fold
1049ret true
1050end
1051i = add i 1
1052end
1053ret false
1054end
1055
1056fn mfind off ulong n ulong po ulong pl ulong to bool
1057note arena off..off+n holds the arena bytes po..po+pl somewhere
1058if or eq pl 0 gt pl n
1059ret false
1060end
1061last = sub n pl
1062i = ulong 0
1063while le i last bound 4194304
1064if mcmp add off i po pl
1065ret true
1066end
1067i = add i 1
1068end
1069ret false
1070end
1071
1072fn fewdig vo ulong vl ulong to bool
1073note fewer than six different bytes: a placeholder such as all zeros, not a real fingerprint
1074seen = new uchar 256 0
1075d = ulong 0
1076for j ulong vl bound 128
1077c = ulong mg add vo j
1078if eq get seen c 0
1079put seen c 1
1080d = add d 1
1081end
1082end
1083ret lt d 6
1084end
1085
1086fn setvm ko ulong kl ulong vo ulong vl ulong to void
1087n = sg NV
1088if ge n 512
1089die ervars
1090end
1091b = mul n 4
1092put vars b ko
1093put vars add b 1 kl
1094put vars add b 2 vo
1095put vars add b 3 vl
1096put st NV add n 1
1097end
1098
1099fn setv k view uchar * vo ulong vl ulong to void
1100ko = keep k
1101setvm ko len k vo vl
1102end
1103
1104fn setvt k view uchar * v view uchar * to void
1105vo = keep v
1106setv k vo len v
1107end
1108
1109fn findv off ulong n ulong to ulong
1110note 1 + index of the newest placeholder with this name, 0 when there is none
1111i = sg NV
1112while gt i 0 bound 1024
1113i = sub i 1
1114b = mul i 4
1115if eq vg add b 1 n
1116if mcmp vg b off n
1117ret add i 1
1118end
1119end
1120end
1121ret 0
1122end
1123
1124fn vlook k view uchar * to ulong
1125ko = keep k
1126v = findv ko len k
1127put st TOP ko
1128ret v
1129end
1130
1131fn vset k view uchar * to bool
1132note the placeholder exists and is not empty
1133v = vlook k
1134if eq v 0
1135ret false
1136end
1137ret gt vg add mul sub v 1 4 3 0
1138end
1139
1140fn tagend s ulong lim ulong to ulong
1141i = s
1142while lt add i 1 lim bound 512
1143if gt sub i s 200
1144die ertag
1145end
1146if eq mg i 125
1147if eq mg add i 1 125
1148ret i
1149end
1150end
1151i = add i 1
1152end
1153die ertag
1154ret lim
1155end
1156
1157fn iscl i ulong no ulong nl ulong to bool
1158if ne mg add i 1 123
1159ret false
1160end
1161if ne mg add i 2 47
1162ret false
1163end
1164if not mcmp add i 3 no nl
1165ret false
1166end
1167if ne mg add add i 3 nl 125
1168ret false
1169end
1170if ne mg add add i 4 nl 125
1171ret false
1172end
1173ret true
1174end
1175
1176fn skipto p ulong lim ulong no ulong nl ulong to ulong
1177note first index after the closing tag of block NAME (arena no..no+nl), searching from p
1178i = p
1179need = add nl 5
1180while le add i need lim bound 16777216
1181if eq mg i 123
1182if iscl i no nl
1183ret add i need
1184end
1185end
1186i = add i 1
1187end
1188die erblock
1189ret lim
1190end
1191
1192fn dotag i ulong lim ulong depth ulong to ulong
1193s = add i 2
1194e = tagend s lim
1195k = mg s
1196if eq k 47
1197ret add e 2
1198end
1199if or eq k 35 eq k 94
1200no = add s 1
1201nl = sub e no
1202v = findv no nl
1203have = ulong 0
1204if gt v 0
1205if gt vg add mul sub v 1 4 3 0
1206have = 1
1207end
1208end
1209want = ulong 0
1210if eq k 35
1211want = 1
1212end
1213if eq have want
1214ret add e 2
1215end
1216ret skipto add e 2 lim no nl
1217end
1218v = findv s sub e s
1219if eq v 0
1220put st CXO s
1221put st CXL sub e s
1222die erunk
1223end
1224b = mul sub v 1 4
1225expand vg add b 2 vg add b 3 add depth 1
1226ret add e 2
1227end
1228
1229fn expand off ulong n ulong depth ulong to void
1230if gt depth 6
1231die erdeep
1232end
1233lim = add off n
1234i = off
1235while lt i lim bound 16777216
1236c = mg i
1237tag = false
1238if eq c 123
1239if lt add i 1 lim
1240if eq mg add i 1 123
1241tag = true
1242end
1243end
1244end
1245if tag
1246i = dotag i lim depth
1247else
1248ob c
1249i = add i 1
1250end
1251end
1252end
1253
1254note ---- small parsers over the arena
1255
1256fn eol i ulong lim ulong to ulong
1257j = i
1258while lt j lim bound 16777216
1259if eq mg j 10
1260ret j
1261end
1262j = add j 1
1263end
1264ret lim
1265end
1266
1267fn split s ulong e ulong sep uchar to ulong
1268note field k of arena s..e is fb 2k .. fb 2k+1; returns the field count (at most 16)
1269n = ulong 0
1270a = s
1271i = s
1272while le i e bound 16777216
1273stop = false
1274if eq i e
1275stop = true
1276else
1277if eq mg i sep
1278stop = true
1279end
1280end
1281if stop
1282if ge n 16
1283ret 99
1284end
1285put fb mul n 2 a
1286put fb add mul n 2 1 i
1287n = add n 1
1288a = add i 1
1289end
1290i = add i 1
1291end
1292ret n
1293end
1294
1295fn alnum c uchar to bool
1296if and ge c 48 le c 57
1297ret true
1298end
1299if and ge c 65 le c 90
1300ret true
1301end
1302ret and ge c 97 le c 122
1303end
1304
1305fn inset c uchar mode ulong to bool
1306note sets: 1 name (A-Z a-z 0-9 . _ -), 2 lowercase hex, 3 time (0-9 T Z : -), 4 Radicle id
1307note (alphanumeric and colon), 5 digits, 6 printable ASCII without markup or placeholder bytes,
1308note 7 URL bytes, 8 digits and spaces
1309dig = and ge c 48 le c 57
1310if eq mode 1
1311if alnum c
1312ret true
1313end
1314ret or eq c 46 or eq c 95 eq c 45
1315end
1316if eq mode 2
1317if dig
1318ret true
1319end
1320ret and ge c 97 le c 102
1321end
1322if eq mode 3
1323if dig
1324ret true
1325end
1326ret or eq c 84 or eq c 90 or eq c 58 eq c 45
1327end
1328if eq mode 4
1329if alnum c
1330ret true
1331end
1332ret eq c 58
1333end
1334if eq mode 5
1335ret dig
1336end
1337if eq mode 6
1338if or lt c 32 gt c 126
1339ret false
1340end
1341if or eq c 60 or eq c 62 eq c 38
1342ret false
1343end
1344if or eq c 34 or eq c 123 eq c 125
1345ret false
1346end
1347ret true
1348end
1349if eq mode 7
1350if alnum c
1351ret true
1352end
1353if or eq c 46 or eq c 95 or eq c 45 eq c 47
1354ret true
1355end
1356ret or eq c 58 or eq c 126 or eq c 63 or eq c 61 eq c 43
1357end
1358if eq mode 8
1359ret or dig eq c 32
1360end
1361ret false
1362end
1363
1364fn okset s ulong e ulong mode ulong to bool
1365note every byte of the nonempty arena range s..e is in the set (see inset)
1366if ge s e
1367ret false
1368end
1369i = s
1370while lt i e bound 16777216
1371if not inset mg i mode
1372ret false
1373end
1374i = add i 1
1375end
1376ret true
1377end
1378
1379fn mnum s ulong e ulong to ulong
1380note the decimal number in arena s..e; 0 when it is not 1 to 9 digits or has a leading zero
1381if ge s e
1382ret 0
1383end
1384if gt sub e s 9
1385ret 0
1386end
1387if eq mg s 48
1388ret 0
1389end
1390v = ulong 0
1391i = s
1392while lt i e bound 16
1393c = mg i
1394if or lt c 48 gt c 57
1395ret 0
1396end
1397v = add mul v 10 ulong sub c 48
1398i = add i 1
1399end
1400ret v
1401end
1402
1403note ---- text policy on obuf
1404
1405fn low c uchar to uchar
1406if and ge c 65 le c 90
1407ret add c 32
1408end
1409ret c
1410end
1411
1412fn space c uchar to bool
1413ret or eq c 32 or eq c 9 or eq c 10 eq c 13
1414end
1415
1416fn namechar c uchar to bool
1417d = low c
1418ret or and ge d 97 le d 122 or and ge d 48 le d 57 or eq d 45 eq d 58
1419end
1420
1421fn omatch pos ulong pat view uchar * to bool
1422if gt add pos len pat sg OBN
1423ret false
1424end
1425for j ulong len pat bound 4096
1426if ne low og add pos j get pat j
1427ret false
1428end
1429end
1430ret true
1431end
1432
1433fn otoken pos ulong size ulong pat view uchar * to bool
1434if ne size len pat
1435ret false
1436end
1437ret omatch pos pat
1438end
1439
1440fn ofind from ulong pat view uchar * to ulong
1441n = sg OBN
1442j = from
1443while lt j n bound 16777216
1444if omatch j pat
1445ret j
1446end
1447j = add j 1
1448end
1449ret n
1450end
1451
1452fn ohas pat view uchar * to bool
1453ret lt ofind 0 pat sg OBN
1454end
1455
1456fn emailc c uchar to bool
1457d = low c
1458ret or and ge d 97 le d 122 or and ge d 48 le d 57 or eq d 46 or eq d 95 or eq d 43 eq d 45
1459end
1460
1461fn labelc c uchar to bool
1462d = low c
1463ret or and ge d 97 le d 122 or and ge d 48 le d 57 eq d 45
1464end
1465
1466fn isemail i ulong to bool
1467note obuf i is an at sign with a name byte before it and "label.letter" after it
1468n = sg OBN
1469if eq i 0
1470ret false
1471end
1472if not emailc og sub i 1
1473ret false
1474end
1475j = add i 1
1476while lt j n bound 16777216
1477if not labelc og j
1478break
1479end
1480j = add j 1
1481end
1482if eq j add i 1
1483ret false
1484end
1485if ge add j 1 n
1486ret false
1487end
1488if ne og j 46
1489ret false
1490end
1491d = low og add j 1
1492ret and ge d 97 le d 122
1493end
1494
1495fn polpath i ulong c uchar to void
1496if eq c 47
1497if or omatch i phome or omatch i pusers or omatch i pvarwww or omatch i ptmp omatch i prootd
1498dieat erpriv i
1499end
1500end
1501if eq c 126
1502if omatch i ptilde
1503dieat erpriv i
1504end
1505end
1506if eq c 46
1507if omatch i ptsnet
1508dieat erpriv i
1509end
1510end
1511if eq c 108
1512if omatch i plocalh
1513dieat erpriv i
1514end
1515end
1516if eq c 49
1517if or omatch i ploop or omatch i pcgnat omatch i plan
1518dieat erpriv i
1519end
1520end
1521if eq c 116
1522if omatch i ptail
1523dieat erpriv i
1524end
1525end
1526if eq c 102
1527if omatch i pfile
1528dieat erpriv i
1529end
1530end
1531end
1532
1533fn polword i ulong c uchar to void
1534if eq c 64
1535if isemail i
1536dieat eremail i
1537end
1538end
1539if eq c 109
1540if omatch i pmailto
1541dieat eremail i
1542end
1543end
1544if eq c 38
1545if or omatch i pmdash or omatch i pndash or omatch i pnumref omatch i preg
1546dieat erdash i
1547end
1548end
1549if eq c 115
1550if omatch i pspark
1551dieat erpriv i
1552end
1553if omatch i psireg
1554dieat ertm i
1555end
1556if or omatch i psup1 or omatch i psup2 omatch i psup3
1557ok = false
1558if ge i len psupok
1559if omatch sub i len psupok psupok
1560if eq sg SIOK 0
1561ok = true
1562end
1563end
1564end
1565if not ok
1566dieat ersuper i
1567end
1568put st SIOK 1
1569end
1570end
1571end
1572
1573fn polscan strict bool to void
1574note strict: printable ASCII
1575put st SIOK 0
1576n = sg OBN
1577i = ulong 0
1578while lt i n bound 16777216
1579c = og i
1580k = ulong 1
1581if strict
1582if lt c 32
1583if not space c
1584dieat ertext i
1585end
1586end
1587if gt c 126
1588dieat ertext i
1589end
1590end
1591if eq k 1
1592d = low c
1593polpath i d
1594polword i d
1595end
1596i = add i k
1597end
1598end
1599
1600fn oeq i ulong t view uchar * to bool
1601note obuf i.. starts with the text t, compared exactly
1602if gt add i len t sg OBN
1603ret false
1604end
1605for j ulong len t bound 4096
1606if ne og add i j get t j
1607ret false
1608end
1609end
1610ret true
1611end
1612
1613fn ohasx t view uchar * to bool
1614note obuf holds the text t, compared exactly
1615n = sg OBN
1616i = ulong 0
1617while lt i n bound 16777216
1618if oeq i t
1619ret true
1620end
1621i = add i 1
1622end
1623ret false
1624end
1625
1626fn chklang to void
1627note a page declares <html lang="en">
1628if not ohasx hlen
1629die erlang
1630end
1631end
1632
1633note ---- markup checks on obuf
1634
1635fn badtag pos ulong size ulong to bool
1636if or otoken pos size tgscript or otoken pos size tgiframe or otoken pos size tgobject otoken pos size tgembed
1637ret true
1638end
1639if or otoken pos size tgapplet or otoken pos size tgframe or otoken pos size tgfrset otoken pos size tgbase
1640ret true
1641end
1642if or otoken pos size tgstyle or otoken pos size tgforgn or otoken pos size tganim otoken pos size tgset
1643ret true
1644end
1645if or otoken pos size tganimt or otoken pos size tganimm otoken pos size tgform
1646ret true
1647end
1648ret false
1649end
1650
1651fn badattr pos ulong size ulong to bool
1652if ge size 2
1653if and eq low og pos 111 eq low og add pos 1 110
1654ret true
1655end
1656end
1657if or otoken pos size tgstyle or otoken pos size tasrcset or otoken pos size tasrcdoc otoken pos size tahttpeq
1658ret true
1659end
1660if or otoken pos size taaction or otoken pos size taformac otoken pos size taping
1661ret true
1662end
1663ret false
1664end
1665
1666fn boolattr pos ulong size ulong to bool
1667if or otoken pos size tahidden or otoken pos size taopen otoken pos size tachk
1668ret true
1669end
1670ret or otoken pos size tareq or otoken pos size tadown otoken pos size tadis
1671end
1672
1673fn skipsp pos ulong to ulong
1674n = sg OBN
1675i = pos
1676while lt i n bound 16777216
1677if not space og i
1678break
1679end
1680i = add i 1
1681end
1682ret i
1683end
1684
1685fn fragat i ulong fo ulong fl ulong to bool
1686note arena i.. is id="FRAG" where FRAG is obuf fo..fo+fl
1687if ne mg add i 1 100
1688ret false
1689end
1690if ne mg add i 2 61
1691ret false
1692end
1693if ne mg add i 3 34
1694ret false
1695end
1696for j ulong fl bound 1024
1697if ne mg add add i 4 j og add fo j
1698ret false
1699end
1700end
1701ret eq mg add add i 4 fl 34
1702end
1703
1704fn fragmem base ulong n ulong fo ulong fl ulong to bool
1705need = add fl 5
1706i = base
1707lim = add base n
1708while le add i need lim bound 16777216
1709if eq mg i 105
1710if fragat i fo fl
1711ret true
1712end
1713end
1714i = add i 1
1715end
1716ret false
1717end
1718
1719fn fragself fo ulong fl ulong pos ulong to void
1720note the page in obuf must hold id="FRAG"
1721if eq fl 0
1722ret
1723end
1724base = sg TOP
1725n = sg OBN
1726if gt add base n MEMSZ
1727die erfull
1728end
1729for j ulong n bound 16777216
1730put mem add base j og j
1731end
1732if not fragmem base n fo fl
1733dieat erfrag pos
1734end
1735end
1736
1737fn fragfile fo ulong fl ulong pos ulong to void
1738note the output file named by pb must hold id="FRAG"
1739if eq fl 0
1740ret
1741end
1742mark = sg TOP
1743base = slurp
1744ok = fragmem base sg FLEN fo fl
1745put st TOP mark
1746if not ok
1747dieat erfrag pos
1748end
1749end
1750
1751fn urlpath pos ulong size ulong to ulong
1752note appends the path part of the local URL to pb (after the site root); returns its length
1753pbroot sg SITE
1754n = sg PBL
1755cnt = ulong 0
1756while lt cnt size bound 1024
1757c = og add pos cnt
1758if or eq c 35 eq c 63
1759break
1760end
1761if or le c 32 or eq c 92 or eq c 38 or eq c 37 eq c 58
1762dieat erurl pos
1763end
1764if eq c 46
1765if lt add cnt 1 size
1766if eq og add add pos cnt 1 46
1767dieat erurl pos
1768end
1769end
1770end
1771put pb add n cnt c
1772cnt = add cnt 1
1773end
1774put st PBL add n cnt
1775if eq get pb sub add n cnt 1 47
1776pbadd tindex
1777end
1778ret cnt
1779end
1780
1781fn linkchk pos ulong size ulong cnt ulong to void
1782p = readlnk pb 0 sg PBL sy 0 1024
1783if ne p -22
1784dieat erlink pos
1785end
1786fd = fopen pb 0 sg PBL 34816 0
1787if lt fd 0
1788dieat erlink pos
1789end
1790r = fclose int fd
1791if lt cnt size
1792if eq og add pos cnt 35
1793fragfile add add pos cnt 1 sub sub size cnt 1 pos
1794end
1795end
1796end
1797
1798fn localurl pos ulong size ulong to void
1799c = og pos
1800if eq c 35
1801if eq sg LCHK 1
1802fragself add pos 1 sub size 1 pos
1803end
1804ret
1805end
1806if ne c 47
1807dieat erurl pos
1808end
1809if gt size 1
1810if eq og add pos 1 47
1811dieat erurl pos
1812end
1813end
1814cnt = urlpath pos size
1815if eq sg LCHK 1
1816linkchk pos size cnt
1817end
1818end
1819
1820fn checkurl pos ulong size ulong ext bool to void
1821if or eq size 0 gt size 768
1822dieat erurl pos
1823end
1824if ext
1825if omatch pos thttps
1826if le size len thttps
1827dieat erurl pos
1828end
1829ret
1830end
1831end
1832localurl pos size
1833end
1834
1835fn ownbase pos ulong to bool
1836note the value starts with the current site's own address
1837if eq sg SITE 0
1838ret omatch pos tbase0
1839end
1840ret omatch pos tbase1
1841end
1842
1843fn attrurl start ulong size ulong as ulong az ulong to void
1844note resource attributes take local targets only
1845if or otoken as az tasrc otoken as az taposter
1846checkurl start size false
1847end
1848if or otoken as az tabackg otoken as az taxhref
1849checkurl start size false
1850end
1851end
1852
1853fn hrefurl start ulong size ulong tp ulong tz ulong to void
1854note a link may leave the site; a link element may name only this site; anything else is local
1855ext = otoken tp tz tga
1856if otoken tp tz tglink
1857ext = ownbase start
1858end
1859checkurl start size ext
1860end
1861
1862fn attrval pos ulong as ulong az ulong tp ulong tz ulong to ulong
1863i = skipsp pos
1864n = sg OBN
1865if ge i n
1866dieat erattr pos
1867end
1868if ne og i 61
1869if boolattr as az
1870ret pos
1871end
1872dieat erattr as
1873end
1874i = skipsp add i 1
1875if ge i n
1876dieat erattr as
1877end
1878q = og i
1879if not or eq q 34 eq q 39
1880dieat erattr as
1881end
1882start = add i 1
1883i = start
1884while lt i n bound 16777216
1885if eq og i q
1886break
1887end
1888if eq og i 60
1889dieat erattr as
1890end
1891i = add i 1
1892end
1893if ge i n
1894dieat erattr as
1895end
1896size = sub i start
1897attrurl start size as az
1898if otoken as az tahref
1899hrefurl start size tp tz
1900end
1901ret add i 1
1902end
1903
1904fn starttag pos ulong to ulong
1905n = sg OBN
1906i = pos
1907while lt i n bound 16777216
1908if not namechar og i
1909break
1910end
1911i = add i 1
1912end
1913sz = sub i pos
1914if eq sz 0
1915dieat ermark pos
1916end
1917if badtag pos sz
1918dieat ermark pos
1919end
1920while lt i n bound 16777216
1921c = og i
1922if eq c 62
1923ret add i 1
1924end
1925if eq c 47
1926i = add i 1
1927if lt i n
1928if eq og i 62
1929ret add i 1
1930end
1931end
1932dieat ermark pos
1933end
1934if not space c
1935dieat erattr i
1936end
1937i = skipsp i
1938if ge i n
1939dieat ermark pos
1940end
1941c2 = og i
1942if or eq c2 62 eq c2 47
1943continue
1944end
1945as = i
1946while lt i n bound 16777216
1947if not namechar og i
1948break
1949end
1950i = add i 1
1951end
1952az = sub i as
1953if eq az 0
1954dieat erattr as
1955end
1956if badattr as az
1957dieat erattr as
1958end
1959i = attrval i as az pos sz
1960end
1961dieat ermark pos
1962ret i
1963end
1964
1965fn endtag pos ulong to ulong
1966n = sg OBN
1967i = pos
1968while lt i n bound 16777216
1969if not namechar og i
1970break
1971end
1972i = add i 1
1973end
1974if eq i pos
1975dieat ermark pos
1976end
1977if badtag pos sub i pos
1978dieat ermark pos
1979end
1980i = skipsp i
1981if ge i n
1982dieat ermark pos
1983end
1984if ne og i 62
1985dieat ermark pos
1986end
1987ret add i 1
1988end
1989
1990fn chkhead to void
1991if not and ohas tdoctype and ohas thtmlo and ohas thtmle and ohas theade and ohas tbodyo ohas tbodye
1992die erhtml
1993end
1994if not and ohas ttitleo ohas ttitlee
1995die erhtml
1996end
1997if le ofind 0 ttitlee add ofind 0 ttitleo len ttitleo
1998die erhtml
1999end
2000if not and ohas trelst ohas tstylea
2001die erhtml
2002end
2003note every Sovereign Intelligence in the document, head and body, carries the trade mark sign
2004n = sg OBN
2005p = ofind 0 psi
2006while lt p n bound 100000
2007if not omatch add p len psi ptrade
2008dieat ertm p
2009end
2010p = ofind add p 1 psi
2011end
2012end
2013
2014fn tmtext to void
2015note llms.txt is plain text: every Sovereign Intelligence is followed by (TM)
2016n = sg OBN
2017p = ofind 0 psi
2018while lt p n bound 100000
2019if not omatch add p len psi ptml
2020dieat ertm p
2021end
2022p = ofind add p 1 psi
2023end
2024end
2025
2026fn isvoid pos ulong sz ulong to bool
2027note an HTML element that never has an end tag
2028if or otoken pos sz vtmeta or otoken pos sz vtlink or otoken pos sz vtbr otoken pos sz vtimg
2029ret true
2030end
2031if or otoken pos sz vthr or otoken pos sz vtwbr or otoken pos sz vtinput or otoken pos sz vtsource otoken pos sz vtcol
2032ret true
2033end
2034ret false
2035end
2036
2037fn namelen pos ulong to ulong
2038n = sg OBN
2039i = pos
2040while lt i n bound 16777216
2041if not namechar og i
2042break
2043end
2044i = add i 1
2045end
2046ret sub i pos
2047end
2048
2049fn nopen pos ulong after ulong to void
2050note a start tag at obuf pos that ended at after: push it unless it is void or closes itself
2051sz = namelen pos
2052if isvoid pos sz
2053ret
2054end
2055if ge after 2
2056if eq og sub after 2 47
2057ret
2058end
2059end
2060d = sg NSD
2061if ge d 120
2062dieat ernest pos
2063end
2064put nst mul d 2 pos
2065put nst add mul d 2 1 sz
2066put st NSD add d 1
2067end
2068
2069fn nclose pos ulong to void
2070note an end tag at obuf pos: it must close the element opened last
2071sz = namelen pos
2072d = sg NSD
2073if eq d 0
2074dieat ernest pos
2075end
2076d = sub d 1
2077op = get nst mul d 2
2078if ne get nst add mul d 2 1 sz
2079dieat ernest pos
2080end
2081for j ulong sz bound 64
2082if ne low og add op j low og add pos j
2083dieat ernest pos
2084end
2085end
2086put st NSD d
2087end
2088
2089fn chkmark html bool to void
2090if html
2091chkhead
2092end
2093put st NSD 0
2094n = sg OBN
2095i = ulong 0
2096while lt i n bound 16777216
2097if eq og i 60
2098if omatch i tcmo
2099i = ofind i tcme
2100if ge i n
2101die ermark
2102end
2103i = add i len tcme
2104continue
2105end
2106if omatch i tdoctype
2107if not html
2108dieat ermark i
2109end
2110i = add i len tdoctype
2111continue
2112end
2113i = add i 1
2114if ge i n
2115die ermark
2116end
2117if eq og i 47
2118t0 = add i 1
2119i = endtag t0
2120nclose t0
2121else
2122t1 = i
2123i = starttag t1
2124nopen t1 i
2125end
2126else
2127i = add i 1
2128end
2129end
2130if ne sg NSD 0
2131d = sub sg NSD 1
2132dieat ernest get nst mul d 2
2133end
2134end
2135
2136fn cssban pat view uchar * to void
2137p = ofind 0 pat
2138if lt p sg OBN
2139dieat ercss p
2140end
2141end
2142
2143fn cssbehav to void
2144note the old behavior property is refused; scroll-behavior is an ordinary property
2145n = sg OBN
2146p = ofind 0 cbehav
2147while lt p n bound 100000
2148if eq p 0
2149dieat ercss p
2150end
2151if ne og sub p 1 45
2152dieat ercss p
2153end
2154p = ofind add p 1 cbehav
2155end
2156end
2157
2158fn chkcss to void
2159cssban cimport
2160cssban chttp
2161cssban cjs
2162cssban cmoz
2163cssban cexpr
2164cssban cimgset
2165cssban cproto
2166cssurl
2167cssban crgb
2168cssban crgba
2169cssban chsl
2170cssban chsla
2171cssbehav
2172if not omatch 0 croot
2173die ercss
2174end
2175n = sg OBN
2176seen = false
2177for j ulong n bound 16777216
2178c = og j
2179if eq c 92
2180dieat ercss j
2181end
2182if eq c 125
2183seen = true
2184end
2185if eq c 35
2186if seen
2187dieat ercss j
2188end
2189end
2190end
2191end
2192
2193fn obeqm p ulong e ulong mo ulong ml ulong to bool
2194note obuf p..e equals the arena bytes mo..mo+ml
2195if ne sub e p ml
2196ret false
2197end
2198for j ulong ml bound 4096
2199if ne og add p j mg add mo j
2200ret false
2201end
2202end
2203ret true
2204end
2205
2206fn urlstop c uchar to bool
2207note a byte that ends a URL in plain text
2208if or le c 32 or eq c 41 or eq c 62 eq c 60
2209ret true
2210end
2211ret or eq c 34 or eq c 39 or eq c 35 or eq c 63 eq c 44
2212end
2213
2214fn isroute p ulong e ulong to bool
2215note obuf p..e is the route (without its leading slash) of an enabled interplane.io entry
2216nr = sg NR
2217r = ulong 0
2218while lt r nr bound RTCAP
2219b = mul r 8
2220if eq rg add b 1 0
2221if enabled r
2222if obeqm p e add rg add b 2 1 sub rg add b 3 1
2223ret true
2224end
2225end
2226end
2227r = add r 1
2228end
2229ret false
2230end
2231
2232fn llmspath p ulong e ulong to bool
2233if eq p e
2234ret true
2235end
2236if isroute p e
2237ret true
2238end
2239size = sub e p
2240if or otoken p size fsitemap or otoken p size lexplore or otoken p size lexplorej otoken p size lowner
2241ret true
2242end
2243if omatch p lownerp
2244ret true
2245end
2246if eq sg FRC 1
2247if or otoken p size lledger omatch p lpayp
2248ret true
2249end
2250end
2251ret false
2252end
2253
2254fn llmspage r ulong to bool
2255note the address of page route r is in obuf, ended by a URL stop byte
2256b = mul r 8
2257ro = add rg add b 2 1
2258rl = sub rg add b 3 1
2259n = sg OBN
2260i = ofind 0 tbase0
2261while lt i n bound 100000
2262p = add i len tbase0
2263e = add p rl
2264if le e n
2265if obeqm p e ro rl
2266if eq e n
2267ret true
2268end
2269if urlstop og e
2270ret true
2271end
2272end
2273end
2274i = ofind add i 1 tbase0
2275end
2276ret false
2277end
2278
2279fn llmschk to void
2280note every interplane.io address in obuf is real, and every enabled page is listed
2281n = sg OBN
2282i = ofind 0 tbase0
2283while lt i n bound 100000
2284p = add i len tbase0
2285e = p
2286while lt e n bound 4096
2287if urlstop og e
2288break
2289end
2290e = add e 1
2291end
2292if not llmspath p e
2293dieat erllms i
2294end
2295i = ofind add i 1 tbase0
2296end
2297nr = sg NR
2298r = ulong 0
2299while lt r nr bound RTCAP
2300b = mul r 8
2301if and or eq rg b 1 eq rg b 7 eq rg add b 1 0
2302if enabled r
2303if not llmspage r
2304put st CXO rg add b 2
2305put st CXL rg add b 3
2306die erllmp
2307end
2308end
2309end
2310r = add r 1
2311end
2312end
2313
2314fn lint kind ulong to void
2315if eq kind 5
2316polscan false
2317ret
2318end
2319if eq kind 8
2320chkfont
2321ret
2322end
2323if eq kind 9
2324chkpng
2325ret
2326end
2327if eq kind 11
2328if lt sg OBN 18
2329die ergzip
2330end
2331if not and eq og 0 31 and eq og 1 139 eq og 2 8
2332die ergzip
2333end
2334ret
2335end
2336polscan true
2337if eq kind 1
2338chkmark true
2339chklang
2340trcheck
2341end
2342if eq kind 2
2343chkcss
2344end
2345if eq kind 3
2346chkmark false
2347end
2348if eq kind 6
2349llmschk
2350tmtext
2351end
2352end
2353
2354fn chkfont to void
2355note a font route holds an OpenType file with CFF outlines: it starts with the tag OTTO
2356if lt sg OBN 12
2357die erfont
2358end
2359if not and and eq og 0 79 eq og 1 84 and eq og 2 84 eq og 3 79
2360die erfont
2361end
2362end
2363
2364fn chkpng to void
2365note a png route holds a PNG image: it starts with the signature 137 80 78 71 13 10 26 10
2366if lt sg OBN 8
2367die erpng
2368end
2369if not and and eq og 0 137 eq og 1 80 and eq og 2 78 eq og 3 71
2370die erpng
2371end
2372if not and and eq og 4 13 eq og 5 10 and eq og 6 26 eq og 7 10
2373die erpng
2374end
2375end
2376
2377fn isfont p ulong e ulong to bool
2378note obuf p..e is the route (without its leading slash) of an enabled font route of the site in work
2379nr = sg NR
2380site = sg SITE
2381r = ulong 0
2382while lt r nr bound RTCAP
2383b = mul r 8
2384if and eq rg b 8 eq rg add b 1 site
2385if enabled r
2386if obeqm p e add rg add b 2 1 sub rg add b 3 1
2387ret true
2388end
2389end
2390end
2391r = add r 1
2392end
2393ret false
2394end
2395
2396fn cssurl to void
2397note url() may name only a font route of the same site: url(/public/fonts/NAME.otf)
2398n = sg OBN
2399p = ofind 0 curl
2400while lt p n bound 100000
2401q = add p len curl
2402e = q
2403while lt e n bound 512
2404if not inset og e 7
2405break
2406end
2407e = add e 1
2408end
2409if ge e n
2410dieat ercss p
2411end
2412if ne og e 41
2413dieat ercss p
2414end
2415if not omatch q tfonts
2416dieat ercss p
2417end
2418if not isfont add q 1 e
2419dieat ercss p
2420end
2421p = ofind add p 1 curl
2422end
2423end
2424
2425note ---- button contrast (WCAG 2.1 relative luminance), integer arithmetic over a Wolfram table
2426
2427fn hexv c uchar to ulong
2428d = low c
2429if and ge d 48 le d 57
2430ret ulong sub d 48
2431end
2432if and ge d 97 le d 102
2433ret ulong sub d 87
2434end
2435ret 99
2436end
2437
2438fn ishex6 pos ulong to bool
2439if gt add pos 6 sg OBN
2440ret false
2441end
2442for j ulong 6
2443if eq hexv og add pos j 99
2444ret false
2445end
2446end
2447ret true
2448end
2449
2450fn chan pos ulong to ulong
2451ret add mul hexv og pos 16 hexv og add pos 1
2452end
2453
2454fn lumat pos ulong to ulong
2455note relative luminance x 1e13 of the colour whose six hex digits start at obuf pos
2456r = get lum chan pos
2457g = get lum chan add pos 2
2458b = get lum chan add pos 4
2459ret add add mul 2126 r mul 7152 g mul 722 b
2460end
2461
2462fn obcmp a ulong b ulong n ulong to bool
2463for j ulong n bound 4096
2464if ne og add a j og add b j
2465ret false
2466end
2467end
2468ret true
2469end
2470
2471fn inkval i ulong pl ulong rbe ulong to ulong
2472note position of the six hex digits of the -ink token whose prefix is obuf i..i+pl; 0 when missing
2473j = ulong 0
2474while le add add j pl 12 rbe bound 1048576
2475if obcmp j i pl
2476if omatch add j pl cink
2477if ishex6 add add j pl len cink
2478ret add add j pl len cink
2479end
2480end
2481end
2482j = add j 1
2483end
2484ret 0
2485end
2486
2487fn saychan pos ulong to void
2488sayn chan pos
2489say tsp
2490sayn chan add pos 2
2491say tsp
2492sayn chan add pos 4
2493end
2494
2495fn saylin pos ulong to void
2496sayn get lum chan pos
2497say tsp
2498sayn get lum chan add pos 2
2499say tsp
2500sayn get lum chan add pos 4
2501end
2502
2503fn showpair i ulong e ulong bp ulong ip ulong to bool
2504note prints the arithmetic for one background token (name obuf i..e, digits at bp) and its text colour
2505lb = lumat bp
2506li = lumat ip
2507hi = add lb 500000000000
2508lo = add li 500000000000
2509if lt hi lo
2510t = hi
2511hi = lo
2512lo = t
2513end
2514say mc1
2515sayob i sub e i
2516say tsp
2517say thash
2518sayob bp 6
2519say mc2
2520say thash
2521sayob ip 6
2522say mc3
2523saychan bp
2524say mc4
2525saychan ip
2526say mc5
2527saylin bp
2528say mc4
2529saylin ip
2530say mc6
2531sayn lb
2532say mc4
2533sayn li
2534say mc7
2535q = div mul hi 100 lo
2536sayn div q 100
2537say tdot
2538sayn div rem q 100 10
2539sayn rem q 10
2540say mc8
2541pass = ge mul hi 2 mul lo 9
2542if pass
2543say mcpass
2544else
2545say mcfail
2546end
2547ret pass
2548end
2549
2550fn btnrole i ulong e ulong to ulong
2551note length of the role suffix of the token name obuf i..e: 3 for -bg, 6 for -hover, else 0
2552if gt sub e i 9
2553if omatch sub e 3 csbg
2554ret 3
2555end
2556if omatch sub e 6 cshov
2557ret 6
2558end
2559if omatch sub e 6 cspress
2560ret 6
2561end
2562end
2563ret 0
2564end
2565
2566fn contrast to void
2567note obuf holds the stylesheet; every --btn-NAME-bg, --btn-NAME-hover and --btn-NAME-press is checked against --btn-NAME-ink
2568rbe = ofind 0 tcbrace
2569pairs = ulong 0
2570bad = ulong 0
2571i = len croot
2572while lt i rbe bound 1048576
2573if omatch i cbtn
2574p = og sub i 1
2575if or eq p 59 eq p 123
2576e = i
2577while lt e rbe bound 256
2578if eq og e 58
2579break
2580end
2581e = add e 1
2582end
2583role = btnrole i e
2584if gt role 0
2585ip = inkval i sub sub e i role rbe
2586ok = false
2587if gt ip 0
2588if eq og add e 1 35
2589if ishex6 add e 2
2590t = og add e 8
2591if or eq t 59 eq t 125
2592ok = showpair i e add e 2 ip
2593end
2594end
2595end
2596end
2597pairs = add pairs 1
2598if not ok
2599bad = add bad 1
2600end
2601end
2602end
2603end
2604i = add i 1
2605end
2606say mcsum
2607sayn pairs
2608say tnl
2609if or eq pairs 0 gt bad 0
2610die ercon
2611end
2612end
2613
2614
2615fn luminit to void
2616put lum 0 0
2617put lum 1 303527
2618put lum 2 607054
2619put lum 3 910581
2620put lum 4 1214108
2621put lum 5 1517635
2622put lum 6 1821162
2623put lum 7 2124689
2624put lum 8 2428216
2625put lum 9 2731743
2626put lum 10 3035270
2627put lum 11 3346536
2628put lum 12 3676507
2629put lum 13 4024717
2630put lum 14 4391442
2631put lum 15 4776953
2632put lum 16 5181517
2633put lum 17 5605392
2634put lum 18 6048833
2635put lum 19 6512091
2636put lum 20 6995410
2637put lum 21 7499032
2638put lum 22 8023193
2639put lum 23 8568126
2640put lum 24 9134059
2641put lum 25 9721217
2642put lum 26 10329823
2643put lum 27 10960094
2644put lum 28 11612245
2645put lum 29 12286488
2646put lum 30 12983032
2647put lum 31 13702083
2648put lum 32 14443844
2649put lum 33 15208514
2650put lum 34 15996293
2651put lum 35 16807376
2652put lum 36 17641954
2653put lum 37 18500220
2654put lum 38 19382361
2655put lum 39 20288563
2656put lum 40 21219010
2657put lum 41 22173885
2658put lum 42 23153366
2659put lum 43 24157632
2660put lum 44 25186860
2661put lum 45 26241222
2662put lum 46 27320892
2663put lum 47 28426040
2664put lum 48 29556834
2665put lum 49 30713444
2666put lum 50 31896033
2667put lum 51 33104767
2668put lum 52 34339807
2669put lum 53 35601315
2670put lum 54 36889450
2671put lum 55 38204372
2672put lum 56 39546235
2673put lum 57 40915197
2674put lum 58 42311411
2675put lum 59 43735029
2676put lum 60 45186204
2677put lum 61 46665086
2678put lum 62 48171824
2679put lum 63 49706566
2680put lum 64 51269458
2681put lum 65 52860647
2682put lum 66 54480276
2683put lum 67 56128490
2684put lum 68 57805430
2685put lum 69 59511238
2686put lum 70 61246054
2687put lum 71 63010018
2688put lum 72 64803267
2689put lum 73 66625939
2690put lum 74 68478170
2691put lum 75 70360096
2692put lum 76 72271851
2693put lum 77 74213568
2694put lum 78 76185381
2695put lum 79 78187422
2696put lum 80 80219820
2697put lum 81 82282707
2698put lum 82 84376212
2699put lum 83 86500462
2700put lum 84 88655586
2701put lum 85 90841711
2702put lum 86 93058963
2703put lum 87 95307467
2704put lum 88 97587347
2705put lum 89 99898728
2706put lum 90 102241733
2707put lum 91 104616484
2708put lum 92 107023103
2709put lum 93 109461711
2710put lum 94 111932428
2711put lum 95 114435374
2712put lum 96 116970668
2713put lum 97 119538428
2714put lum 98 122138772
2715put lum 99 124771818
2716put lum 100 127437680
2717put lum 101 130136477
2718put lum 102 132868322
2719put lum 103 135633330
2720put lum 104 138431615
2721put lum 105 141263291
2722put lum 106 144128471
2723put lum 107 147027266
2724put lum 108 149959790
2725put lum 109 152926152
2726put lum 110 155926464
2727put lum 111 158960835
2728put lum 112 162029376
2729put lum 113 165132195
2730put lum 114 168269400
2731put lum 115 171441101
2732put lum 116 174647404
2733put lum 117 177888416
2734put lum 118 181164244
2735put lum 119 184474995
2736put lum 120 187820772
2737put lum 121 191201683
2738put lum 122 194617830
2739put lum 123 198069320
2740put lum 124 201556254
2741put lum 125 205078736
2742put lum 126 208636870
2743put lum 127 212230757
2744put lum 128 215860500
2745put lum 129 219526200
2746put lum 130 223227957
2747put lum 131 226965874
2748put lum 132 230740049
2749put lum 133 234550582
2750put lum 134 238397574
2751put lum 135 242281122
2752put lum 136 246201327
2753put lum 137 250158285
2754put lum 138 254152094
2755put lum 139 258182853
2756put lum 140 262250658
2757put lum 141 266355605
2758put lum 142 270497791
2759put lum 143 274677312
2760put lum 144 278894263
2761put lum 145 283148740
2762put lum 146 287440838
2763put lum 147 291770650
2764put lum 148 296138271
2765put lum 149 300543794
2766put lum 150 304987314
2767put lum 151 309468923
2768put lum 152 313988713
2769put lum 153 318546778
2770put lum 154 323143209
2771put lum 155 327778098
2772put lum 156 332451536
2773put lum 157 337163615
2774put lum 158 341914425
2775put lum 159 346704056
2776put lum 160 351532600
2777put lum 161 356400144
2778put lum 162 361306780
2779put lum 163 366252596
2780put lum 164 371237680
2781put lum 165 376262123
2782put lum 166 381326011
2783put lum 167 386429434
2784put lum 168 391572478
2785put lum 169 396755231
2786put lum 170 401977780
2787put lum 171 407240212
2788put lum 172 412542613
2789put lum 173 417885071
2790put lum 174 423267670
2791put lum 175 428690497
2792put lum 176 434153636
2793put lum 177 439657174
2794put lum 178 445201195
2795put lum 179 450785783
2796put lum 180 456411023
2797put lum 181 462077000
2798put lum 182 467783796
2799put lum 183 473531496
2800put lum 184 479320183
2801put lum 185 485149940
2802put lum 186 491020850
2803put lum 187 496932995
2804put lum 188 502886458
2805put lum 189 508881321
2806put lum 190 514917665
2807put lum 191 520995573
2808put lum 192 527115126
2809put lum 193 533276404
2810put lum 194 539479489
2811put lum 195 545724461
2812put lum 196 552011402
2813put lum 197 558340390
2814put lum 198 564711506
2815put lum 199 571124829
2816put lum 200 577580440
2817put lum 201 584078418
2818put lum 202 590618841
2819put lum 203 597201788
2820put lum 204 603827339
2821put lum 205 610495571
2822put lum 206 617206562
2823put lum 207 623960392
2824put lum 208 630757136
2825put lum 209 637596874
2826put lum 210 644479682
2827put lum 211 651405637
2828put lum 212 658374817
2829put lum 213 665387298
2830put lum 214 672443157
2831put lum 215 679542470
2832put lum 216 686685312
2833put lum 217 693871761
2834put lum 218 701101892
2835put lum 219 708375780
2836put lum 220 715693501
2837put lum 221 723055129
2838put lum 222 730460740
2839put lum 223 737910409
2840put lum 224 745404210
2841put lum 225 752942217
2842put lum 226 760524505
2843put lum 227 768151147
2844put lum 228 775822218
2845put lum 229 783537792
2846put lum 230 791297940
2847put lum 231 799102738
2848put lum 232 806952258
2849put lum 233 814846572
2850put lum 234 822785754
2851put lum 235 830769877
2852put lum 236 838799012
2853put lum 237 846873232
2854put lum 238 854992608
2855put lum 239 863157213
2856put lum 240 871367119
2857put lum 241 879622397
2858put lum 242 887923118
2859put lum 243 896269353
2860put lum 244 904661174
2861put lum 245 913098652
2862put lum 246 921581856
2863put lum 247 930110858
2864put lum 248 938685728
2865put lum 249 947306537
2866put lum 250 955973353
2867put lum 251 964686248
2868put lum 252 973445290
2869put lum 253 982250550
2870put lum 254 991102097
2871put lum 255 1000000000
2872end
2873
2874fn cssload to void
2875note obuf = public/style.css
2876mark = sg TOP
2877pbset fcss
2878off = slurp
2879put st OBN 0
2880om off sg FLEN
2881put st TOP mark
2882end
2883
2884note ---- the yard: content/yard.snapshot.tsv, a snapshot of the public project registry
2885
2886fn yardrow to void
2887note fb holds name, rid, branch, head, recorded time of one snapshot row; the rid is checked, not printed
2888ot y1
2889om sg OWNO sg OWNL
2890ob 47
2891om fg 0 sub fg 1 fg 0
2892ot y2
2893om fg 0 sub fg 1 fg 0
2894ot y4
2895om fg 6 8
2896ot y5
2897om fg 8 10
2898ot y6
2899end
2900
2901fn yardok to bool
2902if not okset fg 0 fg 1 1
2903ret false
2904end
2905if not okset fg 2 fg 3 4
2906ret false
2907end
2908if not okset fg 4 fg 5 1
2909ret false
2910end
2911if ne sub fg 7 fg 6 40
2912ret false
2913end
2914if not okset fg 6 fg 7 2
2915ret false
2916end
2917if ne sub fg 9 fg 8 20
2918ret false
2919end
2920ret okset fg 8 fg 9 3
2921end
2922
2923fn yardscan off ulong lim ulong to ulong
2924note emits the rows of the snapshot at arena off..lim into obuf and returns how many
2925count = ulong 0
2926i = off
2927while lt i lim bound 100000
2928e = eol i lim
2929if gt e i
2930if ne mg i 35
2931nf = split i e 9
2932if eq nf 2
2933if fbis 0 kasof
2934if not okset fg 2 fg 3 3
2935die eryard
2936end
2937setv vyasof fg 2 sub fg 3 fg 2
2938else
2939if not fbis 0 kowner
2940die eryard
2941end
2942if not okset fg 2 fg 3 1
2943die eryard
2944end
2945put st OWNO fg 2
2946put st OWNL sub fg 3 fg 2
2947end
2948else
2949if or ne nf 5 eq sg OWNL 0
2950die eryard
2951end
2952if not yardok
2953die eryard
2954end
2955yardrow
2956count = add count 1
2957end
2958end
2959end
2960i = add e 1
2961end
2962ret count
2963end
2964
2965fn yard to void
2966pbset fyard
2967put st CXO keep fyard
2968put st CXL len fyard
2969off = slurp
2970n = sg FLEN
2971hashm off n
2972ho = hxkeep
2973setv vysha ho 64
2974say myard
2975lim = add off n
2976put st OBN 0
2977count = yardscan off lim
2978if or eq count 0 not vset vyasof
2979die eryard
2980end
2981ro = stash
2982setv vyrows ro sg FLEN
2983onum count
2984co = stash
2985setv vycount co sg FLEN
2986sayn count
2987say mysha
2988sayhx
2989say tnl
2990end
2991
2992note ---- papers: content/papers.snapshot holds the Zenodo records of one ORCID iD, written by
2993note scripts/fetch-papers.sh; content/papers.sources names the papers whose source is an Interplane
2994note project. Header lines: orcid, fetched, response (one or more, numbered from 1), records. Then one
2995note block per record, newest first, fields in this order: record concept title date type [version]
2996note license creator.. orcid_attached file.. [related..]. The builder reads files only; no network.
2997note Record table pr, 32 slots per record: 0,1 DOI; 2,3 concept DOI; 4,5 title; 6 date; 8,9 type;
2998note 10,11 version (length 0: none); 12,13 licence; 14 ORCID attached; 16,17 block start and end;
2999note 18,19 Interplane source address (length 0: none). Pairs are arena offset and length.
3000
3001text fpapers "content/papers.snapshot"
3002text fpsrc "content/papers.sources"
3003text erpap "content/papers.snapshot has a missing, unknown, out-of-order or malformed line"
3004text erpdoi "content/papers.snapshot: a DOI must be 10.5281/zenodo. followed by digits"
3005text erptit "content/papers.snapshot: a record has no title"
3006text erpesc "content/papers.snapshot: an escaped character that the builder cannot write"
3007text erpord "content/papers.snapshot: records must run newest first, as many as the records line says"
3008text erpsrc "content/papers.sources: a line must name a record of the snapshot, an interplane.io address and the checksum of one of that record's files"
3009text erpdup "content/papers.snapshot: a record DOI or a concept DOI appears twice"
3010text kprec "record"
3011text kpcon "concept"
3012text kptit "title"
3013text kpdate "date"
3014text kptype "type"
3015text kpver "version"
3016text kplic "license"
3017text kpcre "creator"
3018text kpatt "orcid_attached"
3019text kpfile "file"
3020text kprel "related"
3021text kporc "orcid"
3022text kpfet "fetched"
3023text kpresp "response"
3024text kprecs "records"
3025text kpsrc "source"
3026text tnone "none"
3027text tdoipre "10.5281/zenodo."
3028text tmd5 "md5:"
3029text tsha2 "sha256:"
3030text tescom "u03a9"
3031text tomega "Omega"
3032text tmonths "janfebmaraprmayjunjulaugsepoctnovdec"
3033text vprows "papers.rows"
3034text vpcount "papers.count"
3035text vpasof "papers.asof"
3036text vporcid "papers.orcid"
3037text vpsha "papers.sha256"
3038text vpnsrc "papers.sources"
3039text vpjson "papers.json"
3040text vpbib "papers.bib"
3041text mpap "papers: records "
3042text mpsrc " sources "
3043text ph1 "<li class=\"paper\" id=\"zenodo-"
3044text ph2 "\"><h2 class=\"paper-title\">"
3045text ph3 "</h2>\n<p class=\"paper-meta\">"
3046text pmid " &middot; "
3047text pverw "version "
3048text plicw "licence "
3049text ph4 "</p>\n<p class=\"paper-links\"><a href=\"https://doi.org/"
3050text ph5 "\">DOI "
3051text ph6 "</a> <a href=\"https://doi.org/"
3052text ph7 "\">Version history, "
3053text ph7b "</a>"
3054text ph8 " <a href=\""
3055text ph9 "\">Source on Interplane for "
3056text ph10 "</p>\n<ul class=\"paper-files\">\n"
3057text ph11 "</ul></li>\n"
3058text pf1 "<li><span class=\"mono\">"
3059text pf2 "</span> "
3060text pf3 " bytes, <span class=\"mono\">"
3061text pf4 "</span></li>\n"
3062text pomega "&Omega;"
3063text pj1 "{\n \"source\": \"https://zenodo.org/api/records\",\n \"orcid\": \""
3064text pj2 "\",\n \"fetched\": \""
3065text pj3 "\",\n \"snapshot_sha256\": \""
3066text pj4 "\",\n \"responses\": ["
3067text pj5 "],\n \"count\": "
3068text pj6 ",\n \"papers\": [\n"
3069text pj7 "\n ]\n}\n"
3070text pjr1 "{\"page\": "
3071text pjr2 ", \"sha256\": \""
3072text pjr3 "\"}"
3073text jr1 " {\n \"doi\": \""
3074text jr2 "\",\n \"doi_url\": \"https://doi.org/"
3075text jr3 "\",\n \"concept_doi\": \""
3076text jr4 "\",\n \"concept_doi_url\": \"https://doi.org/"
3077text jr5 "\",\n \"title\": \""
3078text jr6 "\",\n \"date\": \""
3079text jr7 "\",\n \"type\": \""
3080text jr8 "\",\n \"version\": "
3081text jr9 ",\n \"license\": \""
3082text jr10 "\",\n \"creators\": ["
3083text jr11 "],\n \"orcid_attached\": "
3084text jr12 ",\n \"source_on_interplane\": "
3085text jr13 ",\n \"files\": [\n"
3086text jr14 "\n ],\n \"related\": ["
3087text jr15 "]\n }"
3088text jrnl "\n "
3089text jsep ",\n"
3090text jnull "null"
3091text jtrue "true"
3092text jfalse "false"
3093text jc1 "{\"name\": \""
3094text jc2 "\", \"orcid\": "
3095text jf1 " {\"name\": \""
3096text jf2 "\", \"size\": "
3097text jf3 ", \"checksum\": \""
3098text jq2 "\"}"
3099text jrl1 "\n {\"relation\": \""
3100text jrl2 "\", \"scheme\": \""
3101text jrl3 "\", \"identifier\": \""
3102text pbh1 "% Papers of ORCID iD "
3103text pbh2 ", copied from Zenodo on "
3104text pbh3 ".\n% Generated from content/papers.snapshot by the interplane.io builder.\n"
3105text bb1 "\n@misc{zenodo"
3106text bb2 ",\n author = {"
3107text bb3 "},\n title = \"{"
3108text bb4 "}\",\n howpublished = {Zenodo},\n year = {"
3109text bb5 "},\n month = "
3110text bb6 ",\n date = {"
3111text bb7 "},\n"
3112text bb8 " version = {"
3113text bb10 " doi = {"
3114text bb11 "},\n url = {https://doi.org/"
3115text bb12 "},\n note = {"
3116text bb13 ". Licence "
3117text bb14 ". Version history: doi "
3118text bb15 "}\n}\n"
3119text band " and "
3120text btilde "textasciitilde{}"
3121text bcaret "textasciicircum{}"
3122
3123fn pg k ulong to ulong
3124ret get pr k
3125end
3126
3127fn kvsp s ulong e ulong to ulong
3128note the first space in arena s..e, or e when there is none
3129i = s
3130while lt i e bound 16777216
3131if eq mg i 32
3132ret i
3133end
3134i = add i 1
3135end
3136ret e
3137end
3138
3139fn vstart k ulong e ulong to ulong
3140note the value after the key that ends at k
3141if lt k e
3142ret add k 1
3143end
3144ret e
3145end
3146
3147fn pkey s ulong n ulong to ulong
3148note record fields 1..11 in their order, header keys 21..24, 0 for an unknown key
3149if mist s n kprec
3150ret 1
3151end
3152if mist s n kpcon
3153ret 2
3154end
3155if mist s n kptit
3156ret 3
3157end
3158if mist s n kpdate
3159ret 4
3160end
3161if mist s n kptype
3162ret 5
3163end
3164if mist s n kpver
3165ret 6
3166end
3167if mist s n kplic
3168ret 7
3169end
3170if mist s n kpcre
3171ret 8
3172end
3173if mist s n kpatt
3174ret 9
3175end
3176if mist s n kpfile
3177ret 10
3178end
3179if mist s n kprel
3180ret 11
3181end
3182if mist s n kporc
3183ret 21
3184end
3185if mist s n kpfet
3186ret 22
3187end
3188if mist s n kpresp
3189ret 23
3190end
3191if mist s n kprecs
3192ret 24
3193end
3194ret 0
3195end
3196
3197fn digok s ulong e ulong max ulong to bool
3198note 1 to max decimal digits without a leading zero
3199if or ge s e gt sub e s max
3200ret false
3201end
3202if and eq mg s 48 gt sub e s 1
3203ret false
3204end
3205ret okset s e 5
3206end
3207
3208fn doiok s ulong e ulong to bool
3209note 10.5281/zenodo. and 1 to 12 digits
3210if le e s
3211ret false
3212end
3213if le sub e s len tdoipre
3214ret false
3215end
3216if not mistf s tdoipre false
3217ret false
3218end
3219ret digok add s len tdoipre e 12
3220end
3221
3222fn orcidok s ulong e ulong to bool
3223note four groups of four digits joined by hyphens; the last character may be X
3224if ne sub e s 19
3225ret false
3226end
3227for i ulong 19
3228c = mg add s i
3229if or eq i 4 or eq i 9 eq i 14
3230if ne c 45
3231ret false
3232end
3233else
3234if or lt c 48 gt c 57
3235if not and eq i 18 eq c 88
3236ret false
3237end
3238end
3239end
3240end
3241ret true
3242end
3243
3244fn ymdok s ulong e ulong to bool
3245note arena s..e is YYYY-MM-DD and names a real day
3246if ne sub e s 10
3247ret false
3248end
3249for i ulong 10
3250c = mg add s i
3251if or eq i 4 eq i 7
3252if ne c 45
3253ret false
3254end
3255else
3256if or lt c 48 gt c 57
3257ret false
3258end
3259end
3260end
3261m = l2 add s 5
3262if or lt m 1 gt m 12
3263ret false
3264end
3265d = l2 add s 8
3266y = add mul l2 s 100 l2 add s 2
3267ret and ge d 1 le d ldim y m
3268end
3269
3270fn sumok s ulong e ulong to bool
3271note md5: and 32 lowercase hex digits, or sha256: and 64
3272n = sub e s
3273if mistf s tmd5 false
3274if eq n add len tmd5 32
3275ret okset add s len tmd5 e 2
3276end
3277ret false
3278end
3279if mistf s tsha2 false
3280if eq n add len tsha2 64
3281ret okset add s len tsha2 e 2
3282end
3283end
3284ret false
3285end
3286
3287fn dgt a ulong c ulong to bool
3288note the date at arena a is later than the date at arena c (both YYYY-MM-DD)
3289for j ulong 10
3290x = mg add a j
3291y = mg add c j
3292if gt x y
3293ret true
3294end
3295if lt x y
3296ret false
3297end
3298end
3299ret false
3300end
3301
3302fn pescok p ulong e ulong to bool
3303note the backslash at arena p starts the one escape the builder can write: u03a9, capital omega
3304if gt add p 6 e
3305ret false
3306end
3307ret mistf add p 1 tescom false
3308end
3309
3310fn pchars s ulong e ulong max ulong to void
3311note a text value: 1 to max printable bytes without markup bytes; a backslash only in a known escape
3312if or ge s e gt sub e s max
3313die erpap
3314end
3315i = s
3316while lt i e bound 16777216
3317c = mg i
3318if eq c 92
3319if not pescok i e
3320die erpesc
3321end
3322i = add i 6
3323else
3324if not inset c 6
3325die erpap
3326end
3327i = add i 1
3328end
3329end
3330end
3331
3332fn presp v ulong e ulong to void
3333note response N sha256:HEX, numbered from 1 in order
3334nf = split v e 32
3335if ne nf 2
3336die erpap
3337end
3338n = mnum fg 0 fg 1
3339if ne n add sg PNRESP 1
3340die erpap
3341end
3342a = fg 2
3343if not mistf a tsha2 false
3344die erpap
3345end
3346if ne sub fg 3 a add len tsha2 64
3347die erpap
3348end
3349if not okset add a len tsha2 fg 3 2
3350die erpap
3351end
3352put st PNRESP n
3353end
3354
3355fn phead f ulong v ulong e ulong to void
3356note a header line, in the order orcid, fetched, response.., records
3357p = sg PST
3358ok = false
3359if and eq f 21 eq p 0
3360ok = true
3361end
3362if and eq f 22 eq p 21
3363ok = true
3364end
3365if and eq f 23 or eq p 22 eq p 23
3366ok = true
3367end
3368if and eq f 24 eq p 23
3369ok = true
3370end
3371if or not ok gt sg PNR 0
3372die erpap
3373end
3374if eq f 21
3375if not orcidok v e
3376die erpap
3377end
3378put st POO v
3379end
3380if eq f 22
3381if not ymdok v e
3382die erpap
3383end
3384put st PFO v
3385end
3386if eq f 23
3387presp v e
3388end
3389if eq f 24
3390n = mnum v e
3391if or eq n 0 gt n 64
3392die erpap
3393end
3394put st PDECL n
3395end
3396put st PST f
3397end
3398
3399fn pclose e ulong to void
3400note ends the open record at arena e: it is complete and not newer than the record before it
3401n = sg PNR
3402p = sg PST
3403if eq p 2
3404die erptit
3405end
3406if lt p 10
3407die erpap
3408end
3409b = mul sub n 1 32
3410put pr add b 17 e
3411if ge n 2
3412if dgt pg add b 6 pg sub add b 6 32
3413die erpord
3414end
3415end
3416end
3417
3418fn pnew s ulong v ulong e ulong to void
3419note a record line: closes the record before it and opens the next slot of pr
3420n = sg PNR
3421if eq n 0
3422if ne sg PST 24
3423die erpap
3424end
3425put st PHE s
3426else
3427pclose s
3428end
3429if ge n 64
3430die erpap
3431end
3432if not doiok v e
3433die erpdoi
3434end
3435if pseen n 0 v sub e v
3436die erpdup
3437end
3438b = mul n 32
3439for j ulong 32
3440put pr add b j 0
3441end
3442put pr b v
3443put pr add b 1 sub e v
3444put pr add b 16 s
3445put st PNR add n 1
3446put st PST 1
3447put st PATT 0
3448end
3449
3450fn pnext p ulong f ulong to bool
3451note field f may follow field p: the next one, version may be left out, and creator, file and
3452note related may repeat
3453if eq f add p 1
3454ret true
3455end
3456if and eq p 5 eq f 7
3457ret true
3458end
3459ret and eq f p or eq f 8 or eq f 10 eq f 11
3460end
3461
3462fn pcreat v ulong e ulong to void
3463note creator ORCID-or-none NAME; the header's ORCID iD on a creator marks the record attached
3464k = kvsp v e
3465if ge k e
3466die erpap
3467end
3468if not mist v sub k v tnone
3469if not orcidok v k
3470die erpap
3471end
3472if mcmp v sg POO 19
3473put st PATT 1
3474end
3475end
3476pchars add k 1 e 200
3477end
3478
3479fn patt v ulong e ulong to void
3480note orcid_attached yes or no, in agreement with the creator lines
3481b = mul sub sg PNR 1 32
3482want = sg PATT
3483if mist v sub e v tyes
3484if ne want 1
3485die erpap
3486end
3487put pr add b 14 1
3488ret
3489end
3490if not mist v sub e v tno
3491die erpap
3492end
3493if ne want 0
3494die erpap
3495end
3496end
3497
3498fn pfiln v ulong e ulong to void
3499note file NAME SIZE CHECKSUM
3500nf = split v e 32
3501if ne nf 3
3502die erpap
3503end
3504if or not okset fg 0 fg 1 1 gt sub fg 1 fg 0 128
3505die erpap
3506end
3507if not digok fg 2 fg 3 12
3508die erpap
3509end
3510if not sumok fg 4 fg 5
3511die erpap
3512end
3513end
3514
3515fn prel v ulong e ulong to void
3516note related RELATION SCHEME IDENTIFIER
3517nf = split v e 32
3518if ne nf 3
3519die erpap
3520end
3521if or not okset fg 0 fg 1 1 gt sub fg 1 fg 0 40
3522die erpap
3523end
3524if or not okset fg 2 fg 3 1 gt sub fg 3 fg 2 20
3525die erpap
3526end
3527if or not okset fg 4 fg 5 7 gt sub fg 5 fg 4 300
3528die erpap
3529end
3530end
3531
3532fn pstore f ulong v ulong e ulong to void
3533note checks the value of field f and records it in the open record
3534b = mul sub sg PNR 1 32
3535if eq f 2
3536if not doiok v e
3537die erpdoi
3538end
3539if pseen sub sg PNR 1 2 v sub e v
3540die erpdup
3541end
3542put pr add b 2 v
3543put pr add b 3 sub e v
3544end
3545if eq f 3
3546if ge v e
3547die erptit
3548end
3549pchars v e 400
3550put pr add b 4 v
3551put pr add b 5 sub e v
3552end
3553if eq f 4
3554if not ymdok v e
3555die erpap
3556end
3557put pr add b 6 v
3558end
3559if eq f 5
3560pchars v e 80
3561put pr add b 8 v
3562put pr add b 9 sub e v
3563end
3564if eq f 6
3565pchars v e 80
3566put pr add b 10 v
3567put pr add b 11 sub e v
3568end
3569if eq f 7
3570if or not okset v e 1 gt sub e v 40
3571die erpap
3572end
3573put pr add b 12 v
3574put pr add b 13 sub e v
3575end
3576if eq f 8
3577pcreat v e
3578end
3579if eq f 9
3580patt v e
3581end
3582if eq f 10
3583pfiln v e
3584end
3585if eq f 11
3586prel v e
3587end
3588end
3589
3590fn pfield f ulong v ulong e ulong to void
3591note a record field: inside a record, in order; a record that skips its title is named as such
3592if eq sg PNR 0
3593die erpap
3594end
3595p = sg PST
3596if and eq p 2 ne f 3
3597die erptit
3598end
3599if not pnext p f
3600die erpap
3601end
3602pstore f v e
3603put st PST f
3604end
3605
3606fn papline s ulong e ulong to void
3607k = kvsp s e
3608f = pkey s sub k s
3609v = vstart k e
3610if eq f 0
3611die erpap
3612end
3613if gt f 20
3614phead f v e
3615ret
3616end
3617if eq f 1
3618pnew s v e
3619ret
3620end
3621pfield f v e
3622end
3623
3624fn pseen n ulong k ulong v ulong l ulong to bool
3625note one of the first n records holds arena v..v+l in slot pair k (0 record DOI, 2 concept DOI)
3626for r ulong n bound 64
3627b = mul r 32
3628if eq pg add b add k 1 l
3629if mcmp pg add b k v l
3630ret true
3631end
3632end
3633end
3634ret false
3635end
3636
3637fn pfind co ulong cl ulong to ulong
3638note 1 + the index of the record whose concept DOI is arena co..co+cl, 0 when there is none
3639n = sg PNR
3640for r ulong n bound 64
3641b = mul r 32
3642if eq pg add b 3 cl
3643if mcmp pg add b 2 co cl
3644ret add r 1
3645end
3646end
3647end
3648ret 0
3649end
3650
3651fn psumin r ulong so ulong sl ulong to bool
3652note record r lists a file whose checksum is arena so..so+sl
3653b = mul r 32
3654lim = pg add b 17
3655i = pg add b 16
3656while lt i lim bound 16777216
3657e = eol i lim
3658k = kvsp i e
3659if mist i sub k i kpfile
3660nf = split vstart k e e 32
3661if eq nf 3
3662if eq sub fg 5 fg 4 sl
3663if mcmp fg 4 so sl
3664ret true
3665end
3666end
3667end
3668end
3669i = add e 1
3670end
3671ret false
3672end
3673
3674fn psrcline s ulong e ulong to void
3675note source CONCEPT-DOI ADDRESS CHECKSUM
3676nf = split s e 32
3677if or ne nf 4 not fbis 0 kpsrc
3678die erpsrc
3679end
3680r = pfind fg 2 sub fg 3 fg 2
3681if eq r 0
3682die erpsrc
3683end
3684b = mul sub r 1 32
3685uo = fg 4
3686ul = sub fg 5 fg 4
3687so = fg 6
3688sl = sub fg 7 fg 6
3689if gt pg add b 19 0
3690die erpsrc
3691end
3692if or le ul len tbase0 gt ul 300
3693die erpsrc
3694end
3695if not mistf uo tbase0 false
3696die erpsrc
3697end
3698if not okset uo add uo ul 7
3699die erpsrc
3700end
3701if not psumin sub r 1 so sl
3702die erpsrc
3703end
3704put pr add b 18 uo
3705put pr add b 19 ul
3706put st PNSRC add sg PNSRC 1
3707end
3708
3709fn psources to void
3710note content/papers.sources is optional: without it no paper has a source link
3711put st PNSRC 0
3712pbset fpsrc
3713if not isfile
3714ret
3715end
3716put st CXO keep fpsrc
3717put st CXL len fpsrc
3718off = slurp
3719lim = add off sg FLEN
3720i = off
3721while lt i lim bound 100000
3722e = eol i lim
3723if gt e i
3724if ne mg i 35
3725psrcline i e
3726end
3727end
3728i = add e 1
3729end
3730end
3731
3732fn obib c uchar to void
3733note one byte of a BibTeX value; the special characters are escaped
3734if or or eq c 37 eq c 36 or eq c 35 eq c 95
3735ob 92
3736ob c
3737ret
3738end
3739if eq c 126
3740ob 92
3741ot btilde
3742ret
3743end
3744if eq c 94
3745ob 92
3746ot bcaret
3747ret
3748end
3749ob c
3750end
3751
3752fn pesc m ulong to void
3753note the escape u03a9, capital omega, in HTML (1), JSON (2) or BibTeX (3)
3754if eq m 1
3755ot pomega
3756ret
3757end
3758if eq m 3
3759ob 36
3760ob 92
3761ot tomega
3762ob 36
3763ret
3764end
3765ob 92
3766ot tescom
3767end
3768
3769fn ptx o ulong l ulong m ulong to void
3770note writes a checked snapshot text value as HTML (1), JSON (2) or BibTeX (3)
3771i = o
3772lim = add o l
3773while lt i lim bound 16777216
3774c = mg i
3775if eq c 92
3776pesc m
3777i = add i 6
3778else
3779if eq m 1
3780oesc i 1
3781else
3782if eq m 3
3783obib c
3784else
3785ob c
3786end
3787end
3788i = add i 1
3789end
3790end
3791end
3792
3793fn plic o ulong l ulong to void
3794note a licence id for reading: cc-by-4.0 is written CC BY 4.0
3795for j ulong l bound 64
3796c = mg add o j
3797if eq c 45
3798ob 32
3799else
3800if and ge c 97 le c 122
3801ob sub c 32
3802else
3803ob c
3804end
3805end
3806end
3807end
3808
3809fn pver o ulong l ulong to void
3810note a version that is a bare number reads "version 3"; a worded one such as "Revision 4" stays
3811c = mg o
3812if and ge c 48 le c 57
3813ot pverw
3814end
3815ptx o l 1
3816end
3817
3818fn onumg s ulong e ulong to void
3819note the digits at arena s..e with a comma before each group of three from the right
3820n = sub e s
3821for j ulong n bound 16
3822if gt j 0
3823if eq rem sub n j 3 0
3824ob 44
3825end
3826end
3827ob mg add s j
3828end
3829end
3830
3831fn jcreat v ulong e ulong cnt ulong to void
3832note one creator as a JSON object
3833if gt cnt 0
3834ot tcomma
3835end
3836k = kvsp v e
3837ot jc1
3838ptx add k 1 sub e add k 1 2
3839ot jc2
3840if mist v sub k v tnone
3841ot jnull
3842else
3843ob 34
3844om v sub k v
3845ob 34
3846end
3847ob 125
3848end
3849
3850fn pitem v ulong e ulong m ulong cnt ulong to void
3851note one creator, file or related line: 1 HTML file, 2 JSON creator, 3 JSON file, 4 JSON related,
3852note 5 BibTeX author
3853if eq m 2
3854jcreat v e cnt
3855ret
3856end
3857if eq m 5
3858if gt cnt 0
3859ot band
3860end
3861k = kvsp v e
3862ptx add k 1 sub e add k 1 3
3863ret
3864end
3865nf = split v e 32
3866if eq m 1
3867ot pf1
3868om fg 0 sub fg 1 fg 0
3869ot pf2
3870onumg fg 2 fg 3
3871ot pf3
3872om fg 4 sub fg 5 fg 4
3873ot pf4
3874ret
3875end
3876if eq m 3
3877if gt cnt 0
3878ot jsep
3879end
3880ot jf1
3881om fg 0 sub fg 1 fg 0
3882ot jf2
3883om fg 2 sub fg 3 fg 2
3884ot jf3
3885om fg 4 sub fg 5 fg 4
3886ot jq2
3887ret
3888end
3889if gt cnt 0
3890ob 44
3891end
3892ot jrl1
3893om fg 0 sub fg 1 fg 0
3894ot jrl2
3895om fg 2 sub fg 3 fg 2
3896ot jrl3
3897om fg 4 sub fg 5 fg 4
3898ot jq2
3899end
3900
3901fn pwalk r ulong key view uchar * m ulong to ulong
3902note pitem for each line of record r with this key; returns how many there were
3903b = mul r 32
3904lim = pg add b 17
3905i = pg add b 16
3906cnt = ulong 0
3907while lt i lim bound 16777216
3908e = eol i lim
3909k = kvsp i e
3910if mist i sub k i key
3911pitem vstart k e e m cnt
3912cnt = add cnt 1
3913end
3914i = add e 1
3915end
3916ret cnt
3917end
3918
3919fn prow r ulong to void
3920note one entry of the papers page
3921b = mul r 32
3922co = pg add b 2
3923cl = pg add b 3
3924ot ph1
3925om add co len tdoipre sub cl len tdoipre
3926ot ph2
3927ptx pg add b 4 pg add b 5 1
3928ot ph3
3929om pg add b 6 10
3930ot pmid
3931ptx pg add b 8 pg add b 9 1
3932if gt pg add b 11 0
3933ot pmid
3934pver pg add b 10 pg add b 11
3935end
3936ot pmid
3937ot plicw
3938plic pg add b 12 pg add b 13
3939ot ph4
3940om pg b pg add b 1
3941ot ph5
3942om pg b pg add b 1
3943ot ph6
3944om co cl
3945ot ph7
3946om co cl
3947ot ph7b
3948if gt pg add b 19 0
3949ot ph8
3950om pg add b 18 pg add b 19
3951ot ph9
3952om co cl
3953ot ph7b
3954end
3955ot ph10
3956x = pwalk r kpfile 1
3957ot ph11
3958end
3959
3960fn jopt o ulong l ulong to void
3961note a JSON string, or null when the value is absent
3962if eq l 0
3963ot jnull
3964ret
3965end
3966ob 34
3967ptx o l 2
3968ob 34
3969end
3970
3971fn jrec r ulong to void
3972note one record of papers.json
3973b = mul r 32
3974ot jr1
3975om pg b pg add b 1
3976ot jr2
3977om pg b pg add b 1
3978ot jr3
3979om pg add b 2 pg add b 3
3980ot jr4
3981om pg add b 2 pg add b 3
3982ot jr5
3983ptx pg add b 4 pg add b 5 2
3984ot jr6
3985om pg add b 6 10
3986ot jr7
3987ptx pg add b 8 pg add b 9 2
3988ot jr8
3989jopt pg add b 10 pg add b 11
3990ot jr9
3991om pg add b 12 pg add b 13
3992ot jr10
3993x = pwalk r kpcre 2
3994ot jr11
3995if eq pg add b 14 1
3996ot jtrue
3997else
3998ot jfalse
3999end
4000ot jr12
4001jopt pg add b 18 pg add b 19
4002ot jr13
4003x = pwalk r kpfile 3
4004ot jr14
4005x = pwalk r kprel 4
4006if gt x 0
4007ot jrnl
4008end
4009ot jr15
4010end
4011
4012fn presps to void
4013note the response lines of the snapshot header as JSON objects
4014i = sg PSO
4015lim = sg PHE
4016cnt = ulong 0
4017while lt i lim bound 16777216
4018e = eol i lim
4019k = kvsp i e
4020if mist i sub k i kpresp
4021nf = split add k 1 e 32
4022if gt cnt 0
4023ot tcomma
4024end
4025ot pjr1
4026om fg 0 sub fg 1 fg 0
4027ot pjr2
4028a = add fg 2 len tsha2
4029om a sub fg 3 a
4030ot pjr3
4031cnt = add cnt 1
4032end
4033i = add e 1
4034end
4035end
4036
4037fn pjson to void
4038note the placeholder papers.json: the snapshot as one JSON document
4039put st OBN 0
4040ot pj1
4041om sg POO 19
4042ot pj2
4043om sg PFO 10
4044ot pj3
4045om sg PSHA 64
4046ot pj4
4047presps
4048ot pj5
4049onum sg PNR
4050ot pj6
4051n = sg PNR
4052for r ulong n bound 64
4053if gt r 0
4054ot jsep
4055end
4056jrec r
4057end
4058ot pj7
4059o = stash
4060setv vpjson o sg FLEN
4061end
4062
4063fn brec r ulong to void
4064note one BibTeX entry
4065b = mul r 32
4066co = pg b
4067cl = pg add b 1
4068d = pg add b 6
4069ot bb1
4070om add co len tdoipre sub cl len tdoipre
4071ot bb2
4072x = pwalk r kpcre 5
4073ot bb3
4074ptx pg add b 4 pg add b 5 3
4075ot bb4
4076om d 4
4077ot bb5
4078m = l2 add d 5
4079for j ulong 3
4080ob get tmonths add mul sub m 1 3 j
4081end
4082ot bb6
4083om d 10
4084ot bb7
4085if gt pg add b 11 0
4086ot bb8
4087ptx pg add b 10 pg add b 11 3
4088ot bb7
4089end
4090ot bb10
4091om co cl
4092ot bb11
4093om co cl
4094ot bb12
4095ptx pg add b 8 pg add b 9 3
4096ot bb13
4097ptx pg add b 12 pg add b 13 3
4098ot bb14
4099om pg add b 2 pg add b 3
4100ot bb15
4101end
4102
4103fn pbib to void
4104note the placeholder papers.bib: one BibTeX entry per record
4105put st OBN 0
4106ot pbh1
4107om sg POO 19
4108ot pbh2
4109om sg PFO 10
4110ot pbh3
4111n = sg PNR
4112for r ulong n bound 64
4113brec r
4114end
4115o = stash
4116setv vpbib o sg FLEN
4117end
4118
4119fn phtml to void
4120note the placeholder papers.rows: one list entry per record, in snapshot order
4121put st OBN 0
4122n = sg PNR
4123for r ulong n bound 64
4124prow r
4125end
4126o = stash
4127setv vprows o sg FLEN
4128end
4129
4130fn papers to void
4131pbset fpapers
4132put st CXO keep fpapers
4133put st CXL len fpapers
4134off = slurp
4135n = sg FLEN
4136hashm off n
4137ho = hxkeep
4138put st PSHA ho
4139put st PSO off
4140if eq sg TESTD 0
4141if mhas off n pfix true
4142die errel
4143end
4144end
4145put st PST 0
4146put st PNR 0
4147put st PNRESP 0
4148lim = add off n
4149i = off
4150while lt i lim bound 100000
4151e = eol i lim
4152if gt e i
4153if ne mg i 35
4154papline i e
4155end
4156end
4157i = add e 1
4158end
4159if eq sg PNR 0
4160die erpap
4161end
4162pclose lim
4163if ne sg PNR sg PDECL
4164die erpord
4165end
4166psources
4167put st CXL 0
4168phtml
4169pjson
4170pbib
4171onum sg PNR
4172co = stash
4173setv vpcount co sg FLEN
4174setv vpasof sg PFO 10
4175setv vporcid sg POO 19
4176setv vpsha sg PSHA 64
4177onum sg PNSRC
4178so = stash
4179setv vpnsrc so sg FLEN
4180say mpap
4181sayn sg PNR
4182say mpsrc
4183sayn sg PNSRC
4184say mysha
4185saym sg PSHA 64
4186say tnl
4187end
4188
4189note ---- receipts: the forge chain format (seq utc kind actor subject payload prev)
4190
4191fn l2 a ulong to ulong
4192x = ulong mg a
4193y = ulong mg add a 1
4194ret add mul sub x 48 10 sub y 48
4195end
4196
4197fn ldim y ulong m ulong to ulong
4198if eq m 2
4199if and eq rem y 4 0 or ne rem y 100 0 eq rem y 400 0
4200ret 29
4201end
4202ret 28
4203end
4204if or or eq m 4 eq m 6 or eq m 9 eq m 11
4205ret 30
4206end
4207ret 31
4208end
4209
4210fn utcok a ulong e ulong to bool
4211note arena a..e is YYYY-MM-DDTHH:MM:SSZ and names a real date and time
4212if ne sub e a 20
4213ret false
4214end
4215for i ulong 20
4216c = mg add a i
4217w = uchar 0
4218if or eq i 4 eq i 7
4219w = 45
4220end
4221if eq i 10
4222w = 84
4223end
4224if or eq i 13 eq i 16
4225w = 58
4226end
4227if eq i 19
4228w = 90
4229end
4230if eq w 0
4231if or lt c 48 gt c 57
4232ret false
4233end
4234else
4235if ne c w
4236ret false
4237end
4238end
4239end
4240m = l2 add a 5
4241if or lt m 1 gt m 12
4242ret false
4243end
4244d = l2 add a 8
4245y = add mul l2 a 100 l2 add a 2
4246if or lt d 1 gt d ldim y m
4247ret false
4248end
4249if gt l2 add a 11 23
4250ret false
4251end
4252if gt l2 add a 14 59
4253ret false
4254end
4255ret le l2 add a 17 59
4256end
4257
4258fn kindok s ulong e ulong to bool
4259if or ge s e gt sub e s 24
4260ret false
4261end
4262i = s
4263while lt i e bound 32
4264c = mg i
4265ok = or and ge c 65 le c 90 or and ge c 48 le c 57 eq c 95
4266if not ok
4267ret false
4268end
4269i = add i 1
4270end
4271ret true
4272end
4273
4274fn linehash s ulong e ulong to void
4275note hx = SHA-256 of the ledger line arena s..e (without its line feed)
4276hashm s sub e s
4277end
4278
4279fn phis s ulong e ulong to bool
4280note arena s..e equals the 64 hex digits in ph
4281if ne sub e s 64
4282ret false
4283end
4284for j ulong 64
4285if ne mg add s j get ph j
4286ret false
4287end
4288end
4289ret true
4290end
4291
4292fn recshape s ulong e ulong to bool
4293note exactly six tabs and every other byte printable ASCII
4294t = ulong 0
4295i = s
4296while lt i e bound 1024
4297c = mg i
4298if eq c 9
4299t = add t 1
4300else
4301if or lt c 32 gt c 126
4302ret false
4303end
4304end
4305i = add i 1
4306end
4307ret eq t 6
4308end
4309
4310fn reccheck s ulong e ulong n ulong prevu ulong to ulong
4311note 0 when arena s..e is the valid record number n; else the chain tool's BAD code
4312if gt sub e s 1023
4313ret 6
4314end
4315if not recshape s e
4316ret 1
4317end
4318nf = split s e 9
4319if ne mnum fg 0 fg 1 n
4320ret 2
4321end
4322if not utcok fg 2 fg 3
4323ret 3
4324end
4325if gt prevu 0
4326if utclt fg 2 prevu
4327ret 3
4328end
4329end
4330if not kindok fg 4 fg 5
4331ret 8
4332end
4333al = sub fg 7 fg 6
4334if or eq al 0 gt al 64
4335ret 8
4336end
4337sl = sub fg 9 fg 8
4338if or eq sl 0 gt sl 128
4339ret 8
4340end
4341if ne sub fg 11 fg 10 64
4342ret 4
4343end
4344if not okset fg 10 fg 11 2
4345ret 4
4346end
4347if eq n 1
4348if not fbis 6 tgenesis
4349ret 5
4350end
4351else
4352if not phis fg 12 fg 13
4353ret 5
4354end
4355end
4356ret 0
4357end
4358
4359fn utclt a ulong b ulong to bool
4360note the 20-byte time at arena a is earlier than the one at b
4361for j ulong 20
4362x = mg add a j
4363y = mg add b j
4364if lt x y
4365ret true
4366end
4367if gt x y
4368ret false
4369end
4370end
4371ret false
4372end
4373
4374fn paycheck po ulong to void
4375note the payload file named by the 64 hex digits at arena po exists and hashes to its name.
4376note st PAYO 1 reads it from the written output instead of the source tree.
4377if eq sg PAYO 1
4378pbroot 0
4379pbadd tslash
4380pbadd fpayout
4381else
4382pbset fpayd
4383end
4384pbaddm po 64
4385pbadd ftxt
4386if not isfile
4387put st CXO po
4388put st CXL 64
4389die erpayl
4390end
4391mark = sg TOP
4392off = slurp
4393hashm off sg FLEN
4394fix = false
4395if eq sg TESTD 0
4396fix = mhas off sg FLEN pfixu false
4397end
4398put st TOP mark
4399if not hxis po
4400put st CXO po
4401put st CXL 64
4402die erpayl
4403end
4404if fix
4405put st CXO po
4406put st CXL 64
4407die errel
4408end
4409end
4410
4411fn recrow s ulong n ulong to void
4412note emits the table row of the record whose line starts at arena s; fb is refilled
4413e = eol s add s 1024
4414nf = split s e 9
4415ot r1
4416onum n
4417ot r2
4418onum n
4419ot r3
4420om fg 2 sub fg 3 fg 2
4421ot r4
4422om fg 4 sub fg 5 fg 4
4423ot r5
4424oesc fg 6 sub fg 7 fg 6
4425ot r6
4426oesc fg 8 sub fg 9 fg 8
4427ot r7
4428om fg 10 64
4429ot r8
4430om fg 10 16
4431ot r9
4432end
4433
4434fn errnum v ulong to void
4435i = ulong 20
4436x = v
4437if eq x 0
4438i = 19
4439put sy 19 48
4440end
4441while gt x 0 bound 20
4442i = sub i 1
4443put sy i uchar add 48 rem x 10
4444x = div x 10
4445end
4446w = write 2 sy i sub 20 i
4447end
4448
4449fn rcsay code ulong line ulong to void
4450note the chain tool's wording: BAD line N code
4451sayerr tbadl
4452errnum line
4453sayerr tsp
4454errnum code
4455sayerr tnl
4456end
4457
4458fn rcloop off ulong lim ulong to ulong
4459note checks every record and its payload file; returns the record count, st BADC the last payload offset
4460count = ulong 0
4461prevu = ulong 0
4462i = off
4463while lt i lim bound 2000
4464e = eol i lim
4465count = add count 1
4466if gt count 1999
4467die erledg
4468end
4469code = reccheck i e count prevu
4470if ne code 0
4471rcsay code count
4472die erledg
4473end
4474prevu = fg 2
4475put st BADC fg 10
4476put rcs count i
4477linehash i e
4478for j ulong 64
4479put ph j get hx j
4480end
4481paycheck sg BADC
4482i = add e 1
4483end
4484ret count
4485end
4486
4487fn rcvars count ulong to void
4488note the head is the digest of the last line, held in ph
4489for j ulong 64
4490put hx j get ph j
4491end
4492ho = hxkeep
4493setv vrhead ho 64
4494setv vrlast sg BADC 64
4495put st OBN 0
4496onum count
4497co = stash
4498setv vrcount co sg FLEN
4499setv vrlseq co sg FLEN
4500k = ulong 1
4501while le k count bound 2000
4502recrow cg k k
4503k = add k 1
4504end
4505ro = stash
4506setv vrrows ro sg FLEN
4507setvt krcpt vone
4508say mrcyes
4509sayn count
4510say mrchead
4511sayhx
4512say tnl
4513end
4514
4515fn receipts to void
4516pbset fledger
4517if not isfile
4518put st FRC 0
4519say mrcno
4520ret
4521end
4522put st FRC 1
4523put st CXO keep fledger
4524put st CXL len fledger
4525off = slurp
4526n = sg FLEN
4527put st LDGO off
4528put st LDGN n
4529lim = add off n
4530if ne mg sub lim 1 10
4531rcsay 7 1
4532die erledg
4533end
4534if eq sg TESTD 0
4535if or mhas off n pfixu false mhas off n pfixd false
4536die errel
4537end
4538end
4539count = rcloop off lim
4540if eq count 0
4541die erledg
4542end
4543put st NREC count
4544note the head is also written down in the source, so the signed history of this repository records it
4545pbset fhead
4546put st CXO keep fhead
4547put st CXL len fhead
4548if not isfile
4549die erhead
4550end
4551mark = sg TOP
4552ho = slurp
4553okh = false
4554if eq sg FLEN 65
4555if eq mg add ho 64 10
4556okh = phis ho add ho 64
4557end
4558end
4559put st TOP mark
4560if not okh
4561die erhead
4562end
4563rcvars count
4564pbset fvsh
4565put st CXO keep fvsh
4566put st CXL len fvsh
4567so = slurp
4568put st OBN 0
4569oesc so sg FLEN
4570vo = stash
4571setv vrvsh vo sg FLEN
4572put st CXL 0
4573end
4574
4575note ---- Hop release data: content/hop.release.txt, one "key value" per line
4576
4577fn hopkey ko ulong kl ulong vo ulong ve ulong to bool
4578note checks one key's value; false for an unknown key or a value outside its rule
4579vl = sub ve vo
4580if mist ko kl hkver
4581ret okset vo ve 1
4582end
4583if mist ko kl hkcommit
4584ret and eq vl 40 okset vo ve 2
4585end
4586if mist ko kl hkrid
4587ret okset vo ve 4
4588end
4589if mist ko kl hkzip
4590ret okset vo ve 1
4591end
4592if or mist ko kl hkzsha or mist ko kl hkesha mist ko kl hkins
4593ret and eq vl 64 okset vo ve 2
4594end
4595if or mist ko kl hkbuilt mist ko kl hkmacos
4596ret okset vo ve 6
4597end
4598if or mist ko kl hkdl or mist ko kl hksrc mist ko kl hkbase
4599if lt vl 12
4600ret false
4601end
4602if not mist vo 8 thttps
4603ret false
4604end
4605ret okset vo ve 7
4606end
4607if or mist ko kl hkrepro mist ko kl hkverif
4608ret or mist vo vl tyes mist vo vl tno
4609end
4610if mist ko kl hkcheck
4611ret and eq vl 20 utcok vo ve
4612end
4613if mist ko kl hkseqs
4614ret okset vo ve 8
4615end
4616ret false
4617end
4618
4619fn hopline s ulong e ulong to void
4620c = s
4621while lt c e bound 16777216
4622if eq mg c 32
4623break
4624end
4625c = add c 1
4626end
4627if or eq c s or ge add c 1 e gt sub c s 40
4628die erhop
4629end
4630if not hopkey s sub c s add c 1 e
4631put st CXO s
4632put st CXL sub e s
4633die erhop
4634end
4635ko = keep vhoppre
4636base = sg TOP
4637if gt add base 64 MEMSZ
4638die erfull
4639end
4640for j ulong sub c s bound 64
4641put mem add base j mg add s j
4642end
4643put st TOP add base sub c s
4644setvm ko add len vhoppre sub c s add c 1 sub e add c 1
4645end
4646
4647fn hopneed k view uchar * to void
4648if not vset k
4649put st CXO keep k
4650put st CXL len k
4651die erhop
4652end
4653end
4654
4655
4656fn visyes k view uchar * to bool
4657v = vlook k
4658if eq v 0
4659ret false
4660end
4661b = mul sub v 1 4
4662ret mist vg add b 2 vg add b 3 tyes
4663end
4664
4665fn hopseq idx ulong s ulong e ulong to void
4666note receipt record number idx (1..4) is the decimal in arena s..e
4667v = mnum s e
4668if or eq v 0 gt v sg NREC
4669die erhopr
4670end
4671if eq idx 1
4672setv vhr1 s sub e s
4673end
4674if eq idx 2
4675setv vhr2 s sub e s
4676end
4677if eq idx 3
4678setv vhr3 s sub e s
4679end
4680if eq idx 4
4681setv vhr4 s sub e s
4682end
4683end
4684
4685fn hopseqs to void
4686v = vlook nseqs
4687if eq v 0
4688ret
4689end
4690b = mul sub v 1 4
4691s = vg add b 2
4692e = add s vg add b 3
4693nf = split s e 32
4694if or eq nf 0 gt nf 4
4695die erhopr
4696end
4697if eq sg FRC 0
4698die erhopr
4699end
4700hopseq 1 fg 0 fg 1
4701if gt nf 1
4702hopseq 2 fg 2 fg 3
4703end
4704if gt nf 2
4705hopseq 3 fg 4 fg 5
4706end
4707if gt nf 3
4708hopseq 4 fg 6 fg 7
4709end
4710end
4711
4712fn relval k view uchar * to void
4713note release mode: the value of key k is not a repeated-digit placeholder
4714v = vlook k
4715if eq v 0
4716ret
4717end
4718b = mul sub v 1 4
4719if fewdig vg add b 2 vg add b 3
4720put st CXO keep k
4721put st CXL len k
4722die errel
4723end
4724end
4725
4726fn relhost k view uchar * both bool to void
4727note release mode: the address of key k is on interplane.io or, when both is set, on hopbot.org
4728v = vlook k
4729if eq v 0
4730ret
4731end
4732b = mul sub v 1 4
4733vo = vg add b 2
4734vl = vg add b 3
4735ok = false
4736if ge vl len hip
4737ok = mistf vo hip false
4738end
4739if both
4740if ge vl len hhb
4741if mistf vo hhb false
4742ok = true
4743end
4744end
4745if mist vo vl vhbased
4746ok = true
4747end
4748end
4749if not ok
4750put st CXO keep k
4751put st CXL len k
4752die errel
4753end
4754end
4755
4756fn hopzipn to bool
4757note the installer fetches Hop-VERSION.zip from install_base, so zip_name must be exactly that
4758z = vlook nzip
4759w = vlook nver
4760if or eq z 0 eq w 0
4761ret false
4762end
4763zb = mul sub z 1 4
4764wb = mul sub w 1 4
4765zo = vg add zb 2
4766zl = vg add zb 3
4767wl = vg add wb 3
4768if ne zl add wl 8
4769ret false
4770end
4771if not mistf zo thopp false
4772ret false
4773end
4774if not mcmp add zo 4 vg add wb 2 wl
4775ret false
4776end
4777ret mistf add add zo 4 wl xzipx false
4778end
4779
4780fn hopinst to void
4781note content/hop.install.sh, install_sha256 and install_base come together or not at all, and must agree
4782put st FINS 0
4783pbset fhins
4784has = isfile
4785key = vset nins
4786base = vset vhbase
4787if and not has and not key not base
4788say minsno
4789ret
4790end
4791put st CXO keep fhins
4792put st CXL len fhins
4793if or not has or not key not base
4794die erhins
4795end
4796mark = sg TOP
4797off = slurp
4798hashm off sg FLEN
4799put st TOP mark
4800v = vlook nins
4801if not hxis vg add mul sub v 1 4 2
4802die erhins
4803end
4804if not hopzipn
4805die erhins
4806end
4807put st FINS 1
4808setvt khins vone
4809say minsyes
4810end
4811
4812fn insroute r ulong to bool
4813note route r is the one installer route: hopbot.org /install.sh from content/hop.install.sh, with the install flag
4814b = mul r 8
4815if or ne rg add b 6 3 ne rg add b 1 1
4816ret false
4817end
4818if ne sg FINS 1
4819ret false
4820end
4821if not mist rg add b 2 rg add b 3 rinst
4822ret false
4823end
4824ret mist rg add b 4 rg add b 5 fhins
4825end
4826
4827fn inspin to bool
4828note hx, the SHA-256 just taken, equals install_sha256
4829v = vlook nins
4830if eq v 0
4831ret false
4832end
4833ret hxis vg add mul sub v 1 4 2
4834end
4835
4836fn insfile s ulong e ulong site ulong to bool
4837note verify: the hopbot.org file install.sh whose SHA-256 (in hx) equals install_sha256.
4838note It is the one file whose content is not scanned; its bytes are fixed by that fingerprint.
4839if or ne site 1 ne sg FINS 1
4840ret false
4841end
4842if not mist s sub e s finsout
4843ret false
4844end
4845ret inspin
4846end
4847
4848fn hoppay rk view uchar * to ulong
4849note arena offset of the evidence name (64 hex digits) of the receipt whose number is in placeholder rk; 0 for none
4850r = vlook rk
4851if eq r 0
4852ret 0
4853end
4854rb = mul sub r 1 4
4855n = mnum vg add rb 2 add vg add rb 2 vg add rb 3
4856s = cg n
4857nf = split s eol s add s 1024 9
4858ret fg 10
4859end
4860
4861fn hopproof rk view uchar * vk view uchar * fk view uchar * to ulong
4862note 1 when the receipt named for this row exists and its evidence file holds the row's value
4863po = hoppay rk
4864v = vlook vk
4865if or eq po 0 eq v 0
4866ret 0
4867end
4868pbset fpayd
4869pbaddm po 64
4870pbadd ftxt
4871mark = sg TOP
4872off = slurp
4873vb = mul sub v 1 4
4874found = mfind off sg FLEN vg add vb 2 vg add vb 3
4875put st TOP mark
4876if not found
4877ret 0
4878end
4879setvt fk vone
4880ret 1
4881end
4882
4883fn hopdbase to void
4884note hop.download_base: the folder the zip is served from, when download_url ends in a slash and zip_name
4885u = vlook ndl
4886z = vlook nzip
4887if or eq u 0 eq z 0
4888ret
4889end
4890ub = mul sub u 1 4
4891uo = vg add ub 2
4892ul = vg add ub 3
4893zb = mul sub z 1 4
4894zl = vg add zb 3
4895if le ul add zl 1
4896ret
4897end
4898if and eq mg sub sub add uo ul zl 1 47 mcmp sub add uo ul zl vg add zb 2 zl
4899setv vhdbase uo sub sub ul zl 1
4900end
4901end
4902
4903fn hopbadge to void
4904note the badge needs all three fingerprint rows backed by a receipt that holds the same value
4905got = hopproof vhr1 ncommit vhok1
4906got = add got hopproof vhr2 nzsha vhok2
4907got = add got hopproof vhr3 nesha vhok3
4908k4 = hopproof vhr4 ncheck vhok4
4909if eq got 3
4910setvt vhbadge vone
4911end
4912say mbadge
4913sayn got
4914say mbadgeof
4915end
4916
4917fn hopcopy to void
4918note content/hop.copy.txt names the Hop commit the page wording describes; a release must be that commit
4919pbset fhcopy
4920put st CXO keep fhcopy
4921put st CXL len fhcopy
4922if not isfile
4923die erhcopy
4924end
4925mark = sg TOP
4926off = slurp
4927lim = add off sg FLEN
4928seen = ulong 0
4929co = ulong 0
4930i = off
4931while lt i lim bound 100000
4932e = eol i lim
4933if gt e i
4934if ne mg i 35
4935seen = add seen 1
4936if ne sub e i 50
4937die erhcopy
4938end
4939if not mistf i tdescr false
4940die erhcopy
4941end
4942co = add i 10
4943if not okset co e 2
4944die erhcopy
4945end
4946end
4947end
4948i = add e 1
4949end
4950if ne seen 1
4951die erhcopy
4952end
4953if eq sg TESTD 1
4954put st TOP mark
4955say mhcopyt
4956ret
4957end
4958v = vlook ncommit
4959same = mcmp co vg add mul sub v 1 4 2 40
4960put st TOP mark
4961if not same
4962die erhcopy
4963end
4964say mhcopy
4965end
4966
4967fn hoprel off ulong n ulong to void
4968note release mode: no fixture word, no placeholder fingerprint, and addresses on our own two sites
4969if mhas off n pfix true
4970die errel
4971end
4972relval ncommit
4973relval nzsha
4974relval nesha
4975relval nins
4976relhost ndl true
4977relhost nsrc false
4978relhost vhbase true
4979end
4980
4981fn hop to void
4982pbset fhop
4983if not isfile
4984put st FHOP 0
4985say mhopno
4986ret
4987end
4988put st FHOP 1
4989put st CXO keep fhop
4990put st CXL len fhop
4991off = slurp
4992lim = add off sg FLEN
4993i = off
4994while lt i lim bound 100000
4995e = eol i lim
4996if gt e i
4997if ne mg i 35
4998hopline i e
4999end
5000end
5001i = add e 1
5002end
5003put st CXO keep fhop
5004put st CXL len fhop
5005hopneed nver
5006hopneed ncommit
5007hopneed nrid
5008hopneed nzip
5009hopneed nzsha
5010hopneed nesha
5011hopneed nbuilt
5012hopneed nmacos
5013hopneed ndl
5014hopneed nsrc
5015hopneed nrepro
5016hopneed ncheck
5017if visyes nrepro
5018setvt vhrepro vone
5019end
5020if visyes nverif
5021setvt vhverif vone
5022end
5023if eq sg TESTD 0
5024hoprel off sub lim off
5025end
5026hopcopy
5027put st CXO keep fhop
5028put st CXL len fhop
5029v = vlook ncommit
5030setv vhshort vg add mul sub v 1 4 2 12
5031hopdbase
5032hopseqs
5033hopinst
5034hopbadge
5035put st CXL 0
5036setvt khop vone
5037say mhopyes
5038end
5039
5040note ---- live switches: content/live.txt, one line "map yes" or "map no"; lines starting with # are skipped
5041
5042fn live to void
5043pbset flive
5044if not isfile
5045say mmapno
5046ret
5047end
5048put st CXO keep flive
5049put st CXL len flive
5050off = slurp
5051lim = add off sg FLEN
5052on = ulong 0
5053seen = ulong 0
5054i = off
5055while lt i lim bound 100000
5056e = eol i lim
5057if ne mg i 35
5058seen = add seen 1
5059on = 2
5060if mist i sub e i lmapyes
5061on = 1
5062end
5063if mist i sub e i lmapno
5064on = 0
5065end
5066if or eq on 2 gt seen 1
5067die erlive
5068end
5069end
5070i = add e 1
5071end
5072if ne seen 1
5073die erlive
5074end
5075if eq on 1
5076setvt kmap vone
5077say mmapyes
5078ret
5079end
5080say mmapno
5081end
5082
5083note ---- routes: content/routes.txt, "kind site route source [hop|receipts|install]" per line.
5084note Kinds: 1 page, 2 css, 3 svg, 4 raw, 5 receipts payload (verify only), 6 tpl (llms.txt),
5085note 7 data (a text template, such as papers.json), 8 font (an OpenType file copied as it is),
5086note 9 png (a PNG image under /public/), 10 forge (sitemap only),
5087note 11 gzip (an Omega download archive, copied as it is).
5088
5089fn rkind s ulong n ulong to ulong
5090if mist s n kpage
5091ret 1
5092end
5093if mist s n kcss
5094ret 2
5095end
5096if mist s n ksvg
5097ret 3
5098end
5099if mist s n kraw
5100ret 4
5101end
5102if mist s n ktpl
5103ret 6
5104end
5105if mist s n kdata
5106ret 7
5107end
5108if mist s n kfont
5109ret 8
5110end
5111if mist s n kpng
5112ret 9
5113end
5114if mist s n kforge
5115ret 10
5116end
5117if mist s n kgzip
5118ret 11
5119end
5120ret 0
5121end
5122
5123fn fbis k ulong t view uchar * to bool
5124note field k of the last split equals the text t
5125a = fg mul k 2
5126ret mist a sub fg add mul k 2 1 a t
5127end
5128
5129fn rsite to ulong
5130if fbis 1 kmain
5131ret 0
5132end
5133if fbis 1 khopbot
5134ret 1
5135end
5136ret 9
5137end
5138
5139fn rflag nf ulong to ulong
5140if ne nf 5
5141ret 0
5142end
5143if fbis 4 khop
5144ret 1
5145end
5146if fbis 4 krcpt
5147ret 2
5148end
5149if fbis 4 kinst
5150ret 3
5151end
5152ret 9
5153end
5154
5155fn route1 nr ulong nf ulong to void
5156note stores the route whose fields are in fb as entry nr
5157b = mul nr 8
5158kind = rkind fg 0 sub fg 1 fg 0
5159site = rsite
5160flag = rflag nf
5161if or eq kind 0 or eq site 9 eq flag 9
5162die erroute
5163end
5164if ne mg fg 4 47
5165die erroute
5166end
5167if eq kind 8
5168if not fontrt fg 4 fg 5
5169die erroute
5170end
5171end
5172if eq kind 9
5173if not pngrt fg 4 fg 5
5174die erroute
5175end
5176end
5177if eq kind 10
5178if or ne site 0 or ne nf 4 not mist fg 6 sub fg 7 fg 6 kdash
5179die erroute
5180end
5181if not forgert fg 4 fg 5
5182die erroute
5183end
5184end
5185if eq kind 11
5186if or ne site 0 or ne nf 4 not gziprt add fg 4 1 fg 5
5187die erroute
5188end
5189end
5190rdup nr site fg 4 sub fg 5 fg 4
5191put rt b kind
5192put rt add b 1 site
5193put rt add b 2 fg 4
5194put rt add b 3 sub fg 5 fg 4
5195put rt add b 4 fg 6
5196put rt add b 5 sub fg 7 fg 6
5197put rt add b 6 flag
5198end
5199
5200fn rdup nr ulong site ulong s ulong n ulong to void
5201note refuses a route whose site and address equal those of one of the first nr routes
5202for j ulong nr bound RTCAP
5203rb = mul j 8
5204gs = get rt add rb 1
5205gn = get rt add rb 3
5206if and eq gs site eq gn n
5207gp = get rt add rb 2
5208if mcmp gp s n
5209die erdupr
5210end
5211end
5212end
5213end
5214
5215fn forgert s ulong e ulong to bool
5216note a forge route is /explore or /drakestapleton/NAME, NAME in A-Z a-z 0-9 . _ - and not starting
5217note with a dot: a page the forge serves at that address, which this site only lists in its sitemap
5218p = add s 1
5219if mist p sub e p lexplore
5220ret true
5221end
5222if le sub e p len lownerp
5223ret false
5224end
5225if not mistf p lownerp false
5226ret false
5227end
5228q = add p len lownerp
5229if eq mg q 46
5230ret false
5231end
5232ret okset q e 1
5233end
5234
5235fn fontrt s ulong e ulong to bool
5236note a font route is /public/fonts/NAME.otf with NAME in A-Z a-z 0-9 . _ -
5237n = sub e s
5238if le n add len tfonts len xotf
5239ret false
5240end
5241if not mistf s tfonts false
5242ret false
5243end
5244if not mist sub e len xotf len xotf xotf
5245ret false
5246end
5247ret okset add s len tfonts e 1
5248end
5249
5250fn pngrt s ulong e ulong to bool
5251note a png route is /public/NAME.png with NAME in A-Z a-z 0-9 . _ -
5252n = sub e s
5253if le n add len tpubl len xpng
5254ret false
5255end
5256if not mistf s tpubl false
5257ret false
5258end
5259if not mist sub e len xpng len xpng xpng
5260ret false
5261end
5262ret okset add s len tpubl e 1
5263end
5264
5265fn gziprt s ulong e ulong to bool
5266note a gzip route is /omega/downloads/NAME.tar.gz without subdirectories
5267n = sub e s
5268if le n add len odloads len xgzip
5269ret false
5270end
5271if not mistf s odloads false
5272ret false
5273end
5274if not mist sub e len xgzip len xgzip xgzip
5275ret false
5276end
5277p = add s len odloads
5278if eq mg p 46
5279ret false
5280end
5281ret okset p e 1
5282end
5283
5284fn routes to void
5285pbset froutes
5286put st CXO keep froutes
5287put st CXL len froutes
5288off = slurp
5289lim = add off sg FLEN
5290nr = ulong 0
5291i = off
5292while lt i lim bound 100000
5293e = eol i lim
5294if gt e i
5295if ne mg i 35
5296nf = split i e 32
5297if ge nr RTCAP
5298die erfullr
5299end
5300if or lt nf 4 gt nf 5
5301die erroute
5302end
5303route1 nr nf
5304nr = add nr 1
5305end
5306end
5307i = add e 1
5308end
5309if eq nr 0
5310die erroute
5311end
5312put st NR nr
5313end
5314
5315fn omdlread name ulong n ulong kind ulong to ulong
5316note read the registered source file, so hashes bind the bytes that will actually be published
5317nr = sg NR
5318r = ulong 0
5319while lt r nr bound RTCAP
5320b = mul r 8
5321a = add rg add b 2 1
5322if and eq rg b kind and eq rg add b 1 0 eq rg add b 6 0
5323if eq rg add b 3 add add n len odloads 1
5324if and mistf a odloads false mcmp add a len odloads name n
5325put st PBL 0
5326pbaddm rg add b 4 rg add b 5
5327put st CXO rg add b 4
5328put st CXL rg add b 5
5329ret slurp
5330end
5331end
5332end
5333r = add r 1
5334end
5335put st CXO keep froutes
5336put st CXL len froutes
5337die erodload
5338ret 0
5339end
5340
5341fn omdownloads to void
5342note the checksum file is pinned like robots.txt; its two rows name the archive and installer
5343name = keep odloadsums
5344start = omdlread name len odloadsums 4
5345n = sg FLEN
5346hashm start n
5347for j ulong 64
5348if ne get hx j get odloadpin j
5349die erodload
5350end
5351end
5352stop = add start n
5353pos = start
5354for row ulong 2
5355last = eol pos stop
5356name = add pos 66
5357size = sub last name
5358kind = ulong 11
5359if eq row 0
5360setv odkarch name size
5361else
5362kind = 4
5363setv odkinst name size
5364end
5365mark = sg TOP
5366off = omdlread name size kind
5367if eq row 0
5368put st OBN 0
5369om off sg FLEN
5370lint 11
5371end
5372hashm off sg FLEN
5373if not hxis pos
5374die erodload
5375end
5376put st TOP mark
5377pos = add last 1
5378end
5379setvt odksums odloadsums
5380setvt odkcommit odcommit
5381note every route in the download directory is either one of those three or a release error
5382count = ulong 0
5383nr = sg NR
5384for r ulong nr bound RTCAP
5385b = mul r 8
5386if ge rg add b 3 add len odloads 1
5387if mistf add rg add b 2 1 odloads false
5388count = add count 1
5389end
5390end
5391end
5392if ne count 3
5393put st CXO keep froutes
5394put st CXL len froutes
5395die erodextra
5396end
5397end
5398
5399fn omdllink key view uchar * to bool
5400note find a download anchor targeting the file name read from the pinned release
5401v = mul sub vlook key 1 4
5402name = vg add v 2
5403n = vg add v 3
5404i = ofind 0 odhref
5405while lt i sg OBN bound 100000
5406p = add i len odhref
5407e = add p n
5408if le e sg OBN
5409if and obeqm p e name n omatch e odend
5410ret true
5411end
5412end
5413i = ofind add i 1 odhref
5414end
5415ret false
5416end
5417
5418fn omdlcopy r ulong to void
5419b = mul r 8
5420if ne rg add b 1 0
5421ret
5422end
5423a = rg add b 2
5424n = rg add b 3
5425if mist a n odhome
5426if not and ohas odtitle and ohas odcommit and omdllink odkarch and omdllink odkinst omdllink odksums
5427die erodcopy
5428end
5429end
5430if mist add a 1 sub n 1 fllms
5431if not ohas odguide
5432die erodguide
5433end
5434end
5435end
5436
5437fn enabled r ulong to bool
5438b = mul r 8
5439if eq rg b 10
5440ret false
5441end
5442if eq rg add b 1 1
5443if eq sg FHOP 0
5444ret false
5445end
5446end
5447flag = rg add b 6
5448if eq flag 1
5449ret eq sg FHOP 1
5450end
5451if eq flag 2
5452ret eq sg FRC 1
5453end
5454if eq flag 3
5455ret and eq sg FHOP 1 eq sg FINS 1
5456end
5457ret true
5458end
5459
5460fn outpb r ulong to void
5461note pb = output path of route r: site root, the route, and index.html for a directory route
5462b = mul r 8
5463pbroot rg add b 1
5464ro = rg add b 2
5465rl = rg add b 3
5466pbaddm ro rl
5467if eq mg sub add ro rl 1 47
5468pbadd tindex
5469end
5470end
5471
5472fn manadd site ulong to void
5473note records "<sha256> <path below the root>" for the file named by pb, whose bytes are in obuf
5474hasho
5475m = sg MANL
5476s = add rootlen site 1
5477n = sg PBL
5478if gt add add m 70 sub n s 524000
5479die erbig
5480end
5481for j ulong 64
5482put man add m j get hx j
5483end
5484put man add m 64 32
5485put man add m 65 32
5486m = add m 66
5487for j ulong sub n s bound 2048
5488put man add m j get pb add s j
5489end
5490m = add m sub n s
5491put man m 10
5492put st MANL add m 1
5493put st NFILE add sg NFILE 1
5494end
5495
5496fn wrfile site ulong to void
5497note st DRY 1 (verify) records the digest without writing, to rebuild the expected manifest
5498if eq sg DRY 0
5499mkpar site
5500wrraw
5501end
5502manadd site
5503end
5504
5505note ---- retired Chinese copies: readers translate pages with their own tools (/translate/), so a
5506note route under /zh-CN/ is refused; the helpers below are shared by pages and the translation unit.
5507
5508fn zhpath r ulong to bool
5509note route r lies under /zh-..., /zh/ or is /zh (letter case ignored)
5510b = mul r 8
5511n = rg add b 3
5512p = rg add b 2
5513if lt n len tzhb
5514ret false
5515end
5516if not mistf p tzhb true
5517ret false
5518end
5519if eq n len tzhb
5520ret true
5521end
5522c = mg add p len tzhb
5523ret or eq c 45 eq c 47
5524end
5525
5526fn zhnone to void
5527note translated copies are retired: no route of either site may lie under a Chinese path
5528nr = sg NR
5529r = ulong 0
5530while lt r nr bound RTCAP
5531if zhpath r
5532b = mul r 8
5533put st CXO rg add b 2
5534put st CXL rg add b 3
5535die erzh
5536end
5537r = add r 1
5538end
5539end
5540
5541fn zurl r ulong to void
5542note the address of route r: its site's base and its path
5543b = mul r 8
5544if eq rg add b 1 0
5545ot tbase0
5546else
5547ot tbase1
5548end
5549om add rg add b 2 1 sub rg add b 3 1
5550end
5551
5552fn mfirst s ulong e ulong t view uchar * to ulong
5553note the first arena offset in s..e where the text t starts, e when there is none
5554i = s
5555while le add i len t e bound 16777216
5556if mistf i t false
5557ret i
5558end
5559i = add i 1
5560end
5561ret e
5562end
5563
5564fn mlast s ulong e ulong t view uchar * to ulong
5565note the last arena offset in s..e where the text t starts, e when there is none
5566if lt sub e s len t
5567ret e
5568end
5569i = sub e len t
5570while ge i s bound 16777216
5571if mistf i t false
5572ret i
5573end
5574if eq i s
5575ret e
5576end
5577i = sub i 1
5578end
5579ret e
5580end
5581
5582note ---- pages
5583
5584fn isdash i ulong e ulong to bool
5585if ne sub e i 3
5586ret false
5587end
5588ret and eq mg i 45 and eq mg add i 1 45 eq mg add i 2 45
5589end
5590
5591fn front off ulong n ulong to ulong
5592note one placeholder per "key: value" line; returns the offset of the body after the dashes line
5593lim = add off n
5594i = off
5595while lt i lim bound 200
5596e = eol i lim
5597if isdash i e
5598ret add e 1
5599end
5600c = i
5601while lt add c 1 e bound 16777216
5602if eq mg c 58
5603break
5604end
5605c = add c 1
5606end
5607if or eq c i or ge add c 2 e gt sub c i 40
5608die erfront
5609end
5610if ne mg add c 1 32
5611die erfront
5612end
5613setvm i sub c i add c 2 sub e add c 2
5614i = add e 1
5615end
5616die erfront
5617ret lim
5618end
5619
5620fn sitevars site ulong to void
5621if eq site 0
5622setv vip 0 0
5623setvt vismain vone
5624setv vishop 0 0
5625else
5626setvt vip vipurl
5627setv vismain 0 0
5628setvt vishop vone
5629end
5630end
5631
5632fn page r ulong to void
5633note assembles page route r into obuf
5634b = mul r 8
5635site = rg add b 1
5636put st PBL 0
5637pbaddm rg add b 4 rg add b 5
5638off = slurp
5639n = sg FLEN
5640body = front off n
5641setv vmain body sub add off n body
5642setv vroute rg add b 2 rg add b 3
5643put st OBN 0
5644if eq site 0
5645ot tbase0
5646else
5647ot tbase1
5648end
5649om add rg add b 2 1 sub rg add b 3 1
5650co = stash
5651setv vcanon co sg FLEN
5652sitevars site
5653if eq site 0
5654expand sg L0O sg L0N 0
5655else
5656expand sg L1O sg L1N 0
5657end
5658trpage r
5659end
5660
5661fn sitefont site ulong to bool
5662note the site builds at least one enabled font route
5663nr = sg NR
5664r = ulong 0
5665while lt r nr bound RTCAP
5666b = mul r 8
5667if and eq rg b 8 eq rg add b 1 site
5668if enabled r
5669ret true
5670end
5671end
5672r = add r 1
5673end
5674ret false
5675end
5676
5677fn omcss off ulong n ulong to void
5678note the stylesheet of a site that builds no font: every byte except each "@font-face{...}" block
5679note and the line feed after it, so it names no font the site leaves out; a block left open is refused
5680e = add off n
5681j = off
5682while lt j e bound 16777216
5683hit = false
5684if le add j len cface e
5685hit = mistf j cface false
5686end
5687if hit
5688k = add j len cface
5689while lt k e bound 16777216
5690if eq mg k 125
5691break
5692end
5693k = add k 1
5694end
5695if ge k e
5696die ercss
5697end
5698j = add k 1
5699if lt j e
5700if eq mg j 10
5701j = add j 1
5702end
5703end
5704else
5705ob mg j
5706j = add j 1
5707end
5708end
5709end
5710
5711fn produce r ulong to void
5712note obuf = the bytes of route r, assembled or copied, and checked
5713b = mul r 8
5714kind = rg add b 0
5715put st SITE rg add b 1
5716put st CXO rg add b 4
5717put st CXL rg add b 5
5718if eq kind 1
5719page r
5720else
5721put st PBL 0
5722pbaddm rg add b 4 rg add b 5
5723off = slurp
5724put st OBN 0
5725if or eq kind 6 eq kind 7
5726sitevars rg add b 1
5727expand off sg FLEN 0
5728else
5729if and eq kind 2 not sitefont rg add b 1
5730omcss off sg FLEN
5731else
5732om off sg FLEN
5733end
5734end
5735end
5736if insroute r
5737note the released installer is copied as it is and never scanned: its bytes must be the pinned ones
5738hasho
5739if not inspin
5740die erhins
5741end
5742ret
5743end
5744lint kind
5745omdlcopy r
5746end
5747
5748fn permchk r ulong to void
5749note the page at /contribute/ on interplane.io must tell the publisher that publishing is permanent
5750b = mul r 8
5751if or ne rg b 1 ne rg add b 1 0
5752ret
5753end
5754if not mist rg add b 2 rg add b 3 rcontrib
5755ret
5756end
5757if not ohas pperm
5758die erperm
5759end
5760put st PERM 1
5761end
5762
5763fn robotchk r ulong to void
5764note the crawl rules of interplane.io are pinned: the bytes that Radicle main 4968bc8 generated
5765b = mul r 8
5766if ne rg add b 1 0
5767ret
5768end
5769if ne rg add b 3 11
5770ret
5771end
5772ko = keep frobots
5773same = mcmp add rg add b 2 1 ko 10
5774put st TOP ko
5775if not same
5776ret
5777end
5778hasho
5779for j ulong 64
5780if ne get hx j get probots j
5781die errobot
5782end
5783end
5784end
5785
5786fn preflight to void
5787note assembles and checks every enabled route of both sites; nothing is written
5788nr = sg NR
5789r = ulong 0
5790while lt r nr bound RTCAP
5791if enabled r
5792put st NV sg NVB
5793put st TOP sg TOPB
5794produce r
5795robotchk r
5796permchk r
5797end
5798r = add r 1
5799end
5800put st NV sg NVB
5801put st TOP sg TOPB
5802put st CXL 0
5803if eq sg PERM 0
5804die erperm
5805end
5806end
5807
5808fn sitemap site ulong to void
5809put st OBN 0
5810ot s1
5811nr = sg NR
5812r = ulong 0
5813while lt r nr bound RTCAP
5814b = mul r 8
5815if eq rg add b 1 site
5816if or eq rg b 10 and or eq rg b 1 eq rg b 7 enabled r
5817ot s2
5818if eq site 0
5819ot tbase0
5820else
5821ot tbase1
5822end
5823om add rg add b 2 1 sub rg add b 3 1
5824ot s3
5825end
5826end
5827r = add r 1
5828end
5829ot s4
5830pbroot site
5831pbadd tslash
5832pbadd fsitemap
5833put st CXL 0
5834put st SITE site
5835lint 4
5836wrfile site
5837end
5838
5839fn payfirst k ulong po ulong to bool
5840note no earlier record names the payload at arena po
5841j = ulong 1
5842while lt j k bound 2000
5843sj = cg j
5844ej = eol sj add sj 1024
5845nj = split sj ej 9
5846if mcmp fg 10 po 64
5847ret false
5848end
5849j = add j 1
5850end
5851ret true
5852end
5853
5854fn paycopy po ulong to void
5855mark = sg TOP
5856pbset fpayd
5857pbaddm po 64
5858pbadd ftxt
5859put st CXO po
5860put st CXL 64
5861off = slurp
5862put st OBN 0
5863om off sg FLEN
5864put st TOP mark
5865lint 5
5866pbroot 0
5867pbadd tslash
5868pbadd fpayout
5869pbaddm po 64
5870pbadd ftxt
5871wrfile 0
5872end
5873
5874fn rcfiles to void
5875note copies the ledger and every payload file named in it, unchanged, into the main output
5876if eq sg FRC 0
5877ret
5878end
5879put st SITE 0
5880put st CXO keep fledger
5881put st CXL len fledger
5882put st OBN 0
5883om sg LDGO sg LDGN
5884lint 4
5885pbroot 0
5886pbadd tslash
5887pbadd fledout
5888wrfile 0
5889k = ulong 1
5890n = sg NREC
5891while le k n bound 2000
5892s = cg k
5893e = eol s add s 1024
5894nf = split s e 9
5895po = fg 10
5896if payfirst k po
5897paycopy po
5898end
5899k = add k 1
5900end
5901end
5902
5903fn mancmp site ulong to void
5904note verify: the manifest in the output equals, byte for byte, the one this source builds
5905m = sg MANL
5906pbroot site
5907pbadd tslash
5908pbadd fmanif
5909put st CXL 0
5910mark = sg TOP
5911off = slurp
5912same = eq sg FLEN m
5913if same
5914for j ulong m bound 524288
5915if ne mg add off j get man j
5916same = false
5917end
5918end
5919end
5920put st TOP mark
5921put st MANL 0
5922put st NFILE 0
5923put st NPAGE 0
5924if not same
5925put st CXO keep fmanif
5926put st CXL len fmanif
5927die erset
5928end
5929end
5930
5931fn manwrite site ulong to void
5932note writes manifest.sha256 (sha256sum -c format) and prints the site summary
5933if eq sg DRY 1
5934mancmp site
5935ret
5936end
5937put st OBN 0
5938m = sg MANL
5939for j ulong m bound 524288
5940ob get man j
5941end
5942hasho
5943pbroot site
5944pbadd tslash
5945pbadd fmanif
5946wrraw
5947if eq site 0
5948say mbuilt0
5949else
5950say mbuilt1
5951end
5952sayn sg NPAGE
5953say mfiles
5954sayn sg NFILE
5955say mmsha
5956sayhx
5957say tnl
5958put st MANL 0
5959put st NFILE 0
5960put st NPAGE 0
5961end
5962
5963fn mkroot site ulong to void
5964pbroot site
5965k = makedir pb 0 sg PBL 493
5966if ne k 0
5967put st CXL 0
5968die erdir
5969end
5970end
5971
5972fn writesite site ulong to void
5973note pass 1 for one site: every enabled route of that site, then generated files and the manifest
5974nr = sg NR
5975r = ulong 0
5976while lt r nr bound RTCAP
5977if eq rg add mul r 8 1 site
5978if enabled r
5979put st NV sg NVB
5980put st TOP sg TOPB
5981produce r
5982outpb r
5983wrfile site
5984if eq rg mul r 8 1
5985put st NPAGE add sg NPAGE 1
5986trforms r
5987end
5988end
5989end
5990r = add r 1
5991end
5992put st NV sg NVB
5993put st TOP sg TOPB
5994if eq site 0
5995rcfiles
5996end
5997if eq sg TESTD 1
5998put st OBN 0
5999ot ttestd
6000pbroot site
6001pbadd tslash
6002pbadd ftestd
6003put st CXL 0
6004put st SITE site
6005lint 4
6006wrfile site
6007end
6008sitemap site
6009manwrite site
6010end
6011
6012fn kindof s ulong e ulong site ulong to ulong
6013note check kind of an output path (arena s..e) by its ending
6014n = sub e s
6015if mist s n fllms
6016ret 6
6017end
6018if ge n 5
6019if mist sub e 5 5 xhtml
6020ret 1
6021end
6022end
6023if ge n 4
6024if mist sub e 4 4 xcss
6025ret 2
6026end
6027if mist sub e 4 4 xsvg
6028ret 3
6029end
6030end
6031if gt n 17
6032if mist s 17 fpayout
6033ret 5
6034end
6035end
6036if ge n 4
6037if mist sub e 4 4 xotf
6038ret 8
6039end
6040end
6041if ge n 4
6042if mist sub e 4 4 xpng
6043ret 9
6044end
6045end
6046if and eq site 0 gziprt s e
6047ret 11
6048end
6049ret 4
6050end
6051
6052
6053fn inman po ulong pl ulong dir bool to bool
6054note the manifest (arena st MNO..st MNL) names the file at arena po..po+pl, or, for a directory, a file inside it
6055lim = sg MNL
6056i = sg MNO
6057while lt i lim bound 100000
6058e = eol i lim
6059s = add i 66
6060n = sub e s
6061if dir
6062if gt n pl
6063if mcmp s po pl
6064if eq mg add s pl 47
6065ret true
6066end
6067end
6068end
6069else
6070if eq n pl
6071if mcmp s po pl
6072ret true
6073end
6074end
6075end
6076i = add e 1
6077end
6078ret false
6079end
6080
6081fn lsone site ulong ns ulong nl ulong ty uchar to void
6082note one directory entry (name at dbuf ns, length nl, type ty) of the directory st DRO, st DRL
6083dl = sg DRL
6084base = sg TOP
6085if gt add add base dl add nl 2 MEMSZ
6086die erfull
6087end
6088p = base
6089if gt dl 0
6090for j ulong dl bound 2048
6091put mem add p j mg add sg DRO j
6092end
6093p = add p dl
6094put mem p 47
6095p = add p 1
6096end
6097for j ulong nl bound 4096
6098put mem add p j get dbuf add ns j
6099end
6100p = add p nl
6101pl = sub p base
6102ok = false
6103if eq ty 8
6104ok = inman base pl false
6105if eq dl 0
6106if mist base pl fmanif
6107ok = true
6108end
6109end
6110end
6111if eq ty 4
6112ok = inman base pl true
6113end
6114if not ok
6115put st CXO base
6116put st CXL pl
6117die erset
6118end
6119end
6120
6121fn dnlen e ulong rl ulong to ulong
6122note length of the name in the getdents64 record at dbuf e, whose record length is rl
6123nl = ulong 0
6124while lt add 19 nl rl bound 4096
6125if eq get dbuf add add e 19 nl 0
6126break
6127end
6128nl = add nl 1
6129end
6130ret nl
6131end
6132
6133fn dotdir e ulong nl ulong to bool
6134note the entry is . or ..
6135if ne get dbuf add e 19 46
6136ret false
6137end
6138if eq nl 1
6139ret true
6140end
6141if eq nl 2
6142ret eq get dbuf add e 20 46
6143end
6144ret false
6145end
6146
6147fn lsrecs site ulong r ulong to void
6148note walks the getdents64 records in dbuf: inode 8, offset 8, record length 2, type 1, name ending in a zero
6149e = ulong 0
6150while lt e r bound 4097
6151lo = ulong get dbuf add e 16
6152hi = ulong get dbuf add e 17
6153rl = add lo mul hi 256
6154if or eq rl 0 gt add e rl r
6155die erset
6156end
6157nl = dnlen e rl
6158if not dotdir e nl
6159lsone site add e 19 nl get dbuf add e 18
6160end
6161e = add e rl
6162end
6163end
6164
6165fn lsdir site ulong to void
6166note every entry of one output directory is a file the manifest names or a directory that holds one.
6167note 49152 is O_RDONLY, O_DIRECTORY and O_NOFOLLOW on Linux AArch64.
6168pbroot site
6169if gt sg DRL 0
6170pbadd tslash
6171pbaddm sg DRO sg DRL
6172end
6173put st CXL 0
6174fd = fopen pb 0 sg PBL 49152 0
6175if lt fd 0
6176die erset
6177end
6178go = true
6179while go bound 100000
6180r = getdnts int fd dbuf 0 4096
6181if lt r 0
6182k = fclose int fd
6183die erset
6184end
6185if eq r 0
6186go = false
6187else
6188lsrecs site ulong r
6189end
6190end
6191k = fclose int fd
6192end
6193
6194fn lsall site ulong mo ulong lim ulong to void
6195note the root and every directory above a manifest entry; an entry the manifest does not explain refuses
6196put st MNO mo
6197put st MNL lim
6198put st DRO 0
6199put st DRL 0
6200lsdir site
6201i = mo
6202while lt i lim bound 100000
6203e = eol i lim
6204s = add i 66
6205j = s
6206while lt j e bound 2048
6207if eq mg j 47
6208put st DRO s
6209put st DRL sub j s
6210lsdir site
6211end
6212j = add j 1
6213end
6214i = add e 1
6215end
6216end
6217
6218fn rewalk to void
6219note walks the receipts chain again from the bytes in the output, with the evidence files in the output
6220put st TOP sg TOPB
6221put st CXO keep fledout
6222put st CXL len fledout
6223pbroot 0
6224pbadd tslash
6225pbadd fledout
6226off = slurp
6227n = sg FLEN
6228if ne mg sub add off n 1 10
6229rcsay 7 1
6230die erledg
6231end
6232put st PAYO 1
6233count = rcloop off add off n
6234put st PAYO 0
6235v = vlook vrhead
6236ho = vg add mul sub v 1 4 2
6237same = and eq count sg NREC phis ho add ho 64
6238put st TOP sg TOPB
6239put st CXL 0
6240note the record offsets go back to the source ledger, which the expected-manifest pass reads
6241count = rcloop sg LDGO add sg LDGO sg LDGN
6242if not same
6243die erledg
6244end
6245put st CXL 0
6246end
6247
6248fn nohop to void
6249note without Hop data there is no second site: an output directory for it is an extra
6250pbroot 1
6251fd = fopen pb 0 sg PBL 49152 0
6252if ge fd 0
6253k = fclose int fd
6254put st CXL 0
6255die erset
6256end
6257end
6258
6259fn versite site ulong to void
6260note re-reads the site's manifest and every file it names: digest, policy, links, fragments
6261put st SITE site
6262put st CXL 0
6263pbroot site
6264pbadd tslash
6265pbadd fmanif
6266mo = slurp
6267mn = sg FLEN
6268put st TOPB sg TOP
6269lim = add mo mn
6270files = ulong 0
6271i = mo
6272while lt i lim bound 100000
6273e = eol i lim
6274if lt sub e i 67
6275die erman
6276end
6277put st TOP sg TOPB
6278pbroot site
6279pbadd tslash
6280pbaddm add i 66 sub e add i 66
6281put st CXO add i 66
6282put st CXL sub e add i 66
6283off = slurp
6284n = sg FLEN
6285hashm off n
6286if not hxis i
6287die erman
6288end
6289put st OBN 0
6290om off n
6291put st TOP sg TOPB
6292if not insfile add i 66 e site
6293if not trformpath add i 66 e
6294lint kindof add i 66 e site
6295end
6296end
6297files = add files 1
6298i = add e 1
6299end
6300if eq files 0
6301die erman
6302end
6303put st TOP sg TOPB
6304lsall site mo lim
6305if eq site 0
6306if eq sg FRC 1
6307rewalk
6308end
6309end
6310if eq site 0
6311say mver0
6312else
6313say mver1
6314end
6315sayn files
6316say tnl
6317end
6318
6319note ---- commands
6320
6321fn argis t view uchar * n ulong to bool
6322if ne n len t
6323ret false
6324end
6325for j ulong n bound 64
6326if ne get arg j get t j
6327ret false
6328end
6329end
6330ret true
6331end
6332
6333fn rootok n ulong site ulong to void
6334note the output path has no space, backslash or dot-dot and does not end in a slash
6335for j ulong n bound 512
6336c = uchar 0
6337if eq site 0
6338c = get root0 j
6339else
6340c = get root1 j
6341end
6342if or le c 32 eq c 92
6343die erarg
6344end
6345if eq c 46
6346if lt add j 1 n
6347d = uchar 0
6348if eq site 0
6349d = get root0 add j 1
6350else
6351d = get root1 add j 1
6352end
6353if eq d 46
6354die erarg
6355end
6356end
6357end
6358if eq add j 1 n
6359if eq c 47
6360die erarg
6361end
6362end
6363end
6364end
6365
6366fn rootargs to void
6367note the two output directories follow the command, or the --test-data flag when it is given
6368k = argread 2 root0 0 512
6369if eq sg TESTD 1
6370k = argread 3 root0 0 512
6371end
6372if or le k 0 ge k 500
6373die erarg
6374end
6375put st R0L ulong k
6376rootok ulong k 0
6377k = argread 3 root1 0 512
6378if eq sg TESTD 1
6379k = argread 4 root1 0 512
6380end
6381if or le k 0 ge k 500
6382die erarg
6383end
6384put st R1L ulong k
6385rootok ulong k 1
6386end
6387
6388fn omtxt off ulong n ulong to void
6389note copies arena text into obuf for a plain-text file: the trade mark entity becomes (TM)
6390i = ulong 0
6391while lt i n bound 8192
6392tm = false
6393if le add i 7 n
6394tm = mistf add off i ptrade false
6395end
6396if tm
6397ot ttm
6398i = add i 7
6399else
6400ob mg add off i
6401i = add i 1
6402end
6403end
6404end
6405
6406fn pageline r ulong to void
6407note one llms.txt line for page route r: - [title](address): description
6408b = mul r 8
6409put st PBL 0
6410pbaddm rg add b 4 rg add b 5
6411put st CXO rg add b 4
6412put st CXL rg add b 5
6413off = slurp
6414body = front off sg FLEN
6415t = vlook vtitle
6416d = vlook vdesc
6417if or eq t 0 eq d 0
6418die erfront
6419end
6420ot pl1
6421tb = mul sub t 1 4
6422omtxt vg add tb 2 vg add tb 3
6423ot pl2
6424ot tbase0
6425om add rg add b 2 1 sub rg add b 3 1
6426ot pl3
6427db = mul sub d 1 4
6428omtxt vg add db 2 vg add db 3
6429ob 10
6430end
6431
6432fn pagelist to void
6433note the placeholder pages: every enabled interplane.io page, in routes order
6434put st OBN 0
6435nr = sg NR
6436r = ulong 0
6437while lt r nr bound RTCAP
6438b = mul r 8
6439if and eq rg b 1 eq rg add b 1 0
6440if enabled r
6441mark = sg TOP
6442nv = sg NV
6443pageline r
6444put st TOP mark
6445put st NV nv
6446end
6447end
6448r = add r 1
6449end
6450po = stash
6451setv vpages po sg FLEN
6452end
6453
6454fn agentprompts to void
6455note Bind each plain-text prompt route as a template variable without the leading slash.
6456note Mode 6 excludes HTML and template delimiters so the displayed text stays literal.
6457for r ulong sg NR bound RTCAP
6458b = mul r 8
6459ro = rg add b 2
6460rl = rg add b 3
6461if and eq rg b 4 eq rg add b 1 0
6462if and gt rl len promptdir mistf ro promptdir false
6463if enabled r
6464so = rg add b 4
6465sl = rg add b 5
6466put st CXO so
6467put st CXL sl
6468put st PBL 0
6469pbaddm so sl
6470off = slurp
6471e = sub add off sg FLEN 1
6472if not and eq mg e 10 okset off e 6
6473die erprompt
6474end
6475setvm add ro 1 sub rl 1 off sub e off
6476end
6477end
6478end
6479end
6480end
6481
6482fn setup to void
6483note loads everything a build or a verify needs: data, flags, layouts and routes
6484luminit
6485put st TOP 0
6486put st NV 0
6487put st CXL 0
6488if eq sg TESTD 1
6489setvt ktestd vone
6490say mtest
6491end
6492yard
6493papers
6494receipts
6495hop
6496live
6497routes
6498agentprompts
6499omdownloads
6500zhnone
6501pbset flay0
6502put st CXO keep flay0
6503put st CXL len flay0
6504lo = slurp
6505put st L0O lo
6506put st L0N sg FLEN
6507pbset flay1
6508put st CXO keep flay1
6509put st CXL len flay1
6510lo = slurp
6511put st L1O lo
6512put st L1N sg FLEN
6513put st CXL 0
6514pagelist
6515put st CXL 0
6516put st NVB sg NV
6517put st TOPB sg TOP
6518end
6519
6520fn dobuild to void
6521rootargs
6522setup
6523cssload
6524contrast
6525put st LCHK 0
6526preflight
6527mkroot 0
6528writesite 0
6529if eq sg FHOP 1
6530mkroot 1
6531writesite 1
6532end
6533put st LCHK 1
6534versite 0
6535if eq sg FHOP 1
6536versite 1
6537end
6538say mbpass
6539end
6540
6541fn doverify to void
6542rootargs
6543setup
6544put st LCHK 1
6545versite 0
6546if eq sg FHOP 1
6547versite 1
6548else
6549nohop
6550end
6551note the expected manifest of each site, rebuilt from the source without writing, equals the one found
6552put st LCHK 0
6553put st DRY 1
6554put st MANL 0
6555put st NFILE 0
6556put st NPAGE 0
6557writesite 0
6558if eq sg FHOP 1
6559writesite 1
6560end
6561put st DRY 0
6562say mvpass
6563end
6564
6565fn main to int
6566ac = argcnt
6567if lt ac 2
6568say tusage
6569ret 2
6570end
6571n = argread 1 arg 0 64
6572if le n 0
6573say tusage
6574ret 2
6575end
6576if argis trcgate ulong n
6577if ne ac 3
6578ret 2
6579end
6580trcli
6581ret 0
6582end
6583if argis trcsp ulong n
6584if ne ac 3
6585ret 2
6586end
6587trheaders
6588ret 0
6589end
6590if argis ccontr ulong n
6591if ne ac 2
6592say tusage
6593ret 2
6594end
6595luminit
6596put st TOP 0
6597put st CXL 0
6598cssload
6599contrast
6600ret 0
6601end
6602cmd = ulong 0
6603if argis cbuild ulong n
6604cmd = 1
6605end
6606if argis cverify ulong n
6607cmd = 2
6608end
6609if eq cmd 0
6610say tusage
6611ret 2
6612end
6613put st TESTD 0
6614put st DRY 0
6615put st PAYO 0
6616if eq ac 5
6617n = argread 2 arg 0 64
6618if le n 0
6619say tusage
6620ret 2
6621end
6622if not argis ctestd ulong n
6623say tusage
6624ret 2
6625end
6626put st TESTD 1
6627else
6628if ne ac 4
6629say tusage
6630ret 2
6631end
6632end
6633if eq cmd 1
6634dobuild
6635else
6636doverify
6637end
6638ret 0
6639end