Rename module 'memxfrm' to 'amemxfrm'.
authorBruno Haible <bruno@clisp.org>
Sat, 14 Aug 2010 22:42:00 +0000 (00:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 14 Aug 2010 22:42:00 +0000 (00:42 +0200)
23 files changed:
ChangeLog
MODULES.html.sh
NEWS
lib/amemxfrm.c [new file with mode: 0644]
lib/amemxfrm.h [new file with mode: 0644]
lib/memxfrm.c [deleted file]
lib/memxfrm.h [deleted file]
lib/unicase/u-casexfrm.h
lib/unicase/u16-casexfrm.c
lib/unicase/u32-casexfrm.c
lib/unicase/u8-casexfrm.c
lib/uninorm/u-normxfrm.h
lib/uninorm/u16-normxfrm.c
lib/uninorm/u32-normxfrm.c
lib/uninorm/u8-normxfrm.c
modules/amemxfrm [new file with mode: 0644]
modules/memxfrm [deleted file]
modules/unicase/u16-casexfrm
modules/unicase/u32-casexfrm
modules/unicase/u8-casexfrm
modules/uninorm/u16-normxfrm
modules/uninorm/u32-normxfrm
modules/uninorm/u8-normxfrm

index 97646f4..d86bbc3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,32 @@
 2010-08-14  Bruno Haible  <bruno@clisp.org>
 
+       Rename module 'memxfrm' to 'amemxfrm'.
+       * lib/amemxfrm.h: Renamed from lib/memxfrm.h.
+       (amemxfrm): Renamed from memxfrm.
+       * lib/amemxfrm.c: Renamed from lib/memxfrm.h. Include amemxfrm.h.
+       (amemxfrm): Renamed from memxfrm.
+       * modules/amemxfrm: Renamed from modules/memxfrm. Update.
+       * NEWS: Mention the change.
+       * MODULES.html.sh (String handling <string.h>): Update.
+       * lib/unicase/u-casexfrm.h: Invoke amemxfrm instead of memxfrm.
+       * lib/unicase/u8-casexfrm.c: Include amemxfrm.h instead of memxfrm.h.
+       * lib/unicase/u16-casexfrm.c: Likewise.
+       * lib/unicase/u32-casexfrm.c: Likewise.
+       * lib/uninorm/u-normxfrm.h: Invoke amemxfrm instead of memxfrm.
+       * lib/uninorm/u8-normxfrm.c: Include amemxfrm.h instead of memxfrm.h.
+       * lib/uninorm/u16-normxfrm.c: Likewise.
+       * lib/uninorm/u32-normxfrm.c: Likewise.
+       * modules/unicase/u8-casexfrm (Depends-on): Add amemxfrm, remove
+       memxfrm.
+       * modules/unicase/u16-casexfrm (Depends-on): Likewise.
+       * modules/unicase/u32-casexfrm (Depends-on): Likewise.
+       * modules/uninorm/u8-normxfrm (Depends-on): Likewise.
+       * modules/uninorm/u16-normxfrm (Depends-on): Likewise.
+       * modules/uninorm/u32-normxfrm (Depends-on): Likewise.
+       Suggested by Paul Eggert.
+
+2010-08-14  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'astrxfrm'.
        * modules/astrxfrm-tests: New file.
        * tests/test-astrxfrm.c: New file.
index 76574ff..7fc6b79 100755 (executable)
@@ -1778,7 +1778,7 @@ func_all_modules ()
   func_module memmem-simple
   func_module mempcpy
   func_module memrchr
-  func_module memxfrm
+  func_module amemxfrm
   func_module rawmemchr
   func_module stpcpy
   func_module stpncpy
diff --git a/NEWS b/NEWS
index ff3bfb6..3f08cc4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2010-08-14  memxfrm         This module is renamed to amemxfrm. The include
+                            file is renamed to "amemxfrm.h". The function is
+                            renamed to amemxfrm.
+
 2010-08-09  symlinkat       This module now only provides symlinkat; use the
                             new module 'readlinkat' if needed.
 
diff --git a/lib/amemxfrm.c b/lib/amemxfrm.c
new file mode 100644 (file)
index 0000000..3823ce4
--- /dev/null
@@ -0,0 +1,180 @@
+/* Locale dependent memory area transformation for comparison.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+   This program is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published
+   by the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "amemxfrm.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
+{
+  /* Result accumulator.  */
+  char *result;
+  size_t length;
+  size_t allocated;
+
+  char orig_sentinel;
+
+  /* Initial memory allocation.  */
+  if (resultbuf != NULL && *lengthp > 0)
+    {
+      result = resultbuf;
+      allocated = *lengthp;
+    }
+  else
+    {
+      allocated = (n > 0 ? n : 1);
+      result = (char *) malloc (allocated);
+      if (result == NULL)
+        goto out_of_memory_2;
+    }
+  length = 0;
+
+  /* Add sentinel.byte.  */
+  orig_sentinel = s[n];
+  s[n] = '\0';
+
+  /* Iterate through S, transforming each NUL terminated segment.
+     Accumulate the resulting transformed segments in result, separated by
+     NULs.  */
+  {
+    const char *p_end = s + n + 1;
+    const char *p;
+
+    p = s;
+    for (;;)
+      {
+        /* Search next NUL byte.  */
+        size_t l = strlen (p);
+
+        for (;;)
+          {
+            size_t k;
+
+            /* A call to strxfrm costs about 20 times more than a call to
+               strdup of the result.  Therefore it is worth to try to avoid
+               calling strxfrm more than once on a given string, by making
+               enough room before calling strxfrm.
+               The size of the strxfrm result, k, is likely to be between
+               l and 3 * l.  */
+            if (3 * l >= allocated - length)
+              {
+                /* Grow the result buffer.  */
+                size_t new_allocated;
+                char *new_result;
+
+                new_allocated = length + 3 * l + 1;
+                if (new_allocated < 2 * allocated)
+                  new_allocated = 2 * allocated;
+                if (new_allocated < 64)
+                  new_allocated = 64;
+                if (result == resultbuf)
+                  new_result = (char *) malloc (new_allocated);
+                else
+                  new_result = (char *) realloc (result, new_allocated);
+                if (new_result != NULL)
+                  {
+                    allocated = new_allocated;
+                    result = new_result;
+                  }
+              }
+
+            errno = 0;
+            k = strxfrm (result + length, p, allocated - length);
+            if (errno != 0)
+              goto fail;
+            if (k >= allocated - length)
+              {
+                /* Grow the result buffer.  */
+                size_t new_allocated;
+                char *new_result;
+
+                new_allocated = length + k + 1;
+                if (new_allocated < 2 * allocated)
+                  new_allocated = 2 * allocated;
+                if (new_allocated < 64)
+                  new_allocated = 64;
+                if (result == resultbuf)
+                  new_result = (char *) malloc (new_allocated);
+                else
+                  new_result = (char *) realloc (result, new_allocated);
+                if (new_result == NULL)
+                  goto out_of_memory_1;
+                allocated = new_allocated;
+                result = new_result;
+              }
+            else
+              {
+                length += k;
+                break;
+              }
+          }
+
+        p = p + l + 1;
+        if (p == p_end)
+          break;
+        result[length] = '\0';
+        length++;
+      }
+  }
+
+  /* Shrink the allocated memory if possible.
+     It is not worth calling realloc when length + 1 == allocated; it would
+     save just one byte.  */
+  if (result != resultbuf && length + 1 < allocated)
+    {
+      if ((length > 0 ? length : 1) <= *lengthp)
+        {
+          memcpy (resultbuf, result, length);
+          free (result);
+          result = resultbuf;
+        }
+      else
+        {
+          char *memory = (char *) realloc (result, length > 0 ? length : 1);
+          if (memory != NULL)
+            result = memory;
+        }
+    }
+
+  s[n] = orig_sentinel;
+  *lengthp = length;
+  return result;
+
+ fail:
+  {
+    int saved_errno = errno;
+    if (result != resultbuf)
+      free (result);
+    s[n] = orig_sentinel;
+    errno = saved_errno;
+    return NULL;
+  }
+
+ out_of_memory_1:
+  if (result != resultbuf)
+    free (result);
+  s[n] = orig_sentinel;
+ out_of_memory_2:
+  errno = ENOMEM;
+  return NULL;
+}
diff --git a/lib/amemxfrm.h b/lib/amemxfrm.h
new file mode 100644 (file)
index 0000000..2edf535
--- /dev/null
@@ -0,0 +1,48 @@
+/* Locale dependent memory area transformation for comparison.
+   Copyright (C) 2009-2010 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published
+   by the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef AMEMXFRM_H
+#define AMEMXFRM_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Generalization of strxfrm() to strings with embedded NUL bytes.  */
+
+/* Transform the memory area [S..S+N-1] to a memory area, in such a way that
+   comparing (S1,N1) and (S2,N2) with memcoll() is equivalent to comparing
+   amemxfrm(S1,N1) and amemxfrm(S2,N2) with memcmp2().
+   The byte S[N] may be temporarily overwritten by this function, but will be
+   restored before this function returns.
+   The result of this function depends on the LC_COLLATE category of the
+   current locale.
+   If successful: If resultbuf is not NULL and the result fits into *lengthp
+   bytes, it is put in resultbuf, and resultbuf is returned.  Otherwise, a
+   freshly allocated string is returned.  In both cases, *lengthp is set to the
+   length of the returned string.
+   Upon failure, return NULL, with errno set.  */
+extern char * amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AMEMXFRM_H */
diff --git a/lib/memxfrm.c b/lib/memxfrm.c
deleted file mode 100644 (file)
index d0a3c78..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-/* Locale dependent memory area transformation for comparison.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-   Written by Bruno Haible <bruno@clisp.org>, 2009.
-
-   This program is free software: you can redistribute it and/or modify it
-   under the terms of the GNU Lesser General Public License as published
-   by the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "memxfrm.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
-{
-  /* Result accumulator.  */
-  char *result;
-  size_t length;
-  size_t allocated;
-
-  char orig_sentinel;
-
-  /* Initial memory allocation.  */
-  if (resultbuf != NULL && *lengthp > 0)
-    {
-      result = resultbuf;
-      allocated = *lengthp;
-    }
-  else
-    {
-      allocated = (n > 0 ? n : 1);
-      result = (char *) malloc (allocated);
-      if (result == NULL)
-        goto out_of_memory_2;
-    }
-  length = 0;
-
-  /* Add sentinel.byte.  */
-  orig_sentinel = s[n];
-  s[n] = '\0';
-
-  /* Iterate through S, transforming each NUL terminated segment.
-     Accumulate the resulting transformed segments in result, separated by
-     NULs.  */
-  {
-    const char *p_end = s + n + 1;
-    const char *p;
-
-    p = s;
-    for (;;)
-      {
-        /* Search next NUL byte.  */
-        size_t l = strlen (p);
-
-        for (;;)
-          {
-            size_t k;
-
-            /* A call to strxfrm costs about 20 times more than a call to
-               strdup of the result.  Therefore it is worth to try to avoid
-               calling strxfrm more than once on a given string, by making
-               enough room before calling strxfrm.
-               The size of the strxfrm result, k, is likely to be between
-               l and 3 * l.  */
-            if (3 * l >= allocated - length)
-              {
-                /* Grow the result buffer.  */
-                size_t new_allocated;
-                char *new_result;
-
-                new_allocated = length + 3 * l + 1;
-                if (new_allocated < 2 * allocated)
-                  new_allocated = 2 * allocated;
-                if (new_allocated < 64)
-                  new_allocated = 64;
-                if (result == resultbuf)
-                  new_result = (char *) malloc (new_allocated);
-                else
-                  new_result = (char *) realloc (result, new_allocated);
-                if (new_result != NULL)
-                  {
-                    allocated = new_allocated;
-                    result = new_result;
-                  }
-              }
-
-            errno = 0;
-            k = strxfrm (result + length, p, allocated - length);
-            if (errno != 0)
-              goto fail;
-            if (k >= allocated - length)
-              {
-                /* Grow the result buffer.  */
-                size_t new_allocated;
-                char *new_result;
-
-                new_allocated = length + k + 1;
-                if (new_allocated < 2 * allocated)
-                  new_allocated = 2 * allocated;
-                if (new_allocated < 64)
-                  new_allocated = 64;
-                if (result == resultbuf)
-                  new_result = (char *) malloc (new_allocated);
-                else
-                  new_result = (char *) realloc (result, new_allocated);
-                if (new_result == NULL)
-                  goto out_of_memory_1;
-                allocated = new_allocated;
-                result = new_result;
-              }
-            else
-              {
-                length += k;
-                break;
-              }
-          }
-
-        p = p + l + 1;
-        if (p == p_end)
-          break;
-        result[length] = '\0';
-        length++;
-      }
-  }
-
-  /* Shrink the allocated memory if possible.
-     It is not worth calling realloc when length + 1 == allocated; it would
-     save just one byte.  */
-  if (result != resultbuf && length + 1 < allocated)
-    {
-      if ((length > 0 ? length : 1) <= *lengthp)
-        {
-          memcpy (resultbuf, result, length);
-          free (result);
-          result = resultbuf;
-        }
-      else
-        {
-          char *memory = (char *) realloc (result, length > 0 ? length : 1);
-          if (memory != NULL)
-            result = memory;
-        }
-    }
-
-  s[n] = orig_sentinel;
-  *lengthp = length;
-  return result;
-
- fail:
-  {
-    int saved_errno = errno;
-    if (result != resultbuf)
-      free (result);
-    s[n] = orig_sentinel;
-    errno = saved_errno;
-    return NULL;
-  }
-
- out_of_memory_1:
-  if (result != resultbuf)
-    free (result);
-  s[n] = orig_sentinel;
- out_of_memory_2:
-  errno = ENOMEM;
-  return NULL;
-}
diff --git a/lib/memxfrm.h b/lib/memxfrm.h
deleted file mode 100644 (file)
index 8b7284a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Locale dependent memory area transformation for comparison.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-
-   This program is free software: you can redistribute it and/or modify it
-   under the terms of the GNU Lesser General Public License as published
-   by the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef MEMXFRM_H
-#define MEMXFRM_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Generalization of strxfrm() to strings with embedded NUL bytes.  */
-
-/* Transform the memory area [S..S+N-1] to a memory area, in such a way that
-   comparing (S1,N1) and (S2,N2) with memcoll() is equivalent to comparing
-   memxfrm(S1,N1) and memxfrm(S2,N2) with memcmp2().
-   The byte S[N] may be temporarily overwritten by this function, but will be
-   restored before this function returns.
-   The result of this function depends on the LC_COLLATE category of the
-   current locale.
-   If successful: If resultbuf is not NULL and the result fits into *lengthp
-   bytes, it is put in resultbuf, and resultbuf is returned.  Otherwise, a
-   freshly allocated string is returned.  In both cases, *lengthp is set to the
-   length of the returned string.
-   Upon failure, return NULL, with errno set.  */
-extern char * memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* MEMXFRM_H */
index 5c7430c..b2725d4 100644 (file)
@@ -70,7 +70,7 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf,
     }
 
   /* Apply locale dependent transformations for comparison.  */
