summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <dev@sinitax.com>2026-01-03 21:35:42 +0100
committerLouis Burda <dev@sinitax.com>2026-01-03 21:35:42 +0100
commit48e58be7ad6694a9ab81bdc510cde3365f62503a (patch)
treee4405abd4310dada7663cceb391cf7411925960c
parent75d1adc7063ca5894df46f7aeb9e6c8f8c6efcf2 (diff)
downloadargv-master.tar.gz
argv-master.zip
Add usage and long optionsHEADmaster
-rw-r--r--argv.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/argv.c b/argv.c
index 7c879ac..d6af492 100644
--- a/argv.c
+++ b/argv.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
+static const char usage[] = "argv [-n] [-0] [-d CHAR] [--] [ARG ...]";
+
int
main(int argc, const char **argv)
{
@@ -13,9 +15,12 @@ main(int argc, const char **argv)
break;
} else if (!strcmp(*arg, "-n")) {
endchar = 0;
- } else if (!strcmp(*arg, "-d")) {
+ } else if (!strcmp(*arg, "-h") || !strcmp(*arg, "--help")) {
+ puts(usage);
+ return 0;
+ } else if (!strcmp(*arg, "-d") || !strcmp(*arg, "--delim")) {
if (!*++arg) {
- fprintf(stderr, "Missing arg for -d\n");
+ fputs(usage, stderr);
return 1;
}
delim = **++arg;