Merge remote-tracking branch 'origin/master' into windows
[scilab.git] / scilab / modules / output_stream / sci_gateway / cpp / sci_diary.cpp
index 3f26499..fa4b30a 100644 (file)
@@ -13,8 +13,9 @@
 *
 */
 /*--------------------------------------------------------------------------*/
-#include "diary_manager.hxx"
 /*--------------------------------------------------------------------------*/
+#include "diary_manager.hxx"
+
 extern "C"
 {
 #include "gw_output_stream.h"
@@ -26,20 +27,20 @@ extern "C"
 #include "freeArrayOfString.h"
 }
 /*--------------------------------------------------------------------------*/
-#define DIARY_SECOND_ARG_LIST L"list"
-#define DIARY_SECOND_ARG_CLOSE L"close"
-#define DIARY_SECOND_ARG_PAUSE L"pause"
-#define DIARY_SECOND_ARG_OFF L"off"
-#define DIARY_SECOND_ARG_RESUME L"resume"
-#define DIARY_SECOND_ARG_ON L"on"
-#define DIARY_SECOND_ARG_NEW L"new"
-#define DIARY_SECOND_ARG_APPEND L"append"
-#define DIARY_SECOND_ARG_EXISTS L"exists"
-#define DIARY_THIRD_ARG_FILTER_COMMAND L"filter=command"
-#define DIARY_THIRD_ARG_FILTER_OUTPUT L"filter=output"
-#define DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH L"prefix=U"
-#define DIARY_THIRD_ARG_PREFIX_DEFAULT L"prefix=YYYY-MM-DD hh:mm:ss"
-#define DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS L"prefix-only-commands"
+#define DIARY_SECOND_ARG_LIST "list"
+#define DIARY_SECOND_ARG_CLOSE "close"
+#define DIARY_SECOND_ARG_PAUSE "pause"
+#define DIARY_SECOND_ARG_OFF "off"
+#define DIARY_SECOND_ARG_RESUME "resume"
+#define DIARY_SECOND_ARG_ON "on"
+#define DIARY_SECOND_ARG_NEW "new"
+#define DIARY_SECOND_ARG_APPEND "append"
+#define DIARY_SECOND_ARG_EXISTS "exists"
+#define DIARY_THIRD_ARG_FILTER_COMMAND "filter=command"
+#define DIARY_THIRD_ARG_FILTER_OUTPUT "filter=output"
+#define DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH "prefix=U"
+#define DIARY_THIRD_ARG_PREFIX_DEFAULT "prefix=YYYY-MM-DD hh:mm:ss"
+#define DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS "prefix-only-commands"
 /*--------------------------------------------------------------------------*/
 static int sci_diary_no_rhs(char *fname, void* pvApiCtx);
 static int sci_diary_one_rhs(char *fname, void* pvApiCtx);
@@ -47,11 +48,11 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx);
 static int sci_diary_three_rhs(char *fname, void* pvApiCtx);
 /*--------------------------------------------------------------------------*/
 static double *getInputArgumentOneIDs(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror);
-static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror);
-static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror);
-static wchar_t **getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror);
+static char** getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror);
+static char* getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror);
+static char** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror);
 static int checkExistByIDs(char *fname, void* pvApiCtx, double *IDs, int size_IDs);
-static int checkExistByFilenames(char *fname, void* pvApiCtx, wchar_t **wcFilenames, int size_IDs);
+static int checkExistByFilenames(char *fname, void* pvApiCtx, char** filenames, int size_IDs);
 static int CloseByFilenames(char *fname, void* pvApiCtx);
 static int CloseByIds(char *fname, void* pvApiCtx);
 static int PauseByFilenames(char *fname, void* pvApiCtx);
@@ -96,9 +97,9 @@ static int sci_diary_no_rhs(char *fname, void* pvApiCtx)
     // [ids, filenames] = diary([],"list")
     SciErr sciErr;
     int nb_diary_ids = 0;
-    double *diary_ids  = getDiaryIDsAsDouble(&nb_diary_ids);
+    double *diary_ids = getDiaryIDsAsDouble(&nb_diary_ids);
 
-    if ( (diary_ids) && (nb_diary_ids > 0) )
+    if ((diary_ids) && (nb_diary_ids > 0))
     {
         sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, nb_diary_ids, 1, diary_ids);
         delete [] diary_ids;
@@ -128,7 +129,6 @@ static int sci_diary_no_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
             LhsVar(1) = Rhs + 1;
