nx_args.nx
buildroot/runtime/nx_args.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 41 | struct NxArgsSpec |
| 49 | struct NxArgsIter |
consts
| 38 | const NX_ARGS_MAX_SPEC: i64 = 64 |
| 39 | const NX_ARGS_MAX_POSITIONAL: i64 = 64 |
| 47 | const NX_ARGS_SPEC_BYTES: i64 = 24 |
| 63 | const NX_ARGS_ITER_BYTES: i64 = 88 |
functions
| 68 | func nx_args_iter_new(argc: i64, argv: *i64, spec: *NxArgsSpec, n_spec: i64) -> *NxArgsIter called by 1: main |
| 87 | func nx_args_find_short(it: *NxArgsIter, ch: i64) -> i64 called by 1: nx_args_next |
| 98 | func nx_args_find_long(it: *NxArgsIter, name: *u8, name_len: i64) -> i64 called by 1: nx_args_next |
| 115 | func nx_args_push_positional(it: *NxArgsIter, idx: i64) -> i64 called by 1: nx_args_next |
| 127 | func nx_args_next(it: *NxArgsIter) -> i64 called by 2: nx_args_nextmain calls 4: nx_args_find_shortnx_args_push_positionalnx_args_find_longnx_args_next |
| 252 | func main() -> i64 |