sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

arg.h (1113B)


      1 /* See the LICENSE file for copyright and license details. */
      2 
      3 #ifndef __ARG_H__
      4 #define __ARG_H__
      5 
      6 extern char *argv0;
      7 
      8 #define USED(x)		((void)(x))
      9 
     10 /* use main(int argc, char *argv[]) */
     11 #define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
     12 					argv[0] && argv[0][1]\
     13 					&& argv[0][0] == '-';\
     14 					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;\
     24 						argv[0][0] && !brk;\
     25 						argv[0]++) {\
     26 					if (_argv != argv)\
     27 						break;\
     28 					_argc = argv[0][0];\
     29 					switch (_argc)
     30 
     31 #define ARGEND			}\
     32 				USED(_argc);\
     33 			}\
     34 			USED(argv);\
     35 			USED(argc);
     36 
     37 #define ARGC()		_argc
     38 
     39 #define EARGF(x)	((argv[0][1] == '\0' && argv[1] == NULL)?\
     40 				((x), abort(), (char *)0) :\
     41 				(brk = 1, (argv[0][1] != '\0')?\
     42 					(&argv[0][1]) :\
     43 					(argc--, argv++, argv[0])))
     44 
     45 #define ARGF()		((argv[0][1] == '\0' && argv[1] == NULL)?\
     46 				(char *)0 :\
     47 				(brk = 1, (argv[0][1] != '\0')?\
     48 					(&argv[0][1]) :\
     49 					(argc--, argv++, argv[0])))
     50 
     51 #endif
     52