arg.h (619B) download
1#pragma once
2
3#define SHIFT (argc--, argv++)
4
5#define ARGBEGIN \
6 for (SHIFT; *argv && *argv[0] == '-'; SHIFT) { \
7 if ((*argv)[1] == '-' && (*argv)[2] == '\0') { \
8 SHIFT; \
9 break; \
10 } \
11 for (char* opt = *argv + 1; *opt; opt++) {
12
13#define ARGEND \
14 } \
15 }
16
17#define OPT (*opt)
18#define ARGF (argv[1] ? (SHIFT, *argv) : NULL)
19#define EARGF(usage) (argv[1] ? ARGF : (printf("'-%c' requires an argument\n", *opt), usage, NULL))