utf: module scinotes 77/17677/1
Antoine ELIAS [Tue, 12 Jan 2016 09:14:10 +0000 (10:14 +0100)]
Change-Id: Icea21088903b813f7c4d344c751e10ae56b918fd

scilab/modules/scinotes/includes/callscinotes.h
scilab/modules/scinotes/sci_gateway/cpp/sci_scinotes.cpp
scilab/modules/scinotes/src/cpp/callscinotes.cpp

index c58680f..d01f8ba 100644 (file)
@@ -22,8 +22,8 @@
 * @param[in] size of _wcfilenames
 * @return 0
 */
-SCINOTES_IMPEXP int callSciNotesW(wchar_t **_wcfilenames, int _nbfiles);
-SCINOTES_IMPEXP int callSciNotesWWithLineNumberAndFunction(wchar_t **_wcfilenames, double* pdblLineNumber, char *functionName, int _nbfiles);
-SCINOTES_IMPEXP int callSciNotesWWithOption(wchar_t **_wcfilenames, wchar_t** option, int _nboptions, int _nbfiles);
+SCINOTES_IMPEXP int callSciNotesW(char **_filenames, int _nbfiles);
+SCINOTES_IMPEXP int callSciNotesWWithLineNumberAndFunction(char** _filenames, double* pdblLineNumber, char *functionName, int _nbfiles);
+SCINOTES_IMPEXP int callSciNotesWWithOption(char** _filenames, char** option, int _nboptions, int _nbfiles);
 /*--------------------------------------------------------------------------*/
 #endif /* __CALLSCINOTES_H__ */
index 19e9a73..5ad917c 100644 (file)
@@ -55,8 +55,7 @@ int sci_scinotes(char * fname, void* pvApiCtx)
     {
         int m1 = 0, n1 = 0;
         int *piAddressVarOne = NULL;
-        wchar_t **pStVarOne = NULL;
-        int *lenStVarOne = NULL;
+        char **pStVarOne = NULL;
         int i = 0;
         int iType1 = 0;
         char *functionName = NULL;
@@ -83,64 +82,10 @@ int sci_scinotes(char * fname, void* pvApiCtx)
             return 0;
         }
 
-        /* get dimensions */
-        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-            return 0;
-        }
-
-        lenStVarOne = (int *)MALLOC(sizeof(int) * (m1 * n1));
-        if (lenStVarOne == NULL)
-        {
-            Scierror(999, _("%s: No more memory.\n"), fname);
-            return 0;
-        }
-
-        /* get lengths */
-        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-            FREE(lenStVarOne);
-            return 0;
-        }
-
-        pStVarOne = (wchar_t **) MALLOC(sizeof(wchar_t *) * (m1 * n1));
-        if (pStVarOne == NULL)
-        {
-            Scierror(999, _("%s: No more memory.\n"), fname);
-            FREE(lenStVarOne);
-            return 0;
-        }
-
-        for (i = 0; i < m1 * n1; i++)
-        {
-            pStVarOne[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
-            if (pStVarOne[i] == NULL)
-            {
-                Scierror(999, _("%s: No more memory.\n"), fname);
-                for (; i >= 0; i--)
-                {
-                    FREE(pStVarOne[i]);
-                }
-                FREE(pStVarOne);
-                FREE(lenStVarOne);
-                return 0;
-            }
-        }
-
-        /* get strings */
-        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
-        if (sciErr.iErr)
+        if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &pStVarOne))
         {
             printError(&sciErr, 0);
             Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-            freeArrayOfWideString(pStVarOne, m1 * n1);
-            FREE(lenStVarOne);
             return 0;
         }
 
@@ -156,8 +101,7 @@ int sci_scinotes(char * fname, void* pvApiCtx)
             {
                 printError(&sciErr, 0);
                 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                freeArrayOfWideString(pStVarOne, m1 * n1);
-                FREE(lenStVarOne);
+                freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                 return 0;
             }
 
