diff options
author | terminaldweller <thabogre@gmail.com> | 2022-04-22 05:25:23 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-04-22 05:25:23 +0000 |
commit | 641062ef0fca969feae3980afd0d22e436a26c41 (patch) | |
tree | 5a882d43a56662f82b805e7943873211c4a5b6a1 /arg.h | |
parent | Initial commit (diff) | |
download | tabbed-641062ef0fca969feae3980afd0d22e436a26c41.tar.gz tabbed-641062ef0fca969feae3980afd0d22e436a26c41.zip |
Diffstat (limited to '')
-rw-r--r-- | arg.h | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ +/* See the LICENSE file for copyright and license details. */ + +#ifndef __ARG_H__ +#define __ARG_H__ + +extern char *argv0; + +#define USED(x) ((void)(x)) + +/* use main(int argc, char *argv[]) */ +#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ + argv[0] && argv[0][1]\ + && argv[0][0] == '-';\ + argc--, argv++) {\ + char _argc;\ + char **_argv;\ + int brk;\ + if (argv[0][1] == '-' && argv[0][2] == '\0') {\ + argv++;\ + argc--;\ + break;\ + }\ + for (brk = 0, argv[0]++, _argv = argv;\ + argv[0][0] && !brk;\ + argv[0]++) {\ + if (_argv != argv)\ + break;\ + _argc = argv[0][0];\ + switch (_argc) + +#define ARGEND }\ + USED(_argc);\ + }\ + 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 + |