diary enabled on linux (to check on windows ...)
Allan CORNET [Fri, 21 Aug 2009 13:12:12 +0000 (15:12 +0200)]
scilab/modules/output_stream/src/cpp/Diary.cpp
scilab/modules/output_stream/src/cpp/getFullFilename.cpp

index 4309e6f..4ff9ac0 100644 (file)
@@ -40,23 +40,63 @@ Diary::Diary(std::wstring _wfilename,int _mode,int ID)
        {
                wofstream_mode = std::ios::app | std::ios::binary ;
        }
+#ifdef _MSC_VER
+       std::wofstream fileDiary(getFullFilename(_wfilename).c_str(),wofstream_mode);
+       if ( fileDiary.bad())
+       {
+               wfilename = std::wstring(L"");
+               fileAttribMode = -1;
+               setID(-1);
+       }
+       else
+       {
+               wfilename = getFullFilename(_wfilename);
+               fileAttribMode = wofstream_mode;
+               setID(ID);
+       }
+       fileDiary.close();
 
-//     std::wofstream fileDiary(getFullFilename(_wfilename).c_str(),wofstream_mode);
+#else
+       std::wstring wstrfile = getFullFilename(_wfilename);
+       wchar_t *wcfile = (wchar_t*)wstrfile.c_str();
+       char *filename = wide_string_to_UTF8(wcfile);
 
-       if ( /*fileDiary.bad()*/ 1 )
+       if (_mode == 0)
        {
+               std::ofstream fileDiary(filename,  std::ios::trunc | std::ios::binary) ;
+               if ( fileDiary.bad())
+               {
                wfilename = std::wstring(L"");
                fileAttribMode = -1;
                setID(-1);
+               }
+               else
+               {
+               wfilename = getFullFilename(_wfilename);
+               fileAttribMode = wofstream_mode;
+               setID(ID);
+               }       
+       fileDiary.close();
        }
        else
        {
+               std::ofstream fileDiary(filename, std::ios::app | std::ios::binary );
+               if ( fileDiary.bad())
+               {
+               wfilename = std::wstring(L"");
+               fileAttribMode = -1;
+               setID(-1);
+               }
+               else
+               {
                wfilename = getFullFilename(_wfilename);
                fileAttribMode = wofstream_mode;
                setID(ID);
+               }
+       fileDiary.close();
        }
+#endif
 
-//     fileDiary.close();
 }
 /*--------------------------------------------------------------------------*/ 
 Diary::~Diary()
@@ -75,8 +115,14 @@ void Diary::write(std::wstring _wstr, bool bInput)
 {
        if (!suspendwrite)
        {
-//             std::wofstream fileDiary(wfilename.c_str(),std::ios::app | std::ios::binary );
-               if (/*fileDiary.good() */ 1)
+#ifdef _MSC_VER
+               std::wofstream fileDiary(wfilename.c_str(),std::ios::app | std::ios::binary );
+#else
+               wchar_t *wcfile = (wchar_t*)wfilename.c_str();
+               char *filename = wide_string_to_UTF8(wcfile);
+               std::ofstream fileDiary(filename, std::ios::app | std::ios::binary);
+#endif
+               if (fileDiary.good())
                {
                        char *line = NULL;
 
@@ -95,11 +141,11 @@ void Diary::write(std::wstring _wstr, bool bInput)
                                                char *timeInfo = wide_string_to_UTF8((wchar_t*)getDiaryDate(Prefixmode).c_str());
                                                if (timeInfo) 
                                                {
-                                               //      fileDiary << timeInfo << " ";
+                                                       fileDiary << timeInfo << " ";
                                                        FREE(timeInfo); timeInfo = NULL;
                                                }
                                        }
-//                                     if (line) fileDiary << line;
+                                       if (line) fileDiary << line;
                                }
                        }
                        else // output
@@ -111,11 +157,11 @@ void Diary::write(std::wstring _wstr, bool bInput)
                                                char *timeInfo = wide_string_to_UTF8((wchar_t*)getDiaryDate(Prefixmode).c_str());
                                                if (timeInfo) 
                                                {
-//                                                     fileDiary << timeInfo << " ";
+                                                       fileDiary << timeInfo << " ";
                                                        FREE(timeInfo); timeInfo = NULL;
                                                }
                                        }
-//                                     if (line) fileDiary << line;
+                                       if (line) fileDiary << line;
                                }
                        }
 
index d8a0798..9f90a44 100644 (file)
@@ -20,19 +20,22 @@ extern "C"
 {
 #include "machine.h"
 #include "PATH_MAX.h"
+#include "MALLOC.h"
+#include "charEncoding.h"
 }
 /*--------------------------------------------------------------------------*/ 
 static void wcsplitpath(const wchar_t* path, wchar_t* drv, wchar_t* dir, wchar_t* name, wchar_t* ext);
 /*--------------------------------------------------------------------------*/ 
 std::wstring getFullFilename(std::wstring _wfilename)
 {
-       std::wstring wfullfilename(L"");
-       std::wstring tmpWstr;
        wchar_t wcdrive[1024];
        wchar_t wcdirectory[1024];
        wchar_t wcname[1024];
        wchar_t wcext [1024];
 
+       std::wstring wfullfilename(L"");
+       std::wstring tmpWstr;
+
        size_t found = _wfilename.rfind(L"\\");
 
        while (found != std::wstring::npos)
@@ -45,14 +48,21 @@ std::wstring getFullFilename(std::wstring _wfilename)
        wfullfilename.append(tmpWstr.assign(wcdirectory));
        if (wfullfilename.compare(L"") == 0)
        {
-               wchar_t wcCurrentDir[1024];
 #if _MSC_VER
+               wchar_t wcCurrentDir[1024];
                if ( _wgetcwd(wcCurrentDir, PATH_MAX) != NULL)
 #else
-               if (/*getcwd(wcCurrentDir,1024) != NULL*/ 1)
+               char CurrentDir[1024];
+               if (getcwd(CurrentDir,1024) != NULL)
 #endif
                {
+#if _MSC_VER           
                        wfullfilename = tmpWstr.assign(wcCurrentDir);
+#else
+                       wchar_t *wcCurrentDir = to_wide_string(CurrentDir);
+                       wfullfilename = tmpWstr.assign(wcCurrentDir);
+                       FREE(wcCurrentDir);
+#endif
                        size_t found = wfullfilename.rfind(L"\\");
                        while (found != std::wstring::npos)
                        {
@@ -65,7 +75,9 @@ std::wstring getFullFilename(std::wstring _wfilename)
                {
                        wfullfilename.assign(L"");
                }
-
+#ifndef _MSC_VER
+               //if (CurrentDir) {FREE(CurrentDir); CurrentDir = NULL;}
+#endif
        }
        wfullfilename.append(tmpWstr.assign(wcname));
        wfullfilename.append(tmpWstr.assign(wcext));