dircolors patch for locales like Turkish

View: New views
2 Messages — Rating Filter:   Alert me  

dircolors patch for locales like Turkish

by Paul Eggert :: Rate this Message:

| View Threaded | Show Only this Message

As we've been seeing in bug-gnulib, locales like Turkish say that "i"
and "I" are not lower- and upper-case variants of the same letter, but
are two different letters.  Hence utilities should not rely on
strcasecmp when they want the usual ASCII semantics.  Here's a patch
for coreutils.

2007-02-14  Paul Eggert  <eggert@...>

        * bootstrap.conf (gnulib_modules): Add c-strcase.  Remove strcase.
        * src/dircolors.c: Include c-strcase.h.
        (dc_parse_stream): Use c_strcasecmp rather than
        strcasecmp to avoid unreliable results in locales like Turkish
        where strcasecmp is incompatible with the C locale.

diff --git a/bootstrap.conf b/bootstrap.conf
index 631f2ed..e94478a 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -38,7 +38,8 @@ obsolete_gnulib_modules='
 gnulib_modules="
  $avoided_gnulib_modules
  $obsolete_gnulib_modules
- acl alloca announce-gen argmatch assert backupfile base64 c-strtod
+ acl alloca announce-gen argmatch assert backupfile base64
+ c-strcase c-strtod
  c-strtold calloc canon-host canonicalize chown cloexec
  config-h configmake
  closeout cycle-check d-ino d-type diacrit dirfd dirname dup2
@@ -60,7 +61,7 @@ gnulib_modules="
  rpmatch
  safe-read same
  save-cwd savedir savewd settime sha1 sig2str ssize_t stat-macros
- stat-time stdbool stdlib-safer stpcpy strcase strftime
+ stat-time stdbool stdlib-safer stpcpy strftime
  strpbrk strtoimax strtoumax strverscmp sys_stat timespec tzset
  unicodeio unistd-safer unlink-busy unlinkdir unlocked-io
  uptime userspec utimecmp utimens vasprintf verify version-etc-fsf
diff --git a/src/dircolors.c b/src/dircolors.c
index a6c9889..82eb1e0 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -24,6 +24,7 @@
 
 #include "system.h"
 #include "dircolors.h"
+#include "c-strcase.h"
 #include "error.h"
 #include "getline.h"
 #include "obstack.h"
@@ -295,7 +296,7 @@ dc_parse_stream (FILE *fp, const char *filename)
  }
 
       unrecognized = false;
-      if (strcasecmp (keywd, "TERM") == 0)
+      if (c_strcasecmp (keywd, "TERM") == 0)
  {
   if (STREQ (arg, term))
     state = ST_TERMSURE;
@@ -324,9 +325,9 @@ dc_parse_stream (FILE *fp, const char *filename)
   append_quoted (arg);
   APPEND_CHAR (':');
  }
-      else if (strcasecmp (keywd, "OPTIONS") == 0
-       || strcasecmp (keywd, "COLOR") == 0
-       || strcasecmp (keywd, "EIGHTBIT") == 0)
+      else if (c_strcasecmp (keywd, "OPTIONS") == 0
+       || c_strcasecmp (keywd, "COLOR") == 0
+       || c_strcasecmp (keywd, "EIGHTBIT") == 0)
  {
   /* Ignore.  */
  }
@@ -335,7 +336,7 @@ dc_parse_stream (FILE *fp, const char *filename)
   int i;
 
   for (i = 0; slack_codes[i] != NULL; ++i)
-    if (strcasecmp (keywd, slack_codes[i]) == 0)
+    if (c_strcasecmp (keywd, slack_codes[i]) == 0)
       break;
 
   if (slack_codes[i] != NULL)


_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@...
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Re: dircolors patch for locales like Turkish

by Jim Meyering :: Rate this Message:

| View Threaded | Show Only this Message

Paul Eggert <eggert@...> wrote:

> As we've been seeing in bug-gnulib, locales like Turkish say that "i"
> and "I" are not lower- and upper-case variants of the same letter, but
> are two different letters.  Hence utilities should not rely on
> strcasecmp when they want the usual ASCII semantics.  Here's a patch
> for coreutils.
>
> 2007-02-14  Paul Eggert  <eggert@...>
>
> * bootstrap.conf (gnulib_modules): Add c-strcase.  Remove strcase.
> * src/dircolors.c: Include c-strcase.h.
> (dc_parse_stream): Use c_strcasecmp rather than
> strcasecmp to avoid unreliable results in locales like Turkish
> where strcasecmp is incompatible with the C locale.

Thanks.
Applied.


_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@...
http://lists.gnu.org/mailman/listinfo/bug-coreutils