aboutsummaryrefslogtreecommitdiff
path: root/arg.h
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2013-04-03 21:00:38 +0200
committerChristoph Lohmann <20h@r-36.net>2013-04-03 21:00:38 +0200
commitb1813b14d956978ae8af37166b3cccc3a7b4b720 (patch)
treead5656d373cbb9bbd4b9063b49641f47b6cfcc26 /arg.h
parent580c8bbd4691218849c9a809acaa4c95f65cb846 (diff)
downloadst-b1813b14d956978ae8af37166b3cccc3a7b4b720.tar.gz
st-b1813b14d956978ae8af37166b3cccc3a7b4b720.tar.bz2
Adopting arg.h with more flexible cmd handling.
Diffstat (limited to 'arg.h')
-rw-r--r--arg.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/arg.h b/arg.h
new file mode 100644
index 0000000..2b189fe
--- /dev/null
+++ b/arg.h
@@ -0,0 +1,55 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#ifndef __ARG_H__
+#define __ARG_H__
+
+extern char *argv0;
+
+#define USED(x) ((void)(x))
+
+/* 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 }\
+ USED(_argc);\
+ }\
+ USED(argv);\
+ USED(argc);
+
+#define ARGC() _argc
+
+#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ ((x), abort(), (char *)0) :\
+ (brk = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#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
+