-
         }
         else
         {
@@ -140,12 +140,11 @@ static int sci_diary_no_rhs(char *fname, void* pvApiCtx)
     if (Lhs == 2)
     {
         int nb_diary_filenames = 0;
-        wchar_t **wcdiary_filenames = getDiaryFilenames(&nb_diary_filenames);
+        const char** diary_filenames = getDiaryFilenames(&nb_diary_filenames);
 
-        if ( (wcdiary_filenames) && (nb_diary_filenames > 0) )
+        if ((diary_filenames) && (nb_diary_filenames > 0))
         {
-            sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, nb_diary_filenames, 1, wcdiary_filenames);
-            freeArrayOfWideString(wcdiary_filenames, nb_diary_filenames);
+            sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, nb_diary_filenames, 1, diary_filenames);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
@@ -157,10 +156,6 @@ static int sci_diary_no_rhs(char *fname, void* pvApiCtx)
         }
         else
         {
-            if (wcdiary_filenames)
-            {
-                freeArrayOfWideString(wcdiary_filenames, nb_diary_filenames);
-            }
             if (nb_diary_filenames == 0)
             {
                 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 2, 0, 0, NULL);
@@ -189,7 +184,7 @@ static int sci_diary_no_rhs(char *fname, void* pvApiCtx)
 static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
 {
     SciErr sciErr;
-    int iType  = 0;
+    int iType = 0;
     int *piAddressVarOne = NULL;
 
     sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
@@ -221,8 +216,8 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
         // diary([])
         // diary(0)
         // close all
-        if ( (IDs_size == 0) ||
-                ((IDs_size == 1) && ((int)IDs[0] == 0)))
+        if ((IDs_size == 0) ||
+            ((IDs_size == 1) && ((int)IDs[0] == 0)))
         {
             diaryCloseAll();
             PutLhsVar();
@@ -235,32 +230,22 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
     else if (iType == sci_strings)
     {
         int ierr = 0;
-        int sizewcFilenames = 0;
-        wchar_t ** wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &sizewcFilenames, &ierr);
+        int sizeFilenames = 0;
+        char ** filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &sizeFilenames, &ierr);
         if (ierr)
         {
             return 0;
         }
 
-        if (sizewcFilenames == 1)
+        if (sizeFilenames == 1)
         {
-            if (diaryExists(wcFilenames[0]))
+            if (diaryExists(filenames[0]))
             {
-                double dID = (double)diaryNew(wcFilenames[0], false);
+                double dID = (double)diaryNew(filenames[0], false);
                 if (dID == -1)
                 {
-                    char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
-                    if (utf_str)
-                    {
-                        Scierror(999, _("%s: error can not create diary: %s.\n"), fname, utf_str);
-                        FREE(utf_str);
-                        utf_str = NULL;
-                    }
-                    else
-                    {
-                        Scierror(999, _("%s: error can not create diary.\n"), fname);
-                    }
-                    freeArrayOfWideString(wcFilenames, sizewcFilenames);
+                    Scierror(999, _("%s: error can not create diary: %s.\n"), fname, filenames[0]);
+                    freeArrayOfString(filenames, sizeFilenames);
                     return 0;
                 }
 
@@ -269,7 +254,7 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
                 {
                     printError(&sciErr, 0);
                     Scierror(999, _("%s: Memory allocation error.\n"), fname);
-                    freeArrayOfWideString(wcFilenames, sizewcFilenames);
+                    freeArrayOfString(filenames, sizeFilenames);
                     return 0;
                 }
 
@@ -277,40 +262,37 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
 
                 if (Lhs == 2)
                 {
-                    wchar_t **wfilenameUsed = new wchar_t*[1];
-                    wfilenameUsed[0] = getDiaryFilename((int)dID);
-                    sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
+                    const char* filenameUsed = getDiaryFilename((int)dID);
+                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, 1, 1, &filenameUsed);
                     if (sciErr.iErr)
                     {
                         printError(&sciErr, 0);
                         Scierror(999, _("%s: Memory allocation error.\n"), fname);
-                        freeArrayOfWideString(wcFilenames, sizewcFilenames);
+                        freeArrayOfString(filenames, sizeFilenames);
                         return 0;
                     }
 
                     LhsVar(2) = Rhs + 2;
-                    FREE(wfilenameUsed[0]);
-                    delete [] wfilenameUsed;
                 }
             }
             else // diary(filename) exists (close diary)
             {
-                if (diaryClose(wcFilenames[0]))
+                if (diaryClose(filenames[0]))
                 {
                     Scierror(999, _("%s: error can not close diary.\n"), fname);
-                    freeArrayOfWideString(wcFilenames, sizewcFilenames);
+                    freeArrayOfString(filenames, sizeFilenames);
                     return 0;
                 }
                 LhsVar(1) = 0;
             }
 
-            freeArrayOfWideString(wcFilenames, sizewcFilenames);
+            freeArrayOfString(filenames, sizeFilenames);
             PutLhsVar();
         }
         else
         {
             Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1);
-            freeArrayOfWideString(wcFilenames, sizewcFilenames);
+            freeArrayOfString(filenames, sizeFilenames);
         }
     }
     else
