2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Allan CORNET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 /*--------------------------------------------------------------------------*/
13 #include "gw_fileio.h"
16 #include "localization.h"
17 #include "api_scilab.h"
19 #include "pathconvert.h"
20 #include "freeArrayOfString.h"
21 /*--------------------------------------------------------------------------*/
22 int sci_pathconvert(char *fname, unsigned long fname_len)
25 int *piAddressVarOne = NULL;
26 wchar_t **pStVarOne = NULL;
28 int *lenStVarOne = NULL;
31 wchar_t **results = NULL;
34 BOOL flagtrail = TRUE;
35 BOOL flagexpand = TRUE;
37 PathConvertType PType = AUTO_STYLE;
39 /* Check Input & Output parameters */
45 int *piAddressVarFour = NULL;
46 wchar_t *pStVarFour = NULL;
51 sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddressVarFour);
54 printError(&sciErr, 0);
55 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
59 sciErr = getVarType(pvApiCtx, piAddressVarFour, &iType4);
62 printError(&sciErr, 0);
63 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
67 if (iType4 != sci_strings)
69 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 4);
73 sciErr = getVarDimension(pvApiCtx, piAddressVarFour, &m4, &n4);
76 printError(&sciErr, 0);
77 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
81 if ((m4 != n4) && (n4 != 1))
83 Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 4);
87 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarFour, &m4, &n4, &lenStVarFour, NULL);
90 printError(&sciErr, 0);
91 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
95 pStVarFour = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarFour + 1));
96 if (pStVarFour == NULL)
98 Scierror(999, _("%s: Memory allocation error.\n"), fname);
102 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarFour, &m4, &n4, &lenStVarFour, &pStVarFour);
105 printError(&sciErr, 0);
106 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
110 if ((wcscmp(pStVarFour, L"w") == 0) || (wcscmp(pStVarFour, L"u") == 0))
112 if (wcscmp(pStVarFour, L"w") == 0)
114 PType = WINDOWS_STYLE;
133 Scierror(999, _("%s: Wrong value for input argument #%d: 'w' or 'u' string expected.\n"), fname, 4);
140 int *piAddressVarThree = NULL;
145 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
148 printError(&sciErr, 0);
149 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
153 sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3);
156 printError(&sciErr, 0);
157 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
161 if (iType3 != sci_boolean)
163 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
167 sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3);
170 printError(&sciErr, 0);
171 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
175 if ((m3 != n3) && (n3 != 1))
177 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
181 sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarThree, &m3, &n3, &piData);
184 printError(&sciErr, 0);
185 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
189 flagexpand = piData[0];
194 int *piAddressVarTwo = NULL;
199 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
202 printError(&sciErr, 0);
203 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
207 sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
210 printError(&sciErr, 0);
211 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
215 if (iType2 != sci_boolean)
217 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
221 sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &m2, &n2);
224 printError(&sciErr, 0);
225 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
229 if ((m2 != n2) && (n2 != 1))
231 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
235 sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2, &piData);
238 printError(&sciErr, 0);
239 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
243 flagtrail = piData[0];
246 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
249 printError(&sciErr, 0);
250 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
254 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
257 printError(&sciErr, 0);
258 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
262 if (iType1 == sci_matrix)
264 sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
267 printError(&sciErr, 0);
268 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
272 if ((m1 == n1) && (m1 == 0))
274 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, NULL);
277 printError(&sciErr, 0);
278 Scierror(999,_("%s: Memory allocation error.\n"), fname);
287 Scierror(999, _("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
290 else if (iType1 == sci_strings)
292 sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
295 printError(&sciErr, 0);
296 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
300 lenStVarOne = (int *)MALLOC(sizeof(int) * (m1 * n1));
301 if (lenStVarOne == NULL)
303 Scierror(999, _("%s: Memory allocation error.\n"), fname);
307 results = (wchar_t **) MALLOC(sizeof(wchar_t *) * (m1 * n1));
313 freeArrayOfWideString(pStVarOne, m1 * n1);
314 Scierror(999, _("%s: Memory allocation error.\n"), fname);
318 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
321 printError(&sciErr, 0);
322 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
326 pStVarOne = (wchar_t **) MALLOC(sizeof(wchar_t *) * (m1 * n1));
327 if (pStVarOne == NULL)
334 Scierror(999, _("%s: Memory allocation error.\n"), fname);
338 for (i = 0; i < m1 * n1; i++)
340 pStVarOne[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
341 if (pStVarOne[i] == NULL)
348 freeArrayOfWideString(pStVarOne, m1 * n1);
349 Scierror(999, _("%s: Memory allocation error.\n"), fname);
354 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
357 printError(&sciErr, 0);
358 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
362 for (i = 0; i < m1 * n1; i++)
364 results[i] = pathconvertW(pStVarOne[i], flagtrail, flagexpand, PType);
367 sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, m1, n1, results);
370 printError(&sciErr, 0);
371 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
381 freeArrayOfWideString(results, m1 * n1);
382 freeArrayOfWideString(pStVarOne, m1 * n1);
387 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
393 /*--------------------------------------------------------------------------*/