diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2023-03-16 13:52:21 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2023-03-16 15:45:37 +0300 |
commit | 585e7f9891d68cf14a5fdce70e1f1c613c98bb94 (patch) | |
tree | ae4fbd61efd76e3a96a2f018c9030ebd51b3d9b1 /winsup/cygwin | |
parent | 988c304ec253958759658d0bf5d03a36e6971b94 (diff) |
Cygwin: regex: convert wchar_t to wint_t throughout
...and use __wcollate_range_cmp. This will have to be tweaked further
when supporting collation symbols...
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/regex/engine.c | 2 | ||||
-rw-r--r-- | winsup/cygwin/regex/regcomp.c | 30 | ||||
-rw-r--r-- | winsup/cygwin/regex/regexec.c | 4 |
3 files changed, 21 insertions, 15 deletions
diff --git a/winsup/cygwin/regex/engine.c b/winsup/cygwin/regex/engine.c index bb40018c0..77e7007bb 100644 --- a/winsup/cygwin/regex/engine.c +++ b/winsup/cygwin/regex/engine.c @@ -170,7 +170,7 @@ stepback(const char *start, const char *cur, int nchar) if ((ret - mbc) < start) return (NULL); memset(&mbs, 0, sizeof(mbs)); - clen = mbrtowc(NULL, ret - mbc, mbc, &mbs); + clen = mbrtowi(NULL, ret - mbc, mbc, &mbs); if (clen != (size_t)-1 && clen != (size_t)-2) break; } diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c index 7e9f5a50f..3c7359310 100644 --- a/winsup/cygwin/regex/regcomp.c +++ b/winsup/cygwin/regex/regcomp.c @@ -57,7 +57,13 @@ __FBSDID("$FreeBSD$"); #include <wchar.h> #include <wctype.h> -#ifndef LIBREGEX +/* We want the extensions implemented with LIBREGEX... */ +#ifdef __CYGWIN__ +#define LIBREGEX +#endif + +/* ...but we also want to use the collation functions from nlsfuncs.cc. */ +#if 1//ndef LIBREGEX #include "collate.h" #endif @@ -131,7 +137,7 @@ static void p_re(struct parse *p, int end1, int end2); static bool p_simp_re(struct parse *p, struct branchc *bc); static int p_count(struct parse *p); static void p_bracket(struct parse *p); -static int p_range_cmp(wchar_t c1, wchar_t c2); +static int p_range_cmp(wint_t c1, wint_t c2); static void p_b_term(struct parse *p, cset *cs); static int p_b_pseudoclass(struct parse *p, char c); static void p_b_cclass(struct parse *p, cset *cs); @@ -1058,13 +1064,13 @@ p_bracket(struct parse *p) } static int -p_range_cmp(wchar_t c1, wchar_t c2) +p_range_cmp(wint_t c1, wint_t c2) { -#ifndef LIBREGEX +#if 1//ndef LIBREGEX return __wcollate_range_cmp(c1, c2); #else /* Copied from libc/collate __wcollate_range_cmp */ - wchar_t s1[2], s2[2]; + wint_t s1[2], s2[2]; s1[0] = c1; s1[1] = L'\0'; @@ -1272,7 +1278,7 @@ p_b_coll_elem(struct parse *p, const char *sp = p->next; struct cname *cp; mbstate_t mbs; - wchar_t wc; + wint_t wc; size_t clen, len; while (MORE() && !SEETWO(endc, ']')) @@ -1286,7 +1292,7 @@ p_b_coll_elem(struct parse *p, if (strncmp(cp->name, sp, len) == 0 && strlen(cp->name) == len) return(cp->code); /* known name */ memset(&mbs, 0, sizeof(mbs)); - if ((clen = mbrtowc(&wc, sp, len, &mbs)) == len) + if ((clen = mbrtowi(&wc, sp, len, &mbs)) == len) return (wc); /* single character */ else if (clen == (size_t)-1 || clen == (size_t)-2) SETERROR(REG_ILLSEQ); @@ -1378,7 +1384,7 @@ bothcases(struct parse *p, wint_t ch) assert(othercase(ch) != ch); /* p_bracket() would recurse */ p->next = bracket; memset(&mbs, 0, sizeof(mbs)); - n = wcrtomb(bracket, ch, &mbs); + n = wirtomb(bracket, ch, &mbs); assert(n != (size_t)-1); bracket[n] = ']'; bracket[n + 1] = '\0'; @@ -1519,11 +1525,11 @@ static wint_t wgetnext(struct parse *p) { mbstate_t mbs; - wchar_t wc; + wint_t wc; size_t n; memset(&mbs, 0, sizeof(mbs)); - n = mbrtowc(&wc, p->next, p->end - p->next, &mbs); + n = mbrtowi(&wc, p->next, p->end - p->next, &mbs); if (n == (size_t)-1 || n == (size_t)-2) { SETERROR(REG_ILLSEQ); return (0); @@ -1871,7 +1877,7 @@ findmust(struct parse *p, struct re_guts *g) memset(&mbs, 0, sizeof(mbs)); newstart = scan - 1; } - clen = wcrtomb(buf, OPND(s), &mbs); + clen = wirtomb(buf, OPND(s), &mbs); if (clen == (size_t)-1) goto toohard; newlen += clen; @@ -1994,7 +2000,7 @@ findmust(struct parse *p, struct re_guts *g) while (cp < g->must + g->mlen) { while (OP(s = *scan++) != OCHAR) continue; - clen = wcrtomb(cp, OPND(s), &mbs); + clen = wirtomb(cp, OPND(s), &mbs); assert(clen != (size_t)-1); cp += clen; } diff --git a/winsup/cygwin/regex/regexec.c b/winsup/cygwin/regex/regexec.c index d7aa46f45..52d365a48 100644 --- a/winsup/cygwin/regex/regexec.c +++ b/winsup/cygwin/regex/regexec.c @@ -67,9 +67,9 @@ static __inline size_t xmbrtowc(wint_t *wi, const char *s, size_t n, mbstate_t *mbs, wint_t dummy) { size_t nr; - wchar_t wc; + wint_t wc; - nr = mbrtowc(&wc, s, n, mbs); + nr = mbrtowi(&wc, s, n, mbs); if (wi != NULL) *wi = wc; if (nr == 0) |