@@ -323,7 +305,7 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
 static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
 {
     int ierr = 0;
-    wchar_t *wcArgumentTwo = getInputArgumentTwo(fname, pvApiCtx, &ierr);
+    char *argumentTwo = getInputArgumentTwo(fname, pvApiCtx, &ierr);
     SciErr sciErr;
     int *piAddressVarOne = NULL;
 
@@ -332,8 +314,6 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
     {
         printError(&sciErr, 0);
         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-        FREE(wcArgumentTwo);
-        wcArgumentTwo = NULL;
         return 0;
     }
 
@@ -342,12 +322,11 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         return 0;
     }
 
-    if (wcArgumentTwo)
+    if (argumentTwo)
     {
-        if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_LIST) == 0)
+        if (strcmp(argumentTwo, DIARY_SECOND_ARG_LIST) == 0)
         {
-            FREE(wcArgumentTwo);
-            wcArgumentTwo = NULL;
+            FREE(argumentTwo);
             int m1 = 0, n1 = 0;
             sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
             if (sciErr.iErr)
@@ -357,7 +336,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
 
-            if ( (m1 == n1) && (n1 == 0) )
+            if ((m1 == n1) && (n1 == 0))
             {
                 // diary() == diary([], "list")
                 return sci_diary_no_rhs(fname, pvApiCtx);
@@ -367,10 +346,9 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 2);
             }
         }
-        else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_CLOSE) == 0)
+        else if (strcmp(argumentTwo, DIARY_SECOND_ARG_CLOSE) == 0)
         {
-            FREE(wcArgumentTwo);
-            wcArgumentTwo = NULL;
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -394,10 +372,10 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
         }
-        else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_PAUSE) == 0) ||
-                  (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_OFF) == 0) )
+        else if ((strcmp(argumentTwo, DIARY_SECOND_ARG_PAUSE) == 0) ||
+            (strcmp(argumentTwo, DIARY_SECOND_ARG_OFF) == 0))
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -421,10 +399,10 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
         }
-        else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_RESUME) == 0) ||
-                  (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_ON) == 0) )
+        else if ((strcmp(argumentTwo, DIARY_SECOND_ARG_RESUME) == 0) ||
+            (strcmp(argumentTwo, DIARY_SECOND_ARG_ON) == 0))
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -448,9 +426,9 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
         }
-        else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_NEW) == 0)
+        else if (strcmp(argumentTwo, DIARY_SECOND_ARG_NEW) == 0)
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -463,8 +441,8 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
             if (iType == sci_strings)
             {
                 return NewByFilenames(fname, pvApiCtx, DIARY_FILTER_INPUT_AND_OUTPUT,
-                                      PREFIX_TIME_FORMAT_UNIX_EPOCH,
-                                      PREFIX_FILTER_NONE, false);
+                    PREFIX_TIME_FORMAT_UNIX_EPOCH,
+                    PREFIX_FILTER_NONE, false);
             }
             else
             {
@@ -472,9 +450,9 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
         }
-        else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
+        else if (strcmp(argumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -487,8 +465,8 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
             if (iType == sci_strings)
             {
                 return AppendByFilenames(fname, pvApiCtx, DIARY_FILTER_INPUT_AND_OUTPUT,
-                                         PREFIX_TIME_FORMAT_UNIX_EPOCH,
-                                         PREFIX_FILTER_NONE, false);
+                    PREFIX_TIME_FORMAT_UNIX_EPOCH,
+                    PREFIX_FILTER_NONE, false);
             }
             else
             {
@@ -496,9 +474,9 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
                 return 0;
             }
         }
-        else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_EXISTS) == 0)
+        else if (strcmp(argumentTwo, DIARY_SECOND_ARG_EXISTS) == 0)
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -524,7 +502,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else
         {
-            FREE(wcArgumentTwo);
+            FREE(argumentTwo);
             Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 2);
             return 0;
         }