@@ -166,90 +110,27 @@ int sci_scinotes(char * fname, void* pvApiCtx)
             {
                 printError(&sciErr, 0);
                 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                freeArrayOfWideString(pStVarOne, m1 * n1);
-                FREE(lenStVarOne);
+                freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                 return 0;
             }
 
             if (iType2 != sci_matrix && iType2 != sci_strings)
             {
                 Scierror(999, _("%s: Wrong type for argument #%d: Real matrix or \'readonly\' expected.\n"), fname, 2);
-                freeArrayOfWideString(pStVarOne, m1 * n1);
-                FREE(lenStVarOne);
+                freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                 return 0;
             }
 
             if (iType2 == sci_strings)
             {
                 /* get dimensions */
-                wchar_t **pStVarTwo = NULL;
-                int *lenStVarTwo = NULL;
-
-                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, NULL);
-                if (sciErr.iErr)
-                {
-                    printError(&sciErr, 0);
-                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
-                    return 0;
-                }
-
-                lenStVarTwo = (int *)MALLOC(sizeof(int) * m2 * n2);
-                if (lenStVarTwo == NULL)
-                {
-                    Scierror(999, _("%s: No more memory.\n"), fname);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
-                    return 0;
-                }
-
-                /* get lengths */
-                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo);
-                if (sciErr.iErr)
-                {
-                    printError(&sciErr, 0);
-                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                    FREE(lenStVarTwo);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
-                    return 0;
-                }
-
-                pStVarTwo = (wchar_t **) MALLOC(sizeof(wchar_t *) * m2 * n2);
-                if (pStVarTwo == NULL)
-                {
-                    Scierror(999, _("%s: No more memory.\n"), fname);
-                    FREE(lenStVarTwo);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
-                    return 0;
-                }
+                char** pStVarTwo = NULL;
 
-                for (int i = 0; i < m2 * n2; i++)
-                {
-                    pStVarTwo[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarTwo[i] + 1));
-                    if (pStVarTwo[i] == NULL)
-                    {
-                        Scierror(999, _("%s: No more memory.\n"), fname);
-                        freeArrayOfWideString(pStVarTwo, i);
-                        FREE(lenStVarTwo);
-                        freeArrayOfWideString(pStVarOne, m1 * n1);
-                        FREE(lenStVarOne);
-                        return 0;
-                    }
-                }
-
-                /* get strings */
-                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo);
-                if (sciErr.iErr)
+                if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &pStVarTwo))
                 {
                     printError(&sciErr, 0);
                     Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                    FREE(pStVarTwo);
-                    FREE(lenStVarTwo);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                     return 0;
                 }
 
@@ -260,31 +141,25 @@ int sci_scinotes(char * fname, void* pvApiCtx)
                 catch (GiwsException::JniCallMethodException exception)
                 {
                     Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
-                    freeArrayOfWideString(pStVarTwo, m2 * n2);
-                    FREE(lenStVarTwo);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
+                    freeAllocatedMatrixOfString(m2, n2, pStVarTwo);
                     return 0;
                 }
                 catch (GiwsException::JniException exception)
                 {
                     Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
-                    freeArrayOfWideString(pStVarTwo, m2 * n2);
-                    FREE(lenStVarTwo);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
+                    freeAllocatedMatrixOfString(m2, n2, pStVarTwo);
                     return 0;
                 }
-                freeArrayOfWideString(pStVarTwo, m2 * n2);
-                FREE(lenStVarTwo);
+                freeAllocatedMatrixOfString(m2, n2, pStVarTwo);
             }
             else
             {
                 if (isVarComplex(pvApiCtx, piAddressVarTwo) == 1)
                 {
                     Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), fname, 2);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                     return 0;
                 }
 
@@ -293,16 +168,14 @@ int sci_scinotes(char * fname, void* pvApiCtx)
                 {
                     printError(&sciErr, 0);
                     Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                     return 0;
                 }
 
                 if (m2 * n2 != m1 * n1)
                 {
                     Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: Same dimensions expected.\n"), fname, 1, 2);
-                    freeArrayOfWideString(pStVarOne, m1 * n1);
-                    FREE(lenStVarOne);
+                    freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                     return 0;
                 }
 
@@ -321,8 +194,7 @@ int sci_scinotes(char * fname, void* pvApiCtx)
                     if (!isStringType(pvApiCtx, piAddressVarThree))
                     {
                         Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
-                        freeArrayOfWideString(pStVarOne, m1 * n1);
-                        FREE(lenStVarOne);
+                        freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                         return 0;
                     }
 
@@ -331,8 +203,7 @@ int sci_scinotes(char * fname, void* pvApiCtx)
                     if (ret)
                     {
                         Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
-                        freeArrayOfWideString(pStVarOne, m1 * n1);
-                        FREE(lenStVarOne);
+                        freeAllocatedMatrixOfString(m1, n1, pStVarOne);
                         return 0;
                     }
                 }
@@ -367,8 +238,7 @@ int sci_scinotes(char * fname, void* pvApiCtx)
             }
         }
 
