[sheepdog] [PATCH 3/6] introduce sd_getopt as an alternative to getopt_long
Liu Yuan
namei.unix at gmail.com
Mon Nov 5 15:39:00 CET 2012
On 11/05/2012 06:52 PM, morita.kazutaka at gmail.com wrote:
> +#define SD_OPT_NONE 0x00
> +#define SD_OPT_STRING 0x01
> +#define SD_OPT_NUMBER 0x02
> +#define SD_OPT_BOOL 0x04
> +#define SD_OPT_SIZE 0x08
Is this flags for check necessary? We already set 'type' of parameter at
the very beginning (at sd_opt_param struct), so we can do type check at
the parse phase and throw error message when meeting invalid parameters.
So when we call sd_opt_param_get(), we should get what we specify at
sd_opt_param struct and no need to check type after calling this function.
Maybe we can even do range check for 'size' at parse time by built-in
'min' 'max' information at sd_opt_param struct.
I'd suggest to name sd_opt_param_get() as sd_opt_get_value(prefix, key)
to reflect the K:V pairs. This prefix can be NULL to save extra call of
strcmp() inside for options like '-j {dir, size, skip}'
Thanks,
Yuan
More information about the sheepdog
mailing list