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 / apps / interplane-forge / research / sync.om
| 1 | note research/sync.om: research-sync, its own seeded Omega program (composed after om/tls/sha2.om). |
| 2 | note It runs outside the forged sandbox, beside the research agent: forged has no network. It turns |
| 3 | note requests that signed-in Radicle keys queued (research/route.om) and public metadata into registry |
| 4 | note lines for authors other than the registry's own (README.md "Other authors"). Every byte it |
| 5 | note reads from a repository, from Zenodo or from the queue is untrusted: each field is checked, |
| 6 | note decoded to one line, cut to the README's limits and written only through these checks. |
| 7 | note research-sync zenodo ORCID DID DATE AUTHOR stdin: jflat lines of Zenodo search responses |
| 8 | note research-sync repo RID DID DATE AUTHOR [COMMIT SHA256 | plan] stdin: jflat lines of .zenodo.json, "@tree", git ls-tree -l |
| 9 | note research-sync text stdin: plain text; stdout: one paragraph a line |
| 10 | note research-sync queue ADDDIR/ STATE ALLOW REMOVE REGDIR/ stdout: the accepted requests |
| 11 | note research-sync layout raw|selected stdin: one catalog; stdout: lossless bound bundles |
| 12 | note research-sync gather REMOVE SHELFLIST stdin: an author's raw catalogs; stdout: what may be shown |
| 13 | note research-sync compact ADDDIR/ STATE called under the shared queue.lock |
| 14 | note research-sync onshelf SHELFLIST RID DID exit 0 when the shelf lists RID as brought by DID |
| 15 | note research-sync bind SEQ TEXTDIR/ stdin: one import's catalog; stdout: it with R and T |
| 16 | note zenodo and repo write registry lines on stdout, one "slug <tab> source" line per work |
| 17 | note whose full text may be copied on descriptor 3, and one line per refusal or dropped link on |
| 18 | note stderr. A record is listed only when its creators carry ORCID (zenodo mode); full text only when |
| 19 | note the licence is on the open list (kopen). Exit 0 done, 1 refused (stderr says why), 2 usage or |
| 20 | note input this program does not accept (over 8 MiB, an argument that is not well formed). |
| 21 | global ib uchar 8388608 |
| 22 | global ibl ulong 1 |
| 23 | global ob uchar 4194304 |
| 24 | global obl ulong 1 |
| 25 | global oof ulong 1 |
| 26 | global tb uchar 65536 |
| 27 | global tbl ulong 1 |
| 28 | global lb uchar 65536 |
| 29 | global lbl ulong 1 |
| 30 | global av uchar 4096 |
| 31 | global avl ulong 8 |
| 32 | global sg uchar 80 |
| 33 | global sgl ulong 1 |
| 34 | global hs ulong 1 |
| 35 | global he ulong 1 |
| 36 | global hpl ulong 1 |
| 37 | global gn ulong 4 |
| 38 | global rb uchar 65536 |
| 39 | global rbl ulong 1 |
| 40 | global rerr ulong 1 |
| 41 | global pfail ulong 1 |
| 42 | global lamb ulong 1 |
| 43 | text mpolicy "refused: POLICY_READ: allow/remove file read, type or size error" |
| 44 | global qb uchar 65536 |
| 45 | global pth uchar 1100 |
| 46 | global pthl ulong 1 |
| 47 | global pt2 uchar 1100 |
| 48 | global rpk uchar 2300 |
| 49 | note gather's bundles, one cell each: an 8 MiB input holds at most 2796203 W lines of 3 bytes |
| 50 | global gbw ulong 2796203 |
| 51 | global gbe ulong 2796203 |
| 52 | global gbp ulong 2796203 |
| 53 | global gbg ulong 2796203 |
| 54 | global gbs ulong 2796203 |
| 55 | global gbk ulong 2796203 |
| 56 | global gbl ulong 2796203 |
| 57 | global gbsel uchar 2796203 |
| 58 | note gxs: start of the first X line of gather's input (ibl when absent). Bundles after it are |
| 59 | note auxiliary evidence: they deny and close copies of selected work but are never selected. |
| 60 | global gxs ulong 1 |
| 61 | global dg uchar 32 |
| 62 | text khits "/hits/hits/" |
| 63 | text kmeta "/metadata" |
| 64 | text knone "" |
| 65 | text kid "/id" |
| 66 | text kdoi "/doi" |
| 67 | text kcdoi "/conceptdoi" |
| 68 | text ktitle "/title" |
| 69 | text kdesc "/description" |
| 70 | text kdate "/publication_date" |
| 71 | text klic "/license/id" |
| 72 | text klics "/license" |
| 73 | text ksub "/resource_type/subtype" |
| 74 | text ktyp "/resource_type/type" |
| 75 | text kupt "/upload_type" |
| 76 | text kput "/publication_type" |
| 77 | text kver "/version" |
| 78 | text kvix "/relations/version/0/index" |
| 79 | text kcor "/creators/*/orcid" |
| 80 | text kcnm "/creators/*/name" |
| 81 | text kkw "/keywords/*" |
| 82 | text kri "/related_identifiers/*/identifier" |
| 83 | text krr "/related_identifiers/*/relation" |
| 84 | text kfk "/files/*/key" |
| 85 | text kfs "/files/*/size" |
| 86 | text kfl "/files/*/links/self" |
| 87 | text kopen " cc-by-4.0 cc-by-sa-4.0 cc0-1.0 cc-by-3.0 cc-by-sa-3.0 " |
| 88 | text khttps "https://" |
| 89 | text kzrec "https://zenodo.org/records/" |
| 90 | text kzen "Zenodo" |
| 91 | text krad "Radicle" |
| 92 | text krp "rad:" |
| 93 | text kart "article" |
| 94 | text kjart "journal-article" |
| 95 | text ktree "@tree" |
| 96 | text kos "O\tid\t" |
| 97 | text kon "O\tname\t" |
| 98 | text koo "O\torcid\t" |
| 99 | text koa "O\tadded-by\t" |
| 100 | text koc "O\tchecked\t" |
| 101 | text kov "O\tvia\t" |
| 102 | text kzv "zenodo" |
| 103 | text krv "radicle" |
| 104 | text ksep "; " |
| 105 | text kand " and " |
| 106 | text kmode1 "zenodo" |
| 107 | text kmode2 "repo" |
| 108 | text kmode3 "text" |
| 109 | text kmode4 "queue" |
| 110 | text kmode5 "gather" |
| 111 | text kmode6 "onshelf" |
| 112 | text kmode9 "policies" |
| 113 | text kmode8 "compact" |
| 114 | text kmode7 "identify" |
| 115 | text kplan "plan" |
| 116 | text kq "queue" |
| 117 | text kxt ".tmp" |
| 118 | text kaut "a/" |
| 119 | text kkey "key-" |
| 120 | text khex "0123456789abcdef" |
| 121 | text kzpre "10.5281/zenodo." |
| 122 | text kst1 "open" |
| 123 | text kst2 "stored" |
| 124 | text kst3 "held" |
| 125 | text kpaper1 "paper.md" |
| 126 | text kpaper2 "paper.txt" |
| 127 | text kpaper3 "paper.pdf" |
| 128 | text klic1 "LICENSE" |
| 129 | text klic2 "LICENSE.md" |
| 130 | text klic3 "LICENSE.txt" |
| 131 | text klic4 "LICENCE" |
| 132 | text klic5 "COPYING" |
| 133 | text mref "refused " |
| 134 | text mown " the Zenodo record does not name ORCID iD " |
| 135 | text mown2 " among its creators" |
| 136 | text mmany " more than 200 records for one author" |
| 137 | text mnoid "a record without a record number" |
| 138 | text mnot " has no title" |
| 139 | text mlink "dropped link " |
| 140 | text mlink2 " (not https)" |
| 141 | text mlisted "listed " |
| 142 | text mrefd " refused " |
| 143 | text mbig "research-sync: input is 8388608 bytes or longer\n" |
| 144 | text mfull "research-sync: output is 4194304 bytes or longer\n" |
| 145 | text mrt "refused: .zenodo.json has no title" |
| 146 | text mrc "refused: .zenodo.json names no creator" |
| 147 | text mrl "refused: .zenodo.json names no license" |
| 148 | text mrf "refused: the repository has no LICENSE file at its top level" |
| 149 | text mrp "refused: the repository has no paper.md, paper.txt or paper.pdf at its top level" |
| 150 | text mqbad "refused: a malformed queue line" |
| 151 | text mqallow "refused: the key is not allowed to add work (the shelf's allow file)" |
| 152 | text mqrem "refused: the operator's remove file names this key, repository, ORCID iD or DOI" |
| 153 | text kdidp "did:key:z" |
| 154 | text kblob "100" |
| 155 | text k10 "10." |
| 156 | text krec "record" |
| 157 | text kwt "W\t" |
| 158 | text kpt "P\t" |
| 159 | text kone "1" |
| 160 | text kmode10 "bind" |
| 161 | text ktxt ".txt" |
| 162 | text kamb "ambiguous" |
| 163 | text kobject "{" |
| 164 | text karray "[" |
| 165 | text kemptyo "{}" |
| 166 | text kemptya "[]" |
| 167 | text mmeta " invalid or ambiguous metadata container" |
| 168 | text mprofile "refused: MIXED_PROFILE_LAYOUT: normalise header selections before appending raw imports" |
| 169 | text kbr "R\t" |
| 170 | text kbt "T\t" |
| 171 | text mamb " has ambiguous or invalid licence/metadata fields; no full text" |
| 172 | text kmode11 "layout" |
| 173 | text kraw "raw" |
| 174 | text ksel "selected" |
| 175 | text kni "I\t" |
| 176 | text knn "N\t" |
| 177 | text kzero "0" |
| 178 | text knid "id\t" |
| 179 | text knname "name\t" |
| 180 | text kob "O\t" |
| 181 | text korc "orcid\t" |
| 182 | text kna "added-by\t" |
| 183 | text knc "checked\t" |
| 184 | text knv "via\t" |
| 185 | text mlayout "refused: LAYOUT_INPUT: raw layout takes one raw catalog; N, I and X records are not raw" |
| 186 | text mbind "refused: PROFILE_BINDING: a bundle's N/I facts are missing, repeated or name another slug" |
| 187 | text munbound "refused: SELECTED_PROFILE_UNBOUND: this selection lacks complete per-bundle profile facts; rebuild it from retained raw catalogs (layout raw each file, then one gather); do not infer association from shared O" |
| 188 | text maux "refused: AUX_LAYOUT: evidence after the X line must be laid-out bundles without O lines" |
| 189 | note ---- output: stdout (ob), descriptor 3 (tb), stderr (lb) |
| 190 | fn emb c uchar to void |
| 191 | o = get obl 0 |
| 192 | if lt o 4194304 |
| 193 | put ob o c |
| 194 | put obl 0 add o 1 |
| 195 | else |
| 196 | put oof 0 1 |
| 197 | end |
| 198 | end |
| 199 | fn em t view uchar * to void |
| 200 | for i ulong len t bound 65536 |
| 201 | emb get t i |
| 202 | end |
| 203 | end |
| 204 | fn emn v ulong to void |
| 205 | d = new uchar 20 0 |
| 206 | n = ulong 0 |
| 207 | x = v |
| 208 | if eq x 0 |
| 209 | emb 48 |
| 210 | end |
| 211 | while gt x 0 bound 20 |
| 212 | put d n uchar add 48 rem x 10 |
| 213 | x = div x 10 |
| 214 | n = add n 1 |
| 215 | end |
| 216 | while gt n 0 bound 20 |
| 217 | n = sub n 1 |
| 218 | emb get d n |
| 219 | end |
| 220 | end |
| 221 | fn emr a ulong b ulong to void |
| 222 | i = a |
| 223 | while lt i b bound 8388608 |
| 224 | emb get ib i |
| 225 | i = add i 1 |
| 226 | end |
| 227 | end |
| 228 | fn tbb c uchar to void |
| 229 | o = get tbl 0 |
| 230 | if lt o 65536 |
| 231 | put tb o c |
| 232 | put tbl 0 add o 1 |
| 233 | else |
| 234 | put oof 0 1 |
| 235 | end |
| 236 | end |
| 237 | fn lgb c uchar to void |
| 238 | o = get lbl 0 |
| 239 | if lt o 65000 |
| 240 | put lb o c |
| 241 | put lbl 0 add o 1 |
| 242 | end |
| 243 | end |
| 244 | fn lgt t view uchar * to void |
| 245 | for i ulong len t bound 4096 |
| 246 | lgb get t i |
| 247 | end |
| 248 | end |
| 249 | fn lgn v ulong to void |
| 250 | d = new uchar 20 0 |
| 251 | n = ulong 0 |
| 252 | x = v |
| 253 | if eq x 0 |
| 254 | lgb 48 |
| 255 | end |
| 256 | while gt x 0 bound 20 |
| 257 | put d n uchar add 48 rem x 10 |
| 258 | x = div x 10 |
| 259 | n = add n 1 |
| 260 | end |
| 261 | while gt n 0 bound 20 |
| 262 | n = sub n 1 |
| 263 | lgb get d n |
| 264 | end |
| 265 | end |
| 266 | note lgr: ib[a, b) into the log as printable ASCII (anything else becomes ?), at most 200 bytes |
| 267 | fn lgr a ulong b ulong to void |
| 268 | e = b |
| 269 | if gt sub b a 200 |
| 270 | e = add a 200 |
| 271 | end |
| 272 | i = a |
| 273 | while lt i e bound 200 |
| 274 | c = get ib i |
| 275 | if or lt c 32 gt c 126 |
| 276 | c = uchar 63 |
| 277 | end |
| 278 | lgb c |
| 279 | i = add i 1 |
| 280 | end |
| 281 | end |
| 282 | fn flush fd int b view uchar * n ulong to bool |
| 283 | o = ulong 0 |
| 284 | while lt o n bound 8388608 |
| 285 | k = write fd b o sub n o |
| 286 | if le k 0 |
| 287 | ret false |
| 288 | end |
| 289 | o = add o ulong k |
| 290 | end |
| 291 | ret true |
| 292 | end |
| 293 | note Global arrays cannot be passed to user functions at the pinned compiler. Stream local windows. |
| 294 | fn flushg fd int n ulong to bool |
| 295 | b = new uchar 4096 0 |
| 296 | o = ulong 0 |
| 297 | while lt o n bound 4194304 |
| 298 | m = sub n o |
| 299 | if gt m 4096 |
| 300 | m = ulong 4096 |
| 301 | end |
| 302 | for i ulong m bound 4096 |
| 303 | if eq fd 1 |
| 304 | put b i get ob add o i |
| 305 | end |
| 306 | if eq fd 2 |
| 307 | put b i get lb add o i |
| 308 | end |
| 309 | if eq fd 3 |
| 310 | put b i get tb add o i |
| 311 | end |
| 312 | end |
| 313 | if not flush fd b m |
| 314 | ret false |
| 315 | end |
| 316 | o = add o m |
| 317 | end |
| 318 | ret true |
| 319 | end |
| 320 | fn done rc int to int |
| 321 | x = flushg 2 get lbl 0 |
| 322 | if ne get oof 0 0 |
| 323 | x = flush 2 mfull len mfull |
| 324 | ret 2 |
| 325 | end |
| 326 | if not flushg 1 get obl 0 |
| 327 | ret 2 |
| 328 | end |
| 329 | if gt get tbl 0 0 |
| 330 | if not flushg 3 get tbl 0 |
| 331 | ret 2 |
| 332 | end |
| 333 | end |
| 334 | ret rc |
| 335 | end |
| 336 | note ---- arguments: argument k into av[512 k, ...), its length into avl k |
| 337 | fn arg k ulong to ulong |
| 338 | b = new uchar 512 0 |
| 339 | n = argread k b 0 500 |
| 340 | if or le n 0 ge n 500 |
| 341 | put avl k 0 |
| 342 | ret 0 |
| 343 | end |
| 344 | m = ulong n |
| 345 | o = mul k 512 |
| 346 | for i ulong m bound 512 |
| 347 | put av add o i get b i |
| 348 | end |
| 349 | put avl k m |
| 350 | ret m |
| 351 | end |
| 352 | fn ava k ulong i ulong to uchar |
| 353 | ret get av add mul k 512 i |
| 354 | end |
| 355 | fn ema k ulong to void |
| 356 | for i ulong get avl k bound 512 |
| 357 | emb ava k i |
| 358 | end |
| 359 | end |
| 360 | fn lga k ulong to void |
| 361 | for i ulong get avl k bound 512 |
| 362 | lgb ava k i |
| 363 | end |
| 364 | end |
| 365 | fn argeq k ulong t view uchar * to bool |
| 366 | if ne get avl k len t |
| 367 | ret false |
| 368 | end |
| 369 | for i ulong len t bound 64 |
| 370 | if ne ava k i get t i |
| 371 | ret false |
| 372 | end |
| 373 | end |
| 374 | ret true |
| 375 | end |
| 376 | note shl1: move arguments 2.. down one slot (the mode word leaves slot 1) |
| 377 | fn shl1 to void |
| 378 | for k ulong 6 |
| 379 | for i ulong get avl add k 2 bound 512 |
| 380 | put av add mul add k 1 512 i ava add k 2 i |
| 381 | end |
| 382 | put avl add k 1 get avl add k 2 |
| 383 | end |
| 384 | put avl 7 0 |
| 385 | end |
| 386 | note ---- checks on bytes |
| 387 | fn isdig c uchar to bool |
| 388 | ret and ge c 48 le c 57 |
| 389 | end |
| 390 | fn islow c uchar to bool |
| 391 | ret and ge c 97 le c 122 |
| 392 | end |
| 393 | fn lowc c uchar to uchar |
| 394 | if and ge c 65 le c 90 |
| 395 | ret uchar add c 32 |
| 396 | end |
| 397 | ret c |
| 398 | end |
| 399 | fn b58 c uchar to bool |
| 400 | if isdig c |
| 401 | ret ne c 48 |
| 402 | end |
| 403 | if and ge c 65 le c 90 |
| 404 | ret and ne c 73 ne c 79 |
| 405 | end |
| 406 | if islow c |
| 407 | ret ne c 108 |
| 408 | end |
| 409 | ret false |
| 410 | end |
| 411 | note orcok: argument k is an ORCID iD: dddd-dddd-dddd-dddX with its ISO 7064 11,2 check character |
| 412 | fn orcok k ulong to bool |
| 413 | if ne get avl k 19 |
| 414 | ret false |
| 415 | end |
| 416 | t = ulong 0 |
| 417 | for i ulong 19 |
| 418 | c = ava k i |
| 419 | if or eq i 4 or eq i 9 eq i 14 |
| 420 | if ne c 45 |
| 421 | ret false |
| 422 | end |
| 423 | else |
| 424 | if lt i 18 |
| 425 | if not isdig c |
| 426 | ret false |
| 427 | end |
| 428 | t = mul add t ulong sub c 48 2 |
| 429 | end |
| 430 | end |
| 431 | end |
| 432 | r = rem sub 12 rem t 11 11 |
| 433 | c = ava k 18 |
| 434 | if eq r 10 |
| 435 | ret eq c 88 |
| 436 | end |
| 437 | ret eq c uchar add 48 r |
| 438 | end |
| 439 | note didok: argument k is did:key:z followed by 1 to 87 base58 characters |
| 440 | fn didok k ulong to bool |
| 441 | n = get avl k |
| 442 | if or lt n 10 gt n 96 |
| 443 | ret false |
| 444 | end |
| 445 | for i ulong 9 |
| 446 | if ne ava k i get kdidp i |
| 447 | ret false |
| 448 | end |
| 449 | end |
| 450 | for i ulong sub n 9 bound 96 |
| 451 | if not b58 ava k add 9 i |
| 452 | ret false |
| 453 | end |
| 454 | end |
| 455 | ret true |
| 456 | end |
| 457 | note ridok: argument k is z followed by 19 to 43 base58 characters (the shelf's rule, rad: dropped) |
| 458 | fn ridok k ulong to bool |
| 459 | n = get avl k |
| 460 | if or lt n 20 gt n 44 |
| 461 | ret false |
| 462 | end |
| 463 | if ne ava k 0 122 |
| 464 | ret false |
| 465 | end |
| 466 | for i ulong n bound 44 |
| 467 | if not b58 ava k i |
| 468 | ret false |
| 469 | end |
| 470 | end |
| 471 | ret true |
| 472 | end |
| 473 | note autok: argument k is an author id: 1 to 64 bytes of a-z, 0-9 and - |
| 474 | fn autok k ulong to bool |
| 475 | n = get avl k |
| 476 | if or eq n 0 gt n 64 |
| 477 | ret false |
| 478 | end |
| 479 | for i ulong n bound 64 |
| 480 | c = ava k i |
| 481 | if not or or isdig c islow c eq c 45 |
| 482 | ret false |
| 483 | end |
| 484 | end |
| 485 | ret true |
| 486 | end |
| 487 | fn dateok k ulong to bool |
| 488 | if ne get avl k 10 |
| 489 | ret false |
| 490 | end |
| 491 | for i ulong 10 |
| 492 | c = ava k i |
| 493 | if or eq i 4 eq i 7 |
| 494 | if ne c 45 |
| 495 | ret false |
| 496 | end |
| 497 | else |
| 498 | if not isdig c |
| 499 | ret false |
| 500 | end |
| 501 | end |
| 502 | end |
| 503 | ret true |
| 504 | end |
| 505 | note ---- the input |
| 506 | fn rdin to bool |
| 507 | n = ulong 0 |
| 508 | k = long 1 |
| 509 | while gt k 0 bound 8388608 |
| 510 | if ge n 8388607 |
| 511 | ret false |
| 512 | end |
| 513 | k = read 0 ib n sub 8388607 n |
| 514 | if gt k 0 |
| 515 | n = add n ulong k |
| 516 | end |
| 517 | end |
| 518 | put ibl 0 n |
| 519 | ret true |
| 520 | end |
| 521 | fn eol a ulong to ulong |
| 522 | i = a |
| 523 | n = get ibl 0 |
| 524 | while lt i n bound 8388608 |
| 525 | if eq get ib i 10 |
| 526 | ret i |
| 527 | end |
| 528 | i = add i 1 |
| 529 | end |
| 530 | ret n |
| 531 | end |
| 532 | fn tabat a ulong e ulong to ulong |
| 533 | i = a |
| 534 | while lt i e bound 8388608 |
| 535 | if eq get ib i 9 |
| 536 | ret i |
| 537 | end |
| 538 | i = add i 1 |
| 539 | end |
| 540 | ret e |
| 541 | end |
| 542 | fn lpre a ulong e ulong t view uchar * to bool |
| 543 | n = len t |
| 544 | if lt e a |
| 545 | ret false |
| 546 | end |
| 547 | if lt sub e a n |
| 548 | ret false |
| 549 | end |
| 550 | for i ulong n bound 256 |
| 551 | if ne get ib add a i get t i |
| 552 | ret false |
| 553 | end |
| 554 | end |
| 555 | ret true |
| 556 | end |
| 557 | fn reqt a ulong b ulong t view uchar * to bool |
| 558 | if lt b a |
| 559 | ret false |
| 560 | end |
| 561 | if ne sub b a len t |
| 562 | ret false |
| 563 | end |
| 564 | ret lpre a b t |
| 565 | end |
| 566 | fn feqr a ulong b ulong c ulong d ulong to bool |
| 567 | if or lt b a lt d c |
| 568 | ret false |
| 569 | end |
| 570 | if ne sub b a sub d c |
| 571 | ret false |
| 572 | end |
| 573 | i = ulong 0 |
| 574 | while lt i sub b a bound 8388608 |
| 575 | if ne get ib add a i get ib add c i |
| 576 | ret false |
| 577 | end |
| 578 | i = add i 1 |
| 579 | end |
| 580 | ret true |
| 581 | end |
| 582 | note sfield: start of field f (0 based) of the line ib[a, e); e when the line has fewer fields |
| 583 | fn sfield a ulong e ulong f ulong to ulong |
| 584 | p = a |
| 585 | j = ulong 0 |
| 586 | while lt j f bound 16 |
| 587 | while lt p e bound 8388608 |
| 588 | if eq get ib p 9 |
| 589 | break |
| 590 | end |
| 591 | p = add p 1 |
| 592 | end |
| 593 | if ge p e |
| 594 | ret e |
| 595 | end |
| 596 | p = add p 1 |
| 597 | j = add j 1 |
| 598 | end |
| 599 | ret p |
| 600 | end |
| 601 | note ---- jflat paths. A hit is the run of lines whose path starts /hits/hits/<n>/ (zenodo) or the |
| 602 | note whole input up to "@tree" (repo). hpl is the length of the hit prefix of each line. |
| 603 | note pmat: the path ib[p, e) is pre followed by pat, where * in pat stands for a decimal index of |
| 604 | note 1 to 12 digits: k when k < 1000000, any index otherwise. The matched index (0 without *), or -1. |
| 605 | fn pindex p ulong e ulong k ulong to ulong |
| 606 | q = p |
| 607 | v = ulong 0 |
| 608 | while lt q e bound 8388608 |
| 609 | c = get ib q |
| 610 | if not isdig c |
| 611 | break |
| 612 | end |
| 613 | if ge sub q p 12 |
| 614 | ret get ibl 0 |
| 615 | end |
| 616 | v = add mul v 10 ulong sub c 48 |
| 617 | q = add q 1 |
| 618 | end |
| 619 | if eq q p |
| 620 | ret get ibl 0 |
| 621 | end |
| 622 | if and lt k 1000000 ne v k |
| 623 | ret get ibl 0 |
| 624 | end |
| 625 | put gn 3 v |
| 626 | ret q |
| 627 | end |
| 628 | fn pmat p ulong pre view uchar * pat view uchar * k ulong to long |
| 629 | e = tabat p eol p |
| 630 | q = p |
| 631 | for i ulong len pre bound 64 |
| 632 | if ge q e |
| 633 | ret -1 |
| 634 | end |
| 635 | if ne get ib q get pre i |
| 636 | ret -1 |
| 637 | end |
| 638 | q = add q 1 |
| 639 | end |
| 640 | got = long 0 |
| 641 | for i ulong len pat bound 128 |
| 642 | if eq get pat i 42 |
| 643 | q = pindex q e k |
| 644 | if ge q get ibl 0 |
| 645 | ret -1 |
| 646 | end |
| 647 | got = long get gn 3 |
| 648 | else |
| 649 | if ge q e |
| 650 | ret -1 |
| 651 | end |
| 652 | if ne get ib q get pat i |
| 653 | ret -1 |
| 654 | end |
| 655 | q = add q 1 |
| 656 | end |
| 657 | end |
| 658 | if ne q e |
| 659 | ret -1 |
| 660 | end |
| 661 | ret got |
| 662 | end |
| 663 | note hfind: the first line at or after s in the hit whose path matches; he when none |
| 664 | fn hfind s ulong pre view uchar * pat view uchar * k ulong to ulong |
| 665 | l = s |
| 666 | e = get he 0 |
| 667 | while lt l e bound 8388608 |
| 668 | ln = eol l |
| 669 | t = tabat l ln |
| 670 | if lt t ln |
| 671 | if ge pmat add l get hpl 0 pre pat k 0 |
| 672 | ret l |
| 673 | end |
| 674 | end |
| 675 | l = add ln 1 |
| 676 | end |
| 677 | ret e |
| 678 | end |
| 679 | note hidx: the index the line l matched (pmat again) |
| 680 | fn hidx l ulong pre view uchar * pat view uchar * to ulong |
| 681 | ln = eol l |
| 682 | t = tabat l ln |
| 683 | r = pmat add l get hpl 0 pre pat 1000000 |
| 684 | if lt r 0 |
| 685 | ret 0 |
| 686 | end |
| 687 | ret ulong r |
| 688 | end |
| 689 | fn vala l ulong to ulong |
| 690 | ln = eol l |
| 691 | t = tabat l ln |
| 692 | if lt t ln |
| 693 | ret add t 1 |
| 694 | end |
| 695 | ret ln |
| 696 | end |
| 697 | fn valb l ulong to ulong |
| 698 | ret eol l |
| 699 | end |
| 700 | fn hval pre view uchar * pat view uchar * to ulong |
| 701 | ret hfind get hs 0 pre pat 0 |
| 702 | end |
| 703 | note ---- one field. emv writes the jflat value ib[a, b) as one registry field: \n and \t become a |
| 704 | note space, \\ a backslash, other control bytes are dropped, runs of spaces become one, no space at |
| 705 | note either end, at most cap bytes and never part of a UTF-8 character (a malformed byte becomes ?). |
| 706 | note The bytes written. |
| 707 | fn u8len a ulong b ulong to ulong |
| 708 | c = get ib a |
| 709 | if lt c 128 |
| 710 | ret 1 |
| 711 | end |
| 712 | n = ulong 0 |
| 713 | lo = uchar 128 |
| 714 | hi = uchar 191 |
| 715 | if and ge c 194 le c 223 |
| 716 | n = ulong 2 |
| 717 | end |
| 718 | if and ge c 224 le c 239 |
| 719 | n = ulong 3 |
| 720 | if eq c 224 |
| 721 | lo = uchar 160 |
| 722 | end |
| 723 | if eq c 237 |
| 724 | hi = uchar 159 |
| 725 | end |
| 726 | end |
| 727 | if and ge c 240 le c 244 |
| 728 | n = ulong 4 |
| 729 | if eq c 240 |
| 730 | lo = uchar 144 |
| 731 | end |
| 732 | if eq c 244 |
| 733 | hi = uchar 143 |
| 734 | end |
| 735 | end |
| 736 | if or eq n 0 gt add a n b |
| 737 | ret 0 |
| 738 | end |
| 739 | d = get ib add a 1 |
| 740 | if or lt d lo gt d hi |
| 741 | ret 0 |
| 742 | end |
| 743 | for j ulong sub n 2 bound 4 |
| 744 | d = get ib add add a 2 j |
| 745 | if or lt d 128 gt d 191 |
| 746 | ret 0 |
| 747 | end |
| 748 | end |
| 749 | ret n |
| 750 | end |
| 751 | note Preserve markup as text. The builder escapes it for each output format. No HTML is trusted. |
| 752 | fn emv a ulong b ulong cap ulong to ulong |
| 753 | w = ulong 0 |
| 754 | pend = false |
| 755 | i = a |
| 756 | while lt i b bound 8388608 |
| 757 | c = get ib i |
| 758 | n = ulong 1 |
| 759 | if eq c 92 |
| 760 | if lt add i 1 b |
| 761 | n = ulong 2 |
| 762 | c = get ib add i 1 |
| 763 | if or eq c 110 eq c 116 |
| 764 | c = uchar 32 |
| 765 | end |
| 766 | end |
| 767 | end |
| 768 | if or le c 32 eq c 127 |
| 769 | if gt w 0 |
| 770 | pend = true |
| 771 | end |
| 772 | else |
| 773 | k = ulong 1 |
| 774 | if ge c 128 |
| 775 | k = u8len i b |
| 776 | if eq k 0 |
| 777 | c = uchar 63 |
| 778 | k = ulong 1 |
| 779 | else |
| 780 | n = k |
| 781 | end |
| 782 | end |
| 783 | if pend |
| 784 | if gt add add w k 1 cap |
| 785 | ret w |
| 786 | end |
| 787 | emb 32 |
| 788 | w = add w 1 |
| 789 | pend = false |
| 790 | end |
| 791 | if gt add w k cap |
| 792 | ret w |
| 793 | end |
| 794 | if ge c 128 |
| 795 | emr i add i k |
| 796 | else |
| 797 | emb c |
| 798 | end |
| 799 | w = add w k |
| 800 | end |
| 801 | i = add i n |
| 802 | end |
| 803 | ret w |
| 804 | end |
| 805 | note urlok: ib[a, b) is an https URL of at most 400 printable bytes without quote, angle bracket, |
| 806 | note backslash or backtick |
| 807 | fn urlok a ulong b ulong to bool |
| 808 | if lt b a |
| 809 | ret false |
| 810 | end |
| 811 | if or gt sub b a 400 le sub b a len khttps |
| 812 | ret false |
| 813 | end |
| 814 | if not lpre a b khttps |
| 815 | ret false |
| 816 | end |
| 817 | i = a |
| 818 | while lt i b bound 400 |
| 819 | c = get ib i |
| 820 | if or le c 32 ge c 127 |
| 821 | ret false |
| 822 | end |
| 823 | if or or eq c 34 eq c 39 or or eq c 60 eq c 62 or eq c 92 eq c 96 |
| 824 | ret false |
| 825 | end |
| 826 | i = add i 1 |
| 827 | end |
| 828 | ret true |
| 829 | end |
| 830 | note doiok: ib[a, b) is a DOI: 10.<digits>/<1 to 90 printable bytes without quote, angle bracket, |
| 831 | note backslash or space> |
| 832 | fn doiok a ulong b ulong to bool |
| 833 | if lt b a |
| 834 | ret false |
| 835 | end |
| 836 | if or lt sub b a 6 gt sub b a 120 |
| 837 | ret false |
| 838 | end |
| 839 | if not lpre a b k10 |
| 840 | ret false |
| 841 | end |
| 842 | i = add a 3 |
| 843 | s = i |
| 844 | while lt i b bound 120 |
| 845 | if not isdig get ib i |
| 846 | break |
| 847 | end |
| 848 | i = add i 1 |
| 849 | end |
| 850 | if or eq i s ge i b |
| 851 | ret false |
| 852 | end |
| 853 | if ne get ib i 47 |
| 854 | ret false |
| 855 | end |
| 856 | i = add i 1 |
| 857 | if or eq i b gt sub b i 90 |
| 858 | ret false |
| 859 | end |
| 860 | while lt i b bound 120 |
| 861 | c = get ib i |
| 862 | if or le c 32 ge c 127 |
| 863 | ret false |
| 864 | end |
| 865 | if or or eq c 34 eq c 39 or or eq c 60 eq c 62 eq c 92 |
| 866 | ret false |
| 867 | end |
| 868 | i = add i 1 |
| 869 | end |
| 870 | ret true |
| 871 | end |
| 872 | fn vdate a ulong b ulong to bool |
| 873 | if lt b a |
| 874 | ret false |
| 875 | end |
| 876 | if ne sub b a 10 |
| 877 | ret false |
| 878 | end |
| 879 | for i ulong 10 |
| 880 | c = get ib add a i |
| 881 | if or eq i 4 eq i 7 |
| 882 | if ne c 45 |
| 883 | ret false |
| 884 | end |
| 885 | else |
| 886 | if not isdig c |
| 887 | ret false |
| 888 | end |
| 889 | end |
| 890 | end |
| 891 | ret true |
| 892 | end |
| 893 | fn alldig a ulong b ulong to bool |
| 894 | if le b a |
| 895 | ret false |
| 896 | end |
| 897 | if gt sub b a 12 |
| 898 | ret false |
| 899 | end |
| 900 | i = a |
| 901 | while lt i b bound 12 |
| 902 | if not isdig get ib i |
| 903 | ret false |
| 904 | end |
| 905 | i = add i 1 |
| 906 | end |
| 907 | ret true |
| 908 | end |
| 909 | fn dnum a ulong b ulong to ulong |
| 910 | v = ulong 0 |
| 911 | i = a |
| 912 | while lt i b bound 12 |
| 913 | v = add mul v 10 ulong sub get ib i 48 |
| 914 | i = add i 1 |
| 915 | end |
| 916 | ret v |
| 917 | end |
| 918 | note emw: ib[a, b) lowercased, keeping a-z 0-9 . - only, at most cap bytes (licence, kind, relation) |
| 919 | fn emw a ulong b ulong cap ulong to void |
| 920 | w = ulong 0 |
| 921 | i = a |
| 922 | while lt i b bound 8388608 |
| 923 | c = lowc get ib i |
| 924 | if or or isdig c islow c or eq c 45 eq c 46 |
| 925 | if lt w cap |
| 926 | emb c |
| 927 | w = add w 1 |
| 928 | end |
| 929 | end |
| 930 | i = add i 1 |
| 931 | end |
| 932 | end |
| 933 | note isopen: the licence id ib[a, b) (any case) is on the open list kopen |
| 934 | fn isopen a ulong b ulong to bool |
| 935 | if le b a |
| 936 | ret false |
| 937 | end |
| 938 | n = sub b a |
| 939 | if gt n 32 |
| 940 | ret false |
| 941 | end |
| 942 | m = len kopen |
| 943 | s = ulong 0 |
| 944 | while lt add s add n 1 m bound 256 |
| 945 | if eq get kopen s 32 |
| 946 | hit = true |
| 947 | for i ulong n bound 32 |
| 948 | if ne lowc get ib add a i get kopen add add s 1 i |
| 949 | hit = false |
| 950 | break |
| 951 | end |
| 952 | end |
| 953 | if hit |
| 954 | if eq get kopen add add s 1 n 32 |
| 955 | ret true |
| 956 | end |
| 957 | end |
| 958 | end |
| 959 | s = add s 1 |
| 960 | end |
| 961 | ret false |
| 962 | end |
| 963 | note Count container occurrences too: duplicate licence objects with disjoint children must not |
| 964 | note disappear when flattened. One ordinary object marker plus one id is one decision, not two. |
| 965 | fn badcontainer a ulong b ulong to bool |
| 966 | if or reqt a b kobject reqt a b karray |
| 967 | ret true |
| 968 | end |
| 969 | ret or reqt a b kemptyo reqt a b kemptya |
| 970 | end |
| 971 | fn metacount to ulong |
| 972 | n = ulong 0 |
| 973 | l = hfind get hs 0 knone kmeta 0 |
| 974 | while lt l get he 0 bound 8388608 |
| 975 | if not reqt vala l valb l kobject |
| 976 | ret 2 |
| 977 | end |
| 978 | n = add n 1 |
| 979 | l = hfind add eol l 1 knone kmeta 0 |
| 980 | end |
| 981 | ret n |
| 982 | end |
| 983 | fn lcount pre view uchar * to ulong |
| 984 | if gt len pre 0 |
| 985 | if gt metacount 1 |
| 986 | ret 2 |
| 987 | end |
| 988 | end |
| 989 | n = ulong 0 |
| 990 | l = hfind get hs 0 pre klic 0 |
| 991 | while lt l get he 0 bound 8388608 |
| 992 | if badcontainer vala l valb l |
| 993 | ret 2 |
| 994 | end |
| 995 | n = add n 1 |
| 996 | l = hfind add eol l 1 pre klic 0 |
| 997 | end |
| 998 | objects = ulong 0 |
| 999 | scalars = ulong 0 |
| 1000 | l = hfind get hs 0 pre klics 0 |
| 1001 | while lt l get he 0 bound 8388608 |
| 1002 | a = vala l |
| 1003 | b = valb l |
| 1004 | if reqt a b kobject |
| 1005 | objects = add objects 1 |
| 1006 | else |
| 1007 | if badcontainer a b |
| 1008 | ret 2 |
| 1009 | end |
| 1010 | scalars = add scalars 1 |
| 1011 | end |
| 1012 | l = hfind add eol l 1 pre klics 0 |
| 1013 | end |
| 1014 | if gt objects 1 |
| 1015 | ret 2 |
| 1016 | end |
| 1017 | if eq objects 1 |
| 1018 | if gt scalars 0 |
| 1019 | ret 2 |
| 1020 | end |
| 1021 | ret n |
| 1022 | end |
| 1023 | if and gt len pre 0 gt scalars 0 |
| 1024 | ret 2 |
| 1025 | end |
| 1026 | ret add n scalars |
| 1027 | end |
| 1028 | note ---- the slug: the title lowercased, a-z and 0-9 kept, any other run one -, at most 40 bytes, |
| 1029 | note then - and the suffix (a record number, or r and the first letters of a repository id) |
| 1030 | fn sgc c uchar to void |
| 1031 | n = get sgl 0 |
| 1032 | if lt n 80 |
| 1033 | put sg n c |
| 1034 | put sgl 0 add n 1 |
| 1035 | end |
| 1036 | end |
| 1037 | fn mkslug a ulong b ulong to void |
| 1038 | put sgl 0 0 |
| 1039 | dash = false |
| 1040 | i = a |
| 1041 | while lt i b bound 8388608 |
| 1042 | c = lowc get ib i |
| 1043 | if or isdig c islow c |
| 1044 | if and dash gt get sgl 0 0 |
| 1045 | if ge get sgl 0 39 |
| 1046 | break |
| 1047 | end |
| 1048 | sgc 45 |
| 1049 | end |
| 1050 | dash = false |
| 1051 | sgc c |
| 1052 | if ge get sgl 0 40 |
| 1053 | break |
| 1054 | end |
| 1055 | else |
| 1056 | dash = true |
| 1057 | end |
| 1058 | i = add i 1 |
| 1059 | end |
| 1060 | if eq get sgl 0 0 |
| 1061 | for j ulong len krec |
| 1062 | sgc get krec j |
| 1063 | end |
| 1064 | end |
| 1065 | sgc 45 |
| 1066 | end |
| 1067 | fn ems to void |
| 1068 | for i ulong get sgl 0 bound 80 |
| 1069 | emb get sg i |
| 1070 | end |
| 1071 | end |
| 1072 | fn tbs to void |
| 1073 | for i ulong get sgl 0 bound 80 |
| 1074 | tbb get sg i |
| 1075 | end |
| 1076 | end |
| 1077 | note lhead: start a registry line "ty <tab> slug <tab>" |
| 1078 | fn lhead ty uchar to void |
| 1079 | emb ty |
| 1080 | emb 9 |
| 1081 | ems |
| 1082 | emb 9 |
| 1083 | end |
| 1084 | note ---- the common part of a work (both modes): pre is /metadata (zenodo) or empty (repo) |
| 1085 | fn names sep view uchar * pre view uchar * to void |
| 1086 | l = hfind get hs 0 pre kcnm 1000000 |
| 1087 | n = ulong 0 |
| 1088 | while lt l get he 0 bound 8388608 |
| 1089 | if ge n 64 |
| 1090 | break |
| 1091 | end |
| 1092 | if gt n 0 |
| 1093 | em sep |
| 1094 | end |
| 1095 | x = emv vala l valb l 120 |
| 1096 | n = add n 1 |
| 1097 | l = hfind add eol l 1 pre kcnm 1000000 |
| 1098 | end |
| 1099 | end |
| 1100 | fn kwords pre view uchar * to void |
| 1101 | l = hfind get hs 0 pre kkw 1000000 |
| 1102 | n = ulong 0 |
| 1103 | while lt l get he 0 bound 8388608 |
| 1104 | if ge n 16 |
| 1105 | break |
| 1106 | end |
| 1107 | lhead 75 |
| 1108 | x = emv vala l valb l 80 |
| 1109 | emb 10 |
| 1110 | n = add n 1 |
| 1111 | l = hfind add eol l 1 pre kkw 1000000 |
| 1112 | end |
| 1113 | end |
| 1114 | note links: L lines for related identifiers that are https URLs (at most 16); the rest is logged |
| 1115 | fn links pre view uchar * to void |
| 1116 | l = hfind get hs 0 pre kri 1000000 |
| 1117 | n = ulong 0 |
| 1118 | while lt l get he 0 bound 8388608 |
| 1119 | k = hidx l pre kri |
| 1120 | a = vala l |
| 1121 | b = valb l |
| 1122 | if urlok a b |
| 1123 | if lt n 16 |
| 1124 | r = hfind get hs 0 pre krr k |
| 1125 | lhead 76 |
| 1126 | if lt r get he 0 |
| 1127 | emw vala r valb r 32 |
| 1128 | end |
| 1129 | emb 9 |
| 1130 | emr a b |
| 1131 | emb 10 |
| 1132 | n = add n 1 |
| 1133 | end |
| 1134 | else |
| 1135 | lgt mlink |
| 1136 | lgr a b |
| 1137 | lgt mlink2 |
| 1138 | lgb 10 |
| 1139 | end |
| 1140 | l = hfind add eol l 1 pre kri 1000000 |
| 1141 | end |
| 1142 | end |
| 1143 | note abstr: the A line and the S line (the abstract's first 300 bytes, cut at a space after 200) |
| 1144 | fn abstr pre view uchar * to void |
| 1145 | l = hfind get hs 0 pre kdesc 0 |
| 1146 | if ge l get he 0 |
| 1147 | ret |
| 1148 | end |
| 1149 | lhead 65 |
| 1150 | s = get obl 0 |
| 1151 | w = emv vala l valb l 12000 |
| 1152 | emb 10 |
| 1153 | if or eq w 0 ne get oof 0 0 |
| 1154 | ret |
| 1155 | end |
| 1156 | lhead 83 |
| 1157 | m = w |
| 1158 | if gt m 300 |
| 1159 | c = ulong 300 |
| 1160 | while gt c 200 bound 300 |
| 1161 | if eq get ob add s c 32 |
| 1162 | break |
| 1163 | end |
| 1164 | c = sub c 1 |
| 1165 | end |
| 1166 | while gt c 0 bound 300 |
| 1167 | if ne and get ob add s c 192 128 |
| 1168 | break |
| 1169 | end |
| 1170 | c = sub c 1 |
| 1171 | end |
| 1172 | m = c |
| 1173 | end |
| 1174 | for i ulong m bound 300 |
| 1175 | emb get ob add s i |
| 1176 | end |
| 1177 | emb 10 |
| 1178 | end |
| 1179 | note ---- zenodo mode |
| 1180 | note zowner: the creator name line of the creator whose orcid is the claimed iD (slot 2), else he |
| 1181 | fn zowner to ulong |
| 1182 | l = hfind get hs 0 kmeta kcor 1000000 |
| 1183 | while lt l get he 0 bound 8388608 |
| 1184 | a = vala l |
| 1185 | b = valb l |
| 1186 | if eq sub b a get avl 2 |
| 1187 | same = true |
| 1188 | for i ulong get avl 2 bound 19 |
| 1189 | if ne get ib add a i ava 2 i |
| 1190 | same = false |
| 1191 | end |
| 1192 | end |
| 1193 | if same |
| 1194 | k = hidx l kmeta kcor |
| 1195 | ret hfind get hs 0 kmeta kcnm k |
| 1196 | end |
| 1197 | end |
| 1198 | l = hfind add eol l 1 kmeta kcor 1000000 |
| 1199 | end |
| 1200 | ret get he 0 |
| 1201 | end |
| 1202 | note fext: the file name ib[a, b) ends in .pdf, .txt or .md (any case) |
| 1203 | fn fext a ulong b ulong to bool |
| 1204 | if le sub b a 4 |
| 1205 | ret false |
| 1206 | end |
| 1207 | x1 = lowc get ib sub b 4 |
| 1208 | x2 = lowc get ib sub b 3 |
| 1209 | x3 = lowc get ib sub b 2 |
| 1210 | x4 = lowc get ib sub b 1 |
| 1211 | if and and eq x1 46 eq x2 112 and eq x3 100 eq x4 102 |
| 1212 | ret true |
| 1213 | end |
| 1214 | if and and eq x1 46 eq x2 116 and eq x3 120 eq x4 116 |
| 1215 | ret true |
| 1216 | end |
| 1217 | ret and eq x2 46 and eq x3 109 eq x4 100 |
| 1218 | end |
| 1219 | note zfiles: F lines for files with an https link (at most 16); with an open licence, one T line |
| 1220 | note on descriptor 3 for the first .pdf, .txt or .md file of at most 8 decimal digits of bytes |
| 1221 | fn tbr a ulong b ulong to void |
| 1222 | i = a |
| 1223 | while lt i b bound 8388608 |
| 1224 | tbb get ib i |
| 1225 | i = add i 1 |
| 1226 | end |
| 1227 | end |
| 1228 | fn zfiles opn bool to void |
| 1229 | l = hfind get hs 0 knone kfk 1000000 |
| 1230 | n = ulong 0 |
| 1231 | t = false |
| 1232 | while lt l get he 0 bound 8388608 |
| 1233 | k = hidx l knone kfk |
| 1234 | u = hfind get hs 0 knone kfl k |
| 1235 | z = hfind get hs 0 knone kfs k |
| 1236 | if lt u get he 0 |
| 1237 | ua = vala u |
| 1238 | ub = valb u |
| 1239 | if urlok ua ub |
| 1240 | if lt n 16 |
| 1241 | lhead 70 |
| 1242 | x = emv vala l valb l 200 |
| 1243 | emb 9 |
| 1244 | if lt z get he 0 |
| 1245 | if alldig vala z valb z |
| 1246 | emr vala z valb z |
| 1247 | end |
| 1248 | end |
| 1249 | emb 9 |
| 1250 | emr ua ub |
| 1251 | emb 10 |
| 1252 | n = add n 1 |
| 1253 | end |
| 1254 | if and opn not t |
| 1255 | ok = fext vala l valb l |
| 1256 | if lt z get he 0 |
| 1257 | if not alldig vala z valb z |
| 1258 | ok = false |
| 1259 | else |
| 1260 | if gt sub valb z vala z 8 |
| 1261 | ok = false |
| 1262 | end |
| 1263 | end |
| 1264 | end |
| 1265 | if ok |
| 1266 | tbs |
| 1267 | tbb 9 |
| 1268 | tbr ua ub |
| 1269 | tbb 10 |
| 1270 | t = true |
| 1271 | end |
| 1272 | end |
| 1273 | else |
| 1274 | lgt mlink |
| 1275 | lgr ua ub |
| 1276 | lgt mlink2 |
| 1277 | lgb 10 |
| 1278 | end |
| 1279 | end |
| 1280 | l = hfind add eol l 1 knone kfk 1000000 |
| 1281 | end |
| 1282 | end |
| 1283 | note zhit: one search hit. 1 listed, 0 refused. |
| 1284 | note A per-author namespace binds paper paths and cached text to the author catalog. A public |
| 1285 | note coauthored record can be listed under each matching ORCID without duplicate work keys. |
| 1286 | fn zauthor to void |
| 1287 | b = new uchar 128 0 |
| 1288 | d = new uchar 32 0 |
| 1289 | n = get avl 5 |
| 1290 | for i ulong n bound 64 |
| 1291 | put b i ava 5 i |
| 1292 | end |
| 1293 | x = sha2_digest 256 view part b 0 n d |
| 1294 | put sgl 0 0 |
| 1295 | sgc 122 |
| 1296 | for i ulong 16 |
| 1297 | c = get d i |
| 1298 | sgc get khex ulong shr c 4 |
| 1299 | sgc get khex ulong and c 15 |
| 1300 | end |
| 1301 | sgc 45 |
| 1302 | end |
| 1303 | fn zhit nl ulong to ulong |
| 1304 | l = hval knone kid |
| 1305 | if ge l get he 0 |
| 1306 | lgt mref |
| 1307 | lgt mnoid |
| 1308 | lgb 10 |
| 1309 | ret 0 |
| 1310 | end |
| 1311 | ra = vala l |
| 1312 | rb2 = valb l |
| 1313 | if not alldig ra rb2 |
| 1314 | lgt mref |
| 1315 | lgt mnoid |
| 1316 | lgb 10 |
| 1317 | ret 0 |
| 1318 | end |
| 1319 | if gt metacount 1 |
| 1320 | lgt mref |
| 1321 | lgr ra rb2 |
| 1322 | lgt mmeta |
| 1323 | lgb 10 |
| 1324 | ret 0 |
| 1325 | end |
| 1326 | ow = zowner |
| 1327 | if ge ow get he 0 |
| 1328 | lgt mref |
| 1329 | lgr ra rb2 |
| 1330 | lgt mown |
| 1331 | lga 2 |
| 1332 | lgt mown2 |
| 1333 | lgb 10 |
| 1334 | ret 0 |
| 1335 | end |
| 1336 | if ge nl 200 |
| 1337 | lgt mref |
| 1338 | lgr ra rb2 |
| 1339 | lgt mmany |
| 1340 | lgb 10 |
| 1341 | ret 0 |
| 1342 | end |
| 1343 | tl = hval kmeta ktitle |
| 1344 | if ge tl get he 0 |
| 1345 | lgt mref |
| 1346 | lgr ra rb2 |
| 1347 | lgt mnot |
| 1348 | lgb 10 |
| 1349 | ret 0 |
| 1350 | end |
| 1351 | if eq nl 0 |
| 1352 | put gn 1 vala ow |
| 1353 | put gn 2 valb ow |
| 1354 | end |
| 1355 | zauthor |
| 1356 | i = ra |
| 1357 | while lt i rb2 bound 12 |
| 1358 | sgc get ib i |
| 1359 | i = add i 1 |
| 1360 | end |
| 1361 | put lamb 0 lcount kmeta |
| 1362 | lc = hval kmeta klic |
| 1363 | opn = false |
| 1364 | if lt lc get he 0 |
| 1365 | opn = isopen vala lc valb lc |
| 1366 | end |
| 1367 | if gt get lamb 0 1 |
| 1368 | opn = false |
| 1369 | lgt mref |
| 1370 | lgr ra rb2 |
| 1371 | lgt mamb |
| 1372 | lgb 10 |
| 1373 | end |
| 1374 | note W: slug, thread (none), date, kind, venue, DOI of all versions, DOI of this version, version, |
| 1375 | note number of versions, on ORCID (0: not checked here), licence, title |
| 1376 | lhead 87 |
| 1377 | emb 9 |
| 1378 | d = hval kmeta kdate |
| 1379 | if lt d get he 0 |
| 1380 | if vdate vala d valb d |
| 1381 | emr vala d valb d |
| 1382 | end |
| 1383 | end |
| 1384 | emb 9 |
| 1385 | k = hval kmeta ksub |
| 1386 | if ge k get he 0 |
| 1387 | k = hval kmeta ktyp |
| 1388 | end |
| 1389 | if lt k get he 0 |
| 1390 | if reqt vala k valb k kart |
| 1391 | em kjart |
| 1392 | else |
| 1393 | emw vala k valb k 32 |
| 1394 | end |
| 1395 | end |
| 1396 | emb 9 |
| 1397 | em kzen |
| 1398 | emb 9 |
| 1399 | d = hval knone kcdoi |
| 1400 | if lt d get he 0 |
| 1401 | if doiok vala d valb d |
| 1402 | emr vala d valb d |
| 1403 | end |
| 1404 | end |
| 1405 | emb 9 |
| 1406 | d = hval knone kdoi |
| 1407 | if lt d get he 0 |
| 1408 | if doiok vala d valb d |
| 1409 | emr vala d valb d |
| 1410 | end |
| 1411 | end |
| 1412 | emb 9 |
| 1413 | d = hval kmeta kver |
| 1414 | if lt d get he 0 |
| 1415 | x = emv vala d valb d 48 |
| 1416 | end |
| 1417 | emb 9 |
| 1418 | d = hval kmeta kvix |
| 1419 | nv = ulong 1 |
| 1420 | if lt d get he 0 |
| 1421 | if alldig vala d valb d |
| 1422 | if le sub valb d vala d 6 |
| 1423 | nv = add dnum vala d valb d 1 |
| 1424 | end |
| 1425 | end |
| 1426 | end |
| 1427 | emn nv |
| 1428 | emb 9 |
| 1429 | emb 48 |
| 1430 | emb 9 |
| 1431 | if gt get lamb 0 1 |
| 1432 | em kamb |
| 1433 | else |
| 1434 | if lt lc get he 0 |
| 1435 | emw vala lc valb lc 32 |
| 1436 | end |
| 1437 | end |
| 1438 | emb 9 |
| 1439 | x = emv vala tl valb tl 400 |
| 1440 | emb 10 |
| 1441 | abstr kmeta |
| 1442 | lhead 67 |
| 1443 | names ksep kmeta |
| 1444 | emb 10 |
| 1445 | lhead 66 |
| 1446 | names kand kmeta |
| 1447 | emb 10 |
| 1448 | kwords kmeta |
| 1449 | links kmeta |
| 1450 | zfiles opn |
| 1451 | note P: slug, how, the key that asked, the date, the source, 1 when the licence is on the open list |
| 1452 | lhead 80 |
| 1453 | em kzv |
| 1454 | emb 9 |
| 1455 | ema 3 |
| 1456 | emb 9 |
| 1457 | ema 4 |
| 1458 | emb 9 |
| 1459 | em kzrec |
| 1460 | emr ra rb2 |
| 1461 | emb 9 |
| 1462 | if opn |
| 1463 | emb 49 |
| 1464 | else |
| 1465 | emb 48 |
| 1466 | end |
| 1467 | emb 10 |
| 1468 | ret 1 |
| 1469 | end |
| 1470 | fn zend s ulong w ulong to ulong |
| 1471 | lim = get ibl 0 |
| 1472 | t = add eol s 1 |
| 1473 | while lt t lim bound 8388608 |
| 1474 | te = eol t |
| 1475 | same = lpre t te khits |
| 1476 | if same |
| 1477 | if le sub te t w |
| 1478 | same = false |
| 1479 | end |
| 1480 | end |
| 1481 | if same |
| 1482 | same = feqr t add t w s add s w |
| 1483 | if ne get ib add t w 47 |
| 1484 | same = false |
| 1485 | end |
| 1486 | end |
| 1487 | if not same |
| 1488 | break |
| 1489 | end |
| 1490 | t = add te 1 |
| 1491 | end |
| 1492 | if gt t lim |
| 1493 | t = lim |
| 1494 | end |
| 1495 | ret t |
| 1496 | end |
| 1497 | fn zmode to int |
| 1498 | if not orcok 2 |
| 1499 | ret 2 |
| 1500 | end |
| 1501 | if not didok 3 |
| 1502 | ret 2 |
| 1503 | end |
| 1504 | if not dateok 4 |
| 1505 | ret 2 |
| 1506 | end |
| 1507 | if not autok 5 |
| 1508 | ret 2 |
| 1509 | end |
| 1510 | if not rdin |
| 1511 | x = flush 2 mbig len mbig |
| 1512 | ret 2 |
| 1513 | end |
| 1514 | put hpl 0 0 |
| 1515 | lim = get ibl 0 |
| 1516 | nl = ulong 0 |
| 1517 | nr = ulong 0 |
| 1518 | s = ulong 0 |
| 1519 | while lt s lim bound 8388608 |
| 1520 | e = eol s |
| 1521 | nx = add e 1 |
| 1522 | if lpre s e khits |
| 1523 | p = add s len khits |
| 1524 | q = p |
| 1525 | while lt q e bound 8388608 |
| 1526 | if not isdig get ib q |
| 1527 | break |
| 1528 | end |
| 1529 | if ge sub q p 12 |
| 1530 | break |
| 1531 | end |
| 1532 | q = add q 1 |
| 1533 | end |
| 1534 | if and gt q p lt q e |
| 1535 | if eq get ib q 47 |
| 1536 | w = sub q s |
| 1537 | put hpl 0 w |
| 1538 | put hs 0 s |
| 1539 | t = zend s w |
| 1540 | put he 0 t |
| 1541 | r = zhit nl |
| 1542 | nl = add nl r |
| 1543 | if eq r 0 |
| 1544 | nr = add nr 1 |
| 1545 | end |
| 1546 | nx = t |
| 1547 | end |
| 1548 | end |
| 1549 | end |
| 1550 | s = nx |
| 1551 | end |
| 1552 | if gt nl 0 |
| 1553 | em kos |
| 1554 | ema 5 |
| 1555 | emb 10 |
| 1556 | em kon |
| 1557 | x = emv get gn 1 get gn 2 120 |
| 1558 | emb 10 |
| 1559 | em koo |
| 1560 | ema 2 |
| 1561 | emb 10 |
| 1562 | em koa |
| 1563 | ema 3 |
| 1564 | emb 10 |
| 1565 | em koc |
| 1566 | ema 4 |
| 1567 | emb 10 |
| 1568 | em kov |
| 1569 | em kzv |
| 1570 | emb 10 |
| 1571 | end |
| 1572 | lgt mlisted |
| 1573 | lgn nl |
| 1574 | lgt mrefd |
| 1575 | lgn nr |
| 1576 | lgb 10 |
| 1577 | ret done 0 |
| 1578 | end |
| 1579 | note ---- repo mode: .zenodo.json (jflat) then @tree and git ls-tree -l HEAD |
| 1580 | note tname: the ls-tree line l names a top-level blob called t |
| 1581 | note git ls-tree -l ends the metadata part with a decimal blob size. Apply the same 8 MiB |
| 1582 | note foreign file transport boundary before copying or decoding repository paper bytes. |
| 1583 | fn tbytes l ulong to bool |
| 1584 | e = tabat l eol l |
| 1585 | a = e |
| 1586 | while gt a l bound 8388608 |
| 1587 | c = get ib sub a 1 |
| 1588 | if eq c 32 |
| 1589 | break |
| 1590 | end |
| 1591 | a = sub a 1 |
| 1592 | end |
| 1593 | if not alldig a e |
| 1594 | ret false |
| 1595 | end |
| 1596 | n = dnum a e |
| 1597 | ret and gt n 0 lt n 8388608 |
| 1598 | end |
| 1599 | fn tname l ulong t view uchar * to bool |
| 1600 | ln = eol l |
| 1601 | x = tabat l ln |
| 1602 | if ge x ln |
| 1603 | ret false |
| 1604 | end |
| 1605 | if not reqt add x 1 ln t |
| 1606 | ret false |
| 1607 | end |
| 1608 | if not lpre l ln kblob |
| 1609 | ret false |
| 1610 | end |
| 1611 | ret tbytes l |
| 1612 | end |
| 1613 | fn tfind s ulong t view uchar * to bool |
| 1614 | l = s |
| 1615 | lim = get ibl 0 |
| 1616 | while lt l lim bound 8388608 |
| 1617 | if tname l t |
| 1618 | ret true |
| 1619 | end |
| 1620 | l = add eol l 1 |
| 1621 | end |
| 1622 | ret false |
| 1623 | end |
| 1624 | fn tbt t view uchar * to void |
| 1625 | for i ulong len t bound 64 |
| 1626 | tbb get t i |
| 1627 | end |
| 1628 | end |
| 1629 | note A repository slug ends with 128 bits of SHA-256 of its complete RID, not a colliding RID prefix. |
| 1630 | fn rsuffix to void |
| 1631 | b = new uchar 128 0 |
| 1632 | d = new uchar 32 0 |
| 1633 | n = get avl 2 |
| 1634 | for i ulong n bound 44 |
| 1635 | put b i ava 2 i |
| 1636 | end |
| 1637 | put b n 9 |
| 1638 | n = add n 1 |
| 1639 | for i ulong get avl 5 bound 64 |
| 1640 | put b add n i ava 5 i |
| 1641 | end |
| 1642 | n = add n get avl 5 |
| 1643 | x = sha2_digest 256 view part b 0 n d |
| 1644 | if gt get sgl 0 30 |
| 1645 | put sgl 0 30 |
| 1646 | put sg 29 45 |
| 1647 | end |
| 1648 | sgc 114 |
| 1649 | for i ulong 16 |
| 1650 | v = get d i |
| 1651 | sgc get khex ulong shr v 4 |
| 1652 | sgc get khex ulong and v 15 |
| 1653 | end |
| 1654 | end |
| 1655 | fn hexarg k ulong n ulong to bool |
| 1656 | if ne get avl k n |
| 1657 | ret false |
| 1658 | end |
| 1659 | for i ulong n bound 64 |
| 1660 | c = ava k i |
| 1661 | if not or isdig c and ge c 97 le c 102 |
| 1662 | ret false |
| 1663 | end |
| 1664 | end |
| 1665 | ret true |
| 1666 | end |
| 1667 | fn rmode to int |
| 1668 | if not ridok 2 |
| 1669 | ret 2 |
| 1670 | end |
| 1671 | if not didok 3 |
| 1672 | ret 2 |
| 1673 | end |
| 1674 | if not dateok 4 |
| 1675 | ret 2 |
| 1676 | end |
| 1677 | if not autok 5 |
| 1678 | ret 2 |
| 1679 | end |
| 1680 | if not rdin |
| 1681 | x = flush 2 mbig len mbig |
| 1682 | ret 2 |
| 1683 | end |
| 1684 | lim = get ibl 0 |
| 1685 | t = ulong 0 |
| 1686 | while lt t lim bound 8388608 |
| 1687 | if reqt t eol t ktree |
| 1688 | break |
| 1689 | end |
| 1690 | t = add eol t 1 |
| 1691 | end |
| 1692 | if gt t lim |
| 1693 | t = lim |
| 1694 | end |
| 1695 | put hs 0 0 |
| 1696 | put he 0 t |
| 1697 | put hpl 0 0 |
| 1698 | ts = lim |
| 1699 | if lt t lim |
| 1700 | ts = add eol t 1 |
| 1701 | end |
| 1702 | tl = hval knone ktitle |
| 1703 | if ge tl get he 0 |
| 1704 | lgt mrt |
| 1705 | lgb 10 |
| 1706 | ret done 1 |
| 1707 | end |
| 1708 | nm = hfind 0 knone kcnm 1000000 |
| 1709 | if ge nm get he 0 |
| 1710 | lgt mrc |
| 1711 | lgb 10 |
| 1712 | ret done 1 |
| 1713 | end |
| 1714 | lc = hval knone klic |
| 1715 | if ge lc get he 0 |
| 1716 | lc = hval knone klics |
| 1717 | end |
| 1718 | if ge lc get he 0 |
| 1719 | lgt mrl |
| 1720 | lgb 10 |
| 1721 | ret done 1 |
| 1722 | end |
| 1723 | put lamb 0 lcount knone |
| 1724 | hasl = or or tfind ts klic1 tfind ts klic2 or or tfind ts klic3 tfind ts klic4 tfind ts klic5 |
| 1725 | if not hasl |
| 1726 | lgt mrf |
| 1727 | lgb 10 |
| 1728 | ret done 1 |
| 1729 | end |
| 1730 | pf = ulong 0 |
| 1731 | if tfind ts kpaper3 |
| 1732 | pf = ulong 3 |
| 1733 | end |
| 1734 | if tfind ts kpaper2 |
| 1735 | pf = ulong 2 |
| 1736 | end |
| 1737 | if tfind ts kpaper1 |
| 1738 | pf = ulong 1 |
| 1739 | end |
| 1740 | if eq pf 0 |
| 1741 | lgt mrp |
| 1742 | lgb 10 |
| 1743 | ret done 1 |
| 1744 | end |
| 1745 | opn = isopen vala lc valb lc |
| 1746 | if gt get lamb 0 1 |
| 1747 | opn = false |
| 1748 | lgt mamb |
| 1749 | lgb 10 |
| 1750 | end |
| 1751 | mkslug vala tl valb tl |
| 1752 | rsuffix |
| 1753 | lhead 87 |
| 1754 | emb 9 |
| 1755 | d = hval knone kdate |
| 1756 | dk = false |
| 1757 | if lt d get he 0 |
| 1758 | if vdate vala d valb d |
| 1759 | emr vala d valb d |
| 1760 | dk = true |
| 1761 | end |
| 1762 | end |
| 1763 | if not dk |
| 1764 | ema 4 |
| 1765 | end |
| 1766 | emb 9 |
| 1767 | k = hval knone kput |
| 1768 | if ge k get he 0 |
| 1769 | k = hval knone kupt |
| 1770 | end |
| 1771 | if lt k get he 0 |
| 1772 | if reqt vala k valb k kart |
| 1773 | em kjart |
| 1774 | else |
| 1775 | emw vala k valb k 32 |
| 1776 | end |
| 1777 | end |
| 1778 | emb 9 |
| 1779 | em krad |
| 1780 | emb 9 |
| 1781 | emb 9 |
| 1782 | d = hval knone kdoi |
| 1783 | if lt d get he 0 |
| 1784 | if doiok vala d valb d |
| 1785 | emr vala d valb d |
| 1786 | end |
| 1787 | end |
| 1788 | emb 9 |
| 1789 | d = hval knone kver |
| 1790 | if lt d get he 0 |
| 1791 | x = emv vala d valb d 48 |
| 1792 | end |
| 1793 | emb 9 |
| 1794 | emb 49 |
| 1795 | emb 9 |
| 1796 | emb 48 |
| 1797 | emb 9 |
| 1798 | if gt get lamb 0 1 |
| 1799 | em kamb |
| 1800 | else |
| 1801 | emw vala lc valb lc 32 |
| 1802 | end |
| 1803 | emb 9 |
| 1804 | x = emv vala tl valb tl 400 |
| 1805 | emb 10 |
| 1806 | abstr knone |
| 1807 | lhead 67 |
| 1808 | names ksep knone |
| 1809 | emb 10 |
| 1810 | lhead 66 |
| 1811 | names kand knone |
| 1812 | emb 10 |
| 1813 | kwords knone |
| 1814 | links knone |
| 1815 | lhead 80 |
| 1816 | em krv |
| 1817 | emb 9 |
| 1818 | ema 3 |
| 1819 | emb 9 |
| 1820 | ema 4 |
| 1821 | emb 9 |
| 1822 | em krp |
| 1823 | ema 2 |
| 1824 | emb 9 |
| 1825 | if opn |
| 1826 | emb 49 |
| 1827 | else |
| 1828 | emb 48 |
| 1829 | end |
| 1830 | emb 10 |
| 1831 | if or opn argeq 6 kplan |
| 1832 | tbs |
| 1833 | tbb 9 |
| 1834 | if eq pf 1 |
| 1835 | tbt kpaper1 |
| 1836 | end |
| 1837 | if eq pf 2 |
| 1838 | tbt kpaper2 |
| 1839 | end |
| 1840 | if eq pf 3 |
| 1841 | tbt kpaper3 |
| 1842 | end |
| 1843 | if argeq 6 kplan |
| 1844 | tbb 9 |
| 1845 | if opn |
| 1846 | tbb 49 |
| 1847 | else |
| 1848 | tbb 48 |
| 1849 | end |
| 1850 | end |
| 1851 | tbb 10 |
| 1852 | end |
| 1853 | em kos |
| 1854 | ema 5 |
| 1855 | emb 10 |
| 1856 | em kon |
| 1857 | x = emv vala nm valb nm 120 |
| 1858 | emb 10 |
| 1859 | em koa |
| 1860 | ema 3 |
| 1861 | emb 10 |
| 1862 | em koc |
| 1863 | ema 4 |
| 1864 | emb 10 |
| 1865 | em kov |
| 1866 | em krv |
| 1867 | emb 10 |
| 1868 | if eq argcnt 8 |
| 1869 | if not hexarg 6 40 |
| 1870 | ret 2 |
| 1871 | end |
| 1872 | if not hexarg 7 64 |
| 1873 | ret 2 |
| 1874 | end |
| 1875 | lhead 71 |
| 1876 | ema 6 |
| 1877 | emb 9 |
| 1878 | ema 7 |
| 1879 | emb 10 |
| 1880 | end |
| 1881 | ret done 0 |
| 1882 | end |
| 1883 | note ---- text mode: paragraphs (separated by a blank line or a form feed) become one line each; |
| 1884 | note line ends inside a paragraph, tabs and other control bytes become a space; runs of spaces |
| 1885 | note become one; a malformed UTF-8 byte becomes ?; at most 262,144 bytes are written (whole |
| 1886 | note paragraphs where they fit: the paragraph that would pass the limit and the rest are left oc). |
| 1887 | fn tmode to int |
| 1888 | if not rdin |
| 1889 | x = flush 2 mbig len mbig |
| 1890 | ret 2 |
| 1891 | end |
| 1892 | lim = get ibl 0 |
| 1893 | i = ulong 0 |
| 1894 | ps = get obl 0 |
| 1895 | pw = ulong 0 |
| 1896 | nlc = ulong 0 |
| 1897 | pend = false |
| 1898 | stop = false |
| 1899 | while lt i lim bound 8388608 |
| 1900 | c = get ib i |
| 1901 | brk = false |
| 1902 | if eq c 12 |
| 1903 | brk = true |
| 1904 | end |
| 1905 | if eq c 10 |
| 1906 | nlc = add nlc 1 |
| 1907 | if ge nlc 2 |
| 1908 | brk = true |
| 1909 | end |
| 1910 | else |
| 1911 | if and ne c 13 and ne c 32 ne c 9 |
| 1912 | nlc = ulong 0 |
| 1913 | end |
| 1914 | end |
| 1915 | if brk |
| 1916 | if gt pw 0 |
| 1917 | emb 10 |
| 1918 | if gt get obl 0 262144 |
| 1919 | put obl 0 ps |
| 1920 | stop = true |
| 1921 | break |
| 1922 | end |
| 1923 | ps = get obl 0 |
| 1924 | end |
| 1925 | pw = ulong 0 |
| 1926 | pend = false |
| 1927 | i = add i 1 |
| 1928 | else |
| 1929 | if or le c 32 eq c 127 |
| 1930 | if gt pw 0 |
| 1931 | pend = true |
| 1932 | end |
| 1933 | i = add i 1 |
| 1934 | else |
| 1935 | k = ulong 1 |
| 1936 | if ge c 128 |
| 1937 | k = u8len i lim |
| 1938 | end |
| 1939 | if pend |
| 1940 | emb 32 |
| 1941 | pend = false |
| 1942 | end |
| 1943 | if eq k 0 |
| 1944 | emb 63 |
| 1945 | k = ulong 1 |
| 1946 | else |
| 1947 | emr i add i k |
| 1948 | end |
| 1949 | pw = add pw k |
| 1950 | i = add i k |
| 1951 | end |
| 1952 | end |
| 1953 | end |
| 1954 | if and not stop gt pw 0 |
| 1955 | emb 10 |
| 1956 | if gt get obl 0 262144 |
| 1957 | put obl 0 ps |
| 1958 | end |
| 1959 | end |
| 1960 | ret done 0 |
| 1961 | end |
| 1962 | note ---- small file reads into rb (allow, remove, an author's registry), at most 65,535 bytes |
| 1963 | fn ldarg k ulong to void |
| 1964 | n = get avl k |
| 1965 | for i ulong n bound 512 |
| 1966 | put pth i ava k i |
| 1967 | end |
| 1968 | put pthl 0 n |
| 1969 | end |
| 1970 | fn rregular fd int to bool |
| 1971 | st = new uchar 128 0 |
| 1972 | r = fstat fd st 0 128 |
| 1973 | if ne r 0 |
| 1974 | ret false |
| 1975 | end |
| 1976 | m = or ulong get st 16 shl ulong get st 17 8 |
| 1977 | ret eq and m 61440 32768 |
| 1978 | end |
| 1979 | note Absence is permitted for remove, but any other open/read/type/overflow failure is fatal. |
| 1980 | fn rload to bool |
| 1981 | one = new uchar 1 0 |
| 1982 | put rerr 0 0 |
| 1983 | put rbl 0 0 |
| 1984 | fd = fopen pth 0 get pthl 0 559104 0 |
| 1985 | if lt fd 0 |
| 1986 | if ne fd -2 |
| 1987 | put rerr 0 1 |
| 1988 | end |
| 1989 | ret false |
| 1990 | end |
| 1991 | if not rregular int fd |
| 1992 | x = fclose int fd |
| 1993 | put rerr 0 1 |
| 1994 | ret false |
| 1995 | end |
| 1996 | n = ulong 0 |
| 1997 | k = long 1 |
| 1998 | while gt k 0 bound 65536 |
| 1999 | if eq n 65535 |
| 2000 | k = read int fd one 0 1 |
| 2001 | if ne k 0 |
| 2002 | put rerr 0 1 |
| 2003 | end |
| 2004 | break |
| 2005 | end |
| 2006 | k = read int fd rb n sub 65535 n |
| 2007 | if lt k 0 |
| 2008 | put rerr 0 1 |
| 2009 | end |
| 2010 | if gt k 0 |
| 2011 | n = add n ulong k |
| 2012 | end |
| 2013 | end |
| 2014 | x = fclose int fd |
| 2015 | if ne get rerr 0 0 |
| 2016 | ret false |
| 2017 | end |
| 2018 | put rbl 0 n |
| 2019 | ret true |
| 2020 | end |
| 2021 | fn reol a ulong to ulong |
| 2022 | n = get rbl 0 |
| 2023 | e = a |
| 2024 | while lt e n bound 65536 |
| 2025 | if eq get rb e 10 |
| 2026 | ret e |
| 2027 | end |
| 2028 | e = add e 1 |
| 2029 | end |
| 2030 | ret n |
| 2031 | end |
| 2032 | note rstart: the start of the value of an rb line that may begin with rad: |
| 2033 | fn rstart a ulong e ulong pre bool to ulong |
| 2034 | if pre |
| 2035 | if gt sub e a 4 |
| 2036 | x = and eq get rb a 114 eq get rb add a 1 97 |
| 2037 | y = and eq get rb add a 2 100 eq get rb add a 3 58 |
| 2038 | if and x y |
| 2039 | ret add a 4 |
| 2040 | end |
| 2041 | end |
| 2042 | end |
| 2043 | ret a |
| 2044 | end |
| 2045 | note rhas: a line of rb is exactly argument k (pre: also with rad: in front) |
| 2046 | fn rhas k ulong pre bool to bool |
| 2047 | n = get rbl 0 |
| 2048 | a = ulong 0 |
| 2049 | m = get avl k |
| 2050 | if eq m 0 |
| 2051 | ret false |
| 2052 | end |
| 2053 | while lt a n bound 65536 |
| 2054 | e = reol a |
| 2055 | b = rstart a e pre |
| 2056 | if eq sub e b m |
| 2057 | same = true |
| 2058 | for i ulong m bound 512 |
| 2059 | if ne get rb add b i ava k i |
| 2060 | same = false |
| 2061 | end |
| 2062 | end |
| 2063 | if same |
| 2064 | ret true |
| 2065 | end |
| 2066 | end |
| 2067 | a = add e 1 |
| 2068 | end |
| 2069 | ret false |
| 2070 | end |
| 2071 | note rbhas: a line of rb is ib[a, b) (pre: also with rad: in front) |
| 2072 | fn rbeq y ulong a ulong m ulong to bool |
| 2073 | for i ulong m bound 8388608 |
| 2074 | x = get rb add y i |
| 2075 | z = get ib add a i |
| 2076 | if ne x z |
| 2077 | ret false |
| 2078 | end |
| 2079 | end |
| 2080 | ret true |
| 2081 | end |
| 2082 | fn rbhas a ulong b ulong pre bool to bool |
| 2083 | if pre |
| 2084 | if lpre a b krp |
| 2085 | a = add a 4 |
| 2086 | end |
| 2087 | end |
| 2088 | n = get rbl 0 |
| 2089 | if le b a |
| 2090 | ret false |
| 2091 | end |
| 2092 | m = sub b a |
| 2093 | x = ulong 0 |
| 2094 | while lt x n bound 65536 |
| 2095 | e = reol x |
| 2096 | y = rstart x e pre |
| 2097 | if eq sub e y m |
| 2098 | same = rbeq y a m |
| 2099 | if same |
| 2100 | ret true |
| 2101 | end |
| 2102 | end |
| 2103 | x = add e 1 |
| 2104 | end |
| 2105 | ret false |
| 2106 | end |
| 2107 | fn rstar to bool |
| 2108 | n = get rbl 0 |
| 2109 | a = ulong 0 |
| 2110 | while lt a n bound 65536 |
| 2111 | e = reol a |
| 2112 | if eq sub e a 1 |
| 2113 | if eq get rb a 42 |
| 2114 | ret true |
| 2115 | end |
| 2116 | end |
| 2117 | a = add e 1 |
| 2118 | end |
| 2119 | ret false |
| 2120 | end |
| 2121 | note ---- the shelf list (rows: rid, state, did, ...), read a row at a time. listed: a row for the |
| 2122 | note rid in slot 0 (with or without rad:) in state open, stored or held, brought by the did in slot 7 |
| 2123 | fn roweq r view uchar 1024 s ulong e ulong t view uchar * to bool |
| 2124 | if ne sub e s len t |
| 2125 | ret false |
| 2126 | end |
| 2127 | for i ulong len t bound 16 |
| 2128 | if ne get r add s i get t i |
| 2129 | ret false |
| 2130 | end |
| 2131 | end |
| 2132 | ret true |
| 2133 | end |
| 2134 | fn rowst r view uchar 1024 s ulong e ulong to bool |
| 2135 | if roweq r s e kst1 |
| 2136 | ret true |
| 2137 | end |
| 2138 | if roweq r s e kst2 |
| 2139 | ret true |
| 2140 | end |
| 2141 | ret roweq r s e kst3 |
| 2142 | end |
| 2143 | fn rowok r view uchar 1024 n ulong to bool |
| 2144 | p = ulong 0 |
| 2145 | if gt n 4 |
| 2146 | if and and eq get r 0 114 eq get r 1 97 and eq get r 2 100 eq get r 3 58 |
| 2147 | p = ulong 4 |
| 2148 | end |
| 2149 | end |
| 2150 | m = get avl 0 |
| 2151 | if or eq m 0 lt sub n p m |
| 2152 | ret false |
| 2153 | end |
| 2154 | for i ulong m bound 512 |
| 2155 | if ne get r add p i ava 0 i |
| 2156 | ret false |
| 2157 | end |
| 2158 | end |
| 2159 | q = add p m |
| 2160 | if ge q n |
| 2161 | ret false |
| 2162 | end |
| 2163 | if ne get r q 9 |
| 2164 | ret false |
| 2165 | end |
| 2166 | q = add q 1 |
| 2167 | s = q |
| 2168 | while lt q n bound 1024 |
| 2169 | if eq get r q 9 |
| 2170 | break |
| 2171 | end |
| 2172 | q = add q 1 |
| 2173 | end |
| 2174 | if not rowst r s q |
| 2175 | ret false |
| 2176 | end |
| 2177 | if ge q n |
| 2178 | ret false |
| 2179 | end |
| 2180 | q = add q 1 |
| 2181 | d = get avl 7 |
| 2182 | if or eq d 0 lt sub n q d |
| 2183 | ret false |
| 2184 | end |
| 2185 | for i ulong d bound 512 |
| 2186 | if ne get r add q i ava 7 i |
| 2187 | ret false |
| 2188 | end |
| 2189 | end |
| 2190 | e = add q d |
| 2191 | if lt e n |
| 2192 | ret eq get r e 9 |
| 2193 | end |
| 2194 | ret true |
| 2195 | end |
| 2196 | fn listed lk ulong to bool |
| 2197 | ldarg lk |
| 2198 | fd = fopen pth 0 get pthl 0 557056 0 |
| 2199 | if lt fd 0 |
| 2200 | ret false |
| 2201 | end |
| 2202 | b = new uchar 4096 0 |
| 2203 | line = new uchar 1024 0 |
| 2204 | got = false |
| 2205 | ll = ulong 0 |
| 2206 | over = false |
| 2207 | k = long 1 |
| 2208 | while gt k 0 bound 9223372036854775807 |
| 2209 | k = read int fd b 0 4096 |
| 2210 | if gt k 0 |
| 2211 | for i ulong ulong k bound 4096 |
| 2212 | c = get b i |
| 2213 | if eq c 10 |
| 2214 | if not over |
| 2215 | if rowok line ll |
| 2216 | got = true |
| 2217 | end |
| 2218 | end |
| 2219 | ll = ulong 0 |
| 2220 | over = false |
| 2221 | else |
| 2222 | if lt ll 1024 |
| 2223 | put line ll c |
| 2224 | ll = add ll 1 |
| 2225 | else |
| 2226 | over = true |
| 2227 | end |
| 2228 | end |
| 2229 | end |
| 2230 | end |
| 2231 | end |
| 2232 | x = fclose int fd |
| 2233 | if and gt ll 0 not over |
| 2234 | if rowok line ll |
| 2235 | got = true |
| 2236 | end |
| 2237 | end |
| 2238 | ret got |
| 2239 | end |
| 2240 | note ---- the queue (written by forged: a less trusted process). Lines: |
| 2241 | note Z <tab> did <tab> ORCID iD <tab> DOI (empty or 10.5281/zenodo.<digits>) |
| 2242 | note P <tab> did <tab> rid <tab> ORCID iD (may be empty) |
| 2243 | note Accepted requests go to stdout with the author id they are filed under as the last field: |
| 2244 | note the ORCID iD lowercased, or key- and the first 16 hex characters of SHA-256 over the did (a |
| 2245 | note repository brought without an ORCID iD that this key added). Refusals go to stderr. |
| 2246 | note Slots: 1 add dir, 2 state, 3 allow, 4 remove, 5 reg dir; a line's fields go to 0 (rid or DOI), |
| 2247 | note 6 (ORCID iD) and 7 (did). |
| 2248 | fn getoff to ulong |
| 2249 | ldarg 2 |
| 2250 | b = new uchar 24 0 |
| 2251 | fd = fopen pth 0 get pthl 0 524288 0 |
| 2252 | if lt fd 0 |
| 2253 | ret 0 |
| 2254 | end |
| 2255 | k = read int fd b 0 20 |
| 2256 | x = fclose int fd |
| 2257 | v = ulong 0 |
| 2258 | if gt k 0 |
| 2259 | for i ulong ulong k bound 20 |
| 2260 | c = get b i |
| 2261 | if isdig c |
| 2262 | v = add mul v 10 ulong sub c 48 |
| 2263 | end |
| 2264 | end |
| 2265 | end |
| 2266 | ret v |
| 2267 | end |
| 2268 | fn pmove n ulong m ulong to bool |
| 2269 | put rpk 0 2 |
| 2270 | put rpk 1 0 |
| 2271 | put rpk 2 uchar and m 255 |
| 2272 | put rpk 3 uchar shr m 8 |
| 2273 | for i ulong m bound 1100 |
| 2274 | put rpk add 4 i get pt2 i |
| 2275 | end |
| 2276 | o = add 4 m |
| 2277 | put rpk o uchar and n 255 |
| 2278 | put rpk add o 1 uchar shr n 8 |
| 2279 | for i ulong n bound 1100 |
| 2280 | put rpk add add o 2 i get pth i |
| 2281 | end |
| 2282 | ret eq renames rpk 0 add add o 2 n 0 0 |
| 2283 | end |
| 2284 | fn putoff v ulong to bool |
| 2285 | ldarg 2 |
| 2286 | n = get pthl 0 |
| 2287 | for i ulong n bound 1100 |
| 2288 | put pt2 i get pth i |
| 2289 | end |
| 2290 | for i ulong len kxt |
| 2291 | put pt2 add n i get kxt i |
| 2292 | end |
| 2293 | m = add n len kxt |
| 2294 | c = new uchar 24 0 |
| 2295 | d = new uchar 24 0 |
| 2296 | k = ulong 0 |
| 2297 | x = v |
| 2298 | while gt x 0 bound 20 |
| 2299 | put c k uchar add 48 rem x 10 |
| 2300 | x = div x 10 |
| 2301 | k = add k 1 |
| 2302 | end |
| 2303 | if eq k 0 |
| 2304 | put c 0 48 |
| 2305 | k = ulong 1 |
| 2306 | end |
| 2307 | for j ulong k bound 20 |
| 2308 | put d j get c sub sub k 1 j |
| 2309 | end |
| 2310 | put d k 10 |
| 2311 | r = unlink pt2 0 m |
| 2312 | fd = fopen pt2 0 m 557249 384 |
| 2313 | if lt fd 0 |
| 2314 | ret false |
| 2315 | end |
| 2316 | w = write int fd d 0 add k 1 |
| 2317 | r = fsync int fd |
| 2318 | y = fclose int fd |
| 2319 | if ne w long add k 1 |
| 2320 | ret false |
| 2321 | end |
| 2322 | ret pmove n m |
| 2323 | end |
| 2324 | note qfld: field f (0 based) of the queue line qb[a, e) into argument slot k; false when the line |
| 2325 | note has fewer fields or the field is over 500 bytes |
| 2326 | fn qcopy p ulong q ulong k ulong to void |
| 2327 | o = mul k 512 |
| 2328 | for i ulong sub q p bound 512 |
| 2329 | c = get qb add p i |
| 2330 | put av add o i c |
| 2331 | end |
| 2332 | put avl k sub q p |
| 2333 | end |
| 2334 | fn qfld a ulong e ulong f ulong k ulong to bool |
| 2335 | p = a |
| 2336 | j = ulong 0 |
| 2337 | while lt j f bound 8 |
| 2338 | while lt p e bound 65536 |
| 2339 | if eq get qb p 9 |
| 2340 | break |
| 2341 | end |
| 2342 | p = add p 1 |
| 2343 | end |
| 2344 | if ge p e |
| 2345 | ret false |
| 2346 | end |
| 2347 | p = add p 1 |
| 2348 | j = add j 1 |
| 2349 | end |
| 2350 | q = p |
| 2351 | while lt q e bound 65536 |
| 2352 | if eq get qb q 9 |
| 2353 | break |
| 2354 | end |
| 2355 | q = add q 1 |
| 2356 | end |
| 2357 | if gt sub q p 500 |
| 2358 | ret false |
| 2359 | end |
| 2360 | qcopy p q k |
| 2361 | ret true |
| 2362 | end |
| 2363 | fn nfld a ulong e ulong to ulong |
| 2364 | n = ulong 1 |
| 2365 | i = a |
| 2366 | while lt i e bound 65536 |
| 2367 | if eq get qb i 9 |
| 2368 | n = add n 1 |
| 2369 | end |
| 2370 | i = add i 1 |
| 2371 | end |
| 2372 | ret n |
| 2373 | end |
| 2374 | note zdoiok: argument k is empty or 10.5281/zenodo.<1 to 12 digits> |
| 2375 | fn zdoiok k ulong to bool |
| 2376 | n = get avl k |
| 2377 | if eq n 0 |
| 2378 | ret true |
| 2379 | end |
| 2380 | m = len kzpre |
| 2381 | if or le n m gt n add m 12 |
| 2382 | ret false |
| 2383 | end |
| 2384 | for i ulong m bound 32 |
| 2385 | if ne ava k i get kzpre i |
| 2386 | ret false |
| 2387 | end |
| 2388 | end |
| 2389 | for i ulong sub n m bound 12 |
| 2390 | if not isdig ava k add m i |
| 2391 | ret false |
| 2392 | end |
| 2393 | end |
| 2394 | ret true |
| 2395 | end |
| 2396 | note kdid: key- and 16 hex characters of SHA-256 over the did (slot 7) |
| 2397 | fn kdid to void |
| 2398 | b = new uchar 128 0 |
| 2399 | d = new uchar 32 0 |
| 2400 | n = get avl 7 |
| 2401 | for i ulong n bound 96 |
| 2402 | put b i ava 7 i |
| 2403 | end |
| 2404 | r = sha2_digest 256 view part b 0 n d |
| 2405 | em kkey |
| 2406 | for i ulong 8 |
| 2407 | v = get d i |
| 2408 | emb get khex ulong shr v 4 |
| 2409 | emb get khex ulong and v 15 |
| 2410 | end |
| 2411 | end |
| 2412 | fn qrefuse m view uchar * to void |
| 2413 | lgt m |
| 2414 | lgb 10 |
| 2415 | end |
| 2416 | note qline: one queue line qb[a, e) |
| 2417 | fn qline a ulong e ulong to void |
| 2418 | if lt sub e a 3 |
| 2419 | qrefuse mqbad |
| 2420 | ret |
| 2421 | end |
| 2422 | ty = get qb a |
| 2423 | ok = or eq ty 90 eq ty 80 |
| 2424 | if ok |
| 2425 | ok = eq get qb add a 1 9 |
| 2426 | end |
| 2427 | if ok |
| 2428 | ok = eq nfld a e 4 |
| 2429 | end |
| 2430 | if ok |
| 2431 | ok = qfld a e 1 7 |
| 2432 | end |
| 2433 | if ok |
| 2434 | ok = didok 7 |
| 2435 | end |
| 2436 | if ok |
| 2437 | if eq ty 90 |
| 2438 | ok = qfld a e 2 6 |
| 2439 | if ok |
| 2440 | if gt get avl 6 0 |
| 2441 | ok = orcok 6 |
| 2442 | end |
| 2443 | end |
| 2444 | if ok |
| 2445 | ok = qfld a e 3 0 |
| 2446 | end |
| 2447 | if ok |
| 2448 | ok = zdoiok 0 |
| 2449 | if eq add get avl 6 get avl 0 0 |
| 2450 | ok = false |
| 2451 | end |
| 2452 | end |
| 2453 | else |
| 2454 | ok = qfld a e 3 6 |
| 2455 | if ok |
| 2456 | if gt get avl 6 0 |
| 2457 | ok = orcok 6 |
| 2458 | end |
| 2459 | end |
| 2460 | if ok |
| 2461 | ok = qfld a e 2 0 |
| 2462 | end |
| 2463 | if ok |
| 2464 | ok = ridok 0 |
| 2465 | end |
| 2466 | end |
| 2467 | end |
| 2468 | if not ok |
| 2469 | qrefuse mqbad |
| 2470 | ret |
| 2471 | end |
| 2472 | note the shelf's allow file names the key or *; no file: no key may add |
| 2473 | ldarg 3 |
| 2474 | if not rload |
| 2475 | if ne get rerr 0 0 |
| 2476 | qrefuse mpolicy |
| 2477 | put pfail 0 1 |
| 2478 | ret |
| 2479 | end |
| 2480 | qrefuse mqallow |
| 2481 | ret |
| 2482 | end |
| 2483 | if not or rstar rhas 7 false |
| 2484 | qrefuse mqallow |
| 2485 | ret |
| 2486 | end |
| 2487 | ldarg 4 |
| 2488 | rloaded = rload |
| 2489 | if ne get rerr 0 0 |
| 2490 | qrefuse mpolicy |
| 2491 | put pfail 0 1 |
| 2492 | ret |
| 2493 | end |
| 2494 | if rloaded |
| 2495 | if or or rhas 7 false rhas 0 true rhas 6 false |
| 2496 | qrefuse mqrem |
| 2497 | ret |
| 2498 | end |
| 2499 | end |
| 2500 | emb ty |
| 2501 | emb 9 |
| 2502 | ema 7 |
| 2503 | emb 9 |
| 2504 | if eq ty 90 |
| 2505 | ema 6 |
| 2506 | emb 9 |
| 2507 | ema 0 |
| 2508 | else |
| 2509 | ema 0 |
| 2510 | emb 9 |
| 2511 | ema 6 |
| 2512 | end |
| 2513 | emb 9 |
| 2514 | if gt get avl 6 0 |
| 2515 | for i ulong 19 |
| 2516 | emb lowc ava 6 i |
| 2517 | end |
| 2518 | else |
| 2519 | kdid |
| 2520 | end |
| 2521 | emb 10 |
| 2522 | end |
| 2523 | fn qmode to int |
| 2524 | for k ulong 5 |
| 2525 | if eq get avl add k 1 0 |
| 2526 | ret 2 |
| 2527 | end |
| 2528 | end |
| 2529 | n = get avl 1 |
| 2530 | if ne ava 1 sub n 1 47 |
| 2531 | ret 2 |
| 2532 | end |
| 2533 | if ne ava 5 sub get avl 5 1 47 |
| 2534 | ret 2 |
| 2535 | end |
| 2536 | for i ulong n bound 512 |
| 2537 | put pth i ava 1 i |
| 2538 | end |
| 2539 | for i ulong len kq |
| 2540 | put pth add n i get kq i |
| 2541 | end |
| 2542 | put pthl 0 add n len kq |
| 2543 | fd = fopen pth 0 get pthl 0 524288 0 |
| 2544 | if lt fd 0 |
| 2545 | ret done 0 |
| 2546 | end |
| 2547 | off = getoff |
| 2548 | k = pread int fd qb 0 65536 long off |
| 2549 | x = fclose int fd |
| 2550 | if le k 0 |
| 2551 | ret done 0 |
| 2552 | end |
| 2553 | m = ulong k |
| 2554 | a = ulong 0 |
| 2555 | while lt a m bound 65536 |
| 2556 | e = a |
| 2557 | while lt e m bound 65536 |
| 2558 | if eq get qb e 10 |
| 2559 | break |
| 2560 | end |
| 2561 | e = add e 1 |
| 2562 | end |
| 2563 | if ge e m |
| 2564 | if and eq a 0 eq m 65536 |
| 2565 | a = m |
| 2566 | end |
| 2567 | break |
| 2568 | end |
| 2569 | qline a e |
| 2570 | a = add e 1 |
| 2571 | end |
| 2572 | if ne get pfail 0 0 |
| 2573 | put obl 0 0 |
| 2574 | ret done 1 |
| 2575 | end |
| 2576 | if not putoff add off a |
| 2577 | ret done 1 |
| 2578 | end |
| 2579 | ret done 0 |
| 2580 | end |
| 2581 | note ---- onshelf: exit 0 when the shelf list (slot 1) lists RID (slot 2) as brought by DID (slot 3) |
| 2582 | fn smode to int |
| 2583 | if not ridok 2 |
| 2584 | ret 2 |
| 2585 | end |
| 2586 | if not didok 3 |
| 2587 | ret 2 |
| 2588 | end |
| 2589 | for i ulong get avl 2 bound 512 |
| 2590 | put av i ava 2 i |
| 2591 | end |
| 2592 | put avl 0 get avl 2 |
| 2593 | for i ulong get avl 3 bound 512 |
| 2594 | put av add 3584 i ava 3 i |
| 2595 | end |
| 2596 | put avl 7 get avl 3 |
| 2597 | if listed 1 |
| 2598 | ret 0 |
| 2599 | end |
| 2600 | ret 1 |
| 2601 | end |
| 2602 | note ---- per-import bundles end at the next W or O. Never join provenance by slug globally. |
| 2603 | fn slugok a ulong b ulong to bool |
| 2604 | if or le b a gt sub b a 64 |
| 2605 | ret false |
| 2606 | end |
| 2607 | for i ulong sub b a bound 64 |
| 2608 | c = get ib add a i |
| 2609 | if not or or isdig c islow c eq c 45 |
| 2610 | ret false |
| 2611 | end |
| 2612 | end |
| 2613 | ret true |
| 2614 | end |
| 2615 | fn wserial a ulong b ulong to ulong |
| 2616 | if or le b a gt sub b a 19 |
| 2617 | ret 18446744073709551615 |
| 2618 | end |
| 2619 | if eq get ib a 48 |
| 2620 | ret 18446744073709551615 |
| 2621 | end |
| 2622 | v = ulong 0 |
| 2623 | for i ulong sub b a bound 19 |
| 2624 | c = get ib add a i |
| 2625 | if not isdig c |
| 2626 | ret 18446744073709551615 |
| 2627 | end |
| 2628 | v = add mul v 10 ulong sub c 48 |
| 2629 | end |
| 2630 | ret v |
| 2631 | end |
| 2632 | fn gend s ulong to ulong |
| 2633 | t = add eol s 1 |
| 2634 | while lt t get ibl 0 bound 8388608 |
| 2635 | c = get ib t |
| 2636 | if or or eq c 87 eq c 79 eq c 88 |
| 2637 | ret t |
| 2638 | end |
| 2639 | t = add eol t 1 |
| 2640 | end |
| 2641 | ret get ibl 0 |
| 2642 | end |
| 2643 | note Canonical raw/gather output has a trailing O block; header-only legacy input is the fallback. |
| 2644 | note gmode rejects mixed header/trailing input before this association can cross imports. |
| 2645 | fn gprofile s ulong to ulong |
| 2646 | t = add eol s 1 |
| 2647 | while lt t get ibl 0 bound 8388608 |
| 2648 | if eq get ib t 88 |
| 2649 | break |
| 2650 | end |
| 2651 | if eq get ib t 79 |
| 2652 | ret t |
| 2653 | end |
| 2654 | t = add eol t 1 |
| 2655 | end |
| 2656 | t = ulong 0 |
| 2657 | while lt t s bound 8388608 |
| 2658 | if eq get ib t 79 |
| 2659 | ret t |
| 2660 | end |
| 2661 | if eq get ib t 87 |
| 2662 | break |
| 2663 | end |
| 2664 | t = add eol t 1 |
| 2665 | end |
| 2666 | ret get ibl 0 |
| 2667 | end |
| 2668 | fn goval s ulong key view uchar * to ulong |
| 2669 | t = s |
| 2670 | while lt t get ibl 0 bound 8388608 |
| 2671 | e = eol t |
| 2672 | if ne get ib t 79 |
| 2673 | break |
| 2674 | end |
| 2675 | if lpre t e key |
| 2676 | ret add t len key |
| 2677 | end |
| 2678 | t = add e 1 |
| 2679 | end |
| 2680 | ret get ibl 0 |
| 2681 | end |
| 2682 | fn gsameslug s ulong t ulong to bool |
| 2683 | ret feqr add s 2 tabat add s 2 eol s add t 2 tabat add t 2 eol t |
| 2684 | end |
| 2685 | note Exactly one matching fact inside this bundle, ibl means absent, ibl+1 ambiguous. |
| 2686 | fn gfact s ulong ty uchar to ulong |
| 2687 | t = add eol s 1 |
| 2688 | v = get ibl 0 |
| 2689 | lim = gend s |
| 2690 | while lt t lim bound 8388608 |
| 2691 | if eq get ib t ty |
| 2692 | if not gsameslug s t |
| 2693 | ret add get ibl 0 1 |
| 2694 | end |
| 2695 | if lt v get ibl 0 |
| 2696 | ret add get ibl 0 1 |
| 2697 | end |
| 2698 | v = t |
| 2699 | end |
| 2700 | t = add eol t 1 |
| 2701 | end |
| 2702 | ret v |
| 2703 | end |
| 2704 | note N: slug, static O key, value, scoped inside the W bundle. I: slug, original P.open. |
| 2705 | note P.open stays conservative across repeated selected-only gathers. I preserves the own |
| 2706 | note decision without reopening aggregate-closed text; a successful full raw selection can reopen it. |
| 2707 | note N is private association data, never inferred from the shared selected O profile. |
| 2708 | fn gnfirst s ulong to ulong |
| 2709 | t = add eol s 1 |
| 2710 | lim = gend s |
| 2711 | while lt t lim bound 8388608 |
| 2712 | if eq get ib t 78 |
| 2713 | ret t |
| 2714 | end |
| 2715 | t = add eol t 1 |
| 2716 | end |
| 2717 | ret get ibl 0 |
| 2718 | end |
| 2719 | fn gnval s ulong key view uchar * to ulong |
| 2720 | t = gnfirst s |
| 2721 | lim = gend s |
| 2722 | while lt t lim bound 8388608 |
| 2723 | if eq get ib t 78 |
| 2724 | a = sfield t eol t 2 |
| 2725 | if lpre a eol t key |
| 2726 | ret add a len key |
| 2727 | end |
| 2728 | end |
| 2729 | t = add eol t 1 |
| 2730 | end |
| 2731 | ret get ibl 0 |
| 2732 | end |
| 2733 | fn gorcid s ulong to ulong |
| 2734 | if lt gnfirst s get ibl 0 |
| 2735 | ret gnval s korc |
| 2736 | end |
| 2737 | ret goval gprofile s koo |
| 2738 | end |
| 2739 | note Association validation is structural; publisher still validates the public profile values. |
| 2740 | fn gbound s ulong to bool |
| 2741 | if ge gnfirst s get ibl 0 |
| 2742 | ret eq gfact s 73 get ibl 0 |
| 2743 | end |
| 2744 | il = gfact s 73 |
| 2745 | if ge il get ibl 0 |
| 2746 | ret false |
| 2747 | end |
| 2748 | v = sfield il eol il 2 |
| 2749 | if ne sub eol il v 1 |
| 2750 | ret false |
| 2751 | end |
| 2752 | if not or reqt v eol il kone reqt v eol il kzero |
| 2753 | ret false |
| 2754 | end |
| 2755 | t = add eol s 1 |
| 2756 | lim = gend s |
| 2757 | while lt t lim bound 8388608 |
| 2758 | if eq get ib t 78 |
| 2759 | if not gsameslug s t |
| 2760 | ret false |
| 2761 | end |
| 2762 | a = sfield t eol t 2 |
| 2763 | b = tabat a eol t |
| 2764 | if or ge b eol t eq a b |
| 2765 | ret false |
| 2766 | end |
| 2767 | if or lpre a eol t kna or lpre a eol t knc lpre a eol t knv |
| 2768 | ret false |
| 2769 | end |
| 2770 | u = add eol s 1 |
| 2771 | while lt u t bound 8388608 |
| 2772 | if eq get ib u 78 |
| 2773 | c = sfield u eol u 2 |
| 2774 | if feqr a b c tabat c eol u |
| 2775 | ret false |
| 2776 | end |
| 2777 | end |
| 2778 | u = add eol u 1 |
| 2779 | end |
| 2780 | end |
| 2781 | t = add eol t 1 |
| 2782 | end |
| 2783 | ret and lt gnval s knid get ibl 0 lt gnval s knname get ibl 0 |
| 2784 | end |
| 2785 | fn gbindings to bool |
| 2786 | s = ulong 0 |
| 2787 | while lt s get ibl 0 bound 8388608 |
| 2788 | if eq get ib s 87 |
| 2789 | if not gbound s |
| 2790 | ret false |
| 2791 | end |
| 2792 | end |
| 2793 | s = add eol s 1 |
| 2794 | end |
| 2795 | ret true |
| 2796 | end |
| 2797 | fn gorig s ulong pl ulong to ulong |
| 2798 | t = gfact s 73 |
| 2799 | if lt t get ibl 0 |
| 2800 | ret sfield t eol t 2 |
| 2801 | end |
| 2802 | ret sfield pl eol pl 6 |
| 2803 | end |
| 2804 | fn gnhead s ulong to void |
| 2805 | em knn |
| 2806 | a = add s 2 |
| 2807 | emr a tabat a eol s |
| 2808 | emb 9 |
| 2809 | end |
| 2810 | fn gattach s ulong to void |
| 2811 | t = gnfirst s |
| 2812 | if lt t get ibl 0 |
| 2813 | lim = gend s |
| 2814 | while lt t lim bound 8388608 |
| 2815 | if eq get ib t 78 |
| 2816 | emr t eol t |
| 2817 | emb 10 |
| 2818 | end |
| 2819 | t = add eol t 1 |
| 2820 | end |
| 2821 | else |
| 2822 | t = gprofile s |
| 2823 | while lt t get ibl 0 bound 8388608 |
| 2824 | e = eol t |
| 2825 | if ne get ib t 79 |
| 2826 | break |
| 2827 | end |
| 2828 | if not or lpre t e koa or lpre t e koc lpre t e kov |
| 2829 | gnhead s |
| 2830 | emr add t 2 e |
| 2831 | emb 10 |
| 2832 | end |
| 2833 | t = add e 1 |
| 2834 | end |
| 2835 | end |
| 2836 | pl = gfact s 80 |
| 2837 | if lt pl get ibl 0 |
| 2838 | em kni |
| 2839 | a = add s 2 |
| 2840 | emr a tabat a eol s |
| 2841 | emb 9 |
| 2842 | v = gorig s pl |
| 2843 | emr v eol v |
| 2844 | emb 10 |
| 2845 | end |
| 2846 | end |
| 2847 | note Older repo serializers put G after the final O profile. Gather moves the chosen G into its bundle. |
| 2848 | fn gsource s ulong to ulong |
| 2849 | v = gfact s 71 |
| 2850 | if ne v get ibl 0 |
| 2851 | ret v |
| 2852 | end |
| 2853 | t = gend s |
| 2854 | if lt t get ibl 0 |
| 2855 | if eq get ib t 79 |
| 2856 | while lt t get ibl 0 bound 8388608 |
| 2857 | if or eq get ib t 87 eq get ib t 88 |
| 2858 | break |
| 2859 | end |
| 2860 | if eq get ib t 71 |
| 2861 | if gsameslug s t |
| 2862 | if lt v get ibl 0 |
| 2863 | ret add get ibl 0 1 |
| 2864 | end |
| 2865 | v = t |
| 2866 | end |
| 2867 | end |
| 2868 | t = add eol t 1 |
| 2869 | end |
| 2870 | end |
| 2871 | end |
| 2872 | ret v |
| 2873 | end |
| 2874 | fn shelfok a ulong b ulong c ulong d ulong to bool |
| 2875 | x = a |
| 2876 | if lpre a b krp |
| 2877 | x = add a 4 |
| 2878 | end |
| 2879 | if or gt sub b x 44 gt sub d c 96 |
| 2880 | ret false |
| 2881 | end |
| 2882 | for i ulong sub b x bound 44 |
| 2883 | put av i get ib add x i |
| 2884 | end |
| 2885 | put avl 0 sub b x |
| 2886 | for i ulong sub d c bound 96 |
| 2887 | put av add 3584 i get ib add c i |
| 2888 | end |
| 2889 | put avl 7 sub d c |
| 2890 | ret listed 2 |
| 2891 | end |
| 2892 | fn gremoved s ulong k ulong pre bool to bool |
| 2893 | e = eol s |
| 2894 | a = sfield s e k |
| 2895 | ret rbhas a tabat a e pre |
| 2896 | end |
| 2897 | fn gexplicit s ulong pl ulong to bool |
| 2898 | if or gremoved s 1 false or gremoved s 6 false gremoved s 7 false |
| 2899 | ret true |
| 2900 | end |
| 2901 | if lt pl get ibl 0 |
| 2902 | ret gremoved pl 5 true |
| 2903 | end |
| 2904 | ret false |
| 2905 | end |
| 2906 | fn geligible s ulong pl ulong to bool |
| 2907 | if ge pl get ibl 0 |
| 2908 | ret false |
| 2909 | end |
| 2910 | if ne get gn 1 0 |
| 2911 | if gremoved pl 3 false |
| 2912 | ret false |
| 2913 | end |
| 2914 | v = gorcid s |
| 2915 | if lt v get ibl 0 |
| 2916 | if rbhas v eol v false |
| 2917 | ret false |
| 2918 | end |
| 2919 | end |
| 2920 | end |
| 2921 | pe = eol pl |
| 2922 | how = sfield pl pe 2 |
| 2923 | if reqt how tabat how pe krv |
| 2924 | src = sfield pl pe 5 |
| 2925 | dd = sfield pl pe 3 |
| 2926 | ret shelfok src tabat src pe dd tabat dd pe |
| 2927 | end |
| 2928 | ret true |
| 2929 | end |
| 2930 | fn gtvalid t ulong to bool |
| 2931 | if eq t get ibl 0 |
| 2932 | ret true |
| 2933 | end |
| 2934 | if gt t get ibl 0 |
| 2935 | ret false |
| 2936 | end |
| 2937 | e = eol t |
| 2938 | a = sfield t e 2 |
| 2939 | if eq sub e a 1 |
| 2940 | ret eq get ib a 45 |
| 2941 | end |
| 2942 | if ne sub e a 64 |
| 2943 | ret false |
| 2944 | end |
| 2945 | for i ulong 64 |
| 2946 | c = get ib add a i |
| 2947 | if not or isdig c and ge c 97 le c 102 |
| 2948 | ret false |
| 2949 | end |
| 2950 | end |
| 2951 | ret true |
| 2952 | end |
| 2953 | fn gscan to ulong |
| 2954 | n = ulong 0 |
| 2955 | s = ulong 0 |
| 2956 | while lt s get ibl 0 bound 8388608 |
| 2957 | if eq get ib s 87 |
| 2958 | put gbw n s |
| 2959 | put gbe n gend s |
| 2960 | pl = gfact s 80 |
| 2961 | put gbp n pl |
| 2962 | put gbg n gsource s |
| 2963 | put gbs n 0 |
| 2964 | put gbk n 0 |
| 2965 | put gbl n 0 |
| 2966 | a = add s 2 |
| 2967 | if slugok a tabat a eol s |
| 2968 | if geligible s pl |
| 2969 | if le get gbg n get ibl 0 |
| 2970 | r = gfact s 82 |
| 2971 | t = gfact s 84 |
| 2972 | if and le r get ibl 0 gtvalid t |
| 2973 | seq = ulong 0 |
| 2974 | if lt r get ibl 0 |
| 2975 | v = sfield r eol r 2 |
| 2976 | seq = wserial v eol r |
| 2977 | end |
| 2978 | if ne seq 18446744073709551615 |
| 2979 | put gbs n seq |
| 2980 | put gbk n 1 |
| 2981 | v = sfield pl eol pl 6 |
| 2982 | if reqt v eol pl kone |
| 2983 | put gbl n 1 |
| 2984 | end |
| 2985 | end |
| 2986 | end |
| 2987 | end |
| 2988 | end |
| 2989 | end |
| 2990 | n = add n 1 |
| 2991 | end |
| 2992 | s = add eol s 1 |
| 2993 | end |
| 2994 | ret n |
| 2995 | end |
| 2996 | note Each copy is filtered before dedup/licence aggregation; explicit work/source takedowns span copies. |
| 2997 | fn gpick i ulong n ulong to ulong |
| 2998 | s = get gbw i |
| 2999 | win = n |
| 3000 | for j ulong n bound 2796203 |
| 3001 | if gsameslug s get gbw j |
| 3002 | if ne get gn 1 0 |
| 3003 | if gexplicit get gbw j get gbp j |
| 3004 | ret n |
| 3005 | end |
| 3006 | end |
| 3007 | if ge get gbw j get gxs 0 |
| 3008 | continue |
| 3009 | end |
| 3010 | if ne get gbk j 0 |
| 3011 | if eq win n |
| 3012 | win = j |
| 3013 | else |
| 3014 | if ge get gbs j get gbs win |
| 3015 | win = j |
| 3016 | end |
| 3017 | end |
| 3018 | end |
| 3019 | end |
| 3020 | end |
| 3021 | ret win |
| 3022 | end |
| 3023 | fn gopen i ulong n ulong to bool |
| 3024 | for j ulong n bound 2796203 |
| 3025 | if ne get gbk j 0 |
| 3026 | if gsameslug get gbw i get gbw j |
| 3027 | if eq get gbl j 0 |
| 3028 | ret false |
| 3029 | end |
| 3030 | end |
| 3031 | end |
| 3032 | end |
| 3033 | ret true |
| 3034 | end |
| 3035 | fn gemit i ulong n ulong to void |
| 3036 | s = get gbw i |
| 3037 | t = s |
| 3038 | while lt t get gbe i bound 8388608 |
| 3039 | e = eol t |
| 3040 | c = get ib t |
| 3041 | if not or eq c 78 eq c 73 |
| 3042 | if eq c 80 |
| 3043 | v = sfield t e 6 |
| 3044 | emr t v |
| 3045 | if gopen i n |
| 3046 | emb 49 |
| 3047 | else |
| 3048 | emb 48 |
| 3049 | end |
| 3050 | else |
| 3051 | emr t e |
| 3052 | end |
| 3053 | emb 10 |
| 3054 | end |
| 3055 | t = add e 1 |
| 3056 | end |
| 3057 | gattach s |
| 3058 | g = get gbg i |
| 3059 | if lt g get ibl 0 |
| 3060 | if ge g get gbe i |
| 3061 | emr g eol g |
| 3062 | emb 10 |
| 3063 | end |
| 3064 | end |
| 3065 | end |
| 3066 | fn gemprofile i ulong to void |
| 3067 | s = get gbw i |
| 3068 | pl = get gbp i |
| 3069 | t = gnfirst s |
| 3070 | if lt t get ibl 0 |
| 3071 | lim = gend s |
| 3072 | while lt t lim bound 8388608 |
| 3073 | if eq get ib t 78 |
| 3074 | em kob |
| 3075 | v = sfield t eol t 2 |
| 3076 | emr v eol t |
| 3077 | emb 10 |
| 3078 | end |
| 3079 | t = add eol t 1 |
| 3080 | end |
| 3081 | else |
| 3082 | t = gprofile s |
| 3083 | while lt t get ibl 0 bound 8388608 |
| 3084 | e = eol t |
| 3085 | if ne get ib t 79 |
| 3086 | break |
| 3087 | end |
| 3088 | if not or lpre t e koa or lpre t e koc lpre t e kov |
| 3089 | emr t e |
| 3090 | emb 10 |
| 3091 | end |
| 3092 | t = add e 1 |
| 3093 | end |
| 3094 | end |
| 3095 | em koa |
| 3096 | v = sfield pl eol pl 3 |
| 3097 | emr v tabat v eol pl |
| 3098 | emb 10 |
| 3099 | em koc |
| 3100 | v = sfield pl eol pl 4 |
| 3101 | emr v tabat v eol pl |
| 3102 | emb 10 |
| 3103 | em kov |
| 3104 | v = sfield pl eol pl 2 |
| 3105 | emr v tabat v eol pl |
| 3106 | emb 10 |
| 3107 | end |
| 3108 | note Legacy header-only input is accepted, but header plus later raw profile is ambiguous. |
| 3109 | fn gmixed to bool |
| 3110 | header = false |
| 3111 | works = false |
| 3112 | s = ulong 0 |
| 3113 | while lt s get ibl 0 bound 8388608 |
| 3114 | c = get ib s |
| 3115 | if eq c 87 |
| 3116 | works = true |
| 3117 | end |
| 3118 | if eq c 79 |
| 3119 | if works |
| 3120 | if header |
| 3121 | ret true |
| 3122 | end |
| 3123 | else |
| 3124 | header = true |
| 3125 | end |
| 3126 | end |
| 3127 | s = add eol s 1 |
| 3128 | end |
| 3129 | ret false |
| 3130 | end |
| 3131 | fn gmode to int |
| 3132 | if not rdin |
| 3133 | x = flush 2 mbig len mbig |
| 3134 | ret 2 |
| 3135 | end |
| 3136 | if gmixed |
| 3137 | lgt mprofile |
| 3138 | lgb 10 |
| 3139 | ret done 1 |
| 3140 | end |
| 3141 | if not gbindings |
| 3142 | lgt mbind |
| 3143 | lgb 10 |
| 3144 | ret done 1 |
| 3145 | end |
| 3146 | put gxs 0 get ibl 0 |
| 3147 | saux = ulong 0 |
| 3148 | while lt saux get ibl 0 bound 8388608 |
| 3149 | if eq get ib saux 88 |
| 3150 | if lt get gxs 0 get ibl 0 |
| 3151 | lgt maux |
| 3152 | lgb 10 |
| 3153 | ret done 1 |
| 3154 | end |
| 3155 | put gxs 0 saux |
| 3156 | else |
| 3157 | if lt get gxs 0 saux |
| 3158 | if eq get ib saux 79 |
| 3159 | lgt maux |
| 3160 | lgb 10 |
| 3161 | ret done 1 |
| 3162 | end |
| 3163 | if eq get ib saux 87 |
| 3164 | if ge gnfirst saux get ibl 0 |
| 3165 | lgt maux |
| 3166 | lgb 10 |
| 3167 | ret done 1 |
| 3168 | end |
| 3169 | end |
| 3170 | end |
| 3171 | end |
| 3172 | saux = add eol saux 1 |
| 3173 | end |
| 3174 | put gn 1 0 |
| 3175 | ldarg 1 |
| 3176 | if rload |
| 3177 | put gn 1 1 |
| 3178 | end |
| 3179 | if ne get rerr 0 0 |
| 3180 | lgt mpolicy |
| 3181 | lgb 10 |
| 3182 | ret done 1 |
| 3183 | end |
| 3184 | n = gscan |
| 3185 | profile = n |
| 3186 | for i ulong n bound 2796203 |
| 3187 | put gbsel i 0 |
| 3188 | if eq gpick i n i |
| 3189 | put gbsel i 1 |
| 3190 | if eq profile n |
| 3191 | profile = i |
| 3192 | else |
| 3193 | if ge get gbs i get gbs profile |
| 3194 | profile = i |
| 3195 | end |
| 3196 | end |
| 3197 | end |
| 3198 | end |
| 3199 | if eq profile n |
| 3200 | ret done 0 |
| 3201 | end |
| 3202 | s = ulong 0 |
| 3203 | while lt s get ibl 0 bound 8388608 |
| 3204 | if eq get ib s 72 |
| 3205 | emr s eol s |
| 3206 | emb 10 |
| 3207 | end |
| 3208 | s = add eol s 1 |
| 3209 | end |
| 3210 | for i ulong n bound 2796203 |
| 3211 | if ne get gbsel i 0 |
| 3212 | gemit i n |
| 3213 | end |
| 3214 | end |
| 3215 | gemprofile profile |
| 3216 | ret done 0 |
| 3217 | end |
| 3218 | note ---- layout: one raw catalog, or a selected catalog with explicit bundle associations. |
| 3219 | note It neither reads policy nor picks, removes, deduplicates or changes a P.open flag. |
| 3220 | note Selected input always requires explicit N/I facts. Old selections cannot establish exact |
| 3221 | note association from shared O; rebuild from retained raw catalogs. Legacy raw headers convert alone. |
| 3222 | fn lcopy s ulong to void |
| 3223 | t = s |
| 3224 | lim = gend s |
| 3225 | while lt t lim bound 8388608 |
| 3226 | c = get ib t |
| 3227 | if not or eq c 78 eq c 73 |
| 3228 | emr t eol t |
| 3229 | emb 10 |
| 3230 | end |
| 3231 | t = add eol t 1 |
| 3232 | end |
| 3233 | gattach s |
| 3234 | end |
| 3235 | fn lmode to int |
| 3236 | if not or argeq 1 kraw argeq 1 ksel |
| 3237 | ret 2 |
| 3238 | end |
| 3239 | if not rdin |
| 3240 | x = flush 2 mbig len mbig |
| 3241 | ret 2 |
| 3242 | end |
| 3243 | if gmixed |
| 3244 | lgt mprofile |
| 3245 | lgb 10 |
| 3246 | ret done 1 |
| 3247 | end |
| 3248 | if not gbindings |
| 3249 | lgt mbind |
| 3250 | lgb 10 |
| 3251 | ret done 1 |
| 3252 | end |
| 3253 | nw = ulong 0 |
| 3254 | nn = ulong 0 |
| 3255 | blocks = ulong 0 |
| 3256 | waso = false |
| 3257 | s = ulong 0 |
| 3258 | while lt s get ibl 0 bound 8388608 |
| 3259 | c = get ib s |
| 3260 | if eq c 87 |
| 3261 | nw = add nw 1 |
| 3262 | if lt gnfirst s get ibl 0 |
| 3263 | nn = add nn 1 |
| 3264 | end |
| 3265 | end |
| 3266 | if eq c 79 |
| 3267 | if not waso |
| 3268 | blocks = add blocks 1 |
| 3269 | end |
| 3270 | waso = true |
| 3271 | else |
| 3272 | waso = false |
| 3273 | end |
| 3274 | if eq c 88 |
| 3275 | lgt mlayout |
| 3276 | lgb 10 |
| 3277 | ret done 1 |
| 3278 | end |
| 3279 | if argeq 1 kraw |
| 3280 | if or eq c 78 eq c 73 |
| 3281 | lgt mlayout |
| 3282 | lgb 10 |
| 3283 | ret done 1 |
| 3284 | end |
| 3285 | end |
| 3286 | s = add eol s 1 |
| 3287 | end |
| 3288 | if argeq 1 kraw |
| 3289 | if or gt blocks 1 and gt nw 0 eq blocks 0 |
| 3290 | lgt mlayout |
| 3291 | lgb 10 |
| 3292 | ret done 1 |
| 3293 | end |
| 3294 | else |
| 3295 | if ne nn nw |
| 3296 | lgt munbound |
| 3297 | lgb 10 |
| 3298 | ret done 1 |
| 3299 | end |
| 3300 | end |
| 3301 | s = ulong 0 |
| 3302 | while lt s get ibl 0 bound 8388608 |
| 3303 | if eq get ib s 87 |
| 3304 | lcopy s |
| 3305 | s = gend s |
| 3306 | continue |
| 3307 | end |
| 3308 | if ne get ib s 79 |
| 3309 | emr s eol s |
| 3310 | emb 10 |
| 3311 | end |
| 3312 | s = add eol s 1 |
| 3313 | end |
| 3314 | ret done 0 |
| 3315 | end |
| 3316 | note ---- bind: descriptors are derived only from this import's fresh alias, never old hashed cache. |
| 3317 | fn seqok to bool |
| 3318 | n = get avl 1 |
| 3319 | if or eq n 0 gt n 19 |
| 3320 | ret false |
| 3321 | end |
| 3322 | if eq ava 1 0 48 |
| 3323 | ret false |
| 3324 | end |
| 3325 | for i ulong n bound 19 |
| 3326 | if not isdig ava 1 i |
| 3327 | ret false |
| 3328 | end |
| 3329 | end |
| 3330 | ret true |
| 3331 | end |
| 3332 | fn bhash s ulong to bool |
| 3333 | b = new uchar 4096 0 |
| 3334 | ctx = new ulong 40 0 |
| 3335 | d = new uchar 32 0 |
| 3336 | n = get avl 2 |
| 3337 | for i ulong n bound 512 |
| 3338 | put pth i ava 2 i |
| 3339 | end |
| 3340 | a = add s 2 |
| 3341 | z = tabat a eol s |
| 3342 | for i ulong sub z a bound 64 |
| 3343 | put pth add n i get ib add a i |
| 3344 | end |
| 3345 | n = add n sub z a |
| 3346 | for i ulong len ktxt |
| 3347 | put pth add n i get ktxt i |
| 3348 | end |
| 3349 | n = add n len ktxt |
| 3350 | fd = fopen pth 0 n 559104 0 |
| 3351 | if lt fd 0 |
| 3352 | ret false |
| 3353 | end |
| 3354 | ok = rregular int fd |
| 3355 | sha256_init ctx |
| 3356 | total = ulong 0 |
| 3357 | k = long 1 |
| 3358 | while and ok gt k 0 bound 262145 |
| 3359 | k = read int fd b 0 4096 |
| 3360 | if lt k 0 |
| 3361 | ok = false |
| 3362 | end |
| 3363 | if gt k 0 |
| 3364 | total = add total ulong k |
| 3365 | if gt total 262144 |
| 3366 | ok = false |
| 3367 | else |
| 3368 | sha256_update ctx view part b 0 ulong k |
| 3369 | end |
| 3370 | end |
| 3371 | end |
| 3372 | x = fclose int fd |
| 3373 | if or not ok eq total 0 |
| 3374 | ret false |
| 3375 | end |
| 3376 | sha256_final ctx d |
| 3377 | for i ulong 32 |
| 3378 | put dg i get d i |
| 3379 | end |
| 3380 | ret true |
| 3381 | end |
| 3382 | fn bemit s ulong to void |
| 3383 | em kbr |
| 3384 | a = add s 2 |
| 3385 | z = tabat a eol s |
| 3386 | emr a z |
| 3387 | emb 9 |
| 3388 | ema 1 |
| 3389 | emb 10 |
| 3390 | em kbt |
| 3391 | emr a z |
| 3392 | emb 9 |
| 3393 | if bhash s |
| 3394 | for i ulong 32 |
| 3395 | c = get dg i |
| 3396 | emb get khex ulong shr c 4 |
| 3397 | emb get khex ulong and c 15 |
| 3398 | end |
| 3399 | tbr a z |
| 3400 | tbb 9 |
| 3401 | for i ulong 32 |
| 3402 | c = get dg i |
| 3403 | tbb get khex ulong shr c 4 |
| 3404 | tbb get khex ulong and c 15 |
| 3405 | end |
| 3406 | tbb 10 |
| 3407 | else |
| 3408 | emb 45 |
| 3409 | end |
| 3410 | emb 10 |
| 3411 | end |
| 3412 | fn bmode to int |
| 3413 | if not seqok |
| 3414 | ret 2 |
| 3415 | end |
| 3416 | if eq get avl 2 0 |
| 3417 | ret 2 |
| 3418 | end |
| 3419 | if ne ava 2 sub get avl 2 1 47 |
| 3420 | ret 2 |
| 3421 | end |
| 3422 | if not rdin |
| 3423 | ret 2 |
| 3424 | end |
| 3425 | s = ulong 0 |
| 3426 | active = get ibl 0 |
| 3427 | while lt s get ibl 0 bound 8388608 |
| 3428 | e = eol s |
| 3429 | c = get ib s |
| 3430 | if or eq c 87 eq c 79 |
| 3431 | if lt active get ibl 0 |
| 3432 | bemit active |
| 3433 | active = get ibl 0 |
| 3434 | end |
| 3435 | end |
| 3436 | if eq c 87 |
| 3437 | a = add s 2 |
| 3438 | if not slugok a tabat a e |
| 3439 | ret 2 |
| 3440 | end |
| 3441 | active = s |
| 3442 | end |
| 3443 | if not or eq c 82 eq c 84 |
| 3444 | emr s e |
| 3445 | emb 10 |
| 3446 | end |
| 3447 | s = add e 1 |
| 3448 | end |
| 3449 | if lt active get ibl 0 |
| 3450 | bemit active |
| 3451 | end |
| 3452 | ret done 0 |
| 3453 | end |
| 3454 | note identify: single Zenodo record jflat lines; the first well-formed creator ORCID iD |
| 3455 | fn imode to int |
| 3456 | if not rdin |
| 3457 | ret 2 |
| 3458 | end |
| 3459 | put hs 0 0 |
| 3460 | put he 0 get ibl 0 |
| 3461 | put hpl 0 0 |
| 3462 | l = hfind 0 kmeta kcor 1000000 |
| 3463 | while lt l get he 0 bound 8388608 |
| 3464 | a = vala l |
| 3465 | b = valb l |
| 3466 | if eq sub b a 19 |
| 3467 | for i ulong 19 |
| 3468 | put av add 1024 i get ib add a i |
| 3469 | end |
| 3470 | put avl 2 19 |
| 3471 | if orcok 2 |
| 3472 | emr a b |
| 3473 | emb 10 |
| 3474 | ret done 0 |
| 3475 | end |
| 3476 | end |
| 3477 | l = hfind add eol l 1 kmeta kcor 1000000 |
| 3478 | end |
| 3479 | ret 1 |
| 3480 | end |
| 3481 | note compact runs while the caller holds ADD/queue.lock, shared with forged. It copies only the |
| 3482 | note unread tail, fsyncs, writes cursor 0, then atomically replaces queue. A crash before rename can |
| 3483 | note replay already-handled requests (safe, idempotent imports), but cannot skip an unread request. |
| 3484 | fn qpaths to ulong |
| 3485 | n = get avl 1 |
| 3486 | for i ulong n bound 512 |
| 3487 | put pth i ava 1 i |
| 3488 | end |
| 3489 | for i ulong len kq |
| 3490 | put pth add n i get kq i |
| 3491 | end |
| 3492 | n = add n len kq |
| 3493 | put pthl 0 n |
| 3494 | for i ulong n bound 1100 |
| 3495 | put pt2 i get pth i |
| 3496 | end |
| 3497 | for i ulong len kxt |
| 3498 | put pt2 add n i get kxt i |
| 3499 | end |
| 3500 | ret n |
| 3501 | end |
| 3502 | fn qtail src int dest int off ulong to bool |
| 3503 | b = new uchar 4096 0 |
| 3504 | k = long 1 |
| 3505 | o = off |
| 3506 | while gt k 0 bound 9223372036854775807 |
| 3507 | k = pread src b 0 4096 long o |
| 3508 | if lt k 0 |
| 3509 | ret false |
| 3510 | end |
| 3511 | if gt k 0 |
| 3512 | if not flush dest b ulong k |
| 3513 | ret false |
| 3514 | end |
| 3515 | o = add o ulong k |
| 3516 | end |
| 3517 | end |
| 3518 | ret true |
| 3519 | end |
| 3520 | fn cmode to int |
| 3521 | if eq get avl 1 0 |
| 3522 | ret 2 |
| 3523 | end |
| 3524 | if ne ava 1 sub get avl 1 1 47 |
| 3525 | ret 2 |
| 3526 | end |
| 3527 | off = getoff |
| 3528 | if eq off 0 |
| 3529 | ret 0 |
| 3530 | end |
| 3531 | n = qpaths |
| 3532 | fd = fopen pth 0 n 557056 0 |
| 3533 | if lt fd 0 |
| 3534 | ret 1 |
| 3535 | end |
| 3536 | m = add n len kxt |
| 3537 | x = unlink pt2 0 m |
| 3538 | tmp = fopen pt2 0 m 557249 384 |
| 3539 | if lt tmp 0 |
| 3540 | x = fclose int fd |
| 3541 | ret 1 |
| 3542 | end |
| 3543 | ok = qtail int fd int tmp off |
| 3544 | x = fsync int tmp |
| 3545 | if ne x 0 |
| 3546 | ok = false |
| 3547 | end |
| 3548 | x = fclose int fd |
| 3549 | x = fclose int tmp |
| 3550 | if not ok |
| 3551 | ret 1 |
| 3552 | end |
| 3553 | if not putoff 0 |
| 3554 | ret 1 |
| 3555 | end |
| 3556 | n = qpaths |
| 3557 | if not pmove n add n len kxt |
| 3558 | ret 1 |
| 3559 | end |
| 3560 | ret 0 |
| 3561 | end |
| 3562 | note Validate configured policy IO even with an empty queue/catalog. Absence is distinct from error. |
| 3563 | fn pmode to int |
| 3564 | ldarg 1 |
| 3565 | loaded = rload |
| 3566 | if ne get rerr 0 0 |
| 3567 | qrefuse mpolicy |
| 3568 | ret done 1 |
| 3569 | end |
| 3570 | ldarg 2 |
| 3571 | loaded = rload |
| 3572 | if ne get rerr 0 0 |
| 3573 | qrefuse mpolicy |
| 3574 | ret done 1 |
| 3575 | end |
| 3576 | ret 0 |
| 3577 | end |
| 3578 | fn main to int |
| 3579 | c = argcnt |
| 3580 | if lt c 2 |
| 3581 | ret 2 |
| 3582 | end |
| 3583 | for k ulong 7 |
| 3584 | if lt add k 1 ulong c |
| 3585 | x = arg add k 1 |
| 3586 | end |
| 3587 | end |
| 3588 | if argeq 1 kmode11 |
| 3589 | if ne c 3 |
| 3590 | ret 2 |
| 3591 | end |
| 3592 | shl1 |
| 3593 | ret lmode |
| 3594 | end |
| 3595 | if argeq 1 kmode10 |
| 3596 | if ne c 4 |
| 3597 | ret 2 |
| 3598 | end |
| 3599 | shl1 |
| 3600 | ret bmode |
| 3601 | end |
| 3602 | if argeq 1 kmode1 |
| 3603 | if ne c 6 |
| 3604 | ret 2 |
| 3605 | end |
| 3606 | ret zmode |
| 3607 | end |
| 3608 | if argeq 1 kmode2 |
| 3609 | if not or eq c 6 or eq c 7 eq c 8 |
| 3610 | ret 2 |
| 3611 | end |
| 3612 | ret rmode |
| 3613 | end |
| 3614 | if argeq 1 kmode9 |
| 3615 | if ne c 4 |
| 3616 | ret 2 |
| 3617 | end |
| 3618 | shl1 |
| 3619 | ret pmode |
| 3620 | end |
| 3621 | if argeq 1 kmode8 |
| 3622 | if ne c 4 |
| 3623 | ret 2 |
| 3624 | end |
| 3625 | shl1 |
| 3626 | ret cmode |
| 3627 | end |
| 3628 | if argeq 1 kmode7 |
| 3629 | ret imode |
| 3630 | end |
| 3631 | if argeq 1 kmode3 |
| 3632 | ret tmode |
| 3633 | end |
| 3634 | if argeq 1 kmode4 |
| 3635 | if ne c 7 |
| 3636 | ret 2 |
| 3637 | end |
| 3638 | shl1 |
| 3639 | ret qmode |
| 3640 | end |
| 3641 | if argeq 1 kmode5 |
| 3642 | if ne c 4 |
| 3643 | ret 2 |
| 3644 | end |
| 3645 | shl1 |
| 3646 | ret gmode |
| 3647 | end |
| 3648 | if argeq 1 kmode6 |
| 3649 | if ne c 5 |
| 3650 | ret 2 |
| 3651 | end |
| 3652 | shl1 |
| 3653 | ret smode |
| 3654 | end |
| 3655 | ret 2 |
| 3656 | end |