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 / gpu / nvidia / checks / inventory.om

1098 lines · 20857 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note gpu/nvidia/checks/inventory.om: writes gpu/nvidia/checks/INVENTORY.tsv, the inventory of the files of CUDApp
4note tests/ and tools/ that are not Omega, in seeded Omega (Linux AArch64). Nobody types that table: this program
5note derives it from the files themselves, the list of Omega files under gpu/ and the decisions in ports.tsv.
6note Build from the omega-mv root: seed/out/omc < gpu/nvidia/checks/inventory.om > inventory
7note Run from the CUDApp checkout root: inventory LIST GPULIST PORTS LABEL > INVENTORY.tsv
8note LIST the paths of CUDApp tests/ and tools/, one per line (git ls-files tests tools); a path ending in .om
9note is skipped (those are Omega already)
10note GPULIST the paths of the files under gpu/ of the omega-mv head the inventory is read against, one per line
11note PORTS gpu/nvidia/checks/ports.tsv: PATH, a tab, ported|retired|blocked, a tab, the detail; # starts a comment.
12note Each row must name a path of LIST exactly once, or the run fails (exit 1): a stale decision is loud.
13note LABEL one line naming the inputs (heads), copied into the header
14note Columns: path kind bytes lines tier marker om_ref same_stem status detail summary
15note kind the extension, or none
16note tier data (not code), device (a device marker in the text), tiered (a device marker and a --host-only or
17note --sim tier), host (code with no device marker). A heuristic over the text, not a run.
18note marker the first device marker found, in the order of the m_ texts below, or -
19note om_ref the first NAME.om named in the text that is a file of GPULIST: gpu/nvidia/NAME.om (om/ and native/
20note read as gpu/nvidia/), or, when NAME holds a '/', a GPULIST file ending in /NAME.om; or -
21note same_stem the file gpu/nvidia/PATH.om of GPULIST, where PATH is the path without its extension (tests/X/y.c
22note gives gpu/nvidia/tests/X/y.om): an Omega program of the same name, or -
23note status ported, retired or blocked from PORTS, else open
24note summary the first comment line of the file that is not a licence line (md: the first heading), or -
25note Files and lists are read whole into memory that grows to fit them (run-time pools); nothing is cut. A
26note path of LIST that Linux could not open (PATH_MAX) is refused, naming it. Exit 0 written, 1 a PORTS row names
27note no path of LIST, 2 bad usage, unreadable input, or memory the host refused.
28text t_usage "usage: inventory LIST GPULIST PORTS LABEL (run from the CUDApp checkout root)\n"
29text t_unread "inventory: cannot read, or the host refused the memory for: "
30text t_plong "inventory: a LIST path is longer than Linux PATH_MAX allows: "
31text t_badport "inventory: ports.tsv row is not PATH<tab>ported|retired|blocked<tab>DETAIL: "
32text t_stale "inventory: ports.tsv rows that name no path of LIST, or name one twice: "
33text t_h1 "# gpu/nvidia/checks/INVENTORY.tsv, generated by gpu/nvidia/checks/inventory.om; do not edit by hand.\n# inputs: "
34text t_h2 "path\tkind\tbytes\tlines\ttier\tmarker\tom_ref\tsame_stem\tstatus\tdetail\tsummary\n"
35text t_tot "# files="
36text t_code " code="
37text t_data " data="
38text t_dev " device="
39text t_tier " tiered="
40text t_host " host="
41text t_por " ported="
42text t_ret " retired="
43text t_blk " blocked="
44text t_open " open="
45text t_okh "# open by tier/kind:"
46text t_dash "-"
47text t_none "none"
48text t_ktdata "data"
49text t_nl "\n"
50text t_ktdev "device"
51text t_kttier "tiered"
52text t_kthost "host"
53text t_kopen "open\t-"
54text t_ported "ported"
55text t_retired "retired"
56text t_blocked "blocked"
57text t_gn "gpu/nvidia/"
58text t_copyr "Copyright"
59text t_dotom ".om"
60text t_spdx "SPDX"
61text t_hostonly "--host-only"
62text t_sim "--sim"
63text t_m1 "/dev/nvidia"
64text t_m2 "/dev/kfd"
65text t_m3 "/dev/dri"
66text t_m4 "omega_gpu_session_open"
67text t_m5 "nvrm_open"
68text t_m6 "cuInit"
69text t_m7 "hipMalloc"
70text t_m8 "ioctl("
71text t_m9 "nvidia-smi"
72text t_m10 "spark-window"
73text t_kc "c"
74text t_kh "h"
75text t_kpy "py"
76text t_ksh "sh"
77text t_kmk "mk"
78text t_kinc "inc"
79text t_kmd "md"
80global g_f uchar *
81global g_lst uchar *
82global g_gpu uchar *
83global g_prt uchar *
84note a path for fopen: Linux PATH_MAX, the longest path open(2) takes (getconf PATH_MAX / gives 4096)
85global g_pa uchar 4096
86note the LABEL argument: Linux MAX_ARG_STRLEN, the longest single argument execve passes (32 pages of 4096)
87global g_lab uchar 131072
88global g_o uchar 65536
89global g_ok uchar *
90global g_n ulong 48
91note g_n: 0 path length, 1 file length, 2 list length, 3 gpu list length, 4 ports length, 5 output length,
92note 6 label length, 7 entry start, 8 entry end, 9 ports rows matched, 10 files, 11 code, 12 data, 13 device,
93note 14 tiered, 15 host, 16 ported, 17 retired, 18 blocked, 19 open, 20 summary start, 21 summary end,
94note 22 om_ref start, 23 om_ref end (in g_gpu), 24 stem start, 25 stem end (in g_lst), 26 extension start,
95note 27 same_stem start, 28 same_stem end, 29 port line start, 30 port line end, 31 ports rows, 32 bytes of g_ok,
96note 33 the tier of this row (1 device, 2 tiered, 3 host, 4 data)
97note g_ok: one key per open row, its tier byte, its kind, a newline (the open-by-kind footer line)
98note ---- output
99fn oflush to void
100o = ulong 0
101n = get g_n 5
102while lt o n bound 65537
103x = write 1 g_o o sub n o
104if le x 0
105exit 2
106end
107o = add o ulong x
108end
109put g_n 5 0
110end
111fn oc c ulong to void
112n = get g_n 5
113if ge n len g_o
114oflush
115n = 0
116end
117put g_o n uchar c
118put g_n 5 add n 1
119end
120fn ot t view uchar * to void
121for i ulong len t bound 4096
122oc ulong get t i
123end
124end
125fn onum v ulong to void
126if ge v 10
127onum div v 10
128end
129oc add 48 rem v 10
130end
131fn otab to void
132oc 9
133end
134fn ofr s ulong e ulong to void
135for i ulong sub e s bound 9223372036854775807
136c = ulong get g_f add s i
137if or eq c 9 eq c 13
138c = 32
139end
140oc c
141end
142end
143fn olr s ulong e ulong to void
144for i ulong sub e s bound 9223372036854775807
145oc ulong get g_lst add s i
146end
147end
148fn ogr s ulong e ulong to void
149for i ulong sub e s bound 9223372036854775807
150oc ulong get g_gpu add s i
151end
152end
153fn opr s ulong e ulong to void
154for i ulong sub e s bound 9223372036854775807
155oc ulong get g_prt add s i
156end
157end
158fn eput t view uchar * to void
159r = write 2 t 0 len t
160end
161fn epath to void
162r = write 2 g_pa 0 get g_n 0
163r = write 2 t_nl 0 1
164end
165note ---- files
166fn pclr to void
167put g_n 0 0
168end
169fn pc c ulong to void
170n = get g_n 0
171put g_pa n uchar c
172put g_n 0 add n 1
173end
174note read the file named by g_pa into g_f, growing g_f to fit: its length, or -1 unreadable, -2 the host refused
175note the memory
176fn fload to long
177r = fopen g_pa 0 get g_n 0 int 524288 int 0
178if lt r 0
179ret long -1
180end
181fd = int r
182n = ulong 0
183res = long 0
184while true bound 9223372036854775807
185if ge add n 1 len g_f
186q = enlarge g_f add add n n 65536
187if lt q 0
188res = long -2
189break
190end
191end
192x = read fd g_f n sub len g_f n
193if lt x 0
194res = long -1
195break
196end
197if eq x 0
198break
199end
200n = add n ulong x
201end
202r = fclose fd
203if lt res 0
204ret res
205end
206put g_n 1 n
207ret long n
208end
209note argument I into g_pa, then the file into g_f; exits 2 when either fails
210fn aload i ulong to ulong
211r = argread i g_pa 0 4095
212if lt r 1
213eput t_usage
214exit 2
215end
216put g_n 0 ulong r
217x = fload
218if lt x 0
219eput t_unread
220epath
221exit 2
222end
223ret ulong x
224end
225note ---- character classes
226fn alnum c ulong to bool
227if and ge c 48 le c 57
228ret true
229end
230if and ge c 65 le c 90
231ret true
232end
233if and ge c 97 le c 122
234ret true
235end
236ret false
237end
238fn tokch c ulong to bool
239if alnum c
240ret true
241end
242if or or or eq c 95 eq c 46 eq c 47 eq c 45
243ret true
244end
245ret false
246end
247note ---- search in g_f
248fn fat i ulong t view uchar * to bool
249n = get g_n 1
250m = len t
251if gt add i m n
252ret false
253end
254for j ulong m bound 9223372036854775807
255if ne get g_f add i j get t j
256ret false
257end
258end
259ret true
260end
261fn fhas t view uchar * to bool
262n = get g_n 1
263m = len t
264if gt m n
265ret false
266end
267for i ulong add sub n m 1 bound 9223372036854775807
268if fat i t
269ret true
270end
271end
272ret false
273end
274note the first device marker in g_f, 1..10, or 0
275fn marker to ulong
276if fhas t_m1
277ret 1
278end
279if fhas t_m2
280ret 2
281end
282if fhas t_m3
283ret 3
284end
285if fhas t_m4
286ret 4
287end
288if fhas t_m5
289ret 5
290end
291if fhas t_m6
292ret 6
293end
294if fhas t_m7
295ret 7
296end
297if fhas t_m8
298ret 8
299end
300if fhas t_m9
301ret 9
302end
303if fhas t_m10
304ret 10
305end
306ret 0
307end
308fn omark m ulong to void
309if eq m 1
310ot t_m1
311end
312if eq m 2
313ot t_m2
314end
315if eq m 3
316ot t_m3
317end
318if eq m 4
319ot t_m4
320end
321if eq m 5
322ot t_m5
323end
324if eq m 6
325ot t_m6
326end
327if eq m 7
328ot t_m7
329end
330if eq m 8
331ot t_m8
332end
333if eq m 9
334ot t_m9
335end
336if eq m 10
337ot t_m10
338end
339if eq m 0
340ot t_dash
341end
342end
343note ---- the list entry g_lst[g_n 7, g_n 8): extension and stem
344note sets 24 stem start, 25 stem end, 26 extension start (= entry end when there is none)
345fn names to void
346s = get g_n 7
347e = get g_n 8
348b = s
349d = e
350for i ulong sub e s bound 9223372036854775807
351c = get g_lst add s i
352if eq c 47
353b = add add s i 1
354d = e
355end
356if eq c 46
357d = add s i
358end
359end
360put g_n 24 b
361put g_n 25 d
362if lt d e
363put g_n 26 add d 1
364else
365put g_n 26 e
366end
367end
368fn lext t view uchar * to bool
369s = get g_n 26
370e = get g_n 8
371if ne sub e s len t
372ret false
373end
374for i ulong len t bound 9223372036854775807
375if ne get g_lst add s i get t i
376ret false
377end
378end
379ret true
380end
381fn iscode to bool
382if or or lext t_kc lext t_kh lext t_kpy
383ret true
384end
385if or or lext t_ksh lext t_kmk lext t_kinc
386ret true
387end
388if ge get g_n 1 2
389if and eq get g_f 0 35 eq get g_f 1 33
390ret true
391end
392end
393ret false
394end
395fn isdotom to bool
396s = get g_n 7
397e = get g_n 8
398if lt sub e s 3
399ret false
400end
401c3 = get g_lst sub e 3
402c2 = get g_lst sub e 2
403c1 = get g_lst sub e 1
404ret and and eq c3 46 eq c2 111 eq c1 109
405end
406note ---- the gpu list
407note gpu line [lo, hi) equals PREFIX then g_f[ts, te)
408fn gpeq lo ulong hi ulong pre view uchar * ts ulong te ulong to bool
409m = len pre
410tl = sub te ts
411if ne sub hi lo add m tl
412ret false
413end
414for i ulong m bound 9223372036854775807
415if ne get g_gpu add lo i get pre i
416ret false
417end
418end
419for j ulong tl bound 9223372036854775807
420c = get g_f add ts j
421if ne get g_gpu add add lo m j c
422ret false
423end
424end
425ret true
426end
427note gpu line [lo, hi) ends with '/' then g_f[ts, te)
428fn gpsuf lo ulong hi ulong ts ulong te ulong to bool
429tl = sub te ts
430if le sub hi lo tl
431ret false
432end
433if ne get g_gpu sub sub hi tl 1 47
434ret false
435end
436b = sub hi tl
437for j ulong tl bound 9223372036854775807
438c = get g_f add ts j
439if ne get g_gpu add b j c
440ret false
441end
442end
443ret true
444end
445note find a gpu line for the token g_f[ts, te): mode 0 exact under gpu/nvidia/, mode 1 by suffix; sets 22, 23
446fn gfind ts ulong te ulong mode ulong to bool
447n = get g_n 3
448s = ulong 0
449note every pass consumes at least one byte of the gpu list
450while lt s n bound 9223372036854775807
451e = s
452while and lt e n ne get g_gpu e 10 bound 9223372036854775807
453e = add e 1
454end
455hit = false
456if eq mode 0
457hit = gpeq s e t_gn ts te
458else
459hit = gpsuf s e ts te
460end
461if hit
462put g_n 22 s
463put g_n 23 e
464ret true
465end
466s = add e 1
467end
468ret false
469end
470note the token that ends with ".om" at g_f[i, i+3): its start, or i when there is none
471fn tokstart i ulong to ulong
472b = i
473while gt b 0 bound 9223372036854775807
474if not tokch ulong get g_f sub b 1
475break
476end
477b = sub b 1
478end
479ret b
480end
481fn slashin s ulong e ulong to bool
482for i ulong sub e s bound 9223372036854775807
483if eq get g_f add s i 47
484ret true
485end
486end
487ret false
488end
489fn omref to bool
490n = get g_n 1
491if lt n 3
492ret false
493end
494for i ulong sub n 2 bound 9223372036854775807
495if fat i t_dotom
496ok = true
497if lt add i 3 n
498if or alnum ulong get g_f add i 3 eq get g_f add i 3 95
499ok = false
500end
501end
502if ok
503b = tokstart i
504if lt b i
505if gfind b add i 3 0
506ret true
507end
508if and slashin b i gfind b add i 3 1
509ret true
510end
511end
512end
513end
514end
515ret false
516end
517fn gdotom hi ulong to bool
518if ne get g_gpu sub hi 3 46
519ret false
520end
521if ne get g_gpu sub hi 2 111
522ret false
523end
524ret eq get g_gpu sub hi 1 109
525end
526note gpu line [lo, hi) is gpu/nvidia/ then the list entry up to its extension, then ".om"
527fn stemeq lo ulong hi ulong to bool
528m = len t_gn
529ss = get g_n 7
530sl = sub get g_n 25 ss
531if ne sub hi lo add add m sl 3
532ret false
533end
534for i ulong m bound 9223372036854775807
535if ne get g_gpu add lo i get t_gn i
536ret false
537end
538end
539for j ulong sl bound 9223372036854775807
540c = get g_lst add ss j
541if ne get g_gpu add add lo m j c
542ret false
543end
544end
545ret gdotom hi
546end
547fn samestem to bool
548n = get g_n 3
549s = ulong 0
550while lt s n bound 9223372036854775807
551e = s
552while and lt e n ne get g_gpu e 10 bound 9223372036854775807
553e = add e 1
554end
555if stemeq s e
556put g_n 27 s
557put g_n 28 e
558ret true
559end
560s = add e 1
561end
562ret false
563end
564note ---- summary: the first comment line of g_f that is not a licence line; sets 20, 21
565note style 0 C (/* * //), 1 hash (#, not #!), 2 Markdown (first # heading)
566fn hasalnum s ulong e ulong to bool
567for i ulong sub e s bound 9223372036854775807
568if alnum ulong get g_f add s i
569ret true
570end
571end
572ret false
573end
574note g_f[p] is c
575fn fis p ulong c ulong to bool
576ret eq ulong get g_f p c
577end
578fn skipsp s ulong e ulong to ulong
579p = s
580while and lt p e or fis p 32 fis p 9 bound 9223372036854775807
581p = add p 1
582end
583ret p
584end
585note trailing spaces, "*/" and quotes off the end
586fn trimend s ulong e ulong to ulong
587q = e
588while gt q s bound 9223372036854775807
589c = get g_f sub q 1
590if or or or eq c 32 eq c 9 eq c 13 eq c 34
591q = sub q 1
592continue
593end
594note two ifs, not one and: Omega's and reads both sides, and q - 2 is below 0 when q is 1
595if and eq c 47 gt sub q s 1
596if eq get g_f sub q 2 42
597q = sub q 2
598continue
599end
600end
601break
602end
603ret q
604end
605note the text of a line [s, e) after its comment marker, as a start; e when it is not a comment line
606fn cstart s ulong e ulong style ulong to ulong
607p = skipsp s e
608if ge p e
609ret e
610end
611c = get g_f p
612if eq style 0
613d = ulong 0
614if lt add p 1 e
615d = ulong get g_f add p 1
616end
617if and eq c 47 or eq d 42 eq d 47
618p = add p 2
619while and lt p e or fis p 42 fis p 47 bound 9223372036854775807
620p = add p 1
621end
622ret skipsp p e
623end
624if eq c 42
625p = add p 1
626if and lt p e eq get g_f p 47
627ret e
628end
629ret skipsp p e
630end
631ret e
632end
633if eq c 34
634if and lt add p 2 e and fis add p 1 34 fis add p 2 34
635ret skipsp add p 3 e
636end
637ret e
638end
639if ne c 35
640ret e
641end
642if and lt add p 1 e eq get g_f add p 1 33
643ret e
644end
645while and lt p e eq get g_f p 35 bound 9223372036854775807
646p = add p 1
647end
648ret skipsp p e
649end
650fn hastext s ulong e ulong t view uchar * to bool
651m = len t
652if lt sub e s m
653ret false
654end
655for i ulong add sub sub e s m 1 bound 9223372036854775807
656if fat add s i t
657ret true
658end
659end
660ret false
661end
662fn spdx s ulong e ulong to bool
663ret or hastext s e t_spdx hastext s e t_copyr
664end
665fn summary style ulong to bool
666n = get g_n 1
667s = ulong 0
668lines = ulong 0
669while and lt s n lt lines 80 bound 9223372036854775807
670e = s
671while and lt e n ne get g_f e 10 bound 9223372036854775807
672e = add e 1
673end
674p = cstart s e style
675q = trimend p e
676if and lt p q and hasalnum p q not spdx p q
677put g_n 20 p
678put g_n 21 q
679ret true
680end
681s = add e 1
682lines = add lines 1
683end
684ret false
685end
686fn summ to bool
687if or lext t_kc lext t_kh
688ret summary 0
689end
690if or iscode lext t_kmd
691ret summary 1
692end
693ret false
694end
695note ---- ports.tsv
696note the decision field of port line [s, e): 1 ported, 2 retired, 3 blocked, 0 malformed; the path ends at the tab
697fn pdec s ulong e ulong to ulong
698t = s
699while and lt t e ne get g_prt t 9 bound 9223372036854775807
700t = add t 1
701end
702if or eq t s ge t e
703ret 0
704end
705d = add t 1
706u = d
707while and lt u e ne get g_prt u 9 bound 9223372036854775807
708u = add u 1
709end
710if ge u e
711ret 0
712end
713r = ulong 0
714if pword d u t_ported
715r = 1
716end
717if pword d u t_retired
718r = 2
719end
720if pword d u t_blocked
721r = 3
722end
723ret r
724end
725fn pword s ulong e ulong t view uchar * to bool
726if ne sub e s len t
727ret false
728end
729for i ulong len t bound 9223372036854775807
730if ne get g_prt add s i get t i
731ret false
732end
733end
734ret true
735end
736note every ports row is well formed; counts rows into 31; exits 2 on a malformed one
737fn pcheck to void
738n = get g_n 4
739s = ulong 0
740k = ulong 0
741while lt s n bound 9223372036854775807
742e = s
743while and lt e n ne get g_prt e 10 bound 9223372036854775807
744e = add e 1
745end
746if and lt s e ne get g_prt s 35
747if eq pdec s e 0
748eput t_badport
749r = write 2 g_prt s sub e s
750r = write 2 t_nl 0 1
751exit 2
752end
753k = add k 1
754end
755s = add e 1
756end
757put g_n 31 k
758end
759note the port row of the list entry: sets 29, 30 to its line and returns the decision, 0 when there is none
760fn pfind to ulong
761n = get g_n 4
762ls = get g_n 7
763ll = sub get g_n 8 ls
764s = ulong 0
765while lt s n bound 9223372036854775807
766e = s
767while and lt e n ne get g_prt e 10 bound 9223372036854775807
768e = add e 1
769end
770note two ifs, not one and: Omega's and reads both sides, and s + ll may lie past the end of g_prt
771if gt sub e s ll
772if eq get g_prt add s ll 9
773if peq s ls ll
774put g_n 29 s
775put g_n 30 e
776ret pdec s e
777end
778end
779end
780s = add e 1
781end
782ret 0
783end
784fn peq s ulong ls ulong ll ulong to bool
785for i ulong ll bound 9223372036854775807
786c = get g_lst add ls i
787if ne get g_prt add s i c
788ret false
789end
790end
791ret true
792end
793fn bump k ulong to void
794put g_n k add get g_n k 1
795end
796note ---- one row
797fn row to void
798s = get g_n 7
799e = get g_n 8
800names
801pclr
802if ge sub e s len g_pa
803eput t_plong
804r = write 2 g_lst s sub e s
805r = write 2 t_nl 0 1
806exit 2
807end
808for i ulong sub e s bound 4096
809pc ulong get g_lst add s i
810end
811x = fload
812if lt x 0
813eput t_unread
814epath
815exit 2
816end
817bump 10
818olr s e
819otab
820if lt get g_n 26 e
821olr get g_n 26 e
822else
823ot t_none
824end
825otab
826onum get g_n 1
827otab
828nl = ulong 0
829for i ulong get g_n 1 bound 9223372036854775807
830if eq get g_f i 10
831nl = add nl 1
832end
833end
834onum nl
835otab
836m = ulong 0
837if iscode
838bump 11
839m = marker
840if eq m 0
841bump 15
842ot t_kthost
843put g_n 33 3
844else
845if or fhas t_hostonly fhas t_sim
846bump 14
847ot t_kttier
848put g_n 33 2
849else
850bump 13
851ot t_ktdev
852put g_n 33 1
853end
854end
855else
856bump 12
857ot t_ktdata
858put g_n 33 4
859end
860otab
861omark m
862otab
863row2
864end
865fn row2 to void
866if omref
867ogr get g_n 22 get g_n 23
868else
869ot t_dash
870end
871otab
872if samestem
873ogr get g_n 27 get g_n 28
874else
875ot t_dash
876end
877otab
878d = pfind
879if eq d 0
880bump 19
881ot t_kopen
882okadd
883else
884bump 9
885bump add 15 d
886t = get g_n 29
887while ne get g_prt t 9 bound 9223372036854775807
888t = add t 1
889end
890opr add t 1 get g_n 30
891end
892otab
893if summ
894ofr get g_n 20 get g_n 21
895else
896ot t_dash
897end
898oc 10
899end
900note copy g_f into the list pool k (2 LIST, 3 GPULIST, 4 PORTS), growing it to fit with one zero byte past the
901note copy, so that reading the byte at the end of the text (in the eager and of the line loops) stays in range,
902note an empty file too; exits 2 when the host refuses the memory
903fn copyf k ulong to void
904n = get g_n 1
905q = long 0
906if eq k 2
907q = enlarge g_lst add n 1
908end
909if eq k 3
910q = enlarge g_gpu add n 1
911end
912if eq k 4
913q = enlarge g_prt add n 1
914end
915if lt q 0
916eput t_unread
917epath
918exit 2
919end
920for i ulong n bound 9223372036854775807
921if eq k 2
922put g_lst i get g_f i
923end
924if eq k 3
925put g_gpu i get g_f i
926end
927if eq k 4
928put g_prt i get g_f i
929end
930end
931put g_n k n
932end
933note ---- the open-by-kind line: keys of open rows in g_ok, counted in the order each key first appears
934fn okc c ulong to void
935n = get g_n 32
936if ge n len g_ok
937q = enlarge g_ok add mul n 2 64
938if lt q 0
939eput t_unread
940r = write 2 t_nl 0 1
941exit 2
942end
943end
944put g_ok n uchar c
945put g_n 32 add n 1
946end
947fn okadd to void
948okc get g_n 33
949s = get g_n 26
950e = get g_n 8
951if lt s e
952for i ulong sub e s bound 9223372036854775807
953okc ulong get g_lst add s i
954end
955else
956for i ulong len t_none bound 16
957okc ulong get t_none i
958end
959end
960okc 10
961end
962fn oknext a ulong to ulong
963p = a
964while ne get g_ok p 10 bound 9223372036854775807
965p = add p 1
966end
967ret add p 1
968end
969fn okeq a ulong b ulong to bool
970i = ulong 0
971while eq get g_ok add a i get g_ok add b i bound 9223372036854775807
972if eq get g_ok add a i 10
973ret true
974end
975i = add i 1
976end
977ret false
978end
979fn okname a ulong to void
980t = ulong get g_ok a
981if eq t 1
982ot t_ktdev
983end
984if eq t 2
985ot t_kttier
986end
987if eq t 3
988ot t_kthost
989end
990if eq t 4
991ot t_ktdata
992end
993oc 47
994p = add a 1
995while ne get g_ok p 10 bound 9223372036854775807
996oc ulong get g_ok p
997p = add p 1
998end
999end
1000fn okline to void
1001n = get g_n 32
1002ot t_okh
1003a = ulong 0
1004while lt a n bound 9223372036854775807
1005seen = ulong 0
1006b = ulong 0
1007while lt b a bound 9223372036854775807
1008if okeq a b
1009seen = 1
1010end
1011b = oknext b
1012end
1013if eq seen 0
1014c = ulong 0
1015b = a
1016while lt b n bound 9223372036854775807
1017if okeq a b
1018c = add c 1
1019end
1020b = oknext b
1021end
1022oc 32
1023okname a
1024oc 61
1025onum c
1026end
1027a = oknext a
1028end
1029oc 10
1030end
1031fn tot k ulong t view uchar * to void
1032ot t
1033onum get g_n k
1034end
1035fn main to int
1036if ne argcnt 5
1037eput t_usage
1038ret 2
1039end
1040x = aload 1
1041copyf 2
1042x = aload 2
1043copyf 3
1044x = aload 3
1045copyf 4
1046r = argread 4 g_lab 0 len g_lab
1047if lt r 0
1048eput t_usage
1049ret 2
1050end
1051put g_n 6 ulong r
1052pcheck
1053ot t_h1
1054for i ulong get g_n 6 bound 131072
1055c = ulong get g_lab i
1056if or eq c 10 eq c 9
1057c = 32
1058end
1059oc c
1060end
1061oc 10
1062ot t_h2
1063n = get g_n 2
1064s = ulong 0
1065while lt s n bound 9223372036854775807
1066e = s
1067while and lt e n ne get g_lst e 10 bound 9223372036854775807
1068e = add e 1
1069end
1070if lt s e
1071put g_n 7 s
1072put g_n 8 e
1073if not isdotom
1074row
1075end
1076end
1077s = add e 1
1078end
1079okline
1080tot 10 t_tot
1081tot 11 t_code
1082tot 12 t_data
1083tot 13 t_dev
1084tot 14 t_tier
1085tot 15 t_host
1086tot 16 t_por
1087tot 17 t_ret
1088tot 18 t_blk
1089tot 19 t_open
1090oc 10
1091oflush
1092if ne get g_n 9 get g_n 31
1093eput t_stale
1094r = write 2 t_nl 0 1
1095ret 1
1096end
1097ret 0
1098end