Commit fee5959d authored by Paul Eggert's avatar Paul Eggert

Use c_strcasecmp for ASCII case-insensitive comparison.

Fixes: debbugs:11786
parent fd573f31
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.
......
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
......
......@@ -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
......
......@@ -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
......
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
......
......@@ -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)
......
......@@ -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
......
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.
......
......@@ -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;
}
......
......@@ -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
......
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>
......
......@@ -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);
......
......@@ -33,6 +33,7 @@ Updated by Christian Limpach (chris@nice.ch)
#include <signal.h>
#include <math.h>
#include <setjmp.h>
#include <c-strcase.h>
#include "lisp.h"
#include "blockinput.h"
......@@ -2226,8 +2227,8 @@ and GNUstep implementations ("distributor-specific release
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));
}
......
......@@ -36,6 +36,7 @@ Updated by Christian Limpach (chris@nice.ch)
#include <signal.h>
#include <unistd.h>
#include <setjmp.h>
#include <c-strcase.h>
#include "lisp.h"
#include "blockinput.h"
......@@ -3848,9 +3849,9 @@ Convert modifier code (see lisp.h) to lisp symbol
{
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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment