emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r108922: Use c_strcasecmp for ASCII c


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108922: Use c_strcasecmp for ASCII case-insensitive comparison.
Date: Fri, 06 Jul 2012 14:07:46 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108922
fixes bug: http://debbugs.gnu.org/11786
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Fri 2012-07-06 14:07:46 -0700
message:
  Use c_strcasecmp for ASCII case-insensitive comparison.
modified:
  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
=== modified file 'ChangeLog'
--- a/ChangeLog 2012-07-06 17:53:26 +0000
+++ b/ChangeLog 2012-07-06 21:07:46 +0000
@@ -1,5 +1,14 @@
 2012-07-06  Paul Eggert  <address@hidden>
 
+       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.

=== modified file 'admin/ChangeLog'
--- a/admin/ChangeLog   2012-07-05 06:32:41 +0000
+++ b/admin/ChangeLog   2012-07-06 21:07:46 +0000
@@ -1,3 +1,8 @@
+2012-07-06  Paul Eggert  <address@hidden>
+
+       Use c_strcasecmp for ASCII case-insensitive comparison (Bug#11786).
+       * merge-gnulib (GNULIB_MODULES): Add c-strcase.
+
 2012-07-05  Dmitry Antipov  <address@hidden>
 
        * coccinelle/xzalloc.cocci: Semantic patch to convert

=== modified file 'admin/merge-gnulib'
--- a/admin/merge-gnulib        2012-06-22 21:17:42 +0000
+++ b/admin/merge-gnulib        2012-07-06 21:07:46 +0000
@@ -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

=== modified file 'configure.in'
--- a/configure.in      2012-07-04 08:07:26 +0000
+++ b/configure.in      2012-07-06 21:07:46 +0000
@@ -2707,7 +2707,6 @@
 difftime posix_memalign \
 getpwent endpwent getgrent endgrent \
 touchlock \
-strcasecmp strncasecmp \
 cfmakeraw cfsetspeed copysign __executable_start)
 
 dnl Cannot use AC_CHECK_FUNCS

=== modified file 'lib-src/ChangeLog'
--- a/lib-src/ChangeLog 2012-07-06 19:50:17 +0000
+++ b/lib-src/ChangeLog 2012-07-06 21:07:46 +0000
@@ -1,3 +1,10 @@
+2012-07-06  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        * make-docfile.c (write_globals): Warn about duplicate function

=== modified file 'lib-src/etags.c'
--- a/lib-src/etags.c   2012-06-26 01:05:39 +0000
+++ b/lib-src/etags.c   2012-07-06 21:07:46 +0000
@@ -144,6 +144,7 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <c-strcase.h>
 
 #include <assert.h>
 #ifdef NDEBUG
@@ -174,9 +175,9 @@
 #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 *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 @@
   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)

=== modified file 'lib/gnulib.mk'
--- a/lib/gnulib.mk     2012-06-22 21:17:42 +0000
+++ b/lib/gnulib.mk     2012-07-06 21:07:46 +0000
@@ -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 @@
 
 ## 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

=== modified file 'lwlib/ChangeLog'
--- a/lwlib/ChangeLog   2012-06-26 01:05:39 +0000
+++ b/lwlib/ChangeLog   2012-07-06 21:07:46 +0000
@@ -1,3 +1,9 @@
+2012-07-06  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        Clean out last vestiges of the old HAVE_CONFIG_H stuff.

=== modified file 'lwlib/lwlib.c'
--- a/lwlib/lwlib.c     2012-06-26 01:05:39 +0000
+++ b/lwlib/lwlib.c     2012-07-06 21:07:46 +0000
@@ -24,6 +24,7 @@
 
 #include <setjmp.h>
 #include <lisp.h>
+#include <c-strcase.h>
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -112,31 +113,6 @@
   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 @@
 {
   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;
 }

=== modified file 'm4/gnulib-comp.m4'
--- a/m4/gnulib-comp.m4 2012-06-22 21:17:42 +0000
+++ b/m4/gnulib-comp.m4 2012-07-06 21:07:46 +0000
@@ -40,6 +40,8 @@
   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 @@
   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

=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-06 20:49:23 +0000
+++ b/src/ChangeLog     2012-07-06 21:07:46 +0000
@@ -1,5 +1,12 @@
 2012-07-06  Paul Eggert  <address@hidden>
 
+       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  <address@hidden>

=== modified file 'src/dispextern.h'
--- a/src/dispextern.h  2012-07-03 18:24:42 +0000
+++ b/src/dispextern.h  2012-07-06 21:07:46 +0000
@@ -46,6 +46,13 @@
 #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 @@
 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);

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2012-07-05 18:35:48 +0000
+++ b/src/nsfns.m       2012-07-06 21:07:46 +0000
@@ -33,6 +33,7 @@
 #include <signal.h>
 #include <math.h>
 #include <setjmp.h>
+#include <c-strcase.h>
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -2226,8 +2227,8 @@
 
   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));
 }
 
 

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2012-07-05 18:35:48 +0000
+++ b/src/nsterm.m      2012-07-06 21:07:46 +0000
@@ -36,6 +36,7 @@
 #include <signal.h>
 #include <unistd.h>
 #include <setjmp.h>
+#include <c-strcase.h>
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -3848,9 +3849,9 @@
     {
       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);

=== modified file 'src/xfaces.c'
--- a/src/xfaces.c      2012-07-05 18:35:48 +0000
+++ b/src/xfaces.c      2012-07-06 21:07:46 +0000
@@ -715,30 +715,6 @@
 }
 #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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]