zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk
Subject: Re: problems with 4.3.4 and Tru64
Date: Sun, 13 May 2007 21:12:52 +0100	[thread overview]
Message-ID: <20070513211252.4561b92b.p.w.stephenson@ntlworld.com> (raw)
In-Reply-To: <20070510123039.c36e16f2.pws@csr.com>

On Thu, 10 May 2007 12:30:39 +0100
Peter Stephenson <pws@csr.com> wrote:
> However, I think I've got somewhere with reproducing your original
> problem by using your locales:
> 
> LANG=C
> LC_COLLATE="C"
> LC_CTYPE=fi_FI.UTF-8
> LC_MONETARY="C"
> LC_NUMERIC="C"
> LC_TIME="C"
> LC_MESSAGES="C"
> LC_ALL=
> 
> This also fails to handle multibyte characters properly.
> (However, in my case the multibyte option is still set.)
> If I remove the LANG=C from that set, it starts working.  This
> is obviously a bug.

Unfortunately, this wasn't Timo's problem, but this fixes it anyway.

I'm assuming, at least, that setting one of the variables above to the
empty string should be equivalent to leaving it unset.  The rule for
setlocale() internally is that the empty string means "use the
environment variable", but that's meaninglessly self-referential here,
so I think the right thing to do is for the shell deliberately to let
the value of $LANG and (if appropriate) the LC_* categories show
through.

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.124
diff -u -r1.124 params.c
--- Src/params.c	13 Apr 2007 11:54:17 -0000	1.124
+++ Src/params.c	13 May 2007 20:07:31 -0000
@@ -3414,10 +3414,21 @@
 {
     struct localename *ln;
 
+    /*
+     * Set the global locale to the value passed, but override
+     * this with any non-empty definitions for specific
+     * categories.
+     *
+     * We only use non-empty definitions because empty values aren't
+     * valid as locales; when passed to setlocale() they mean "use the
+     * environment variable", but if that's what we're setting the value
+     * from this is meaningless.  So just all $LANG to show through in
+     * that case.
+     */
     setlocale(LC_ALL, x ? x : "");
     queue_signals();
     for (ln = lc_names; ln->name; ln++)
-	if ((x = getsparam(ln->name)))
+	if ((x = getsparam(ln->name)) && *x)
 	    setlocale(ln->category, x);
     unqueue_signals();
 }
@@ -3427,10 +3438,18 @@
 lc_allsetfn(Param pm, char *x)
 {
     strsetfn(pm, x);
-    if (!x) {
-	queue_signals();
-	setlang(getsparam("LANG"));
-	unqueue_signals();
+    /*
+     * Treat an empty LC_ALL the same as an unset one,
+     * namely by using LANG as the default locale but overriding
+     * that with any LC_* that are set.
+     */
+    if (!x || !*x) {
+	x = getsparam("LANG");
+	if (x && *x) {
+	    queue_signals();
+	    setlang(x);
+	    unqueue_signals();
+	}
     }
     else
 	setlocale(LC_ALL, x);
@@ -3448,18 +3467,27 @@
 void
 lcsetfn(Param pm, char *x)
 {
+    char *x2;
     struct localename *ln;
 
     strsetfn(pm, x);
-    if (getsparam("LC_ALL"))
+    if ((x2 = getsparam("LC_ALL")) && *x)
 	return;
     queue_signals();
-    if (!x)
+    /* Treat empty LC_* the same as unset. */
+    if (!x || !*x)
 	x = getsparam("LANG");
 
-    for (ln = lc_names; ln->name; ln++)
-	if (!strcmp(ln->name, pm->node.nam))
-	    setlocale(ln->category, x ? x : "");
+    /*
+     * If we've got no non-empty string at this
+     * point (after checking $LANG, too),
+     * we shouldn't bother setting anything.
+     */
+    if (x && *x) {
+	for (ln = lc_names; ln->name; ln++)
+	    if (!strcmp(ln->name, pm->node.nam))
+		setlocale(ln->category, x);
+    }
     unqueue_signals();
 }
 #endif /* USE_LOCALE */

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  parent reply	other threads:[~2007-05-13 20:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10  8:25 Timo Aaltonen
2007-05-10  9:55 ` Peter Stephenson
2007-05-10 10:05   ` Peter Stephenson
2007-05-10 10:06   ` Timo Aaltonen
2007-05-10 10:15     ` Timo Aaltonen
2007-05-10 10:30       ` Peter Stephenson
2007-05-10 11:03         ` Timo Aaltonen
2007-05-10 11:30           ` Peter Stephenson
2007-05-10 11:43             ` Timo Aaltonen
2007-05-10 11:55               ` Peter Stephenson
2007-05-10 13:05                 ` Timo Aaltonen
2007-05-10 13:35                   ` Peter Stephenson
2007-05-13 20:12             ` Peter Stephenson [this message]
2007-05-13 23:43               ` Wayne Davison
2007-05-10 17:55 ` Phil Pennock
2007-05-10 19:24   ` Timo Aaltonen
2007-05-10 22:26     ` Phil Pennock
2007-05-11  9:28       ` Peter Stephenson
2007-05-11 16:23         ` Jordan Breeding
2007-05-11 17:25           ` Jordan Breeding
2007-05-11 17:56             ` Peter Stephenson
2007-05-11 18:42               ` Jordan Breeding

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=20070513211252.4561b92b.p.w.stephenson@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /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).