1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-28 02:50:41 +03:00

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()
This commit is contained in:
Zdenek Kabelac 2014-10-15 15:06:42 +02:00
parent fd1aa7fd5a
commit 2fc403b0fc
2 changed files with 37 additions and 0 deletions

View File

@ -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;

View File

@ -148,6 +148,8 @@ unsigned arg_count(const struct cmd_context *cmd, int a);
unsigned arg_is_set(const struct cmd_context *cmd, int a);
int arg_from_list_is_set(const struct cmd_context *cmd, const char *err_found, ...);
int arg_outside_list_is_set(const struct cmd_context *cmd, const char *err_found, ...);
int arg_from_list_is_negative(const struct cmd_context *cmd, const char *err_found, ...);
int arg_from_list_is_zero(const struct cmd_context *cmd, const char *err_found, ...);
const char *arg_long_option_name(int a);
const char *arg_value(const struct cmd_context *cmd, int a);
const char *arg_str_value(const struct cmd_context *cmd, int a, const char *def);