1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +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

@@ -182,13 +182,13 @@ is
---Purpose: Sets a TCL sting variable
Atof(Name : CString) returns Real;
---Purpose: Search a numeric variable. If none found converts
-- the string to a real.
---Purpose: Converts numeric expression, that can involve DRAW
-- variables, to real value.
Atoi(Name : CString) returns Integer;
---Purpose: Search a numeric variable. If none found converts
-- the string to an integer.
---Purpose: Converts numeric expression, that can involve DRAW
-- variables, to integer value.
-- Implemented as cast of Atof() to integer.
LastPick(view,X,Y,button : out Integer);
---Purpose: Returns last graphic selection description.

View File

@@ -110,7 +110,7 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName)
try {
aPath.ChangeAll ('\\', '/');
sprintf(console_command, "source \"%.980s\"", aPath.ToCString());
Sprintf(console_command, "source \"%.980s\"", aPath.ToCString());
console_semaphore = HAS_CONSOLE_COMMAND;
while (console_semaphore == HAS_CONSOLE_COMMAND)
Sleep(10);
@@ -122,7 +122,7 @@ static void ReadInitFile (const TCollection_AsciiString& theFileName)
} else {
#endif
char* com = new char [aPath.Length() + strlen ("source ") + 2];
sprintf (com, "source %s", aPath.ToCString());
Sprintf (com, "source %s", aPath.ToCString());
Draw_Interprete (com);
delete [] com;
#ifdef WNT

View File

@@ -64,9 +64,6 @@ extern Draw_Viewer dout;
extern Standard_Boolean Draw_Batch;
#endif
#define atof(X) Draw::Atof(X)
#define atoi(X) Draw::Atoi(X)
class Draw_SaveAndRestore {
public :

View File

@@ -391,7 +391,7 @@ static Standard_Integer Draw_wait(Draw_Interpretor& , Standard_Integer n, const
{
Standard_Integer w = 10;
if (n > 1)
w = atoi(a[1]);
w = Draw::Atoi(a[1]);
time_t ct = time(NULL) + w;
while (time(NULL) < ct) {};
return 0;
@@ -443,7 +443,7 @@ static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const
CPU_LIMIT = RLIM_INFINITY;
else
{
CPU_LIMIT = atoi (a[1]);
CPU_LIMIT = Draw::Atoi (a[1]);
Standard_Real anUserSeconds, aSystemSeconds;
OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds);
CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds);
@@ -464,7 +464,7 @@ static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const
if (n <= 1)
rlp.rlim_cur = RLIM_INFINITY;
else
rlp.rlim_cur = atoi(a[1]);
rlp.rlim_cur = Draw::Atoi(a[1]);
CPU_LIMIT = rlp.rlim_cur;
int status;
@@ -517,7 +517,7 @@ By default <logfile> is \"mem-log.txt\", <outfile> is \"mem-stat.txt\""
}
if (strcmp(a[1], "set") == 0)
{
int aType = (n > 2 ? atoi(a[2]) : 1);
int aType = (n > 2 ? Draw::Atoi(a[2]) : 1);
if (aType < 0 || aType > 2)
{
di << "unknown op of the command set" << "\n";
@@ -581,7 +581,7 @@ By default <logfile> is \"mem-log.txt\", <outfile> is \"mem-stat.txt\""
const char* aOutFile = "mem-stat.txt";
if (n > 2)
{
includeAlive = (atoi(a[2]) != 0);
includeAlive = (Draw::Atoi(a[2]) != 0);
if (n > 3)
{
aLogFile = a[3];
@@ -608,6 +608,38 @@ By default <logfile> is \"mem-log.txt\", <outfile> is \"mem-stat.txt\""
return 0;
}
//==============================================================================
//function : dlocale
//purpose :
//==============================================================================
static int dlocale (Draw_Interpretor& di, Standard_Integer n, const char** argv)
{
int category = LC_ALL;
if (n > 1)
{
const char *cat = argv[1];
if ( ! strcmp (cat, "LC_ALL") ) category = LC_ALL;
else if ( ! strcmp (cat, "LC_COLLATE") ) category = LC_COLLATE;
else if ( ! strcmp (cat, "LC_CTYPE") ) category = LC_CTYPE;
else if ( ! strcmp (cat, "LC_MONETARY") ) category = LC_MONETARY;
else if ( ! strcmp (cat, "LC_NUMERIC") ) category = LC_NUMERIC;
else if ( ! strcmp (cat, "LC_TIME") ) category = LC_TIME;
else
{
cout << "Error: cannot recognize argument " << cat << " as one of LC_ macros" << endl;
return 1;
}
}
const char* locale = (n > 2 ? argv[2] : NULL);
const char* result = setlocale (category, locale);
if (result)
di << result;
else
cout << "Error: unsupported locale specification: " << locale << endl;
return 0;
}
//==============================================================================
//function : dmeminfo
//purpose :
@@ -702,4 +734,6 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
__FILE__,dbreak,g);
theCommands.Add("dversion", "provides information on OCCT build configuration (version, compiler, OS, C library, etc.)",
__FILE__,dversion,g);
theCommands.Add("dlocale", "set and / or query locate of C subsystem (function setlocale())",
__FILE__,dlocale,g);
}

View File

@@ -74,7 +74,7 @@ static char Draw_fontsizedefault[FONTLENGTH]="150";
static Standard_Integer ViewId(const Standard_CString a)
{
Standard_Integer id = atoi(a);
Standard_Integer id = Draw::Atoi(a);
if ((id < 0) || (id >= MAXVIEW)) {
cout << "Incorrect view-id, must be in 0.."<<MAXVIEW-1<<endl;
return -1;
@@ -90,7 +90,7 @@ static void SetTitle(const Standard_Integer id)
{
if (dout.HasView(id)) {
char title[255];
sprintf(title,"%d : %s - Zoom %f",id,dout.GetType(id),dout.Zoom(id));
Sprintf(title,"%d : %s - Zoom %f",id,dout.GetType(id),dout.Zoom(id));
dout.SetTitle(id,title);
}
}
@@ -106,7 +106,7 @@ static Standard_Integer zoom(Draw_Interpretor& , Standard_Integer n, const char*
// two argument -> First is the view
Standard_Boolean z2d = !strcasecmp(a[0],"2dzoom");
if (n == 2) {
Standard_Real z = atof(a[1]);
Standard_Real z = Draw::Atof(a[1]);
for (Standard_Integer id = 0; id < MAXVIEW; id++) {
if (dout.HasView(id)) {
if ((z2d && !dout.Is3D(id)) || (!z2d && dout.Is3D(id))) {
@@ -121,7 +121,7 @@ static Standard_Integer zoom(Draw_Interpretor& , Standard_Integer n, const char*
else if (n >= 3) {
Standard_Integer id = ViewId(a[1]);
if (id < 0) return 1;
Standard_Real z = atof(a[2]);
Standard_Real z = Draw::Atof(a[2]);
dout.SetZoom(id,z);
dout.RepaintView(id);
SetTitle(id);
@@ -263,7 +263,7 @@ static Standard_Integer view(Draw_Interpretor& di, Standard_Integer n, const cha
if (Draw_Batch) return 1;
if ((n >= 3) && (n != 4)) {
Standard_Integer id = atoi(a[1]);
Standard_Integer id = Draw::Atoi(a[1]);
if ((id < 0) || (id >= MAXVIEW)) {
di <<"View-id must be in 0.."<<MAXVIEW-1<<"\n";
return 1;
@@ -276,13 +276,13 @@ static Standard_Integer view(Draw_Interpretor& di, Standard_Integer n, const cha
if (dout.HasView(id))
dout.GetPosSize(id,X,Y,W,H);
if (n >= 4)
X = atoi(a[3]);
X = Draw::Atoi(a[3]);
if (n >= 5)
Y = atoi(a[4]);
Y = Draw::Atoi(a[4]);
if (n >= 6)
W = atoi(a[5]);
W = Draw::Atoi(a[5]);
if (n >= 7)
H = atoi(a[6]);
H = Draw::Atoi(a[6]);
dout.MakeView(id,a[2],X,Y,W,H);
if (!dout.HasView(id)) {
di << "View creation failed"<<"\n";
@@ -294,7 +294,7 @@ static Standard_Integer view(Draw_Interpretor& di, Standard_Integer n, const cha
}
else if (n == 4) {
// create a view on a given window
Standard_Integer id = atoi(a[1]);
Standard_Integer id = Draw::Atoi(a[1]);
if ((id < 0) || (id >= MAXVIEW)) {
di <<"View-id must be in 0.."<<MAXVIEW-1<<"\n";
return 1;
@@ -421,7 +421,7 @@ static Standard_Integer setfocal(Draw_Interpretor& di, Standard_Integer n, const
}
}
else {
Standard_Real f = atof(a[1]);
Standard_Real f = Draw::Atof(a[1]);
for (Standard_Integer id = 0; id < MAXVIEW; id++) {
if (!strcasecmp(dout.GetType(id),"PERS"))
dout.SetFocal(id,f);
@@ -575,14 +575,14 @@ static Standard_Integer ptv(Draw_Interpretor& , Standard_Integer n, const char**
Standard_Integer anid = ViewId(a[1]);
if (anid < 0) return 1;
start = end = anid;
X = atof(a[2]);
Y = atof(a[3]);
Z = atof(a[4]);
X = Draw::Atof(a[2]);
Y = Draw::Atof(a[3]);
Z = Draw::Atof(a[4]);
}
else {
X = atof(a[1]);
Y = atof(a[2]);
Z = atof(a[3]);
X = Draw::Atof(a[1]);
Y = Draw::Atof(a[2]);
Z = Draw::Atof(a[3]);
}
for (Standard_Integer id = start; id <= end; id++) {
@@ -614,14 +614,14 @@ static Standard_Integer dptv(Draw_Interpretor& , Standard_Integer n, const char*
Standard_Integer anid = ViewId(a[1]);
if (anid < 0) return 1;
start = end = anid;
DX = atof(a[2]);
DY = atof(a[3]);
DZ = atof(a[4]);
DX = Draw::Atof(a[2]);
DY = Draw::Atof(a[3]);
DZ = Draw::Atof(a[4]);
}
else {
DX = atof(a[1]);
DY = atof(a[2]);
DZ = atof(a[3]);
DX = Draw::Atof(a[1]);
DY = Draw::Atof(a[2]);
DZ = Draw::Atof(a[3]);
}
for (Standard_Integer id = start; id <= end; id++) {
@@ -647,7 +647,7 @@ static Standard_Integer color(Draw_Interpretor& di, Standard_Integer n, const ch
if (n < 3) {
Draw_BlackBackGround = !Draw_BlackBackGround;
}
else if (!dout.DefineColor(atoi(a[1]),a[2])) {
else if (!dout.DefineColor(Draw::Atoi(a[1]),a[2])) {
di << "Could not allocate color "<<a[2]<<"\n";
return 1;
}
@@ -826,7 +826,7 @@ static Standard_Integer hcolor(Draw_Interpretor& di, Standard_Integer n, const c
di << "12 = Yellow,\t 13 = Khaki,\t 14 = Coral" << "\n" ;
di << "1 <= width <= 11, 0 (noir) <= gray <= 1 (blanc)" << "\n" ;
} else {
dout.PostColor(atoi(a[1]),atoi(a[2]),atof(a[3]));
dout.PostColor(Draw::Atoi(a[1]),Draw::Atoi(a[2]),Draw::Atof(a[3]));
}
return 0;
}
@@ -848,7 +848,7 @@ static Standard_Integer xwd(Draw_Interpretor& , Standard_Integer n, const char**
Standard_Integer id = 1;
const char* file = a[1];
if (n > 2) {
id = atoi(a[1]);
id = Draw::Atoi(a[1]);
file = a[2];
}
if (!dout.SaveView(id,file))
@@ -873,19 +873,19 @@ static Standard_Integer grid (Draw_Interpretor& , Standard_Integer NbArg, const
StepZ = DefaultGridStep ;
break ;
case 2 :
StepX = Abs (atof (Arg[1])) ;
StepY = Abs (atof (Arg[1])) ;
StepZ = Abs (atof (Arg[1])) ;
StepX = Abs (Draw::Atof (Arg[1])) ;
StepY = Abs (Draw::Atof (Arg[1])) ;
StepZ = Abs (Draw::Atof (Arg[1])) ;
break ;
case 3 :
StepX = Abs (atof (Arg[1])) ;
StepY = Abs (atof (Arg[2])) ;
StepZ = Abs (atof (Arg[2])) ;
StepX = Abs (Draw::Atof (Arg[1])) ;
StepY = Abs (Draw::Atof (Arg[2])) ;
StepZ = Abs (Draw::Atof (Arg[2])) ;
break ;
case 4 :
StepX = Abs (atof (Arg[1])) ;
StepY = Abs (atof (Arg[2])) ;
StepZ = Abs (atof (Arg[3])) ;
StepX = Abs (Draw::Atof (Arg[1])) ;
StepY = Abs (Draw::Atof (Arg[2])) ;
StepZ = Abs (Draw::Atof (Arg[3])) ;
break ;
default :
return 1 ;
@@ -941,7 +941,7 @@ static Standard_Integer dtext(Draw_Interpretor& di, Standard_Integer n, const ch
}
else if (n >= 4) {
is3d = n > 4;
P.SetCoord(atof(a[1]),atof(a[2]),is3d ? atof(a[3]) : 0);
P.SetCoord(Draw::Atof(a[1]),Draw::Atof(a[2]),is3d ? Draw::Atof(a[3]) : 0);
}
else
return 0;

View File

@@ -233,7 +233,7 @@ static Standard_Integer CommandCmd
cout << "An exception was caught " << E << endl;
if (cc && atoi(cc)) {
if (cc && Draw::Atoi(cc)) {
#ifdef WNT
Tcl_Exit(0);
#else
@@ -497,7 +497,7 @@ Draw_Interpretor& Draw_Interpretor::Append(const TCollection_ExtendedString& the
Draw_Interpretor& Draw_Interpretor::Append(const Standard_Integer i)
{
char c[100];
sprintf(c,"%d",i);
Sprintf(c,"%d",i);
Tcl_AppendResult(myInterp,c,(Standard_CString)0);
return *this;
}
@@ -510,7 +510,7 @@ Draw_Interpretor& Draw_Interpretor::Append(const Standard_Integer i)
Draw_Interpretor& Draw_Interpretor::Append(const Standard_Real r)
{
char s[100];
sprintf(s,"%.17g",r);
Sprintf(s,"%.17g",r);
Tcl_AppendResult(myInterp,s,(Standard_CString)0);
return *this;
}

View File

@@ -87,7 +87,7 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
// Prepare textual progress info
char text[2048];
Standard_Integer n = 0;
n += sprintf ( &text[n], "Progress: %.0f%%", 100. * GetPosition() );
n += Sprintf ( &text[n], "Progress: %.0f%%", 100. * GetPosition() );
for ( Standard_Integer i=GetNbScopes(); i >=1; i-- ) {
const Message_ProgressScale &scale = GetScope ( i );
if ( scale.GetName().IsNull() ) continue; // skip unnamed scopes
@@ -95,16 +95,16 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
Standard_Real locPos = ( i >1 ? GetScope ( i-1 ).GetLast() : GetPosition() );
// print progress info differently for finite and infinite scopes
if ( scale.GetInfinite() )
n += sprintf ( &text[n], " %s: %.0f", scale.GetName()->ToCString(),
n += Sprintf ( &text[n], " %s: %.0f", scale.GetName()->ToCString(),
scale.BaseToLocal ( locPos ) );
else
n += sprintf ( &text[n], " %s: %.0f / %.0f", scale.GetName()->ToCString(),
n += Sprintf ( &text[n], " %s: %.0f / %.0f", scale.GetName()->ToCString(),
scale.BaseToLocal ( locPos ), scale.GetMax() );
}
// In addition, write elapsed/estimated/remaining time
if ( GetPosition() > 0.01 ) {
n += sprintf ( &text[n], "\nElapsed/estimated time: %ld/%.0f sec",
n += Sprintf ( &text[n], "\nElapsed/estimated time: %ld/%.0f sec",
(long)(aTime - myStartTime), ( aTime - myStartTime ) / GetPosition() );
}
@@ -112,7 +112,7 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
if ( myGraphMode ) {
if ( ! myShown ) {
char command[1024];
sprintf ( command, "toplevel .xprogress -height 100 -width 410;"
Sprintf ( command, "toplevel .xprogress -height 100 -width 410;"
"wm title .xprogress \"Progress\";"
"set xprogress_stop 0;"
"canvas .xprogress.bar -width 402 -height 22;"
@@ -127,12 +127,12 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
}
char command[1024];
Standard_Integer num = 0;
num += sprintf ( &command[num], ".xprogress.bar coords progress 2 2 %.0f 21;",
num += Sprintf ( &command[num], ".xprogress.bar coords progress 2 2 %.0f 21;",
1+400*GetPosition() );
num += sprintf ( &command[num], ".xprogress.bar coords progress_next 2 2 %.0f 21;",
num += Sprintf ( &command[num], ".xprogress.bar coords progress_next 2 2 %.0f 21;",
1+400*GetScope(1).GetLast() );
num += sprintf ( &command[num], ".xprogress.text configure -text \"%s\";", text );
num += sprintf ( &command[num], "update" );
num += Sprintf ( &command[num], ".xprogress.text configure -text \"%s\";", text );
num += Sprintf ( &command[num], "update" );
((Draw_Interpretor*)myDraw)->Eval ( command );
}

View File

@@ -45,7 +45,7 @@ static Standard_Integer parsing
TCollection_AsciiString aStrTok(argv[1]);
Standard_Integer nbIter =1;
if(argc >2)
nbIter = atoi(argv[2]);
nbIter = Draw::Atoi(argv[2]);
UnitsAPI::SetLocalSystem();
Handle(Units_Token) atoken;
Units_UnitSentence aUnitSent(aStrTok.ToCString());
@@ -93,7 +93,7 @@ static Standard_Integer converttoSI
return 1;
}
Standard_Real aData = atof(argv[1]);
Standard_Real aData = Draw::Atof(argv[1]);
Standard_CString aUnit = argv[2];
Standard_Real res = UnitsAPI::AnyToSI(aData,aUnit);
@@ -115,7 +115,7 @@ static Standard_Integer converttoMDTV
return 1;
}
Standard_Real aData = atof(argv[1]);
Standard_Real aData = Draw::Atof(argv[1]);
Standard_CString aUnit = argv[2];
UnitsAPI::SetLocalSystem(UnitsAPI_MDTV);
@@ -134,7 +134,7 @@ static Standard_Integer converttoMDTV
static Standard_Integer unit(Draw_Interpretor& , Standard_Integer n, const char** a)
{
if(n == 4) {
cout << Units::Convert(atof(a[1]), a[2], a[3]) << endl;
cout << Units::Convert(Draw::Atof(a[1]), a[2], a[3]) << endl;
return 0;
}
else

View File

@@ -400,12 +400,12 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch
static Standard_Integer draw(Draw_Interpretor& , Standard_Integer n, const char** a)
{
if (n < 3) return 1;
Standard_Integer id = atoi(a[1]);
Standard_Integer id = Draw::Atoi(a[1]);
if (!dout.HasView(id)) {
cout << "bad view number in draw"<<endl;
return 1;
}
Standard_Integer mo = atoi(a[2]);
Standard_Integer mo = Draw::Atoi(a[2]);
Draw_Display d = dout.MakeDisplay(id);
d.SetMode(mo);
Standard_Integer i;
@@ -479,7 +479,7 @@ static Standard_Integer whatis(Draw_Interpretor& di, Standard_Integer n, const c
static Standard_Integer value(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n != 2) return 1;
di << atof(a[1]);
di << Draw::Atof(a[1]);
return 0;
}
@@ -586,7 +586,7 @@ static Standard_Integer set(Draw_Interpretor& di, Standard_Integer n, const char
Standard_Real val=0;
for (i = 1; i < n; i += 2) {
val = 0;
if (i+1 < n) val = atof(a[i+1]);
if (i+1 < n) val = Draw::Atof(a[i+1]);
Draw::Set(a[i],val);
}
di << val;
@@ -681,7 +681,7 @@ static Standard_Integer pick(Draw_Interpretor& , Standard_Integer n, const char*
Standard_Integer id;
Standard_Integer X,Y,b;
Standard_Boolean wait = (n == 6);
if (!wait) id = atoi(a[1]);
if (!wait) id = Draw::Atoi(a[1]);
dout.Select(id,X,Y,b,wait);
Standard_Real z = dout.Zoom(id);
gp_Pnt P((Standard_Real)X /z,(Standard_Real)Y /z,0);
@@ -945,7 +945,7 @@ void Draw::Repaint()
static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const char** a)
{
Standard_Real x = atof(a[1]);
Standard_Real x = Draw::Atof(a[1]);
if (!strcasecmp(a[0],"cos"))
di << Cos(x);
@@ -960,7 +960,7 @@ static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const ch
else if (!strcasecmp(a[0],"asin"))
di << ASin(x);
else if (!strcasecmp(a[0],"atan2"))
di << ATan2(x,atof(a[2]));
di << ATan2(x,Draw::Atof(a[2]));
return 0;
}
@@ -970,9 +970,6 @@ static Standard_Integer trigo (Draw_Interpretor& di, Standard_Integer , const ch
// Atof and Atoi
//=======================================================================
#undef atof
#undef atoi
static Standard_Boolean Numeric(char c)
{
return (c == '.' || (c >= '0' && c <= '9'));
@@ -1028,7 +1025,7 @@ static Standard_Real ParseValue(char*& name)
*p = '\0';
if (Numeric(*name)) // numeric litteral
x = atof(name);
x = Atof(name);
else if (!Draw::Get((Standard_CString) name,x)) { // variable
// search for a function ...
@@ -1086,7 +1083,7 @@ static Standard_Real ParseValue(char*& name)
x = 0;
}
else
x = atof(theCommands.Result());
x = Atof(theCommands.Result());
theCommands.Reset();
if (sv) {
theCommands << sv;