[pacman-dev] [PATCH] Sort short options before long options in --help

Dan McGee dpmcgee at gmail.com
Thu Oct 14 09:44:00 EDT 2010


On Thu, Oct 14, 2010 at 8:36 AM, Xavier Chantry
<chantry.xavier at gmail.com> wrote:
> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> index 7d51124..38d7f6a 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -26,8 +26,10 @@
>  #define PACKAGE_VERSION GIT_VERSION
>  #endif
>
> +#include <assert.h>
>  #include <stdlib.h> /* atoi */
>  #include <stdio.h>
> +#include <ctype.h> /* isspace */
>  #include <limits.h>
>  #include <getopt.h>
>  #include <string.h>
> @@ -59,6 +61,41 @@ pmdb_t *db_local;
>  /* list of targets specified on command line */
>  static alpm_list_t *pm_targets;
>
> +/* Used to sort the options in --help */
> +static int options_cmp(const void *p1, const void *p2)
> +{
> +       const char *s1 = p1;
> +       const char *s2 = p2;
> +
> +       assert(s1);
> +       assert(s2);

Is the assert stuff you added to be safer? We don't want to use this.
One, they are compiled into nothing if NDEBUG is defined, and two, it
is a bit silly to abort on this condition. cmp(NULL, NULL) ==0, and
then just decide whether to sort NULL first or last.

-Dan


More information about the pacman-dev mailing list