hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
| 1 | note Linux Ask. Model endpoint and model are explicit HOP_MODEL_URL and HOP_MODEL settings. |
| 2 | note curl is the platform HTTP/TLS transport; build/linux/dependency-curl.txt records its exact version. |
| 3 | note Successor: Omega om/tls client plus native DNS/HTTP transport. No shell or host language runtime. |
| 4 | note curl reads URL, request and optional API key from anonymous memory on stdin, never argv or a disk file. |
| 5 | note No redirects, ambient proxy, curlrc, cookies, retries or TLS verification overrides. |
| 6 | note Ask is synchronous: the window waits for the configured server. The transport deadline is 60 seconds. |
| 7 | global hc_cfg uchar * |
| 8 | global hc_json uchar * |
| 9 | global hc_str uchar * |
| 10 | global hc_body uchar * |
| 11 | global hc_url uchar * |
| 12 | global hc_model uchar * |
| 13 | global hc_key uchar * |
| 14 | global hc_ans uchar * |
| 15 | global hc_n ulong 8 |
| 16 | global hc_pos ulong 1 |
| 17 | global hc_found ulong 1 |
| 18 | global hc_http ulong 1 |
| 19 | global hc_env uchar 131072 |
| 20 | global hc_io uchar 8192 |
| 21 | global hc_pipe uchar 16 |
| 22 | global hc_wait uchar 4 |
| 23 | global hc_exec uchar 128 |
| 24 | text hc_uk "HOP_MODEL_URL=" |
| 25 | text hc_mk "HOP_MODEL=" |
| 26 | text hc_kk "HOP_API_KEY=" |
| 27 | text hc_h "http://" |
| 28 | text hc_hs "https://" |
| 29 | text hc_tail "/chat/completions" |
| 30 | text hc_curl "/usr/bin/curl" |
| 31 | text hc_q "-q" |
| 32 | text hc_config "--config" |
| 33 | text hc_dash "-" |
| 34 | text hc_memname "hop-model-request" |
| 35 | text hc_ct "silent\nshow-error\nfail-with-body\ngloboff\nconnect-timeout = 10\nmax-time = 60\nproto = \"=http,https\"\nproxy = \"\"\nrequest = \"POST\"\nheader = \"Content-Type: application/json\"\nurl = \"" |
| 36 | text hc_auth "\"\nheader = \"Authorization: Bearer " |
| 37 | text hc_data "\"\ndata-binary = \"" |
| 38 | text hc_end "\"\nwrite-out = \"\\n%{http_code}\"\n" |
| 39 | text hc_b1 "{\"model\":\"" |
| 40 | text hc_b2 "\",\"messages\":[{\"role\":\"user\",\"content\":\"" |
| 41 | text hc_b3 "\"}],\"stream\":false}" |
| 42 | text hc_choices "choices" |
| 43 | text hc_message "message" |
| 44 | text hc_content "content" |
| 45 | text hc_true "true" |
| 46 | text hc_false "false" |
| 47 | text hc_null "null" |
| 48 | text hc_need "Ask needs a model. Set HOP_MODEL_URL to your OpenAI-compatible server's base address and HOP_MODEL to its model name." |
| 49 | text hc_badurl "Ask: use an http:// or https:// model base address without control characters, query or fragment." |
| 50 | text hc_badkey "Ask: HOP_API_KEY contains a control character and cannot be used as a request header." |
| 51 | text hc_transport "Ask: the model request failed. Check the server address, model name, sign-in and network. curl with HTTPS support is required." |
| 52 | text hc_server "Ask: the server returned HTTP " |
| 53 | text hc_serverend ". Check the model settings and sign-in." |
| 54 | text hc_badjson "Ask: the server did not return a valid chat answer (choices[0].message.content must be text)." |
| 55 | text hc_mem "Hop Ask: the system could not allocate memory.\n" |
| 56 | text hc_action "Ask: " |
| 57 | |
| 58 | fn hc_res which ulong need ulong to void |
| 59 | r = long 0 |
| 60 | if eq which 0 |
| 61 | if gt need len hc_cfg |
| 62 | r = enlarge hc_cfg add need add len hc_cfg 256 |
| 63 | end |
| 64 | end |
| 65 | if eq which 1 |
| 66 | if gt need len hc_json |
| 67 | r = enlarge hc_json add need add len hc_json 8192 |
| 68 | end |
| 69 | end |
| 70 | if eq which 2 |
| 71 | if gt need len hc_str |
| 72 | r = enlarge hc_str add need add len hc_str 256 |
| 73 | end |
| 74 | end |
| 75 | if eq which 3 |
| 76 | if gt need len hc_body |
| 77 | r = enlarge hc_body add need add len hc_body 256 |
| 78 | end |
| 79 | end |
| 80 | if eq which 4 |
| 81 | if gt need len hc_url |
| 82 | r = enlarge hc_url add need add len hc_url 256 |
| 83 | end |
| 84 | end |
| 85 | if eq which 5 |
| 86 | if gt need len hc_model |
| 87 | r = enlarge hc_model add need add len hc_model 256 |
| 88 | end |
| 89 | end |
| 90 | if eq which 6 |
| 91 | if gt need len hc_key |
| 92 | r = enlarge hc_key add need add len hc_key 256 |
| 93 | end |
| 94 | end |
| 95 | if eq which 7 |
| 96 | if gt need len hc_ans |
| 97 | r = enlarge hc_ans add need add len hc_ans 256 |
| 98 | end |
| 99 | end |
| 100 | if lt r 0 |
| 101 | x = write 2 hc_mem 0 len hc_mem |
| 102 | exit 1 |
| 103 | end |
| 104 | end |
| 105 | |
| 106 | fn hc_add which ulong c uchar to void |
| 107 | p = get hc_n which |
| 108 | hc_res which add p 1 |
| 109 | if eq which 0 |
| 110 | put hc_cfg p c |
| 111 | end |
| 112 | if eq which 1 |
| 113 | put hc_json p c |
| 114 | end |
| 115 | if eq which 2 |
| 116 | put hc_str p c |
| 117 | end |
| 118 | if eq which 3 |
| 119 | put hc_body p c |
| 120 | end |
| 121 | if eq which 4 |
| 122 | put hc_url p c |
| 123 | end |
| 124 | if eq which 5 |
| 125 | put hc_model p c |
| 126 | end |
| 127 | if eq which 6 |
| 128 | put hc_key p c |
| 129 | end |
| 130 | if eq which 7 |
| 131 | put hc_ans p c |
| 132 | end |
| 133 | put hc_n which add p 1 |
| 134 | end |
| 135 | |
| 136 | fn hc_get which ulong p ulong to uchar |
| 137 | if eq which 0 |
| 138 | ret get hc_cfg p |
| 139 | end |
| 140 | if eq which 1 |
| 141 | ret get hc_json p |
| 142 | end |
| 143 | if eq which 2 |
| 144 | ret get hc_str p |
| 145 | end |
| 146 | if eq which 3 |
| 147 | ret get hc_body p |
| 148 | end |
| 149 | if eq which 4 |
| 150 | ret get hc_url p |
| 151 | end |
| 152 | if eq which 5 |
| 153 | ret get hc_model p |
| 154 | end |
| 155 | if eq which 6 |
| 156 | ret get hc_key p |
| 157 | end |
| 158 | ret get hc_ans p |
| 159 | end |
| 160 | |
| 161 | fn hc_text which ulong s view uchar * to void |
| 162 | for i ulong len s bound 9223372036854775807 |
| 163 | hc_add which get s i |
| 164 | end |
| 165 | end |
| 166 | |
| 167 | fn hc_rows s view uchar * to void |
| 168 | r = enlarge lx_rows len s |
| 169 | if lt r 0 |
| 170 | x = write 2 hc_mem 0 len hc_mem |
| 171 | exit 1 |
| 172 | end |
| 173 | for i ulong len s bound 9223372036854775807 |
| 174 | put lx_rows i get s i |
| 175 | end |
| 176 | put lx_rn 0 len s |
| 177 | put lx_pick 0 0 |
| 178 | end |
| 179 | |
| 180 | fn hc_envget key view uchar * which ulong to bool |
| 181 | put hc_n which 0 |
| 182 | for i ulong ulong envcnt bound 9223372036854775807 |
| 183 | n = envread i hc_env 0 len hc_env |
| 184 | if lt n 0 |
| 185 | ret false |
| 186 | end |
| 187 | if ge ulong n len key |
| 188 | same = true |
| 189 | for j ulong len key bound 9223372036854775807 |
| 190 | if ne get hc_env j get key j |
| 191 | same = false |
| 192 | end |
| 193 | end |
| 194 | if same |
| 195 | p = len key |
| 196 | while lt p ulong n bound 9223372036854775807 |
| 197 | hc_add which get hc_env p |
| 198 | p = add p 1 |
| 199 | end |
| 200 | ret true |
| 201 | end |
| 202 | end |
| 203 | end |
| 204 | ret false |
| 205 | end |
| 206 | |
| 207 | fn hc_prefix which ulong s view uchar * to bool |
| 208 | if lt get hc_n which len s |
| 209 | ret false |
| 210 | end |
| 211 | for i ulong len s bound 9223372036854775807 |
| 212 | if ne hc_get which i get s i |
| 213 | ret false |
| 214 | end |
| 215 | end |
| 216 | ret true |
| 217 | end |
| 218 | |
| 219 | fn hc_jbyte c uchar to void |
| 220 | if or eq c 34 eq c 92 |
| 221 | hc_add 3 92 |
| 222 | hc_add 3 c |
| 223 | ret |
| 224 | end |
| 225 | if lt c 32 |
| 226 | hc_add 3 92 |
| 227 | hc_add 3 117 |
| 228 | hc_add 3 48 |
| 229 | hc_add 3 48 |
| 230 | v = add uchar 48 shr c 4 |
| 231 | if gt v 57 |
| 232 | v = add v 39 |
| 233 | end |
| 234 | hc_add 3 v |
| 235 | v = add uchar 48 and c 15 |
| 236 | if gt v 57 |
| 237 | v = add v 39 |
| 238 | end |
| 239 | hc_add 3 v |
| 240 | ret |
| 241 | end |
| 242 | hc_add 3 c |
| 243 | end |
| 244 | |
| 245 | fn hc_cfgesc which ulong to void |
| 246 | for i ulong get hc_n which bound 9223372036854775807 |
| 247 | c = hc_get which i |
| 248 | if or eq c 34 eq c 92 |
| 249 | hc_add 0 92 |
| 250 | end |
| 251 | hc_add 0 c |
| 252 | end |
| 253 | end |
| 254 | |
| 255 | fn hc_prepare to bool |
| 256 | a = hc_envget hc_uk 4 |
| 257 | b = hc_envget hc_mk 5 |
| 258 | k = hc_envget hc_kk 6 |
| 259 | if or or not a not b or eq get hc_n 4 0 eq get hc_n 5 0 |
| 260 | hc_rows hc_need |
| 261 | ret false |
| 262 | end |
| 263 | if not or hc_prefix 4 hc_h hc_prefix 4 hc_hs |
| 264 | hc_rows hc_badurl |
| 265 | ret false |
| 266 | end |
| 267 | for i ulong get hc_n 4 bound 9223372036854775807 |
| 268 | c = get hc_url i |
| 269 | if or lt c 33 or eq c 127 or eq c 63 eq c 35 |
| 270 | hc_rows hc_badurl |
| 271 | ret false |
| 272 | end |
| 273 | end |
| 274 | for i ulong get hc_n 6 bound 9223372036854775807 |
| 275 | c = get hc_key i |
| 276 | if or lt c 32 eq c 127 |
| 277 | hc_rows hc_badkey |
| 278 | ret false |
| 279 | end |
| 280 | end |
| 281 | while gt get hc_n 4 0 bound 9223372036854775807 |
| 282 | if ne get hc_url sub get hc_n 4 1 47 |
| 283 | break |
| 284 | end |
| 285 | put hc_n 4 sub get hc_n 4 1 |
| 286 | end |
| 287 | hc_text 4 hc_tail |
| 288 | put hc_n 3 0 |
| 289 | hc_text 3 hc_b1 |
| 290 | for i ulong get hc_n 5 bound 9223372036854775807 |
| 291 | hc_jbyte get hc_model i |
| 292 | end |
| 293 | hc_text 3 hc_b2 |
| 294 | p = ulong 4 |
| 295 | while lt p get lx_qn 0 bound 9223372036854775807 |
| 296 | hc_jbyte get lx_query p |
| 297 | p = add p 1 |
| 298 | end |
| 299 | hc_text 3 hc_b3 |
| 300 | put hc_n 0 0 |
| 301 | hc_text 0 hc_ct |
| 302 | hc_cfgesc 4 |
| 303 | if gt get hc_n 6 0 |
| 304 | hc_text 0 hc_auth |
| 305 | hc_cfgesc 6 |
| 306 | end |
| 307 | hc_text 0 hc_data |
| 308 | hc_cfgesc 3 |
| 309 | hc_text 0 hc_end |
| 310 | ret true |
| 311 | end |
| 312 | |
| 313 | fn hc_pack p ulong s view uchar * to ulong |
| 314 | put hc_exec p uchar and len s 255 |
| 315 | put hc_exec add p 1 uchar shr len s 8 |
| 316 | for i ulong len s bound 128 |
| 317 | put hc_exec add add p 2 i get s i |
| 318 | end |
| 319 | ret add add p 2 len s |
| 320 | end |
| 321 | |
| 322 | fn hc_readfd p ulong to int |
| 323 | v = or ulong get hc_pipe p shl ulong get hc_pipe add p 1 8 |
| 324 | v = or v shl ulong get hc_pipe add p 2 16 |
| 325 | v = or v shl ulong get hc_pipe add p 3 24 |
| 326 | ret int v |
| 327 | end |
| 328 | |
| 329 | fn hc_request to bool |
| 330 | put hc_http 0 0 |
| 331 | put hc_exec 0 4 |
| 332 | put hc_exec 1 0 |
| 333 | p = hc_pack 2 hc_curl |
| 334 | p = hc_pack p hc_q |
| 335 | p = hc_pack p hc_config |
| 336 | p = hc_pack p hc_dash |
| 337 | plen = p |
| 338 | input = memfd hc_memname 0 len hc_memname 1 |
| 339 | if lt input 0 |
| 340 | ret false |
| 341 | end |
| 342 | p = ulong 0 |
| 343 | while lt p get hc_n 0 bound 9223372036854775807 |
| 344 | k = write int input hc_cfg p sub get hc_n 0 p |
| 345 | if eq k -4 |
| 346 | continue |
| 347 | end |
| 348 | if le k 0 |
| 349 | k = fclose int input |
| 350 | ret false |
| 351 | end |
| 352 | p = add p ulong k |
| 353 | end |
| 354 | k = fseek int input 0 0 |
| 355 | if lt k 0 |
| 356 | k = fclose int input |
| 357 | ret false |
| 358 | end |
| 359 | k = pipefds hc_pipe 8 8 524288 |
| 360 | if ne k 0 |
| 361 | k = fclose int input |
| 362 | ret false |
| 363 | end |
| 364 | pid = fork |
| 365 | if eq pid 0 |
| 366 | k = dupfd int input 0 0 |
| 367 | if lt k 0 |
| 368 | exit 126 |
| 369 | end |
| 370 | k = dupfd hc_readfd 12 1 0 |
| 371 | if lt k 0 |
| 372 | exit 126 |
| 373 | end |
| 374 | note discard transport diagnostics: model URLs or server text can contain sensitive information. |
| 375 | note All failures are reported in Hop without echoing the key, URL or response. |
| 376 | k = dupfd hc_readfd 12 2 0 |
| 377 | if lt k 0 |
| 378 | exit 126 |
| 379 | end |
| 380 | k = execprog hc_exec 0 plen |
| 381 | exit 127 |
| 382 | end |
| 383 | k = fclose int input |
| 384 | k = fclose hc_readfd 12 |
| 385 | if lt pid 0 |
| 386 | k = fclose hc_readfd 8 |
| 387 | ret false |
| 388 | end |
| 389 | ok = true |
| 390 | note Erase credential-bearing configuration after forking its anonymous input. |
| 391 | for i ulong get hc_n 0 bound 9223372036854775807 |
| 392 | put hc_cfg i 0 |
| 393 | end |
| 394 | for i ulong get hc_n 6 bound 9223372036854775807 |
| 395 | put hc_key i 0 |
| 396 | end |
| 397 | put hc_n 0 0 |
| 398 | put hc_n 6 0 |
| 399 | put hc_n 1 0 |
| 400 | while true bound 9223372036854775807 |
| 401 | k = read hc_readfd 8 hc_io 0 len hc_io |
| 402 | if eq k -4 |
| 403 | continue |
| 404 | end |
| 405 | if lt k 0 |
| 406 | ok = false |
| 407 | break |
| 408 | end |
| 409 | if eq k 0 |
| 410 | break |
| 411 | end |
| 412 | for i ulong ulong k bound 8192 |
| 413 | hc_add 1 get hc_io i |
| 414 | end |
| 415 | end |
| 416 | k = fclose hc_readfd 8 |
| 417 | k = waitpid int pid hc_wait 0 4 0 |
| 418 | if ne k pid |
| 419 | ret false |
| 420 | end |
| 421 | if lt get hc_n 1 4 |
| 422 | ret false |
| 423 | end |
| 424 | p = sub get hc_n 1 4 |
| 425 | if ne get hc_json p 10 |
| 426 | ret false |
| 427 | end |
| 428 | statusv = ulong 0 |
| 429 | for i ulong 3 |
| 430 | c = get hc_json add add p 1 i |
| 431 | if or lt c 48 gt c 57 |
| 432 | ret false |
| 433 | end |
| 434 | statusv = add mul statusv 10 ulong sub c 48 |
| 435 | end |
| 436 | put hc_http 0 statusv |
| 437 | put hc_n 1 p |
| 438 | if or lt statusv 200 ge statusv 300 |
| 439 | ret false |
| 440 | end |
| 441 | ret and ok and eq get hc_wait 0 0 eq get hc_wait 1 0 |
| 442 | end |
| 443 | |
| 444 | fn hc_space to void |
| 445 | while lt get hc_pos 0 get hc_n 1 bound 9223372036854775807 |
| 446 | c = get hc_json get hc_pos 0 |
| 447 | if not or eq c 32 or eq c 9 or eq c 10 eq c 13 |
| 448 | break |
| 449 | end |
| 450 | put hc_pos 0 add get hc_pos 0 1 |
| 451 | end |
| 452 | end |
| 453 | |
| 454 | fn hc_next to int |
| 455 | hc_space |
| 456 | if ge get hc_pos 0 get hc_n 1 |
| 457 | ret -1 |
| 458 | end |
| 459 | ret int get hc_json get hc_pos 0 |
| 460 | end |
| 461 | |
| 462 | fn hc_hex c uchar to long |
| 463 | if and ge c 48 le c 57 |
| 464 | ret long sub c 48 |
| 465 | end |
| 466 | if and ge c 65 le c 70 |
| 467 | ret add long sub c 65 10 |
| 468 | end |
| 469 | if and ge c 97 le c 102 |
| 470 | ret add long sub c 97 10 |
| 471 | end |
| 472 | ret -1 |
| 473 | end |
| 474 | |
| 475 | fn hc_code to long |
| 476 | v = long 0 |
| 477 | for i ulong 4 |
| 478 | if ge get hc_pos 0 get hc_n 1 |
| 479 | ret -1 |
| 480 | end |
| 481 | h = hc_hex get hc_json get hc_pos 0 |
| 482 | if lt h 0 |
| 483 | ret -1 |
| 484 | end |
| 485 | v = add mul v 16 h |
| 486 | put hc_pos 0 add get hc_pos 0 1 |
| 487 | end |
| 488 | ret v |
| 489 | end |
| 490 | |
| 491 | fn hc_utf cp ulong to void |
| 492 | if lt cp 128 |
| 493 | hc_add 2 uchar cp |
| 494 | ret |
| 495 | end |
| 496 | if lt cp 2048 |
| 497 | hc_add 2 uchar or 192 shr cp 6 |
| 498 | else |
| 499 | if ge cp 65536 |
| 500 | hc_add 2 uchar or 240 shr cp 18 |
| 501 | hc_add 2 uchar or 128 and shr cp 12 63 |
| 502 | else |
| 503 | hc_add 2 uchar or 224 shr cp 12 |
| 504 | end |
| 505 | hc_add 2 uchar or 128 and shr cp 6 63 |
| 506 | end |
| 507 | hc_add 2 uchar or 128 and cp 63 |
| 508 | end |
| 509 | |
| 510 | fn hc_string to bool |
| 511 | if ne hc_next 34 |
| 512 | ret false |
| 513 | end |
| 514 | put hc_pos 0 add get hc_pos 0 1 |
| 515 | put hc_n 2 0 |
| 516 | while lt get hc_pos 0 get hc_n 1 bound 9223372036854775807 |
| 517 | c = get hc_json get hc_pos 0 |
| 518 | put hc_pos 0 add get hc_pos 0 1 |
| 519 | if eq c 34 |
| 520 | ret true |
| 521 | end |
| 522 | if lt c 32 |
| 523 | ret false |
| 524 | end |
| 525 | if ne c 92 |
| 526 | hc_add 2 c |
| 527 | continue |
| 528 | end |
| 529 | if ge get hc_pos 0 get hc_n 1 |
| 530 | ret false |
| 531 | end |
| 532 | c = get hc_json get hc_pos 0 |
| 533 | put hc_pos 0 add get hc_pos 0 1 |
| 534 | if or eq c 34 or eq c 92 eq c 47 |
| 535 | hc_add 2 c |
| 536 | continue |
| 537 | end |
| 538 | if eq c 110 |
| 539 | hc_add 2 10 |
| 540 | continue |
| 541 | end |
| 542 | if eq c 114 |
| 543 | hc_add 2 13 |
| 544 | continue |
| 545 | end |
| 546 | if eq c 116 |
| 547 | hc_add 2 9 |
| 548 | continue |
| 549 | end |
| 550 | if eq c 98 |
| 551 | hc_add 2 8 |
| 552 | continue |
| 553 | end |
| 554 | if eq c 102 |
| 555 | hc_add 2 12 |
| 556 | continue |
| 557 | end |
| 558 | if ne c 117 |
| 559 | ret false |
| 560 | end |
| 561 | cp = hc_code |
| 562 | if lt cp 0 |
| 563 | ret false |
| 564 | end |
| 565 | if and ge cp 55296 le cp 56319 |
| 566 | if gt add get hc_pos 0 2 get hc_n 1 |
| 567 | ret false |
| 568 | end |
| 569 | if ne get hc_json get hc_pos 0 92 |
| 570 | ret false |
| 571 | end |
| 572 | if ne get hc_json add get hc_pos 0 1 117 |
| 573 | ret false |
| 574 | end |
| 575 | put hc_pos 0 add get hc_pos 0 2 |
| 576 | lo = hc_code |
| 577 | if or lt lo 56320 gt lo 57343 |
| 578 | ret false |
| 579 | end |
| 580 | cp = add 65536 add mul sub cp 55296 1024 sub lo 56320 |
| 581 | else |
| 582 | if and ge cp 56320 le cp 57343 |
| 583 | ret false |
| 584 | end |
| 585 | end |
| 586 | hc_utf ulong cp |
| 587 | end |
| 588 | ret false |
| 589 | end |
| 590 | |
| 591 | fn hc_streq s view uchar * to bool |
| 592 | if ne get hc_n 2 len s |
| 593 | ret false |
| 594 | end |
| 595 | for i ulong len s bound 9223372036854775807 |
| 596 | if ne get hc_str i get s i |
| 597 | ret false |
| 598 | end |
| 599 | end |
| 600 | ret true |
| 601 | end |
| 602 | |
| 603 | fn hc_literal s view uchar * to bool |
| 604 | if gt add get hc_pos 0 len s get hc_n 1 |
| 605 | ret false |
| 606 | end |
| 607 | for i ulong len s bound 9223372036854775807 |
| 608 | if ne get hc_json add get hc_pos 0 i get s i |
| 609 | ret false |
| 610 | end |
| 611 | end |
| 612 | put hc_pos 0 add get hc_pos 0 len s |
| 613 | ret true |
| 614 | end |
| 615 | |
| 616 | fn hc_digit to bool |
| 617 | if ge get hc_pos 0 get hc_n 1 |
| 618 | ret false |
| 619 | end |
| 620 | c = get hc_json get hc_pos 0 |
| 621 | ret and ge c 48 le c 57 |
| 622 | end |
| 623 | |
| 624 | fn hc_digits to void |
| 625 | while hc_digit bound 9223372036854775807 |
| 626 | put hc_pos 0 add get hc_pos 0 1 |
| 627 | end |
| 628 | end |
| 629 | |
| 630 | fn hc_number to bool |
| 631 | if eq hc_next 45 |
| 632 | put hc_pos 0 add get hc_pos 0 1 |
| 633 | end |
| 634 | if not hc_digit |
| 635 | ret false |
| 636 | end |
| 637 | if eq get hc_json get hc_pos 0 48 |
| 638 | put hc_pos 0 add get hc_pos 0 1 |
| 639 | else |
| 640 | hc_digits |
| 641 | end |
| 642 | if lt get hc_pos 0 get hc_n 1 |
| 643 | if eq get hc_json get hc_pos 0 46 |
| 644 | put hc_pos 0 add get hc_pos 0 1 |
| 645 | if not hc_digit |
| 646 | ret false |
| 647 | end |
| 648 | hc_digits |
| 649 | end |
| 650 | end |
| 651 | if lt get hc_pos 0 get hc_n 1 |
| 652 | c = get hc_json get hc_pos 0 |
| 653 | if or eq c 101 eq c 69 |
| 654 | put hc_pos 0 add get hc_pos 0 1 |
| 655 | if lt get hc_pos 0 get hc_n 1 |
| 656 | c = get hc_json get hc_pos 0 |
| 657 | if or eq c 43 eq c 45 |
| 658 | put hc_pos 0 add get hc_pos 0 1 |
| 659 | end |
| 660 | end |
| 661 | if not hc_digit |
| 662 | ret false |
| 663 | end |
| 664 | hc_digits |
| 665 | end |
| 666 | end |
| 667 | ret true |
| 668 | end |
| 669 | |
| 670 | fn hc_value mode ulong to bool |
| 671 | c = hc_next |
| 672 | if eq c 123 |
| 673 | put hc_pos 0 add get hc_pos 0 1 |
| 674 | if eq hc_next 125 |
| 675 | put hc_pos 0 add get hc_pos 0 1 |
| 676 | ret true |
| 677 | end |
| 678 | while true bound 9223372036854775807 |
| 679 | if not hc_string |
| 680 | ret false |
| 681 | end |
| 682 | next = ulong 0 |
| 683 | if and eq mode 1 hc_streq hc_choices |
| 684 | next = 2 |
| 685 | end |
| 686 | if and eq mode 3 hc_streq hc_message |
| 687 | next = 4 |
| 688 | end |
| 689 | if and eq mode 4 hc_streq hc_content |
| 690 | next = 5 |
| 691 | end |
| 692 | if ne hc_next 58 |
| 693 | ret false |
| 694 | end |
| 695 | put hc_pos 0 add get hc_pos 0 1 |
| 696 | if not hc_value next |
| 697 | ret false |
| 698 | end |
| 699 | c = hc_next |
| 700 | put hc_pos 0 add get hc_pos 0 1 |
| 701 | if eq c 125 |
| 702 | ret true |
| 703 | end |
| 704 | if ne c 44 |
| 705 | ret false |
| 706 | end |
| 707 | end |
| 708 | end |
| 709 | if eq c 91 |
| 710 | put hc_pos 0 add get hc_pos 0 1 |
| 711 | if eq hc_next 93 |
| 712 | put hc_pos 0 add get hc_pos 0 1 |
| 713 | ret true |
| 714 | end |
| 715 | idx = ulong 0 |
| 716 | while true bound 9223372036854775807 |
| 717 | next = ulong 0 |
| 718 | if and eq mode 2 eq idx 0 |
| 719 | next = 3 |
| 720 | end |
| 721 | if not hc_value next |
| 722 | ret false |
| 723 | end |
| 724 | idx = add idx 1 |
| 725 | c = hc_next |
| 726 | put hc_pos 0 add get hc_pos 0 1 |
| 727 | if eq c 93 |
| 728 | ret true |
| 729 | end |
| 730 | if ne c 44 |
| 731 | ret false |
| 732 | end |
| 733 | end |
| 734 | end |
| 735 | if eq c 34 |
| 736 | if not hc_string |
| 737 | ret false |
| 738 | end |
| 739 | if eq mode 5 |
| 740 | if ne get hc_found 0 0 |
| 741 | ret false |
| 742 | end |
| 743 | put hc_n 7 0 |
| 744 | for i ulong get hc_n 2 bound 9223372036854775807 |
| 745 | hc_add 7 get hc_str i |
| 746 | end |
| 747 | put hc_found 0 1 |
| 748 | end |
| 749 | ret true |
| 750 | end |
| 751 | if eq c 116 |
| 752 | ret hc_literal hc_true |
| 753 | end |
| 754 | if eq c 102 |
| 755 | ret hc_literal hc_false |
| 756 | end |
| 757 | if eq c 110 |
| 758 | ret hc_literal hc_null |
| 759 | end |
| 760 | if or eq c 45 and ge c 48 le c 57 |
| 761 | ret hc_number |
| 762 | end |
| 763 | ret false |
| 764 | end |
| 765 | |
| 766 | fn hc_query to int |
| 767 | if lt get lx_qn 0 5 |
| 768 | ret 0 |
| 769 | end |
| 770 | if or ne get lx_query 0 97 ne get lx_query 1 115 |
| 771 | ret 0 |
| 772 | end |
| 773 | if or ne get lx_query 2 107 ne get lx_query 3 32 |
| 774 | ret 0 |
| 775 | end |
| 776 | r = enlarge lx_rows add get lx_qn 0 1 |
| 777 | if lt r 0 |
| 778 | x = write 2 hc_mem 0 len hc_mem |
| 779 | exit 1 |
| 780 | end |
| 781 | for i ulong len hc_action |
| 782 | put lx_rows i get hc_action i |
| 783 | end |
| 784 | p = len hc_action |
| 785 | i = ulong 4 |
| 786 | while lt i get lx_qn 0 bound 9223372036854775807 |
| 787 | put lx_rows p get lx_query i |
| 788 | p = add p 1 |
| 789 | i = add i 1 |
| 790 | end |
| 791 | put lx_rn 0 p |
| 792 | put lx_pick 0 0 |
| 793 | ret 1 |
| 794 | end |
| 795 | |
| 796 | fn hc_activate to int |
| 797 | if not hc_prepare |
| 798 | ret 0 |
| 799 | end |
| 800 | if not hc_request |
| 801 | if gt get hc_http 0 0 |
| 802 | put hc_n 7 0 |
| 803 | hc_text 7 hc_server |
| 804 | hc_add 7 uchar add 48 div get hc_http 0 100 |
| 805 | hc_add 7 uchar add 48 rem div get hc_http 0 10 10 |
| 806 | hc_add 7 uchar add 48 rem get hc_http 0 10 |
| 807 | hc_text 7 hc_serverend |
| 808 | r = enlarge lx_rows get hc_n 7 |
| 809 | if lt r 0 |
| 810 | x = write 2 hc_mem 0 len hc_mem |
| 811 | exit 1 |
| 812 | end |
| 813 | for i ulong get hc_n 7 bound 9223372036854775807 |
| 814 | put lx_rows i get hc_ans i |
| 815 | end |
| 816 | put lx_rn 0 get hc_n 7 |
| 817 | put lx_pick 0 0 |
| 818 | ret 0 |
| 819 | end |
| 820 | hc_rows hc_transport |
| 821 | ret 0 |
| 822 | end |
| 823 | put hc_pos 0 0 |
| 824 | put hc_found 0 0 |
| 825 | put hc_n 7 0 |
| 826 | ok = hc_value 1 |
| 827 | hc_space |
| 828 | if or not ok or ne get hc_found 0 1 ne get hc_pos 0 get hc_n 1 |
| 829 | hc_rows hc_badjson |
| 830 | ret 0 |
| 831 | end |
| 832 | r = enlarge lx_rows get hc_n 7 |
| 833 | if lt r 0 |
| 834 | x = write 2 hc_mem 0 len hc_mem |
| 835 | exit 1 |
| 836 | end |
| 837 | for i ulong get hc_n 7 bound 9223372036854775807 |
| 838 | put lx_rows i get hc_ans i |
| 839 | end |
| 840 | put lx_rn 0 get hc_n 7 |
| 841 | put lx_pick 0 0 |
| 842 | ret 0 |
| 843 | end |