git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [ALTERNATE PATCH] Add a simple option parser.

From
Pierre Habouzit <madcoder@debian.org>
Date
Oct 5, 2007, 15:54 UTC
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:
Show 22 quoted lines
> 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.
Show 5 quoted lines
> > 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
Previous: Kristian HøgsbergNext: Pierre Habouzit
Message 25 of 26 in “Add a simple option parser.”
  1. Add a simple option parser.Kristian Høgsberg, Oct 3, 2007
  2. Port builtin-add.c to use the new option parser.Kristian Høgsberg, Oct 3, 2007
  3. Pierre HabouzitOct 3, 2007
  4. Kristian HøgsbergOct 4, 2007
  5. Pierre HabouzitOct 4, 2007
  6. Pierre HabouzitOct 4, 2007
  7. Johannes SchindelinOct 4, 2007
  8. Pierre HabouzitOct 5, 2007
  9. Pierre HabouzitOct 5, 2007
  10. Add a simple option parser.Pierre Habouzit, Oct 5, 2007
  11. Mike HommeyOct 5, 2007
  12. Pierre HabouzitOct 5, 2007
  13. Medve Emilian-EMMEDVE1Oct 5, 2007
  14. Pierre HabouzitOct 5, 2007
  15. Medve Emilian-EMMEDVE1Oct 5, 2007
  16. David KastrupOct 5, 2007
  17. Pierre HabouzitOct 5, 2007
  18. Sven VerdoolaegeOct 6, 2007
  19. Linus TorvaldsOct 5, 2007
  20. Medve Emilian-EMMEDVE1Oct 5, 2007
  21. Pierre HabouzitOct 5, 2007
  22. Linus TorvaldsOct 5, 2007
  23. David KastrupOct 5, 2007
  24. Kristian HøgsbergOct 5, 2007
  25. Pierre HabouzitOct 5, 2007
  26. Pierre HabouzitOct 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.