Commit d4a938f6 d4a938f6d533981a77ddd55972e4c98b016d03d3 by Sergey Poznyakoff

Bugfixes in libmailutils/opt/opt.c

1 parent af83aaff
...@@ -34,21 +34,29 @@ optcmp (const void *a, const void *b) ...@@ -34,21 +34,29 @@ optcmp (const void *a, const void *b)
34 { 34 {
35 struct mu_option const *ap = *(struct mu_option const **)a; 35 struct mu_option const *ap = *(struct mu_option const **)a;
36 struct mu_option const *bp = *(struct mu_option const **)b; 36 struct mu_option const *bp = *(struct mu_option const **)b;
37 37
38 while (ap->opt_flags & MU_OPTION_ALIAS) 38 while (ap->opt_flags & MU_OPTION_ALIAS)
39 ap--; 39 ap--;
40 while (bp->opt_flags & MU_OPTION_ALIAS) 40 while (bp->opt_flags & MU_OPTION_ALIAS)
41 bp--; 41 bp--;
42 42
43 if (MU_OPTION_IS_VALID_SHORT_OPTION (ap) 43 if (!MU_OPTION_IS_VALID_SHORT_OPTION (ap)
44 && MU_OPTION_IS_VALID_SHORT_OPTION (bp)) 44 && MU_OPTION_IS_VALID_LONG_OPTION (ap)
45 return ap->opt_short - bp->opt_short; 45 && !MU_OPTION_IS_VALID_SHORT_OPTION (bp)
46 if (MU_OPTION_IS_VALID_LONG_OPTION (ap)
47 && MU_OPTION_IS_VALID_LONG_OPTION (bp)) 46 && MU_OPTION_IS_VALID_LONG_OPTION (bp))
48 return strcmp (ap->opt_long, bp->opt_long); 47 return strcasecmp (ap->opt_long, bp->opt_long);
49 if (MU_OPTION_IS_VALID_LONG_OPTION (ap)) 48 else
50 return 1; 49 {
51 return -1; 50 char afirst, bfirst;
51 int res;
52
53 afirst = ap->opt_short ? ap->opt_short : ap->opt_long ? *ap->opt_long : 0;
54 bfirst = bp->opt_short ? bp->opt_short : bp->opt_long ? *bp->opt_long : 0;
55
56 res = mu_tolower (afirst) - mu_tolower (bfirst);
57
58 return res ? res : afirst - bfirst;
59 }
52 } 60 }
53 61
54 /* Sort a group of options in OPTBUF, starting at index START (first 62 /* Sort a group of options in OPTBUF, starting at index START (first
...@@ -545,7 +553,7 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options, ...@@ -545,7 +553,7 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
545 /* Ensure sane start of options. This is necessary, in particular, 553 /* Ensure sane start of options. This is necessary, in particular,
546 because optcmp backs up until it finds an element with cleared 554 because optcmp backs up until it finds an element with cleared
547 MU_OPTION_ALIAS bit. */ 555 MU_OPTION_ALIAS bit. */
548 po->po_optv[0]->opt_flags &= MU_OPTION_ALIAS; 556 po->po_optv[0]->opt_flags &= ~MU_OPTION_ALIAS;
549 if (!(flags & MU_PARSEOPT_NO_SORT)) 557 if (!(flags & MU_PARSEOPT_NO_SORT))
550 { 558 {
551 /* Sort the options */ 559 /* Sort the options */
......