@@ -541,13 +519,13 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
 {
     int ierr = 0;
     int size_ArgThree = 0;
-    wchar_t **wcArgumentThree = getInputArgumentThree(fname, pvApiCtx, &size_ArgThree, &ierr);
+    char** argumentThree = getInputArgumentThree(fname, pvApiCtx, &size_ArgThree, &ierr);
     if (ierr)
     {
         return 0;
     }
 
-    if (wcArgumentThree)
+    if (argumentThree)
     {
         diary_filter filterMode = DIARY_FILTER_INPUT_AND_OUTPUT;
         diary_prefix_time_format iPrefixMode = PREFIX_TIME_FORMAT_UNIX_EPOCH;
@@ -556,15 +534,15 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
 
         for (int i = 0; i < size_ArgThree; i++)
         {
-            if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_FILTER_COMMAND) == 0)
+            if (strcmp(argumentThree[i], DIARY_THIRD_ARG_FILTER_COMMAND) == 0)
             {
                 filterMode = DIARY_FILTER_ONLY_INPUT; // input only
             }
-            else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_FILTER_OUTPUT) == 0)
+            else if (strcmp(argumentThree[i], DIARY_THIRD_ARG_FILTER_OUTPUT) == 0)
             {
                 filterMode = DIARY_FILTER_ONLY_OUTPUT; // output only
             }
-            else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH) == 0)
+            else if (strcmp(argumentThree[i], DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH) == 0)
             {
                 iPrefixMode = PREFIX_TIME_FORMAT_UNIX_EPOCH;
                 if (iPrefixIoModeFilter == PREFIX_FILTER_NONE)
@@ -572,7 +550,7 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
                     iPrefixIoModeFilter = PREFIX_FILTER_INPUT_AND_OUTPUT;
                 }
             }
-            else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_DEFAULT) == 0)
+            else if (strcmp(argumentThree[i], DIARY_THIRD_ARG_PREFIX_DEFAULT) == 0)
             {
                 iPrefixMode = PREFIX_TIME_FORMAT_ISO_8601;
                 if (iPrefixIoModeFilter == PREFIX_FILTER_NONE)
@@ -580,33 +558,33 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
                     iPrefixIoModeFilter = PREFIX_FILTER_INPUT_AND_OUTPUT;
                 }
             }
-            else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS) == 0)
+            else if (strcmp(argumentThree[i], DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS) == 0)
             {
                 iPrefixIoModeFilter = PREFIX_FILTER_ONLY_INPUT;
             }
-            else if ( (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_ON) == 0) || (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_RESUME) == 0) )
+            else if ((strcmp(argumentThree[i], DIARY_SECOND_ARG_ON) == 0) || (strcmp(argumentThree[i], DIARY_SECOND_ARG_RESUME) == 0))
             {
                 suspendedDiary = false;
             }
-            else if ( (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_OFF) == 0) || (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_PAUSE) == 0) )
+            else if ((strcmp(argumentThree[i], DIARY_SECOND_ARG_OFF) == 0) || (strcmp(argumentThree[i], DIARY_SECOND_ARG_PAUSE) == 0))
             {
                 suspendedDiary = true;
             }
             else
             {
-                freeArrayOfWideString(wcArgumentThree, size_ArgThree);
+                freeArrayOfString(argumentThree, size_ArgThree);
                 Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 3);
                 return 0;
             }
         }
-        freeArrayOfWideString(wcArgumentThree, size_ArgThree);
+        freeArrayOfString(argumentThree, size_ArgThree);
 
-        wchar_t *wcArgumentTwo = getInputArgumentTwo(fname, pvApiCtx, &ierr);
+        char* argumentTwo = getInputArgumentTwo(fname, pvApiCtx, &ierr);
         if (ierr)
         {
             return 0;
         }
-        if (wcArgumentTwo)
+        if (argumentTwo)
         {
             int *piAddressVarOne = NULL;
             SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
@@ -614,14 +592,12 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
             {
                 printError(&sciErr, 0);
                 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-                FREE(wcArgumentTwo);
                 return 0;
             }
 
-            if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_NEW) == 0)
+            if (strcmp(argumentTwo, DIARY_SECOND_ARG_NEW) == 0)
             {
                 int iType = 0;
-                FREE(wcArgumentTwo);
                 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
                 if (sciErr.iErr)
                 {
@@ -640,10 +616,9 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
                     return 0;
                 }
             }
