omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / apps / hop / Linux / files.om
| 1 | note Hop Linux file-list foundation. SPDX-License-Identifier: Apache-2.0 |
| 2 | note No timer or scan runs until explicitly requested. Symlink directories are never traversed. |
| 3 | note File format HOPFIND1:64-byte header, then NUL-terminated absolute pathname byte strings. |
| 4 | note CLI JSON follows RFC8259 section7 and UTF-8 validation RFC3629 sections3/4. |
| 5 | note Invalid filesystem UTF-8 bytes use the reversible surrogateescape convention U+DC80..U+DCFF; |
| 6 | note agents must retain these escapes when round-tripping such names. Ordinary Unicode is encoded normally. |
| 7 | note Header0..7 magic; u64 little-endian at8 record count,16 partial-warning count,24 body bytes, |
| 8 | note 32 attempted-directory count;40..63 reserved zero. A newline is an ordinary pathname byte. |
| 9 | note Linux AArch64 stat and fcntl layouts are those of installed kernel UAPI headers. |
| 10 | note Directory flags O_NOFOLLOW|O_DIRECTORY=49152 calc:a636669bf8335bbaf4882cbbea217a1bbb71e5037a035961710684bb41f1597c. |
| 11 | note Temp flags O_NOFOLLOW|O_CREAT|O_EXCL|O_WRONLY=32961 calc:a20ca9614e5701d380af7d625ecc52fc9d081fc5f1c2dbce397542e1bb81313a. |
| 12 | note Lock flags O_NOFOLLOW|O_CREAT|O_NONBLOCK|O_RDWR=34882 calc:55d3315f96faa89f2851ea6d22b07a20adda0081bf621917b0eca71661a94ceb. |
| 13 | note Fixed4096 pathname buffers reflect the Linux pathname syscall boundary; directories and records grow. |
| 14 | note All cache operations occur relative to an open cache directory, then the original working directory is restored. |
| 15 | note This avoids imposing the compiler's4096-byte packed-rename boundary on a pair of long absolute paths. |
| 16 | global ff_path uchar 4096 |
| 17 | global ff_cache uchar 4096 |
| 18 | global ff_home uchar 4096 |
| 19 | global ff_cwd uchar 4096 |
| 20 | global ff_tmp uchar 96 |
| 21 | global ff_hdr uchar 64 |
| 22 | global ff_buf uchar 65536 |
| 23 | global ff_stat uchar 128 |
| 24 | global ff_arg uchar 131072 |
| 25 | global ff_rename uchar 128 |
| 26 | global ff_nul uchar 1 |
| 27 | global ff_out uchar 4096 |
| 28 | global ff_on ulong 1 |
| 29 | global ff_queue uchar * |
| 30 | global ff_qmeta ulong * |
| 31 | global ff_seen ulong * |
| 32 | global ff_oldseen ulong * |
| 33 | global ff_data uchar * |
| 34 | global ff_hits ulong * |
| 35 | global ff_terms uchar * |
| 36 | global ff_s ulong 32 |
| 37 | global ff_fd int 4 |
| 38 | note ff_s fields:0 path bytes,1 cache bytes,2 temp-name bytes,3 records,4 partial warnings, |
| 39 | note 5 body bytes,6 attempted directories,7 queued dirs,8 queue bytes,9 seen count,10 seen slots, |
| 40 | note 11 alarm threshold,12 alarm emitted,13 error,14 UI mode,15 loaded bytes,16 hits, |
| 41 | note 17 term bytes,18 home bytes,19 cwd bytes,20 temp exists,21 leading status rows. |
| 42 | text ff_magic "HOPFIND1" |
| 43 | text ff_index "files.idx" |
| 44 | text ff_lock "files.lock" |
| 45 | text ff_tempstart ".files." |
| 46 | text ff_dot "." |
| 47 | text ff_reindexarg "--reindex" |
| 48 | text ff_tmpend ".tmp" |
| 49 | text ff_homekey "HOME=" |
| 50 | text ff_cachekey "XDG_CACHE_HOME=" |
| 51 | text ff_cachetail "/.cache" |
| 52 | text ff_hoptail "/hop" |
| 53 | text ff_hive "/work/hive" |
| 54 | text ff_lanes "/work/lanes" |
| 55 | text ff_alarmkey "HOP_INDEX_ALARM_ENTRIES=" |
| 56 | text ff_node "node_modules" |
| 57 | text ff_target "target" |
| 58 | text ff_build "build" |
| 59 | text ff_dist "dist" |
| 60 | text ff_py "__pycache__" |
| 61 | text ff_venv "venv" |
| 62 | text ff_dotvenv ".venv" |
| 63 | text ff_site "site-packages" |
| 64 | text ff_slash "/" |
| 65 | text ff_partialmsg "Hop kept the file list it could read. Some folders were unavailable; coverage is partial.\n" |
| 66 | text ff_failmsg "Hop could not replace its file list. The previous list has been kept.\n" |
| 67 | text ff_cachemsg "Hop needs an absolute private cache folder and a valid home folder or explicit root.\n" |
| 68 | text ff_busymsg "Hop's file list is already being built. The current list is unchanged.\n" |
| 69 | text ff_badmsg "Hop's file list is damaged. Rebuild it before searching.\n" |
| 70 | text ff_missingmsg "Hop has no file list yet. Use --reindex or choose Build file list.\n" |
| 71 | text ff_memmsg "Hop could not grow its file-list memory.\n" |
| 72 | text ff_alarmmsg "ALARM Hop file-list entries " |
| 73 | text ff_alarmmid " crossed HOP_INDEX_ALARM_ENTRIES=" |
| 74 | text ff_alarmend "; indexing continues.\n" |
| 75 | text ff_alarmbad "Hop: invalid HOP_INDEX_ALARM_ENTRIES; using the default alarm threshold.\n" |
| 76 | text ff_buildrow "Build file list\n" |
| 77 | text ff_rebuildrow "File list is damaged. Build it again\n" |
| 78 | text ff_warnrow "Some folders could not be read. Results below are partial\n" |
| 79 | text ff_emptyrow "No files match that search\n" |
| 80 | text ff_hex "0123456789abcdef" |
| 81 | |
| 82 | fn ff_message message view uchar * to void |
| 83 | k = write 2 message 0 len message |
| 84 | end |
| 85 | |
| 86 | fn ff_reserve which ulong need ulong to bool |
| 87 | r = long 0 |
| 88 | if eq which 0 |
| 89 | if gt need len ff_queue |
| 90 | r = enlarge ff_queue add need add len ff_queue 4096 |
| 91 | end |
| 92 | end |
| 93 | if eq which 1 |
| 94 | if gt need len ff_qmeta |
| 95 | r = enlarge ff_qmeta add need add len ff_qmeta 64 |
| 96 | end |
| 97 | end |
| 98 | if eq which 2 |
| 99 | r = enlarge ff_seen need |
| 100 | end |
| 101 | if eq which 3 |
| 102 | r = enlarge ff_oldseen need |
| 103 | end |
| 104 | if eq which 4 |
| 105 | if gt need len ff_data |
| 106 | r = enlarge ff_data add need add len ff_data 65536 |
| 107 | end |
| 108 | end |
| 109 | if eq which 5 |
| 110 | if gt need len ff_hits |
| 111 | r = enlarge ff_hits add need add len ff_hits 128 |
| 112 | end |
| 113 | end |
| 114 | if eq which 6 |
| 115 | if gt need len ff_terms |
| 116 | r = enlarge ff_terms add need add len ff_terms 128 |
| 117 | end |
| 118 | end |
| 119 | if lt r 0 |
| 120 | put ff_s 13 1 |
| 121 | ff_message ff_memmsg |
| 122 | ret false |
| 123 | end |
| 124 | ret true |
| 125 | end |
| 126 | |
| 127 | fn ff_pathset source view uchar * to bool |
| 128 | if ge len source len ff_path |
| 129 | ret false |
| 130 | end |
| 131 | for i ulong len source bound 9223372036854775807 |
| 132 | c = get source i |
| 133 | put ff_path i c |
| 134 | end |
| 135 | put ff_s 0 len source |
| 136 | ret true |
| 137 | end |
| 138 | |
| 139 | fn ff_pathadd source view uchar * to bool |
| 140 | p = get ff_s 0 |
| 141 | if ge add p len source len ff_path |
| 142 | ret false |
| 143 | end |
| 144 | for i ulong len source bound 9223372036854775807 |
| 145 | c = get source i |
| 146 | put ff_path add p i c |
| 147 | end |
| 148 | put ff_s 0 add p len source |
| 149 | ret true |
| 150 | end |
| 151 | |
| 152 | fn ff_envpath n ulong to bool |
| 153 | if ge n len ff_path |
| 154 | ret false |
| 155 | end |
| 156 | for i ulong n bound 9223372036854775807 |
| 157 | c = get ha_env i |
| 158 | put ff_path i c |
| 159 | end |
| 160 | put ff_s 0 n |
| 161 | ret true |
| 162 | end |
| 163 | |
| 164 | fn ff_normalize to bool |
| 165 | n = get ff_s 0 |
| 166 | if eq n 0 |
| 167 | ret false |
| 168 | end |
| 169 | if ne get ff_path 0 47 |
| 170 | ret false |
| 171 | end |
| 172 | r = ulong 1 |
| 173 | w = ulong 1 |
| 174 | while lt r n bound 4096 |
| 175 | while lt r n bound 4096 |
| 176 | if ne get ff_path r 47 |
| 177 | break |
| 178 | end |
| 179 | r = add r 1 |
| 180 | end |
| 181 | start = r |
| 182 | while lt r n bound 4096 |
| 183 | if eq get ff_path r 47 |
| 184 | break |
| 185 | end |
| 186 | r = add r 1 |
| 187 | end |
| 188 | size = sub r start |
| 189 | if eq size 1 |
| 190 | if eq get ff_path start 46 |
| 191 | size = 0 |
| 192 | end |
| 193 | end |
| 194 | if eq size 2 |
| 195 | if eq get ff_path start 46 |
| 196 | if eq get ff_path add start 1 46 |
| 197 | if gt w 1 |
| 198 | w = sub w 1 |
| 199 | while gt w 1 bound 4096 |
| 200 | if eq get ff_path sub w 1 47 |
| 201 | break |
| 202 | end |
| 203 | w = sub w 1 |
| 204 | end |
| 205 | if gt w 1 |
| 206 | w = sub w 1 |
| 207 | end |
| 208 | end |
| 209 | size = 0 |
| 210 | end |
| 211 | end |
| 212 | end |
| 213 | if gt size 0 |
| 214 | if gt w 1 |
| 215 | put ff_path w 47 |
| 216 | w = add w 1 |
| 217 | end |
| 218 | ff_pathmove start w size |
| 219 | w = add w size |
| 220 | end |
| 221 | end |
| 222 | put ff_s 0 w |
| 223 | ret true |
| 224 | end |
| 225 | |
| 226 | fn ff_pathmove source ulong dest ulong size ulong to void |
| 227 | for i ulong size bound 4096 |
| 228 | c = get ff_path add source i |
| 229 | put ff_path add dest i c |
| 230 | end |
| 231 | end |
| 232 | |
| 233 | fn ff_statword offset ulong size ulong to ulong |
| 234 | v = ulong 0 |
| 235 | for i ulong size bound 8 |
| 236 | c = ulong get ff_stat add offset i |
| 237 | v = or v shl c mul i 8 |
| 238 | end |
| 239 | ret v |
| 240 | end |
| 241 | |
| 242 | fn ff_mode to ulong |
| 243 | ret and ff_statword 16 4 61440 |
| 244 | end |
| 245 | |
| 246 | fn ff_getstat follow bool to bool |
| 247 | r = long 0 |
| 248 | if follow |
| 249 | r = stat ff_path 0 get ff_s 0 ff_stat 0 len ff_stat |
| 250 | else |
| 251 | r = lstat ff_path 0 get ff_s 0 ff_stat 0 len ff_stat |
| 252 | end |
| 253 | ret ge r 0 |
| 254 | end |
| 255 | |
| 256 | fn ff_setup create bool to bool |
| 257 | for i ulong 4 |
| 258 | put ff_fd i -1 |
| 259 | end |
| 260 | put ff_s 20 0 |
| 261 | put ff_s 18 0 |
| 262 | n = ha_envget ff_homekey |
| 263 | if gt n 0 |
| 264 | if eq get ha_env 0 47 |
| 265 | if ff_envpath ulong n |
| 266 | if ff_normalize |
| 267 | ff_savehome |
| 268 | end |
| 269 | end |
| 270 | end |
| 271 | end |
| 272 | n = cwd ff_cwd 0 len ff_cwd |
| 273 | if le n 0 |
| 274 | ret false |
| 275 | end |
| 276 | put ff_s 19 sub ulong n 1 |
| 277 | n = ha_envget ff_cachekey |
| 278 | valid = false |
| 279 | if gt n 0 |
| 280 | valid = eq get ha_env 0 47 |
| 281 | end |
| 282 | if valid |
| 283 | if not ff_envpath ulong n |
| 284 | ret false |
| 285 | end |
| 286 | else |
| 287 | if eq get ff_s 18 0 |
| 288 | ret false |
| 289 | end |
| 290 | ff_homepath |
| 291 | if not ff_pathadd ff_cachetail |
| 292 | ret false |
| 293 | end |
| 294 | end |
| 295 | if not ff_pathadd ff_hoptail |
| 296 | ret false |
| 297 | end |
| 298 | if not ff_normalize |
| 299 | ret false |
| 300 | end |
| 301 | ff_savecache |
| 302 | if create |
| 303 | if not ff_mkdirs |
| 304 | ret false |
| 305 | end |
| 306 | end |
| 307 | ret true |
| 308 | end |
| 309 | |
| 310 | fn ff_savehome to void |
| 311 | n = get ff_s 0 |
| 312 | for i ulong n bound 4096 |
| 313 | c = get ff_path i |
| 314 | put ff_home i c |
| 315 | end |
| 316 | put ff_s 18 n |
| 317 | end |
| 318 | |
| 319 | fn ff_homepath to void |
| 320 | n = get ff_s 18 |
| 321 | for i ulong n bound 4096 |
| 322 | c = get ff_home i |
| 323 | put ff_path i c |
| 324 | end |
| 325 | put ff_s 0 n |
| 326 | end |
| 327 | |
| 328 | fn ff_savecache to void |
| 329 | n = get ff_s 0 |
| 330 | for i ulong n bound 4096 |
| 331 | c = get ff_path i |
| 332 | put ff_cache i c |
| 333 | end |
| 334 | put ff_s 1 n |
| 335 | end |
| 336 | |
| 337 | fn ff_cachepath to void |
| 338 | n = get ff_s 1 |
| 339 | for i ulong n bound 4096 |
| 340 | c = get ff_cache i |
| 341 | put ff_path i c |
| 342 | end |
| 343 | put ff_s 0 n |
| 344 | end |
| 345 | |
| 346 | fn ff_mkdirs to bool |
| 347 | n = get ff_s 0 |
| 348 | for i ulong add n 1 bound 4097 |
| 349 | sep = eq i n |
| 350 | if not sep |
| 351 | sep = eq get ff_path i 47 |
| 352 | end |
| 353 | if and sep gt i 0 |
| 354 | r = makedir ff_path 0 i 448 |
| 355 | if and lt r 0 ne r -17 |
| 356 | ret false |
| 357 | end |
| 358 | end |
| 359 | end |
| 360 | if not ff_getstat false |
| 361 | ret false |
| 362 | end |
| 363 | if ne ff_mode 16384 |
| 364 | ret false |
| 365 | end |
| 366 | if ne ff_statword 24 4 ulong getuid |
| 367 | ret false |
| 368 | end |
| 369 | ret eq and ff_statword 16 4 63 0 |
| 370 | end |
| 371 | |
| 372 | fn ff_enter to bool |
| 373 | old = int fopen ff_dot 0 len ff_dot 0 0 |
| 374 | if lt old 0 |
| 375 | ret false |
| 376 | end |
| 377 | put ff_fd 0 old |
| 378 | ff_cachepath |
| 379 | cache = int fopen ff_path 0 get ff_s 0 49152 0 |
| 380 | if lt cache 0 |
| 381 | put ff_s 24 ulong neg long cache |
| 382 | ret false |
| 383 | end |
| 384 | put ff_fd 1 cache |
| 385 | ret eq fchdir cache 0 |
| 386 | end |
| 387 | |
| 388 | fn ff_cleanup to void |
| 389 | if ge get ff_fd 3 0 |
| 390 | k = fclose get ff_fd 3 |
| 391 | put ff_fd 3 -1 |
| 392 | end |
| 393 | if ne get ff_s 20 0 |
| 394 | k = unlink ff_tmp 0 get ff_s 2 |
| 395 | put ff_s 20 0 |
| 396 | end |
| 397 | if ge get ff_fd 2 0 |
| 398 | k = fclose get ff_fd 2 |
| 399 | put ff_fd 2 -1 |
| 400 | end |
| 401 | if ge get ff_fd 0 0 |
| 402 | k = fchdir get ff_fd 0 |
| 403 | if ne k 0 |
| 404 | put ff_s 13 1 |
| 405 | end |
| 406 | k = fclose get ff_fd 0 |
| 407 | put ff_fd 0 -1 |
| 408 | end |
| 409 | if ge get ff_fd 1 0 |
| 410 | k = fclose get ff_fd 1 |
| 411 | put ff_fd 1 -1 |
| 412 | end |
| 413 | end |
| 414 | |
| 415 | fn ff_temptext source view uchar * to void |
| 416 | p = get ff_s 2 |
| 417 | for i ulong len source bound 96 |
| 418 | c = get source i |
| 419 | put ff_tmp add p i c |
| 420 | end |
| 421 | put ff_s 2 add p len source |
| 422 | end |
| 423 | |
| 424 | fn ff_tempnum value ulong to void |
| 425 | digits = new uchar 20 0 |
| 426 | n = ulong 0 |
| 427 | v = value |
| 428 | while true bound 20 |
| 429 | put digits n uchar add 48 rem v 10 |
| 430 | n = add n 1 |
| 431 | v = div v 10 |
| 432 | if eq v 0 |
| 433 | break |
| 434 | end |
| 435 | end |
| 436 | p = get ff_s 2 |
| 437 | for i ulong n bound 20 |
| 438 | put ff_tmp add p i get digits sub sub n i 1 |
| 439 | end |
| 440 | put ff_s 2 add p n |
| 441 | end |
| 442 | |
| 443 | fn ff_startoutput to int |
| 444 | lockfd = int fopen ff_lock 0 len ff_lock 34882 384 |
| 445 | if lt lockfd 0 |
| 446 | ret 1 |
| 447 | end |
| 448 | put ff_fd 2 lockfd |
| 449 | k = fstat lockfd ff_stat 0 len ff_stat |
| 450 | if lt k 0 |
| 451 | ret 1 |
| 452 | end |
| 453 | if ne ff_mode 32768 |
| 454 | ret 1 |
| 455 | end |
| 456 | k = flock lockfd 6 |
| 457 | if eq k -11 |
| 458 | ret 3 |
| 459 | end |
| 460 | if ne k 0 |
| 461 | ret 1 |
| 462 | end |
| 463 | put ff_s 2 0 |
| 464 | ff_temptext ff_tempstart |
| 465 | ff_tempnum ulong getpid |
| 466 | ff_temptext ff_dot |
| 467 | ff_tempnum ulong monons |
| 468 | ff_temptext ff_tmpend |
| 469 | fd = int fopen ff_tmp 0 get ff_s 2 32961 384 |
| 470 | if lt fd 0 |
| 471 | ret 1 |
| 472 | end |
| 473 | put ff_s 20 1 |
| 474 | put ff_fd 3 fd |
| 475 | ff_header |
| 476 | ret ff_writeheader |
| 477 | end |
| 478 | |
| 479 | fn ff_headernum offset ulong value ulong to void |
| 480 | for i ulong 8 |
| 481 | c = uchar and shr value mul i 8 255 |
| 482 | put ff_hdr add offset i c |
| 483 | end |
| 484 | end |
| 485 | |
| 486 | fn ff_header to void |
| 487 | for i ulong len ff_hdr |
| 488 | put ff_hdr i 0 |
| 489 | end |
| 490 | for i ulong len ff_magic |
| 491 | put ff_hdr i get ff_magic i |
| 492 | end |
| 493 | ff_headernum 8 get ff_s 3 |
| 494 | ff_headernum 16 get ff_s 4 |
| 495 | ff_headernum 24 get ff_s 5 |
| 496 | ff_headernum 32 get ff_s 6 |
| 497 | end |
| 498 | |
| 499 | fn ff_writeheader to int |
| 500 | p = ulong 0 |
| 501 | while lt p len ff_hdr bound 64 |
| 502 | k = write get ff_fd 3 ff_hdr p sub len ff_hdr p |
| 503 | if eq k -4 |
| 504 | continue |
| 505 | end |
| 506 | if le k 0 |
| 507 | put ff_s 13 1 |
| 508 | ret 1 |
| 509 | end |
| 510 | p = add p ulong k |
| 511 | end |
| 512 | ret 0 |
| 513 | end |
| 514 | |
| 515 | fn ff_dataword offset ulong to ulong |
| 516 | v = ulong 0 |
| 517 | for i ulong 8 |
| 518 | c = ulong get ff_data add offset i |
| 519 | v = or v shl c mul i 8 |
| 520 | end |
| 521 | ret v |
| 522 | end |
| 523 | |
| 524 | fn ff_load to int |
| 525 | put ff_s 13 0 |
| 526 | put ff_s 15 0 |
| 527 | put ff_s 16 0 |
| 528 | put ff_s 4 0 |
| 529 | put ff_s 24 0 |
| 530 | if not ff_setup false |
| 531 | ret 3 |
| 532 | end |
| 533 | if not ff_enter |
| 534 | ff_cleanup |
| 535 | if eq get ff_s 24 2 |
| 536 | ret 1 |
| 537 | end |
| 538 | ret 3 |
| 539 | end |
| 540 | fd = int fopen ff_index 0 len ff_index 34816 0 |
| 541 | if lt fd 0 |
| 542 | ff_cleanup |
| 543 | if eq fd -2 |
| 544 | ret 1 |
| 545 | end |
| 546 | ret 3 |
| 547 | end |
| 548 | put ff_fd 3 fd |
| 549 | k = fstat fd ff_stat 0 len ff_stat |
| 550 | if or lt k 0 ne ff_mode 32768 |
| 551 | ff_cleanup |
| 552 | ret 2 |
| 553 | end |
| 554 | while true bound 9223372036854775807 |
| 555 | n = read fd ff_buf 0 len ff_buf |
| 556 | if eq n -4 |
| 557 | continue |
| 558 | end |
| 559 | if lt n 0 |
| 560 | ff_cleanup |
| 561 | ret 3 |
| 562 | end |
| 563 | if eq n 0 |
| 564 | break |
| 565 | end |
| 566 | if not ff_loadpart ulong n |
| 567 | ff_cleanup |
| 568 | ret 3 |
| 569 | end |
| 570 | end |
| 571 | ff_cleanup |
| 572 | if ne get ff_s 13 0 |
| 573 | ret 3 |
| 574 | end |
| 575 | if not ff_validate |
| 576 | ret 2 |
| 577 | end |
| 578 | ret 0 |
| 579 | end |
| 580 | |
| 581 | fn ff_loadpart size ulong to bool |
| 582 | p = get ff_s 15 |
| 583 | if not ff_reserve 4 add p size |
| 584 | ret false |
| 585 | end |
| 586 | for i ulong size bound 65536 |
| 587 | c = get ff_buf i |
| 588 | put ff_data add p i c |
| 589 | end |
| 590 | put ff_s 15 add p size |
| 591 | ret true |
| 592 | end |
| 593 | |
| 594 | fn ff_validate to bool |
| 595 | n = get ff_s 15 |
| 596 | if lt n 64 |
| 597 | ret false |
| 598 | end |
| 599 | for i ulong len ff_magic |
| 600 | if ne get ff_data i get ff_magic i |
| 601 | ret false |
| 602 | end |
| 603 | end |
| 604 | for i ulong 24 |
| 605 | if ne get ff_data add i 40 0 |
| 606 | ret false |
| 607 | end |
| 608 | end |
| 609 | if ne ff_dataword 24 sub n 64 |
| 610 | ret false |
| 611 | end |
| 612 | p = ulong 64 |
| 613 | count = ulong 0 |
| 614 | while lt p n bound 9223372036854775807 |
| 615 | if ne get ff_data p 47 |
| 616 | ret false |
| 617 | end |
| 618 | start = p |
| 619 | while lt p n bound 4096 |
| 620 | if eq get ff_data p 0 |
| 621 | break |
| 622 | end |
| 623 | p = add p 1 |
| 624 | if ge sub p start 4096 |
| 625 | ret false |
| 626 | end |
| 627 | end |
| 628 | if eq p n |
| 629 | ret false |
| 630 | end |
| 631 | count = add count 1 |
| 632 | p = add p 1 |
| 633 | end |
| 634 | if ne count ff_dataword 8 |
| 635 | ret false |
| 636 | end |
| 637 | put ff_s 3 count |
| 638 | put ff_s 4 ff_dataword 16 |
| 639 | put ff_s 5 ff_dataword 24 |
| 640 | put ff_s 6 ff_dataword 32 |
| 641 | ret true |
| 642 | end |
| 643 | |
| 644 | fn ff_termwhite c uchar to bool |
| 645 | ret or eq c 32 and ge c 9 le c 13 |
| 646 | end |
| 647 | |
| 648 | fn ff_pathhas start ulong size ulong term ulong termsize ulong to bool |
| 649 | if gt termsize size |
| 650 | ret false |
| 651 | end |
| 652 | for i ulong add sub size termsize 1 bound 4096 |
| 653 | if ff_pathterm add start i term termsize |
| 654 | ret true |
| 655 | end |
| 656 | end |
| 657 | ret false |
| 658 | end |
| 659 | |
| 660 | fn ff_pathterm start ulong term ulong size ulong to bool |
| 661 | for j ulong size bound 9223372036854775807 |
| 662 | a = ha_lower get ff_data add start j |
| 663 | b = ha_lower get ff_terms add term j |
| 664 | if ne a b |
| 665 | ret false |
| 666 | end |
| 667 | end |
| 668 | ret true |
| 669 | end |
| 670 | |
| 671 | fn ff_match start ulong size ulong to bool |
| 672 | n = get ff_s 17 |
| 673 | p = ulong 0 |
| 674 | while lt p n bound 9223372036854775807 |
| 675 | while lt p n bound 9223372036854775807 |
| 676 | if not ff_termwhite get ff_terms p |
| 677 | break |
| 678 | end |
| 679 | p = add p 1 |
| 680 | end |
| 681 | lo = p |
| 682 | while lt p n bound 9223372036854775807 |
| 683 | if ff_termwhite get ff_terms p |
| 684 | break |
| 685 | end |
| 686 | p = add p 1 |
| 687 | end |
| 688 | if gt p lo |
| 689 | if not ff_pathhas start size lo sub p lo |
| 690 | ret false |
| 691 | end |
| 692 | end |
| 693 | end |
| 694 | ret true |
| 695 | end |
| 696 | |
| 697 | fn ff_search to bool |
| 698 | put ff_s 16 0 |
| 699 | p = ulong 64 |
| 700 | n = get ff_s 15 |
| 701 | while lt p n bound 9223372036854775807 |
| 702 | start = p |
| 703 | while ne get ff_data p 0 bound 4096 |
| 704 | p = add p 1 |
| 705 | end |
| 706 | if ff_match start sub p start |
| 707 | k = get ff_s 16 |
| 708 | if not ff_reserve 5 mul add k 1 2 |
| 709 | ret false |
| 710 | end |
| 711 | put ff_hits mul k 2 start |
| 712 | put ff_hits add mul k 2 1 sub p start |
| 713 | put ff_s 16 add k 1 |
| 714 | end |
| 715 | p = add p 1 |
| 716 | end |
| 717 | ret true |
| 718 | end |
| 719 | |
| 720 | fn ff_rowbyte c uchar to void |
| 721 | p = get lx_rn 0 |
| 722 | if eq p len lx_rows |
| 723 | r = enlarge lx_rows add add p p 128 |
| 724 | if lt r 0 |
| 725 | put ff_s 13 1 |
| 726 | ret |
| 727 | end |
| 728 | end |
| 729 | put lx_rows p c |
| 730 | put lx_rn 0 add p 1 |
| 731 | end |
| 732 | |
| 733 | fn ff_rowtext value view uchar * to void |
| 734 | for i ulong len value bound 4096 |
| 735 | ff_rowbyte get value i |
| 736 | end |
| 737 | end |
| 738 | |
| 739 | fn ff_rowpath start ulong size ulong to void |
| 740 | for i ulong size bound 4096 |
| 741 | c = get ff_data add start i |
| 742 | if eq c 10 |
| 743 | ff_rowbyte 92 |
| 744 | ff_rowbyte 110 |
| 745 | else |
| 746 | if eq c 13 |
| 747 | ff_rowbyte 92 |
| 748 | ff_rowbyte 114 |
| 749 | else |
| 750 | if eq c 9 |
| 751 | ff_rowbyte 92 |
| 752 | ff_rowbyte 116 |
| 753 | else |
| 754 | if eq c 92 |
| 755 | ff_rowbyte 92 |
| 756 | ff_rowbyte 92 |
| 757 | else |
| 758 | if or lt c 32 eq c 127 |
| 759 | ff_rowbyte 92 |
| 760 | ff_rowbyte 120 |
| 761 | ff_rowbyte get ff_hex shr c 4 |
| 762 | ff_rowbyte get ff_hex and c 15 |
| 763 | else |
| 764 | ff_rowbyte c |
| 765 | end |
| 766 | end |
| 767 | end |
| 768 | end |
| 769 | end |
| 770 | end |
| 771 | ff_rowbyte 10 |
| 772 | end |
| 773 | |
| 774 | fn ff_queryterms start ulong size ulong to bool |
| 775 | if not ff_reserve 6 size |
| 776 | ret false |
| 777 | end |
| 778 | for i ulong size bound 9223372036854775807 |
| 779 | c = get lx_query add start i |
| 780 | put ff_terms i c |
| 781 | end |
| 782 | put ff_s 17 size |
| 783 | ret true |
| 784 | end |
| 785 | |
| 786 | fn ff_isfind to bool |
| 787 | n = get lx_qn 0 |
| 788 | if lt n 4 |
| 789 | ret false |
| 790 | end |
| 791 | if ne ha_lower get lx_query 0 102 |
| 792 | ret false |
| 793 | end |
| 794 | if ne ha_lower get lx_query 1 105 |
| 795 | ret false |
| 796 | end |
| 797 | if ne ha_lower get lx_query 2 110 |
| 798 | ret false |
| 799 | end |
| 800 | if ne ha_lower get lx_query 3 100 |
| 801 | ret false |
| 802 | end |
| 803 | if eq n 4 |
| 804 | ret true |
| 805 | end |
| 806 | ret eq get lx_query 4 32 |
| 807 | end |
| 808 | |
| 809 | fn ff_query to int |
| 810 | if not ff_isfind |
| 811 | ret 0 |
| 812 | end |
| 813 | start = ulong 4 |
| 814 | if gt get lx_qn 0 4 |
| 815 | start = 5 |
| 816 | end |
| 817 | put lx_rn 0 0 |
| 818 | put lx_pick 0 0 |
| 819 | put ff_s 14 3 |
| 820 | put ff_s 21 0 |
| 821 | if not ff_queryterms start sub get lx_qn 0 start |
| 822 | ret 1 |
| 823 | end |
| 824 | loaded = ff_load |
| 825 | if ne loaded 0 |
| 826 | if eq loaded 1 |
| 827 | put ff_s 14 1 |
| 828 | ff_rowtext ff_buildrow |
| 829 | else |
| 830 | if eq loaded 2 |
| 831 | put ff_s 14 1 |
| 832 | ff_rowtext ff_rebuildrow |
| 833 | else |
| 834 | ff_rowtext ff_failmsg |
| 835 | end |
| 836 | end |
| 837 | ret 1 |
| 838 | end |
| 839 | if not ff_search |
| 840 | ff_rowtext ff_memmsg |
| 841 | ret 1 |
| 842 | end |
| 843 | if ne get ff_s 4 0 |
| 844 | ff_rowtext ff_warnrow |
| 845 | put ff_s 21 1 |
| 846 | end |
| 847 | if eq get ff_s 16 0 |
| 848 | ff_rowtext ff_emptyrow |
| 849 | ret 1 |
| 850 | end |
| 851 | put ff_s 14 2 |
| 852 | for i ulong get ff_s 16 bound 9223372036854775807 |
| 853 | ff_rowhit i |
| 854 | end |
| 855 | if eq get ff_s 21 1 |
| 856 | put lx_pick 0 1 |
| 857 | end |
| 858 | ret 1 |
| 859 | end |
| 860 | |
| 861 | fn ff_rowhit index ulong to void |
| 862 | p = get ff_hits mul index 2 |
| 863 | n = get ff_hits add mul index 2 1 |
| 864 | ff_rowpath p n |
| 865 | end |
| 866 | |
| 867 | fn ff_activate to int |
| 868 | mode = get ff_s 14 |
| 869 | if eq mode 1 |
| 870 | if eq ff_rebuild 0 |
| 871 | k = ff_query |
| 872 | end |
| 873 | ret 0 |
| 874 | end |
| 875 | if ne mode 2 |
| 876 | ret 0 |
| 877 | end |
| 878 | pick = get lx_pick 0 |
| 879 | if lt pick get ff_s 21 |
| 880 | ret 0 |
| 881 | end |
| 882 | pick = sub pick get ff_s 21 |
| 883 | if ge pick get ff_s 16 |
| 884 | ret 0 |
| 885 | end |
| 886 | p = get ff_hits mul pick 2 |
| 887 | n = get ff_hits add mul pick 2 1 |
| 888 | path = new uchar 4096 0 |
| 889 | for i ulong n bound 4096 |
| 890 | c = get ff_data add p i |
| 891 | put path i c |
| 892 | end |
| 893 | ret ha_openfile part path 0 n |
| 894 | end |
| 895 | |
| 896 | fn ff_partial to ulong |
| 897 | ret get ff_s 4 |
| 898 | end |
| 899 | |
| 900 | fn ff_flush to bool |
| 901 | p = ulong 0 |
| 902 | n = get ff_on 0 |
| 903 | while lt p n bound 4096 |
| 904 | k = write 1 ff_out p sub n p |
| 905 | if eq k -4 |
| 906 | continue |
| 907 | end |
| 908 | if le k 0 |
| 909 | put ff_s 13 1 |
| 910 | ret false |
| 911 | end |
| 912 | p = add p ulong k |
| 913 | end |
| 914 | put ff_on 0 0 |
| 915 | ret true |
| 916 | end |
| 917 | |
| 918 | fn ff_outbyte c uchar to void |
| 919 | if eq get ff_on 0 len ff_out |
| 920 | if not ff_flush |
| 921 | ret |
| 922 | end |
| 923 | end |
| 924 | p = get ff_on 0 |
| 925 | put ff_out p c |
| 926 | put ff_on 0 add p 1 |
| 927 | end |
| 928 | |
| 929 | fn ff_jsonhex scalar ulong to void |
| 930 | ff_outbyte 92 |
| 931 | ff_outbyte 117 |
| 932 | ff_outbyte get ff_hex and shr scalar 12 15 |
| 933 | ff_outbyte get ff_hex and shr scalar 8 15 |
| 934 | ff_outbyte get ff_hex and shr scalar 4 15 |
| 935 | ff_outbyte get ff_hex and scalar 15 |
| 936 | end |
| 937 | |
| 938 | fn ff_scalar pos ulong endpos ulong to ulong |
| 939 | put ff_s 25 1 |
| 940 | c = ulong get ff_data pos |
| 941 | if lt c 128 |
| 942 | ret c |
| 943 | end |
| 944 | count = ulong 0 |
| 945 | value = ulong 0 |
| 946 | if and ge c 194 le c 223 |
| 947 | count = 2 |
| 948 | value = and c 31 |
| 949 | end |
| 950 | if and ge c 224 le c 239 |
| 951 | count = 3 |
| 952 | value = and c 15 |
| 953 | end |
| 954 | if and ge c 240 le c 244 |
| 955 | count = 4 |
| 956 | value = and c 7 |
| 957 | end |
| 958 | if or eq count 0 gt add pos count endpos |
| 959 | ret add 56320 c |
| 960 | end |
| 961 | for i ulong sub count 1 bound 3 |
| 962 | d = ulong get ff_data add add pos i 1 |
| 963 | if or lt d 128 gt d 191 |
| 964 | ret add 56320 c |
| 965 | end |
| 966 | value = or shl value 6 and d 63 |
| 967 | end |
| 968 | if and eq count 2 lt value 128 |
| 969 | ret add 56320 c |
| 970 | end |
| 971 | if and eq count 3 lt value 2048 |
| 972 | ret add 56320 c |
| 973 | end |
| 974 | if and eq count 4 lt value 65536 |
| 975 | ret add 56320 c |
| 976 | end |
| 977 | if or and ge value 55296 le value 57343 gt value 1114111 |
| 978 | ret add 56320 c |
| 979 | end |
| 980 | put ff_s 25 count |
| 981 | ret value |
| 982 | end |
| 983 | |
| 984 | fn ff_jsonpath start ulong size ulong to void |
| 985 | ff_outbyte 34 |
| 986 | p = start |
| 987 | endpos = add start size |
| 988 | while lt p endpos bound 4096 |
| 989 | v = ff_scalar p endpos |
| 990 | if or eq v 34 eq v 92 |
| 991 | ff_outbyte 92 |
| 992 | ff_outbyte uchar v |
| 993 | else |
| 994 | if or lt v 32 ge v 127 |
| 995 | if le v 65535 |
| 996 | ff_jsonhex v |
| 997 | else |
| 998 | partv = sub v 65536 |
| 999 | ff_jsonhex add 55296 shr partv 10 |
| 1000 | ff_jsonhex add 56320 and partv 1023 |
| 1001 | end |
| 1002 | else |
| 1003 | ff_outbyte uchar v |
| 1004 | end |
| 1005 | end |
| 1006 | p = add p get ff_s 25 |
| 1007 | end |
| 1008 | ff_outbyte 34 |
| 1009 | end |
| 1010 | |
| 1011 | fn ff_json to int |
| 1012 | put ff_on 0 0 |
| 1013 | ff_outbyte 91 |
| 1014 | for i ulong get ff_s 16 bound 9223372036854775807 |
| 1015 | if ne i 0 |
| 1016 | ff_outbyte 44 |
| 1017 | end |
| 1018 | ff_jsonhit i |
| 1019 | end |
| 1020 | ff_outbyte 93 |
| 1021 | ff_outbyte 10 |
| 1022 | if not ff_flush |
| 1023 | ret 1 |
| 1024 | end |
| 1025 | if ne get ff_s 13 0 |
| 1026 | ret 1 |
| 1027 | end |
| 1028 | ret 0 |
| 1029 | end |
| 1030 | |
| 1031 | fn ff_jsonhit index ulong to void |
| 1032 | p = get ff_hits mul index 2 |
| 1033 | n = get ff_hits add mul index 2 1 |
| 1034 | ff_jsonpath p n |
| 1035 | end |
| 1036 | |
| 1037 | fn ff_cliterms to bool |
| 1038 | put ff_s 17 0 |
| 1039 | if le argcnt 2 |
| 1040 | ret true |
| 1041 | end |
| 1042 | n = argread 2 ff_arg 0 len ff_arg |
| 1043 | if lt n 0 |
| 1044 | ret false |
| 1045 | end |
| 1046 | if not ff_reserve 6 ulong n |
| 1047 | ret false |
| 1048 | end |
| 1049 | for i ulong ulong n bound 131072 |
| 1050 | c = get ff_arg i |
| 1051 | put ff_terms i c |
| 1052 | end |
| 1053 | put ff_s 17 ulong n |
| 1054 | ret true |
| 1055 | end |
| 1056 | |
| 1057 | fn ff_cli mode int to int |
| 1058 | if eq mode 0 |
| 1059 | ret ff_rebuild |
| 1060 | end |
| 1061 | if gt argcnt 3 |
| 1062 | ret 2 |
| 1063 | end |
| 1064 | if not ff_cliterms |
| 1065 | ret 1 |
| 1066 | end |
| 1067 | loaded = ff_load |
| 1068 | if ne loaded 0 |
| 1069 | if eq loaded 1 |
| 1070 | ff_message ff_missingmsg |
| 1071 | else |
| 1072 | if eq loaded 2 |
| 1073 | ff_message ff_badmsg |
| 1074 | else |
| 1075 | ff_message ff_failmsg |
| 1076 | end |
| 1077 | end |
| 1078 | ret 1 |
| 1079 | end |
| 1080 | if not ff_search |
| 1081 | ret 1 |
| 1082 | end |
| 1083 | if ne get ff_s 4 0 |
| 1084 | ff_message ff_partialmsg |
| 1085 | end |
| 1086 | ret ff_json |
| 1087 | end |
| 1088 | |
| 1089 | fn ff_record to bool |
| 1090 | n = get ff_s 0 |
| 1091 | p = ulong 0 |
| 1092 | while lt p n bound 4096 |
| 1093 | k = write get ff_fd 3 ff_path p sub n p |
| 1094 | if eq k -4 |
| 1095 | continue |
| 1096 | end |
| 1097 | if le k 0 |
| 1098 | put ff_s 13 1 |
| 1099 | ret false |
| 1100 | end |
| 1101 | p = add p ulong k |
| 1102 | end |
| 1103 | k = write get ff_fd 3 ff_nul 0 1 |
| 1104 | if ne k 1 |
| 1105 | put ff_s 13 1 |
| 1106 | ret false |
| 1107 | end |
| 1108 | put ff_s 3 add get ff_s 3 1 |
| 1109 | put ff_s 5 add get ff_s 5 add n 1 |
| 1110 | ff_alarm |
| 1111 | ret true |
| 1112 | end |
| 1113 | |
| 1114 | fn ff_printnum value ulong to void |
| 1115 | b = new uchar 20 0 |
| 1116 | v = value |
| 1117 | n = ulong 20 |
| 1118 | while true bound 20 |
| 1119 | n = sub n 1 |
| 1120 | put b n uchar add 48 rem v 10 |
| 1121 | v = div v 10 |
| 1122 | if eq v 0 |
| 1123 | break |
| 1124 | end |
| 1125 | end |
| 1126 | k = write 2 b n sub 20 n |
| 1127 | end |
| 1128 | |
| 1129 | fn ff_alarm to void |
| 1130 | if ne get ff_s 12 0 |
| 1131 | ret |
| 1132 | end |
| 1133 | if le get ff_s 3 get ff_s 11 |
| 1134 | ret |
| 1135 | end |
| 1136 | put ff_s 12 1 |
| 1137 | ff_message ff_alarmmsg |
| 1138 | ff_printnum get ff_s 3 |
| 1139 | ff_message ff_alarmmid |
| 1140 | ff_printnum get ff_s 11 |
| 1141 | ff_message ff_alarmend |
| 1142 | end |
| 1143 | |
| 1144 | fn ff_alarmsetting to void |
| 1145 | put ff_s 11 1000000 |
| 1146 | n = ha_envget ff_alarmkey |
| 1147 | if lt n 0 |
| 1148 | ret |
| 1149 | end |
| 1150 | if eq n 0 |
| 1151 | ff_message ff_alarmbad |
| 1152 | ret |
| 1153 | end |
| 1154 | v = ulong 0 |
| 1155 | for i ulong ulong n bound 131072 |
| 1156 | c = get ha_env i |
| 1157 | if or lt c 48 gt c 57 |
| 1158 | ff_message ff_alarmbad |
| 1159 | ret |
| 1160 | end |
| 1161 | d = ulong sub c 48 |
| 1162 | if gt v div sub 18446744073709551615 d 10 |
| 1163 | ff_message ff_alarmbad |
| 1164 | ret |
| 1165 | end |
| 1166 | v = add mul v 10 d |
| 1167 | end |
| 1168 | put ff_s 11 v |
| 1169 | end |
| 1170 | |
| 1171 | fn ff_seenplace device ulong inode ulong cap ulong to ulong |
| 1172 | slot = rem xor device inode cap |
| 1173 | while ne get ff_seen add mul slot 3 2 0 bound 9223372036854775807 |
| 1174 | if eq get ff_seen mul slot 3 device |
| 1175 | if eq get ff_seen add mul slot 3 1 inode |
| 1176 | ret slot |
| 1177 | end |
| 1178 | end |
| 1179 | slot = rem add slot 1 cap |
| 1180 | end |
| 1181 | ret slot |
| 1182 | end |
| 1183 | |
| 1184 | fn ff_seengrow to bool |
| 1185 | oldcap = get ff_s 10 |
| 1186 | cap = ulong 64 |
| 1187 | if gt oldcap 0 |
| 1188 | cap = mul oldcap 2 |
| 1189 | end |
| 1190 | if not ff_reserve 3 mul oldcap 3 |
| 1191 | ret false |
| 1192 | end |
| 1193 | for i ulong mul oldcap 3 bound 9223372036854775807 |
| 1194 | c = get ff_seen i |
| 1195 | put ff_oldseen i c |
| 1196 | end |
| 1197 | if not ff_reserve 2 mul cap 3 |
| 1198 | ret false |
| 1199 | end |
| 1200 | for i ulong cap bound 9223372036854775807 |
| 1201 | put ff_seen add mul i 3 2 0 |
| 1202 | end |
| 1203 | for i ulong oldcap bound 9223372036854775807 |
| 1204 | if ne get ff_oldseen add mul i 3 2 0 |
| 1205 | ff_rehash i cap |
| 1206 | end |
| 1207 | end |
| 1208 | put ff_s 10 cap |
| 1209 | ret true |
| 1210 | end |
| 1211 | |
| 1212 | fn ff_rehash oldslot ulong cap ulong to void |
| 1213 | device = get ff_oldseen mul oldslot 3 |
| 1214 | inode = get ff_oldseen add mul oldslot 3 1 |
| 1215 | slot = ff_seenplace device inode cap |
| 1216 | put ff_seen mul slot 3 device |
| 1217 | put ff_seen add mul slot 3 1 inode |
| 1218 | put ff_seen add mul slot 3 2 1 |
| 1219 | end |
| 1220 | |
| 1221 | fn ff_remember device ulong inode ulong to int |
| 1222 | if ge mul get ff_s 9 2 get ff_s 10 |
| 1223 | if not ff_seengrow |
| 1224 | ret -1 |
| 1225 | end |
| 1226 | end |
| 1227 | slot = ff_seenplace device inode get ff_s 10 |
| 1228 | if ne get ff_seen add mul slot 3 2 0 |
| 1229 | ret 0 |
| 1230 | end |
| 1231 | put ff_seen mul slot 3 device |
| 1232 | put ff_seen add mul slot 3 1 inode |
| 1233 | put ff_seen add mul slot 3 2 1 |
| 1234 | put ff_s 9 add get ff_s 9 1 |
| 1235 | ret 1 |
| 1236 | end |
| 1237 | |
| 1238 | fn ff_homesuffix suffix view uchar * to bool |
| 1239 | n = get ff_s 18 |
| 1240 | if eq n 0 |
| 1241 | ret false |
| 1242 | end |
| 1243 | if ne get ff_s 0 add n len suffix |
| 1244 | ret false |
| 1245 | end |
| 1246 | for i ulong n bound 4096 |
| 1247 | if ne get ff_path i get ff_home i |
| 1248 | ret false |
| 1249 | end |
| 1250 | end |
| 1251 | for i ulong len suffix bound 4096 |
| 1252 | if ne get ff_path add n i get suffix i |
| 1253 | ret false |
| 1254 | end |
| 1255 | end |
| 1256 | ret true |
| 1257 | end |
| 1258 | |
| 1259 | fn ff_excludedpath to bool |
| 1260 | if ff_skipcurrent |
| 1261 | ret true |
| 1262 | end |
| 1263 | if eq get ff_s 0 get ff_s 1 |
| 1264 | same = true |
| 1265 | for i ulong get ff_s 1 bound 4096 |
| 1266 | if ne get ff_path i get ff_cache i |
| 1267 | same = false |
| 1268 | break |
| 1269 | end |
| 1270 | end |
| 1271 | if same |
| 1272 | ret true |
| 1273 | end |
| 1274 | end |
| 1275 | if ff_homesuffix ff_hive |
| 1276 | ret true |
| 1277 | end |
| 1278 | ret ff_homesuffix ff_lanes |
| 1279 | end |
| 1280 | |
| 1281 | fn ff_enqueue to bool |
| 1282 | if ff_excludedpath |
| 1283 | ret true |
| 1284 | end |
| 1285 | if not ff_getstat false |
| 1286 | ff_warn |
| 1287 | ret true |
| 1288 | end |
| 1289 | if ne ff_mode 16384 |
| 1290 | ff_warn |
| 1291 | ret true |
| 1292 | end |
| 1293 | device = ff_statword 0 8 |
| 1294 | inode = ff_statword 8 8 |
| 1295 | newdir = ff_remember device inode |
| 1296 | if lt newdir 0 |
| 1297 | ret false |
| 1298 | end |
| 1299 | if eq newdir 0 |
| 1300 | ret true |
| 1301 | end |
| 1302 | q = get ff_s 7 |
| 1303 | p = get ff_s 8 |
| 1304 | n = get ff_s 0 |
| 1305 | if not ff_reserve 0 add p n |
| 1306 | ret false |
| 1307 | end |
| 1308 | if not ff_reserve 1 mul add q 1 4 |
| 1309 | ret false |
| 1310 | end |
| 1311 | ff_queuecopy p n |
| 1312 | put ff_qmeta mul q 4 p |
| 1313 | put ff_qmeta add mul q 4 1 n |
| 1314 | put ff_qmeta add mul q 4 2 device |
| 1315 | put ff_qmeta add mul q 4 3 inode |
| 1316 | put ff_s 7 add q 1 |
| 1317 | put ff_s 8 add p n |
| 1318 | ret ff_record |
| 1319 | end |
| 1320 | |
| 1321 | fn ff_queuecopy dest ulong size ulong to void |
| 1322 | for i ulong size bound 4096 |
| 1323 | c = get ff_path i |
| 1324 | put ff_queue add dest i c |
| 1325 | end |
| 1326 | end |
| 1327 | |
| 1328 | fn ff_queuepath index ulong to void |
| 1329 | p = get ff_qmeta mul index 4 |
| 1330 | n = get ff_qmeta add mul index 4 1 |
| 1331 | for i ulong n bound 4096 |
| 1332 | c = get ff_queue add p i |
| 1333 | put ff_path i c |
| 1334 | end |
| 1335 | put ff_s 0 n |
| 1336 | end |
| 1337 | |
| 1338 | fn ff_warn to void |
| 1339 | put ff_s 4 add get ff_s 4 1 |
| 1340 | end |
| 1341 | |
| 1342 | fn ff_skipname pos ulong size ulong to bool |
| 1343 | b = new uchar 4096 0 |
| 1344 | if ge size len b |
| 1345 | ret true |
| 1346 | end |
| 1347 | for i ulong size bound 4096 |
| 1348 | put b i get ff_buf add pos i |
| 1349 | end |
| 1350 | ret ff_skipvalue part b 0 size |
| 1351 | end |
| 1352 | |
| 1353 | fn ff_skipcurrent to bool |
| 1354 | b = new uchar 4096 0 |
| 1355 | n = get ff_s 0 |
| 1356 | start = n |
| 1357 | while gt start 0 bound 4096 |
| 1358 | if eq get ff_path sub start 1 47 |
| 1359 | break |
| 1360 | end |
| 1361 | start = sub start 1 |
| 1362 | end |
| 1363 | size = sub n start |
| 1364 | for i ulong size bound 4096 |
| 1365 | put b i get ff_path add start i |
| 1366 | end |
| 1367 | ret ff_skipvalue part b 0 size |
| 1368 | end |
| 1369 | |
| 1370 | fn ff_equal a view uchar * b view uchar * to bool |
| 1371 | if ne len a len b |
| 1372 | ret false |
| 1373 | end |
| 1374 | for i ulong len a bound 4096 |
| 1375 | if ne get a i get b i |
| 1376 | ret false |
| 1377 | end |
| 1378 | end |
| 1379 | ret true |
| 1380 | end |
| 1381 | |
| 1382 | fn ff_skipvalue value view uchar * to bool |
| 1383 | if eq len value 0 |
| 1384 | ret false |
| 1385 | end |
| 1386 | if eq get value 0 46 |
| 1387 | ret true |
| 1388 | end |
| 1389 | if ff_equal value ff_node |
| 1390 | ret true |
| 1391 | end |
| 1392 | if ff_equal value ff_target |
| 1393 | ret true |
| 1394 | end |
| 1395 | if ff_equal value ff_build |
| 1396 | ret true |
| 1397 | end |
| 1398 | if ff_equal value ff_dist |
| 1399 | ret true |
| 1400 | end |
| 1401 | if ff_equal value ff_py |
| 1402 | ret true |
| 1403 | end |
| 1404 | if ff_equal value ff_venv |
| 1405 | ret true |
| 1406 | end |
| 1407 | if ff_equal value ff_dotvenv |
| 1408 | ret true |
| 1409 | end |
| 1410 | ret ff_equal value ff_site |
| 1411 | end |
| 1412 | |
| 1413 | fn ff_childpath dir ulong pos ulong size ulong to bool |
| 1414 | ff_queuepath dir |
| 1415 | base = get ff_s 0 |
| 1416 | extra = ulong 1 |
| 1417 | if eq base 1 |
| 1418 | extra = 0 |
| 1419 | end |
| 1420 | if ge add add base extra size len ff_path |
| 1421 | ff_warn |
| 1422 | ret false |
| 1423 | end |
| 1424 | if ne extra 0 |
| 1425 | put ff_path base 47 |
| 1426 | end |
| 1427 | for i ulong size bound 65536 |
| 1428 | c = get ff_buf add pos i |
| 1429 | put ff_path add add base extra i c |
| 1430 | end |
| 1431 | put ff_s 0 add add base extra size |
| 1432 | ret true |
| 1433 | end |
| 1434 | |
| 1435 | fn ff_entry dir ulong pos ulong endpos ulong to bool |
| 1436 | start = add pos 19 |
| 1437 | n = ulong 0 |
| 1438 | while lt add start n endpos bound 65536 |
| 1439 | if eq get ff_buf add start n 0 |
| 1440 | break |
| 1441 | end |
| 1442 | n = add n 1 |
| 1443 | end |
| 1444 | if eq add start n endpos |
| 1445 | ff_warn |
| 1446 | ret true |
| 1447 | end |
| 1448 | if eq n 0 |
| 1449 | ret true |
| 1450 | end |
| 1451 | if eq get ff_buf start 46 |
| 1452 | if eq n 1 |
| 1453 | ret true |
| 1454 | end |
| 1455 | if eq n 2 |
| 1456 | if eq get ff_buf add start 1 46 |
| 1457 | ret true |
| 1458 | end |
| 1459 | end |
| 1460 | end |
| 1461 | if not ff_childpath dir start n |
| 1462 | ret true |
| 1463 | end |
| 1464 | if not ff_getstat false |
| 1465 | ff_warn |
| 1466 | ret true |
| 1467 | end |
| 1468 | kind = ff_mode |
| 1469 | if eq kind 16384 |
| 1470 | if ff_skipname start n |
| 1471 | ret true |
| 1472 | end |
| 1473 | ret ff_enqueue |
| 1474 | end |
| 1475 | if or eq kind 32768 eq kind 40960 |
| 1476 | ret ff_record |
| 1477 | end |
| 1478 | ret true |
| 1479 | end |
| 1480 | |
| 1481 | fn ff_dirbytes dir ulong size ulong to bool |
| 1482 | p = ulong 0 |
| 1483 | while lt p size bound 65536 |
| 1484 | if lt sub size p 20 |
| 1485 | ff_warn |
| 1486 | ret true |
| 1487 | end |
| 1488 | low = ulong get ff_buf add p 16 |
| 1489 | high = ulong get ff_buf add p 17 |
| 1490 | rec = add low shl high 8 |
| 1491 | if or lt rec 20 gt add p rec size |
| 1492 | ff_warn |
| 1493 | ret true |
| 1494 | end |
| 1495 | if not ff_entry dir p add p rec |
| 1496 | ret false |
| 1497 | end |
| 1498 | p = add p rec |
| 1499 | end |
| 1500 | ret true |
| 1501 | end |
| 1502 | |
| 1503 | fn ff_scandir dir ulong to bool |
| 1504 | ff_queuepath dir |
| 1505 | fd = int fopen ff_path 0 get ff_s 0 49152 0 |
| 1506 | put ff_s 6 add get ff_s 6 1 |
| 1507 | if lt fd 0 |
| 1508 | ff_warn |
| 1509 | ret true |
| 1510 | end |
| 1511 | k = fstat fd ff_stat 0 len ff_stat |
| 1512 | if lt k 0 |
| 1513 | k = fclose fd |
| 1514 | ff_warn |
| 1515 | ret true |
| 1516 | end |
| 1517 | if not ff_samedir dir |
| 1518 | k = fclose fd |
| 1519 | ff_warn |
| 1520 | ret true |
| 1521 | end |
| 1522 | ok = true |
| 1523 | while true bound 9223372036854775807 |
| 1524 | n = getdnts fd ff_buf 0 len ff_buf |
| 1525 | if eq n -4 |
| 1526 | continue |
| 1527 | end |
| 1528 | if lt n 0 |
| 1529 | ff_warn |
| 1530 | break |
| 1531 | end |
| 1532 | if eq n 0 |
| 1533 | break |
| 1534 | end |
| 1535 | if not ff_dirbytes dir ulong n |
| 1536 | ok = false |
| 1537 | break |
| 1538 | end |
| 1539 | end |
| 1540 | k = fclose fd |
| 1541 | ret ok |
| 1542 | end |
| 1543 | |
| 1544 | fn ff_samedir dir ulong to bool |
| 1545 | if ne ff_mode 16384 |
| 1546 | ret false |
| 1547 | end |
| 1548 | if ne ff_statword 0 8 get ff_qmeta add mul dir 4 2 |
| 1549 | ret false |
| 1550 | end |
| 1551 | ret eq ff_statword 8 8 get ff_qmeta add mul dir 4 3 |
| 1552 | end |
| 1553 | |
| 1554 | fn ff_rootarg source view uchar * to bool |
| 1555 | if eq len source 0 |
| 1556 | ret false |
| 1557 | end |
| 1558 | if eq get source 0 47 |
| 1559 | if not ff_pathset source |
| 1560 | ret false |
| 1561 | end |
| 1562 | else |
| 1563 | n = get ff_s 19 |
| 1564 | for i ulong n bound 4096 |
| 1565 | c = get ff_cwd i |
| 1566 | put ff_path i c |
| 1567 | end |
| 1568 | put ff_s 0 n |
| 1569 | if not ff_pathadd ff_slash |
| 1570 | ret false |
| 1571 | end |
| 1572 | if not ff_pathadd source |
| 1573 | ret false |
| 1574 | end |
| 1575 | end |
| 1576 | ret ff_normalize |
| 1577 | end |
| 1578 | |
| 1579 | fn ff_roots to bool |
| 1580 | if not ff_rootargs |
| 1581 | if eq get ff_s 18 0 |
| 1582 | put ff_s 13 1 |
| 1583 | ret false |
| 1584 | end |
| 1585 | ff_homepath |
| 1586 | ret ff_enqueue |
| 1587 | end |
| 1588 | for i ulong sub ulong argcnt 2 bound 9223372036854775807 |
| 1589 | n = argread add i 2 ff_arg 0 len ff_arg |
| 1590 | if lt n 0 |
| 1591 | ff_warn |
| 1592 | else |
| 1593 | if ff_rootargbuf ulong n |
| 1594 | if not ff_enqueue |
| 1595 | ret false |
| 1596 | end |
| 1597 | else |
| 1598 | ff_warn |
| 1599 | end |
| 1600 | end |
| 1601 | end |
| 1602 | ret true |
| 1603 | end |
| 1604 | |
| 1605 | fn ff_rootargs to bool |
| 1606 | if le argcnt 2 |
| 1607 | ret false |
| 1608 | end |
| 1609 | b = new uchar 16 0 |
| 1610 | n = argread 1 b 0 len b |
| 1611 | if ne n long len ff_reindexarg |
| 1612 | ret false |
| 1613 | end |
| 1614 | for i ulong len ff_reindexarg |
| 1615 | if ne get b i get ff_reindexarg i |
| 1616 | ret false |
| 1617 | end |
| 1618 | end |
| 1619 | ret true |
| 1620 | end |
| 1621 | |
| 1622 | fn ff_rootargbuf size ulong to bool |
| 1623 | local = new uchar 4096 0 |
| 1624 | if ge size len local |
| 1625 | ret false |
| 1626 | end |
| 1627 | for j ulong size bound 4096 |
| 1628 | put local j get ff_arg j |
| 1629 | end |
| 1630 | ret ff_rootarg part local 0 size |
| 1631 | end |
| 1632 | |
| 1633 | fn ff_publish to bool |
| 1634 | ff_header |
| 1635 | k = fseek get ff_fd 3 0 0 |
| 1636 | if ne k 0 |
| 1637 | ret false |
| 1638 | end |
| 1639 | if ne ff_writeheader 0 |
| 1640 | ret false |
| 1641 | end |
| 1642 | if ne fsync get ff_fd 3 0 |
| 1643 | ret false |
| 1644 | end |
| 1645 | put ff_rename 0 2 |
| 1646 | put ff_rename 1 0 |
| 1647 | n = get ff_s 2 |
| 1648 | put ff_rename 2 uchar n |
| 1649 | put ff_rename 3 0 |
| 1650 | for i ulong n bound 96 |
| 1651 | c = get ff_tmp i |
| 1652 | put ff_rename add i 4 c |
| 1653 | end |
| 1654 | p = add n 4 |
| 1655 | put ff_rename p uchar len ff_index |
| 1656 | put ff_rename add p 1 0 |
| 1657 | for i ulong len ff_index |
| 1658 | put ff_rename add add p 2 i get ff_index i |
| 1659 | end |
| 1660 | k = renames ff_rename 0 add add p 2 len ff_index 0 |
| 1661 | if ne k 0 |
| 1662 | ret false |
| 1663 | end |
| 1664 | put ff_s 20 0 |
| 1665 | ret true |
| 1666 | end |
| 1667 | |
| 1668 | fn ff_rebuild to int |
| 1669 | for i ulong 32 |
| 1670 | put ff_s i 0 |
| 1671 | end |
| 1672 | if not ff_setup true |
| 1673 | ff_message ff_cachemsg |
| 1674 | ff_cleanup |
| 1675 | ret 1 |
| 1676 | end |
| 1677 | if not ff_enter |
| 1678 | ff_message ff_failmsg |
| 1679 | ff_cleanup |
| 1680 | ret 1 |
| 1681 | end |
| 1682 | started = ff_startoutput |
| 1683 | if ne started 0 |
| 1684 | if eq started 3 |
| 1685 | ff_message ff_busymsg |
| 1686 | else |
| 1687 | ff_message ff_failmsg |
| 1688 | end |
| 1689 | ff_cleanup |
| 1690 | ret started |
| 1691 | end |
| 1692 | ff_alarmsetting |
| 1693 | ok = ff_roots |
| 1694 | di = ulong 0 |
| 1695 | while and ok lt di get ff_s 7 bound 9223372036854775807 |
| 1696 | ok = ff_scandir di |
| 1697 | di = add di 1 |
| 1698 | end |
| 1699 | if ok |
| 1700 | ok = ff_publish |
| 1701 | end |
| 1702 | if not ok |
| 1703 | put ff_s 13 1 |
| 1704 | end |
| 1705 | ff_cleanup |
| 1706 | if ne get ff_s 13 0 |
| 1707 | ff_message ff_failmsg |
| 1708 | ret 1 |
| 1709 | end |
| 1710 | if ne get ff_s 4 0 |
| 1711 | ff_message ff_partialmsg |
| 1712 | end |
| 1713 | ret 0 |
| 1714 | end |