diff options
author | Mattias Andrée <maandree@kth.se> | 2022-01-04 21:15:13 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-01-04 21:15:13 +0100 |
commit | cb0d932597377a6dbc595dbe13f55c9a2cf1ad00 (patch) | |
tree | 80ec6488e06a260229acb8a45afc44f5c84a3a48 /arg.h | |
parent | Rename to makel (diff) | |
download | makel-cb0d932597377a6dbc595dbe13f55c9a2cf1ad00.tar.gz makel-cb0d932597377a6dbc595dbe13f55c9a2cf1ad00.tar.bz2 makel-cb0d932597377a6dbc595dbe13f55c9a2cf1ad00.tar.xz |
Replace dependency on libsimple with boilerplate code
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 |