2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
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
13 #include "configvariable.hxx"
14 #include "context.hxx"
19 #include "os_wcsdup.h"
20 #include "sci_malloc.h"
21 #include "elem_common.h"
27 std::list<std::wstring> ConfigVariable::m_ModuleList;
29 void ConfigVariable::setModuleList(std::list<std::wstring>& _pModule_list)
31 m_ModuleList = _pModule_list;
34 std::list<std::wstring> ConfigVariable::getModuleList()
36 std::list<std::wstring> moduleList(m_ModuleList);
47 std::wstring ConfigVariable::m_SCIPath;
49 void ConfigVariable::setSCIPath(std::wstring& _SCIPath)
54 std::wstring ConfigVariable::getSCIPath()
68 std::wstring ConfigVariable::m_SCIHOME;
70 void ConfigVariable::setSCIHOME(std::wstring& _SCIHOME)
75 std::wstring ConfigVariable::getSCIHOME()
88 std::wstring ConfigVariable::m_TMPDIR;
90 void ConfigVariable::setTMPDIR(std::wstring& _TMPDIR)
95 std::wstring ConfigVariable::getTMPDIR()
107 bool ConfigVariable::m_bForceQuit = false;
109 void ConfigVariable::setForceQuit(bool _bForceQuit)
111 m_bForceQuit = _bForceQuit;
114 bool ConfigVariable::getForceQuit(void)
126 int ConfigVariable::m_iExitStatus = 0;
128 void ConfigVariable::setExitStatus(int _iExitStatus)
130 m_iExitStatus = _iExitStatus;
133 int ConfigVariable::getExitStatus(void)
135 return m_iExitStatus;
142 ** Digit precision, ex format function
146 int ConfigVariable::m_iFormatSize = 0;
148 void ConfigVariable::setFormatSize(int _iFormatSize)
150 m_iFormatSize = _iFormatSize;
153 int ConfigVariable::getFormatSize(void)
155 return m_iFormatSize;
158 int ConfigVariable::m_iFormatMode = 0;
160 void ConfigVariable::setFormatMode(int _iFormatMode)
162 m_iFormatMode = _iFormatMode;
165 int ConfigVariable::getFormatMode(void)
167 return m_iFormatMode;
175 ** Screen console width
179 int ConfigVariable::m_iConsoleWidth = 0;
181 void ConfigVariable::setConsoleWidth(int _iConsoleWidth)
183 m_iConsoleWidth = _iConsoleWidth;
186 int ConfigVariable::getConsoleWidth(void)
188 return m_iConsoleWidth;
195 ** Screen console lines
199 int ConfigVariable::m_iConsoleLines = 0; //console lines default value
201 void ConfigVariable::setConsoleLines(int _iConsoleLines)
203 m_iConsoleLines = _iConsoleLines;
206 int ConfigVariable::getConsoleLines(void)
208 return m_iConsoleLines;
219 int ConfigVariable::m_iScilabMode = 0;
221 void ConfigVariable::setScilabMode(int _iScilabMode)
223 m_iScilabMode = _iScilabMode;
226 int ConfigVariable::getScilabMode(void)
228 return m_iScilabMode;
238 bool ConfigVariable::m_bWarningMode = true;
240 void ConfigVariable::setWarningMode(bool _bWarningMode)
242 m_bWarningMode = _bWarningMode;
245 bool ConfigVariable::getWarningMode(void)
247 return m_bWarningMode;
258 std::wstring ConfigVariable::m_HOME;
260 void ConfigVariable::setHOME(std::wstring& _HOME)
265 std::wstring ConfigVariable::getHOME()
274 ** Clear last error information
277 bool ConfigVariable::m_bLastErrorCall = false;
279 void ConfigVariable::setLastErrorCall(void)
281 m_bLastErrorCall = true;
284 void ConfigVariable::clearLastError(void)
286 //if (m_bLastErrorCall == false)
291 m_wstErrorFunction = L"";
293 m_bLastErrorCall = false;
300 ** Last Error Message
304 std::wstring ConfigVariable::m_wstError;
306 void ConfigVariable::setLastErrorMessage(std::wstring _wstError)
308 wchar_t* pwstTemp1 = os_wcsdup(_wstError.c_str());
309 m_wstError = pwstTemp1;
312 std::wstring ConfigVariable::getLastErrorMessage()
324 int ConfigVariable::m_iError = 0;
325 bool ConfigVariable::m_bError = false;
327 void ConfigVariable::setError()
332 bool ConfigVariable::isError()
337 void ConfigVariable::resetError()
342 void ConfigVariable::setLastErrorNumber(int _iError)
347 int ConfigVariable::getLastErrorNumber(void)
359 int ConfigVariable::m_iErrorLine = 0;
361 void ConfigVariable::setLastErrorLine(int _iErrorLine)
363 m_iErrorLine = _iErrorLine;
366 int ConfigVariable::getLastErrorLine(void)
375 ** Last Error Function
379 std::wstring ConfigVariable::m_wstErrorFunction;
381 void ConfigVariable::setLastErrorFunction(std::wstring _wstErrorFunction)
383 m_wstErrorFunction = _wstErrorFunction;
386 std::wstring ConfigVariable::getLastErrorFunction()
388 return m_wstErrorFunction;
400 int ConfigVariable::m_iPromptMode = 0;
401 int ConfigVariable::m_iSilentError = 0;
402 bool ConfigVariable::m_bVerbose = true;
404 void ConfigVariable::setPromptMode(int _iPromptMode)
406 m_iPromptMode = _iPromptMode;
407 if (m_iPromptMode == 0)
409 //m_iPromptMode = -1;
413 int ConfigVariable::getPromptMode(void)
415 return m_iPromptMode;
418 bool ConfigVariable::isPromptShow(void)
420 if ( m_iPromptMode == 0 ||
421 m_iPromptMode == 1 ||
422 m_iPromptMode == 2 ||
433 void ConfigVariable::setSilentError(int _iSilentError)
435 m_iSilentError = _iSilentError;
438 int ConfigVariable::getSilentError(void)
440 return m_iSilentError;
443 void ConfigVariable::setVerbose(bool _bVerbose)
445 m_bVerbose = _bVerbose;
448 bool ConfigVariable::getVerbose(void)
458 std::list<types::ThreadId *> ConfigVariable::m_threadList;
460 types::ThreadId* ConfigVariable::getLastPausedThread()
462 std::list<types::ThreadId *>::reverse_iterator it;
463 for (it = m_threadList.rbegin() ; it != m_threadList.rend() ; it++)
465 if ((*it)->getStatus() == types::ThreadId::Paused)
473 types::ThreadId* ConfigVariable::getLastRunningThread()
475 std::list<types::ThreadId *>::reverse_iterator it;
476 for (it = m_threadList.rbegin() ; it != m_threadList.rend() ; it++)
478 if ((*it)->getStatus() == types::ThreadId::Running)
486 types::ThreadId* ConfigVariable::getLastThread()
488 return m_threadList.back();
491 types::Cell* ConfigVariable::getAllThreads(void)
493 int iSize = (int) ConfigVariable::m_threadList.size();
497 return new types::Cell();
501 types::Cell *pcResult = new types::Cell(iSize, 1);
502 std::list<types::ThreadId *>::iterator it;
504 for (it = ConfigVariable::m_threadList.begin() ; it != ConfigVariable::m_threadList.end() ; ++it, ++i)
506 pcResult->set(i, *it);
513 void ConfigVariable::addThread(types::ThreadId* _thread)
515 _thread->IncreaseRef();
516 m_threadList.push_back(_thread);
520 types::ThreadId* ConfigVariable::getThread(__threadKey _key)
522 std::list<types::ThreadId *>::const_iterator it;
524 for (it = ConfigVariable::m_threadList.begin() ; it != ConfigVariable::m_threadList.end() ; ++it)
526 if ((*it)->getKey() == _key)
535 void ConfigVariable::deleteThread(__threadKey _key)
537 //for(int i = 0 ; i < m_threadList.size() ; i++)
539 // types::ThreadId* pThread = m_threadList[i];
540 // if(pThread->getKey() == _key)
542 // pThread->DecreaseRef();
543 // if(pThread->isDeletable())
546 // m_threadList.erase(.begin() + i - 1);
550 std::list<types::ThreadId *>::iterator it;
551 for (it = ConfigVariable::m_threadList.begin() ; it != ConfigVariable::m_threadList.end() ; ++it)
553 if ((*it)->getKey() == _key)
555 (*it)->DecreaseRef();
556 if ((*it)->isDeletable())
560 m_threadList.erase(it);
576 int ConfigVariable::m_iPauseLevel = 0;
577 std::list<int> ConfigVariable::m_listScope;
579 void ConfigVariable::IncreasePauseLevel()
582 m_listScope.push_back(symbol::Context::getInstance()->getScopeLevel());
585 void ConfigVariable::DecreasePauseLevel()
588 m_listScope.pop_back();
591 int ConfigVariable::getActivePauseLevel()
593 return m_listScope.back();
596 int ConfigVariable::getPauseLevel()
598 return m_iPauseLevel;
610 std::vector<ConfigVariable::DynamicLibraryStr*> ConfigVariable::m_DynLibList;
611 std::list<ConfigVariable::EntryPointStr*> ConfigVariable::m_EntryPointList;
614 ConfigVariable::DynamicLibraryStr* ConfigVariable::getNewDynamicLibraryStr()
616 DynamicLibraryStr* pDL = (DynamicLibraryStr*)MALLOC(sizeof(DynamicLibraryStr));
617 pDL->pwstLibraryName = NULL;
622 ConfigVariable::EntryPointStr* ConfigVariable::getNewEntryPointStr()
624 EntryPointStr* pEP = (EntryPointStr*)MALLOC(sizeof(EntryPointStr));
626 pEP->functionPtr = NULL;
628 pEP->pwstEntryPointName = NULL;
632 void ConfigVariable::setLibraryName(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary, wchar_t* _pwstLibraryName)
634 if (_pDynamicLibrary)
636 if (_pDynamicLibrary->pwstLibraryName)
638 FREE(_pDynamicLibrary->pwstLibraryName);
640 _pDynamicLibrary->pwstLibraryName = os_wcsdup(_pwstLibraryName);
644 void ConfigVariable::setEntryPointName(ConfigVariable::EntryPointStr* _pEntryPoint, wchar_t* _pwstEntryPointName)
648 if (_pEntryPoint->pwstEntryPointName)
650 FREE(_pEntryPoint->pwstEntryPointName);
652 _pEntryPoint->pwstEntryPointName = os_wcsdup(_pwstEntryPointName);;
656 /* Dynamic libraries functions */
657 int ConfigVariable::addDynamicLibrary(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary)
659 for (int i = 0 ; i < (int)m_DynLibList.size() ; i++)
661 if (m_DynLibList[i] == NULL)
663 m_DynLibList[i] = _pDynamicLibrary;
668 m_DynLibList.push_back(_pDynamicLibrary);
669 return (int)m_DynLibList.size() - 1;
672 void ConfigVariable::removeDynamicLibrary(int _iDynamicLibraryIndex)
674 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
676 std::list<EntryPointStr*>::const_iterator it;
677 for (it = m_EntryPointList.begin() ; it != m_EntryPointList.end() ; it++)
679 //clear all entry points linked to removed dynamic library
680 if ((*it)->iLibIndex == _iDynamicLibraryIndex)
682 m_EntryPointList.remove(*it);
683 if (m_EntryPointList.size() == 0)
687 it = m_EntryPointList.begin();
690 //remove dynamic library
691 m_DynLibList[_iDynamicLibraryIndex] = NULL;
694 //clean dynamic library vector
695 while (m_DynLibList.size() != 0 && m_DynLibList.back() == NULL)
697 m_DynLibList.pop_back();
701 ConfigVariable::DynamicLibraryStr* ConfigVariable::getDynamicLibrary(int _iDynamicLibraryIndex)
703 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
705 return m_DynLibList[_iDynamicLibraryIndex];
710 bool ConfigVariable::isDynamicLibrary(int _iDynamicLibraryIndex)
712 if (_iDynamicLibraryIndex < (int)m_DynLibList.size())
714 if (m_DynLibList[_iDynamicLibraryIndex] != NULL)
722 void ConfigVariable::addEntryPoint(ConfigVariable::EntryPointStr* _pEP)
726 m_EntryPointList.push_back(_pEP);
730 ConfigVariable::EntryPointStr* ConfigVariable::getEntryPoint(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex)
732 std::list<EntryPointStr*>::const_iterator it;
733 for (it = m_EntryPointList.begin() ; it != m_EntryPointList.end() ; it++)
735 //by pass iLibIndex check if _iDynamicLibraryIndex == -1
736 if (_iDynamicLibraryIndex == -1 || (*it)->iLibIndex == _iDynamicLibraryIndex)
738 if (wcscmp((*it)->pwstEntryPointName, _pwstEntryPointName) == 0)
747 std::vector<std::wstring> ConfigVariable::getEntryPointNameList()
749 std::vector<std::wstring> EntryPointNames;
750 std::list<EntryPointStr*>::const_iterator it;
751 for (it = m_EntryPointList.begin() ; it != m_EntryPointList.end() ; it++)
753 EntryPointNames.push_back((*it)->pwstEntryPointName);
755 return EntryPointNames;
758 std::vector<ConfigVariable::DynamicLibraryStr*>* ConfigVariable::getDynamicLibraryList()
760 return &m_DynLibList;
763 std::list<ConfigVariable::EntryPointStr*>* ConfigVariable::getEntryPointList()
765 return &m_EntryPointList;
769 std::map<std::wstring, DynLibHandle> ConfigVariable::m_DynModules;
771 void ConfigVariable::addDynModule(std::wstring _name, DynLibHandle _lib)
773 m_DynModules[_name] = _lib;
776 void ConfigVariable::removeDynModule(std::wstring _name)
778 m_DynModules.erase(_name);
781 DynLibHandle ConfigVariable::getDynModule(std::wstring _name)
783 std::map<std::wstring, DynLibHandle>::iterator it;
784 it = m_DynModules.find(_name);
785 if (it != m_DynModules.end())
793 int ConfigVariable::getDynModuleCount()
795 return (int)m_DynModules.size();
798 DynLibHandle* ConfigVariable::getAllDynModule()
800 DynLibHandle* moduleList = new DynLibHandle[m_DynModules.size()];
801 std::map<std::wstring, DynLibHandle>::iterator it = m_DynModules.begin();
802 std::map<std::wstring, DynLibHandle>::iterator itEnd = m_DynModules.end();
803 for (int i = 0; it != itEnd ; ++it, ++i)
805 moduleList[i] = it->second;
811 void ConfigVariable::cleanDynModule()
813 m_DynModules.clear();
816 // Command Line Arguments
817 std::vector<std::wstring> ConfigVariable::m_Args;
818 bool ConfigVariable::m_bTimed = false;
819 bool ConfigVariable::m_bSerialize = false;
821 void ConfigVariable::setCommandLineArgs(int _iArgs, char** _pstArgs)
824 for (int i = 0 ; i < _iArgs ; i++)
826 wchar_t * ws = to_wide_string(_pstArgs[i]);
827 m_Args.push_back(ws);
832 wchar_t** ConfigVariable::getCommandLineArgs(int* _piCount)
834 wchar_t** pwstArgs = (wchar_t**)MALLOC(m_Args.size() * sizeof(wchar_t*));
835 for (int i = 0 ; i < (int)m_Args.size() ; i++)
837 pwstArgs[i] = os_wcsdup(m_Args[i].c_str());
840 *_piCount = (int)m_Args.size();
844 bool ConfigVariable::getTimed()
849 void ConfigVariable::setTimed(bool _bTimed)
854 bool ConfigVariable::getSerialize()
859 void ConfigVariable::setSerialize(bool _bSerialize)
861 m_bSerialize = _bSerialize;
873 //SCILAB_INPUT_METHOD ConfigVariable::m_pInputMethod = NULL;
875 //void ConfigVariable::setInputMethod(SCILAB_INPUT_METHOD _pInputMethod)
877 // m_pInputMethod = _pInputMethod;
880 //SCILAB_INPUT_METHOD ConfigVariable::getInputMethod(void)
882 // return m_pInputMethod;
894 //SCILAB_OUTPUT_METHOD ConfigVariable::m_pOutputMethod = NULL;
896 //void ConfigVariable::setOutputMethod(SCILAB_OUTPUT_METHOD _pOutputMethod)
898 // m_pOutputMethod = _pOutputMethod;
901 //SCILAB_OUTPUT_METHOD ConfigVariable::getOutputMethod(void)
903 // return m_pOutputMethod;
915 types::Callable* ConfigVariable::m_schurFunction = NULL;
917 void ConfigVariable::setSchurFunction(types::Callable* _schurFunction)
919 m_schurFunction = _schurFunction;
922 types::Callable* ConfigVariable::getSchurFunction()
924 return m_schurFunction;
932 ** grand (module randlib)
936 int ConfigVariable::m_currentBaseGen = 0;
937 int ConfigVariable::m_currentClcg4 = 0;
939 void ConfigVariable::setCurrentBaseGen(int _gen)
941 m_currentBaseGen = _gen;
944 int ConfigVariable::getCurrentBaseGen()
946 return m_currentBaseGen;
949 void ConfigVariable::setCurrentClcg4(int _clcg4)
951 m_currentClcg4 = _clcg4;
954 int ConfigVariable::getCurrentClcg4()
956 return m_currentClcg4;
966 bool ConfigVariable::m_bStartProcessing = false;
967 bool ConfigVariable::m_bEndProcessing = false;
969 void ConfigVariable::setStartProcessing(bool _bStartProcessing)
971 m_bStartProcessing = _bStartProcessing;
974 bool ConfigVariable::getStartProcessing()
976 return m_bStartProcessing;
979 void ConfigVariable::setEndProcessing(bool _bEndProcessing)
981 m_bEndProcessing = _bEndProcessing;
984 bool ConfigVariable::getEndProcessing()
986 return m_bEndProcessing;
996 int ConfigVariable::m_iIeee = 0;
998 void ConfigVariable::setIeee(int _iIeee)
1003 int ConfigVariable::getIeee()
1015 int ConfigVariable::m_iSimpMode = 1;
1017 void ConfigVariable::setSimpMode(int _iSimpMode)
1019 m_iSimpMode = _iSimpMode;
1022 int ConfigVariable::getSimpMode()
1034 int ConfigVariable::m_iFuncprot = 1;
1036 void ConfigVariable::setFuncprot(int _iFuncprot)
1038 m_iFuncprot = _iFuncprot;
1041 int ConfigVariable::getFuncprot()
1054 std::list< std::pair<int, std::wstring> > ConfigVariable::m_Where;
1055 std::list<int> ConfigVariable::m_FirstMacroLine;
1056 void ConfigVariable::where_begin(int _iLineNum, std::wstring _wstName)
1058 m_Where.push_front(std::pair<int, std::wstring>(_iLineNum, _wstName));
1061 void ConfigVariable::where_end()
1063 if (m_Where.empty() == false)
1065 m_Where.pop_front();
1069 std::list< std::pair<int, std::wstring> >& ConfigVariable::getWhere()
1074 void ConfigVariable::macroFirstLine_begin(int _iLine)
1076 m_FirstMacroLine.push_back(_iLine);
1079 void ConfigVariable::macroFirstLine_end()
1081 m_FirstMacroLine.pop_back();
1084 int ConfigVariable::getMacroFirstLines()
1086 if (m_FirstMacroLine.empty())
1091 return m_FirstMacroLine.back();
1099 ** module called with variable by reference
1103 std::list<std::wstring> ConfigVariable::m_ReferenceModules;
1105 bool ConfigVariable::checkReferenceModule(std::wstring _module)
1107 std::list<std::wstring>::iterator it = m_ReferenceModules.begin();
1108 for ( ; it != m_ReferenceModules.end() ; ++it)
1119 void ConfigVariable::addReferenceModule(std::wstring _module)
1121 if (checkReferenceModule(_module) == false)
1123 m_ReferenceModules.push_back(_module);
1127 void ConfigVariable::removeReferenceModule(std::wstring _module)
1129 if (checkReferenceModule(_module))
1131 m_ReferenceModules.remove(_module);
1135 std::list<std::wstring> ConfigVariable::getReferenceModules()
1137 std::list<std::wstring> l(m_ReferenceModules);
1150 int ConfigVariable::m_analyzerOptions = 0;
1151 void ConfigVariable::setAnalyzerOptions(int _val)
1153 m_analyzerOptions = _val;
1156 int ConfigVariable::getAnalyzerOptions(void)
1158 return m_analyzerOptions;
1170 bool ConfigVariable::m_dividebyzero = false;
1171 void ConfigVariable::setDivideByZero(bool _dividebyzero)
1173 m_dividebyzero = _dividebyzero;
1176 bool ConfigVariable::isDivideByZero(void)
1178 return m_dividebyzero;