guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing the environment's locale encoding settings


From: Mark H Weaver
Subject: Re: Accessing the environment's locale encoding settings
Date: Thu, 24 Nov 2011 21:11:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux)

address@hidden (Ludovic Courtès) writes:
> It’s not completely satisfying either because --locale is not in
> 2.0.[0-3], so users who really need it will need some configury;
> furthermore, from 2.2.x on, it will be mostly unneeded.
>
> Yet, a choice has to be made between this hack and the other one.  :-)
>
> Thoughts?

I like the --locale argument, except that the default (if there is no
--locale argument) should be to either (A) call setlocale(LC_ALL, "") or
(B) do something like the other hack, where the arguments are decoded as
if the locale had been temporarily set according to the environment
variables.

My strong preference would be Option A.

If you are trying to maintain backward compatibility, keep in mind that
for most practical purposes, Guile 1.8 acts closer to option A than the
other options.  Furthermore, Option A is the Right Thing moving forward,
and matches what Guile 2.2 will do.

If we accept only ASCII arguments by default, then _most_ Guile scripts
will need to add the --locale argument, but only for versions after
2.0.3.  More likely, many authors won't bother with this ugliness, and
their scripts will be broken for non-ASCII locales.

If we choose option A, then 2.0.[0123] simply have a bug that was fixed
in 2.0.4, and apart from those versions, things will mostly work the
right way by default, and fairly close to how Guile 1.8 worked.

Also, I see a problem with your code:

> @@ -376,6 +386,22 @@ scm_shell_usage (int fatal, char *messag
>  SCM
>  scm_compile_shell_switches (int argc, char **argv)
>  {
> +  int i;
> +
> +  for (i = 0; i < argc && !terminating_argument (argv[i]); i++)
> +    {
> +      if (strncmp (argv[i], "--locale", sizeof "--locale") == 0)

(sizeof "--locale") is 9, not 8.  It includes the NULL terminator, so
this test will not recognize "--locale=...", as you apparently intended
based on the code that follows.

    Best,
     Mark


> +     {
> +       const char *equal;
> +
> +       equal = strchr (argv[i], '=');
> +       if (equal != NULL)
> +         setlocale (LC_ALL, &argv[i][equal + 1]);
> +       else
> +         setlocale (LC_ALL, "");
> +     }
> +    }
> +
>    return scm_call_2 (scm_c_public_ref ("ice-9 command-line",
>                                         "compile-shell-switches"),
>                       scm_makfromstrs (argc, argv),



reply via email to

[Prev in Thread] Current Thread [Next in Thread]