hfingerd

[archived] hhvn.uk:79
git clone https://hhvn.uk/hfingerd
git clone git://hhvn.uk/hfingerd
Log | Files | Refs | LICENSE

arg.h (2170B)


      1 /*
      2  * Copy me if you can.
      3  * by 20h
      4  *
      5  * 2012-2016 Christoph Lohmann <20h at r-36 dot net>
      6  *
      7  * Permission is hereby granted, free of charge, to any person obtaining a
      8  * copy of this software and associated documentation files (the "Software"),
      9  * to deal in the Software without restriction, including without limitation
     10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     11  * and/or sell copies of the Software, and to permit persons to whom the
     12  * Software is furnished to do so, subject to the following conditions:
     13  * 
     14  * The above copyright notice and this permission notice shall be included in
     15  * all copies or substantial portions of the Software.
     16  * 
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     23  * DEALINGS IN THE SOFTWARE.
     24  */
     25 
     26 #ifndef ARG_H__
     27 #define ARG_H__
     28 
     29 extern char *argv0;
     30 
     31 /* use main(int argc, char *argv[]) */
     32 #define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
     33 					argv[0] && argv[0][0] == '-'\
     34 					&& argv[0][1];\
     35 					argc--, argv++) {\
     36 				char argc_;\
     37 				char **argv_;\
     38 				int brk_;\
     39 				if (argv[0][1] == '-' && argv[0][2] == '\0') {\
     40 					argv++;\
     41 					argc--;\
     42 					break;\
     43 				}\
     44 				int i_;\
     45 				for (i_ = 1, brk_ = 0, argv_ = argv;\
     46 						argv[0][i_] && !brk_;\
     47 						i_++) {\
     48 					if (argv_ != argv)\
     49 						break;\
     50 					argc_ = argv[0][i_];\
     51 					switch (argc_)
     52 
     53 #define ARGEND			}\
     54 			}
     55 
     56 #define ARGC()		argc_
     57 
     58 #define EARGF(x)	((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
     59 				((x), abort(), (char *)0) :\
     60 				(brk_ = 1, (argv[0][i_+1] != '\0')?\
     61 					(&argv[0][i_+1]) :\
     62 					(argc--, argv++, argv[0])))
     63 
     64 #define ARGF()		((argv[0][i_+1] == '\0' && argv[1] == NULL)?\
     65 				(char *)0 :\
     66 				(brk_ = 1, (argv[0][i_+1] != '\0')?\
     67 					(&argv[0][i_+1]) :\
     68 					(argc--, argv++, argv[0])))
     69 
     70 #endif