From 74290b5f977894eb1fb92b6a2e978b6fdbd76bde Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 15 Nov 2014 02:54:18 +0100 Subject: select last value of the options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/common.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/common.c b/src/common.c index 48b33d8..a021ff6 100644 --- a/src/common.c +++ b/src/common.c @@ -39,14 +39,16 @@ -#define USER_ERROR(string) \ +#define USER_ERROR(string) \ (fprintf(stderr, "%s: %s.\n", execname, string), 1) - -#define ADD(arg, desc, ...) \ - (arg ? args_add_option(args_new_argumented(NULL, arg, 0, __VA_ARGS__, NULL), desc) \ +#define ADD(arg, desc, ...) \ + (arg ? args_add_option(args_new_argumented(NULL, arg, 0, __VA_ARGS__, NULL), desc) \ : args_add_option(args_new_argumentless(NULL, 0, __VA_ARGS__, NULL), desc)) +#define LAST(arg) \ + (args_opts_get(arg)[args_opts_get_count(arg) - 1]) + /** @@ -529,12 +531,12 @@ int run(int argc, char* argv[], libkeccak_generalised_spec_t* restrict gspec, co args_parse(argc, argv); if (args_opts_used("-h")) return args_help(0), 0; - if (args_opts_used("-R")) gspec->bitrate = atol(args_opts_get("-R")[0]); - if (args_opts_used("-C")) gspec->capacity = atol(args_opts_get("-C")[0]); - if (args_opts_used("-N")) gspec->output = atol(args_opts_get("-N")[0]); - if (args_opts_used("-S")) gspec->state_size = atol(args_opts_get("-S")[0]); - if (args_opts_used("-W")) gspec->word_size = atol(args_opts_get("-W")[0]); - if (args_opts_used("-Z")) squeezes = atol(args_opts_get("-Z")[0]); + if (args_opts_used("-R")) gspec->bitrate = atol(LAST("-R")); + if (args_opts_used("-C")) gspec->capacity = atol(LAST("-C")); + if (args_opts_used("-N")) gspec->output = atol(LAST("-N")); + if (args_opts_used("-S")) gspec->state_size = atol(LAST("-S")); + if (args_opts_used("-W")) gspec->word_size = atol(LAST("-W")); + if (args_opts_used("-Z")) squeezes = atol(LAST("-Z")); if (args_opts_used("-u")) presentation = REPRESENTATION_UPPER_CASE; if (args_opts_used("-l")) presentation = REPRESENTATION_LOWER_CASE; if (args_opts_used("-b")) presentation = REPRESENTATION_BINARY; -- cgit v1.2.3-70-g09d2