diff options
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/stdlib.c | 12 | ||||
| -rw-r--r-- | src/stdlib/stdlib.h | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 6a855c66..6dfc735b 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -232,7 +232,7 @@ static Table_t parse_table(const TypeInfo_t *table, int n, char *args[]) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" #endif -public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, int spec_len, cli_arg_t spec[spec_len]) +public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, const char *version, int spec_len, cli_arg_t spec[spec_len]) { bool populated_args[spec_len]; bool used_args[argc]; @@ -310,7 +310,11 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, } if (streq(argv[i], "--help")) { - say(help, true); + print(help); + exit(0); + } + if (streq(argv[i], "--version")) { + print(version); exit(0); } print_err("Unrecognized argument: ", argv[i], "\n", usage); @@ -361,7 +365,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, } if (*f == 'h') { - say(help, true); + print(help); exit(0); } print_err("Unrecognized flag: ", flag, "\n", usage); @@ -554,7 +558,7 @@ public void say(Text_t text, bool newline) public _Noreturn void tomo_exit(Text_t text, int32_t status) { if (text.length > 0) - say(text, true); + print(text); _exit(status); } diff --git a/src/stdlib/stdlib.h b/src/stdlib/stdlib.h index 04c504fe..2dd3c5b7 100644 --- a/src/stdlib/stdlib.h +++ b/src/stdlib/stdlib.h @@ -25,9 +25,9 @@ typedef struct { } cli_arg_t; void tomo_init(void); -void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, int spec_len, cli_arg_t spec[spec_len]); -#define tomo_parse_args(argc, argv, usage, help, ...) \ - _tomo_parse_args(argc, argv, usage, help, sizeof((cli_arg_t[]){__VA_ARGS__})/sizeof(cli_arg_t), (cli_arg_t[]){__VA_ARGS__}) +void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, const char *version, int spec_len, cli_arg_t spec[spec_len]); +#define tomo_parse_args(argc, argv, usage, help, version, ...) \ + _tomo_parse_args(argc, argv, usage, help, version, sizeof((cli_arg_t[]){__VA_ARGS__})/sizeof(cli_arg_t), (cli_arg_t[]){__VA_ARGS__}) #define fail(...) ({ \ fflush(stdout); \ |
