st

simple terminal
git clone git://git.suckless.org/st
Log | Files | Refs | README | LICENSE

arg.h (1036B)


      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	for (argv0 = *argv, argv++, argc--;\
     13 					argv[0] && argv[0][0] == '-'\
     14 					&& argv[0][1];\
     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;\
     23 				}\
     24 				int i_;\
     25 				for (i_ = 1, brk_ = 0, argv_ = argv;\
     26 						argv[0][i_] && !brk_;\
     27 						i_++) {\
     28 					if (argv_ != argv)\
     29 						break;\
     30 					argc_ = argv[0][i_];\
     31 					switch (argc_)
     32 
     33 #define ARGEND			}\
     34 			}
     35 
     36 #define ARGC()		argc_
     37 
     38 #define EARGF(x)	((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
     39 				((x), abort(), (char *)0) :\
     40 				(brk_ = 1, (argv[0][i_+1] != '\0')?\
     41 					(&argv[0][i_+1]) :\
     42 					(argc--, argv++, argv[0])))
     43 
     44 #define ARGF()		((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
     45 				(char *)0 :\
     46 				(brk_ = 1, (argv[0][i_+1] != '\0')?\
     47 					(&argv[0][i_+1]) :\
     48 					(argc--, argv++, argv[0])))
     49 
     50 #endif