From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 8C30D3858004; Wed, 15 Feb 2023 21:37:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C30D3858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676497075; bh=fgNGhd6Ofiuw2tM9OMSt/QKVN3HCzl9x6Mw28PeabqM=; h=From:To:Subject:Date:From; b=E5I5ZvcLmEGZCwmswDPqDR5tE5x2cu5iiyk9NGk9ZkVCYHXCdFdArCEme+BiYKX3n YVnWC0ffjp+94x4kE55VLddPm89xI2DOmniy2Cscj9ArpnRHqEN8Zk2DSVuCzHqv4i U9QW3fRzZb1ri2pyhV14431RV1GD226IUx7+VF5I= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: glob: handle equivalence class expressions X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 20162667de8c0029c974420230f2dcc903159e66 X-Git-Newrev: 1df19b3caeaee95388a3c4d78559389bbcfc9ad5 Message-Id: <20230215213755.8C30D3858004@sourceware.org> Date: Wed, 15 Feb 2023 21:37:55 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D1df19b3caea= ee95388a3c4d78559389bbcfc9ad5 commit 1df19b3caeaee95388a3c4d78559389bbcfc9ad5 Author: Corinna Vinschen AuthorDate: Wed Feb 15 22:34:46 2023 +0100 Commit: Corinna Vinschen CommitDate: Wed Feb 15 22:34:46 2023 +0100 Cygwin: glob: handle equivalence class expressions =20 Handle [=3Dx=3D] expressions in range brackets. Use the new is_unicode_equiv() function to perform the check. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/glob.cc | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index 1e8eda903e70..c882cd59d2e2 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -158,6 +158,7 @@ typedef char Char; #define M_RNG META('-') #define M_SET META('[') #define M_NAMED META(':') +#define M_EQUIV META('=3D') #define ismeta(c) (((c)&M_QUOTE) !=3D 0) =20 static int compare(const void *, const void *); @@ -186,7 +187,7 @@ static void qprintf(const char *, Char *); /* Return value is either EOS, COLON, DOT, EQUALS, or LBRACKET if no class expression found. */ static inline Char -check_classes_expr(const Char *&cptr, char *classbuf =3D NULL, +check_classes_expr(const Char *&cptr, wint_t *classbuf =3D NULL, size_t classbufsize =3D 0) { const Char *ctype =3D NULL; @@ -206,7 +207,7 @@ check_classes_expr(const Char *&cptr, char *classbuf = =3D NULL, =20 if (clen < classbufsize) { for (idx =3D 0; idx < clen; ++idx) - classbuf[idx] =3D class_p[idx]; + classbuf[idx] =3D CHAR(class_p[idx]); classbuf[idx] =3D '\0'; } else ctype =3D NULL; @@ -480,6 +481,11 @@ globtilde(const Char *pattern, Char *patbuf, size_t pa= tbuf_len, glob_t *pglob) return patbuf; } =20 +static void +wcitoascii(char *dst, wint_t *src) +{ + while ((*dst++ =3D *src++)); +} =20 /* * The main glob() routine: compiles the pattern (optionally processing @@ -523,19 +529,30 @@ glob0(const Char *pattern, glob_t *pglob, size_t *lim= it) *bufnext++ =3D M_NOT; c =3D *qpatnext; do { - char cclass[64]; - wctype_t type; + wint_t wclass[64]; Char ctype; =20 - ctype =3D check_classes_expr(qpatnext, cclass, - sizeof cclass); + ctype =3D check_classes_expr(qpatnext, wclass, + 64); if (ctype) { - if (ctype =3D=3D COLON && - (type =3D wctype (cclass))) { - *bufnext++ =3D M_NAMED; - *bufnext++ =3D CHAR (type); + wctype_t type; + + if (ctype =3D=3D COLON) { + char cclass[64]; + + /* No worries, char classes are + ASCII-only anyway */ + wcitoascii (cclass, wclass); + if ((type =3D wctype (cclass))) { + *bufnext++ =3D M_NAMED; + *bufnext++ =3D CHAR (type); + } + } else if (ctype =3D=3D EQUALS && + wclass[0] && !wclass[1]) { + *bufnext++ =3D M_EQUIV; + *bufnext++ =3D CHAR (wclass[0]); } - /* TODO: [. and [=3D are ignored yet */ + /* TODO: [. is ignored yet */ qpatnext++; continue; } @@ -858,6 +875,9 @@ match(Char *name, Char *pat, Char *patend) if ((c & M_MASK) =3D=3D M_NAMED) { if (iswctype (k, *pat++)) ok =3D 1; + } else if ((c & M_MASK) =3D=3D M_EQUIV) { + if (is_unicode_equiv (k, *pat++)) + ok =3D 1; } else if ((*pat & M_MASK) =3D=3D M_RNG) { if (__collate_load_error ? CCHAR(c) <=3D CCHAR(k) && CCHAR(k) <=3D CCHAR(pat[1]) :