Bug#850475: [PATCH] common: Avoid unnecessary ambiguity in argparse.

2017-01-10 Thread Werner Koch
On Tue, 10 Jan 2017 22:16, d...@fifthhorseman.net said:

> If two struct ARGPARSE_OPTS share a prefix in their long_opt name, but
> have the exact same short_opt and flags, they are aliases and not

Smart.  Please push with the usual two dashes before the free form
text.


Salam-Shalom,

   Werner

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.


pgpBN3Xrqw8Gn.pgp
Description: PGP signature


Bug#850475: [PATCH] common: Avoid unnecessary ambiguity in argparse.

2017-01-10 Thread Daniel Kahn Gillmor
* common/argparse.c (find_long_option): Avoid unnecessary ambiguity.

If two struct ARGPARSE_OPTS share a prefix in their long_opt name, but
have the exact same short_opt and flags, they are aliases and not
distinct options.  Avoid reporting this as an ambiguity, so that (for
example) both --clearsign and --clear-sign can be invoked as --clear.

Signed-off-by: Daniel Kahn Gillmor 
Debian-Bug-Id: 850475
---
 common/argparse.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/argparse.c b/common/argparse.c
index dce725af9..d395229ad 100644
--- a/common/argparse.c
+++ b/common/argparse.c
@@ -898,7 +898,9 @@ find_long_option( ARGPARSE_ARGS *arg,
int j;
for(j=i+1; opts[j].short_opt; j++ ) {
if( opts[j].long_opt
-   && !strncmp( opts[j].long_opt, keyword, n ) )
+   && !strncmp( opts[j].long_opt, keyword, n )
+&& !(opts[j].short_opt == opts[i].short_opt
+ && opts[j].flags == opts[i].flags ) )
return -2;  /* abbreviation is ambiguous */
}
return i;
-- 
2.11.0