Commit 959b70ab authored by Laslo Hunhold's avatar Laslo Hunhold

arg.h: Refactor ARGF_()

parent 26c09259
......@@ -24,15 +24,15 @@ extern char *argv0;
/* int main(int argc, char *argv[]) */
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
int i, argused; \
int _i, _argused; \
if ((*argv)[1] == '-' && !(*argv)[2]) { \
argc--, argv++; \
break; \
} \
for (i = 1, argused = 0; (*argv)[i]; i++) { \
switch((*argv)[i])
#define ARGEND if (argused) { \
if ((*argv)[i + 1]) { \
for (_i = 1, _argused = 0; (*argv)[_i]; _i++) { \
switch((*argv)[_i])
#define ARGEND if (_argused) { \
if ((*argv)[_i + 1]) { \
break; \
} else { \
argc--, argv++; \
......@@ -41,13 +41,9 @@ extern char *argv0;
} \
} \
}
#define ARGC() (*argv)[i]
#define ARGF_(x) ((!(*argv)[i + 1] && !*(argv + 1)) ? \
(x) : \
(argused = 1, ((*argv)[i + 1]) ? \
(&(*argv)[i + 1]) : \
(*(argv + 1)) \
) \
#define ARGC() (*argv)[_i]
#define ARGF_(x) (((*argv)[_i + 1]) ? (_argused = 1, &((*argv)[_i + 1])) : \
(*(argv + 1)) ? (_argused = 1, *(argv + 1)) : (x) \
)
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
#define ARGF() ARGF_((char *)0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment