* Bug 16664 fixed: diag(spzeros(2,2)) warned for Operation - []
[scilab.git] / scilab / modules / core / src / c / getversion.c
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - 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 <string.h>
17 #include "getversion.h"
18 #include "version.h"
19 #include "configvariable_interface.h"
20 #include "scilabDefaults.h"
21 #include "getenvc.h"
22 #include "os_string.h"
23 #include "with_module.h"
24 #include "loadversion.h"
25 #include "freeArrayOfString.h"
26 #include "sci_malloc.h"
27 #include "../../../io/includes/getenvc.h"
28 #include "charEncoding.h"
29
30 /*--------------------------------------------------------------------------*/
31 /*wide char*/
32 #define TCLSCI_MODULE_NAME L"tclsci"
33 #define TCLTK_OPTION_STRING L"tk"
34 #define MODELICAC_OPTION_STRING L"modelicac"
35 #define X86_STRING L"x86"
36 #define X64_STRING L"x64"
37 #define ICC_STRING L"ICC"
38 #define VC_STRING L"VC++"
39 #define GCC_STRING L"GCC"
40 #define PGI_STRING L"PGI"
41 #define SUN_STRING L"SUN"
42 #define UNKNOW_STRING L"UKN"
43 #define RELEASE_STRING L"release"
44 #define DEBUG_STRING L"debug"
45 #define DEFAULT_VERSION_ARRAY_SIZE 4
46 #define SCILAB_STRING L"scilab"
47 /*--------------------------------------------------------------------------*/
48 int *getScilabVersion(int *sizeArrayReturned)
49 {
50     int *returnedArray = (int *)MALLOC(sizeof(int) * DEFAULT_VERSION_ARRAY_SIZE);
51     *sizeArrayReturned = 0;
52     if (returnedArray)
53     {
54         returnedArray[0] = (int)SCI_VERSION_MAJOR;
55         returnedArray[1] = (int)SCI_VERSION_MINOR;
56         returnedArray[2] = (int)SCI_VERSION_MAINTENANCE;
57         returnedArray[3] = (int)SCI_VERSION_TIMESTAMP;
58
59         *sizeArrayReturned = DEFAULT_VERSION_ARRAY_SIZE;
60     }
61     return returnedArray;
62 }
63 /*--------------------------------------------------------------------------*/
64 char* getScilabVersionAsString(void)
65 {
66     return os_strdup(SCI_VERSION);
67 }
68 /*--------------------------------------------------------------------------*/
69 wchar_t *getScilabVersionAsWideString(void)
70 {
71     return os_wcsdup(SCI_VERSION_WIDE_STRING);
72 }
73 /*--------------------------------------------------------------------------*/
74 int getScilabVersionMajor()
75 {
76     return (int)SCI_VERSION_MAJOR;
77 }
78 /*--------------------------------------------------------------------------*/
79 int getScilabVersionMinor()
80 {
81     return (int)SCI_VERSION_MINOR;
82 }
83 /*--------------------------------------------------------------------------*/
84 int getScilabVersionMaintenance()
85 {
86     return (int)SCI_VERSION_MAINTENANCE;
87 }
88 /*--------------------------------------------------------------------------*/
89 int getScilabVersionTimestamp()
90 {
91     return (int)SCI_VERSION_TIMESTAMP;
92 }
93 /*--------------------------------------------------------------------------*/
94 int* getModuleVersion(wchar_t* _pwstModule, int *sizeArrayReturned)
95 {
96     int *returnedArray = NULL;
97
98     if (_pwstModule)
99     {
100         if (wcscmp(_pwstModule, SCILAB_STRING) == 0)
101         {
102             returnedArray = getScilabVersion(sizeArrayReturned);
103             return returnedArray;
104         }
105     }
106
107     if (with_module(_pwstModule))
108     {
109 #define LineMax 1024
110         wchar_t versionstring[LineMax];
111         int version_module_major = 0;
112         int version_module_minor = 0;
113         int version_module_maintenance = 0;
114         int version_module_revision = 0;
115
116         if (getversionmodule(_pwstModule, &version_module_major, &version_module_minor,
117                              &version_module_maintenance, versionstring,
118                              &version_module_revision))
119         {
120             returnedArray = (int *)MALLOC(sizeof(int) * DEFAULT_VERSION_ARRAY_SIZE);
121             if (returnedArray)
122             {
123                 returnedArray[0] = version_module_major;
124                 returnedArray[1] = version_module_minor;
125                 returnedArray[2] = version_module_maintenance;
126                 returnedArray[3] = version_module_revision;
127                 *sizeArrayReturned = DEFAULT_VERSION_ARRAY_SIZE;
128             }
129             else
130             {
131                 *sizeArrayReturned = 0;
132             }
133         }
134     }
135     else
136     {
137         *sizeArrayReturned = 0;
138     }
139     return returnedArray;
140 }
141 /*--------------------------------------------------------------------------*/
142 wchar_t* getModuleVersionInfoAsString(wchar_t* _pwstModule)
143 {
144     wchar_t* infoString = NULL;
145
146     if (_pwstModule)
147     {
148         if (wcscmp(_pwstModule, SCILAB_STRING) == 0)
149         {
150             infoString = getScilabVersionAsWideString();
151             return infoString;
152         }
153     }
154
155     if (with_module(_pwstModule))
156     {
157 #define LineMax 1024
158         wchar_t versionstring[LineMax];
159         int version_module_major = 0;
160         int version_module_minor = 0;
161         int version_module_maintenance = 0;
162         int version_module_revision = 0;
163         if (getversionmodule(_pwstModule, &version_module_major, &version_module_minor,
164                              &version_module_maintenance, versionstring,
165                              &version_module_revision))
166         {
167             infoString = os_wcsdup(versionstring);
168         }
169     }
170     return infoString;
171 }
172 /*--------------------------------------------------------------------------*/
173 wchar_t** getScilabVersionOptions(int *sizeArrayReturned)
174 {
175     wchar_t** options = NULL;
176     int nbOptions = 2;
177     *sizeArrayReturned = 0;
178
179     options = (wchar_t**)MALLOC(sizeof(wchar_t*) * nbOptions);
180     if (options)
181     {
182         options[0] = getCompilerUsedToBuildScilab();
183         options[1] = getCompilerArchitecture();
184
185         if (with_tk())
186         {
187             options = (wchar_t**)REALLOC(options, sizeof(wchar_t*) * (nbOptions + 1));
188             if (options)
189             {
190                 options[nbOptions] = os_wcsdup(TCLTK_OPTION_STRING);
191                 nbOptions++;
192             }
193             else
194             {
195                 freeArrayOfWideString(options, nbOptions);
196                 return NULL;
197             }
198         }
199
200         if (with_modelica_compiler())
201         {
202             options = (wchar_t**)REALLOC(options, sizeof(wchar_t*) * (nbOptions + 1));
203             if (options)
204             {
205                 options[nbOptions] = os_wcsdup(MODELICAC_OPTION_STRING);
206                 nbOptions++;
207             }
208             else
209             {
210                 freeArrayOfWideString(options, nbOptions);
211                 return NULL;
212             }
213         }
214
215         options = (wchar_t**)REALLOC(options, sizeof(wchar_t*) * (nbOptions + 1));
216         if (options)
217         {
218             options[nbOptions] = getReleaseMode();
219             nbOptions++;
220         }
221         else
222         {
223             freeArrayOfWideString(options, nbOptions);
224             return NULL;
225         }
226
227         options = (wchar_t**)REALLOC(options, sizeof(wchar_t*) * (nbOptions + 1));
228         if (options)
229         {
230             options[nbOptions] = getReleaseDate();
231             nbOptions++;
232         }
233         else
234         {
235             freeArrayOfWideString(options, nbOptions);
236             return NULL;
237         }
238
239         options = (wchar_t**)REALLOC(options, sizeof(wchar_t*) * (nbOptions + 1));
240         if (options)
241         {
242             options[nbOptions] = getReleaseTime();
243             nbOptions++;
244         }
245         else
246         {
247             freeArrayOfWideString(options, nbOptions);
248             return NULL;
249         }
250
251         *sizeArrayReturned = nbOptions;
252     }
253     return options;
254 }
255 /*--------------------------------------------------------------------------*/
256 wchar_t* getReleaseMode(void)
257 {
258 #ifdef NDEBUG
259     return os_wcsdup(RELEASE_STRING);
260 #else
261     return os_wcsdup(DEBUG_STRING);
262 #endif
263 }
264 /*--------------------------------------------------------------------------*/
265 wchar_t* getReleaseDate(void)
266 {
267     return to_wide_string(__DATE__);
268 }
269 /*--------------------------------------------------------------------------*/
270 wchar_t *getReleaseTime(void)
271 {
272     return to_wide_string(__TIME__);
273 }
274 /*--------------------------------------------------------------------------*/
275 wchar_t* getCompilerUsedToBuildScilab(void)
276 {
277 #ifdef __INTEL_COMPILER
278     return os_wcsdup(ICC_STRING);
279 #else
280 #ifdef _MSC_VER
281     return os_wcsdup(VC_STRING);
282 #else
283 #ifdef __GNUC__
284     return os_wcsdup(GCC_STRING);
285 #else
286 #ifdef __PGI
287     return os_wcsdup(PGI_STRING);
288 #else
289 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
290     return os_wcsdup(SUN_STRING);
291 #else
292     return os_wcsdup(UNKNOW_STRING);
293 #endif
294 #endif
295 #endif
296 #endif
297 #endif
298 }
299 /*--------------------------------------------------------------------------*/
300 wchar_t* getCompilerArchitecture(void)
301 {
302 #ifdef _MSC_VER
303 #ifdef _WIN64
304     return os_wcsdup(X64_STRING);
305 #else
306     return os_wcsdup(X86_STRING);
307 #endif
308 #else
309 #ifdef _LP64
310     return os_wcsdup(X64_STRING);
311 #else
312     return os_wcsdup(X86_STRING);
313 #endif
314 #endif
315 }
316 /*--------------------------------------------------------------------------*/
317 BOOL with_modelica_compiler(void)
318 {
319     char *fullpathModelicac = searchEnv(ModelicacName, "PATH");
320     if (fullpathModelicac)
321     {
322         FREE(fullpathModelicac);
323         fullpathModelicac = NULL;
324         return TRUE;
325     }
326     return FALSE;
327 }
328 /*--------------------------------------------------------------------------*/
329 BOOL with_tk(void)
330 {
331     return with_module(TCLSCI_MODULE_NAME) && (getScilabMode() != SCILAB_NWNI);
332 }
333 /*--------------------------------------------------------------------------*/