From: Pierre Habouzit Date: Fri, 05 Oct 2007 15:54:53 GMT Subject: Re: [ALTERNATE PATCH] Add a simple option parser. Message-ID: <20071005155453.GB20305@artemis.corp> In-Reply-To: <1191598424.7117.10.camel@hinata.boston.redhat.com> On Fri, Oct 05, 2007 at 03:33:44PM +0000, Kristian Høgsberg wrote: > On Fri, 2007-10-05 at 16:25 +0200, Pierre Habouzit wrote: > > The option parser takes argc, argv, an array of struct option > > and a usage string. Each of the struct option elements in the array > > describes a valid option, its type and a pointer to the location where the > > value is written. The entry point is parse_options(), which scans through > > the given argv, and matches each option there against the list of valid > > options. During the scan, argv is rewritten to only contain the > > non-option command line arguments and the number of these is returned. > > > > Aggregation of single switches is allowed: > > -rC0 is the same as -r -C 0 (supposing that -C wants an arg). > > > > Boolean switches automatically support the option with the same name, > > prefixed with 'no-' to disable the switch: > > --no-color / --color only need to have an entry for "color". > > > > Long options are supported either with '=' or without: > > --some-option=foo is the same as --some-option foo > > That looks great, works for me. One comment, though: it looks like > you're not sure whether to call these things "options" or "switches". > We should choose one and stick with it. I use the word "switch" when it's a short_option, and "option" when it's a long one. But maybe the distinction doesn't make sense, and it's a non-native speaker glitch. I don't care that much btw. > > oh and I don't grok what OPTION_LAST is for, so I left it apart, but > > it seems unused ? > > Oh, kill that. I used that as the option array terminator before we > switched to ARRAY_SIZE(). Okay :) -- ·O· Pierre Habouzit ··O madcoder@debian.org OOO http://www.madism.org