1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

refactor: move code detecting report options to a separate function

This commit is contained in:
Peter Rajnoha 2015-10-20 16:36:11 +02:00
parent 77605457e7
commit e149fe7fdf

View File

@ -604,13 +604,35 @@ static void _check_pv_list(struct cmd_context *cmd, int argc, char **argv,
}
}
static int _get_report_options(struct cmd_context *cmd, const char **options)
{
const char *opts;
char *str;
opts = arg_str_value(cmd, options_ARG, "");
if (!opts || !*opts) {
log_error("Invalid options string: %s", opts);
return EINVALID_CMD_LINE;
}
if (*opts == '+') {
if (!(str = dm_pool_alloc(cmd->mem,
strlen(*options) + strlen(opts) + 1))) {
log_error("options string allocation failed");
return ECMD_FAILED;
}
(void) sprintf(str, "%s,%s", *options, opts + 1);
*options = str;
} else
*options = opts;
return ECMD_PROCESSED;
}
static int _report(struct cmd_context *cmd, int argc, char **argv,
report_type_t report_type)
{
void *report_handle;
struct processing_handle handle = {0};
const char *opts;
char *str;
const char *keys = NULL, *options = NULL, *selection = NULL, *separator;
int r = ECMD_PROCESSED;
int aligned, buffered, headings, field_prefixes, quoted;
@ -689,23 +711,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
}
/* If -o supplied use it, else use default for report_type */
if (arg_count(cmd, options_ARG)) {
opts = arg_str_value(cmd, options_ARG, "");
if (!opts || !*opts) {
log_error("Invalid options string: %s", opts);
return EINVALID_CMD_LINE;
}
if (*opts == '+') {
if (!(str = dm_pool_alloc(cmd->mem,
strlen(options) + strlen(opts) + 1))) {
log_error("options string allocation failed");
return ECMD_FAILED;
}
(void) sprintf(str, "%s,%s", options, opts + 1);
options = str;
} else
options = opts;
}
if (arg_count(cmd, options_ARG) &&
((r = _get_report_options(cmd, &options) != ECMD_PROCESSED)))
return r;
/* -O overrides default sort settings */
keys = arg_str_value(cmd, sort_ARG, keys);