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 / si / harvester / harvester.om

1011 lines · 18461 bytes Raw Blame History
1om2
2note si/harvester/harvester.om: Zero-telemetry documentation & reasoning harvester in pure OM-2.
3note Faithful conversion of harvester (extractor.rs, filter.rs, export.rs) + markdown doc extraction:
4note - Reads markdown/text on stdin (zero network, zero disk secrets, zero telemetry)
5note - Extracts # / ## / ### headings outside fenced code blocks
6note - Counts fenced code blocks (``` fences)
7note - Extracts [text](url) markdown links, rejects telemetry/tracking domains & unsafe schemes,
8note strips tracking query parameters (utm_*, fbclid, gclid, mc_eid), deduplicates links via SHA-256
9note - Extracts key metadata lines (title, author, license, pin, source, date, version, provider, model)
10note - Extracts <think>...</think> and <thought>...</thought> reasoning blocks with quality scoring
11note - Emits deterministic JSONL records on stdout with RFC 8259 string escaping.
12
13global inbuf uchar 32768
14global rdbuf uchar 4096
15global outbuf uchar 32768
16global urlbuf uchar 512
17global cleanurl uchar 512
18global decbuf uchar 32
19global stats ulong 16
20global shastate uint 8
21global shak uint 64
22global shaw uint 64
23global shablk uchar 64
24global shadig uchar 32
25global shahex uchar 64
26global seenfp uchar 4096
27
28note stats indices
29const st_inlen ulong 0
30const st_outlen ulong 1
31const st_heads ulong 2
32const st_blocks ulong 3
33const st_links ulong 4
34const st_telrej ulong 5
35const st_strip ulong 6
36const st_meta ulong 7
37const st_reas ulong 8
38const st_qual ulong 9
39const st_clen ulong 10
40const st_seencnt ulong 11
41const st_dedup ulong 12
42
43text khex "0123456789abcdef"
44text j_head1 "{\"type\":\"heading\",\"level\":"
45text j_text ",\"text\":\""
46text j_link1 "{\"type\":\"link\",\"text\":\""
47text j_url "\",\"url\":\""
48text j_meta1 "{\"type\":\"meta\",\"key\":\""
49text j_val "\",\"value\":\""
50text j_reas1 "{\"type\":\"reasoning\",\"tokens\":"
51text j_qm ",\"quality_milli\":"
52text j_sum1 "{\"type\":\"summary\",\"headings\":"
53text j_sum2 ",\"code_blocks\":"
54text j_sum3 ",\"links\":"
55text j_sum4 ",\"telemetry_rejected\":"
56text j_sum5 ",\"tracking_stripped\":"
57text j_sum6 ",\"meta\":"
58text j_sum7 ",\"reasoning\":"
59text j_sum8 ",\"quality_milli\":"
60text j_sum9 ",\"sha256\":\""
61text j_end "\"}\n"
62
63text t_fence "```"
64text t_think_o "<think>"
65text t_think_c "</think>"
66text t_thought_o "<thought>"
67text t_thought_c "</thought>"
68text t_kw_step "step"
69text t_kw_ver "verify"
70text t_kw_bigo "O("
71
72note Metadata keys
73text mk_title "title:"
74text mk_author "author:"
75text mk_lic "license:"
76text mk_pin "pin:"
77text mk_src "source:"
78text mk_date "date:"
79text mk_ver "version:"
80text mk_prov "provider:"
81text mk_mod "model:"
82
83note Telemetry/tracking domain patterns and unsafe schemes
84text td_ga "google-analytics.com"
85text td_gtm "googletagmanager.com"
86text td_dc "doubleclick.net"
87text td_mp "mixpanel.com"
88text td_sg1 "segment.io"
89text td_sg2 "segment.com"
90text td_amp "amplitude.com"
91text td_hj "hotjar.com"
92text td_fb "facebook.com/tr"
93text td_tel "telemetry."
94text td_ana "analytics."
95text td_pix "pixel."
96text td_bea "beacon."
97text td_js "javascript:"
98text td_dat "data:"
99
100note Tracking query param prefixes
101text qp_utm "utm_"
102text qp_fb "fbclid="
103text qp_gc "gclid="
104text qp_mc "mc_eid="
105
106text e_io "harvester: failed to read stdin\n"
107
108fn write_all fd int src view uchar * off ulong n ulong to void
109p = ulong 0
110while lt p n bound 32768
111k = write fd src add off p sub n p
112if le k 0
113exit 2
114end
115p = add p ulong k
116end
117end
118
119fn wstr fd int s view uchar * to void
120write_all fd s 0 len s
121end
122
123fn to_lower c uchar to uchar
124if and ge c 65 le c 90
125ret add c 32
126end
127ret c
128end
129
130fn out_push_ch c uchar to void
131p = get stats st_outlen
132if lt p 32768
133put outbuf p c
134put stats st_outlen add p 1
135end
136end
137
138fn out_push_lit s view uchar * to void
139sl = len s
140i = ulong 0
141while lt i sl bound 1024
142out_push_ch get s i
143i = add i 1
144end
145end
146
147fn out_push_dec v ulong to void
148i = ulong 32
149n = v
150while true bound 24
151i = sub i 1
152put decbuf i uchar add rem n 10 48
153n = div n 10
154if eq n 0
155break
156end
157end
158p = i
159while lt p 32 bound 32
160out_push_ch get decbuf p
161p = add p 1
162end
163end
164
165fn out_push_json_ch c uchar to void
166if eq c 34
167out_push_ch 92
168out_push_ch 34
169ret
170end
171if eq c 92
172out_push_ch 92
173out_push_ch 92
174ret
175end
176if eq c 10
177out_push_ch 92
178out_push_ch 110
179ret
180end
181if eq c 13
182out_push_ch 92
183out_push_ch 114
184ret
185end
186if eq c 9
187out_push_ch 92
188out_push_ch 116
189ret
190end
191if ge c 32
192out_push_ch c
193end
194end
195
196fn out_push_in_json off ulong n ulong to void
197i = ulong 0
198while lt i n bound 32768
199if lt add off i 32768
200out_push_json_ch get inbuf add off i
201end
202i = add i 1
203end
204end
205
206fn out_push_cleanurl_json to void
207n = get stats st_clen
208i = ulong 0
209while lt i n bound 512
210out_push_json_ch get cleanurl i
211i = add i 1
212end
213end
214
215fn out_push_shahex to void
216for i ulong 64
217out_push_ch get shahex i
218end
219end
220
221note FIPS 180-4 SHA-256
222fn sha_kinit to void
223put shak 0 0x428a2f98
224put shak 1 0x71374491
225put shak 2 0xb5c0fbcf
226put shak 3 0xe9b5dba5
227put shak 4 0x3956c25b
228put shak 5 0x59f111f1
229put shak 6 0x923f82a4
230put shak 7 0xab1c5ed5
231put shak 8 0xd807aa98
232put shak 9 0x12835b01
233put shak 10 0x243185be
234put shak 11 0x550c7dc3
235put shak 12 0x72be5d74
236put shak 13 0x80deb1fe
237put shak 14 0x9bdc06a7
238put shak 15 0xc19bf174
239put shak 16 0xe49b69c1
240put shak 17 0xefbe4786
241put shak 18 0x0fc19dc6
242put shak 19 0x240ca1cc
243put shak 20 0x2de92c6f
244put shak 21 0x4a7484aa
245put shak 22 0x5cb0a9dc
246put shak 23 0x76f988da
247put shak 24 0x983e5152
248put shak 25 0xa831c66d
249put shak 26 0xb00327c8
250put shak 27 0xbf597fc7
251put shak 28 0xc6e00bf3
252put shak 29 0xd5a79147
253put shak 30 0x06ca6351
254put shak 31 0x14292967
255put shak 32 0x27b70a85
256put shak 33 0x2e1b2138
257put shak 34 0x4d2c6dfc
258put shak 35 0x53380d13
259put shak 36 0x650a7354
260put shak 37 0x766a0abb
261put shak 38 0x81c2c92e
262put shak 39 0x92722c85
263put shak 40 0xa2bfe8a1
264put shak 41 0xa81a664b
265put shak 42 0xc24b8b70
266put shak 43 0xc76c51a3
267put shak 44 0xd192e819
268put shak 45 0xd6990624
269put shak 46 0xf40e3585
270put shak 47 0x106aa070
271put shak 48 0x19a4c116
272put shak 49 0x1e376c08
273put shak 50 0x2748774c
274put shak 51 0x34b0bcb5
275put shak 52 0x391c0cb3
276put shak 53 0x4ed8aa4a
277put shak 54 0x5b9cca4f
278put shak 55 0x682e6ff3
279put shak 56 0x748f82ee
280put shak 57 0x78a5636f
281put shak 58 0x84c87814
282put shak 59 0x8cc70208
283put shak 60 0x90befffa
284put shak 61 0xa4506ceb
285put shak 62 0xbef9a3f7
286put shak 63 0xc67178f2
287end
288
289fn sha_iv to void
290put shastate 0 0x6a09e667
291put shastate 1 0xbb67ae85
292put shastate 2 0x3c6ef372
293put shastate 3 0xa54ff53a
294put shastate 4 0x510e527f
295put shastate 5 0x9b05688c
296put shastate 6 0x1f83d9ab
297put shastate 7 0x5be0cd19
298end
299
300fn sha_sched to void
301for i ulong 16
302q = mul i 4
303x = uint get shablk q
304x = or shl x 8 uint get shablk add q 1
305x = or shl x 8 uint get shablk add q 2
306put shaw i or shl x 8 uint get shablk add q 3
307end
308for i ulong 48
309x = get shaw add i 1
310y = get shaw add i 14
311s0 = xor xor rotr x 7 rotr x 18 shr x 3
312s1 = xor xor rotr y 17 rotr y 19 shr y 10
313put shaw add i 16 add add get shaw i get shaw add i 9 add s0 s1
314end
315end
316
317fn sha_compress to void
318sha_sched
319a = get shastate 0
320b = get shastate 1
321c = get shastate 2
322d = get shastate 3
323e = get shastate 4
324f = get shastate 5
325g = get shastate 6
326h = get shastate 7
327t = uint 0
328for i ulong 64
329h = add h get shak i
330h = add h get shaw i
331t = xor rotr e 6 rotr e 11
332t = xor t rotr e 25
333h = add h t
334h = add h xor g and e xor f g
335d = add d h
336t = xor rotr a 2 rotr a 13
337t = xor t rotr a 22
338h = add h t
339h = add h or and a b and c or a b
340t = h
341h = g
342g = f
343f = e
344e = d
345d = c
346c = b
347b = a
348a = t
349end
350put shastate 0 add get shastate 0 a
351put shastate 1 add get shastate 1 b
352put shastate 2 add get shastate 2 c
353put shastate 3 add get shastate 3 d
354put shastate 4 add get shastate 4 e
355put shastate 5 add get shastate 5 f
356put shastate 6 add get shastate 6 g
357put shastate 7 add get shastate 7 h
358end
359
360fn sha_finalize_hex to void
361for i ulong 8
362w = get shastate i
363q = mul i 4
364put shadig q uchar and shr w 24 255
365put shadig add q 1 uchar and shr w 16 255
366put shadig add q 2 uchar and shr w 8 255
367put shadig add q 3 uchar and w 255
368end
369for i ulong 32
370bv = ulong get shadig i
371put shahex mul i 2 get khex shr bv 4
372put shahex add mul i 2 1 get khex and bv 15
373end
374end
375
376fn sha256_inbuf to void
377dlen = get stats st_inlen
378sha_kinit
379sha_iv
380off = ulong 0
381while ge sub dlen off 64 bound 1024
382for j ulong 64
383put shablk j get inbuf add off j
384end
385sha_compress
386off = add off 64
387end
388remn = sub dlen off
389for j ulong 64
390if lt j remn
391put shablk j get inbuf add off j
392else
393put shablk j 0
394end
395end
396put shablk remn 0x80
397if gt remn 55
398sha_compress
399for j ulong 64
400put shablk j 0
401end
402end
403bits = mul dlen 8
404put shablk 56 uchar and shr bits 56 255
405put shablk 57 uchar and shr bits 48 255
406put shablk 58 uchar and shr bits 40 255
407put shablk 59 uchar and shr bits 32 255
408put shablk 60 uchar and shr bits 24 255
409put shablk 61 uchar and shr bits 16 255
410put shablk 62 uchar and shr bits 8 255
411put shablk 63 uchar and bits 255
412sha_compress
413sha_finalize_hex
414end
415
416fn sha256_cleanurl to void
417dlen = get stats st_clen
418sha_kinit
419sha_iv
420off = ulong 0
421while ge sub dlen off 64 bound 16
422for j ulong 64
423put shablk j to_lower get cleanurl add off j
424end
425sha_compress
426off = add off 64
427end
428remn = sub dlen off
429for j ulong 64
430if lt j remn
431put shablk j to_lower get cleanurl add off j
432else
433put shablk j 0
434end
435end
436put shablk remn 0x80
437if gt remn 55
438sha_compress
439for j ulong 64
440put shablk j 0
441end
442end
443bits = mul dlen 8
444put shablk 56 uchar and shr bits 56 255
445put shablk 57 uchar and shr bits 48 255
446put shablk 58 uchar and shr bits 40 255
447put shablk 59 uchar and shr bits 32 255
448put shablk 60 uchar and shr bits 24 255
449put shablk 61 uchar and shr bits 16 255
450put shablk 62 uchar and shr bits 8 255
451put shablk 63 uchar and bits 255
452sha_compress
453sha_finalize_hex
454end
455
456note Deduplication check against seenfp (up to 64 unique 64-byte hex fingerprints)
457fn dedup_insert_cleanurl to bool
458sha256_cleanurl
459cnt = get stats st_seencnt
460k = ulong 0
461while lt k cnt bound 64
462base = mul k 64
463same = true
464for i ulong 64
465if ne get seenfp add base i get shahex i
466same = false
467end
468end
469if same
470put stats st_dedup add get stats st_dedup 1
471ret false
472end
473k = add k 1
474end
475if lt cnt 64
476base2 = mul cnt 64
477for i ulong 64
478put seenfp add base2 i get shahex i
479end
480put stats st_seencnt add cnt 1
481end
482ret true
483end
484
485note String matching helpers on inbuf and urlbuf
486fn in_starts_ci off ulong lim ulong pat view uchar * to bool
487pl = len pat
488if gt add off pl lim
489ret false
490end
491i = ulong 0
492while lt i pl bound 64
493if ne to_lower get inbuf add off i to_lower get pat i
494ret false
495end
496i = add i 1
497end
498ret true
499end
500
501fn in_contains_ci off ulong lim ulong pat view uchar * to bool
502pl = len pat
503if lt sub lim off pl
504ret false
505end
506endp = add sub lim pl 1
507p = off
508while lt p endp bound 32768
509if in_starts_ci p lim pat
510ret true
511end
512p = add p 1
513end
514ret false
515end
516
517fn url_starts_ci pos ulong ulen ulong pat view uchar * to bool
518pl = len pat
519if gt add pos pl ulen
520ret false
521end
522i = ulong 0
523while lt i pl bound 64
524if ne to_lower get urlbuf add pos i to_lower get pat i
525ret false
526end
527i = add i 1
528end
529ret true
530end
531
532fn url_contains_ci ulen ulong pat view uchar * to bool
533pl = len pat
534if gt pl ulen
535ret false
536end
537lim = add sub ulen pl 1
538i = ulong 0
539while lt i lim bound 512
540if url_starts_ci i ulen pat
541ret true
542end
543i = add i 1
544end
545ret false
546end
547
548fn is_telemetry_url ulen ulong to bool
549if url_starts_ci 0 ulen td_js
550ret true
551end
552if url_starts_ci 0 ulen td_dat
553ret true
554end
555if url_contains_ci ulen td_ga
556ret true
557end
558if url_contains_ci ulen td_gtm
559ret true
560end
561if url_contains_ci ulen td_dc
562ret true
563end
564if url_contains_ci ulen td_mp
565ret true
566end
567if url_contains_ci ulen td_sg1
568ret true
569end
570if url_contains_ci ulen td_sg2
571ret true
572end
573if url_contains_ci ulen td_amp
574ret true
575end
576if url_contains_ci ulen td_hj
577ret true
578end
579if url_contains_ci ulen td_fb
580ret true
581end
582if url_contains_ci ulen td_tel
583ret true
584end
585if url_contains_ci ulen td_ana
586ret true
587end
588if url_contains_ci ulen td_pix
589ret true
590end
591ret url_contains_ci ulen td_bea
592end
593
594fn is_tracking_param pos ulong lim ulong to bool
595if url_starts_ci pos lim qp_utm
596ret true
597end
598if url_starts_ci pos lim qp_fb
599ret true
600end
601if url_starts_ci pos lim qp_gc
602ret true
603end
604ret url_starts_ci pos lim qp_mc
605end
606
607note Strip tracking query params from urlbuf[0..ulen) into cleanurl[0..st_clen)
608fn strip_tracking_params ulen ulong to void
609qpos = ulen
610i = ulong 0
611while lt i ulen bound 512
612if eq get urlbuf i 63
613qpos = i
614break
615end
616i = add i 1
617end
618cl = ulong 0
619j = ulong 0
620while lt j qpos bound 512
621put cleanurl cl get urlbuf j
622cl = add cl 1
623j = add j 1
624end
625if eq qpos ulen
626put stats st_clen cl
627ret
628end
629first_q = true
630pos = add qpos 1
631while lt pos ulen bound 512
632ps = pos
633while lt pos ulen bound 512
634if eq get urlbuf pos 38
635break
636end
637pos = add pos 1
638end
639if is_tracking_param ps pos
640put stats st_strip add get stats st_strip 1
641else
642if gt pos ps
643if first_q
644put cleanurl cl 63
645cl = add cl 1
646first_q = false
647else
648put cleanurl cl 38
649cl = add cl 1
650end
651k = ps
652while lt k pos bound 512
653if lt cl 512
654put cleanurl cl get urlbuf k
655cl = add cl 1
656end
657k = add k 1
658end
659end
660end
661if lt pos ulen
662pos = add pos 1
663end
664end
665put stats st_clen cl
666end
667
668fn extract_links_on_line ls ulong le_pos ulong to void
669p = ls
670while lt p le_pos bound 32768
671if eq get inbuf p 91
672ts = add p 1
673te = ts
674while lt te le_pos bound 32768
675if eq get inbuf te 93
676break
677end
678te = add te 1
679end
680if and lt add te 2 le_pos eq get inbuf add te 1 40
681us = add te 2
682ue = us
683while lt ue le_pos bound 32768
684if eq get inbuf ue 41
685break
686end
687ue = add ue 1
688end
689if and lt ue le_pos gt ue us
690ul = sub ue us
691if gt ul 511
692ul = ulong 511
693end
694k = ulong 0
695while lt k ul bound 512
696put urlbuf k get inbuf add us k
697k = add k 1
698end
699if is_telemetry_url ul
700put stats st_telrej add get stats st_telrej 1
701else
702strip_tracking_params ul
703if dedup_insert_cleanurl
704put stats st_links add get stats st_links 1
705out_push_lit j_link1
706out_push_in_json ts sub te ts
707out_push_lit j_url
708out_push_cleanurl_json
709out_push_lit j_end
710end
711end
712p = ue
713end
714end
715end
716p = add p 1
717end
718end
719
720fn try_meta_key ls ulong le_pos ulong key view uchar * to bool
721kl = len key
722if not in_starts_ci ls le_pos key
723ret false
724end
725vs = add ls kl
726while lt vs le_pos bound 32768
727if ne get inbuf vs 32
728break
729end
730vs = add vs 1
731end
732ve = le_pos
733while gt ve vs bound 32768
734if ne get inbuf sub ve 1 32
735break
736end
737ve = sub ve 1
738end
739if eq ve vs
740ret false
741end
742put stats st_meta add get stats st_meta 1
743out_push_lit j_meta1
744out_push_in_json ls sub kl 1
745out_push_lit j_val
746out_push_in_json vs sub ve vs
747out_push_lit j_end
748ret true
749end
750
751fn check_meta_line ls ulong le_pos ulong to bool
752if try_meta_key ls le_pos mk_title
753ret true
754end
755if try_meta_key ls le_pos mk_author
756ret true
757end
758if try_meta_key ls le_pos mk_lic
759ret true
760end
761if try_meta_key ls le_pos mk_pin
762ret true
763end
764if try_meta_key ls le_pos mk_src
765ret true
766end
767if try_meta_key ls le_pos mk_date
768ret true
769end
770if try_meta_key ls le_pos mk_ver
771ret true
772end
773if try_meta_key ls le_pos mk_prov
774ret true
775end
776ret try_meta_key ls le_pos mk_mod
777end
778
779fn check_heading_line ls ulong le_pos ulong to bool
780ll = sub le_pos ls
781if lt ll 3
782ret false
783end
784if ne get inbuf ls 35
785ret false
786end
787lvl = ulong 0
788while and lt lvl 3 lt add ls lvl le_pos bound 4
789if ne get inbuf add ls lvl 35
790break
791end
792lvl = add lvl 1
793end
794if eq lvl 0
795ret false
796end
797if ge add ls lvl le_pos
798ret false
799end
800if ne get inbuf add ls lvl 32
801ret false
802end
803ts = add add ls lvl 1
804while lt ts le_pos bound 32768
805if ne get inbuf ts 32
806break
807end
808ts = add ts 1
809end
810ve = le_pos
811while gt ve ts bound 32768
812if ne get inbuf sub ve 1 32
813break
814end
815ve = sub ve 1
816end
817put stats st_heads add get stats st_heads 1
818out_push_lit j_head1
819out_push_dec lvl
820out_push_lit j_text
821out_push_in_json ts sub ve ts
822out_push_lit j_end
823ret true
824end
825
826note Extract <think>...</think> or <thought>...</thought> reasoning blocks (upstream extractor.rs)
827fn extract_reasoning_blocks to void
828tot = get stats st_inlen
829has_code = gt get stats st_blocks 0
830base_q = ulong 500
831if has_code
832base_q = add base_q 100
833end
834put stats st_qual base_q
835pos = ulong 0
836while lt pos tot bound 32768
837rs = ulong 0
838re = ulong 0
839found = false
840if in_starts_ci pos tot t_think_o
841rs = add pos 7
842q = rs
843while lt q tot bound 32768
844if in_starts_ci q tot t_think_c
845re = q
846found = true
847pos = add q 8
848break
849end
850q = add q 1
851end
852else
853if in_starts_ci pos tot t_thought_o
854rs = add pos 9
855q = rs
856while lt q tot bound 32768
857if in_starts_ci q tot t_thought_c
858re = q
859found = true
860pos = add q 10
861break
862end
863q = add q 1
864end
865end
866end
867if found
868rlen = sub re rs
869qm = ulong 500
870if gt rlen 0
871qm = add qm 200
872end
873if gt rlen 50
874qm = add qm 100
875end
876if or in_contains_ci rs re t_kw_step or in_contains_ci rs re t_kw_ver in_contains_ci rs re t_kw_bigo
877qm = add qm 100
878end
879if has_code
880qm = add qm 100
881end
882if gt qm 1000
883qm = ulong 1000
884end
885if gt qm get stats st_qual
886put stats st_qual qm
887end
888put stats st_reas add get stats st_reas 1
889out_push_lit j_reas1
890out_push_dec div tot 4
891out_push_lit j_qm
892out_push_dec qm
893out_push_lit j_text
894out_push_in_json rs rlen
895out_push_lit j_end
896else
897pos = add pos 1
898end
899end
900end
901
902fn harvest_loaded to void
903tot = get stats st_inlen
904for i ulong 13
905if ne i st_inlen
906put stats i 0
907end
908end
909in_fence = false
910pos = ulong 0
911while lt pos tot bound 32768
912ls = pos
913while lt pos tot bound 32768
914if eq get inbuf pos 10
915break
916end
917pos = add pos 1
918end
919if in_starts_ci ls pos t_fence
920if not in_fence
921in_fence = true
922put stats st_blocks add get stats st_blocks 1
923else
924in_fence = false
925end
926else
927if not in_fence
928if not check_heading_line ls pos
929is_m = check_meta_line ls pos
930if not is_m
931extract_links_on_line ls pos
932end
933end
934end
935end
936if lt pos tot
937pos = add pos 1
938end
939end
940extract_reasoning_blocks
941sha256_inbuf
942out_push_lit j_sum1
943out_push_dec get stats st_heads
944out_push_lit j_sum2
945out_push_dec get stats st_blocks
946out_push_lit j_sum3
947out_push_dec get stats st_links
948out_push_lit j_sum4
949out_push_dec get stats st_telrej
950out_push_lit j_sum5
951out_push_dec get stats st_strip
952out_push_lit j_sum6
953out_push_dec get stats st_meta
954out_push_lit j_sum7
955out_push_dec get stats st_reas
956out_push_lit j_sum8
957out_push_dec get stats st_qual
958out_push_lit j_sum9
959out_push_shahex
960out_push_lit j_end
961end
962
963fn read_stdin to bool
964tot = ulong 0
965while true bound 32768
966k = read 0 rdbuf 0 4096
967if lt k 0
968ret false
969end
970if eq k 0
971break
972end
973kn = ulong k
974i = ulong 0
975while lt i kn bound 4096
976c = get rdbuf i
977if ne c 13
978if ge tot 32768
979ret false
980end
981put inbuf tot c
982tot = add tot 1
983end
984i = add i 1
985end
986end
987put stats st_inlen tot
988ret true
989end
990
991fn flush_out to void
992n = get stats st_outlen
993p = ulong 0
994while lt p n bound 32768
995k = write 1 outbuf p sub n p
996if le k 0
997exit 2
998end
999p = add p ulong k
1000end
1001end
1002
1003fn main to int
1004if not read_stdin
1005wstr 2 e_io
1006ret 2
1007end
1008harvest_loaded
1009flush_out
1010ret 0
1011end