From 5aad6908a36c695ae23eaaa0635d1907e1e1e97b Mon Sep 17 00:00:00 2001 From: abv Date: Fri, 18 Sep 2015 09:25:55 +0300 Subject: [PATCH] Fixing regressions (CmpFile only): - Returned lost setting of precision and locale in file stream - Disable FSD_CmpFile::FlushEndOfLine() to avoid eating lines - Reimplement writing reals to keep precision (and simplified other types) --- src/FSD/FSD_CmpFile.cxx | 74 ++++++++++++------------------------ src/FSD/FSD_File.cxx | 42 -------------------- src/Storage/Storage_File.cxx | 2 + 3 files changed, 26 insertions(+), 92 deletions(-) diff --git a/src/FSD/FSD_CmpFile.cxx b/src/FSD/FSD_CmpFile.cxx index 3e669590cf..a5303f5158 100644 --- a/src/FSD/FSD_CmpFile.cxx +++ b/src/FSD/FSD_CmpFile.cxx @@ -176,8 +176,8 @@ const Standard_CString FSD_CmpFile::MagicNumber() void FSD_CmpFile::FlushEndOfLine() { - TCollection_AsciiString aDummy; - ReadLine (aDummy); // flush is nothing more than to read till the line-break +// TCollection_AsciiString aDummy; +// ReadLine (aDummy); // flush is nothing more than to read till the line-break /* static char Buffer[8192]; char c; @@ -235,9 +235,9 @@ void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer) { buffer += '\0'; IsEnd = Standard_True; + } } } -} //======================================================================= //function : WriteExtendedLine @@ -422,10 +422,7 @@ void FSD_CmpFile::SkipObject() Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue) { - TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) - Storage_StreamWriteError::Raise(); - return *this; + return PutInteger (aValue); } //======================================================================= @@ -435,12 +432,7 @@ Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue) Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue) { - Standard_Integer i = aValue; - TCollection_AsciiString aStr = TCollection_AsciiString( i ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) - Storage_StreamWriteError::Raise(); - - return *this; + return PutInteger (aValue); } //======================================================================= @@ -450,12 +442,7 @@ Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue) Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue) { - Standard_Integer i = aValue; - TCollection_AsciiString aStr = TCollection_AsciiString( i ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) - Storage_StreamWriteError::Raise(); - - return *this; + return PutInteger (aValue); } //======================================================================= @@ -465,8 +452,9 @@ Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aVa Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue) { - TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) + char buffer[256]; + Standard_Size aLen = sprintf (buffer, "%d ", aValue); + if ( Device()->Write (buffer, aLen ) != aLen ) Storage_StreamWriteError::Raise(); return *this; @@ -479,8 +467,11 @@ Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue) Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue) { - TCollection_AsciiString aStr = TCollection_AsciiString( (Standard_Integer)aValue ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) + char buffer[3]; + buffer[0] = (aValue ? '1' : '0'); + buffer[1] = ' '; + buffer[2] = '\0'; + if ( Device()->Write (buffer, 2) != 2 ) Storage_StreamWriteError::Raise(); return *this; @@ -493,8 +484,9 @@ Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue) Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue) { - TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) + char buffer[256]; + Standard_Size aLen = sprintf (buffer, "%.17g ", aValue); + if ( Device()->Write (buffer, aLen ) != aLen ) Storage_StreamWriteError::Raise(); return *this; @@ -507,8 +499,9 @@ Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue) Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue) { - TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " "; - if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() ) + char buffer[256]; + Standard_Size aLen = sprintf (buffer, "%.8g ", (double)aValue); + if ( Device()->Write (buffer, aLen ) != aLen ) Storage_StreamWriteError::Raise(); return *this; @@ -1241,29 +1234,10 @@ Storage_Error FSD_CmpFile::BeginReadDataSection() void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef, Standard_Integer& aType) { - char c; - - Device()->Read( (Standard_Address)&c, sizeof( char ) ); - - while (c != '#') { - if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) { - Storage_StreamFormatError::Raise(); - } - Device()->Read( (Standard_Address)&c, sizeof( char ) ); - } - - GetInteger (aRef); - - Device()->Read( (Standard_Address)&c, sizeof( char ) ); - - while (c != '%') { - if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) { - Storage_StreamFormatError::Raise(); - } - Device()->Read( (Standard_Address)&c, sizeof( char ) ); - } - - GetInteger (aType); + TCollection_AsciiString buffer; + ReadWord (buffer); + if (sscanf (buffer.ToCString(), "#%d%%%d", &aRef, &aType) !=2) + Storage_StreamFormatError::Raise(); } //======================================================================= diff --git a/src/FSD/FSD_File.cxx b/src/FSD/FSD_File.cxx index d120154996..c99b5a778f 100644 --- a/src/FSD/FSD_File.cxx +++ b/src/FSD/FSD_File.cxx @@ -73,48 +73,6 @@ Storage_Error FSD_File::Open(const Handle(Storage_IODevice)& aDevice, const Stor return Storage_VSOpenError; return Device()->Open(aMode); - /* - Storage_Error result = Storage_VSOk; - - if (OpenMode() == Storage_VSNone) { - -#ifdef _WIN32 - TCollection_ExtendedString aWName(aName); - if (aMode == Storage_VSRead) { - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in); // ios::nocreate is not portable - } - else if (aMode == Storage_VSWrite) { - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::out); - } - else if (aMode == Storage_VSReadWrite) { - myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in|ios::out); -#else - if (aMode == Storage_VSRead) { - myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable - } - else if (aMode == Storage_VSWrite) { - myStream.open(aName.ToCString(),ios::out); - } - else if (aMode == Storage_VSReadWrite) { - myStream.open(aName.ToCString(),ios::in|ios::out); -#endif - } - - if (myStream.fail()) { - result = Storage_VSOpenError; - } - else { - myStream.precision(17); - myStream.imbue (std::locale::classic()); // use always C locale - SetOpenMode(aMode); - } - } - else { - result = Storage_VSAlreadyOpen; - } - - return result; - */ } //======================================================================= diff --git a/src/Storage/Storage_File.cxx b/src/Storage/Storage_File.cxx index 5e8cdcb31e..66c10dbfd6 100644 --- a/src/Storage/Storage_File.cxx +++ b/src/Storage/Storage_File.cxx @@ -99,6 +99,8 @@ Storage_Error Storage_File::Open (const Storage_OpenMode theMode) } else { + myStream.precision(17); + myStream.imbue (std::locale::classic()); // use always C locale SetOpenMode (theMode); } } -- 2.39.5