Menu

Problem with sort (coreutils)

Help
2006-03-30
2012-07-26
  • Nobody/Anonymous

    I'm having problems with sort. I can't manage to sort in ASCII order, even if I set LC_ALL=C. The result I'm getting is:

    @@
    3@

    ... and I was expecting:

    3@
    @@ (I can obtain this when running sort under Cygwin)

    Please, can anyone help me?

     
    • Nobody/Anonymous

      Thanks a lot Mathias...

      I'll try to see if it works...

      Alexandre

       
    • Mathias Michaelis

      I think the most gnuwin32 tools will ignore LC_... environment variables because they utilise the windows xp native setlocale() function. To substantiate my assumption, I wrote a small program in C:

      int main(void) {
      printf("%s\n", setlocale( LC_ALL, NULL ));
      setlocale( LC_ALL, "");
      printf("%s\n", setlocale( LC_ALL, NULL ));
      return 0;
      }

      The output of the program was

      C
      German_Switzerland.1252

      -- independent on LC_ALL! Now, the first thing that happens within sort.c is:

      setlocale( LC_ALL, "");

      Thus, on my computer sort.exe will work always with the German_Switzerland.1252 locale.

      I propose to apply a patch to all gnuwin32 programs that replace the line

      setlocale( LC_ALL, "");

      by something more meaningful, e.g. by

      {
      static struct {int id; char const * name;} const locale_list[] = {
      {LC_ALL, "LC_ALL"},
      {LC_COLLATE, "LC_COLLATE"},
      {LC_CTYPE, "LC_CTYPE"},
      {LC_MONETARY, "LC_MONETARY"},
      {LC_NUMERIC, "LC_NUMERIC"},
      {LC_TIME, "LC_TIME"}
      };
      int index;

      for (
          index = 0;
          index = sizeof locale_list / sizeof locale_list[0];
          index += 1
      ) {
          char const * env_var_name    = locale_list[index].name;
          char const * env_var_content = getenv(env_var_name);
          if (env_var_content != NULL) {
              setlocale(locale_list[index].id, env_var_content);
          }
      }
      

      }

      I guess that is what happens with the posix setlocale that the gnuwin32 utilities are expecting to handle with.

      With kind regards

      Mathias

       
MongoDB Logo MongoDB