Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Ethan Merritt
>
> >Comment By: Petr Mikulik (mikulik)
> Date: 2005-06-10 09:24
>
> I hope gnuplot's reading will not depend on environmental
> variables as it would immediately became non-portable.

I think you have this backwards.  The LOCALE mechanism is our
best and probably only path toward true portability.
 
> I would rather prefer
>         set decimalsign input ","

We can discuss the choice of gnuplot commands at leisure,
but the fact is that the only way to take action on such a
request is via the LOCALE mechanism, and for better or for
worse that affects both input (scanf, atof, strtod, ...) and
output (printf, ...) in parallel.

This is the code I have been testing:

======================================================
/* process 'set decimalsign' command */
static void
set_decimalsign()
{
    c_token++;

    if (END_OF_COMMAND) {
        if (decimalsign != NULL)
            free(decimalsign);
        decimalsign=NULL;
#ifdef HAVE_LOCALE_H
    } else if (equals(c_token,"locale")) {
        c_token++;
        setlocale(LC_NUMERIC,"");
        fprintf(stderr,"decimal_sign in locale is %s\n", (localeconv()->decimal_point));
        decimalsign = gp_strdup(localeconv()->decimal_point);
#endif
    } else if (!(decimalsign = try_to_get_string()))
        int_error(c_token, "expecting string");
}
=======================================================

So to read an input file with numeric formatting in the convention
of your local environment, you would say
        set decimal locale
        plot "foo" ...

So far as I know, it is not possible to hard-code the LOCALE choice
entirely internal to gnuplot, because gnuplot has no control over
what locales are installed or supported on the machine it runs on.
We are guaranteed that the "C" locale is available, which uses
'.' as a decimal sign, but I have been unable to find any guaranteed
locale that would use ',' instead.

From the command line on linux you can say
        setenv LC_NUMERIC ,
and `locale -c -k` claims that the decimal sign is now "," but upon
testing I find that it does not in fact have any effect on formatting
and anyhow the equivalent request from inside a program via setlocale()
is not accepted at all.

(I'll be out of town for several days, so I won't see any replies for
 a while)

--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r 
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Ethan Merritt
On Saturday 11 June 2005 02:41 am, SourceForge.net wrote:
> >Comment By: Hans-Bernhard Broeker (broeker)
>
> I.e. we need a new command
>
>   set locale {input|output|both} <locale_name>
>
> (or equivalent additions to 'set style data' and 'set
> format'), and maybe even a per-file handling option in
> {s}plot to override this.

I was under the impression that there is no way of separating the locale
used for input (e.g. scanf) from the locale used for output (e.g. printf).
Do you know otherwise?

As to "set locale xx_YY.ZZ", we could create such a command easily.
But the documentation must be as clear as possible that such a command
will only *work* if the appropriate locale is already installed on the
user's machine.

--
Ethan A Merritt
Biomolecular Structure Center
University of Washington 98195-7742


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Hans-Bernhard Bröker
Ethan Merritt wrote:

> I was under the impression that there is no way of separating the locale
> used for input (e.g. scanf) from the locale used for output (e.g. printf).
> Do you know otherwise?

Well, we know when we're doing what, so we could conceivably switch
between the two at the correct times during the process.  Worst thing
that could happen is slightly unexpected error messages in input locale
rather than output locale, if they are printed during datafile reading.



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Ethan Merritt
On Monday 13 June 2005 01:02 am, Hans-Bernhard Broeker wrote:

> Ethan Merritt wrote:
>
> > I was under the impression that there is no way of separating the locale
> > used for input (e.g. scanf) from the locale used for output (e.g. printf).
> > Do you know otherwise?
>
> Well, we know when we're doing what, so we could conceivably switch
> between the two at the correct times during the process.  Worst thing
> that could happen is slightly unexpected error messages in input locale
> rather than output locale, if they are printed during datafile reading.

It would have to be a very fine-grained switch, bracketing each
scanf/printf call.  For instance a plot command like
        plot 'foo' using 1:2:(sprintf(format,column(3))) with labels
will be mixing scanf and sprintf during the parsing of every data line.

Could be done, but I can already here the screams about the performance
hit :-)

--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Hans-Bernhard Bröker
Ethan Merritt wrote:

> It would have to be a very fine-grained switch, bracketing each
> scanf/printf call.  For instance a plot command like
> plot 'foo' using 1:2:(sprintf(format,column(3))) with labels
> will be mixing scanf and sprintf during the parsing of every data line.
>
> Could be done, but I can already here the screams about the performance
> hit :-)

Well, since we wouldn't be forcing anyone to use any locale setting at
all, and the default should be "all locales are 'C', so no setlocale()
calls needed", I consider that a negligible risk.


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: [ gnuplot-Bugs-1217701 ] Locale settings not initialized properly

Ethan Merritt
On Monday 13 June 2005 10:33 am, Hans-Bernhard Broeker wrote:

> Ethan Merritt wrote:
>
> > It would have to be a very fine-grained switch, bracketing each
> > scanf/printf call.  For instance a plot command like
> > plot 'foo' using 1:2:(sprintf(format,column(3))) with labels
> > will be mixing scanf and sprintf during the parsing of every data line.
> >
> > Could be done, but I can already hear screams about the performance
> > hit :-)
>
> Well, since we wouldn't be forcing anyone to use any locale setting at
> all, and the default should be "all locales are 'C', so no setlocale()
> calls needed", I consider that a negligible risk.

I've uploaded a patchset to SourceForge that implements
        set decimalsign { <value> | {locale {<LOC>}}

My thought is that people can try this out and report back whether
there is a need to separate out the input and output locales.

By the way, it may be obvious but let me state it explicitly:

The existing `set locale` command only affects LC_TIME, the format used
for time/date strings.

The new command options to `set decimalsign` only affect LC_NUMERIC,
the format conventions used by the C library for scanf and printf.

Neither of these affects LC_CTYPE, which controls the character set
and font encoding.



--
Ethan A Merritt       [hidden email]
Biomolecular Structure Center
Mailstop 357742
University of Washington, Seattle, WA 98195


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
gnuplot-beta mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gnuplot-beta