show usage on invalid flags or any arguments - json2tsv - JSON to TSV converter (HTM) git clone git://git.codemadness.org/json2tsv (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit f4ae5c240dbe7ca52eb9b7a7ab0a94a4fe3b6f06 (DIR) parent e569792c8bc41e19f1702ae57bbfbebc9fc64bff (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Sun, 29 Dec 2019 18:42:53 +0100 show usage on invalid flags or any arguments Diffstat: M json2tsv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- (DIR) diff --git a/json2tsv.c b/json2tsv.c @@ -66,6 +66,13 @@ processnode(struct json_node *nodes, size_t depth, const char *value) putchar('\n'); } +void +usage(const char *argv0) +{ + fprintf(stderr, "usage: %s [-n] [-r]\n", argv0); + exit(1); +} + int main(int argc, char *argv[]) { @@ -77,12 +84,13 @@ main(int argc, char *argv[]) } for (i = 1; i < argc; i++) { - if (argv[i][0] != '-') - continue; + if (argv[i][0] != '-' || argv[i][1] == '\0') + usage(argv[0]); for (j = 1; argv[i][j]; j++) { switch (argv[i][j]) { case 'n': nflag = 1; break; case 'r': rflag = 1; break; + default: usage(argv[0]); break; } } }