]> code.delx.au - gnu-emacs/commitdiff
Use c_strcasecmp for ASCII case-insensitive comparison.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jul 2012 21:07:46 +0000 (14:07 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jul 2012 21:07:46 +0000 (14:07 -0700)
Fixes: debbugs:11786
15 files changed:
ChangeLog
admin/ChangeLog
admin/merge-gnulib
configure.in
lib-src/ChangeLog
lib-src/etags.c
lib/gnulib.mk
lwlib/ChangeLog
lwlib/lwlib.c
m4/gnulib-comp.m4
src/ChangeLog
src/dispextern.h
src/nsfns.m
src/nsterm.m
src/xfaces.c

index 359035e58007acbbf721a9e24b28bcf2baab952a..b85855511bce5b17838dd1e6b5f82b33ba065f03 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2012-07-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       This is safer than strcasecmp, which has unspecified behavior
+       outside the POSIX locale and in practice sometimes does not work
+       in multibyte locales.  Similarly for c_strncasecmp and strncasecmp.
+       * configure.in (strcasecmp, strncasecmp): Remove checks.
+       * lib/c-ctype.c, lib/c-ctype.h, lib/c-strcase.h, lib/c-strcasecmp.c:
+       * lib/c-strncasecmp.c: New files, taken from gnulib.
+       * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
+
        Merge from gnulib, incorporating:
        2012-07-06 timespec-sub: avoid duplicate include
        Reported by Juanma Barranquero.
index 4563f2e6618e79d7af20eb9ee24eaf6a904bcf43..53b6143c82c0a3375f9da19bfb06c42852c283a1 100644 (file)
@@ -1,3 +1,8 @@
+2012-07-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       * merge-gnulib (GNULIB_MODULES): Add c-strcase.
+
 2012-07-05  Dmitry Antipov  <dmantipov@yandex.ru>
 
        * coccinelle/xzalloc.cocci: Semantic patch to convert
index d33807551d6ab51ba1697a716ce599a30a2d05a6..727b701cfe0c429667c905c023985623fd3898de 100755 (executable)
@@ -26,7 +26,7 @@
 GNULIB_URL=git://git.savannah.gnu.org/gnulib.git
 
 GNULIB_MODULES='
-  alloca-opt
+  alloca-opt c-strcase
   careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512
   dtoastr dtotimespec dup2
   filemode getloadavg getopt-gnu gettime gettimeofday
index dde8bcca855d529f6652a35183e5d49fee094b49..1a43aed754084437a5bfa063a37c18ffe42aaf74 100644 (file)
@@ -2707,7 +2707,6 @@ gai_strerror mkstemp getline getdelim fsync sync \
 difftime posix_memalign \
 getpwent endpwent getgrent endgrent \
 touchlock \
-strcasecmp strncasecmp \
 cfmakeraw cfsetspeed copysign __executable_start)
 
 dnl Cannot use AC_CHECK_FUNCS
index 11f2a688cd25f5e563dfd3f59e39a62a70c3d9f9..56f1551e8ba37f7d5470bcf0eda188de09924700 100644 (file)
@@ -1,3 +1,10 @@
+2012-07-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       * etags.c: Include c-strcase.h.
+       (etags_strcasecmp, etags_strncasecmp): Remove.
+       All uses replaced with c_strcasecmp and c_strncasecmp.
+
 2012-07-06  Andreas Schwab  <schwab@linux-m68k.org>
 
        * make-docfile.c (write_globals): Warn about duplicate function
index 2e05e37e80f0512086ddce4c71aa8da3c29b7fd7..5bdf3402e552bae86d16fc5ce18d64a5a37000e9 100644 (file)
@@ -144,6 +144,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <c-strcase.h>
 
 #include <assert.h>
 #ifdef NDEBUG
@@ -174,9 +175,9 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 #endif
 
 #define streq(s,t)     (assert ((s)!=NULL || (t)!=NULL), !strcmp (s, t))
