Fix match function bugs
[st.git] / arg.h
blob2b189fea87b22566ef8fa7eaaa3290999bd4d0fb
1 /*
2 * Copy me if you can.
3 * by 20h
4 */
6 #ifndef __ARG_H__
7 #define __ARG_H__
9 extern char *argv0;
11 #define USED(x) ((void)(x))
13 /* use main(int argc, char *argv[]) */
14 #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
15 argv[0] && argv[0][1]\
16 && argv[0][0] == '-';\
17 argc--, argv++) {\
18 char _argc;\
19 char **_argv;\
20 int brk;\
21 if (argv[0][1] == '-' && argv[0][2] == '\0') {\
22 argv++;\
23 argc--;\
24 break;\
26 for (brk = 0, argv[0]++, _argv = argv;\
27 argv[0][0] && !brk;\
28 argv[0]++) {\
29 if (_argv != argv)\
30 break;\
31 _argc = argv[0][0];\
32 switch (_argc)
34 #define ARGEND }\
35 USED(_argc);\
37 USED(argv);\
38 USED(argc);
40 #define ARGC() _argc
42 #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
43 ((x), abort(), (char *)0) :\
44 (brk = 1, (argv[0][1] != '\0')?\
45 (&argv[0][1]) :\
46 (argc--, argv++, argv[0])))
48 #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
49 (char *)0 :\
50 (brk = 1, (argv[0][1] != '\0')?\
51 (&argv[0][1]) :\
52 (argc--, argv++, argv[0])))
54 #endif