commit f1f75870440190dbc194e15467091c96f7e83346
parent decf2b20c153ba07c1cbd4414e5c5f062e7d0b59
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 15 Apr 2012 23:08:20 +0200
Migrating to a more powerful ARGBEGIN.
Diffstat:
arg.h | | | 42 | ++++++++++++++++++++++++++++++++---------- |
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/arg.h b/arg.h
@@ -1,18 +1,40 @@
-#ifndef ARG_H
-#define ARG_H
+/*
+ * Copy me if you can.
+ * by 20h
+ */
-#define USED(x) ((void)(x))
+#ifndef __ARG_H__
+#define __ARG_H__
extern char *argv0;
-#define ARGBEGIN for(argv0 = *argv, argv++, argc--;\
- argv[0] && argv[0][0]=='-' && argv[0][1];\
- argc--, argv++) {\
+#define USED(x) ((void)(x))
+
+#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
+ argv[0] && argv[0][1]\
+ && argv[0][0] == '-';\
+ argc--, argv++) {\
char _argc;\
- _argc = argv[0][1];\
- switch(_argc)
-#define ARGEND USED(_argc);} USED(argv);USED(argc);
-#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\
+ char **_argv;\
+ if (argv[0][1] == '-' && argv[0][2] == '\0') {\
+ argv++;\
+ argc--;\
+ break;\
+ }\
+ for (argv[0]++, _argv = argv; argv[0][0];\
+ argv[0]++) {\
+ if (_argv != argv)\
+ break;\
+ _argc = argv[0][0];\
+ switch (_argc)
+
+#define ARGEND }\
+ USED(_argc);\
+ }\
+ USED(argv);\
+ USED(argc);
+
+#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\
(argc--, argv++, argv[0]))
#endif