interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / browse / b_md.om

2110 lines · 32098 bytes Raw Blame History
1note browse/b_md.om (ForgeBrowse): safe Markdown renderer (CommonMark subset plus GFM tables,
2note strikethrough, task items and bare https autolinks). Source: fxo[a, b); output: fob.
3note Safety: every source byte reaches fob through fescc or the URL encoder; raw HTML is escaped,
4note never passed through; link schemes other than http, https and mailto render as plain text;
5note an HTML comment ("<!--" up to the first "-->") renders nothing (comment section below); an
6note opener without a closing "-->" stays escaped text;
7note images load only from this repo (relative paths -> /raw/<ref>/...); an external image renders
8note as its alt text only. Relative links resolve against gbmd (the document's directory) at gbref.
9global gbm ulong 40
10global gbmlm ulong 8
11global gbmlc ulong 8
12global gbmlt ulong 8
13global gbmlk ulong 8
14global gbmta uchar 64
15global gbmd uchar 4096
16global gbmdl ulong 1
17global gbmu uchar 4096
18global gbmul ulong 1
19global gbmrd ulong 512
20global gbmrn ulong 1
21const BMP ulong 0
22const BMPW ulong 1
23const BMF ulong 2
24const BMFC ulong 3
25const BMFN ulong 4
26const BMFI ulong 5
27const BMQ ulong 6
28const BMT ulong 7
29const BMTC ulong 8
30const BMIC ulong 9
31const BMIB ulong 10
32const BML ulong 11
33const BMB ulong 12
34const BMSK ulong 13
35const BMHB ulong 14
36const BMFP ulong 15
37const BMCP ulong 16
38const BMMC ulong 17
39const BMMP ulong 18
40const BMMN ulong 19
41const BMDS ulong 20
42const BMDE ulong 21
43const BMTS ulong 22
44const BMTE ulong 23
45const BMNS ulong 24
46const BMNE ulong 25
47const BMTK ulong 26
48const BMMK ulong 27
49note BMXE: end after the "-->" of an open comment block (0 = none); BMDB: end of the document;
50note BMCV/BMCF/BMCX: cached comment-closer lookup (no "-->" starts in [BMCF, BMCX); BMCX is one or BMDB)
51const BMXE ulong 28
52const BMDB ulong 29
53const BMCV ulong 30
54const BMCF ulong 31
55const BMCX ulong 32
56text tbmp "<p>"
57text tbmpe "</p>\n"
58text tbmpre "<pre><code>"
59text tbmprl "<pre><code class=\"language-"
60text tbmpree "</code></pre>\n"
61text tbmbq "<blockquote>\n"
62text tbmbqe "</blockquote>\n"
63text tbmul "<ul>\n"
64text tbmule "</ul>\n"
65text tbmol "<ol>\n"
66text tbmols "<ol start=\""
67text tbmole "</ol>\n"
68text tbmli "<li>"
69text tbmlie "</li>\n"
70text tbmhr "<hr>\n"
71text tbmbr "<br>\n"
72text tbmtab "<table class=\"md\">\n<thead>\n<tr>"
73text tbmthe "</tr>\n</thead>\n<tbody>\n"
74text tbmtabe "</tbody>\n</table>\n"
75text tbmtr "<tr>"
76text tbmtre "</tr>\n"
77text tbmthl "<th class=\"md-l\">"
78text tbmthc "<th class=\"md-c\">"
79text tbmthr "<th class=\"md-r\">"
80text tbmth "<th>"
81text tbmthx "</th>"
82text tbmtdl "<td class=\"md-l\">"
83text tbmtdc "<td class=\"md-c\">"
84text tbmtdr "<td class=\"md-r\">"
85text tbmtd "<td>"
86text tbmtdx "</td>"
87text tbmcode "<code>"
88text tbmcodx "</code>"
89text tbmem "<em>"
90text tbmemx "</em>"
91text tbmst "<strong>"
92text tbmstx "</strong>"
93text tbmdel "<del>"
94text tbmdelx "</del>"
95note tbmaext: a link that leaves the site (http, https, mailto or protocol-relative, and the http(s)
96note autolinks) gets class "ext" (the stylesheet draws an arrow and says "leaves this site") and
97note neither the referrer nor the opener
98text tbmaext "\" class=\"ext\" rel=\"nofollow noopener noreferrer\">"
99text tbmtitl "\" title=\""
100text tbmimg "<img src=\""
101text tbmalt "\" alt=\""
102text tbmimgx "\">"
103text tbmblob "/blob/"
104text tbmraw "/raw/"
105text tbmmail "mailto:"
106text tbmhttp "http"
107text tbmhttps "https"
108text tbmmto "mailto"
109text tbmbh "http://"
110text tbmbhs "https://"
111text tbmchk "<input type=\"checkbox\" disabled> "
112text tbmchkd "<input type=\"checkbox\" disabled checked> "
113text tbmimgw "image"
114text tbmaq "\">\n"
115text tbmh "<h"
116text tbmhid " id=\""
117text tbmhx "</h"
118text tbmgt ">\n"
119note ---- state helpers
120fn brmg k ulong to ulong
121ret get gbm k
122end
123fn brms k ulong v ulong to void
124put gbm k v
125end
126fn brmreset to void
127for i ulong 40
128put gbm i 0
129end
130put gbmrn 0 0
131end
132fn brmc a ulong to uchar
133ret get fxo a
134end
135fn brpunct c uchar to bool
136if and ge c 33 le c 47
137ret true
138end
139if and ge c 58 le c 64
140ret true
141end
142if and ge c 91 le c 96
143ret true
144end
145ret and ge c 123 le c 126
146end
147note brmcols: whitespace columns at the start of fxo[p, e) (tab = to the next multiple of 4);
148note the first non-space position goes to gbm[BMFP]
149fn brmcols p ulong e ulong to ulong
150c = ulong 0
151i = p
152while lt i e bound BRBIG
153x = get fxo i
154if eq x 32
155c = add c 1
156else
157if ne x 9
158break
159end
160c = add sub c rem c 4 4
161end
162i = add i 1
163end
164brms BMFP i
165ret c
166end
167note brmskipc: position after up to `cols` whitespace columns of fxo[p, e)
168fn brmskipc p ulong e ulong cols ulong to ulong
169c = ulong 0
170i = p
171while lt i e bound BRBIG
172if ge c cols
173ret i
174end
175x = get fxo i
176if eq x 32
177c = add c 1
178else
179if ne x 9
180ret i
181end
182c = add sub c rem c 4 4
183end
184i = add i 1
185end
186ret i
187end
188fn brmblank p ulong e ulong to bool
189i = p
190while lt i e bound BRBIG
191if not brspc get fxo i
192ret false
193end
194i = add i 1
195end
196ret true
197end
198note brmtrim: end of fxo[p, e) without trailing spaces and tabs
199fn brmtrim p ulong e ulong to ulong
200k = e
201while gt k p bound BRBIG
202if not brspc get fxo sub k 1
203ret k
204end
205k = sub k 1
206end
207ret k
208end
209fn brmspan p ulong e ulong to void
210i = p
211while lt i e bound BRBIG
212fescc get fxo i
213i = add i 1
214end
215end
216note ---- block closers
217fn brmcp to void
218if eq brmg BMP 1
219if eq brmg BMPW 1
220fput tbmpe
221else
222fputc 10
223end
224end
225brms BMP 0
226brms BMHB 0
227end
228fn brmct to void
229if eq brmg BMT 1
230fput tbmtabe
231end
232brms BMT 0
233end
234fn brmci to void
235if eq brmg BMIC 1
236fput tbmpree
237end
238brms BMIC 0
239brms BMIB 0
240end
241fn brmcf to void
242if eq brmg BMF 1
243fput tbmpree
244end
245brms BMF 0
246end
247fn brmcleaf to void
248brmcp
249brmct
250brmci
251brmcf
252end
253fn brmlclose to void
254l = brmg BML
255if eq l 0
256ret
257end
258brmcleaf
259fput tbmlie
260if eq get gbmlt sub l 1 1
261fput tbmole
262else
263fput tbmule
264end
265brms BML sub l 1
266end
267fn brmclist k ulong to void
268while gt brmg BML k bound BRBIG
269brmlclose
270end
271end
272fn brmsetq q ulong to void
273brmclist 0
274brmcleaf
275while gt brmg BMQ q bound BRBIG
276fput tbmbqe
277brms BMQ sub brmg BMQ 1
278end
279while lt brmg BMQ q bound BRBIG
280fput tbmbq
281brms BMQ add brmg BMQ 1
282end
283end
284note ---- entry point
285fn brmd a ulong b ulong to void
286brmreset
287brms BMDB b
288brmdefs a b
289s = a
290while lt s b bound BRBIG
291e = brxfind s b 10
292k = e
293if gt k s
294if eq get fxo sub k 1 13
295k = sub k 1
296end
297end
298if eq brmg BMSK 1
299brms BMSK 0
300else
301if gt brmg BMXE 0
302brmcline k
303else
304brmline s k add e 1 b
305end
306end
307s = add e 1
308end
309brmsetq 0
310end
311note brmq: count blockquote markers of fxo[s, e) (at most `lim`); content start to gbm[BMCP]
312fn brmq s ulong e ulong lim ulong to ulong
313q = ulong 0
314p = s
315while lt q lim bound BRBIG
316i = brmskipc p e 3
317if ge i e
318break
319end
320if ne get fxo i 62
321break
322end
323q = add q 1
324p = add i 1
325if lt p e
326if eq get fxo p 32
327p = add p 1
328end
329end
330end
331brms BMCP p
332ret q
333end
334fn brmline s ulong e ulong nx ulong b ulong to void
335if eq brmg BMF 1
336if brmfline s e
337ret
338end
339end
340q = brmq s e 64
341p = brmg BMCP
342bl = brmblank p e
343if ne q brmg BMQ
344if and lt q brmg BMQ brmlazy p e bl
345brmpline p e
346brms BMB 0
347ret
348end
349brmsetq q
350end
351if bl
352brmcp
353brmct
354if eq brmg BMIC 1
355brms BMIB add brmg BMIB 1
356end
357brms BMB 1
358ret
359end
360brmblock p e nx b
361brms BMB 0
362end
363note brmlazy: a line continuing an open paragraph without its container markers
364fn brmlazy p ulong e ulong bl bool to bool
365if bl
366ret false
367end
368if ne brmg BMP 1
369ret false
370end
371ret brmplain p e
372end
373fn brmplain p ulong e ulong to bool
374i = brmcols p e
375f = brmg BMFP
376if ge i 4
377ret true
378end
379c = get fxo f
380if or eq c 35 eq c 62
381ret false
382end
383if eq c 60
384if gt brmcbx f e 0
385ret false
386end
387end
388if or brmisfence f e brmhr f e
389ret false
390end
391ret eq brmmark f e 0
392end
393note brmfline: a line while a fence is open; true when consumed
394fn brmfline s ulong e ulong to bool
395fq = brmg BMQ
396q = brmq s e fq
397if lt q fq
398brmcf
399ret false
400end
401p = brmskipc brmg BMCP e brmg BMFI
402if brmfend p e
403brmcf
404ret true
405end
406brmspan p e
407fputc 10
408ret true
409end
410note brmfend: fxo[p, e) closes the open fence (same char, at least as long, nothing after)
411fn brmfend p ulong e ulong to bool
412i = brmcols p e
413f = brmg BMFP
414if ge i 4
415ret false
416end
417if ge f e
418ret false
419end
420c = get fxo f
421if ne ulong c brmg BMFC
422ret false
423end
424n = brmrun f e c
425if lt n brmg BMFN
426ret false
427end
428ret brmblank add f n e
429end
430fn brmrun f ulong e ulong c uchar to ulong
431n = ulong 0
432i = f
433while lt i e bound BRBIG
434if ne get fxo i c
435ret n
436end
437n = add n 1
438i = add i 1
439end
440ret n
441end
442note ---- containers: lists
443fn brmblock p ulong e ulong nx ulong b ulong to void
444i = brmcols p e
445f = brmg BMFP
446if eq brmg BMIC 1
447if ge i add brmlci 4
448brmicode p e
449ret
450end
451brmci
452end
453m = ulong 0
454if lt i add brmlci 4
455if not brmhr f e
456m = brmmark f e
457end
458end
459if gt m 0
460brmitem p e i m nx
461ret
462end
463if eq brmg BML 0
464brmleaf p e nx b 0
465ret
466end
467brmlcont p e nx b i
468end
469note brmlci: content indent of the innermost open list item (0 outside lists)
470fn brmlci to ulong
471l = brmg BML
472if eq l 0
473ret 0
474end
475ret get gbmlc sub l 1
476end
477fn brmicode p ulong e ulong to void
478if eq brmg BMIC 0
479brmcp
480fput tbmpre
481brms BMIC 1
482brms BMIB 0
483end
484for k ulong brmg BMIB bound BRBIG
485fputc 10
486end
487brms BMIB 0
488brmspan brmskipc p e add brmlci 4 e
489fputc 10
490end
491note brmlcont: a non-marker line while a list is open
492fn brmlcont p ulong e ulong nx ulong b ulong i ulong to void
493if and eq brmg BMB 0 eq brmg BMP 1
494if lt i brmlci
495if brmplain p e
496brmpline p e
497ret
498end
499end
500end
501while gt brmg BML 0 bound BRBIG
502if ge i brmlci
503break
504end
505brmlclose
506end
507if eq brmg BML 0
508brmleaf p e nx b 0
509ret
510end
511if eq brmg BMB 1
512brmcp
513end
514brmleaf brmskipc p e brmlci e nx b brmlci
515end
516note brmmark: list marker at f? 1 bullet, 2 ordered, 0 none. Sets BMMP (content position),
517note BMMC (marker + spacing width) and BMMN (ordered start number)
518fn brmmark f ulong e ulong to ulong
519c = get fxo f
520t = ulong 0
521k = f
522if or eq c 45 or eq c 42 eq c 43
523t = 1
524brms BMMK ulong c
525k = add f 1
526else
527v = ulong 0
528while lt k e bound BRBIG
529if not brdig get fxo k
530break
531end
532v = add mul v 10 ulong sub get fxo k 48
533k = add k 1
534end
535if or eq k f gt sub k f 9
536ret 0
537end
538if ge k e
539ret 0
540end
541if and ne get fxo k 46 ne get fxo k 41
542ret 0
543end
544t = 2
545brms BMMK ulong get fxo k
546k = add k 1
547brms BMMN v
548end
549if lt k e
550if not brspc get fxo k
551ret 0
552end
553end
554w = sub k f
555sp = ulong 0
556while lt k e bound BRBIG
557if or ne get fxo k 32 ge sp 4
558break
559end
560sp = add sp 1
561k = add k 1
562end
563if eq sp 0
564sp = 1
565end
566if ge sp 4
567if ge k e
568sp = 1
569end
570end
571brms BMMP k
572brms BMMC add w sp
573ret t
574end
575fn brmlopen t ulong to void
576if eq t 2
577n = brmg BMMN
578if eq n 1
579fput tbmol
580else
581fput tbmols
582fnum n
583fput tbmaq
584end
585else
586fput tbmul
587end
588end
589fn brmitem p ulong e ulong i ulong t ulong nx ulong to void
590brmcleaf
591cp = brmg BMMP
592w = brmg BMMC
593while gt brmg BML 0 bound BRBIG
594if ge i get gbmlm sub brmg BML 1
595break
596end
597brmlclose
598end
599l = brmg BML
600sib = false
601if gt l 0
602sib = lt i brmlci
603end
604mk = brmg BMMK
605if sib
606fput tbmlie
607if ne get gbmlk sub l 1 mk
608if eq get gbmlt sub l 1 1
609fput tbmole
610else
611fput tbmule
612end
613brms BMB 0
614brmlopen t
615end
616l = sub l 1
617else
618if ge l 8
619brmclist 7
620l = 7
621end
622brms BMB 0
623brmlopen t
624end
625put gbmlk l mk
626put gbmlm l i
627put gbmlc l add i w
628put gbmlt l sub t 1
629brms BML add l 1
630fput tbmli
631brmtask cp e nx
632end
633note brmtask: item text after the marker, with a GFM task box when it starts "[ ] " / "[x] "
634fn brmtask cp ulong e ulong nx ulong to void
635if ge cp e
636ret
637end
638p = cp
639if le add cp 3 e
640if and eq get fxo cp 91 eq get fxo add cp 2 93
641x = get fxo add cp 1
642ok = or eq add cp 3 e brspc get fxo add cp 3
643if and ok eq x 32
644fput tbmchk
645p = add cp 3
646end
647if and ok or eq x 120 eq x 88
648fput tbmchkd
649p = add cp 3
650end
651end
652end
653brmleaf p e nx e 0
654end
655note ---- leaf blocks
656fn brmleaf p ulong e ulong nx ulong b ulong ci ulong to void
657i = brmcols p e
658f = brmg BMFP
659if ge f e
660ret
661end
662if and ge i 4 eq brmg BMP 0
663brmicode p e
664ret
665end
666if brmisfence f e
667brmfopen f e add ci i
668ret
669end
670c = get fxo f
671if eq c 60
672if lt i 4
673x = brmcbx f e
674if gt x 0
675brmcleaf
676if gt x e
677brms BMXE x
678end
679ret
680end
681end
682end
683if eq c 35
684if brmhead f e
685ret
686end
687end
688if brmhr f e
689brmcleaf
690fput tbmhr
691ret
692end
693if eq brmg BMP 0
694if brmleaf2 f e nx b
695ret
696end
697end
698if eq brmg BMT 1
699brmct
700end
701brmpline f e
702end
703note brmleaf2: definitions, tables and setext headings (only where no paragraph is open)
704fn brmleaf2 f ulong e ulong nx ulong b ulong to bool
705if brmdefln f e false
706ret true
707end
708if eq brmg BMT 1
709if brmhaspipe f e
710brmrow f e
711ret true
712end
713brmct
714end
715if lt nx b
716brmnext nx b
717ns = brmg BMNS
718nn = brmg BMNE
719if brmhaspipe f e
720n = brmdelim ns nn
721if gt n 0
722brmthead f e n
723brms BMSK 1
724ret true
725end
726end
727h = brmsetx ns nn
728if gt h 0
729brmhopen h f e
730brmi f brmtrim f e
731brmhclose h
732brms BMSK 1
733ret true
734end
735end
736ret false
737end
738note brmnext: the next line, its quote markers and indentation skipped, into BMNS/BMNE
739fn brmnext nx ulong b ulong to void
740e = brxfind nx b 10
741if gt e nx
742if eq get fxo sub e 1 13
743e = sub e 1
744end
745end
746q = brmq nx e 64
747p = brmg BMCP
748i = brmcols p e
749brms BMNS brmg BMFP
750brms BMNE e
751end
752fn brmsetx s ulong e ulong to ulong
753if ge s e
754ret 0
755end
756c = get fxo s
757if and ne c 61 ne c 45
758ret 0
759end
760n = brmrun s e c
761if not brmblank add s n e
762ret 0
763end
764if eq c 61
765ret 1
766end
767if ge n 2
768ret 2
769end
770ret 0
771end
772fn brmisfence f ulong e ulong to bool
773c = get fxo f
774if and ne c 96 ne c 126
775ret false
776end
777n = brmrun f e c
778if lt n 3
779ret false
780end
781if eq c 126
782ret true
783end
784ret ge brxfind add f n e 96 e
785end
786fn brmfopen f ulong e ulong ind ulong to void
787brmcleaf
788c = get fxo f
789n = brmrun f e c
790brms BMF 1
791brms BMFC ulong c
792brms BMFN n
793brms BMFI ind
794s = add f n
795while lt s e bound BRBIG
796if not brspc get fxo s
797break
798end
799s = add s 1
800end
801k = s
802while lt k e bound BRBIG
803if brspc get fxo k
804break
805end
806k = add k 1
807end
808if gt k s
809fput tbmprl
810brmspan s k
811fput tbaq
812else
813fput tbmpre
814end
815end
816fn brmhr f ulong e ulong to bool
817c = get fxo f
818if and ne c 45 and ne c 42 ne c 95
819ret false
820end
821n = ulong 0
822i = f
823while lt i e bound BRBIG
824x = get fxo i
825if eq x c
826n = add n 1
827else
828if not brspc x
829ret false
830end
831end
832i = add i 1
833end
834ret ge n 3
835end
836note brmpline: one paragraph line (opens the paragraph when needed)
837fn brmpline f ulong e ulong to void
838if eq brmg BMP 0
839brmcleaf
840brms BMP 1
841brms BMPW 1
842if and gt brmg BML 0 eq brmg BMB 0
843brms BMPW 0
844end
845if eq brmg BMPW 1
846fput tbmp
847end
848else
849if eq brmg BMHB 1
850fput tbmbr
851else
852fputc 10
853end
854end
855k = brmtrim f e
856hb = ulong 0
857if ge sub e k 2
858hb = 1
859end
860if gt k f
861if eq get fxo sub k 1 92
862hb = 1
863k = sub k 1
864end
865end
866brms BMHB hb
867brmi f k
868end
869note ---- HTML comments
870note "<!--" up to the first "-->" renders nothing ("<!-->" and "<!--->" included, as in CommonMark
871note 0.31). No byte of a comment is ever written, so a comment cannot carry markup through; "--!>",
872note "-- >" and a nested "<!--" do not end it, only the first "-->" (also inside "--->") does. An opener with no
873note "-->" after it in the document is not a comment: it stays text and is escaped like any other "<".
874note Fenced and indented code and code spans never reach these checks, so comments there stay text.
875note Block: a line starting with "<!--" (under 4 columns of indent) closes the open leaf block and
876note renders nothing up to the first "-->", across lines, when only spaces and further comments
877note follow the "-->" or the "-->" is on a later line; text after a "-->" on a later line is paragraph
878note text. A comment that closes on its own line with other text after it is paragraph text instead
879note (the inline rule drops it). Inline: a comment that opens and closes inside one inline run is
880note dropped from it (headings, emphasis, link text, table cells, list items); heading anchors skip it.
881fn brmisopen i ulong to bool
882if ne get fxo i 60
883ret false
884end
885if ne get fxo add i 1 33
886ret false
887end
888if ne get fxo add i 2 45
889ret false
890end
891ret eq get fxo add i 3 45
892end
893note brmcmend: the first "-->" starting at or after p, BMDB when none. The cached scan (no "-->" in
894note [BMCF, BMCX)) answers every later lookup inside it, and a lookup before BMCF scans only up to
895note BMCF, so the lookups of one document (made in document order) scan each byte about once.
896fn brmcmend p ulong to ulong
897b = brmg BMDB
898lim = b
899if eq brmg BMCV 1
900cf = brmg BMCF
901cx = brmg BMCX
902if le cf p
903if le p cx
904ret cx
905end
906else
907lim = cf
908end
909end
910j = p
911r = b
912while lt j lim bound BRBIG
913if ge add j 2 b
914break
915end
916if eq get fxo j 45
917if eq get fxo add j 1 45
918if eq get fxo add j 2 62
919r = j
920break
921end
922end
923end
924j = add j 1
925end
926if eq r b
927if lt lim b
928r = brmg BMCX
929end
930end
931brms BMCV 1
932brms BMCF p
933brms BMCX r
934ret r
935end
936note brmicmt: an inline comment at i that closes before e: the end after its "-->", else 0
937fn brmicmt i ulong e ulong to ulong
938if gt add i 4 e
939ret 0
940end
941if not brmisopen i
942ret 0
943end
944j = brmcmend add i 2
945if gt add j 3 e
946ret 0
947end
948ret add j 3
949end
950note brmcbx: a comment block at f (under 4 columns of indent, checked by the callers) on the line
951note ending at e: the end after its last "-->" when the line holds only comments and spaces or its
952note last comment closes on a later line, else 0
953fn brmcbx f ulong e ulong to ulong
954p = f
955while lt p e bound BRBIG
956if gt add p 4 e
957ret 0
958end
959if not brmisopen p
960ret 0
961end
962j = brmcmend add p 2
963if ge j brmg BMDB
964ret 0
965end
966x = add j 3
967if gt x e
968ret x
969end
970p = x
971while lt p e bound BRBIG
972if not brspc get fxo p
973break
974end
975p = add p 1
976end
977if ge p e
978ret x
979end
980end
981ret 0
982end
983note brmcline: a line ending at k while a comment block is open (BMXE): nothing before the "-->"
984note renders; text after it on the closing line is paragraph text
985fn brmcline k ulong to void
986x = brmg BMXE
987if gt x k
988ret
989end
990brms BMXE 0
991if brmblank x k
992ret
993end
994i = brmcols x k
995brmpline brmg BMFP k
996brms BMB 0
997end
998note ---- headings
999fn brmhead f ulong e ulong to bool
1000n = brmrun f e 35
1001if gt n 6
1002ret false
1003end
1004s = add f n
1005if lt s e
1006if not brspc get fxo s
1007ret false
1008end
1009end
1010while lt s e bound BRBIG
1011if not brspc get fxo s
1012break
1013end
1014s = add s 1
1015end
1016k = brmtrim s e
1017j = k
1018while gt j s bound BRBIG
1019if ne get fxo sub j 1 35
1020break
1021end
1022j = sub j 1
1023end
1024if lt j k
1025if eq j s
1026k = j
1027else
1028if brspc get fxo sub j 1
1029k = brmtrim s j
1030end
1031end
1032end
1033brmcleaf
1034brmhopen n s k
1035brmi s k
1036brmhclose n
1037ret true
1038end
1039fn brmhopen n ulong s ulong k ulong to void
1040brmcleaf
1041fput tbmh
1042fputc uchar add n 48
1043fput tbmhid
1044brmslug s k
1045fput tbaq
1046end
1047fn brmhclose n ulong to void
1048fput tbmhx
1049fputc uchar add n 48
1050fput tbmgt
1051end
1052note brmslug: heading anchor: ASCII letters lower-cased, digits, "-" and "_" kept, spaces to "-",
1053note bytes >= 128 kept, HTML comments and everything else dropped
1054fn brmslug s ulong k ulong to void
1055i = s
1056while lt i k bound BRBIG
1057c = get fxo i
1058if eq c 60
1059r = brmicmt i k
1060if gt r 0
1061i = r
1062continue
1063end
1064end
1065if bralnum c
1066fputc brlow c
1067end
1068if or eq c 45 eq c 95
1069fputc c
1070end
1071if eq c 32
1072fputc 45
1073end
1074if ge c 128
1075fputc c
1076end
1077i = add i 1
1078end
1079end
1080note ---- tables
1081fn brmhaspipe f ulong e ulong to bool
1082i = f
1083while lt i e bound BRBIG
1084c = get fxo i
1085if eq c 92
1086i = add i 1
1087else
1088if eq c 124
1089ret true
1090end
1091end
1092i = add i 1
1093end
1094ret false
1095end
1096note brmdelim: GFM delimiter row -> column count (aligns into gbmta), 0 when not one
1097fn brmdelim s ulong e ulong to ulong
1098e2 = brmtrim s e
1099if ge s e2
1100ret 0
1101end
1102a = s
1103if eq get fxo a 124
1104a = add a 1
1105end
1106if gt e2 a
1107if eq get fxo sub e2 1 124
1108e2 = sub e2 1
1109end
1110end
1111n = ulong 0
1112c = a
1113while le c e2 bound BRBIG
1114k = brxfind c e2 124
1115if not brmdcell c k n
1116ret 0
1117end
1118n = add n 1
1119if ge n 64
1120ret 0
1121end
1122c = add k 1
1123end
1124ret n
1125end
1126fn brmdcell a ulong k ulong n ulong to bool
1127s = a
1128while lt s k bound BRBIG
1129if not brspc get fxo s
1130break
1131end
1132s = add s 1
1133end
1134t = brmtrim s k
1135if ge s t
1136ret false
1137end
1138al = ulong 0
1139if eq get fxo s 58
1140al = 1
1141s = add s 1
1142end
1143if lt s t
1144if eq get fxo sub t 1 58
1145al = add al 2
1146t = sub t 1
1147end
1148end
1149if ge s t
1150ret false
1151end
1152for i ulong sub t s bound BRBIG
1153if ne get fxo add s i 45
1154ret false
1155end
1156end
1157put gbmta n uchar al
1158ret true
1159end
1160fn brmthead f ulong e ulong n ulong to void
1161brmcleaf
1162brms BMT 1
1163brms BMTC n
1164fput tbmtab
1165brmcells f e 1
1166fput tbmthe
1167end
1168fn brmrow f ulong e ulong to void
1169fput tbmtr
1170brmcells f e 0
1171fput tbmtre
1172end
1173note brmcells: split fxo[f, e) on unescaped "|" (outside code spans) into BMTC cells
1174fn brmcells f ulong e ulong th ulong to void
1175e2 = brmtrim f e
1176a = f
1177if lt a e2
1178if eq get fxo a 124
1179a = add a 1
1180end
1181end
1182if gt e2 a
1183if eq get fxo sub e2 1 124
1184if ne get fxo sub e2 2 92
1185e2 = sub e2 1
1186end
1187end
1188end
1189n = brmg BMTC
1190col = ulong 0
1191c = a
1192while lt col n bound BRBIG
1193k = brmcend c e2
1194if gt c e2
1195k = c
1196end
1197brmcell c k col th
1198col = add col 1
1199c = add k 1
1200end
1201end
1202fn brmcend c ulong e ulong to ulong
1203i = c
1204while lt i e bound BRBIG
1205x = get fxo i
1206if eq x 92
1207i = add i 2
1208else
1209if eq x 124
1210ret i
1211end
1212if eq x 96
1213i = brmcskip i e
1214else
1215i = add i 1
1216end
1217end
1218end
1219ret e
1220end
1221fn brmcell a ulong k ulong col ulong th ulong to void
1222al = get gbmta col
1223if eq th 1
1224if eq al 1
1225fput tbmthl
1226end
1227if eq al 2
1228fput tbmthr
1229end
1230if eq al 3
1231fput tbmthc
1232end
1233if eq al 0
1234fput tbmth
1235end
1236else
1237if eq al 1
1238fput tbmtdl
1239end
1240if eq al 2
1241fput tbmtdr
1242end
1243if eq al 3
1244fput tbmtdc
1245end
1246if eq al 0
1247fput tbmtd
1248end
1249end
1250if lt a k
1251s = a
1252while lt s k bound BRBIG
1253if not brspc get fxo s
1254break
1255end
1256s = add s 1
1257end
1258brmi s brmtrim s k
1259end
1260if eq th 1
1261fput tbmthx
1262else
1263fput tbmtdx
1264end
1265end
1266note ---- link reference definitions: "[label]: url" (title ignored)
1267fn brmdefs a ulong b ulong to void
1268s = a
1269while lt s b bound BRBIG
1270e = brxfind s b 10
1271k = e
1272if gt k s
1273if eq get fxo sub k 1 13
1274k = sub k 1
1275end
1276end
1277i = brmskipc s k 3
1278if lt i k
1279if eq get fxo i 91
1280x = brmdefln i k true
1281end
1282end
1283s = add e 1
1284end
1285end
1286fn brmdefln f ulong e ulong rec bool to bool
1287if ge f e
1288ret false
1289end
1290if ne get fxo f 91
1291ret false
1292end
1293j = add f 1
1294while lt j e bound BRBIG
1295c = get fxo j
1296if or eq c 93 eq c 91
1297break
1298end
1299j = add j 1
1300end
1301if or ge j e eq j add f 1
1302ret false
1303end
1304if ne get fxo j 93
1305ret false
1306end
1307if ge add j 1 e
1308ret false
1309end
1310if ne get fxo add j 1 58
1311ret false
1312end
1313u = add j 2
1314while lt u e bound BRBIG
1315if not brspc get fxo u
1316break
1317end
1318u = add u 1
1319end
1320if ge u e
1321ret false
1322end
1323ue = u
1324while lt ue e bound BRBIG
1325if brspc get fxo ue
1326break
1327end
1328ue = add ue 1
1329end
1330if eq get fxo u 60
1331if eq get fxo sub ue 1 62
1332u = add u 1
1333ue = sub ue 1
1334end
1335end
1336if rec
1337brmdefrec add f 1 j u ue
1338end
1339ret true
1340end
1341fn brmdefrec ls ulong lz ulong us ulong ue ulong to void
1342n = get gbmrn 0
1343if ge n 128
1344ret
1345end
1346b = mul n 4
1347put gbmrd b ls
1348put gbmrd add b 1 lz
1349put gbmrd add b 2 us
1350put gbmrd add b 3 ue
1351put gbmrn 0 add n 1
1352end
1353note brmref: find the definition labelled fxo[s, e) (ASCII case-insensitive); sets BMDS/BMDE
1354fn brmref s ulong e ulong to bool
1355n = get gbmrn 0
1356for d ulong n bound BRBIG
1357b = mul d 4
1358ls = get gbmrd b
1359lz = get gbmrd add b 1
1360if eq sub lz ls sub e s
1361if brmlabeq ls s sub e s
1362brms BMDS get gbmrd add b 2
1363brms BMDE get gbmrd add b 3
1364brms BMTS 0
1365brms BMTE 0
1366ret true
1367end
1368end
1369end
1370ret false
1371end
1372fn brmlabeq a ulong b ulong n ulong to bool
1373for i ulong n bound BRBIG
1374if ne brlow get fxo add a i brlow get fxo add b i
1375ret false
1376end
1377end
1378ret true
1379end
1380note ---- inline
1381fn brmi a ulong e ulong to void
1382i = a
1383while lt i e bound BRBIG
1384i = brmi1 i e a
1385end
1386end
1387fn brmi1 i ulong e ulong a ulong to ulong
1388c = get fxo i
1389if eq c 92
1390if lt add i 1 e
1391if brpunct get fxo add i 1
1392fescc get fxo add i 1
1393ret add i 2
1394end
1395end
1396fputc 92
1397ret add i 1
1398end
1399if eq c 96
1400ret brmcode i e
1401end
1402if or eq c 33 eq c 91
1403r = brmlnk i e
1404if gt r 0
1405ret r
1406end
1407fputc c
1408ret add i 1
1409end
1410if eq c 60
1411r = brmicmt i e
1412if gt r 0
1413ret r
1414end
1415r = brmauto i e
1416if gt r 0
1417ret r
1418end
1419fescc c
1420ret add i 1
1421end
1422ret brmi2 i e a
1423end
1424fn brmi2 i ulong e ulong a ulong to ulong
1425c = get fxo i
1426if or eq c 42 eq c 95
1427r = brmemph i e a
1428if gt r 0
1429ret r
1430end
1431n = brmrun i e c
1432for k ulong n bound BRBIG
1433fputc c
1434end
1435ret add i n
1436end
1437if eq c 126
1438r = brmstrike i e
1439if gt r 0
1440ret r
1441end
1442fputc c
1443ret add i 1
1444end
1445if eq c 104
1446r = brmbare i e a
1447if gt r 0
1448ret r
1449end
1450end
1451if eq c 38
1452r = brment i e
1453if gt r 0
1454ret r
1455end
1456end
1457fescc c
1458ret add i 1
1459end
1460note brmcskip: past the code span starting at i (or past its backtick run when unmatched)
1461fn brmcskip i ulong e ulong to ulong
1462n = brmrun i e 96
1463j = add i n
1464while lt j e bound BRBIG
1465if eq get fxo j 96
1466m = brmrun j e 96
1467if eq m n
1468ret add j m
1469end
1470j = add j m
1471else
1472j = add j 1
1473end
1474end
1475ret add i n
1476end
1477fn brmcode i ulong e ulong to ulong
1478n = brmrun i e 96
1479k = brmcskip i e
1480if eq k add i n
1481for x ulong n bound BRBIG
1482fputc 96
1483end
1484ret k
1485end
1486s = add i n
1487t = sub k n
1488if gt sub t s 1
1489if and eq get fxo s 32 eq get fxo sub t 1 32
1490if not brmblank s t
1491s = add s 1
1492t = sub t 1
1493end
1494end
1495end
1496fput tbmcode
1497brmspan s t
1498fput tbmcodx
1499ret k
1500end
1501note brmbrk: matching "]" for the "[" at i (nested brackets, escapes and code spans honoured)
1502fn brmbrk i ulong e ulong to ulong
1503d = ulong 0
1504j = i
1505while lt j e bound BRBIG
1506c = get fxo j
1507if eq c 92
1508j = add j 2
1509continue
1510end
1511if eq c 96
1512j = brmcskip j e
1513continue
1514end
1515if eq c 91
1516d = add d 1
1517end
1518if eq c 93
1519d = sub d 1
1520if eq d 0
1521ret j
1522end
1523end
1524j = add j 1
1525end
1526ret 0
1527end
1528note brmdest: "(dest "title")" at k -> end after ")" or 0; dest to BMDS/BMDE, title BMTS/BMTE
1529fn brmdest k ulong e ulong to ulong
1530j = brmsksp add k 1 e
1531s = j
1532if and lt j e eq get fxo j 60
1533s = add j 1
1534j = brxfind s e 62
1535if ge j e
1536ret 0
1537end
1538brms BMDS s
1539brms BMDE j
1540j = add j 1
1541else
1542d = ulong 0
1543while lt j e bound BRBIG
1544c = get fxo j
1545if brspc c
1546break
1547end
1548if eq c 40
1549d = add d 1
1550end
1551if eq c 41
1552if eq d 0
1553break
1554end
1555d = sub d 1
1556end
1557j = add j 1
1558end
1559brms BMDS s
1560brms BMDE j
1561end
1562ret brmtitle j e
1563end
1564fn brmsksp j ulong e ulong to ulong
1565i = j
1566while lt i e bound BRBIG
1567if not brspc get fxo i
1568ret i
1569end
1570i = add i 1
1571end
1572ret i
1573end
1574fn brmtitle j ulong e ulong to ulong
1575brms BMTS 0
1576brms BMTE 0
1577i = brmsksp j e
1578if ge i e
1579ret 0
1580end
1581c = get fxo i
1582if or eq c 34 eq c 39
1583t = brxfind add i 1 e c
1584if ge t e
1585ret 0
1586end
1587brms BMTS add i 1
1588brms BMTE t
1589i = brmsksp add t 1 e
1590end
1591if ge i e
1592ret 0
1593end
1594if ne get fxo i 41
1595ret 0
1596end
1597ret add i 1
1598end
1599note brmlnk: "[text](dest)", "[text][label]", "[label]" and the same with "!" for images
1600fn brmlnk i ulong e ulong to ulong
1601img = eq get fxo i 33
1602o = i
1603if img
1604o = add i 1
1605if ge o e
1606ret 0
1607end
1608if ne get fxo o 91
1609ret 0
1610end
1611end
1612k = brmbrk o e
1613if eq k 0
1614ret 0
1615end
1616r = brmtarget o k e
1617if eq r 0
1618ret 0
1619end
1620if img
1621brmimgout add o 1 k
1622else
1623brmaout add o 1 k
1624end
1625ret r
1626end
1627note brmtarget: the destination after "]" at k; end of the construct or 0
1628fn brmtarget o ulong k ulong e ulong to ulong
1629n = add k 1
1630if lt n e
1631if eq get fxo n 40
1632r = brmdest n e
1633if gt r 0
1634ret r
1635end
1636end
1637if eq get fxo n 91
1638j = brxfind n e 93
1639if lt j e
1640if eq j add n 1
1641if brmref add o 1 k
1642ret add j 1
1643end
1644ret 0
1645end
1646if brmref add n 1 j
1647ret add j 1
1648end
1649ret 0
1650end
1651end
1652end
1653if brmref add o 1 k
1654ret n
1655end
1656ret 0
1657end
1658note brmkind: 0 unsafe scheme, 1 http(s)/mailto/protocol-relative, 2 "#anchor" or empty, 3 relative
1659fn brmkind s ulong e ulong to ulong
1660if ge s e
1661ret 2
1662end
1663c = get fxo s
1664if eq c 35
1665ret 2
1666end
1667if eq c 47
1668if lt add s 1 e
1669if eq get fxo add s 1 47
1670ret 1
1671end
1672end
1673ret 3
1674end
1675j = s
1676while lt j e bound BRBIG
1677x = get fxo j
1678if not or bralnum x or eq x 43 or eq x 45 eq x 46
1679break
1680end
1681j = add j 1
1682end
1683if and lt j e gt j s
1684if eq get fxo j 58
1685if brmschem s j
1686ret 1
1687end
1688ret 0
1689end
1690end
1691j = s
1692while lt j e bound BRBIG
1693x = get fxo j
1694if or eq x 58 or eq x 47 or eq x 63 eq x 35
1695break
1696end
1697j = add j 1
1698end
1699if lt j e
1700if eq get fxo j 58
1701ret 0
1702end
1703end
1704ret 3
1705end
1706fn brmschem s ulong j ulong to bool
1707if brmlabt s j tbmhttp
1708ret true
1709end
1710if brmlabt s j tbmhttps
1711ret true
1712end
1713ret brmlabt s j tbmmto
1714end
1715fn brmlabt s ulong j ulong t view uchar * to bool
1716if ne sub j s len t
1717ret false
1718end
1719for i ulong len t
1720if ne brlow get fxo add s i get t i
1721ret false
1722end
1723end
1724ret true
1725end
1726note brmuc: a byte of a relative destination: existing %XX kept, other unsafe bytes encoded
1727fn brmuc c uchar to void
1728if eq c 37
1729fputc c
1730ret
1731end
1732bruc c
1733end
1734note brmhref: href/src value of fxo[s, e) of kind k; raw = 1 for images (repo /raw/ URL)
1735fn brmhref s ulong e ulong k ulong raw ulong to void
1736if ne k 3
1737brmspan s e
1738ret
1739end
1740q = s
1741while lt q e bound BRBIG
1742x = get fxo q
1743if or eq x 35 eq x 63
1744break
1745end
1746q = add q 1
1747end
1748if gt q s
1749brmres s q
1750brurepo
1751if eq raw 1
1752fput tbmraw
1753else
1754fput tbmblob
1755end
1756bruref
1757for i ulong get gbmul 0 bound BRBIG
1758brmuc get gbmu i
1759end
1760end
1761brmspan q e
1762end
1763note brmres: resolve the relative path fxo[s, q) against gbmd into gbmu ("/a/b", "" = root)
1764fn brmres s ulong q ulong to void
1765put gbmul 0 0
1766if ne get fxo s 47
1767if gt get gbmdl 0 0
1768brmuadd 47
1769for i ulong get gbmdl 0 bound BRBIG
1770brmuadd get gbmd i
1771end
1772end
1773end
1774a = s
1775while le a q bound BRBIG
1776j = brxfind a q 47
1777brmuseg a j
1778a = add j 1
1779end
1780end
1781fn brmuadd c uchar to void
1782n = get gbmul 0
1783if lt n 4096
1784put gbmu n c
1785put gbmul 0 add n 1
1786end
1787end
1788fn brmuseg a ulong j ulong to void
1789n = sub j a
1790if eq n 0
1791ret
1792end
1793if and eq n 1 eq get fxo a 46
1794ret
1795end
1796if and eq n 2 and eq get fxo a 46 eq get fxo add a 1 46
1797k = get gbmul 0
1798while gt k 0 bound BRBIG
1799k = sub k 1
1800if eq get gbmu k 47
1801break
1802end
1803end
1804put gbmul 0 k
1805ret
1806end
1807brmuadd 47
1808for i ulong n bound BRBIG
1809brmuadd get fxo add a i
1810end
1811end
1812fn brmaout ts ulong te ulong to void
1813ds = brmg BMDS
1814de = brmg BMDE
1815k = brmkind ds de
1816if eq k 0
1817brmi ts te
1818ret
1819end
1820fput tbah
1821brmhref ds de k 0
1822if lt brmg BMTS brmg BMTE
1823fput tbmtitl
1824brmspan brmg BMTS brmg BMTE
1825end
1826if eq k 1
1827fput tbmaext
1828else
1829fput tbaq
1830end
1831brmi ts te
1832fput tbae
1833end
1834fn brmimgout ts ulong te ulong to void
1835ds = brmg BMDS
1836de = brmg BMDE
1837k = brmkind ds de
1838if eq k 3
1839fput tbmimg
1840brmhref ds de k 1
1841fput tbmalt
1842brmspan ts te
1843fput tbmimgx
1844ret
1845end
1846brmspan ts te
1847end
1848note brmauto: "<scheme:...>" or "<user@host>" autolinks
1849fn brmauto i ulong e ulong to ulong
1850j = add i 1
1851hat = false
1852while lt j e bound BRBIG
1853c = get fxo j
1854if or eq c 62 or eq c 60 brspc c
1855break
1856end
1857if eq c 64
1858hat = true
1859end
1860j = add j 1
1861end
1862if ge j e
1863ret 0
1864end
1865if ne get fxo j 62
1866ret 0
1867end
1868s = add i 1
1869if ge s j
1870ret 0
1871end
1872k = brmkind s j
1873if and eq k 1 ne get fxo s 47
1874fput tbah
1875brmspan s j
1876fput tbmaext
1877brmspan s j
1878fput tbae
1879ret add j 1
1880end
1881if and hat eq k 3
1882fput tbah
1883fput tbmmail
1884brmspan s j
1885fput tbmaext
1886brmspan s j
1887fput tbae
1888ret add j 1
1889end
1890ret 0
1891end
1892note brmbare: GFM-style bare http(s):// autolink at a word start
1893fn brmbare i ulong e ulong a ulong to ulong
1894if gt i a
1895if bralnum get fxo sub i 1
1896ret 0
1897end
1898end
1899n = ulong 0
1900if brxat i e tbmbhs
1901n = len tbmbhs
1902end
1903if eq n 0
1904if brxat i e tbmbh
1905n = len tbmbh
1906end
1907end
1908if eq n 0
1909ret 0
1910end
1911j = add i n
1912while lt j e bound BRBIG
1913c = get fxo j
1914if or brspc c eq c 60
1915break
1916end
1917j = add j 1
1918end
1919while gt j add i n bound BRBIG
1920c = get fxo sub j 1
1921if not brmtrail c
1922break
1923end
1924j = sub j 1
1925end
1926if le j add i n
1927ret 0
1928end
1929fput tbah
1930brmspan i j
1931fput tbmaext
1932brmspan i j
1933fput tbae
1934ret j
1935end
1936fn brmtrail c uchar to bool
1937if or eq c 46 or eq c 44 or eq c 58 eq c 59
1938ret true
1939end
1940if or eq c 33 or eq c 63 or eq c 41 eq c 39
1941ret true
1942end
1943ret or eq c 34 or eq c 42 or eq c 95 eq c 126
1944end
1945note brment: a named or numeric character reference kept as written
1946fn brment i ulong e ulong to ulong
1947j = add i 1
1948hex = false
1949num = false
1950if lt j e
1951if eq get fxo j 35
1952num = true
1953j = add j 1
1954if lt j e
1955if or eq get fxo j 120 eq get fxo j 88
1956hex = true
1957j = add j 1
1958end
1959end
1960end
1961end
1962s = j
1963while lt j e bound BRBIG
1964c = get fxo j
1965ok = bralnum c
1966if num
1967ok = brdig c
1968if hex
1969ok = lt brhexv c 16
1970end
1971end
1972if not ok
1973break
1974end
1975j = add j 1
1976end
1977n = sub j s
1978if or lt n 1 gt n 31
1979ret 0
1980end
1981if and not num lt n 2
1982ret 0
1983end
1984if or ge j e ne get fxo j 59
1985ret 0
1986end
1987for k ulong add sub j i 1 bound BRBIG
1988fputc get fxo add i k
1989end
1990ret add j 1
1991end
1992note ---- emphasis
1993fn brmemph i ulong e ulong a ulong to ulong
1994c = get fxo i
1995n = brmrun i e c
1996s = add i n
1997if ge s e
1998ret 0
1999end
2000if brspc get fxo s
2001ret 0
2002end
2003if and eq c 95 gt i a
2004if bralnum get fxo sub i 1
2005ret 0
2006end
2007end
2008if ge n 3
2009k = brmclose add i 3 e c 3
2010if gt k 0
2011fput tbmem
2012fput tbmst
2013brmi add i 3 k
2014fput tbmstx
2015fput tbmemx
2016ret add k 3
2017end
2018end
2019if ge n 2
2020k = brmclose add i 2 e c 2
2021if gt k 0
2022fput tbmst
2023brmi add i 2 k
2024fput tbmstx
2025ret add k 2
2026end
2027end
2028if ne n 1
2029ret 0
2030end
2031k = brmclose add i 1 e c 1
2032if eq k 0
2033ret 0
2034end
2035fput tbmem
2036brmi add i 1 k
2037fput tbmemx
2038ret add k 1
2039end
2040note brmclose: closing run of c (length w; for w = 1 a lone c, double runs are nested strong)
2041fn brmclose s ulong e ulong c uchar w ulong to ulong
2042j = s
2043while lt j e bound BRBIG
2044x = get fxo j
2045if eq x 92
2046j = add j 2
2047continue
2048end
2049if eq x 96
2050j = brmcskip j e
2051continue
2052end
2053if ne x c
2054j = add j 1
2055continue
2056end
2057r = brmrun j e c
2058if brmcfit j e r w c s
2059ret j
2060end
2061j = add j r
2062end
2063ret 0
2064end
2065fn brmcfit j ulong e ulong r ulong w ulong c uchar s ulong to bool
2066if le j s
2067ret false
2068end
2069if brspc get fxo sub j 1
2070ret false
2071end
2072if eq w 1
2073if eq r 2
2074ret false
2075end
2076else
2077if lt r w
2078ret false
2079end
2080end
2081if eq c 95
2082if lt add j w e
2083if bralnum get fxo add j w
2084ret false
2085end
2086end
2087end
2088ret true
2089end
2090fn brmstrike i ulong e ulong to ulong
2091n = brmrun i e 126
2092if ne n 2
2093ret 0
2094end
2095s = add i 2
2096if ge s e
2097ret 0
2098end
2099if brspc get fxo s
2100ret 0
2101end
2102k = brmclose s e 126 2
2103if eq k 0
2104ret 0
2105end
2106fput tbmdel
2107brmi s k
2108fput tbmdelx
2109ret add k 2
2110end