Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / DriverGMF / libmesh5.c
index c7d6c52ea5fd3e8fec7c5f296a094557fd8fe4ab..e1fe65fb66ccda79f0619cb8013b79d0a407badc 100644 (file)
@@ -26,7 +26,9 @@
 #include <math.h>
 #include <ctype.h>
 #include "libmesh5.h"
-
+#ifdef WIN32
+#include <windows.h>
+#endif
 
 /*----------------------------------------------------------*/
 /* Defines                                                                                                      */
@@ -76,6 +78,7 @@ typedef struct
 
 static int GmfIniFlg=0;
 static GmfMshSct *GmfMshTab[ MaxMsh + 1 ];
+/* see MeshGems/Docs/meshgems_formats_description.pdf */
 static const char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = 
 {       {"Reserved", "", "", ""},
         {"MeshVersionFormatted", "", "", "i"},
@@ -157,7 +160,8 @@ static const char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] =
         {"Iterations", "","","i"},
         {"Time", "","","r"},
         {"Fault_SmallTri", "Fault_SmallTri","i","i"},
-        {"CoarseHexahedra", "CoarseHexahedron", "i", "i"}
+        {"CoarseHexahedra", "CoarseHexahedron", "i", "i"},
+        {"Fault_MultipleEdge", "Fault_MultipleEdge", "i", "i"}
  };
 
 
@@ -190,7 +194,10 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
         GmfMshSct *msh;
         char *ptr;
         int k;
-
+#if defined(WIN32) && defined(UNICODE)
+               wchar_t* encoded = 0;
+               int size_needed = 0;
+#endif
         if(!GmfIniFlg)
         {
                 for(i=0;i<=MaxMsh;i++)
@@ -262,13 +269,27 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
                 va_end(VarArg);
 
                 /* Create the name string and open the file */
-
-                if(!(msh->hdl = fopen(msh->FilNam, "rb")))
+#if defined(WIN32) && defined(UNICODE)
+                               size_needed = MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), NULL, 0);
+                               encoded = malloc((size_needed + 1)*sizeof(wchar_t));
+                               MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), encoded, size_needed);
+                               encoded[size_needed] = '\0';
+                               if (!(msh->hdl = _wfopen(encoded, L"rb")))
+#else
+                               if (!(msh->hdl = fopen(msh->FilNam, "rb")))
+#endif
                 {
                         free (msh);
+#if defined(WIN32) && defined(UNICODE)
+                                               free(encoded);
+#endif
                         return(0);
                 }
 
+#if defined(WIN32) && defined(UNICODE)
+                               free(encoded);
+#endif
+
                 /* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */
 
                 if(msh->typ & Bin)
@@ -401,13 +422,26 @@ int GmfOpenMesh(const char *FilNam, int mod, ...)
                 }
 
                 /* Create the mesh file */
-
+#if defined(WIN32) && defined(UNICODE)
+                               size_needed = MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), NULL, 0);
+                               encoded = malloc((size_needed + 1) * sizeof(wchar_t));
+                               MultiByteToWideChar(CP_UTF8, 0, msh->FilNam, strlen(msh->FilNam), encoded, size_needed);
+                               encoded[size_needed] = '\0';
+                               if (!(msh->hdl = _wfopen(encoded, L"wb")))
+#else
                 if(!(msh->hdl = fopen(msh->FilNam, "wb")))
+#endif
                 {
                         free (msh);
+#if defined(WIN32) && defined(UNICODE)
+                                               free(encoded);
+#endif
                         return(0);
                 }
 
+#if defined(WIN32) && defined(UNICODE)
+                               free(encoded);
+#endif
                 GmfMshTab[ MshIdx ] = msh;
 
 
@@ -841,7 +875,7 @@ void GmfSetLin(int MshIdx, int KwdCod, ...)
                         {
                                 for(i=0;i<kwd->SolSiz;i++)
                                         if(kwd->fmt[i] == 'r')
-                                                fprintf(msh->hdl, "%.15lg ", va_arg(VarArg, double));
+                                                fprintf(msh->hdl, "%.15lg ", va_arg(VarArg, double)); /* todo: ISO C90 does not support the '%lg' gnu_printf format */
                                         else if(kwd->fmt[i] == 'n') {
                                                 nb_repeat = va_arg(VarArg, int);
                                                 fprintf(msh->hdl, "%d ", nb_repeat);
@@ -902,7 +936,7 @@ void GmfSetLin(int MshIdx, int KwdCod, ...)
 
                         if(msh->typ & Asc)
                                 for(j=0;j<kwd->SolSiz;j++)
-                                        fprintf(msh->hdl, "%.15lg ", DblSolTab[j]);
+                                        fprintf(msh->hdl, "%.15lg ", DblSolTab[j]); /* todo: ISO C90 does not support the '%lg' gnu_printf format */
                         else
                                 RecBlk(msh, (unsigned char *)DblSolTab, kwd->NmbWrd);
                 }
@@ -1030,7 +1064,7 @@ static int ScaKwdTab(GmfMshSct *msh)
                         {
                                 /* Search which kwd code this string is associated with, 
                                         then get its header and save the current position in file (just before the data) */
-
+                                /* printf("libmesh ScaKwdTab %s\n", str); */
                                 for(KwdCod=1; KwdCod<= GmfMaxKwd; KwdCod++)
                                         if(!strcmp(str, GmfKwdFmt[ KwdCod ][0]))
                                         {
@@ -1157,7 +1191,7 @@ static void ExpFmt(GmfMshSct *msh, int KwdCod)
 
         i = kwd->SolSiz = kwd->NmbWrd = 0;
 
-        while(i < strlen(InpFmt))
+        while(i < (int)strlen(InpFmt))
         {
                 chr = InpFmt[ i++ ];