Import updated arg.h from farbfeld
This commit is contained in:
parent
84d77d096b
commit
08ef9966b5
1 changed files with 17 additions and 23 deletions
40
arg.h
40
arg.h
|
@ -1,20 +1,19 @@
|
||||||
/*
|
/*
|
||||||
* ISC-License
|
* ISC-License
|
||||||
*
|
*
|
||||||
* (c) 2017 Laslo Hunhold <dev@frign.de>
|
* Copyright 2017 Laslo Hunhold <dev@frign.de>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
* copyright notice and this permission notice appear in all copies.
|
* copyright notice and this permission notice appear in all copies.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
* PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
#ifndef ARG_H
|
#ifndef ARG_H
|
||||||
#define ARG_H
|
#define ARG_H
|
||||||
|
@ -24,15 +23,15 @@ extern char *argv0;
|
||||||
/* int main(int argc, char *argv[]) */
|
/* int main(int argc, char *argv[]) */
|
||||||
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
|
#define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void *)0); \
|
||||||
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
|
*argv && (*argv)[0] == '-' && (*argv)[1]; argc--, argv++) { \
|
||||||
int argparsed; \
|
int _i, _argused; \
|
||||||
if ((*argv)[1] == '-' && (*argv)[2] == '\0') { \
|
if ((*argv)[1] == '-' && !(*argv)[2]) { \
|
||||||
argc--, argv++; \
|
argc--, argv++; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
for (argparsed = 0, (*argv)++; (*argv)[0]; (*argv)++) { \
|
for (_i = 1, _argused = 0; (*argv)[_i]; _i++) { \
|
||||||
switch((*argv)[0])
|
switch((*argv)[_i])
|
||||||
#define ARGEND if (argparsed) { \
|
#define ARGEND if (_argused) { \
|
||||||
if ((*argv)[1] != '\0') { \
|
if ((*argv)[_i + 1]) { \
|
||||||
break; \
|
break; \
|
||||||
} else { \
|
} else { \
|
||||||
argc--, argv++; \
|
argc--, argv++; \
|
||||||
|
@ -41,14 +40,9 @@ extern char *argv0;
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define ARGC() *argv[0]
|
#define ARGC() ((*argv)[_i])
|
||||||
#define ARGF_(x) (((*argv)[1] == '\0' && !*(argv + 1)) ? \
|
#define ARGF_(x) (((*argv)[_i + 1]) ? (_argused = 1, &((*argv)[_i + 1])) : \
|
||||||
(x) : \
|
(*(argv + 1)) ? (_argused = 1, *(argv + 1)) : (x))
|
||||||
(argparsed = 1, ((*argv)[1] != '\0') ? \
|
|
||||||
(&(*argv)[1]) : \
|
|
||||||
(*(argv + 1)) \
|
|
||||||
) \
|
|
||||||
)
|
|
||||||
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
|
#define EARGF(x) ARGF_(((x), exit(1), (char *)0))
|
||||||
#define ARGF() ARGF_((char *)0)
|
#define ARGF() ARGF_((char *)0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue