don't modify argv, use a counter
[azarus-st.git] / arg.h
bloba22e019e36f180cec5e5bb003a924f5ec11203ad
1 /*
2 * Copy me if you can.
3 * by 20h
4 */
6 #ifndef ARG_H__
7 #define ARG_H__
9 extern char *argv0;
11 /* use main(int argc, char *argv[]) */
12 #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
13 argv[0] && argv[0][0] == '-'\
14 && argv[0][1];\
15 argc--, argv++) {\
16 char argc_;\
17 char **argv_;\
18 int brk_;\
19 if (argv[0][1] == '-' && argv[0][2] == '\0') {\
20 argv++;\
21 argc--;\
22 break;\
24 int i_;\
25 for (i_ = 1, brk_ = 0, argv_ = argv;\
26 argv[0][i_] && !brk_;\
27 i_++) {\
28 if (argv_ != argv)\
29 break;\
30 argc_ = argv[0][i_];\
31 switch (argc_)
33 #define ARGEND }\
36 #define ARGC() argc_
38 #define EARGF(x) ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
39 ((x), abort(), (char *)0) :\
40 (brk_ = 1, (argv[0][i_+1] != '\0')?\
41 (&argv[0][i_+1]) :\
42 (argc--, argv++, argv[0])))
44 #define ARGF() ((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
45 (char *)0 :\
46 (brk_ = 1, (argv[0][i_+1] != '\0')?\
47 (&argv[0][i_+1]) :\
48 (argc--, argv++, argv[0])))
50 #endif