xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: "linux@eikelenboom.it" <linux@eikelenboom.it>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH 5 of 5] xl: Introduce helper macro for option parsing
Date: Thu, 18 Oct 2012 08:42:32 +0100	[thread overview]
Message-ID: <1350546152.28188.22.camel@dagon.hellion.org.uk> (raw)
In-Reply-To: <20606.55597.190403.314007@mariner.uk.xensource.com>

On Wed, 2012-10-17 at 17:13 +0100, Ian Jackson wrote:
> Ian Campbell writes ("[PATCH 5 of 5] xl: Introduce helper macro for option parsing"):
> > xl: Introduce helper macro for option parsing.
> 
> The idea is a reasonable one, but I have some quibbles.
> 
> > +#define FOREACH_OPT(_opt, _opts, _lopts, _help, _req)           \
> > +    while (((_opt) = def_getopt(argc, argv, (_opts), (_lopts),  \
> > +                                (_help), (_req))) != -1)        \
> > +        switch (opt)
> 
> This macro name should have the word SWITCH in it too so you know it
> has to take cases and that "break" doesn't do what you think.
> FOREACH_SWITCH_OPT maybe.

Good idea.

> 
> > @@ -2304,8 +2309,10 @@ int main_memmax(int argc, char **argv)
> >      char *mem;
> >      int rc;
> > 
> > -    if ((opt = def_getopt(argc, argv, "", NULL, "mem-max", 2)) != -1)
> > +    FOREACH_OPT(opt, "", NULL, "mem-max", 2) {
> > +    case 0: case 2:
> >          return opt;
> > +    }
> 
> This error handling behaviour (?) is rather opaque.  I RTFM
> getopt_long and AFAICT it returns 0 only for certain long options and
> it doesn't seem to mention returning 2.

2 comes from our existing implementation of def_getopt, which returns it
in the "not enough args" case. I don't think any callers differentiate
between that and 0 which is the other error indication though.

> Perhaps this would all be clearer if FOREACH_OPT had a big comment
> explaining how to use it.

Yes, will do.

  reply	other threads:[~2012-10-18  7:42 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-15 10:09 [PATCH 0 of 5] xl shutdown compatibility with xm Ian Campbell
2012-10-15 10:09 ` [PATCH 1 of 5] libxl: propagate user supplied values into event for_user field Ian Campbell
2012-10-17 15:58   ` Ian Jackson
2012-10-15 10:09 ` [PATCH 2 of 5] xl: Introduce xl shutdown --all support for xm compatibility Ian Campbell
2012-10-17 16:03   ` Ian Jackson
2012-10-18  8:24     ` Ian Campbell
2012-10-15 10:09 ` [PATCH 3 of 5] xl: Add --wait and --all to xl reboot Ian Campbell
2012-10-17 16:04   ` Ian Jackson
2012-10-15 10:09 ` [PATCH 4 of 5] xl: allow def_getopt to handle long options Ian Campbell
2012-10-17 16:05   ` Ian Jackson
2012-10-15 10:09 ` [PATCH 5 of 5] xl: Introduce helper macro for option parsing Ian Campbell
2012-10-17 16:13   ` Ian Jackson
2012-10-18  7:42     ` Ian Campbell [this message]
2012-10-15 10:32 ` [PATCH 0 of 5] xl shutdown compatibility with xm Sander Eikelenboom
2012-10-15 10:37   ` Ian Campbell
2012-10-15 11:21     ` Sander Eikelenboom
2012-10-15 11:45       ` Ian Campbell
2012-10-16  8:59         ` Sander Eikelenboom
2012-10-16  9:43           ` Ian Campbell
2012-10-16 10:06             ` Sander Eikelenboom
2012-10-19 10:21         ` Ian Jackson
2012-10-25 15:18           ` Sander Eikelenboom
2012-10-25 15:23             ` Ian Jackson
2012-10-25 15:32               ` Sander Eikelenboom
2012-10-25 15:47                 ` Ian Campbell
2012-10-25 15:55                   ` Sander Eikelenboom
2012-10-25 15:56                   ` Ian Jackson
2012-10-25 17:27                     ` Sander Eikelenboom
2012-10-25 15:34               ` Ian Campbell
2012-10-25 15:41                 ` Ian Jackson
2012-10-18  8:35 ` Ian Campbell

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=1350546152.28188.22.camel@dagon.hellion.org.uk \
    --to=ian.campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=linux@eikelenboom.it \
    --cc=xen-devel@lists.xen.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).