aboutsummaryrefslogtreecommitdiff
path: root/arg.h
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-11 18:43:18 -0800
committerMichael Forney <mforney@mforney.org>2019-02-12 01:55:14 -0800
commiteddc4693e49f70cd214b7645cb9fce54a89fbb6c (patch)
treefa1b640f49cde25e323aa0629aed64c064da930e /arg.h
Initial import
Diffstat (limited to 'arg.h')
-rw-r--r--arg.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/arg.h b/arg.h
new file mode 100644
index 0000000..8f93ee1
--- /dev/null
+++ b/arg.h
@@ -0,0 +1,18 @@
+#define ARGBEGIN \
+ for (;;) { \
+ ++argv, --argc; \
+ if (argc == 0 || (*argv)[0] != '-') \
+ break; \
+ if ((*argv)[1] == '-' && !(*argv)[2]) { \
+ ++argv, --argc; \
+ break; \
+ } \
+ for (char *opt_ = &(*argv)[1], done_ = 0; !done_ && *opt_; ++opt_) { \
+ switch (*opt_)
+
+#define ARGEND \
+ } \
+ }
+
+#define EARGF(x) \
+ (done_ = 1, *++opt_ ? opt_ : argv[1] ? --argc, *++argv : ((x), abort(), NULL))