From: <ai...@us...> - 2009-09-04 23:31:00
|
Revision: 10369 http://plplot.svn.sourceforge.net/plplot/?rev=10369&view=rev Author: airwin Date: 2009-09-04 23:30:52 +0000 (Fri, 04 Sep 2009) Log Message: ----------- Partial fix (set LC_NUMERIC to "C" but no restoration of locale afterwards) for the palette file reading locale issues. Modified Paths: -------------- trunk/drivers/qt.cpp trunk/include/plplotP.h trunk/src/plcore.c trunk/src/plctrl.c Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-09-04 19:39:51 UTC (rev 10368) +++ trunk/drivers/qt.cpp 2009-09-04 23:30:52 UTC (rev 10369) @@ -96,7 +96,13 @@ snprintf(argv[0], 10, "qt_driver"); argv[1][0]='\0'; new QApplication(argc, argv, isGUI); - setlocale(LC_NUMERIC, "C"); + /* Restore default LC_NUMERIC locale since Qt4 fiddles with it + on some platforms. + if(!(setlocale(LC_NUMERIC, plplot_default_lc_numeric_locale))) { + char msgbuf[1024]; + snprintf(msgbuf,1024,"cmap0_palette_read: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", plplot_default_lc_numeric_locale); + plexit(msgbuf); + }*/ res=true; } return res; Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-09-04 19:39:51 UTC (rev 10368) +++ trunk/include/plplotP.h 2009-09-04 23:30:52 UTC (rev 10369) @@ -120,6 +120,8 @@ #include <unistd.h> #endif +#include <locale.h> + /* (AM) Define M_PI if the platform does not include it (MSVC for instance) */ #if !defined(M_PI) @@ -424,7 +426,14 @@ /* Greek character translation array (defined in plcore.c) */ extern const char plP_greek_mnemonic[]; +/* plinit calls setlocale to establish this pointer to a character string + that stores the LC_NUMERIC locale set by any library or application before + it calls plinit. This character string is used to restore the LC_NUMERIC + locale to the original one after anything (such as colour palette file + reading) within PLplot that temporarily changes the locale. + extern PLDLLIMPEXP_DATA(char *) plplot_default_lc_numeric_locale; */ + /*--------------------------------------------------------------------------*\ * Function Prototypes * Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-09-04 19:39:51 UTC (rev 10368) +++ trunk/src/plcore.c 2009-09-04 23:30:52 UTC (rev 10369) @@ -128,6 +128,9 @@ */ const char plP_greek_mnemonic[] = "ABGDEZYHIKLMNCOPRSTUFXQWabgdezyhiklmncoprstufxqw"; +/* Must define this pointer once. Corresponding declaration is in plplotP.h + char * plplot_default_lc_numeric_locale; */ + void plP_init(void) { @@ -1801,7 +1804,15 @@ PLFLT def_arrow_y[6] = {0.0, 0.0, 0.2, 0.0, -0.2, 0.0}; PLFLT lx, ly, xpmm_loc, ypmm_loc, aspect_old, aspect_new; PLINT mk = 0, sp = 0, inc = 0, del = 2000; + /* Save current LC_NUMERIC locale string pointer in + plplot_default_lc_numeric_locale for purposes of restoring the + current LC_NUMERIC locale after the PLplot library temporarily + fiddles with it. + if(!(plplot_default_lc_numeric_locale = setlocale(LC_NUMERIC, NULL))) { + plexit("plinit: LC_NUMERIC has no default name of locale"); + } */ + pllib_init(); if (plsc->level != 0) Modified: trunk/src/plctrl.c =================================================================== --- trunk/src/plctrl.c 2009-09-04 19:39:51 UTC (rev 10368) +++ trunk/src/plctrl.c 2009-09-04 23:30:52 UTC (rev 10369) @@ -1207,6 +1207,9 @@ char msgbuf[1024]; FILE *fp; + if(!(setlocale(LC_NUMERIC, "C"))) { + plexit("cmap0_palette_read: LC_NUMERIC locale could not be set for \"C\""); + } if(strlen(filename) == 0) { fp = plLibOpen(PL_DEFAULT_CMAP0_FILE); if (fp == NULL) { @@ -1303,6 +1306,12 @@ *(*a+i) = 1.0; } } + + /* Restore default LC_NUMERIC locale since we fiddled with it above. + if(!(setlocale(LC_NUMERIC, plplot_default_lc_numeric_locale))) { + snprintf(msgbuf,1024,"cmap0_palette_read: LC_NUMERIC could not be restored to the default \"%s\" locale.\n", *plplot_default_lc_numeric_locale); + plexit(msgbuf); + } */ } /*--------------------------------------------------------------------------*\ @@ -1373,6 +1382,9 @@ FILE *fp; char msgbuf[1024]; + if(!(setlocale(LC_NUMERIC, "C"))) { + plexit("plspal1: LC_NUMERIC locale could not be set for \"C\""); + } rgb = TRUE; err = 0; format_version = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |