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 / aienux / pi-register / main.om

247 lines · 4863 bytes Raw Blame History
1note aienux/pi-register/main.om: CLI entrypoint for pi-register
2note Compose with: si/directives/om2.om aienux/pi-register/lib.om aienux/pi-register/main.om
3
4text pm_flag_reg "--register"
5text pm_cmd_status "status"
6text pm_cmd_jsonl "jsonl"
7text pm_cmd_show "show"
8text pm_cmd_filter "filter"
9text pm_cmd_check "check"
10
11text pm_f_owner "owner"
12text pm_f_proto "protocol"
13text pm_f_status "status"
14text pm_f_cat "category"
15text pm_f_port "port"
16text pm_f_boot "boot"
17
18text pm_err_open "pi-register: could not open register file\n"
19text pm_err_parse "pi-register: registry validation failed (code="
20text pm_err_line ", line="
21text pm_err_close ")\n"
22text pm_err_notfound "pi-register: service not found in register\n"
23text pm_err_filter "pi-register: unknown filter field\n"
24text pm_ok_check "All good: registry parsed and validated ("
25text pm_ok_svcs " services).\n"
26text pm_usage "Usage: pi-register [--register <path>] <status|jsonl|show <name>|filter <field> <value>|check>\n"
27
28fn pi_read_fd fd int dst edit uchar * to ulong
29cap = len dst
30pos = ulong 0
31note bound 65536 caps register input size
32while lt pos cap bound 65536
33remn = sub cap pos
34k = read fd dst pos remn
35if le k long 0
36break
37end
38pos = add pos ulong k
39end
40ret pos
41end
42
43fn pi_parse_fkind s view uchar * to ulong
44if pi_eq s pm_f_owner
45ret FILT_OWNER
46end
47if pi_eq s pm_f_proto
48ret FILT_PROTO
49end
50if pi_eq s pm_f_status
51ret FILT_STATUS
52end
53if pi_eq s pm_f_cat
54ret FILT_CAT
55end
56if pi_eq s pm_f_port
57ret FILT_PORT
58end
59if pi_eq s pm_f_boot
60ret FILT_BOOT
61end
62ret ulong 99
63end
64
65fn pi_emit_parse_err info view PiParseInfo to void
66ebuf = new uchar 128 0
67p = ulong 0
68p = pi_put_s ebuf p pm_err_parse
69p = pi_put_u64 ebuf p get info code
70p = pi_put_s ebuf p pm_err_line
71p = pi_put_u64 ebuf p get info line
72p = pi_put_s ebuf p pm_err_close
73w = pi_write_all int 2 part ebuf 0 p
74if w
75ret
76end
77end
78
79fn pi_run_cmd cidx ulong ac ulong to int
80outbuf = new uchar 16384 0
81arg0 = new uchar 256 0
82arg1 = new uchar 256 0
83arg2 = new uchar 256 0
84nc = argread cidx arg0 ulong 0 ulong 256
85if le nc long 0
86ret 2
87end
88l0 = ulong nc
89if pi_eq part arg0 0 l0 pm_cmd_status
90n = pi_render_table FILT_ALL part arg1 0 0 outbuf
91if pi_write_all int 1 part outbuf 0 n
92ret 0
93end
94ret 1
95end
96if pi_eq part arg0 0 l0 pm_cmd_jsonl
97n = pi_render_jsonl FILT_ALL part arg1 0 0 outbuf
98if pi_write_all int 1 part outbuf 0 n
99ret 0
100end
101ret 1
102end
103if pi_eq part arg0 0 l0 pm_cmd_check
104p = pi_put_s outbuf ulong 0 pm_ok_check
105p = pi_put_u64 outbuf p pi_svc_count
106p = pi_put_s outbuf p pm_ok_svcs
107if pi_write_all int 1 part outbuf 0 p
108ret 0
109end
110ret 1
111end
112if pi_eq part arg0 0 l0 pm_cmd_show
113if le ac add cidx ulong 1
114w0 = pi_write_all int 2 pm_usage
115if w0
116ret 2
117end
118ret 2
119end
120r1 = argread add cidx ulong 1 arg1 ulong 0 ulong 256
121if le r1 long 0
122ret 2
123end
124idx = pi_find_by_name part arg1 0 ulong r1
125if lt idx long 0
126w = pi_write_all int 2 pm_err_notfound
127if w
128ret 1
129end
130ret 1
131end
132n = pi_render_show ulong idx outbuf
133if pi_write_all int 1 part outbuf 0 n
134ret 0
135end
136ret 1
137end
138if pi_eq part arg0 0 l0 pm_cmd_filter
139if le ac add cidx ulong 2
140w1 = pi_write_all int 2 pm_usage
141if w1
142ret 2
143end
144ret 2
145end
146r1 = argread add cidx ulong 1 arg1 ulong 0 ulong 256
147r2 = argread add cidx ulong 2 arg2 ulong 0 ulong 256
148if or le r1 long 0 le r2 long 0
149ret 2
150end
151fk = pi_parse_fkind part arg1 0 ulong r1
152if eq fk ulong 99
153w2 = pi_write_all int 2 pm_err_filter
154if w2
155ret 2
156end
157ret 2
158end
159n = pi_render_jsonl fk part arg2 0 ulong r2 outbuf
160if pi_write_all int 1 part outbuf 0 n
161ret 0
162end
163ret 1
164end
165w3 = pi_write_all int 2 pm_usage
166if w3
167ret 2
168end
169ret 2
170end
171
172fn pi_load_source use_file bool path view uchar * inp edit uchar * to long
173if not use_file
174ret long pi_read_fd int 0 inp
175end
176fdl = fopen path ulong 0 len path int 0 int 0
177if lt fdl long 0
178w = pi_write_all int 2 pm_err_open
179if w
180ret long -1
181end
182ret long -1
183end
184nlen = pi_read_fd int fdl inp
185cl = fclose int fdl
186if lt cl long 0
187ret long -1
188end
189ret long nlen
190end
191
192fn pi_load_and_parse cidx_out edit ulong 1 to int
193inp = new uchar 32768 0
194arg0 = new uchar 256 0
195arg1 = new uchar 256 0
196info = new PiParseInfo 0 0 0
197ac = argcnt
198n0 = argread ulong 1 arg0 ulong 0 ulong 256
199if le n0 long 0
200ret 2
201end
202nlen_s = long 0
203if pi_eq part arg0 0 ulong n0 pm_flag_reg
204if le ac long 3
205w2 = pi_write_all int 2 pm_usage
206if w2
207ret 2
208end
209ret 2
210end
211np = argread ulong 2 arg1 ulong 0 ulong 256
212if le np long 0
213ret 2
214end
215nlen_s = pi_load_source true part arg1 0 ulong np inp
216put cidx_out 0 ulong 3
217else
218nlen_s = pi_load_source false part arg1 0 0 inp
219put cidx_out 0 ulong 1
220end
221if lt nlen_s long 0
222ret 1
223end
224rc = pi_parse_register part inp 0 ulong nlen_s info
225if ne rc PI_OK
226pi_emit_parse_err info
227ret 1
228end
229ret 0
230end
231
232fn main to int
233cidx_box = new ulong 1 0
234ac = argcnt
235if le ac long 1
236w = pi_write_all int 1 pm_usage
237if w
238ret 0
239end
240ret 1
241end
242lrc = pi_load_and_parse cidx_box
243if ne lrc int 0
244ret lrc
245end
246ret pi_run_cmd get cidx_box 0 ulong ac
247end