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 / patch / p5imp.om
| 1 | note patch/p5imp.om: imported proposals (SPEC prstore/r1 extension, written only by tools/ghimport): |
| 2 | note reading an imported item back, its list row and page, and the diff of a bundle-backed item. |
| 3 | note Every imported byte goes out through fescc (HTML) or fjtc (JSON); a GitHub login is text. Each |
| 4 | note reader checks a length against its buffer before it reads, so a malformed or oversized file |
| 5 | note ends in "not an item", a cut value or a sentence on the page, never in a trap. |
| 6 | note ---- loading |
| 7 | note pafrd t cap: the file <t> of item gpid into fxo; its length cut to cap, 0 when it cannot be read |
| 8 | fn pafrd t view uchar * cap ulong to ulong |
| 9 | pafp t |
| 10 | n = frdall |
| 11 | if lt n 0 |
| 12 | ret 0 |
| 13 | end |
| 14 | ret hmin ulong n cap |
| 15 | end |
| 16 | note pasjat s t: gpsrc holds t at s (the caller keeps s + len t inside gpsrc) |
| 17 | fn pasjat s ulong t view uchar * to bool |
| 18 | for i ulong len t bound 64 |
| 19 | if ne get gpsrc add s i get t i |
| 20 | ret false |
| 21 | end |
| 22 | end |
| 23 | ret true |
| 24 | end |
| 25 | note pasjf t: the offset in gpsrc of the first t, the length of gpsrc when it is not there |
| 26 | fn pasjf t view uchar * to ulong |
| 27 | n = get gpsrcl 0 |
| 28 | k = len t |
| 29 | if gt k n |
| 30 | ret n |
| 31 | end |
| 32 | for s ulong add sub n k 1 bound 4097 |
| 33 | if pasjat s t |
| 34 | ret s |
| 35 | end |
| 36 | end |
| 37 | ret n |
| 38 | end |
| 39 | note pasjv t: the string value after the key text t in gpsrc: its offset; its length in gpr 15, and gpr |
| 40 | note 14 is 1 when the key is there (0 and length 0 when it is not). The value ends at its closing |
| 41 | note quote; a backslash ends it too (the value is cut there, never decoded), and so does the end of |
| 42 | note the buffer |
| 43 | fn pasjv t view uchar * to ulong |
| 44 | n = get gpsrcl 0 |
| 45 | s = pasjf t |
| 46 | put gpr 15 0 |
| 47 | put gpr 14 0 |
| 48 | if ge s n |
| 49 | ret 0 |
| 50 | end |
| 51 | put gpr 14 1 |
| 52 | p = add s len t |
| 53 | q = p |
| 54 | while lt q n bound 4097 |
| 55 | c = get gpsrc q |
| 56 | if or eq c 34 eq c 92 |
| 57 | break |
| 58 | end |
| 59 | q = add q 1 |
| 60 | end |
| 61 | put gpr 15 sub q p |
| 62 | ret p |
| 63 | end |
| 64 | note pasjnum: the number of source.json ("number":N, 1..18 digits), 0 when it has none |
| 65 | fn pasjnum to ulong |
| 66 | n = get gpsrcl 0 |
| 67 | s = pasjf tpsjnum |
| 68 | if ge s n |
| 69 | ret 0 |
| 70 | end |
| 71 | p = add s len tpsjnum |
| 72 | v = ulong 0 |
| 73 | k = ulong 0 |
| 74 | while lt p n bound 19 |
| 75 | c = get gpsrc p |
| 76 | if not fisdig c |
| 77 | break |
| 78 | end |
| 79 | if ge k 18 |
| 80 | ret 0 |
| 81 | end |
| 82 | v = add mul v 10 ulong sub c 48 |
| 83 | k = add k 1 |
| 84 | p = add p 1 |
| 85 | end |
| 86 | ret v |
| 87 | end |
| 88 | note paghat s e t: the gh line gpgh[s, e) starts with t |
| 89 | fn paghat s ulong e ulong t view uchar * to bool |
| 90 | if lt sub e s len t |
| 91 | ret false |
| 92 | end |
| 93 | for i ulong len t bound 16 |
| 94 | if ne get gpgh add s i get t i |
| 95 | ret false |
| 96 | end |
| 97 | end |
| 98 | ret true |
| 99 | end |
| 100 | note paghv t: the value of the gh line "<t><value>\n" in gpgh: its offset; its length in gpr 15 (0 |
| 101 | note when there is no such whole line) |
| 102 | fn paghv t view uchar * to ulong |
| 103 | n = get gpghl 0 |
| 104 | s = ulong 0 |
| 105 | for i ulong n bound 2048 |
| 106 | if eq get gpgh i 10 |
| 107 | if paghat s i t |
| 108 | put gpr 15 sub sub i s len t |
| 109 | ret add s len t |
| 110 | end |
| 111 | s = add i 1 |
| 112 | end |
| 113 | end |
| 114 | put gpr 15 0 |
| 115 | ret 0 |
| 116 | end |
| 117 | note paghnum: the GitHub number of the gh file ("number N", 1..18 digits), 0 when it has none |
| 118 | fn paghnum to ulong |
| 119 | o = paghv tpghn |
| 120 | k = get gpr 15 |
| 121 | if or eq k 0 gt k 18 |
| 122 | ret 0 |
| 123 | end |
| 124 | v = ulong 0 |
| 125 | for i ulong k bound 18 |
| 126 | c = get gpgh add o i |
| 127 | if not fisdig c |
| 128 | ret 0 |
| 129 | end |
| 130 | v = add mul v 10 ulong sub c 48 |
| 131 | end |
| 132 | ret v |
| 133 | end |
| 134 | note paiload2: the optional files of the imported item: title (cut to 1024 bytes), base (40 hex and |
| 135 | note a line feed, else the item has no base), gh (cut to 2048 bytes), and the code file: mbox, else |
| 136 | note head.bundle, else none (its size in gpmby) |
| 137 | fn paiload2 to bool |
| 138 | n = pafrd tpftt 1024 |
| 139 | for i ulong n bound 1024 |
| 140 | put gpttl i get fxo i |
| 141 | end |
| 142 | put gpttll 0 n |
| 143 | put gpihb 0 0 |
| 144 | papid tpfbase |
| 145 | r = pards |
| 146 | if pal40 |
| 147 | put gpihb 0 1 |
| 148 | for i ulong 40 |
| 149 | put gpbase i get gpln i |
| 150 | end |
| 151 | end |
| 152 | n = pafrd tpfgh 2048 |
| 153 | for i ulong n bound 2048 |
| 154 | put gpgh i get fxo i |
| 155 | end |
| 156 | put gpghl 0 n |
| 157 | put gpnum 0 paghnum |
| 158 | if eq get gpnum 0 0 |
| 159 | put gpnum 0 pasjnum |
| 160 | end |
| 161 | put gpicode 0 0 |
| 162 | put gpmby 0 0 |
| 163 | papid tpfbn |
| 164 | e = paexist |
| 165 | if e |
| 166 | put gpicode 0 2 |
| 167 | put gpmby 0 pastsz |
| 168 | end |
| 169 | papid tpfmb |
| 170 | e = paexist |
| 171 | if e |
| 172 | put gpicode 0 1 |
| 173 | put gpmby 0 pastsz |
| 174 | end |
| 175 | put gpmcm 0 0 |
| 176 | put gpmfl 0 0 |
| 177 | put gpmdidl 0 0 |
| 178 | put gpmts 0 0 |
| 179 | ret true |
| 180 | end |
| 181 | note paiload: the imported item gpid into the globals (SPEC section 1): false unless source.json |
| 182 | note starts with the import prefix, status is one of the three words and head is 40 hex and a line |
| 183 | note feed. source.json is kept up to 4096 bytes. |
| 184 | fn paiload to bool |
| 185 | put gpimp 0 1 |
| 186 | n = pafrd tpfsj 4096 |
| 187 | if lt n len tpsjpre |
| 188 | ret false |
| 189 | end |
| 190 | for i ulong len tpsjpre bound 64 |
| 191 | if ne get fxo i get tpsjpre i |
| 192 | ret false |
| 193 | end |
| 194 | end |
| 195 | for i ulong n bound 4096 |
| 196 | put gpsrc i get fxo i |
| 197 | end |
| 198 | put gpsrcl 0 n |
| 199 | put gpider 0 0 |
| 200 | if lt pasjf tpsjder n |
| 201 | put gpider 0 1 |
| 202 | end |
| 203 | s = pastrd |
| 204 | if gt s 2 |
| 205 | ret false |
| 206 | end |
| 207 | put gpist 0 s |
| 208 | papid tpfhd |
| 209 | r = pards |
| 210 | if not pal40 |
| 211 | ret false |
| 212 | end |
| 213 | for i ulong 40 |
| 214 | put gphead i get gpln i |
| 215 | end |
| 216 | ret paiload2 |
| 217 | end |
| 218 | note ---- the thread: records "comment <time> <login> <len>\n<body>\n", "review <time> <login> |
| 219 | note <STATE|-> <len>\n<body>\n" and "review-comment <time> <login> <line> <pathlen> <len>\n<path>\n |
| 220 | note <body>\n" (time: 20 bytes, or "-") |
| 221 | note pathld: the thread file of item gpid into gpth; gpthc is set when the file is larger than gpth |
| 222 | fn pathld to void |
| 223 | put gpthl 0 0 |
| 224 | put gpthc 0 0 |
| 225 | pafp tpfth |
| 226 | n = frdall |
| 227 | if le n 0 |
| 228 | ret |
| 229 | end |
| 230 | if ne get fxotr 0 0 |
| 231 | put gpthc 0 1 |
| 232 | end |
| 233 | for i ulong ulong n bound 16777216 |
| 234 | put gpth i get fxo i |
| 235 | end |
| 236 | put gpthl 0 ulong n |
| 237 | end |
| 238 | note patword a: the word at gpcur (1..256 bytes above 32) up to its space: offset in gpr a, length in |
| 239 | note gpr a+1; gpcur moves past the space. gpbad is set (length 0) when it is not such a word; with |
| 240 | note gpbad set nothing is read. At most 257 passes: the pass that sees 256 bytes returns. |
| 241 | fn patword a ulong to void |
| 242 | put gpr add a 1 0 |
| 243 | if ne get gpbad 0 0 |
| 244 | ret |
| 245 | end |
| 246 | p = get gpcur 0 |
| 247 | n = get gpthl 0 |
| 248 | q = p |
| 249 | while lt q n bound 257 |
| 250 | if le get gpth q 32 |
| 251 | break |
| 252 | end |
| 253 | if ge sub q p 256 |
| 254 | put gpbad 0 1 |
| 255 | ret |
| 256 | end |
| 257 | q = add q 1 |
| 258 | end |
| 259 | if or ge q n eq q p |
| 260 | put gpbad 0 1 |
| 261 | ret |
| 262 | end |
| 263 | if ne get gpth q 32 |
| 264 | put gpbad 0 1 |
| 265 | ret |
| 266 | end |
| 267 | put gpr a p |
| 268 | put gpr add a 1 sub q p |
| 269 | put gpcur 0 add q 1 |
| 270 | end |
| 271 | note patnum t: the decimal at gpcur (1..18 digits) ended by the byte t; gpcur moves past t. gpbad is |
| 272 | note set when it is not one. At most 19 passes: the pass that sees an 19th digit returns. |
| 273 | fn patnum t uchar to ulong |
| 274 | if ne get gpbad 0 0 |
| 275 | ret 0 |
| 276 | end |
| 277 | p = get gpcur 0 |
| 278 | n = get gpthl 0 |
| 279 | v = ulong 0 |
| 280 | k = ulong 0 |
| 281 | while lt p n bound 19 |
| 282 | c = get gpth p |
| 283 | if not fisdig c |
| 284 | break |
| 285 | end |
| 286 | if ge k 18 |
| 287 | put gpbad 0 1 |
| 288 | ret 0 |
| 289 | end |
| 290 | v = add mul v 10 ulong sub c 48 |
| 291 | k = add k 1 |
| 292 | p = add p 1 |
| 293 | end |
| 294 | if or eq k 0 ge p n |
| 295 | put gpbad 0 1 |
| 296 | ret 0 |
| 297 | end |
| 298 | if ne get gpth p t |
| 299 | put gpbad 0 1 |
| 300 | ret 0 |
| 301 | end |
| 302 | put gpcur 0 add p 1 |
| 303 | ret v |
| 304 | end |
| 305 | note patis a t: the word of gpr a, a+1 is t |
| 306 | fn patis a ulong t view uchar * to bool |
| 307 | if ne get gpr add a 1 len t |
| 308 | ret false |
| 309 | end |
| 310 | o = get gpr a |
| 311 | for i ulong len t bound 16 |
| 312 | if ne get gpth add o i get t i |
| 313 | ret false |
| 314 | end |
| 315 | end |
| 316 | ret true |
| 317 | end |
| 318 | note patkind: the record kind of the word in gpr 12, 13: 1 comment, 2 review, 3 review-comment, else 0 |
| 319 | fn patkind to ulong |
| 320 | if patis 12 tprcom |
| 321 | ret 1 |
| 322 | end |
| 323 | if patis 12 tprrev |
| 324 | ret 2 |
| 325 | end |
| 326 | if patis 12 tprrc |
| 327 | ret 3 |
| 328 | end |
| 329 | ret 0 |
| 330 | end |
| 331 | note pattok: the time word (gpr 1, 2) is 20 bytes or "-" |
| 332 | fn pattok to bool |
| 333 | k = get gpr 2 |
| 334 | if eq k 20 |
| 335 | ret true |
| 336 | end |
| 337 | if ne k 1 |
| 338 | ret false |
| 339 | end |
| 340 | ret eq get gpth get gpr 1 45 |
| 341 | end |
| 342 | note patrec p: parse the record at p into gpr (0 kind, 1-2 time, 3-4 login, 5-6 state, 7 line, 8-9 |
| 343 | note path, 10-11 body); the index after it. A malformed record leaves kind 0 and returns the thread's |
| 344 | note length, which stops the caller: every length is checked against the thread before the bytes it |
| 345 | note names are read (a path is at most 4096 bytes). |
| 346 | fn patrec p ulong to ulong |
| 347 | n = get gpthl 0 |
| 348 | put gpr 0 0 |
| 349 | put gpr 6 0 |
| 350 | put gpr 7 0 |
| 351 | put gpr 9 0 |
| 352 | put gpbad 0 0 |
| 353 | put gpcur 0 p |
| 354 | patword 12 |
| 355 | k = patkind |
| 356 | if eq k 0 |
| 357 | ret n |
| 358 | end |
| 359 | patword 1 |
| 360 | patword 3 |
| 361 | if eq k 2 |
| 362 | patword 5 |
| 363 | end |
| 364 | if eq k 3 |
| 365 | put gpr 7 patnum 32 |
| 366 | put gpr 9 patnum 32 |
| 367 | end |
| 368 | b = patnum 10 |
| 369 | if ne get gpbad 0 0 |
| 370 | ret n |
| 371 | end |
| 372 | if not pattok |
| 373 | ret n |
| 374 | end |
| 375 | q = get gpcur 0 |
| 376 | if eq k 3 |
| 377 | m = get gpr 9 |
| 378 | if or gt m 4096 ge add q m n |
| 379 | ret n |
| 380 | end |
| 381 | if ne get gpth add q m 10 |
| 382 | ret n |
| 383 | end |
| 384 | put gpr 8 q |
| 385 | q = add add q m 1 |
| 386 | end |
| 387 | if ge add q b n |
| 388 | ret n |
| 389 | end |
| 390 | if ne get gpth add q b 10 |
| 391 | ret n |
| 392 | end |
| 393 | put gpr 10 q |
| 394 | put gpr 11 b |
| 395 | put gpr 0 k |
| 396 | ret add add q b 1 |
| 397 | end |
| 398 | note patcnt: the records of the loaded thread up to its end or its first malformed record. A record |
| 399 | note is at least 15 bytes, so the passes stay far under the bound. |
| 400 | fn patcnt to ulong |
| 401 | p = ulong 0 |
| 402 | c = ulong 0 |
| 403 | n = get gpthl 0 |
| 404 | while lt p n bound 16777216 |
| 405 | p = patrec p |
| 406 | if ne get gpr 0 0 |
| 407 | c = add c 1 |
| 408 | end |
| 409 | end |
| 410 | ret c |
| 411 | end |
| 412 | note ---- pieces of the HTML pages |
| 413 | note patraw a: gpth[gpr a, + gpr a+1), HTML-escaped |
| 414 | fn patraw a ulong to void |
| 415 | o = get gpr a |
| 416 | for i ulong get gpr add a 1 bound 16777216 |
| 417 | fescc get gpth add o i |
| 418 | end |
| 419 | end |
| 420 | note pattime: the record's time as YYYY-MM-DD HH:MM UTC, escaped ("-" when it has none) |
| 421 | fn pattime to void |
| 422 | if ne get gpr 2 20 |
| 423 | fputc 45 |
| 424 | ret |
| 425 | end |
| 426 | o = get gpr 1 |
| 427 | for i ulong 10 |
| 428 | fescc get gpth add o i |
| 429 | end |
| 430 | fputc 32 |
| 431 | for i ulong 5 |
| 432 | fescc get gpth add add o 11 i |
| 433 | end |
| 434 | fput tputc |
| 435 | end |
| 436 | note paghhas t: the gh file has a 20-byte time under t |
| 437 | fn paghhas t view uchar * to bool |
| 438 | o = paghv t |
| 439 | ret eq get gpr 15 20 |
| 440 | end |
| 441 | note paghtm t: the gh time under t as YYYY-MM-DD HH:MM UTC, escaped ("-" when it is not 20 bytes) |
| 442 | fn paghtm t view uchar * to void |
| 443 | o = paghv t |
| 444 | if ne get gpr 15 20 |
| 445 | fputc 45 |
| 446 | ret |
| 447 | end |
| 448 | for i ulong 10 |
| 449 | fescc get gpgh add o i |
| 450 | end |
| 451 | fputc 32 |
| 452 | for i ulong 5 |
| 453 | fescc get gpgh add add o 11 i |
| 454 | end |
| 455 | fput tputc |
| 456 | end |
| 457 | note paghp t: the gh value under t, HTML-escaped |
| 458 | fn paghp t view uchar * to void |
| 459 | o = paghv t |
| 460 | for i ulong get gpr 15 bound 2048 |
| 461 | fescc get gpgh add o i |
| 462 | end |
| 463 | end |
| 464 | note pasjp t: the source.json string after the key text t, HTML-escaped |
| 465 | fn pasjp t view uchar * to void |
| 466 | o = pasjv t |
| 467 | for i ulong get gpr 15 bound 4096 |
| 468 | fescc get gpsrc add o i |
| 469 | end |
| 470 | end |
| 471 | note paprov: the provenance text: Imported from GitHub <gho>/<ghr>#<n>, by <login>; a code-only item |
| 472 | note (no GitHub metadata) has no login: Imported from GitHub <gho>/<ghr>#<n> (code only) |
| 473 | note An item with metadata whose gh file names no login ends after the number: no ", by ". |
| 474 | fn paprov to void |
| 475 | fput tpimp1 |
| 476 | pasjp tpsjow |
| 477 | fputc 47 |
| 478 | pasjp tpsjrp |
| 479 | fputc 35 |
| 480 | fnum get gpnum 0 |
| 481 | if ne get gpider 0 0 |
| 482 | fput tpimp3 |
| 483 | ret |
| 484 | end |
| 485 | o = paghv tpghl |
| 486 | if eq get gpr 15 0 |
| 487 | ret |
| 488 | end |
| 489 | fput tpimp2 |
| 490 | paghp tpghl |
| 491 | end |
| 492 | note pabadge: the status word as a badge, and the word "derived" when the state is derived |
| 493 | fn pabadge to void |
| 494 | s = get gpist 0 |
| 495 | if eq s 0 |
| 496 | fput tpbok |
| 497 | fput tpwopn |
| 498 | end |
| 499 | if eq s 1 |
| 500 | fput tpbbad |
| 501 | fput tpwclo |
| 502 | end |
| 503 | if eq s 2 |
| 504 | fput tpbmut |
| 505 | fput tpwmrg |
| 506 | end |
| 507 | fput tpboff |
| 508 | if ne get gpider 0 0 |
| 509 | fput tpbder |
| 510 | end |
| 511 | end |
| 512 | note paitl: the title, escaped; "(untitled)" when the item has none |
| 513 | fn paitl to void |
| 514 | if eq get gpttll 0 0 |
| 515 | fput tpnotl |
| 516 | ret |
| 517 | end |
| 518 | paesct |
| 519 | end |
| 520 | note paiwhen: " opened YYYY-MM-DD" (gh opened); a code-only item: " imported <date of imported_utc>" |
| 521 | fn paiwhen to void |
| 522 | if ne get gpider 0 0 |
| 523 | fput tpiwi |
| 524 | o = pasjv tpsjutc |
| 525 | if ge get gpr 15 10 |
| 526 | for i ulong 10 |
| 527 | fescc get gpsrc add o i |
| 528 | end |
| 529 | else |
| 530 | fputc 45 |
| 531 | end |
| 532 | ret |
| 533 | end |
| 534 | fput tpiwo |
| 535 | o = paghv tpgho |
| 536 | if eq get gpr 15 20 |
| 537 | for i ulong 10 |
| 538 | fescc get gpgh add o i |
| 539 | end |
| 540 | else |
| 541 | fputc 45 |
| 542 | end |
| 543 | end |
| 544 | note pairow: the list row of an imported item: title link, badge, id, date, provenance; no counts |
| 545 | fn pairow to void |
| 546 | fput tphli |
| 547 | papath |
| 548 | fput tphq |
| 549 | paitl |
| 550 | fput tphae |
| 551 | fput tpir1 |
| 552 | pabadge |
| 553 | fput tpir2 |
| 554 | paputid |
| 555 | fput tphcodz |
| 556 | paiwhen |
| 557 | fput tphm3 |
| 558 | paprov |
| 559 | fput tphm4 |
| 560 | end |
| 561 | note ---- the page of an imported item |
| 562 | note paitms: the opened, closed and merged times of the gh file (none for a code-only item) |
| 563 | fn paitms to void |
| 564 | if ne get gpider 0 0 |
| 565 | ret |
| 566 | end |
| 567 | fput tpito |
| 568 | paghtm tpgho |
| 569 | if paghhas tpghc |
| 570 | fput tpitc |
| 571 | paghtm tpghc |
| 572 | end |
| 573 | if paghhas tpghm |
| 574 | fput tpitm |
| 575 | paghtm tpghm |
| 576 | end |
| 577 | end |
| 578 | note pailabs: "Labels: a, b" from the labels file (one per line; its first 65536 bytes) |
| 579 | fn pailabs to void |
| 580 | n = pafrd tpflb 65536 |
| 581 | if eq n 0 |
| 582 | ret |
| 583 | end |
| 584 | fput tpipm |
| 585 | fput tpilab |
| 586 | for i ulong n bound 65536 |
| 587 | c = get fxo i |
| 588 | if eq c 10 |
| 589 | if lt add i 1 n |
| 590 | fputc 44 |
| 591 | fputc 32 |
| 592 | end |
| 593 | else |
| 594 | fescc c |
| 595 | end |
| 596 | end |
| 597 | fput tpipe |
| 598 | end |
| 599 | note parchsp s n: the index of the first space of gpln at or after s, n when there is none (n is at |
| 600 | note most 255) |
| 601 | fn parchsp s ulong n ulong to ulong |
| 602 | q = s |
| 603 | while lt q n bound 257 |
| 604 | if eq get gpln q 32 |
| 605 | break |
| 606 | end |
| 607 | q = add q 1 |
| 608 | end |
| 609 | ret q |
| 610 | end |
| 611 | note parchw a t: gpln[0, a) is t |
| 612 | fn parchw a ulong t view uchar * to bool |
| 613 | if ne a len t |
| 614 | ret false |
| 615 | end |
| 616 | for i ulong a bound 16 |
| 617 | if ne get gpln i get t i |
| 618 | ret false |
| 619 | end |
| 620 | end |
| 621 | ret true |
| 622 | end |
| 623 | note parchld: the reach file of item gpid ("<reachable|not-reachable|unknown> <main sha|-> <utc>\n") |
| 624 | note into gpln: 1 reachable, 2 not-reachable, 3 unknown, 0 when there is none or it is not that |
| 625 | note line. The main sha is at gpr 12 (length gpr 13: 40, or 0 for "-"), the observation time at |
| 626 | note gpr 14 (length gpr 15: 1..32 bytes). |
| 627 | fn parchld to ulong |
| 628 | papid tpfrc |
| 629 | r = pards |
| 630 | if or lt r 5 gt r 255 |
| 631 | ret 0 |
| 632 | end |
| 633 | n = get gplnl 0 |
| 634 | if ne get gpln sub n 1 10 |
| 635 | ret 0 |
| 636 | end |
| 637 | a = parchsp 0 n |
| 638 | if ge a n |
| 639 | ret 0 |
| 640 | end |
| 641 | b = parchsp add a 1 n |
| 642 | if ge b n |
| 643 | ret 0 |
| 644 | end |
| 645 | w = ulong 0 |
| 646 | if parchw a tprch1 |
| 647 | w = 1 |
| 648 | end |
| 649 | if parchw a tprch2 |
| 650 | w = 2 |
| 651 | end |
| 652 | if parchw a tprch3 |
| 653 | w = 3 |
| 654 | end |
| 655 | if eq w 0 |
| 656 | ret 0 |
| 657 | end |
| 658 | m = sub sub b a 1 |
| 659 | put gpr 12 add a 1 |
| 660 | put gpr 13 0 |
| 661 | if eq m 40 |
| 662 | for i ulong 40 |
| 663 | if lt sohexv get gpln add add a 1 i 0 |
| 664 | ret 0 |
| 665 | end |
| 666 | end |
| 667 | put gpr 13 40 |
| 668 | else |
| 669 | if ne m 1 |
| 670 | ret 0 |
| 671 | end |
| 672 | if ne get gpln add a 1 45 |
| 673 | ret 0 |
| 674 | end |
| 675 | end |
| 676 | u = sub sub n b 2 |
| 677 | if or lt u 1 gt u 32 |
| 678 | ret 0 |
| 679 | end |
| 680 | put gpr 14 add b 1 |
| 681 | put gpr 15 u |
| 682 | ret w |
| 683 | end |
| 684 | note paimrg: a merged item with GitHub metadata: the merge commit (the merged file) and what the |
| 685 | note importer observed about this project's main (the reach file) |
| 686 | fn paimrg to void |
| 687 | papid tpfmg |
| 688 | r = pards |
| 689 | if not pal40 |
| 690 | ret |
| 691 | end |
| 692 | fput tpipm |
| 693 | fput tpimg1 |
| 694 | for i ulong 40 |
| 695 | fputc get gpln i |
| 696 | end |
| 697 | fput tphcodz |
| 698 | w = parchld |
| 699 | if or eq w 1 eq w 2 |
| 700 | if eq w 1 |
| 701 | fput tpimr1 |
| 702 | else |
| 703 | fput tpimr2 |
| 704 | end |
| 705 | o = get gpr 12 |
| 706 | for i ulong get gpr 13 bound 40 |
| 707 | fputc get gpln add o i |
| 708 | end |
| 709 | fput tphcodz |
| 710 | end |
| 711 | if eq w 3 |
| 712 | fput tpimr3 |
| 713 | end |
| 714 | if ne w 0 |
| 715 | fput tpimro |
| 716 | o = get gpr 14 |
| 717 | for i ulong get gpr 15 bound 32 |
| 718 | fescc get gpln add o i |
| 719 | end |
| 720 | fputc 41 |
| 721 | end |
| 722 | fput tpipe |
| 723 | end |
| 724 | note paishas: the base and head commits, and the merge line of a merged item |
| 725 | fn paishas to void |
| 726 | fput tpipm |
| 727 | if ne get gpihb 0 0 |
| 728 | fput tpisb |
| 729 | paput40 0 |
| 730 | fput tpisb2 |
| 731 | else |
| 732 | fput tpisnb |
| 733 | end |
| 734 | fput tpish |
| 735 | paput40 1 |
| 736 | fput tphcodz |
| 737 | fput tpipe |
| 738 | if eq get gpist 0 2 |
| 739 | paimrg |
| 740 | end |
| 741 | end |
| 742 | note pamd n: render fxo[0, n) using the browse renderer at the project root on its default branch |
| 743 | fn pamd n ulong to void |
| 744 | repo = get fridx 0 |
| 745 | branch = get fabo repo |
| 746 | size = get fabl repo |
| 747 | for i ulong size bound 64 |
| 748 | put gbref i get fabr add branch i |
| 749 | end |
| 750 | put gbrefl 0 size |
| 751 | put gbmdl 0 0 |
| 752 | fput tbart1 |
| 753 | brmd 0 n |
| 754 | fput tbart2 |
| 755 | end |
| 756 | note papgfit f0 t0: true while the page is at most PAPGMX bytes and no byte was dropped; else the |
| 757 | note output goes back to f0 (and the cut flag to t0), so the caller writes one sentence in place of |
| 758 | note what it rendered and the rest of the page still fits fob |
| 759 | fn papgfit f0 ulong t0 ulong to bool |
| 760 | if and le get fobl 0 PAPGMX eq get fobtr 0 t0 |
| 761 | ret true |
| 762 | end |
| 763 | put fobl 0 f0 |
| 764 | put fobtr 0 t0 |
| 765 | ret false |
| 766 | end |
| 767 | note paidesc: the description as Markdown under "<login> wrote on <time>"; nothing when there is |
| 768 | note none; one sentence when it is over fxo or takes the page over PAPGMX |
| 769 | fn paidesc to void |
| 770 | pafp tpfds |
| 771 | n = frdall |
| 772 | if le n 0 |
| 773 | ret |
| 774 | end |
| 775 | huge = ne get fxotr 0 0 |
| 776 | f0 = get fobl 0 |
| 777 | t0 = get fobtr 0 |
| 778 | fput tpibox |
| 779 | if eq get gpider 0 0 |
| 780 | paghp tpghl |
| 781 | fput tpiwr |
| 782 | paghtm tpgho |
| 783 | else |
| 784 | fput tpidsc |
| 785 | end |
| 786 | fput tpipe |
| 787 | if huge |
| 788 | fput tpidbig |
| 789 | else |
| 790 | pamd ulong n |
| 791 | end |
| 792 | fput tphdv |
| 793 | if not papgfit f0 t0 |
| 794 | fput tpidbig |
| 795 | end |
| 796 | end |
| 797 | note paibox: the parsed record (gpr) as a box: login (text), what it is, time, the body as Markdown |
| 798 | fn paibox to void |
| 799 | k = get gpr 0 |
| 800 | fput tpibox |
| 801 | patraw 3 |
| 802 | if eq k 1 |
| 803 | fput tpiwr |
| 804 | end |
| 805 | if eq k 2 |
| 806 | fput tpirv1 |
| 807 | patraw 5 |
| 808 | fput tpirv2 |
| 809 | end |
| 810 | if eq k 3 |
| 811 | fput tpirc1 |
| 812 | patraw 8 |
| 813 | fput tpirc2 |
| 814 | fnum get gpr 7 |
| 815 | fput tpion |
| 816 | end |
| 817 | pattime |
| 818 | fput tpipe |
| 819 | o = get gpr 10 |
| 820 | b = get gpr 11 |
| 821 | if gt b 0 |
| 822 | for i ulong b bound 16777216 |
| 823 | put fxo i get gpth add o i |
| 824 | end |
| 825 | pamd b |
| 826 | end |
| 827 | fput tphdv |
| 828 | end |
| 829 | note paithr: the thread, one box per record. It stops at the first malformed record (one sentence), |
| 830 | note and when a box takes the page over PAPGMX (that box is taken back, one sentence). |
| 831 | fn paithr to void |
| 832 | pathld |
| 833 | p = ulong 0 |
| 834 | n = get gpthl 0 |
| 835 | while lt p n bound 16777216 |
| 836 | p = patrec p |
| 837 | if eq get gpr 0 0 |
| 838 | if eq get gpthc 0 0 |
| 839 | fput tpitbad |
| 840 | end |
| 841 | break |
| 842 | end |
| 843 | f0 = get fobl 0 |
| 844 | t0 = get fobtr 0 |
| 845 | paibox |
| 846 | if not papgfit f0 t0 |
| 847 | fput tpitcut |
| 848 | break |
| 849 | end |
| 850 | end |
| 851 | if ne get gpthc 0 0 |
| 852 | fput tpitbig |
| 853 | end |
| 854 | end |
| 855 | note paiapply: the code box of an mbox-backed item: the "Apply it" lines and raw links of a signed |
| 856 | note patch (no Signature box) |
| 857 | fn paiapply to void |
| 858 | fput tphap1 |
| 859 | paputid |
| 860 | if ne get gpihb 0 0 |
| 861 | fputc 32 |
| 862 | paput40 0 |
| 863 | end |
| 864 | fput tphap2 |
| 865 | paorig |
| 866 | papath |
| 867 | fput tpsfxp |
| 868 | fput tphap3 |
| 869 | papath |
| 870 | fput tpsfxp |
| 871 | fput tphap4 |
| 872 | papath |
| 873 | fput tpsfxd |
| 874 | fput tphap5 |
| 875 | end |
| 876 | note paibund: the code box of a bundle-backed item: size, the fetch lines, the raw link, and the |
| 877 | note diff link when the diff exists (gpbd 0) |
| 878 | fn paibund to void |
| 879 | fput tpibd1 |
| 880 | fnum get gpmby 0 |
| 881 | fput tpibd2 |
| 882 | paorig |
| 883 | papath |
| 884 | fput tpsfxb |
| 885 | fput tpibd3 |
| 886 | paputid |
| 887 | fput tpsfxb |
| 888 | fput tpibd4 |
| 889 | paputid |
| 890 | fput tpsfxb |
| 891 | fput tpibd4b |
| 892 | fnum get gpnum 0 |
| 893 | fput tpibd5 |
| 894 | papath |
| 895 | fput tpsfxb |
| 896 | fput tpibd6 |
| 897 | if eq get gpbd 0 0 |
| 898 | fput tpibd7 |
| 899 | papath |
| 900 | fput tpsfxd |
| 901 | fput tphap5 |
| 902 | ret |
| 903 | end |
| 904 | fput tpibd9 |
| 905 | end |
| 906 | note paonmn: the loaded imported item is the importer's on-main route: a code-only item (derived |
| 907 | note state) whose state is merged and whose base file names its head commit |
| 908 | fn paonmn to bool |
| 909 | if eq get gpider 0 0 |
| 910 | ret false |
| 911 | end |
| 912 | if ne get gpist 0 2 |
| 913 | ret false |
| 914 | end |
| 915 | if eq get gpihb 0 0 |
| 916 | ret false |
| 917 | end |
| 918 | for i ulong 40 |
| 919 | if ne get gpbase i get gphead i |
| 920 | ret false |
| 921 | end |
| 922 | end |
| 923 | ret true |
| 924 | end |
| 925 | note paicode: the Code box. Without a code file only the on-main route says the head is on main (with |
| 926 | note the link to its commit page); any other item says that it holds no code file. |
| 927 | fn paicode to void |
| 928 | k = get gpicode 0 |
| 929 | if eq k 1 |
| 930 | paiapply |
| 931 | ret |
| 932 | end |
| 933 | if eq k 2 |
| 934 | paibund |
| 935 | ret |
| 936 | end |
| 937 | if not paonmn |
| 938 | fput tpicx |
| 939 | ret |
| 940 | end |
| 941 | fput tpicn1 |
| 942 | fputrl |
| 943 | fput tphcm |
| 944 | paput40 1 |
| 945 | fput tphq |
| 946 | fput tphcode |
| 947 | paput40 1 |
| 948 | fput tpicn2 |
| 949 | end |
| 950 | note paiprov: the Provenance box: imported, not signed; the statement and source.json, escaped |
| 951 | fn paiprov to void |
| 952 | fput tpipv1 |
| 953 | n = pafrd tpfst 65536 |
| 954 | fxesc 0 n |
| 955 | fput tphpre |
| 956 | fput tphsg3 |
| 957 | for i ulong get gpsrcl 0 bound 4096 |
| 958 | fescc get gpsrc i |
| 959 | end |
| 960 | fput tphpre |
| 961 | fput tphdv |
| 962 | end |
| 963 | note paichn t: the Changes heading with one sentence in place of a diff |
| 964 | fn paichn t view uchar * to void |
| 965 | fput tpich |
| 966 | fput t |
| 967 | fput tpipe |
| 968 | end |
| 969 | note pafpp: fpth = gpp, for frdall |
| 970 | fn pafpp to void |
| 971 | fpb |
| 972 | for i ulong get gppl 0 bound 4096 |
| 973 | fpc get gpp i |
| 974 | end |
| 975 | end |
| 976 | note paichg: Changes: the stored diff of an mbox, the cached diff of a bundle with a base (gpbd is |
| 977 | note pabdiff's answer), else the sentence that says why there is none |
| 978 | fn paichg to void |
| 979 | k = get gpicode 0 |
| 980 | if eq k 1 |
| 981 | n = pardf tpfdf |
| 982 | if gt n 0 |
| 983 | pashdn n |
| 984 | ret |
| 985 | end |
| 986 | paichn tpicg1 |
| 987 | ret |
| 988 | end |
| 989 | if eq k 0 |
| 990 | if paonmn |
| 991 | paichn tpicg0 |
| 992 | else |
| 993 | paichn tpicg7 |
| 994 | end |
| 995 | ret |
| 996 | end |
| 997 | if eq get gpihb 0 0 |
| 998 | paichn tpicg2 |
| 999 | ret |
| 1000 | end |
| 1001 | w = get gpbd 0 |
| 1002 | if eq w 1 |
| 1003 | paichn tpicg3 |
| 1004 | ret |
| 1005 | end |
| 1006 | if eq w 2 |
| 1007 | paichn tpicg4 |
| 1008 | ret |
| 1009 | end |
| 1010 | if eq w 4 |
| 1011 | paichn tpicg8 |
| 1012 | ret |
| 1013 | end |
| 1014 | if ne w 0 |
| 1015 | paichn tpicg5 |
| 1016 | ret |
| 1017 | end |
| 1018 | papdf |
| 1019 | pafpp |
| 1020 | r = frdall |
| 1021 | if lt r 0 |
| 1022 | paichn tpicg5 |
| 1023 | ret |
| 1024 | end |
| 1025 | if eq r 0 |
| 1026 | paichn tpicg6 |
| 1027 | ret |
| 1028 | end |
| 1029 | pashdn ulong r |
| 1030 | end |
| 1031 | note paishow: the page of the loaded imported item |
| 1032 | fn paishow to long |
| 1033 | put gpbd 0 9 |
| 1034 | if eq get gpicode 0 2 |
| 1035 | if ne get gpihb 0 0 |
| 1036 | put gpbd 0 pabdiff |
| 1037 | end |
| 1038 | end |
| 1039 | fyalt |
| 1040 | if eq get gpttll 0 0 |
| 1041 | fsetti tptlist |
| 1042 | else |
| 1043 | patitl |
| 1044 | end |
| 1045 | frepohd 5 |
| 1046 | fput tphp1 |
| 1047 | paitl |
| 1048 | fput tpip2 |
| 1049 | pabadge |
| 1050 | fput tpir2 |
| 1051 | paputid |
| 1052 | fput tphcodz |
| 1053 | fput tpipn |
| 1054 | fnum get gpnum 0 |
| 1055 | paitms |
| 1056 | fput tpipe |
| 1057 | fput tpipm |
| 1058 | paprov |
| 1059 | fput tpipe |
| 1060 | if ne get gpider 0 0 |
| 1061 | fput tpider |
| 1062 | end |
| 1063 | pailabs |
| 1064 | paishas |
| 1065 | fput tphdv |
| 1066 | paidesc |
| 1067 | paithr |
| 1068 | paicode |
| 1069 | paiprov |
| 1070 | paichg |
| 1071 | ret 200 |
| 1072 | end |
| 1073 | note ---- the diff of a bundle-backed item (SPEC section 4), made once and kept as the cache file |
| 1074 | note <data>pdiff/<owner>/<repo>/<id>: derived data outside the item folder, safe to delete |
| 1075 | note pabcat: git --git-dir=<store> cat-file -e <base>^{commit} for the loaded item's base (gpbase), |
| 1076 | note fexec's answer: 0 the project's git store holds the base commit, above 0 it does not, below 0 |
| 1077 | note git did not run. One check for the diff (pabdiff) and for the JSON documents (pajdun) |
| 1078 | fn pabcat to long |
| 1079 | pakst |
| 1080 | fka tpcatf |
| 1081 | fka tpde |
| 1082 | fkopen |
| 1083 | pakbase |
| 1084 | fkt tpcmt |
| 1085 | ret fexec PATMO |
| 1086 | end |
| 1087 | note pabbig: leave the marker <data>pdiff/<owner>/<repo>/<id>.big, an empty file created exclusively |
| 1088 | note (one that is there stays; a failure leaves none and the next attempt tries again): the bundle |
| 1089 | note diff of item gpid was cut at 16 MiB. Derived data like the cache file, safe to delete |
| 1090 | fn pabbig to void |
| 1091 | if not pamkpd |
| 1092 | ret |
| 1093 | end |
| 1094 | papdfg |
| 1095 | x = pawf 6 0 |
| 1096 | end |
| 1097 | note pabst: what the cache folder says of the loaded bundle-backed item, without running git: 0 the |
| 1098 | note cache file is there, 2 the marker is there, 9 neither |
| 1099 | fn pabst to ulong |
| 1100 | papdf |
| 1101 | if paexist |
| 1102 | ret 0 |
| 1103 | end |
| 1104 | papdfg |
| 1105 | if paexist |
| 1106 | ret 2 |
| 1107 | end |
| 1108 | ret 9 |
| 1109 | end |
| 1110 | note pabkeep: fxo[0, fxol) -> this request's staging file -> the cache file (rename over it; the |
| 1111 | note staging file is removed when the write or the rename fails): 0 kept, 3 failed |
| 1112 | fn pabkeep to ulong |
| 1113 | if not pamkpd |
| 1114 | ret 3 |
| 1115 | end |
| 1116 | papdfn |
| 1117 | if not pawf 6 get fxol 0 |
| 1118 | x = unlink gpp 0 get gppl 0 |
| 1119 | ret 3 |
| 1120 | end |
| 1121 | soavb |
| 1122 | papdfn |
| 1123 | paavp |
| 1124 | papdf |
| 1125 | paavp |
| 1126 | r = renames gspk 0 get gspkl 0 0 |
| 1127 | if lt r 0 |
| 1128 | papdfn |
| 1129 | x = unlink gpp 0 get gppl 0 |
| 1130 | ret 3 |
| 1131 | end |
| 1132 | ret 0 |
| 1133 | end |
| 1134 | note pabrun: in the work folder: git bundle unbundle <item>/head.bundle, then git diff --no-color |
| 1135 | note --no-ext-diff --no-textconv <base>...<head> (the importer's own diff form), both with pakwt's |
| 1136 | note settings through fexec (argv only): 0 the output is kept as the cache file, 2 it is over fxo |
| 1137 | note (not kept), 3 git or the disk failed |
| 1138 | fn pabrun to ulong |
| 1139 | pakwt |
| 1140 | fka tpbund |
| 1141 | fka tpunb |
| 1142 | fkopen |
| 1143 | papid tpfbn |
| 1144 | pakp |
| 1145 | r = fexec PATMO |
| 1146 | if ne r 0 |
| 1147 | ret 3 |
| 1148 | end |
| 1149 | pakwt |
| 1150 | fka tpdiff |
| 1151 | fka tpnocol |
| 1152 | fka tpnoext |
| 1153 | fka tpnotc |
| 1154 | fkopen |
| 1155 | pakbase |
| 1156 | fkt tpdots3 |
| 1157 | for i ulong 40 |
| 1158 | fkc get gphead i |
| 1159 | end |
| 1160 | r = fexec PATMO |
| 1161 | if ne r 0 |
| 1162 | ret 3 |
| 1163 | end |
| 1164 | if ne get fxotr 0 0 |
| 1165 | ret 2 |
| 1166 | end |
| 1167 | ret pabkeep |
| 1168 | end |
| 1169 | note Cache failed diff work briefly without changing imported data. |
| 1170 | global gpbkeys uchar 1024 |
| 1171 | global gpbexp ulong 64 |
| 1172 | global gpbslot ulong 1 |
| 1173 | fn pabbad to bool |
| 1174 | now = ulong monons |
| 1175 | for slot ulong 64 |
| 1176 | if gt get gpbexp slot now |
| 1177 | same = true |
| 1178 | for i ulong 16 |
| 1179 | if ne get gpbkeys add mul slot 16 i get gpid i |
| 1180 | same = false |
| 1181 | break |
| 1182 | end |
| 1183 | end |
| 1184 | if same |
| 1185 | ret true |
| 1186 | end |
| 1187 | end |
| 1188 | end |
| 1189 | ret false |
| 1190 | end |
| 1191 | fn pabbset to void |
| 1192 | slot = get gpbslot 0 |
| 1193 | for i ulong 16 |
| 1194 | put gpbkeys add mul slot 16 i get gpid i |
| 1195 | end |
| 1196 | put gpbexp slot add ulong monons 120000000000 |
| 1197 | put gpbslot 0 rem add slot 1 64 |
| 1198 | end |
| 1199 | note Skip synchronous diff generation for large bundles. The bundle download stays available. |
| 1200 | fn pabbcap to bool |
| 1201 | papid tpfbn |
| 1202 | if not paexist |
| 1203 | ret false |
| 1204 | end |
| 1205 | ret gt pastsz 134217728 |
| 1206 | end |
| 1207 | note pabdiff: the cache file of the loaded bundle-backed item (gpid, gpbase, gphead) exists, making |
| 1208 | note it when it does not: 0 it is there, 1 the base commit is not in the project's git store, 2 the |
| 1209 | note diff is over fxo (the marker is left beside the cache, pabbig; with the marker there git is not |
| 1210 | note run again: the page and the raw route answer from it), 3 git, the disk or the work folder |
| 1211 | note failed. The work folder is removed whatever happened. |
| 1212 | fn pabdiff to ulong |
| 1213 | papdf |
| 1214 | e = paexist |
| 1215 | if e |
| 1216 | ret 0 |
| 1217 | end |
| 1218 | papdfg |
| 1219 | if paexist |
| 1220 | ret 2 |
| 1221 | end |
| 1222 | if pabbcap |
| 1223 | ret 4 |
| 1224 | end |
| 1225 | if pabbad |
| 1226 | ret 3 |
| 1227 | end |
| 1228 | r = pabcat |
| 1229 | if lt r 0 |
| 1230 | pabbset |
| 1231 | ret 3 |
| 1232 | end |
| 1233 | if ne r 0 |
| 1234 | ret 1 |
| 1235 | end |
| 1236 | if not pastem |
| 1237 | ret 3 |
| 1238 | end |
| 1239 | w = ulong 3 |
| 1240 | if pawinit |
| 1241 | w = pabrun |
| 1242 | end |
| 1243 | if not parmtree |
| 1244 | flog tplrm |
| 1245 | end |
| 1246 | if eq w 2 |
| 1247 | pabbig |
| 1248 | end |
| 1249 | if eq w 3 |
| 1250 | pabbset |
| 1251 | end |
| 1252 | ret w |
| 1253 | end |
| 1254 | note pabraw: GET <id>.diff of an item that stores no diff file: 0 with gpp = the cache file of the |
| 1255 | note bundle diff (made now when it is not there), else the status: 404 (not an item, no bundle, no |
| 1256 | note base, the base is not in the git store, the diff is over fxo), 500 (the diff could not be made) |
| 1257 | fn pabraw to long |
| 1258 | if not paany |
| 1259 | ret 404 |
| 1260 | end |
| 1261 | if eq get gpimp 0 0 |
| 1262 | ret 404 |
| 1263 | end |
| 1264 | if ne get gpicode 0 2 |
| 1265 | ret 404 |
| 1266 | end |
| 1267 | if eq get gpihb 0 0 |
| 1268 | ret 404 |
| 1269 | end |
| 1270 | w = pabdiff |
| 1271 | if eq w 0 |
| 1272 | papdf |
| 1273 | ret 0 |
| 1274 | end |
| 1275 | if eq w 3 |
| 1276 | patext |
| 1277 | fput tpmdint |
| 1278 | ret 500 |
| 1279 | end |
| 1280 | ret 404 |
| 1281 | end |