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 / architecture / tools / zero-legacy / closure.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note zero-legacy closure checker, v0 (aien-architecture-mv #316, under #300). |
| 3 | note Seeded Omega program: walks one checked-out tree, classifies every regular |
| 4 | note file by content and name, applies a declared manifest, prints one row per |
| 5 | note file and a summary, and in release mode refuses outstanding or unknown rows. |
| 6 | note usage: closure ROOT [release] [MANIFEST] |
| 7 | note Built only by seed/out/omc from aien-dev/omega-mv (see omega.pin). |
| 8 | |
| 9 | text tuse "usage: closure ROOT [release] [MANIFEST]\n" |
| 10 | text terr "closure: cannot read MANIFEST\n" |
| 11 | text tbig "closure: MANIFEST over 65534 bytes\n" |
| 12 | text tnl "\n" |
| 13 | text ttab "\t" |
| 14 | text tsp " " |
| 15 | text thash "# " |
| 16 | text tout "OUTSTANDING " |
| 17 | text tunk "UNKNOWN " |
| 18 | text tmode "MODE " |
| 19 | text trel "release" |
| 20 | text tpy "python" |
| 21 | text tpl "perl" |
| 22 | text tnd "node" |
| 23 | text trb "ruby" |
| 24 | text tinc "#includ" |
| 25 | text tfnm "fn main" |
| 26 | text texe "execpro" |
| 27 | text tmk "Makefile" |
| 28 | text tdat "data " |
| 29 | text tgen "generated " |
| 30 | text text_ "external " |
| 31 | text tskp "skip " |
| 32 | |
| 33 | text c0 "OM" |
| 34 | text c1 "C_H" |
| 35 | text c2 "RUST" |
| 36 | text c3 "PYTHON" |
| 37 | text c4 "SHELL" |
| 38 | text c5 "OSC" |
| 39 | text c6 "HEXASM" |
| 40 | text c7 "ELF" |
| 41 | text c8 "ARCHIVE" |
| 42 | text c9 "DOC" |
| 43 | text c10 "OTHER" |
| 44 | text c11 "HIDDEN" |
| 45 | text c12 "WRAPPER" |
| 46 | text c13 "DATA" |
| 47 | text c14 "GENERATED" |
| 48 | text c15 "EXTERNAL" |
| 49 | text c16 "FOREIGN" |
| 50 | text c17 "SYMLINK" |
| 51 | text c18 "FORGED" |
| 52 | text c19 "SKIP" |
| 53 | text c20 "MAKE" |
| 54 | text c21 "UNREADABLE" |
| 55 | |
| 56 | global path uchar 4096 |
| 57 | global plen ulong 1 |
| 58 | global rootl ulong 1 |
| 59 | global stk uchar 1048576 |
| 60 | global stkt ulong 1 |
| 61 | global dbuf uchar 65536 |
| 62 | global head uchar 4096 |
| 63 | global hlen ulong 1 |
| 64 | global ndl uchar 32 |
| 65 | global ndln ulong 1 |
| 66 | global nb uchar 24 |
| 67 | global cnt ulong 32 |
| 68 | global alw uchar 65536 |
| 69 | global alwn ulong 1 |
| 70 | global pst ulong 1 |
| 71 | global mode ulong 1 |
| 72 | global name uchar 256 |
| 73 | |
| 74 | note ---- output ---- |
| 75 | |
| 76 | fn wnl to void |
| 77 | r = write 1 tnl 0 1 |
| 78 | end |
| 79 | |
| 80 | fn wnum v ulong to void |
| 81 | n = ulong 0 |
| 82 | if eq v 0 |
| 83 | put nb 23 48 |
| 84 | n = 1 |
| 85 | end |
| 86 | x = v |
| 87 | while gt x 0 bound 20 |
| 88 | put nb sub 23 n uchar add 48 rem x 10 |
| 89 | x = div x 10 |
| 90 | n = add n 1 |
| 91 | end |
| 92 | r = write 1 nb sub 24 n n |
| 93 | end |
| 94 | |
| 95 | fn wcat k ulong to void |
| 96 | if eq k 0 |
| 97 | r = write 1 c0 0 len c0 |
| 98 | end |
| 99 | if eq k 1 |
| 100 | r = write 1 c1 0 len c1 |
| 101 | end |
| 102 | if eq k 2 |
| 103 | r = write 1 c2 0 len c2 |
| 104 | end |
| 105 | if eq k 3 |
| 106 | r = write 1 c3 0 len c3 |
| 107 | end |
| 108 | if eq k 4 |
| 109 | r = write 1 c4 0 len c4 |
| 110 | end |
| 111 | if eq k 5 |
| 112 | r = write 1 c5 0 len c5 |
| 113 | end |
| 114 | if eq k 6 |
| 115 | r = write 1 c6 0 len c6 |
| 116 | end |
| 117 | if eq k 7 |
| 118 | r = write 1 c7 0 len c7 |
| 119 | end |
| 120 | if eq k 8 |
| 121 | r = write 1 c8 0 len c8 |
| 122 | end |
| 123 | if eq k 9 |
| 124 | r = write 1 c9 0 len c9 |
| 125 | end |
| 126 | if eq k 10 |
| 127 | r = write 1 c10 0 len c10 |
| 128 | end |
| 129 | if eq k 11 |
| 130 | r = write 1 c11 0 len c11 |
| 131 | end |
| 132 | if eq k 12 |
| 133 | r = write 1 c12 0 len c12 |
| 134 | end |
| 135 | if eq k 13 |
| 136 | r = write 1 c13 0 len c13 |
| 137 | end |
| 138 | if eq k 14 |
| 139 | r = write 1 c14 0 len c14 |
| 140 | end |
| 141 | if eq k 15 |
| 142 | r = write 1 c15 0 len c15 |
| 143 | end |
| 144 | if eq k 16 |
| 145 | r = write 1 c16 0 len c16 |
| 146 | end |
| 147 | if eq k 17 |
| 148 | r = write 1 c17 0 len c17 |
| 149 | end |
| 150 | if eq k 18 |
| 151 | r = write 1 c18 0 len c18 |
| 152 | end |
| 153 | if eq k 19 |
| 154 | r = write 1 c19 0 len c19 |
| 155 | end |
| 156 | if eq k 20 |
| 157 | r = write 1 c20 0 len c20 |
| 158 | end |
| 159 | if eq k 21 |
| 160 | r = write 1 c21 0 len c21 |
| 161 | end |
| 162 | end |
| 163 | |
| 164 | fn report k ulong to void |
| 165 | wcat k |
| 166 | r = write 1 ttab 0 1 |
| 167 | r = write 1 path 0 get plen 0 |
| 168 | wnl |
| 169 | put cnt k add get cnt k 1 |
| 170 | end |
| 171 | |
| 172 | note ---- needles and searches over the file head ---- |
| 173 | |
| 174 | fn ldpy to void |
| 175 | for i ulong len tpy |
| 176 | put ndl i get tpy i |
| 177 | end |
| 178 | put ndln 0 len tpy |
| 179 | end |
| 180 | |
| 181 | fn ldpl to void |
| 182 | for i ulong len tpl |
| 183 | put ndl i get tpl i |
| 184 | end |
| 185 | put ndln 0 len tpl |
| 186 | end |
| 187 | |
| 188 | fn ldnd to void |
| 189 | for i ulong len tnd |
| 190 | put ndl i get tnd i |
| 191 | end |
| 192 | put ndln 0 len tnd |
| 193 | end |
| 194 | |
| 195 | fn ldrb to void |
| 196 | for i ulong len trb |
| 197 | put ndl i get trb i |
| 198 | end |
| 199 | put ndln 0 len trb |
| 200 | end |
| 201 | |
| 202 | note needles are completed at run time so this source does not match itself |
| 203 | fn ldinc to void |
| 204 | for i ulong len tinc |
| 205 | put ndl i get tinc i |
| 206 | end |
| 207 | put ndl len tinc 101 |
| 208 | put ndln 0 add len tinc 1 |
| 209 | end |
| 210 | |
| 211 | fn ldfnm to void |
| 212 | for i ulong len tfnm |
| 213 | put ndl i get tfnm i |
| 214 | end |
| 215 | put ndl len tfnm 40 |
| 216 | put ndln 0 add len tfnm 1 |
| 217 | end |
| 218 | |
| 219 | fn ldexe to void |
| 220 | for i ulong len texe |
| 221 | put ndl i get texe i |
| 222 | end |
| 223 | put ndl len texe 103 |
| 224 | put ndln 0 add len texe 1 |
| 225 | end |
| 226 | |
| 227 | fn found to bool |
| 228 | h = get hlen 0 |
| 229 | m = get ndln 0 |
| 230 | if lt h m |
| 231 | ret false |
| 232 | end |
| 233 | e = sub h m |
| 234 | i = ulong 0 |
| 235 | while le i e bound 4097 |
| 236 | j = ulong 0 |
| 237 | while lt j m bound 32 |
| 238 | if ne get head add i j get ndl j |
| 239 | break |
| 240 | end |
| 241 | j = add j 1 |
| 242 | end |
| 243 | if eq j m |
| 244 | ret true |
| 245 | end |
| 246 | i = add i 1 |
| 247 | end |
| 248 | ret false |
| 249 | end |
| 250 | |
| 251 | fn interp to bool |
| 252 | ldpy |
| 253 | if found |
| 254 | ret true |
| 255 | end |
| 256 | ldpl |
| 257 | if found |
| 258 | ret true |
| 259 | end |
| 260 | ldnd |
| 261 | if found |
| 262 | ret true |
| 263 | end |
| 264 | ldrb |
| 265 | if found |
| 266 | ret true |
| 267 | end |
| 268 | ret false |
| 269 | end |
| 270 | |
| 271 | fn isshb to bool |
| 272 | if lt get hlen 0 2 |
| 273 | ret false |
| 274 | end |
| 275 | ret and eq get head 0 35 eq get head 1 33 |
| 276 | end |
| 277 | |
| 278 | fn m4 a uchar b uchar c uchar d uchar to bool |
| 279 | if ne get head 0 a |
| 280 | ret false |
| 281 | end |
| 282 | if ne get head 1 b |
| 283 | ret false |
| 284 | end |
| 285 | if ne get head 2 c |
| 286 | ret false |
| 287 | end |
| 288 | ret eq get head 3 d |
| 289 | end |
| 290 | |
| 291 | fn tar to bool |
| 292 | if ne get head 257 117 |
| 293 | ret false |
| 294 | end |
| 295 | if ne get head 258 115 |
| 296 | ret false |
| 297 | end |
| 298 | if ne get head 259 116 |
| 299 | ret false |
| 300 | end |
| 301 | if ne get head 260 97 |
| 302 | ret false |
| 303 | end |
| 304 | ret eq get head 261 114 |
| 305 | end |
| 306 | |
| 307 | fn isbin to ulong |
| 308 | h = get hlen 0 |
| 309 | if lt h 4 |
| 310 | ret 0 |
| 311 | end |
| 312 | if m4 127 69 76 70 |
| 313 | ret 7 |
| 314 | end |
| 315 | if and eq get head 0 31 eq get head 1 139 |
| 316 | ret 8 |
| 317 | end |
| 318 | if m4 80 75 3 4 |
| 319 | ret 8 |
| 320 | end |
| 321 | if m4 253 55 122 88 |
| 322 | ret 8 |
| 323 | end |
| 324 | if ge h 262 |
| 325 | if tar |
| 326 | ret 8 |
| 327 | end |
| 328 | end |
| 329 | ret 0 |
| 330 | end |
| 331 | |
| 332 | note ---- name suffixes on the current path ---- |
| 333 | |
| 334 | fn e1 a uchar to bool |
| 335 | n = get plen 0 |
| 336 | if lt n 2 |
| 337 | ret false |
| 338 | end |
| 339 | if ne get path sub n 2 46 |
| 340 | ret false |
| 341 | end |
| 342 | ret eq get path sub n 1 a |
| 343 | end |
| 344 | |
| 345 | fn e2 a uchar b uchar to bool |
| 346 | n = get plen 0 |
| 347 | if lt n 3 |
| 348 | ret false |
| 349 | end |
| 350 | if ne get path sub n 3 46 |
| 351 | ret false |
| 352 | end |
| 353 | if ne get path sub n 2 a |
| 354 | ret false |
| 355 | end |
| 356 | ret eq get path sub n 1 b |
| 357 | end |
| 358 | |
| 359 | fn e3 a uchar b uchar c uchar to bool |
| 360 | n = get plen 0 |
| 361 | if lt n 4 |
| 362 | ret false |
| 363 | end |
| 364 | if ne get path sub n 4 46 |
| 365 | ret false |
| 366 | end |
| 367 | if ne get path sub n 3 a |
| 368 | ret false |
| 369 | end |
| 370 | if ne get path sub n 2 b |
| 371 | ret false |
| 372 | end |
| 373 | ret eq get path sub n 1 c |
| 374 | end |
| 375 | |
| 376 | fn e4 a uchar b uchar c uchar d uchar to bool |
| 377 | n = get plen 0 |
| 378 | if lt n 5 |
| 379 | ret false |
| 380 | end |
| 381 | if ne get path sub n 5 46 |
| 382 | ret false |
| 383 | end |
| 384 | if ne get path sub n 4 a |
| 385 | ret false |
| 386 | end |
| 387 | if ne get path sub n 3 b |
| 388 | ret false |
| 389 | end |
| 390 | if ne get path sub n 2 c |
| 391 | ret false |
| 392 | end |
| 393 | ret eq get path sub n 1 d |
| 394 | end |
| 395 | |
| 396 | fn ismake to bool |
| 397 | if e2 109 107 |
| 398 | ret true |
| 399 | end |
| 400 | n = get plen 0 |
| 401 | if lt n 8 |
| 402 | ret false |
| 403 | end |
| 404 | for i ulong 8 |
| 405 | if ne get path add sub n 8 i get tmk i |
| 406 | ret false |
| 407 | end |
| 408 | end |
| 409 | if eq n 8 |
| 410 | ret true |
| 411 | end |
| 412 | ret eq get path sub n 9 47 |
| 413 | end |
| 414 | |
| 415 | fn e5 a uchar b uchar c uchar d uchar e uchar to bool |
| 416 | n = get plen 0 |
| 417 | if lt n 6 |
| 418 | ret false |
| 419 | end |
| 420 | if ne get path sub n 6 46 |
| 421 | ret false |
| 422 | end |
| 423 | if ne get path sub n 5 a |
| 424 | ret false |
| 425 | end |
| 426 | if ne get path sub n 4 b |
| 427 | ret false |
| 428 | end |
| 429 | if ne get path sub n 3 c |
| 430 | ret false |
| 431 | end |
| 432 | if ne get path sub n 2 d |
| 433 | ret false |
| 434 | end |
| 435 | ret eq get path sub n 1 e |
| 436 | end |
| 437 | |
| 438 | note the last path component: a dotfile with one dot, or an all-capitals name |
| 439 | fn base to ulong |
| 440 | n = get plen 0 |
| 441 | i = n |
| 442 | while gt i 0 bound 4096 |
| 443 | if eq get path sub i 1 47 |
| 444 | break |
| 445 | end |
| 446 | i = sub i 1 |
| 447 | end |
| 448 | ret i |
| 449 | end |
| 450 | |
| 451 | fn isdot to bool |
| 452 | b = base |
| 453 | n = get plen 0 |
| 454 | if ne get path b 46 |
| 455 | ret false |
| 456 | end |
| 457 | i = add b 1 |
| 458 | while lt i n bound 256 |
| 459 | if eq get path i 46 |
| 460 | ret false |
| 461 | end |
| 462 | i = add i 1 |
| 463 | end |
| 464 | ret gt n add b 1 |
| 465 | end |
| 466 | |
| 467 | fn iscaps to bool |
| 468 | b = base |
| 469 | n = get plen 0 |
| 470 | if ge b n |
| 471 | ret false |
| 472 | end |
| 473 | i = b |
| 474 | while lt i n bound 256 |
| 475 | c = get path i |
| 476 | if lt c 65 |
| 477 | if and ne c 45 ne c 95 |
| 478 | ret false |
| 479 | end |
| 480 | end |
| 481 | if gt c 90 |
| 482 | if ne c 95 |
| 483 | ret false |
| 484 | end |
| 485 | end |
| 486 | i = add i 1 |
| 487 | end |
| 488 | ret true |
| 489 | end |
| 490 | |
| 491 | fn isdoc to bool |
| 492 | if or e2 109 100 e3 116 120 116 |
| 493 | ret true |
| 494 | end |
| 495 | if or e5 99 114 117 109 98 e3 108 111 103 |
| 496 | ret true |
| 497 | end |
| 498 | if or isdot iscaps |
| 499 | ret true |
| 500 | end |
| 501 | if or e4 106 115 111 110 e4 116 111 109 108 |
| 502 | ret true |
| 503 | end |
| 504 | if or e3 121 109 108 e4 121 97 109 108 |
| 505 | ret true |
| 506 | end |
| 507 | if or e4 108 111 99 107 e3 99 115 118 |
| 508 | ret true |
| 509 | end |
| 510 | if or e3 115 118 103 e4 104 116 109 108 |
| 511 | ret true |
| 512 | end |
| 513 | if or e3 99 115 115 e3 112 110 103 |
| 514 | ret true |
| 515 | end |
| 516 | if or e3 106 112 103 e3 103 105 102 |
| 517 | ret true |
| 518 | end |
| 519 | if or e3 112 100 102 e4 103 97 116 101 |
| 520 | ret true |
| 521 | end |
| 522 | if or e3 120 109 108 e3 112 117 98 |
| 523 | ret true |
| 524 | end |
| 525 | if or e3 115 105 103 e3 116 101 120 |
| 526 | ret true |
| 527 | end |
| 528 | if or e3 105 110 105 e3 99 102 103 |
| 529 | ret true |
| 530 | end |
| 531 | if or e3 112 101 109 e4 116 111 109 108 |
| 532 | ret true |
| 533 | end |
| 534 | ret false |
| 535 | end |
| 536 | |
| 537 | note ---- classification of one regular file at path ---- |
| 538 | |
| 539 | fn readhd to bool |
| 540 | put hlen 0 0 |
| 541 | fd = fopen path 0 get plen 0 0 0 |
| 542 | if lt fd 0 |
| 543 | ret false |
| 544 | end |
| 545 | r = read int fd head 0 len head |
| 546 | ok = ge r 0 |
| 547 | if gt r 0 |
| 548 | put hlen 0 ulong r |
| 549 | end |
| 550 | r = fclose int fd |
| 551 | ret ok |
| 552 | end |
| 553 | |
| 554 | note is head[i-1] (or the start) and head[i+m] (or the end) whitespace |
| 555 | fn alone i ulong m ulong to bool |
| 556 | h = get hlen 0 |
| 557 | if gt i 0 |
| 558 | c = get head sub i 1 |
| 559 | if and ne c 32 and ne c 9 ne c 10 |
| 560 | ret false |
| 561 | end |
| 562 | end |
| 563 | e = add i m |
| 564 | if lt e h |
| 565 | c = get head e |
| 566 | if and ne c 32 and ne c 9 ne c 10 |
| 567 | ret false |
| 568 | end |
| 569 | end |
| 570 | ret true |
| 571 | end |
| 572 | |
| 573 | note the needle as a whole word anywhere in the head |
| 574 | fn token to bool |
| 575 | h = get hlen 0 |
| 576 | m = get ndln 0 |
| 577 | if lt h m |
| 578 | ret false |
| 579 | end |
| 580 | e = sub h m |
| 581 | i = ulong 0 |
| 582 | while le i e bound 4097 |
| 583 | j = ulong 0 |
| 584 | while lt j m bound 32 |
| 585 | if ne get head add i j get ndl j |
| 586 | break |
| 587 | end |
| 588 | j = add j 1 |
| 589 | end |
| 590 | if eq j m |
| 591 | if alone i m |
| 592 | ret true |
| 593 | end |
| 594 | end |
| 595 | i = add i 1 |
| 596 | end |
| 597 | ret false |
| 598 | end |
| 599 | |
| 600 | fn classif to ulong |
| 601 | if not readhd |
| 602 | ret 21 |
| 603 | end |
| 604 | b = isbin |
| 605 | if ne b 0 |
| 606 | ret b |
| 607 | end |
| 608 | if or e1 99 e1 104 |
| 609 | ret 1 |
| 610 | end |
| 611 | if or e2 99 117 or e3 99 117 104 or e3 99 112 112 or e2 99 99 e3 104 112 112 |
| 612 | ret 1 |
| 613 | end |
| 614 | if e2 114 115 |
| 615 | ret 2 |
| 616 | end |
| 617 | if e2 112 121 |
| 618 | ret 3 |
| 619 | end |
| 620 | if or e2 115 104 e4 98 97 115 104 |
| 621 | if interp |
| 622 | ret 16 |
| 623 | end |
| 624 | ret 4 |
| 625 | end |
| 626 | if e3 111 115 99 |
| 627 | ret 5 |
| 628 | end |
| 629 | if or e3 104 101 120 or e4 104 101 120 49 or e1 115 or e1 83 or e2 115 50 e3 97 115 109 |
| 630 | ret 6 |
| 631 | end |
| 632 | if ismake |
| 633 | ret 20 |
| 634 | end |
| 635 | if isshb |
| 636 | ret 11 |
| 637 | end |
| 638 | ldinc |
| 639 | if found |
| 640 | ret 11 |
| 641 | end |
| 642 | ldfnm |
| 643 | if found |
| 644 | ret 11 |
| 645 | end |
| 646 | if e2 111 109 |
| 647 | ldexe |
| 648 | if token |
| 649 | ret 12 |
| 650 | end |
| 651 | ret 0 |
| 652 | end |
| 653 | if isdoc |
| 654 | ret 9 |
| 655 | end |
| 656 | ret 10 |
| 657 | end |
| 658 | |
| 659 | note assembly text stays source under any manifest; .hex/.hex1 may be declared data |
| 660 | fn isasm to bool |
| 661 | if or e1 115 e1 83 |
| 662 | ret true |
| 663 | end |
| 664 | ret or e2 115 50 e3 97 115 109 |
| 665 | end |
| 666 | |
| 667 | fn issrc c ulong to bool |
| 668 | if or eq c 1 or eq c 2 or eq c 3 or eq c 4 eq c 5 |
| 669 | ret true |
| 670 | end |
| 671 | if or eq c 11 or eq c 12 or eq c 16 eq c 20 |
| 672 | ret true |
| 673 | end |
| 674 | if eq c 6 |
| 675 | ret isasm |
| 676 | end |
| 677 | ret false |
| 678 | end |
| 679 | |
| 680 | note ---- manifest: lines "data P", "generated P", "external P", "skip P" ---- |
| 681 | |
| 682 | fn pdat s ulong to bool |
| 683 | if gt add s len tdat get alwn 0 |
| 684 | ret false |
| 685 | end |
| 686 | for i ulong len tdat |
| 687 | if ne get alw add s i get tdat i |
| 688 | ret false |
| 689 | end |
| 690 | end |
| 691 | ret true |
| 692 | end |
| 693 | |
| 694 | fn pgen s ulong to bool |
| 695 | if gt add s len tgen get alwn 0 |
| 696 | ret false |
| 697 | end |
| 698 | for i ulong len tgen |
| 699 | if ne get alw add s i get tgen i |
| 700 | ret false |
| 701 | end |
| 702 | end |
| 703 | ret true |
| 704 | end |
| 705 | |
| 706 | fn pext s ulong to bool |
| 707 | if gt add s len text_ get alwn 0 |
| 708 | ret false |
| 709 | end |
| 710 | for i ulong len text_ |
| 711 | if ne get alw add s i get text_ i |
| 712 | ret false |
| 713 | end |
| 714 | end |
| 715 | ret true |
| 716 | end |
| 717 | |
| 718 | fn pskp s ulong to bool |
| 719 | if gt add s len tskp get alwn 0 |
| 720 | ret false |
| 721 | end |
| 722 | for i ulong len tskp |
| 723 | if ne get alw add s i get tskp i |
| 724 | ret false |
| 725 | end |
| 726 | end |
| 727 | ret true |
| 728 | end |
| 729 | |
| 730 | fn kindof s ulong to ulong |
| 731 | if pdat s |
| 732 | put pst 0 add s len tdat |
| 733 | ret 1 |
| 734 | end |
| 735 | if pgen s |
| 736 | put pst 0 add s len tgen |
| 737 | ret 2 |
| 738 | end |
| 739 | if pext s |
| 740 | put pst 0 add s len text_ |
| 741 | ret 3 |
| 742 | end |
| 743 | if pskp s |
| 744 | put pst 0 add s len tskp |
| 745 | ret 4 |
| 746 | end |
| 747 | ret 0 |
| 748 | end |
| 749 | |
| 750 | fn prefix p ulong m ulong to bool |
| 751 | if eq m 0 |
| 752 | ret false |
| 753 | end |
| 754 | rl = add get rootl 0 1 |
| 755 | if gt add rl m get plen 0 |
| 756 | ret false |
| 757 | end |
| 758 | for i ulong m |
| 759 | if ne get alw add p i get path add rl i |
| 760 | ret false |
| 761 | end |
| 762 | end |
| 763 | ret true |
| 764 | end |
| 765 | |
| 766 | fn allowk to ulong |
| 767 | n = get alwn 0 |
| 768 | s = ulong 0 |
| 769 | while lt s n bound 100000 |
| 770 | e = s |
| 771 | while lt e n bound 65536 |
| 772 | if eq get alw e 10 |
| 773 | break |
| 774 | end |
| 775 | e = add e 1 |
| 776 | end |
| 777 | k = kindof s |
| 778 | if ne k 0 |
| 779 | p = get pst 0 |
| 780 | if prefix p sub e p |
| 781 | ret k |
| 782 | end |
| 783 | end |
| 784 | s = add e 1 |
| 785 | end |
| 786 | ret 0 |
| 787 | end |
| 788 | |
| 789 | note ---- directory stack of paths: bytes then a two-byte length trailer ---- |
| 790 | |
| 791 | fn push to void |
| 792 | t = get stkt 0 |
| 793 | n = get plen 0 |
| 794 | if gt add t add n 2 len stk |
| 795 | trap 3 |
| 796 | end |
| 797 | for i ulong n |
| 798 | put stk add t i get path i |
| 799 | end |
| 800 | put stk add t n uchar rem n 256 |
| 801 | put stk add t add n 1 uchar div n 256 |
| 802 | put stkt 0 add t add n 2 |
| 803 | end |
| 804 | |
| 805 | fn pop to bool |
| 806 | t = get stkt 0 |
| 807 | if lt t 2 |
| 808 | ret false |
| 809 | end |
| 810 | n = add ulong get stk sub t 2 mul 256 ulong get stk sub t 1 |
| 811 | b = sub sub t 2 n |
| 812 | for i ulong n |
| 813 | put path i get stk add b i |
| 814 | end |
| 815 | put plen 0 n |
| 816 | put stkt 0 b |
| 817 | ret true |
| 818 | end |
| 819 | |
| 820 | note ---- walking ---- |
| 821 | |
| 822 | fn file to void |
| 823 | a = allowk |
| 824 | if eq a 4 |
| 825 | put cnt 19 add get cnt 19 1 |
| 826 | ret |
| 827 | end |
| 828 | c = classif |
| 829 | if eq a 3 |
| 830 | report 15 |
| 831 | ret |
| 832 | end |
| 833 | if ne a 0 |
| 834 | if issrc c |
| 835 | report 18 |
| 836 | ret |
| 837 | end |
| 838 | if eq c 21 |
| 839 | report 21 |
| 840 | ret |
| 841 | end |
| 842 | if eq a 1 |
| 843 | if or eq c 7 eq c 8 |
| 844 | report 18 |
| 845 | ret |
| 846 | end |
| 847 | report 13 |
| 848 | ret |
| 849 | end |
| 850 | if eq c 8 |
| 851 | report 18 |
| 852 | ret |
| 853 | end |
| 854 | report 14 |
| 855 | ret |
| 856 | end |
| 857 | report c |
| 858 | end |
| 859 | |
| 860 | fn isgit k ulong m ulong to bool |
| 861 | if ne m 4 |
| 862 | ret false |
| 863 | end |
| 864 | if ne get dbuf k 46 |
| 865 | ret false |
| 866 | end |
| 867 | if ne get dbuf add k 1 103 |
| 868 | ret false |
| 869 | end |
| 870 | if ne get dbuf add k 2 105 |
| 871 | ret false |
| 872 | end |
| 873 | ret eq get dbuf add k 3 116 |
| 874 | end |
| 875 | |
| 876 | fn entry o ulong ty uchar dl ulong to void |
| 877 | k = add o 19 |
| 878 | m = ulong 0 |
| 879 | while ne get dbuf add k m 0 bound 256 |
| 880 | m = add m 1 |
| 881 | end |
| 882 | if eq m 1 |
| 883 | if eq get dbuf k 46 |
| 884 | ret |
| 885 | end |
| 886 | end |
| 887 | if eq m 2 |
| 888 | if and eq get dbuf k 46 eq get dbuf add k 1 46 |
| 889 | ret |
| 890 | end |
| 891 | end |
| 892 | if gt add dl add m 1 4095 |
| 893 | report 21 |
| 894 | ret |
| 895 | end |
| 896 | put path dl 47 |
| 897 | for i ulong m |
| 898 | put path add dl add 1 i get dbuf add k i |
| 899 | end |
| 900 | put plen 0 add dl add m 1 |
| 901 | if isgit k m |
| 902 | ret |
| 903 | end |
| 904 | if eq ty 4 |
| 905 | if eq allowk 4 |
| 906 | put cnt 19 add get cnt 19 1 |
| 907 | ret |
| 908 | end |
| 909 | push |
| 910 | ret |
| 911 | end |
| 912 | if eq ty 10 |
| 913 | report 17 |
| 914 | ret |
| 915 | end |
| 916 | if ne ty 8 |
| 917 | report 10 |
| 918 | ret |
| 919 | end |
| 920 | file |
| 921 | end |
| 922 | |
| 923 | fn reclen o ulong to ulong |
| 924 | lo = ulong get dbuf add o 16 |
| 925 | hi = ulong get dbuf add o 17 |
| 926 | ret add lo mul 256 hi |
| 927 | end |
| 928 | |
| 929 | fn scandir to void |
| 930 | dl = get plen 0 |
| 931 | fd = fopen path 0 dl 16384 0 |
| 932 | if lt fd 0 |
| 933 | report 21 |
| 934 | ret |
| 935 | end |
| 936 | while true bound 100000 |
| 937 | r = getdnts int fd dbuf 0 len dbuf |
| 938 | if lt r 0 |
| 939 | note entry changes plen; the error belongs to this directory, not its last child. |
| 940 | put plen 0 dl |
| 941 | report 21 |
| 942 | break |
| 943 | end |
| 944 | if eq r 0 |
| 945 | break |
| 946 | end |
| 947 | o = ulong 0 |
| 948 | while lt o ulong r bound 65536 |
| 949 | rl = reclen o |
| 950 | ty = get dbuf add o 18 |
| 951 | entry o ty dl |
| 952 | o = add o rl |
| 953 | end |
| 954 | end |
| 955 | r = fclose int fd |
| 956 | end |
| 957 | |
| 958 | fn summary to void |
| 959 | for k ulong 22 |
| 960 | r = write 1 thash 0 2 |
| 961 | wcat k |
| 962 | r = write 1 tsp 0 1 |
| 963 | wnum get cnt k |
| 964 | wnl |
| 965 | end |
| 966 | end |
| 967 | |
| 968 | fn outst to ulong |
| 969 | s = add get cnt 1 get cnt 2 |
| 970 | s = add s get cnt 3 |
| 971 | s = add s get cnt 4 |
| 972 | s = add s get cnt 5 |
| 973 | s = add s get cnt 6 |
| 974 | s = add s get cnt 11 |
| 975 | s = add s get cnt 12 |
| 976 | s = add s get cnt 16 |
| 977 | s = add s get cnt 18 |
| 978 | ret add s get cnt 20 |
| 979 | end |
| 980 | |
| 981 | fn unknown to ulong |
| 982 | s = add get cnt 7 get cnt 8 |
| 983 | s = add s get cnt 10 |
| 984 | ret add s get cnt 21 |
| 985 | end |
| 986 | |
| 987 | fn main to int |
| 988 | if lt argcnt 2 |
| 989 | r = write 2 tuse 0 len tuse |
| 990 | ret 64 |
| 991 | end |
| 992 | n = argread 1 path 0 4095 |
| 993 | if lt n 1 |
| 994 | r = write 2 tuse 0 len tuse |
| 995 | ret 64 |
| 996 | end |
| 997 | while and gt n 1 eq get path sub ulong n 1 47 bound 4095 |
| 998 | n = sub n 1 |
| 999 | end |
| 1000 | put plen 0 ulong n |
| 1001 | put rootl 0 ulong n |
| 1002 | if ge argcnt 3 |
| 1003 | n = argread 2 name 0 255 |
| 1004 | if eq n long len trel |
| 1005 | ok = true |
| 1006 | for i ulong len trel |
| 1007 | if ne get name i get trel i |
| 1008 | ok = false |
| 1009 | end |
| 1010 | end |
| 1011 | if ok |
| 1012 | put mode 0 1 |
| 1013 | end |
| 1014 | end |
| 1015 | end |
| 1016 | if ge argcnt 4 |
| 1017 | n = argread 3 name 0 255 |
| 1018 | if lt n 1 |
| 1019 | r = write 2 terr 0 len terr |
| 1020 | ret 65 |
| 1021 | end |
| 1022 | fd = fopen name 0 ulong n 0 0 |
| 1023 | if lt fd 0 |
| 1024 | r = write 2 terr 0 len terr |
| 1025 | ret 65 |
| 1026 | end |
| 1027 | r = read int fd alw 0 65535 |
| 1028 | if gt r 0 |
| 1029 | put alwn 0 ulong r |
| 1030 | end |
| 1031 | if ge r 65535 |
| 1032 | r = write 2 tbig 0 len tbig |
| 1033 | ret 65 |
| 1034 | end |
| 1035 | r = fclose int fd |
| 1036 | end |
| 1037 | push |
| 1038 | while pop bound 999999 |
| 1039 | scandir |
| 1040 | end |
| 1041 | summary |
| 1042 | r = write 1 thash 0 2 |
| 1043 | r = write 1 tmode 0 len tmode |
| 1044 | wnum get mode 0 |
| 1045 | wnl |
| 1046 | r = write 1 thash 0 2 |
| 1047 | r = write 1 tout 0 len tout |
| 1048 | wnum outst |
| 1049 | wnl |
| 1050 | r = write 1 thash 0 2 |
| 1051 | r = write 1 tunk 0 len tunk |
| 1052 | wnum unknown |
| 1053 | wnl |
| 1054 | if eq get mode 0 1 |
| 1055 | if gt outst 0 |
| 1056 | ret 1 |
| 1057 | end |
| 1058 | if gt unknown 0 |
| 1059 | ret 2 |
| 1060 | end |
| 1061 | end |
| 1062 | ret 0 |
| 1063 | end |