-#define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !etags_strcasecmp (s, t))
+#define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !c_strcasecmp (s, t))
 #define strneq(s,t,n)  (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n))
-#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !etags_strncasecmp (s, t, n))
+#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n))
 
 #define CHARS 256              /* 2^sizeof(char) */
 #define CHAR(x)                ((unsigned int)(x) & (CHARS - 1))
@@ -375,16 +376,6 @@ static char *savenstr (const char *, int);
 static char *savestr (const char *);
 static char *etags_strchr (const char *, int);
 static char *etags_strrchr (const char *, int);
-#ifdef HAVE_STRCASECMP
-#define etags_strcasecmp(x,y) strcasecmp ((x), (y))
-#else
-static int etags_strcasecmp (const char *, const char *);
-#endif
-#ifdef HAVE_STRNCASECMP
-#define etags_strncasecmp(x,y,z) strncasecmp ((x), (y), (z))
-#else
-static int etags_strncasecmp (const char *, const char *, int);
-#endif
 static char *etags_getcwd (void);
 static char *relative_filename (char *, char *);
 static char *absolute_filename (char *, char *);
@@ -6314,52 +6305,6 @@ etags_strchr (register const char *sp, register int c)
   return NULL;
 }
 
-#ifndef HAVE_STRCASECMP
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- *
- * Same as BSD's strcasecmp, included for portability.
- */
-static int
-etags_strcasecmp (register const char *s1, register const char *s2)
-{
-  while (*s1 != '\0'
-        && (ISALPHA (*s1) && ISALPHA (*s2)
-            ? lowcase (*s1) == lowcase (*s2)
-            : *s1 == *s2))
-    s1++, s2++;
-
-  return (ISALPHA (*s1) && ISALPHA (*s2)
-         ? lowcase (*s1) - lowcase (*s2)
-         : *s1 - *s2);
-}
-#endif /* HAVE_STRCASECMP */
-
-#ifndef HAVE_STRNCASECMP
-/*
- * Compare two strings, ignoring case for alphabetic characters.
- * Stop after a given number of characters
- *
- * Same as BSD's strncasecmp, included for portability.
- */
-static int
-etags_strncasecmp (register const char *s1, register const char *s2, register int n)
-{
-  while (*s1 != '\0' && n-- > 0
-        && (ISALPHA (*s1) && ISALPHA (*s2)
-            ? lowcase (*s1) == lowcase (*s2)
-            : *s1 == *s2))
-    s1++, s2++;
-
-  if (n < 0)
-    return 0;
-  else
-    return (ISALPHA (*s1) && ISALPHA (*s2)
-           ? lowcase (*s1) - lowcase (*s2)
-           : *s1 - *s2);
-}
-#endif /* HAVE_STRCASECMP */
-
 /* Skip spaces (end of string is not space), return new pointer. */
 static char *
 skip_spaces (char *cp)
index 20aa19d93a5784d7d445c8325e07974f4a0aa13d..6e2bf89786c5349b6ee18b4880de1198a9257b1b 100644 (file)
@@ -21,7 +21,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdarg stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timespec-add timespec-sub utimens warnings
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdarg stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timespec-add timespec-sub utimens warnings
 
 
 MOSTLYCLEANFILES += core *.stackdump
@@ -64,6 +64,18 @@ EXTRA_DIST += allocator.h
 
 ## end   gnulib module allocator
 
+## begin gnulib module c-ctype
+
+libgnu_a_SOURCES += c-ctype.h c-ctype.c
+
+## end   gnulib module c-ctype
+
+## begin gnulib module c-strcase
+
+libgnu_a_SOURCES += c-strcase.h c-strcasecmp.c c-strncasecmp.c
+
+## end   gnulib module c-strcase
+
 ## begin gnulib module careadlinkat
 
 libgnu_a_SOURCES += careadlinkat.c
