Fix handling of ambiguous command line options.
The approach used so far failed to recognize ambiguous abbreviations located in different groups. It also didn't work when MU_PARSEOPT_NO_SORT was requested. This commit fixes it by keeping an additional array of indices to long options. The array is sorted so that its elements produce a lexicographically ascending list of long options. * include/mailutils/opt.h (mu_parseopt): New members po_longcnt, po_longidx keep a sorted array of indices to po_optv with long options. * libmailutils/opt/opt.c (find_long_option): Iterate over po_longidx. (parseopt_init): Initialize and sort po_longidx. (mu_parseopt_free): Free po_longidx. * libmailutils/tests/parseopt.c: Add three more potentially ambiguous options * libmailutils/tests/parseopt26.at: New testcase. * libmailutils/tests/parseopt27.at: New testcase. * libmailutils/tests/Makefile.am: Add new testcases. * libmailutils/tests/testsuite.at: Likewise.
Showing
40 changed files
with
277 additions
and
63 deletions
libmailutils/tests/parseopt26.at
0 → 100644
libmailutils/tests/parseopt27.at
0 → 100644
-
Please register or sign in to post a comment