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 / apps / omega-projects / main.om

165 lines · 2943 bytes Raw Blame History
1note omega-projects CLI: validates slugs/paths or renders HTML index from TSV stdin.
2note Compose: si/directives/om2.om + apps/omega-projects/lib.om + apps/omega-projects/main.om
3
4text op_cli_flag_slug "--check-slug"
5text op_cli_flag_path "--check-path"
6text op_cli_ok "OK\n"
7text op_cli_refused "REFUSED\n"
8text op_cli_err_read "omega-projects: stdin read error\n"
9text op_cli_err_row "omega-projects: invalid project TSV row\n"
10text op_cli_err_buf "omega-projects: output buffer overflow\n"
11
12fn op_write_all fd int buf view uchar * off ulong n ulong to bool
13done = ulong 0
14while lt done n bound 65536
15k = write fd buf add off done sub n done
16if le k 0
17ret false
18end
19done = add done ulong k
20end
21ret true
22end
23
24fn op_read_stdin dst edit uchar * to long
25got = ulong 0
26cap = len dst
27while lt got cap bound 65536
28k = read 0 dst got sub cap got
29if lt k 0
30ret -1
31end
32if eq k 0
33break
34end
35got = add got ulong k
36end
37ret long got
38end
39
40fn op_check_mode to int
41argc = argcnt
42if lt argc 3
43ret -1
44end
45arg1 = new uchar 256 0
46arg2 = new uchar 512 0
47n1 = argread 1 arg1 0 256
48if lt n1 0
49ret 2
50end
51n2 = argread 2 arg2 0 512
52if lt n2 0
53ret 2
54end
55if op_slice_eq arg1 0 ulong n1 op_cli_flag_slug
56if op_valid_slug arg2 0 ulong n2
57okw = op_write_all 1 op_cli_ok 0 len op_cli_ok
58if not okw
59ret 1
60end
61ret 0
62end
63okw = op_write_all 2 op_cli_refused 0 len op_cli_refused
64if not okw
65ret 1
66end
67ret 1
68end
69if op_slice_eq arg1 0 ulong n1 op_cli_flag_path
70if op_valid_project_path arg2 0 ulong n2
71okw = op_write_all 1 op_cli_ok 0 len op_cli_ok
72if not okw
73ret 1
74end
75ret 0
76end
77okw = op_write_all 2 op_cli_refused 0 len op_cli_refused
78if not okw
79ret 1
80end
81ret 1
82end
83ret -1
84end
85
86fn main to int
87mode_rc = op_check_mode
88if ge mode_rc 0
89ret mode_rc
90end
91inbuf = new uchar 16384 0
92outbuf = new uchar 32768 0
93nread = op_read_stdin inbuf
94if lt nread 0
95w = op_write_all 2 op_cli_err_read 0 len op_cli_err_read
96if not w
97ret 2
98end
99ret 1
100end
101pos = op_emit_index_header outbuf 0
102if lt pos 0
103w = op_write_all 2 op_cli_err_buf 0 len op_cli_err_buf
104if not w
105ret 2
106end
107ret 1
108end
109cards = ulong 0
110cur = ulong 0
111total = ulong nread
112meta = new OpMeta 0 0 0 0 0 0 0 0 0 0 0
113while lt cur total bound 16384
114line_start = cur
115while lt cur total bound 16384
116if eq get inbuf cur 10
117cur = add cur 1
118break
119end
120cur = add cur 1
121end
122line_len = sub cur line_start
123if eq line_len 0
124continue
125end
126if eq get inbuf line_start 10
127continue
128end
129if eq get inbuf line_start 35
130continue
131end
132rc = op_parse_tsv_line inbuf line_start line_len meta
133if ne rc 0
134w = op_write_all 2 op_cli_err_row 0 len op_cli_err_row
135if not w
136ret 2
137end
138ret 1
139end
140pos = op_emit_card outbuf ulong pos inbuf meta
141if lt pos 0
142w = op_write_all 2 op_cli_err_buf 0 len op_cli_err_buf
143if not w
144ret 2
145end
146ret 1
147end
148cards = add cards 1
149end
150if eq cards 0
151pos = op_emit_index_empty outbuf ulong pos
152if lt pos 0
153ret 1
154end
155end
156pos = op_emit_index_footer outbuf ulong pos
157if lt pos 0
158ret 1
159end
160ok = op_write_all 1 outbuf 0 ulong pos
161if not ok
162ret 1
163end
164ret 0
165end