From: Dan Williams <dan.j.williams@intel.com>
To: QI Fuli <qi.fuli@jp.fujitsu.com>
Cc: linux-nvdimm <linux-nvdimm@lists.01.org>
Subject: Re: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Date: Tue, 17 Apr 2018 07:56:37 -0700 [thread overview]
Message-ID: <CAPcyv4g16niVJ+X73nSB9vHn3kNdc_X3ydZ1wy22AwVEp-1Rdw@mail.gmail.com> (raw)
In-Reply-To: <20180417063848.5585-2-qi.fuli@jp.fujitsu.com>
On Mon, Apr 16, 2018 at 11:38 PM, QI Fuli <qi.fuli@jp.fujitsu.com> wrote:
> This patch adds OPT_STRING_LIST to parse_option in order to support
> multiple space seperated string objects in one option.
>
> Signed-off-by: QI Fuli <qi.fuli@jp.fujitsu.com>
> ---
> ccan/list/list.h | 6 ++++++
> util/parse-options.c | 25 +++++++++++++++++++++++++
> util/parse-options.h | 3 +++
> 3 files changed, 34 insertions(+)
>
> diff --git a/ccan/list/list.h b/ccan/list/list.h
> index 4d1d34e..f6c927f 100644
> --- a/ccan/list/list.h
> +++ b/ccan/list/list.h
> @@ -26,6 +26,12 @@ struct list_node
> struct list_node *next, *prev;
> };
>
> +struct string_list_node
> +{
> + char *str;
> + struct list_node list;
> +};
> +
> /**
> * struct list_head - the head of a doubly-linked list
> * @h: the list_head (containing next and prev pointers)
> diff --git a/util/parse-options.c b/util/parse-options.c
> index 751c091..cac18f0 100644
> --- a/util/parse-options.c
> +++ b/util/parse-options.c
> @@ -20,6 +20,7 @@
> #include <util/util.h>
> #include <util/strbuf.h>
> #include <util/parse-options.h>
> +#include <ccan/list/list.h>
>
> #define OPT_SHORT 1
> #define OPT_UNSET 2
> @@ -695,3 +696,27 @@ int parse_opt_verbosity_cb(const struct option *opt,
> }
> return 0;
> }
> +
> +int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
> +{
> + if (unset)
> + return 0;
> +
> + if (!arg)
> + return -1;
> +
> + struct list_head *v = opt->value;
> + char *temp = strdup(arg);
> + const char *deli = " ";
> +
> + temp = strtok(temp, deli);
> + while (temp != NULL) {
> + struct string_list_node *sln = malloc(sizeof(*sln));
> + sln->str = temp;
> + list_add_tail(v, &sln->list);
> + temp = strtok(NULL, deli);
> + }
> +
> + free(temp);
> + return 0;
> +}
As far as I can see we do not need to allocate a list or add this new
OPT_STRING_LIST argument type. Just teach the util_<object>_filter()
routines that the 'ident' argument may be a space delimited list. See
the attached patch:
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2018-04-17 14:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 6:38 [PATCH 0/2] ndctl: change ndctl to support multiple arguments per option QI Fuli
2018-04-17 6:38 ` [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option QI Fuli
2018-04-17 14:56 ` Dan Williams [this message]
2018-04-17 15:29 ` Qi, Fuli
2018-04-17 16:32 ` Dan Williams
2018-04-18 10:09 ` Qi, Fuli
2018-04-18 14:30 ` Dan Williams
2018-04-19 2:06 ` Qi, Fuli
2018-04-19 2:09 ` Dan Williams
2018-04-19 2:18 ` Qi, Fuli
2018-04-17 6:38 ` [PATCH 2/2] ndctl, list: change -b -d -r -n options to support multiple arguments QI Fuli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPcyv4g16niVJ+X73nSB9vHn3kNdc_X3ydZ1wy22AwVEp-1Rdw@mail.gmail.com \
--to=dan.j.williams@intel.com \
--cc=linux-nvdimm@lists.01.org \
--cc=qi.fuli@jp.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).