rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | LICENSE

commit 84c06dab64f6e3821faa4569b21b44e3701579bc
parent 8720991b7363937ae203386176547a56d18c0151
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri,  7 Dec 2012 07:48:07 +0100

Optimizing arg.h and ordering some options.

Diffstat:
arg.h | 22++++++++++++++++++----
sieve.c | 37++++++++++++++++++-------------------
2 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/arg.h b/arg.h @@ -8,20 +8,23 @@ extern char *argv0; -#define USED(x) ((void)(x)) +#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 (argv[0]++, _argv = argv; argv[0][0];\ + for (brk = 0, argv[0]++, _argv = argv;\ + argv[0][0] && !brk;\ argv[0]++) {\ if (_argv != argv)\ break;\ @@ -34,8 +37,19 @@ extern char *argv0; USED(argv);\ USED(argc); -#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\ - (argc--, argv++, argv[0])) +#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 diff --git a/sieve.c b/sieve.c @@ -448,17 +448,11 @@ sievemain(int argc, char *argv[]) results = NULL; ARGBEGIN { - case 'l': - status |= DOLIST; - break; - case 'p': - status |= DOPUT; - break; - case 'g': - status |= DOGET; + case 'a': + status |= DOACTIVATE; break; - case 'e': - status |= DOEDIT; + case 'b': + status |= DOSHOWCAPABILITIES; break; case 'c': status |= DOCHECK; @@ -466,22 +460,27 @@ sievemain(int argc, char *argv[]) case 'd': status |= DODELETE; break; - case 'r': - status |= DORENAME; + case 'e': + status |= DOEDIT; break; - case 'a': - status |= DOACTIVATE; + case 'g': + status |= DOGET; break; - case 'v': - status |= DODEACTIVATE; + case 'l': + status |= DOLIST; + break; + case 'p': + status |= DOPUT; + break; + case 'r': + status |= DORENAME; break; case 's': status |= DOHAVESPACE; break; - case 'b': - status |= DOSHOWCAPABILITIES; + case 'v': + status |= DODEACTIVATE; break; - case 'h': default: sieveusage(); } ARGEND;