From: Luiz Capitulino <lcapitulino@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 2/4] monitor: New argument type 'b'
Date: Thu, 25 Mar 2010 14:39:48 -0300 [thread overview]
Message-ID: <20100325143948.77b8a1f9@redhat.com> (raw)
In-Reply-To: <m3aatwe2es.fsf@blackfin.pond.sub.org>
On Thu, 25 Mar 2010 18:28:43 +0100
Markus Armbruster <armbru@redhat.com> wrote:
> Luiz Capitulino <lcapitulino@redhat.com> writes:
>
> > On Tue, 23 Mar 2010 11:27:56 +0100
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> This is a boolean value. Human monitor accepts "on" or "off".
> >> Consistent with option parsing (see parse_option_bool()).
> >>
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >> ---
> >> monitor.c | 31 +++++++++++++++++++++++++++++++
> >> 1 files changed, 31 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/monitor.c b/monitor.c
> >> index 3ce9a4e..47b68a2 100644
> >> --- a/monitor.c
> >> +++ b/monitor.c
> >> @@ -85,6 +85,8 @@
> >> *
> >> * '?' optional type (for all types, except '/')
> >> * '.' other form of optional type (for 'i' and 'l')
> >> + * 'b' boolean
> >> + * user mode accepts "on" or "off"
> >> * '-' optional parameter (eg. '-f')
> >> *
> >> */
> >> @@ -3841,6 +3843,29 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
> >> qdict_put(qdict, key, qfloat_from_double(val));
> >> }
> >> break;
> >> + case 'b':
> >> + {
> >> + const char *beg;
> >> + int val;
> >> +
> >> + while (qemu_isspace(*p)) {
> >> + p++;
> >> + }
> >> + beg = p;
> >> + while (qemu_isgraph(*p)) {
> >> + p++;
> >> + }
> >> + if (!strncmp(beg, "on", p - beg)) {
> >> + val = 1;
> >> + } else if (!strncmp(beg, "off", p - beg)) {
> >> + val = 0;
> >> + } else {
> >> + monitor_printf(mon, "Expected 'on' or 'off'\n");
> >> + goto fail;
> >> + }
> >
> > This will make 'on' be the default when no on/off is specified, is that
> > your intention? I'm wondering if this can cause problems when you add
> > optional support for it and mixes it with other arguments.
>
> No. Intended behavior: the argument must be either "on" or "off". With
> "on", (KEY, true) is put into the dictionary, for "off" it's (KEY,
> false).
>
> We get a third case for optional argument if we support that: KEY not in
> dictionary. The handler decides how to interpret that.
Ok, but strncmp() will return 0 if p - beg = 0, right? In this
case the current implementation will put true on the dict for a line like:
(qemu) set_link foo
Which should return an error to the user then.
next prev parent reply other threads:[~2010-03-25 17:40 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-23 10:27 [Qemu-devel] [PATCH 0/4] monitor: Convert do_set_link() to QObject, QError Markus Armbruster
2010-03-23 10:27 ` [Qemu-devel] [PATCH 1/4] monitor: Rename argument type 'b' to 'f' Markus Armbruster
2010-03-23 10:27 ` [Qemu-devel] [PATCH 2/4] monitor: New argument type 'b' Markus Armbruster
2010-03-24 19:31 ` [Qemu-devel] " Luiz Capitulino
2010-03-25 17:28 ` Markus Armbruster
2010-03-25 17:39 ` Luiz Capitulino [this message]
2010-03-26 7:43 ` Markus Armbruster
2010-03-23 10:27 ` [Qemu-devel] [PATCH 3/4] monitor: Use argument type 'b' for set_link Markus Armbruster
2010-03-23 10:27 ` [Qemu-devel] [PATCH 4/4] monitor: Convert do_set_link() to QObject, QError Markus Armbruster
2010-03-24 19:20 ` [Qemu-devel] Re: [PATCH 0/4] " Luiz Capitulino
2010-03-25 17:40 ` Daniel P. Berrange
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=20100325143948.77b8a1f9@redhat.com \
--to=lcapitulino@redhat.com \
--cc=armbru@redhat.com \
--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 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).