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 / protocol / synapse / pulse / src / 20main.om

272 lines · 4680 bytes Raw Blame History
1note synapse-pulse 20main.om: arguments, defaults, run order, findings file, alert, exit code.
2fn pu_usage to void
3syn_die tusage 64
4end
5
6note pu_pfx: b starts with t
7fn pu_pfx b view uchar * t view uchar * to bool
8for j ulong len t
9if ne get b j get t j
10ret false
11end
12end
13ret true
14end
15
16note pu_envopt: option i from environment entry with prefix t, plus suffix s; true when found
17fn pu_envopt i ulong t view uchar * s view uchar * to bool
18b = new uchar 8192 0
19for e ulong ulong envcnt
20n = envread e b 0 len b
21if gt n long len t
22if pu_pfx b t
23m = syn_mark
24syn_pa b len t sub ulong n len t
25syn_pt s
26put gop i m
27put gopl i syn_len m
28ret true
29end
30end
31end
32ret false
33end
34
35fn pu_setdef i ulong t view uchar * to void
36if eq get gopl i 0
37m = syn_mark
38syn_pt t
39put gop i m
40put gopl i syn_len m
41end
42end
43
44fn pu_args to void
45n = ulong argcnt
46i = ulong 1
47sawrun = false
48while lt i n bound 1000
49o = syn_arg i
50l = ulong get gxs 2
51if syn_seq o l trun
52sawrun = true
53i = add i 1
54continue
55end
56if syn_seq o l talert
57put gfl 0 1
58i = add i 1
59continue
60end
61k = ulong 99
62if syn_seq o l thome
63k = 0
64end
65if syn_seq o l tadir
66k = 1
67end
68if syn_seq o l tgh
69k = 2
70end
71if syn_seq o l tsess
72k = 3
73end
74if syn_seq o l tcbin
75k = 4
76end
77if syn_seq o l toff
78k = 5
79end
80if syn_seq o l tnow
81k = 6
82end
83if or eq k 99 ge add i 1 n
84pu_usage
85end
86v = syn_arg add i 1
87vl = ulong get gxs 2
88if eq vl 0
89pu_usage
90end
91put gop k v
92put gopl k vl
93i = add i 2
94end
95if not sawrun
96pu_usage
97end
98end
99
100note the AIEN_COORD_HOME branch above used tnl as an empty suffix; strip it
101fn pu_fixhome to void
102l = get gopl 0
103if and gt l 0 eq get gsp add get gop 0 sub l 1 10
104put gopl 0 sub l 1
105end
106end
107
108note pu_envraw: option i from environment entry with prefix t, value only; true when present and non-empty
109fn pu_envraw i ulong t view uchar * to bool
110if pu_envopt i t tnl
111put gopl i sub get gopl i 1
112ret true
113end
114ret false
115end
116
117note pu_hdef: when option i is unset, default it to HOME (slot 7) + t; with no HOME, refuse with msg (exit 64)
118fn pu_hdef i ulong t view uchar * msg view uchar * to void
119if eq get gopl i 0
120if not pu_opt 7
121syn_die msg 64
122end
123m = syn_mark
124pu_popt 7
125syn_pt t
126put gop i m
127put gopl i syn_len m
128end
129end
130
131note pu_envkv: option i = text k followed by option j (e.g. HOME= + the caller's HOME)
132fn pu_envkv i ulong k view uchar * j ulong to void
133m = syn_mark
134syn_pt k
135pu_popt j
136put gop i m
137put gopl i syn_len m
138end
139
140note option slots: 0 coord home, 1 alert dir, 2 gh, 3 sessions, 4 claims-bin, 5 offline, 6 now,
141note 7 caller HOME, 8 caller PATH, 9 gh child HOME=, 10 gh child PATH=. No path is built in: every
142note default is HOME-relative, HOME comes only from the caller's environment, and a needed but unset HOME
143note refuses with 64 instead of guessing.
144fn pu_setup to void
145if pu_envraw 7 tenvhm
146if ne get gsp get gop 7 47
147syn_die tbadenvh 64
148end
149end
150if pu_opt 5
151put gfl 1 1
152end
153if eq get gopl 0 0
154if not pu_envopt 0 tenvh tnl
155if pu_opt 7
156pu_hdef 0 tdhome tnohome
157end
158end
159end
160if eq get gopl 0 0
161syn_die tnohome 64
162end
163pu_fixhome
164if eq get gfl 0 1
165pu_hdef 1 tdadir tnohadir
166end
167pu_hdef 3 tdsess tnohsess
168if eq get gfl 1 0
169pu_hdef 2 tdgh tnohgh
170if not pu_opt 7
171syn_die tnohkid 64
172end
173pu_envkv 9 tenvhm 7
174if not pu_envraw 8 tenvpath
175pu_setdef 8 tdpath
176end
177pu_envkv 10 tenvpath 8
178end
179if eq get gopl 4 0
180syn_die tnocbin 64
181end
182if ne get gsp get gop 4 47
183syn_die tnocbin 64
184end
185if pu_opt 6
186t = syn_tsp get gop 6 get gopl 6
187if eq get gxs 2 0
188syn_die tbadnow 64
189end
190put gnow 0 t
191put gfl 2 1
192else
193put gnow 0 div ulong realns 1000000000
194end
195m = pu_pathi 0 tslpu
196r = syn_mkdir m syn_len m
197syn_rew m
198m = pu_pathi 0 tsletag
199r = syn_mkdir m syn_len m
200syn_rew m
201m = syn_mark
202syn_pt tstops
203pu_toks m syn_len m 0 0
204syn_rew m
205end
206
207text tsum1 " coordination finding(s) in "
208text tsum2 "; first: "
209fn pu_mkalert to ulong
210if eq get gcnt 0 0
211pu_alert 0 0 0
212ret 0
213end
214m = syn_mark
215syn_pd get gcnt 0
216syn_pt tsum1
217pu_popt 0
218syn_pt tslfind
219syn_pt tsum2
220syn_ps get gcnt 9 get gcnt 10
221pu_alert 1 m syn_len m
222ret 1
223end
224
225text tofull "synapse-pulse: findings over 4 MiB, truncated"
226text tfwerr "synapse-pulse: cannot write findings.jsonl"
227fn main to int
228pu_args
229pu_setup
230r = pu_ldclaims
231if lt r 0
232ret int neg r
233end
234r = pu_expire
235if lt r 0
236ret int neg r
237end
238r = pu_ldconf
239if lt r 0
240ret int neg r
241end
242pu_sessions
243pu_dup
244pu_repos
245pu_github
246if eq get gfl 7 1
247w = write 2 tofull 0 len tofull
248w = write 2 tnl 0 1
249end
250w = write 1 gout 0 get gon 0
251fp = pu_pathi 0 tslfind
252fd = syn_wbeg fp syn_len fp
253if lt fd 0
254syn_die tfwerr 70
255end
256w = write int fd gout 0 get gon 0
257r = syn_wend fd fp syn_len fp
258if lt r 0
259syn_die tfwerr 70
260end
261syn_rew fp
262if eq get gfl 0 1
263r2 = pu_mkalert
264end
265if gt get gcnt 0 0
266ret 1
267end
268if and gt get gcnt 3 0 eq get gcnt 4 0
269ret 75
270end
271ret 0
272end