index 7f87c5d8e6a709646f1a39ed651af645f3a467de..ab1212441bbd85eec7a820f66b1184a07b309d5a 100644 (file)
@@ -1,3 +1,9 @@
+2012-07-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       * lwlib.c: Include c-strcase.h.
+       (lwlib_strcasecmp): Remove.  All uses replaced with c_strcasecmp.
+
 2012-06-26  Paul Eggert  <eggert@cs.ucla.edu>
 
        Clean out last vestiges of the old HAVE_CONFIG_H stuff.
index d436b18d2228a90637bede5e46ae40a599c0caa5..5820be8d7a4dc3e9c923e6992682fd26bfbb0f12 100644 (file)
@@ -24,6 +24,7 @@ Boston, MA 02110-1301, USA.  */
 
 #include <setjmp.h>
 #include <lisp.h>
+#include <c-strcase.h>
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -112,31 +113,6 @@ safe_strdup (const char *s)
   return result;
 }
 
-#ifdef HAVE_STRCASECMP
-#define lwlib_strcasecmp(x,y) strcasecmp ((x), (y))
-#else
-
-/* Like strcmp but ignore differences in case.  */
-
-static int
-lwlib_strcasecmp (const char *s1, const char *s2)
-{
-  while (1)
-    {
-      int c1 = *s1++;
-      int c2 = *s2++;
-      if (isupper (c1))
-       c1 = tolower (c1);
-      if (isupper (c2))
-       c2 = tolower (c2);
-      if (c1 != c2)
-       return (c1 > c2 ? 1 : -1);
-      if (c1 == 0)
-       return 0;
-    }
-}
-#endif /* HAVE_STRCASECMP */
-
 static void
 safe_free_str (char *s)
 {
@@ -733,7 +709,7 @@ find_in_table (const char *type, const widget_creation_entry *table)
 {
   const widget_creation_entry* cur;
   for (cur = table; cur->type; cur++)
-    if (!lwlib_strcasecmp (type, cur->type))
+    if (!c_strcasecmp (type, cur->type))
       return cur->function;
   return NULL;
 }
index 17ece1cfe3544f0a1c3b0c148cd40c69592c72a3..824c8bbffc8d1617c73cc66207605ef10b8a8240 100644 (file)
@@ -40,6 +40,8 @@ AC_DEFUN([gl_EARLY],
   AC_REQUIRE([gl_PROG_AR_RANLIB])
   # Code from module alloca-opt:
   # Code from module allocator:
+  # Code from module c-ctype:
+  # Code from module c-strcase:
   # Code from module careadlinkat:
   # Code from module clock-time:
   # Code from module crypto/md5:
@@ -518,6 +520,11 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/alloca.in.h
   lib/allocator.c
   lib/allocator.h
+  lib/c-ctype.c
+  lib/c-ctype.h
+  lib/c-strcase.h
+  lib/c-strcasecmp.c
+  lib/c-strncasecmp.c
   lib/careadlinkat.c
   lib/careadlinkat.h
   lib/dosname.h
index 96458770122830a0c2e23fe1e10ecde0861c65c2..3f8cbdff476db9a38740fbbf43a0ec7ecb20febb 100644 (file)
@@ -1,5 +1,12 @@
 2012-07-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       * dispextern.h, nsfns.m, nsterm.m: Include <c-strcase.h>.
+       * dispextern.h (xstrcasecmp): Rewrite using c_strcasecmp.
+       * nsfns.m (x_get_string_resource): Use c_strncasecmp, not strncasecmp.
+       * nsterm.m (ns_default): Use c_strcasecmp, not strcasecmp.
+       * xfaces.c (xstrcasecmp) [!HAVE_STRCASECMP]: Remove.
+
        * xfont.c (compare_font_names): Redo to omit the need for casts.
 
 2012-07-06  Andreas Schwab  <schwab@linux-m68k.org>
index 4672d108e936d07818f4528c6af6a88a061a8a10..7d9f913e4f1e8005b00655b4d033d58d55ece79f 100644 (file)
@@ -46,6 +46,13 @@ typedef struct {
 #include "msdos.h"
 #endif
 
+#include <c-strcase.h>
+static inline int
+xstrcasecmp (char const *a, char const *b)
+{
+  return c_strcasecmp (a, b);
+}
+
 #ifdef HAVE_X_WINDOWS
 typedef struct x_display_info Display_Info;
 typedef XImage * XImagePtr;
@@ -3198,11 +3205,6 @@ void unload_color (struct frame *, unsigned long);
 char *choose_face_font (struct frame *, Lisp_Object *, Lisp_Object,
                         int *);
 void prepare_face_for_display (struct frame *, struct face *);
-#ifdef HAVE_STRCASECMP
-#define xstrcasecmp(x,y) strcasecmp ((x), (y))
-#else
-int xstrcasecmp (const char *, const char *);
-#endif
 int lookup_named_face (struct frame *, Lisp_Object, int);
 int lookup_basic_face (struct frame *, int);
 int smaller_face (struct frame *, int, int);
index 5303a5ec3136bd06bb9da655af227edd37f83b16..47943e5d98a17f74be021de3701484f94c8828b0 100644 (file)
@@ -33,6 +33,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
 #include <signal.h>
 #include <math.h>
 #include <setjmp.h>
+#include <c-strcase.h>
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -2226,8 +2227,8 @@ x_get_string_resource (XrmDatabase rdb, char *name, char *class)
 
   res = ns_get_defaults_value (toCheck);
   return !res ? NULL :
-      (!strncasecmp (res, "YES", 3) ? "true" :
-          (!strncasecmp (res, "NO", 2) ? "false" : res));
+      (!c_strncasecmp (res, "YES", 3) ? "true" :
+          (!c_strncasecmp (res, "NO", 2) ? "false" : res));
 }
 
 
index ae536638c3374a2e746eada15c52df3b9afe04b3..1cd4c1c427125d949743d8e04b02d9151eddab4a 100644 (file)
@@ -36,6 +36,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
 #include <signal.h>
 #include <unistd.h>
 #include <setjmp.h>
+#include <c-strcase.h>
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -3848,9 +3849,9 @@ ns_default (const char *parameter, Lisp_Object *result,
     {
       double f;
       char *pos;
-      if (strcasecmp (value, "YES") == 0)
+      if (c_strcasecmp (value, "YES") == 0)
         *result = yesval;
-      else if (strcasecmp (value, "NO") == 0)
+      else if (c_strcasecmp (value, "NO") == 0)
         *result = noval;
       else if (is_float && (f = strtod (value, &pos), pos != value))
         *result = make_float (f);
index a1062a4423287be7ac04d27d1e8d642768f22dd1..bc42cb4312a9a2a9634c17908dae7f011e52d526 100644 (file)
@@ -715,30 +715,6 @@ x_free_gc (struct frame *f, GC gc)
 }
 #endif  /* HAVE_NS */
 
-#ifndef HAVE_STRCASECMP
-/* Like strcasecmp/stricmp.  Used to compare parts of font names which
-   are in ISO8859-1.  */
-
-int
-xstrcasecmp (const char *s1, const char *s2)
-{
-  while (*s1 && *s2)
-    {
-      unsigned char b1 = *s1;
-      unsigned char b2 = *s2;
-      unsigned char c1 = tolower (b1);
-      unsigned char c2 = tolower (b2);
-      if (c1 != c2)
-       return c1 < c2 ? -1 : 1;
-      ++s1, ++s2;
-    }
-
-  if (*s1 == 0)
-    return *s2 == 0 ? 0 : -1;
-  return 1;
-}
-#endif /* HAVE_STRCASECMP */
-
 /* If FRAME is nil, return a pointer to the selected frame.
    Otherwise, check that FRAME is a live frame, and return a pointer
    to it.  NPARAM is the parameter number of FRAME, for