Add MC sequence
[st.git] / arg.h
blob4df77a701f443d2b9e91d90dd1a1405891986ff1
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][1]\
14 && argv[0][0] == '-';\
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 for (brk_ = 0, argv[0]++, argv_ = argv;\
25 argv[0][0] && !brk_;\
26 argv[0]++) {\
27 if (argv_ != argv)\
28 break;\
29 argc_ = argv[0][0];\
30 switch (argc_)
32 /* Handles obsolete -NUM syntax */
33 #define ARGNUM case '0':\
34 case '1':\
35 case '2':\
36 case '3':\
37 case '4':\
38 case '5':\
39 case '6':\
40 case '7':\
41 case '8':\
42 case '9'
44 #define ARGEND }\
47 #define ARGC() argc_
49 #define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base)))
51 #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
52 ((x), abort(), (char *)0) :\
53 (brk_ = 1, (argv[0][1] != '\0')?\
54 (&argv[0][1]) :\
55 (argc--, argv++, argv[0])))
57 #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
58 (char *)0 :\
59 (brk_ = 1, (argv[0][1] != '\0')?\
60 (&argv[0][1]) :\
61 (argc--, argv++, argv[0])))
63 #endif