9static int ARG_LONG_func(
wchar_t **argv0,
char const *name) {
10 wchar_t *argIt = *argv0;
11 while (*argIt == *name && *argIt)
13 if (*argIt == *name || (*argIt ==
'=' && !*name)) {
22 for (argv[0] && (--argc, ++argv); argv[0] && argv[0][0] == '-'; \
23 argv[0] && (--argc, ++argv)) { \
25 wchar_t *arg = argv[0]; \
26 if (arg[1] == '-' && arg[2] == 0 && (--argc, ++argv, 1)) \
29 switch ((++arg)[0]) { \
35#define ARG_LONG(name) ARG_LONG_func(&(arg), (name))
38 (isFlag ? (arg[1] ? ++arg : *(--argc, ++argv)) : (arg[0] == '=' ? ++arg : *(--argc, ++argv)))
41 if (isFlag && arg[1]) \
57#if defined(ARG_EXAMPLE) || defined(ARG_FUZZ)
70int main(
int argc,
char **argv) {
71 char *argv0 = argv[0];
72 int a = 0, b = 0, c = 0, reverse = 0;
73 char const *input =
"default", *output =
"default";
93 }
else if (ARG_LONG(
"reverse"))
98 else if (ARG_LONG(
"input"))
case 'i': {
101 else if (ARG_LONG(
"output"))
case 'o': {
104 else if (ARG_LONG(
"help"))
case 'h':
106 printf(
"Usage: %s [OPTION...] [STRING...]\n", argv0);
107 puts(
"Example usage of arg.h\n");
109 puts(
" -a, set a to true");
110 puts(
" -b, set b to true");
111 puts(
" -c, set c to true");
112 puts(
" -r, --reverse set reverse to true");
113 puts(
" -i, --input=STR set input string to STR");
114 puts(
" -o, --output=STR set output string to STR");
115 puts(
" -h, --help display this help and exit");
121 "%s: invalid option '%s'\n"
122 "Try '%s --help' for more information.\n",
131 printf(
"a = %s\n", a ?
"true" :
"false");
132 printf(
"b = %s\n", b ?
"true" :
"false");
133 printf(
"c = %s\n", c ?
"true" :
"false");
134 printf(
"reverse = %s\n", reverse ?
"true" :
"false");
135 printf(
"readstdin = %s\n", readstdin ?
"true" :
"false");
136 printf(
"input = %s\n", input);
137 printf(
"output = %s\n", output);
139 printf(
"\nargc: %d", argc);
142 printf(
" %s\n", *argv++);
157#define MAX_ARGC 50000
159int LLVMFuzzerTestOneInput(
const uint8_t *data,
size_t size) {
163 char *buf = malloc(size + 2);
164 memcpy(buf, data, size);
165 buf[size] = buf[size + 1] = 0;
167 static char *argv[MAX_ARGC + 1];
169 for (
char *ptr = buf; *ptr && argc < MAX_ARGC;) {