From 3e18b101a0845f826de29cfd0c554c5e2be2baa5 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Wed, 21 Oct 2015 15:36:26 +0200 Subject: [PATCH] report: support "-o -field_name1,field_name2,...." --- tools/reporter.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/reporter.c b/tools/reporter.c index f053b0888..591f4ed98 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -604,11 +604,26 @@ static void _check_pv_list(struct cmd_context *cmd, int argc, char **argv, } } +static void _del_option_from_list(struct dm_list *sll, const char *str) +{ + struct dm_list *slh; + struct dm_str_list *sl; + + dm_list_uniterate(slh, sll, sll) { + sl = dm_list_item(slh, struct dm_str_list); + if (!strcmp(str, sl->str)) { + dm_list_del(slh); + return; + } + } +} + static int _get_report_options(struct cmd_context *cmd, const char **options) { struct arg_value_group_list *current_group; struct dm_list *final_opts_list; struct dm_list *opts_list = NULL; + struct dm_str_list *sl; const char *opts; int r = ECMD_PROCESSED; @@ -630,11 +645,18 @@ static int _get_report_options(struct cmd_context *cmd, const char **options) switch (*opts) { case '+': + /* fall through */ + case '-': if (!(opts_list = str_to_str_list(NULL, opts + 1, ",", 1))) { r = ECMD_FAILED; goto_out; } - dm_list_splice(final_opts_list, opts_list); + if (*opts == '+') { + dm_list_splice(final_opts_list, opts_list); + } else if (*opts == '-') { + dm_list_iterate_items(sl, opts_list) + _del_option_from_list(final_opts_list, sl->str); + } str_list_destroy(opts_list, 1); opts_list = NULL; break;