This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] nm: sort according to collating order of current locale


On Wed, Jun 19, 2002 at 06:51:57PM +0900, Mitsuru Chinen wrote:
> diff -upr binutils-020617.orig/binutils/nm.c binutils-020617/binutils/nm.c
> --- binutils-020617.orig/binutils/nm.c	Wed Jun 19 15:58:58 2002
> +++ binutils-020617/binutils/nm.c	Wed Jun 19 15:59:50 2002
> @@ -351,6 +351,7 @@ main (argc, argv)
>  #endif
>  #if defined (HAVE_SETLOCALE)
>    setlocale (LC_CTYPE, "");
> +  setlocale (LC_COLLATE, "");
>  #endif
>    bindtextdomain (PACKAGE, LOCALEDIR);
>    textdomain (PACKAGE);
> @@ -658,6 +659,7 @@ non_numeric_forward (P_x, P_y)
>  {
>    asymbol *x, *y;
>    const char *xn, *yn;
> +  int (*compare_string) (const char *s1, const char *s2);
>  
>    x = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_x, sort_x);
>    y = bfd_minisymbol_to_symbol (sort_bfd, sort_dynamic, P_y, sort_y);
> @@ -667,8 +669,13 @@ non_numeric_forward (P_x, P_y)
>    xn = bfd_asymbol_name (x);
>    yn = bfd_asymbol_name (y);
>  
> +  compare_string = strcmp;
> +#ifdef HAVE_STRCOLL
> +  if (MB_CUR_MAX > 1)
> +    compare_string = strcoll;
> +#endif
>    return ((xn == NULL) ? ((yn == NULL) ? 0 : -1) :
> -	  ((yn == NULL) ? 1 : strcmp (xn, yn)));
> +	  ((yn == NULL) ? 1 : compare_string (xn, yn)));
>  }
>  
>  static int

Is there a reason to not always use strcoll if it's available?

I'd be inclined to rewrite the end of non_numeric_forward like

  if (yn == NULL)
    return xn != NULL;
  if (xn == NULL)
    return -1;

#ifdef HAVE_STRCOLL
  return strcoll (xn, yn);
#else
  return strcmp (xn, yn);
#endif
}

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]