Hi Alan, I have been experimenting a bit with the test program I sent earlier to see how this works on Windows. Well, the short version is: setlocale() doesn't have effect.
The long version is: With both MSVC/C++ 6.0 and MSVC/C++ 2008 I have been unable to get a comma to work as a decimal separator. The online help uses quite different names from nl_NL and the like (Dutch_netherlands and similar names for other countries/languages), but there is no effect whatsoever. This is the program: // chklocale.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "locale.h" int _tmain(int argc, _TCHAR* argv[]) { float x = 1.2; char *pstr; pstr = setlocale(LC_NUMERIC, ""); printf( "Number: %f -- %s\n", x, pstr ); if ( argc > 1 ) { sscanf( (char *)argv[1], "%f", &x ); printf( "Read: %f\n", x ); } if ( argc > 2 ) { pstr = setlocale(LC_ALL, (char *)argv[2]); sscanf( (char *)argv[1], "%f", &x ); printf( "Read: %f -- %s\n", x, pstr ); } } It writes the return string from setlocale() and produces: chklocale 1,3 English Number: 1.200000 -- Dutch_Netherlands.1252 Read: 1.000000 Read: 1.000000 -- (null) (I expected the first 1.0 to read 1,3) ... I remembered suddenly that on Windows you can set the regional settings. That contained a period ... So setting that to a comma, I get: chklocale 1,3 Dutch_Netherlands.1252 Number: 1,200000 -- Dutch_Netherlands.1252 Read: 1,000000 Read: 1,000000 -- (null) Note: the comma is apparently not recognised on input, it is used on output! (I should check this with gcc too ...) Regards, Arjen On 2009-09-08 05:50, Alan W. Irwin wrote: > On 2009-09-06 18:36-0700 Alan W. Irwin wrote: > >> BTW, plsave_set_locale and plrestore_locale are the antithesis of functional >> programming because they have no arguments and return nothing. That is, >> they cause nothing but side effects. However, that is the name of the game >> when dealing with POSIX locale issues. plsave_set_locale simply saves the >> original locale string (set by external code such as x01c.c) in a global way >> and sets locale to "C". plrestore_locale restores the original locale, and >> frees the memory where the original global locale string was stored. >> >> I think this is the best way to implement this pair of functions because I >> think we will always need them to communicate with each other between >> different routines. (Note, the file open and close are in different routines >> in ps.c if we want to block all locale changes when writing the output >> PostScript file from ps.c as above.) However, my C skills are not as good as >> I would like them to be so I would be interested in discussing changes in >> the implementation of these two functions if someone has some better ideas. > > Well, practical experience with plsave_set_locale and plrestore_locale today > showed me that these are always called from the same routine so I didn't > need the global variable approach. Dropping that allowed me to change these > to reentrant routines (which was required for some situations [i.e., the > -debug option which recursively called these routines] in any case). > > I have now protected all PLplot core device driver calls with these routines > (revision 10383), and the result is all devices appear to work fine > for the -locale option for example 1. That is, > > LC_NUMERIC=nl_NL.utf8 examples/c/x01c -locale > > appears to give a comma decimal separator for axis labels for every device I > have tried with no obvious valgrind or other issues. > > So this looks quite promising, and I plan to follow up by expanding the > testing of this new PLplot feature to all devices and all examples to see if > there are any limitations for this new feature. The test of locale for all > examples will be made possible by replacing the limited example 1 -locale > option by a general -locale option that executes > > setlocale(LC_NUMERIC, ""); > > to establish the basic PLplot locale and thus make PLplot generally portable > to all LC_NUMERIC locales depending on how users set the LC_NUMERIC > or LC_ALL environment variables. > > Alan > __________________________ > Alan W. Irwin > > Astronomical research affiliation with Department of Physics and Astronomy, > University of Victoria (astrowww.phys.uvic.ca). > > Programming affiliations with the FreeEOS equation-of-state implementation > for stellar interiors (freeeos.sf.net); PLplot scientific plotting software > package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of > Linux Links project (loll.sf.net); and the Linux Brochure Project > (lbproject.sf.net). > __________________________ > > Linux-powered Science > __________________________ > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Plplot-devel mailing list > Plplot-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/plplot-devel > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel