1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0022898: IGES import fails in german environment

Added DRAW command dlocale to set and query current locale of the C subsystem
Equivalents of C functions working with conversions of strings to/from reals added in Standard_CString, providing locale-independent behavior (using always "C" locale)
In DRAW packages, calls to atof() and atoi() are replaced by direct calls to Draw::Atof() and Draw::Atoi(), respectively, instead of substituting by #define
Use of atof(), strtod(), and *scanf() involving floating point conversions in OCCT code replaced by locale-independent Atof() and Strtod()
Calls to sprintf() involving floating point in OCCT code are replaced by call to locale-independent Sprintf(), except a few places where converted strings are used immediately for display in the 3d viewer
Changes of global locale are eliminated throughout OCCT code
Proposed correction for GNU libC where v*printf_l functions are absent
Added test case (bugs xde bug22898) for data exchange operations with non-standard locale
Use xlocale on Mac OS X and within glibc
Corrected strtod_l wrapper
Generate error rather than warning
Introduce Standard_CLocaleSentry replacement for removed OSD_Localizer
Standard_CLocaleSentry - copy locale string
Standard_CLocaleSentry - use _configthreadlocale on Windows
Standard_CLocaleSentry::GetCLocale() - return locale_t rather than void*
Corrected misprint in ~Standard_CLocaleSentry()
Use French locale in bug22898 test case
Mark test case as skipped if locale is unavailable on tested system.
Use fr_FR locale for tests on Mac OS X
This commit is contained in:
abv
2013-02-01 18:41:16 +04:00
parent 3bea4c165c
commit 91322f44fd
203 changed files with 2707 additions and 2807 deletions

View File

@@ -16,7 +16,6 @@ OSD_signal.cxx
OSD_signal_WNT.cxx
OSD_ThreadFunction.hxx
OSD_PThread.hxx
OSD_Localizer.cxx
OSD_PerfMeter.cxx
OSD_PerfMeter.h
OSD_PerfMeter.hxx

View File

@@ -176,13 +176,6 @@ is
class Thread;
---Purpose: A tool to manage threads
class Real2String;
---Purpose: Convertion of CString to Real and reciprocally
class Localizer;
---Purpose: Manages locale.
-----------------------------------------------
-- UNIX specific exceptions and enumeration --
-----------------------------------------------

View File

@@ -28,17 +28,6 @@
# define finite isfinite
#endif
static Standard_Integer DecimalPoint = 0 ;
static void GetDecimalPoint() {
float F1 = (float ) 1.1 ;
char str[5] ;
sprintf(str,"%.1f",F1) ;
// printf("%s\n",str) ;
DecimalPoint = str[1] ;
}
// Convert Real to CString in format e with 16 significant digits.
// The decimal point character is always a period.
// The conversion is independant from current locale database
@@ -48,20 +37,9 @@ Standard_Boolean OSD::RealToCString(const Standard_Real aReal,
{
char *p, *q ;
// Get the local decimal point character
if (!DecimalPoint)
GetDecimalPoint() ;
// Substitute it
// if (sprintf(aString,"%.15le",aReal) <= 0)
if (sprintf(aString,"%.17e",aReal) <= 0) //BUC60808
if (Sprintf(aString,"%.17e",aReal) <= 0) //BUC60808
return Standard_False ;
if ((p = strchr(aString,DecimalPoint)))
*p = '.' ;
// Suppress "e+00" and unsignificant 0's
if ((p = strchr(aString,'e'))) {
@@ -83,25 +61,8 @@ Standard_Boolean OSD::RealToCString(const Standard_Real aReal,
Standard_Boolean OSD::CStringToReal(const Standard_CString aString,
Standard_Real& aReal)
{
const char *p;
char *endptr ;
// Get the local decimal point character
if (!DecimalPoint)
GetDecimalPoint() ;
const char *str = aString;
char buff[1024];
//if((p = strchr(aString,'.')))
if(DecimalPoint != '.' && (p = strchr(aString,'.'))&& ((p-aString) < 1000) )
{
strncpy(buff, aString, 1000);
buff[p-aString] = DecimalPoint ;
str = buff;
}
aReal = strtod(str,&endptr) ;
aReal = Strtod(aString, &endptr);
if (*endptr)
return Standard_False ;
return Standard_True;

View File

@@ -1,60 +0,0 @@
-- Created on: 2010-08-27
-- Created by: Paul SUPRYATKIN
-- Copyright (c) 2010-2012 OPEN CASCADE SAS
--
-- The content of this file is subject to the Open CASCADE Technology Public
-- License Version 6.5 (the "License"). You may not use the content of this file
-- except in compliance with the License. Please obtain a copy of the License
-- at http://www.opencascade.org and read it completely before using this file.
--
-- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
--
-- The Original Code and all software distributed under the License is
-- distributed on an "AS IS" basis, without warranty of any kind, and the
-- Initial Developer hereby disclaims all such warranties, including without
-- limitation, any warranties of merchantability, fitness for a particular
-- purpose or non-infringement. Please see the License for the specific terms
-- and conditions governing the rights and limitations under the License.
class Localizer from OSD
---Purpose: Define the locale.
is
Create ( Category : Integer from Standard;
Locale : CString from Standard);
---Purpose: Set locale
---Level: Public
Restore( me: in out );
---Purpose: Restore previously locale
---Level: Public
SetLocale( me: in out;
Category : Integer from Standard;
Locale : CString from Standard);
---Purpose: Set locale
---Level: Public
Locale( me )
returns CString from Standard;
---Purpose: Get locale
---Level: Public
Category( me )
returns Integer from Standard;
---Purpose: Get Gategory
---Level: Public
fields
myLocale : CString from Standard;
myCategory : Integer from Standard;
end Localizer from OSD;

View File

@@ -1,54 +0,0 @@
// Created on: 2010-08-27
// Created by: Paul SUPRYATKIN
// Copyright (c) 2010-2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// except in compliance with the License. Please obtain a copy of the License
// at http://www.opencascade.org and read it completely before using this file.
//
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
//
// The Original Code and all software distributed under the License is
// distributed on an "AS IS" basis, without warranty of any kind, and the
// Initial Developer hereby disclaims all such warranties, including without
// limitation, any warranties of merchantability, fitness for a particular
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
#include <OSD_Localizer.hxx>
#include <Standard.hxx>
#include <locale.h>
OSD_Localizer::OSD_Localizer(const Standard_Integer Category,const Standard_CString Locale )
{
SetLocale( Category, Locale );
}
void OSD_Localizer::Restore()
{
setlocale( myCategory, myLocale );
}
void OSD_Localizer::SetLocale(const Standard_Integer Category,const Standard_CString Locale )
{
myLocale = setlocale( Category, 0 );
myCategory = Category;
setlocale( Category, Locale );
}
Standard_CString OSD_Localizer::Locale() const
{
return myLocale;
}
Standard_Integer OSD_Localizer::Category() const
{
return myCategory;
}

View File

@@ -1,54 +0,0 @@
-- Created on: 2002-01-25
-- Created by: doneux <doneux@samcef.com>
-- Copyright (c) 2002-2012 OPEN CASCADE SAS
--
-- The content of this file is subject to the Open CASCADE Technology Public
-- License Version 6.5 (the "License"). You may not use the content of this file
-- except in compliance with the License. Please obtain a copy of the License
-- at http://www.opencascade.org and read it completely before using this file.
--
-- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
--
-- The Original Code and all software distributed under the License is
-- distributed on an "AS IS" basis, without warranty of any kind, and the
-- Initial Developer hereby disclaims all such warranties, including without
-- limitation, any warranties of merchantability, fitness for a particular
-- purpose or non-infringement. Please see the License for the specific terms
-- and conditions governing the rights and limitations under the License.
class Real2String from OSD
---Purpose: Convertion of CString to Real and reciprocally
is
Create
returns Real2String from OSD;
RealToCString(me;
aReal: Real;
aString:out PCharacter)
returns Boolean ;
---Purpose:
-- Converts aReal into aCstring in exponential format with maximum
-- 17 digits. The size of the destination string must be sufficient (at least 23 characters)
-- The decimal separator account for locale setting, but
-- neither thousand separator nor grouping of digits in the output string.
--
CStringToReal(me: in out;
aString: CString;
aReal: out Real) returns Boolean ;
---Purpose:
-- Converts aCstring representing a real. The first occurence of the decimal separator
-- (comma or period) defines it values for further readings.
-- Neither thousand separator nor grouping of digits are allowed in the CString
fields
myReadDecimalPoint: Integer from Standard;
myLocalDecimalPoint: Integer from Standard;
end Real2String;

View File

@@ -1,124 +0,0 @@
// Created on: 2002-01-25
// Created by: doneux
// Copyright (c) 2002-2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// except in compliance with the License. Please obtain a copy of the License
// at http://www.opencascade.org and read it completely before using this file.
//
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
//
// The Original Code and all software distributed under the License is
// distributed on an "AS IS" basis, without warranty of any kind, and the
// Initial Developer hereby disclaims all such warranties, including without
// limitation, any warranties of merchantability, fitness for a particular
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
// Lastly modified by :
// +---------------------------------------------------------------------------+
// ! doneux ! Creation ! 06/17/02! %V%-1!
// +---------------------------------------------------------------------------+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <OSD_Real2String.ixx>
#include <stdio.h>
#if defined(HAVE_STDLIB_H) || defined(WNT)
# include <stdlib.h>
#endif
//=======================================================================
//function : OSD_Real2String
//purpose :
//=======================================================================
OSD_Real2String::OSD_Real2String():
myReadDecimalPoint(0)
{
float F1 = (float ) 1.1 ;
char str[5] ;
sprintf(str,"%.1f",F1) ;
// printf("%s\n",str) ;
myLocalDecimalPoint = str[1] ;
}
//=======================================================================
//function : RealToCString
//purpose :
//=======================================================================
Standard_Boolean OSD_Real2String::RealToCString(const Standard_Real theReal,
Standard_PCharacter& theString) const
{
char *p, *q ;
if (sprintf(theString,"%.17e",theReal) <= 0)
return Standard_False ;
// Suppress "e+00" and unsignificant 0's
if ((p = strchr(theString,'e'))) {
if (!strcmp(p,"e+00"))
*p = 0 ;
for (q = p-1 ; *q == '0' ; q--) ;
if (q != p-1) {
if (*q != myLocalDecimalPoint) q++ ;
while (*p)
*q++ = *p++ ;
*q = 0 ;
}
}
return Standard_True ;
}
//=======================================================================
//function : CStringToReal
//purpose :
//=======================================================================
Standard_Boolean OSD_Real2String::CStringToReal(const Standard_CString theString,
Standard_Real& theReal)
{
char *endptr ;
if (! theString) return Standard_False;
// Get the decimal point character in the string (if any)
if (!myReadDecimalPoint) {
if (strchr(theString, ',')) myReadDecimalPoint = ',';
else if (strchr(theString, '.')) myReadDecimalPoint = '.';
}
const char *str = theString;
char buff[1024];
if (myReadDecimalPoint) {
if (myReadDecimalPoint != myLocalDecimalPoint) {
const char * p;
// replace the decimal point by the local one
if(myReadDecimalPoint != myLocalDecimalPoint &&
(p = strchr(theString,myReadDecimalPoint))&& ((p-theString) < 1000) )
{
strncpy(buff, theString, 1000);
buff[p-theString] = myLocalDecimalPoint;
str = buff;
}
}
}
theReal = strtod(str,&endptr) ;
if (*endptr)
return Standard_False ;
return Standard_True;
}