From 11fbc57405a118e6ec9a3ebc19bbf5ececdae4d6 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Fri, 5 Feb 2010 13:33:15 +0200 Subject: [PATCH] Argp: fix recognition of short alias options. * lib/argp-parse.c (convert_options): Fix improper use of `|' between character values. * tests/test-argp.c (group1_option): New alias option --read (-r). (group1_parser): Special handling for 'r'. (test15): New test case. (test_fun): Add test15. * tests/test-argp-2.sh: Update expected --help and --usage outputs. --- ChangeLog | 16 +++++++++++++++- lib/argp-parse.c | 2 +- tests/test-argp-2.sh | 18 ++++++++++-------- tests/test-argp.c | 15 ++++++++++++++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 064c086be..4f4ffb13a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2010-02-05 Sergey Poznyakoff + Argp: fix recognition of short alias options. + + * lib/argp-parse.c (convert_options): Fix improper use of + `|' between character values. + * tests/test-argp.c (group1_option): New alias option + --read (-r). + (group1_parser): Special handling for 'r'. + (test15): New test case. + (test_fun): Add test15. + * tests/test-argp-2.sh: Update expected --help and --usage + outputs. + +2010-02-05 Sergey Poznyakoff + * tests/test-argp.c: Fix indentation. 2010-02-04 Eric Blake @@ -1062,7 +1076,7 @@ * tests/test-xalloc-die.sh: Use $EXEEXT. 2010-01-12 Simon Josefsson - Bruno Haible + Bruno Haible getlogin, getlogin_r: Avoid test failure. * tests/test-getlogin.c: Include . diff --git a/lib/argp-parse.c b/lib/argp-parse.c index 9a7877814..a1cbf884e 100644 --- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -339,7 +339,7 @@ convert_options (const struct argp *argp, values (the sign of the lower bits is preserved however)... */ cvt->long_end->val = - ((opt->key | real->key) & USER_MASK) + ((opt->key ? opt->key : real->key) & USER_MASK) + (((group - cvt->parser->groups) + 1) << USER_BITS); /* Keep the LONG_OPTS list terminated. */ diff --git a/tests/test-argp-2.sh b/tests/test-argp-2.sh index 344bf3716..5c0c64ce6 100755 --- a/tests/test-argp-2.sh +++ b/tests/test-argp-2.sh @@ -33,10 +33,10 @@ func_compare() { #### # Test --usage output cat > $TMP < $TMP <verbose++; break; + case 'r': + args->read = 1; + /* fall through */ case 'f': args->file = arg; break; @@ -430,6 +435,14 @@ test14 (struct argp *argp) fail ("option not processed"); } +void +test15 (struct argp *argp) +{ + INIT_TEST2 (1, "-r", "FILE"); + test_file (argp, argc, argv, &test_args); + if (!test_args.read) + fail ("short alias not recognized properly"); +} typedef void (*test_fp) (struct argp *argp); @@ -438,7 +451,7 @@ test_fp test_fun[] = { test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, test11, test12, - test13, test14, + test13, test14, test15, NULL }; -- 2.11.0