All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com
Subject: Re: [PATCH 1/4] keyval: Parse help options
Date: Fri, 09 Oct 2020 16:36:06 +0200	[thread overview]
Message-ID: <871ri7ii09.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <b28cad72-d344-78fa-fc07-b4a6a63fbc50@redhat.com> (Eric Blake's message of "Tue, 29 Sep 2020 12:46:55 -0500")

Eric Blake <eblake@redhat.com> writes:

> On 9/29/20 12:26 PM, Kevin Wolf wrote:
>> This adds a new parameter 'help' to keyval_parse() that enables parsing
>> of help options. If NULL is passed, the function behaves the same as
>> before. But if a bool pointer is given, it contains the information
>> whether an option "help" without value was given (which would otherwise
>> either result in an error or be interpreted as the value for an implied
>> key).
>> 
>> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> ---
>
>> +++ b/util/keyval.c
>
> Might be nice to see this before the testsuite changes by tweaking the
> git orderfile.
>
>> @@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
>>   * On failure, return NULL.
>>   */
>>  static const char *keyval_parse_one(QDict *qdict, const char *params,
>> -                                    const char *implied_key,
>> +                                    const char *implied_key, bool *help,
>>                                      Error **errp)
>>  {
>>      const char *key, *key_end, *s, *end;
>> @@ -179,6 +179,16 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
>>  
>>      key = params;
>>      len = strcspn(params, "=,");
>> +
>> +    if (help && key[len] != '=' && !strncmp(key, "help", len)) {
>
> What if the user typed "help,," to get "help," as the value of the
> implied key?

The value of an implied key cannot contain ','.  This is intentional.

test-keyval.c:

    /* Implied key with empty value (qemu_opts_parse() accepts this) */
    qdict = keyval_parse(",", "implied", &err);
    error_free_or_abort(&err);
    g_assert(!qdict);

    /* Likewise (qemu_opts_parse(): implied key with comma value) */
    qdict = keyval_parse(",,,a=1", "implied", &err);
    error_free_or_abort(&err);
    g_assert(!qdict);

Grammar:

 *   val-no-key   = / [^=,]* /

Aside: should be + instead of *.  Doc bug.  I'll fix it.

[...]



  parent reply	other threads:[~2020-10-09 14:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 17:26 [PATCH 0/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-29 17:26 ` [PATCH 1/4] keyval: Parse help options Kevin Wolf
2020-09-29 17:46   ` Eric Blake
2020-09-30 13:04     ` Kevin Wolf
2020-09-30 13:42       ` Eric Blake
2020-09-30 14:56         ` Kevin Wolf
2020-10-09 14:36     ` Markus Armbruster [this message]
2020-09-29 17:26 ` [PATCH 2/4] qom: Factor out helpers from user_creatable_print_help() Kevin Wolf
2020-09-29 17:51   ` Eric Blake
2020-09-29 17:26 ` [PATCH 3/4] qom: Add user_creatable_print_help_from_qdict() Kevin Wolf
2020-09-29 17:53   ` Eric Blake
2020-09-29 17:26 ` [PATCH 4/4] qemu-storage-daemon: Remove QemuOpts from --object parser Kevin Wolf
2020-09-29 17:54   ` Eric Blake

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=871ri7ii09.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.