-            else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
+            else if (strcmp(argumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
             {
                 int iType = 0;
-                FREE(wcArgumentTwo);
                 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
                 if (sciErr.iErr)
                 {
@@ -665,7 +640,6 @@ static int sci_diary_three_rhs(char *fname, void* pvApiCtx)
             else
             {
                 Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 2);
-                FREE(wcArgumentTwo);
                 return 0;
             }
         }
@@ -717,11 +691,11 @@ static double *getInputArgumentOneIDs(char *fname, void* pvApiCtx, int *sizeRetu
             return 0;
         }
 
-        if ( (m1 == 1) || (n1 == 1) )
+        if ((m1 == 1) || (n1 == 1))
         {
             *sizeReturnedArray = m1 * n1;
         }
-        else if ( (m1 == 0) || (n1 == 0) )
+        else if ((m1 == 0) || (n1 == 0))
         {
             *sizeReturnedArray = 0;
             *ierror = 2;
@@ -742,9 +716,9 @@ static double *getInputArgumentOneIDs(char *fname, void* pvApiCtx, int *sizeRetu
     return IDs;
 }
 /*--------------------------------------------------------------------------*/
-static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror)
+static char** getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror)
 {
-    wchar_t** wcFilenames = NULL;
+    char** filenames = NULL;
     *sizeReturnedArray = 0;
     *ierror = 0;
 
@@ -785,7 +759,7 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
             Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1);
             *ierror = 1;
         }
-        else if ( (m1 == 1) || (n1 == 1) )
+        else if ((m1 == 1) || (n1 == 1))
         {
             lenStVarOne = (int *)MALLOC(sizeof(int) * (m1 * n1));
             if (lenStVarOne == NULL)
@@ -795,7 +769,7 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
             }
             else
             {
-                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, wcFilenames);
+                sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, filenames);
                 if (sciErr.iErr)
                 {
                     FREE(lenStVarOne);
@@ -805,8 +779,8 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                     return NULL;
                 }
 
-                wcFilenames = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m1 * n1));
-                if (wcFilenames == NULL)
+                filenames = (char**)MALLOC(sizeof(char*) * (m1 * n1));
+                if (filenames == NULL)
                 {
                     Scierror(999, _("%s: Memory allocation error.\n"), fname);
                     *ierror = 1;
@@ -816,22 +790,23 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                 {
                     for (int i = 0; i < m1 * n1; i++)
                     {
-                        wcFilenames[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
-                        if (wcFilenames[i] == NULL)
+                        filenames[i] = (char*)MALLOC(sizeof(char) * (lenStVarOne[i] + 1));
+                        if (filenames[i] == NULL)
                         {
                             Scierror(999, _("%s: Memory allocation error.\n"), fname);
                             *ierror = 1;
                             for (int j = 0; j < i; j++)
                             {
-                                FREE(wcFilenames[i]);
+                                FREE(filenames[i]);
                             }
-                            FREE(wcFilenames);
+
+                            FREE(filenames);
                             FREE(lenStVarOne);
                             return NULL;
                         }
                     }
 
-                    sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, wcFilenames);
+                    sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, filenames);
                     FREE(lenStVarOne);
                     if (sciErr.iErr)
                     {
@@ -840,9 +815,9 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                         *ierror = 1;
                         for (int i = 0; i < m1 * n1; i++)
                         {
-                            FREE(wcFilenames[i]);
+                            FREE(filenames[i]);
                         }
-                        FREE(wcFilenames);
+                        FREE(filenames);
                         return NULL;
                     }
 
@@ -861,12 +836,12 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
         Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
         *ierror = 1;
     }
-    return wcFilenames;
+    return filenames;
 }
 /*--------------------------------------------------------------------------*/
-static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
+static char* getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
 {
-    wchar_t *wcInputArgumentTwo = NULL;
+    char* inputArgumentTwo = NULL;
     *ierror = 0;
 
     int m2 = 0, n2 = 0;
@@ -900,7 +875,7 @@ static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
             return 0;
         }
 
-        if ( (m2 != n2) && (n2 != 1) )
+        if ((m2 != n2) && (n2 != 1))
         {
             Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 2);
             *ierror = 1;
@@ -908,7 +883,7 @@ static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
         else
         {
             // get length lenStVarTwo
-            sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &wcInputArgumentTwo);
+            sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &inputArgumentTwo);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
@@ -916,15 +891,15 @@ static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
                 return 0;
             }
 
-            wcInputArgumentTwo = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarTwo + 1));
+            inputArgumentTwo = (char*)MALLOC(sizeof(char) * (lenStVarTwo + 1));
 
-            if (wcInputArgumentTwo == NULL)
+            if (inputArgumentTwo == NULL)
             {
                 Scierror(999, _("%s: Memory allocation error.\n"), fname);
                 *ierror = 1;
             }
 
-            sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &wcInputArgumentTwo);
+            sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &inputArgumentTwo);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
@@ -938,12 +913,12 @@ static wchar_t *getInputArgumentTwo(char *fname, void* pvApiCtx, int *ierror)
         Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
         *ierror = 1;
     }
-    return wcInputArgumentTwo;
+    return inputArgumentTwo;
 }
 /*--------------------------------------------------------------------------*/
