code wiki / _hdl_build / nx_connect_api.nx
nx_connect_api.nx source
↩ module page · 21 lines · 972 B
1// nx_connect_api.nx -- the CLI wrapper registered as the MCP tool `nx_connect`. It shifts the program name
2// off argv (so argv[0] becomes the VERB), calls the pure dispatcher, and writes the JSON to stdout. All the
3// logic lives in nx_connect_api_lib.nx so the gate can drive ca_dispatch directly.
4// nx_connect <verb> [args...] e.g. nx_connect match 30 16 1 5 27 1 16 9 0
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_connect_api_lib.nx"
8const K_MAGIC_65536: i64 = 65536
9
10func main(argc: i64, argv: *i64) -> i64 {
11 let out: *u8 = sys_mmap(K_MAGIC_65536)
12 var n: i64 = 0
13 if argc < 2 {
14 n = ca_dispatch(0, argv, out) // no verb -> the help catalog
15 } else {
16 n = ca_dispatch(argc-1, (argv as i64 + 8) as *i64, out) // shift program name; argv[0]=verb
17 }
18 out[n] = 10 as u8 // trailing newline
19 sys_write(1, out, n+1)
20 return 0
21}