new arg.h version by frign
This commit is contained in:
parent
4b4b2ac079
commit
999cf00490
3
LICENSE
3
LICENSE
|
@ -1,6 +1,7 @@
|
||||||
ISC License
|
ISC License
|
||||||
|
|
||||||
Copyright (C) 2016-2017 Aaron Marcher
|
Copyright (C) 2016-2017 Aaron Marcher <me@drkhsh.at>
|
||||||
|
Copyright (C) 2017 Laslo Hunhold <dev@frign.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||||
with or without fee is hereby granted, provided that the above copyright notice
|
with or without fee is hereby granted, provided that the above copyright notice
|
||||||
|
|
77
arg.h
77
arg.h
|
@ -1,55 +1,34 @@
|
||||||
/*
|
/* See LICENSE file for copyright and license details. */
|
||||||
* Copy me if you can.
|
|
||||||
* by 20h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ARG_H__
|
#ifndef ARG_H
|
||||||
#define __ARG_H__
|
#define ARG_H
|
||||||
|
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
|
|
||||||
#define USED(x) ((void)(x))
|
/* int main(int argc, char *argv[]) */
|
||||||
|
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
|
||||||
/* use main(int argc, char *argv[]) */
|
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
|
||||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
int i_, argused_; \
|
||||||
argv[0] && argv[0][1]\
|
if ((*argv)[1] == '-' && !(*argv)[2]) { \
|
||||||
&& argv[0][0] == '-';\
|
argc--, argv++; \
|
||||||
argc--, argv++) {\
|
break; \
|
||||||
char _argc;\
|
} \
|
||||||
char **_argv;\
|
for (i_ = 1, argused_ = 0; (*argv)[i_]; i_++) { \
|
||||||
int brk;\
|
switch((*argv)[i_])
|
||||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
#define ARGEND if (argused_) { \
|
||||||
argv++;\
|
if ((*argv)[i_ + 1]) { \
|
||||||
argc--;\
|
break; \
|
||||||
break;\
|
} else { \
|
||||||
}\
|
argc--, argv++; \
|
||||||
for (brk = 0, argv[0]++, _argv = argv;\
|
break; \
|
||||||
argv[0][0] && !brk;\
|
} \
|
||||||
argv[0]++) {\
|
} \
|
||||||
if (_argv != argv)\
|
} \
|
||||||
break;\
|
}
|
||||||
_argc = argv[0][0];\
|
#define ARGC() ((*argv)[i_])
|
||||||
switch (_argc)
|
#define ARGF_(x) (((*argv)[i_ + 1]) ? (argused_ = 1, &((*argv)[i_ + 1])) : \
|
||||||
|
(*(argv + 1)) ? (argused_ = 1, *(argv + 1)) : (x))
|
||||||
#define ARGEND }\
|
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
|
||||||
USED(_argc);\
|
#define ARGF() ARGF_((char *)0)
|
||||||
}\
|
|
||||||
USED(argv);\
|
|
||||||
USED(argc);
|
|
||||||
|
|
||||||
#define ARGC() _argc
|
|
||||||
|
|
||||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
|
||||||
((x), abort(), (char *)0) :\
|
|
||||||
(brk = 1, (argv[0][1] != '\0')?\
|
|
||||||
(&argv[0][1]) :\
|
|
||||||
(argc--, argv++, argv[0])))
|
|
||||||
|
|
||||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
|
||||||
(char *)0 :\
|
|
||||||
(brk = 1, (argv[0][1] != '\0')?\
|
|
||||||
(&argv[0][1]) :\
|
|
||||||
(argc--, argv++, argv[0])))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue