sovereign-intelligence
Front door to Drake Stapleton's sovereign stack.
Brought by drakestapleton
sovereign-intelligence / tools / forkpush.om
| 1 | om2 |
| 2 | note tools/forkpush.om: the Radicle fork-push script generator, in pure seeded Omega. |
| 3 | note |
| 4 | note My personal GitHub account holds branches of stack work that never reached the projects' |
| 5 | note Radicle homes. stack/FORKS.tsv lists every one of them and where it goes. This program turns |
| 6 | note that manifest into the POSIX sh script that pushes the Radicle-bound ones home, so the script |
| 7 | note is generated from data, never written by hand. Build with the seed-born compiler: |
| 8 | note omc < tools/forkpush.om > forkpush && chmod +x forkpush |
| 9 | note { printf 'target x86linux\n'; cat tools/forkpush.om; } | omc-x86 > forkpush (native x86-64) |
| 10 | note Run: |
| 11 | note forkpush FORKS OUT |
| 12 | note FORKS read: stack/FORKS.tsv. The header line is exactly |
| 13 | note github TAB branch TAB head TAB commits TAB date TAB action TAB dest |
| 14 | note then one branch per line, exactly 7 TAB-separated fields: |
| 15 | note github owner/name, both parts of letters, digits, . _ - |
| 16 | note branch letters, digits, . _ / -; not starting with - or /, not ending with /, |
| 17 | note no .. and no // |
| 18 | note head 40 lowercase hex digits |
| 19 | note commits 1 to 20 decimal digits |
| 20 | note date YYYY-MM-DD, digits |
| 21 | note action radicle (dest is the project's RID, rad:z then letters and digits), |
| 22 | note private (dest is -) or si (dest is the path in this repository, the |
| 23 | note same characters and rules as a branch) |
| 24 | note A (github, branch) pair appears once. At most 4096 rows and 4 MiB. |
| 25 | note OUT written: the script. For every radicle row it fetches the branch from |
| 26 | note https://github.com/<github> into a Radicle working copy of the project, checks the |
| 27 | note fetched commit is the manifest head, and pushes it to Radicle as fork/<branch>. |
| 28 | note private and si rows become comment lines only. Every value is single-quoted in the |
| 29 | note script; validation guarantees none holds a quote. |
| 30 | note Exit 0 when OUT is written; 2 for the wrong number of arguments; 1 for any refusal, with one |
| 31 | note stderr line "forkpush: ..." and OUT not opened (the script is built in memory and written |
| 32 | note once, at the end). The output depends only on the input bytes: no clock, no environment. |
| 33 | |
| 34 | note the manifest bytes and the script bytes |
| 35 | global inp uchar 4194304 |
| 36 | global inn ulong 1 |
| 37 | global ob uchar 4194304 |
| 38 | global obn ulong 1 |
| 39 | note the path named by the current argument |
| 40 | global pb uchar 4096 |
| 41 | global pbn ulong 1 |
| 42 | note rows, 16 cells each: offset and length of the 7 fields (cells 0..13), then the offset and |
| 43 | note length of the whole line (14, 15) |
| 44 | global row ulong 65536 |
| 45 | global nrow ulong 1 |
| 46 | note the action of each row: 1 radicle, 2 private, 3 si |
| 47 | global act ulong 4096 |
| 48 | note rows per action: radicle, private, si |
| 49 | global cnt ulong 3 |
| 50 | |
| 51 | text tpre "forkpush: " |
| 52 | text tnl "\n" |
| 53 | text tusage "usage: forkpush FORKS OUT\n" |
| 54 | text targ "cannot read a command-line argument" |
| 55 | text topen "cannot open " |
| 56 | text tread "cannot read " |
| 57 | text tbig "manifest over the 4 MiB buffer: " |
| 58 | text twrite "cannot write " |
| 59 | text toverf "script over the 4 MiB buffer" |
| 60 | text thdr "github\tbranch\thead\tcommits\tdate\taction\tdest" |
| 61 | text tbhdr "header line is not github TAB branch TAB head TAB commits TAB date TAB action TAB dest: " |
| 62 | text tcols "row needs exactly 7 TAB-separated fields: " |
| 63 | text tmany "more than 4096 rows at: " |
| 64 | text tbgh "bad github owner/name: " |
| 65 | text tbbr "bad branch: " |
| 66 | text tbhd "head is not 40 lowercase hex digits: " |
| 67 | text tbcm "commits is not 1 to 20 decimal digits: " |
| 68 | text tbdt "date is not YYYY-MM-DD: " |
| 69 | text tbac "action is not radicle, private or si: " |
| 70 | text tbrid "radicle dest is not a RID (rad:z then letters and digits): " |
| 71 | text tbpr "private dest is not -: " |
| 72 | text tbsi "bad si dest path: " |
| 73 | text tdup "duplicate github and branch: " |
| 74 | text aradi "radicle" |
| 75 | text apriv "private" |
| 76 | text asi "si" |
| 77 | text tradz "rad:z" |
| 78 | text tdash "-" |
| 79 | text q1 "fp '" |
| 80 | text q2 "' '" |
| 81 | text q3 "'\n" |
| 82 | text c1 "# private, kept off Radicle: " |
| 83 | text c2 "# in this repository at " |
| 84 | text c3 ": " |
| 85 | text sp " " |
| 86 | text m1 "# Manifest: " |
| 87 | text m2 " to push to Radicle, " |
| 88 | text m3 " kept private, " |
| 89 | text m4 " in this repository.\n\n" |
| 90 | |
| 91 | note the script, paragraph by paragraph |
| 92 | text h0 "#!/bin/sh\n# fork-push: push the fork-only branches of my personal GitHub forks to their Radicle projects.\n# Generated by tools/forkpush.om from stack/FORKS.tsv; do not edit by hand.\n#\n# For every stack/FORKS.tsv row whose action is radicle, it fetches the branch from\n# https://github.com/<owner>/<repo> into a Radicle working copy of the project, checks that the\n# fetched commit is the head the manifest names, and only then pushes it to Radicle as\n# fork/<branch>. Rows kept private and rows already in this repository are listed below as\n# comments and are never fetched or pushed.\n#\n# Needs git, and rad authenticated as the project's delegate with its node running\n# (rad auth, rad node start). It refuses to run as root.\n# FP_DIR=path the one directory it creates and works in (default ./fork-push); each project\n# is cloned there once, into a directory named after its RID without rad:\n# Exit status: 0 every branch OK, 2 a fetched commit is not the manifest head,\n# 3 a clone, fetch or push failed (3 wins over 2).\n" |
| 93 | text h1 "set -eu\numask 022\n\nFP_DIR=\"${FP_DIR:-./fork-push}\"\nfp_say() { printf '%s\\n' \"$*\"; }\nfp_die() { printf 'fork-push: %s\\n' \"$*\" >&2; exit 1; }\n\nif [ \"$(id -u)\" = \"0\" ]; then fp_die \"refusing to run as root; run it as your own user\"; fi\ncommand -v git >/dev/null 2>&1 || fp_die \"git is required: https://git-scm.com\"\ncommand -v rad >/dev/null 2>&1 || fp_die \"rad is required: https://radicle.xyz\"\nmkdir -p -- \"$FP_DIR\"\ncd -- \"$FP_DIR\"\nfp_ok=0\nfp_bad=0\nfp_fail=0\n\n" |
| 94 | text h2 "fp() {\n fp_d=\"${1#rad:}\"\n if [ ! -d \"$fp_d\" ]; then\n if ! rad clone \"$1\" \"$fp_d\" </dev/null; then\n fp_say \"FAILED $1 rad clone\"\n fp_fail=$((fp_fail + 1))\n rm -rf -- \"./$fp_d\"\n return 0\n fi\n fi\n if ! git -C \"$fp_d\" fetch --no-tags --quiet \"https://github.com/$2\" \"+refs/heads/$3:refs/heads/fork/$3\" </dev/null; then\n fp_say \"FAILED $1 fork/$3 fetch from https://github.com/$2\"\n fp_fail=$((fp_fail + 1))\n return 0\n fi\n fp_got=\"$(git -C \"$fp_d\" rev-parse \"refs/heads/fork/$3\" 2>/dev/null || true)\"\n if [ \"$fp_got\" != \"$4\" ]; then\n fp_say \"MISMATCH $1 fork/$3 manifest $4, fetched ${fp_got:-none}\"\n fp_bad=$((fp_bad + 1))\n return 0\n fi\n if git -C \"$fp_d\" push --quiet rad \"refs/heads/fork/$3:refs/heads/fork/$3\" </dev/null; then\n fp_say \"OK $1 fork/$3 $4\"\n fp_ok=$((fp_ok + 1))\n else\n fp_say \"FAILED $1 fork/$3 push\"\n fp_fail=$((fp_fail + 1))\n fi\n}\n\n" |
| 95 | text h3 "\nfp_say \"\"\nfp_say \"Done in $(pwd): $fp_ok OK, $fp_bad MISMATCH, $fp_fail FAILED.\"\nif [ \"$fp_fail\" -gt 0 ]; then exit 3; fi\nif [ \"$fp_bad\" -gt 0 ]; then exit 2; fi\nexit 0\n" |
| 96 | |
| 97 | note die: report m and up to 200 bytes of inp from o on stderr, then exit 1 |
| 98 | fn die m view uchar * o ulong n ulong to void |
| 99 | k = n |
| 100 | if gt k 200 |
| 101 | k = 200 |
| 102 | end |
| 103 | w = write 2 tpre 0 len tpre |
| 104 | w = write 2 m 0 len m |
| 105 | if gt k 0 |
| 106 | w = write 2 inp o k |
| 107 | end |
| 108 | w = write 2 tnl 0 len tnl |
| 109 | exit 1 |
| 110 | end |
| 111 | |
| 112 | note dief: report m and the current path on stderr, then exit 1 |
| 113 | fn dief m view uchar * to void |
| 114 | w = write 2 tpre 0 len tpre |
| 115 | w = write 2 m 0 len m |
| 116 | w = write 2 pb 0 get pbn 0 |
| 117 | w = write 2 tnl 0 len tnl |
| 118 | exit 1 |
| 119 | end |
| 120 | |
| 121 | note setpath: copy command-line argument ai into pb |
| 122 | fn setpath ai ulong to void |
| 123 | n = argread ai pb 0 4096 |
| 124 | if le n 0 |
| 125 | die targ 0 0 |
| 126 | end |
| 127 | put pbn 0 ulong n |
| 128 | end |
| 129 | |
| 130 | note load: read the file named by argument ai into inp |
| 131 | fn load ai ulong to void |
| 132 | setpath ai |
| 133 | fd = fopen pb 0 get pbn 0 0 0 |
| 134 | if lt fd 0 |
| 135 | dief topen |
| 136 | end |
| 137 | p = ulong 0 |
| 138 | note every pass but the last reads at least one byte of the 4 MiB buffer |
| 139 | while lt p 4194304 bound 4194305 |
| 140 | k = read int fd inp p sub 4194304 p |
| 141 | if lt k 0 |
| 142 | dief tread |
| 143 | end |
| 144 | if eq k 0 |
| 145 | break |
| 146 | end |
| 147 | p = add p ulong k |
| 148 | end |
| 149 | c = fclose int fd |
| 150 | if ge p 4194304 |
| 151 | dief tbig |
| 152 | end |
| 153 | put inn 0 p |
| 154 | end |
| 155 | |
| 156 | note wout: write ob to the file named by argument ai (created or truncated, mode 0644) |
| 157 | fn wout ai ulong to void |
| 158 | setpath ai |
| 159 | fd = fopen pb 0 get pbn 0 577 420 |
| 160 | if lt fd 0 |
| 161 | dief topen |
| 162 | end |
| 163 | n = get obn 0 |
| 164 | p = ulong 0 |
| 165 | while lt p n bound 4194305 |
| 166 | k = write int fd ob p sub n p |
| 167 | if le k 0 |
| 168 | dief twrite |
| 169 | end |
| 170 | p = add p ulong k |
| 171 | end |
| 172 | c = fclose int fd |
| 173 | if ne c 0 |
| 174 | dief twrite |
| 175 | end |
| 176 | end |
| 177 | |
| 178 | note em: append a text to ob |
| 179 | fn em t view uchar * to void |
| 180 | p = get obn 0 |
| 181 | n = len t |
| 182 | if gt n sub 4194304 p |
| 183 | die toverf 0 0 |
| 184 | end |
| 185 | for i ulong n bound 4194304 |
| 186 | put ob add p i get t i |
| 187 | end |
| 188 | put obn 0 add p n |
| 189 | end |
| 190 | |
| 191 | note emi: append n bytes of inp from o to ob |
| 192 | fn emi o ulong n ulong to void |
| 193 | p = get obn 0 |
| 194 | if gt n sub 4194304 p |
| 195 | die toverf 0 0 |
| 196 | end |
| 197 | for i ulong n bound 4194304 |
| 198 | put ob add p i get inp add o i |
| 199 | end |
| 200 | put obn 0 add p n |
| 201 | end |
| 202 | |
| 203 | note emb: append one byte to ob |
| 204 | fn emb c uchar to void |
| 205 | p = get obn 0 |
| 206 | if ge p 4194304 |
| 207 | die toverf 0 0 |
| 208 | end |
| 209 | put ob p c |
| 210 | put obn 0 add p 1 |
| 211 | end |
| 212 | |
| 213 | note emu: append v in decimal to ob |
| 214 | fn emu v ulong to void |
| 215 | d = new uchar 20 0 |
| 216 | x = v |
| 217 | put d 0 uchar add rem x 10 48 |
| 218 | k = ulong 1 |
| 219 | x = div x 10 |
| 220 | while gt x 0 bound 20 |
| 221 | put d k uchar add rem x 10 48 |
| 222 | k = add k 1 |
| 223 | x = div x 10 |
| 224 | end |
| 225 | while gt k 0 bound 20 |
| 226 | k = sub k 1 |
| 227 | emb get d k |
| 228 | end |
| 229 | end |
| 230 | |
| 231 | note eqx: do the n bytes of inp at o equal the text t |
| 232 | fn eqx o ulong n ulong t view uchar * to bool |
| 233 | if ne n len t |
| 234 | ret false |
| 235 | end |
| 236 | for i ulong n bound 4194304 |
| 237 | if ne get inp add o i get t i |
| 238 | ret false |
| 239 | end |
| 240 | end |
| 241 | ret true |
| 242 | end |
| 243 | |
| 244 | note eqs: are two slices of inp equal |
| 245 | fn eqs a ulong an ulong b ulong bn ulong to bool |
| 246 | if ne an bn |
| 247 | ret false |
| 248 | end |
| 249 | for i ulong an bound 4194304 |
| 250 | if ne get inp add a i get inp add b i |
| 251 | ret false |
| 252 | end |
| 253 | end |
| 254 | ret true |
| 255 | end |
| 256 | |
| 257 | note eol: the end of the line that starts at p (its newline, or e) |
| 258 | fn eol p ulong e ulong to ulong |
| 259 | q = p |
| 260 | while lt q e bound 4194305 |
| 261 | if eq get inp q 10 |
| 262 | ret q |
| 263 | end |
| 264 | q = add q 1 |
| 265 | end |
| 266 | ret e |
| 267 | end |
| 268 | |
| 269 | fn isaln c uchar to bool |
| 270 | ret or or and ge c 48 le c 57 and ge c 65 le c 90 and ge c 97 le c 122 |
| 271 | end |
| 272 | |
| 273 | note isnm: a letter, a digit, or one of . _ - |
| 274 | fn isnm c uchar to bool |
| 275 | if isaln c |
| 276 | ret true |
| 277 | end |
| 278 | ret or or eq c 46 eq c 95 eq c 45 |
| 279 | end |
| 280 | |
| 281 | fn isdig c uchar to bool |
| 282 | ret and ge c 48 le c 57 |
| 283 | end |
| 284 | |
| 285 | fn ishex c uchar to bool |
| 286 | ret or and ge c 48 le c 57 and ge c 97 le c 102 |
| 287 | end |
| 288 | |
| 289 | note vgh: is inp[o, o+n) owner/name, both parts non-empty letters, digits, . _ - |
| 290 | fn vgh o ulong n ulong to bool |
| 291 | sl = ulong 0 |
| 292 | ns = ulong 0 |
| 293 | for i ulong n bound 4194304 |
| 294 | c = get inp add o i |
| 295 | if eq c 47 |
| 296 | ns = add ns 1 |
| 297 | sl = i |
| 298 | else |
| 299 | if not isnm c |
| 300 | ret false |
| 301 | end |
| 302 | end |
| 303 | end |
| 304 | if ne ns 1 |
| 305 | ret false |
| 306 | end |
| 307 | ret and gt sl 0 lt add sl 1 n |
| 308 | end |
| 309 | |
| 310 | note vpath: is inp[o, o+n) a branch or path: letters, digits, . _ / -, not starting with - or |
| 311 | note /, not ending with /, no .. and no // |
| 312 | fn vpath o ulong n ulong to bool |
| 313 | if eq n 0 |
| 314 | ret false |
| 315 | end |
| 316 | c0 = get inp o |
| 317 | if or eq c0 45 eq c0 47 |
| 318 | ret false |
| 319 | end |
| 320 | if eq get inp add o sub n 1 47 |
| 321 | ret false |
| 322 | end |
| 323 | pr = uchar 0 |
| 324 | for i ulong n bound 4194304 |
| 325 | c = get inp add o i |
| 326 | if not or isnm c eq c 47 |
| 327 | ret false |
| 328 | end |
| 329 | if and eq c 46 eq pr 46 |
| 330 | ret false |
| 331 | end |
| 332 | if and eq c 47 eq pr 47 |
| 333 | ret false |
| 334 | end |
| 335 | pr = c |
| 336 | end |
| 337 | ret true |
| 338 | end |
| 339 | |
| 340 | note vhead: is inp[o, o+n) 40 lowercase hex digits |
| 341 | fn vhead o ulong n ulong to bool |
| 342 | if ne n 40 |
| 343 | ret false |
| 344 | end |
| 345 | for i ulong 40 |
| 346 | if not ishex get inp add o i |
| 347 | ret false |
| 348 | end |
| 349 | end |
| 350 | ret true |
| 351 | end |
| 352 | |
| 353 | note vnum: is inp[o, o+n) 1 to 20 decimal digits |
| 354 | fn vnum o ulong n ulong to bool |
| 355 | if or eq n 0 gt n 20 |
| 356 | ret false |
| 357 | end |
| 358 | for i ulong n bound 20 |
| 359 | if not isdig get inp add o i |
| 360 | ret false |
| 361 | end |
| 362 | end |
| 363 | ret true |
| 364 | end |
| 365 | |
| 366 | note vdate: is inp[o, o+n) YYYY-MM-DD in digits |
| 367 | fn vdate o ulong n ulong to bool |
| 368 | if ne n 10 |
| 369 | ret false |
| 370 | end |
| 371 | for i ulong 10 |
| 372 | c = get inp add o i |
| 373 | if or eq i 4 eq i 7 |
| 374 | if ne c 45 |
| 375 | ret false |
| 376 | end |
| 377 | else |
| 378 | if not isdig c |
| 379 | ret false |
| 380 | end |
| 381 | end |
| 382 | end |
| 383 | ret true |
| 384 | end |
| 385 | |
| 386 | note vrid: is inp[o, o+n) rad:z then at least one letter or digit |
| 387 | fn vrid o ulong n ulong to bool |
| 388 | if le n 5 |
| 389 | ret false |
| 390 | end |
| 391 | if not eqx o 5 tradz |
| 392 | ret false |
| 393 | end |
| 394 | for i ulong sub n 5 bound 4194304 |
| 395 | if not isaln get inp add add o 5 i |
| 396 | ret false |
| 397 | end |
| 398 | end |
| 399 | ret true |
| 400 | end |
| 401 | |
| 402 | note fo / fl: offset and length of field k of row r |
| 403 | fn fo r ulong k ulong to ulong |
| 404 | ret get row add mul r 16 mul k 2 |
| 405 | end |
| 406 | |
| 407 | fn fl r ulong k ulong to ulong |
| 408 | ret get row add add mul r 16 mul k 2 1 |
| 409 | end |
| 410 | |
| 411 | note lineo / linel: offset and length of row r's whole line |
| 412 | fn lineo r ulong to ulong |
| 413 | ret get row add mul r 16 14 |
| 414 | end |
| 415 | |
| 416 | fn linel r ulong to ulong |
| 417 | ret get row add mul r 16 15 |
| 418 | end |
| 419 | |
| 420 | note bad: refuse row r with message m when ok is false |
| 421 | fn bad ok bool m view uchar * r ulong to void |
| 422 | if not ok |
| 423 | die m lineo r linel r |
| 424 | end |
| 425 | end |
| 426 | |
| 427 | note split: store the 7 TAB-separated fields of the line [p, q) as row r |
| 428 | fn split p ulong q ulong r ulong to void |
| 429 | b = mul r 16 |
| 430 | put row add b 14 p |
| 431 | put row add b 15 sub q p |
| 432 | k = ulong 0 |
| 433 | s = p |
| 434 | t = p |
| 435 | while lt t q bound 4194305 |
| 436 | if eq get inp t 9 |
| 437 | if ge k 6 |
| 438 | die tcols p sub q p |
| 439 | end |
| 440 | put row add b mul k 2 s |
| 441 | put row add add b mul k 2 1 sub t s |
| 442 | k = add k 1 |
| 443 | s = add t 1 |
| 444 | end |
| 445 | t = add t 1 |
| 446 | end |
| 447 | if ne k 6 |
| 448 | die tcols p sub q p |
| 449 | end |
| 450 | put row add b 12 s |
| 451 | put row add b 13 sub q s |
| 452 | end |
| 453 | |
| 454 | note actof: the action of row r: 1 radicle, 2 private, 3 si; 0 for anything else |
| 455 | fn actof r ulong to ulong |
| 456 | o = fo r 5 |
| 457 | n = fl r 5 |
| 458 | if eqx o n aradi |
| 459 | ret 1 |
| 460 | end |
| 461 | if eqx o n apriv |
| 462 | ret 2 |
| 463 | end |
| 464 | if eqx o n asi |
| 465 | ret 3 |
| 466 | end |
| 467 | ret 0 |
| 468 | end |
| 469 | |
| 470 | note vdest: check row r's dest against its action a |
| 471 | fn vdest r ulong a ulong to void |
| 472 | o = fo r 6 |
| 473 | n = fl r 6 |
| 474 | if eq a 1 |
| 475 | bad vrid o n tbrid r |
| 476 | end |
| 477 | if eq a 2 |
| 478 | bad eqx o n tdash tbpr r |
| 479 | end |
| 480 | if eq a 3 |
| 481 | bad vpath o n tbsi r |
| 482 | end |
| 483 | end |
| 484 | |
| 485 | note vrow: check every field of row r, record its action, and refuse a repeated pair |
| 486 | fn vrow r ulong to void |
| 487 | bad vgh fo r 0 fl r 0 tbgh r |
| 488 | bad vpath fo r 1 fl r 1 tbbr r |
| 489 | bad vhead fo r 2 fl r 2 tbhd r |
| 490 | bad vnum fo r 3 fl r 3 tbcm r |
| 491 | bad vdate fo r 4 fl r 4 tbdt r |
| 492 | a = actof r |
| 493 | bad gt a 0 tbac r |
| 494 | vdest r a |
| 495 | put act r a |
| 496 | j = sub a 1 |
| 497 | put cnt j add get cnt j 1 |
| 498 | for i ulong r bound 4096 |
| 499 | if eqs fo i 0 fl i 0 fo r 0 fl r 0 |
| 500 | bad not eqs fo i 1 fl i 1 fo r 1 fl r 1 tdup r |
| 501 | end |
| 502 | end |
| 503 | end |
| 504 | |
| 505 | note parse: check the header, then split and check every row |
| 506 | fn parse to void |
| 507 | e = get inn 0 |
| 508 | q = eol 0 e |
| 509 | if not eqx 0 q thdr |
| 510 | die tbhdr 0 q |
| 511 | end |
| 512 | p = add q 1 |
| 513 | r = ulong 0 |
| 514 | note every pass consumes at least one byte of the manifest |
| 515 | while lt p e bound 4194305 |
| 516 | q = eol p e |
| 517 | if ge r 4096 |
| 518 | die tmany p sub q p |
| 519 | end |
| 520 | split p q r |
| 521 | vrow r |
| 522 | r = add r 1 |
| 523 | p = add q 1 |
| 524 | end |
| 525 | put nrow 0 r |
| 526 | end |
| 527 | |
| 528 | note emf: append field k of row r |
| 529 | fn emf r ulong k ulong to void |
| 530 | emi fo r k fl r k |
| 531 | end |
| 532 | |
| 533 | note emrow: append row r's line of the script |
| 534 | fn emrow r ulong to void |
| 535 | a = get act r |
| 536 | if eq a 1 |
| 537 | em q1 |
| 538 | emf r 6 |
| 539 | em q2 |
| 540 | emf r 0 |
| 541 | em q2 |
| 542 | emf r 1 |
| 543 | em q2 |
| 544 | emf r 2 |
| 545 | em q3 |
| 546 | ret |
| 547 | end |
| 548 | if eq a 2 |
| 549 | em c1 |
| 550 | else |
| 551 | em c2 |
| 552 | emf r 6 |
| 553 | em c3 |
| 554 | end |
| 555 | emf r 0 |
| 556 | em sp |
| 557 | emf r 1 |
| 558 | em tnl |
| 559 | end |
| 560 | |
| 561 | fn main to int |
| 562 | if ne argcnt 3 |
| 563 | w = write 2 tusage 0 len tusage |
| 564 | ret 2 |
| 565 | end |
| 566 | load 1 |
| 567 | parse |
| 568 | em h0 |
| 569 | em m1 |
| 570 | emu get cnt 0 |
| 571 | em m2 |
| 572 | emu get cnt 1 |
| 573 | em m3 |
| 574 | emu get cnt 2 |
| 575 | em m4 |
| 576 | em h1 |
| 577 | em h2 |
| 578 | n = get nrow 0 |
| 579 | for r ulong n bound 4096 |
| 580 | emrow r |
| 581 | end |
| 582 | em h3 |
| 583 | wout 2 |
| 584 | ret 0 |
| 585 | end |