[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
regex.c question, plus patch
From: |
Jim Meyering |
Subject: |
regex.c question, plus patch |
Date: |
Wed, 21 Nov 2001 14:14:28 +0100 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.1.50 (i686-pc-linux-gnu) |
Hi Uli,
In looking at some of the recent regex.c changes, I saw code
like this:
----------------------------------
#ifdef _LIBC
consumed = __mbrtowc (pdest, psrc, mb_remain, &mbs);
#else
consumed = mbrtowc (pdest, psrc, mb_remain, &mbs);
#endif
----------------------------------
# ifdef _LIBC
if (__iswctype((wint_t)c, wctype))
goto char_set_matched;
# else
if (iswctype((wint_t)c, wctype))
goto char_set_matched;
# endif
----------------------------------
# ifdef _LIBC
if (__iswctype (__btowc (ch), wt))
SET_LIST_BIT (ch);
# else
if (iswctype (btowc (ch), wt))
SET_LIST_BIT (ch);
# endif
----------------------------------
Since the above seem to be the only uses of mbrtowc, and iswctype,
and since the if/else branches seem otherwise identical,
do you know why they're not written without #ifdef directives?
Note that __btowc is already defined.
# ifdef _LIBC
...
# define btowc __btowc
Wouldn't it be enough to add these
# define iswctype __iswctype
# define mbrtowc __mbrtowc
and remove the __-using variants?
While fixing those, I found three more.
Here's a patch.
=============================================================================
2001-11-21 Jim Meyering <address@hidden>
* posix/regex.c (iswctype, mbrtowc, wcslen, wcscoll, wcrtomb) [_LIBC]:
Define to be __-prefixed.
Remove unnecessary duplication in `#ifdef _LIBC' blocks.
--- regex.c.~3~ Sun Nov 18 05:41:17 2001
+++ regex.c Wed Nov 21 11:57:48 2001
@@ -82,6 +82,11 @@
# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
# define btowc __btowc
+# define iswctype __iswctype
+# define mbrtowc __mbrtowc
+# define wcslen __wcslen
+# define wcscoll __wcscoll
+# define wcrtomb __wcrtomb
/* We are also using some library internals. */
# include <locale/localeinfo.h>
@@ -1283,11 +1288,7 @@ convert_mbs_to_wcs (dest, src, len, offs
for( ; mb_remain > 0 ; ++wc_count, ++pdest, mb_remain -= consumed,
psrc += consumed)
{
-#ifdef _LIBC
- consumed = __mbrtowc (pdest, psrc, mb_remain, &mbs);
-#else
consumed = mbrtowc (pdest, psrc, mb_remain, &mbs);
-#endif
if (consumed <= 0)
/* failed to convert. maybe src contains binary data.
@@ -3308,13 +3309,8 @@ PREFIX(regex_compile) (ARG_PREFIX(patter
for (ch = 0; ch < 1 << BYTEWIDTH; ++ch)
{
-# ifdef _LIBC
- if (__iswctype (__btowc (ch), wt))
- SET_LIST_BIT (ch);
-# else
if (iswctype (btowc (ch), wt))
SET_LIST_BIT (ch);
-# endif
if (translate && (is_upper || is_lower)
&& (ISUPPER (ch) || ISLOWER (ch)))
@@ -4630,11 +4626,7 @@ truncate_wchar (c)
mbstate_t state;
int retval;
memset (&state, '\0', sizeof (state));
-# ifdef _LIBC
- retval = __wcrtomb (buf, c, &state);
-# else
retval = wcrtomb (buf, c, &state);
-# endif
return retval > 0 ? buf[0] : (unsigned char) c;
}
#endif /* WCHAR */
@@ -6434,13 +6426,8 @@ byte_re_match_2_internal (bufp, string1,
& ~(uintptr_t)(__alignof__(wctype_t) - 1);
wctype = *((wctype_t*)alignedp);
workp += CHAR_CLASS_SIZE;
-# ifdef _LIBC
- if (__iswctype((wint_t)c, wctype))
- goto char_set_matched;
-# else
if (iswctype((wint_t)c, wctype))
goto char_set_matched;
-# endif
}
/* match with collating_symbol? */
@@ -6476,20 +6463,12 @@ byte_re_match_2_internal (bufp, string1,
for (workp2 = workp + coll_symbol_length ; workp < workp2 ;)
{
const CHAR_T *backup_d = d, *backup_dend = dend;
-# ifdef _LIBC
- length = __wcslen (workp);
-# else
length = wcslen (workp);
-# endif
/* If wcscoll(the collating symbol, whole string) > 0,
any substring of the string never match with the
collating symbol. */
-# ifdef _LIBC
- if (__wcscoll (workp, d) > 0)
-# else
if (wcscoll (workp, d) > 0)
-# endif
{
workp += length + 1;
continue;
@@ -6514,11 +6493,7 @@ byte_re_match_2_internal (bufp, string1,
str_buf[i] = TRANSLATE(*d);
str_buf[i+1] = '\0';
-# ifdef _LIBC
- match = __wcscoll (workp, str_buf);
-# else
match = wcscoll (workp, str_buf);
-# endif
if (match == 0)
goto char_set_matched;
@@ -6629,20 +6604,12 @@ byte_re_match_2_internal (bufp, string1,
for (workp2 = workp + equiv_class_length ; workp < workp2 ;)
{
const CHAR_T *backup_d = d, *backup_dend = dend;
-# ifdef _LIBC
- length = __wcslen (workp);
-# else
length = wcslen (workp);
-# endif
/* If wcscoll(the collating symbol, whole string) > 0,
any substring of the string never match with the
collating symbol. */
-# ifdef _LIBC
- if (__wcscoll (workp, d) > 0)
-# else
if (wcscoll (workp, d) > 0)
-# endif
{
workp += length + 1;
break;
@@ -6667,11 +6634,7 @@ byte_re_match_2_internal (bufp, string1,
str_buf[i] = TRANSLATE(*d);
str_buf[i+1] = '\0';
-# ifdef _LIBC
- match = __wcscoll (workp, str_buf);
-# else
match = wcscoll (workp, str_buf);
-# endif
if (match == 0)
goto char_set_matched;
@@ -6753,13 +6716,8 @@ byte_re_match_2_internal (bufp, string1,
range_end_char = str_buf + 4;
}
-# ifdef _LIBC
- if (__wcscoll (range_start_char, str_buf+2) <= 0
- && __wcscoll (str_buf+2, range_end_char) <= 0)
-# else
if (wcscoll (range_start_char, str_buf+2) <= 0
&& wcscoll (str_buf+2, range_end_char) <= 0)
-# endif
goto char_set_matched;
}
}
- regex.c question, plus patch,
Jim Meyering <=