-        freeArrayOfWideString(pStVarOne, m1 * n1);
-        FREE(lenStVarOne);
+        freeAllocatedMatrixOfString(m1, n1, pStVarOne);
         if (functionName)
         {
             freeAllocatedSingleString(functionName);
index 0ff1a69..9d019dd 100644 (file)
@@ -25,28 +25,21 @@ extern "C"
 /*--------------------------------------------------------------------------*/
 using namespace org_scilab_modules_scinotes;
 /*--------------------------------------------------------------------------*/
-int callSciNotesW(wchar_t **_wcfilenames, int _nbfiles)
+int callSciNotesW(char** _filenames, int _nbfiles)
 {
-    if ( (_wcfilenames) && (_nbfiles > 0) )
+    if ( (_filenames) && (_nbfiles > 0) )
     {
         int i = 0;
         for (i = 0; i < _nbfiles; i++)
         {
-            if (_wcfilenames[i])
+            if (_filenames[i])
             {
-                wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
-                if (wcFullFilename)
+                char *cFullFilename = getFullFilename(_filenames[i]);
+                if (cFullFilename)
                 {
-                    char *fullFilename = wide_string_to_UTF8(wcFullFilename);
-                    if (fullFilename)
-                    {
-                        SciNotes::scinotes(getScilabJavaVM(), fullFilename);
-                        FREE(fullFilename);
-                        fullFilename = NULL;
-                    }
-
-                    FREE(wcFullFilename);
-                    wcFullFilename = NULL;
+                    SciNotes::scinotes(getScilabJavaVM(), cFullFilename);
+                    FREE(cFullFilename);
+                    cFullFilename = NULL;
                 }
             }
         }
@@ -58,28 +51,21 @@ int callSciNotesW(wchar_t **_wcfilenames, int _nbfiles)
     return 0;
 }
 
-int callSciNotesWWithLineNumberAndFunction(wchar_t **_wcfilenames, double* pdblLineNumber, char *functionName, int _nbfiles)
+int callSciNotesWWithLineNumberAndFunction(char** _filenames, double* pdblLineNumber, char *functionName, int _nbfiles)
 {
-    if ( (_wcfilenames) && (_nbfiles > 0) )
+    if ( (_filenames) && (_nbfiles > 0) )
     {
         int i = 0;
         for (i = 0; i < _nbfiles; i++)
         {
-            if (_wcfilenames[i])
+            if (_filenames[i])
             {
-                wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
-                if (wcFullFilename)
+                char *cFullFilename = getFullFilename(_filenames[i]);
+                if (cFullFilename)
                 {
-                    char *fullFilename = wide_string_to_UTF8(wcFullFilename);
-                    if (fullFilename)
-                    {
-                        SciNotes::scinotes(getScilabJavaVM(), fullFilename, (int)pdblLineNumber[i], functionName);
-                        FREE(fullFilename);
-                        fullFilename = NULL;
-                    }
-
-                    FREE(wcFullFilename);
-                    wcFullFilename = NULL;
+                    SciNotes::scinotes(getScilabJavaVM(), cFullFilename, (int)pdblLineNumber[i], functionName);
+                    FREE(cFullFilename);
+                    cFullFilename = NULL;
                 }
             }
         }
@@ -91,42 +77,24 @@ int callSciNotesWWithLineNumberAndFunction(wchar_t **_wcfilenames, double* pdblL
     return 0;
 }
 
-int callSciNotesWWithOption(wchar_t **_wcfilenames, wchar_t** option, int _nboptions, int _nbfiles)
+int callSciNotesWWithOption(char** _filenames, char** option, int _nboptions, int _nbfiles)
 {
-    if ( (_wcfilenames) && (_nbfiles > 0) )
+    if ( (_filenames) && (_nbfiles > 0) )
     {
         int i = 0;
-        char ** opt = NULL;
-        if (_nboptions)
-        {
-            opt = new char*[_nboptions];
-            for (int i = 0; i < _nboptions; i++)
-            {
-                opt[i] = wide_string_to_UTF8(option[i]);
-            }
-        }
-
         for (i = 0; i < _nbfiles; i++)
         {
-            if (_wcfilenames[i])
+            if (_filenames[i])
             {
-                wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
-                if (wcFullFilename)
+                char *cFullFilename = getFullFilename(_filenames[i]);
+                if (cFullFilename)
                 {
-                    char *fullFilename = wide_string_to_UTF8(wcFullFilename);
-                    if (fullFilename)
-                    {
-                        SciNotes::scinotes(getScilabJavaVM(), fullFilename, opt, _nboptions);
-                        FREE(fullFilename);
-                        fullFilename = NULL;
-                    }
-
-                    FREE(wcFullFilename);
-                    wcFullFilename = NULL;
+                    SciNotes::scinotes(getScilabJavaVM(), cFullFilename, option, _nboptions);
+                    FREE(cFullFilename);
+                    cFullFilename = NULL;
                 }
             }
         }
-        FREE(opt);
     }
     else
     {