rename only with 'new'
Allan CORNET [Mon, 24 Aug 2009 11:04:06 +0000 (13:04 +0200)]
scilab/modules/output_stream/sci_gateway/cpp/sci_diary.cpp
scilab/modules/output_stream/src/cpp/Diary.cpp
scilab/modules/output_stream/src/cpp/Diary.hxx
scilab/modules/output_stream/src/cpp/DiaryList.cpp
scilab/modules/output_stream/src/cpp/DiaryList.hxx
scilab/modules/output_stream/src/cpp/diary_manager.cpp
scilab/modules/output_stream/src/cpp/diary_manager.hxx
scilab/modules/output_stream/src/cpp/getFullFilename.cpp

index 4f3a5ae..30f44c6 100644 (file)
@@ -207,7 +207,7 @@ static int sci_diary_one_rhs(char *fname)
                {
                        if (diaryExists(wcFilenames[0]))
                        {
-                               double dID = (double)diaryNew(wcFilenames[0]);
+                               double dID = (double)diaryNew(wcFilenames[0], false);
                                if (dID == -1)
                                {
                                        char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
@@ -1069,7 +1069,7 @@ static int NewByFilenames(char *fname,
 
        if (dIDs_size == 1)
        {
-               double dID = (double)diaryNew(wcFilenames[0]);
+               double dID = (double)diaryNew(wcFilenames[0], true);
                if (dID == -1)
                {
                        char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
index b33d863..6a45ed8 100644 (file)
@@ -22,11 +22,20 @@ extern "C"
 #include "MALLOC.h"
 }
 /*--------------------------------------------------------------------------*/ 
-Diary::Diary(std::wstring _wfilename,int _mode,int ID)
+Diary::Diary(std::wstring _wfilename,int _mode,int ID, bool autorename)
 {
        std::ios::openmode wofstream_mode = std::ios::trunc | std::ios::binary;
 
-       std::wstring uniquefullfilename = getUniqueFilename(_wfilename);
+       std::wstring fullfilename = getUniqueFilename(_wfilename);
+       if (autorename)
+       {
+               fullfilename = getUniqueFilename(_wfilename);
+       }
+       else
+       {
+               fullfilename = getFullFilename(_wfilename);
+       }
+
 
        suspendwrite = false;
 
@@ -44,9 +53,9 @@ Diary::Diary(std::wstring _wfilename,int _mode,int ID)
        }
 
 #ifdef _MSC_VER
-       std::wofstream fileDiary(uniquefullfilename.c_str(),wofstream_mode);
+       std::wofstream fileDiary(fullfilename.c_str(),wofstream_mode);
 #else
-       wchar_t *wcfile = (wchar_t*)uniquefullfilename.c_str();
+       wchar_t *wcfile = (wchar_t*)fullfilename.c_str();
        char *filename = wide_string_to_UTF8(wcfile);
 
        std::ofstream fileDiary(filename, wofstream_mode);
@@ -62,7 +71,7 @@ Diary::Diary(std::wstring _wfilename,int _mode,int ID)
        }
        else
        {
-               wfilename = uniquefullfilename;
+               wfilename = fullfilename;
                fileAttribMode = wofstream_mode;
                setID(ID);
        }
index d9af5ea..9fbd286 100644 (file)
@@ -48,7 +48,7 @@ public:
        /*
        * constructor
        */
-       Diary(std::wstring _wfilename,int _mode,int ID);
+       Diary(std::wstring _wfilename,int _mode,int ID, bool autorename);
 
        /*
        * destructor
index c634507..9d57f09 100644 (file)
@@ -23,15 +23,15 @@ DiaryList::~DiaryList()
        closeAllDiaries();
 }
 /*--------------------------------------------------------------------------*/ 
-int DiaryList::openDiary(std::wstring _wfilename)
+int DiaryList::openDiary(std::wstring _wfilename, bool autorename)
 {
-       return openDiary(_wfilename,0);
+       return openDiary(_wfilename, 0, autorename);
 }
 /*--------------------------------------------------------------------------*/ 
-int DiaryList::openDiary(std::wstring _wfilename,int _mode)
+int DiaryList::openDiary(std::wstring _wfilename,int _mode, bool autorename)
 {
        int ID = -1;
-       Diary newDiary(_wfilename, _mode,findFreeID());
+       Diary newDiary(_wfilename, _mode, findFreeID(), autorename);
        if (newDiary.getID() != -1)
        {
                LSTDIARY.push_back(newDiary);
index 634b7ea..d1132ed 100644 (file)
@@ -29,8 +29,8 @@ public:
        ~DiaryList();
 
        /* open a diary */
-       int openDiary(std::wstring _wfilename,int _mode);
-       int openDiary(std::wstring _wfilename);
+       int openDiary(std::wstring _wfilename,int _mode, bool autorename);
+       int openDiary(std::wstring _wfilename, bool autorename);
 
        /* close a diary by ID */
        bool closeDiary(int ID_diary);
index 3e1a899..96533e1 100644 (file)
@@ -222,13 +222,13 @@ int diaryExists(wchar_t *filename)
        return 1;
 }
 /*--------------------------------------------------------------------------*/
-int diaryNew(wchar_t *filename)
+int diaryNew(wchar_t *filename, bool autorename)
 {
        createDiaryManager();
 
        if (SCIDIARY)
        {
-               return SCIDIARY->openDiary(std::wstring(filename));
+               return SCIDIARY->openDiary(std::wstring(filename),autorename);
        }
 
        return -1;
@@ -239,7 +239,7 @@ int diaryAppend(wchar_t *filename)
        createDiaryManager();
        if (SCIDIARY)
        {
-               return SCIDIARY->openDiary(std::wstring(filename),1);
+               return SCIDIARY->openDiary(std::wstring(filename),1,false);
        }
        return -1;
 }
index 67cd80b..aae4373 100644 (file)
@@ -123,7 +123,7 @@ int diaryExists(wchar_t *filename);
 * @param[in] filename
 * @return ID or -1 (NOK)
 */
-int diaryNew(wchar_t *filename);
+int diaryNew(wchar_t *filename, bool autorename);
 
 /**
 * append to a diary
index e83db84..4069b6e 100644 (file)
@@ -211,14 +211,7 @@ static int GetFileSize(std::wstring _wfilename)
        if (_filename == NULL) return false;
        ifstream file(_filename);
 #endif
-       int size = 0;
-       while (!file.eof()) 
-       {
-               file.get();
-               size++;
-       }
-       file.close();
-       delete file;
-       return size;
+       file.seekg(std::ios::end); 
+       return (int)file.tellg();
 }
 /*--------------------------------------------------------------------------*/