hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Omega / tests / mutant / hopcore-board.om
| 1 | note hopcore: Hop's matching core, an Omega program built by Omega NG (ng front-ir, opt, a64 macho). It holds |
| 2 | note hopfuzz, the name matcher of the one box, and a main that serves it to Hop over stdin and stdout. |
| 3 | note Contract: Omega/README.md. |
| 4 | note One call scores typed text against one name: a whole match beats a prefix, which beats a later |
| 5 | note word start, initials, a plain "contains", one wrong letter, and letters in order with few gaps. |
| 6 | note The host lowercases both texts and sends one word per character: bits 0..31 a character id |
| 7 | note (equal characters get equal ids), bit 32 "letter or number", bit 33 "trimmable white space". |
| 8 | note Any malformed input fails closed as verdict 2 INVALID with the first faulting word; a text |
| 9 | note over the limits is INVALID, never cut short. Verdict 0 is "no match", 1 is "match" (score at 3). |
| 10 | |
| 11 | fn isword w ulong to bool |
| 12 | ret ne and w 4294967296 0 |
| 13 | end |
| 14 | |
| 15 | fn istrim w ulong to bool |
| 16 | ret ne and w 8589934592 0 |
| 17 | end |
| 18 | |
| 19 | fn minu a ulong b ulong to ulong |
| 20 | if lt a b |
| 21 | ret a |
| 22 | end |
| 23 | ret b |
| 24 | end |
| 25 | |
| 26 | note true when inp[a .. a+n) equals inp[b .. b+n); both runs must lie inside the buffer |
| 27 | fn same inp view ulong 256 a ulong b ulong n ulong to bool |
| 28 | for k ulong n |
| 29 | if ne get inp add a k get inp add b k |
| 30 | ret false |
| 31 | end |
| 32 | end |
| 33 | ret true |
| 34 | end |
| 35 | |
| 36 | note x is one longer than y (ls characters): true when dropping one character of x gives y |
| 37 | fn skip1 inp view ulong 256 x ulong y ulong ls ulong to bool |
| 38 | k = ulong 0 |
| 39 | while lt k ls bound 256 |
| 40 | if ne get inp add x k get inp add y k |
| 41 | break |
| 42 | end |
| 43 | k = add k 1 |
| 44 | end |
| 45 | ret same inp add x add k 1 add y k sub ls k |
| 46 | end |
| 47 | |
| 48 | note edit distance at most 1, where swapping two neighbours counts as one |
| 49 | fn near inp view ulong 256 a ulong la ulong b ulong lb ulong to bool |
| 50 | if eq la lb |
| 51 | d = ulong 0 |
| 52 | p = ulong 0 |
| 53 | for k ulong la |
| 54 | if ne get inp add a k get inp add b k |
| 55 | if eq d 0 |
| 56 | p = k |
| 57 | end |
| 58 | d = add d 1 |
| 59 | end |
| 60 | end |
| 61 | if le d 1 |
| 62 | ret true |
| 63 | end |
| 64 | if eq d 2 |
| 65 | if lt add p 1 la |
| 66 | if eq get inp add a p get inp add b add p 1 |
| 67 | if eq get inp add a add p 1 get inp add b p |
| 68 | ret true |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | end |
| 73 | ret false |
| 74 | end |
| 75 | if eq la add lb 1 |
| 76 | ret skip1 inp a b lb |
| 77 | end |
| 78 | if eq lb add la 1 |
| 79 | ret skip1 inp b a la |
| 80 | end |
| 81 | ret false |
| 82 | end |
| 83 | |
| 84 | note score of q = inp[qa .. qa+ql) in the name inp[72 .. 72+nl); 0 means no match. ql and nl >= 1 |
| 85 | fn one inp view ulong 256 qa ulong ql ulong nl ulong to ulong |
| 86 | if le ql nl |
| 87 | if same inp qa 72 ql |
| 88 | if eq ql nl |
| 89 | ret 200 |
| 90 | end |
| 91 | ret sub 160 minu 30 sub nl ql |
| 92 | end |
| 93 | end |
| 94 | qw = true |
| 95 | for k ulong ql |
| 96 | if not isword get inp add qa k |
| 97 | qw = false |
| 98 | end |
| 99 | end |
| 100 | wc = ulong 0 |
| 101 | later = false |
| 102 | inits = true |
| 103 | inw = false |
| 104 | for i ulong nl |
| 105 | c = get inp add 72 i |
| 106 | if isword c |
| 107 | if not inw |
| 108 | if lt wc ql |
| 109 | if ne c get inp add qa wc |
| 110 | inits = false |
| 111 | end |
| 112 | end |
| 113 | if gt wc 0 |
| 114 | if qw |
| 115 | if le add i ql nl |
| 116 | if same inp qa add 72 i ql |
| 117 | later = true |
| 118 | end |
| 119 | end |
| 120 | end |
| 121 | end |
| 122 | wc = add wc 1 |
| 123 | end |
| 124 | inw = true |
| 125 | else |
| 126 | inw = false |
| 127 | end |
| 128 | end |
| 129 | if later |
| 130 | ret sub 120 minu 20 div nl 3 |
| 131 | end |
| 132 | if ge ql 2 |
| 133 | if gt wc 1 |
| 134 | if ge wc ql |
| 135 | if inits |
| 136 | ret 110 |
| 137 | end |
| 138 | end |
| 139 | end |
| 140 | end |
| 141 | if le ql nl |
| 142 | for i ulong add sub nl ql 1 |
| 143 | if same inp qa add 72 i ql |
| 144 | ret sub 80 minu 20 div nl 3 |
| 145 | end |
| 146 | end |
| 147 | end |
| 148 | if ge ql 4 |
| 149 | if le ql nl |
| 150 | if near inp qa ql 72 ql |
| 151 | ret 70 |
| 152 | end |
| 153 | end |
| 154 | if le sub ql 1 nl |
| 155 | if near inp qa ql 72 sub ql 1 |
| 156 | ret 70 |
| 157 | end |
| 158 | end |
| 159 | if le add ql 1 nl |
| 160 | if near inp qa ql 72 add ql 1 |
| 161 | ret 70 |
| 162 | end |
| 163 | end |
| 164 | end |
| 165 | if lt ql 3 |
| 166 | ret 0 |
| 167 | end |
| 168 | qi = ulong 0 |
| 169 | gaps = ulong 0 |
| 170 | last = ulong 0 |
| 171 | first = ulong 0 |
| 172 | for i ulong nl |
| 173 | if lt qi ql |
| 174 | if eq get inp add 72 i get inp add qa qi |
| 175 | if gt qi 0 |
| 176 | gaps = add gaps sub sub i last 1 |
| 177 | else |
| 178 | first = i |
| 179 | end |
| 180 | last = i |
| 181 | qi = add qi 1 |
| 182 | end |
| 183 | end |
| 184 | end |
| 185 | if ne qi ql |
| 186 | ret 0 |
| 187 | end |
| 188 | if gt gaps ql |
| 189 | ret 0 |
| 190 | end |
| 191 | t = add mul gaps 6 mul first 3 |
| 192 | if ge t 45 |
| 193 | ret 15 |
| 194 | end |
| 195 | ret sub 60 t |
| 196 | end |
| 197 | |
| 198 | note first faulting word plus 1, or 0 when the input is well formed |
| 199 | fn check inp view ulong 256 to ulong |
| 200 | if ne get inp 0 1212568922 |
| 201 | ret 1 |
| 202 | end |
| 203 | if ne get inp 1 1 |
| 204 | ret 2 |
| 205 | end |
| 206 | ql = get inp 2 |
| 207 | nl = get inp 3 |
| 208 | if gt ql 64 |
| 209 | ret 3 |
| 210 | end |
| 211 | if gt nl 184 |
| 212 | ret 4 |
| 213 | end |
| 214 | for i ulong 4 |
| 215 | if ne get inp add 4 i 0 |
| 216 | ret add 5 i |
| 217 | end |
| 218 | end |
| 219 | for i ulong 64 |
| 220 | w = get inp add 8 i |
| 221 | if lt i ql |
| 222 | if ge w 17179869184 |
| 223 | ret add 9 i |
| 224 | end |
| 225 | if eq and w 4294967295 0 |
| 226 | ret add 9 i |
| 227 | end |
| 228 | else |
| 229 | if ne w 0 |
| 230 | ret add 9 i |
| 231 | end |
| 232 | end |
| 233 | end |
| 234 | for i ulong 184 |
| 235 | w = get inp add 72 i |
| 236 | if lt i nl |
| 237 | if ge w 17179869184 |
| 238 | ret add 73 i |
| 239 | end |
| 240 | if eq and w 4294967295 0 |
| 241 | ret add 73 i |
| 242 | end |
| 243 | else |
| 244 | if ne w 0 |
| 245 | ret add 73 i |
| 246 | end |
| 247 | end |
| 248 | end |
| 249 | ret 0 |
| 250 | end |
| 251 | |
| 252 | fn hopfuzz inp view ulong 256 res edit ulong 256 to ulong |
| 253 | for i ulong 256 |
| 254 | put res i 0 |
| 255 | end |
| 256 | put res 0 1212568922 |
| 257 | put res 1 1 |
| 258 | e = check inp |
| 259 | if ne e 0 |
| 260 | put res 2 2 |
| 261 | put res 4 sub e 1 |
| 262 | ret 2 |
| 263 | end |
| 264 | nl = get inp 3 |
| 265 | qa = ulong 8 |
| 266 | qe = add 8 get inp 2 |
| 267 | while lt qa qe bound 256 |
| 268 | if not istrim get inp qa |
| 269 | break |
| 270 | end |
| 271 | qa = add qa 1 |
| 272 | end |
| 273 | while gt qe qa bound 256 |
| 274 | if not istrim get inp sub qe 1 |
| 275 | break |
| 276 | end |
| 277 | qe = sub qe 1 |
| 278 | end |
| 279 | ql = sub qe qa |
| 280 | if eq ql 0 |
| 281 | ret 0 |
| 282 | end |
| 283 | if eq nl 0 |
| 284 | ret 0 |
| 285 | end |
| 286 | s = one inp qa ql nl |
| 287 | if eq s 0 |
| 288 | terms = ulong 0 |
| 289 | sum = ulong 0 |
| 290 | p = qa |
| 291 | while lt p qe bound 256 |
| 292 | if eq and get inp p 4294967295 32 |
| 293 | p = add p 1 |
| 294 | continue |
| 295 | end |
| 296 | b = p |
| 297 | while lt p qe bound 256 |
| 298 | if eq and get inp p 4294967295 32 |
| 299 | break |
| 300 | end |
| 301 | p = add p 1 |
| 302 | end |
| 303 | ts = one inp b sub p b nl |
| 304 | if eq ts 0 |
| 305 | ret 0 |
| 306 | end |
| 307 | terms = add terms 1 |
| 308 | sum = add sum ts |
| 309 | end |
| 310 | if le terms 1 |
| 311 | ret 0 |
| 312 | end |
| 313 | s = sub div sum terms 10 |
| 314 | end |
| 315 | put res 2 1 |
| 316 | put res 3 s |
| 317 | ret 1 |
| 318 | end |
| 319 | |
| 320 | note ---- file-name scoring (kind 2): how well a path found on another machine matches the typed terms ---- |
| 321 | note The host sends bytes: the terms, and for each path its lowercased bytes, the lowercased bytes of its last |
| 322 | note component (its name), and the byte length of the path as written. A term found in the name scores 60 when the name |
| 323 | note starts with it and 30 otherwise; found only elsewhere in the path it scores 5; a term found nowhere, or an |
| 324 | note empty term, means no match. One point less for every 20 bytes of path; 40 more when the name is exactly as long as the terms. |
| 325 | |
| 326 | fn rd16 b view uchar 1048576 o ulong to ulong |
| 327 | ret or ulong get b o shl ulong get b add o 1 8 |
| 328 | end |
| 329 | |
| 330 | fn rd32 b view uchar 1048576 o ulong to ulong |
| 331 | ret or rd16 b o shl rd16 b add o 2 16 |
| 332 | end |
| 333 | |
| 334 | note true when b[x .. x+n) equals b[y .. y+n) |
| 335 | fn beq b view uchar 1048576 x ulong y ulong n ulong to bool |
| 336 | for k ulong n |
| 337 | if ne get b add x k get b add y k |
| 338 | ret false |
| 339 | end |
| 340 | end |
| 341 | ret true |
| 342 | end |
| 343 | |
| 344 | note true when the run b[t .. t+tl) occurs in b[h .. h+hl) |
| 345 | fn bhas b view uchar 1048576 h ulong hl ulong t ulong tl ulong to bool |
| 346 | if gt tl hl |
| 347 | ret false |
| 348 | end |
| 349 | for i ulong add sub hl tl 1 |
| 350 | if beq b add h i t tl |
| 351 | ret true |
| 352 | end |
| 353 | end |
| 354 | ret false |
| 355 | end |
| 356 | |
| 357 | note score of one path plus 1000000, or 0 for no match. pm: 0 the number of terms, 1 where the path's bytes |
| 358 | note start, 2 how many, 3 where its name's bytes start, 4 how many, 5 the path's length as written |
| 359 | fn fscore b view uchar 1048576 toff view ulong 64 tlen view ulong 64 pm view ulong 8 to ulong |
| 360 | nt = get pm 0 |
| 361 | p = get pm 1 |
| 362 | pl = get pm 2 |
| 363 | ns = get pm 3 |
| 364 | nl = get pm 4 |
| 365 | ol = get pm 5 |
| 366 | s = ulong 1000000 |
| 367 | sum = ulong 0 |
| 368 | for k ulong nt |
| 369 | t = get toff k |
| 370 | tl = get tlen k |
| 371 | sum = add sum tl |
| 372 | if eq tl 0 |
| 373 | ret 0 |
| 374 | end |
| 375 | if bhas b ns nl t tl |
| 376 | if beq b ns t tl |
| 377 | s = add s 60 |
| 378 | else |
| 379 | s = add s 30 |
| 380 | end |
| 381 | else |
| 382 | if bhas b p pl t tl |
| 383 | s = add s 5 |
| 384 | else |
| 385 | ret 0 |
| 386 | end |
| 387 | end |
| 388 | end |
| 389 | s = sub s div ol 20 |
| 390 | if eq nl sum |
| 391 | s = add s 40 |
| 392 | end |
| 393 | ret s |
| 394 | end |
| 395 | |
| 396 | note ---- text decisions (kind 3): is it a question, which words to search for, is it a web address ---- |
| 397 | note The host lowercases the text and sends one 8-byte word per character: bits 0..31 an id (equal characters get |
| 398 | note equal ids; a character of one Unicode scalar has that scalar's number), then a flag byte: 1 letter or number, |
| 399 | note 2 trimmable white space, 4 white space, 8 white space or line end. |
| 400 | note lists: three lists of plain words, separated by "|": 0 the words a question starts with, 1 the words a search |
| 401 | note leaves out, 2 the endings of a bare web address. |
| 402 | text lists "what what's whats why how how's who who's whom whose when where which explain define translate summarize summarise describe|the and for with that this what when where does did how why can you are was were have has from into about please make need want just our my its not|com org net io dev ai co edu gov xyz me us uk ca de tv gg" |
| 403 | |
| 404 | fn cid b view uchar 1048576 i ulong to ulong |
| 405 | ret rd32 b add 16 mul i 8 |
| 406 | end |
| 407 | |
| 408 | fn cfl b view uchar 1048576 i ulong to ulong |
| 409 | ret ulong get b add 20 mul i 8 |
| 410 | end |
| 411 | |
| 412 | note true when the n characters from s are exactly one word of list sec |
| 413 | fn inlist b view uchar 1048576 s ulong n ulong sec ulong to bool |
| 414 | cur = ulong 0 |
| 415 | p = ulong 0 |
| 416 | ln = len lists |
| 417 | while lt p ln bound 999999 |
| 418 | e = p |
| 419 | while lt e ln bound 999999 |
| 420 | c = ulong get lists e |
| 421 | if or eq c 32 eq c 124 |
| 422 | break |
| 423 | end |
| 424 | e = add e 1 |
| 425 | end |
| 426 | if eq cur sec |
| 427 | if eq sub e p n |
| 428 | ok = true |
| 429 | for k ulong n |
| 430 | if ne cid b add s k ulong get lists add p k |
| 431 | ok = false |
| 432 | end |
| 433 | end |
| 434 | if ok |
| 435 | ret true |
| 436 | end |
| 437 | end |
| 438 | end |
| 439 | if lt e ln |
| 440 | if eq ulong get lists e 124 |
| 441 | cur = add cur 1 |
| 442 | end |
| 443 | end |
| 444 | p = add e 1 |
| 445 | end |
| 446 | ret false |
| 447 | end |
| 448 | |
| 449 | note op 1: 1 when the text reads as a question: it ends with "?" and is longer than that, or it has three words |
| 450 | note or more and starts with a question word |
| 451 | fn qlike b view uchar 1048576 n ulong to ulong |
| 452 | a = ulong 0 |
| 453 | e = n |
| 454 | while lt a e bound 999999 |
| 455 | if eq and cfl b a 8 0 |
| 456 | break |
| 457 | end |
| 458 | a = add a 1 |
| 459 | end |
| 460 | while gt e a bound 999999 |
| 461 | if eq and cfl b sub e 1 8 0 |
| 462 | break |
| 463 | end |
| 464 | e = sub e 1 |
| 465 | end |
| 466 | if gt sub e a 1 |
| 467 | if eq cid b sub e 1 63 |
| 468 | ret 1 |
| 469 | end |
| 470 | end |
| 471 | w = ulong 0 |
| 472 | fs = ulong 0 |
| 473 | fl = ulong 0 |
| 474 | i = a |
| 475 | while lt i e bound 999999 |
| 476 | if ne and cfl b i 4 0 |
| 477 | i = add i 1 |
| 478 | continue |
| 479 | end |
| 480 | st = i |
| 481 | while lt i e bound 999999 |
| 482 | if ne and cfl b i 4 0 |
| 483 | break |
| 484 | end |
| 485 | i = add i 1 |
| 486 | end |
| 487 | if eq w 0 |
| 488 | fs = st |
| 489 | fl = sub i st |
| 490 | end |
| 491 | w = add w 1 |
| 492 | end |
| 493 | if lt w 3 |
| 494 | ret 0 |
| 495 | end |
| 496 | if inlist b fs fl 0 |
| 497 | ret 1 |
| 498 | end |
| 499 | ret 0 |
| 500 | end |
| 501 | |
| 502 | note a character of a search word: a letter, a number, "-", "_" or "." |
| 503 | fn iswc b view uchar 1048576 i ulong to bool |
| 504 | if ne and cfl b i 1 0 |
| 505 | ret true |
| 506 | end |
| 507 | c = cid b i |
| 508 | if eq c 45 |
| 509 | ret true |
| 510 | end |
| 511 | if eq c 95 |
| 512 | ret true |
| 513 | end |
| 514 | ret eq c 46 |
| 515 | end |
| 516 | |
| 517 | fn samec b view uchar 1048576 x ulong y ulong n ulong to bool |
| 518 | for k ulong n |
| 519 | if ne cid b add x k cid b add y k |
| 520 | ret false |
| 521 | end |
| 522 | end |
| 523 | ret true |
| 524 | end |
| 525 | |
| 526 | note true when the word of wl characters at st also stands earlier in the text |
| 527 | fn seen b view uchar 1048576 st ulong wl ulong to bool |
| 528 | i = ulong 0 |
| 529 | while lt i st bound 999999 |
| 530 | if not iswc b i |
| 531 | i = add i 1 |
| 532 | continue |
| 533 | end |
| 534 | s0 = i |
| 535 | while lt i st bound 999999 |
| 536 | if not iswc b i |
| 537 | break |
| 538 | end |
| 539 | i = add i 1 |
| 540 | end |
| 541 | if eq sub i s0 wl |
| 542 | if samec b s0 st wl |
| 543 | ret true |
| 544 | end |
| 545 | end |
| 546 | end |
| 547 | ret false |
| 548 | end |
| 549 | |
| 550 | note op 2: the words to search for: three characters or more, not a left-out word, each once, the longest four, |
| 551 | note longest first and in the order typed among equals. Writes the count, then where each starts and its length |
| 552 | fn keyw b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 553 | ts = new ulong 4 0 |
| 554 | tl = new ulong 4 0 |
| 555 | k = ulong 0 |
| 556 | i = ulong 0 |
| 557 | while lt i n bound 999999 |
| 558 | if not iswc b i |
| 559 | i = add i 1 |
| 560 | continue |
| 561 | end |
| 562 | st = i |
| 563 | while lt i n bound 999999 |
| 564 | if not iswc b i |
| 565 | break |
| 566 | end |
| 567 | i = add i 1 |
| 568 | end |
| 569 | wl = sub i st |
| 570 | if lt wl 3 |
| 571 | continue |
| 572 | end |
| 573 | if inlist b st wl 1 |
| 574 | continue |
| 575 | end |
| 576 | if seen b st wl |
| 577 | continue |
| 578 | end |
| 579 | pos = k |
| 580 | for j ulong k |
| 581 | if lt get tl j wl |
| 582 | if eq pos k |
| 583 | pos = j |
| 584 | end |
| 585 | end |
| 586 | end |
| 587 | if lt pos 4 |
| 588 | for d ulong sub 3 pos |
| 589 | u = sub 3 d |
| 590 | put tl u get tl sub u 1 |
| 591 | put ts u get ts sub u 1 |
| 592 | end |
| 593 | put tl pos wl |
| 594 | put ts pos st |
| 595 | if lt k 4 |
| 596 | k = add k 1 |
| 597 | end |
| 598 | end |
| 599 | end |
| 600 | put ob 8 uchar k |
| 601 | for j ulong k |
| 602 | s = get ts j |
| 603 | l = get tl j |
| 604 | put ob add 9 mul j 4 uchar and s 255 |
| 605 | put ob add 10 mul j 4 uchar shr s 8 |
| 606 | put ob add 11 mul j 4 uchar and l 255 |
| 607 | put ob add 12 mul j 4 uchar shr l 8 |
| 608 | end |
| 609 | ret add 1 mul k 4 |
| 610 | end |
| 611 | |
| 612 | fn hasscheme b view uchar 1048576 n ulong to bool |
| 613 | if lt n 7 |
| 614 | ret false |
| 615 | end |
| 616 | if ne cid b 0 104 |
| 617 | ret false |
| 618 | end |
| 619 | if ne cid b 1 116 |
| 620 | ret false |
| 621 | end |
| 622 | if ne cid b 2 116 |
| 623 | ret false |
| 624 | end |
| 625 | if ne cid b 3 112 |
| 626 | ret false |
| 627 | end |
| 628 | o = ulong 4 |
| 629 | if eq cid b 4 115 |
| 630 | o = ulong 5 |
| 631 | end |
| 632 | if lt n add o 3 |
| 633 | ret false |
| 634 | end |
| 635 | if ne cid b o 58 |
| 636 | ret false |
| 637 | end |
| 638 | if ne cid b add o 1 47 |
| 639 | ret false |
| 640 | end |
| 641 | ret eq cid b add o 2 47 |
| 642 | end |
| 643 | |
| 644 | note op 3: 0 not a web address; 1 it starts with http:// or https:// (the host then checks that it names a |
| 645 | note machine); 2 a bare address such as example.com/page (the host then checks that it parses). aux: the text's |
| 646 | note length in bytes as written |
| 647 | fn weba b view uchar 1048576 n ulong aux ulong to ulong |
| 648 | if eq n 0 |
| 649 | ret 0 |
| 650 | end |
| 651 | if ge aux 2000 |
| 652 | ret 0 |
| 653 | end |
| 654 | for i ulong n |
| 655 | if ne and cfl b i 4 0 |
| 656 | ret 0 |
| 657 | end |
| 658 | end |
| 659 | if hasscheme b n |
| 660 | ret 1 |
| 661 | end |
| 662 | h0 = ulong 0 |
| 663 | while lt h0 n bound 999999 |
| 664 | if ne cid b h0 47 |
| 665 | break |
| 666 | end |
| 667 | h0 = add h0 1 |
| 668 | end |
| 669 | h1 = h0 |
| 670 | while lt h1 n bound 999999 |
| 671 | if eq cid b h1 47 |
| 672 | break |
| 673 | end |
| 674 | h1 = add h1 1 |
| 675 | end |
| 676 | parts = ulong 0 |
| 677 | ps = h0 |
| 678 | i = h0 |
| 679 | while le i h1 bound 999999 |
| 680 | atend = eq i h1 |
| 681 | dot = false |
| 682 | if not atend |
| 683 | dot = eq cid b i 46 |
| 684 | end |
| 685 | if or atend dot |
| 686 | if eq i ps |
| 687 | ret 0 |
| 688 | end |
| 689 | parts = add parts 1 |
| 690 | if atend |
| 691 | if lt parts 2 |
| 692 | ret 0 |
| 693 | end |
| 694 | if inlist b ps sub i ps 2 |
| 695 | ret 2 |
| 696 | end |
| 697 | ret 0 |
| 698 | end |
| 699 | ps = add i 1 |
| 700 | else |
| 701 | if eq and cfl b i 1 0 |
| 702 | if ne cid b i 45 |
| 703 | ret 0 |
| 704 | end |
| 705 | end |
| 706 | end |
| 707 | i = add i 1 |
| 708 | end |
| 709 | ret 0 |
| 710 | end |
| 711 | |
| 712 | note the single-character edits that turn one spelling into another, on letters and numbers only. r: 0 and 1 the |
| 713 | note first spelling's characters [from, to), 2 and 3 the second's. Writes 4 the edits and 5 the longer length. |
| 714 | note Returns 1, and writes nothing, when a spelling has more than 4096 letters and numbers |
| 715 | fn edist b view uchar 1048576 r edit ulong 8 to ulong |
| 716 | xa = new ulong 4096 0 |
| 717 | ya = new ulong 4096 0 |
| 718 | row = new ulong 4097 0 |
| 719 | xc = ulong 0 |
| 720 | yc = ulong 0 |
| 721 | i = get r 0 |
| 722 | x1 = get r 1 |
| 723 | while lt i x1 bound 999999 |
| 724 | if ne and cfl b i 1 0 |
| 725 | if ge xc 4096 |
| 726 | ret 1 |
| 727 | end |
| 728 | put xa xc cid b i |
| 729 | xc = add xc 1 |
| 730 | end |
| 731 | i = add i 1 |
| 732 | end |
| 733 | i = get r 2 |
| 734 | y1 = get r 3 |
| 735 | while lt i y1 bound 999999 |
| 736 | if ne and cfl b i 1 0 |
| 737 | if ge yc 4096 |
| 738 | ret 1 |
| 739 | end |
| 740 | put ya yc cid b i |
| 741 | yc = add yc 1 |
| 742 | end |
| 743 | i = add i 1 |
| 744 | end |
| 745 | for j ulong add yc 1 |
| 746 | put row j j |
| 747 | end |
| 748 | for k ulong xc |
| 749 | prev = get row 0 |
| 750 | put row 0 add k 1 |
| 751 | xi = get xa k |
| 752 | for j ulong yc |
| 753 | cur = get row add j 1 |
| 754 | v = add cur 1 |
| 755 | w = add get row j 1 |
| 756 | if lt w v |
| 757 | v = w |
| 758 | end |
| 759 | w = prev |
| 760 | if ne xi get ya j |
| 761 | w = add prev 1 |
| 762 | end |
| 763 | if lt w v |
| 764 | v = w |
| 765 | end |
| 766 | put row add j 1 v |
| 767 | prev = cur |
| 768 | end |
| 769 | end |
| 770 | m = xc |
| 771 | if gt yc m |
| 772 | m = yc |
| 773 | end |
| 774 | put r 4 get row yc |
| 775 | put r 5 m |
| 776 | ret 0 |
| 777 | end |
| 778 | |
| 779 | note op 4: how alike two spellings are. The text is the first spelling (aux characters), then the second. Writes |
| 780 | note the edits and the longer length, each as a 16-bit number; the host divides |
| 781 | fn alike b view uchar 1048576 n ulong aux ulong ob edit uchar 65544 to ulong |
| 782 | r = new ulong 8 0 |
| 783 | bad = ulong 18446744073709551615 |
| 784 | if gt aux n |
| 785 | ret bad |
| 786 | end |
| 787 | put r 0 0 |
| 788 | put r 1 aux |
| 789 | put r 2 aux |
| 790 | put r 3 n |
| 791 | if ne edist b r 0 |
| 792 | ret bad |
| 793 | end |
| 794 | d = get r 4 |
| 795 | m = get r 5 |
| 796 | put ob 8 uchar and d 255 |
| 797 | put ob 9 uchar shr d 8 |
| 798 | put ob 10 uchar and m 255 |
| 799 | put ob 11 uchar shr m 8 |
| 800 | ret 4 |
| 801 | end |
| 802 | |
| 803 | note op 5: which run of typed words is the fix for what was heard. The text is what was heard (aux characters), |
| 804 | note then up to four runs: the first typed word, the first two, the first three, the first four; flag 16 marks the |
| 805 | note last character of each run. Each run is compared with what was heard (fn edist); the most alike wins, the |
| 806 | note shorter run among equals. Returns which run (1 to 4), or 0 for no fix: the winner is less than half alike, or |
| 807 | note is the very text that was heard (the host says which runs are: bit k-1 of sm). 255: a spelling is too long |
| 808 | fn pick b view uchar 1048576 n ulong aux ulong sm ulong to ulong |
| 809 | r = new ulong 8 0 |
| 810 | if gt aux n |
| 811 | ret 255 |
| 812 | end |
| 813 | bk = ulong 0 |
| 814 | bn = ulong 0 |
| 815 | bd = ulong 1 |
| 816 | k = ulong 0 |
| 817 | i = aux |
| 818 | while lt i n bound 999999 |
| 819 | e = i |
| 820 | while lt e n bound 999999 |
| 821 | f = cfl b e |
| 822 | e = add e 1 |
| 823 | if ne and f 16 0 |
| 824 | break |
| 825 | end |
| 826 | end |
| 827 | k = add k 1 |
| 828 | if gt k 4 |
| 829 | break |
| 830 | end |
| 831 | put r 0 0 |
| 832 | put r 1 aux |
| 833 | put r 2 i |
| 834 | put r 3 e |
| 835 | if ne edist b r 0 |
| 836 | ret 255 |
| 837 | end |
| 838 | m = get r 5 |
| 839 | nu = ulong 1 |
| 840 | de = ulong 1 |
| 841 | if gt m 0 |
| 842 | nu = sub m get r 4 |
| 843 | de = m |
| 844 | end |
| 845 | if eq bk 0 |
| 846 | bk = k |
| 847 | bn = nu |
| 848 | bd = de |
| 849 | else |
| 850 | if gt mul nu bd mul bn de |
| 851 | bk = k |
| 852 | bn = nu |
| 853 | bd = de |
| 854 | end |
| 855 | end |
| 856 | i = e |
| 857 | end |
| 858 | if eq bk 0 |
| 859 | ret 0 |
| 860 | end |
| 861 | if lt mul bn 2 bd |
| 862 | ret 0 |
| 863 | end |
| 864 | if ne and shr sm sub bk 1 1 0 |
| 865 | ret 0 |
| 866 | end |
| 867 | ret bk |
| 868 | end |
| 869 | |
| 870 | note kind 3: op, the number of characters n (at most 16384), aux and 0 as four 32-bit numbers, then n character |
| 871 | note words. Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op |
| 872 | fn texts ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 873 | bad = ulong 18446744073709551615 |
| 874 | if lt nb 16 |
| 875 | ret bad |
| 876 | end |
| 877 | op = rd32 ib 0 |
| 878 | n = rd32 ib 4 |
| 879 | aux = rd32 ib 8 |
| 880 | if gt n 16384 |
| 881 | ret bad |
| 882 | end |
| 883 | if ne nb add 16 mul n 8 |
| 884 | ret bad |
| 885 | end |
| 886 | if eq op 1 |
| 887 | put ob 8 uchar qlike ib n |
| 888 | ret 1 |
| 889 | end |
| 890 | if eq op 2 |
| 891 | ret keyw ib n ob |
| 892 | end |
| 893 | if eq op 3 |
| 894 | put ob 8 uchar weba ib n aux |
| 895 | ret 1 |
| 896 | end |
| 897 | if eq op 4 |
| 898 | ret alike ib n aux ob |
| 899 | end |
| 900 | if eq op 5 |
| 901 | put ob 8 uchar pick ib n aux rd32 ib 12 |
| 902 | ret 1 |
| 903 | end |
| 904 | ret bad |
| 905 | end |
| 906 | |
| 907 | note ---- the helper process ---- |
| 908 | note hopcore main: Hop's core as a helper process. A request is 8 bytes (kind, then body length n, both 32-bit |
| 909 | note little-endian) and n body bytes, n at most 1048576. The reply is 8 bytes (status, then length m) and m bytes. |
| 910 | note Status 0 is an answer; 1 an unknown kind; 2 a malformed body. End of input ends it with status 0; a body |
| 911 | note over the limit or a short read ends it with status 3 (the host starts a fresh one). |
| 912 | note Kind 1, names: the body is k cases of 2048 bytes (256 words, the hopfuzz input); 3 bytes back per case: |
| 913 | note verdict, score low byte, score high byte. At most 512 cases. |
| 914 | note Kind 2, paths: 16-bit little-endian fields: number of terms (at most 64), number of paths (at most 16000); |
| 915 | note each term as length then bytes; each path as three lengths (its lowercased bytes, its name's lowercased |
| 916 | note bytes, the path as written), then the path bytes, then the name bytes. 4 bytes back per path: 0 for no |
| 917 | note match, else the score plus 1000000. |
| 918 | note Kind 3, text: see fn texts. Op 1 and op 3 answer one byte; op 2 a count, then two 16-bit numbers a word; |
| 919 | note op 4 two 16-bit numbers; op 5 one byte. |
| 920 | note Kind 4, corrected words: see fn wdiff. Kind 5, a board line or a time: see fn board. Kind 6, a whole board: see fn asm. Kind 7, the members' state and the graph: see fn status. |
| 921 | |
| 922 | note fill b[0 .. n) from stdin; false at end of input or on a short read |
| 923 | fn rdn b edit uchar 1048576 n ulong to bool |
| 924 | got = ulong 0 |
| 925 | while lt got n bound 999999 |
| 926 | k = read 0 b got sub n got |
| 927 | if le k 0 |
| 928 | ret false |
| 929 | end |
| 930 | got = add got ulong k |
| 931 | end |
| 932 | ret true |
| 933 | end |
| 934 | |
| 935 | fn wrn b view uchar 65544 n ulong to bool |
| 936 | p = ulong 0 |
| 937 | while lt p n bound 999999 |
| 938 | k = write 1 b p sub n p |
| 939 | if le k 0 |
| 940 | ret false |
| 941 | end |
| 942 | p = add p ulong k |
| 943 | end |
| 944 | ret true |
| 945 | end |
| 946 | |
| 947 | fn put32 b edit uchar 65544 o ulong v ulong to void |
| 948 | put b o uchar and v 255 |
| 949 | put b add o 1 uchar and shr v 8 255 |
| 950 | put b add o 2 uchar and shr v 16 255 |
| 951 | put b add o 3 uchar and shr v 24 255 |
| 952 | end |
| 953 | |
| 954 | note kind 1: returns the reply length, or 18446744073709551615 for a malformed body |
| 955 | note ---- one line of a plain-text board (kind 5) ---- |
| 956 | note A swarm's board is a text file, one post a line: |
| 957 | note <time> <sender> (<detail>) to <recipient> + <recipient> (<detail>): <text> |
| 958 | note Also read: several senders joined by " + ", no "to" part, recipients written "@name", a leading "- ", and |
| 959 | note words between the sender's bracket and the colon (they stay in the text). A line that does not start with a |
| 960 | note time is not a post. A header that does not fit the form is read plainly: the first word is the sender, the |
| 961 | note rest is the text. The answer names every part by where it starts in the line and how long it is. |
| 962 | note Limits: 65536 bytes of line, 600 of header, 4 senders, 16 recipients, 64 bytes and 3 words a name, 32768 bytes |
| 963 | note of text; over a limit the part is cut at a whole character and the answer says so. |
| 964 | |
| 965 | note byte i of the line (the line follows the 8-byte op header of the request) |
| 966 | fn lc b view uchar 1048576 i ulong to ulong |
| 967 | ret ulong get b add 8 i |
| 968 | end |
| 969 | |
| 970 | fn lsp c ulong to bool |
| 971 | ret or eq c 32 eq c 9 |
| 972 | end |
| 973 | |
| 974 | note the two digits at byte i of the n-byte line as a number, or 100 |
| 975 | fn l2d b view uchar 1048576 i ulong n ulong to ulong |
| 976 | if ge add i 1 n |
| 977 | ret 100 |
| 978 | end |
| 979 | x = lc b i |
| 980 | y = lc b add i 1 |
| 981 | if or lt x 48 gt x 57 |
| 982 | ret 100 |
| 983 | end |
| 984 | if or lt y 48 gt y 57 |
| 985 | ret 100 |
| 986 | end |
| 987 | ret add mul sub x 48 10 sub y 48 |
| 988 | end |
| 989 | |
| 990 | note out[k], out[k+1]: the bytes lo..hi without spaces at either end (equal when nothing is left) |
| 991 | fn ltrim b view uchar 1048576 lo ulong hi ulong outv edit ulong 8 k ulong to void |
| 992 | a = lo |
| 993 | e = hi |
| 994 | while lt a e bound 999999 |
| 995 | if not lsp lc b a |
| 996 | break |
| 997 | end |
| 998 | a = add a 1 |
| 999 | end |
| 1000 | while gt e a bound 999999 |
| 1001 | if not lsp lc b sub e 1 |
| 1002 | break |
| 1003 | end |
| 1004 | e = sub e 1 |
| 1005 | end |
| 1006 | put outv k a |
| 1007 | put outv add k 1 e |
| 1008 | end |
| 1009 | |
| 1010 | note where a text of bytes a..e is cut to lim bytes without splitting a character (e when it is short enough) |
| 1011 | fn lclip b view uchar 1048576 a ulong e ulong lim ulong to ulong |
| 1012 | if le sub e a lim |
| 1013 | ret e |
| 1014 | end |
| 1015 | ce = add a lim |
| 1016 | back = ulong 0 |
| 1017 | while gt ce a bound 8 |
| 1018 | if ge back 3 |
| 1019 | break |
| 1020 | end |
| 1021 | if ne and lc b ce 192 128 |
| 1022 | break |
| 1023 | end |
| 1024 | ce = sub ce 1 |
| 1025 | back = add back 1 |
| 1026 | end |
| 1027 | ret ce |
| 1028 | end |
| 1029 | |
| 1030 | note "YYYY-MM-DD", then optionally "T" or one space and "HH:MM" or "HH:MM:SS", a fraction, and "Z" or an offset |
| 1031 | note such as "+00:00", from byte s of the n-byte line. Returns 1 when it is a time, from 1970 on. tm: 1 the |
| 1032 | note seconds since 1970 as written (less the offset when one is named) plus 100000, 2 the first byte after the |
| 1033 | note time, 3 1 when the text names its zone |
| 1034 | fn ltime b view uchar 1048576 s ulong n ulong tm edit ulong 16 to ulong |
| 1035 | if gt add s 10 n |
| 1036 | ret 0 |
| 1037 | end |
| 1038 | ce = l2d b s n |
| 1039 | yy = l2d b add s 2 n |
| 1040 | mo = l2d b add s 5 n |
| 1041 | dy = l2d b add s 8 n |
| 1042 | if or eq ce 100 eq yy 100 |
| 1043 | ret 0 |
| 1044 | end |
| 1045 | if or or lt mo 1 gt mo 12 or lt dy 1 gt dy 31 |
| 1046 | ret 0 |
| 1047 | end |
| 1048 | if or ne lc b add s 4 45 ne lc b add s 7 45 |
| 1049 | ret 0 |
| 1050 | end |
| 1051 | yr = add mul ce 100 yy |
| 1052 | if lt yr 1970 |
| 1053 | ret 0 |
| 1054 | end |
| 1055 | p = add s 10 |
| 1056 | sec = ulong 0 |
| 1057 | off = ulong 0 |
| 1058 | pls = ulong 0 |
| 1059 | zoned = ulong 0 |
| 1060 | tp = ulong 0 |
| 1061 | if lt add p 5 n |
| 1062 | tp = lc b p |
| 1063 | end |
| 1064 | if or eq tp 84 eq tp 32 |
| 1065 | hr = l2d b add p 1 n |
| 1066 | mi = l2d b add p 4 n |
| 1067 | okhm = false |
| 1068 | if and lt hr 24 lt mi 60 |
| 1069 | if eq lc b add p 3 58 |
| 1070 | okhm = true |
| 1071 | end |
| 1072 | end |
| 1073 | if okhm |
| 1074 | sec = add mul hr 3600 mul mi 60 |
| 1075 | p = add p 6 |
| 1076 | if lt p n |
| 1077 | if eq lc b p 58 |
| 1078 | sx = l2d b add p 1 n |
| 1079 | if lt sx 61 |
| 1080 | sec = add sec sx |
| 1081 | p = add p 3 |
| 1082 | end |
| 1083 | end |
| 1084 | end |
| 1085 | if lt p n |
| 1086 | if eq lc b p 46 |
| 1087 | q = add p 1 |
| 1088 | while lt q n bound 32 |
| 1089 | if gt sub q p 9 |
| 1090 | break |
| 1091 | end |
| 1092 | c = lc b q |
| 1093 | if or lt c 48 gt c 57 |
| 1094 | break |
| 1095 | end |
| 1096 | q = add q 1 |
| 1097 | end |
| 1098 | if gt q add p 1 |
| 1099 | p = q |
| 1100 | end |
| 1101 | end |
| 1102 | end |
| 1103 | if lt p n |
| 1104 | zc = lc b p |
| 1105 | if or eq zc 90 eq zc 122 |
| 1106 | zoned = 1 |
| 1107 | p = add p 1 |
| 1108 | else |
| 1109 | if or eq zc 43 eq zc 45 |
| 1110 | oh = l2d b add p 1 n |
| 1111 | om = ulong 100 |
| 1112 | used = ulong 5 |
| 1113 | c3 = false |
| 1114 | if lt add p 3 n |
| 1115 | if eq lc b add p 3 58 |
| 1116 | c3 = true |
| 1117 | end |
| 1118 | end |
| 1119 | if c3 |
| 1120 | om = l2d b add p 4 n |
| 1121 | used = 6 |
| 1122 | else |
| 1123 | om = l2d b add p 3 n |
| 1124 | end |
| 1125 | if and lt oh 24 lt om 60 |
| 1126 | o = add mul oh 3600 mul om 60 |
| 1127 | if eq zc 43 |
| 1128 | off = o |
| 1129 | else |
| 1130 | pls = o |
| 1131 | end |
| 1132 | zoned = 1 |
| 1133 | p = add p used |
| 1134 | end |
| 1135 | end |
| 1136 | end |
| 1137 | end |
| 1138 | else |
| 1139 | if eq tp 84 |
| 1140 | ret 0 |
| 1141 | end |
| 1142 | end |
| 1143 | else |
| 1144 | if lt p n |
| 1145 | if eq lc b p 84 |
| 1146 | ret 0 |
| 1147 | end |
| 1148 | end |
| 1149 | end |
| 1150 | y = yr |
| 1151 | if le mo 2 |
| 1152 | y = sub yr 1 |
| 1153 | end |
| 1154 | era = div y 400 |
| 1155 | yoe = sub y mul era 400 |
| 1156 | mm = add mo 9 |
| 1157 | if gt mo 2 |
| 1158 | mm = sub mo 3 |
| 1159 | end |
| 1160 | doy = sub add div add mul 153 mm 2 5 dy 1 |
| 1161 | doe = add sub add mul yoe 365 div yoe 4 div yoe 100 doy |
| 1162 | days = sub add mul era 146097 doe 719468 |
| 1163 | put tm 1 sub add add add mul days 86400 sec 100000 pls off |
| 1164 | put tm 2 p |
| 1165 | put tm 3 zoned |
| 1166 | ret 1 |
| 1167 | end |
| 1168 | |
| 1169 | note one name from byte lo, stopping before " + ", before "(" and, on the sender side (side 1), before " to " |
| 1170 | note and " @". A bracket right after the name is its detail. nr: 0 and 1 the name, 2 and 3 the detail, 4 the first |
| 1171 | note byte after the name, its bracket and the spaces that follow, 5 1 when there was a bracket |
| 1172 | fn lname b view uchar 1048576 lo ulong limit ulong side ulong nr edit ulong 8 to void |
| 1173 | i = lo |
| 1174 | while lt i limit bound 999999 |
| 1175 | if not lsp lc b i |
| 1176 | break |
| 1177 | end |
| 1178 | i = add i 1 |
| 1179 | end |
| 1180 | start = i |
| 1181 | while lt i limit bound 999999 |
| 1182 | c = lc b i |
| 1183 | if eq c 40 |
| 1184 | break |
| 1185 | end |
| 1186 | stop = false |
| 1187 | if eq c 32 |
| 1188 | if lt add i 1 limit |
| 1189 | d = lc b add i 1 |
| 1190 | if eq d 43 |
| 1191 | if ge add i 2 limit |
| 1192 | stop = true |
| 1193 | else |
| 1194 | if eq lc b add i 2 32 |
| 1195 | stop = true |
| 1196 | end |
| 1197 | end |
| 1198 | end |
| 1199 | if eq side 1 |
| 1200 | if eq d 64 |
| 1201 | stop = true |
| 1202 | end |
| 1203 | if eq d 116 |
| 1204 | if lt add i 2 limit |
| 1205 | if eq lc b add i 2 111 |
| 1206 | if ge add i 3 limit |
| 1207 | stop = true |
| 1208 | else |
| 1209 | if eq lc b add i 3 32 |
| 1210 | stop = true |
| 1211 | end |
| 1212 | end |
| 1213 | end |
| 1214 | end |
| 1215 | end |
| 1216 | end |
| 1217 | end |
| 1218 | end |
| 1219 | if stop |
| 1220 | break |
| 1221 | end |
| 1222 | i = add i 1 |
| 1223 | end |
| 1224 | ltrim b start i nr 0 |
| 1225 | while lt i limit bound 999999 |
| 1226 | if not lsp lc b i |
| 1227 | break |
| 1228 | end |
| 1229 | i = add i 1 |
| 1230 | end |
| 1231 | put nr 2 0 |
| 1232 | put nr 3 0 |
| 1233 | put nr 5 0 |
| 1234 | if lt i limit |
| 1235 | if eq lc b i 40 |
| 1236 | depth = ulong 0 |
| 1237 | j = i |
| 1238 | while lt j limit bound 999999 |
| 1239 | cj = lc b j |
| 1240 | if eq cj 40 |
| 1241 | depth = add depth 1 |
| 1242 | else |
| 1243 | if eq cj 41 |
| 1244 | depth = sub depth 1 |
| 1245 | if eq depth 0 |
| 1246 | break |
| 1247 | end |
| 1248 | end |
| 1249 | end |
| 1250 | j = add j 1 |
| 1251 | end |
| 1252 | ltrim b add i 1 j nr 2 |
| 1253 | put nr 5 1 |
| 1254 | i = limit |
| 1255 | if lt j limit |
| 1256 | i = add j 1 |
| 1257 | end |
| 1258 | while lt i limit bound 999999 |
| 1259 | if not lsp lc b i |
| 1260 | break |
| 1261 | end |
| 1262 | i = add i 1 |
| 1263 | end |
| 1264 | end |
| 1265 | end |
| 1266 | put nr 4 i |
| 1267 | end |
| 1268 | |
| 1269 | note a name fits when it has 1 to 64 bytes and at most 3 words |
| 1270 | fn lfits b view uchar 1048576 a ulong e ulong to bool |
| 1271 | if le e a |
| 1272 | ret false |
| 1273 | end |
| 1274 | if gt sub e a 64 |
| 1275 | ret false |
| 1276 | end |
| 1277 | n = ulong 0 |
| 1278 | inw = false |
| 1279 | i = a |
| 1280 | while lt i e bound 999999 |
| 1281 | if lsp lc b i |
| 1282 | inw = false |
| 1283 | else |
| 1284 | if not inw |
| 1285 | inw = true |
| 1286 | n = add n 1 |
| 1287 | end |
| 1288 | end |
| 1289 | i = add i 1 |
| 1290 | end |
| 1291 | ret le n 3 |
| 1292 | end |
| 1293 | |
| 1294 | note "all", "all lanes", "everyone" (any case, a leading "@" dropped): the whole board, not one member. |
| 1295 | note The name fits (lfits), so its key has at most 64 bytes |
| 1296 | fn levery b view uchar 1048576 a ulong e ulong to bool |
| 1297 | k = new uchar 80 0 |
| 1298 | n = ulong 0 |
| 1299 | i = a |
| 1300 | if lt i e |
| 1301 | if eq lc b i 64 |
| 1302 | i = add i 1 |
| 1303 | end |
| 1304 | end |
| 1305 | gap = false |
| 1306 | while lt i e bound 999999 |
| 1307 | c = lc b i |
| 1308 | if lsp c |
| 1309 | gap = true |
| 1310 | else |
| 1311 | if and gap gt n 0 |
| 1312 | put k n uchar 45 |
| 1313 | n = add n 1 |
| 1314 | end |
| 1315 | gap = false |
| 1316 | if and ge c 65 le c 90 |
| 1317 | c = add c 32 |
| 1318 | end |
| 1319 | put k n uchar c |
| 1320 | n = add n 1 |
| 1321 | end |
| 1322 | i = add i 1 |
| 1323 | end |
| 1324 | if lt n 3 |
| 1325 | ret false |
| 1326 | end |
| 1327 | al = and and eq ulong get k 0 97 eq ulong get k 1 108 eq ulong get k 2 108 |
| 1328 | if eq n 3 |
| 1329 | ret al |
| 1330 | end |
| 1331 | if gt n 4 |
| 1332 | if and al eq ulong get k 3 45 |
| 1333 | ret true |
| 1334 | end |
| 1335 | end |
| 1336 | if ne n 8 |
| 1337 | ret false |
| 1338 | end |
| 1339 | ev = and and eq ulong get k 0 101 eq ulong get k 1 118 and eq ulong get k 2 101 eq ulong get k 3 114 |
| 1340 | ev = and ev and and eq ulong get k 4 121 eq ulong get k 5 111 and eq ulong get k 6 110 eq ulong get k 7 101 |
| 1341 | ret ev |
| 1342 | end |
| 1343 | |
| 1344 | note where a part starts and how long it is, at byte o of the answer |
| 1345 | fn lput ob edit uchar 65544 o ulong s ulong e ulong to void |
| 1346 | l = ulong 0 |
| 1347 | if gt e s |
| 1348 | l = sub e s |
| 1349 | end |
| 1350 | put32 ob add 8 o s |
| 1351 | put32 ob add 12 o l |
| 1352 | end |
| 1353 | |
| 1354 | note op 1: one board line of n0 bytes. The answer is 344 bytes: 0 1 when it is a post, 1 1 when it is to all, |
| 1355 | note 2 1 when something went over a limit, 3 the senders, 4 the recipients; 8 the time (64-bit, seconds since 1970 |
| 1356 | note plus 100000); 16 the text; from 24 sixteen bytes a sender (name, detail), from 88 sixteen a recipient. Each |
| 1357 | note part is two 32-bit numbers: where it starts in the line and its length |
| 1358 | fn lline b view uchar 1048576 n0 ulong ob edit uchar 65544 to ulong |
| 1359 | tm = new ulong 16 0 |
| 1360 | nr = new ulong 8 0 |
| 1361 | for z ulong 344 |
| 1362 | put ob add 8 z uchar 0 |
| 1363 | end |
| 1364 | n = n0 |
| 1365 | clipped = ulong 0 |
| 1366 | if gt n 65536 |
| 1367 | n = lclip b 0 n 65536 |
| 1368 | clipped = 1 |
| 1369 | end |
| 1370 | put ob 10 uchar clipped |
| 1371 | en = n |
| 1372 | while gt en 0 bound 999999 |
| 1373 | c = lc b sub en 1 |
| 1374 | blank = lsp c |
| 1375 | if or eq c 13 eq c 10 |
| 1376 | blank = true |
| 1377 | end |
| 1378 | if not blank |
| 1379 | break |
| 1380 | end |
| 1381 | en = sub en 1 |
| 1382 | end |
| 1383 | p = ulong 0 |
| 1384 | while lt p en bound 999999 |
| 1385 | if not lsp lc b p |
| 1386 | break |
| 1387 | end |
| 1388 | p = add p 1 |
| 1389 | end |
| 1390 | if lt add p 1 en |
| 1391 | if and eq lc b p 45 eq lc b add p 1 32 |
| 1392 | p = add p 2 |
| 1393 | end |
| 1394 | end |
| 1395 | if eq ltime b p n tm 0 |
| 1396 | ret 344 |
| 1397 | end |
| 1398 | te = get tm 2 |
| 1399 | if ge te en |
| 1400 | ret 344 |
| 1401 | end |
| 1402 | if not lsp lc b te |
| 1403 | ret 344 |
| 1404 | end |
| 1405 | p = te |
| 1406 | while lt p en bound 999999 |
| 1407 | if not lsp lc b p |
| 1408 | break |
| 1409 | end |
| 1410 | p = add p 1 |
| 1411 | end |
| 1412 | if ge p en |
| 1413 | ret 344 |
| 1414 | end |
| 1415 | put ob 8 uchar 1 |
| 1416 | tv = get tm 1 |
| 1417 | put32 ob 16 tv |
| 1418 | put32 ob 20 shr tv 32 |
| 1419 | bst = p |
| 1420 | colon = ulong 0 |
| 1421 | hasc = false |
| 1422 | depth = ulong 0 |
| 1423 | i = p |
| 1424 | while lt i en bound 999999 |
| 1425 | if ge sub i p 600 |
| 1426 | break |
| 1427 | end |
| 1428 | c = lc b i |
| 1429 | if eq c 40 |
| 1430 | depth = add depth 1 |
| 1431 | else |
| 1432 | if eq c 41 |
| 1433 | if gt depth 0 |
| 1434 | depth = sub depth 1 |
| 1435 | end |
| 1436 | else |
| 1437 | if and eq c 58 eq depth 0 |
| 1438 | nx = true |
| 1439 | if lt add i 1 en |
| 1440 | if ne lc b add i 1 32 |
| 1441 | nx = false |
| 1442 | end |
| 1443 | end |
| 1444 | if nx |
| 1445 | colon = i |
| 1446 | hasc = true |
| 1447 | break |
| 1448 | end |
| 1449 | end |
| 1450 | end |
| 1451 | end |
| 1452 | i = add i 1 |
| 1453 | end |
| 1454 | fits = hasc |
| 1455 | ts = add colon 1 |
| 1456 | q = p |
| 1457 | md = ulong 0 |
| 1458 | ns = ulong 0 |
| 1459 | nrc = ulong 0 |
| 1460 | tall = ulong 0 |
| 1461 | rnd = ulong 0 |
| 1462 | while and and fits eq md 0 lt rnd 64 bound 100 |
| 1463 | rnd = add rnd 1 |
| 1464 | lname b q colon 1 nr |
| 1465 | if not lfits b get nr 0 get nr 1 |
| 1466 | fits = false |
| 1467 | break |
| 1468 | end |
| 1469 | if lt ns 3 |
| 1470 | lput ob add 24 mul ns 16 get nr 0 get nr 1 |
| 1471 | lput ob add 32 mul ns 16 get nr 2 get nr 3 |
| 1472 | ns = add ns 1 |
| 1473 | else |
| 1474 | clipped = 1 |
| 1475 | end |
| 1476 | x = get nr 4 |
| 1477 | if ge x colon |
| 1478 | md = 3 |
| 1479 | else |
| 1480 | cx = lc b x |
| 1481 | did = false |
| 1482 | if eq cx 43 |
| 1483 | sp = true |
| 1484 | if lt add x 1 colon |
| 1485 | if ne lc b add x 1 32 |
| 1486 | sp = false |
| 1487 | end |
| 1488 | end |
| 1489 | if sp |
| 1490 | q = add x 1 |
| 1491 | did = true |
| 1492 | end |
| 1493 | end |
| 1494 | if not did |
| 1495 | if eq cx 116 |
| 1496 | if lt add x 2 colon |
| 1497 | if and eq lc b add x 1 111 eq lc b add x 2 32 |
| 1498 | md = 1 |
| 1499 | q = add x 3 |
| 1500 | did = true |
| 1501 | end |
| 1502 | end |
| 1503 | end |
| 1504 | end |
| 1505 | if not did |
| 1506 | if eq cx 64 |
| 1507 | md = 2 |
| 1508 | q = x |
| 1509 | did = true |
| 1510 | end |
| 1511 | end |
| 1512 | if not did |
| 1513 | if eq get nr 5 1 |
| 1514 | md = 3 |
| 1515 | ts = x |
| 1516 | else |
| 1517 | fits = false |
| 1518 | end |
| 1519 | end |
| 1520 | end |
| 1521 | end |
| 1522 | if and fits eq md 0 |
| 1523 | fits = false |
| 1524 | end |
| 1525 | rnd = 0 |
| 1526 | while and and fits eq md 1 lt rnd 64 bound 100 |
| 1527 | rnd = add rnd 1 |
| 1528 | lname b q colon 0 nr |
| 1529 | a = get nr 0 |
| 1530 | e = get nr 1 |
| 1531 | if gt e a |
| 1532 | if eq lc b a 64 |
| 1533 | a = add a 1 |
| 1534 | end |
| 1535 | end |
| 1536 | if not lfits b a e |
| 1537 | fits = false |
| 1538 | break |
| 1539 | end |
| 1540 | if levery b a e |
| 1541 | tall = 1 |
| 1542 | else |
| 1543 | if lt nrc 16 |
| 1544 | lput ob add 88 mul nrc 16 a e |
| 1545 | lput ob add 96 mul nrc 16 get nr 2 get nr 3 |
| 1546 | nrc = add nrc 1 |
| 1547 | else |
| 1548 | clipped = 1 |
| 1549 | end |
| 1550 | end |
| 1551 | x = get nr 4 |
| 1552 | if ge x colon |
| 1553 | md = 3 |
| 1554 | else |
| 1555 | plus = false |
| 1556 | if eq lc b x 43 |
| 1557 | plus = true |
| 1558 | if lt add x 1 colon |
| 1559 | if ne lc b add x 1 32 |
| 1560 | plus = false |
| 1561 | end |
| 1562 | end |
| 1563 | end |
| 1564 | if plus |
| 1565 | q = add x 1 |
| 1566 | else |
| 1567 | fits = false |
| 1568 | end |
| 1569 | end |
| 1570 | end |
| 1571 | if and fits eq md 1 |
| 1572 | fits = false |
| 1573 | end |
| 1574 | rnd = 0 |
| 1575 | while and and fits eq md 2 lt rnd 64 bound 100 |
| 1576 | rnd = add rnd 1 |
| 1577 | while lt q colon bound 999999 |
| 1578 | c = lc b q |
| 1579 | if not or lsp c eq c 43 |
| 1580 | break |
| 1581 | end |
| 1582 | q = add q 1 |
| 1583 | end |
| 1584 | if ge q colon |
| 1585 | md = 3 |
| 1586 | break |
| 1587 | end |
| 1588 | if ne lc b q 64 |
| 1589 | fits = false |
| 1590 | break |
| 1591 | end |
| 1592 | j = add q 1 |
| 1593 | while lt j colon bound 999999 |
| 1594 | if lsp lc b j |
| 1595 | break |
| 1596 | end |
| 1597 | j = add j 1 |
| 1598 | end |
| 1599 | ltrim b add q 1 j nr 0 |
| 1600 | a = get nr 0 |
| 1601 | e = get nr 1 |
| 1602 | if not lfits b a e |
| 1603 | fits = false |
| 1604 | break |
| 1605 | end |
| 1606 | if levery b a e |
| 1607 | tall = 1 |
| 1608 | else |
| 1609 | if lt nrc 16 |
| 1610 | lput ob add 88 mul nrc 16 a e |
| 1611 | nrc = add nrc 1 |
| 1612 | else |
| 1613 | clipped = 1 |
| 1614 | end |
| 1615 | end |
| 1616 | q = j |
| 1617 | end |
| 1618 | if and fits eq md 2 |
| 1619 | fits = false |
| 1620 | end |
| 1621 | if not fits |
| 1622 | for z ulong 320 |
| 1623 | put ob add 32 z uchar 0 |
| 1624 | end |
| 1625 | ns = 1 |
| 1626 | nrc = 0 |
| 1627 | tall = 0 |
| 1628 | j = bst |
| 1629 | while lt j en bound 999999 |
| 1630 | if lsp lc b j |
| 1631 | break |
| 1632 | end |
| 1633 | j = add j 1 |
| 1634 | end |
| 1635 | ltrim b bst j nr 0 |
| 1636 | a = get nr 0 |
| 1637 | e = get nr 1 |
| 1638 | if gt sub e a 1 |
| 1639 | if eq lc b sub e 1 58 |
| 1640 | e = sub e 1 |
| 1641 | end |
| 1642 | end |
| 1643 | if gt sub e a 64 |
| 1644 | e = lclip b a e 64 |
| 1645 | clipped = 1 |
| 1646 | end |
| 1647 | lput ob 24 a e |
| 1648 | ts = j |
| 1649 | end |
| 1650 | ltrim b ts en nr 0 |
| 1651 | a = get nr 0 |
| 1652 | e = get nr 1 |
| 1653 | if gt e a |
| 1654 | if gt sub e a 32768 |
| 1655 | e = lclip b a e 32768 |
| 1656 | clipped = 1 |
| 1657 | end |
| 1658 | end |
| 1659 | lput ob 16 a e |
| 1660 | put ob 9 uchar tall |
| 1661 | put ob 10 uchar clipped |
| 1662 | put ob 11 uchar ns |
| 1663 | put ob 12 uchar nrc |
| 1664 | ret 344 |
| 1665 | end |
| 1666 | |
| 1667 | note ---- who a post calls and which posts it cites (kind 5 op 3) ---- |
| 1668 | note "@name", "@all", "@#channel" and "#seq" in the text of a post. A mention counts only at a word start: the |
| 1669 | note character before "@" or "#" must not be a name character, and the name must not run on into more name |
| 1670 | note characters. Positions in these functions are places in the request: the text is the bytes t0..t1. |
| 1671 | |
| 1672 | note the character that starts at byte i, as a code point; 4294967295 at or after t1. A broken sequence gives its |
| 1673 | note first byte |
| 1674 | fn rune b view uchar 1048576 i ulong t1 ulong to ulong |
| 1675 | if ge i t1 |
| 1676 | ret 4294967295 |
| 1677 | end |
| 1678 | b0 = ulong get b i |
| 1679 | if or lt b0 128 ge b0 248 |
| 1680 | ret b0 |
| 1681 | end |
| 1682 | if lt b0 192 |
| 1683 | ret b0 |
| 1684 | end |
| 1685 | need = ulong 1 |
| 1686 | cp = and b0 31 |
| 1687 | if ge b0 224 |
| 1688 | need = 2 |
| 1689 | cp = and b0 15 |
| 1690 | end |
| 1691 | if ge b0 240 |
| 1692 | need = 3 |
| 1693 | cp = and b0 7 |
| 1694 | end |
| 1695 | k = ulong 1 |
| 1696 | while le k need bound 8 |
| 1697 | if ge add i k t1 |
| 1698 | ret b0 |
| 1699 | end |
| 1700 | c = ulong get b add i k |
| 1701 | if ne and c 192 128 |
| 1702 | ret b0 |
| 1703 | end |
| 1704 | cp = or shl cp 6 and c 63 |
| 1705 | k = add k 1 |
| 1706 | end |
| 1707 | ret cp |
| 1708 | end |
| 1709 | |
| 1710 | note the character that ends just before byte e; 4294967295 at the start of the text |
| 1711 | fn runeb b view uchar 1048576 e ulong t0 ulong t1 ulong to ulong |
| 1712 | if or le e t0 gt e t1 |
| 1713 | ret 4294967295 |
| 1714 | end |
| 1715 | i = sub e 1 |
| 1716 | back = ulong 0 |
| 1717 | while gt i t0 bound 8 |
| 1718 | if ge back 3 |
| 1719 | break |
| 1720 | end |
| 1721 | if ne and ulong get b i 192 128 |
| 1722 | break |
| 1723 | end |
| 1724 | i = sub i 1 |
| 1725 | back = add back 1 |
| 1726 | end |
| 1727 | ret rune b i t1 |
| 1728 | end |
| 1729 | |
| 1730 | note can this character be part of a name? Letters, digits, "_" and "-"; outside ASCII everything except the |
| 1731 | note blocks that hold punctuation, symbols and emoji |
| 1732 | fn namer cp ulong to bool |
| 1733 | if eq cp 4294967295 |
| 1734 | ret false |
| 1735 | end |
| 1736 | if lt cp 128 |
| 1737 | if and ge cp 48 le cp 57 |
| 1738 | ret true |
| 1739 | end |
| 1740 | if and ge cp 65 le cp 90 |
| 1741 | ret true |
| 1742 | end |
| 1743 | if and ge cp 97 le cp 122 |
| 1744 | ret true |
| 1745 | end |
| 1746 | ret or eq cp 95 eq cp 45 |
| 1747 | end |
| 1748 | if or or lt cp 192 eq cp 215 eq cp 247 |
| 1749 | ret false |
| 1750 | end |
| 1751 | if and ge cp 8192 le cp 11263 |
| 1752 | ret false |
| 1753 | end |
| 1754 | if and ge cp 12288 le cp 12351 |
| 1755 | ret false |
| 1756 | end |
| 1757 | if and ge cp 65072 le cp 65135 |
| 1758 | ret false |
| 1759 | end |
| 1760 | if or and ge cp 65280 le cp 65295 and ge cp 65306 le cp 65312 |
| 1761 | ret false |
| 1762 | end |
| 1763 | if or and ge cp 65339 le cp 65344 and ge cp 65371 le cp 65381 |
| 1764 | ret false |
| 1765 | end |
| 1766 | if and ge cp 126976 le cp 129791 |
| 1767 | ret false |
| 1768 | end |
| 1769 | ret true |
| 1770 | end |
| 1771 | |
| 1772 | fn lowc c ulong to ulong |
| 1773 | if and ge c 65 le c 90 |
| 1774 | ret add c 32 |
| 1775 | end |
| 1776 | ret c |
| 1777 | end |
| 1778 | |
| 1779 | note true when the ln bytes at na stand at byte pos of the text (ASCII letters without case) and no name |
| 1780 | note character follows them |
| 1781 | fn nameat b view uchar 1048576 pos ulong na ulong ln ulong t1 ulong to bool |
| 1782 | if eq ln 0 |
| 1783 | ret false |
| 1784 | end |
| 1785 | if gt add pos ln t1 |
| 1786 | ret false |
| 1787 | end |
| 1788 | for k ulong ln |
| 1789 | if ne lowc ulong get b add pos k lowc ulong get b add na k |
| 1790 | ret false |
| 1791 | end |
| 1792 | end |
| 1793 | ret not namer rune b add pos ln t1 |
| 1794 | end |
| 1795 | |
| 1796 | note "all" at byte pos, and no name character after it |
| 1797 | fn allat b view uchar 1048576 pos ulong t1 ulong to bool |
| 1798 | if gt add pos 3 t1 |
| 1799 | ret false |
| 1800 | end |
| 1801 | if ne lowc ulong get b pos 97 |
| 1802 | ret false |
| 1803 | end |
| 1804 | if ne lowc ulong get b add pos 1 108 |
| 1805 | ret false |
| 1806 | end |
| 1807 | if ne lowc ulong get b add pos 2 108 |
| 1808 | ret false |
| 1809 | end |
| 1810 | ret not namer rune b add pos 3 t1 |
| 1811 | end |
| 1812 | |
| 1813 | note a member called "<prefix>-<digits>" also answers to "@<prefix>": the length of that prefix, or 0 |
| 1814 | fn cprefix b view uchar 1048576 na ulong nl ulong to ulong |
| 1815 | i = nl |
| 1816 | while gt i 0 bound 999999 |
| 1817 | c = ulong get b add na sub i 1 |
| 1818 | if or lt c 48 gt c 57 |
| 1819 | break |
| 1820 | end |
| 1821 | i = sub i 1 |
| 1822 | end |
| 1823 | if eq i nl |
| 1824 | ret 0 |
| 1825 | end |
| 1826 | if lt i 2 |
| 1827 | ret 0 |
| 1828 | end |
| 1829 | if ne ulong get b add na sub i 1 45 |
| 1830 | ret 0 |
| 1831 | end |
| 1832 | ret sub i 1 |
| 1833 | end |
| 1834 | |
| 1835 | note the length of a channel name at byte pos (after "@#"): a letter, then letters, digits and "-", 24 at most |
| 1836 | fn chlen b view uchar 1048576 pos ulong t1 ulong to ulong |
| 1837 | if ge pos t1 |
| 1838 | ret 0 |
| 1839 | end |
| 1840 | f = lowc ulong get b pos |
| 1841 | if or lt f 97 gt f 122 |
| 1842 | ret 0 |
| 1843 | end |
| 1844 | j = pos |
| 1845 | while lt j t1 bound 64 |
| 1846 | if ge sub j pos 25 |
| 1847 | break |
| 1848 | end |
| 1849 | c = lowc ulong get b j |
| 1850 | okc = and ge c 97 le c 122 |
| 1851 | if and ge c 48 le c 57 |
| 1852 | okc = true |
| 1853 | end |
| 1854 | if eq c 45 |
| 1855 | okc = true |
| 1856 | end |
| 1857 | if not okc |
| 1858 | break |
| 1859 | end |
| 1860 | j = add j 1 |
| 1861 | end |
| 1862 | n = sub j pos |
| 1863 | if gt n 24 |
| 1864 | ret 0 |
| 1865 | end |
| 1866 | if namer rune b j t1 |
| 1867 | ret 0 |
| 1868 | end |
| 1869 | ret n |
| 1870 | end |
| 1871 | |
| 1872 | note part idx of the answer: where it starts in the text, its length, its kind (1 a member, 2 all, 3 a channel, |
| 1873 | note 4 a cited post) and its value (the member's number, or the post's) |
| 1874 | fn semit ob edit uchar 65544 idx ulong s ulong l ulong kind ulong v ulong to void |
| 1875 | o = add 16 mul idx 16 |
| 1876 | put32 ob o s |
| 1877 | put32 ob add o 4 l |
| 1878 | put32 ob add o 8 kind |
| 1879 | put32 ob add o 12 v |
| 1880 | end |
| 1881 | |
| 1882 | note op 3: n bytes after the op header: a 16-bit count of member names (96 at most), each name as a 16-bit length |
| 1883 | note and its bytes, then the text (900000 bytes at most). head is the highest post number that may be cited; 0 |
| 1884 | note turns citations off. The answer: a 16-bit count of parts, a byte that is 1 when the post has more than 128 |
| 1885 | note parts (the rest is not marked), then from byte 8 sixteen bytes a part (semit), in text order. Parts that |
| 1886 | note start at one byte are kept or dropped together |
| 1887 | fn spans b view uchar 1048576 n ulong head ulong ob edit uchar 65544 to ulong |
| 1888 | noff = new ulong 96 0 |
| 1889 | nlen = new ulong 96 0 |
| 1890 | npre = new ulong 96 0 |
| 1891 | bad = ulong 18446744073709551615 |
| 1892 | if lt n 2 |
| 1893 | ret bad |
| 1894 | end |
| 1895 | nn = rd16 b 8 |
| 1896 | if gt nn 96 |
| 1897 | ret bad |
| 1898 | end |
| 1899 | lim = add 8 n |
| 1900 | p = ulong 10 |
| 1901 | for k ulong nn |
| 1902 | if gt add p 2 lim |
| 1903 | ret bad |
| 1904 | end |
| 1905 | l = rd16 b p |
| 1906 | p = add p 2 |
| 1907 | if gt add p l lim |
| 1908 | ret bad |
| 1909 | end |
| 1910 | put noff k p |
| 1911 | put nlen k l |
| 1912 | put npre k cprefix b p l |
| 1913 | p = add p l |
| 1914 | end |
| 1915 | t0 = p |
| 1916 | t1 = lim |
| 1917 | if gt sub t1 t0 900000 |
| 1918 | ret bad |
| 1919 | end |
| 1920 | cnt = ulong 0 |
| 1921 | clipped = ulong 0 |
| 1922 | i = t0 |
| 1923 | while lt i t1 bound 999999 |
| 1924 | c = ulong get b i |
| 1925 | st = ulong 1 |
| 1926 | g = ulong 0 |
| 1927 | mark = or eq c 64 eq c 35 |
| 1928 | if mark |
| 1929 | if namer runeb b i t0 t1 |
| 1930 | mark = false |
| 1931 | end |
| 1932 | end |
| 1933 | if mark |
| 1934 | if eq c 64 |
| 1935 | nxt = ulong 0 |
| 1936 | if lt add i 1 t1 |
| 1937 | nxt = ulong get b add i 1 |
| 1938 | end |
| 1939 | if eq nxt 35 |
| 1940 | cl = chlen b add i 2 t1 |
| 1941 | if gt cl 0 |
| 1942 | semit ob cnt sub i t0 add cl 2 3 0 |
| 1943 | g = 1 |
| 1944 | st = add cl 2 |
| 1945 | end |
| 1946 | else |
| 1947 | for k ulong nn |
| 1948 | if nameat b add i 1 get noff k get nlen k t1 |
| 1949 | semit ob add cnt g sub i t0 add get nlen k 1 1 k |
| 1950 | g = add g 1 |
| 1951 | end |
| 1952 | end |
| 1953 | if eq g 0 |
| 1954 | if allat b add i 1 t1 |
| 1955 | semit ob add cnt g sub i t0 4 2 0 |
| 1956 | g = 1 |
| 1957 | end |
| 1958 | end |
| 1959 | k2 = ulong 0 |
| 1960 | while lt k2 nn bound 128 |
| 1961 | if gt g 0 |
| 1962 | break |
| 1963 | end |
| 1964 | pk = get npre k2 |
| 1965 | if gt pk 0 |
| 1966 | if nameat b add i 1 get noff k2 pk t1 |
| 1967 | j = k2 |
| 1968 | while lt j nn bound 128 |
| 1969 | if eq get npre j pk |
| 1970 | if nameat b add i 1 get noff j pk t1 |
| 1971 | semit ob add cnt g sub i t0 add pk 1 1 j |
| 1972 | g = add g 1 |
| 1973 | end |
| 1974 | end |
| 1975 | j = add j 1 |
| 1976 | end |
| 1977 | end |
| 1978 | end |
| 1979 | k2 = add k2 1 |
| 1980 | end |
| 1981 | end |
| 1982 | else |
| 1983 | if gt head 0 |
| 1984 | if ne runeb b i t0 t1 38 |
| 1985 | j = add i 1 |
| 1986 | v = ulong 0 |
| 1987 | while lt j t1 bound 16 |
| 1988 | if gt sub j i 9 |
| 1989 | break |
| 1990 | end |
| 1991 | d = ulong get b j |
| 1992 | if or lt d 48 gt d 57 |
| 1993 | break |
| 1994 | end |
| 1995 | v = add mul v 10 sub d 48 |
| 1996 | j = add j 1 |
| 1997 | end |
| 1998 | if gt j add i 1 |
| 1999 | if and ge v 1 le v head |
| 2000 | if not namer rune b j t1 |
| 2001 | semit ob cnt sub i t0 sub j i 4 v |
| 2002 | g = 1 |
| 2003 | st = sub j i |
| 2004 | end |
| 2005 | end |
| 2006 | end |
| 2007 | end |
| 2008 | end |
| 2009 | end |
| 2010 | end |
| 2011 | if gt g 0 |
| 2012 | if gt add cnt g 128 |
| 2013 | clipped = 1 |
| 2014 | break |
| 2015 | end |
| 2016 | cnt = add cnt g |
| 2017 | end |
| 2018 | i = add i st |
| 2019 | end |
| 2020 | put ob 8 uchar and cnt 255 |
| 2021 | put ob 9 uchar shr cnt 8 |
| 2022 | put ob 10 uchar clipped |
| 2023 | for z ulong 5 |
| 2024 | put ob add 11 z uchar 0 |
| 2025 | end |
| 2026 | ret add 8 mul cnt 16 |
| 2027 | end |
| 2028 | |
| 2029 | note ---- who a post addresses (kind 5 op 4) ---- |
| 2030 | note the members its header names, the members its text calls with "@name" or reaches through "@#channel", and |
| 2031 | note whether it is to everyone. The sender is left out. |
| 2032 | |
| 2033 | note two runs of bytes of the request, equal when ASCII letters are compared without case |
| 2034 | fn eqf b view uchar 1048576 x ulong xl ulong y ulong yl ulong to bool |
| 2035 | if ne xl yl |
| 2036 | ret false |
| 2037 | end |
| 2038 | for k ulong xl |
| 2039 | if ne lowc ulong get b add x k lowc ulong get b add y k |
| 2040 | ret false |
| 2041 | end |
| 2042 | end |
| 2043 | ret true |
| 2044 | end |
| 2045 | |
| 2046 | note "main", "all" and "here" are not channels anyone follows |
| 2047 | fn chplain b view uchar 1048576 x ulong n ulong to bool |
| 2048 | if eq n 3 |
| 2049 | ret and and eq lowc ulong get b x 97 eq lowc ulong get b add x 1 108 eq lowc ulong get b add x 2 108 |
| 2050 | end |
| 2051 | if ne n 4 |
| 2052 | ret false |
| 2053 | end |
| 2054 | c0 = lowc ulong get b x |
| 2055 | c1 = lowc ulong get b add x 1 |
| 2056 | c2 = lowc ulong get b add x 2 |
| 2057 | c3 = lowc ulong get b add x 3 |
| 2058 | if and and eq c0 109 eq c1 97 and eq c2 105 eq c3 110 |
| 2059 | ret true |
| 2060 | end |
| 2061 | ret and and eq c0 104 eq c1 101 and eq c2 114 eq c3 101 |
| 2062 | end |
| 2063 | |
| 2064 | note does a member follow the channel named by the xl bytes at x? cp is where the member's channel list starts: a |
| 2065 | note count, then each channel as a 16-bit length and its bytes. An empty list is the role's default: everyone but a |
| 2066 | note worker (role 0) follows every channel. "*" follows every channel |
| 2067 | fn follows b view uchar 1048576 role ulong cp ulong x ulong xl ulong to bool |
| 2068 | cc = ulong get b cp |
| 2069 | if eq cc 0 |
| 2070 | ret ne role 0 |
| 2071 | end |
| 2072 | p = add cp 1 |
| 2073 | for i ulong cc |
| 2074 | l = rd16 b p |
| 2075 | if eq l 1 |
| 2076 | if eq ulong get b add p 2 42 |
| 2077 | ret true |
| 2078 | end |
| 2079 | end |
| 2080 | if eqf b add p 2 l x xl |
| 2081 | ret true |
| 2082 | end |
| 2083 | p = add add p 2 l |
| 2084 | end |
| 2085 | ret false |
| 2086 | end |
| 2087 | |
| 2088 | note op 4: n bytes after the op header: 16-bit counts of members (96 at most), parts (128) and header recipients |
| 2089 | note (16); a byte that is 1 when the header says all; a byte 0; the sender as a 32-bit member number; a byte a |
| 2090 | note member (0 for a worker); the header's recipients, 32 bits each; the parts as fn spans gives them; for each |
| 2091 | note member its channel list (follows); then the text of the post. A number that is not a member is 4294967295. |
| 2092 | note The answer: a byte that is 1 when the post is to everyone, a count, then that many member numbers |
| 2093 | fn addr b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 2094 | flag = new ulong 96 0 |
| 2095 | coff = new ulong 96 0 |
| 2096 | bad = ulong 18446744073709551615 |
| 2097 | if lt n 12 |
| 2098 | ret bad |
| 2099 | end |
| 2100 | lim = add 8 n |
| 2101 | mem = rd16 b 8 |
| 2102 | nsp = rd16 b 10 |
| 2103 | nh = rd16 b 12 |
| 2104 | tall = ulong get b 14 |
| 2105 | sender = rd32 b 16 |
| 2106 | if or gt mem 96 or gt nsp 128 gt nh 16 |
| 2107 | ret bad |
| 2108 | end |
| 2109 | roles = ulong 20 |
| 2110 | hto = add roles mem |
| 2111 | sp = add hto mul nh 4 |
| 2112 | p = add sp mul nsp 16 |
| 2113 | if gt p lim |
| 2114 | ret bad |
| 2115 | end |
| 2116 | for m ulong mem |
| 2117 | if ge p lim |
| 2118 | ret bad |
| 2119 | end |
| 2120 | put coff m p |
| 2121 | cc = ulong get b p |
| 2122 | if gt cc 16 |
| 2123 | ret bad |
| 2124 | end |
| 2125 | p = add p 1 |
| 2126 | for c ulong cc |
| 2127 | if gt add p 2 lim |
| 2128 | ret bad |
| 2129 | end |
| 2130 | p = add add p 2 rd16 b p |
| 2131 | if gt p lim |
| 2132 | ret bad |
| 2133 | end |
| 2134 | end |
| 2135 | end |
| 2136 | t0 = p |
| 2137 | tn = sub lim t0 |
| 2138 | for i ulong nh |
| 2139 | v = rd32 b add hto mul i 4 |
| 2140 | if lt v mem |
| 2141 | put flag v 1 |
| 2142 | end |
| 2143 | end |
| 2144 | for s ulong nsp |
| 2145 | o = add sp mul s 16 |
| 2146 | start = rd32 b o |
| 2147 | ln = rd32 b add o 4 |
| 2148 | kind = rd32 b add o 8 |
| 2149 | v = rd32 b add o 12 |
| 2150 | if eq kind 1 |
| 2151 | if lt v mem |
| 2152 | put flag v 1 |
| 2153 | end |
| 2154 | end |
| 2155 | if eq kind 2 |
| 2156 | tall = 1 |
| 2157 | end |
| 2158 | if eq kind 3 |
| 2159 | if and gt ln 2 le add start ln tn |
| 2160 | cx = add add t0 start 2 |
| 2161 | cl = sub ln 2 |
| 2162 | if not chplain b cx cl |
| 2163 | for m ulong mem |
| 2164 | if follows b ulong get b add roles m get coff m cx cl |
| 2165 | put flag m 1 |
| 2166 | end |
| 2167 | end |
| 2168 | end |
| 2169 | end |
| 2170 | end |
| 2171 | end |
| 2172 | if lt sender mem |
| 2173 | put flag sender 0 |
| 2174 | end |
| 2175 | cnt = ulong 0 |
| 2176 | for m ulong mem |
| 2177 | if eq get flag m 1 |
| 2178 | put ob add 10 cnt uchar m |
| 2179 | cnt = add cnt 1 |
| 2180 | end |
| 2181 | end |
| 2182 | if ne tall 0 |
| 2183 | tall = 1 |
| 2184 | end |
| 2185 | put ob 8 uchar tall |
| 2186 | put ob 9 uchar cnt |
| 2187 | ret add 2 cnt |
| 2188 | end |
| 2189 | |
| 2190 | note kind 5: op and a number as two 32-bit values, then the bytes of the text (at most 70000 for op 1 and 2). |
| 2191 | note op 1: a board line (fn lline). op 2: a time at byte `number` (fn ltime); the answer is 16 bytes: 0 1 when it |
| 2192 | note is a time, 1 1 when it names its zone, 4 the first byte after it (32-bit), 8 the seconds since 1970 plus 100000 |
| 2193 | note (64-bit). op 3: who a post calls and what it cites (fn spans; the number is the highest post that may be |
| 2194 | note cited). op 4: who a post addresses (fn addr). Returns the reply length, or 18446744073709551615 for a malformed body or an unknown op |
| 2195 | fn board ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 2196 | tm = new ulong 16 0 |
| 2197 | bad = ulong 18446744073709551615 |
| 2198 | if lt nb 8 |
| 2199 | ret bad |
| 2200 | end |
| 2201 | op = rd32 ib 0 |
| 2202 | arg = rd32 ib 4 |
| 2203 | n = sub nb 8 |
| 2204 | if eq op 3 |
| 2205 | ret spans ib n arg ob |
| 2206 | end |
| 2207 | if eq op 4 |
| 2208 | ret addr ib n ob |
| 2209 | end |
| 2210 | if gt n 70000 |
| 2211 | ret bad |
| 2212 | end |
| 2213 | if eq op 1 |
| 2214 | ret lline ib n ob |
| 2215 | end |
| 2216 | if eq op 2 |
| 2217 | for z ulong 16 |
| 2218 | put ob add 8 z uchar 0 |
| 2219 | end |
| 2220 | if eq ltime ib arg n tm 1 |
| 2221 | put ob 8 uchar 1 |
| 2222 | put ob 9 uchar get tm 3 |
| 2223 | put32 ob 12 get tm 2 |
| 2224 | put32 ob 16 get tm 1 |
| 2225 | put32 ob 20 shr get tm 1 32 |
| 2226 | end |
| 2227 | ret 16 |
| 2228 | end |
| 2229 | ret bad |
| 2230 | end |
| 2231 | |
| 2232 | note ---- a whole plain-text board: its members and who each post is from and to (kind 6) ---- |
| 2233 | note The host reads each line (kind 5 op 1) and sends what the lines name: for each line a byte that is 1 for a |
| 2234 | note post, a byte that is 1 when it was cut, the number of senders (4 at most) and of recipients (16 at most), then |
| 2235 | note each sender and each recipient as a 16-bit length and the name, a 16-bit length and the bracket after it. |
| 2236 | note Senders and recipients become members. Two spellings are one member when they share a key (no leading "@", |
| 2237 | note ASCII lower case, each run of spaces one "-"); when one stands in the brackets of one agent only and is used |
| 2238 | note as a sender or recipient elsewhere ("merge-desk (omp-queen-spark)"); or when it is that agent's name without |
| 2239 | note its lane ("Worker" for "lane/Worker") and exactly one sender posts under a name that ends that way. |
| 2240 | note Limits: 400 lines, 192 spellings, 96 members, 8 comma-separated items in a bracket. |
| 2241 | global a_keys uchar 12288 |
| 2242 | global a_kl ulong 192 |
| 2243 | global a_sref ulong 192 |
| 2244 | global a_own ulong 192 |
| 2245 | global a_can ulong 192 |
| 2246 | global a_mem ulong 192 |
| 2247 | global a_lo ulong 400 |
| 2248 | global a_kb uchar 72 |
| 2249 | global a_e ulong 8 |
| 2250 | global a_ds ulong 96 |
| 2251 | |
| 2252 | note entry k of side (0 senders, 1 recipients) of the line record at p. a_e: 0 and 1 the name, 2 and 3 the bracket |
| 2253 | fn aent b view uchar 1048576 p ulong side ulong k ulong to void |
| 2254 | skip = k |
| 2255 | if eq side 1 |
| 2256 | skip = add k ulong get b add p 2 |
| 2257 | end |
| 2258 | q = add p 4 |
| 2259 | for i ulong skip |
| 2260 | q = add add q 2 rd16 b q |
| 2261 | q = add add q 2 rd16 b q |
| 2262 | end |
| 2263 | nl = rd16 b q |
| 2264 | put a_e 0 add q 2 |
| 2265 | put a_e 1 nl |
| 2266 | q = add add q 2 nl |
| 2267 | put a_e 2 add q 2 |
| 2268 | put a_e 3 rd16 b q |
| 2269 | end |
| 2270 | |
| 2271 | note the key of the n bytes at off into a_kb; its length, or 65 when it is over 64 bytes (no member has such a key) |
| 2272 | fn akey b view uchar 1048576 off ulong n ulong to ulong |
| 2273 | a = off |
| 2274 | e = add off n |
| 2275 | while lt a e bound 999999 |
| 2276 | if not lsp ulong get b a |
| 2277 | break |
| 2278 | end |
| 2279 | a = add a 1 |
| 2280 | end |
| 2281 | while gt e a bound 999999 |
| 2282 | if not lsp ulong get b sub e 1 |
| 2283 | break |
| 2284 | end |
| 2285 | e = sub e 1 |
| 2286 | end |
| 2287 | if lt a e |
| 2288 | if eq ulong get b a 64 |
| 2289 | a = add a 1 |
| 2290 | end |
| 2291 | end |
| 2292 | kn = ulong 0 |
| 2293 | gap = false |
| 2294 | while lt a e bound 999999 |
| 2295 | c = ulong get b a |
| 2296 | if lsp c |
| 2297 | gap = true |
| 2298 | else |
| 2299 | if and gap gt kn 0 |
| 2300 | if ge kn 64 |
| 2301 | ret 65 |
| 2302 | end |
| 2303 | put a_kb kn uchar 45 |
| 2304 | kn = add kn 1 |
| 2305 | end |
| 2306 | gap = false |
| 2307 | if ge kn 64 |
| 2308 | ret 65 |
| 2309 | end |
| 2310 | put a_kb kn uchar lowc c |
| 2311 | kn = add kn 1 |
| 2312 | end |
| 2313 | a = add a 1 |
| 2314 | end |
| 2315 | ret kn |
| 2316 | end |
| 2317 | |
| 2318 | note where the key in a_kb (kn bytes) stands among the first nk keys, or 1000 |
| 2319 | fn afind kn ulong nk ulong to ulong |
| 2320 | if gt kn 64 |
| 2321 | ret 1000 |
| 2322 | end |
| 2323 | i = ulong 0 |
| 2324 | while lt i nk bound 256 |
| 2325 | if eq get a_kl i kn |
| 2326 | j = ulong 0 |
| 2327 | while lt j kn bound 128 |
| 2328 | if ne ulong get a_keys add mul i 64 j ulong get a_kb j |
| 2329 | break |
| 2330 | end |
| 2331 | j = add j 1 |
| 2332 | end |
| 2333 | if eq j kn |
| 2334 | ret i |
| 2335 | end |
| 2336 | end |
| 2337 | i = add i 1 |
| 2338 | end |
| 2339 | ret 1000 |
| 2340 | end |
| 2341 | |
| 2342 | note "L1122" or "L1124/L1125": a ledger number, never another name of the agent |
| 2343 | fn aledger b view uchar 1048576 off ulong n ulong to bool |
| 2344 | i = ulong 0 |
| 2345 | parts = ulong 0 |
| 2346 | while lt i n bound 16 |
| 2347 | if ge parts 8 |
| 2348 | break |
| 2349 | end |
| 2350 | c = ulong get b add off i |
| 2351 | if and ne c 76 ne c 108 |
| 2352 | ret false |
| 2353 | end |
| 2354 | j = add i 1 |
| 2355 | while lt j n bound 16 |
| 2356 | if gt sub j i 9 |
| 2357 | break |
| 2358 | end |
| 2359 | d = ulong get b add off j |
| 2360 | if or lt d 48 gt d 57 |
| 2361 | break |
| 2362 | end |
| 2363 | j = add j 1 |
| 2364 | end |
| 2365 | if eq j add i 1 |
| 2366 | ret false |
| 2367 | end |
| 2368 | parts = add parts 1 |
| 2369 | if eq j n |
| 2370 | ret true |
| 2371 | end |
| 2372 | if ne ulong get b add off j 47 |
| 2373 | ret false |
| 2374 | end |
| 2375 | i = add j 1 |
| 2376 | end |
| 2377 | ret false |
| 2378 | end |
| 2379 | |
| 2380 | note the main spelling of the set that holds spelling s |
| 2381 | fn aroot s ulong nk ulong to ulong |
| 2382 | i = s |
| 2383 | hops = ulong 0 |
| 2384 | while lt i nk bound 256 |
| 2385 | if eq get a_can i i |
| 2386 | break |
| 2387 | end |
| 2388 | if ge hops 192 |
| 2389 | break |
| 2390 | end |
| 2391 | i = get a_can i |
| 2392 | hops = add hops 1 |
| 2393 | end |
| 2394 | ret i |
| 2395 | end |
| 2396 | |
| 2397 | note joins the sets that hold x0 and y0; the earlier spelling stays the main one |
| 2398 | fn ajoin x0 ulong y0 ulong nk ulong to void |
| 2399 | x = aroot x0 nk |
| 2400 | y = aroot y0 nk |
| 2401 | if or ge x nk ge y nk |
| 2402 | ret |
| 2403 | end |
| 2404 | if eq x y |
| 2405 | ret |
| 2406 | end |
| 2407 | if lt x y |
| 2408 | put a_can y x |
| 2409 | else |
| 2410 | put a_can x y |
| 2411 | end |
| 2412 | end |
| 2413 | |
| 2414 | note is key f the key s with a lane in front: "lane/s"? |
| 2415 | fn alane f ulong s ulong to bool |
| 2416 | fl = get a_kl f |
| 2417 | sl = get a_kl s |
| 2418 | if eq sl 0 |
| 2419 | ret false |
| 2420 | end |
| 2421 | if lt fl add sl 2 |
| 2422 | ret false |
| 2423 | end |
| 2424 | p = sub fl sl |
| 2425 | if ne ulong get a_keys add mul f 64 sub p 1 47 |
| 2426 | ret false |
| 2427 | end |
| 2428 | i = ulong 0 |
| 2429 | while lt i sl bound 128 |
| 2430 | if ne ulong get a_keys add add mul f 64 p i ulong get a_keys add mul s 64 i |
| 2431 | ret false |
| 2432 | end |
| 2433 | i = add i 1 |
| 2434 | end |
| 2435 | ret true |
| 2436 | end |
| 2437 | |
| 2438 | note the member that the name of the current entry (a_e) belongs to, or 1000 |
| 2439 | fn amember b view uchar 1048576 nk ulong to ulong |
| 2440 | f = afind akey b get a_e 0 get a_e 1 nk |
| 2441 | if ge f 1000 |
| 2442 | ret 1000 |
| 2443 | end |
| 2444 | ret get a_mem f |
| 2445 | end |
| 2446 | |
| 2447 | note kind 6: a 32-bit count of lines, then the line records. The answer: 16-bit counts of members, of joined |
| 2448 | note spellings and of posts; from byte 8 four 32-bit counts: lines that are not posts, posts that were cut, |
| 2449 | note agents beyond 96 members, names met after the 192 spellings were full; from byte 24 eight bytes a member: |
| 2450 | note the line (16-bit), side and entry of its newest spelling, then the line (65535: none) and entry of the newest |
| 2451 | note bracket after it as a sender; six bytes a joined spelling: its member, 0, then line, side and entry; then a |
| 2452 | note post each: its sender (255: none), how many others signed and how many members its header names, then |
| 2453 | note those members. Returns the reply length, or 18446744073709551615 for a malformed body |
| 2454 | fn asm b view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 2455 | wl = new ulong 8 0 |
| 2456 | to2 = new ulong 24 0 |
| 2457 | bad = ulong 18446744073709551615 |
| 2458 | if lt n 4 |
| 2459 | ret bad |
| 2460 | end |
| 2461 | nl = rd32 b 0 |
| 2462 | if gt nl 400 |
| 2463 | ret bad |
| 2464 | end |
| 2465 | p = ulong 4 |
| 2466 | for li ulong nl |
| 2467 | if gt add p 4 n |
| 2468 | ret bad |
| 2469 | end |
| 2470 | put a_lo li p |
| 2471 | ns = ulong get b add p 2 |
| 2472 | nr = ulong get b add p 3 |
| 2473 | if or gt ns 4 gt nr 16 |
| 2474 | ret bad |
| 2475 | end |
| 2476 | p = add p 4 |
| 2477 | for k ulong mul 2 add ns nr |
| 2478 | if gt add p 2 n |
| 2479 | ret bad |
| 2480 | end |
| 2481 | p = add add p 2 rd16 b p |
| 2482 | if gt p n |
| 2483 | ret bad |
| 2484 | end |
| 2485 | end |
| 2486 | end |
| 2487 | nk = ulong 0 |
| 2488 | sdrop = ulong 0 |
| 2489 | skeys = ulong 0 |
| 2490 | for pz ulong 2 |
| 2491 | for lr ulong nl |
| 2492 | lq = sub sub nl 1 lr |
| 2493 | p = get a_lo lq |
| 2494 | if eq ulong get b p 1 |
| 2495 | cnt = ulong get b add p 2 |
| 2496 | if eq pz 1 |
| 2497 | cnt = ulong get b add p 3 |
| 2498 | end |
| 2499 | for k ulong cnt |
| 2500 | aent b p pz k |
| 2501 | kn = akey b get a_e 0 get a_e 1 |
| 2502 | if and gt kn 0 le kn 64 |
| 2503 | if ge afind kn nk 1000 |
| 2504 | if lt nk 192 |
| 2505 | for j ulong kn |
| 2506 | put a_keys add mul nk 64 j get a_kb j |
| 2507 | end |
| 2508 | put a_kl nk kn |
| 2509 | put a_sref nk or or shl lq 16 shl pz 8 k |
| 2510 | nk = add nk 1 |
| 2511 | else |
| 2512 | sdrop = add sdrop 1 |
| 2513 | end |
| 2514 | end |
| 2515 | end |
| 2516 | end |
| 2517 | end |
| 2518 | end |
| 2519 | if eq pz 0 |
| 2520 | skeys = nk |
| 2521 | end |
| 2522 | end |
| 2523 | for c ulong nk |
| 2524 | put a_own c 1000 |
| 2525 | put a_can c c |
| 2526 | put a_mem c 1000 |
| 2527 | end |
| 2528 | for li ulong nl |
| 2529 | p = get a_lo li |
| 2530 | if eq ulong get b p 1 |
| 2531 | for side ulong 2 |
| 2532 | cnt = ulong get b add p 2 |
| 2533 | if eq side 1 |
| 2534 | cnt = ulong get b add p 3 |
| 2535 | end |
| 2536 | for k ulong cnt |
| 2537 | aent b p side k |
| 2538 | d0 = get a_e 2 |
| 2539 | dn = get a_e 3 |
| 2540 | outer = afind akey b get a_e 0 get a_e 1 nk |
| 2541 | a = ulong 0 |
| 2542 | items = ulong 0 |
| 2543 | while le a dn bound 1024 |
| 2544 | if ge outer 1000 |
| 2545 | break |
| 2546 | end |
| 2547 | if ge items 8 |
| 2548 | break |
| 2549 | end |
| 2550 | e = a |
| 2551 | while lt e dn bound 999999 |
| 2552 | if eq ulong get b add d0 e 44 |
| 2553 | break |
| 2554 | end |
| 2555 | e = add e 1 |
| 2556 | end |
| 2557 | x = a |
| 2558 | y = e |
| 2559 | while lt x y bound 999999 |
| 2560 | if not lsp ulong get b add d0 x |
| 2561 | break |
| 2562 | end |
| 2563 | x = add x 1 |
| 2564 | end |
| 2565 | while gt y x bound 999999 |
| 2566 | if not lsp ulong get b add d0 sub y 1 |
| 2567 | break |
| 2568 | end |
| 2569 | y = sub y 1 |
| 2570 | end |
| 2571 | if lt x y |
| 2572 | if not aledger b add d0 x sub y x |
| 2573 | inner = afind akey b add d0 x sub y x nk |
| 2574 | if lt inner 1000 |
| 2575 | if ne inner outer |
| 2576 | if eq get a_own inner 1000 |
| 2577 | put a_own inner outer |
| 2578 | else |
| 2579 | if ne get a_own inner outer |
| 2580 | put a_own inner 2000 |
| 2581 | end |
| 2582 | end |
| 2583 | end |
| 2584 | end |
| 2585 | end |
| 2586 | end |
| 2587 | items = add items 1 |
| 2588 | a = add e 1 |
| 2589 | end |
| 2590 | end |
| 2591 | end |
| 2592 | end |
| 2593 | end |
| 2594 | for c ulong nk |
| 2595 | if lt get a_own c 1000 |
| 2596 | ajoin get a_own c c nk |
| 2597 | end |
| 2598 | end |
| 2599 | for c ulong nk |
| 2600 | slash = false |
| 2601 | for j ulong get a_kl c |
| 2602 | if eq ulong get a_keys add mul c 64 j 47 |
| 2603 | slash = true |
| 2604 | end |
| 2605 | end |
| 2606 | if not slash |
| 2607 | mt1 = ulong 0 |
| 2608 | matches = ulong 0 |
| 2609 | for k ulong skeys |
| 2610 | if ne k c |
| 2611 | if alane k c |
| 2612 | mt1 = k |
| 2613 | matches = add matches 1 |
| 2614 | end |
| 2615 | end |
| 2616 | end |
| 2617 | if eq matches 1 |
| 2618 | ajoin mt1 c nk |
| 2619 | end |
| 2620 | end |
| 2621 | end |
| 2622 | nm = ulong 0 |
| 2623 | mdrop = ulong 0 |
| 2624 | for c ulong nk |
| 2625 | if eq aroot c nk c |
| 2626 | if lt nm 96 |
| 2627 | put a_mem c nm |
| 2628 | r = get a_sref c |
| 2629 | o = add 32 mul nm 8 |
| 2630 | put ob o uchar and shr r 16 255 |
| 2631 | put ob add o 1 uchar shr r 24 |
| 2632 | put ob add o 2 uchar and shr r 8 255 |
| 2633 | put ob add o 3 uchar and r 255 |
| 2634 | put ob add o 4 uchar 255 |
| 2635 | put ob add o 5 uchar 255 |
| 2636 | put ob add o 6 uchar 0 |
| 2637 | put ob add o 7 uchar 0 |
| 2638 | put a_ds nm 0 |
| 2639 | nm = add nm 1 |
| 2640 | else |
| 2641 | mdrop = add mdrop 1 |
| 2642 | end |
| 2643 | end |
| 2644 | end |
| 2645 | o = add 32 mul nm 8 |
| 2646 | nalso = ulong 0 |
| 2647 | for c ulong nk |
| 2648 | rt = aroot c nk |
| 2649 | if ne rt c |
| 2650 | if lt rt nk |
| 2651 | if lt get a_mem rt 1000 |
| 2652 | put a_mem c get a_mem rt |
| 2653 | r = get a_sref c |
| 2654 | put ob o uchar get a_mem rt |
| 2655 | put ob add o 1 uchar 0 |
| 2656 | put ob add o 2 uchar and shr r 16 255 |
| 2657 | put ob add o 3 uchar shr r 24 |
| 2658 | put ob add o 4 uchar and shr r 8 255 |
| 2659 | put ob add o 5 uchar and r 255 |
| 2660 | o = add o 6 |
| 2661 | nalso = add nalso 1 |
| 2662 | end |
| 2663 | end |
| 2664 | end |
| 2665 | end |
| 2666 | skipped = ulong 0 |
| 2667 | clipped = ulong 0 |
| 2668 | nposts = ulong 0 |
| 2669 | for li ulong nl |
| 2670 | p = get a_lo li |
| 2671 | if ne ulong get b p 1 |
| 2672 | skipped = add skipped 1 |
| 2673 | else |
| 2674 | if eq ulong get b add p 1 1 |
| 2675 | clipped = add clipped 1 |
| 2676 | end |
| 2677 | sender = ulong 1000 |
| 2678 | nw = ulong 0 |
| 2679 | ns = ulong get b add p 2 |
| 2680 | for k ulong ns |
| 2681 | aent b p 0 k |
| 2682 | m = amember b nk |
| 2683 | if eq k 0 |
| 2684 | sender = m |
| 2685 | else |
| 2686 | if and lt m 1000 ne m sender |
| 2687 | dup = false |
| 2688 | for j ulong nw |
| 2689 | if eq get wl j m |
| 2690 | dup = true |
| 2691 | end |
| 2692 | end |
| 2693 | if not dup |
| 2694 | put wl nw m |
| 2695 | nw = add nw 1 |
| 2696 | end |
| 2697 | end |
| 2698 | end |
| 2699 | end |
| 2700 | nt = ulong 0 |
| 2701 | nr = ulong get b add p 3 |
| 2702 | for k ulong nr |
| 2703 | aent b p 1 k |
| 2704 | m = amember b nk |
| 2705 | if and lt m 1000 ne m sender |
| 2706 | dup = false |
| 2707 | for j ulong nt |
| 2708 | if eq get to2 j m |
| 2709 | dup = true |
| 2710 | end |
| 2711 | end |
| 2712 | if not dup |
| 2713 | put to2 nt m |
| 2714 | nt = add nt 1 |
| 2715 | end |
| 2716 | end |
| 2717 | end |
| 2718 | sb = ulong 255 |
| 2719 | if lt sender 1000 |
| 2720 | sb = sender |
| 2721 | end |
| 2722 | put ob o uchar sb |
| 2723 | put ob add o 1 uchar nw |
| 2724 | put ob add o 2 uchar nt |
| 2725 | o = add o 3 |
| 2726 | for j ulong nw |
| 2727 | put ob o uchar get wl j |
| 2728 | o = add o 1 |
| 2729 | end |
| 2730 | for j ulong nt |
| 2731 | put ob o uchar get to2 j |
| 2732 | o = add o 1 |
| 2733 | end |
| 2734 | nposts = add nposts 1 |
| 2735 | end |
| 2736 | end |
| 2737 | for lr ulong nl |
| 2738 | lq = sub sub nl 1 lr |
| 2739 | p = get a_lo lq |
| 2740 | if eq ulong get b p 1 |
| 2741 | ns = ulong get b add p 2 |
| 2742 | for k ulong ns |
| 2743 | aent b p 0 k |
| 2744 | dn = get a_e 3 |
| 2745 | m = amember b nk |
| 2746 | if and lt m 1000 gt dn 0 |
| 2747 | if eq get a_ds m 0 |
| 2748 | put a_ds m 1 |
| 2749 | mo = add 36 mul m 8 |
| 2750 | put ob mo uchar and lq 255 |
| 2751 | put ob add mo 1 uchar shr lq 8 |
| 2752 | put ob add mo 2 uchar k |
| 2753 | end |
| 2754 | end |
| 2755 | end |
| 2756 | end |
| 2757 | end |
| 2758 | put ob 8 uchar and nm 255 |
| 2759 | put ob 9 uchar shr nm 8 |
| 2760 | put ob 10 uchar and nalso 255 |
| 2761 | put ob 11 uchar shr nalso 8 |
| 2762 | put ob 12 uchar and nposts 255 |
| 2763 | put ob 13 uchar shr nposts 8 |
| 2764 | put ob 14 uchar 0 |
| 2765 | put ob 15 uchar 0 |
| 2766 | put32 ob 16 skipped |
| 2767 | put32 ob 20 clipped |
| 2768 | put32 ob 24 mdrop |
| 2769 | put32 ob 28 sdrop |
| 2770 | ret sub o 8 |
| 2771 | end |
| 2772 | |
| 2773 | note ---- the state of a swarm's members, and the graph (kind 7) ---- |
| 2774 | note A request is an op and a count c as two 32-bit values, then c numbers of 64 bits, then bytes when the op has a |
| 2775 | note text. Every number, in and out, is the value plus 1099511627776, so that -1 ("not known", "none") travels as |
| 2776 | note an unsigned number. Codes: role 0 worker, 1 coordinator, 2 helper; turn 0 not known, 1 running, 2 ended; wake |
| 2777 | note 2 parked for mentions, 3 for any post; state 1 working, 2 waiting, 3 stopped; attention 0 none, 1 stuck, |
| 2778 | note 2 error, 3 quota; group 1 needs you, 2 working, 3 waiting on someone, 4 parked; step 1 planner, 2 result, |
| 2779 | note 3 user, 4 error; status 1 done, 2 error. |
| 2780 | const k_b ulong 1099511627776 |
| 2781 | text q_words "resource_exhausted|quota|rate limit|rate-limit|ratelimit|exhausted your capacity|" |
| 2782 | text q_roles "coordinatorworkernarratormonitor" |
| 2783 | global d_role ulong 96 |
| 2784 | global d_kill ulong 96 |
| 2785 | global d_wake ulong 96 |
| 2786 | global d_turn ulong 96 |
| 2787 | global d_lr ulong 96 |
| 2788 | global d_lm ulong 96 |
| 2789 | global d_fail ulong 96 |
| 2790 | global d_own ulong 96 |
| 2791 | global d_no ulong 96 |
| 2792 | global d_nl ulong 96 |
| 2793 | global d_cnt ulong 96 |
| 2794 | global d_last ulong 96 |
| 2795 | global d_state ulong 96 |
| 2796 | global d_att ulong 96 |
| 2797 | global d_won ulong 96 |
| 2798 | global d_grp ulong 96 |
| 2799 | global d_key ulong 96 |
| 2800 | global d_ord ulong 96 |
| 2801 | global d_po ulong 400 |
| 2802 | global d_cell ulong 18432 |
| 2803 | global d_nm ulong 96 |
| 2804 | |
| 2805 | note number k of the request |
| 2806 | fn gi b view uchar 1048576 k ulong to ulong |
| 2807 | o = add 8 mul k 8 |
| 2808 | ret or rd32 b o shl rd32 b add o 4 32 |
| 2809 | end |
| 2810 | |
| 2811 | note number k of the request as a count; a negative number gives a value over every limit |
| 2812 | fn gu b view uchar 1048576 k ulong to ulong |
| 2813 | v = gi b k |
| 2814 | if lt v k_b |
| 2815 | ret 4294967295 |
| 2816 | end |
| 2817 | ret sub v k_b |
| 2818 | end |
| 2819 | |
| 2820 | note number k of the answer |
| 2821 | fn po ob edit uchar 65544 k ulong v ulong to void |
| 2822 | o = add 8 mul k 8 |
| 2823 | put32 ob o v |
| 2824 | put32 ob add o 4 shr v 32 |
| 2825 | end |
| 2826 | |
| 2827 | note a member's state is worked out, never taken from what it says about itself. With a roster: stopped when it |
| 2828 | note was killed; else waiting when its own run has ended and working when it is mid-turn; with no transcript to |
| 2829 | note go on, waiting when it is parked. With no roster: working when it posted within 900 seconds (age, -1 never) |
| 2830 | fn swstate killed ulong turn ulong wake ulong roster ulong age ulong to ulong |
| 2831 | if eq killed add k_b 1 |
| 2832 | ret 3 |
| 2833 | end |
| 2834 | if ne roster add k_b 1 |
| 2835 | if and ge age k_b le age add k_b 900 |
| 2836 | ret 1 |
| 2837 | end |
| 2838 | ret 2 |
| 2839 | end |
| 2840 | if eq turn add k_b 2 |
| 2841 | ret 2 |
| 2842 | end |
| 2843 | if eq turn add k_b 1 |
| 2844 | ret 1 |
| 2845 | end |
| 2846 | if or eq wake add k_b 2 eq wake add k_b 3 |
| 2847 | ret 2 |
| 2848 | end |
| 2849 | ret 1 |
| 2850 | end |
| 2851 | |
| 2852 | note what needs a look: a failed newest step, or a member that should be working and has not moved for more |
| 2853 | note than 600 seconds (idle -1: not known) |
| 2854 | fn swatt state ulong failure ulong idle ulong to ulong |
| 2855 | if eq state add k_b 3 |
| 2856 | ret 0 |
| 2857 | end |
| 2858 | if eq failure add k_b 2 |
| 2859 | ret 2 |
| 2860 | end |
| 2861 | if eq failure add k_b 3 |
| 2862 | ret 3 |
| 2863 | end |
| 2864 | if and eq state add k_b 1 gt idle add k_b 600 |
| 2865 | ret 1 |
| 2866 | end |
| 2867 | ret 0 |
| 2868 | end |
| 2869 | |
| 2870 | note the Overview group of one member (asks and won: 1 when it asks the owner, when it waits on someone) |
| 2871 | fn swgroup state ulong att ulong asks ulong won ulong to ulong |
| 2872 | if eq state add k_b 3 |
| 2873 | ret 4 |
| 2874 | end |
| 2875 | if or ne att k_b ne asks k_b |
| 2876 | ret 1 |
| 2877 | end |
| 2878 | if eq state add k_b 1 |
| 2879 | ret 2 |
| 2880 | end |
| 2881 | if ne won k_b |
| 2882 | ret 3 |
| 2883 | end |
| 2884 | ret 4 |
| 2885 | end |
| 2886 | |
| 2887 | note is this post the first row of a visual group? Posts by one sender, next to each other and at most 600 |
| 2888 | note seconds apart, are one group |
| 2889 | fn swstarts ps ulong pt ulong s ulong t ulong to ulong |
| 2890 | if or lt s k_b ne s ps |
| 2891 | ret 1 |
| 2892 | end |
| 2893 | if or le t k_b le pt k_b |
| 2894 | ret 0 |
| 2895 | end |
| 2896 | if or gt t add pt 600 lt t pt |
| 2897 | ret 1 |
| 2898 | end |
| 2899 | ret 0 |
| 2900 | end |
| 2901 | |
| 2902 | note the n bytes at off, ASCII letters without case, against the wn bytes at w0 of q_roles |
| 2903 | fn eqrole b view uchar 1048576 off ulong n ulong w0 ulong wn ulong to bool |
| 2904 | if ne n wn |
| 2905 | ret false |
| 2906 | end |
| 2907 | i = ulong 0 |
| 2908 | while lt i n bound 64 |
| 2909 | if ne lowc ulong get b add off i ulong get q_roles add w0 i |
| 2910 | ret false |
| 2911 | end |
| 2912 | i = add i 1 |
| 2913 | end |
| 2914 | ret true |
| 2915 | end |
| 2916 | |
| 2917 | note the order of members: by key (small first), the coordinator before the others, then by name (ASCII letters |
| 2918 | note without case, the shorter first). n members; keys in d_key, roles in d_role, names at d_no, d_nl; order to d_ord |
| 2919 | fn sworder b view uchar 1048576 n ulong to void |
| 2920 | cntd = ulong 0 |
| 2921 | for i ulong n |
| 2922 | pos = cntd |
| 2923 | while gt pos 0 bound 128 |
| 2924 | o = get d_ord sub pos 1 |
| 2925 | after = false |
| 2926 | if ne get d_key o get d_key i |
| 2927 | after = gt get d_key o get d_key i |
| 2928 | else |
| 2929 | co = eq get d_role o 1 |
| 2930 | ci = eq get d_role i 1 |
| 2931 | dif = false |
| 2932 | if co |
| 2933 | if not ci |
| 2934 | dif = true |
| 2935 | end |
| 2936 | else |
| 2937 | if ci |
| 2938 | dif = true |
| 2939 | end |
| 2940 | end |
| 2941 | if dif |
| 2942 | after = ci |
| 2943 | else |
| 2944 | x = get d_no o |
| 2945 | xl = get d_nl o |
| 2946 | y = get d_no i |
| 2947 | yl = get d_nl i |
| 2948 | k = ulong 0 |
| 2949 | cmp = ulong 1 |
| 2950 | while lt k xl bound 999999 |
| 2951 | if ge k yl |
| 2952 | break |
| 2953 | end |
| 2954 | cx = lowc ulong get b add x k |
| 2955 | cy = lowc ulong get b add y k |
| 2956 | if ne cx cy |
| 2957 | cmp = 0 |
| 2958 | if gt cx cy |
| 2959 | cmp = 2 |
| 2960 | end |
| 2961 | break |
| 2962 | end |
| 2963 | k = add k 1 |
| 2964 | end |
| 2965 | if eq cmp 1 |
| 2966 | if gt xl yl |
| 2967 | cmp = 2 |
| 2968 | end |
| 2969 | end |
| 2970 | after = eq cmp 2 |
| 2971 | end |
| 2972 | end |
| 2973 | if not after |
| 2974 | break |
| 2975 | end |
| 2976 | put d_ord pos o |
| 2977 | pos = sub pos 1 |
| 2978 | end |
| 2979 | put d_ord pos i |
| 2980 | cntd = add cntd 1 |
| 2981 | end |
| 2982 | end |
| 2983 | |
| 2984 | note op 8: has the member's run stopped? Its newest steps, oldest first: four counts (they must be equal), then |
| 2985 | note the kinds, the statuses, for a planner step how many tools it called, and which of them was the wait for |
| 2986 | note posts (-1 none). Ended (2) when the newest planner step called no tool and nothing came after it, or when it |
| 2987 | note called the wait and that call's result is done; anything newer means mid-turn (1). 0: not known |
| 2988 | fn swturn b view uchar 1048576 c ulong to ulong |
| 2989 | if lt c 4 |
| 2990 | ret 0 |
| 2991 | end |
| 2992 | n = gu b 0 |
| 2993 | if gt n 100000 |
| 2994 | ret 0 |
| 2995 | end |
| 2996 | if or eq n 0 or ne gi b 1 gi b 0 or ne gi b 2 gi b 0 ne gi b 3 gi b 0 |
| 2997 | ret 0 |
| 2998 | end |
| 2999 | if ne c add 4 mul n 4 |
| 3000 | ret 0 |
| 3001 | end |
| 3002 | kd = ulong 4 |
| 3003 | sx = add 4 n |
| 3004 | tl = add 4 mul n 2 |
| 3005 | wt2 = add 4 mul n 3 |
| 3006 | i = n |
| 3007 | results = ulong 0 |
| 3008 | looked = ulong 0 |
| 3009 | while gt i 0 bound 512 |
| 3010 | if ge looked 256 |
| 3011 | break |
| 3012 | end |
| 3013 | if ne gi b add kd sub i 1 add k_b 2 |
| 3014 | break |
| 3015 | end |
| 3016 | results = add results 1 |
| 3017 | i = sub i 1 |
| 3018 | looked = add looked 1 |
| 3019 | end |
| 3020 | if or eq i 0 ge looked 256 |
| 3021 | ret 1 |
| 3022 | end |
| 3023 | i = sub i 1 |
| 3024 | if ne gi b add kd i add k_b 1 |
| 3025 | ret 1 |
| 3026 | end |
| 3027 | tools = gi b add tl i |
| 3028 | if le tools k_b |
| 3029 | if eq results 0 |
| 3030 | ret 2 |
| 3031 | end |
| 3032 | ret 1 |
| 3033 | end |
| 3034 | wait = gi b add wt2 i |
| 3035 | if or lt wait k_b ge wait tools |
| 3036 | ret 1 |
| 3037 | end |
| 3038 | if lt results sub tools k_b |
| 3039 | ret 1 |
| 3040 | end |
| 3041 | if eq gi b add sx add add i 1 sub wait k_b add k_b 1 |
| 3042 | ret 2 |
| 3043 | end |
| 3044 | ret 1 |
| 3045 | end |
| 3046 | |
| 3047 | note op 9: the step that says what the member is doing now: the newest planner step of the current turn that has |
| 3048 | note a label. Three counts (equal), then kinds, waits and labels. A turn starts after user input or after a wait |
| 3049 | note for posts. The answer is the step's place, or -1 |
| 3050 | fn swact b view uchar 1048576 c ulong to ulong |
| 3051 | none = sub k_b 1 |
| 3052 | if lt c 3 |
| 3053 | ret none |
| 3054 | end |
| 3055 | n = gu b 0 |
| 3056 | if gt n 100000 |
| 3057 | ret none |
| 3058 | end |
| 3059 | if or ne gi b 1 gi b 0 ne gi b 2 gi b 0 |
| 3060 | ret none |
| 3061 | end |
| 3062 | if ne c add 3 mul n 3 |
| 3063 | ret none |
| 3064 | end |
| 3065 | i = n |
| 3066 | looked = ulong 0 |
| 3067 | while gt i 0 bound 512 |
| 3068 | if ge looked 256 |
| 3069 | break |
| 3070 | end |
| 3071 | kk = gi b add 3 sub i 1 |
| 3072 | if eq kk add k_b 3 |
| 3073 | ret none |
| 3074 | end |
| 3075 | if eq kk add k_b 1 |
| 3076 | if ge gi b add add 3 n sub i 1 k_b |
| 3077 | ret none |
| 3078 | end |
| 3079 | if eq gi b add add 3 mul n 2 sub i 1 add k_b 1 |
| 3080 | ret add k_b sub i 1 |
| 3081 | end |
| 3082 | end |
| 3083 | i = sub i 1 |
| 3084 | looked = add looked 1 |
| 3085 | end |
| 3086 | ret none |
| 3087 | end |
| 3088 | |
| 3089 | note op 10: does an error text (t0..t1) say the member ran out of quota or was rate limited? One of the words of |
| 3090 | note q_words in its first 32768 places, or "429" standing alone |
| 3091 | fn swquota b view uchar 1048576 t0 ulong t1 ulong to ulong |
| 3092 | tn = sub t1 t0 |
| 3093 | w0 = ulong 0 |
| 3094 | wi = ulong 0 |
| 3095 | while lt wi len q_words bound 256 |
| 3096 | if eq ulong get q_words wi 124 |
| 3097 | wn = sub wi w0 |
| 3098 | if and gt wn 0 ge tn wn |
| 3099 | i = ulong 0 |
| 3100 | while le add i wn tn bound 40000 |
| 3101 | if ge i 32768 |
| 3102 | break |
| 3103 | end |
| 3104 | k = ulong 0 |
| 3105 | while lt k wn bound 64 |
| 3106 | if ne lowc ulong get b add add t0 i k ulong get q_words add w0 k |
| 3107 | break |
| 3108 | end |
| 3109 | k = add k 1 |
| 3110 | end |
| 3111 | if eq k wn |
| 3112 | ret 1 |
| 3113 | end |
| 3114 | i = add i 1 |
| 3115 | end |
| 3116 | end |
| 3117 | w0 = add wi 1 |
| 3118 | end |
| 3119 | wi = add wi 1 |
| 3120 | end |
| 3121 | i = ulong 0 |
| 3122 | while le add i 3 tn bound 40000 |
| 3123 | if ge i 32768 |
| 3124 | break |
| 3125 | end |
| 3126 | p = add t0 i |
| 3127 | if and and eq ulong get b p 52 eq ulong get b add p 1 50 eq ulong get b add p 2 57 |
| 3128 | if not namer runeb b p t0 t1 |
| 3129 | if not namer rune b add p 3 t1 |
| 3130 | ret 1 |
| 3131 | end |
| 3132 | end |
| 3133 | end |
| 3134 | i = add i 1 |
| 3135 | end |
| 3136 | ret 0 |
| 3137 | end |
| 3138 | |
| 3139 | note op 11: the role code of a roster member from its role (rl bytes at ro) and its name (nl bytes at no). The |
| 3140 | note coordinator leads; "narrator" and "monitor", also with "-<digits>" after, are helpers by name; so is any role |
| 3141 | note other than "worker" |
| 3142 | fn swrole b view uchar 1048576 ro ulong rl ulong no ulong nl ulong to ulong |
| 3143 | if eqrole b ro rl 0 11 |
| 3144 | ret 1 |
| 3145 | end |
| 3146 | plain = eq rl 0 |
| 3147 | if eqrole b ro rl 11 6 |
| 3148 | plain = true |
| 3149 | end |
| 3150 | if not plain |
| 3151 | ret 2 |
| 3152 | end |
| 3153 | bl = nl |
| 3154 | pf = cprefix b no nl |
| 3155 | if gt pf 0 |
| 3156 | bl = pf |
| 3157 | end |
| 3158 | if eqrole b no bl 17 8 |
| 3159 | ret 2 |
| 3160 | end |
| 3161 | if eqrole b no bl 25 7 |
| 3162 | ret 2 |
| 3163 | end |
| 3164 | ret 0 |
| 3165 | end |
| 3166 | |
| 3167 | note op 16: everything the views show about the members. Numbers: 0 1 when there is a roster, 1 now (seconds |
| 3168 | note since 1970), 2 the members n (96 at most), 3 the posts p (400 at most); nine a member: role, killed, wake, |
| 3169 | note turn, the last post it read (-1 not known), its last own movement (0 not known), failure, 1 when it is the |
| 3170 | note person using Hop, the length of its name; then a post each: its number, its time (0 not known), its sender |
| 3171 | note (-1: not a member), how many others signed and who, how many members it addresses by name and who. The |
| 3172 | note names follow as bytes. The answer: 0 the newest post number, 1 to 3 the members working, waiting and stopped |
| 3173 | note (helpers are not counted); a number a post: 1 when it starts a visual group; then eleven lists of n: posts |
| 3174 | note by each member, its newest post (-1 none), state, attention, idle seconds (-1), unread posts (-1), 1 for a |
| 3175 | note helper, who it waits on (-1), the post that says so, the post that asks the owner (0 none), its group; then |
| 3176 | note the Overview order and the Members order. Returns the count of numbers, or 0 for a malformed request |
| 3177 | fn swderive b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 3178 | if lt c 4 |
| 3179 | ret 0 |
| 3180 | end |
| 3181 | roster = gi b 0 |
| 3182 | now = gi b 1 |
| 3183 | n = gu b 2 |
| 3184 | p = gu b 3 |
| 3185 | if or gt n 96 gt p 400 |
| 3186 | ret 0 |
| 3187 | end |
| 3188 | q = add 4 mul n 9 |
| 3189 | if gt q c |
| 3190 | ret 0 |
| 3191 | end |
| 3192 | no = add 8 mul c 8 |
| 3193 | for m ulong n |
| 3194 | o = add 4 mul m 9 |
| 3195 | put d_role m gu b o |
| 3196 | put d_kill m gi b add o 1 |
| 3197 | put d_wake m gi b add o 2 |
| 3198 | put d_turn m gi b add o 3 |
| 3199 | put d_lr m gi b add o 4 |
| 3200 | put d_lm m gi b add o 5 |
| 3201 | put d_fail m gi b add o 6 |
| 3202 | put d_own m gi b add o 7 |
| 3203 | l = gu b add o 8 |
| 3204 | if gt l 1048576 |
| 3205 | ret 0 |
| 3206 | end |
| 3207 | put d_no m no |
| 3208 | put d_nl m l |
| 3209 | no = add no l |
| 3210 | put d_cnt m 0 |
| 3211 | put d_last m 1000 |
| 3212 | end |
| 3213 | if gt no add add 8 mul c 8 nbytes |
| 3214 | ret 0 |
| 3215 | end |
| 3216 | for i ulong p |
| 3217 | if gt add q 4 c |
| 3218 | ret 0 |
| 3219 | end |
| 3220 | put d_po i q |
| 3221 | nw = gu b add q 3 |
| 3222 | if gt nw 4 |
| 3223 | ret 0 |
| 3224 | end |
| 3225 | if gt add add q 5 nw c |
| 3226 | ret 0 |
| 3227 | end |
| 3228 | nd = gu b add add q 4 nw |
| 3229 | if gt nd 96 |
| 3230 | ret 0 |
| 3231 | end |
| 3232 | q = add add add q 5 nw nd |
| 3233 | if gt q c |
| 3234 | ret 0 |
| 3235 | end |
| 3236 | end |
| 3237 | head = k_b |
| 3238 | if gt p 0 |
| 3239 | head = gi b get d_po sub p 1 |
| 3240 | end |
| 3241 | po ob 0 head |
| 3242 | for i ulong p |
| 3243 | q = get d_po i |
| 3244 | s = gi b add q 2 |
| 3245 | sg = ulong 1 |
| 3246 | if gt i 0 |
| 3247 | pq = get d_po sub i 1 |
| 3248 | sg = swstarts gi b add pq 2 gi b add pq 1 s gi b add q 1 |
| 3249 | end |
| 3250 | po ob add 4 i add k_b sg |
| 3251 | if and ge s k_b lt s add k_b n |
| 3252 | sm = sub s k_b |
| 3253 | put d_cnt sm add get d_cnt sm 1 |
| 3254 | put d_last sm i |
| 3255 | end |
| 3256 | nw = gu b add q 3 |
| 3257 | for k ulong nw |
| 3258 | w = gi b add add q 4 k |
| 3259 | if ne w s |
| 3260 | if and ge w k_b lt w add k_b n |
| 3261 | wm = sub w k_b |
| 3262 | put d_cnt wm add get d_cnt wm 1 |
| 3263 | put d_last wm i |
| 3264 | end |
| 3265 | end |
| 3266 | end |
| 3267 | end |
| 3268 | base = add 4 p |
| 3269 | for m ulong n |
| 3270 | last = get d_last m |
| 3271 | age = sub k_b 1 |
| 3272 | if lt last 1000 |
| 3273 | pt = gi b add get d_po last 1 |
| 3274 | if gt pt k_b |
| 3275 | age = k_b |
| 3276 | if gt now pt |
| 3277 | age = add k_b sub now pt |
| 3278 | end |
| 3279 | end |
| 3280 | end |
| 3281 | st = swstate get d_kill m get d_turn m get d_wake m roster age |
| 3282 | idle = sub k_b 1 |
| 3283 | if eq roster add k_b 1 |
| 3284 | lm = get d_lm m |
| 3285 | if gt lm k_b |
| 3286 | idle = k_b |
| 3287 | if gt now lm |
| 3288 | idle = add k_b sub now lm |
| 3289 | end |
| 3290 | end |
| 3291 | end |
| 3292 | put d_state m st |
| 3293 | put d_att m swatt add k_b st get d_fail m idle |
| 3294 | unr = sub k_b 1 |
| 3295 | if eq roster add k_b 1 |
| 3296 | lr = get d_lr m |
| 3297 | if ge lr k_b |
| 3298 | unr = k_b |
| 3299 | if gt head lr |
| 3300 | unr = add k_b sub head lr |
| 3301 | end |
| 3302 | end |
| 3303 | end |
| 3304 | po ob add base m add k_b get d_cnt m |
| 3305 | lp = sub k_b 1 |
| 3306 | if lt last 1000 |
| 3307 | lp = add k_b last |
| 3308 | end |
| 3309 | po ob add add base n m lp |
| 3310 | po ob add add base mul n 2 m add k_b st |
| 3311 | po ob add add base mul n 3 m add k_b get d_att m |
| 3312 | po ob add add base mul n 4 m idle |
| 3313 | po ob add add base mul n 5 m unr |
| 3314 | hp = ulong 0 |
| 3315 | if eq get d_role m 2 |
| 3316 | hp = 1 |
| 3317 | end |
| 3318 | po ob add add base mul n 6 m add k_b hp |
| 3319 | end |
| 3320 | working = ulong 0 |
| 3321 | waiting = ulong 0 |
| 3322 | stopped = ulong 0 |
| 3323 | for m ulong n |
| 3324 | on = ulong 1000 |
| 3325 | seq = k_b |
| 3326 | you = k_b |
| 3327 | last = get d_last m |
| 3328 | if and lt last 1000 ne get d_state m 3 |
| 3329 | q = get d_po last |
| 3330 | nw = gu b add q 3 |
| 3331 | nd = gu b add add q 4 nw |
| 3332 | t0 = add add q 5 nw |
| 3333 | if gt nd 0 |
| 3334 | answered = false |
| 3335 | j = add last 1 |
| 3336 | while lt j p bound 512 |
| 3337 | if answered |
| 3338 | break |
| 3339 | end |
| 3340 | qj = get d_po j |
| 3341 | sj = gi b add qj 2 |
| 3342 | nwj = gu b add qj 3 |
| 3343 | for k ulong nd |
| 3344 | tk = gi b add t0 k |
| 3345 | if eq tk sj |
| 3346 | answered = true |
| 3347 | end |
| 3348 | for k2 ulong nwj |
| 3349 | if eq tk gi b add add qj 4 k2 |
| 3350 | answered = true |
| 3351 | end |
| 3352 | end |
| 3353 | end |
| 3354 | j = add j 1 |
| 3355 | end |
| 3356 | if not answered |
| 3357 | for k ulong nd |
| 3358 | tk = gi b add t0 k |
| 3359 | if and ge tk k_b lt tk add k_b n |
| 3360 | tm2 = sub tk k_b |
| 3361 | if eq get d_own tm2 add k_b 1 |
| 3362 | you = gi b q |
| 3363 | else |
| 3364 | if and eq on 1000 ne get d_state tm2 3 |
| 3365 | on = tm2 |
| 3366 | end |
| 3367 | end |
| 3368 | end |
| 3369 | end |
| 3370 | if lt on 1000 |
| 3371 | seq = gi b q |
| 3372 | end |
| 3373 | end |
| 3374 | end |
| 3375 | end |
| 3376 | wo = sub k_b 1 |
| 3377 | won = ulong 0 |
| 3378 | if lt on 1000 |
| 3379 | wo = add k_b on |
| 3380 | won = 1 |
| 3381 | end |
| 3382 | asks = ulong 0 |
| 3383 | if gt you k_b |
| 3384 | asks = 1 |
| 3385 | end |
| 3386 | g = swgroup add k_b get d_state m add k_b get d_att m add k_b asks add k_b won |
| 3387 | put d_grp m g |
| 3388 | po ob add add base mul n 7 m wo |
| 3389 | po ob add add base mul n 8 m seq |
| 3390 | po ob add add base mul n 9 m you |
| 3391 | po ob add add base mul n 10 m add k_b g |
| 3392 | if ne get d_role m 2 |
| 3393 | if eq get d_state m 1 |
| 3394 | working = add working 1 |
| 3395 | else |
| 3396 | if eq get d_state m 2 |
| 3397 | waiting = add waiting 1 |
| 3398 | else |
| 3399 | stopped = add stopped 1 |
| 3400 | end |
| 3401 | end |
| 3402 | end |
| 3403 | end |
| 3404 | po ob 1 add k_b working |
| 3405 | po ob 2 add k_b waiting |
| 3406 | po ob 3 add k_b stopped |
| 3407 | for pass2 ulong 2 |
| 3408 | for m ulong n |
| 3409 | v = get d_grp m |
| 3410 | if eq pass2 1 |
| 3411 | v = get d_state m |
| 3412 | end |
| 3413 | if ne roster add k_b 1 |
| 3414 | v = mul v 2 |
| 3415 | if eq get d_cnt m 0 |
| 3416 | v = add v 1 |
| 3417 | end |
| 3418 | end |
| 3419 | put d_key m v |
| 3420 | end |
| 3421 | sworder b n |
| 3422 | for m ulong n |
| 3423 | po ob add add base mul n add 11 pass2 m add k_b get d_ord m |
| 3424 | end |
| 3425 | end |
| 3426 | ret add base mul n 13 |
| 3427 | end |
| 3428 | |
| 3429 | note op 12: who addressed whom in the first posts, for the graph. Numbers: the members n, upTo, how many posts |
| 3430 | note have a sender, how many helper flags, how many posts have their co-signers, their addressed members and |
| 3431 | note their to-all flag; then the helper flags (n); then a post each: sender, how many co-signers (4 at most) and |
| 3432 | note who, how many addressed members and who, 1 when it is to all. Helpers are left out. The answer is bytes, |
| 3433 | note six a pair in order of sender then receiver: from, to, how many posts named the receiver (16-bit), how many |
| 3434 | note reached it only because the post was for everyone (16-bit). Returns the reply length |
| 3435 | fn swedges b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 3436 | named = new ulong 96 0 |
| 3437 | if lt c 7 |
| 3438 | ret 0 |
| 3439 | end |
| 3440 | nn = gi b 0 |
| 3441 | if or le nn k_b gt nn add k_b 96 |
| 3442 | ret 0 |
| 3443 | end |
| 3444 | n = sub nn k_b |
| 3445 | upto = gi b 1 |
| 3446 | posts = gu b 2 |
| 3447 | if gt posts 100000 |
| 3448 | ret 0 |
| 3449 | end |
| 3450 | if lt upto add k_b posts |
| 3451 | posts = ulong 0 |
| 3452 | if gt upto k_b |
| 3453 | posts = sub upto k_b |
| 3454 | end |
| 3455 | end |
| 3456 | if or gt posts 400 ne gi b 3 nn |
| 3457 | ret 0 |
| 3458 | end |
| 3459 | if or or lt gi b 4 add k_b posts lt gi b 5 add k_b posts lt gi b 6 add k_b posts |
| 3460 | ret 0 |
| 3461 | end |
| 3462 | for z ulong mul n n |
| 3463 | put d_cell z 0 |
| 3464 | put d_cell add 9216 z 0 |
| 3465 | end |
| 3466 | hb = ulong 7 |
| 3467 | q = add 7 n |
| 3468 | if gt q c |
| 3469 | ret 0 |
| 3470 | end |
| 3471 | for i ulong posts |
| 3472 | if gt add q 2 c |
| 3473 | ret 0 |
| 3474 | end |
| 3475 | s0 = gi b q |
| 3476 | nw = gu b add q 1 |
| 3477 | if gt nw 4 |
| 3478 | ret 0 |
| 3479 | end |
| 3480 | if gt add add q 3 nw c |
| 3481 | ret 0 |
| 3482 | end |
| 3483 | nd = gu b add add q 2 nw |
| 3484 | if gt nd 96 |
| 3485 | ret 0 |
| 3486 | end |
| 3487 | dq = add add q 3 nw |
| 3488 | if gt add add dq nd 1 c |
| 3489 | ret 0 |
| 3490 | end |
| 3491 | tall = gi b add dq nd |
| 3492 | for s ulong add nw 1 |
| 3493 | from = s0 |
| 3494 | if gt s 0 |
| 3495 | from = gi b add add q 2 sub s 1 |
| 3496 | end |
| 3497 | okf = and ge from k_b lt from add k_b n |
| 3498 | if okf |
| 3499 | if ne gi b add hb sub from k_b k_b |
| 3500 | okf = false |
| 3501 | end |
| 3502 | end |
| 3503 | if okf |
| 3504 | if gt s 0 |
| 3505 | if eq from s0 |
| 3506 | okf = false |
| 3507 | end |
| 3508 | end |
| 3509 | end |
| 3510 | if okf |
| 3511 | f = sub from k_b |
| 3512 | for z ulong n |
| 3513 | put named z 0 |
| 3514 | end |
| 3515 | for k ulong nd |
| 3516 | if lt k n |
| 3517 | tv = gi b add dq k |
| 3518 | if and ge tv k_b lt tv add k_b n |
| 3519 | tt = sub tv k_b |
| 3520 | if and ne tt f eq gi b add hb tt k_b |
| 3521 | if eq get named tt 0 |
| 3522 | put named tt 1 |
| 3523 | put d_cell add mul f n tt add get d_cell add mul f n tt 1 |
| 3524 | end |
| 3525 | end |
| 3526 | end |
| 3527 | end |
| 3528 | end |
| 3529 | if eq tall add k_b 1 |
| 3530 | for tt ulong n |
| 3531 | if and ne tt f eq gi b add hb tt k_b |
| 3532 | if eq get named tt 0 |
| 3533 | put d_cell add 9216 add mul f n tt add get d_cell add 9216 add mul f n tt 1 |
| 3534 | end |
| 3535 | end |
| 3536 | end |
| 3537 | end |
| 3538 | end |
| 3539 | end |
| 3540 | q = add add dq nd 1 |
| 3541 | end |
| 3542 | o = ulong 8 |
| 3543 | for cell ulong mul n n |
| 3544 | dv = get d_cell cell |
| 3545 | av = get d_cell add 9216 cell |
| 3546 | if gt add dv av 0 |
| 3547 | put ob o uchar div cell n |
| 3548 | put ob add o 1 uchar rem cell n |
| 3549 | put ob add o 2 uchar and dv 255 |
| 3550 | put ob add o 3 uchar and shr dv 8 255 |
| 3551 | put ob add o 4 uchar and av 255 |
| 3552 | put ob add o 5 uchar and shr av 8 255 |
| 3553 | o = add o 6 |
| 3554 | end |
| 3555 | end |
| 3556 | ret sub o 8 |
| 3557 | end |
| 3558 | |
| 3559 | note op 14: which members to draw when there are too many for one picture: the keep members with the most posts |
| 3560 | note to or from others (the earlier member wins a tie). Numbers: the members n, 1 to count posts for everyone |
| 3561 | note too, keep, how many edge numbers follow, then the edges, five numbers a row: from, to, count, direct, to all. |
| 3562 | note The answer is a byte a member, 1 when it is picked; a member with no line is never picked |
| 3563 | fn swbusy b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 3564 | weight = new ulong 96 0 |
| 3565 | flag = new ulong 96 0 |
| 3566 | if lt c 4 |
| 3567 | ret 0 |
| 3568 | end |
| 3569 | nn = gi b 0 |
| 3570 | if or le nn k_b gt nn add k_b 96 |
| 3571 | ret 0 |
| 3572 | end |
| 3573 | n = sub nn k_b |
| 3574 | ne2 = gu b 3 |
| 3575 | if ne c add 4 ne2 |
| 3576 | ret 0 |
| 3577 | end |
| 3578 | e = ulong 0 |
| 3579 | while lt add e 4 ne2 bound 16384 |
| 3580 | if ge e 46080 |
| 3581 | break |
| 3582 | end |
| 3583 | from = gi b add 4 e |
| 3584 | tv = gi b add 5 e |
| 3585 | cv = gi b add 7 e |
| 3586 | if eq gi b 1 add k_b 1 |
| 3587 | cv = gi b add 6 e |
| 3588 | end |
| 3589 | if and and ge from k_b lt from add k_b n and ge tv k_b lt tv add k_b n |
| 3590 | if ge cv k_b |
| 3591 | put weight sub from k_b add get weight sub from k_b sub cv k_b |
| 3592 | put weight sub tv k_b add get weight sub tv k_b sub cv k_b |
| 3593 | end |
| 3594 | end |
| 3595 | e = add e 5 |
| 3596 | end |
| 3597 | keep = gi b 2 |
| 3598 | picked = ulong 0 |
| 3599 | while lt picked n bound 128 |
| 3600 | if ge add k_b picked keep |
| 3601 | break |
| 3602 | end |
| 3603 | best = ulong 1000 |
| 3604 | for m ulong n |
| 3605 | if and eq get flag m 0 gt get weight m 0 |
| 3606 | if eq best 1000 |
| 3607 | best = m |
| 3608 | else |
| 3609 | if gt get weight m get weight best |
| 3610 | best = m |
| 3611 | end |
| 3612 | end |
| 3613 | end |
| 3614 | end |
| 3615 | if eq best 1000 |
| 3616 | break |
| 3617 | end |
| 3618 | put flag best 1 |
| 3619 | picked = add picked 1 |
| 3620 | end |
| 3621 | for m ulong n |
| 3622 | put ob add 8 m uchar get flag m |
| 3623 | end |
| 3624 | ret n |
| 3625 | end |
| 3626 | |
| 3627 | note op 13: how many of the first posts each member sent to everyone. Numbers: the members n, upTo, how many posts |
| 3628 | note have a sender and how many have a to-all flag, then a post each: sender, 1 when it is to all. The answer is n |
| 3629 | note numbers (none when n is not 1 to 96). Returns the count of numbers |
| 3630 | fn swbroad b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 3631 | outv = new ulong 96 0 |
| 3632 | if lt c 4 |
| 3633 | ret 0 |
| 3634 | end |
| 3635 | nn = gi b 0 |
| 3636 | if or le nn k_b gt nn add k_b 96 |
| 3637 | ret 0 |
| 3638 | end |
| 3639 | n = sub nn k_b |
| 3640 | posts = gu b 2 |
| 3641 | if gt posts 100000 |
| 3642 | posts = ulong 100000 |
| 3643 | end |
| 3644 | upto = gi b 1 |
| 3645 | if lt upto add k_b posts |
| 3646 | posts = ulong 0 |
| 3647 | if gt upto k_b |
| 3648 | posts = sub upto k_b |
| 3649 | end |
| 3650 | end |
| 3651 | na = gu b 3 |
| 3652 | i = ulong 0 |
| 3653 | while lt i posts bound 512 |
| 3654 | if or ge i 400 ge i na |
| 3655 | break |
| 3656 | end |
| 3657 | if gt add 6 mul i 2 c |
| 3658 | break |
| 3659 | end |
| 3660 | s = gi b add 4 mul i 2 |
| 3661 | if eq gi b add 5 mul i 2 add k_b 1 |
| 3662 | if and ge s k_b lt s add k_b n |
| 3663 | put outv sub s k_b add get outv sub s k_b 1 |
| 3664 | end |
| 3665 | end |
| 3666 | i = add i 1 |
| 3667 | end |
| 3668 | for m ulong n |
| 3669 | po ob m add k_b get outv m |
| 3670 | end |
| 3671 | ret n |
| 3672 | end |
| 3673 | |
| 3674 | note ---- the one box: which rows it shows for a typed text, and in which order (kind 7 op 17) ---- |
| 3675 | note Numbers: 0 the characters of the typed text (trimmed, lower case), 1 its bytes, 2 a web address (0 no, 1 typed |
| 3676 | note with its scheme, 2 bare), 3 1 when this Mac has finished searching its files, 4 1 when a file has exactly that |
| 3677 | note name, 5 1 for a question, 6 1 when a sentence may go to the agent; 7 to 12 the counts of apps, files, |
| 3678 | note screens, commands, accounts and copied things; then four an app (how well it matched, how much it is used, |
| 3679 | note its lift from habit, 1 when it was in front before), three a file (its match, its use, 1 when it is an app |
| 3680 | note already listed), two an account (1 when its name holds the text, 1 when it starts with it), one a copied |
| 3681 | note thing (1 when pinned); then for each screen and each command a count of words and their lengths. Bytes: the |
| 3682 | note text, then those words. The rows: the 8 best apps (match + 40 + use + half the lift + 10 for the one in |
| 3683 | note front before); the address (150 with a scheme; bare, only after the file search: 95, or 3 when a file has |
| 3684 | note that name); from 2 characters a screen (230 named, 125 a word starts so), a command (220; 110 from 3 |
| 3685 | note characters when a word starts so) and each matching account (95 when it starts so, else 70); the first 8 |
| 3686 | note copied things (85 less the place, 10 more when pinned); the first 12 files that are not apps (match + use); |
| 3687 | note Ask (1000 for a question, else 2); the agent (999 when nothing else matched, it is not a question and a |
| 3688 | note sentence may go to it, else 1). Highest first; equal rows stay in this order. |
| 3689 | note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 screen, 4 command, |
| 3690 | note 5 account, 6 copied, 7 file, 8 ask, 9 agent), its place in its list, its score, 1 for the promoted agent |
| 3691 | global r_kind ulong 1024 |
| 3692 | global r_idx ulong 1024 |
| 3693 | global r_score ulong 1024 |
| 3694 | global r_flag ulong 1024 |
| 3695 | global r_as ulong 2048 |
| 3696 | global r_ao ulong 2048 |
| 3697 | |
| 3698 | fn rkadd n ulong kind ulong idx ulong score ulong flag ulong to ulong |
| 3699 | if ge n 1024 |
| 3700 | ret n |
| 3701 | end |
| 3702 | put r_kind n kind |
| 3703 | put r_idx n idx |
| 3704 | put r_score n score |
| 3705 | put r_flag n flag |
| 3706 | ret add n 1 |
| 3707 | end |
| 3708 | |
| 3709 | note half of a number as it travels, toward zero |
| 3710 | fn rkhalf v ulong to ulong |
| 3711 | if ge v k_b |
| 3712 | ret add k_b div sub v k_b 2 |
| 3713 | end |
| 3714 | ret sub k_b div sub k_b v 2 |
| 3715 | end |
| 3716 | |
| 3717 | note the wl bytes at w against the ll bytes of the typed text at lo: equal (md 0), or starting with it (md 1) |
| 3718 | fn rkword b view uchar 1048576 w ulong wl ulong lo ulong ll ulong md ulong to bool |
| 3719 | if eq md 0 |
| 3720 | if ne wl ll |
| 3721 | ret false |
| 3722 | end |
| 3723 | else |
| 3724 | if lt wl ll |
| 3725 | ret false |
| 3726 | end |
| 3727 | end |
| 3728 | i = ulong 0 |
| 3729 | while lt i ll bound 999999 |
| 3730 | if ne ulong get b add w i ulong get b add lo i |
| 3731 | ret false |
| 3732 | end |
| 3733 | i = add i 1 |
| 3734 | end |
| 3735 | ret true |
| 3736 | end |
| 3737 | |
| 3738 | note the n rows, highest score first (equal rows stay in their order), as the answer: the count, then four numbers |
| 3739 | note a row (kind, place, score, flag); how many numbers that is |
| 3740 | fn rkout n ulong ob edit uchar 65544 to ulong |
| 3741 | for i ulong n |
| 3742 | s = get r_score i |
| 3743 | pos = i |
| 3744 | while gt pos 0 bound 2048 |
| 3745 | p = get r_ao sub pos 1 |
| 3746 | if ge get r_score p s |
| 3747 | break |
| 3748 | end |
| 3749 | put r_ao pos p |
| 3750 | pos = sub pos 1 |
| 3751 | end |
| 3752 | put r_ao pos i |
| 3753 | end |
| 3754 | po ob 0 add k_b n |
| 3755 | for i ulong n |
| 3756 | x = get r_ao i |
| 3757 | o = add 1 mul i 4 |
| 3758 | po ob o add k_b get r_kind x |
| 3759 | po ob add o 1 add k_b get r_idx x |
| 3760 | po ob add o 2 get r_score x |
| 3761 | po ob add o 3 add k_b get r_flag x |
| 3762 | end |
| 3763 | ret add 1 mul n 4 |
| 3764 | end |
| 3765 | |
| 3766 | fn swrank b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 3767 | if lt c 13 |
| 3768 | ret 0 |
| 3769 | end |
| 3770 | lcn = gu b 0 |
| 3771 | ll = gu b 1 |
| 3772 | na = gu b 7 |
| 3773 | nf = gu b 8 |
| 3774 | ns = gu b 9 |
| 3775 | nc = gu b 10 |
| 3776 | nacc = gu b 11 |
| 3777 | ncl = gu b 12 |
| 3778 | if or or gt na 2048 gt nf 4000 or gt ns 32 gt nc 32 |
| 3779 | ret 0 |
| 3780 | end |
| 3781 | if or gt nacc 800 or gt ncl 64 gt ll 100000 |
| 3782 | ret 0 |
| 3783 | end |
| 3784 | pa = ulong 13 |
| 3785 | pf = add pa mul na 4 |
| 3786 | pacc = add pf mul nf 3 |
| 3787 | pcl = add pacc mul nacc 2 |
| 3788 | q = add pcl ncl |
| 3789 | if gt q c |
| 3790 | ret 0 |
| 3791 | end |
| 3792 | lo = add 8 mul c 8 |
| 3793 | tend = add lo nbytes |
| 3794 | wp = add lo ll |
| 3795 | if gt wp tend |
| 3796 | ret 0 |
| 3797 | end |
| 3798 | n = ulong 0 |
| 3799 | for i ulong na |
| 3800 | o = add pa mul i 4 |
| 3801 | s = sub add add add gi b o gi b add o 1 rkhalf gi b add o 2 40 mul 2 k_b |
| 3802 | if eq gi b add o 3 add k_b 1 |
| 3803 | s = add s 10 |
| 3804 | end |
| 3805 | put r_as i s |
| 3806 | pos = i |
| 3807 | while gt pos 0 bound 4096 |
| 3808 | p = get r_ao sub pos 1 |
| 3809 | if ge get r_as p s |
| 3810 | break |
| 3811 | end |
| 3812 | put r_ao pos p |
| 3813 | pos = sub pos 1 |
| 3814 | end |
| 3815 | put r_ao pos i |
| 3816 | end |
| 3817 | for i ulong na |
| 3818 | if lt i 8 |
| 3819 | n = rkadd n 1 get r_ao i get r_as get r_ao i 0 |
| 3820 | end |
| 3821 | end |
| 3822 | adr = gi b 2 |
| 3823 | if eq adr add k_b 1 |
| 3824 | n = rkadd n 2 0 add k_b 150 0 |
| 3825 | end |
| 3826 | if and eq adr add k_b 2 eq gi b 3 add k_b 1 |
| 3827 | sc = add k_b 95 |
| 3828 | if eq gi b 4 add k_b 1 |
| 3829 | sc = add k_b 3 |
| 3830 | end |
| 3831 | n = rkadd n 2 0 sc 0 |
| 3832 | end |
| 3833 | for pass3 ulong 2 |
| 3834 | cntw = ns |
| 3835 | if eq pass3 1 |
| 3836 | cntw = nc |
| 3837 | end |
| 3838 | for k ulong cntw |
| 3839 | if ge q c |
| 3840 | ret 0 |
| 3841 | end |
| 3842 | nw = gu b q |
| 3843 | q = add q 1 |
| 3844 | if gt nw 64 |
| 3845 | ret 0 |
| 3846 | end |
| 3847 | exact = false |
| 3848 | pre = false |
| 3849 | for w ulong nw |
| 3850 | if ge q c |
| 3851 | ret 0 |
| 3852 | end |
| 3853 | wl = gu b q |
| 3854 | q = add q 1 |
| 3855 | if gt add wp wl tend |
| 3856 | ret 0 |
| 3857 | end |
| 3858 | if rkword b wp wl lo ll 0 |
| 3859 | exact = true |
| 3860 | end |
| 3861 | if rkword b wp wl lo ll 1 |
| 3862 | pre = true |
| 3863 | end |
| 3864 | wp = add wp wl |
| 3865 | end |
| 3866 | if ge lcn 2 |
| 3867 | if eq pass3 0 |
| 3868 | if exact |
| 3869 | n = rkadd n 3 k add k_b 230 0 |
| 3870 | else |
| 3871 | if pre |
| 3872 | n = rkadd n 3 k add k_b 125 0 |
| 3873 | end |
| 3874 | end |
| 3875 | else |
| 3876 | if exact |
| 3877 | n = rkadd n 4 k add k_b 220 0 |
| 3878 | else |
| 3879 | if and pre ge lcn 3 |
| 3880 | n = rkadd n 4 k add k_b 110 0 |
| 3881 | end |
| 3882 | end |
| 3883 | end |
| 3884 | end |
| 3885 | end |
| 3886 | end |
| 3887 | if ge lcn 2 |
| 3888 | for i ulong nacc |
| 3889 | if eq gi b add pacc mul i 2 add k_b 1 |
| 3890 | sc = add k_b 70 |
| 3891 | if eq gi b add add pacc mul i 2 1 add k_b 1 |
| 3892 | sc = add k_b 95 |
| 3893 | end |
| 3894 | n = rkadd n 5 i sc 0 |
| 3895 | end |
| 3896 | end |
| 3897 | end |
| 3898 | for i ulong ncl |
| 3899 | if lt i 8 |
| 3900 | sc = sub add k_b 85 i |
| 3901 | if eq gi b add pcl i add k_b 1 |
| 3902 | sc = add sc 10 |
| 3903 | end |
| 3904 | n = rkadd n 6 i sc 0 |
| 3905 | end |
| 3906 | end |
| 3907 | shown = ulong 0 |
| 3908 | for i ulong nf |
| 3909 | o = add pf mul i 3 |
| 3910 | if and ne gi b add o 2 add k_b 1 lt shown 12 |
| 3911 | n = rkadd n 7 i sub add gi b o gi b add o 1 k_b 0 |
| 3912 | shown = add shown 1 |
| 3913 | end |
| 3914 | end |
| 3915 | nothing = eq n 0 |
| 3916 | quest = eq gi b 5 add k_b 1 |
| 3917 | sc = add k_b 2 |
| 3918 | if quest |
| 3919 | sc = add k_b 1000 |
| 3920 | end |
| 3921 | n = rkadd n 8 0 sc 0 |
| 3922 | prom = ulong 0 |
| 3923 | sc = add k_b 1 |
| 3924 | if and and not quest nothing eq gi b 6 add k_b 1 |
| 3925 | prom = 1 |
| 3926 | sc = add k_b 999 |
| 3927 | end |
| 3928 | n = rkadd n 9 0 sc prom |
| 3929 | ret rkout n ob |
| 3930 | end |
| 3931 | |
| 3932 | note ---- the one box before anything is typed: what to offer (kind 7 op 18) ---- |
| 3933 | note Numbers: 0 1 when something was copied, 1 how many seconds ago, 2 1 when it is a web address written with |
| 3934 | note http, 3 1 when the app in front is a browser, 4 how many other copied things follow (at most 20), 5 1 when |
| 3935 | note the clipboard history is paused, 6 the count of apps; then six an app: its lift from the app in front, its |
| 3936 | note lift from the hour, how much it is used, 1 when it is running, 1 when it was in front before, and its |
| 3937 | note points for being in front lately. The apps come in the order of their ids, which settles equal scores. |
| 3938 | note The rows: the copied thing (130 under a minute old, 95 under ten, else 70) and, for an address, a row to |
| 3939 | note open it (5 more, or 5 less when a browser is in front); the six best apps among those with a lift, some |
| 3940 | note use, running or in front before (40 + both lifts + a quarter of the use + 45 in front before + 8 running + |
| 3941 | note the points for lately); the other copied things (38 less the place); the clipboard screen at 39 when the |
| 3942 | note history is paused. Highest first; equal rows stay in this order. |
| 3943 | note The answer: the count of rows, then four numbers a row: its kind (1 app, 2 address, 3 the clipboard |
| 3944 | note screen, 6 copied), its place (an app's place in the list; 0 the newest copied thing, then 1 and up), its |
| 3945 | note score, and why it is offered (0 nothing said, 1 just copied, 2 the last thing copied, 3 a copied address, |
| 3946 | note 4 often opened from here, 5 just here, 6 often opened around now, 7 among the most used, 8 running now, |
| 3947 | note 9 the history is paused) |
| 3948 | global s_ps ulong 8 |
| 3949 | global s_pi ulong 8 |
| 3950 | global s_pw ulong 8 |
| 3951 | |
| 3952 | fn swsuggest b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 3953 | if lt c 7 |
| 3954 | ret 0 |
| 3955 | end |
| 3956 | rest = gu b 4 |
| 3957 | na = gu b 6 |
| 3958 | if or gt na 2048 gt rest 20 |
| 3959 | ret 0 |
| 3960 | end |
| 3961 | if ne c add 7 mul na 6 |
| 3962 | ret 0 |
| 3963 | end |
| 3964 | n = ulong 0 |
| 3965 | if eq gi b 0 add k_b 1 |
| 3966 | age = gi b 1 |
| 3967 | s = ulong 70 |
| 3968 | why = ulong 2 |
| 3969 | if lt age add k_b 600 |
| 3970 | s = 95 |
| 3971 | why = 1 |
| 3972 | end |
| 3973 | if lt age add k_b 60 |
| 3974 | s = 130 |
| 3975 | end |
| 3976 | n = rkadd n 6 0 add k_b s why |
| 3977 | if eq gi b 2 add k_b 1 |
| 3978 | if eq gi b 3 add k_b 1 |
| 3979 | n = rkadd n 2 0 add k_b sub s 5 3 |
| 3980 | else |
| 3981 | n = rkadd n 2 0 add k_b add s 5 3 |
| 3982 | end |
| 3983 | end |
| 3984 | end |
| 3985 | cnt = ulong 0 |
| 3986 | for i ulong na |
| 3987 | o = add 7 mul i 6 |
| 3988 | lf = gu b o |
| 3989 | lh = gu b add o 1 |
| 3990 | used = gu b add o 2 |
| 3991 | run = eq gi b add o 3 add k_b 1 |
| 3992 | prev = eq gi b add o 4 add k_b 1 |
| 3993 | lately = gu b add o 5 |
| 3994 | if or or gt add lf lh 0 gt used 0 or run prev |
| 3995 | sc = add add add 40 lf lh div used 4 |
| 3996 | if prev |
| 3997 | sc = add sc 45 |
| 3998 | end |
| 3999 | if run |
| 4000 | sc = add sc 8 |
| 4001 | end |
| 4002 | sc = add sc lately |
| 4003 | why = ulong 8 |
| 4004 | if gt used 0 |
| 4005 | why = 7 |
| 4006 | end |
| 4007 | if gt lh 0 |
| 4008 | why = 6 |
| 4009 | end |
| 4010 | if prev |
| 4011 | why = 5 |
| 4012 | end |
| 4013 | if gt lf 0 |
| 4014 | why = 4 |
| 4015 | end |
| 4016 | keep = true |
| 4017 | pos = cnt |
| 4018 | if eq cnt 6 |
| 4019 | if le sc get s_ps 5 |
| 4020 | keep = false |
| 4021 | end |
| 4022 | pos = 5 |
| 4023 | else |
| 4024 | cnt = add cnt 1 |
| 4025 | end |
| 4026 | if keep |
| 4027 | while gt pos 0 bound 8 |
| 4028 | if ge get s_ps sub pos 1 sc |
| 4029 | break |
| 4030 | end |
| 4031 | put s_ps pos get s_ps sub pos 1 |
| 4032 | put s_pi pos get s_pi sub pos 1 |
| 4033 | put s_pw pos get s_pw sub pos 1 |
| 4034 | pos = sub pos 1 |
| 4035 | end |
| 4036 | put s_ps pos sc |
| 4037 | put s_pi pos i |
| 4038 | put s_pw pos why |
| 4039 | end |
| 4040 | end |
| 4041 | end |
| 4042 | for j ulong cnt |
| 4043 | n = rkadd n 1 get s_pi j add k_b get s_ps j get s_pw j |
| 4044 | end |
| 4045 | for i ulong rest |
| 4046 | n = rkadd n 6 add 1 i add k_b sub 38 i 0 |
| 4047 | end |
| 4048 | if eq gi b 5 add k_b 1 |
| 4049 | n = rkadd n 3 0 add k_b 39 9 |
| 4050 | end |
| 4051 | ret rkout n ob |
| 4052 | end |
| 4053 | |
| 4054 | note ---- habits: how much an app is lifted by where and when it is usually opened (kind 7 op 19) ---- |
| 4055 | note Numbers: 0 the hour now, 1 1 when an app is in front, 2 the count of apps, 3 the count of remembered |
| 4056 | note launches; then three a launch: 1 when it was made from the app now in front, its hour, and which app it |
| 4057 | note opened (its place in the list, or -1 for an app not in it). A habit counts from the second time. An app's |
| 4058 | note lift from the app in front is 60 times its share of the launches made from there; its lift from the hour |
| 4059 | note is 25 times its share of the launches within an hour of now (23 and 0 are an hour apart). |
| 4060 | note The answer: the count of apps, then two numbers an app: the lift from the app in front, the lift from the hour |
| 4061 | fn swlifts b view uchar 1048576 c ulong ob edit uchar 65544 to ulong |
| 4062 | if lt c 4 |
| 4063 | ret 0 |
| 4064 | end |
| 4065 | hour = gi b 0 |
| 4066 | front = eq gi b 1 add k_b 1 |
| 4067 | na = gu b 2 |
| 4068 | nl = gu b 3 |
| 4069 | if or gt na 2048 gt nl 4096 |
| 4070 | ret 0 |
| 4071 | end |
| 4072 | if ne c add 4 mul nl 3 |
| 4073 | ret 0 |
| 4074 | end |
| 4075 | for i ulong na |
| 4076 | put r_as i 0 |
| 4077 | put r_ao i 0 |
| 4078 | end |
| 4079 | ft = ulong 0 |
| 4080 | nt = ulong 0 |
| 4081 | for j ulong nl |
| 4082 | o = add 4 mul j 3 |
| 4083 | here = and front eq gi b o add k_b 1 |
| 4084 | h = gi b add o 1 |
| 4085 | d = ulong 0 |
| 4086 | if ge h hour |
| 4087 | d = sub h hour |
| 4088 | else |
| 4089 | d = sub hour h |
| 4090 | end |
| 4091 | nearh = or le d 1 ge d 23 |
| 4092 | a = gi b add o 2 |
| 4093 | ix = na |
| 4094 | if ge a k_b |
| 4095 | if lt sub a k_b na |
| 4096 | ix = sub a k_b |
| 4097 | end |
| 4098 | end |
| 4099 | if here |
| 4100 | ft = add ft 1 |
| 4101 | if lt ix na |
| 4102 | put r_as ix add get r_as ix 1 |
| 4103 | end |
| 4104 | end |
| 4105 | if nearh |
| 4106 | nt = add nt 1 |
| 4107 | if lt ix na |
| 4108 | put r_ao ix add get r_ao ix 1 |
| 4109 | end |
| 4110 | end |
| 4111 | end |
| 4112 | po ob 0 add k_b na |
| 4113 | for i ulong na |
| 4114 | f = ulong 0 |
| 4115 | if ge get r_as i 2 |
| 4116 | f = div mul 60 get r_as i ft |
| 4117 | end |
| 4118 | g = ulong 0 |
| 4119 | if ge get r_ao i 2 |
| 4120 | g = div mul 25 get r_ao i nt |
| 4121 | end |
| 4122 | po ob add 1 mul i 2 add k_b f |
| 4123 | po ob add 2 mul i 2 add k_b g |
| 4124 | end |
| 4125 | ret add 1 mul na 2 |
| 4126 | end |
| 4127 | |
| 4128 | note ---- AES-256-GCM, for Hop's encrypted clipboard history (kind 7 op 20) ---- |
| 4129 | note The history is sealed as CryptoKit's AES.GCM seals it: a 256-bit key, a 12-byte nonce, no added data, a |
| 4130 | note 16-byte tag. This is that cipher in Omega: AES by its definition (the S-box is worked out, not listed), the |
| 4131 | note counter mode, and the tag by GHASH with a table of 16 multiples of the hash key. The work is done on |
| 4132 | note globals: the key in c_k, the nonce in c_n, the data in c_d (in place, 16 MiB at most), the tag in c_tg. fn gcunlock checks |
| 4133 | note the tag over the whole data before any of it is unsealed, and compares all 16 bytes whatever they are. It is |
| 4134 | note not written to run in the same time for every key (the tables are indexed by secret bytes): it is for |
| 4135 | note files on the person's own Mac, not for a service others can time. |
| 4136 | note Request: two numbers (1 to seal, 0 to unseal; the count of data bytes, 4096 at most), then the bytes: the |
| 4137 | note key, the nonce, the data, and to unseal the tag. Answer to unseal: 1 and the data's bytes, or 0 alone when |
| 4138 | note the tag is not the data's. Answer to seal: 1, the sealed bytes, the 16 bytes of the tag. |
| 4139 | global c_sb uchar 256 |
| 4140 | global c_m2 uchar 256 |
| 4141 | global c_l4 ulong 16 |
| 4142 | global c_rd ulong 1 |
| 4143 | global c_k uchar 32 |
| 4144 | global c_n uchar 12 |
| 4145 | global c_tg uchar 16 |
| 4146 | global c_rk uchar 240 |
| 4147 | global c_st uchar 16 |
| 4148 | global c_tm uchar 16 |
| 4149 | global c_y uchar 16 |
| 4150 | global c_x uchar 16 |
| 4151 | global c_hh ulong 16 |
| 4152 | global c_hl ulong 16 |
| 4153 | global c_d uchar 16777216 |
| 4154 | |
| 4155 | note the tables that do not depend on the key: the S-box (the inverse in the field, then the affine step), the |
| 4156 | note doubling in the field, and the 16 reductions of GHASH |
| 4157 | fn gcinit to void |
| 4158 | if eq get c_rd 0 1 |
| 4159 | ret |
| 4160 | end |
| 4161 | p = ulong 1 |
| 4162 | q = ulong 1 |
| 4163 | for i ulong 255 |
| 4164 | t = xor p shl p 1 |
| 4165 | if ne and p 128 0 |
| 4166 | t = xor t 27 |
| 4167 | end |
| 4168 | p = and t 255 |
| 4169 | q = and xor q shl q 1 255 |
| 4170 | q = and xor q shl q 2 255 |
| 4171 | q = and xor q shl q 4 255 |
| 4172 | if ne and q 128 0 |
| 4173 | q = xor q 9 |
| 4174 | end |
| 4175 | r1 = and or shl q 1 shr q 7 255 |
| 4176 | r2 = and or shl q 2 shr q 6 255 |
| 4177 | r3 = and or shl q 3 shr q 5 255 |
| 4178 | r4 = and or shl q 4 shr q 4 255 |
| 4179 | x = xor xor xor xor q r1 r2 r3 r4 |
| 4180 | put c_sb p uchar xor x 99 |
| 4181 | end |
| 4182 | put c_sb 0 99 |
| 4183 | for i ulong 256 |
| 4184 | d = shl i 1 |
| 4185 | if ne and i 128 0 |
| 4186 | d = xor d 27 |
| 4187 | end |
| 4188 | put c_m2 i uchar and d 255 |
| 4189 | end |
| 4190 | put c_l4 0 0 |
| 4191 | put c_l4 1 7200 |
| 4192 | put c_l4 2 14400 |
| 4193 | put c_l4 3 9312 |
| 4194 | put c_l4 4 28800 |
| 4195 | put c_l4 5 27808 |
| 4196 | put c_l4 6 18624 |
| 4197 | put c_l4 7 21728 |
| 4198 | put c_l4 8 57600 |
| 4199 | put c_l4 9 64800 |
| 4200 | put c_l4 10 55616 |
| 4201 | put c_l4 11 50528 |
| 4202 | put c_l4 12 37248 |
| 4203 | put c_l4 13 36256 |
| 4204 | put c_l4 14 43456 |
| 4205 | put c_l4 15 46560 |
| 4206 | put c_rd 0 1 |
| 4207 | end |
| 4208 | |
| 4209 | note the cipher on the 16 bytes of c_st, with the round keys of c_rk |
| 4210 | fn gcblk to void |
| 4211 | for i ulong 16 |
| 4212 | put c_st i uchar xor ulong get c_st i ulong get c_rk i |
| 4213 | end |
| 4214 | for r ulong 14 |
| 4215 | rk = mul add r 1 16 |
| 4216 | for cc ulong 4 |
| 4217 | for w ulong 4 |
| 4218 | put c_tm add mul cc 4 w get c_sb ulong get c_st add mul and add cc w 3 4 w |
| 4219 | end |
| 4220 | end |
| 4221 | if lt r 13 |
| 4222 | for cc ulong 4 |
| 4223 | o = mul cc 4 |
| 4224 | a0 = ulong get c_tm o |
| 4225 | a1 = ulong get c_tm add o 1 |
| 4226 | a2 = ulong get c_tm add o 2 |
| 4227 | a3 = ulong get c_tm add o 3 |
| 4228 | d0 = ulong get c_m2 a0 |
| 4229 | d1 = ulong get c_m2 a1 |
| 4230 | d2 = ulong get c_m2 a2 |
| 4231 | d3 = ulong get c_m2 a3 |
| 4232 | put c_st o uchar xor xor xor xor xor d0 d1 a1 a2 a3 ulong get c_rk add rk o |
| 4233 | put c_st add o 1 uchar xor xor xor xor xor a0 d1 d2 a2 a3 ulong get c_rk add rk add o 1 |
| 4234 | put c_st add o 2 uchar xor xor xor xor xor a0 a1 d2 d3 a3 ulong get c_rk add rk add o 2 |
| 4235 | put c_st add o 3 uchar xor xor xor xor xor d0 a0 a1 a2 d3 ulong get c_rk add rk add o 3 |
| 4236 | end |
| 4237 | else |
| 4238 | for i ulong 16 |
| 4239 | put c_st i uchar xor ulong get c_tm i ulong get c_rk add rk i |
| 4240 | end |
| 4241 | end |
| 4242 | end |
| 4243 | end |
| 4244 | |
| 4245 | note the key of c_k: its 15 round keys into c_rk, and the 16 multiples of the hash key (the cipher of 16 zero |
| 4246 | note bytes) into c_hh and c_hl |
| 4247 | fn gckey to void |
| 4248 | gcinit |
| 4249 | for i ulong 32 |
| 4250 | put c_rk i get c_k i |
| 4251 | end |
| 4252 | rc = ulong 1 |
| 4253 | for w ulong 52 |
| 4254 | i = add w 8 |
| 4255 | o = mul i 4 |
| 4256 | t0 = ulong get c_rk sub o 4 |
| 4257 | t1 = ulong get c_rk sub o 3 |
| 4258 | t2 = ulong get c_rk sub o 2 |
| 4259 | t3 = ulong get c_rk sub o 1 |
| 4260 | if eq and i 7 0 |
| 4261 | u0 = xor ulong get c_sb t1 rc |
| 4262 | u1 = ulong get c_sb t2 |
| 4263 | u2 = ulong get c_sb t3 |
| 4264 | u3 = ulong get c_sb t0 |
| 4265 | rc = ulong get c_m2 rc |
| 4266 | t0 = u0 |
| 4267 | t1 = u1 |
| 4268 | t2 = u2 |
| 4269 | t3 = u3 |
| 4270 | end |
| 4271 | if eq and i 7 4 |
| 4272 | t0 = ulong get c_sb t0 |
| 4273 | t1 = ulong get c_sb t1 |
| 4274 | t2 = ulong get c_sb t2 |
| 4275 | t3 = ulong get c_sb t3 |
| 4276 | end |
| 4277 | put c_rk o uchar xor ulong get c_rk sub o 32 t0 |
| 4278 | put c_rk add o 1 uchar xor ulong get c_rk sub o 31 t1 |
| 4279 | put c_rk add o 2 uchar xor ulong get c_rk sub o 30 t2 |
| 4280 | put c_rk add o 3 uchar xor ulong get c_rk sub o 29 t3 |
| 4281 | end |
| 4282 | for i ulong 16 |
| 4283 | put c_st i 0 |
| 4284 | end |
| 4285 | gcblk |
| 4286 | vh = ulong 0 |
| 4287 | vl = ulong 0 |
| 4288 | for i ulong 8 |
| 4289 | vh = or shl vh 8 ulong get c_st i |
| 4290 | vl = or shl vl 8 ulong get c_st add 8 i |
| 4291 | end |
| 4292 | put c_hh 0 0 |
| 4293 | put c_hl 0 0 |
| 4294 | put c_hh 8 vh |
| 4295 | put c_hl 8 vl |
| 4296 | ix = ulong 4 |
| 4297 | for s ulong 3 |
| 4298 | tt = ulong 0 |
| 4299 | if ne and vl 1 0 |
| 4300 | tt = 16212958658533785600 |
| 4301 | end |
| 4302 | vl = or shl vh 63 shr vl 1 |
| 4303 | vh = xor shr vh 1 tt |
| 4304 | put c_hl ix vl |
| 4305 | put c_hh ix vh |
| 4306 | ix = shr ix 1 |
| 4307 | end |
| 4308 | ix = 2 |
| 4309 | for s ulong 3 |
| 4310 | for j ulong sub ix 1 |
| 4311 | jj = add j 1 |
| 4312 | put c_hh add ix jj xor get c_hh ix get c_hh jj |
| 4313 | put c_hl add ix jj xor get c_hl ix get c_hl jj |
| 4314 | end |
| 4315 | ix = shl ix 1 |
| 4316 | end |
| 4317 | end |
| 4318 | |
| 4319 | note c_y times the hash key, in the field of GHASH |
| 4320 | fn gcmul to void |
| 4321 | nlo = and ulong get c_y 15 15 |
| 4322 | zh = get c_hh nlo |
| 4323 | zl = get c_hl nlo |
| 4324 | for s ulong 16 |
| 4325 | bv = ulong get c_y sub 15 s |
| 4326 | nlo = and bv 15 |
| 4327 | nhi = shr bv 4 |
| 4328 | if ne s 0 |
| 4329 | r4 = and zl 15 |
| 4330 | zl = or shl zh 60 shr zl 4 |
| 4331 | zh = xor shr zh 4 shl get c_l4 r4 48 |
| 4332 | zh = xor zh get c_hh nlo |
| 4333 | zl = xor zl get c_hl nlo |
| 4334 | end |
| 4335 | r4 = and zl 15 |
| 4336 | zl = or shl zh 60 shr zl 4 |
| 4337 | zh = xor shr zh 4 shl get c_l4 r4 48 |
| 4338 | zh = xor zh get c_hh nhi |
| 4339 | zl = xor zl get c_hl nhi |
| 4340 | end |
| 4341 | for i ulong 8 |
| 4342 | sh = mul sub 7 i 8 |
| 4343 | put c_y i uchar and shr zh sh 255 |
| 4344 | put c_y add 8 i uchar and shr zl sh 255 |
| 4345 | end |
| 4346 | end |
| 4347 | |
| 4348 | note the tag of the n sealed bytes of c_d under the key and the nonce, into c_x |
| 4349 | fn gctag n ulong to void |
| 4350 | for i ulong 16 |
| 4351 | put c_y i 0 |
| 4352 | end |
| 4353 | nb = div add n 15 16 |
| 4354 | bk = ulong 0 |
| 4355 | for seg ulong 17 |
| 4356 | while and lt bk nb lt bk mul add seg 1 65536 bound 70000 |
| 4357 | o = mul bk 16 |
| 4358 | m = sub n o |
| 4359 | if gt m 16 |
| 4360 | m = 16 |
| 4361 | end |
| 4362 | for j ulong m bound 16 |
| 4363 | put c_y j uchar xor ulong get c_y j ulong get c_d add o j |
| 4364 | end |
| 4365 | gcmul |
| 4366 | bk = add bk 1 |
| 4367 | end |
| 4368 | end |
| 4369 | bits = mul n 8 |
| 4370 | for j ulong 8 |
| 4371 | put c_y add 8 j uchar xor ulong get c_y add 8 j and shr bits mul sub 7 j 8 255 |
| 4372 | end |
| 4373 | gcmul |
| 4374 | for i ulong 12 |
| 4375 | put c_st i get c_n i |
| 4376 | end |
| 4377 | put c_st 12 0 |
| 4378 | put c_st 13 0 |
| 4379 | put c_st 14 0 |
| 4380 | put c_st 15 1 |
| 4381 | gcblk |
| 4382 | for i ulong 16 |
| 4383 | put c_x i uchar xor ulong get c_st i ulong get c_y i |
| 4384 | end |
| 4385 | end |
| 4386 | |
| 4387 | note the n bytes of c_d through the counter mode (sealing and unsealing are the same) |
| 4388 | fn gcctr n ulong to void |
| 4389 | ctr = ulong 2 |
| 4390 | nb = div add n 15 16 |
| 4391 | bk = ulong 0 |
| 4392 | for seg ulong 17 |
| 4393 | while and lt bk nb lt bk mul add seg 1 65536 bound 70000 |
| 4394 | for i ulong 12 |
| 4395 | put c_st i get c_n i |
| 4396 | end |
| 4397 | put c_st 12 uchar and shr ctr 24 255 |
| 4398 | put c_st 13 uchar and shr ctr 16 255 |
| 4399 | put c_st 14 uchar and shr ctr 8 255 |
| 4400 | put c_st 15 uchar and ctr 255 |
| 4401 | gcblk |
| 4402 | o = mul bk 16 |
| 4403 | m = sub n o |
| 4404 | if gt m 16 |
| 4405 | m = 16 |
| 4406 | end |
| 4407 | for j ulong m bound 16 |
| 4408 | put c_d add o j uchar xor ulong get c_d add o j ulong get c_st j |
| 4409 | end |
| 4410 | ctr = add ctr 1 |
| 4411 | bk = add bk 1 |
| 4412 | end |
| 4413 | end |
| 4414 | end |
| 4415 | |
| 4416 | note unseal the n bytes of c_d: 1 and they are the data when c_tg is their tag, else 0 and they are untouched |
| 4417 | fn gcunlock n ulong to ulong |
| 4418 | if gt n 16777216 |
| 4419 | ret 0 |
| 4420 | end |
| 4421 | gckey |
| 4422 | gctag n |
| 4423 | df = ulong 0 |
| 4424 | for i ulong 16 |
| 4425 | df = or df xor ulong get c_x i ulong get c_tg i |
| 4426 | end |
| 4427 | if ne df 0 |
| 4428 | ret 0 |
| 4429 | end |
| 4430 | gcctr n |
| 4431 | ret 1 |
| 4432 | end |
| 4433 | |
| 4434 | note seal the n bytes of c_d (16 MiB at most; more is left as it is, with a tag of zeros); their tag into c_tg |
| 4435 | fn gclock n ulong to void |
| 4436 | if gt n 16777216 |
| 4437 | for i ulong 16 |
| 4438 | put c_tg i 0 |
| 4439 | end |
| 4440 | ret |
| 4441 | end |
| 4442 | gckey |
| 4443 | gcctr n |
| 4444 | gctag n |
| 4445 | for i ulong 16 |
| 4446 | put c_tg i get c_x i |
| 4447 | end |
| 4448 | end |
| 4449 | |
| 4450 | note forget the key and everything worked out from it |
| 4451 | fn gcwipe to void |
| 4452 | for i ulong 32 |
| 4453 | put c_k i 0 |
| 4454 | end |
| 4455 | for i ulong 240 |
| 4456 | put c_rk i 0 |
| 4457 | end |
| 4458 | for i ulong 16 |
| 4459 | put c_hh i 0 |
| 4460 | put c_hl i 0 |
| 4461 | put c_st i 0 |
| 4462 | put c_tm i 0 |
| 4463 | put c_y i 0 |
| 4464 | put c_x i 0 |
| 4465 | end |
| 4466 | end |
| 4467 | |
| 4468 | fn swgcm b view uchar 1048576 c ulong nbytes ulong ob edit uchar 65544 to ulong |
| 4469 | if ne c 2 |
| 4470 | ret 0 |
| 4471 | end |
| 4472 | dir = gu b 0 |
| 4473 | n = gu b 1 |
| 4474 | if or gt dir 1 gt n 4096 |
| 4475 | ret 0 |
| 4476 | end |
| 4477 | want = add 44 n |
| 4478 | if eq dir 0 |
| 4479 | want = add want 16 |
| 4480 | end |
| 4481 | if ne nbytes want |
| 4482 | ret 0 |
| 4483 | end |
| 4484 | t0 = add 8 mul c 8 |
| 4485 | for i ulong 32 |
| 4486 | put c_k i get b add t0 i |
| 4487 | end |
| 4488 | for i ulong 12 |
| 4489 | put c_n i get b add add t0 32 i |
| 4490 | end |
| 4491 | for i ulong n bound 4096 |
| 4492 | put c_d i get b add add t0 44 i |
| 4493 | end |
| 4494 | if eq dir 0 |
| 4495 | for i ulong 16 |
| 4496 | put c_tg i get b add add add t0 44 n i |
| 4497 | end |
| 4498 | good = gcunlock n |
| 4499 | gcwipe |
| 4500 | po ob 0 add k_b good |
| 4501 | if eq good 0 |
| 4502 | ret 1 |
| 4503 | end |
| 4504 | for i ulong n bound 4096 |
| 4505 | po ob add 1 i add k_b ulong get c_d i |
| 4506 | end |
| 4507 | ret add 1 n |
| 4508 | end |
| 4509 | gclock n |
| 4510 | gcwipe |
| 4511 | po ob 0 add k_b 1 |
| 4512 | for i ulong n bound 4096 |
| 4513 | po ob add 1 i add k_b ulong get c_d i |
| 4514 | end |
| 4515 | for i ulong 16 |
| 4516 | po ob add add 1 n i add k_b ulong get c_tg i |
| 4517 | end |
| 4518 | ret add 17 n |
| 4519 | end |
| 4520 | |
| 4521 | note kind 7: see the note above. Scalar ops answer one number: 1 state, 2 attention, 3 unread (the newest post |
| 4522 | note less the last one read; -1 not known), 4 group, 5 starts a group, 6 failure (how a member's newest step |
| 4523 | note failed: a model error at once, a failed tool step once it stayed newest for 60 seconds; 3 when the text |
| 4524 | note spoke of quota), 7 the line weight of an edge, 1 to 5, by its count against the heaviest, 8 to 11 as noted. |
| 4525 | note 13 and 16 answer a list of numbers; 12 and 14 answer bytes. 17: the rows of the one box (fn swrank). 18: what the one box offers before anything is typed (fn swsuggest). |
| 4526 | note 19: the lift of each app from habit (fn swlifts). 20: AES-256-GCM, to seal and unseal (fn swgcm). Returns the reply length, or |
| 4527 | note 18446744073709551615 for a malformed request |
| 4528 | fn status ib view uchar 1048576 nb ulong ob edit uchar 65544 to ulong |
| 4529 | bad = ulong 18446744073709551615 |
| 4530 | if lt nb 8 |
| 4531 | ret bad |
| 4532 | end |
| 4533 | op = rd32 ib 0 |
| 4534 | c = rd32 ib 4 |
| 4535 | if gt add 8 mul c 8 nb |
| 4536 | ret bad |
| 4537 | end |
| 4538 | nbytes = sub nb add 8 mul c 8 |
| 4539 | t0 = add 8 mul c 8 |
| 4540 | r = k_b |
| 4541 | if eq op 1 |
| 4542 | if ne c 5 |
| 4543 | ret bad |
| 4544 | end |
| 4545 | r = add k_b swstate gi ib 0 gi ib 1 gi ib 2 gi ib 3 gi ib 4 |
| 4546 | end |
| 4547 | if eq op 2 |
| 4548 | if ne c 3 |
| 4549 | ret bad |
| 4550 | end |
| 4551 | r = add k_b swatt gi ib 0 gi ib 1 gi ib 2 |
| 4552 | end |
| 4553 | if eq op 3 |
| 4554 | if ne c 2 |
| 4555 | ret bad |
| 4556 | end |
| 4557 | r = sub k_b 1 |
| 4558 | if ge gi ib 1 k_b |
| 4559 | r = k_b |
| 4560 | if gt gi ib 0 gi ib 1 |
| 4561 | r = add k_b sub gi ib 0 gi ib 1 |
| 4562 | end |
| 4563 | end |
| 4564 | end |
| 4565 | if eq op 4 |
| 4566 | if ne c 4 |
| 4567 | ret bad |
| 4568 | end |
| 4569 | r = add k_b swgroup gi ib 0 gi ib 1 gi ib 2 gi ib 3 |
| 4570 | end |
| 4571 | if eq op 5 |
| 4572 | if ne c 4 |
| 4573 | ret bad |
| 4574 | end |
| 4575 | r = add k_b swstarts gi ib 0 gi ib 1 gi ib 2 gi ib 3 |
| 4576 | end |
| 4577 | if eq op 6 |
| 4578 | if ne c 4 |
| 4579 | ret bad |
| 4580 | end |
| 4581 | failed = eq gi ib 0 add k_b 4 |
| 4582 | if and eq gi ib 1 add k_b 2 ge gi ib 2 add k_b 60 |
| 4583 | failed = true |
| 4584 | end |
| 4585 | r = k_b |
| 4586 | if failed |
| 4587 | r = add k_b 2 |
| 4588 | if eq gi ib 3 add k_b 1 |
| 4589 | r = add k_b 3 |
| 4590 | end |
| 4591 | end |
| 4592 | end |
| 4593 | if eq op 7 |
| 4594 | if ne c 2 |
| 4595 | ret bad |
| 4596 | end |
| 4597 | cn = gi ib 0 |
| 4598 | hv = gi ib 1 |
| 4599 | r = add k_b 1 |
| 4600 | if and gt cn add k_b 1 gt hv add k_b 1 |
| 4601 | if ge cn hv |
| 4602 | r = add k_b 5 |
| 4603 | else |
| 4604 | r = add add k_b 1 div mul sub sub cn k_b 1 4 sub sub hv k_b 1 |
| 4605 | end |
| 4606 | end |
| 4607 | end |
| 4608 | if eq op 8 |
| 4609 | r = add k_b swturn ib c |
| 4610 | end |
| 4611 | if eq op 9 |
| 4612 | r = swact ib c |
| 4613 | end |
| 4614 | if eq op 10 |
| 4615 | r = add k_b swquota ib t0 add t0 nbytes |
| 4616 | end |
| 4617 | if eq op 11 |
| 4618 | if ne c 2 |
| 4619 | ret bad |
| 4620 | end |
| 4621 | rl = gu ib 0 |
| 4622 | nl = gu ib 1 |
| 4623 | if or gt rl 1048576 gt nl 1048576 |
| 4624 | ret bad |
| 4625 | end |
| 4626 | if ne add rl nl nbytes |
| 4627 | ret bad |
| 4628 | end |
| 4629 | r = add k_b swrole ib t0 rl add t0 rl nl |
| 4630 | end |
| 4631 | if eq op 12 |
| 4632 | ret swedges ib c ob |
| 4633 | end |
| 4634 | if eq op 13 |
| 4635 | ret mul 8 swbroad ib c ob |
| 4636 | end |
| 4637 | if eq op 14 |
| 4638 | ret swbusy ib c ob |
| 4639 | end |
| 4640 | if eq op 16 |
| 4641 | k = swderive ib c nbytes ob |
| 4642 | if eq k 0 |
| 4643 | ret bad |
| 4644 | end |
| 4645 | ret mul k 8 |
| 4646 | end |
| 4647 | if eq op 17 |
| 4648 | k = swrank ib c nbytes ob |
| 4649 | if eq k 0 |
| 4650 | ret bad |
| 4651 | end |
| 4652 | ret mul k 8 |
| 4653 | end |
| 4654 | if eq op 18 |
| 4655 | k = swsuggest ib c ob |
| 4656 | if eq k 0 |
| 4657 | ret bad |
| 4658 | end |
| 4659 | ret mul k 8 |
| 4660 | end |
| 4661 | if eq op 19 |
| 4662 | k = swlifts ib c ob |
| 4663 | if eq k 0 |
| 4664 | ret bad |
| 4665 | end |
| 4666 | ret mul k 8 |
| 4667 | end |
| 4668 | if eq op 20 |
| 4669 | k = swgcm ib c nbytes ob |
| 4670 | if eq k 0 |
| 4671 | ret bad |
| 4672 | end |
| 4673 | ret mul k 8 |
| 4674 | end |
| 4675 | if or gt op 11 eq op 0 |
| 4676 | ret bad |
| 4677 | end |
| 4678 | po ob 0 r |
| 4679 | ret 8 |
| 4680 | end |
| 4681 | |
| 4682 | note ---- which words were corrected (kind 4) ---- |
| 4683 | note After Hop types a dictation, the field is read again later. The host splits three texts into words (what was |
| 4684 | note dictated, the field before, the field after) and gives each distinct word a number. This finds the dictation |
| 4685 | note in the field (its last whole occurrence), sets aside the words that are the same at both ends, lines up the |
| 4686 | note rest word by word (longest common subsequence) and reports each run where words of the dictation were |
| 4687 | note replaced: at most 3 words, wholly inside the dictation. Nothing is reported when the dictation is not in the |
| 4688 | note field, when the part that changed is too large (words before times words after over 250000), or when more |
| 4689 | note than half of the dictation changed (a rewrite, not a fix). |
| 4690 | note wt: the table of the line-up, (words before + 1) rows of (words after + 1) |
| 4691 | global wt ulong 500008 |
| 4692 | |
| 4693 | note st: 0 where the removed run starts in the field, 1 its length, 2 where the typed run starts in the later |
| 4694 | note field, 3 its length, 4 runs written, 5 where the dictation starts, 6 its length, 7 removed words that lie |
| 4695 | note inside the dictation, 8 1 when there were more runs than the answer holds (4096) |
| 4696 | fn hclose st edit ulong 16 ob edit uchar 65544 to void |
| 4697 | rc = get st 1 |
| 4698 | ic = get st 3 |
| 4699 | if and gt rc 0 gt ic 0 |
| 4700 | rs = get st 0 |
| 4701 | s0 = get st 5 |
| 4702 | if ge rs s0 |
| 4703 | if le add rs rc add s0 get st 6 |
| 4704 | if le rc 3 |
| 4705 | h = get st 4 |
| 4706 | if ge h 4096 |
| 4707 | put st 8 1 |
| 4708 | else |
| 4709 | o = add 10 mul h 14 |
| 4710 | put32 ob o rs |
| 4711 | put ob add o 4 uchar and rc 255 |
| 4712 | put ob add o 5 uchar shr rc 8 |
| 4713 | put32 ob add o 6 get st 2 |
| 4714 | put32 ob add o 10 ic |
| 4715 | put st 4 add h 1 |
| 4716 | end |
| 4717 | end |
| 4718 | end |
| 4719 | end |
| 4720 | end |
| 4721 | put st 1 0 |
| 4722 | put st 3 0 |
| 4723 | end |
| 4724 | |
| 4725 | note kind 4: three 32-bit counts (dictated, before, after), then that many 32-bit word numbers for each. The |
| 4726 | note answer is a 16-bit count, then for each run: where the removed words start in the field before (32-bit), how |
| 4727 | note many (16-bit), where the typed words start in the field after (32-bit) and how many (32-bit). |
| 4728 | note Returns the reply length, or 18446744073709551615 for a malformed body or too many runs |
| 4729 | fn wdiff ib view uchar 1048576 n ulong ob edit uchar 65544 to ulong |
| 4730 | st = new ulong 16 0 |
| 4731 | bad = ulong 18446744073709551615 |
| 4732 | if lt n 12 |
| 4733 | ret bad |
| 4734 | end |
| 4735 | nd = rd32 ib 0 |
| 4736 | nb = rd32 ib 4 |
| 4737 | na = rd32 ib 8 |
| 4738 | if ne n add 12 mul 4 add add nd nb na |
| 4739 | ret bad |
| 4740 | end |
| 4741 | d0 = ulong 12 |
| 4742 | b0 = add 12 mul 4 nd |
| 4743 | a0 = add b0 mul 4 nb |
| 4744 | put ob 8 uchar 0 |
| 4745 | put ob 9 uchar 0 |
| 4746 | if eq nd 0 |
| 4747 | ret 2 |
| 4748 | end |
| 4749 | if lt nb nd |
| 4750 | ret 2 |
| 4751 | end |
| 4752 | found = false |
| 4753 | start = ulong 0 |
| 4754 | q = sub nb nd |
| 4755 | while true bound 999999 |
| 4756 | k = ulong 0 |
| 4757 | while lt k nd bound 999999 |
| 4758 | if ne rd32 ib add b0 mul 4 add q k rd32 ib add d0 mul 4 k |
| 4759 | break |
| 4760 | end |
| 4761 | k = add k 1 |
| 4762 | end |
| 4763 | if eq k nd |
| 4764 | found = true |
| 4765 | start = q |
| 4766 | break |
| 4767 | end |
| 4768 | if eq q 0 |
| 4769 | break |
| 4770 | end |
| 4771 | q = sub q 1 |
| 4772 | end |
| 4773 | if not found |
| 4774 | ret 2 |
| 4775 | end |
| 4776 | p = ulong 0 |
| 4777 | while lt p nb bound 999999 |
| 4778 | if ge p na |
| 4779 | break |
| 4780 | end |
| 4781 | if ne rd32 ib add b0 mul 4 p rd32 ib add a0 mul 4 p |
| 4782 | break |
| 4783 | end |
| 4784 | p = add p 1 |
| 4785 | end |
| 4786 | s = ulong 0 |
| 4787 | while lt s sub nb p bound 999999 |
| 4788 | if ge s sub na p |
| 4789 | break |
| 4790 | end |
| 4791 | if ne rd32 ib add b0 mul 4 sub sub nb 1 s rd32 ib add a0 mul 4 sub sub na 1 s |
| 4792 | break |
| 4793 | end |
| 4794 | s = add s 1 |
| 4795 | end |
| 4796 | bc = sub sub nb p s |
| 4797 | ac = sub sub na p s |
| 4798 | if eq bc 0 |
| 4799 | ret 2 |
| 4800 | end |
| 4801 | am = ac |
| 4802 | if eq am 0 |
| 4803 | am = ulong 1 |
| 4804 | end |
| 4805 | if gt mul bc am 250000 |
| 4806 | ret 2 |
| 4807 | end |
| 4808 | w1 = add ac 1 |
| 4809 | for z ulong add bc 1 |
| 4810 | put wt add mul z w1 ac 0 |
| 4811 | end |
| 4812 | for z ulong w1 |
| 4813 | put wt add mul bc w1 z 0 |
| 4814 | end |
| 4815 | for ii ulong bc |
| 4816 | i = sub sub bc 1 ii |
| 4817 | bi = rd32 ib add b0 mul 4 add p i |
| 4818 | for jj ulong ac |
| 4819 | j = sub sub ac 1 jj |
| 4820 | if eq bi rd32 ib add a0 mul 4 add p j |
| 4821 | put wt add mul i w1 j add get wt add mul add i 1 w1 add j 1 1 |
| 4822 | else |
| 4823 | x = get wt add mul add i 1 w1 j |
| 4824 | y = get wt add mul i w1 add j 1 |
| 4825 | if lt x y |
| 4826 | x = y |
| 4827 | end |
| 4828 | put wt add mul i w1 j x |
| 4829 | end |
| 4830 | end |
| 4831 | end |
| 4832 | put st 5 start |
| 4833 | put st 6 nd |
| 4834 | ci = ulong 0 |
| 4835 | cj = ulong 0 |
| 4836 | while or lt ci bc lt cj ac bound 999999 |
| 4837 | mt = false |
| 4838 | if lt ci bc |
| 4839 | if lt cj ac |
| 4840 | if eq rd32 ib add b0 mul 4 add p ci rd32 ib add a0 mul 4 add p cj |
| 4841 | mt = true |
| 4842 | end |
| 4843 | end |
| 4844 | end |
| 4845 | if mt |
| 4846 | hclose st ob |
| 4847 | ci = add ci 1 |
| 4848 | cj = add cj 1 |
| 4849 | continue |
| 4850 | end |
| 4851 | rm = false |
| 4852 | if lt ci bc |
| 4853 | if eq cj ac |
| 4854 | rm = true |
| 4855 | else |
| 4856 | if ge get wt add mul add ci 1 w1 cj get wt add mul ci w1 add cj 1 |
| 4857 | rm = true |
| 4858 | end |
| 4859 | end |
| 4860 | end |
| 4861 | if rm |
| 4862 | if eq get st 1 0 |
| 4863 | put st 0 add p ci |
| 4864 | end |
| 4865 | put st 1 add get st 1 1 |
| 4866 | ai = add p ci |
| 4867 | if ge ai start |
| 4868 | if lt ai add start nd |
| 4869 | put st 7 add get st 7 1 |
| 4870 | end |
| 4871 | end |
| 4872 | ci = add ci 1 |
| 4873 | else |
| 4874 | if eq get st 3 0 |
| 4875 | put st 2 add p cj |
| 4876 | end |
| 4877 | put st 3 add get st 3 1 |
| 4878 | cj = add cj 1 |
| 4879 | end |
| 4880 | end |
| 4881 | hclose st ob |
| 4882 | if ne get st 8 0 |
| 4883 | ret bad |
| 4884 | end |
| 4885 | h = get st 4 |
| 4886 | lim = nd |
| 4887 | if lt lim 2 |
| 4888 | lim = ulong 2 |
| 4889 | end |
| 4890 | if gt mul get st 7 2 lim |
| 4891 | h = ulong 0 |
| 4892 | end |
| 4893 | put ob 8 uchar and h 255 |
| 4894 | put ob 9 uchar shr h 8 |
| 4895 | ret add 2 mul h 14 |
| 4896 | end |
| 4897 | |
| 4898 | fn names ib view uchar 1048576 n ulong ob edit uchar 65544 a edit ulong 256 r edit ulong 256 to ulong |
| 4899 | if ne rem n 2048 0 |
| 4900 | ret 18446744073709551615 |
| 4901 | end |
| 4902 | c = div n 2048 |
| 4903 | if gt c 512 |
| 4904 | ret 18446744073709551615 |
| 4905 | end |
| 4906 | for q ulong c |
| 4907 | for i ulong 256 |
| 4908 | w = ulong 0 |
| 4909 | for j ulong 8 |
| 4910 | w = or w shl ulong get ib add add mul q 2048 mul i 8 j mul j 8 |
| 4911 | end |
| 4912 | put a i w |
| 4913 | end |
| 4914 | v = hopfuzz a r |
| 4915 | s = get r 3 |
| 4916 | put ob add 8 mul q 3 uchar v |
| 4917 | put ob add 9 mul q 3 uchar and s 255 |
| 4918 | put ob add 10 mul q 3 uchar shr s 8 |
| 4919 | end |
| 4920 | ret mul c 3 |
| 4921 | end |
| 4922 | |
| 4923 | note kind 2: returns the reply length, or 18446744073709551615 for a malformed body |
| 4924 | fn paths ib view uchar 1048576 n ulong ob edit uchar 65544 toff edit ulong 64 tlen edit ulong 64 pm edit ulong 8 to ulong |
| 4925 | bad = ulong 18446744073709551615 |
| 4926 | if lt n 4 |
| 4927 | ret bad |
| 4928 | end |
| 4929 | nt = rd16 ib 0 |
| 4930 | np = rd16 ib 2 |
| 4931 | if gt nt 64 |
| 4932 | ret bad |
| 4933 | end |
| 4934 | if gt np 16000 |
| 4935 | ret bad |
| 4936 | end |
| 4937 | o = ulong 4 |
| 4938 | for k ulong nt |
| 4939 | if gt add o 2 n |
| 4940 | ret bad |
| 4941 | end |
| 4942 | tl = rd16 ib o |
| 4943 | o = add o 2 |
| 4944 | if gt add o tl n |
| 4945 | ret bad |
| 4946 | end |
| 4947 | put toff k o |
| 4948 | put tlen k tl |
| 4949 | o = add o tl |
| 4950 | end |
| 4951 | for q ulong np |
| 4952 | if gt add o 6 n |
| 4953 | ret bad |
| 4954 | end |
| 4955 | pl = rd16 ib o |
| 4956 | nl = rd16 ib add o 2 |
| 4957 | ol = rd16 ib add o 4 |
| 4958 | o = add o 6 |
| 4959 | if gt add o add pl nl n |
| 4960 | ret bad |
| 4961 | end |
| 4962 | put pm 0 nt |
| 4963 | put pm 1 o |
| 4964 | put pm 2 pl |
| 4965 | put pm 3 add o pl |
| 4966 | put pm 4 nl |
| 4967 | put pm 5 ol |
| 4968 | put32 ob add 8 mul q 4 fscore ib toff tlen pm |
| 4969 | o = add o add pl nl |
| 4970 | end |
| 4971 | if ne o n |
| 4972 | ret bad |
| 4973 | end |
| 4974 | ret mul np 4 |
| 4975 | end |
| 4976 | |
| 4977 | fn main to int |
| 4978 | ib = new uchar 1048576 0 |
| 4979 | ob = new uchar 65544 0 |
| 4980 | a = new ulong 256 0 |
| 4981 | r = new ulong 256 0 |
| 4982 | toff = new ulong 64 0 |
| 4983 | tlen = new ulong 64 0 |
| 4984 | pm = new ulong 8 0 |
| 4985 | while true bound 999999 |
| 4986 | while true bound 999999 |
| 4987 | if not rdn ib 8 |
| 4988 | ret 0 |
| 4989 | end |
| 4990 | kind = rd32 ib 0 |
| 4991 | n = rd32 ib 4 |
| 4992 | if gt n 1048576 |
| 4993 | ret 3 |
| 4994 | end |
| 4995 | if not rdn ib n |
| 4996 | ret 3 |
| 4997 | end |
| 4998 | st = ulong 1 |
| 4999 | m = ulong 0 |
| 5000 | if eq kind 1 |
| 5001 | m = names ib n ob a r |
| 5002 | st = 0 |
| 5003 | end |
| 5004 | if eq kind 2 |
| 5005 | m = paths ib n ob toff tlen pm |
| 5006 | st = 0 |
| 5007 | end |
| 5008 | if eq kind 3 |
| 5009 | m = texts ib n ob |
| 5010 | st = 0 |
| 5011 | end |
| 5012 | if eq kind 4 |
| 5013 | m = wdiff ib n ob |
| 5014 | st = 0 |
| 5015 | end |
| 5016 | if eq kind 5 |
| 5017 | m = board ib n ob |
| 5018 | st = 0 |
| 5019 | end |
| 5020 | if eq kind 6 |
| 5021 | m = asm ib n ob |
| 5022 | st = 0 |
| 5023 | end |
| 5024 | if eq kind 7 |
| 5025 | m = status ib n ob |
| 5026 | st = 0 |
| 5027 | end |
| 5028 | if eq m 18446744073709551615 |
| 5029 | st = 2 |
| 5030 | m = 0 |
| 5031 | end |
| 5032 | put32 ob 0 st |
| 5033 | put32 ob 4 m |
| 5034 | if not wrn ob add 8 m |
| 5035 | ret 3 |
| 5036 | end |
| 5037 | end |
| 5038 | end |
| 5039 | ret 0 |
| 5040 | end |