From 09c6eab77771198f63860aa0c612b324d5ea09d5 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak Date: Mon, 4 Nov 2024 11:56:25 -0500 Subject: switch from using getopt to mike's opt.h --- opt.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 opt.h (limited to 'opt.h') 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 -- cgit v1.2.3-54-g00ecf