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 "funcmanager.hxx"
14 #include "filemanager.hxx"
15 #include "fileio_gw.hxx"
16 #include "function.hxx"
22 #include "localization.h"
24 #include "pathconvert.h"
27 #define UNIX_TYPE L"u"
28 #define WINDOWS_TYPE L"w"
29 /*--------------------------------------------------------------------------*/
30 Function::ReturnValue sci_pathconvert(typed_list &in, int _iRetCount, typed_list &out)
32 PathConvertType PType = AUTO_STYLE;
36 if(in.size() < 1 && in.size() > 4)
38 ScierrorW(999, _W("%ls: Wrong number of input arguments: %d to %d expected.\n"), L"pathconvert" , 1, 4);
39 return Function::Error;
44 ScierrorW(78,_W("%ls: Wrong number of output argument(s): %d expected.\n"), L"pathconvert", 1);
45 return Function::Error;
51 if(in[3]->isString() == false || in[3]->getAsString()->size_get() != 1)
53 ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"pathconvert", 4);
54 return Function::Error;
57 wchar_t* pwstType = in[3]->getAsString()->string_get(0);
58 if(wcscmp(pwstType, WINDOWS_TYPE) == 0)
60 PType = WINDOWS_STYLE;
62 else if(wcscmp(pwstType, UNIX_TYPE) == 0)
68 ScierrorW(999,_W("%ls: Wrong value for input argument #%d: '%ls' or '%ls' expected.\n"), L"pathconvert", 4, UNIX_TYPE, WINDOWS_TYPE);
69 return Function::Error;
75 if(in[2]->isBool() == false || in[2]->getAsBool()->size_get() != 1)
77 ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A boolean expected.\n"), L"pathconvert", 3);
78 return Function::Error;
81 iPathExpand = in[2]->getAsBool()->bool_get()[0];
86 if(in[1]->isBool() == false || in[1]->getAsBool()->size_get() != 1)
88 ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A boolean expected.\n"), L"pathconvert", 2);
89 return Function::Error;
92 iPathTrail = in[1]->getAsBool()->bool_get()[0];
95 if(in[0]->isDouble() && in[0]->getAsDouble()->isEmpty())
97 out.push_back(Double::Empty());
101 if(in[0]->isString() == false)
103 ScierrorW(999, _W("%ls: Wrong type for input argument #%d: Matrix of strings expected.\n"), L"pathconvert", 1);
104 return Function::Error;
107 String* pS = in[0]->getAsString();
108 String* pOut = new String(pS->rows_get(), pS->cols_get());
109 wchar_t** pStr = pOut->string_get();
112 for(int i = 0 ; i < pS->size_get() ; i++)
114 pStr[i] = pathconvertW(pS->string_get(i), iPathTrail, iPathExpand, PType);
120 //int *piAddressVarOne = NULL;
121 //wchar_t **pStVarOne = NULL;
123 //int *lenStVarOne = NULL;
124 //int m1 = 0, n1 = 0;
126 //wchar_t **results = NULL;
129 //BOOL flagtrail = TRUE;
130 //BOOL flagexpand = TRUE;
132 //PathConvertType PType = AUTO_STYLE;
134 ///* Check Input & Output parameters */
141 // int *piAddressVarFour = NULL;
142 // wchar_t *pStVarFour = NULL;
144 // int lenStVarFour = 0;
145 // int m4 = 0, n4 = 0;
147 // sciErr = getVarAddressFromPosition(_piKey, 4, &piAddressVarFour);
150 // printError(&sciErr, 0);
154 // sciErr = getVarType(_piKey, piAddressVarFour, &iType4);
157 // printError(&sciErr, 0);
161 // if (iType4 != sci_strings)
163 // Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 4);
167 // sciErr = getVarDimension(_piKey, piAddressVarFour, &m4, &n4);
170 // printError(&sciErr, 0);
174 // if ( (m4 != n4) && (n4 != 1) )
176 // Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 4);
180 // sciErr = getMatrixOfWideString(_piKey, piAddressVarFour, &m4, &n4, &lenStVarFour, &pStVarFour);
183 // printError(&sciErr, 0);
187 // pStVarFour = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarFour + 1));
188 // if (pStVarFour == NULL)
190 // Scierror(999,_("%s: Memory allocation error.\n"),fname);
194 // sciErr = getMatrixOfWideString(_piKey, piAddressVarFour, &m4, &n4, &lenStVarFour, &pStVarFour);
197 // printError(&sciErr, 0);
202 // if ( (wcscmp(pStVarFour, L"w") == 0) || (wcscmp(pStVarFour, L"u") == 0) )
204 // if (wcscmp(pStVarFour, L"w") == 0)
206 // PType = WINDOWS_STYLE;
210 // PType = UNIX_STYLE;
212 // if (pStVarFour) {FREE(pStVarFour); pStVarFour = NULL;}
216 // if (pStVarFour) {FREE(pStVarFour); pStVarFour = NULL;}
217 // Scierror(999,_("%s: Wrong value for input argument #%d: ''w'' or ''u'' string expected.\n"), fname, 4);
224 // int *piAddressVarThree = NULL;
225 // int *piData = NULL;
227 // int m3 = 0, n3 = 0;
229 // sciErr = getVarAddressFromPosition(_piKey, 3, &piAddressVarThree);
232 // printError(&sciErr, 0);
236 // sciErr = getVarType(_piKey, piAddressVarThree, &iType3);
239 // printError(&sciErr, 0);
243 // if (iType3 != sci_boolean)
245 // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
249 // sciErr = getVarDimension(_piKey, piAddressVarThree, &m3, &n3);
252 // printError(&sciErr, 0);
257 // if ( (m3 != n3) && (n3 != 1) )
259 // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
263 // sciErr = getMatrixOfBoolean(_piKey, piAddressVarThree, &m3, &n3, &piData);
266 // printError(&sciErr, 0);
270 // flagexpand = piData[0];
275 // int *piAddressVarTwo = NULL;
276 // int *piData = NULL;
278 // int m2 = 0, n2 = 0;
280 // sciErr = getVarAddressFromPosition(_piKey, 2, &piAddressVarTwo);
283 // printError(&sciErr, 0);
287 // sciErr = getVarType(_piKey, piAddressVarTwo, &iType2);
290 // printError(&sciErr, 0);
294 // if (iType2 != sci_boolean)
296 // Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
300 // sciErr = getVarDimension(_piKey, piAddressVarTwo, &m2, &n2);
303 // printError(&sciErr, 0);
307 // if ( (m2 != n2) && (n2 != 1) )
309 // Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
313 // sciErr = getMatrixOfBoolean(_piKey, piAddressVarTwo, &m2, &n2, &piData);
316 // printError(&sciErr, 0);
320 // flagtrail = piData[0];
323 //sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
326 // printError(&sciErr, 0);
330 //sciErr = getVarType(_piKey, piAddressVarOne, &iType1);
333 // printError(&sciErr, 0);
337 //if (iType1 == sci_matrix)
339 // sciErr = getVarDimension(_piKey, piAddressVarOne, &m1, &n1);
342 // printError(&sciErr, 0);
346 // if ( (m1 == n1) && (m1 == 0) )
348 // sciErr = createMatrixOfDouble(_piKey, Rhs + 1, m1, n1, NULL);
351 // printError(&sciErr, 0);
355 // LhsVar(1) = Rhs + 1;
360 // Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
363 //else if (iType1 == sci_strings)
365 // sciErr = getVarDimension(_piKey, piAddressVarOne, &m1, &n1);
368 // printError(&sciErr, 0);
372 // lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
373 // if (lenStVarOne == NULL)
375 // Scierror(999,_("%s: Memory allocation error.\n"),fname);
379 // results = (wchar_t **)MALLOC(sizeof(wchar_t*) * (m1 * n1));
381 // if (results == NULL)
383 // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
384 // freeArrayOfWideString(pStVarOne, m1 * n1);
385 // Scierror(999,_("%s: Memory allocation error.\n"),fname);
389 // sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
392 // printError(&sciErr, 0);
396 // pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
397 // if (pStVarOne == NULL)
399 // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
400 // Scierror(999,_("%s: Memory allocation error.\n"),fname);
404 // for( i = 0; i < m1 * n1; i++)
406 // pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne[i] + 1));
407 // if (pStVarOne[i] == NULL)
409 // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
410 // freeArrayOfWideString(pStVarOne, m1 * n1);
411 // Scierror(999,_("%s: Memory allocation error.\n"),fname);
416 // sciErr = getMatrixOfWideString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
419 // printError(&sciErr, 0);
423 // for( i = 0; i < m1 * n1; i++)
425 // results[i] = pathconvertW(pStVarOne[i], flagtrail, flagexpand, PType);
428 // sciErr = createMatrixOfWideString(_piKey, Rhs + 1, m1, n1, results);
431 // printError(&sciErr, 0);
435 // LhsVar(1) = Rhs + 1;
438 // if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
439 // freeArrayOfWideString(results, m1 * n1);
440 // freeArrayOfWideString(pStVarOne, m1 * n1);
444 // Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
449 /*--------------------------------------------------------------------------*/