-static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror)
+static char** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeReturnedArray, int *ierror)
 {
-    wchar_t** wcInputArgumentThree = NULL;
+    char** inputArgumentThree = NULL;
     *sizeReturnedArray = 0;
     *ierror = 0;
 
@@ -984,7 +959,7 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
             Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 3);
             *ierror = 1;
         }
-        else if ( (m3 == 1) || (n3 == 1) )
+        else if ((m3 == 1) || (n3 == 1))
         {
             lenStVarThree = (int *)MALLOC(sizeof(int) * (m3 * n3));
             if (lenStVarThree == NULL)
@@ -994,7 +969,7 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
             }
             else
             {
-                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, wcInputArgumentThree);
+                sciErr = getMatrixOfString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, inputArgumentThree);
                 if (sciErr.iErr)
                 {
                     FREE(lenStVarThree);
@@ -1004,8 +979,8 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
                     return NULL;
                 }
 
-                wcInputArgumentThree = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m3 * n3));
-                if (wcInputArgumentThree == NULL)
+                inputArgumentThree = (char**)MALLOC(sizeof(char*) * (m3 * n3));
+                if (inputArgumentThree == NULL)
                 {
                     FREE(lenStVarThree);
                     Scierror(999, _("%s: Memory allocation error.\n"), fname);
@@ -1015,10 +990,10 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
                 {
                     for (int i = 0; i < m3 * n3; i++)
                     {
-                        wcInputArgumentThree[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarThree[i] + 1));
+                        inputArgumentThree[i] = (char*)MALLOC(sizeof(char) * (lenStVarThree[i] + 1));
                     }
 
-                    sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, wcInputArgumentThree);
+                    sciErr = getMatrixOfString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, inputArgumentThree);
                     FREE(lenStVarThree);
                     if (sciErr.iErr)
                     {
@@ -1026,9 +1001,9 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
                         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
                         for (int i = 0; i < m3 * n3; i++)
                         {
-                            FREE(wcInputArgumentThree[i]);
+                            FREE(inputArgumentThree[i]);
                         }
-                        FREE(wcInputArgumentThree);
+                        FREE(inputArgumentThree);
                         return 0;
                     }
 
@@ -1047,7 +1022,7 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
         Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3);
         *ierror = 1;
     }
-    return wcInputArgumentThree;
+    return inputArgumentThree;
 }
 /*--------------------------------------------------------------------------*/
 static int checkExistByIDs(char *fname, void* pvApiCtx, double *IDs, int size_IDs)
@@ -1067,13 +1042,13 @@ static int checkExistByIDs(char *fname, void* pvApiCtx, double *IDs, int size_ID
     return 1;
 }
 /*--------------------------------------------------------------------------*/
