diff options
Diffstat (limited to 'opt.h')
-rw-r--r-- | opt.h | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 |