2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Antoine ELIAS
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
20 #include "output/SLintScilabResult.hxx"
21 #include "output/SLintXmlResult.hxx"
22 #include "output/cnes/CNESXmlResult.hxx"
23 #include "output/cnes/CNESCsvResult.hxx"
24 #include "config/cnes/ToolConfiguration.hxx"
25 #include "config/XMLConfig.hxx"
29 #include "slint_gw.hxx"
34 #include "localization.h"
38 * slint(String[a,b] files, String[1,c] conf, String[1,1] out)
39 * slint(String[a,b] files, String[1,1] out) : default conf is etc/slint.xml
40 * slint(String[a,b] files) : default conf is etc/slint.xml & out is outputstream
41 * slint(String[a,b] files, bool[1,1] printResult) : default conf is etc/slint.xml
42 * slint(String[a,b] files, String[1,c] conf, bool[1,1] printResult)
45 /*--------------------------------------------------------------------------*/
46 types::Function::ReturnValue sci_slint(types::typed_list & in, int _iRetCount, types::typed_list & out)
48 slint::SLintResult * results = nullptr;
49 bool printResults = false;
50 const int size = (int)in.size();
51 types::String * conf = nullptr;
52 types::String * outFile = nullptr;
54 if (size == 0 || size >= 4)
56 Scierror(999, _("%s: Wrong number of input arguments: at least %d expected.\n"), "slint", 1);
57 return types::Function::Error;
60 if (!in[0]->isString())
62 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "slint", 1);
63 return types::Function::Error;
77 if (in[1]->getAs<types::Bool>()->getSize() == 1)
79 printResults = in[1]->getAs<types::Bool>()->get(0) == 0 ? false : true;
83 Scierror(999, _("%s: Wrong type for input argument #%d: A single boolean expected.\n"), "slint", 2);
84 return types::Function::Error;
87 else if (in[1]->isString())
89 outFile = in[1]->getAs<types::String>();
93 Scierror(999, _("%s: Wrong type for input argument #%d: A string or a boolean expected.\n"), "slint", 2);
94 return types::Function::Error;
102 if (in[2]->getAs<types::Bool>()->getSize() == 1)
104 printResults = in[2]->getAs<types::Bool>()->get(0) == 0 ? false : true;
108 Scierror(999, _("%s: Wrong type for input argument #%d: A single boolean expected.\n"), "slint", 3);
109 return types::Function::Error;
112 else if (in[2]->isString())
114 outFile = in[2]->getAs<types::String>();
118 Scierror(999, _("%s: Wrong type for input argument #%d: A string or a boolean expected.\n"), "slint", 3);
119 return types::Function::Error;
122 if (!in[1]->isString())
124 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "slint", 3);
125 return types::Function::Error;
127 conf = in[1]->getAs<types::String>();
134 slint::SLintOptions options;
137 if (conf->getSize() == 1)
139 slint::XMLConfig::getOptions(conf->get(0), options);
143 slint::XMLConfig::getOptions(*conf, options);
148 slint::XMLConfig::getOptions(L"SCI/modules/slint/etc/slint.xml", options);
153 if (conf && conf->getSize() >= 2 && (std::wstring(conf->get(0)) == L"cnes"))
155 const slint::CNES::ToolConfiguration tc = slint::CNES::ToolConfiguration::createFromXml(conf->get(1));
156 const std::wstring out(outFile->get(0));
157 const std::size_t pos = out.find_last_of(L'.');
158 if (pos != std::string::npos && out.substr(pos) == L".csv")
160 results = new slint::CNES::CNESCsvResult(tc, conf, options.getId(), outFile->get(0));
164 results = new slint::CNES::CNESXmlResult(tc, conf, options.getId(), outFile->get(0));
169 results = new slint::SLintXmlResult(outFile->get(0));
176 results = new slint::SLintScilabResult();
180 results = new slint::SLintScilabOut();
184 slint::SLint slint(options, *results);
185 slint.setFiles(in[0]->getAs<types::String>());
189 if (!outFile && !printResults)
191 out.emplace_back(static_cast<slint::SLintScilabOut *>(results)->getStruct());
194 catch (slint::PCREException & e)
197 Scierror(999, _("%s: %s\n"), "slint", e.what(), 1);
198 return types::Function::Error;
200 catch (slint::FileException & e)
203 Scierror(999, _("%s: %s\n"), "slint", e.what(), 1);
204 return types::Function::Error;
206 catch (slint::SLintXMLException & e)
209 Scierror(999, _("%s: %s\n"), "slint", e.what(), 1);
210 return types::Function::Error;
215 return types::Function::OK;