Small change to correctly query the systems charset

Message ID 200705011712.19886.zzam@gentoo.org
State New
Headers

Commit Message

Matthias Schwarzott May 1, 2007, 3:12 p.m. UTC
  Hi there!

This patch just changes charset querying to not only look at environment 
variable LANG, but respect all in correct order. So now I can overwrite 
charset setting with LC_CTYPE and LC_ALL.

Greetings
Matthias
  

Comments

VDRU VDRU May 1, 2007, 3:45 p.m. UTC | #1
> This patch just changes charset querying to not only look at environment
> variable LANG, but respect all in correct order. So now I can overwrite
> charset setting with LC_CTYPE and LC_ALL.

Just curious, why would you need to query anything other than the
environment LANG variable?  If that tells you what the user wants to
use, there's no need to look any further.  Unless it's empty I guess?

Thanks.
  
Udo Richter May 3, 2007, 10:12 p.m. UTC | #2
VDR User wrote:
>> This patch just changes charset querying to not only look at environment
>> variable LANG, but respect all in correct order. So now I can overwrite
>> charset setting with LC_CTYPE and LC_ALL.
> 
> Just curious, why would you need to query anything other than the
> environment LANG variable?  If that tells you what the user wants to
> use, there's no need to look any further.  Unless it's empty I guess?

 From man 7 locale:
> If the second argument to setlocale() is  empty  string,  "",  for  the
> default locale, it is determined using the following steps:
> 
> 1.     If there is a non-null environment variable LC_ALL, the value of
>        LC_ALL is used.
> 2.     If an environment variable with the same name as one of the cat-
>        egories above exists and is non-null, its value is used for that
>        category.
> 3.     If there is a non-null environment variable LANG, the  value  of
>        LANG is used.

In other words, the locale system can be set in environment by three 
different ways, by setting LANG (lowest precedence), by setting specific 
language aspects (LC_CTYPE describes just character sets, not sorting, 
numeric notation, date notation etc), or by setting LC_ALL (highest 
precedence).

Even if LANG is set, it may not be valid, because other settings can 
override it. And not on all systems LANG is used to set the locale.

Cheers,

Udo
  
Klaus Schmidinger May 6, 2007, 9:50 a.m. UTC | #3
On 05/01/07 17:12, Matthias Schwarzott wrote:
> Hi there!
> 
> This patch just changes charset querying to not only look at environment 
> variable LANG, but respect all in correct order. So now I can overwrite 
> charset setting with LC_CTYPE and LC_ALL.
> 
> Greetings
> Matthias
> 
> 
> 
> ------------------------------------------------------------------------
> 
> diff -ru vdr-1.5.2-vanilla/vdr.c vdr-1.5.2/vdr.c
> --- vdr-1.5.2-vanilla/vdr.c	2007-05-01 17:04:45.000000000 +0200
> +++ vdr-1.5.2/vdr.c	2007-05-01 17:05:18.000000000 +0200
> @@ -493,7 +493,7 @@
>  
>    // Set the system character table:
>  
> -  char *LangEnv = getenv("LANG");
> +  char *LangEnv = setlocale(LC_CTYPE, "");
>    if (LangEnv) {
>       char *CodeSet = strchr(LangEnv, '.');
>       if (CodeSet) {
> 
> 
> ------------------------------------------------------------------------

If I make this change and run VDR with

export LANG=de_DE.iso8859-15

I get a NULL pointer from the setlocale(LC_CTYPE, "") call.
Only with

export LANG=de_DE.iso8859-1

do I get a non-NULL result.
Am I missing something here?

Klaus
  
Johannes Stezenbach May 6, 2007, 10:27 a.m. UTC | #4
On Sun, May 06, 2007 at 11:50:21AM +0200, Klaus Schmidinger wrote:
> If I make this change and run VDR with
> 
> export LANG=de_DE.iso8859-15
> 
> I get a NULL pointer from the setlocale(LC_CTYPE, "") call.
> Only with
> 
> export LANG=de_DE.iso8859-1
> 
> do I get a non-NULL result.
> Am I missing something here?

Maybe you don't have the locale files for iso8859-15 installed?
(At least in Debian you can choose to install only a subset of
the glibc locale files.)


HTH,
Johannes
  
Michael Mauch May 6, 2007, 10:48 a.m. UTC | #5
Klaus Schmidinger wrote:

> If I make this change and run VDR with
> 
> export LANG=de_DE.iso8859-15
> 
> I get a NULL pointer from the setlocale(LC_CTYPE, "") call.
> Only with
> 
> export LANG=de_DE.iso8859-1
> 
> do I get a non-NULL result.
> Am I missing something here?

Do you have a de_DE.iso8859-15 installed? It's called de_DE@euro here
(yes, that naming is "a bit" strange).

You can check with "locale -a | grep de" to find the installed locales
for "de". If no suitable locale is there, you can use locale-gen (at
least on Debian and Gentoo) or localedef to install the missing locale.

Regards...
		Michael
  
Klaus Schmidinger Aug. 12, 2007, 1 p.m. UTC | #6
On 05/01/07 17:12, Matthias Schwarzott wrote:
> Hi there!
> 
> This patch just changes charset querying to not only look at environment 
> variable LANG, but respect all in correct order. So now I can overwrite 
> charset setting with LC_CTYPE and LC_ALL.
> 
> Greetings
> Matthias
> 
> 
> 
> ------------------------------------------------------------------------
> 
> diff -ru vdr-1.5.2-vanilla/vdr.c vdr-1.5.2/vdr.c
> --- vdr-1.5.2-vanilla/vdr.c	2007-05-01 17:04:45.000000000 +0200
> +++ vdr-1.5.2/vdr.c	2007-05-01 17:05:18.000000000 +0200
> @@ -493,7 +493,7 @@
>  
>    // Set the system character table:
>  
> -  char *LangEnv = getenv("LANG");
> +  char *LangEnv = setlocale(LC_CTYPE, "");
>    if (LangEnv) {
>       char *CodeSet = strchr(LangEnv, '.');
>       if (CodeSet) {

It's been a while since this, and there have been some changes
in the meantime.

Can you please check the latest developer version (1.5.7) and
see whether this works correctly now?

Klaus
  

Patch

diff -ru vdr-1.5.2-vanilla/vdr.c vdr-1.5.2/vdr.c
--- vdr-1.5.2-vanilla/vdr.c	2007-05-01 17:04:45.000000000 +0200
+++ vdr-1.5.2/vdr.c	2007-05-01 17:05:18.000000000 +0200
@@ -493,7 +493,7 @@ 
 
   // Set the system character table:
 
-  char *LangEnv = getenv("LANG");
+  char *LangEnv = setlocale(LC_CTYPE, "");
   if (LangEnv) {
      char *CodeSet = strchr(LangEnv, '.');
      if (CodeSet) {