1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-21 10:55:33 +03:00
occt/src/OSD/OSD_OpenFile.cxx
kgv 7c65581dd3 0027197: Configuration - fix compilation issues when using mingw
AIS_ColorScale, AIS_Dimension - the protected method DrawText()
has been renamed to drawText() to avoid name collisions with macros.

_MSC_VER/_WIN32 misuse has been fixed in several places.
Header <malloc.h> is now included where alloca() is used.
Draw_Window - dllimport flag has been dropped from inline methods.

TKernel - mandatory dependencies Winspool.lib and Psapi.lib
are now linked explicitly (instead of msvc-specific pragma syntax).

CMake scripts - the option -std=c++0x has been replaced by -std=gnu++0x
for mingw to allow extensions (like _wfopen() and others).
The minimum Windows version has been set to _WIN32_WINNT=0x0501.
Invalid options "-z defs" and "-lm" have been dropped for mingw.
Flag --export-all-symbols has been added to CMAKE_SHARED_LINKER_FLAGS
to workaround missing vtable symbols when using mingw.
FreeType is now linked explicitly on Windows.

Draw::Load() - "lib" suffix is now prepended on mingw as well.

Drop redundant declaration of _TINT from OSD_WNT_1.hxx.
NCollection_UtfString::FromLocale() - platform-specific code has been moved to .cxx file.
Draw_BasicCommands - fixed incorrect mingw64 version macros.

genproj, cbp - added workaround for process argument list limits on Windows.
TKSTEP linkage is failing on this platform due to too long list of files.
The list of object files to link is now stored in dedicated file which is passed to gcc.

Option "-z defs" removed from CMake linker options to avoid problems when building with different configurations of VTK on Linux

Some MinGW-specific compiler warnings (potentially uninitialized vars, use of NULL, parentheses in conditional expressions) are fixed (speculatively)
2016-03-04 07:31:05 +03:00

163 lines
5.8 KiB
C++

// Copyright (c) 2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifdef _WIN32
#include <windows.h>
#endif
#include <OSD_OpenFile.hxx>
#include <TCollection_ExtendedString.hxx>
#include <NCollection_UtfString.hxx>
// ==============================================
// function : OSD_OpenFile
// purpose : Opens file
// ==============================================
FILE* OSD_OpenFile(const char* theName,
const char* theMode)
{
FILE* aFile = 0;
#if defined(_WIN32)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
aFile = ::_wfopen ((const wchar_t* )aFileNameW.ToExtString(),
(const wchar_t* )aFileModeW.ToExtString());
#else
aFile = ::fopen (theName, theMode);
#endif
return aFile;
}
// ==============================================
// function : OSD_OpenFile
// purpose : Opens file
// ==============================================
FILE* OSD_OpenFile(const TCollection_ExtendedString& theName,
const char* theMode)
{
FILE* aFile = 0;
#if defined(_WIN32)
const TCollection_ExtendedString aFileModeW (theMode, Standard_True);
aFile = ::_wfopen ((const wchar_t* )theName.ToExtString(),
(const wchar_t* )aFileModeW.ToExtString());
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
aFile = ::fopen (aString.ToCString(),theMode);
#endif
return aFile;
}
// ==============================================
// function : OSD_OpenFileBuf
// purpose : Opens file buffer
// ==============================================
void OSD_OpenFileBuf(std::filebuf& theBuff,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theBuff.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
#else
theBuff.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenFileBuf
// purpose : Opens file buffer
// ==============================================
void OSD_OpenFileBuf(std::filebuf& theBuff,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theBuff.open ((const wchar_t* )theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
theBuff.open (aString.ToCString(),theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream(std::ofstream& theStream,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theStream.open ((const wchar_t* )aFileNameW.ToExtString(), theMode);
#else
theStream.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream(std::ofstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theStream.open ((const wchar_t* )theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString((const Standard_Utf16Char*)theName.ToExtString());
theStream.open (aString.ToCString(),theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream (std::ifstream& theStream,
const char* theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
// file name is treated as UTF-8 string and converted to UTF-16 one
const TCollection_ExtendedString aFileNameW (theName, Standard_True);
theStream.open ((const wchar_t*)aFileNameW.ToExtString(), theMode);
#else
theStream.open (theName, theMode);
#endif
}
// ==============================================
// function : OSD_OpenStream
// purpose : Opens file stream
// ==============================================
void OSD_OpenStream (std::ifstream& theStream,
const TCollection_ExtendedString& theName,
const std::ios_base::openmode theMode)
{
#if defined(_WIN32) && defined(_MSC_VER)
theStream.open ((const wchar_t*)theName.ToExtString(), theMode);
#else
// conversion in UTF-8 for linux
NCollection_Utf8String aString ((const Standard_Utf16Char*)theName.ToExtString());
theStream.open (aString.ToCString(), theMode);
#endif
}