Thread (26 messages) flat view 26 messages, 8 authors, 2016-06-15

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

From: Medve Emilian-EMMEDVE1 <hidden>
Date: 2016-06-15 22:43:39

Hi,


You probably already considered and rejected the GNU argp parser. I used it before and I'd like to know reasons I should stay away from it.


Cheers,
Emil.

-----Original Message-----
From: git-owner@vger.kernel.org 
[mailto:git-owner@vger.kernel.org] On Behalf Of Pierre Habouzit
Sent: Friday, October 05, 2007 9:46 AM
To: Mike Hommey
Cc: Kristian Høgsberg; git@vger.kernel.org; Junio C Hamano
Subject: Re: [ALTERNATE PATCH] Add a simple option parser.

On Fri, Oct 05, 2007 at 02:30:14PM +0000, Mike Hommey wrote:
quoted
On Fri, Oct 05, 2007 at 04:25:07PM +0200, Pierre Habouzit 
[off-list ref] wrote:
quoted
quoted
The option parser takes argc, argv, an array of struct option
and a usage string.  Each of the struct option elements 
in the array
quoted
quoted
describes a valid option, its type and a pointer to the 
location where the
quoted
quoted
value is written.  The entry point is parse_options(), 
which scans through
quoted
quoted
the given argv, and matches each option there against the 
list of valid
quoted
quoted
options.  During the scan, argv is rewritten to only contain the
non-option command line arguments and the number of these 
is returned.
quoted
quoted
Aggregation of single switches is allowed:
  -rC0 is the same as -r -C 0 (supposing that -C wants an arg).
I like options aggregation, but I'm not sure aggregating 
option arguments
quoted
is a good idea... I can't even think of an application that does it.
  You mean like `grep -A1` or `diff -u3` or `ls -w10` ?

getopt does that by default as well, so you may not have aware of it,
but it's how things work in your system already.

  btw `ls -rw10` works, though `ls -w10r` drops the 'r' 
silently. FWIW I
don't, in that case, the alternate patch I propose complains 
about "10r"
not being a valid integer, and that's because unlike getopt, the patch
krh proposed knows what an integer is ;)
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                
http://www.madism.org
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help