aboutsummaryrefslogtreecommitdiff
path: root/opt.h
diff options
context:
space:
mode:
authorGravatar Matthew Wozniak <me@woz.blue> 2024-11-04 11:56:25 -0500
committerGravatar Matthew Wozniak <me@woz.blue> 2024-11-04 13:26:49 -0500
commit09c6eab77771198f63860aa0c612b324d5ea09d5 (patch)
tree2eaef4291353ce03f171cb27024f0df3271c651a /opt.h
parent3c19c509af38424cd04df53e1af7ef1b20a191ef (diff)
downloadrt-09c6eab77771198f63860aa0c612b324d5ea09d5.tar.gz
rt-09c6eab77771198f63860aa0c612b324d5ea09d5.zip
switch from using getopt to mike's opt.h
Diffstat (limited to 'opt.h')
-rw-r--r--opt.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/opt.h b/opt.h
new file mode 100644
index 0000000..0492226
--- /dev/null
+++ b/opt.h
@@ -0,0 +1,23 @@
+// Mike wrote this.
+
+#define FOR_OPTS(argc, argv) \
+ for ( \
+ const char *_p = (--(argc), *++(argv)), *_p1; \
+ argc && *_p == '-' && *++_p && \
+ (*_p != '-' || _p[1] || (++(argv), --(argc), 0)); \
+ _p = *++(argv), --(argc), (void)(_p1) /* suppress unused warning */ \
+ ) \
+ while (*_p) \
+ switch (*_p++) \
+ if (0) default: { \
+ fprintf(stderr, "invalid option: -%c\n", _p[-1]); \
+ usage(); \
+ } \
+ else /* { cases/code here } */
+
+#define OPTARG(argc, argv) \
+ (*_p ? (_p1 = _p, _p = "", _p1) : (*(--(argc), ++(argv)) ? *(argv) : \
+ (fprintf(stderr, "missing argument for option -%c\n", _p[-1]), \
+ usage(), (char *)0)))
+
+// vi: sw=4 ts=4 noet tw=80 cc=80