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 / doctrine / doctrine.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note doctrine: doctrine consistency check (aien-architecture#7) in seeded Omega (#316, #300). |
| 3 | note Port of scripts/check_doctrine.sh (bash + GNU grep + gawk, LC_ALL=C): same inputs |
| 4 | note (doctrine/*.md, docs/milestone-*-spec.md under ROOT), same checks 0-4, same output lines |
| 5 | note and the same exit codes (0 pass, 1 fail, 2 ROOT unusable). |
| 6 | note usage: doctrine [ROOT] (ROOT defaults to the current directory) |
| 7 | note Every ERE of the script is hand-written as a matcher below; the ERE is kept in a note |
| 8 | note above its matcher. Byte semantics everywhere (the script runs under LC_ALL=C): word |
| 9 | note characters are [A-Za-z0-9_], [[:space:]] is 9-13 and 32, and gawk's bracket [-–] is |
| 10 | note the four bytes 45, 226, 128, 147 (an en dash never matches it as one character). |
| 11 | note Built only by seed/out/omc from aien-dev/omega-mv (tools/zero-legacy/omega.pin). |
| 12 | |
| 13 | text tbl "<!-- HISTORICAL-PROVENANCE:BEGIN -->\n<!-- HISTORICAL-PROVENANCE:END -->\nALPHA\nAlpha\nalpha.\nbin\nmanifest\nsha256\ndecode\nmemory-map\ncontrol-flow\naudit\nHandoff (EL1)\nEL1 Handoff\nEL1 handoff\nstrictly at **EL1\nEL1 Jump\nat EL1 privilege level\nMilestone\nMILESTONE\nSOVEREIGN_CLOSURE\nSOVEREIGN_MACHINE_CLOSURE\nAIEN_HUMAN_INTERFACE\n27\n28-\n31-\nilestone\nwenty-eight \nprecise \nmilestones\nhirty-one milestones\nMILESTONE \n— \n–\nM27\nBOOTSTRAP_SEED_ATLAS\nATLAS_BAREMETAL_BOOT\nATLAS_MEASUREMENT_CHAIN\nATLAS_STAGE2_ELIMINATION\nPHYSICS_CORE_MEMBRANE\nSENTINEL_GATE_\nAIEN_SEED_TRAINING\nAIEN_SEED_TOPOLOGY\n[COMPLETE]\n[IN PROGRESS]\n[REOPENED\n[COMPLETE / QEMU QUALIFIED]\n[QEMU QUALIFIED]\nPHYSICS_BOOT\nCOMPLETE\n| **M\n** |\nhysics \nero\nCOMPLETE / QEMU QUALIFIED\nCOMPLETE / HARDWARE BOUNDARY QUALIFIED\nCOMPLETE / CORRECTIVELY REQUALIFIED\nCOMPLETE / SILICON QUALIFIED\nREOPENED / IN PROGRESS\nIN PROGRESS\nPLANNED\nPhysics Zero Discovery\nGeneral AIEN\nFAIL [\n] \n: \nunbalanced-historical-marker\nalpha-naming\nfixed-el1-handoff\nobsolete-m27-closure\nobsolete-roadmap-generation\nretired-milestone-identifier\nstatus-outside-roadmap\nduplicate-roadmap-table\nphysics-zero-range\nroadmap-missing\nroadmap-structure\nmilestone-number-mismatch\nHISTORICAL-PROVENANCE marker without partner\ncanonical roadmap file not found\n expected row M\n, found M\n has unknown status \"\n\"\n is outside Physics Zero M27-M35\n must be in the Physics Zero Discovery era\n is outside General AIEN M36-M40\n expected 41 roadmap rows (M0-M40), found \n cited as M\n, is M\n in ROADMAP.md: \n----------------------------------------------------------------------\ncheck_doctrine: scanned \n files; \n failure(s); 0 deferred finding(s).\ncheck_doctrine: FAIL\ncheck_doctrine: PASS\ncheck_doctrine: cannot cd to \ndoctrine/ROADMAP.md\ndoctrine/\ndocs/\n.md\nmilestone-\n-spec.md\ndoctrine\ndocs\n:\n M\n.\n" |
| 14 | |
| 15 | note table entries by index: |
| 16 | note 0 BEGIN marker, 1 END marker, 2-11 alpha-naming parts, 12-17 fixed-el1-handoff literals, |
| 17 | note 18 Milestone, 19 MILESTONE, 20-22 m27 codes, 23 "27", 24-34 roadmap-generation parts |
| 18 | note (32 is em dash + space, 33 is the en dash), 35-42 retired identifiers, 43-49 status parts, |
| 19 | note 50 "| **M", 51 "** |", 52 "hysics ", 53 "ero", 54-60 roadmap statuses (49 is COMPLETE), |
| 20 | note 61-62 eras, 63-65 report pieces, 66-77 check names (66 + check id), 78-90 messages, |
| 21 | note 91-97 summary lines, 98 ROADMAP path, 99-105 directory and glob parts, 106 ":", 107 " M", |
| 22 | note 108 "." (the default ROOT). |
| 23 | |
| 24 | global toff ulong 128 |
| 25 | global tlen ulong 128 |
| 26 | global fbuf uchar 8388608 |
| 27 | global flen ulong 1 |
| 28 | global fpath uchar 4096 |
| 29 | global fplen ulong 1 |
| 30 | global lb ulong 1 |
| 31 | global lx ulong 1 |
| 32 | global nl ulong 1 |
| 33 | global fs ulong 1 |
| 34 | global fe ulong 1 |
| 35 | global names uchar 65536 |
| 36 | global noff ulong 1024 |
| 37 | global nlen ulong 1024 |
| 38 | global ord ulong 1024 |
| 39 | global nf ulong 1 |
| 40 | global nused ulong 1 |
| 41 | global dbuf uchar 65536 |
| 42 | global sb uchar 128 |
| 43 | global nb uchar 24 |
| 44 | global fails ulong 1 |
| 45 | global mcode uchar 32768 |
| 46 | global moff ulong 512 |
| 47 | global mlen ulong 512 |
| 48 | global mnoff ulong 512 |
| 49 | global mnlen ulong 512 |
| 50 | global mcnt ulong 1 |
| 51 | global mused ulong 1 |
| 52 | global mi ulong 1 |
| 53 | |
| 54 | note ---- the text table ---- |
| 55 | |
| 56 | fn tinit to void |
| 57 | k = ulong 0 |
| 58 | s = ulong 0 |
| 59 | for i ulong len tbl |
| 60 | if eq get tbl i 10 |
| 61 | put toff k s |
| 62 | put tlen k sub i s |
| 63 | k = add k 1 |
| 64 | s = add i 1 |
| 65 | end |
| 66 | end |
| 67 | end |
| 68 | |
| 69 | note write table entry k to stdout |
| 70 | fn wt k ulong to void |
| 71 | r = write 1 tbl get toff k get tlen k |
| 72 | end |
| 73 | |
| 74 | fn wnl to void |
| 75 | put nb 0 10 |
| 76 | r = write 1 nb 0 1 |
| 77 | end |
| 78 | |
| 79 | fn wnum v ulong to void |
| 80 | n = ulong 0 |
| 81 | if eq v 0 |
| 82 | put nb 23 48 |
| 83 | n = 1 |
| 84 | end |
| 85 | x = v |
| 86 | while gt x 0 bound 20 |
| 87 | put nb sub 23 n uchar add 48 rem x 10 |
| 88 | x = div x 10 |
| 89 | n = add n 1 |
| 90 | end |
| 91 | r = write 1 nb sub 24 n n |
| 92 | end |
| 93 | |
| 94 | note ---- bytes of the current line [lb, lx) of fbuf ---- |
| 95 | |
| 96 | note byte at i inside the line, 0 at or past its end |
| 97 | fn cb i ulong to ulong |
| 98 | if lt i get lx 0 |
| 99 | ret ulong get fbuf i |
| 100 | end |
| 101 | ret 0 |
| 102 | end |
| 103 | |
| 104 | note table entry k is the text at i (inside the line) |
| 105 | fn lit i ulong k ulong to bool |
| 106 | m = get tlen k |
| 107 | if gt add i m get lx 0 |
| 108 | ret false |
| 109 | end |
| 110 | o = get toff k |
| 111 | for j ulong m |
| 112 | if ne get fbuf add i j get tbl add o j |
| 113 | ret false |
| 114 | end |
| 115 | end |
| 116 | ret true |
| 117 | end |
| 118 | |
| 119 | note table entry k occurs somewhere in the line |
| 120 | fn has k ulong to bool |
| 121 | m = get tlen k |
| 122 | e = get lx 0 |
| 123 | if lt sub e get lb 0 m |
| 124 | ret false |
| 125 | end |
| 126 | i = get lb 0 |
| 127 | e = sub e m |
| 128 | while le i e bound 999999 |
| 129 | if lit i k |
| 130 | ret true |
| 131 | end |
| 132 | i = add i 1 |
| 133 | end |
| 134 | ret false |
| 135 | end |
| 136 | |
| 137 | note ---- byte classes (C locale) ---- |
| 138 | |
| 139 | fn isdg c ulong to bool |
| 140 | if lt c 48 |
| 141 | ret false |
| 142 | end |
| 143 | ret le c 57 |
| 144 | end |
| 145 | |
| 146 | fn isup c ulong to bool |
| 147 | if lt c 65 |
| 148 | ret false |
| 149 | end |
| 150 | ret le c 90 |
| 151 | end |
| 152 | |
| 153 | fn islo c ulong to bool |
| 154 | if lt c 97 |
| 155 | ret false |
| 156 | end |
| 157 | ret le c 122 |
| 158 | end |
| 159 | |
| 160 | note [A-Za-z0-9] |
| 161 | fn isan c ulong to bool |
| 162 | if isdg c |
| 163 | ret true |
| 164 | end |
| 165 | if isup c |
| 166 | ret true |
| 167 | end |
| 168 | ret islo c |
| 169 | end |
| 170 | |
| 171 | note word character of \b and \<: [A-Za-z0-9_] |
| 172 | fn isw c ulong to bool |
| 173 | if isan c |
| 174 | ret true |
| 175 | end |
| 176 | ret eq c 95 |
| 177 | end |
| 178 | |
| 179 | note [A-Z0-9_] |
| 180 | fn isid c ulong to bool |
| 181 | if isup c |
| 182 | ret true |
| 183 | end |
| 184 | if isdg c |
| 185 | ret true |
| 186 | end |
| 187 | ret eq c 95 |
| 188 | end |
| 189 | |
| 190 | note [[:space:]] |
| 191 | fn issp c ulong to bool |
| 192 | if eq c 32 |
| 193 | ret true |
| 194 | end |
| 195 | if lt c 9 |
| 196 | ret false |
| 197 | end |
| 198 | ret le c 13 |
| 199 | end |
| 200 | |
| 201 | note \b before position i: line start or a non-word byte before i |
| 202 | fn wbb i ulong to bool |
| 203 | if le i get lb 0 |
| 204 | ret true |
| 205 | end |
| 206 | ret not isw ulong get fbuf sub i 1 |
| 207 | end |
| 208 | |
| 209 | note \b after a word byte ending just before i: line end or a non-word byte at i |
| 210 | fn wba i ulong to bool |
| 211 | ret not isw cb i |
| 212 | end |
| 213 | |
| 214 | note ---- check 1: alpha-naming ---- |
| 215 | note ERE: \bALPHA\b|\bAlpha\b|\balpha\.(bin|manifest|sha256|decode|memory-map|control-flow|audit)\b |
| 216 | |
| 217 | fn alsuf j ulong to bool |
| 218 | k = ulong 5 |
| 219 | while le k 11 bound 8 |
| 220 | if lit j k |
| 221 | if wba add j get tlen k |
| 222 | ret true |
| 223 | end |
| 224 | end |
| 225 | k = add k 1 |
| 226 | end |
| 227 | ret false |
| 228 | end |
| 229 | |
| 230 | fn m1 to bool |
| 231 | i = get lb 0 |
| 232 | while lt i get lx 0 bound 999999 |
| 233 | if wbb i |
| 234 | if lit i 2 |
| 235 | if wba add i 5 |
| 236 | ret true |
| 237 | end |
| 238 | end |
| 239 | if lit i 3 |
| 240 | if wba add i 5 |
| 241 | ret true |
| 242 | end |
| 243 | end |
| 244 | if lit i 4 |
| 245 | if alsuf add i 6 |
| 246 | ret true |
| 247 | end |
| 248 | end |
| 249 | end |
| 250 | i = add i 1 |
| 251 | end |
| 252 | ret false |
| 253 | end |
| 254 | |
| 255 | note ---- check 1: fixed-el1-handoff ---- |
| 256 | note ERE: Monotonic Handoff \(EL1\)|Handoff \(EL1\)|EL1 [Hh]andoff|strictly at \*\*EL1|EL1 Jump|at EL1 privilege level |
| 257 | note (the first alternative contains the second, so five literals decide) |
| 258 | |
| 259 | fn m2 to bool |
| 260 | i = get lb 0 |
| 261 | while lt i get lx 0 bound 999999 |
| 262 | k = ulong 12 |
| 263 | while le k 17 bound 7 |
| 264 | if lit i k |
| 265 | ret true |
| 266 | end |
| 267 | k = add k 1 |
| 268 | end |
| 269 | i = add i 1 |
| 270 | end |
| 271 | ret false |
| 272 | end |
| 273 | |
| 274 | note ---- check 1: obsolete-m27-closure ---- |
| 275 | note ERE: (Milestone|MILESTONE|\bM) ?27\b[^|]*SOVEREIGN(_MACHINE)?_CLOSURE |
| 276 | note | SOVEREIGN(_MACHINE)?_CLOSURE[^|]*(Milestone|MILESTONE|\bM) ?27\b |
| 277 | note | (Milestone|MILESTONE|M) ?27\b[^|]*AIEN_HUMAN_INTERFACE |
| 278 | note | AIEN_HUMAN_INTERFACE[^|]*(Milestone|MILESTONE|\bM) ?27\b |
| 279 | |
| 280 | note end of "(Milestone|MILESTONE|M) ?27\b" starting at i, 0 when none; bd 1 demands \b before a bare M |
| 281 | fn tok27 i ulong bd ulong to ulong |
| 282 | p = ulong 0 |
| 283 | if lit i 18 |
| 284 | p = add i 9 |
| 285 | end |
| 286 | if lit i 19 |
| 287 | p = add i 9 |
| 288 | end |
| 289 | if eq p 0 |
| 290 | if ne cb i 77 |
| 291 | ret 0 |
| 292 | end |
| 293 | if eq bd 1 |
| 294 | if not wbb i |
| 295 | ret 0 |
| 296 | end |
| 297 | end |
| 298 | p = add i 1 |
| 299 | end |
| 300 | if eq cb p 32 |
| 301 | p = add p 1 |
| 302 | end |
| 303 | if not lit p 23 |
| 304 | ret 0 |
| 305 | end |
| 306 | if not wba add p 2 |
| 307 | ret 0 |
| 308 | end |
| 309 | ret add p 2 |
| 310 | end |
| 311 | |
| 312 | note a token ends at or before s with no | between it and s |
| 313 | fn m3a s ulong bd ulong to bool |
| 314 | i = s |
| 315 | while gt i get lb 0 bound 999999 |
| 316 | i = sub i 1 |
| 317 | if eq cb i 124 |
| 318 | ret false |
| 319 | end |
| 320 | e = tok27 i bd |
| 321 | if ne e 0 |
| 322 | if le e s |
| 323 | ret true |
| 324 | end |
| 325 | end |
| 326 | end |
| 327 | ret false |
| 328 | end |
| 329 | |
| 330 | note a \b-token starts at or after e with no | between e and it |
| 331 | fn m3b e ulong to bool |
| 332 | i = e |
| 333 | while lt i get lx 0 bound 999999 |
| 334 | if eq cb i 124 |
| 335 | ret false |
| 336 | end |
| 337 | if ne tok27 i 1 0 |
| 338 | ret true |
| 339 | end |
| 340 | i = add i 1 |
| 341 | end |
| 342 | ret false |
| 343 | end |
| 344 | |
| 345 | fn m3 to bool |
| 346 | i = get lb 0 |
| 347 | while lt i get lx 0 bound 999999 |
| 348 | if or lit i 20 lit i 21 |
| 349 | if m3a i 1 |
| 350 | ret true |
| 351 | end |
| 352 | end |
| 353 | if lit i 20 |
| 354 | if m3b add i 17 |
| 355 | ret true |
| 356 | end |
| 357 | end |
| 358 | if lit i 21 |
| 359 | if m3b add i 25 |
| 360 | ret true |
| 361 | end |
| 362 | end |
| 363 | if lit i 22 |
| 364 | if m3a i 0 |
| 365 | ret true |
| 366 | end |
| 367 | if m3b add i 20 |
| 368 | ret true |
| 369 | end |
| 370 | end |
| 371 | i = add i 1 |
| 372 | end |
| 373 | ret false |
| 374 | end |
| 375 | |
| 376 | note ---- check 1: obsolete-roadmap-generation ---- |
| 377 | note ERE: \b(28|31)-[Mm]ilestone|[Tt]wenty-eight (precise )?milestones|[Tt]hirty-one milestones |
| 378 | note | ^MILESTONE [0-9]+ +— |\bM[0-9]+ ?(-|–) ?M27\b |
| 379 | |
| 380 | fn m4a i ulong to bool |
| 381 | if not wbb i |
| 382 | ret false |
| 383 | end |
| 384 | if not or lit i 24 lit i 25 |
| 385 | ret false |
| 386 | end |
| 387 | c = cb add i 3 |
| 388 | if not or eq c 77 eq c 109 |
| 389 | ret false |
| 390 | end |
| 391 | ret lit add i 4 26 |
| 392 | end |
| 393 | |
| 394 | fn m4b i ulong to bool |
| 395 | c = cb i |
| 396 | if not or eq c 84 eq c 116 |
| 397 | ret false |
| 398 | end |
| 399 | if lit add i 1 30 |
| 400 | ret true |
| 401 | end |
| 402 | if not lit add i 1 27 |
| 403 | ret false |
| 404 | end |
| 405 | p = add i 13 |
| 406 | if lit p 28 |
| 407 | p = add p 8 |
| 408 | end |
| 409 | ret lit p 29 |
| 410 | end |
| 411 | |
| 412 | fn m4c to bool |
| 413 | p = get lb 0 |
| 414 | if not lit p 31 |
| 415 | ret false |
| 416 | end |
| 417 | p = add p 10 |
| 418 | if not isdg cb p |
| 419 | ret false |
| 420 | end |
| 421 | while isdg cb p bound 999999 |
| 422 | p = add p 1 |
| 423 | end |
| 424 | if ne cb p 32 |
| 425 | ret false |
| 426 | end |
| 427 | while eq cb p 32 bound 999999 |
| 428 | p = add p 1 |
| 429 | end |
| 430 | ret lit p 32 |
| 431 | end |
| 432 | |
| 433 | note position after "-" or the en dash at p, 0 when neither |
| 434 | fn dash p ulong to ulong |
| 435 | if eq cb p 45 |
| 436 | ret add p 1 |
| 437 | end |
| 438 | if lit p 33 |
| 439 | ret add p 3 |
| 440 | end |
| 441 | ret 0 |
| 442 | end |
| 443 | |
| 444 | fn m4d i ulong to bool |
| 445 | if not wbb i |
| 446 | ret false |
| 447 | end |
| 448 | if ne cb i 77 |
| 449 | ret false |
| 450 | end |
| 451 | p = add i 1 |
| 452 | if not isdg cb p |
| 453 | ret false |
| 454 | end |
| 455 | while isdg cb p bound 999999 |
| 456 | p = add p 1 |
| 457 | end |
| 458 | if eq cb p 32 |
| 459 | p = add p 1 |
| 460 | end |
| 461 | p = dash p |
| 462 | if eq p 0 |
| 463 | ret false |
| 464 | end |
| 465 | if eq cb p 32 |
| 466 | p = add p 1 |
| 467 | end |
| 468 | if not lit p 34 |
| 469 | ret false |
| 470 | end |
| 471 | ret wba add p 3 |
| 472 | end |
| 473 | |
| 474 | fn m4 to bool |
| 475 | if m4c |
| 476 | ret true |
| 477 | end |
| 478 | i = get lb 0 |
| 479 | while lt i get lx 0 bound 999999 |
| 480 | if m4a i |
| 481 | ret true |
| 482 | end |
| 483 | if m4b i |
| 484 | ret true |
| 485 | end |
| 486 | if m4d i |
| 487 | ret true |
| 488 | end |
| 489 | i = add i 1 |
| 490 | end |
| 491 | ret false |
| 492 | end |
| 493 | |
| 494 | note ---- check 1: retired-milestone-identifier ---- |
| 495 | note ERE: \b(BOOTSTRAP_SEED_ATLAS|ATLAS_BAREMETAL_BOOT|ATLAS_MEASUREMENT_CHAIN|ATLAS_STAGE2_ELIMINATION |
| 496 | note |PHYSICS_CORE_MEMBRANE|SENTINEL_GATE_[0-9]|AIEN_SEED_TRAINING|AIEN_SEED_TOPOLOGY)\b |
| 497 | |
| 498 | fn m5a i ulong to bool |
| 499 | k = ulong 35 |
| 500 | while le k 42 bound 9 |
| 501 | if lit i k |
| 502 | if eq k 40 |
| 503 | if isdg cb add i 14 |
| 504 | if wba add i 15 |
| 505 | ret true |
| 506 | end |
| 507 | end |
| 508 | else |
| 509 | if wba add i get tlen k |
| 510 | ret true |
| 511 | end |
| 512 | end |
| 513 | end |
| 514 | k = add k 1 |
| 515 | end |
| 516 | ret false |
| 517 | end |
| 518 | |
| 519 | fn m5 to bool |
| 520 | i = get lb 0 |
| 521 | while lt i get lx 0 bound 999999 |
| 522 | if wbb i |
| 523 | if m5a i |
| 524 | ret true |
| 525 | end |
| 526 | end |
| 527 | i = add i 1 |
| 528 | end |
| 529 | ret false |
| 530 | end |
| 531 | |
| 532 | note ---- check 1: status-outside-roadmap ---- |
| 533 | note ERE: \[(COMPLETE|IN PROGRESS|REOPENED[^]]*|COMPLETE / QEMU QUALIFIED|QEMU QUALIFIED)\]|PHYSICS_BOOT[^|]*\bCOMPLETE\b |
| 534 | |
| 535 | fn m6a i ulong to bool |
| 536 | j = add i 12 |
| 537 | while lt j get lx 0 bound 999999 |
| 538 | if eq cb j 124 |
| 539 | ret false |
| 540 | end |
| 541 | if lit j 49 |
| 542 | if wbb j |
| 543 | if wba add j 8 |
| 544 | ret true |
| 545 | end |
| 546 | end |
| 547 | end |
| 548 | j = add j 1 |
| 549 | end |
| 550 | ret false |
| 551 | end |
| 552 | |
| 553 | fn m6b i ulong to bool |
| 554 | j = add i 9 |
| 555 | while lt j get lx 0 bound 999999 |
| 556 | if eq cb j 93 |
| 557 | ret true |
| 558 | end |
| 559 | j = add j 1 |
| 560 | end |
| 561 | ret false |
| 562 | end |
| 563 | |
| 564 | fn m6 to bool |
| 565 | i = get lb 0 |
| 566 | while lt i get lx 0 bound 999999 |
| 567 | if or lit i 43 lit i 44 |
| 568 | ret true |
| 569 | end |
| 570 | if or lit i 46 lit i 47 |
| 571 | ret true |
| 572 | end |
| 573 | if lit i 45 |
| 574 | if m6b i |
| 575 | ret true |
| 576 | end |
| 577 | end |
| 578 | if lit i 48 |
| 579 | if m6a i |
| 580 | ret true |
| 581 | end |
| 582 | end |
| 583 | i = add i 1 |
| 584 | end |
| 585 | ret false |
| 586 | end |
| 587 | |
| 588 | note ---- check 1: duplicate-roadmap-table ---- |
| 589 | note ERE: ^[[:space:]]*M[0-9]{1,2}:[[:space:]]+[A-Z][A-Z0-9_]{3,}|^\| \*\*M[0-9]{1,2}\*\* \| |
| 590 | |
| 591 | fn m7b to bool |
| 592 | p = get lb 0 |
| 593 | if not lit p 50 |
| 594 | ret false |
| 595 | end |
| 596 | p = add p 5 |
| 597 | if not isdg cb p |
| 598 | ret false |
| 599 | end |
| 600 | p = add p 1 |
| 601 | if isdg cb p |
| 602 | p = add p 1 |
| 603 | end |
| 604 | ret lit p 51 |
| 605 | end |
| 606 | |
| 607 | fn m7 to bool |
| 608 | if m7b |
| 609 | ret true |
| 610 | end |
| 611 | p = get lb 0 |
| 612 | while issp cb p bound 999999 |
| 613 | p = add p 1 |
| 614 | end |
| 615 | if ne cb p 77 |
| 616 | ret false |
| 617 | end |
| 618 | p = add p 1 |
| 619 | if not isdg cb p |
| 620 | ret false |
| 621 | end |
| 622 | p = add p 1 |
| 623 | if isdg cb p |
| 624 | p = add p 1 |
| 625 | end |
| 626 | if ne cb p 58 |
| 627 | ret false |
| 628 | end |
| 629 | p = add p 1 |
| 630 | if not issp cb p |
| 631 | ret false |
| 632 | end |
| 633 | while issp cb p bound 999999 |
| 634 | p = add p 1 |
| 635 | end |
| 636 | if not isup cb p |
| 637 | ret false |
| 638 | end |
| 639 | p = add p 1 |
| 640 | n = ulong 0 |
| 641 | while isid cb p bound 999999 |
| 642 | p = add p 1 |
| 643 | n = add n 1 |
| 644 | end |
| 645 | ret ge n 3 |
| 646 | end |
| 647 | |
| 648 | note ---- check 2: physics-zero-range ---- |
| 649 | note awk, leftmost-longest, one report per line: |
| 650 | note while (match(s, /[Pp]hysics [Zz]ero[^.]{0,30}M[0-9]+ ?[-–] ?M[0-9]+|M[0-9]+ ?[-–] ?M[0-9]+ ?\([Pp]hysics [Zz]ero/)) |
| 651 | note t = matched; s = rest; match(t, /M[0-9]+ ?[-–] ?M[0-9]+/); r = that with spaces removed and – turned into - |
| 652 | note if (r != "M27-M35") report the line and stop |
| 653 | |
| 654 | note one byte of gawk's C-locale bracket [-–] |
| 655 | fn isdash c ulong to bool |
| 656 | if eq c 45 |
| 657 | ret true |
| 658 | end |
| 659 | if eq c 226 |
| 660 | ret true |
| 661 | end |
| 662 | if eq c 128 |
| 663 | ret true |
| 664 | end |
| 665 | ret eq c 147 |
| 666 | end |
| 667 | |
| 668 | note end of M[0-9]+ ?[-–] ?M[0-9]+ at j, 0 when none |
| 669 | fn rng j ulong to ulong |
| 670 | if ne cb j 77 |
| 671 | ret 0 |
| 672 | end |
| 673 | p = add j 1 |
| 674 | if not isdg cb p |
| 675 | ret 0 |
| 676 | end |
| 677 | while isdg cb p bound 999999 |
| 678 | p = add p 1 |
| 679 | end |
| 680 | if eq cb p 32 |
| 681 | p = add p 1 |
| 682 | end |
| 683 | if not isdash cb p |
| 684 | ret 0 |
| 685 | end |
| 686 | p = add p 1 |
| 687 | if eq cb p 32 |
| 688 | p = add p 1 |
| 689 | end |
| 690 | if ne cb p 77 |
| 691 | ret 0 |
| 692 | end |
| 693 | p = add p 1 |
| 694 | if not isdg cb p |
| 695 | ret 0 |
| 696 | end |
| 697 | while isdg cb p bound 999999 |
| 698 | p = add p 1 |
| 699 | end |
| 700 | ret p |
| 701 | end |
| 702 | |
| 703 | note [Pp]hysics [Zz]ero at i |
| 704 | fn pz i ulong to bool |
| 705 | c = cb i |
| 706 | if not or eq c 80 eq c 112 |
| 707 | ret false |
| 708 | end |
| 709 | if not lit add i 1 52 |
| 710 | ret false |
| 711 | end |
| 712 | c = cb add i 8 |
| 713 | if not or eq c 90 eq c 122 |
| 714 | ret false |
| 715 | end |
| 716 | ret lit add i 9 53 |
| 717 | end |
| 718 | |
| 719 | note longest end of the first alternative at i, 0 when none |
| 720 | fn alt1 i ulong to ulong |
| 721 | if not pz i |
| 722 | ret 0 |
| 723 | end |
| 724 | b = add i 12 |
| 725 | best = ulong 0 |
| 726 | k = ulong 0 |
| 727 | while le k 30 bound 31 |
| 728 | if gt k 0 |
| 729 | if eq cb sub add b k 1 46 |
| 730 | break |
| 731 | end |
| 732 | end |
| 733 | e = rng add b k |
| 734 | if gt e best |
| 735 | best = e |
| 736 | end |
| 737 | k = add k 1 |
| 738 | end |
| 739 | ret best |
| 740 | end |
| 741 | |
| 742 | note end of the second alternative at i, 0 when none |
| 743 | fn alt2 i ulong to ulong |
| 744 | p = rng i |
| 745 | if eq p 0 |
| 746 | ret 0 |
| 747 | end |
| 748 | if eq cb p 32 |
| 749 | p = add p 1 |
| 750 | end |
| 751 | if ne cb p 40 |
| 752 | ret 0 |
| 753 | end |
| 754 | if pz add p 1 |
| 755 | ret add p 13 |
| 756 | end |
| 757 | ret 0 |
| 758 | end |
| 759 | |
| 760 | note the range at j (already known to match rng) normalizes to M27-M35 |
| 761 | fn rok j ulong to bool |
| 762 | p = add j 1 |
| 763 | if not lit p 23 |
| 764 | ret false |
| 765 | end |
| 766 | p = add p 2 |
| 767 | if isdg cb p |
| 768 | ret false |
| 769 | end |
| 770 | if eq cb p 32 |
| 771 | p = add p 1 |
| 772 | end |
| 773 | if ne cb p 45 |
| 774 | ret false |
| 775 | end |
| 776 | p = add p 1 |
| 777 | if eq cb p 32 |
| 778 | p = add p 1 |
| 779 | end |
| 780 | if ne cb p 77 |
| 781 | ret false |
| 782 | end |
| 783 | p = add p 1 |
| 784 | if ne cb p 51 |
| 785 | ret false |
| 786 | end |
| 787 | if ne cb add p 1 53 |
| 788 | ret false |
| 789 | end |
| 790 | ret not isdg cb add p 2 |
| 791 | end |
| 792 | |
| 793 | note inside t = [i, e): is the leftmost range not M27-M35 |
| 794 | fn m8t i ulong e ulong to bool |
| 795 | sv = get lx 0 |
| 796 | put lx 0 e |
| 797 | r = false |
| 798 | j = i |
| 799 | while lt j e bound 999999 |
| 800 | if ne rng j 0 |
| 801 | r = not rok j |
| 802 | break |
| 803 | end |
| 804 | j = add j 1 |
| 805 | end |
| 806 | put lx 0 sv |
| 807 | ret r |
| 808 | end |
| 809 | |
| 810 | fn m8 to bool |
| 811 | pos = get lb 0 |
| 812 | while lt pos get lx 0 bound 999999 |
| 813 | i = pos |
| 814 | e = ulong 0 |
| 815 | while lt i get lx 0 bound 999999 |
| 816 | a = alt1 i |
| 817 | b = alt2 i |
| 818 | if gt b a |
| 819 | a = b |
| 820 | end |
| 821 | if gt a 0 |
| 822 | e = a |
| 823 | break |
| 824 | end |
| 825 | i = add i 1 |
| 826 | end |
| 827 | if eq e 0 |
| 828 | ret false |
| 829 | end |
| 830 | if m8t i e |
| 831 | ret true |
| 832 | end |
| 833 | pos = e |
| 834 | end |
| 835 | ret false |
| 836 | end |
| 837 | |
| 838 | note ---- roadmap rows (checks 3 and 4): fields split by | like awk -F'|' ---- |
| 839 | |
| 840 | note field k of the line into [fs, fe); empty at the line end when the row has fewer fields |
| 841 | fn fld k ulong to void |
| 842 | p = get lb 0 |
| 843 | c = ulong 1 |
| 844 | while lt c k bound 999999 |
| 845 | if ge p get lx 0 |
| 846 | break |
| 847 | end |
| 848 | if eq cb p 124 |
| 849 | c = add c 1 |
| 850 | end |
| 851 | p = add p 1 |
| 852 | end |
| 853 | if lt c k |
| 854 | put fs 0 get lx 0 |
| 855 | put fe 0 get lx 0 |
| 856 | ret |
| 857 | end |
| 858 | e = p |
| 859 | while lt e get lx 0 bound 999999 |
| 860 | if eq cb e 124 |
| 861 | break |
| 862 | end |
| 863 | e = add e 1 |
| 864 | end |
| 865 | put fs 0 p |
| 866 | put fe 0 e |
| 867 | end |
| 868 | |
| 869 | note gsub(/^ +| +$/, "") on the field |
| 870 | fn trim to void |
| 871 | s = get fs 0 |
| 872 | e = get fe 0 |
| 873 | while lt s e bound 999999 |
| 874 | if ne get fbuf s 32 |
| 875 | break |
| 876 | end |
| 877 | s = add s 1 |
| 878 | end |
| 879 | while gt e s bound 999999 |
| 880 | if ne get fbuf sub e 1 32 |
| 881 | break |
| 882 | end |
| 883 | e = sub e 1 |
| 884 | end |
| 885 | put fs 0 s |
| 886 | put fe 0 e |
| 887 | end |
| 888 | |
| 889 | note the field equals table entry k |
| 890 | fn feq k ulong to bool |
| 891 | if ne sub get fe 0 get fs 0 get tlen k |
| 892 | ret false |
| 893 | end |
| 894 | ret lit get fs 0 k |
| 895 | end |
| 896 | |
| 897 | note row regex ^\| \*\*M[0-9]+\*\* \| |
| 898 | fn isrow to bool |
| 899 | p = get lb 0 |
| 900 | if not lit p 50 |
| 901 | ret false |
| 902 | end |
| 903 | p = add p 5 |
| 904 | if not isdg cb p |
| 905 | ret false |
| 906 | end |
| 907 | while isdg cb p bound 999999 |
| 908 | p = add p 1 |
| 909 | end |
| 910 | ret lit p 51 |
| 911 | end |
| 912 | |
| 913 | note the row's number as awk computes it (m + 0) |
| 914 | fn rowm to ulong |
| 915 | p = add get lb 0 5 |
| 916 | m = ulong 0 |
| 917 | while isdg cb p bound 999999 |
| 918 | m = add mul m 10 sub cb p 48 |
| 919 | p = add p 1 |
| 920 | end |
| 921 | ret m |
| 922 | end |
| 923 | |
| 924 | note status in the roadmap's closed list |
| 925 | fn stok to bool |
| 926 | if feq 49 |
| 927 | ret true |
| 928 | end |
| 929 | k = ulong 54 |
| 930 | while le k 60 bound 8 |
| 931 | if feq k |
| 932 | ret true |
| 933 | end |
| 934 | k = add k 1 |
| 935 | end |
| 936 | ret false |
| 937 | end |
| 938 | |
| 939 | note ---- reports ---- |
| 940 | |
| 941 | note FAIL [check] path:line:␣ and count the failure |
| 942 | fn hdr ci ulong to void |
| 943 | wt 63 |
| 944 | wt add 66 ci |
| 945 | wt 64 |
| 946 | r = write 1 fpath 0 get fplen 0 |
| 947 | wt 106 |
| 948 | wnum get nl 0 |
| 949 | wt 65 |
| 950 | put fails 0 add get fails 0 1 |
| 951 | end |
| 952 | |
| 953 | fn wline to void |
| 954 | r = write 1 fbuf get lb 0 sub get lx 0 get lb 0 |
| 955 | end |
| 956 | |
| 957 | note sed 's/^[[:space:]]*//' | cut -c1-160 |
| 958 | fn wstrip to void |
| 959 | s = get lb 0 |
| 960 | while issp cb s bound 999999 |
| 961 | s = add s 1 |
| 962 | end |
| 963 | n = sub get lx 0 s |
| 964 | if gt n 160 |
| 965 | n = 160 |
| 966 | end |
| 967 | r = write 1 fbuf s n |
| 968 | end |
| 969 | |
| 970 | fn rep ci ulong to void |
| 971 | hdr ci |
| 972 | if eq ci 8 |
| 973 | wline |
| 974 | else |
| 975 | wstrip |
| 976 | end |
| 977 | wnl |
| 978 | end |
| 979 | |
| 980 | note roadmap-structure message " M<m><entry k>" |
| 981 | fn rep3 m ulong k ulong to void |
| 982 | hdr 10 |
| 983 | wt 107 |
| 984 | wnum m |
| 985 | wt k |
| 986 | wnl |
| 987 | end |
| 988 | |
| 989 | fn c3era m ulong to void |
| 990 | pzd = feq 61 |
| 991 | if pzd |
| 992 | if or lt m 27 gt m 35 |
| 993 | rep3 m 84 |
| 994 | end |
| 995 | end |
| 996 | if and ge m 27 le m 35 |
| 997 | if not pzd |
| 998 | rep3 m 85 |
| 999 | end |
| 1000 | end |
| 1001 | if feq 62 |
| 1002 | if or lt m 36 gt m 40 |
| 1003 | rep3 m 86 |
| 1004 | end |
| 1005 | end |
| 1006 | end |
| 1007 | |
| 1008 | note awk's row counter n is unset until the first row passes: printed before that, it is the |
| 1009 | note empty string, not 0 (" expected row M, found M1"; "found " with no rows). Reproduced. |
| 1010 | fn wcnt n ulong to void |
| 1011 | if ne n 0 |
| 1012 | wnum n |
| 1013 | end |
| 1014 | end |
| 1015 | |
| 1016 | note one roadmap row; n = the row index expected |
| 1017 | fn c3row n ulong to void |
| 1018 | m = rowm |
| 1019 | if ne m n |
| 1020 | hdr 10 |
| 1021 | wt 80 |
| 1022 | wcnt n |
| 1023 | wt 81 |
| 1024 | wnum m |
| 1025 | wnl |
| 1026 | end |
| 1027 | fld 6 |
| 1028 | trim |
| 1029 | if not stok |
| 1030 | hdr 10 |
| 1031 | wt 107 |
| 1032 | wnum m |
| 1033 | wt 82 |
| 1034 | r = write 1 fbuf get fs 0 sub get fe 0 get fs 0 |
| 1035 | wt 83 |
| 1036 | wnl |
| 1037 | end |
| 1038 | fld 3 |
| 1039 | trim |
| 1040 | c3era m |
| 1041 | end |
| 1042 | |
| 1043 | note ---- check 4: milestone-number-mismatch ---- |
| 1044 | note MAP: for each roadmap row, code = $4 without spaces and backticks -> number = $2 without " *M" |
| 1045 | note (a digit string; awk compares it to the cited digits as strings; the last row for a code wins) |
| 1046 | |
| 1047 | note copy field bytes that are not ' ' and not x and not y into mcode at mused; return the length |
| 1048 | fn mcopy x ulong y ulong to ulong |
| 1049 | u = get mused 0 |
| 1050 | n = ulong 0 |
| 1051 | s = get fs 0 |
| 1052 | while lt s get fe 0 bound 999999 |
| 1053 | c = ulong get fbuf s |
| 1054 | if ne c 32 |
| 1055 | if ne c x |
| 1056 | if ne c y |
| 1057 | put mcode add u n uchar c |
| 1058 | n = add n 1 |
| 1059 | end |
| 1060 | end |
| 1061 | end |
| 1062 | s = add s 1 |
| 1063 | end |
| 1064 | put mused 0 add u n |
| 1065 | ret n |
| 1066 | end |
| 1067 | |
| 1068 | fn maprow to void |
| 1069 | k = get mcnt 0 |
| 1070 | put moff k get mused 0 |
| 1071 | fld 4 |
| 1072 | put mlen k mcopy 96 96 |
| 1073 | if eq get mlen k 0 |
| 1074 | put mused 0 get moff k |
| 1075 | ret |
| 1076 | end |
| 1077 | put mnoff k get mused 0 |
| 1078 | fld 2 |
| 1079 | put mnlen k mcopy 42 77 |
| 1080 | put mcnt 0 add k 1 |
| 1081 | end |
| 1082 | |
| 1083 | note the code [s, e) is in the map: mi = its last row |
| 1084 | fn look s ulong e ulong to bool |
| 1085 | k = get mcnt 0 |
| 1086 | while gt k 0 bound 512 |
| 1087 | k = sub k 1 |
| 1088 | if eq get mlen k sub e s |
| 1089 | if same s get moff k get mlen k |
| 1090 | put mi 0 k |
| 1091 | ret true |
| 1092 | end |
| 1093 | end |
| 1094 | end |
| 1095 | ret false |
| 1096 | end |
| 1097 | |
| 1098 | fn same s ulong o ulong n ulong to bool |
| 1099 | for j ulong n |
| 1100 | if ne get fbuf add s j get mcode add o j |
| 1101 | ret false |
| 1102 | end |
| 1103 | end |
| 1104 | ret true |
| 1105 | end |
| 1106 | |
| 1107 | note the cited digits [d, e) equal the map number of row mi as strings |
| 1108 | fn numeq d ulong e ulong to bool |
| 1109 | k = get mi 0 |
| 1110 | if ne get mnlen k sub e d |
| 1111 | ret false |
| 1112 | end |
| 1113 | ret same d get mnoff k get mnlen k |
| 1114 | end |
| 1115 | |
| 1116 | fn rep4 cs ulong ce ulong ds ulong de ulong to void |
| 1117 | hdr 11 |
| 1118 | r = write 1 fbuf cs sub ce cs |
| 1119 | wt 88 |
| 1120 | r = write 1 fbuf ds sub de ds |
| 1121 | wt 89 |
| 1122 | r = write 1 mcode get mnoff get mi 0 get mnlen get mi 0 |
| 1123 | wt 90 |
| 1124 | wline |
| 1125 | wnl |
| 1126 | end |
| 1127 | |
| 1128 | note first loop: (Milestones?|MILESTONE|\<M) ?[0-9]+[^A-Za-z0-9]{1,6}[A-Z][A-Z0-9_]+ |
| 1129 | note n = first digit run of t, c = the [A-Z][A-Z0-9_]+$ suffix of t |
| 1130 | |
| 1131 | note position after the keyword at i, 0 when none |
| 1132 | fn kwa i ulong to ulong |
| 1133 | if lit i 18 |
| 1134 | p = add i 9 |
| 1135 | if eq cb p 115 |
| 1136 | ret add p 1 |
| 1137 | end |
| 1138 | ret p |
| 1139 | end |
| 1140 | if lit i 19 |
| 1141 | ret add i 9 |
| 1142 | end |
| 1143 | if ne cb i 77 |
| 1144 | ret 0 |
| 1145 | end |
| 1146 | if not wbb i |
| 1147 | ret 0 |
| 1148 | end |
| 1149 | ret add i 1 |
| 1150 | end |
| 1151 | |
| 1152 | fn ma i ulong to ulong |
| 1153 | p = kwa i |
| 1154 | if eq p 0 |
| 1155 | ret 0 |
| 1156 | end |
| 1157 | if eq cb p 32 |
| 1158 | p = add p 1 |
| 1159 | end |
| 1160 | if not isdg cb p |
| 1161 | ret 0 |
| 1162 | end |
| 1163 | while isdg cb p bound 999999 |
| 1164 | p = add p 1 |
| 1165 | end |
| 1166 | q = p |
| 1167 | g = ulong 0 |
| 1168 | while lt g 7 bound 8 |
| 1169 | if isan cb q |
| 1170 | break |
| 1171 | end |
| 1172 | q = add q 1 |
| 1173 | g = add g 1 |
| 1174 | end |
| 1175 | if lt g 1 |
| 1176 | ret 0 |
| 1177 | end |
| 1178 | if gt g 6 |
| 1179 | ret 0 |
| 1180 | end |
| 1181 | if not isup cb q |
| 1182 | ret 0 |
| 1183 | end |
| 1184 | r = add q 1 |
| 1185 | while isid cb r bound 999999 |
| 1186 | r = add r 1 |
| 1187 | end |
| 1188 | if lt sub r q 2 |
| 1189 | ret 0 |
| 1190 | end |
| 1191 | ret r |
| 1192 | end |
| 1193 | |
| 1194 | fn ja i ulong e ulong to bool |
| 1195 | q = e |
| 1196 | while gt q i bound 999999 |
| 1197 | if not isid cb sub q 1 |
| 1198 | break |
| 1199 | end |
| 1200 | q = sub q 1 |
| 1201 | end |
| 1202 | while not isup cb q bound 999999 |
| 1203 | q = add q 1 |
| 1204 | end |
| 1205 | d = i |
| 1206 | while not isdg cb d bound 999999 |
| 1207 | d = add d 1 |
| 1208 | end |
| 1209 | n = d |
| 1210 | while isdg cb n bound 999999 |
| 1211 | n = add n 1 |
| 1212 | end |
| 1213 | if not look q e |
| 1214 | ret false |
| 1215 | end |
| 1216 | if numeq d n |
| 1217 | ret false |
| 1218 | end |
| 1219 | rep4 q e d n |
| 1220 | ret true |
| 1221 | end |
| 1222 | |
| 1223 | fn m9a to bool |
| 1224 | pos = get lb 0 |
| 1225 | while lt pos get lx 0 bound 999999 |
| 1226 | i = pos |
| 1227 | e = ulong 0 |
| 1228 | while lt i get lx 0 bound 999999 |
| 1229 | e = ma i |
| 1230 | if gt e 0 |
| 1231 | break |
| 1232 | end |
| 1233 | i = add i 1 |
| 1234 | end |
| 1235 | if eq e 0 |
| 1236 | ret false |
| 1237 | end |
| 1238 | if ja i e |
| 1239 | ret true |
| 1240 | end |
| 1241 | pos = e |
| 1242 | end |
| 1243 | ret false |
| 1244 | end |
| 1245 | |
| 1246 | note second loop: [A-Z][A-Z0-9_]+`?[^A-Za-z0-9]{1,4}\((Milestones?|MILESTONE|M) ?[0-9]+ |
| 1247 | note c = the ^[A-Z][A-Z0-9_]+ prefix of t, n = the [0-9]+$ suffix of t |
| 1248 | |
| 1249 | note position after "(Milestones?|MILESTONE|M) ?[0-9]+" at p, 0 when none |
| 1250 | fn kwb p ulong to ulong |
| 1251 | if lit p 18 |
| 1252 | p = add p 9 |
| 1253 | if eq cb p 115 |
| 1254 | p = add p 1 |
| 1255 | end |
| 1256 | else |
| 1257 | if lit p 19 |
| 1258 | p = add p 9 |
| 1259 | else |
| 1260 | if ne cb p 77 |
| 1261 | ret 0 |
| 1262 | end |
| 1263 | p = add p 1 |
| 1264 | end |
| 1265 | end |
| 1266 | if eq cb p 32 |
| 1267 | p = add p 1 |
| 1268 | end |
| 1269 | if not isdg cb p |
| 1270 | ret 0 |
| 1271 | end |
| 1272 | while isdg cb p bound 999999 |
| 1273 | p = add p 1 |
| 1274 | end |
| 1275 | ret p |
| 1276 | end |
| 1277 | |
| 1278 | note longest end given the identifier ends at x: gap of 1..5 non-alnum bytes (5 only after a backtick), then ( |
| 1279 | fn mbg x ulong to ulong |
| 1280 | best = ulong 0 |
| 1281 | g = ulong 1 |
| 1282 | while le g 5 bound 6 |
| 1283 | q = add x g |
| 1284 | if isan cb sub q 1 |
| 1285 | break |
| 1286 | end |
| 1287 | if eq cb q 40 |
| 1288 | if or lt g 5 eq cb x 96 |
| 1289 | e = kwb add q 1 |
| 1290 | if gt e best |
| 1291 | best = e |
| 1292 | end |
| 1293 | end |
| 1294 | end |
| 1295 | g = add g 1 |
| 1296 | end |
| 1297 | ret best |
| 1298 | end |
| 1299 | |
| 1300 | fn mb i ulong to ulong |
| 1301 | if not isup cb i |
| 1302 | ret 0 |
| 1303 | end |
| 1304 | r = add i 1 |
| 1305 | while isid cb r bound 999999 |
| 1306 | r = add r 1 |
| 1307 | end |
| 1308 | if lt sub r i 2 |
| 1309 | ret 0 |
| 1310 | end |
| 1311 | best = ulong 0 |
| 1312 | x = add i 2 |
| 1313 | while le x r bound 999999 |
| 1314 | e = mbg x |
| 1315 | if gt e best |
| 1316 | best = e |
| 1317 | end |
| 1318 | x = add x 1 |
| 1319 | end |
| 1320 | ret best |
| 1321 | end |
| 1322 | |
| 1323 | fn jb i ulong e ulong to bool |
| 1324 | r = add i 1 |
| 1325 | while isid cb r bound 999999 |
| 1326 | r = add r 1 |
| 1327 | end |
| 1328 | d = e |
| 1329 | while isdg cb sub d 1 bound 999999 |
| 1330 | d = sub d 1 |
| 1331 | end |
| 1332 | if not look i r |
| 1333 | ret false |
| 1334 | end |
| 1335 | if numeq d e |
| 1336 | ret false |
| 1337 | end |
| 1338 | rep4 i r d e |
| 1339 | ret true |
| 1340 | end |
| 1341 | |
| 1342 | fn m9b to bool |
| 1343 | pos = get lb 0 |
| 1344 | while lt pos get lx 0 bound 999999 |
| 1345 | i = pos |
| 1346 | e = ulong 0 |
| 1347 | while lt i get lx 0 bound 999999 |
| 1348 | e = mb i |
| 1349 | if gt e 0 |
| 1350 | break |
| 1351 | end |
| 1352 | i = add i 1 |
| 1353 | end |
| 1354 | if eq e 0 |
| 1355 | ret false |
| 1356 | end |
| 1357 | if jb i e |
| 1358 | ret true |
| 1359 | end |
| 1360 | pos = e |
| 1361 | end |
| 1362 | ret false |
| 1363 | end |
| 1364 | |
| 1365 | fn m9 to bool |
| 1366 | if m9a |
| 1367 | ret true |
| 1368 | end |
| 1369 | ret m9b |
| 1370 | end |
| 1371 | |
| 1372 | note ---- line walks over the loaded file ---- |
| 1373 | |
| 1374 | fn eol s ulong to ulong |
| 1375 | i = s |
| 1376 | e = get flen 0 |
| 1377 | while lt i e bound 999999 |
| 1378 | if eq get fbuf i 10 |
| 1379 | ret i |
| 1380 | end |
| 1381 | i = add i 1 |
| 1382 | end |
| 1383 | ret e |
| 1384 | end |
| 1385 | |
| 1386 | fn mt ci ulong to bool |
| 1387 | if eq ci 1 |
| 1388 | ret m1 |
| 1389 | end |
| 1390 | if eq ci 2 |
| 1391 | ret m2 |
| 1392 | end |
| 1393 | if eq ci 3 |
| 1394 | ret m3 |
| 1395 | end |
| 1396 | if eq ci 4 |
| 1397 | ret m4 |
| 1398 | end |
| 1399 | if eq ci 5 |
| 1400 | ret m5 |
| 1401 | end |
| 1402 | if eq ci 6 |
| 1403 | ret m6 |
| 1404 | end |
| 1405 | if eq ci 7 |
| 1406 | ret m7 |
| 1407 | end |
| 1408 | if eq ci 8 |
| 1409 | ret m8 |
| 1410 | end |
| 1411 | ret m9 |
| 1412 | end |
| 1413 | |
| 1414 | note normative lines: a line inside the historical markers is blank and matches nothing |
| 1415 | fn scan ci ulong to void |
| 1416 | hist = ulong 0 |
| 1417 | s = ulong 0 |
| 1418 | put nl 0 0 |
| 1419 | while lt s get flen 0 bound 999999 |
| 1420 | e = eol s |
| 1421 | put nl 0 add get nl 0 1 |
| 1422 | put lb 0 s |
| 1423 | put lx 0 e |
| 1424 | if has 0 |
| 1425 | hist = 1 |
| 1426 | else |
| 1427 | if has 1 |
| 1428 | hist = 0 |
| 1429 | else |
| 1430 | if eq hist 0 |
| 1431 | if gt e s |
| 1432 | if mt ci |
| 1433 | if ne ci 11 |
| 1434 | rep ci |
| 1435 | end |
| 1436 | end |
| 1437 | end |
| 1438 | end |
| 1439 | end |
| 1440 | end |
| 1441 | s = add e 1 |
| 1442 | end |
| 1443 | end |
| 1444 | |
| 1445 | note check 0: the first unbalanced marker of the raw file. The awk prints NR and exits on a |
| 1446 | note second BEGIN or a stray END; exit still runs its END rule, so a second BEGIN also prints the |
| 1447 | note first BEGIN's line: the report's line field is then "NR\nopen". Reproduced, not corrected. |
| 1448 | fn c0 to void |
| 1449 | op = ulong 0 |
| 1450 | bad = ulong 0 |
| 1451 | s = ulong 0 |
| 1452 | put nl 0 0 |
| 1453 | while lt s get flen 0 bound 999999 |
| 1454 | e = eol s |
| 1455 | put nl 0 add get nl 0 1 |
| 1456 | put lb 0 s |
| 1457 | put lx 0 e |
| 1458 | if has 0 |
| 1459 | if ne op 0 |
| 1460 | bad = get nl 0 |
| 1461 | break |
| 1462 | end |
| 1463 | op = get nl 0 |
| 1464 | else |
| 1465 | if has 1 |
| 1466 | if eq op 0 |
| 1467 | bad = get nl 0 |
| 1468 | break |
| 1469 | end |
| 1470 | op = 0 |
| 1471 | end |
| 1472 | end |
| 1473 | s = add e 1 |
| 1474 | end |
| 1475 | if eq bad 0 |
| 1476 | bad = op |
| 1477 | op = 0 |
| 1478 | end |
| 1479 | if ne bad 0 |
| 1480 | put nl 0 bad |
| 1481 | hdr0 op |
| 1482 | wt 78 |
| 1483 | wnl |
| 1484 | end |
| 1485 | end |
| 1486 | |
| 1487 | note FAIL [unbalanced-historical-marker] path:nl[\nop]:␣ |
| 1488 | fn hdr0 op ulong to void |
| 1489 | wt 63 |
| 1490 | wt 66 |
| 1491 | wt 64 |
| 1492 | r = write 1 fpath 0 get fplen 0 |
| 1493 | wt 106 |
| 1494 | wnum get nl 0 |
| 1495 | if ne op 0 |
| 1496 | wnl |
| 1497 | wnum op |
| 1498 | end |
| 1499 | wt 65 |
| 1500 | put fails 0 add get fails 0 1 |
| 1501 | end |
| 1502 | |
| 1503 | note check 3: roadmap structure, row by row, then the row count |
| 1504 | fn c3 to void |
| 1505 | hist = ulong 0 |
| 1506 | n = ulong 0 |
| 1507 | s = ulong 0 |
| 1508 | put nl 0 0 |
| 1509 | while lt s get flen 0 bound 999999 |
| 1510 | e = eol s |
| 1511 | put nl 0 add get nl 0 1 |
| 1512 | put lb 0 s |
| 1513 | put lx 0 e |
| 1514 | if has 0 |
| 1515 | hist = 1 |
| 1516 | else |
| 1517 | if has 1 |
| 1518 | hist = 0 |
| 1519 | else |
| 1520 | if eq hist 0 |
| 1521 | if isrow |
| 1522 | c3row n |
| 1523 | n = add n 1 |
| 1524 | end |
| 1525 | end |
| 1526 | end |
| 1527 | end |
| 1528 | s = add e 1 |
| 1529 | end |
| 1530 | if ne n 41 |
| 1531 | put nl 0 0 |
| 1532 | hdr 10 |
| 1533 | wt 87 |
| 1534 | wcnt n |
| 1535 | wnl |
| 1536 | end |
| 1537 | end |
| 1538 | |
| 1539 | fn c4map to void |
| 1540 | hist = ulong 0 |
| 1541 | s = ulong 0 |
| 1542 | while lt s get flen 0 bound 999999 |
| 1543 | e = eol s |
| 1544 | put lb 0 s |
| 1545 | put lx 0 e |
| 1546 | if has 0 |
| 1547 | hist = 1 |
| 1548 | else |
| 1549 | if has 1 |
| 1550 | hist = 0 |
| 1551 | else |
| 1552 | if eq hist 0 |
| 1553 | if isrow |
| 1554 | maprow |
| 1555 | end |
| 1556 | end |
| 1557 | end |
| 1558 | end |
| 1559 | s = add e 1 |
| 1560 | end |
| 1561 | end |
| 1562 | |
| 1563 | note ---- files ---- |
| 1564 | |
| 1565 | note table entry k into fpath |
| 1566 | fn setent k ulong to void |
| 1567 | o = get toff k |
| 1568 | n = get tlen k |
| 1569 | for i ulong n |
| 1570 | put fpath i get tbl add o i |
| 1571 | end |
| 1572 | put fplen 0 n |
| 1573 | end |
| 1574 | |
| 1575 | note fpath[i..] is table entry k |
| 1576 | fn plit i ulong k ulong to bool |
| 1577 | o = get toff k |
| 1578 | for j ulong get tlen k |
| 1579 | if ne get fpath add i j get tbl add o j |
| 1580 | ret false |
| 1581 | end |
| 1582 | end |
| 1583 | ret true |
| 1584 | end |
| 1585 | |
| 1586 | fn fileeq k ulong to bool |
| 1587 | if ne get fplen 0 get tlen k |
| 1588 | ret false |
| 1589 | end |
| 1590 | ret plit 0 k |
| 1591 | end |
| 1592 | |
| 1593 | fn load to bool |
| 1594 | put flen 0 0 |
| 1595 | fd = fopen fpath 0 get fplen 0 0 0 |
| 1596 | if lt fd 0 |
| 1597 | ret false |
| 1598 | end |
| 1599 | t = ulong 0 |
| 1600 | while lt t len fbuf bound 100000 |
| 1601 | r = read int fd fbuf t sub len fbuf t |
| 1602 | if le r 0 |
| 1603 | break |
| 1604 | end |
| 1605 | t = add t ulong r |
| 1606 | end |
| 1607 | put flen 0 t |
| 1608 | r = fclose int fd |
| 1609 | ret true |
| 1610 | end |
| 1611 | |
| 1612 | note [ -f fpath ]: stat follows symlinks; S_IFMT 61440, S_IFREG 32768 |
| 1613 | fn isreg to bool |
| 1614 | r = stat fpath 0 get fplen 0 sb 0 128 |
| 1615 | if lt r 0 |
| 1616 | ret false |
| 1617 | end |
| 1618 | m = add ulong get sb 16 mul 256 ulong get sb 17 |
| 1619 | ret eq and m 61440 32768 |
| 1620 | end |
| 1621 | |
| 1622 | fn addname to void |
| 1623 | n = get nf 0 |
| 1624 | u = get nused 0 |
| 1625 | put noff n u |
| 1626 | put nlen n get fplen 0 |
| 1627 | for i ulong get fplen 0 |
| 1628 | put names add u i get fpath i |
| 1629 | end |
| 1630 | put nused 0 add u get fplen 0 |
| 1631 | put ord n n |
| 1632 | put nf 0 add n 1 |
| 1633 | end |
| 1634 | |
| 1635 | fn less x ulong y ulong to bool |
| 1636 | m = get nlen x |
| 1637 | if gt m get nlen y |
| 1638 | m = get nlen y |
| 1639 | end |
| 1640 | for i ulong m |
| 1641 | a = ulong get names add get noff x i |
| 1642 | b = ulong get names add get noff y i |
| 1643 | if ne a b |
| 1644 | ret lt a b |
| 1645 | end |
| 1646 | end |
| 1647 | ret lt get nlen x get nlen y |
| 1648 | end |
| 1649 | |
| 1650 | note bash glob order under LC_ALL=C: byte order, within [a, b) of ord |
| 1651 | fn sortn a ulong b ulong to void |
| 1652 | i = add a 1 |
| 1653 | while lt i b bound 1024 |
| 1654 | j = i |
| 1655 | while gt j a bound 1024 |
| 1656 | if not less get ord j get ord sub j 1 |
| 1657 | break |
| 1658 | end |
| 1659 | t = get ord j |
| 1660 | put ord j get ord sub j 1 |
| 1661 | put ord sub j 1 t |
| 1662 | j = sub j 1 |
| 1663 | end |
| 1664 | i = add i 1 |
| 1665 | end |
| 1666 | end |
| 1667 | |
| 1668 | fn setpath k ulong to void |
| 1669 | j = get ord k |
| 1670 | o = get noff j |
| 1671 | n = get nlen j |
| 1672 | for i ulong n |
| 1673 | put fpath i get names add o i |
| 1674 | end |
| 1675 | put fplen 0 n |
| 1676 | end |
| 1677 | |
| 1678 | note the glob: kind 0 = doctrine/*.md, kind 1 = docs/milestone-*-spec.md; name at fpath[pl, pl+n) |
| 1679 | fn pat pl ulong n ulong kind ulong to bool |
| 1680 | if eq kind 0 |
| 1681 | if lt n 3 |
| 1682 | ret false |
| 1683 | end |
| 1684 | ret plit sub add pl n 3 101 |
| 1685 | end |
| 1686 | if lt n 18 |
| 1687 | ret false |
| 1688 | end |
| 1689 | if not plit pl 102 |
| 1690 | ret false |
| 1691 | end |
| 1692 | ret plit sub add pl n 8 103 |
| 1693 | end |
| 1694 | |
| 1695 | fn reclen o ulong to ulong |
| 1696 | lo = ulong get dbuf add o 16 |
| 1697 | hi = ulong get dbuf add o 17 |
| 1698 | ret add lo mul 256 hi |
| 1699 | end |
| 1700 | |
| 1701 | note one getdents64 record at o; the prefix is already in fpath[0, fplen) |
| 1702 | fn entry o ulong kind ulong to void |
| 1703 | pl = get fplen 0 |
| 1704 | n = ulong 0 |
| 1705 | while ne get dbuf add o add 19 n 0 bound 256 |
| 1706 | put fpath add pl n get dbuf add o add 19 n |
| 1707 | n = add n 1 |
| 1708 | end |
| 1709 | if eq n 0 |
| 1710 | ret |
| 1711 | end |
| 1712 | if eq get fpath pl 46 |
| 1713 | ret |
| 1714 | end |
| 1715 | if not pat pl n kind |
| 1716 | ret |
| 1717 | end |
| 1718 | put fplen 0 add pl n |
| 1719 | if isreg |
| 1720 | addname |
| 1721 | end |
| 1722 | put fplen 0 pl |
| 1723 | end |
| 1724 | |
| 1725 | fn listdir kind ulong to void |
| 1726 | a = get nf 0 |
| 1727 | setent add 104 kind |
| 1728 | fd = fopen fpath 0 get fplen 0 16384 0 |
| 1729 | if lt fd 0 |
| 1730 | ret |
| 1731 | end |
| 1732 | setent add 99 kind |
| 1733 | while true bound 100000 |
| 1734 | r = getdnts int fd dbuf 0 len dbuf |
| 1735 | if le r 0 |
| 1736 | break |
| 1737 | end |
| 1738 | o = ulong 0 |
| 1739 | while lt o ulong r bound 65536 |
| 1740 | entry o kind |
| 1741 | o = add o reclen o |
| 1742 | end |
| 1743 | end |
| 1744 | r = fclose int fd |
| 1745 | sortn a get nf 0 |
| 1746 | end |
| 1747 | |
| 1748 | note run check ci over every file (skip 1: not the roadmap) |
| 1749 | fn pass ci ulong skip ulong to void |
| 1750 | for k ulong get nf 0 |
| 1751 | setpath k |
| 1752 | if eq skip 1 |
| 1753 | if fileeq 98 |
| 1754 | continue |
| 1755 | end |
| 1756 | end |
| 1757 | if load |
| 1758 | if eq ci 0 |
| 1759 | c0 |
| 1760 | else |
| 1761 | scan ci |
| 1762 | end |
| 1763 | end |
| 1764 | end |
| 1765 | end |
| 1766 | |
| 1767 | fn main to int |
| 1768 | tinit |
| 1769 | put fplen 0 0 |
| 1770 | if ge argcnt 2 |
| 1771 | n = argread 1 fpath 0 4095 |
| 1772 | if gt n 0 |
| 1773 | put fplen 0 ulong n |
| 1774 | end |
| 1775 | end |
| 1776 | if eq get fplen 0 0 |
| 1777 | setent 108 |
| 1778 | end |
| 1779 | r = chdir fpath 0 get fplen 0 |
| 1780 | if ne r 0 |
| 1781 | r = write 2 tbl get toff 97 get tlen 97 |
| 1782 | r = write 2 fpath 0 get fplen 0 |
| 1783 | put nb 0 10 |
| 1784 | r = write 2 nb 0 1 |
| 1785 | ret 2 |
| 1786 | end |
| 1787 | listdir 0 |
| 1788 | listdir 1 |
| 1789 | pass 0 0 |
| 1790 | pass 1 0 |
| 1791 | pass 2 0 |
| 1792 | pass 3 0 |
| 1793 | pass 4 0 |
| 1794 | pass 5 0 |
| 1795 | pass 6 1 |
| 1796 | pass 7 1 |
| 1797 | pass 8 1 |
| 1798 | setent 98 |
| 1799 | if not isreg |
| 1800 | put nl 0 0 |
| 1801 | hdr 9 |
| 1802 | wt 79 |
| 1803 | wnl |
| 1804 | else |
| 1805 | if load |
| 1806 | c3 |
| 1807 | c4map |
| 1808 | end |
| 1809 | pass 11 1 |
| 1810 | end |
| 1811 | wt 91 |
| 1812 | wnl |
| 1813 | wt 92 |
| 1814 | wnum get nf 0 |
| 1815 | wt 93 |
| 1816 | wnum get fails 0 |
| 1817 | wt 94 |
| 1818 | wnl |
| 1819 | if gt get fails 0 0 |
| 1820 | wt 95 |
| 1821 | wnl |
| 1822 | ret 1 |
| 1823 | end |
| 1824 | wt 96 |
| 1825 | wnl |
| 1826 | ret 0 |
| 1827 | end |