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 / seed / trace / tracecli.om

981 lines · 19724 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note seed/trace/tracecli.om: offline, read-only trace segment CLI (omega-mv #610), interface version 1.
3note Build: cat seed/trace/segment.om seed/trace/tsha.om seed/trace/tracecli.om | seed/out/omc > tracecli
4note Gate: sh seed/trace/cli-gate.sh. It scans the exact return line of fn ropen; the flags literal must stay 32768.
5note tracecli version
6note tracecli verify SEG integrity of one segment
7note tracecli show SEG every valid record
8note tracecli events SEG [--type T] [--range FROM TO] valid records of type T and FROM <= seq < TO
9note tracecli stats SEG [--type T] [--range FROM TO] record count and payload bytes per type
10note tracecli export SEG [--type T] [--range FROM TO] CSV with the source SHA-256 and the query
11note tracecli compare SEGA SEGB record-by-record comparison
12note tracecli list DIR verify every entry of a directory, by name
13note Nothing is written except stdout. Segments are opened O_RDONLY|O_NOFOLLOW (32768) and directories
14note O_RDONLY|O_DIRECTORY|O_NOFOLLOW (49152); nothing is created, so a symbolic link is refused (ELOOP).
15note A damaged segment is never silently shortened: the records before the damage are printed, the verify
16note line says "partial" with the reason and the bytes after the valid prefix, and the exit status is 3.
17note Every record printed is read again and re-checked (CRC, length, sequence) after the scan; a record
18note that no longer checks ends the listing with "changed-during-read at=N" and exit 3.
19note Exit status: 0 ok (compare: identical), 1 compare found a difference, 2 usage, 3 partial or
20note inconclusive, 4 refused (missing, symlink, bad header, unreadable file or directory), 5 stdout write failed.
21global obuf uchar 512
22global on ulong 1
23global wbad ulong 1
24global arec uchar 64
25global argb uchar 64
26global acnt ulong 1
27global moff ulong 96
28global mlen ulong 96
29global qtype ulong 1
30global qlo ulong 1
31global qhi ulong 1
32global wfail ulong 1
33global tcnt ulong 65536
34global tbytes ulong 65536
35global dpath uchar 1024
36global dlen ulong 1
37global dbuf uchar 4096
38global names uchar 16384
39global nlens ulong 64
40global ntype ulong 64
41global nnum ulong 1
42global ntrunc ulong 1
43global nord ulong 64
44note msgs: one message per line; message k is printed by omsg k. Lines 52..57 are the scan reasons
45note (sreason 0..5), lines 58..67 the command and option words.
46text msgs "usage: tracecli version | verify SEG | show SEG | events SEG [--type T] [--range FROM TO] | stats SEG [--type T] [--range FROM TO] | export SEG [--type T] [--range FROM TO] | compare SEGA SEGB | list DIR\ntracecli 1 segment-format 1\nsegment version=1 recsize=64 hdrsize=16\nverify \nok\npartial\n records=\n bytes=\n lost=\n reason=\nrefused code=\n errno=\nseq=\n type=\n len=\n crc=\n payload=\nquery type=\nany\n seq>=\n seq<\nmatched=\n of=\nchanged-during-read at=\ntype=\n payload-bytes=\nstats records=\n types=\nenergy=unavailable timing=unavailable (segment format 1 carries no typed measurements)\na: \nb: \ncompare basis=records (segment format 1 carries no machine, build or precision metadata: not a qualified cross-run comparison)\ncompare identical records=\ncompare differ at=\ncompare prefix a=\n b=\ncompare inconclusive\n# tracecli 1 export\n# source sha256=\n# \n# \nseq,type,len,crc,payload_hex\nlist \n: \ndirectory\nlist entries=\n ok=\n partial=\n refused=\n directories=\nlist truncated at 64 entries\nlist refused errno=\nclean\ntorn-tail\nbad-length\ncrc-mismatch\nseq-mismatch\nover-capacity\nversion\nverify\nshow\nevents\nstats\nexport\ncompare\nlist\n--type\n--range\n"
47text hexd "0123456789abcdef"
48const kusage ulong 0
49const kvers ulong 1
50const khdr ulong 2
51const kverify ulong 3
52const kok ulong 4
53const kpart ulong 5
54const krecs ulong 6
55const kbytes ulong 7
56const klost ulong 8
57const kreason ulong 9
58const krefused ulong 10
59const kerrno ulong 11
60const kseq ulong 12
61const ktype ulong 13
62const klen ulong 14
63const kcrc ulong 15
64const kpay ulong 16
65const kquery ulong 17
66const kany ulong 18
67const kseqge ulong 19
68const kseqlt ulong 20
69const kmatched ulong 21
70const kof ulong 22
71const kchanged ulong 23
72const ktypeeq ulong 24
73const kpbytes ulong 25
74const kstats ulong 26
75const ktypes ulong 27
76const kenergy ulong 28
77const ka ulong 29
78const kb ulong 30
79const kbasis ulong 31
80const kident ulong 32
81const kdiffer ulong 33
82const kprefix ulong 34
83const kbn ulong 35
84const kinconc ulong 36
85const kexport ulong 37
86const ksrc ulong 38
87const khash ulong 39
88const kcsvhdr ulong 41
89const klist ulong 42
90const kcolon ulong 43
91const kdir ulong 44
92const kentries ulong 45
93const knok ulong 46
94const knpart ulong 47
95const knref ulong 48
96const kndirs ulong 49
97const ktrunc ulong 50
98const klistref ulong 51
99const kreasons ulong 52
100const wversion ulong 58
101const wverify ulong 59
102const wshow ulong 60
103const wevents ulong 61
104const wstats ulong 62
105const wexport ulong 63
106const wcompare ulong 64
107const wlist ulong 65
108const wtype ulong 66
109const wrange ulong 67
110fn oflush to void
111w = write 1 obuf 0 get on 0
112if ne w long get on 0
113put wbad 0 1
114end
115put on 0 0
116end
117fn obyte b uchar to void
118if ge get on 0 512
119oflush
120end
121put obuf get on 0 b
122put on 0 add get on 0 1
123end
124fn onl to void
125obyte 10
126end
127fn onum v ulong to void
128d = new uchar 20 0
129x = v
130k = ulong 0
131go = true
132while go bound 21
133put d k uchar add 48 rem x 10
134k = add k 1
135x = div x 10
136if eq x 0
137go = false
138end
139end
140while gt k 0 bound 21
141k = sub k 1
142obyte get d k
143end
144end
145fn ohex b ulong to void
146obyte get hexd and shr b 4 15
147obyte get hexd and b 15
148end
149note minit fills moff/mlen with the start and length of every line of msgs (68 lines, 96 slots).
150fn minit to void
151s = ulong 0
152k = ulong 0
153for i ulong len msgs
154if eq get msgs i 10
155put moff k s
156put mlen k sub i s
157k = add k 1
158s = add i 1
159end
160end
161end
162fn omsg k ulong to void
163o = get moff k
164for i ulong get mlen k
165obyte get msgs add o i
166end
167end
168note omnum k v: message k then the decimal v.
169fn omnum k ulong v ulong to void
170omsg k
171onum v
172end
173note argword i: argument i into argb[0..acnt); acnt = 0 when it does not fit.
174fn argword i ulong to void
175put acnt 0 0
176n = argread i argb 0 64
177if ge n 0
178put acnt 0 ulong n
179end
180end
181note isword k: argb[0..acnt) equals message line k.
182fn isword k ulong to bool
183if ne get acnt 0 get mlen k
184ret false
185end
186o = get moff k
187for i ulong get mlen k
188if ne get argb i get msgs add o i
189ret false
190end
191end
192ret true
193end
194note argpath i: argument i becomes the segment path (tpath, tlen); 0 on success, 1 when it is empty
195note or longer than 1024 bytes.
196fn argpath i ulong to ulong
197n = argread i tpath 0 1024
198if le n 0
199ret 1
200end
201put tlen 0 ulong n
202ret 0
203end
204note argnum i: decimal argument i (1 to 5 digits, value at most 65535); 65536 when malformed.
205fn argnum i ulong to ulong
206argword i
207n = get acnt 0
208if or eq n 0 gt n 5
209ret 65536
210end
211v = ulong 0
212for k ulong n
213b = get argb k
214if or lt b 48 gt b 57
215ret 65536
216end
217v = add mul v 10 sub ulong b 48
218end
219if gt v 65535
220ret 65536
221end
222ret v
223end
224note parseq c: options from argument 3 to c-1 into qtype (65536 = any), qlo, qhi (seq range
225note qlo <= seq < qhi; default 0..4096, the whole segment). 0 ok, 1 usage error. A repeated option
226note replaces the earlier one.
227fn parseq c ulong to ulong
228put qtype 0 65536
229put qlo 0 0
230put qhi 0 4096
231i = ulong 3
232while lt i c bound 64
233argword i
234if isword wtype
235i = qopt i c 1
236else
237if isword wrange
238i = qopt i c 2
239else
240ret 1
241end
242end
243if eq i 0
244ret 1
245end
246end
247ret 0
248end
249note qopt i c k: the option at argument i takes k values (1 --type T, 2 --range FROM TO, FROM <= TO);
250note returns the index of the next argument, 0 when the values are missing or malformed.
251fn qopt i ulong c ulong k ulong to ulong
252if ge add i k c
253ret 0
254end
255a = argnum add i 1
256if gt a 65535
257ret 0
258end
259if eq k 1
260put qtype 0 a
261ret add i 2
262end
263b = argnum add i 2
264if or gt b 65535 gt a b
265ret 0
266end
267put qlo 0 a
268put qhi 0 b
269ret add i 3
270end
271fn oquery to void
272omsg kquery
273if eq get qtype 0 65536
274omsg kany
275else
276onum get qtype 0
277end
278omnum kseqge get qlo 0
279omnum kseqlt get qhi 0
280onl
281end
282note qmatch: the record in trec satisfies the query.
283fn qmatch to bool
284t = ld16 0
285s = ld32 4
286if and ne get qtype 0 65536 ne t get qtype 0
287ret false
288end
289ret and ge s get qlo 0 lt s get qhi 0
290end
291fn ousage to void
292put on 0 0
293omsg kusage
294onl
295end
296note orefused e: the refusal for scan result e; serrno (-errno) is reported for open failures (10).
297fn orefused e ulong to void
298omnum krefused e
299if eq e 10
300omnum kerrno ulong neg get serrno 0
301end
302onl
303end
304note overify: the verify line for the last segscan.
305fn overify to void
306omsg kverify
307if eq get sreason 0 0
308omsg kok
309else
310omsg kpart
311end
312omnum krecs get scount 0
313omnum kbytes get stotal 0
314omnum klost get slost 0
315omsg kreason
316omsg add kreasons get sreason 0
317onl
318end
319note vstatus: exit 3 when the scan stopped on damage (sreason not 0), else 0.
320fn vstatus to int
321ret partial get sreason 0
322end
323note partial r: exit 3 when r is not 0 (damage), else 0. The one place the partial exit status is chosen.
324fn partial r ulong to int
325if ne r 0
326ret 3
327end
328ret 0
329end
330fn orecord to void
331omnum kseq ld32 4
332omnum ktype ld16 0
333n = ld16 2
334omnum klen n
335omnum kcrc ld32 60
336omsg kpay
337for i ulong n
338ohex ulong get trec add 8 i
339end
340onl
341end
342fn ocsv to void
343onum ld32 4
344obyte 44
345onum ld16 0
346obyte 44
347n = ld16 2
348onum n
349obyte 44
350onum ld32 60
351obyte 44
352for i ulong n
353ohex ulong get trec add 8 i
354end
355onl
356end
357note ropen: the one open of a segment path by this unit: O_RDONLY|O_NOFOLLOW, nothing created. cli-gate.sh scans this exact return line.
358fn ropen to long
359ret fopen tpath 0 get tlen 0 32768 0
360end
361note rdrec fd i: read record i into trec and check it again (length, CRC, sequence = i).
362fn rdrec fd long i ulong to bool
363m = pread int fd trec 0 64 long add 16 mul i 64
364if ne m 64
365ret false
366end
367ret eq recok i 0
368end
369note tally: stats accumulation for the record in trec.
370fn tally to void
371t = ld16 0
372put tcnt t add get tcnt t 1
373put tbytes t add get tbytes t ld16 2
374end
375note walk m: the valid records (scount of them, after segscan) that match the query; m 0 prints
376note record lines, 1 CSV rows, 2 tallies them. Returns the match count. wfail = index + 1 of the record
377note whose re-read failed (0 none). At most 4096 valid records: bound 4097.
378fn walk m ulong to ulong
379put wfail 0 0
380fd = ropen
381if lt fd 0
382put wfail 0 1
383ret 0
384end
385hit = ulong 0
386n = get scount 0
387i = ulong 0
388while lt i n bound 4097
389if rdrec fd i
390if qmatch
391hit = add hit 1
392wone m
393end
394i = add i 1
395else
396put wfail 0 add i 1
397i = n
398end
399end
400shut fd
401ret hit
402end
403fn wone m ulong to void
404if eq m 0
405orecord
406end
407if eq m 1
408ocsv
409end
410if eq m 2
411tally
412end
413end
414fn ochanged to void
415if ne get wfail 0 0
416omnum kchanged sub get wfail 0 1
417onl
418end
419end
420note seg i: argument i becomes the segment path and is scanned; 0 scanned (clean or partial), 4
421note refused (the refusal is printed), 2 usage.
422fn seg i ulong to int
423if ne argpath i 0
424ret 2
425end
426e = segscan
427if ne e 0
428orefused e
429ret 4
430end
431ret 0
432end
433note endst: exit 3 when a re-read failed or the scan stopped on damage, else 0.
434fn endst to int
435if ne get wfail 0 0
436ret partial 1
437end
438ret vstatus
439end
440fn cmdverify to int
441e = seg 2
442if ne e 0
443ret e
444end
445overify
446ret vstatus
447end
448note cmdrecs m c: show/events (m 0) and export (m 1) after parseq; header, query, records, totals.
449fn cmdrecs m ulong to int
450e = seg 2
451if ne e 0
452ret e
453end
454if eq m 1
455ret cmdexport
456end
457omsg khdr
458onl
459oquery
460hit = walk 0
461omnum kmatched hit
462omnum kof get scount 0
463onl
464ochanged
465overify
466ret endst
467end
468fn cmdexport to int
469omsg kexport
470onl
471if ne hashfile 0
472omnum kchanged 0
473onl
474ret partial 1
475end
476omsg khash
477oquery
478omsg khash
479overify
480omsg kcsvhdr
481onl
482hit = walk 1
483ochanged
484ret endst
485end
486note hashfile: SHA-256 of the first stotal bytes of the segment (the bytes segscan saw), printed as
487note "# source sha256=<hex> bytes=<n>". 0 ok, 1 when the file could not be read back. stotal is at
488note most 16 + 64*4097 + 63 bytes before segscan stops (over-capacity), so at most 66 chunks of 4096:
489note bound 70.
490fn hashfile to ulong
491st = new ulong 9 0
492blk = new uchar 4096 0
493dig = new uchar 32 0
494shainit st
495fd = ropen
496if lt fd 0
497ret 1
498end
499tot = get stotal 0
500off = ulong 0
501bad = ulong 0
502go = true
503while go bound 70
504want = sub tot off
505if gt want 4096
506want = 4096
507end
508m = pread int fd blk 0 want long off
509if ne m long want
510bad = 1
511go = false
512else
513off = add off want
514if lt off tot
515shaupd st blk want
516else
517shafin st blk want dig
518go = false
519end
520end
521end
522shut fd
523if ne bad 0
524ret 1
525end
526omsg ksrc
527for i ulong 32
528ohex ulong get dig i
529end
530omnum kbytes tot
531onl
532ret 0
533end
534fn cmdstats to int
535e = seg 2
536if ne e 0
537ret e
538end
539omsg khdr
540onl
541oquery
542hit = walk 2
543nt = ulong 0
544pb = ulong 0
545for t ulong 65536
546if ne get tcnt t 0
547nt = add nt 1
548pb = add pb get tbytes t
549omnum ktypeeq t
550omnum krecs get tcnt t
551omnum kpbytes get tbytes t
552onl
553end
554end
555omnum kstats hit
556omnum ktypes nt
557omnum kpbytes pb
558onl
559omsg kenergy
560onl
561ochanged
562overify
563ret endst
564end
565note cmpside k: scan argument k (2 = a, 3 = b) and print its prefixed verify line; 0 when the scan
566note completed (clean or partial), else the refusal status.
567fn cmpside k ulong to int
568if eq k 2
569omsg ka
570else
571omsg kb
572end
573e = seg k
574if eq e 2
575ret 2
576end
577if ne e 0
578ret e
579end
580overify
581ret 0
582end
583note firstdiff fa fb n: index of the first of n records that differs between the two files, n if none,
584note n + 1 when a record could not be read back and re-checked.
585fn firstdiff fa long fb long n ulong to ulong
586at = n
587i = ulong 0
588while lt i n bound 4097
589if rdrec fa i
590for j ulong 64
591put arec j get trec j
592end
593if rdrec fb i
594if recdiff
595at = i
596i = n
597else
598i = add i 1
599end
600else
601at = add n 1
602i = n
603end
604else
605at = add n 1
606i = n
607end
608end
609ret at
610end
611note recdiff: the record in arec (side a) and trec (side b) differ in some byte.
612fn recdiff to bool
613for j ulong 64
614if ne get arec j get trec j
615ret true
616end
617end
618ret same
619end
620note same: recdiff's answer once all 64 bytes matched, so always false (no difference). It is a separate
621note function only so that "ret same" is a unique compare-mutant site for cli-gate.sh (mutant: ret true).
622fn same to bool
623ret false
624end
625note opn i: open argument i read-only (O_RDONLY|O_NOFOLLOW).
626fn opn i ulong to long
627e = argpath i
628if ne e 0
629ret -1
630end
631ret ropen
632end
633fn cmdcompare to int
634omsg kbasis
635onl
636e = cmpside 2
637pa = get sreason 0
638ca = get scount 0
639e2 = cmpside 3
640pb = get sreason 0
641cb = get scount 0
642if or eq e 2 eq e2 2
643ret 2
644end
645if or ne e 0 ne e2 0
646omsg kinconc
647onl
648ret 4
649end
650n = ca
651if lt cb n
652n = cb
653end
654fa = opn 2
655fb = opn 3
656at = add n 1
657if and ge fa 0 ge fb 0
658at = firstdiff fa fb n
659end
660if ge fa 0
661shut fa
662end
663if ge fb 0
664shut fb
665end
666ret cmpout pa ca pb cb at n
667end
668note cmpout: a differing record inside both valid prefixes is a definite difference (1); otherwise
669note damage on either side makes the result inconclusive (3); then unequal lengths differ (1).
670fn cmpout pa ulong ca ulong pb ulong cb ulong at ulong n ulong to int
671if gt at n
672omsg kinconc
673onl
674ret partial 1
675end
676if lt at n
677omnum kdiffer at
678onl
679ret 1
680end
681if or ne pa 0 ne pb 0
682omsg kinconc
683omnum krecs n
684onl
685ret partial 1
686end
687if ne ca cb
688omnum kprefix ca
689omnum kbn cb
690onl
691ret 1
692end
693omnum kident n
694onl
695ret 0
696end
697note dname e: the 2-byte little-endian reclen at dbuf[e+16]; getdents64 record layout d_ino u64,
698note d_off s64, d_reclen u16, d_type u8, d_name NUL-terminated.
699fn dreclen e ulong to ulong
700ret or ulong get dbuf add e 16 shl ulong get dbuf add e 17 8
701end
702note dkeep e r: store the entry at dbuf[e..) (not "." or "..") as name number nnum; ntrunc = 1 when 64
703note names are already stored or the name is longer than 255 bytes (the listing is then inconclusive).
704fn dkeep e ulong r ulong to void
705o = add e 19
706n = dnlen o r
707if dotname o n
708ret
709end
710if or ge get nnum 0 64 gt n 255
711put ntrunc 0 1
712ret
713end
714k = get nnum 0
715dstore k o n
716put ntype k ulong get dbuf add e 18
717put nord k k
718put nnum 0 add k 1
719end
720note dnlen o r: length of the NUL-terminated name at dbuf[o..r), at most 256 bytes are examined.
721fn dnlen o ulong r ulong to ulong
722n = ulong 0
723go = true
724while go bound 257
725if or ge add o n r gt n 255
726go = false
727else
728if eq get dbuf add o n 0
729go = false
730else
731n = add n 1
732end
733end
734end
735ret n
736end
737fn dstore k ulong o ulong n ulong to void
738b = mul k 256
739for i ulong n
740put names add b i get dbuf add o i
741end
742put nlens k n
743end
744fn dotname o ulong n ulong to bool
745if eq n 0
746ret true
747end
748if ne get dbuf o 46
749ret false
750end
751if eq n 1
752ret true
753end
754if eq n 2
755ret eq get dbuf add o 1 46
756end
757ret false
758end
759note dread fd: read every directory entry; 0 ok, else -errno. Every getdnts call that returns more than
760note 0 bytes consumes at least one entry, so the bound 100000 traps (exit 104) only for a directory of
761note more than 100000 entries.
762fn dread fd long to long
763go = true
764while go bound 100000
765r = getdnts int fd dbuf 0 4096
766if lt r 0
767ret r
768end
769if eq r 0
770go = false
771else
772dparse ulong r
773end
774end
775ret 0
776end
777fn dparse r ulong to void
778e = ulong 0
779while lt e r bound 4097
780rl = dreclen e
781if eq rl 0
782e = r
783else
784dkeep e r
785e = add e rl
786end
787end
788end
789note nless a b: name a sorts before name b (bytewise, a proper prefix first).
790fn nless a ulong b ulong to bool
791la = get nlens a
792lb = get nlens b
793m = la
794if lt lb m
795m = lb
796end
797for i ulong m
798x = get names add mul a 256 i
799y = get names add mul b 256 i
800if ne x y
801ret lt x y
802end
803end
804ret lt la lb
805end
806note nsort: insertion sort of nord by name, at most 64 entries.
807fn nsort to void
808n = get nnum 0
809for i ulong n
810j = i
811while gt j 0 bound 64
812p = get nord sub j 1
813q = get nord j
814if nless q p
815put nord j p
816put nord sub j 1 q
817j = sub j 1
818else
819j = 0
820end
821end
822end
823end
824note npath k: tpath = DIR "/" name k; 1 when it does not fit 1024 bytes.
825fn npath k ulong to ulong
826d = get dlen 0
827n = get nlens k
828if gt add add d 1 n 1024
829ret 1
830end
831for i ulong d
832put tpath i get dpath i
833end
834put tpath d 47
835for i ulong n
836put tpath add add d 1 i get names add mul k 256 i
837end
838put tlen 0 add add d 1 n
839ret 0
840end
841fn oname k ulong to void
842for i ulong get nlens k
843obyte get names add mul k 256 i
844end
845omsg kcolon
846end
847note lentry k: one line for name k; returns 0 ok, 1 partial, 2 refused, 3 directory. Spelled ret ulong 3 so the ret 3 in partial stays the unique mutant site.
848fn lentry k ulong to ulong
849oname k
850if eq get ntype k 4
851omsg kdir
852onl
853ret ulong 3
854end
855if ne npath k 0
856orefused 10
857ret 2
858end
859e = segscan
860if ne e 0
861orefused e
862ret 2
863end
864overify
865if ne get sreason 0 0
866ret 1
867end
868ret 0
869end
870fn cmdlist to int
871n = argread 2 dpath 0 1024
872if le n 0
873ret 2
874end
875put dlen 0 ulong n
876fd = fopen dpath 0 get dlen 0 49152 0
877if lt fd 0
878omnum klistref ulong neg fd
879onl
880ret 4
881end
882e = dread fd
883shut fd
884if ne e 0
885omnum klistref ulong neg e
886onl
887ret 4
888end
889nsort
890ret lall
891end
892fn lall to int
893c = new ulong 4 0
894for i ulong get nnum 0
895r = lentry get nord i
896put c r add get c r 1
897end
898omnum kentries get nnum 0
899omnum knok get c 0
900omnum knpart get c 1
901omnum knref get c 2
902omnum kndirs get c 3
903onl
904if ne get ntrunc 0 0
905omsg ktrunc
906onl
907ret partial 1
908end
909if ne add get c 1 get c 2 0
910ret partial 1
911end
912ret 0
913end
914note dispatch: the command word decides the argument count; anything else is usage (2). Nothing is
915note opened before the count and the options are checked.
916fn dispatch to int
917c = ulong argcnt
918if lt c 2
919ret 2
920end
921argword 1
922if isword wversion
923if ne c 2
924ret 2
925end
926omsg kvers
927onl
928ret 0
929end
930if lt c 3
931ret 2
932end
933if isword wcompare
934if ne c 4
935ret 2
936end
937ret cmdcompare
938end
939if ne parseq c 0
940ret 2
941end
942argword 1
943ret disp1 c
944end
945fn disp1 c ulong to int
946if isword wevents
947ret cmdrecs 0
948end
949if isword wexport
950ret cmdrecs 1
951end
952if isword wstats
953ret cmdstats
954end
955if ne c 3
956ret 2
957end
958if isword wverify
959ret cmdverify
960end
961if isword wshow
962ret cmdrecs 0
963end
964if isword wlist
965ret cmdlist
966end
967ret 2
968end
969note main: usage (2) discards any unflushed output and prints the usage line on stdout.
970fn main to int
971minit
972r = dispatch
973if eq r 2
974ousage
975end
976oflush
977if ne get wbad 0 0
978ret 5
979end
980ret r
981end