Coverity #1247398, #1199692, #1321278, #1321279, #1321280, #1321281, #1097625 fixed...
[scilab.git] / scilab / modules / scinotes / src / cpp / callscinotes.cpp
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2009 - DIGITEO - Allan CORNET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15
16 #include "SciNotes.hxx"
17
18 extern "C"
19 {
20 #include "callscinotes.h"
21 #include "charEncoding.h"
22 #include "getScilabJavaVM.h"
23 #include "charEncoding.h"
24 #include "sci_malloc.h"
25 #include "freeArrayOfString.h"
26 #include "getFullFilename.h"
27 }
28 /*--------------------------------------------------------------------------*/
29 using namespace org_scilab_modules_scinotes;
30 /*--------------------------------------------------------------------------*/
31 int callSciNotesW(wchar_t **_wcfilenames, int _nbfiles)
32 {
33     if ( (_wcfilenames) && (_nbfiles > 0) )
34     {
35         int i = 0;
36         for (i = 0; i < _nbfiles; i++)
37         {
38             if (_wcfilenames[i])
39             {
40                 wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
41                 if (wcFullFilename)
42                 {
43                     char *fullFilename = wide_string_to_UTF8(wcFullFilename);
44                     if (fullFilename)
45                     {
46                         SciNotes::scinotes(getScilabJavaVM(), fullFilename);
47                         FREE(fullFilename);
48                         fullFilename = NULL;
49                     }
50
51                     FREE(wcFullFilename);
52                     wcFullFilename = NULL;
53                 }
54             }
55         }
56     }
57     else
58     {
59         SciNotes::scinotes(getScilabJavaVM());
60     }
61     return 0;
62 }
63
64 int callSciNotesWWithLineNumberAndFunction(wchar_t **_wcfilenames, double* pdblLineNumber, char *functionName, int _nbfiles)
65 {
66     if ( (_wcfilenames) && (_nbfiles > 0) )
67     {
68         int i = 0;
69         for (i = 0; i < _nbfiles; i++)
70         {
71             if (_wcfilenames[i])
72             {
73                 wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
74                 if (wcFullFilename)
75                 {
76                     char *fullFilename = wide_string_to_UTF8(wcFullFilename);
77                     if (fullFilename)
78                     {
79                         SciNotes::scinotes(getScilabJavaVM(), fullFilename, (int)pdblLineNumber[i], functionName);
80                         FREE(fullFilename);
81                         fullFilename = NULL;
82                     }
83
84                     FREE(wcFullFilename);
85                     wcFullFilename = NULL;
86                 }
87             }
88         }
89     }
90     else
91     {
92         SciNotes::scinotes(getScilabJavaVM());
93     }
94     return 0;
95 }
96
97 int callSciNotesWWithOption(wchar_t **_wcfilenames, wchar_t** option, int _nboptions, int _nbfiles)
98 {
99     if ( (_wcfilenames) && (_nbfiles > 0) )
100     {
101         int i = 0;
102         char ** opt = NULL;
103         if (_nboptions)
104         {
105             opt = new char*[_nboptions];
106             for (int i = 0; i < _nboptions; i++)
107             {
108                 opt[i] = wide_string_to_UTF8(option[i]);
109             }
110         }
111
112         for (i = 0; i < _nbfiles; i++)
113         {
114             if (_wcfilenames[i])
115             {
116                 wchar_t *wcFullFilename = getFullFilenameW(_wcfilenames[i]);
117                 if (wcFullFilename)
118                 {
119                     char *fullFilename = wide_string_to_UTF8(wcFullFilename);
120                     if (fullFilename)
121                     {
122                         SciNotes::scinotes(getScilabJavaVM(), fullFilename, opt, _nboptions);
123                         FREE(fullFilename);
124                         fullFilename = NULL;
125                     }
126
127                     FREE(wcFullFilename);
128                     wcFullFilename = NULL;
129                 }
130             }
131         }
132         for(int i = 0; i < _nboptions; i++)
133         {
134             FREE(opt[i]);
135         }
136         delete[] opt;
137     }
138     else
139     {
140         SciNotes::scinotes(getScilabJavaVM());
141     }
142     return 0;
143 }
144 /*--------------------------------------------------------------------------*/