2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011 - Digiteo - Cedric DELAMARRE
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 /*--------------------------------------------------------------------------*/
17 #include "funcmanager.hxx"
18 #include "fileio_gw.hxx"
19 #include "function.hxx"
21 #include "filemanager.hxx"
27 #include "sci_malloc.h"
29 #include "localization.h"
30 #include "freeArrayOfString.h"
33 /*--------------------------------------------------------------------------*/
34 types::Function::ReturnValue sci_get_absolute_file_path(types::typed_list &in, int _iRetCount, types::typed_list &out)
36 wchar_t* wcsFileName = NULL;
37 wchar_t** wcsFilesOpened = NULL;
38 wchar_t* wcsTemp = NULL;
39 wchar_t* wcsPath = NULL;
43 Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "get_absolute_file_path", 1);
44 return types::Function::Error;
47 if (in[0]->isString() == false || in[0]->getAs<types::String>()->isScalar() == false)
49 Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), "get_absolute_file_path", 1);
50 return types::Function::Error;
53 wcsFileName = in[0]->getAs<types::String>()->get(0);
54 wcsFilesOpened = FileManager::getFilenames();
56 for (int i = FileManager::getOpenedCount() - 1; i >= 0; --i)
58 wcsTemp = wcsstr(wcsFilesOpened[i], wcsFileName);
61 int iSize = (int)(wcsTemp - wcsFilesOpened[i]);
62 if (wcslen(wcsFilesOpened[i]) == wcslen(wcsFileName) + iSize)
64 wcsPath = (wchar_t*)MALLOC((iSize + 1) * sizeof(wchar_t));
65 memcpy(wcsPath, wcsFilesOpened[i], iSize * sizeof(wchar_t));
66 wcsPath[iSize] = L'\0';
67 types::String* pStringOut = new types::String(wcsPath);
69 out.push_back(pStringOut);
70 freeArrayOfWideString(wcsFilesOpened, FileManager::getOpenedCount());
71 return types::Function::OK;
80 freeArrayOfWideString(wcsFilesOpened, FileManager::getOpenedCount());
84 char* pstFile = wide_string_to_UTF8(wcsFileName);
85 Scierror(999, _("%s: The file %s is not opened in scilab.\n"), "get_absolute_file_path", pstFile);
87 return types::Function::Error;
90 return types::Function::OK;
92 /*--------------------------------------------------------------------------*/