From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 3A2BF3858D28; Mon, 24 Apr 2023 20:42:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A2BF3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682368932; bh=8bKOMTT0riwJyhIg5lQ1rZlDM/zYY5G3+QoBkOHgrOE=; h=From:To:Subject:Date:From; b=I8sUu2PKjrKl9f5UQlCeEtNeXiMCg7Ph1Gh0/esfJX2RD7HZ1pNDSnnqHDH1ID3FF W/NDG3gAkDCj2bRU/4LtxPbAoNU5+TtYJih9Kg5gToscO0nshgswaPF6T7Kni1yi6r SVpSbiI28GEGD7vfLb9bt/MdoE+1wEKapaA9aEF4= 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: locales: ignore @cjkwide and @cjksingle just like @cjknarrow X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: fd26d4b4b6bc84af57caeef81f913707b5d9c0d2 X-Git-Newrev: 48ae24fd8159109077b71d41e528e08b325ded1f Message-Id: <20230424204212.3A2BF3858D28@sourceware.org> Date: Mon, 24 Apr 2023 20:42:12 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D48ae24fd815= 9109077b71d41e528e08b325ded1f commit 48ae24fd8159109077b71d41e528e08b325ded1f Author: Corinna Vinschen AuthorDate: Mon Apr 24 22:40:00 2023 +0200 Commit: Corinna Vinschen CommitDate: Mon Apr 24 22:41:41 2023 +0200 Cygwin: locales: ignore @cjkwide and @cjksingle just like @cjknarrow =20 When the @cjkwide and @cjksingle modifiers have been added, the patches missed to add checks for the new modifiers in the Cygwin locale code. Along the same lines, commit c3e7f7609e46 forgot to add a test for @cjksingle. =20 Merge check for cjk* modifiers into a macro set andf use that throughout. Fix comments. =20 Fixes: f92f048528e6f ("Locale modifier @cjkwide to adjust ambiguous-wid= th in non-CJK locales") Fixes: c8204b106988f ("Locale modifier "@cjksingle" to enforce single-w= idth CJK width.") Fixes: c3e7f7609e46 ("Cygwin: locales: fix behaviour for @cjk* and @eur= o locales") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/nlsfuncs.cc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc index b097a6e5fa0a..7d17b1069e39 100644 --- a/winsup/cygwin/nlsfuncs.cc +++ b/winsup/cygwin/nlsfuncs.cc @@ -39,6 +39,18 @@ details. */ =20 #define has_modifier(x) ((x)[0] && !strcmp (modifier, (x))) =20 +/* Check for @cjk* modifier. Try to be as fast as possible */ +#define __is_cjk_modifier(_in, _cmp, _L) ({ \ + _in[1] =3D=3D 'c' \ + && _in[2] =3D=3D 'j' \ + && _in[3] =3D=3D 'k'\ + && (_cmp (_in + 4, _L##"narrow") =3D=3D 0 \ + || _cmp (_in + 4, _L##"wide") =3D=3D 0 \ + || _cmp (_in + 4, _L##"single") =3D=3D 0); \ +}) +#define is_cjk_modifier(_in) __is_cjk_modifier(_in, strcmp, ) +#define w_is_cjk_modifier(_in) __is_cjk_modifier(_in, wcscmp, L) + /* ResolveLocaleName does not what we want. It converts anything which vaguely resembles a locale into some other locale it supports. Bad examples are: "en-XY" gets converted to "en-US", and worse, "ff-BF" gets @@ -532,9 +544,8 @@ __set_lc_time_from_win (const char *name, { *c =3D '\0'; char *c2 =3D strchr (c + 1, '@'); - /* Ignore @cjknarrow modifier since it's a very personal thing between - Cygwin and newlib... */ - if (c2 && strcmp (c2, "@cjknarrow")) + /* Ignore @cjk* modifiers, they are newlib specials. */ + if (c2 && !is_cjk_modifier (c2)) memmove (c, c2, strlen (c2) + 1); } /* Now search in the alphabetically order lc_era array for the @@ -1075,9 +1086,8 @@ __set_lc_messages_from_win (const char *name, { *c =3D '\0'; c2 =3D strchr (c + 1, '@'); - /* Ignore @cjknarrow modifier since it's a very personal thing between - Cygwin and newlib... */ - if (c2 && strcmp (c2, "@cjknarrow")) + /* Ignore @cjk* modifiers, they are newlib specials. */ + if (c2 && !is_cjk_modifier (c2)) memmove (c, c2, strlen (c2) + 1); } /* Now search in the alphabetically order lc_msg array for the @@ -1537,11 +1547,9 @@ __set_charset_from_locale (const char *loc, char *ch= arset) modifier =3D strchr (loc, '@'); if ((c =3D strchr (locale, '.'))) stpcpy (c, modifier ?: ""); - /* Cut out @cjknarrow/@cjkwide modifier, both are newlib specials and - don't affect the codeset. */ + /* Ignore @cjk* modifiers, they are newlib specials. */ modifier =3D strchr (locale, '@'); - if (modifier && (!strcmp (modifier + 1, "cjknarrow") - || !strcmp (modifier + 1, "cjkwide"))) + if (modifier && is_cjk_modifier (modifier)) *modifier =3D '\0'; =20 default_codeset_t srch_dc =3D { locale, NULL }; @@ -1702,9 +1710,9 @@ __set_locale_from_locale_alias (const char *locale, c= har *new_locale) if (mbstowcs (wlocale, locale, ENCODING_LEN + 1) =3D=3D (size_t) -1) sys_mbstowcs (wlocale, ENCODING_LEN + 1, locale); wlocale[ENCODING_LEN] =3D L'\0'; - /* Ignore @cjknarrow modifier since it's a very personal thing between - Cygwin and newlib... */ - if ((wc =3D wcschr (wlocale, L'@')) && !wcscmp (wc + 1, L"cjknarrow")) + /* Ignore @cjk* modifiers, they are newlib specials. */ + wc =3D wcschr (wlocale, L'@'); + if (wc && w_is_cjk_modifier (wc)) *wc =3D L'\0'; while (fgets (alias_buf, LOCALE_ALIAS_LINE_LEN + 1, fp)) {