interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / server / chromegen.om

561 lines · 12529 bytes Raw Blame History
1om2
2note server/chromegen.om: makes the forge's copy of the interplane.io site chrome from the site's own
3note source, at every build (run.sh units runs it), so a site change never needs a hand copy.
4note stdin: content/_layout.html, a 0 byte, public/style.css, a 0 byte, the site commit (40 hex).
5note stdout: one Omega unit (texts tchrsite, tchrhead, tchrfoot, tchrcss) that server/pages.om writes:
6note tchrhead <header class="site-head"> .. </header> of the layout, release build: {{#flag}} and
7note {{/flag}} marks dropped (the optional data is present on interplane.io), every
8note site-relative href or src made absolute (https://interplane.io/...), and the one link
9note to https://interplane.io/explore marked aria-current="true" (Forge is the section);
10note translate="no" attributes left out: forged adds its hints when it sends a page
11note (server/tr.om, class brand and others), so a page in fob holds none and its size is exact
12note tchrfoot the footer lines after <footer class="site-foot"><div class="shell"> up to the first
13note <p class="foot-fine"> line (the forge writes its own fine print), the same way
14note tchrcss the site's :root line, then between the marks of server/tests/sitechrome.sh every
15note style.css rule line that styles the header or footer (the rule below, the same one
16note sitechrome.sh checks) inside its @-block, in the site's order
17note Chrome rule: a line that starts with a base selector (*, html, body, a, a:hover, a:active,
18note a:focus-visible,summary:focus-visible, code,pre,.mono) and "{", or names one of the classes
19note site-head head-row brand site-foot foot-<a-z> si-line skip shell (not followed by a-z or -), or
20note .button, .button.dark or .button.small before ":" or "{"; left out: nav.short, main p:where,
21note .invite .button, .actions .button, .hop-stage (page rules), a one-line @media print rule, and
22note @-blocks naming
23note prefers-reduced-motion.
24note Refusals (stderr names the reason, stdout is empty): exit 2 input shape, 3 header or footer
25note not found, 4 a {{ mark other than {{#..}} or {{/..}} in them, 5 no single Forge link, 6 no :root
26note first line, 7 a control byte other than a line feed, 8 fewer than 30 chrome lines, 9 output.
27note The input and output buffers are 16 MiB each (the largest pool omc allows); the site files are
28note about 40 KB. A larger input is refused with exit 2, never cut.
29global cgi uchar 16777216
30global cgn ulong 1
31global cgo uchar 16777216
32global cgl ulong 1
33note the three parts of the input: layout [0, cgp 1), style [cgp 2, cgp 3), sha [cgp 4, cgn)
34global cgp ulong 5
35note the current @-block: its line (start, end) and whether it was written yet
36global cgb ulong 3
37global cgcur ulong 1
38text thd "<header class=\"site-head\">"
39text the "</header>"
40text tfo "<footer class=\"site-foot\"><div class=\"shell\">"
41text tff "<p class=\"foot-fine\">"
42text thref "href=\"/"
43text tsrc "src=\"/"
44text tsite "https://interplane.io"
45text tforge "<a href=\"https://interplane.io/explore\""
46text tcur " aria-current=\"true\""
47text thint " translate=\"no\""
48text troot ":root{"
49text tm1 "/* site chrome: copied from interplane.io public/style.css */\n"
50text tm2 "/* end site chrome */\n"
51text tqe "\"\n"
52text tn1 "note server/chrome.om: GENERATED by server/chromegen.om at build (run.sh units) from interplane.io\n"
53text tn2 "note content/_layout.html and public/style.css at the site commit in tchrsite. Not in git; do not edit.\n"
54text ts1 "text tchrsite \""
55text ts2 "text tchrhead \""
56text ts3 "text tchrfoot \""
57text ts4 "text tchrcss \""
58text tbs1 "*{"
59text tbs2 "html{"
60text tbs3 "body{"
61text tbs4 "a{"
62text tbs5 "a:hover{"
63text tbs6 "a:active{"
64text tbs7 "a:focus-visible,summary:focus-visible{"
65text tbs8 "code,pre,.mono{"
66text tcl1 "site-head"
67text tcl2 "head-row"
68text tcl3 "brand"
69text tcl4 "site-foot"
70text tcl5 "si-line"
71text tcl6 "skip"
72text tcl7 "shell"
73text tcl8 "foot-"
74text tbtn "button"
75text tdark ".dark"
76text tsmall ".small"
77text tsk1 "nav.short"
78text tsk2 "main p:where"
79text tsk3 ".invite .button"
80text tsk4 ".actions .button"
81text tsk5 ".hop-stage "
82text tsk6 "@media print"
83text tskin "prefers-reduced-motion"
84text te2 "chromegen: input is not layout, NUL, style, NUL, commit (or larger than 16 MiB)\n"
85text te3 "chromegen: the layout has no <header class=\"site-head\"> .. </header>, or no footer line <footer class=\"site-foot\"><div class=\"shell\"> followed by a <p class=\"foot-fine\"> line\n"
86text te4 "chromegen: the site header or footer holds a {{ mark other than {{#name}} or {{/name}}; teach server/chromegen.om what the release build does with it\n"
87text te5 "chromegen: the site header does not hold exactly one <a href=\"https://interplane.io/explore\"> (the Forge entry)\n"
88text te6 "chromegen: the first line of public/style.css is not the :root token line\n"
89text te7 "chromegen: a control byte other than a line feed in the copied header, footer or stylesheet lines\n"
90text te8 "chromegen: fewer than 30 chrome rule lines found in public/style.css; the rule above no longer fits the site\n"
91text te9 "chromegen: the output did not fit or could not be written\n"
92fn cgdie code ulong t view uchar * to void
93w = write 2 t 0 len t
94exit int code
95end
96fn cgc c uchar to void
97n = get cgl 0
98if ge n len cgo
99cgdie 9 te9
100end
101put cgo n c
102put cgl 0 add n 1
103end
104fn cgt t view uchar * to void
105for i ulong len t bound 4096
106cgc get t i
107end
108end
109note cge: one byte of an Omega text literal
110fn cge c uchar to void
111if eq c 10
112cgc 92
113cgc 110
114ret
115end
116if eq c 9
117cgc 92
118cgc 116
119ret
120end
121if lt c 32
122cgdie 7 te7
123end
124if eq c 127
125cgdie 7 te7
126end
127if or eq c 34 eq c 92
128cgc 92
129end
130cgc c
131end
132note cgat: cgi[p, e) starts with t
133fn cgat p ulong e ulong t view uchar * to bool
134if gt add p len t e
135ret false
136end
137for i ulong len t bound 4096
138if ne get cgi add p i get t i
139ret false
140end
141end
142ret true
143end
144note cgfind: the first p in [a, e) where t starts, or e
145fn cgfind a ulong e ulong t view uchar * to ulong
146p = a
147while lt p e bound 16777216
148if cgat p e t
149ret p
150end
151p = add p 1
152end
153ret e
154end
155fn cglow c uchar to bool
156ret and ge c 97 le c 122
157end
158fn cgname c uchar to bool
159ret or cglow c eq c 45
160end
161note ---- the layout parts
162note cgmark: at cgi[p] a {{ mark; returns its end (after the }}) for {{#name}} or {{/name}}, refuses others
163fn cgmark p ulong e ulong to ulong
164q = add p 2
165if ge q e
166cgdie 4 te4
167end
168c = get cgi q
169if and ne c 35 ne c 47
170cgdie 4 te4
171end
172q = add q 1
173s = q
174while lt q e bound 16777216
175c = get cgi q
176if not or cglow c eq c 95
177break
178end
179q = add q 1
180end
181if or eq q s gt add q 2 e
182cgdie 4 te4
183end
184if or ne get cgi q 125 ne get cgi add q 1 125
185cgdie 4 te4
186end
187ret add q 2
188end
189note cgpart: cgi[a, e) as the release build writes it, escaped into the output; returns the count of
190note Forge links it marked current (when cur)
191fn cgpart a ulong e ulong cur bool to ulong
192n = ulong 0
193p = a
194while lt p e bound 16777216
195if and eq get cgi p 123 lt add p 1 e
196if eq get cgi add p 1 123
197p = cgmark p e
198continue
199end
200end
201if cgat p e thint
202p = add p len thint
203continue
204end
205if and cur cgat p e tforge
206for i ulong len tforge
207cge get tforge i
208end
209for i ulong len tcur
210cge get tcur i
211end
212p = add p len tforge
213n = add n 1
214continue
215end
216k = ulong 0
217if cgat p e thref
218k = len thref
219end
220if cgat p e tsrc
221k = len tsrc
222end
223if gt k 0
224r = sub add p k 1
225if or ge add r 1 e ne get cgi add r 1 47
226for i ulong sub k 1
227cge get cgi add p i
228end
229for i ulong len tsite
230cge get tsite i
231end
232p = r
233continue
234end
235end
236cge get cgi p
237p = add p 1
238end
239ret n
240end
241note ---- the stylesheet
242note cglst: [s, e) is a line of the stylesheet; true when it is a block line "@..{" with no "}"
243fn cgopen s ulong e ulong to bool
244if or ge s e ne get cgi s 64
245ret false
246end
247if ne get cgi sub e 1 123
248ret false
249end
250for i ulong sub e s bound 16777216
251if eq get cgi add s i 125
252ret false
253end
254end
255ret true
256end
257fn cgclose s ulong e ulong to bool
258if ge s e
259ret false
260end
261for i ulong sub e s bound 16777216
262if ne get cgi add s i 125
263ret false
264end
265end
266ret true
267end
268note cgcls: at p a class name t followed by a byte that is not a-z or -, or the line end
269fn cgcls p ulong e ulong t view uchar * to bool
270if not cgat p e t
271ret false
272end
273q = add p len t
274if ge q e
275ret true
276end
277ret not cgname get cgi q
278end
279fn cgfoot p ulong e ulong to bool
280if not cgat p e tcl8
281ret false
282end
283q = add p len tcl8
284s = q
285while lt q e bound 16777216
286if not cglow get cgi q
287break
288end
289q = add q 1
290end
291if eq q s
292ret false
293end
294if ge q e
295ret true
296end
297ret ne get cgi q 45
298end
299fn cgbtn p ulong e ulong to bool
300if not cgat p e tbtn
301ret false
302end
303q = add p len tbtn
304if cgat q e tdark
305q = add q len tdark
306else
307if cgat q e tsmall
308q = add q len tsmall
309end
310end
311if ge q e
312ret false
313end
314c = get cgi q
315if or eq c 58 eq c 123
316ret true
317end
318q = add p len tbtn
319if ge q e
320ret false
321end
322c = get cgi q
323ret or eq c 58 eq c 123
324end
325fn cgbase s ulong e ulong to bool
326if or cgat s e tbs1 or cgat s e tbs2 cgat s e tbs3
327ret true
328end
329if or cgat s e tbs4 or cgat s e tbs5 cgat s e tbs6
330ret true
331end
332ret or cgat s e tbs7 cgat s e tbs8
333end
334note cgsel: the rule line [s, e) styles the header or footer (the chrome rule in the notes above)
335fn cgsel s ulong e ulong to bool
336if lt cgfind s e tsk1 e
337ret false
338end
339if or cgat s e tsk2 or cgat s e tsk3 or cgat s e tsk4 cgat s e tsk5
340ret false
341end
342if cgat s e tsk6
343ret false
344end
345if cgbase s e
346ret true
347end
348p = s
349while lt p e bound 16777216
350if eq get cgi p 46
351q = add p 1
352if or cgcls q e tcl1 or cgcls q e tcl2 or cgcls q e tcl3 cgcls q e tcl4
353ret true
354end
355if or cgcls q e tcl5 or cgcls q e tcl6 or cgcls q e tcl7 cgfoot q e
356ret true
357end
358if cgbtn q e
359ret true
360end
361end
362p = add p 1
363end
364ret false
365end
366fn cgline s ulong e ulong to void
367for i ulong sub e s bound 16777216
368cge get cgi add s i
369end
370cge 10
371end
372note cgcss: the :root line, the marks and the chrome rule lines; returns the count of rule lines
373fn cgcss a ulong e ulong to ulong
374x = a
375while lt x e bound 16777216
376if eq get cgi x 10
377break
378end
379x = add x 1
380end
381if not cgat a x troot
382cgdie 6 te6
383end
384cgline a x
385for i ulong len tm1
386cge get tm1 i
387end
388put cgcur 0 0
389put cgb 2 0
390n = ulong 0
391s = add x 1
392while lt s e bound 16777216
393l = s
394while lt l e bound 16777216
395if eq get cgi l 10
396break
397end
398l = add l 1
399end
400if cgopen s l
401put cgb 0 s
402put cgb 1 l
403put cgb 2 0
404put cgcur 0 1
405else
406if cgclose s l
407if and eq get cgcur 0 1 eq get cgb 2 1
408cgline s l
409end
410put cgcur 0 0
411put cgb 2 0
412else
413if cgsel s l
414sk = false
415if eq get cgcur 0 1
416sk = lt cgfind get cgb 0 get cgb 1 tskin get cgb 1
417end
418if not sk
419if and eq get cgcur 0 1 eq get cgb 2 0
420cgline get cgb 0 get cgb 1
421put cgb 2 1
422end
423cgline s l
424n = add n 1
425end
426end
427end
428end
429s = add l 1
430end
431for i ulong len tm2
432cge get tm2 i
433end
434ret n
435end
436fn main to int
437cgreadin
438cgsplit
439cgsha
440cghead
441cgfootp
442cgt ts4
443m = cgcss add get cgp 1 1 get cgp 2
444cgt tqe
445if lt m 30
446cgdie 8 te8
447end
448w = write 1 cgo 0 get cgl 0
449if ne w long get cgl 0
450cgdie 9 te9
451end
452ret 0
453end
454fn cgreadin to void
455n = ulong 0
456while lt n len cgi bound 16777216
457r = read 0 cgi n sub len cgi n
458if lt r 0
459if eq r -4
460continue
461end
462cgdie 2 te2
463end
464if eq r 0
465break
466end
467n = add n ulong r
468end
469if ge n len cgi
470cgdie 2 te2
471end
472put cgn 0 n
473end
474note cgsplit: the two 0 bytes into cgp 1 and cgp 2
475fn cgsplit to void
476n = get cgn 0
477k = ulong 0
478for i ulong n bound 16777216
479if eq get cgi i 0
480if ge k 2
481cgdie 2 te2
482end
483put cgp add k 1 i
484k = add k 1
485end
486end
487if ne k 2
488cgdie 2 te2
489end
490end
491fn cgisx c uchar to bool
492if and ge c 48 le c 57
493ret true
494end
495ret and ge c 97 le c 102
496end
497note cgsha: the third part is 40 lowercase hex (a trailing line feed allowed); writes tchrsite and the notes
498fn cgsha to void
499ha = add get cgp 2 1
500he = get cgn 0
501while gt he ha bound 16777216
502if ne get cgi sub he 1 10
503break
504end
505he = sub he 1
506end
507if ne sub he ha 40
508cgdie 2 te2
509end
510for i ulong 40
511if not cgisx get cgi add ha i
512cgdie 2 te2
513end
514end
515cgt tn1
516cgt tn2
517cgt ts1
518for i ulong 40
519cgc get cgi add ha i
520end
521cgt tqe
522end
523note cghead: from the header's opening tag to the end of </header>
524fn cghead to void
525lz = get cgp 1
526h0 = cgfind 0 lz thd
527h1 = cgfind h0 lz the
528if or ge h0 lz ge h1 lz
529cgdie 3 te3
530end
531cgt ts2
532m = cgpart h0 add h1 len the true
533cge 10
534cgt tqe
535if ne m 1
536cgdie 5 te5
537end
538end
539note cgfootp: the lines after the footer opening line, before the first fine-print line
540fn cgfootp to void
541lz = get cgp 1
542f0 = cgfind 0 lz tfo
543if ge f0 lz
544cgdie 3 te3
545end
546f1 = cgfind f0 lz tff
547fa = add f0 len tfo
548if or ge f1 lz ge fa lz
549cgdie 3 te3
550end
551if ne get cgi fa 10
552cgdie 3 te3
553end
554fa = add fa 1
555if or le f1 fa ne get cgi sub f1 1 10
556cgdie 3 te3
557end
558cgt ts3
559m = cgpart fa f1 false
560cgt tqe
561end