diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-07 11:42:40 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-07 11:42:40 +0100 |
commit | 222f009731176e3d54d2e45e1c7fd9ccf0f97dd2 (patch) | |
tree | 14145dfbd589c05c46a7c6a0902339960ddb6d04 /arg.h | |
download | blakesum-222f009731176e3d54d2e45e1c7fd9ccf0f97dd2.tar.gz blakesum-222f009731176e3d54d2e45e1c7fd9ccf0f97dd2.tar.bz2 blakesum-222f009731176e3d54d2e45e1c7fd9ccf0f97dd2.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | arg.h | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +/* Trivial code, not subject to copyright, use as you see fit. + * Reimplementation of 20h's arg.h */ + +#ifndef ARG_H +#define ARG_H + +#include <stddef.h> + + +extern const char *argv0; + + +#define ARGBEGIN do {\ + char arg_h_flag_, arg_h_break_;\ + if (!argc)\ + break;\ + argv0 = argv[0];\ + while (--argc, *++argv && argv[0][0] == '-' && argv[0][1]) {\ + if (argv[0][1] == '-' && !argv[0][2]) {\ + argv++;\ + argc--;\ + break;\ + }\ + for (arg_h_break_ = 0; !arg_h_break_ && *++*argv;) {\ + switch ((arg_h_flag_ = **argv)) + +#define ARGEND }\ + }\ + } while (0) + + +#define FLAG() (arg_h_flag_) + +#define ARG() (arg_h_break_ = 1, argv[0][1] ? &argv[0][1] :\ + argv[1] ? (argc--, *++argv) :\ + (usage(), NULL)) + +#endif |