omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / apps / interplane-forge / collab / native / write.om
| 1 | note Native issue writes. The author comes from the session established by SSH key proof. The |
| 2 | note repository lock serializes replacements of its index and threads, even across server processes. |
| 3 | note fopen flags below use Linux AArch64 values (O_CLOEXEC 524288, O_NOFOLLOW 32768). |
| 4 | text tniwnp "/issues/new" |
| 5 | text tniwlog "login" |
| 6 | text tniwlink "<p><a href=\"" |
| 7 | text tniwnewa "\">New issue</a></p>\n" |
| 8 | text tniwttl "New issue" |
| 9 | text tniwform "<section class=\"box\" id=\"comment-form\">" |
| 10 | text tniwsign "<p><a href=\"" |
| 11 | text tniwsgc "\">Sign in to comment</a></p>" |
| 12 | text tniwsgn "\">Sign in to open an issue</a></p>" |
| 13 | text tniwfa "<form method=\"post\" action=\"" |
| 14 | text tniwcs "\"><input type=\"hidden\" name=\"csrf\" value=\"" |
| 15 | text tniwrh "\"><input type=\"hidden\" name=\"request\" value=\"" |
| 16 | text tniwqt "\">" |
| 17 | text tniwtf "<p><label>Title<br><input name=\"title\" required maxlength=\"256\"></label></p>" |
| 18 | text tniwdf "<p><label>Description (Markdown)<br><textarea name=\"body\" rows=\"8\" maxlength=\"16000\"></textarea></label></p>" |
| 19 | text tniwcf "<p><label>Comment (Markdown)<br><textarea name=\"body\" rows=\"6\" required maxlength=\"16000\"></textarea></label></p>" |
| 20 | text tniwbn "<p><button type=\"submit\">Open issue</button></p>" |
| 21 | text tniwbc "<p><button type=\"submit\">Post comment</button></p>" |
| 22 | text tniwfe "</form></section>\n" |
| 23 | text tniwrq "request" |
| 24 | text tniwrql "request " |
| 25 | text tniwmrq "Reload the form before sending it again." |
| 26 | text tniwfs "issue store: directory sync failed after publication\n" |
| 27 | text tniwfsch "forge/issue-form/1" |
| 28 | text tniwwsch "forge/issue-write/1" |
| 29 | text tniwact "action" |
| 30 | text tniwcsrf "csrf" |
| 31 | text tniwappl "applied" |
| 32 | text tniwft "title" |
| 33 | text tniwfb "body" |
| 34 | text tniwbadt "Enter a single-line title of 1 to 256 UTF-8 bytes." |
| 35 | text tniwbadb "Enter valid Markdown text of at most 16000 UTF-8 bytes. A comment cannot be empty." |
| 36 | text tniwopa "open\n" |
| 37 | text tniwlock ".write.lock" |
| 38 | text tniwist ".index.tmp" |
| 39 | text tniwtht ".thread.tmp" |
| 40 | text tniwstg ".new-" |
| 41 | text tniwdir "issues" |
| 42 | text tniwemp "" |
| 43 | global gniwid uchar 16 |
| 44 | global gniwtt uchar 256 |
| 45 | global gniwtl ulong 1 |
| 46 | global gniwrq uchar 32 |
| 47 | |
| 48 | fn niwlink to void |
| 49 | fput tniwlink |
| 50 | fputrl |
| 51 | fput tniwnp |
| 52 | fput tniwnewa |
| 53 | end |
| 54 | fn niwnewjson to void |
| 55 | fputc 34 |
| 56 | fputrl |
| 57 | fput tniwnp |
| 58 | fputc 34 |
| 59 | end |
| 60 | fn niwform k ulong opening bool to void |
| 61 | fput tniwform |
| 62 | if eq get gscur 0 0 |
| 63 | fput tniwsign |
| 64 | fputb |
| 65 | fput tniwlog |
| 66 | if opening |
| 67 | fput tniwsgn |
| 68 | else |
| 69 | fput tniwsgc |
| 70 | end |
| 71 | fput tnsece |
| 72 | ret |
| 73 | end |
| 74 | hex = new uchar 32 0 |
| 75 | if not niwtoken hex |
| 76 | fput tniwmrq |
| 77 | fput tnsece |
| 78 | ret |
| 79 | end |
| 80 | fput tniwfa |
| 81 | if opening |
| 82 | fputrl |
| 83 | fput tniwnp |
| 84 | else |
| 85 | nilink k |
| 86 | fput tncoms |
| 87 | end |
| 88 | fput tniwcs |
| 89 | for j ulong get fcsrfl 0 bound 64 |
| 90 | fputc get fcsrf j |
| 91 | end |
| 92 | fput tniwrh |
| 93 | for j ulong 32 |
| 94 | fputc get hex j |
| 95 | end |
| 96 | fput tniwqt |
| 97 | if opening |
| 98 | fput tniwtf |
| 99 | fput tniwdf |
| 100 | fput tniwbn |
| 101 | else |
| 102 | fput tniwcf |
| 103 | fput tniwbc |
| 104 | end |
| 105 | fput tniwfe |
| 106 | end |
| 107 | fn niwtoken hex edit uchar 32 to bool |
| 108 | raw = new uchar 16 0 |
| 109 | if not sorand raw |
| 110 | ret false |
| 111 | end |
| 112 | sohex raw hex |
| 113 | ret true |
| 114 | end |
| 115 | fn niwlogin to long |
| 116 | put fkind 0 2 |
| 117 | flocb |
| 118 | floct tniwlog |
| 119 | ret 303 |
| 120 | end |
| 121 | fn niwjsform k ulong opening bool to long |
| 122 | if eq get gscur 0 0 |
| 123 | ret niwlogin |
| 124 | end |
| 125 | hex = new uchar 32 0 |
| 126 | if not niwtoken hex |
| 127 | ret 500 |
| 128 | end |
| 129 | fyrhead tniwfsch |
| 130 | fyk tniwact |
| 131 | cojq |
| 132 | if opening |
| 133 | fputrl |
| 134 | fput tniwnp |
| 135 | else |
| 136 | nilink k |
| 137 | fput tncoms |
| 138 | end |
| 139 | cojq |
| 140 | fyk tniwcsrf |
| 141 | fjtb |
| 142 | for i ulong get fcsrfl 0 bound 64 |
| 143 | fjtc get fcsrf i |
| 144 | end |
| 145 | fjstr |
| 146 | fyk tniwrq |
| 147 | fysv hex |
| 148 | fyend |
| 149 | ret 200 |
| 150 | end |
| 151 | fn niwcform to long |
| 152 | if not fjwant |
| 153 | ret 405 |
| 154 | end |
| 155 | if eq get gscur 0 0 |
| 156 | ret niwlogin |
| 157 | end |
| 158 | if not niidx |
| 159 | ret 500 |
| 160 | end |
| 161 | k = niref |
| 162 | if ge k get gnn 0 |
| 163 | ret 404 |
| 164 | end |
| 165 | ret niwjsform k false |
| 166 | end |
| 167 | fn niwresult applied bool to long |
| 168 | if fjwant |
| 169 | fyrhead tniwwsch |
| 170 | fyk tcjpath |
| 171 | cojq |
| 172 | fputrl |
| 173 | fput tcissp |
| 174 | for i ulong 16 |
| 175 | fputc get gniwid i |
| 176 | end |
| 177 | cojq |
| 178 | fyk tniwappl |
| 179 | fybool applied |
| 180 | fyend |
| 181 | if applied |
| 182 | ret 201 |
| 183 | end |
| 184 | ret 200 |
| 185 | end |
| 186 | put fkind 0 2 |
| 187 | flocrepo |
| 188 | floct tcissp |
| 189 | for i ulong 16 |
| 190 | flocc get gniwid i |
| 191 | end |
| 192 | ret 303 |
| 193 | end |
| 194 | fn niwnew to long |
| 195 | if fjwant |
| 196 | ret niwjsform 0 true |
| 197 | end |
| 198 | fsetti tniwttl |
| 199 | frepohd 6 |
| 200 | niwform 0 true |
| 201 | ret 200 |
| 202 | end |
| 203 | fn niwerr t view uchar * to long |
| 204 | if fjwant |
| 205 | fyerr 400 |
| 206 | note The common error envelope is used by all machine clients. |
| 207 | else |
| 208 | frepohd 6 |
| 209 | fput tnbox |
| 210 | fput t |
| 211 | fput tnmetae |
| 212 | fput tnsece |
| 213 | end |
| 214 | ret 400 |
| 215 | end |
| 216 | fn niwfields opening bool to long |
| 217 | if ne cobfld tniwrq 32 |
| 218 | ret niwerr tniwmrq |
| 219 | end |
| 220 | for i ulong 32 |
| 221 | c = get gcfv i |
| 222 | if lt sohexv c 0 |
| 223 | ret niwerr tniwmrq |
| 224 | end |
| 225 | put gniwrq i c |
| 226 | end |
| 227 | if opening |
| 228 | n = cobfld tniwft |
| 229 | if or lt n 1 gt n 256 |
| 230 | ret niwerr tniwbadt |
| 231 | end |
| 232 | n = cotxtok ulong n false |
| 233 | if lt n 1 |
| 234 | ret niwerr tniwbadt |
| 235 | end |
| 236 | put gniwtl 0 ulong n |
| 237 | for i ulong ulong n bound 256 |
| 238 | put gniwtt i get gcfv i |
| 239 | end |
| 240 | end |
| 241 | b = cobfld tniwfb |
| 242 | if eq b -1 |
| 243 | b = 0 |
| 244 | end |
| 245 | if lt b 0 |
| 246 | ret niwerr tniwbadb |
| 247 | end |
| 248 | b = cotxtok ulong b true |
| 249 | if or or lt b 0 gt b 16000 and not opening eq b 0 |
| 250 | ret niwerr tniwbadb |
| 251 | end |
| 252 | put gcfvl 0 ulong b |
| 253 | ret 0 |
| 254 | end |
| 255 | fn niwpost opening bool to long |
| 256 | r = sowpre |
| 257 | if ne r 0 |
| 258 | if and fjwant ne r 303 |
| 259 | put fobl 0 0 |
| 260 | put fkind 0 0 |
| 261 | end |
| 262 | ret r |
| 263 | end |
| 264 | soratev get gscur 0 get gsnow 0 |
| 265 | r = niwfields opening |
| 266 | if ne r 0 |
| 267 | ret r |
| 268 | end |
| 269 | fd = niwacq opening |
| 270 | if lt fd 0 |
| 271 | if eq fd -2 |
| 272 | ret 404 |
| 273 | end |
| 274 | if eq fd -11 |
| 275 | put fretry 0 1 |
| 276 | ret 503 |
| 277 | end |
| 278 | ret 500 |
| 279 | end |
| 280 | if opening |
| 281 | r = niwcreate |
| 282 | else |
| 283 | r = niwcomment |
| 284 | end |
| 285 | x = fclose int fd |
| 286 | if gt r 0 |
| 287 | ret r |
| 288 | end |
| 289 | ret niwresult eq r 0 |
| 290 | end |
| 291 | |
| 292 | note ---- Storage |
| 293 | fn niwdirs to bool |
| 294 | fpb |
| 295 | fpt tfdata |
| 296 | fpt tniwdir |
| 297 | if not niwmkdir |
| 298 | ret false |
| 299 | end |
| 300 | fpc 47 |
| 301 | fpt tfowner |
| 302 | if not niwmkdir |
| 303 | ret false |
| 304 | end |
| 305 | fpc 47 |
| 306 | i = get fridx 0 |
| 307 | for k ulong get fanl i bound 128 |
| 308 | fpc frnbyte i k |
| 309 | end |
| 310 | ret niwmkdir |
| 311 | end |
| 312 | fn niwmkdir to bool |
| 313 | r = makedir fpth 0 get fpthl 0 448 |
| 314 | ret or eq r 0 eq r -17 |
| 315 | end |
| 316 | fn niwacq opening bool to long |
| 317 | if opening |
| 318 | if not niwdirs |
| 319 | ret -5 |
| 320 | end |
| 321 | end |
| 322 | nipath |
| 323 | fpt tniwlock |
| 324 | fd = fopen fpth 0 get fpthl 0 557121 384 |
| 325 | if lt fd 0 |
| 326 | ret fd |
| 327 | end |
| 328 | r = flock int fd 6 |
| 329 | if ne r 0 |
| 330 | x = fclose int fd |
| 331 | ret r |
| 332 | end |
| 333 | ret fd |
| 334 | end |
| 335 | fn niwpath stage bool file view uchar * to void |
| 336 | nipath |
| 337 | if stage |
| 338 | fpt tniwstg |
| 339 | end |
| 340 | for i ulong 16 |
| 341 | fpc get gniwid i |
| 342 | end |
| 343 | if ne len file 0 |
| 344 | fpc 47 |
| 345 | fpt file |
| 346 | end |
| 347 | end |
| 348 | fn niwarg to void |
| 349 | soavopen |
| 350 | for i ulong get fpthl 0 bound 4096 |
| 351 | soavc get fpth i |
| 352 | end |
| 353 | end |
| 354 | note Source selectors: response buffer (0), file read buffer (1), title (2), form body (3), open status (4). |
| 355 | fn niwwrite fd int src ulong p ulong n ulong to long |
| 356 | if eq src 0 |
| 357 | ret write fd fob p n |
| 358 | end |
| 359 | if eq src 1 |
| 360 | ret write fd fxo p n |
| 361 | end |
| 362 | if eq src 2 |
| 363 | ret write fd gniwtt p n |
| 364 | end |
| 365 | if eq src 3 |
| 366 | ret write fd gcfv p n |
| 367 | end |
| 368 | ret write fd tniwopa p n |
| 369 | end |
| 370 | fn niwout fd int src ulong size ulong to bool |
| 371 | p = ulong 0 |
| 372 | for i ulong 100000 |
| 373 | if eq p size |
| 374 | ret true |
| 375 | end |
| 376 | n = niwwrite fd src p sub size p |
| 377 | if gt n 0 |
| 378 | p = add p ulong n |
| 379 | else |
| 380 | if ne n -4 |
| 381 | ret false |
| 382 | end |
| 383 | end |
| 384 | end |
| 385 | ret false |
| 386 | end |
| 387 | fn niwput src ulong size ulong tail ulong to bool |
| 388 | fd = fopen fpth 0 get fpthl 0 557249 384 |
| 389 | if lt fd 0 |
| 390 | ret false |
| 391 | end |
| 392 | ok = niwout int fd src size |
| 393 | if and ok gt tail 0 |
| 394 | ok = niwout int fd 0 tail |
| 395 | end |
| 396 | if ok |
| 397 | ok = eq fsync int fd 0 |
| 398 | end |
| 399 | r = fclose int fd |
| 400 | if or not ok ne r 0 |
| 401 | x = unlink fpth 0 get fpthl 0 |
| 402 | ret false |
| 403 | end |
| 404 | ret true |
| 405 | end |
| 406 | note Read a whole file into fxo under the write lock. Distinguish missing from other I/O errors. |
| 407 | fn niwread cap ulong to long |
| 408 | fd = fopen fpth 0 get fpthl 0 559104 0 |
| 409 | if lt fd 0 |
| 410 | ret fd |
| 411 | end |
| 412 | n = niwreadfd int fd cap |
| 413 | r = fclose int fd |
| 414 | ret n |
| 415 | end |
| 416 | fn niwreadfd fd int cap ulong to long |
| 417 | p = ulong 0 |
| 418 | for i ulong 100000 |
| 419 | if gt p cap |
| 420 | ret -27 |
| 421 | end |
| 422 | n = read fd fxo p sub add cap 1 p |
| 423 | if eq n 0 |
| 424 | ret long p |
| 425 | end |
| 426 | if gt n 0 |
| 427 | p = add p ulong n |
| 428 | else |
| 429 | if ne n -4 |
| 430 | ret n |
| 431 | end |
| 432 | end |
| 433 | end |
| 434 | ret -5 |
| 435 | end |
| 436 | fn niwremove file view uchar * stage bool to void |
| 437 | niwpath stage file |
| 438 | x = unlink fpth 0 get fpthl 0 |
| 439 | end |
| 440 | fn niwdiscard stage bool to void |
| 441 | niwremove tnfttl stage |
| 442 | niwremove tnfdsc stage |
| 443 | niwremove tnfsts stage |
| 444 | niwremove tniwnat stage |
| 445 | niwpath stage tniwemp |
| 446 | x = rmdir fpth 0 get fpthl 0 |
| 447 | end |
| 448 | note Use the authenticated DID and the form token as a stable issue ID across retries. |
| 449 | fn niwnewid to void |
| 450 | seed = new uchar 160 0 |
| 451 | hash = new uchar 32 0 |
| 452 | hex = new uchar 16 0 |
| 453 | for i ulong 32 |
| 454 | put seed i get gniwrq i |
| 455 | end |
| 456 | d = get gscur 0 |
| 457 | o = get gsso d |
| 458 | n = get gssl d |
| 459 | for i ulong n bound 128 |
| 460 | put seed add i 32 get gsstr add o i |
| 461 | end |
| 462 | x = sha2_digest 256 part seed 0 add 32 n hash |
| 463 | sohex part hash 0 8 hex |
| 464 | for i ulong 16 |
| 465 | put gniwid i get hex i |
| 466 | end |
| 467 | end |
| 468 | fn niwreq to void |
| 469 | for i ulong 32 |
| 470 | fputc get gniwrq i |
| 471 | end |
| 472 | end |
| 473 | fn niwmeta to void |
| 474 | put fobl 0 0 |
| 475 | fput tniwdid |
| 476 | niwactor |
| 477 | fputc 10 |
| 478 | fput tnghop |
| 479 | fjisob get gsnow 0 |
| 480 | fputc 10 |
| 481 | fput tniwrql |
| 482 | niwreq |
| 483 | fputc 10 |
| 484 | end |
| 485 | fn niwactor to void |
| 486 | d = get gscur 0 |
| 487 | o = get gsso d |
| 488 | for i ulong get gssl d bound 128 |
| 489 | fputc get gsstr add o i |
| 490 | end |
| 491 | end |
| 492 | fn niwnewfiles to bool |
| 493 | niwpath true tnfttl |
| 494 | if not niwput 2 get gniwtl 0 0 |
| 495 | ret false |
| 496 | end |
| 497 | niwpath true tnfdsc |
| 498 | if not niwput 3 get gcfvl 0 0 |
| 499 | ret false |
| 500 | end |
| 501 | niwpath true tnfsts |
| 502 | if not niwput 4 len tniwopa 0 |
| 503 | ret false |
| 504 | end |
| 505 | niwmeta |
| 506 | niwpath true tniwnat |
| 507 | ok = niwput 0 get fobl 0 0 |
| 508 | put fobl 0 0 |
| 509 | if not ok |
| 510 | ret false |
| 511 | end |
| 512 | ret niwsync true |
| 513 | end |
| 514 | fn niwsync stage bool to bool |
| 515 | niwpath stage tniwemp |
| 516 | ret niwsyncat |
| 517 | end |
| 518 | fn niwsyncat to bool |
| 519 | fd = fopen fpth 0 get fpthl 0 573440 0 |
| 520 | if lt fd 0 |
| 521 | ret false |
| 522 | end |
| 523 | r = fsync int fd |
| 524 | x = fclose int fd |
| 525 | ret eq r 0 |
| 526 | end |
| 527 | note Publish the complete issue before replacing its index. After a crash between the renames the |
| 528 | note unindexed directory is unreachable. Retrying the same request repairs its index entry. |
| 529 | fn niwcreate to long |
| 530 | niwnewid |
| 531 | nipath |
| 532 | fpt tnindex |
| 533 | n = niwread len gnix |
| 534 | if eq n -2 |
| 535 | n = 0 |
| 536 | end |
| 537 | if eq n -27 |
| 538 | ret 409 |
| 539 | end |
| 540 | if or lt n 0 ne rem ulong n 17 0 |
| 541 | ret 500 |
| 542 | end |
| 543 | for j ulong div ulong n 17 bound NIROWS |
| 544 | p = mul j 17 |
| 545 | if not niidok p |
| 546 | ret 500 |
| 547 | end |
| 548 | if niwrow p |
| 549 | if niwexisting |
| 550 | ret -1 |
| 551 | end |
| 552 | ret 409 |
| 553 | end |
| 554 | end |
| 555 | if eq n long len gnix |
| 556 | ret 409 |
| 557 | end |
| 558 | for i ulong 16 |
| 559 | put fob i get gniwid i |
| 560 | end |
| 561 | put fob 16 10 |
| 562 | nipath |
| 563 | fpt tniwist |
| 564 | x = unlink fpth 0 get fpthl 0 |
| 565 | if not niwput 1 ulong n 17 |
| 566 | ret 500 |
| 567 | end |
| 568 | r = niwinst |
| 569 | if gt r 0 |
| 570 | nipath |
| 571 | fpt tniwist |
| 572 | x = unlink fpth 0 get fpthl 0 |
| 573 | end |
| 574 | ret r |
| 575 | end |
| 576 | fn niwrow p ulong to bool |
| 577 | for i ulong 16 |
| 578 | if ne get fxo add p i get gniwid i |
| 579 | ret false |
| 580 | end |
| 581 | end |
| 582 | ret true |
| 583 | end |
| 584 | fn niwexisting to bool |
| 585 | niwpath false tniwnat |
| 586 | r = niwread 256 |
| 587 | if le r 0 |
| 588 | ret false |
| 589 | end |
| 590 | for i ulong ulong r bound 256 |
| 591 | put gngh i get fxo i |
| 592 | end |
| 593 | put gnghl 0 ulong r |
| 594 | if not niwmetasame |
| 595 | ret false |
| 596 | end |
| 597 | ret niwsame |
| 598 | end |
| 599 | fn niwmetasame to bool |
| 600 | d = get gscur 0 |
| 601 | o = get gsso d |
| 602 | a = nighv tniwdid |
| 603 | if ne get gnr 15 get gssl d |
| 604 | ret false |
| 605 | end |
| 606 | for i ulong get gssl d bound 128 |
| 607 | if ne get gngh add a i get gsstr add o i |
| 608 | ret false |
| 609 | end |
| 610 | end |
| 611 | b = nighv tniwrql |
| 612 | if ne get gnr 15 32 |
| 613 | ret false |
| 614 | end |
| 615 | for i ulong 32 |
| 616 | if ne get gngh add b i get gniwrq i |
| 617 | ret false |
| 618 | end |
| 619 | end |
| 620 | ret true |
| 621 | end |
| 622 | fn niwsame to bool |
| 623 | niwpath false tnfttl |
| 624 | if ne niwread 256 long get gniwtl 0 |
| 625 | ret false |
| 626 | end |
| 627 | for i ulong get gniwtl 0 bound 256 |
| 628 | if ne get fxo i get gniwtt i |
| 629 | ret false |
| 630 | end |
| 631 | end |
| 632 | niwpath false tnfdsc |
| 633 | if ne niwread 16000 long get gcfvl 0 |
| 634 | ret false |
| 635 | end |
| 636 | for i ulong get gcfvl 0 bound 16000 |
| 637 | if ne get fxo i get gcfv i |
| 638 | ret false |
| 639 | end |
| 640 | end |
| 641 | ret true |
| 642 | end |
| 643 | fn niwinst to long |
| 644 | niwpath false tniwemp |
| 645 | r = stat fpth 0 get fpthl 0 fstb 0 128 |
| 646 | if eq r -2 |
| 647 | if not niwstage |
| 648 | ret 500 |
| 649 | end |
| 650 | else |
| 651 | if lt r 0 |
| 652 | ret 500 |
| 653 | end |
| 654 | if not niwexisting |
| 655 | ret 409 |
| 656 | end |
| 657 | end |
| 658 | nipath |
| 659 | if not niwsyncat |
| 660 | ret 500 |
| 661 | end |
| 662 | soavb |
| 663 | nipath |
| 664 | fpt tniwist |
| 665 | niwarg |
| 666 | nipath |
| 667 | fpt tnindex |
| 668 | niwarg |
| 669 | if ne renames gspk 0 get gspkl 0 0 0 |
| 670 | ret 500 |
| 671 | end |
| 672 | nipath |
| 673 | if not niwsyncat |
| 674 | flog tniwfs |
| 675 | end |
| 676 | ret 0 |
| 677 | end |
| 678 | fn niwstage to bool |
| 679 | note Discard remnants of an interrupted attempt of this same unindexed action. |
| 680 | niwdiscard true |
| 681 | niwpath true tniwemp |
| 682 | if ne makedir fpth 0 get fpthl 0 448 0 |
| 683 | ret false |
| 684 | end |
| 685 | if not niwnewfiles |
| 686 | niwdiscard true |
| 687 | ret false |
| 688 | end |
| 689 | soavb |
| 690 | niwpath true tniwemp |
| 691 | niwarg |
| 692 | niwpath false tniwemp |
| 693 | niwarg |
| 694 | if ne renames gspk 0 get gspkl 0 1 0 |
| 695 | niwdiscard true |
| 696 | ret false |
| 697 | end |
| 698 | ret true |
| 699 | end |
| 700 | fn niwrecord to void |
| 701 | put fobl 0 0 |
| 702 | fput tniwncom |
| 703 | cosp |
| 704 | fjisob get gsnow 0 |
| 705 | cosp |
| 706 | niwactor |
| 707 | cosp |
| 708 | niwreq |
| 709 | cosp |
| 710 | n = get gcfvl 0 |
| 711 | fnum n |
| 712 | fputc 10 |
| 713 | for i ulong n bound 16000 |
| 714 | fputc get gcfv i |
| 715 | end |
| 716 | fputc 10 |
| 717 | end |
| 718 | fn niwcomment to long |
| 719 | for i ulong 16 |
| 720 | put gniwid i get gcrq i |
| 721 | end |
| 722 | r = niwindexed |
| 723 | if ne r 0 |
| 724 | ret r |
| 725 | end |
| 726 | niwpath false tnfthr |
| 727 | n = niwread 1048576 |
| 728 | if eq n -2 |
| 729 | n = 0 |
| 730 | end |
| 731 | if eq n -27 |
| 732 | ret 409 |
| 733 | end |
| 734 | if lt n 0 |
| 735 | ret 500 |
| 736 | end |
| 737 | r = niwthread ulong n |
| 738 | if ne r 0 |
| 739 | ret r |
| 740 | end |
| 741 | niwrecord |
| 742 | if gt add ulong n get fobl 0 1048576 |
| 743 | put fobl 0 0 |
| 744 | ret 409 |
| 745 | end |
| 746 | niwpath false tniwtht |
| 747 | x = unlink fpth 0 get fpthl 0 |
| 748 | ok = niwput 1 ulong n get fobl 0 |
| 749 | put fobl 0 0 |
| 750 | if not ok |
| 751 | ret 500 |
| 752 | end |
| 753 | soavb |
| 754 | niwarg |
| 755 | niwpath false tnfthr |
| 756 | niwarg |
| 757 | if ne renames gspk 0 get gspkl 0 0 0 |
| 758 | niwremove tniwtht false |
| 759 | ret 500 |
| 760 | end |
| 761 | if not niwsync false |
| 762 | flog tniwfs |
| 763 | end |
| 764 | ret 0 |
| 765 | end |
| 766 | fn niwindexed to long |
| 767 | nipath |
| 768 | fpt tnindex |
| 769 | n = niwread len gnix |
| 770 | if eq n -2 |
| 771 | ret 404 |
| 772 | end |
| 773 | if or lt n 0 ne rem ulong n 17 0 |
| 774 | ret 500 |
| 775 | end |
| 776 | for j ulong div ulong n 17 bound NIROWS |
| 777 | p = mul j 17 |
| 778 | if and niidok p niwrow p |
| 779 | ret 0 |
| 780 | end |
| 781 | end |
| 782 | ret 404 |
| 783 | end |
| 784 | note Check the whole prefix before replacing it. An already-published form returns its prior result. |
| 785 | fn niwthread n ulong to long |
| 786 | for i ulong n bound 1048576 |
| 787 | put gnth i get fxo i |
| 788 | end |
| 789 | put gnthl 0 n |
| 790 | p = ulong 0 |
| 791 | while lt p n bound 1048576 |
| 792 | p = nirec p |
| 793 | k = get gnr 0 |
| 794 | if eq k 0 |
| 795 | ret 409 |
| 796 | end |
| 797 | if eq k 4 |
| 798 | if niwcomreq |
| 799 | if niwcombody |
| 800 | ret -1 |
| 801 | end |
| 802 | ret 409 |
| 803 | end |
| 804 | end |
| 805 | end |
| 806 | ret 0 |
| 807 | end |
| 808 | fn niwcomreq to bool |
| 809 | d = get gscur 0 |
| 810 | n = get gssl d |
| 811 | if or ne get gnr 4 n ne get gnr 6 32 |
| 812 | ret false |
| 813 | end |
| 814 | a = get gnr 3 |
| 815 | o = get gsso d |
| 816 | for i ulong n bound 128 |
| 817 | if ne get gnth add a i get gsstr add o i |
| 818 | ret false |
| 819 | end |
| 820 | end |
| 821 | b = get gnr 5 |
| 822 | for i ulong 32 |
| 823 | if ne get gnth add b i get gniwrq i |
| 824 | ret false |
| 825 | end |
| 826 | end |
| 827 | ret true |
| 828 | end |
| 829 | fn niwcombody to bool |
| 830 | n = get gcfvl 0 |
| 831 | if ne n get gnr 11 |
| 832 | ret false |
| 833 | end |
| 834 | a = get gnr 10 |
| 835 | for i ulong n bound 16000 |
| 836 | if ne get gnth add a i get gcfv i |
| 837 | ret false |
| 838 | end |
| 839 | end |
| 840 | ret true |
| 841 | end |