Subject: Re: bug#15608: kbd.scm unicode problem

From: [email-masked] (Ludovic Courtès)
Date: Wed, 16 Oct 2013 15:32:37 +0200

"Guy Ze Grant" <[email-masked]> skribis:

> I was asked to post here, so here it is; Attached is my expression thus
> far for kbd, at the patch phase though -- the following issue pops up:
> "find-files: ./doc/utf/??????: No such file or directory", along with a
> spew of guile barf following (which you can see in the kbd.scm.log file).

As we discussed on IRC, the problem is that POSIX considers file names
to be just byte strings, and the encoding is up to the application, and
locale-dependent by default.  In practice people typically use UTF-8
(GLib and friends expect that.)

Here’s the problem and fix:

--8<---------------cut here---------------start------------->8---
$ echo $LANG
en_US.UTF-8

$ ls -a
.  ..  ♪♬

$ guile -c '(use-modules (ice-9 ftw)) (pk (scandir "."))'

;;; (("." ".." "??????"))

$ guile -c '(use-modules (ice-9 ftw)) (setlocale LC_ALL "en_US.utf8") (pk (scandir "."))'

;;; (("." ".." "♪♬"))
--8<---------------cut here---------------end--------------->8---

In the first run Guile uses the “C” locale, so it’s unable to decode “♪♬”.

In the second run it uses a UTF-8 locale, so everything works fine.

Back to kbd: can you add a phase after the ‘unpack’ phase that just
does this?

  (setlocale "LC_ALL" "en_US.utf8")

If that works we can probably make it the default in the ‘core-updates’
branch.

> (define-module (gnu packages kbd)

Since kbd is Linux-specific, could you put it in (gnu packages linux)?

[...]

>  102: 1 [patch-source-shebangs # ...]
> In unknown file:
>    ?: 0 [sort # #<procedure string<? (#:optional _ _ . _)>]
>
> ERROR: In procedure sort:
> ERROR: In procedure list-copy: Wrong type argument in position 1: ("./config/ylwrap" "./config/install-sh" "./config/depcomp" "./config/config.sub" "./config/config.rpath" "./config/missing" "./config/config.guess" "./config/mkinstalldirs" "./config/compile" "./
[...]
> " "./doc/utf/README" "./doc/utf/ethiopic" . #f)

It’s also a bug that ‘find-files’ returns a improper list when
encountering such an issue.  I’ll fit it in ‘core-updates’.

Thanks,
Ludo’.