-// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
#include "HDFOI.hxx"
+#include "Basics_Utils.hxx"
+
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
//============================================================================
bool HDFascii::isASCII(const char* thePath) {
int fd;
+#if defined(WIN32) && defined(UNICODE)
+ const wchar_t * aPath = Kernel_Utils::utf8_decode(thePath);
+ fd = _wopen(aPath, O_RDONLY);
+ if (fd == -1) return false;
+#else
if(!(fd = open(thePath, O_RDONLY))) return false;
+#endif
char* aBuffer = new char[9];
aBuffer[8] = (char)0;
read(fd, aBuffer, 8);
close(fd);
-
bool res = (strcmp(aBuffer, ASCIIHDF_ID) == 0);
-
delete [] aBuffer;
return res;
return NULL;
}
- int length = strlen(aPath.c_str());
+ size_t length = strlen(aPath.c_str());
char *new_str = new char[ 1+length ];
strcpy(new_str , aPath.c_str()) ;
delete [] name;
hdf_dataset->GetDim(dim);
- fprintf(fp, " %i\n", ndim);
+ fprintf(fp, " %li\n", ndim);
for(int i = 0;i < ndim;i++) {
- fprintf(fp, " %i", dim[i]);
+ fprintf(fp, " %lu", (unsigned long)dim[i]);
}
fprintf(fp, "\n");
array->GetDim(arr_dim);
for( int i = 0;i < arr_ndim; i++ ) {
- fprintf(fp, " %i", arr_dim[i]);
+ fprintf(fp, " %lu", (unsigned long)arr_dim[i]);
}
//And write the data array
// function : SaveAttributeInASCIIfile
// purpose :
//============================================================================
-void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int ident)
+void SaveAttributeInASCIIfile(HDFattribute *hdf_attribute, FILE* fp, int /*ident*/)
{
hdf_attribute->OpenOnDisk();
hdf_type type = hdf_attribute->GetType();
char* name = makeName(hdf_attribute->GetName());
- int size = hdf_attribute->GetSize();
+ size_t size = hdf_attribute->GetSize();
fprintf(fp, "%s\n", ATTRIBUTE_ID);
- fprintf(fp, "%s %i %i\n", name, type, size);
+ fprintf(fp, "%s %i %lu\n", name, type, size);
delete [] name;
return NULL;
}
- int length = strlen(aTmpDir.c_str());
+ size_t length = strlen(aTmpDir.c_str());
char *new_str = new char[ 1+length ];
strcpy(new_str , aTmpDir.c_str()) ;
bool CreateDatasetFromASCII(HDFcontainerObject *father, FILE *fp)
{
char name[HDF_NAME_MAX_LEN+1];
- hdf_type type;
- hdf_byte_order order;
+ int type;
+ int order;
int nbDim, nbAttr;
long i, size;
HDFarray* anArray = 0;
if( type == HDF_ARRAY ){
//Get array information
- hdf_type arr_data_type;
+ int arr_data_type;
int arr_ndim;
fscanf(fp, "%c", &tmp);
fscanf(fp, " %i\n", &arr_data_type ); //Get array data type
fscanf(fp, " %i", &tdim);
arr_dim[i] = tdim;
}
- anArray = new HDFarray(0, arr_data_type, arr_ndim, arr_dim);
+ anArray = new HDFarray(0, (hdf_type)arr_data_type, arr_ndim, arr_dim);
anArray->CreateOnDisk();
type = arr_data_type;
delete [] arr_dim;
}
- HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : type, sizeArray, nbDim, order);
+ HDFdataset* hdf_dataset = new HDFdataset(new_name, father, anArray ? HDF_ARRAY : (hdf_type)type, sizeArray, nbDim, (hdf_byte_order)order);
if(anArray)
hdf_dataset->SetArrayId(anArray->GetId());
} else if(type == HDF_CHAR) {
hdf_char* val = new hdf_char[size];
for(i=0; i<size; i++) {
- fscanf(fp, " %i", &(val[i]));
+ fscanf(fp, " %c", &(val[i]));
}
hdf_dataset->WriteOnDisk(val);
delete [] val;
{
char name[HDF_NAME_MAX_LEN+1];
- hdf_type type;
+ int type;
int size;
fscanf(fp, "%s %i %i\n", name, &type, &size);
char* new_name = restoreName(name);
- HDFattribute* hdf_attribute = new HDFattribute(new_name, father, type, size);
+ HDFattribute* hdf_attribute = new HDFattribute(new_name, father, (hdf_type)type, size);
hdf_attribute->CreateOnDisk();
{
//Find a temporary directory to store a file
std::string aTmpDir;
+#if defined(UNICODE)
+ wchar_t *Tmp_dir = _wgetenv(L"SALOME_TMP_DIR");
+#else
char *Tmp_dir = getenv("SALOME_TMP_DIR");
+#endif
if(Tmp_dir != NULL) {
+#if defined(UNICODE)
+ aTmpDir = Kernel_Utils::utf8_encode_s(Tmp_dir);
+#else
aTmpDir = std::string(Tmp_dir);
+#endif
if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator;
}
else {
}
#ifdef WIN32
+#if defined(UNICODE)
+ std::wstring aTmpDirToCreate = Kernel_Utils::utf8_decode_s(aTmpDir);
+ std::wstring aDirToCreate = Kernel_Utils::utf8_decode_s(aDir);
+#else
+ std::string aTmpDirToCreate = aTmpDir;
+ std::string aDirToCreate = aDir;
+#endif
//function CreateDirectory create only final directory, but not intermediate
- CreateDirectory(aTmpDir.c_str(), NULL);
- CreateDirectory(aDir.c_str(), NULL);
+ CreateDirectory(aTmpDirToCreate.c_str(), NULL);
+ CreateDirectory(aDirToCreate.c_str(), NULL);
#else
mkdir(aDir.c_str(), 0x1ff);
#endif
char* makeName(char* name)
{
std::string aName(name), aNewName;
- int i, length = aName.size();
+ size_t i, length = aName.size();
char replace = (char)19;
for(i=0; i<length; i++) {
char* restoreName(char* name)
{
std::string aName(name), aNewName;
- int i, length = aName.size();
+ size_t i, length = aName.size();
char replace = (char)19;
for(i=0; i<length; i++) {
void write_float64(FILE* fp, hdf_float64* value)
{
unsigned char* array = (unsigned char*)value;
- for(int i = 0; i < sizeof(hdf_float64); i++) {
+ for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
unsigned tmp = (unsigned short)array[i];
fprintf(fp, " %2x", tmp);
}
void read_float64(FILE* fp, hdf_float64* value)
{
unsigned char* array = (unsigned char*)value;
- for(int i = 0; i < sizeof(hdf_float64); i++) {
+ for(int i = 0; i < (int)sizeof(hdf_float64); i++) {
unsigned tmp;
fscanf(fp, " %x", &tmp);
array[i] = (unsigned char)tmp;
bool Exists(const std::string thePath)
{
#ifdef WIN32
- if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) {
+#if defined(UNICODE)
+ std::wstring aPathToCheck = Kernel_Utils::utf8_decode_s( thePath );
+#else
+ std::string aPathToCheck = thePath;
+#endif
+ if ( GetFileAttributes ( aPathToCheck.c_str() ) == 0xFFFFFFFF ) {
DWORD errorId = GetLastError ();
if ( errorId == ERROR_FILE_NOT_FOUND || errorId == ERROR_PATH_NOT_FOUND )
return false;
void Move(const std::string& fName, const std::string& fNameDst)
{
#ifdef WIN32
- MoveFileEx (fName.c_str(), fNameDst.c_str(),MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
+#if defined(UNICODE)
+ std::wstring fNameToMove = Kernel_Utils::utf8_decode_s( fName );
+ std::wstring fNameDestination = Kernel_Utils::utf8_decode_s( fNameDst );
+#else
+ std::string fNameToMove = fName;
+ std::string fNameDestination = fNameDst;
+#endif
+ MoveFileEx ( fNameToMove.c_str(), fNameDestination.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
#else
- rename(fName.c_str(), fNameDst.c_str());
+ rename( fName.c_str(), fNameDst.c_str() );
#endif
}