summaryrefslogtreecommitdiffstats
path: root/arg.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-04 21:15:13 +0100
committerMattias Andrée <maandree@kth.se>2022-01-04 21:15:13 +0100
commitcb0d932597377a6dbc595dbe13f55c9a2cf1ad00 (patch)
tree80ec6488e06a260229acb8a45afc44f5c84a3a48 /arg.h
parentRename to makel (diff)
downloadmakel-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.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/arg.h b/arg.h
new file mode 100644
index 0000000..1231320
--- /dev/null
+++ b/arg.h
@@ -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