public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: regex: convert wchar_t to wint_t throughout
@ 2023-03-16 12:54 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-03-16 12:54 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=585e7f9891d68cf14a5fdce70e1f1c613c98bb94
commit 585e7f9891d68cf14a5fdce70e1f1c613c98bb94
Author: Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Thu Mar 16 11:52:21 2023 +0100
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Thu Mar 16 13:45:37 2023 +0100
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>
Diff:
---
winsup/cygwin/regex/engine.c | 2 +-
winsup/cygwin/regex/regcomp.c | 30 ++++++++++++++++++------------
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 bb40018c07e1..77e7007bb1fa 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 7e9f5a50f21a..3c735931040f 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 d7aa46f45b2b..52d365a481c3 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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-16 12:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 12:54 [newlib-cygwin/main] Cygwin: regex: convert wchar_t to wint_t throughout Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).