arg.h (3288B)
1 /* 2 * Copy me if you can. 3 * by 20h 4 */ 5 6 #ifndef ARG_H__ 7 #define ARG_H__ 8 9 extern char *argv0; 10 11 /* use main(int argc, char *argv[]) */ 12 #define ARGBEGIN \ 13 for (argv0 = *argv, argv++, argc--; \ 14 argv[0] && argv[0][1] && argv[0][0] == '-'; argc--, argv++) { \ 15 char argc_; \ 16 char **argv_; \ 17 int brk_; \ 18 if (argv[0][1] == '-' && argv[0][2] == '\0') { \ 19 argv++; \ 20 argc--; \ 21 break; \ 22 } \ 23 for (brk_ = 0, argv[0]++, argv_ = argv; argv[0][0] && !brk_; argv[0]++) { \ 24 if (argv_ != argv) \ 25 break; \ 26 argc_ = argv[0][0]; \ 27 switch (argc_) 28 29 /* Handles obsolete -NUM syntax */ 30 #define ARGNUM \ 31 case '0': \ 32 case '1': \ 33 case '2': \ 34 case '3': \ 35 case '4': \ 36 case '5': \ 37 case '6': \ 38 case '7': \ 39 case '8': \ 40 case '9' 41 42 #define ARGEND \ 43 } \ 44 } 45 46 #define ARGC() argc_ 47 48 #define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base))) 49 50 #define EARGF(x) \ 51 ((argv[0][1] == '\0' && argv[1] == NULL) \ 52 ? ((x), abort(), (char *)0) \ 53 : (brk_ = 1, \ 54 (argv[0][1] != '\0') ? (&argv[0][1]) : (argc--, argv++, argv[0]))) 55 56 #define ARGF() \ 57 ((argv[0][1] == '\0' && argv[1] == NULL) \ 58 ? (char *)0 \ 59 : (brk_ = 1, \ 60 (argv[0][1] != '\0') ? (&argv[0][1]) : (argc--, argv++, argv[0]))) 61 62 #endif