interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / contrib / forge-contribute.om
| 1 | note forge-contribute: clone, branch, commit, receipt, Radicle patch, review request, digest. |
| 2 | note Twelve arguments after the program name. See docs/ANNOYANCES.md. |
| 3 | note The receipt is attached by rad patch edit. git refuses a newline in a push option. |
| 4 | note hmin: the smaller of two counts. server/util.om fputlc calls it (since the JSON repo summary); |
| 5 | note forged gets it from seed/net/http.om, which this tool does not compose, so the same five lines |
| 6 | note stand here. Copied from omega-mv seed/net/http.om fn hmin. |
| 7 | fn hmin a ulong b ulong to ulong |
| 8 | if lt a b |
| 9 | ret a |
| 10 | end |
| 11 | ret b |
| 12 | end |
| 13 | global fcbig uchar 3840 |
| 14 | global fcal ulong 12 |
| 15 | global qnid uchar 40 |
| 16 | global fccd ulong 1 |
| 17 | text tcenv "/usr/bin/env" |
| 18 | text tcdash "-i" |
| 19 | text tchome "HOME=" |
| 20 | text tcpath "PATH=" |
| 21 | text tclbin "/.local/bin:/usr/bin:/bin" |
| 22 | text tcradh "RAD_HOME=" |
| 23 | text tcradp "/.radicle" |
| 24 | text tcradx "/.local/bin/rad" |
| 25 | text tcg1 "GIT_AUTHOR_NAME=forge-contribute" |
| 26 | text tcg2 "GIT_AUTHOR_EMAIL=forge@localhost" |
| 27 | text tcg3 "GIT_COMMITTER_NAME=forge-contribute" |
| 28 | text tcg4 "GIT_COMMITTER_EMAIL=forge@localhost" |
| 29 | text tcgit "/usr/bin/git" |
| 30 | text tcc "-C" |
| 31 | text tcadd "add" |
| 32 | text tcdd "--" |
| 33 | text tccmt "commit" |
| 34 | text tcm "-m" |
| 35 | text tccfg "-c" |
| 36 | text tcgp "commit.gpgsign=false" |
| 37 | text tcun "user.name=forge-contribute" |
| 38 | text tcum "user.email=forge@localhost" |
| 39 | text tcco "checkout" |
| 40 | text tcb "-b" |
| 41 | text tcpush "push" |
| 42 | text tco "-o" |
| 43 | text tcpm "patch.message=" |
| 44 | text tcref "HEAD:refs/patches" |
| 45 | text tcrad "rad" |
| 46 | text tcrp "rev-parse" |
| 47 | text tchead "HEAD" |
| 48 | text tctree "HEAD^{tree}" |
| 49 | text tcclone "clone" |
| 50 | text tcradp2 "rad:" |
| 51 | text tcped "patch" |
| 52 | text tcedit "edit" |
| 53 | text tcrev "review" |
| 54 | text tcrepo "--repo" |
| 55 | text tcna "--no-announce" |
| 56 | text tcmsg "--message" |
| 57 | text tcreq "review requested" |
| 58 | text tcok1 "patch " |
| 59 | text tcok2 "commit " |
| 60 | text tcnl "\n" |
| 61 | text tcpass "RAD_PASSPHRASE=" |
| 62 | text tcfail "forge-contribute: a step failed; its output follows\n" |
| 63 | fn fcgit to void |
| 64 | fka tcgit |
| 65 | fka tcc |
| 66 | fcnew 1 |
| 67 | end |
| 68 | fn fcoff i ulong to ulong |
| 69 | ret mul i ulong 320 |
| 70 | end |
| 71 | fn fcarg i ulong to void |
| 72 | o = mul i 320 |
| 73 | n = get fcal i |
| 74 | for k ulong n bound 320 |
| 75 | fkc get fcbig add o k |
| 76 | end |
| 77 | end |
| 78 | note fcnew: argument i as a record of its own (fcarg appends to the open record) |
| 79 | fn fcnew i ulong to void |
| 80 | fkopen |
| 81 | fcarg i |
| 82 | end |
| 83 | fn fcload to long |
| 84 | buf = new uchar 320 0 |
| 85 | if ne argcnt 13 |
| 86 | ret 2 |
| 87 | end |
| 88 | for i ulong 12 |
| 89 | r = argread add i 1 buf 0 319 |
| 90 | if or lt r 1 gt r 319 |
| 91 | ret 2 |
| 92 | end |
| 93 | put fcal i ulong r |
| 94 | o = mul i 320 |
| 95 | for k ulong ulong r bound 320 |
| 96 | put fcbig add o k get buf k |
| 97 | end |
| 98 | end |
| 99 | ret 0 |
| 100 | end |
| 101 | fn fcbad i ulong to bool |
| 102 | o = mul i 320 |
| 103 | n = get fcal i |
| 104 | for k ulong n bound 320 |
| 105 | c = get fcbig add o k |
| 106 | if or lt c 32 eq c 127 |
| 107 | ret true |
| 108 | end |
| 109 | end |
| 110 | ret false |
| 111 | end |
| 112 | fn fcabs i ulong to bool |
| 113 | if eq get fcbig mul i 320 47 |
| 114 | ret true |
| 115 | end |
| 116 | ret false |
| 117 | end |
| 118 | note fcdots: argument i holds a ".." path segment (start or "/" before it, end or "/" after it) |
| 119 | fn fcdots i ulong to bool |
| 120 | o = mul i 320 |
| 121 | n = get fcal i |
| 122 | for k ulong n bound 320 |
| 123 | if fcdotat o n k |
| 124 | ret true |
| 125 | end |
| 126 | end |
| 127 | ret false |
| 128 | end |
| 129 | fn fcdotat o ulong n ulong k ulong to bool |
| 130 | if ge add k 1 n |
| 131 | ret false |
| 132 | end |
| 133 | if ne get fcbig add o k 46 |
| 134 | ret false |
| 135 | end |
| 136 | if ne get fcbig add o add k 1 46 |
| 137 | ret false |
| 138 | end |
| 139 | if gt k 0 |
| 140 | if ne get fcbig add o sub k 1 47 |
| 141 | ret false |
| 142 | end |
| 143 | end |
| 144 | if lt add k 2 n |
| 145 | if ne get fcbig add o add k 2 47 |
| 146 | ret false |
| 147 | end |
| 148 | end |
| 149 | ret true |
| 150 | end |
| 151 | note fcpdots: a ".." segment in DIR, CMD, FILE, BODY, DATA or HOME |
| 152 | fn fcpdots to bool |
| 153 | if fcdots 1 |
| 154 | ret true |
| 155 | end |
| 156 | if fcdots 4 |
| 157 | ret true |
| 158 | end |
| 159 | if fcdots 8 |
| 160 | ret true |
| 161 | end |
| 162 | if fcdots 9 |
| 163 | ret true |
| 164 | end |
| 165 | if fcdots 10 |
| 166 | ret true |
| 167 | end |
| 168 | ret fcdots 11 |
| 169 | end |
| 170 | note fcdpath: fpth = DIR (argument 1) |
| 171 | fn fcdpath to void |
| 172 | put fpthl 0 0 |
| 173 | o = mul ulong 1 320 |
| 174 | for k ulong get fcal 1 bound 320 |
| 175 | fpc get fcbig add o k |
| 176 | end |
| 177 | end |
| 178 | note fcexist: DIR already exists (any file type) |
| 179 | fn fcexist to bool |
| 180 | fcdpath |
| 181 | r = lstat fpth 0 get fpthl 0 fstb 0 128 |
| 182 | ret ge r 0 |
| 183 | end |
| 184 | fn fctok i ulong to bool |
| 185 | o = mul i 320 |
| 186 | n = get fcal i |
| 187 | if or eq n 0 gt n 39 |
| 188 | ret false |
| 189 | end |
| 190 | for k ulong n bound 39 |
| 191 | c = get fcbig add o k |
| 192 | ok = false |
| 193 | if and ge c 48 le c 57 |
| 194 | ok = true |
| 195 | end |
| 196 | if and ge c 97 le c 122 |
| 197 | ok = true |
| 198 | end |
| 199 | if eq c 45 |
| 200 | ok = true |
| 201 | end |
| 202 | if not ok |
| 203 | ret false |
| 204 | end |
| 205 | end |
| 206 | ret true |
| 207 | end |
| 208 | fn fchex c uchar to bool |
| 209 | if and ge c 48 le c 57 |
| 210 | ret true |
| 211 | end |
| 212 | ret and ge c 97 le c 102 |
| 213 | end |
| 214 | fn fcvalid to bool |
| 215 | for i ulong 12 |
| 216 | if fcbad i |
| 217 | ret false |
| 218 | end |
| 219 | end |
| 220 | if fcpdots |
| 221 | ret false |
| 222 | end |
| 223 | if not fcabs 1 |
| 224 | ret false |
| 225 | end |
| 226 | if not fcabs 4 |
| 227 | ret false |
| 228 | end |
| 229 | if not fcabs 9 |
| 230 | ret false |
| 231 | end |
| 232 | if not fcabs 10 |
| 233 | ret false |
| 234 | end |
| 235 | if not fcabs 11 |
| 236 | ret false |
| 237 | end |
| 238 | if ne get fcbig add fcoff 10 sub get fcal 10 1 47 |
| 239 | ret false |
| 240 | end |
| 241 | if eq get fcbig add fcoff 11 sub get fcal 11 1 47 |
| 242 | ret false |
| 243 | end |
| 244 | if ne get fcbig 0 122 |
| 245 | ret false |
| 246 | end |
| 247 | if or lt get fcal 0 20 gt get fcal 0 40 |
| 248 | ret false |
| 249 | end |
| 250 | if eq get fcbig fcoff 2 45 |
| 251 | ret false |
| 252 | end |
| 253 | if or eq get fcal 2 0 gt get fcal 2 64 |
| 254 | ret false |
| 255 | end |
| 256 | if or eq get fcal 3 0 gt get fcal 3 120 |
| 257 | ret false |
| 258 | end |
| 259 | for k ulong get fcal 3 bound 120 |
| 260 | if eq get fcbig add fcoff 3 k 10 |
| 261 | ret false |
| 262 | end |
| 263 | end |
| 264 | if or eq get fcal 8 0 gt get fcal 8 64 |
| 265 | ret false |
| 266 | end |
| 267 | for k ulong get fcal 8 bound 64 |
| 268 | if eq get fcbig add fcoff 8 k 47 |
| 269 | ret false |
| 270 | end |
| 271 | end |
| 272 | if not fctok 5 |
| 273 | ret false |
| 274 | end |
| 275 | if not fctok 6 |
| 276 | ret false |
| 277 | end |
| 278 | if not fctok 7 |
| 279 | ret false |
| 280 | end |
| 281 | if fcexist |
| 282 | ret false |
| 283 | end |
| 284 | ret true |
| 285 | end |
| 286 | note fcchild: when fccd is 1 the program runs in DIR, the clone at the receipt's commit |
| 287 | fn fcchild wfd int to void |
| 288 | nul = fopen tfdevnul 0 len tfdevnul 2 0 |
| 289 | if lt nul 0 |
| 290 | exit 126 |
| 291 | end |
| 292 | if eq get fccd 0 1 |
| 293 | fcdpath |
| 294 | c = chdir fpth 0 get fpthl 0 |
| 295 | if lt c 0 |
| 296 | exit 126 |
| 297 | end |
| 298 | end |
| 299 | x = dupfd int nul 0 0 |
| 300 | x = dupfd wfd 1 0 |
| 301 | x = dupfd wfd 2 0 |
| 302 | x = execprog fpk 0 get fpkl 0 |
| 303 | exit 127 |
| 304 | end |
| 305 | fn fcrun to long |
| 306 | put fxol 0 0 |
| 307 | put fxotr 0 0 |
| 308 | r = pipefds fpfd 0 8 524288 |
| 309 | if lt r 0 |
| 310 | ret -2 |
| 311 | end |
| 312 | rfd = fpfdv 0 |
| 313 | wfd = fpfdv 1 |
| 314 | dl = add long monons 60000000000 |
| 315 | pid = fork |
| 316 | if lt pid 0 |
| 317 | x = fclose rfd |
| 318 | x = fclose wfd |
| 319 | ret -2 |
| 320 | end |
| 321 | if eq pid 0 |
| 322 | fcchild wfd |
| 323 | exit 127 |
| 324 | end |
| 325 | x = fclose wfd |
| 326 | ok = fdrain rfd dl |
| 327 | x = fclose rfd |
| 328 | if not ok |
| 329 | x = killpid int pid 9 |
| 330 | end |
| 331 | st = freap int pid dl |
| 332 | if not ok |
| 333 | ret -1 |
| 334 | end |
| 335 | ret st |
| 336 | end |
| 337 | fn fcenv to void |
| 338 | fkb |
| 339 | fka tcenv |
| 340 | fka tcdash |
| 341 | fkopen |
| 342 | fkt tchome |
| 343 | fcarg 11 |
| 344 | fkopen |
| 345 | fkt tcpath |
| 346 | fcarg 11 |
| 347 | fkt tclbin |
| 348 | fkopen |
| 349 | fkt tcradh |
| 350 | fcarg 11 |
| 351 | fkt tcradp |
| 352 | fka tcg1 |
| 353 | fka tcg2 |
| 354 | fka tcg3 |
| 355 | fka tcg4 |
| 356 | fcpass |
| 357 | end |
| 358 | fn fcpenv i ulong to void |
| 359 | buf = new uchar 80 0 |
| 360 | r = envread i buf 0 80 |
| 361 | if lt r 16 |
| 362 | ret |
| 363 | end |
| 364 | for k ulong len tcpass |
| 365 | if ne get buf k get tcpass k |
| 366 | ret |
| 367 | end |
| 368 | end |
| 369 | fkopen |
| 370 | m = ulong r |
| 371 | for k ulong m bound 80 |
| 372 | fkc get buf k |
| 373 | end |
| 374 | end |
| 375 | fn fcpass to void |
| 376 | n = envcnt |
| 377 | if lt n 1 |
| 378 | ret |
| 379 | end |
| 380 | u = ulong n |
| 381 | if gt u 4096 |
| 382 | u = ulong 4096 |
| 383 | end |
| 384 | i = ulong 0 |
| 385 | while lt i u bound 4096 |
| 386 | fcpenv i |
| 387 | i = add i 1 |
| 388 | end |
| 389 | end |
| 390 | fn fcrad to void |
| 391 | fkopen |
| 392 | fcarg 11 |
| 393 | fkt tcradx |
| 394 | end |
| 395 | fn fcclone to long |
| 396 | fcenv |
| 397 | fcrad |
| 398 | fka tcclone |
| 399 | fkopen |
| 400 | fkt tcradp2 |
| 401 | fcarg 0 |
| 402 | fcnew 1 |
| 403 | ret fcrun |
| 404 | end |
| 405 | fn fccopy to long |
| 406 | put fpthl 0 0 |
| 407 | o = fcoff 1 |
| 408 | for k ulong get fcal 1 bound 320 |
| 409 | fpc get fcbig add o k |
| 410 | end |
| 411 | fpc 47 |
| 412 | o = fcoff 8 |
| 413 | for k ulong get fcal 8 bound 64 |
| 414 | fpc get fcbig add o k |
| 415 | end |
| 416 | ofd = fopen fpth 0 get fpthl 0 524865 384 |
| 417 | if lt ofd 0 |
| 418 | ret 4 |
| 419 | end |
| 420 | put fpthl 0 0 |
| 421 | o = fcoff 9 |
| 422 | for k ulong get fcal 9 bound 320 |
| 423 | fpc get fcbig add o k |
| 424 | end |
| 425 | inn = fopen fpth 0 get fpthl 0 524288 0 |
| 426 | if lt inn 0 |
| 427 | x = fclose int ofd |
| 428 | ret 4 |
| 429 | end |
| 430 | buf = new uchar 4096 0 |
| 431 | left = ulong 65536 |
| 432 | ok = true |
| 433 | while gt left 0 bound 65536 |
| 434 | k = read int inn buf 0 4096 |
| 435 | if lt k 0 |
| 436 | ok = false |
| 437 | left = ulong 0 |
| 438 | end |
| 439 | if eq k 0 |
| 440 | left = ulong 0 |
| 441 | end |
| 442 | if gt k 0 |
| 443 | w = write int ofd buf 0 ulong k |
| 444 | if ne w k |
| 445 | ok = false |
| 446 | left = ulong 0 |
| 447 | end |
| 448 | left = sub left ulong k |
| 449 | end |
| 450 | end |
| 451 | x = fsync int ofd |
| 452 | x = fclose int ofd |
| 453 | x = fclose int inn |
| 454 | if not ok |
| 455 | ret 4 |
| 456 | end |
| 457 | ret 0 |
| 458 | end |
| 459 | fn fcbranch to long |
| 460 | fcenv |
| 461 | fcgit |
| 462 | fka tcco |
| 463 | fka tcb |
| 464 | fcnew 2 |
| 465 | ret fcrun |
| 466 | end |
| 467 | fn fcadd to long |
| 468 | fcenv |
| 469 | fcgit |
| 470 | fka tcadd |
| 471 | fka tcdd |
| 472 | fcnew 8 |
| 473 | ret fcrun |
| 474 | end |
| 475 | fn fccommit to long |
| 476 | fcenv |
| 477 | fcgit |
| 478 | fka tccfg |
| 479 | fka tcgp |
| 480 | fka tccfg |
| 481 | fka tcun |
| 482 | fka tccfg |
| 483 | fka tcum |
| 484 | fka tccmt |
| 485 | fka tcm |
| 486 | fcnew 3 |
| 487 | ret fcrun |
| 488 | end |
| 489 | fn fcsha to bool |
| 490 | if lt get fxol 0 40 |
| 491 | ret false |
| 492 | end |
| 493 | for i ulong 40 |
| 494 | if not fchex get fxo i |
| 495 | ret false |
| 496 | end |
| 497 | end |
| 498 | ret true |
| 499 | end |
| 500 | fn fchead to long |
| 501 | fcenv |
| 502 | fcgit |
| 503 | fka tcrp |
| 504 | fka tchead |
| 505 | r = fcrun |
| 506 | if ne r 0 |
| 507 | ret r |
| 508 | end |
| 509 | if not fcsha |
| 510 | ret 5 |
| 511 | end |
| 512 | for i ulong 40 |
| 513 | put qncm i get fxo i |
| 514 | end |
| 515 | fcenv |
| 516 | fcgit |
| 517 | fka tcrp |
| 518 | fka tctree |
| 519 | r = fcrun |
| 520 | if ne r 0 |
| 521 | ret r |
| 522 | end |
| 523 | if not fcsha |
| 524 | ret 5 |
| 525 | end |
| 526 | for i ulong 40 |
| 527 | put qntr i get fxo i |
| 528 | end |
| 529 | ret 0 |
| 530 | end |
| 531 | fn fcevid to long |
| 532 | fcenv |
| 533 | fcnew 4 |
| 534 | put fccd 0 1 |
| 535 | r = fcrun |
| 536 | put fccd 0 0 |
| 537 | put qnrcn 0 0 |
| 538 | if and ge r 0 le r 255 |
| 539 | put qnrcn 0 ulong r |
| 540 | end |
| 541 | if lt r 0 |
| 542 | ret 6 |
| 543 | end |
| 544 | h = new uchar 32 0 |
| 545 | b = new uchar 4096 0 |
| 546 | n = get fxol 0 |
| 547 | if gt n 4096 |
| 548 | n = ulong 4096 |
| 549 | end |
| 550 | for i ulong n bound 4096 |
| 551 | put b i get fxo i |
| 552 | end |
| 553 | k = sha2_digest 256 view part b 0 n h |
| 554 | for i ulong 32 |
| 555 | v = get h i |
| 556 | put qnout64 mul i 2 qnhxb shr v 4 |
| 557 | put qnout64 add mul i 2 1 qnhxb and v 15 |
| 558 | end |
| 559 | o = fcoff 4 |
| 560 | n = get fcal 4 |
| 561 | if gt n 200 |
| 562 | ret 6 |
| 563 | end |
| 564 | for i ulong n bound 200 |
| 565 | put qncmd i get fcbig add o i |
| 566 | end |
| 567 | put qncmdl 0 n |
| 568 | o = fcoff 6 |
| 569 | n = get fcal 6 |
| 570 | for i ulong n bound 39 |
| 571 | put qnag i get fcbig add o i |
| 572 | end |
| 573 | put qnagl 0 n |
| 574 | if not qnseal |
| 575 | ret 6 |
| 576 | end |
| 577 | ret 0 |
| 578 | end |
| 579 | fn fcid to bool |
| 580 | n = get fxol 0 |
| 581 | p = ulong 0 |
| 582 | got = false |
| 583 | while lt p n bound 16777216 |
| 584 | if and le add p 40 n fcis p |
| 585 | same = true |
| 586 | for i ulong 40 |
| 587 | if ne get fxo add p i get qncm i |
| 588 | same = false |
| 589 | end |
| 590 | end |
| 591 | if not same |
| 592 | for i ulong 40 |
| 593 | put qnid i get fxo add p i |
| 594 | end |
| 595 | got = true |
| 596 | end |
| 597 | p = add p 40 |
| 598 | end |
| 599 | if not fcis p |
| 600 | p = add p 1 |
| 601 | end |
| 602 | end |
| 603 | ret got |
| 604 | end |
| 605 | fn fcis p ulong to bool |
| 606 | if gt add p 40 get fxol 0 |
| 607 | ret false |
| 608 | end |
| 609 | for i ulong 40 |
| 610 | if not fchex get fxo add p i |
| 611 | ret false |
| 612 | end |
| 613 | end |
| 614 | if lt add p 40 get fxol 0 |
| 615 | if fchex get fxo add p 40 |
| 616 | ret false |
| 617 | end |
| 618 | end |
| 619 | ret true |
| 620 | end |
| 621 | fn fcpush to long |
| 622 | fcenv |
| 623 | fcgit |
| 624 | fka tcpush |
| 625 | fka tco |
| 626 | fkopen |
| 627 | fkt tcpm |
| 628 | fcarg 3 |
| 629 | fka tcrad |
| 630 | fka tcref |
| 631 | r = fcrun |
| 632 | if ne r 0 |
| 633 | ret 7 |
| 634 | end |
| 635 | if not fcid |
| 636 | ret 7 |
| 637 | end |
| 638 | fcenv |
| 639 | fcrad |
| 640 | fka tcped |
| 641 | fka tcedit |
| 642 | fkopen |
| 643 | for i ulong 40 |
| 644 | fkc get qnid i |
| 645 | end |
| 646 | fka tcrepo |
| 647 | fkopen |
| 648 | fkt tcradp2 |
| 649 | fcarg 0 |
| 650 | fka tcna |
| 651 | fka tcmsg |
| 652 | fcnew 3 |
| 653 | fka tcmsg |
| 654 | fkopen |
| 655 | for i ulong get qnrcl 0 bound 1024 |
| 656 | fkc get qnrc i |
| 657 | end |
| 658 | r = fcrun |
| 659 | if ne r 0 |
| 660 | ret 7 |
| 661 | end |
| 662 | ret 0 |
| 663 | end |
| 664 | fn fcreview to long |
| 665 | fcenv |
| 666 | fcrad |
| 667 | fka tcped |
| 668 | fka tcrev |
| 669 | fkopen |
| 670 | for i ulong 40 |
| 671 | fkc get qnid i |
| 672 | end |
| 673 | fka tcrepo |
| 674 | fkopen |
| 675 | fkt tcradp2 |
| 676 | fcarg 0 |
| 677 | fka tcna |
| 678 | fka tcmsg |
| 679 | fka tcreq |
| 680 | ret fcrun |
| 681 | end |
| 682 | fn fcdata to void |
| 683 | buf = new uchar 320 0 |
| 684 | o = fcoff 10 |
| 685 | n = get fcal 10 |
| 686 | for i ulong n bound 320 |
| 687 | put buf i get fcbig add o i |
| 688 | end |
| 689 | qnsetd buf n |
| 690 | end |
| 691 | fn fcdigest to long |
| 692 | fcdata |
| 693 | o = fcoff 7 |
| 694 | put qnlinel 0 0 |
| 695 | for i ulong len tcped |
| 696 | put qnline i get tcped i |
| 697 | end |
| 698 | put qnlinel 0 len tcped |
| 699 | put qnline get qnlinel 0 32 |
| 700 | put qnlinel 0 add get qnlinel 0 1 |
| 701 | o = fcoff 7 |
| 702 | for i ulong get fcal 7 bound 39 |
| 703 | put qnline add get qnlinel 0 i get fcbig add o i |
| 704 | end |
| 705 | put qnlinel 0 add get qnlinel 0 get fcal 7 |
| 706 | put qnline get qnlinel 0 32 |
| 707 | put qnlinel 0 add get qnlinel 0 1 |
| 708 | o = fcoff 6 |
| 709 | for i ulong get fcal 6 bound 39 |
| 710 | put qnline add get qnlinel 0 i get fcbig add o i |
| 711 | end |
| 712 | put qnlinel 0 add get qnlinel 0 get fcal 6 |
| 713 | put qnline get qnlinel 0 32 |
| 714 | put qnlinel 0 add get qnlinel 0 1 |
| 715 | for i ulong 40 |
| 716 | put qnline add get qnlinel 0 i get qnid i |
| 717 | end |
| 718 | put qnlinel 0 add get qnlinel 0 40 |
| 719 | put qnline get qnlinel 0 32 |
| 720 | put qnlinel 0 add get qnlinel 0 1 |
| 721 | for i ulong 40 |
| 722 | put qnline add get qnlinel 0 i get qncm i |
| 723 | end |
| 724 | put qnlinel 0 add get qnlinel 0 40 |
| 725 | put qnline get qnlinel 0 10 |
| 726 | put qnlinel 0 add get qnlinel 0 1 |
| 727 | if not qnapp |
| 728 | ret 9 |
| 729 | end |
| 730 | if not qnregen |
| 731 | ret 9 |
| 732 | end |
| 733 | ret 0 |
| 734 | end |
| 735 | fn fcprint to void |
| 736 | k = write 1 tcok1 0 len tcok1 |
| 737 | for i ulong 40 |
| 738 | k = write 1 qnid i 1 |
| 739 | end |
| 740 | k = write 1 tcnl 0 1 |
| 741 | k = write 1 tcok2 0 len tcok2 |
| 742 | for i ulong 40 |
| 743 | k = write 1 qncm i 1 |
| 744 | end |
| 745 | k = write 1 tcnl 0 1 |
| 746 | end |
| 747 | note fcfail: print the failing step's captured output (up to 4096 bytes) on stderr, return its exit code |
| 748 | fn fcfail code int to int |
| 749 | k = write 2 tcfail 0 len tcfail |
| 750 | n = get fxol 0 |
| 751 | if gt n 4096 |
| 752 | n = ulong 4096 |
| 753 | end |
| 754 | k = write 2 fxo 0 n |
| 755 | k = write 2 tcnl 0 1 |
| 756 | ret code |
| 757 | end |
| 758 | fn main to int |
| 759 | r = fcload |
| 760 | if ne r 0 |
| 761 | ret int r |
| 762 | end |
| 763 | if not fcvalid |
| 764 | ret 2 |
| 765 | end |
| 766 | r = fcclone |
| 767 | if ne r 0 |
| 768 | ret fcfail 3 |
| 769 | end |
| 770 | r = fcbranch |
| 771 | if ne r 0 |
| 772 | ret fcfail 3 |
| 773 | end |
| 774 | r = fccopy |
| 775 | if ne r 0 |
| 776 | ret int r |
| 777 | end |
| 778 | r = fcadd |
| 779 | if ne r 0 |
| 780 | ret fcfail 5 |
| 781 | end |
| 782 | r = fccommit |
| 783 | if ne r 0 |
| 784 | ret fcfail 5 |
| 785 | end |
| 786 | r = fchead |
| 787 | if ne r 0 |
| 788 | ret fcfail int r |
| 789 | end |
| 790 | r = fcevid |
| 791 | if ne r 0 |
| 792 | ret int r |
| 793 | end |
| 794 | r = fcpush |
| 795 | if ne r 0 |
| 796 | ret fcfail int r |
| 797 | end |
| 798 | r = fcreview |
| 799 | if ne r 0 |
| 800 | ret fcfail 8 |
| 801 | end |
| 802 | r = fcdigest |
| 803 | if ne r 0 |
| 804 | ret int r |
| 805 | end |
| 806 | fcprint |
| 807 | ret 0 |
| 808 | end |