scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

arg.h (1198B)


      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];\
     15      argc--, argv++) {\
     16 	if (argv[0][0] == '-') {\
     17 		char argc_;\
     18 		char **argv_;\
     19 		int brk_;\
     20 		if (argv[0][1] == '-' && argv[0][2] == '\0') {\
     21 			argv++;\
     22 			argc--;\
     23 			break;\
     24 		}\
     25 		for (brk_ = 0, argv[0]++, argv_ = argv;\
     26 		     argv[0][0] && !brk_;\
     27 		     argv[0]++) {\
     28 			if (argv_ != argv)\
     29 				break;\
     30 			argc_ = argv[0][0];\
     31 			switch (argc_)
     32 
     33 #define ARGOPERAND \
     34 		}\
     35 	} else if (argv[0][0] != '\0') {\
     36 		{
     37 
     38 #define ARGEND \
     39 		}\
     40 	} else {\
     41 		break;\
     42 	}\
     43 }
     44 
     45 #define ARGC() argc_
     46 
     47 #define ARGOP() argv[0]
     48 
     49 #define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX))
     50 
     51 #define EARGF(x) \
     52 ((argv[0][1] == '\0' && argv[1] == NULL) ?\
     53     ((x), abort(), (char *)0) :\
     54     (brk_ = 1, (argv[0][1] != '\0') ?\
     55         (&argv[0][1]) :\
     56         (argc--, argv++, argv[0])))
     57 
     58 #define ARGF() \
     59 ((argv[0][1] == '\0' && argv[1] == NULL)?\
     60     (char *)0 :\
     61     (brk_ = 1, (argv[0][1] != '\0')?\
     62         (&argv[0][1]) :\
     63         (argc--, argv++, argv[0])))
     64 
     65 #define LNGARG() &argv[0][0]
     66 
     67 #endif