Mercurial > hg > octave-lyh > gnulib-hg
changeset 13557:8db1bc2a38a3
Rename module 'memxfrm' to 'amemxfrm'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 15 Aug 2010 00:42:00 +0200 |
parents | a82579362064 |
children | 263949fe34ae |
files | ChangeLog MODULES.html.sh NEWS lib/amemxfrm.c lib/amemxfrm.h lib/memxfrm.c lib/memxfrm.h 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 modules/memxfrm modules/unicase/u16-casexfrm modules/unicase/u32-casexfrm modules/unicase/u8-casexfrm modules/uninorm/u16-normxfrm modules/uninorm/u32-normxfrm modules/uninorm/u8-normxfrm |
diffstat | 23 files changed, 296 insertions(+), 265 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +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'.
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1778,7 +1778,7 @@ 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
--- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ 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.
new file mode 100644 --- /dev/null +++ b/lib/amemxfrm.c @@ -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; +}
new file mode 100644 --- /dev/null +++ b/lib/amemxfrm.h @@ -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 */
deleted file mode 100644 --- a/lib/memxfrm.c +++ /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; -}
deleted file mode 100644 --- a/lib/memxfrm.h +++ /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 */
--- a/lib/unicase/u-casexfrm.h +++ b/lib/unicase/u-casexfrm.h @@ -70,7 +70,7 @@ } /* 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)
--- a/lib/unicase/u16-casexfrm.c +++ b/lib/unicase/u16-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u16_casexfrm #define UNIT uint16_t
--- a/lib/unicase/u32-casexfrm.c +++ b/lib/unicase/u32-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u32_casexfrm #define UNIT uint32_t
--- a/lib/unicase/u8-casexfrm.c +++ b/lib/unicase/u8-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u8_casexfrm #define UNIT uint8_t
--- a/lib/uninorm/u-normxfrm.h +++ b/lib/uninorm/u-normxfrm.h @@ -69,7 +69,7 @@ } /* 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)
--- a/lib/uninorm/u16-normxfrm.c +++ b/lib/uninorm/u16-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u16_normxfrm #define UNIT uint16_t
--- a/lib/uninorm/u32-normxfrm.c +++ b/lib/uninorm/u32-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u32_normxfrm #define UNIT uint32_t
--- a/lib/uninorm/u8-normxfrm.c +++ b/lib/uninorm/u8-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u8_normxfrm #define UNIT uint8_t
new file mode 100644 --- /dev/null +++ b/modules/amemxfrm @@ -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
deleted file mode 100644 --- a/modules/memxfrm +++ /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
--- a/modules/unicase/u16-casexfrm +++ b/modules/unicase/u16-casexfrm @@ -11,7 +11,7 @@ unicase/u16-casefold uniconv/u16-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u16-casexfrm])
--- a/modules/unicase/u32-casexfrm +++ b/modules/unicase/u32-casexfrm @@ -11,7 +11,7 @@ unicase/u32-casefold uniconv/u32-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u32-casexfrm])
--- a/modules/unicase/u8-casexfrm +++ b/modules/unicase/u8-casexfrm @@ -11,7 +11,7 @@ unicase/u8-casefold uniconv/u8-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u8-casexfrm])
--- a/modules/uninorm/u16-normxfrm +++ b/modules/uninorm/u16-normxfrm @@ -10,7 +10,7 @@ uninorm/u16-normalize uniconv/u16-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9], [uninorm/u16-normxfrm])