aboutsummaryrefslogtreecommitdiffstats
path: root/src/arg.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2016-01-02 20:55:21 +0100
committerMattias Andrée <maandree@member.fsf.org>2016-01-02 20:55:57 +0100
commiteec0c8194db183ce24b8307226b53c00bde97a4a (patch)
tree361de5b8fc2e10e66a2e45792b2e3d358da751fa /src/arg.h
parentknown issues (diff)
downloadradharc-eec0c8194db183ce24b8307226b53c00bde97a4a.tar.gz
radharc-eec0c8194db183ce24b8307226b53c00bde97a4a.tar.bz2
radharc-eec0c8194db183ce24b8307226b53c00bde97a4a.tar.xz
parse command line
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/arg.h')
-rw-r--r--src/arg.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/arg.h b/src/arg.h
new file mode 100644
index 0000000..8d235ba
--- /dev/null
+++ b/src/arg.h
@@ -0,0 +1,41 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#ifndef ARG_H__
+#define ARG_H__
+
+extern char *argv0;
+
+/* use main(int argc, char *argv[]) */
+#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
+ argv[0] && argv[0][1]\
+ && argv[0][0] == '-';\
+ argc--, argv++) {\
+ char argc_;\
+ char **argv_;\
+ int brk_;\
+ if (argv[0][1] == '-' && argv[0][2] == '\0') {\
+ argv++;\
+ argc--;\
+ break;\
+ }\
+ for (brk_ = 0, argv[0]++, argv_ = argv;\
+ argv[0][0] && !brk_;\
+ argv[0]++) {\
+ if (argv_ != argv)\
+ break;\
+ argc_ = argv[0][0];\
+ switch (argc_)
+
+#define ARGEND }\
+ }
+
+#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ (char *)0 :\
+ (brk_ = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#endif