rfkilld

An rfkill daemon, which runs scripts according to rfkill events.
git clone git://r-36.net/rfkilld
Log | Files | Refs | README | LICENSE

arg.h (1091B)


      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 #define USED(x)		((void)(x))
     12 
     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;\
     25 				}\
     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)
     33 
     34 #define ARGEND			}\
     35 				USED(_argc);\
     36 			}\
     37 			USED(argv);\
     38 			USED(argc);
     39 
     40 #define ARGC()		_argc
     41 
     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])))
     47 
     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])))
     53 
     54 #endif
     55