mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
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
155 lines
4.7 KiB
C++
Executable File
155 lines
4.7 KiB
C++
Executable File
// Copyright (c) 1999-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.
|
|
|
|
//#52 rln 23.12.98
|
|
#include <Interface_FloatWriter.ixx>
|
|
#include <stdio.h>
|
|
|
|
|
|
Interface_FloatWriter::Interface_FloatWriter (const Standard_Integer chars)
|
|
{
|
|
SetDefaults(chars);
|
|
}
|
|
|
|
// .... Controle d Envoi des Flottants ....
|
|
|
|
void Interface_FloatWriter::SetFormat
|
|
(const Standard_CString form, const Standard_Boolean reset)
|
|
{
|
|
strcpy(themainform,form);
|
|
if (!reset) return;
|
|
therange1 = therange2 = 0.; // second form : inhibee
|
|
thezerosup = Standard_False;
|
|
}
|
|
|
|
void Interface_FloatWriter::SetFormatForRange
|
|
(const Standard_CString form,
|
|
const Standard_Real R1, const Standard_Real R2)
|
|
{
|
|
strcpy(therangeform,form);
|
|
therange1 = R1;
|
|
therange2 = R2;
|
|
}
|
|
|
|
void Interface_FloatWriter::SetZeroSuppress (const Standard_Boolean mode)
|
|
{ thezerosup = mode; }
|
|
|
|
void Interface_FloatWriter::SetDefaults (const Standard_Integer chars)
|
|
{
|
|
if (chars <= 0) {
|
|
strcpy(themainform ,"%E");
|
|
strcpy(therangeform ,"%f");
|
|
} else {
|
|
char pourcent = '%'; char point = '.';
|
|
Sprintf(themainform, "%c%d%c%dE",pourcent,chars+2,point,chars);
|
|
Sprintf(therangeform, "%c%d%c%df",pourcent,chars+2,point,chars);
|
|
}
|
|
therange1 = 0.1; therange2 = 1000.;
|
|
thezerosup = Standard_True;
|
|
}
|
|
|
|
void Interface_FloatWriter::Options
|
|
(Standard_Boolean& zerosup, Standard_Boolean& range,
|
|
Standard_Real& R1, Standard_Real& R2) const
|
|
{
|
|
zerosup = thezerosup;
|
|
range = (therange2 >= therange1 && therange1 >= 0.);
|
|
R1 = therange1;
|
|
R2 = therange2;
|
|
}
|
|
|
|
Standard_CString Interface_FloatWriter::MainFormat () const
|
|
{ const Standard_CString mainform = Standard_CString(&themainform[0]); return mainform; }
|
|
|
|
Standard_CString Interface_FloatWriter::FormatForRange () const
|
|
{ const Standard_CString rangeform = Standard_CString(&therangeform[0]); return rangeform; }
|
|
|
|
// ########################################################################
|
|
|
|
Standard_Integer Interface_FloatWriter::Write
|
|
(const Standard_Real val, const Standard_CString text) const
|
|
{
|
|
const Standard_CString mainform = Standard_CString(themainform);
|
|
const Standard_CString rangeform = Standard_CString(therangeform);
|
|
return Convert
|
|
(val,text,thezerosup,therange1,therange2,mainform,rangeform);
|
|
}
|
|
|
|
//=======================================================================
|
|
//function : Convert
|
|
//purpose :
|
|
//=======================================================================
|
|
Standard_Integer Interface_FloatWriter::Convert (const Standard_Real val,
|
|
const Standard_CString text,
|
|
const Standard_Boolean zsup,
|
|
const Standard_Real R1,
|
|
const Standard_Real R2,
|
|
const Standard_CString mainform,
|
|
const Standard_CString rangeform)
|
|
{
|
|
// Valeur flottante, expurgee de "0000" qui trainent et de "E+00"
|
|
// char lval[20];
|
|
char lxp[6], *pText;
|
|
int i0,j0=0;
|
|
|
|
lxp[0] = lxp[4] = '\0';
|
|
pText=(char *)text;
|
|
//
|
|
if ( (val >= R1 && val < R2) ||
|
|
(val <= -R1 && val > -R2) ) {
|
|
Sprintf(pText,rangeform,val);
|
|
}
|
|
else {
|
|
Sprintf(pText,mainform,val);
|
|
}
|
|
|
|
if (zsup) {
|
|
for (int i = 0; i < 16; i ++) {
|
|
i0 = i;
|
|
if (text[i] == 'e' || text[i] == 'E') {
|
|
lxp[0] = 'E';
|
|
lxp[1] = text[i+1];
|
|
lxp[2] = text[i+2];
|
|
lxp[3] = text[i+3];
|
|
lxp[4] = text[i+4];
|
|
if (lxp[1] == '+' && lxp[2] == '0' && lxp[3] == '0' && lxp[4] == '\0') {
|
|
lxp[0] = '\0';
|
|
}
|
|
pText[i] = '\0';
|
|
}
|
|
if (text[i] == '\0') {
|
|
break;
|
|
}
|
|
}
|
|
//#52 rln 23.12.98 converting 1e-07 throws exception
|
|
for (int j = i0-1; j >= 0; j --) {
|
|
j0 = j;
|
|
if (text[j] != '0') {
|
|
break;
|
|
}
|
|
pText[j] = '\0';
|
|
}
|
|
pText[j0+1] = lxp[0];
|
|
pText[j0+2] = lxp[1];
|
|
pText[j0+3] = lxp[2];
|
|
pText[j0+4] = lxp[3];
|
|
pText[j0+5] = lxp[4];
|
|
pText[j0+6] = '\0';
|
|
}
|
|
return strlen(text);
|
|
}
|