-static int checkExistByFilenames(char *fname, void* pvApiCtx, wchar_t **wcFilenames, int size_IDs)
+static int checkExistByFilenames(char *fname, void* pvApiCtx, char** filenames, int size_IDs)
 {
-    if (wcFilenames)
+    if (filenames)
     {
         for (int i = 0; i < size_IDs; i++)
         {
-            if (diaryExists(wcFilenames[i]))
+            if (diaryExists(filenames[i]))
             {
                 Scierror(999, _("%s: Wrong value for input argument #%d: diary filename not exists.\n"), fname, 1);
                 return 1;
@@ -1086,34 +1061,34 @@ static int checkExistByFilenames(char *fname, void* pvApiCtx, wchar_t **wcFilena
 /*--------------------------------------------------------------------------*/
 static int CloseByFilenames(char *fname, void* pvApiCtx)
 {
-    wchar_t **wcFilenames = NULL;
+    char **filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
 
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
     }
 
-    ierr = checkExistByFilenames(fname, pvApiCtx, wcFilenames, dIDs_size);
+    ierr = checkExistByFilenames(fname, pvApiCtx, filenames, dIDs_size);
     if (ierr)
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         return 0;
     }
 
     for (int i = 0; i < dIDs_size; i++)
     {
-        if (diaryClose(wcFilenames[i]))
+        if (diaryClose(filenames[i]))
         {
-            freeArrayOfWideString(wcFilenames, dIDs_size);
+            freeArrayOfString(filenames, dIDs_size);
             Scierror(999, _("%s: Wrong value for input argument #%d: error can not close diary.\n"), fname);
             return 0;
         }
     }
 
-    freeArrayOfWideString(wcFilenames, dIDs_size);
+    freeArrayOfString(filenames, dIDs_size);
     PutLhsVar();
     return 0;
 }
@@ -1158,34 +1133,34 @@ static int CloseByIds(char *fname, void* pvApiCtx)
 /*--------------------------------------------------------------------------*/
 static int PauseByFilenames(char *fname, void* pvApiCtx)
 {
-    wchar_t **wcFilenames = NULL;
+    char** filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
 
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
     }
 
-    ierr = checkExistByFilenames(fname, pvApiCtx, wcFilenames, dIDs_size);
+    ierr = checkExistByFilenames(fname, pvApiCtx, filenames, dIDs_size);
     if (ierr)
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         return 0;
     }
 
     for (int i = 0; i < dIDs_size; i++)
     {
-        if (diaryPause(wcFilenames[i]))
+        if (diaryPause(filenames[i]))
         {
-            freeArrayOfWideString(wcFilenames, dIDs_size);
+            freeArrayOfString(filenames, dIDs_size);
             Scierror(999, _("%s: Wrong value for input argument #%d: error can not pause diary.\n"), fname);
             return 0;
         }
     }
 
-    freeArrayOfWideString(wcFilenames, dIDs_size);
+    freeArrayOfString(filenames, dIDs_size);
 
     PutLhsVar();
     return 0;
@@ -1232,33 +1207,33 @@ static int PauseByIds(char *fname, void* pvApiCtx)
 /*--------------------------------------------------------------------------*/
 static int ResumeByFilenames(char *fname, void* pvApiCtx)
 {
-    wchar_t **wcFilenames = NULL;
+    char** filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
     }
 
-    ierr = checkExistByFilenames(fname, pvApiCtx, wcFilenames, dIDs_size);
+    ierr = checkExistByFilenames(fname, pvApiCtx, filenames, dIDs_size);
     if (ierr)
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         return 0;
     }
 
     for (int i = 0; i < dIDs_size; i++)
     {
-        if (diaryResume(wcFilenames[i]))
+        if (diaryResume(filenames[i]))
         {
-            freeArrayOfWideString(wcFilenames, dIDs_size);
+            freeArrayOfString(filenames, dIDs_size);
             Scierror(999, _("%s: Wrong value for input argument #%d: error can not resume diary.\n"), fname);
             return 0;
         }
     }
 
-    freeArrayOfWideString(wcFilenames, dIDs_size);
+    freeArrayOfString(filenames, dIDs_size);
 
     PutLhsVar();
 
@@ -1306,10 +1281,10 @@ static int ResumeByIds(char *fname, void* pvApiCtx)
 /*--------------------------------------------------------------------------*/
 static int ExistByFilenames(char *fname, void* pvApiCtx)
 {
-    wchar_t **wcFilenames = NULL;
+    char** filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
@@ -1318,24 +1293,24 @@ static int ExistByFilenames(char *fname, void* pvApiCtx)
     int *resultExist = (int*)MALLOC(sizeof(int) * dIDs_size);
     if (resultExist == NULL)
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         Scierror(999, _("%s: Memory allocation error.\n"), fname);
         return 0;
     }
 
     for (int i = 0; i < dIDs_size; i++)
     {
-        int bExists = diaryExists(wcFilenames[i]);
-        if ( bExists == 0)
+        int bExists = diaryExists(filenames[i]);
+        if (bExists == 0)
         {
-            resultExist[i]  = TRUE;
+            resultExist[i] = TRUE;
         }
         else
         {
-            resultExist[i]  = FALSE;
+            resultExist[i] = FALSE;
         }
     }
-    freeArrayOfWideString(wcFilenames, dIDs_size);
+    freeArrayOfString(filenames, dIDs_size);
 
     SciErr sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, 1, dIDs_size, resultExist);
     if (sciErr.iErr)
@@ -1375,13 +1350,13 @@ static int ExistByIds(char *fname, void* pvApiCtx)
     for (int i = 0; i < dIDs_size; i++)
     {
         int bExists = diaryExists((int)dIDs[i]);
-        if ( bExists == 0)
+        if (bExists == 0)
         {
-            resultExist[i]  = TRUE;
+            resultExist[i] = TRUE;
         }
         else
         {
-            resultExist[i]  = FALSE;
+            resultExist[i] = FALSE;
         }
     }
 
