aboutsummaryrefslogtreecommitdiffstats
path: root/arg.h
blob: 12313201795e60cb170346192de5032a65588647 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Trivial code, not subject to copyright, use as you see fit.
 * Reimplementation of 20h's arg.h */

#ifndef ARG_H
#define ARG_H

#include <stddef.h>


extern const char *argv0;


#define ARGBEGIN        do {\
                                char arg_h_flag_, arg_h_break_;\
				if (!argc)\
					break;\
                                argv0 = argv[0];\
                                while (--argc, *++argv && argv[0][0] == '-' && argv[0][1]) {\
					if (argv[0][1] == '-' && !argv[0][2]) {\
                                                argv++;\
                                                argc--;\
                                                break;\
                                        }\
                                        for (arg_h_break_ = 0; !arg_h_break_ && *++*argv;) {\
                                                switch ((arg_h_flag_ = **argv))

#define ARGEND				}\
				}\
			} while (0)


#define FLAG()		(arg_h_flag_)

#define ARG()		(arg_h_break_ = 1, argv[0][1] ? &argv[0][1] :\
			                   argv[1]    ? (argc--, *++argv) :\
			                                (usage(), NULL))

#endif