From: Kwon Yeolhyun <yeolhyunkwon@me.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
"Jun T." <takimoto-j@kba.biglobe.ne.jp>
Cc: Zsh List Hackers' <zsh-workers@zsh.org>
Subject: Re: Unicode, Korean, normalization form, Mac OS X and tab completion
Date: Mon, 02 Jun 2014 20:58:24 +0900 [thread overview]
Message-ID: <D462A2B9-D41B-4A87-9A8B-D8F2340C4B8E@me.com> (raw)
In-Reply-To: <140601125323.ZM9969@torch.brasslantern.com>
[-- Attachment #1: Type: text/plain, Size: 2211 bytes --]
On Jun 2, 2014, at 4:53 AM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jun 2, 2:00am, Jun T. wrote:
> } Subject: Re: Unicode, Korean, normalization form, Mac OS X and tab complet
> }
> } There is a patch by a Japanese user which simply converts
> } file names obtained by readder() into the composed form ("NFC")
>
> I tried this and found a couple of problems, mainly that iconv() can
> return >= 0 but do nothing if the input has no convertible characters.
> Here is my suggested correction, also eliminates unnecessary temp_name:
>
> diff --git a/Src/utils.c b/Src/utils.c
> index 9439227..8b512bb 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -4270,6 +4270,12 @@ mod_export char *
> zreaddir(DIR *dir, int ignoredots)
> {
> struct dirent *de;
> +#if defined(HAVE_ICONV) && defined(__APPLE__)
> + static iconv_t conv_ds = (iconv_t)0;
> + static char *conv_name = 0;
> + char *conv_name_ptr, *orig_name_ptr;
> + size_t conv_name_len, orig_name_len;
> +#endif
>
> do {
> de = readdir(dir);
> @@ -4278,6 +4284,31 @@ zreaddir(DIR *dir, int ignoredots)
> } while(ignoredots && de->d_name[0] == '.' &&
> (!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2])));
>
> +#if defined(HAVE_ICONV) && defined(__APPLE__)
> + if (!conv_ds)
> + conv_ds = iconv_open("UTF-8", "UTF-8-MAC");
> + if (conv_ds) {
> + /* Force initial state in case re-using conv_ds */
> + (void) iconv(conv_ds, 0, &orig_name_len, 0, &conv_name_len);
> +
> + orig_name_ptr = de->d_name;
> + orig_name_len = strlen(de->d_name);
> + conv_name = zrealloc(conv_name, orig_name_len+1);
> + conv_name_ptr = conv_name;
> + conv_name_len = orig_name_len;
> + if (iconv(conv_ds,
> + &orig_name_ptr, &orig_name_len,
> + &conv_name_ptr, &conv_name_len) >= 0) {
> + if (orig_name_len == 0) {
> + /* Completely converted, metafy and return */
> + *conv_name_ptr = '\0';
> + return metafy(conv_name, -1, META_STATIC);
> + }
> + }
> + /* Error, or conversion incomplete, keep the original name */
> + }
> +#endif
> +
> return metafy(de->d_name, -1, META_STATIC);
> }
>
The patch is working properly so far.
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 842 bytes --]
next prev parent reply other threads:[~2014-06-02 11:58 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-31 3:56 Kwon Yeolhyun
2014-05-31 15:21 ` Chet Ramey
2014-05-31 18:47 ` Bart Schaefer
2014-05-31 19:16 ` Peter Stephenson
2014-05-31 21:29 ` Bart Schaefer
2014-06-01 2:25 ` Daniel Shahaf
2014-06-01 5:30 ` Kwon Yeolhyun
2014-06-01 16:53 ` Daniel Shahaf
2014-06-01 7:56 ` Bart Schaefer
2014-06-01 16:46 ` Daniel Shahaf
2014-06-01 17:00 ` Jun T.
2014-06-01 19:13 ` Bart Schaefer
2014-06-02 17:01 ` Jun T.
2014-06-02 17:14 ` Bart Schaefer
2014-06-01 19:53 ` Bart Schaefer
2014-06-02 11:58 ` Kwon Yeolhyun [this message]
2014-06-02 14:23 ` Kwon Yeolhyun
2014-06-02 15:14 ` Bart Schaefer
2014-06-02 15:27 ` Peter Stephenson
2014-06-02 15:48 ` Kwon Yeolhyun
2014-06-02 15:27 ` Kwon Yeolhyun
2014-06-02 15:49 ` Bart Schaefer
2014-06-02 15:58 ` Kwon Yeolhyun
2014-06-02 14:31 ` Bart Schaefer
2014-06-02 17:15 ` Jun T.
2014-06-02 17:27 ` Bart Schaefer
2014-06-05 14:34 ` Jun T.
2014-06-05 15:00 ` Bart Schaefer
2014-06-02 5:17 ` Kwon Yeolhyun
2014-06-02 7:39 ` Jun T.
2014-06-02 8:42 ` Kwon Yeolhyun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D462A2B9-D41B-4A87-9A8B-D8F2340C4B8E@me.com \
--to=yeolhyunkwon@me.com \
--cc=schaefer@brasslantern.com \
--cc=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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 NNTP newsgroup(s).