code wiki / (root) / nx_args.nx

nx_args.nx

buildroot/runtime/nx_args.nx

11971 B308 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_args.nx -- getopt-style argument parser. Toolchain front-ends today inline ad-hoc argv scanning. Adding a new flag means editing every tool's parser independently and re-deriving the same edge-case logic for each one (long flags, `--`, bundled short flags, `=`-attached values). This module gives them a shared parser: spec = [ {short: 'o', long: "output", takes_value: 1}, {short: 'O', long: "opt", takes_value: 0}, {short: 'h', long: "help", takes_value: 0}, ] it = nx_args_iter_new(argc, argv, spec, n_spec) while nx_args_next(it) > 0 { if it.flag == 'o' { out_path = it.value } if it.flag == 'O' { opt_on = 1 } } positional = it.positionals (i64 array of indices into argv) Conventions: - "--" terminates options; everything after is positional. - `--long=val` and `--long val` both work for value-taking longs. - `-ovalue` and `-o value` both work for value-taking shorts. - Bundled shorts (`-Ox` = `-O -x`) supported only for non-value flags. - Unknown flags return -1 from next(); caller decides whether to warn or error.

dependencies 1 imports · 0 importers

syscalls.nx nx_args.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_args_iter_new nx_args_next nx_args_find_short nx_args_push_positional nx_args_find_long nx_args_next ↻

structs

41struct NxArgsSpec
49struct NxArgsIter

consts

38const NX_ARGS_MAX_SPEC: i64 = 64
39const NX_ARGS_MAX_POSITIONAL: i64 = 64
47const NX_ARGS_SPEC_BYTES: i64 = 24
63const NX_ARGS_ITER_BYTES: i64 = 88

functions

68func nx_args_iter_new(argc: i64, argv: *i64, spec: *NxArgsSpec, n_spec: i64) -> *NxArgsIter
called by 1: main
87func nx_args_find_short(it: *NxArgsIter, ch: i64) -> i64
called by 1: nx_args_next
98func nx_args_find_long(it: *NxArgsIter, name: *u8, name_len: i64) -> i64
called by 1: nx_args_next
115func nx_args_push_positional(it: *NxArgsIter, idx: i64) -> i64
called by 1: nx_args_next
127func nx_args_next(it: *NxArgsIter) -> i64
252func main() -> i64