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 / core / sovereign-core / om / crumb-coverage / crumb-coverage.om
| 1 | note om/crumb-coverage/crumb-coverage.om: .crumb coverage of a git tree (DRA-95). |
| 2 | note Usage, from the repository root: git ls-files -z > list; crumb-coverage < list |
| 3 | note Reads the NUL-separated tracked paths (git index order, checked strictly increasing) and counts: |
| 4 | note tracked_dirs the root plus every directory that is an ancestor of a tracked path; |
| 5 | note crumb_dirs tracked paths named .crumb (one per directory); |
| 6 | note enforced_dirs crumb directories with at least one invariant whose check resolves. |
| 7 | note Each .crumb is parsed as strict JSON (om/vendor/json.om). Every string of its top-level "invariants" |
| 8 | note array is one invariant; its check is the text after "Check: ". A check resolves when it is |
| 9 | note cargo test -p CRATE --test T -- --exact NAME and crates/CRATE/tests/T.rs contains "fn LEAF(", or |
| 10 | note cargo test -p CRATE --lib -- --exact M::tests::LEAF and crates/CRATE/src/M.rs (lib.rs when no M) |
| 11 | note contains "fn LEAF(", or |
| 12 | note [sh|bash] PATH ... and PATH is a repository-relative regular file. |
| 13 | note LEAF is the last :: segment of NAME; "tests" segments are dropped from M. Unresolved invariants are |
| 14 | note printed. Exit 0 all resolve, 1 some do not, 2 usage, 3 io, 4 input or crumb JSON refused. |
| 15 | note Build: { printf 'om2\n'; cat om/vendor/json.om om/crumb-coverage/crumb-coverage.om; } | "$AIEN_OMC" > cc |
| 16 | |
| 17 | const ccx ulong 999999999 |
| 18 | |
| 19 | note gst slots |
| 20 | const kop ulong 0 |
| 21 | const kn ulong 1 |
| 22 | const kdirs ulong 2 |
| 23 | const kcr ulong 3 |
| 24 | const kenf ulong 4 |
| 25 | const kinv ulong 5 |
| 26 | const kres ulong 6 |
| 27 | const kunr ulong 7 |
| 28 | const kfsz ulong 8 |
| 29 | const kpn ulong 9 |
| 30 | const kndl ulong 10 |
| 31 | const kci ulong 11 |
| 32 | const kcrr ulong 12 |
| 33 | |
| 34 | global gin uchar 8388608 |
| 35 | global gco ulong 8192 |
| 36 | global gcl ulong 8192 |
| 37 | global gpth uchar 4096 |
| 38 | global gst ulong 16 |
| 39 | global gob uchar 65536 |
| 40 | global gstb uchar 128 |
| 41 | global gdg uchar 24 |
| 42 | global ginv uchar 8192 |
| 43 | global gnd uchar 512 |
| 44 | global gfil uchar 983040 |
| 45 | |
| 46 | text tusage "usage: git ls-files -z | crumb-coverage (no arguments; run from the repository root)" |
| 47 | text tio "io" |
| 48 | text tbig "input-too-large" |
| 49 | text tpath "bad-path" |
| 50 | text tunsort "paths-not-in-git-order" |
| 51 | text tmany "too-many-crumbs" |
| 52 | text tjson "crumb-json" |
| 53 | text tinvarr "invariants-not-array-of-strings" |
| 54 | text tlong "name-too-long" |
| 55 | text tref "crumb-coverage refused " |
| 56 | text tcrumb ".crumb" |
| 57 | text tinv "invariants" |
| 58 | text tchk "Check: " |
| 59 | text tcargo "cargo test -p " |
| 60 | text ttest "--test " |
| 61 | text tlib "--lib" |
| 62 | text tex " -- --exact " |
| 63 | text tcc "::" |
| 64 | text tsh "sh" |
| 65 | text tbash "bash" |
| 66 | text tcrates "crates/" |
| 67 | text ttests "tests/" |
| 68 | text ttestw "tests" |
| 69 | text tsrcd "src/" |
| 70 | text tlibw "lib" |
| 71 | text trs ".rs" |
| 72 | text tfn "fn " |
| 73 | text thead "crumb-coverage " |
| 74 | text o1 "tracked_dirs" |
| 75 | text o2 "crumb_dirs" |
| 76 | text o3 "enforced_dirs" |
| 77 | text o4 "invariants" |
| 78 | text o5 "resolved" |
| 79 | text o6 "unresolved" |
| 80 | text tcrl "crumb " |
| 81 | text tunr "unresolved " |
| 82 | |
| 83 | note ======== output ======== |
| 84 | |
| 85 | fn cc_dec v ulong to ulong |
| 86 | n = ulong 0 |
| 87 | x = v |
| 88 | while true bound 25 |
| 89 | put gdg n add 48 uchar rem x 10 |
| 90 | n = add n 1 |
| 91 | x = div x 10 |
| 92 | if eq x 0 |
| 93 | break |
| 94 | end |
| 95 | end |
| 96 | ret n |
| 97 | end |
| 98 | |
| 99 | note cc_oflush: a pass writes at least one byte of at most 65536, so 65536 passes suffice |
| 100 | fn cc_oflush fd int to void |
| 101 | o = ulong 0 |
| 102 | m = get gst kop |
| 103 | while lt o m bound 65536 |
| 104 | w = write fd gob o sub m o |
| 105 | if le w 0 |
| 106 | exit 3 |
| 107 | end |
| 108 | o = add o ulong w |
| 109 | end |
| 110 | put gst kop 0 |
| 111 | end |
| 112 | |
| 113 | fn cc_ob c uchar to void |
| 114 | p = get gst kop |
| 115 | if ge p len gob |
| 116 | cc_oflush 1 |
| 117 | p = ulong 0 |
| 118 | end |
| 119 | put gob p c |
| 120 | put gst kop add p 1 |
| 121 | end |
| 122 | |
| 123 | fn cc_otx t view uchar * to void |
| 124 | for i ulong len t |
| 125 | cc_ob get t i |
| 126 | end |
| 127 | end |
| 128 | |
| 129 | fn cc_ou v ulong to void |
| 130 | n = cc_dec v |
| 131 | for i ulong n |
| 132 | cc_ob get gdg sub sub n i 1 |
| 133 | end |
| 134 | end |
| 135 | |
| 136 | fn cc_kv t view uchar * v ulong to void |
| 137 | cc_otx t |
| 138 | cc_ob 32 |
| 139 | cc_ou v |
| 140 | end |
| 141 | |
| 142 | fn cc_die c ulong t view uchar * to void |
| 143 | put gst kop 0 |
| 144 | cc_otx tref |
| 145 | cc_ou c |
| 146 | cc_ob 32 |
| 147 | cc_otx t |
| 148 | cc_ob 10 |
| 149 | cc_oflush 2 |
| 150 | exit int c |
| 151 | end |
| 152 | |
| 153 | fn cc_ogin o ulong n ulong to void |
| 154 | for i ulong n |
| 155 | cc_ob get gin add o i |
| 156 | end |
| 157 | end |
| 158 | |
| 159 | fn cc_oinv n ulong to void |
| 160 | for i ulong n |
| 161 | cc_ob get ginv i |
| 162 | end |
| 163 | end |
| 164 | |
| 165 | note ======== input: the NUL-separated path list ======== |
| 166 | |
| 167 | note cc_input: every pass adds at least one byte to gin (8388608 bytes), and a full gin is refused |
| 168 | fn cc_input to void |
| 169 | o = ulong 0 |
| 170 | for it ulong 8388609 |
| 171 | if ge o len gin |
| 172 | cc_die 4 tbig |
| 173 | end |
| 174 | r = read 0 gin o sub len gin o |
| 175 | if lt r 0 |
| 176 | cc_die 3 tio |
| 177 | end |
| 178 | if eq r 0 |
| 179 | break |
| 180 | end |
| 181 | o = add o ulong r |
| 182 | end |
| 183 | put gst kn o |
| 184 | end |
| 185 | |
| 186 | note cc_nul: the NUL ending the path that starts at s (paths are at most 4096 bytes) |
| 187 | fn cc_nul s ulong n ulong to ulong |
| 188 | for k ulong 4097 |
| 189 | p = add s k |
| 190 | if ge p n |
| 191 | cc_die 4 tpath |
| 192 | end |
| 193 | if eq get gin p 0 |
| 194 | ret p |
| 195 | end |
| 196 | end |
| 197 | cc_die 4 tpath |
| 198 | ret 0 |
| 199 | end |
| 200 | |
| 201 | fn cc_common s ulong l ulong ps ulong pl ulong to ulong |
| 202 | m = l |
| 203 | if lt pl m |
| 204 | m = pl |
| 205 | end |
| 206 | for i ulong m |
| 207 | if ne get gin add s i get gin add ps i |
| 208 | ret i |
| 209 | end |
| 210 | end |
| 211 | ret m |
| 212 | end |
| 213 | |
| 214 | note cc_order: the path at s must sort strictly after the previous one (git index order, unsigned bytes) |
| 215 | fn cc_order s ulong l ulong ps ulong pl ulong c ulong to void |
| 216 | if eq c l |
| 217 | cc_die 4 tunsort |
| 218 | end |
| 219 | if lt c pl |
| 220 | if lt get gin add s c get gin add ps c |
| 221 | cc_die 4 tunsort |
| 222 | end |
| 223 | end |
| 224 | end |
| 225 | |
| 226 | fn cc_iscrumb s ulong l ulong to void |
| 227 | t = len tcrumb |
| 228 | if lt l t |
| 229 | ret |
| 230 | end |
| 231 | b = sub add s l t |
| 232 | for i ulong t |
| 233 | if ne get gin add b i get tcrumb i |
| 234 | ret |
| 235 | end |
| 236 | end |
| 237 | if gt l t |
| 238 | if ne get gin sub b 1 47 |
| 239 | ret |
| 240 | end |
| 241 | end |
| 242 | k = get gst kcr |
| 243 | if ge k len gco |
| 244 | cc_die 4 tmany |
| 245 | end |
| 246 | put gco k s |
| 247 | put gcl k l |
| 248 | put gst kcr add k 1 |
| 249 | end |
| 250 | |
| 251 | note cc_path: a directory ending at a '/' at index i is new unless the previous path shares bytes 0..i; |
| 252 | note the subtree of a directory is contiguous in sorted order, so each directory is counted once. |
| 253 | fn cc_path s ulong l ulong ps ulong pl ulong hp bool to void |
| 254 | if eq l 0 |
| 255 | cc_die 4 tpath |
| 256 | end |
| 257 | if eq get gin s 47 |
| 258 | cc_die 4 tpath |
| 259 | end |
| 260 | c = ulong 0 |
| 261 | if hp |
| 262 | c = cc_common s l ps pl |
| 263 | cc_order s l ps pl c |
| 264 | end |
| 265 | for i ulong l |
| 266 | if ge i c |
| 267 | if eq get gin add s i 47 |
| 268 | put gst kdirs add get gst kdirs 1 |
| 269 | end |
| 270 | end |
| 271 | end |
| 272 | cc_iscrumb s l |
| 273 | end |
| 274 | |
| 275 | note cc_scan: every path is at least one byte plus its NUL, so at most 4194304 paths |
| 276 | fn cc_scan to void |
| 277 | n = get gst kn |
| 278 | if gt n 0 |
| 279 | put gst kdirs 1 |
| 280 | end |
| 281 | s = ulong 0 |
| 282 | ps = ulong 0 |
| 283 | pl = ulong 0 |
| 284 | hp = false |
| 285 | for it ulong 4194305 |
| 286 | if ge s n |
| 287 | break |
| 288 | end |
| 289 | e = cc_nul s n |
| 290 | l = sub e s |
| 291 | cc_path s l ps pl hp |
| 292 | ps = s |
| 293 | pl = l |
| 294 | hp = true |
| 295 | s = add e 1 |
| 296 | end |
| 297 | end |
| 298 | |
| 299 | note ======== files ======== |
| 300 | |
| 301 | fn cc_le64 o ulong to ulong |
| 302 | v = ulong 0 |
| 303 | for i ulong 8 |
| 304 | v = or shl v 8 ulong get gstb add o sub 7 i |
| 305 | end |
| 306 | ret v |
| 307 | end |
| 308 | |
| 309 | fn cc_close fd long to void |
| 310 | r = fclose int fd |
| 311 | if ne r 0 |
| 312 | cc_die 3 tio |
| 313 | end |
| 314 | end |
| 315 | |
| 316 | note cc_try: open gpth[0 .. kpn) read-only without following a final symlink; a descriptor of a regular file |
| 317 | note (size in kfsz) or -1 when the path is missing or not a regular file |
| 318 | fn cc_try to long |
| 319 | fd = fopen gpth 0 get gst kpn 557056 0 |
| 320 | if lt fd 0 |
| 321 | ret long -1 |
| 322 | end |
| 323 | r = fstat int fd gstb 0 128 |
| 324 | if ne r 0 |
| 325 | cc_die 3 tio |
| 326 | end |
| 327 | md = or ulong get gstb 16 shl ulong get gstb 17 8 |
| 328 | if ne and md 61440 32768 |
| 329 | cc_close fd |
| 330 | ret long -1 |
| 331 | end |
| 332 | put gst kfsz cc_le64 48 |
| 333 | ret fd |
| 334 | end |
| 335 | |
| 336 | fn cc_rdfil fd long to ulong |
| 337 | sz = get gst kfsz |
| 338 | if gt sz len gfil |
| 339 | cc_die 3 tbig |
| 340 | end |
| 341 | o = ulong 0 |
| 342 | while lt o sz bound 983040 |
| 343 | r = pread int fd gfil o sub sz o long o |
| 344 | if le r 0 |
| 345 | cc_die 3 tio |
| 346 | end |
| 347 | o = add o ulong r |
| 348 | end |
| 349 | cc_close fd |
| 350 | ret sz |
| 351 | end |
| 352 | |
| 353 | fn cc_rdsrc fd long b edit uchar * sz ulong to void |
| 354 | o = ulong 0 |
| 355 | while lt o sz bound 983040 |
| 356 | r = pread int fd b o sub sz o long o |
| 357 | if le r 0 |
| 358 | cc_die 3 tio |
| 359 | end |
| 360 | o = add o ulong r |
| 361 | end |
| 362 | cc_close fd |
| 363 | end |
| 364 | |
| 365 | note ======== gpth and the needle ======== |
| 366 | |
| 367 | fn cc_preset to void |
| 368 | put gst kpn 0 |
| 369 | end |
| 370 | |
| 371 | fn cc_pb c uchar to void |
| 372 | p = get gst kpn |
| 373 | if ge p sub len gpth 1 |
| 374 | cc_die 4 tlong |
| 375 | end |
| 376 | put gpth p c |
| 377 | put gst kpn add p 1 |
| 378 | end |
| 379 | |
| 380 | fn cc_pt t view uchar * to void |
| 381 | for i ulong len t |
| 382 | cc_pb get t i |
| 383 | end |
| 384 | end |
| 385 | |
| 386 | fn cc_pi a ulong b ulong to void |
| 387 | if gt a b |
| 388 | cc_die 4 tpath |
| 389 | end |
| 390 | for i ulong sub b a |
| 391 | cc_pb get ginv add a i |
| 392 | end |
| 393 | end |
| 394 | |
| 395 | fn cc_pset s ulong l ulong to void |
| 396 | cc_preset |
| 397 | for i ulong l |
| 398 | cc_pb get gin add s i |
| 399 | end |
| 400 | end |
| 401 | |
| 402 | fn cc_nb c uchar to void |
| 403 | p = get gst kndl |
| 404 | if ge p len gnd |
| 405 | cc_die 4 tlong |
| 406 | end |
| 407 | put gnd p c |
| 408 | put gst kndl add p 1 |
| 409 | end |
| 410 | |
| 411 | note ======== the invariant text in ginv ======== |
| 412 | |
| 413 | note cc_at: ginv[p ..] starts with t, all within ginv[0 .. n) |
| 414 | fn cc_at p ulong n ulong t view uchar * to bool |
| 415 | m = len t |
| 416 | if gt p n |
| 417 | ret false |
| 418 | end |
| 419 | if gt m sub n p |
| 420 | ret false |
| 421 | end |
| 422 | for i ulong m |
| 423 | if ne get ginv add p i get t i |
| 424 | ret false |
| 425 | end |
| 426 | end |
| 427 | ret true |
| 428 | end |
| 429 | |
| 430 | fn cc_find n ulong from ulong t view uchar * to ulong |
| 431 | m = len t |
| 432 | if gt m n |
| 433 | ret ccx |
| 434 | end |
| 435 | if gt from sub n m |
| 436 | ret ccx |
| 437 | end |
| 438 | for i ulong add sub sub n m from 1 |
| 439 | if cc_at add from i n t |
| 440 | ret add from i |
| 441 | end |
| 442 | end |
| 443 | ret ccx |
| 444 | end |
| 445 | |
| 446 | note cc_word: the end of the space-delimited word starting at p |
| 447 | fn cc_word n ulong p ulong to ulong |
| 448 | if ge p n |
| 449 | ret n |
| 450 | end |
| 451 | for i ulong sub n p |
| 452 | if eq get ginv add p i 32 |
| 453 | ret add p i |
| 454 | end |
| 455 | end |
| 456 | ret n |
| 457 | end |
| 458 | |
| 459 | fn cc_weq p ulong w ulong t view uchar * to bool |
| 460 | if ne sub w p len t |
| 461 | ret false |
| 462 | end |
| 463 | ret cc_at p w t |
| 464 | end |
| 465 | |
| 466 | note cc_leaf: the index after the last "::" in ginv[a .. b), or a |
| 467 | fn cc_leaf a ulong b ulong to ulong |
| 468 | r = a |
| 469 | for i ulong sub b a |
| 470 | if cc_at add a i b tcc |
| 471 | r = add add a i 2 |
| 472 | end |
| 473 | end |
| 474 | ret r |
| 475 | end |
| 476 | |
| 477 | note cc_mods: append src/M.rs for the module path ginv[a .. ls - 2), "tests" segments dropped; src/lib.rs if none |
| 478 | fn cc_mods a ulong ls ulong to void |
| 479 | cc_pt tsrcd |
| 480 | nseg = ulong 0 |
| 481 | if gt ls a |
| 482 | e = sub ls 2 |
| 483 | s = a |
| 484 | while le s e bound 4096 |
| 485 | x = cc_find e s tcc |
| 486 | if eq x ccx |
| 487 | x = e |
| 488 | end |
| 489 | if not cc_weq s x ttestw |
| 490 | if gt nseg 0 |
| 491 | cc_pb 47 |
| 492 | end |
| 493 | cc_pi s x |
| 494 | nseg = add nseg 1 |
| 495 | end |
| 496 | s = add x 2 |
| 497 | end |
| 498 | end |
| 499 | if eq nseg 0 |
| 500 | cc_pt tlibw |
| 501 | end |
| 502 | cc_pt trs |
| 503 | end |
| 504 | |
| 505 | fn cc_fat p ulong m ulong to bool |
| 506 | for k ulong m |
| 507 | if ne get gfil add p k get gnd k |
| 508 | ret false |
| 509 | end |
| 510 | end |
| 511 | ret true |
| 512 | end |
| 513 | |
| 514 | note cc_hasfn: the file at gpth contains the needle gnd[0 .. kndl) |
| 515 | fn cc_hasfn to bool |
| 516 | fd = cc_try |
| 517 | if lt fd 0 |
| 518 | ret false |
| 519 | end |
| 520 | sz = cc_rdfil fd |
| 521 | m = get gst kndl |
| 522 | if gt m sz |
| 523 | ret false |
| 524 | end |
| 525 | for i ulong add sub sz m 1 |
| 526 | if cc_fat i m |
| 527 | ret true |
| 528 | end |
| 529 | end |
| 530 | ret false |
| 531 | end |
| 532 | |
| 533 | note cc_name: q is past the target selector; finds " -- --exact NAME", builds the source path for lib tests |
| 534 | note and the needle "fn LEAF(", then searches the file |
| 535 | fn cc_name n ulong q ulong lib bool to bool |
| 536 | x = cc_find n q tex |
| 537 | if eq x ccx |
| 538 | ret false |
| 539 | end |
| 540 | a = add x len tex |
| 541 | b = cc_word n a |
| 542 | if eq b a |
| 543 | ret false |
| 544 | end |
| 545 | ls = cc_leaf a b |
| 546 | if eq ls b |
| 547 | ret false |
| 548 | end |
| 549 | if lib |
| 550 | cc_mods a ls |
| 551 | end |
| 552 | put gst kndl 0 |
| 553 | for i ulong len tfn |
| 554 | cc_nb get tfn i |
| 555 | end |
| 556 | for i ulong sub b ls |
| 557 | cc_nb get ginv add ls i |
| 558 | end |
| 559 | cc_nb 40 |
| 560 | ret cc_hasfn |
| 561 | end |
| 562 | |
| 563 | fn cc_cargo n ulong p ulong to bool |
| 564 | w = cc_word n p |
| 565 | if or eq w p ge w n |
| 566 | ret false |
| 567 | end |
| 568 | cc_preset |
| 569 | cc_pt tcrates |
| 570 | cc_pi p w |
| 571 | cc_pb 47 |
| 572 | q = add w 1 |
| 573 | if cc_at q n ttest |
| 574 | a = add q len ttest |
| 575 | b = cc_word n a |
| 576 | if eq b a |
| 577 | ret false |
| 578 | end |
| 579 | cc_pt ttests |
| 580 | cc_pi a b |
| 581 | cc_pt trs |
| 582 | ret cc_name n b false |
| 583 | end |
| 584 | if cc_at q n tlib |
| 585 | ret cc_name n add q len tlib true |
| 586 | end |
| 587 | ret false |
| 588 | end |
| 589 | |
| 590 | fn cc_file n ulong p ulong to bool |
| 591 | q = p |
| 592 | w = cc_word n q |
| 593 | if or cc_weq q w tsh cc_weq q w tbash |
| 594 | q = add w 1 |
| 595 | w = cc_word n q |
| 596 | end |
| 597 | if ge q w |
| 598 | ret false |
| 599 | end |
| 600 | if eq get ginv q 47 |
| 601 | ret false |
| 602 | end |
| 603 | cc_preset |
| 604 | cc_pi q w |
| 605 | fd = cc_try |
| 606 | if lt fd 0 |
| 607 | ret false |
| 608 | end |
| 609 | cc_close fd |
| 610 | ret true |
| 611 | end |
| 612 | |
| 613 | fn cc_resolve n ulong to bool |
| 614 | p = cc_find n 0 tchk |
| 615 | if eq p ccx |
| 616 | ret false |
| 617 | end |
| 618 | p = add p len tchk |
| 619 | if cc_at p n tcargo |
| 620 | ret cc_cargo n add p len tcargo |
| 621 | end |
| 622 | ret cc_file n p |
| 623 | end |
| 624 | |
| 625 | note ======== one .crumb ======== |
| 626 | |
| 627 | fn cc_odir j ulong to void |
| 628 | l = get gcl j |
| 629 | if eq l len tcrumb |
| 630 | cc_ob 46 |
| 631 | ret |
| 632 | end |
| 633 | cc_ogin get gco j sub sub l len tcrumb 1 |
| 634 | end |
| 635 | |
| 636 | fn cc_unres j ulong n ulong to void |
| 637 | cc_otx tunr |
| 638 | cc_odir j |
| 639 | cc_ob 58 |
| 640 | cc_ob 32 |
| 641 | cc_oinv n |
| 642 | cc_ob 10 |
| 643 | end |
| 644 | |
| 645 | fn cc_list src view uchar 983040 tape view uint 262160 nb edit uchar 8192 v ulong j ulong to void |
| 646 | if ne js_type tape v jsarr |
| 647 | cc_die 4 tinvarr |
| 648 | end |
| 649 | e = js_first tape v |
| 650 | while ne e jsnone bound 999999 |
| 651 | if ne js_type tape e jsstr |
| 652 | cc_die 4 tinvarr |
| 653 | end |
| 654 | r = js_sget src js_off tape e nb |
| 655 | if lt r 0 |
| 656 | cc_die 4 tjson |
| 657 | end |
| 658 | n = ulong r |
| 659 | if gt n len ginv |
| 660 | cc_die 4 tlong |
| 661 | end |
| 662 | for i ulong n |
| 663 | put ginv i get nb i |
| 664 | end |
| 665 | put gst kci add get gst kci 1 |
| 666 | if cc_resolve n |
| 667 | put gst kcrr add get gst kcrr 1 |
| 668 | else |
| 669 | cc_unres j n |
| 670 | end |
| 671 | e = js_enext tape e |
| 672 | end |
| 673 | end |
| 674 | |
| 675 | fn cc_line j ulong to void |
| 676 | i = get gst kci |
| 677 | r = get gst kcrr |
| 678 | put gst kinv add get gst kinv i |
| 679 | put gst kres add get gst kres r |
| 680 | put gst kunr add get gst kunr sub i r |
| 681 | if gt r 0 |
| 682 | put gst kenf add get gst kenf 1 |
| 683 | end |
| 684 | cc_otx tcrl |
| 685 | cc_odir j |
| 686 | cc_ob 32 |
| 687 | cc_kv o4 i |
| 688 | cc_ob 32 |
| 689 | cc_kv o5 r |
| 690 | cc_ob 10 |
| 691 | end |
| 692 | |
| 693 | fn cc_crumb src edit uchar 983040 tape edit uint 262160 nb edit uchar 8192 j ulong to void |
| 694 | cc_pset get gco j get gcl j |
| 695 | fd = cc_try |
| 696 | if lt fd 0 |
| 697 | cc_die 3 tio |
| 698 | end |
| 699 | sz = get gst kfsz |
| 700 | if or eq sz 0 gt sz len src |
| 701 | cc_close fd |
| 702 | cc_die 4 tjson |
| 703 | end |
| 704 | cc_rdsrc fd src sz |
| 705 | r = js_init tape sz 64 |
| 706 | if lt r 0 |
| 707 | cc_die 4 tjson |
| 708 | end |
| 709 | r = js_parse src tape sz |
| 710 | if lt r 0 |
| 711 | cc_die 4 tjson |
| 712 | end |
| 713 | if ne js_type tape 0 jsobj |
| 714 | cc_die 4 tjson |
| 715 | end |
| 716 | put gst kci 0 |
| 717 | put gst kcrr 0 |
| 718 | k = js_first tape 0 |
| 719 | while ne k jsnone bound 999999 |
| 720 | if js_streq src js_off tape k tinv |
| 721 | cc_list src tape nb add k 1 j |
| 722 | end |
| 723 | k = js_mnext tape k |
| 724 | end |
| 725 | cc_line j |
| 726 | end |
| 727 | |
| 728 | note ======== report ======== |
| 729 | |
| 730 | fn cc_report to void |
| 731 | cc_otx thead |
| 732 | cc_kv o1 get gst kdirs |
| 733 | cc_ob 10 |
| 734 | cc_otx thead |
| 735 | cc_kv o2 get gst kcr |
| 736 | cc_ob 10 |
| 737 | cc_otx thead |
| 738 | cc_kv o3 get gst kenf |
| 739 | cc_ob 10 |
| 740 | cc_otx thead |
| 741 | cc_kv o4 get gst kinv |
| 742 | cc_ob 32 |
| 743 | cc_kv o5 get gst kres |
| 744 | cc_ob 32 |
| 745 | cc_kv o6 get gst kunr |
| 746 | cc_ob 10 |
| 747 | cc_oflush 1 |
| 748 | end |
| 749 | |
| 750 | fn main to int |
| 751 | if ne argcnt 1 |
| 752 | cc_die 2 tusage |
| 753 | end |
| 754 | cc_input |
| 755 | cc_scan |
| 756 | src = new uchar 983040 0 |
| 757 | tape = new uint 262160 0 |
| 758 | nb = new uchar 8192 0 |
| 759 | for j ulong get gst kcr |
| 760 | cc_crumb src tape nb j |
| 761 | end |
| 762 | cc_report |
| 763 | if gt get gst kunr 0 |
| 764 | ret 1 |
| 765 | end |
| 766 | ret 0 |
| 767 | end |