-  result = memxfrm (convs, convs_length, resultbuf, lengthp);
+  result = amemxfrm (convs, convs_length, resultbuf, lengthp);
   if (result == NULL)
     {
       if (convs != convsbuf)
index 661902f..63fe674 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u16_casexfrm
 #define UNIT uint16_t
index bd54497..c65df72 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u32_casexfrm
 #define UNIT uint32_t
index b3e0c66..cd6f45e 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u8_casexfrm
 #define UNIT uint8_t
index ce84ff6..1e0e53d 100644 (file)
@@ -69,7 +69,7 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf,
     }
 
   /* Apply locale dependent transformations for comparison.  */
-  result = memxfrm (convs, convs_length, resultbuf, lengthp);
+  result = amemxfrm (convs, convs_length, resultbuf, lengthp);
   if (result == NULL)
     {
       if (convs != convsbuf)
index 41d274a..d4af5ee 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u16_normxfrm
 #define UNIT uint16_t
index 7e953f9..0d1629d 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u32_normxfrm
 #define UNIT uint32_t
index 47d4fdc..2564f1c 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "localcharset.h"
 #include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
 
 #define FUNC u8_normxfrm
 #define UNIT uint8_t
diff --git a/modules/amemxfrm b/modules/amemxfrm
new file mode 100644 (file)
index 0000000..a5fb244
--- /dev/null
@@ -0,0 +1,22 @@
+Description:
+Locale dependent memory area transformation for comparison.
+
+Files:
+lib/amemxfrm.h
+lib/amemxfrm.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += amemxfrm.c
+
+Include:
+"amemxfrm.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/modules/memxfrm b/modules/memxfrm
deleted file mode 100644 (file)
index 8c9033c..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-Description:
-Locale dependent memory area transformation for comparison.
-
-Files:
-lib/memxfrm.h
-lib/memxfrm.c
-
-Depends-on:
-
-configure.ac:
-
-Makefile.am:
-lib_SOURCES += memxfrm.c
-
-Include:
-"memxfrm.h"
-
-License:
-LGPL
-
-Maintainer:
-Bruno Haible
index 78774e2..a79d163 100644 (file)
@@ -11,7 +11,7 @@ unicase/base
 unicase/u16-casefold
 uniconv/u16-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u16-casexfrm])
index 6fb660e..0f86654 100644 (file)
@@ -11,7 +11,7 @@ unicase/base
 unicase/u32-casefold
 uniconv/u32-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u32-casexfrm])
index 968dd59..bc02912 100644 (file)
@@ -11,7 +11,7 @@ unicase/base
 unicase/u8-casefold
 uniconv/u8-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u8-casexfrm])
index 9305b55..82ba01e 100644 (file)
@@ -10,7 +10,7 @@ uninorm/base
 uninorm/u16-normalize
 uniconv/u16-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9], [uninorm/u16-normxfrm])
index 9cb0641..8e4635b 100644 (file)
@@ -10,7 +10,7 @@ uninorm/base
 uninorm/u32-normalize
 uniconv/u32-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9], [uninorm/u32-normxfrm])
index 123d1a7..4c90b8c 100644 (file)
@@ -10,7 +10,7 @@ uninorm/base
 uninorm/u8-normalize
 uniconv/u8-conv-to-enc
 localcharset
-memxfrm
+amemxfrm
 
 configure.ac:
 gl_LIBUNISTRING_MODULE([0.9], [uninorm/u8-normxfrm])