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
omega-mv / si / packages / homebrew / formula.om
| 1 | om2 |
| 2 | note si/packages/homebrew/formula.om: Deterministic Homebrew Ruby formula generator and validator. |
| 3 | note Faithful pure-Omega conversion of homebrew-omega (Formula/omc.rb). |
| 4 | note Reads key=value manifest on stdin (version, url, sha256, omc_sha256, optional homepage, license), |
| 5 | note validates semver/date version, allowed HTTPS archive URL prefix, 64-hex lowercase SHA-256 digests, |
| 6 | note rejects Ruby/shell injection characters, emits canonical Formula/omc.rb on stdout, and self-validates. |
| 7 | note Exit codes: 0 = emitted valid formula, 1 = validation refusal, 2 = missing fields or I/O error. |
| 8 | |
| 9 | global inbuf uchar 8192 |
| 10 | global rdbuf uchar 2048 |
| 11 | global outbuf uchar 8192 |
| 12 | global f_ver uchar 128 |
| 13 | global f_url uchar 384 |
| 14 | global f_sha uchar 128 |
| 15 | global f_omc uchar 128 |
| 16 | global f_home uchar 384 |
| 17 | global f_lic uchar 128 |
| 18 | global meta ulong 16 |
| 19 | |
| 20 | const k_inlen ulong 0 |
| 21 | const k_outlen ulong 1 |
| 22 | const k_vlen ulong 2 |
| 23 | const k_ulen ulong 3 |
| 24 | const k_slen ulong 4 |
| 25 | const k_olen ulong 5 |
| 26 | const k_hlen ulong 6 |
| 27 | const k_llen ulong 7 |
| 28 | const k_err ulong 8 |
| 29 | |
| 30 | text pfx_ver "version=" |
| 31 | text pfx_url "url=" |
| 32 | text pfx_sha "sha256=" |
| 33 | text pfx_omc "omc_sha256=" |
| 34 | text pfx_home "homepage=" |
| 35 | text pfx_lic "license=" |
| 36 | |
| 37 | text def_home "https://github.com/aien-dev/omega-mv" |
| 38 | text def_lic "Apache-2.0" |
| 39 | |
| 40 | text allow_p1 "https://interplane.io/" |
| 41 | text allow_p2 "https://github.com/aien-dev/" |
| 42 | text allow_p3 "https://github.com/drakestapleton/" |
| 43 | text sfx_tgz ".tar.gz" |
| 44 | text sfx_txz ".tar.xz" |
| 45 | |
| 46 | text rb_hdr "# omc, the Omega compiler, born from the 408-byte hand-written seed of aien-dev/omega-mv.\n# The build runs omega-mv's seed/omega-from-seed.sh (seed0 -> hex1 -> asm2 -> om4 -> omc -> omc -> omc)\n# using only sh, printf, cat, stat, sed, sha256sum and cmp, then refuses any omc whose sha256 is not\n# the pinned one. AArch64 (arm64) Linux only: omc runs on and emits code for that platform alone.\nclass Omc < Formula\n desc \"Omega compiler, born from a 408-byte hand-written seed\"\n homepage \"" |
| 47 | text rb_url "\"\n url \"" |
| 48 | text rb_ver "\"\n version \"" |
| 49 | text rb_sha "\"\n sha256 \"" |
| 50 | text rb_lic "\"\n license \"" |
| 51 | text rb_dep "\"\n\n depends_on arch: :arm64\n depends_on :linux\n\n OMC_SHA256 = \"" |
| 52 | text rb_inst "\".freeze\n\n def install\n system \"sh\", \"seed/omega-from-seed.sh\"\n got = Digest::SHA256.file(\"seed/out/omc\").hexdigest\n odie \"omc sha256 #{got} is not the pinned #{OMC_SHA256}\" if got != OMC_SHA256\n bin.install \"seed/out/omc\"\n end\n\n test do\n (testpath/\"hello.om\").write <<~OM\n note hello: sum 1..10 and print \"omega 55\" through write\n global out uchar 16\n fn main to int\n s = ulong 0\n for i ulong 11\n s = add s i\n end\n put out 0 111\n put out 1 109\n put out 2 101\n put out 3 103\n put out 4 97\n put out 5 32\n put out 6 uchar add div s 10 48\n put out 7 uchar add rem s 10 48\n put out 8 10\n w = write 1 out 0 9\n ret 0\n end\n OM\n system \"sh\", \"-c\", \"#{bin}/omc < hello.om > hello\"\n chmod 0755, testpath/\"hello\"\n assert_equal \"omega 55\\n\", shell_output(\"./hello\")\n assert_equal OMC_SHA256, Digest::SHA256.file(bin/\"omc\").hexdigest\n end\nend\n" |
| 53 | |
| 54 | text chk_cls "class Omc < Formula" |
| 55 | text chk_arm "depends_on arch: :arm64" |
| 56 | text chk_lin "depends_on :linux" |
| 57 | text chk_odi "odie \"omc sha256 " |
| 58 | |
| 59 | text e_io "formula: failed to read stdin\n" |
| 60 | text e_miss "formula: missing required field (version, url, sha256, omc_sha256)\n" |
| 61 | text e_ver "formula: refused invalid or unsafe version\n" |
| 62 | text e_url "formula: refused invalid or disallowed url\n" |
| 63 | text e_sha "formula: refused invalid sha256 (need 64 lowercase hex)\n" |
| 64 | text e_omc "formula: refused invalid omc_sha256 (need 64 lowercase hex)\n" |
| 65 | text e_home "formula: refused invalid homepage\n" |
| 66 | text e_lic "formula: refused invalid license\n" |
| 67 | text e_self "formula: emitted formula failed self-validation\n" |
| 68 | |
| 69 | fn write_all fd int src view uchar * off ulong n ulong to void |
| 70 | p = ulong 0 |
| 71 | while lt p n bound 16384 |
| 72 | k = write fd src add off p sub n p |
| 73 | if le k 0 |
| 74 | exit 2 |
| 75 | end |
| 76 | p = add p ulong k |
| 77 | end |
| 78 | end |
| 79 | |
| 80 | fn wstr fd int s view uchar * to void |
| 81 | write_all fd s 0 len s |
| 82 | end |
| 83 | |
| 84 | fn is_dig c uchar to bool |
| 85 | ret and ge c 48 le c 57 |
| 86 | end |
| 87 | |
| 88 | fn is_hex_low c uchar to bool |
| 89 | if is_dig c |
| 90 | ret true |
| 91 | end |
| 92 | ret and ge c 97 le c 102 |
| 93 | end |
| 94 | |
| 95 | fn is_alnum c uchar to bool |
| 96 | if is_dig c |
| 97 | ret true |
| 98 | end |
| 99 | if and ge c 65 le c 90 |
| 100 | ret true |
| 101 | end |
| 102 | ret and ge c 97 le c 122 |
| 103 | end |
| 104 | |
| 105 | fn is_injection_ch c uchar to bool |
| 106 | if or lt c 32 gt c 126 |
| 107 | ret true |
| 108 | end |
| 109 | if or eq c 34 eq c 39 |
| 110 | ret true |
| 111 | end |
| 112 | if or eq c 96 eq c 92 |
| 113 | ret true |
| 114 | end |
| 115 | if or eq c 36 eq c 35 |
| 116 | ret true |
| 117 | end |
| 118 | if or eq c 59 eq c 124 |
| 119 | ret true |
| 120 | end |
| 121 | if or eq c 38 eq c 40 |
| 122 | ret true |
| 123 | end |
| 124 | if or eq c 41 eq c 123 |
| 125 | ret true |
| 126 | end |
| 127 | if or eq c 125 or eq c 60 eq c 62 |
| 128 | ret true |
| 129 | end |
| 130 | ret false |
| 131 | end |
| 132 | |
| 133 | fn is_url_ch c uchar to bool |
| 134 | if is_alnum c |
| 135 | ret true |
| 136 | end |
| 137 | if or eq c 45 eq c 46 |
| 138 | ret true |
| 139 | end |
| 140 | if or eq c 95 eq c 126 |
| 141 | ret true |
| 142 | end |
| 143 | if or eq c 58 eq c 47 |
| 144 | ret true |
| 145 | end |
| 146 | ret eq c 37 |
| 147 | end |
| 148 | |
| 149 | fn valid_sha_field which ulong to bool |
| 150 | n = ulong 0 |
| 151 | if eq which 0 |
| 152 | n = get meta k_slen |
| 153 | else |
| 154 | n = get meta k_olen |
| 155 | end |
| 156 | if ne n 64 |
| 157 | ret false |
| 158 | end |
| 159 | i = ulong 0 |
| 160 | while lt i 64 bound 64 |
| 161 | c = uchar 0 |
| 162 | if eq which 0 |
| 163 | c = get f_sha i |
| 164 | else |
| 165 | c = get f_omc i |
| 166 | end |
| 167 | if not is_hex_low c |
| 168 | ret false |
| 169 | end |
| 170 | i = add i 1 |
| 171 | end |
| 172 | ret true |
| 173 | end |
| 174 | |
| 175 | fn valid_ver_ext pos ulong vlen ulong to bool |
| 176 | if ge pos vlen |
| 177 | ret false |
| 178 | end |
| 179 | seg = ulong 0 |
| 180 | i = pos |
| 181 | while lt i vlen bound 128 |
| 182 | c = get f_ver i |
| 183 | if is_injection_ch c |
| 184 | ret false |
| 185 | end |
| 186 | if eq c 46 |
| 187 | if eq seg 0 |
| 188 | ret false |
| 189 | end |
| 190 | seg = ulong 0 |
| 191 | else |
| 192 | if or is_alnum c eq c 45 |
| 193 | seg = add seg 1 |
| 194 | else |
| 195 | ret false |
| 196 | end |
| 197 | end |
| 198 | i = add i 1 |
| 199 | end |
| 200 | ret gt seg 0 |
| 201 | end |
| 202 | |
| 203 | fn valid_date_ver to bool |
| 204 | j = ulong 0 |
| 205 | while lt j 8 bound 8 |
| 206 | if not is_dig get f_ver j |
| 207 | ret false |
| 208 | end |
| 209 | j = add j 1 |
| 210 | end |
| 211 | yr = mul ulong sub get f_ver 0 48 1000 |
| 212 | yr = add yr mul ulong sub get f_ver 1 48 100 |
| 213 | yr = add yr mul ulong sub get f_ver 2 48 10 |
| 214 | yr = add yr ulong sub get f_ver 3 48 |
| 215 | mo = mul ulong sub get f_ver 4 48 10 |
| 216 | mo = add mo ulong sub get f_ver 5 48 |
| 217 | dy = mul ulong sub get f_ver 6 48 10 |
| 218 | dy = add dy ulong sub get f_ver 7 48 |
| 219 | if lt yr 2020 |
| 220 | ret false |
| 221 | end |
| 222 | if or lt mo 1 gt mo 12 |
| 223 | ret false |
| 224 | end |
| 225 | ret and ge dy 1 le dy 31 |
| 226 | end |
| 227 | |
| 228 | note valid_version: accepts semver MAJOR.MINOR.PATCH[-pre][+build] or YYYYMMDD (8 digits) |
| 229 | fn valid_version to bool |
| 230 | n = get meta k_vlen |
| 231 | if or eq n 0 gt n 64 |
| 232 | ret false |
| 233 | end |
| 234 | i = ulong 0 |
| 235 | while lt i n bound 128 |
| 236 | if is_injection_ch get f_ver i |
| 237 | ret false |
| 238 | end |
| 239 | i = add i 1 |
| 240 | end |
| 241 | if eq n 8 |
| 242 | if valid_date_ver |
| 243 | ret true |
| 244 | end |
| 245 | end |
| 246 | dots = ulong 0 |
| 247 | seg = ulong 0 |
| 248 | p = ulong 0 |
| 249 | while lt p n bound 128 |
| 250 | c = get f_ver p |
| 251 | if is_dig c |
| 252 | seg = add seg 1 |
| 253 | else |
| 254 | if eq c 46 |
| 255 | if or eq seg 0 ge dots 2 |
| 256 | ret false |
| 257 | end |
| 258 | dots = add dots 1 |
| 259 | seg = ulong 0 |
| 260 | else |
| 261 | if or eq c 45 eq c 43 |
| 262 | if or ne dots 2 eq seg 0 |
| 263 | ret false |
| 264 | end |
| 265 | ret valid_ver_ext add p 1 n |
| 266 | else |
| 267 | ret false |
| 268 | end |
| 269 | end |
| 270 | end |
| 271 | p = add p 1 |
| 272 | end |
| 273 | ret and eq dots 2 gt seg 0 |
| 274 | end |
| 275 | |
| 276 | fn url_starts_with pfx view uchar * is_home bool to bool |
| 277 | pl = len pfx |
| 278 | ul = ulong 0 |
| 279 | if is_home |
| 280 | ul = get meta k_hlen |
| 281 | else |
| 282 | ul = get meta k_ulen |
| 283 | end |
| 284 | if lt ul pl |
| 285 | ret false |
| 286 | end |
| 287 | i = ulong 0 |
| 288 | while lt i pl bound 64 |
| 289 | c = uchar 0 |
| 290 | if is_home |
| 291 | c = get f_home i |
| 292 | else |
| 293 | c = get f_url i |
| 294 | end |
| 295 | if ne c get pfx i |
| 296 | ret false |
| 297 | end |
| 298 | i = add i 1 |
| 299 | end |
| 300 | ret true |
| 301 | end |
| 302 | |
| 303 | fn url_ends_with sfx view uchar * to bool |
| 304 | sl = len sfx |
| 305 | ul = get meta k_ulen |
| 306 | if lt ul sl |
| 307 | ret false |
| 308 | end |
| 309 | off = sub ul sl |
| 310 | i = ulong 0 |
| 311 | while lt i sl bound 32 |
| 312 | if ne get f_url add off i get sfx i |
| 313 | ret false |
| 314 | end |
| 315 | i = add i 1 |
| 316 | end |
| 317 | ret true |
| 318 | end |
| 319 | |
| 320 | fn url_has_dotdot is_home bool to bool |
| 321 | ul = ulong 0 |
| 322 | if is_home |
| 323 | ul = get meta k_hlen |
| 324 | else |
| 325 | ul = get meta k_ulen |
| 326 | end |
| 327 | if lt ul 2 |
| 328 | ret false |
| 329 | end |
| 330 | i = ulong 0 |
| 331 | lim = sub ul 1 |
| 332 | while lt i lim bound 384 |
| 333 | a = uchar 0 |
| 334 | b = uchar 0 |
| 335 | if is_home |
| 336 | a = get f_home i |
| 337 | b = get f_home add i 1 |
| 338 | else |
| 339 | a = get f_url i |
| 340 | b = get f_url add i 1 |
| 341 | end |
| 342 | if and eq a 46 eq b 46 |
| 343 | ret true |
| 344 | end |
| 345 | i = add i 1 |
| 346 | end |
| 347 | ret false |
| 348 | end |
| 349 | |
| 350 | fn valid_url to bool |
| 351 | ul = get meta k_ulen |
| 352 | if or lt ul 16 gt ul 320 |
| 353 | ret false |
| 354 | end |
| 355 | ok_pfx = false |
| 356 | if url_starts_with allow_p1 false |
| 357 | ok_pfx = true |
| 358 | end |
| 359 | if url_starts_with allow_p2 false |
| 360 | ok_pfx = true |
| 361 | end |
| 362 | if url_starts_with allow_p3 false |
| 363 | ok_pfx = true |
| 364 | end |
| 365 | if not ok_pfx |
| 366 | ret false |
| 367 | end |
| 368 | ok_sfx = false |
| 369 | if url_ends_with sfx_tgz |
| 370 | ok_sfx = true |
| 371 | end |
| 372 | if url_ends_with sfx_txz |
| 373 | ok_sfx = true |
| 374 | end |
| 375 | if not ok_sfx |
| 376 | ret false |
| 377 | end |
| 378 | if url_has_dotdot false |
| 379 | ret false |
| 380 | end |
| 381 | i = ulong 0 |
| 382 | while lt i ul bound 384 |
| 383 | c = get f_url i |
| 384 | if or is_injection_ch c not is_url_ch c |
| 385 | ret false |
| 386 | end |
| 387 | i = add i 1 |
| 388 | end |
| 389 | ret true |
| 390 | end |
| 391 | |
| 392 | fn valid_homepage to bool |
| 393 | hl = get meta k_hlen |
| 394 | if or lt hl 16 gt hl 320 |
| 395 | ret false |
| 396 | end |
| 397 | ok_pfx = false |
| 398 | if url_starts_with allow_p1 true |
| 399 | ok_pfx = true |
| 400 | end |
| 401 | if url_starts_with allow_p2 true |
| 402 | ok_pfx = true |
| 403 | end |
| 404 | if url_starts_with allow_p3 true |
| 405 | ok_pfx = true |
| 406 | end |
| 407 | if not ok_pfx |
| 408 | ret false |
| 409 | end |
| 410 | if url_has_dotdot true |
| 411 | ret false |
| 412 | end |
| 413 | i = ulong 0 |
| 414 | while lt i hl bound 384 |
| 415 | c = get f_home i |
| 416 | if or is_injection_ch c not is_url_ch c |
| 417 | ret false |
| 418 | end |
| 419 | i = add i 1 |
| 420 | end |
| 421 | ret true |
| 422 | end |
| 423 | |
| 424 | fn valid_license to bool |
| 425 | ll = get meta k_llen |
| 426 | if or eq ll 0 gt ll 64 |
| 427 | ret false |
| 428 | end |
| 429 | i = ulong 0 |
| 430 | while lt i ll bound 64 |
| 431 | c = get f_lic i |
| 432 | if is_injection_ch c |
| 433 | ret false |
| 434 | end |
| 435 | ok = false |
| 436 | if is_alnum c |
| 437 | ok = true |
| 438 | end |
| 439 | if or eq c 45 or eq c 46 or eq c 43 eq c 32 |
| 440 | ok = true |
| 441 | end |
| 442 | if not ok |
| 443 | ret false |
| 444 | end |
| 445 | i = add i 1 |
| 446 | end |
| 447 | ret true |
| 448 | end |
| 449 | |
| 450 | note Output builder helpers |
| 451 | fn out_clear to void |
| 452 | put meta k_outlen 0 |
| 453 | end |
| 454 | |
| 455 | fn out_push_lit s view uchar * to void |
| 456 | sl = len s |
| 457 | p = get meta k_outlen |
| 458 | i = ulong 0 |
| 459 | while lt i sl bound 4096 |
| 460 | if lt p 8192 |
| 461 | put outbuf p get s i |
| 462 | p = add p 1 |
| 463 | end |
| 464 | i = add i 1 |
| 465 | end |
| 466 | put meta k_outlen p |
| 467 | end |
| 468 | |
| 469 | fn out_push_field which ulong to void |
| 470 | p = get meta k_outlen |
| 471 | n = ulong 0 |
| 472 | if eq which 0 |
| 473 | n = get meta k_hlen |
| 474 | else |
| 475 | if eq which 1 |
| 476 | n = get meta k_ulen |
| 477 | else |
| 478 | if eq which 2 |
| 479 | n = get meta k_vlen |
| 480 | else |
| 481 | if eq which 3 |
| 482 | n = get meta k_slen |
| 483 | else |
| 484 | if eq which 4 |
| 485 | n = get meta k_llen |
| 486 | else |
| 487 | n = get meta k_olen |
| 488 | end |
| 489 | end |
| 490 | end |
| 491 | end |
| 492 | end |
| 493 | i = ulong 0 |
| 494 | while lt i n bound 384 |
| 495 | c = uchar 0 |
| 496 | if eq which 0 |
| 497 | c = get f_home i |
| 498 | else |
| 499 | if eq which 1 |
| 500 | c = get f_url i |
| 501 | else |
| 502 | if eq which 2 |
| 503 | c = get f_ver i |
| 504 | else |
| 505 | if eq which 3 |
| 506 | c = get f_sha i |
| 507 | else |
| 508 | if eq which 4 |
| 509 | c = get f_lic i |
| 510 | else |
| 511 | c = get f_omc i |
| 512 | end |
| 513 | end |
| 514 | end |
| 515 | end |
| 516 | end |
| 517 | if lt p 8192 |
| 518 | put outbuf p c |
| 519 | p = add p 1 |
| 520 | end |
| 521 | i = add i 1 |
| 522 | end |
| 523 | put meta k_outlen p |
| 524 | end |
| 525 | |
| 526 | fn emit_formula to void |
| 527 | out_clear |
| 528 | out_push_lit rb_hdr |
| 529 | out_push_field 0 |
| 530 | out_push_lit rb_url |
| 531 | out_push_field 1 |
| 532 | out_push_lit rb_ver |
| 533 | out_push_field 2 |
| 534 | out_push_lit rb_sha |
| 535 | out_push_field 3 |
| 536 | out_push_lit rb_lic |
| 537 | out_push_field 4 |
| 538 | out_push_lit rb_dep |
| 539 | out_push_field 5 |
| 540 | out_push_lit rb_inst |
| 541 | end |
| 542 | |
| 543 | fn out_starts_at pos ulong needle view uchar * to bool |
| 544 | nl = len needle |
| 545 | tot = get meta k_outlen |
| 546 | if gt add pos nl tot |
| 547 | ret false |
| 548 | end |
| 549 | i = ulong 0 |
| 550 | while lt i nl bound 128 |
| 551 | if ne get outbuf add pos i get needle i |
| 552 | ret false |
| 553 | end |
| 554 | i = add i 1 |
| 555 | end |
| 556 | ret true |
| 557 | end |
| 558 | |
| 559 | fn out_contains needle view uchar * to bool |
| 560 | nl = len needle |
| 561 | tot = get meta k_outlen |
| 562 | if gt nl tot |
| 563 | ret false |
| 564 | end |
| 565 | lim = add sub tot nl 1 |
| 566 | i = ulong 0 |
| 567 | while lt i lim bound 8192 |
| 568 | if out_starts_at i needle |
| 569 | ret true |
| 570 | end |
| 571 | i = add i 1 |
| 572 | end |
| 573 | ret false |
| 574 | end |
| 575 | |
| 576 | fn validate_emitted_formula to bool |
| 577 | if not out_contains chk_cls |
| 578 | ret false |
| 579 | end |
| 580 | if not out_contains chk_arm |
| 581 | ret false |
| 582 | end |
| 583 | if not out_contains chk_lin |
| 584 | ret false |
| 585 | end |
| 586 | if not out_contains chk_odi |
| 587 | ret false |
| 588 | end |
| 589 | ret true |
| 590 | end |
| 591 | |
| 592 | fn in_starts off ulong llen ulong pfx view uchar * to bool |
| 593 | pl = len pfx |
| 594 | if lt llen pl |
| 595 | ret false |
| 596 | end |
| 597 | i = ulong 0 |
| 598 | while lt i pl bound 64 |
| 599 | if ne get inbuf add off i get pfx i |
| 600 | ret false |
| 601 | end |
| 602 | i = add i 1 |
| 603 | end |
| 604 | ret true |
| 605 | end |
| 606 | |
| 607 | fn copy_in_to_field which ulong off ulong n ulong to void |
| 608 | lim = ulong 128 |
| 609 | if or eq which 0 eq which 1 |
| 610 | lim = ulong 384 |
| 611 | end |
| 612 | if gt n lim |
| 613 | n = lim |
| 614 | end |
| 615 | i = ulong 0 |
| 616 | while lt i n bound 384 |
| 617 | c = get inbuf add off i |
| 618 | if eq which 0 |
| 619 | put f_home i c |
| 620 | else |
| 621 | if eq which 1 |
| 622 | put f_url i c |
| 623 | else |
| 624 | if eq which 2 |
| 625 | put f_ver i c |
| 626 | else |
| 627 | if eq which 3 |
| 628 | put f_sha i c |
| 629 | else |
| 630 | if eq which 4 |
| 631 | put f_lic i c |
| 632 | else |
| 633 | put f_omc i c |
| 634 | end |
| 635 | end |
| 636 | end |
| 637 | end |
| 638 | end |
| 639 | i = add i 1 |
| 640 | end |
| 641 | if eq which 0 |
| 642 | put meta k_hlen n |
| 643 | else |
| 644 | if eq which 1 |
| 645 | put meta k_ulen n |
| 646 | else |
| 647 | if eq which 2 |
| 648 | put meta k_vlen n |
| 649 | else |
| 650 | if eq which 3 |
| 651 | put meta k_slen n |
| 652 | else |
| 653 | if eq which 4 |
| 654 | put meta k_llen n |
| 655 | else |
| 656 | put meta k_olen n |
| 657 | end |
| 658 | end |
| 659 | end |
| 660 | end |
| 661 | end |
| 662 | end |
| 663 | |
| 664 | fn set_defaults to void |
| 665 | for i ulong 16 |
| 666 | put meta i 0 |
| 667 | end |
| 668 | hl = len def_home |
| 669 | i = ulong 0 |
| 670 | while lt i hl bound 128 |
| 671 | put f_home i get def_home i |
| 672 | i = add i 1 |
| 673 | end |
| 674 | put meta k_hlen hl |
| 675 | ll = len def_lic |
| 676 | j = ulong 0 |
| 677 | while lt j ll bound 64 |
| 678 | put f_lic j get def_lic j |
| 679 | j = add j 1 |
| 680 | end |
| 681 | put meta k_llen ll |
| 682 | end |
| 683 | |
| 684 | fn parse_manifest to void |
| 685 | tot = get meta k_inlen |
| 686 | pos = ulong 0 |
| 687 | while lt pos tot bound 8192 |
| 688 | ls = pos |
| 689 | while lt pos tot bound 8192 |
| 690 | if eq get inbuf pos 10 |
| 691 | break |
| 692 | end |
| 693 | pos = add pos 1 |
| 694 | end |
| 695 | ll = sub pos ls |
| 696 | if gt ll 0 |
| 697 | if ne get inbuf ls 35 |
| 698 | if in_starts ls ll pfx_ver |
| 699 | copy_in_to_field 2 add ls 8 sub ll 8 |
| 700 | else |
| 701 | if in_starts ls ll pfx_url |
| 702 | copy_in_to_field 1 add ls 4 sub ll 4 |
| 703 | else |
| 704 | if in_starts ls ll pfx_sha |
| 705 | copy_in_to_field 3 add ls 7 sub ll 7 |
| 706 | else |
| 707 | if in_starts ls ll pfx_omc |
| 708 | copy_in_to_field 5 add ls 11 sub ll 11 |
| 709 | else |
| 710 | if in_starts ls ll pfx_home |
| 711 | copy_in_to_field 0 add ls 9 sub ll 9 |
| 712 | else |
| 713 | if in_starts ls ll pfx_lic |
| 714 | copy_in_to_field 4 add ls 8 sub ll 8 |
| 715 | end |
| 716 | end |
| 717 | end |
| 718 | end |
| 719 | end |
| 720 | end |
| 721 | end |
| 722 | end |
| 723 | if lt pos tot |
| 724 | pos = add pos 1 |
| 725 | end |
| 726 | end |
| 727 | end |
| 728 | |
| 729 | fn read_stdin to bool |
| 730 | tot = ulong 0 |
| 731 | while true bound 64 |
| 732 | k = read 0 rdbuf 0 2048 |
| 733 | if lt k 0 |
| 734 | ret false |
| 735 | end |
| 736 | if eq k 0 |
| 737 | break |
| 738 | end |
| 739 | kn = ulong k |
| 740 | i = ulong 0 |
| 741 | while lt i kn bound 2048 |
| 742 | c = get rdbuf i |
| 743 | if ne c 13 |
| 744 | if ge tot 8192 |
| 745 | ret false |
| 746 | end |
| 747 | put inbuf tot c |
| 748 | tot = add tot 1 |
| 749 | end |
| 750 | i = add i 1 |
| 751 | end |
| 752 | end |
| 753 | put meta k_inlen tot |
| 754 | ret true |
| 755 | end |
| 756 | |
| 757 | fn flush_outbuf to void |
| 758 | n = get meta k_outlen |
| 759 | p = ulong 0 |
| 760 | while lt p n bound 8192 |
| 761 | k = write 1 outbuf p sub n p |
| 762 | if le k 0 |
| 763 | exit 2 |
| 764 | end |
| 765 | p = add p ulong k |
| 766 | end |
| 767 | end |
| 768 | |
| 769 | fn main to int |
| 770 | set_defaults |
| 771 | if not read_stdin |
| 772 | wstr 2 e_io |
| 773 | ret 2 |
| 774 | end |
| 775 | parse_manifest |
| 776 | if or eq get meta k_vlen 0 or eq get meta k_ulen 0 or eq get meta k_slen 0 eq get meta k_olen 0 |
| 777 | wstr 2 e_miss |
| 778 | ret 2 |
| 779 | end |
| 780 | if not valid_version |
| 781 | wstr 2 e_ver |
| 782 | ret 1 |
| 783 | end |
| 784 | if not valid_url |
| 785 | wstr 2 e_url |
| 786 | ret 1 |
| 787 | end |
| 788 | if not valid_sha_field 0 |
| 789 | wstr 2 e_sha |
| 790 | ret 1 |
| 791 | end |
| 792 | if not valid_sha_field 1 |
| 793 | wstr 2 e_omc |
| 794 | ret 1 |
| 795 | end |
| 796 | if not valid_homepage |
| 797 | wstr 2 e_home |
| 798 | ret 1 |
| 799 | end |
| 800 | if not valid_license |
| 801 | wstr 2 e_lic |
| 802 | ret 1 |
| 803 | end |
| 804 | emit_formula |
| 805 | if not validate_emitted_formula |
| 806 | wstr 2 e_self |
| 807 | ret 1 |
| 808 | end |
| 809 | flush_outbuf |
| 810 | ret 0 |
| 811 | end |