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 / tr.om

1022 lines · 21053 bytes Raw Blame History
1note forged server/tr.om (TranslateConnector, 2026-11-11): translation hints on every HTML page.
2note Readers translate pages with their own browser or tool; forged translates nothing and stores no
3note translation. This unit only marks what must be copied exactly, so a translator leaves it alone:
4note 1. every opening code, pre, kbd and samp tag, and every tag whose class names the token mono,
5note files, file, dir, crumbs (paths), brand (the Interplane name) or rname (a project name in a
6note list), gets translate="no" (unless it already has a translate attribute);
7note 2. in text outside tags, a word that is a hex hash (7 or more of 0-9 a-f, at least one digit) or
8note a Radicle id (z then 28 or more base58 letters with a digit and a capital) is wrapped in
9note <span translate="no">...</span>; "rad:" or "did:key:" before an id stays outside the span.
10note Text inside title, textarea, option, script and style is copied unchanged.
11note fsend0 (server/main.om) runs ftrrun twice over each part of the page (head, fragment, foot): mode 0 counts the
12note bytes for Content-Length, mode 1 sends them through a 32 KiB chunk. Both passes run the same
13note code, so the length always matches the body. Gate: server/tests/translate.sh.
14note ftrq: 0 chunk fill, 1 bytes counted, 2 mode (0 count, 1 send), 3 raw element open (1 or 0)
15global ftrq ulong 4
16note ftrer: the first negative hput result of a send pass, else 0
17global ftrer long 1
18text tftrno " translate=\"no\""
19text tftrsp "<span translate=\"no\">"
20text tftrse "</span>"
21text tftrat " translate="
22text tftrcl "class=\""
23text tftrcod "code"
24text tftrpre "pre"
25text tftrkbd "kbd"
26text tftrsmp "samp"
27text tftrmon "mono"
28text tftrfil "files"
29text tftrbrd "brand"
30text tftrrnm "rname"
31text tftrcrm "crumbs"
32text tftrfle "file"
33text tftrdir "dir"
34text tftrtit "title"
35text tftrtxa "textarea"
36text tftropt "option"
37text tftrscr "script"
38text tftrsty "style"
39text tftrcm "-->"
40fn ftrfl cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 n ulong to void
41r = hput cs io view part ch 0 n
42if lt r 0
43if eq get ftrer 0 0
44put ftrer 0 r
45end
46end
47end
48fn ftrb cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 b uchar to void
49put ftrq 1 add get ftrq 1 1
50if eq get ftrq 2 0
51ret
52end
53p = get ftrq 0
54put ch p b
55p = add p 1
56if eq p 32768
57ftrfl cs io ch p
58p = ulong 0
59end
60put ftrq 0 p
61end
62note ftrcp: emit fob[a, e)
63fn ftrcp cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 a ulong e ulong to void
64k = a
65while lt k e bound 8388608
66ftrb cs io ch get fob k
67k = add k 1
68end
69end
70fn ftrt cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 s view uchar * to void
71for k ulong len s bound 4096
72ftrb cs io ch get s k
73end
74end
75fn ftrdig c uchar to bool
76ret and ge c 48 le c 57
77end
78fn ftrlow c uchar to bool
79ret and ge c 97 le c 122
80end
81fn ftrup c uchar to bool
82ret and ge c 65 le c 90
83end
84fn ftralnum c uchar to bool
85ret or ftrdig c or ftrlow c ftrup c
86end
87fn ftrhex c uchar to bool
88ret or ftrdig c and ge c 97 le c 102
89end
90note base58: letters and digits except 0 O I l
91fn ftrb58 c uchar to bool
92x = or or eq c 48 eq c 79 or eq c 73 eq c 108
93ret and ftralnum c not x
94end
95note ftrat: fob[a, a + len s) equals s, inside fob[0, e)
96fn ftrat a ulong e ulong s view uchar * to bool
97n = len s
98if gt add a n e
99ret false
100end
101for k ulong n bound 4096
102if ne get fob add a k get s k
103ret false
104end
105end
106ret true
107end
108note ftrfind: first index in [a, e) where s starts and ends before e, else e
109fn ftrfind a ulong e ulong s view uchar * to ulong
110k = a
111while lt k e bound 8388608
112if ftrat k e s
113ret k
114end
115k = add k 1
116end
117ret e
118end
119note ftrnm: fob[a, e) is exactly s
120fn ftrnm a ulong e ulong s view uchar * to bool
121if ne sub e a len s
122ret false
123end
124ret ftrat a e s
125end
126note ftrcls: the tag fob[a, e) has class="..." with a token that must stay exact
127fn ftrcls a ulong e ulong to bool
128c = ftrfind a e tftrcl
129if ge c e
130ret false
131end
132k = add c 7
133s = k
134while lt k e bound 8388608
135b = get fob k
136if or eq b 34 eq b 32
137if ftrnm s k tftrcrm
138ret true
139end
140if ftrnm s k tftrfle
141ret true
142end
143if ftrnm s k tftrdir
144ret true
145end
146if or or ftrnm s k tftrmon ftrnm s k tftrfil or ftrnm s k tftrbrd ftrnm s k tftrrnm
147ret true
148end
149if eq b 34
150ret false
151end
152s = add k 1
153end
154k = add k 1
155end
156ret false
157end
158note ftrnotr: the opening tag named fob[a, n), ending at e, gets translate="no"
159fn ftrnotr a ulong n ulong e ulong to bool
160if lt ftrfind n e tftrat e
161ret false
162end
163c = or or ftrnm a n tftrcod ftrnm a n tftrpre or ftrnm a n tftrkbd ftrnm a n tftrsmp
164ret or c ftrcls n e
165end
166fn ftrraw a ulong n ulong to bool
167c = or or ftrnm a n tftrtit ftrnm a n tftrtxa or ftrnm a n tftropt ftrnm a n tftrscr
168ret or c ftrnm a n tftrsty
169end
170note ftrcmt: fob[j] starts "!--" (j is the byte after '<')
171fn ftrcmt j ulong l ulong to bool
172if ge add j 2 l
173ret false
174end
175if ne get fob j 33
176ret false
177end
178if ne get fob add j 1 45
179ret false
180end
181ret eq get fob add j 2 45
182end
183note ftrtend: the index after the tag that starts at fob[i] = '<': a comment ends after "-->", any
184note other tag after '>'; l when it does not end before l
185fn ftrtend i ulong l ulong to ulong
186j = add i 1
187if ge j l
188ret l
189end
190if ftrcmt j l
191e = ftrfind add j 3 l tftrcm
192ret hmin l add e 3
193end
194e = j
195while lt e l bound 8388608
196if eq get fob e 62
197ret add e 1
198end
199e = add e 1
200end
201ret l
202end
203note ftrnend: the end of the tag name that starts at a (letters and digits)
204fn ftrnend a ulong e ulong to ulong
205n = a
206while lt n e bound 8388608
207if not ftralnum get fob n
208ret n
209end
210n = add n 1
211end
212ret n
213end
214note ftrtag: fob[i] is '<'; emit the tag and return the index after it. A comment, a declaration,
215note a closing tag or a tag cut by l is copied as it is.
216fn ftrtag cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 i ulong l ulong to ulong
217e = ftrtend i l
218j = add i 1
219if or ge j e ne get fob sub e 1 62
220ftrcp cs io ch i e
221ret e
222end
223if eq get fob j 47
224if ftrraw add j 1 ftrnend add j 1 e
225put ftrq 3 0
226end
227ftrcp cs io ch i e
228ret e
229end
230n = ftrnend j e
231if or eq n j ftrcmt j l
232ftrcp cs io ch i e
233ret e
234end
235if ftrraw j n
236put ftrq 3 1
237end
238ftrcp cs io ch i n
239if ftrnotr j n e
240ftrt cs io ch tftrno
241end
242ftrcp cs io ch n e
243ret e
244end
245fn ftrwc c uchar to bool
246ret ftralnum c
247end
248note ftrid: the word fob[s, e) is a hash or a Radicle id
249fn ftrid s ulong e ulong to bool
250a = s
251n = sub e a
252if lt n 7
253ret false
254end
255hx = true
256dg = false
257b58 = true
258up = false
259k = a
260while lt k e bound 8388608
261c = get fob k
262if not ftrhex c
263hx = false
264end
265if not ftrb58 c
266b58 = false
267end
268if ftrdig c
269dg = true
270end
271if ftrup c
272up = true
273end
274k = add k 1
275end
276if and hx dg
277ret true
278end
279if ne get fob a 122
280ret false
281end
282ok = and b58 ge n 29
283ret and ok and dg up
284end
285note ftrtxt: emit the text from fob[i] up to the next '<' (or l); return where it stopped
286fn ftrtxt cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 i ulong l ulong to ulong
287k = i
288while lt k l bound 8388608
289c = get fob k
290if eq c 60
291ret k
292end
293if not ftrwc c
294ftrb cs io ch c
295k = add k 1
296continue
297end
298s = k
299while lt k l bound 8388608
300if not ftrwc get fob k
301break
302end
303k = add k 1
304end
305e = k
306while gt e s bound 8388608
307if ne get fob sub e 1 58
308break
309end
310e = sub e 1
311end
312if and eq get ftrq 3 0 ftrid s e
313ftrt cs io ch tftrsp
314ftrcp cs io ch s e
315ftrt cs io ch tftrse
316ftrcp cs io ch e k
317else
318ftrcp cs io ch s k
319end
320end
321ret k
322end
323note ftrrun: mode 0 returns the byte count of the marked range fob[a, e); mode 1 sends it and
324note returns 0 or the first negative hput result
325fn ftrrun cs edit ulong 320 io edit uchar 131072 a ulong e ulong mode ulong to long
326ch = new uchar 32768 0
327put ftrq 0 0
328put ftrq 1 0
329put ftrq 2 mode
330put ftrq 3 0
331put ftrer 0 0
332i = a
333while lt i e bound 8388608
334if eq get fob i 60
335i = ftrtag cs io ch i e
336else
337i = ftrtxt cs io ch i e
338end
339end
340if eq mode 0
341ret long get ftrq 1
342end
343if gt get ftrq 0 0
344ftrfl cs io ch get ftrq 0
345end
346ret get ftrer 0
347end
348note ---- plain-text rendering: any HTML page with the query format=text (docs/API.md). The page's
349note own content (no site header or footer) as text for reading tools and agents that translate it
350note themselves. Inline code and the hashes and ids found above are in backticks, pre blocks in ```
351note fences, a link's target follows its text in <...>; nothing is translated or stored here.
352note ftxs: 0 last byte, 1 pre depth, 2 pending space, 3 link start, 4 skipped element depth,
353note 5 newlines in a row, 6 code depth, 7 link end, 8 end of the tag ftxel acts on, 9 inside a
354note span of class mono (sent as inline code)
355global ftxs ulong 10
356global ftxcrm ulong 1
357note ftxfil: 0 outside a files table, 1 inside it between cells, 2 inside one of its cells;
358note ftxfsp: one space owed before the next byte of a files-table cell (a new cell or a link target)
359global ftxfil ulong 1
360global ftxfsp ulong 1
361text tftxct "text/plain; charset=utf-8"
362text tftxfmt "format"
363text tftxval "text"
364text tftxpre "Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.\nPage: "
365text tftxfen "```"
366text tftxhr "href=\""
367text tftxamp "&amp;"
368text tftxa "a"
369text tftxbr "br"
370text tftxli "li"
371text tftxtd "td"
372text tftxth "th"
373text tftxsvg "svg"
374text tftxspan "span"
375text tftxp "p"
376text tftxdiv "div"
377text tftxtr "tr"
378text tftxsec "section"
379text tftxart "article"
380text tftxul "ul"
381text tftxol "ol"
382text tftxdl "dl"
383text tftxdt "dt"
384text tftxdd "dd"
385text tftxtab "table"
386text tftxbq "blockquote"
387text tftxhrt "hr"
388text tftxmain "main"
389text tftxhead "header"
390text tftxfoot "footer"
391text tftxnav "nav"
392text tftxfrm "form"
393text tftxent1 "amp"
394text tftxent2 "lt"
395text tftxent3 "gt"
396text tftxent4 "quot"
397text tftxent5 "apos"
398text tftxent6 "nbsp"
399text tftxent7 "middot"
400text tftxent8 "trade"
401text tftxent9 "mdash"
402text tftxen10 "ndash"
403text tftxen11 "hellip"
404text tftxen12 "rarr"
405text tftxen13 "larr"
406text tftxen14 "copy"
407text tftxen15 "times"
408note ftxwant: the query names format=text
409fn ftxwant to bool
410n = fqget tftxfmt
411if ne n long len tftxval
412ret false
413end
414for k ulong len tftxval
415if ne get fval k get tftxval k
416ret false
417end
418end
419ret true
420end
421fn ftxws c uchar to bool
422ret or or eq c 32 eq c 9 or eq c 10 eq c 13
423end
424note ftxraw: emit c as it is (pre text, the page line, fences)
425fn ftxraw cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 c uchar to void
426if eq c 10
427put ftxs 5 add get ftxs 5 1
428else
429put ftxs 5 0
430end
431put ftxs 0 ulong c
432ftrb cs io ch c
433end
434note ftxo: emit c outside pre; no newline before the first text, at most one empty line
435fn ftxo cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 c uchar to void
436if eq c 10
437if or eq get ftxs 0 0 ge get ftxs 5 2
438ret
439end
440end
441ftxraw cs io ch c
442end
443note ftxch: one text byte; outside pre a run of white space is one space, none after a newline
444fn ftxch cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 c uchar to void
445if ne get ftxs 1 0
446if eq get ftxfil 0 1
447ret
448end
449if ne get ftxfsp 0 0
450put ftxfsp 0 0
451ftxraw cs io ch 32
452end
453ftxraw cs io ch c
454ret
455end
456if ftxws c
457put ftxs 2 1
458ret
459end
460if ne get ftxs 2 0
461put ftxs 2 0
462b = get ftxs 0
463if and ne b 0 and ne b 10 ne b 32
464ftxo cs io ch 32
465end
466end
467ftxo cs io ch c
468end
469fn ftxnl cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 to void
470put ftxs 2 0
471if ne get ftxs 1 0
472ftxraw cs io ch 10
473ret
474end
475ftxo cs io ch 10
476end
477fn ftxrt cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 s view uchar * to void
478for k ulong len s bound 4096
479ftxraw cs io ch get s k
480end
481end
482fn ftxct cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 s view uchar * to void
483for k ulong len s bound 4096
484ftxch cs io ch get s k
485end
486end
487note ftxcps: the text bytes fob[a, e)
488fn ftxcps cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 a ulong e ulong to void
489k = a
490while lt k e bound 8388608
491ftxch cs io ch get fob k
492k = add k 1
493end
494end
495note ftxu8: code point v as UTF-8
496fn ftxu8 cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 v ulong to void
497if lt v 128
498ftxch cs io ch uchar v
499ret
500end
501if lt v 2048
502ftxch cs io ch uchar or 192 shr v 6
503ftxch cs io ch uchar or 128 and v 63
504ret
505end
506if lt v 65536
507ftxch cs io ch uchar or 224 shr v 12
508ftxch cs io ch uchar or 128 and shr v 6 63
509ftxch cs io ch uchar or 128 and v 63
510ret
511end
512ftxch cs io ch uchar or 240 shr v 18
513ftxch cs io ch uchar or 128 and shr v 12 63
514ftxch cs io ch uchar or 128 and shr v 6 63
515ftxch cs io ch uchar or 128 and v 63
516end
517note ftxnum: the number of the entity name fob[a, e) after '#' (decimal, or x then hex); 0 when it
518note is not one
519fn ftxnum a ulong e ulong to ulong
520k = a
521hx = false
522if lt k e
523if or eq get fob k 120 eq get fob k 88
524hx = true
525k = add k 1
526end
527end
528if ge k e
529ret 0
530end
531v = ulong 0
532while lt k e bound 8388608
533c = get fob k
534d = ulong 99
535if ftrdig c
536d = sub ulong c 48
537end
538if hx
539if and ge c 97 le c 102
540d = sub ulong c 87
541end
542if and ge c 65 le c 70
543d = sub ulong c 55
544end
545end
546b = ulong 10
547if hx
548b = 16
549end
550if ge d b
551ret 0
552end
553v = add mul v b d
554if gt v 1114111
555ret 0
556end
557k = add k 1
558end
559ret v
560end
561note ftxnam: the code point of a named entity fob[a, e); 0 when not known
562fn ftxnam a ulong e ulong to ulong
563if ftrnm a e tftxent1
564ret 38
565end
566if ftrnm a e tftxent2
567ret 60
568end
569if ftrnm a e tftxent3
570ret 62
571end
572if ftrnm a e tftxent4
573ret 34
574end
575if ftrnm a e tftxent5
576ret 39
577end
578if ftrnm a e tftxent6
579ret 32
580end
581if ftrnm a e tftxent7
582ret 183
583end
584if ftrnm a e tftxent8
585ret 8482
586end
587if ftrnm a e tftxent9
588ret 8212
589end
590if ftrnm a e tftxen10
591ret 8211
592end
593if ftrnm a e tftxen11
594ret 8230
595end
596if ftrnm a e tftxen12
597ret 8594
598end
599if ftrnm a e tftxen13
600ret 8592
601end
602if ftrnm a e tftxen14
603ret 169
604end
605if ftrnm a e tftxen15
606ret 215
607end
608ret 0
609end
610note ftxent: fob[k] is '&'; emit the character and return the index after the entity. An entity
611note that is not known is text: '&' alone is emitted and the rest follows as text.
612fn ftxent cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 k ulong l ulong to ulong
613m = hmin l add k 34
614s = add k 1
615while lt s m bound 64
616if eq get fob s 59
617break
618end
619s = add s 1
620end
621if ge s m
622ftxch cs io ch 38
623ret add k 1
624end
625v = ulong 0
626if and lt add k 1 s eq get fob add k 1 35
627v = ftxnum add k 2 s
628else
629v = ftxnam add k 1 s
630end
631if eq v 0
632ftxch cs io ch 38
633ret add k 1
634end
635ftxu8 cs io ch v
636ret add s 1
637end
638note ftxlink: the link target fob[a, e) after its text, &amp; read as &
639fn ftxlink cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 a ulong e ulong to void
640if ge a e
641ret
642end
643if eq get fob a 35
644ret
645end
646put ftxs 2 1
647if ne get ftxfil 0 0
648put ftxfsp 0 1
649end
650ftxch cs io ch 60
651k = a
652while lt k e bound 8388608
653if ftrat k e tftxamp
654ftxch cs io ch 38
655k = add k 5
656else
657ftxch cs io ch get fob k
658k = add k 1
659end
660end
661ftxo cs io ch 62
662put ftxs 2 1
663end
664fn ftxblk a ulong n ulong to bool
665c = or or ftrnm a n tftxp ftrnm a n tftxdiv or ftrnm a n tftxtr ftrnm a n tftxsec
666c = or c or or ftrnm a n tftxart ftrnm a n tftxul or ftrnm a n tftxol ftrnm a n tftxdl
667c = or c or or ftrnm a n tftxdt ftrnm a n tftxdd or ftrnm a n tftxtab ftrnm a n tftxbq
668c = or c or or ftrnm a n tftxhrt ftrnm a n tftxmain or ftrnm a n tftxhead ftrnm a n tftxfoot
669ret or c or ftrnm a n tftxnav ftrnm a n tftxfrm
670end
671note ftxhn: 1..6 for h1..h6, else 0
672fn ftxhn a ulong n ulong to ulong
673if ne sub n a 2
674ret 0
675end
676if ne get fob a 104
677ret 0
678end
679c = get fob add a 1
680if and ge c 49 le c 54
681ret sub ulong c 48
682end
683ret 0
684end
685note ftxel: the element named fob[a, n), its tag ending at ftxs[8], cl = closing tag
686fn ftxel cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 a ulong n ulong cl bool to void
687sk = or or ftrnm a n tftrscr ftrnm a n tftrsty or ftrnm a n tftrtit ftrnm a n tftxsvg
688if sk
689if cl
690if gt get ftxs 4 0
691put ftxs 4 sub get ftxs 4 1
692end
693else
694put ftxs 4 add get ftxs 4 1
695end
696ret
697end
698if ne get ftxs 4 0
699ret
700end
701if ftrnm a n tftrpre
702ftxpre cs io ch cl
703ret
704end
705if ftrnm a n tftrcod
706ftxcod cs io ch cl
707ret
708end
709if ftrnm a n tftxbr
710ftxnl cs io ch
711ret
712end
713if ftrnm a n tftxspan
714ftxmono cs io ch n cl
715ret
716end
717if ftrnm a n tftxa
718ftxa cs io ch n get ftxs 8 cl
719ret
720end
721hn = ftxhn a n
722if gt hn 0
723ftxnl cs io ch
724ftxnl cs io ch
725if not cl
726for k ulong hn bound 6
727ftxch cs io ch 35
728end
729put ftxs 2 1
730end
731ret
732end
733if ftrnm a n tftxli
734ftxnl cs io ch
735if not cl
736ftxch cs io ch 45
737put ftxs 2 1
738end
739ret
740end
741if ne get ftxfil 0 0
742if or ftrnm a n tftxtd ftrnm a n tftxth
743put ftxfsp 0 0
744if cl
745put ftxfil 0 1
746else
747put ftxfil 0 2
748if ne get ftxs 0 10
749put ftxfsp 0 1
750end
751end
752ret
753end
754if ftrnm a n tftxtr
755put ftxfsp 0 0
756put ftxfil 0 1
757if ne get ftxs 0 10
758ftxraw cs io ch 10
759end
760ret
761end
762end
763if or ftrnm a n tftxtd ftrnm a n tftxth
764put ftxs 2 1
765ret
766end
767if ftrnm a n tftxp
768if cl
769if ne get ftxcrm 0 0
770put ftxcrm 0 0
771ftxcod cs io ch true
772ftxnl cs io ch
773ret
774end
775else
776if ftxhas n tftrcrm
777ftxnl cs io ch
778ftxcod cs io ch false
779put ftxcrm 0 1
780ret
781end
782end
783end
784if ftrnm a n tftxtab
785if cl
786if ne get ftxfil 0 0
787put ftxfil 0 0
788ftxpre cs io ch true
789ret
790end
791else
792if ftxhas n tftrfil
793ftxpre cs io ch false
794put ftxfil 0 1
795ret
796end
797end
798end
799if ftxblk a n
800ftxnl cs io ch
801end
802end
803note ftxhas: the open tag ending at ftxs[8], name ending at n, has class token tok
804fn ftxhas n ulong tok view uchar * to bool
805e = get ftxs 8
806c = ftrfind n e tftrcl
807if ge c e
808ret false
809end
810k = add c 7
811s = k
812while lt k e bound 8388608
813b = get fob k
814if or eq b 34 eq b 32
815if ftrnm s k tok
816ret true
817end
818if eq b 34
819ret false
820end
821s = add k 1
822end
823k = add k 1
824end
825ret false
826end
827note ftxmono: a span whose class names mono (a command, an id) is inline code in the text form
828fn ftxmono cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 n ulong cl bool to void
829if cl
830if ne get ftxs 9 0
831put ftxs 9 0
832ftxcod cs io ch true
833end
834ret
835end
836if ne get ftxs 9 0
837ret
838end
839if ftrcls n get ftxs 8
840put ftxs 9 1
841ftxcod cs io ch false
842end
843end
844fn ftxpre cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 cl bool to void
845if cl
846if gt get ftxs 1 0
847put ftxs 1 sub get ftxs 1 1
848end
849if ne get ftxs 0 10
850ftxraw cs io ch 10
851end
852ftxrt cs io ch tftxfen
853ftxraw cs io ch 10
854ret
855end
856ftxnl cs io ch
857if ne get ftxs 0 10
858ftxraw cs io ch 10
859end
860ftxrt cs io ch tftxfen
861ftxraw cs io ch 10
862put ftxs 1 add get ftxs 1 1
863end
864fn ftxcod cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 cl bool to void
865if ne get ftxs 1 0
866ret
867end
868if cl
869if gt get ftxs 6 0
870put ftxs 6 sub get ftxs 6 1
871ftxo cs io ch 96
872end
873ret
874end
875ftxch cs io ch 96
876put ftxs 6 add get ftxs 6 1
877end
878note ftxa: an opening a keeps where its href value is; the closing a emits it
879fn ftxa cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 n ulong e ulong cl bool to void
880if cl
881ftxlink cs io ch get ftxs 3 get ftxs 7
882put ftxs 3 0
883put ftxs 7 0
884ret
885end
886put ftxs 3 0
887put ftxs 7 0
888h = ftrfind n e tftxhr
889if ge h e
890ret
891end
892p = add h 6
893q = p
894while lt q e bound 8388608
895if eq get fob q 34
896break
897end
898q = add q 1
899end
900put ftxs 3 p
901put ftxs 7 q
902end
903note ftxtag: fob[i] is '<'; act on the element and return the index after the tag
904fn ftxtag cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 i ulong l ulong to ulong
905e = ftrtend i l
906j = add i 1
907if or ge j e ne get fob sub e 1 62
908ret e
909end
910if ftrcmt j l
911ret e
912end
913cl = eq get fob j 47
914a = j
915if cl
916a = add j 1
917end
918n = ftrnend a e
919if gt n a
920put ftxs 8 e
921ftxel cs io ch a n cl
922end
923ret e
924end
925note ftxtxt: the text from fob[i] to the next '<' (or l); hashes and ids outside code in backticks
926fn ftxtxt cs edit ulong 320 io edit uchar 131072 ch edit uchar 32768 i ulong l ulong to ulong
927k = i
928while lt k l bound 8388608
929c = get fob k
930if eq c 60
931ret k
932end
933if ne get ftxs 4 0
934k = add k 1
935continue
936end
937if eq c 38
938k = ftxent cs io ch k l
939continue
940end
941if not ftrwc c
942ftxch cs io ch c
943k = add k 1
944continue
945end
946s = k
947while lt k l bound 8388608
948if not ftrwc get fob k
949break
950end
951k = add k 1
952end
953w = ftxcode
954if and not w ftrid s k
955ftxch cs io ch 96
956ftxcps cs io ch s k
957ftxo cs io ch 96
958else
959ftxcps cs io ch s k
960end
961end
962ret k
963end
964note ftxrun: mode 0 returns the byte count of the text of fob[0, l); mode 1 sends it
965note ftxmore: fsend5 keeps the text renderer's element state between complete batches.
966fn ftxrun cs edit ulong 320 io edit uchar 131072 l ulong mode ulong to long
967ch = new uchar 32768 0
968put ftrq 0 0
969put ftrq 1 0
970put ftrq 2 mode
971put ftrer 0 0
972if eq get ftxmore 0 0
973for k ulong 10
974put ftxs k 0
975end
976put ftxcrm 0 0
977put ftxfil 0 0
978put ftxfsp 0 0
979ftxrt cs io ch tftxpre
980for k ulong get fpathl 0 bound 4096
981ftxraw cs io ch get fpath k
982end
983ftxraw cs io ch 10
984ftxraw cs io ch 10
985end
986i = ulong 0
987while lt i l bound 8388608
988if eq get fob i 60
989i = ftxtag cs io ch i l
990else
991i = ftxtxt cs io ch i l
992end
993end
994if ne get ftxs 0 10
995ftxraw cs io ch 10
996end
997if eq mode 0
998ret long get ftrq 1
999end
1000if gt get ftrq 0 0
1001ftrfl cs io ch get ftrq 0
1002end
1003ret get ftrer 0
1004end
1005note ftxsend: the plain-text response of a kind-0 page, same status and security headers
1006fn ftxsend cs edit ulong 320 io edit uchar 131072 st ulong l ulong to long
1007n = ftxrun cs io l 0
1008r = hrspst cs io st
1009r = hfe r fhdrt cs io tfnctype tftxct
1010r = hfe r fsechdr cs io
1011r = hfe r fhdrt cs io tfncc tfnostor
1012r = hfe r hhend cs io 0 ulong n
1013r = hfe r ftxrun cs io l 1
1014ret hfe r hwfin cs io
1015end
1016note ftxcode: inside a pre block or inline code
1017fn ftxcode to bool
1018if ne get ftxs 1 0
1019ret true
1020end
1021ret ne get ftxs 6 0
1022end