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 / omtex / lib / omtex.om

1176 lines · 21130 bytes Raw Blame History
1note omtex: an Omega -> LaTeX library. Concatenate it in front of a paper body (Omega has no imports, FR-3):
2note cat lib/omtex.om paper.om | omc > paper.gen ; ./paper.gen > paper.tex ; ./paper.gen check OMC DIR
3note Reserved for the library: globals and texts whose names start with z, functions whose names start with tx.
4note Any input the library cannot render safely is refused: a message on stderr, then trap 11 (exit 111).
5om2
6global zob uchar 4194304
7global zst ulong 64
8global znb uchar 32
9global zpb uchar 4096
10global zomc uchar 2048
11global zdir uchar 2048
12global zlng uchar 64
13global zws uchar 8
14note zst cells: 0 out pos, 1 element, 2 mode (1 check), 3 phase (1 preamble, 2 body, 3 ended), 4 quote,
15note 5 emphasis depth, 6-13 emphasis stack, 14 list depth, 15-30 list stack, 31 table open, 32 cells in row,
16note 33 pass, 34 fail, 35 fragments, 36 omc path len, 37 dir len, 38 expected rc of next Omega listing,
17note 39 language len.
18text zmhead "omtex: refused element "
19text zmat " at byte "
20text zmnl "\n"
21text zrbs ": backslash in prose must be followed by one of \\ * ` $ [ ] \" ~"
22text zrctl ": control byte"
23text zrutf ": malformed or unsupported UTF-8"
24text zrquo ": unbalanced \" quote"
25text zremph ": unclosed or misnested * / ** emphasis"
26text zrdeep ": emphasis nested deeper than 8"
27text zrcode ": unclosed ` code span"
28text zrmath ": unclosed or empty $ math span"
29text zrbrace ": unbalanced braces in math"
30text zrmch ": byte not allowed in math (% $ # control non-ASCII, or & outside align)"
31text zrnl ": \\\\ outside align"
32text zrdeny ": control sequence on the deny list"
33text zrkey ": label or key must be non-empty [A-Za-z0-9:._+/-]"
34text zropt ": option text must be [A-Za-z0-9,=.:+/*- ]"
35text zrorder ": word used in the wrong document phase"
36text zrlist ": item, cell or row outside its list or table, or list nesting over 16"
37text zrclose ": enddoc with an open list or table"
38text zrlst ": listing body has \\end{lstlisting}, non-ASCII or a control byte"
39text zrfull ": output larger than 4 MiB"
40text zrusage ": usage: GEN > paper.tex | GEN check OMC DIR"
41text zrlang ": set codelang before listing"
42text zrexec ": cannot write or run a listing check"
43text zbsl "\\textbackslash{}"
44text ztil "\\textasciitilde{}"
45text zcir "\\textasciicircum{}"
46text zlt "\\textless{}"
47text zgt "\\textgreater{}"
48text zbar "\\textbar{}"
49text zdq "\\textquotedbl{}"
50text zgrv "\\textasciigrave{}"
51text zlbr "{[}"
52text zrbr "{]}"
53text ztt "\\texttt{"
54text zemph "\\emph{"
55text zbold "\\textbf{"
56text zoq "``"
57text zcq "''"
58text zcite "~\\cite{"
59text zref "~\\ref{"
60text zdcls "\\documentclass"
61text zusep "\\usepackage"
62text ztitle "\\title{"
63text zauth "\\author{"
64text zdate "\\date{"
65text zbegd "\\begin{document}\n"
66text zmkt "\\maketitle\n\n"
67text zabs1 "\\begin{abstract}\n"
68text zabs2 "\n\\end{abstract}\n\n"
69text zsec "\\section{"
70text zsecs "\\section*{"
71text zsub "\\subsection{"
72text zsubs "\\subsection*{"
73text zlabel "\\label{"
74text znoind "\\noindent "
75text zitem "\\item "
76text zbitz "\\begin{itemize}"
77text zeitz "\\end{itemize}\n\n"
78text zbenu "\\begin{enumerate}"
79text zeenu "\\end{enumerate}\n\n"
80text zbeq "\\begin{equation}\n"
81text zeeq "\n\\end{equation}\n"
82text zbdm "\\[\n"
83text zedm "\n\\]\n"
84text zbal "\\begin{align}\n"
85text zeal "\n\\end{align}\n"
86text zbls "\\begin{lstlisting}[language="
87text zcap ",caption={"
88text zlbl "},label="
89text zels "\\end{lstlisting}\n\n"
90text zendl "\\end{lstlisting}"
91text zomega "Omega"
92text zendd "\\end{document}\n"
93text zbib1 "\\begin{thebibliography}{99}\n"
94text zbib2 "\\end{thebibliography}\n\n"
95text zbibi "\\bibitem{"
96text zbsty "\\bibliographystyle{"
97text zbibf "}\n\\bibliography{"
98text ztab1 "\\begin{table}[htbp]\n\\centering\n\\caption{"
99text ztab2 "\\begin{tabular}{"
100text ztab3 "\\end{tabular}\n\\end{table}\n\n"
101text zrow " \\\\\n"
102text zamp " & "
103text zhline "\\hline\n"
104text zfig1 "\\begin{figure}[htbp]\n\\centering\n\\includegraphics[width=\\linewidth]{"
105text zfig2 "}\n\\caption{"
106text zfig3 "\\end{figure}\n\n"
107text zck "check"
108text zlst1 "LISTING "
109text zlst2 " want="
110text zlst3 " got="
111text zpass " PASS\n"
112text zfailw " FAIL\n"
113text zfragw " fragment NOT_CHECKED\n"
114text zsum1 "LISTINGS pass="
115text zsum2 " fail="
116text zsum3 " fragments="
117text zsfx ".om"
118text zsfxb ".bin"
119text zsfxe ".err"
120text zd1 "input"
121text zd2 "include"
122text zd3 "write"
123text zd4 "def"
124text zd5 "edef"
125text zd6 "gdef"
126text zd7 "xdef"
127text zd8 "let"
128text zd9 "catcode"
129text zd10 "immediate"
130text zd11 "openout"
131text zd12 "openin"
132text zd13 "csname"
133text zd14 "special"
134text zd15 "read"
135text zlang1 "\\usepackage{xcolor}\n\\usepackage{listings}\n\\lstdefinelanguage{Omega}{sensitive=true,morecomment=[l]{note},morestring=[b]\",\n"
136text zlang2 "morekeywords=[1]{fn,to,end,if,else,while,bound,for,ret,break,continue,trap,exit,void,global,text,const,struct,own,view,edit,true,false,free,om2,ir,export,layout,field,at,little,big,abstract,holds,seal,open,inline,unroll,fresh,part,out,ops,requires,ensures,invariant,result,old},\n"
137text zlang3 "morekeywords=[2]{bool,uchar,u8,ushort,u16,uint,u32,ulong,u64,byte,i8,short,i16,int,i32,long,i64,f32,f64},\n"
138text zlang4 "morekeywords=[3]{add,sub,mul,div,rem,and,or,xor,shl,shr,eq,ne,lt,le,gt,ge,neg,not,get,len,read,write,put,new,bitcast,fsqrt,fabs,fmin,fmax,sizeof,offsetof,rotr,rotl},\n"
139text zlang5 "morekeywords=[4]{fclose,fsync,fchmod,fseek,socknew,listen,accept,fork,dupfd,monons,fopen,unlink,makedir,getdnts,connect,bind,waitpid,fstat,recv,send,sleepns,argcnt,argread,waitio,execprog,renames,rmdir,killpid,pipefds,getpid,realns,sockname,cwd,readlnk,sockopt,random,envcnt,envread,chdir,ftrunc,stat,link,symlnk,chmod,faccess,getuid,geteuid,getgid,getegid,lstat,truncate,chown,fchdir,getppid,umask,fdsync,memfd,setsid,getpgid,setpgid,pread,pwrite,getsid,syncfs,shutdown,devctl,mapnew,mapdrop,mapread,mapwrite,devcall,uvmctl,mapaddr,mapget,mapset,maphold,mapbind}}\n"
140text zlang6 "\\lstset{basicstyle=\\ttfamily\\small,keywordstyle=[1]\\color{blue!65!black},keywordstyle=[2]\\color{teal!75!black},keywordstyle=[3]\\color{violet!80!black},keywordstyle=[4]\\color{orange!70!black},commentstyle=\\itshape\\color{black!55},stringstyle=\\color{red!60!black},columns=flexible,keepspaces=true,frame=single,breaklines=true,captionpos=b}\n"
141note ---- byte output: stderr/stdout writers and the document buffer ----
142fn txw fd int t view uchar * to void
143o = ulong 0
144while lt o len t bound 999999
145n = write fd t o sub len t o
146if le n 0
147trap 12
148end
149o = add o ulong n
150end
151end
152fn txnum v ulong to ulong
153i = ulong 31
154put znb i uchar add 48 rem v 10
155x = div v 10
156while gt x 0 bound 21
157i = sub i 1
158put znb i uchar add 48 rem x 10
159x = div x 10
160end
161ret i
162end
163fn txwn fd int v ulong to void
164i = txnum v
165n = write fd znb i sub 32 i
166if le n 0
167trap 12
168end
169end
170fn txfail why view uchar * pos ulong to void
171txw 2 zmhead
172txwn 2 get zst 1
173txw 2 why
174txw 2 zmat
175txwn 2 pos
176txw 2 zmnl
177trap 11
178end
179fn txb b uchar to void
180p = get zst 0
181if ge p 4194304
182txfail zrfull p
183end
184put zob p b
185put zst 0 add p 1
186end
187fn txs t view uchar * to void
188for i ulong len t
189txb get t i
190end
191end
192fn txrng t view uchar * s ulong e ulong to void
193i = s
194while lt i e bound 999999
195txb get t i
196i = add i 1
197end
198end
199fn txflush to void
200n = get zst 0
201o = ulong 0
202while lt o n bound 999999
203w = write 1 zob o sub n o
204if le w 0
205trap 12
206end
207o = add o ulong w
208end
209end
210note ---- element and phase bookkeeping ----
211fn txel ph ulong to void
212put zst 1 add get zst 1 1
213if ne get zst 3 ph
214txfail zrorder 0
215end
216end
217note ---- character classes ----
218fn txalpha c uchar to bool
219ret or and ge c 65 le c 90 and ge c 97 le c 122
220end
221fn txalnum c uchar to bool
222ret or txalpha c and ge c 48 le c 57
223end
224fn txmark c uchar to bool
225if or or or eq c 92 eq c 42 or eq c 96 eq c 36 or or eq c 91 eq c 93 eq c 34
226ret true
227end
228ret eq c 126
229end
230fn txplain c uchar to bool
231ret or or or eq c 35 eq c 36 or eq c 37 eq c 38 or or eq c 95 eq c 123 eq c 125
232end
233fn txkeyc c uchar comma bool to bool
234if txalnum c
235ret true
236end
237if or or eq c 58 eq c 46 or eq c 95 eq c 45
238ret true
239end
240if or eq c 43 eq c 47
241ret true
242end
243ret and comma eq c 44
244end
245fn txoptc c uchar to bool
246if txkeyc c true
247ret true
248end
249ret or or eq c 61 eq c 42 eq c 32
250end
251note ---- one ASCII byte as LaTeX text ----
252fn txch2 c uchar pos ulong to void
253if eq c 126
254txs ztil
255ret
256end
257if eq c 94
258txs zcir
259ret
260end
261if eq c 60
262txs zlt
263ret
264end
265if eq c 62
266txs zgt
267ret
268end
269if eq c 124
270txs zbar
271ret
272end
273if eq c 34
274txs zdq
275ret
276end
277if eq c 96
278txs zgrv
279ret
280end
281if eq c 91
282txs zlbr
283ret
284end
285if eq c 93
286txs zrbr
287ret
288end
289txb c
290end
291fn txch c uchar pos ulong to void
292if txplain c
293txb 92
294txb c
295ret
296end
297if eq c 92
298txs zbsl
299ret
300end
301if or eq c 9 eq c 10
302txb 32
303ret
304end
305if or lt c 32 ge c 127
306txfail zrctl pos
307end
308txch2 c pos
309end
310note ---- prose scanner ----
311fn txfind t view uchar * s ulong c uchar to ulong
312i = s
313while lt i len t bound 999999
314if eq get t i c
315ret i
316end
317i = add i 1
318end
319ret len t
320end
321fn txpesc t view uchar * i ulong to ulong
322j = add i 1
323if ge j len t
324txfail zrbs i
325ret j
326end
327c = get t j
328if not txmark c
329txfail zrbs i
330end
331txch c j
332ret add j 1
333end
334fn txemph k ulong pos ulong to void
335d = get zst 5
336if gt d 0
337if eq get zst add 5 d k
338txb 125
339put zst 5 sub d 1
340ret
341end
342end
343if ge d 8
344txfail zrdeep pos
345end
346if eq k 1
347txs zemph
348else
349txs zbold
350end
351put zst 5 add d 1
352put zst add 6 d k
353end
354fn txpstar t view uchar * i ulong to ulong
355k = ulong 1
356j = add i 1
357if lt j len t
358if eq get t j 42
359k = ulong 2
360j = add j 1
361end
362end
363txemph k i
364ret j
365end
366fn txpcode t view uchar * i ulong to ulong
367s = add i 1
368j = txfind t s 96
369if ge j len t
370txfail zrcode i
371end
372txs ztt
373k = s
374while lt k j bound 999999
375txch get t k k
376k = add k 1
377end
378txb 125
379ret add j 1
380end
381note the closing $ of inline math; a backslash pair such as \$ inside the math is skipped
382fn txfindm t view uchar * s ulong to ulong
383i = s
384while lt i len t bound 999999
385c = get t i
386if eq c 36
387ret i
388end
389if eq c 92
390i = add i 1
391end
392i = add i 1
393end
394ret len t
395end
396fn txpmath t view uchar * i ulong to ulong
397s = add i 1
398j = txfindm t s
399if or ge j len t eq j s
400txfail zrmath i
401end
402txmchk t s j false
403txb 36
404txrng t s j
405txb 36
406ret add j 1
407end
408fn txpbrk t view uchar * i ulong to ulong
409s = add i 2
410if ge s len t
411txch 91 i
412ret add i 1
413end
414c = get t add i 1
415if and ne c 64 ne c 35
416txch 91 i
417ret add i 1
418end
419j = txfind t s 93
420txkey t s j eq c 64
421if eq c 64
422txs zcite
423else
424txs zref
425end
426txrng t s j
427txb 125
428ret add j 1
429end
430fn txquote to void
431if eq get zst 4 0
432txs zoq
433put zst 4 1
434else
435txs zcq
436put zst 4 0
437end
438end
439fn txutf8 t view uchar * i ulong to ulong
440c = get t i
441n = ulong 0
442if and ge c 194 le c 223
443n = ulong 1
444end
445if and ge c 224 le c 239
446n = ulong 2
447end
448if and ge c 240 le c 244
449n = ulong 3
450end
451if or eq n 0 ge add i n len t
452txfail zrutf i
453end
454for k ulong n
455d = get t add add i 1 k
456if or lt d 128 gt d 191
457txfail zrutf i
458end
459end
460txrng t i add add i 1 n
461ret add add i 1 n
462end
463fn txpat t view uchar * i ulong to ulong
464c = get t i
465if eq c 92
466ret txpesc t i
467end
468if eq c 42
469ret txpstar t i
470end
471if eq c 96
472ret txpcode t i
473end
474if eq c 36
475ret txpmath t i
476end
477if eq c 91
478ret txpbrk t i
479end
480if eq c 34
481txquote
482ret add i 1
483end
484if eq c 126
485txb 126
486ret add i 1
487end
488if ge c 128
489ret txutf8 t i
490end
491txch c i
492ret add i 1
493end
494fn txprose t view uchar * to void
495put zst 4 0
496put zst 5 0
497i = ulong 0
498while lt i len t bound 999999
499i = txpat t i
500end
501if ne get zst 4 0
502txfail zrquo len t
503end
504if ne get zst 5 0
505txfail zremph len t
506end
507end
508note ---- keys, options and math ----
509fn txkey t view uchar * s ulong e ulong comma bool to void
510if ge s e
511txfail zrkey s
512end
513i = s
514while lt i e bound 999999
515if not txkeyc get t i comma
516txfail zrkey i
517end
518i = add i 1
519end
520end
521fn txopt t view uchar * to void
522for i ulong len t
523if not txoptc get t i
524txfail zropt i
525end
526end
527end
528fn txeqr t view uchar * s ulong e ulong w view uchar * to bool
529if ne sub e s len w
530ret false
531end
532for i ulong len w
533if ne get t add s i get w i
534ret false
535end
536end
537ret true
538end
539fn txdeny2 t view uchar * s ulong e ulong to bool
540if or or txeqr t s e zd9 txeqr t s e zd10 or txeqr t s e zd11 txeqr t s e zd12
541ret true
542end
543ret or or txeqr t s e zd13 txeqr t s e zd14 txeqr t s e zd15
544end
545fn txdeny t view uchar * s ulong e ulong to bool
546if or or txeqr t s e zd1 txeqr t s e zd2 or txeqr t s e zd3 txeqr t s e zd4
547ret true
548end
549if or or txeqr t s e zd5 txeqr t s e zd6 or txeqr t s e zd7 txeqr t s e zd8
550ret true
551end
552ret txdeny2 t s e
553end
554fn txmcmd t view uchar * i ulong e ulong amp bool to ulong
555j = add i 1
556if ge j e
557txfail zrmch i
558end
559c = get t j
560if txalpha c
561k = add j 1
562while lt k e bound 999999
563if not txalpha get t k
564break
565end
566k = add k 1
567end
568if txdeny t j k
569txfail zrdeny i
570end
571ret k
572end
573if and eq c 92 not amp
574txfail zrnl i
575end
576if or lt c 32 gt c 126
577txfail zrmch j
578end
579ret add j 1
580end
581fn txmbad c uchar amp bool to bool
582if or or lt c 32 gt c 126 or eq c 37 eq c 36
583ret true
584end
585ret or eq c 35 and eq c 38 not amp
586end
587fn txmchk t view uchar * s ulong e ulong amp bool to void
588d = long 0
589i = s
590while lt i e bound 999999
591c = get t i
592if eq c 92
593i = txmcmd t i e amp
594continue
595end
596if eq c 123
597d = add d 1
598end
599if eq c 125
600d = sub d 1
601if lt d 0
602txfail zrbrace i
603end
604end
605if and txmbad c amp ne c 10
606txfail zrmch i
607end
608i = add i 1
609end
610if ne d 0
611txfail zrbrace e
612end
613end
614fn txmath t view uchar * amp bool to void
615if eq len t 0
616txfail zrmath 0
617end
618txmchk t 0 len t amp
619txs t
620end
621fn txlchk t view uchar * to void
622for i ulong len t
623c = get t i
624if and or lt c 32 gt c 126 and ne c 10 ne c 9
625txfail zrlst i
626end
627if eq c 92
628if txeqr t i add i len zendl zendl
629txfail zrlst i
630end
631end
632end
633end
634fn txlabel l view uchar * to void
635txkey l 0 len l false
636txs zlabel
637txs l
638txb 125
639end
640note ---- arguments and phase 0 ----
641fn txinit to void
642n = argcnt
643if eq n 1
644ret
645end
646if ne n 4
647txfail zrusage 0
648end
649k = argread 1 zpb 0 64
650if ne k 5
651txfail zrusage 0
652end
653for i ulong 5
654if ne get zpb i get zck i
655txfail zrusage 0
656end
657end
658a = argread 2 zomc 0 2040
659b = argread 3 zdir 0 2040
660if or le a 0 le b 0
661txfail zrusage 0
662end
663put zst 36 ulong a
664put zst 37 ulong b
665put zst 2 1
666end
667note ---- public preamble words ----
668fn docclass opts view uchar * cls view uchar * to void
669txel 0
670txinit
671put zst 3 1
672txopt opts
673txkey cls 0 len cls false
674txs zdcls
675if gt len opts 0
676txb 91
677txs opts
678txb 93
679end
680txb 123
681txs cls
682txb 125
683txb 10
684end
685fn usepkgo opts view uchar * name view uchar * to void
686txel 1
687txopt opts
688txkey name 0 len name true
689txs zusep
690txb 91
691txs opts
692txb 93
693txb 123
694txs name
695txb 125
696txb 10
697end
698fn usepkg name view uchar * to void
699txel 1
700txkey name 0 len name true
701txs zusep
702txb 123
703txs name
704txb 125
705txb 10
706end
707fn preamble t view uchar * to void
708txel 1
709txmath t true
710txb 10
711end
712fn omlang to void
713txel 1
714txs zlang1
715txs zlang2
716txs zlang3
717txs zlang4
718txs zlang5
719txs zlang6
720end
721fn txwrap w view uchar * t view uchar * to void
722txs w
723txprose t
724txb 125
725txb 10
726end
727fn title t view uchar * to void
728txel 1
729txwrap ztitle t
730end
731fn author t view uchar * to void
732txel 1
733txwrap zauth t
734end
735fn date t view uchar * to void
736txel 1
737txwrap zdate t
738end
739fn begindoc to void
740txel 1
741txb 10
742txs zbegd
743put zst 3 2
744end
745note ---- public body words ----
746fn maketitle to void
747txel 2
748txs zmkt
749end
750fn docabstract t view uchar * to void
751txel 2
752txs zabs1
753txprose t
754txs zabs2
755end
756fn section t view uchar * to void
757txel 2
758txwrap zsec t
759txb 10
760end
761fn sectionl t view uchar * l view uchar * to void
762txel 2
763txs zsec
764txprose t
765txb 125
766txlabel l
767txb 10
768txb 10
769end
770fn sectionn t view uchar * to void
771txel 2
772txwrap zsecs t
773txb 10
774end
775fn subsection t view uchar * to void
776txel 2
777txwrap zsub t
778txb 10
779end
780fn subsectn t view uchar * to void
781txel 2
782txwrap zsubs t
783txb 10
784end
785fn para t view uchar * to void
786txel 2
787txprose t
788txb 10
789txb 10
790end
791note prose: text that does not end its paragraph (e.g. the lead-in to a display).
792fn prose t view uchar * to void
793txel 2
794txprose t
795txb 10
796end
797fn paran t view uchar * to void
798txel 2
799txs znoind
800txprose t
801txb 10
802txb 10
803end
804fn rawtex t view uchar * to void
805txel 2
806txmath t true
807txb 10
808txb 10
809end
810note Displays (equation, displaymath, align) end without a blank line, so the next para continues the
811note same paragraph, as in LaTeX. parbreak ends that paragraph instead.
812fn parbreak to void
813txel 2
814txb 10
815end
816fn txlpush k ulong to void
817d = get zst 14
818if ge d 16
819txfail zrlist 0
820end
821put zst 14 add d 1
822put zst add 15 d k
823end
824fn itemize to void
825txel 2
826txlpush 1
827txs zbitz
828txb 10
829end
830fn itemizeo opts view uchar * to void
831txel 2
832txopt opts
833txlpush 1
834txs zbitz
835txb 91
836txs opts
837txb 93
838txb 10
839end
840fn enumerate to void
841txel 2
842txlpush 2
843txs zbenu
844txb 10
845end
846fn item t view uchar * to void
847txel 2
848d = get zst 14
849if eq d 0
850txfail zrlist 0
851end
852if eq get zst add 14 d 3
853txfail zrlist 0
854end
855txs zitem
856txprose t
857txb 10
858end
859fn endlist to void
860txel 2
861d = get zst 14
862if eq d 0
863txfail zrlist 0
864end
865k = get zst add 14 d
866put zst 14 sub d 1
867if eq k 1
868txs zeitz
869end
870if eq k 2
871txs zeenu
872end
873if eq k 3
874txs zbib2
875end
876end
877fn equation m view uchar * to void
878txel 2
879txs zbeq
880txmath m false
881txs zeeq
882end
883fn equationl l view uchar * m view uchar * to void
884txel 2
885txs zbeq
886txlabel l
887txb 10
888txmath m false
889txs zeeq
890end
891fn displaymath m view uchar * to void
892txel 2
893txs zbdm
894txmath m false
895txs zedm
896end
897fn align m view uchar * to void
898txel 2
899txs zbal
900txmath m true
901txs zeal
902end
903fn figure path view uchar * cap view uchar * l view uchar * to void
904txel 2
905txkey path 0 len path false
906txs zfig1
907txs path
908txs zfig2
909txprose cap
910txb 125
911txlabel l
912txb 10
913txs zfig3
914end
915fn table cap view uchar * l view uchar * spec view uchar * to void
916txel 2
917if ne get zst 31 0
918txfail zrlist 0
919end
920txs ztab1
921txprose cap
922txb 125
923txlabel l
924txb 10
925txs ztab2
926txmath spec false
927txb 125
928txb 10
929put zst 31 1
930put zst 32 0
931end
932fn cell t view uchar * to void
933txel 2
934if eq get zst 31 0
935txfail zrlist 0
936end
937if gt get zst 32 0
938txs zamp
939end
940txprose t
941put zst 32 add get zst 32 1
942end
943fn row to void
944txel 2
945if or eq get zst 31 0 eq get zst 32 0
946txfail zrlist 0
947end
948txs zrow
949put zst 32 0
950end
951fn hline to void
952txel 2
953if or eq get zst 31 0 ne get zst 32 0
954txfail zrlist 0
955end
956txs zhline
957end
958fn endtable to void
959txel 2
960if or eq get zst 31 0 ne get zst 32 0
961txfail zrlist 0
962end
963txs ztab3
964put zst 31 0
965end
966fn bibbegin to void
967txel 2
968txlpush 3
969txs zbib1
970end
971fn bibitem k view uchar * t view uchar * to void
972txel 2
973d = get zst 14
974if or eq d 0 ne get zst add 14 d 3
975txfail zrlist 0
976end
977txkey k 0 len k false
978txs zbibi
979txs k
980txb 125
981txb 32
982txprose t
983txb 10
984end
985fn bibtex style view uchar * file view uchar * to void
986txel 2
987txkey style 0 len style false
988txkey file 0 len file false
989txs zbsty
990txs style
991txs zbibf
992txs file
993txb 125
994txb 10
995end
996note ---- listings ----
997fn codelang t view uchar * to void
998txel 2
999txkey t 0 len t false
1000if gt len t 60
1001txfail zrkey 60
1002end
1003for i ulong len t
1004put zlng i get t i
1005end
1006put zst 39 len t
1007end
1008fn omrefuse rc ulong to void
1009txel 2
1010put zst 38 rc
1011end
1012fn txlhead cap view uchar * l view uchar * omega bool to void
1013txkey l 0 len l false
1014txs zbls
1015if omega
1016txs zomega
1017else
1018n = get zst 39
1019if eq n 0
1020txfail zrlang 0
1021end
1022for i ulong n
1023txb get zlng i
1024end
1025end
1026txs zcap
1027txprose cap
1028txs zlbl
1029txs l
1030txb 93
1031txb 10
1032end
1033fn txlbody code view uchar * to void
1034txlchk code
1035txs code
1036n = len code
1037if or eq n 0 ne get code sub n 1 10
1038txb 10
1039end
1040txs zels
1041end
1042fn listing cap view uchar * l view uchar * code view uchar * to void
1043txel 2
1044txlhead cap l false
1045txlbody code
1046end
1047fn txpath l view uchar * sfx view uchar * to ulong
1048n = get zst 37
1049for i ulong n
1050put zpb i get zdir i
1051end
1052put zpb n 47
1053p = add n 1
1054for i ulong len l
1055put zpb add p i get l i
1056end
1057p = add p len l
1058for i ulong len sfx
1059put zpb add p i get sfx i
1060end
1061p = add p len sfx
1062put zpb p 0
1063ret p
1064end
1065fn txsave l view uchar * code view uchar * to void
1066n = txpath l zsfx
1067fd = fopen zpb 0 n 577 420
1068if lt fd 0
1069txfail zrexec 0
1070end
1071txw int fd code
1072c = fclose int fd
1073end
1074fn txchild l view uchar * to void
1075n = txpath l zsfx
1076fd = fopen zpb 0 n 0 0
1077if lt fd 0
1078exit 97
1079end
1080r = dupfd int fd 0 0
1081n = txpath l zsfxb
1082fd = fopen zpb 0 n 577 493
1083r = dupfd int fd 1 0
1084n = txpath l zsfxe
1085fd = fopen zpb 0 n 577 420
1086r = dupfd int fd 2 0
1087m = get zst 36
1088put zpb 0 1
1089put zpb 1 0
1090put zpb 2 uchar and m 255
1091put zpb 3 uchar shr m 8
1092for i ulong m
1093put zpb add 4 i get zomc i
1094end
1095r = execprog zpb 0 add 4 m
1096exit 97
1097end
1098fn txrun l view uchar * to ulong
1099pid = fork
1100if lt pid 0
1101txfail zrexec 0
1102end
1103if eq pid 0
1104txchild l
1105end
1106r = waitpid int pid zws 0 4 0
1107if lt r 0
1108txfail zrexec 0
1109end
1110s = get zws 0
1111if ne and s 127 0
1112ret add 256 ulong and s 127
1113end
1114ret ulong get zws 1
1115end
1116fn txcheck l view uchar * code view uchar * to void
1117w = get zst 38
1118txsave l code
1119g = txrun l
1120txw 1 zlst1
1121txw 1 l
1122txw 1 zlst2
1123txwn 1 w
1124txw 1 zlst3
1125txwn 1 g
1126if eq g w
1127txw 1 zpass
1128put zst 33 add get zst 33 1
1129else
1130txw 1 zfailw
1131put zst 34 add get zst 34 1
1132end
1133end
1134fn omlisting cap view uchar * l view uchar * code view uchar * to void
1135txel 2
1136txlhead cap l true
1137txlbody code
1138if eq get zst 2 1
1139txcheck l code
1140end
1141put zst 38 0
1142end
1143fn omfragment cap view uchar * l view uchar * code view uchar * to void
1144txel 2
1145txlhead cap l true
1146txlbody code
1147if eq get zst 2 1
1148txw 1 zlst1
1149txw 1 l
1150txw 1 zfragw
1151end
1152put zst 35 add get zst 35 1
1153end
1154note ---- end of document ----
1155fn enddoc to void
1156txel 2
1157if or ne get zst 14 0 ne get zst 31 0
1158txfail zrclose 0
1159end
1160put zst 3 3
1161txs zendd
1162if eq get zst 2 0
1163txflush
1164ret
1165end
1166txw 1 zsum1
1167txwn 1 get zst 33
1168txw 1 zsum2
1169txwn 1 get zst 34
1170txw 1 zsum3
1171txwn 1 get zst 35
1172txw 1 zmnl
1173if ne get zst 34 0
1174exit 113
1175end
1176end