2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre LEDRU
4 * Copyright (C) 2011 - Scilab Enterprises - Sylvestre LEDRU
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 /*--------------------------------------------------------------------------*/
14 #include "SciDocMain.hxx"
15 #include "GiwsException.hxx"
16 #include "BuildDocObject.hxx"
20 /*--------------------------------------------------------------------------*/
22 #include "api_scilab.h"
23 #include "gw_helptools.h"
25 #include "setgetSCIpath.h"
26 #include "localization.h"
27 #include "setgetlanguage.h"
28 #include "getScilabJavaVM.h"
31 #include "ConvertSlash.h"
33 /*--------------------------------------------------------------------------*/
34 #define PATHTOCSS "/modules/helptools/css/javahelp.css"
35 #define PATHTOBUILDDOC "/modules/helptools/build/doc/scilab_%s_help/"
36 #define PATHTOMASTERXML "/modules/helptools/master_%s_help.xml"
37 #define DEFAULTEXPORT "JH"
39 static void __slashToAntislash(std::string * in)
41 size_t found = in->rfind("/");
43 while (found != std::string::npos)
45 in->replace(found, 1, "\\");
46 found = in->rfind("/");
50 /*--------------------------------------------------------------------------*/
51 int sci_buildDocv2(char *fname, unsigned long l)
53 std::string exportFormat;
54 std::string SciPath = getSCIpath(); /* Scilab path */
55 std::string masterXML; /* Which file contains all the doc stuff */
56 std::string masterXMLTMP;
57 std::string outputDirectory; /* Working directory */
58 std::string outputDirectoryTMP;
60 std::string styleSheet; /* the CSS */
61 char * fileToExec = NULL;
69 styleSheet = SciPath + PATHTOCSS;
73 exportFormat = DEFAULTEXPORT;
79 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
82 printError(&sciErr, 0);
83 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
87 if (!isStringType(pvApiCtx, piAddr))
89 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), fname, 1);
94 iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
97 freeAllocatedSingleString(pstData);
100 exportFormat = std::string(pstData);
101 freeAllocatedSingleString(pstData);
105 if (Rhs < 3) /* Language not provided */
107 language = getlanguage();
111 char *pstData = NULL;
113 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
116 printError(&sciErr, 0);
117 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
121 if (!isStringType(pvApiCtx, piAddr))
123 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), fname, 3);
128 if (!isScalar(pvApiCtx, piAddr))
130 language = getlanguage();
134 iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
137 freeAllocatedSingleString(pstData);
140 language = std::string(pstData);
141 freeAllocatedSingleString(pstData);
148 /* Update the path with the localization */
149 masterXMLTMP = std::string("/modules/helptools/master_") + language + std::string("_help.xml");
150 masterXML = SciPath + masterXMLTMP;
154 char *pstData = NULL;
156 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
159 printError(&sciErr, 0);
160 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
163 if (!isStringType(pvApiCtx, piAddr))
165 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), fname, 2);
170 iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
173 freeAllocatedSingleString(pstData);
176 masterXML = std::string(pstData);
177 freeAllocatedSingleString(pstData);
182 char *pstData = NULL;
184 sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
187 printError(&sciErr, 0);
188 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
191 if (!isStringType(pvApiCtx, piAddr))
193 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), fname, 4);
198 iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
201 freeAllocatedSingleString(pstData);
204 outputDirectory = std::string(pstData) + std::string("/scilab_") + language + std::string("_help/");
205 freeAllocatedSingleString(pstData);
208 else /* Scilab help */
210 /* Update the path with the localization */
211 if (exportFormat != "jar-only")
214 std::string("/modules/helptools/") + std::string(exportFormat) + std::string("/scilab_") + language + std::string("_help/");
219 std::string("/modules/helptools/") + std::string("javaHelp") + std::string("/scilab_") + language + std::string("_help/");
222 outputDirectory = SciPath + outputDirectoryTMP;
226 __slashToAntislash(&outputDirectory);
227 __slashToAntislash(&styleSheet);
228 __slashToAntislash(&masterXML);
233 if (exportFormat == "javaHelp" || exportFormat == "html" || exportFormat == "chm" || exportFormat == "web")
235 org_scilab_modules_helptools::SciDocMain * doc = new org_scilab_modules_helptools::SciDocMain(getScilabJavaVM());
237 if (doc->setOutputDirectory((char *)outputDirectory.c_str()))
239 doc->setWorkingLanguage((char *)language.c_str());
240 doc->setExportFormat((char *)exportFormat.c_str());
241 doc->setIsToolbox(Rhs == 4);
242 fileToExec = doc->process((char *)masterXML.c_str(), (char *)styleSheet.c_str());
246 Scierror(999, _("%s: Could find or create the working directory %s.\n"), fname, outputDirectory.c_str());
255 else if (exportFormat == "jar-only")
257 org_scilab_modules_helptools::SciDocMain::generateJavahelp(getScilabJavaVM(), (char *)outputDirectory.c_str(), (char *)language.c_str());
261 org_scilab_modules_helptools::BuildDocObject * doc = new org_scilab_modules_helptools::BuildDocObject(getScilabJavaVM());
263 if (doc->setOutputDirectory((char *)outputDirectory.c_str()))
265 doc->setWorkingLanguage((char *)language.c_str());
266 doc->setExportFormat((char *)exportFormat.c_str());
267 doc->process((char *)masterXML.c_str(), (char *)styleSheet.c_str());
271 Scierror(999, _("%s: Could find or create the working directory %s.\n"), fname, outputDirectory.c_str());
281 catch (GiwsException::JniException ex)
283 Scierror(999, _("%s: Error while building documentation: %s.\n"), fname, ex.getJavaDescription().c_str());
284 Scierror(999, _("%s: Execution Java stack: %s.\n"), fname, ex.getJavaStackTrace().c_str());
287 ("If Scilab is started in a chroot, you might want to try to set the two environment variables: SCI_DISABLE_TK=1 SCI_JAVA_ENABLE_HEADLESS=1\n"));
293 createMatrixOfString(pvApiCtx, Rhs + 1, 1, 1, &fileToExec);
294 delete [] fileToExec;
298 createEmptyMatrix(pvApiCtx, Rhs + 1);
306 /*--------------------------------------------------------------------------*/