@@ -1402,17 +1377,17 @@ static int ExistByIds(char *fname, void* pvApiCtx)
 }
 /*--------------------------------------------------------------------------*/
 static int AppendByFilenames(char *fname, void* pvApiCtx,
-                             diary_filter filterMode,
-                             diary_prefix_time_format prefixMode,
-                             diary_prefix_time_filter prefixModeFilter,
-                             bool suspended)
+    diary_filter filterMode,
+    diary_prefix_time_format prefixMode,
+    diary_prefix_time_filter prefixModeFilter,
+    bool suspended)
 {
     SciErr sciErr;
-    wchar_t **wcFilenames = NULL;
+    char** filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
 
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
@@ -1420,25 +1395,15 @@ static int AppendByFilenames(char *fname, void* pvApiCtx,
 
     if (dIDs_size == 1)
     {
-        double dID = (double)diaryAppend(wcFilenames[0]);
+        double dID = (double)diaryAppend(filenames[0]);
         if (dID == -1)
         {
-            char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
-            if (utf_str)
-            {
-                Scierror(999, _("%s: error can not create diary: %s.\n"), fname, utf_str);
-                FREE(utf_str);
-                utf_str = NULL;
-            }
-            else
-            {
-                Scierror(999, _("%s: error can not create diary.\n"), fname);
-            }
-            freeArrayOfWideString(wcFilenames, dIDs_size);
+            Scierror(999, _("%s: error can not create diary: %s.\n"), fname, filenames[0]);
+            freeArrayOfString(filenames, dIDs_size);
             return 0;
         }
 
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
 
         diarySetFilterMode((int)dID, filterMode);
         diarySetPrefixMode((int)dID, prefixMode);
@@ -1460,9 +1425,8 @@ static int AppendByFilenames(char *fname, void* pvApiCtx,
 
         if (Lhs == 2)
         {
-            wchar_t **wfilenameUsed = new wchar_t*[1];
-            wfilenameUsed[0] = getDiaryFilename((int)dID);
-            sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
+            const char* filenameUsed = getDiaryFilename((int)dID);
+            sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, 1, 1, &filenameUsed);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
@@ -1471,13 +1435,12 @@ static int AppendByFilenames(char *fname, void* pvApiCtx,
             }
 
             LhsVar(2) = Rhs + 2;
-            freeArrayOfWideString(wfilenameUsed, 1);
         }
         PutLhsVar();
     }
     else
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
     }
 
@@ -1485,16 +1448,16 @@ static int AppendByFilenames(char *fname, void* pvApiCtx,
 }
 /*--------------------------------------------------------------------------*/
 static int NewByFilenames(char *fname, void* pvApiCtx,
-                          diary_filter filterMode,
-                          diary_prefix_time_format prefixMode,
-                          diary_prefix_time_filter prefixModeFilter,
-                          bool suspended)
+    diary_filter filterMode,
+    diary_prefix_time_format prefixMode,
+    diary_prefix_time_filter prefixModeFilter,
+    bool suspended)
 {
-    wchar_t **wcFilenames = NULL;
+    char** filenames = NULL;
     int dIDs_size = 0;
     int ierr = 0;
 
-    wcFilenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
+    filenames = getInputArgumentOneFilenames(fname, pvApiCtx, &dIDs_size, &ierr);
     if (ierr)
     {
         return 0;
@@ -1502,25 +1465,15 @@ static int NewByFilenames(char *fname, void* pvApiCtx,
 
     if (dIDs_size == 1)
     {
-        double dID = (double)diaryNew(wcFilenames[0], true);
+        double dID = (double)diaryNew(filenames[0], true);
         if (dID == -1)
         {
-            char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
-            if (utf_str)
-            {
-                Scierror(999, _("%s: error can not create diary: %s.\n"), fname, utf_str);
-                FREE(utf_str);
-                utf_str = NULL;
-            }
-            else
-            {
-                Scierror(999, _("%s: error can not create diary.\n"), fname);
-            }
-            freeArrayOfWideString(wcFilenames, dIDs_size);
+            Scierror(999, _("%s: error can not create diary: %s.\n"), fname, filenames[0]);
+            freeArrayOfString(filenames, dIDs_size);
             return 0;
         }
 
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
 
         diarySetFilterMode((int)dID, filterMode);
         diarySetPrefixMode((int)dID, prefixMode);
@@ -1535,9 +1488,8 @@ static int NewByFilenames(char *fname, void* pvApiCtx,
 
         if (Lhs == 2)
         {
-            wchar_t **wfilenameUsed = new wchar_t*[1];
-            wfilenameUsed[0] = getDiaryFilename((int)dID);
-            sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
+            const char* filenameUsed = getDiaryFilename((int)dID);
+            sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, 1, 1, &filenameUsed);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
@@ -1546,14 +1498,12 @@ static int NewByFilenames(char *fname, void* pvApiCtx,
             }
 
             LhsVar(2) = Rhs + 2;
-            FREE(wfilenameUsed[0]);
-            delete [] wfilenameUsed;
         }
         PutLhsVar();
     }
     else
     {
-        freeArrayOfWideString(wcFilenames, dIDs_size);
+        freeArrayOfString(filenames, dIDs_size);
         Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
     }