2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - DIGITEO - 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.
16 #include "configvariable.hxx"
17 #include "callable.hxx"
19 #include "context.hxx"
20 #include "execvisitor.hxx"
21 #include "macrofile.hxx"
22 #include "threadId.hxx"
23 #include "threadmanagement.hxx"
30 #include "FileExist.h"
31 #include "elem_common.h"
32 #include "os_string.h"
33 #include "sci_malloc.h"
41 std::list<std::wstring> ConfigVariable::m_ModuleList;
43 void ConfigVariable::setModuleList(std::list<std::wstring>& _pModule_list)
45 m_ModuleList = _pModule_list;
48 std::list<std::wstring> ConfigVariable::getModuleList()
50 std::list<std::wstring> moduleList(m_ModuleList);
61 std::wstring ConfigVariable::m_SCIPath;
63 void ConfigVariable::setSCIPath(const std::wstring& _SCIPath)
68 std::wstring& ConfigVariable::getSCIPath()
82 std::wstring ConfigVariable::m_SCIHOME;
84 void ConfigVariable::setSCIHOME(const std::wstring& _SCIHOME)
89 std::wstring& ConfigVariable::getSCIHOME()
102 std::wstring ConfigVariable::m_TMPDIR;
104 void ConfigVariable::setTMPDIR(const std::wstring& _TMPDIR)
109 std::wstring& ConfigVariable::getTMPDIR()
121 bool ConfigVariable::m_bForceQuit = false;
123 void ConfigVariable::setForceQuit(bool _bForceQuit)
125 m_bForceQuit = _bForceQuit;
128 bool ConfigVariable::getForceQuit(void)
140 int ConfigVariable::m_iExitStatus = 0;
142 void ConfigVariable::setExitStatus(int _iExitStatus)
144 m_iExitStatus = _iExitStatus;
147 int ConfigVariable::getExitStatus(void)
149 return m_iExitStatus;
156 ** Digit precision, ex format function
160 int ConfigVariable::m_iFormatSize = 0;
162 void ConfigVariable::setFormatSize(int _iFormatSize)
164 m_iFormatSize = _iFormatSize;
167 int ConfigVariable::getFormatSize(void)
169 return m_iFormatSize;
172 int ConfigVariable::m_iFormatMode = 0;
174 void ConfigVariable::setFormatMode(int _iFormatMode)
176 m_iFormatMode = _iFormatMode;
179 int ConfigVariable::getFormatMode(void)
181 return m_iFormatMode;
189 ** Screen console width
193 int ConfigVariable::m_iConsoleWidth = 0;
195 void ConfigVariable::setConsoleWidth(int _iConsoleWidth)
197 m_iConsoleWidth = Max(ICONSOLEWIDTH_MIN, _iConsoleWidth);
200 int ConfigVariable::getConsoleWidth(void)
202 return m_iConsoleWidth;
209 ** Screen console lines
213 int ConfigVariable::m_iConsoleLines = 0; //console lines default value
215 void ConfigVariable::setConsoleLines(int _iConsoleLines)
217 m_iConsoleLines = Max(ICONSOLELINES_MIN, _iConsoleLines);
220 int ConfigVariable::getConsoleLines(void)
222 return m_iConsoleLines;
233 int ConfigVariable::m_iScilabMode = 1; //SCILAB_API = 1 Scilab is launch as an API
235 void ConfigVariable::setScilabMode(int _iScilabMode)
237 m_iScilabMode = _iScilabMode;
240 int ConfigVariable::getScilabMode(void)
242 return m_iScilabMode;
252 bool ConfigVariable::m_bWarningMode = true;
254 void ConfigVariable::setWarningMode(bool _bWarningMode)
256 m_bWarningMode = _bWarningMode;
259 bool ConfigVariable::getWarningMode(void)
261 return m_bWarningMode;
274 bool ConfigVariable::m_bWarningStop = false;
276 void ConfigVariable::setWarningStop(bool _bWarningStop)
278 m_bWarningStop = _bWarningStop;
281 bool ConfigVariable::getWarningStop(void)
283 return m_bWarningStop;
290 ** Old Empty Behaviour
293 bool ConfigVariable::m_bOldEmptyBehaviour = false;
295 void ConfigVariable::setOldEmptyBehaviour(bool _bOldEmptyBehaviour)
297 m_bOldEmptyBehaviour = _bOldEmptyBehaviour;
300 bool ConfigVariable::getOldEmptyBehaviour(void)
302 return m_bOldEmptyBehaviour;
313 std::wstring ConfigVariable::m_HOME;
315 void ConfigVariable::setHOME(const std::wstring& _HOME)
320 std::wstring& ConfigVariable::getHOME()
329 ** Clear last error information
332 bool ConfigVariable::m_bLastErrorCall = false;
334 void ConfigVariable::setLastErrorCall(void)
336 m_bLastErrorCall = true;
339 void ConfigVariable::clearLastError(void)
341 //if (m_bLastErrorCall == false)
346 m_wstErrorFunction = L"";
348 m_bLastErrorCall = false;
355 ** Last Error Message
359 std::wstring ConfigVariable::m_wstError;
361 void ConfigVariable::setLastErrorMessage(const std::wstring& _wstError)
363 m_wstError = _wstError;
366 std::wstring& ConfigVariable::getLastErrorMessage()
378 int ConfigVariable::m_iError = 0;
379 bool ConfigVariable::m_bError = false;
381 void ConfigVariable::setError()
386 bool ConfigVariable::isError()
391 void ConfigVariable::resetError()
396 void ConfigVariable::setLastErrorNumber(int _iError)
401 int ConfigVariable::getLastErrorNumber(void)
413 int ConfigVariable::m_iErrorLine = 0;
415 void ConfigVariable::setLastErrorLine(int _iErrorLine)
417 m_iErrorLine = _iErrorLine;
420 int ConfigVariable::getLastErrorLine(void)
429 ** Last Error Function
433 std::wstring ConfigVariable::m_wstErrorFunction = L"";
435 void ConfigVariable::setLastErrorFunction(const std::wstring& _wstErrorFunction)
437 m_wstErrorFunction = _wstErrorFunction;
440 std::wstring& ConfigVariable::getLastErrorFunction()
442 return m_wstErrorFunction;
450 bool ConfigVariable::m_bVerbose = true;
452 void ConfigVariable::setVerbose(bool _bVerbose)
454 m_bVerbose = _bVerbose;
457 bool ConfigVariable::getVerbose(void)
464 bool ConfigVariable::m_iSilentError = false;
466 void ConfigVariable::setSilentError(bool _iSilentError)
468 m_iSilentError = _iSilentError;
471 bool ConfigVariable::isSilentError(void)
473 return m_iSilentError;
478 int ConfigVariable::m_iUserMode = 0;
479 void ConfigVariable::setUserMode(int _iPromptMode)
481 m_iUserMode = _iPromptMode;
482 ConfigVariable::setPromptMode(_iPromptMode);
485 int ConfigVariable::getUserMode(void)
492 int ConfigVariable::m_iPromptMode = 0;
493 bool ConfigVariable::m_printInput = true;
494 bool ConfigVariable::m_printOutput = true;
495 bool ConfigVariable::m_printInteractive = false;
496 bool ConfigVariable::m_printCompact = false;
499 mode input output compact interactive
500 -----------------------------------------------
510 void ConfigVariable::setPromptMode(int _iPromptMode)
512 m_iPromptMode = _iPromptMode;
513 switch (_iPromptMode)
517 ConfigVariable::setPrintInput(false);
518 ConfigVariable::setPrintOutput(false);
519 ConfigVariable::setPrintCompact(true);
520 ConfigVariable::setPrintInteractive(false);
523 ConfigVariable::setPrintInput(false);
524 ConfigVariable::setPrintOutput(true);
525 ConfigVariable::setPrintCompact(true);
526 ConfigVariable::setPrintInteractive(false);
530 ConfigVariable::setPrintInput(true);
531 ConfigVariable::setPrintOutput(true);
532 ConfigVariable::setPrintCompact(true);
533 ConfigVariable::setPrintInteractive(false);
536 ConfigVariable::setPrintInput(false);
537 ConfigVariable::setPrintOutput(true);
538 ConfigVariable::setPrintCompact(false);
539 ConfigVariable::setPrintInteractive(false);
542 ConfigVariable::setPrintInput(true);
543 ConfigVariable::setPrintOutput(true);
544 ConfigVariable::setPrintCompact(false);
545 ConfigVariable::setPrintInteractive(false);
548 ConfigVariable::setPrintInput(true);
549 ConfigVariable::setPrintOutput(true);
550 ConfigVariable::setPrintCompact(true);
551 ConfigVariable::setPrintInteractive(true);
555 ConfigVariable::setPrintInput(true);
556 ConfigVariable::setPrintOutput(true);
557 ConfigVariable::setPrintCompact(false);
558 ConfigVariable::setPrintInteractive(true);
563 int ConfigVariable::getPromptMode(void)
565 //bool input = isPrintInput();
566 //bool output = isPrintOutput();
567 //bool compact = isPrintCompact();
568 //bool interactive = isPrintInteractive();
570 //return !interactive ?
571 // (/*-1*/ !input && !output ? -1 :
572 // /* 0*/ !input && output && compact ? 0 :
573 // /* 1*/ input && output && compact ? 1 :
574 // /* 2*/ !input && output && !compact ? 2 :
575 // /* 3*/ input && output && !compact ? 3 : 2 /*default*/) :
576 // (/* 4*/ compact ? 4 :
579 return m_iPromptMode;
582 void ConfigVariable::setPrintInput(bool val)
587 bool ConfigVariable::isPrintInput(void)
592 bool ConfigVariable::togglePrintInput(void)
594 m_printInput = !m_printInput;
598 void ConfigVariable::setPrintOutput(bool val)
603 bool ConfigVariable::isPrintOutput(void)
605 return m_printOutput;
608 bool ConfigVariable::togglePrintOutput(void)
610 m_printOutput = !m_printOutput;
611 return m_printOutput;
614 void ConfigVariable::setPrintInteractive(bool val)
616 m_printInteractive = val;
619 bool ConfigVariable::isPrintInteractive(void)
621 return m_printInteractive;
624 bool ConfigVariable::togglePrintInteractive(void)
626 m_printInteractive = !m_printInteractive;
627 return m_printInteractive;
630 void ConfigVariable::setPrintCompact(bool val)
632 m_printCompact = val;
635 bool ConfigVariable::isPrintCompact(void)
637 return m_printCompact;
640 bool ConfigVariable::togglePrintCompact(void)
642 m_printCompact = !m_printCompact;
643 return m_printCompact;
655 int ConfigVariable::m_iPauseLevel = 0;
656 std::list<int> ConfigVariable::m_listScope;
658 void ConfigVariable::IncreasePauseLevel()
661 m_listScope.push_back(symbol::Context::getInstance()->getScopeLevel());
664 void ConfigVariable::DecreasePauseLevel()
667 m_listScope.pop_back();
670 int ConfigVariable::getActivePauseLevel()
672 return m_listScope.back();
675 int ConfigVariable::getPauseLevel()
677 return m_iPauseLevel;
689 std::vector<ConfigVariable::DynamicLibraryStr*> ConfigVariable::m_DynLibList;
690 std::list<ConfigVariable::EntryPointStr*> ConfigVariable::m_EntryPointList;
692 ConfigVariable::DynamicLibraryStr* ConfigVariable::getNewDynamicLibraryStr()
694 DynamicLibraryStr* pDL = (DynamicLibraryStr*)MALLOC(sizeof(DynamicLibraryStr));
695 pDL->pwstLibraryName = NULL;
700 ConfigVariable::EntryPointStr* ConfigVariable::getNewEntryPointStr()
702 EntryPointStr* pEP = (EntryPointStr*)MALLOC(sizeof(EntryPointStr));
704 pEP->functionPtr = NULL;
706 pEP->pwstEntryPointName = NULL;
710 void ConfigVariable::setLibraryName(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary, wchar_t* _pwstLibraryName)
712 if (_pDynamicLibrary)
714 if (_pDynamicLibrary->pwstLibraryName)
716 FREE(_pDynamicLibrary->pwstLibraryName);
718 _pDynamicLibrary->pwstLibraryName = os_wcsdup(_pwstLibraryName);
722 void ConfigVariable::setEntryPointName(ConfigVariable::EntryPointStr* _pEntryPoint, wchar_t* _pwstEntryPointName)
726 if (_pEntryPoint->pwstEntryPointName)
728 FREE(_pEntryPoint->pwstEntryPointName);
730 _pEntryPoint->pwstEntryPointName = os_wcsdup(_pwstEntryPointName);
734 /* Dynamic libraries functions */
735 int ConfigVariable::addDynamicLibrary(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary)
737 for (int i = 0; i < (int)m_DynLibList.size(); i++)
739 if (m_DynLibList[i] == NULL)
741 m_DynLibList[i] = _pDynamicLibrary;
746 m_DynLibList.push_back(_pDynamicLibrary);
747 return (int)m_DynLibList.size() - 1;
750 void ConfigVariable::removeDynamicLibrary(int _iDynamicLibraryIndex)
752 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
754 std::list<EntryPointStr*>::const_iterator it;
755 for (it = m_EntryPointList.begin(); it != m_EntryPointList.end();)
757 //clear all entry points linked to removed dynamic library
758 if ((*it)->iLibIndex == _iDynamicLibraryIndex)
760 EntryPointStr* pEP = *it;
761 m_EntryPointList.remove(*it);
762 FREE(pEP->pwstEntryPointName);
764 if (m_EntryPointList.size() == 0)
768 it = m_EntryPointList.begin();
775 //remove dynamic library
776 FREE(m_DynLibList[_iDynamicLibraryIndex]->pwstLibraryName);
777 FREE(m_DynLibList[_iDynamicLibraryIndex]);
778 m_DynLibList[_iDynamicLibraryIndex] = NULL;
781 //clean dynamic library vector
782 while (m_DynLibList.size() != 0 && m_DynLibList.back() == NULL)
784 m_DynLibList.pop_back();
788 ConfigVariable::DynamicLibraryStr* ConfigVariable::getDynamicLibrary(int _iDynamicLibraryIndex)
790 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
792 return m_DynLibList[_iDynamicLibraryIndex];
797 bool ConfigVariable::isDynamicLibrary(int _iDynamicLibraryIndex)
799 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
801 if (m_DynLibList[_iDynamicLibraryIndex] != NULL)
809 void ConfigVariable::addEntryPoint(ConfigVariable::EntryPointStr* _pEP)
813 m_EntryPointList.push_back(_pEP);
817 ConfigVariable::EntryPointStr* ConfigVariable::getEntryPoint(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex)
819 std::list<EntryPointStr*>::const_iterator it;
820 for (it = m_EntryPointList.begin(); it != m_EntryPointList.end(); it++)
822 //by pass iLibIndex check if _iDynamicLibraryIndex == -1
823 if (_iDynamicLibraryIndex == -1 || (*it)->iLibIndex == _iDynamicLibraryIndex)
825 if (wcscmp((*it)->pwstEntryPointName, _pwstEntryPointName) == 0)
834 dynlib_ptr ConfigVariable::getEntryPointFromPosition(int position)
836 std::list<EntryPointStr*>::const_iterator it;
838 for (it = m_EntryPointList.begin(); it != m_EntryPointList.end(); it++, ++pos)
842 return (*it)->functionPtr;
848 int ConfigVariable::getEntryPointPosition(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex)
851 std::list<EntryPointStr*>::const_iterator it;
852 for (it = m_EntryPointList.begin(); it != m_EntryPointList.end(); it++, ++pos)
854 //by pass iLibIndex check if _iDynamicLibraryIndex == -1
855 if (_iDynamicLibraryIndex == -1 || (*it)->iLibIndex == _iDynamicLibraryIndex)
857 if (wcscmp((*it)->pwstEntryPointName, _pwstEntryPointName) == 0)
866 std::vector<std::wstring> ConfigVariable::getEntryPointNameList()
868 std::vector<std::wstring> EntryPointNames;
869 std::list<EntryPointStr*>::const_iterator it;
870 for (it = m_EntryPointList.begin(); it != m_EntryPointList.end(); it++)
872 EntryPointNames.push_back((*it)->pwstEntryPointName);
874 return EntryPointNames;
877 std::vector<ConfigVariable::DynamicLibraryStr*>* ConfigVariable::getDynamicLibraryList()
879 return &m_DynLibList;
882 std::list<ConfigVariable::EntryPointStr*>* ConfigVariable::getEntryPointList()
884 return &m_EntryPointList;
888 std::map<std::wstring, DynLibHandle> ConfigVariable::m_DynModules;
890 void ConfigVariable::addDynModule(const std::wstring& _name, DynLibHandle _lib)
892 m_DynModules[_name] = _lib;
895 void ConfigVariable::removeDynModule(const std::wstring& _name)
897 m_DynModules.erase(_name);
900 DynLibHandle ConfigVariable::getDynModule(const std::wstring& _name)
902 std::map<std::wstring, DynLibHandle>::iterator it;
903 it = m_DynModules.find(_name);
904 if (it != m_DynModules.end())
912 int ConfigVariable::getDynModuleCount()
914 return (int)m_DynModules.size();
917 DynLibHandle* ConfigVariable::getAllDynModule()
919 DynLibHandle* moduleList = new DynLibHandle[m_DynModules.size()];
920 std::map<std::wstring, DynLibHandle>::iterator it = m_DynModules.begin();
921 std::map<std::wstring, DynLibHandle>::iterator itEnd = m_DynModules.end();
922 for (int i = 0; it != itEnd; ++it, ++i)
924 moduleList[i] = it->second;
930 void ConfigVariable::cleanDynModule()
932 m_DynModules.clear();
935 // Command Line Arguments
936 std::vector<std::wstring> ConfigVariable::m_Args;
937 bool ConfigVariable::m_bTimed = false;
938 bool ConfigVariable::m_bSerialize = false;
940 void ConfigVariable::setCommandLineArgs(int _iArgs, char** _pstArgs)
943 for (int i = 0; i < _iArgs; i++)
945 wchar_t* ws = to_wide_string(_pstArgs[i]);
946 m_Args.push_back(ws);
951 wchar_t** ConfigVariable::getCommandLineArgs(int* _piCount)
953 wchar_t** pwstArgs = NULL;
954 *_piCount = (int)m_Args.size();
957 pwstArgs = (wchar_t**)MALLOC(*_piCount * sizeof(wchar_t*));
958 for (int i = 0; i < *_piCount; i++)
960 pwstArgs[i] = os_wcsdup(m_Args[i].c_str());
966 bool ConfigVariable::getTimed()
971 void ConfigVariable::setTimed(bool _bTimed)
976 bool ConfigVariable::getSerialize()
981 void ConfigVariable::setSerialize(bool _bSerialize)
983 m_bSerialize = _bSerialize;
995 //SCILAB_INPUT_METHOD ConfigVariable::m_pInputMethod = NULL;
997 //void ConfigVariable::setInputMethod(SCILAB_INPUT_METHOD _pInputMethod)
999 // m_pInputMethod = _pInputMethod;
1002 //SCILAB_INPUT_METHOD ConfigVariable::getInputMethod(void)
1004 // return m_pInputMethod;
1016 //SCILAB_OUTPUT_METHOD ConfigVariable::m_pOutputMethod = NULL;
1018 //void ConfigVariable::setOutputMethod(SCILAB_OUTPUT_METHOD _pOutputMethod)
1020 // m_pOutputMethod = _pOutputMethod;
1023 //SCILAB_OUTPUT_METHOD ConfigVariable::getOutputMethod(void)
1025 // return m_pOutputMethod;
1037 types::Callable* ConfigVariable::m_schurFunction = NULL;
1039 void ConfigVariable::setSchurFunction(types::Callable* _schurFunction)
1041 m_schurFunction = _schurFunction;
1044 types::Callable* ConfigVariable::getSchurFunction()
1046 return m_schurFunction;
1054 ** grand (module randlib)
1058 int ConfigVariable::m_currentBaseGen = 0;
1059 int ConfigVariable::m_currentClcg4 = 0;
1061 void ConfigVariable::setCurrentBaseGen(int _gen)
1063 m_currentBaseGen = _gen;
1066 int ConfigVariable::getCurrentBaseGen()
1068 return m_currentBaseGen;
1071 void ConfigVariable::setCurrentClcg4(int _clcg4)
1073 m_currentClcg4 = _clcg4;
1076 int ConfigVariable::getCurrentClcg4()
1078 return m_currentClcg4;
1085 ** Start finish flag
1088 bool ConfigVariable::m_bStartProcessing = false;
1089 bool ConfigVariable::m_bEndProcessing = false;
1091 void ConfigVariable::setStartProcessing(bool _bStartProcessing)
1093 m_bStartProcessing = _bStartProcessing;
1096 bool ConfigVariable::getStartProcessing()
1098 return m_bStartProcessing;
1101 void ConfigVariable::setEndProcessing(bool _bEndProcessing)
1103 m_bEndProcessing = _bEndProcessing;
1106 bool ConfigVariable::getEndProcessing()
1108 return m_bEndProcessing;
1118 int ConfigVariable::m_iIeee = 2;
1120 void ConfigVariable::setIeee(int _iIeee)
1125 int ConfigVariable::getIeee()
1137 int ConfigVariable::m_iSimpMode = 1;
1139 void ConfigVariable::setSimpMode(int _iSimpMode)
1141 m_iSimpMode = _iSimpMode;
1144 int ConfigVariable::getSimpMode()
1156 int ConfigVariable::m_iFuncprot = 1;
1158 void ConfigVariable::setFuncprot(int _iFuncprot)
1160 m_iFuncprot = _iFuncprot;
1163 int ConfigVariable::getFuncprot()
1176 std::vector<ConfigVariable::WhereEntry> ConfigVariable::m_Where;
1177 std::vector<ConfigVariable::WhereErrorEntry> ConfigVariable::m_WhereError;
1178 std::vector<int> ConfigVariable::m_FirstMacroLine;
1179 void ConfigVariable::where_begin(int _iLineNum, int _iLineLocation, types::Callable* _pCall)
1181 const std::wstring* wstrFileName = nullptr;
1182 types::Callable* pCall = _pCall;
1183 if (pCall->isMacroFile())
1185 types::Macro* pM = pCall->getAs<types::MacroFile>()->getMacro();
1186 wstrFileName = &pM->getFileName();
1189 else if (pCall->isMacro())
1191 types::Macro* pM = pCall->getAs<types::Macro>();
1192 wstrFileName = &pM->getFileName();
1195 m_Where.push_back({_iLineNum, _iLineLocation, symbol::Context::getInstance()->getScopeLevel(), pCall, wstrFileName});
1198 void ConfigVariable::where_end()
1203 const std::vector<ConfigVariable::WhereEntry>& ConfigVariable::getWhere()
1208 void ConfigVariable::macroFirstLine_begin(int _iLine)
1210 m_FirstMacroLine.push_back(_iLine);
1213 void ConfigVariable::macroFirstLine_end()
1215 m_FirstMacroLine.pop_back();
1218 int ConfigVariable::getMacroFirstLines()
1220 if (m_FirstMacroLine.empty())
1225 return m_FirstMacroLine.back();
1227 void ConfigVariable::setFileNameToLastWhere(const std::wstring* _fileName)
1229 m_Where.back().m_file_name = _fileName;
1232 void ConfigVariable::whereErrorToString(std::wostringstream& ostr)
1235 bool isExecstr = false;
1236 bool isExecfile = false;
1238 // get max length of functions name and check if exec or execstr have been called.
1239 for (auto& where : m_WhereError)
1241 if (isExecstr == false && where.m_function_name == L"execstr")
1246 else if (isExecfile == false && where.m_function_name == L"exec")
1252 iLenName = std::max((int)where.m_function_name.length(), iLenName);
1254 // in case of bin file, the file path and line is displayed only if the associated .sci file exists
1255 if (where.m_file_name != L"" && where.m_file_name.find(L".bin") != std::wstring::npos)
1257 std::size_t pos = where.m_file_name.find_last_of(L".");
1258 where.m_file_name.replace(pos, pos + 4, L".sci");
1259 if (FileExistW(const_cast<wchar_t*>(where.m_file_name.c_str())) == false)
1261 where.m_file_name = L"";
1269 // initialize localized strings
1270 std::wstring wstrBuiltin(_W("in builtin "));
1271 std::wstring wstrAtLine(_W("at line % 5d of function "));
1272 std::wstring wstrExecStr(_W("at line % 5d of executed string "));
1273 std::wstring wstrExecFile(_W("at line % 5d of executed file "));
1275 // compute max size between "at line xxx of function" and "in builtin "
1276 // +1 : line number is pad to 5. length of "% 5d" + 1 == 5
1277 int iMaxLen = std::max(wstrAtLine.length() + 1, wstrBuiltin.length());
1280 iMaxLen = std::max(((int)wstrExecStr.length()) + 1, iMaxLen);
1285 iMaxLen = std::max(((int)wstrExecFile.length()) + 1, iMaxLen);
1291 for (auto& where : m_WhereError)
1293 ostr.width(iMaxLen);
1294 if (where.m_line == 0)
1296 ostr << wstrBuiltin;
1300 if (where.m_function_name == L"execstr")
1303 wchar_t wcsTmp[bsiz];
1304 os_swprintf(wcsTmp, bsiz, wstrExecStr.c_str(), where.m_line);
1305 ostr << wcsTmp << std::endl;
1308 else if (where.m_function_name == L"exec")
1310 wchar_t wcsTmp[bsiz];
1311 os_swprintf(wcsTmp, bsiz, wstrExecFile.c_str(), where.m_line);
1312 ostr << wcsTmp << where.m_file_name << std::endl;
1317 wchar_t wcsTmp[bsiz];
1318 os_swprintf(wcsTmp, bsiz, wstrAtLine.c_str(), where.m_line);
1323 ostr.width(iLenName);
1324 ostr << where.m_function_name;
1326 if (where.m_file_name != L"")
1328 // -1 because the first line of a function dec is : "function myfunc()"
1329 ostr << L"( " << where.m_file_name << L" " << _W("line") << L" " << where.m_first_line + where.m_line - 1 << L" )";
1336 << std::resetiosflags(std::ios::adjustfield);
1339 void ConfigVariable::fillWhereError(int _iErrorLine)
1342 if (m_WhereError.empty())
1345 if (_iErrorLine != 0)
1347 // +1 because the first line of the funtionDec "function func()" is the line 1.
1348 iTmp = _iErrorLine - getMacroFirstLines() + 1;
1351 m_WhereError.reserve(m_Where.size());
1352 for (auto where = m_Where.rbegin(); where != m_Where.rend(); ++where)
1354 if (where->m_file_name != nullptr)
1356 m_WhereError.push_back({iTmp, where->m_absolute_line, where->call->getFirstLine(), where->call->getName(), *where->m_file_name});
1360 m_WhereError.push_back({iTmp, where->m_absolute_line, where->call->getFirstLine(), where->call->getName(), L""});
1363 iTmp = where->m_line;
1368 void ConfigVariable::resetWhereError()
1370 m_WhereError.clear();
1378 ** module called with variable by reference
1382 std::list<std::wstring> ConfigVariable::m_ReferenceModules;
1384 bool ConfigVariable::checkReferenceModule(const std::wstring& _module)
1386 for (auto ref : m_ReferenceModules)
1397 void ConfigVariable::addReferenceModule(const std::wstring& _module)
1399 if (checkReferenceModule(_module) == false)
1401 m_ReferenceModules.push_back(_module);
1405 void ConfigVariable::removeReferenceModule(const std::wstring& _module)
1407 if (checkReferenceModule(_module))
1409 m_ReferenceModules.remove(_module);
1413 std::list<std::wstring> ConfigVariable::getReferenceModules()
1415 std::list<std::wstring> l(m_ReferenceModules);
1428 int ConfigVariable::m_analyzerOptions = 0;
1429 void ConfigVariable::setAnalyzerOptions(int _val)
1431 m_analyzerOptions = _val;
1434 int ConfigVariable::getAnalyzerOptions(void)
1436 return m_analyzerOptions;
1448 bool ConfigVariable::m_dividebyzero = false;
1449 void ConfigVariable::setDivideByZero(bool _dividebyzero)
1451 m_dividebyzero = _dividebyzero;
1454 bool ConfigVariable::isDivideByZero(void)
1456 return m_dividebyzero;
1463 std::string ConfigVariable::mexFunctionName;
1464 void ConfigVariable::setMexFunctionName(const std::string& name)
1466 mexFunctionName = name;
1469 std::string& ConfigVariable::getMexFunctionName()
1471 return mexFunctionName;
1477 // executed file with exec
1478 int ConfigVariable::m_iFileID = 0;
1479 void ConfigVariable::setExecutedFileID(int _iFileID)
1481 m_iFileID = _iFileID;
1484 int ConfigVariable::getExecutedFileID()
1490 ** string read from console by scilabRead
1493 std::atomic<char*> ConfigVariable::m_pcConsoleReadStr(nullptr);
1494 void ConfigVariable::setConsoleReadStr(char* _pcConsoleReadStr)
1496 m_pcConsoleReadStr = _pcConsoleReadStr;
1499 char* ConfigVariable::getConsoleReadStr()
1501 ThreadManagement::LockScilabRead();
1502 char* tmp = m_pcConsoleReadStr.exchange(NULL);
1503 ThreadManagement::UnlockScilabRead();
1511 ** Tell to the console thread if the scilabRead return
1512 ** is a scilab command or not.
1515 std::atomic<int> ConfigVariable::m_isScilabCommand(1);
1516 void ConfigVariable::setScilabCommand(int _isciCmd)
1518 m_isScilabCommand = _isciCmd;
1521 int ConfigVariable::isScilabCommand()
1523 return m_isScilabCommand.exchange(1);
1529 //debugger information
1530 bool ConfigVariable::m_bEnabledebug = false;
1531 std::unique_ptr<ast::ConstVisitor> ConfigVariable::m_defaultvisitor(nullptr);
1533 bool ConfigVariable::getEnableDebug()
1535 return m_bEnabledebug;
1538 void ConfigVariable::setEnableDebug(bool _enable)
1540 m_bEnabledebug = _enable;
1543 void ConfigVariable::setDefaultVisitor(ast::ConstVisitor* _default)
1545 m_defaultvisitor.reset(_default);
1548 ast::ConstVisitor* ConfigVariable::getDefaultVisitor()
1550 if (m_defaultvisitor.get() == nullptr)
1552 m_defaultvisitor.reset(new ast::ExecVisitor());
1554 return m_defaultvisitor->clone();
1557 bool ConfigVariable::executionbreak = false;
1559 bool ConfigVariable::isExecutionBreak()
1561 return executionbreak;
1564 void ConfigVariable::setExecutionBreak()
1566 executionbreak = true;
1569 void ConfigVariable::resetExecutionBreak()
1571 executionbreak = false;
1575 int ConfigVariable::recursionLimit = 25;
1577 int ConfigVariable::recursionLimit = 1000;
1579 int ConfigVariable::recursionLevel = 0;
1581 int ConfigVariable::getRecursionLimit()
1583 return recursionLimit;
1586 int ConfigVariable::setRecursionLimit(int val)
1588 int old = recursionLimit;
1589 recursionLimit = std::max(10, val);
1593 int ConfigVariable::getRecursionLevel()
1595 return recursionLevel;
1598 bool ConfigVariable::increaseRecursion()
1600 if (recursionLevel < recursionLimit)
1609 void ConfigVariable::decreaseRecursion()
1611 //recursionLevel = std::max(--recursionLevel, 0);
1615 void ConfigVariable::resetRecursionLevel()
1621 bool ConfigVariable::webMode = true;
1623 bool ConfigVariable::getWebMode()
1628 void ConfigVariable::setWebMode(bool _mode)