diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2014-10-15 15:06:42 +0200 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2014-10-24 16:39:31 +0200 |
commit | 2fc403b0fc5c7fffec4d7864433d0db3c139995c (patch) | |
tree | c739cfcf175f147a2f6d030a458dac54149319cb /tools/lvmcmdline.c | |
parent | fd1aa7fd5a1ccd7ebcf3446988110ad5c16fddc7 (diff) | |
download | lvm2-2fc403b0fc5c7fffec4d7864433d0db3c139995c.tar.gz |
toollib: new arg list functions
Check for negative arg list:
arg_from_list_is_negative()
Check for zero arg in list:
arg_from_list_is_zero()
Diffstat (limited to 'tools/lvmcmdline.c')
-rw-r--r-- | tools/lvmcmdline.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 4c6133230..6e1367940 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -127,6 +127,41 @@ int arg_outside_list_is_set(const struct cmd_context *cmd, const char *err_found return 0; } +int arg_from_list_is_negative(const struct cmd_context *cmd, const char *err_found, ...) +{ + int arg, ret = 0; + va_list ap; + + va_start(ap, err_found); + while ((arg = va_arg(ap, int)) != -1) + if (arg_sign_value(cmd, arg, SIGN_NONE) == SIGN_MINUS) { + if (err_found) + log_error("%s %s.", arg_long_option_name(arg), err_found); + ret = 1; + } + va_end(ap); + + return ret; +} + +int arg_from_list_is_zero(const struct cmd_context *cmd, const char *err_found, ...) +{ + int arg, ret = 0; + va_list ap; + + va_start(ap, err_found); + while ((arg = va_arg(ap, int)) != -1) + if (arg_is_set(cmd, arg) && + !arg_int_value(cmd, arg, 0)) { + if (err_found) + log_error("%s %s.", arg_long_option_name(arg), err_found); + ret = 1; + } + va_end(ap); + + return ret; +} + unsigned grouped_arg_is_set(const struct arg_values *av, int a) { return grouped_arg_count(av, a) ? 1 : 0; |