update mode management 70/17470/6
Antoine ELIAS [Wed, 18 Nov 2015 14:29:27 +0000 (15:29 +0100)]
Change-Id: Ice12edf6b2f4a7152d84ae017bd738fce1396f94

25 files changed:
scilab/modules/api_scilab/src/cpp/api_stack_error.cpp
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/console_Import.def
scilab/modules/ast/includes/ast/visitor_common.hxx
scilab/modules/ast/includes/exps/seqexp.hxx
scilab/modules/ast/includes/system_env/configvariable.hxx
scilab/modules/ast/includes/system_env/configvariable_interface.h
scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
scilab/modules/ast/src/cpp/ast/run_AssignExp.hpp
scilab/modules/ast/src/cpp/ast/run_SeqExp.hpp [new file with mode: 0644]
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/ast/visitor_common.cpp
scilab/modules/ast/src/cpp/system_env/configvariable.cpp
scilab/modules/ast/src/cpp/system_env/configvariable_interface.cpp
scilab/modules/ast/src/cpp/types/types_tools.cpp
scilab/modules/core/sci_gateway/cpp/sci_mode.cpp
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/tests/unit_tests/mode.dia.ref
scilab/modules/core/tests/unit_tests/mode.tst
scilab/modules/core/tests/unit_tests/script_exec.sce [new file with mode: 0644]
scilab/modules/core/tests/unit_tests/script_mode.sce [new file with mode: 0644]
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/output_stream/src/c/ast_Import.def
scilab/modules/output_stream/src/cpp/scilabWrite.cpp

index cf51172..c5b9220 100644 (file)
@@ -68,7 +68,7 @@ int printError(SciErr* _psciErr, int _iLastMsg)
 
     SciStoreError(_psciErr->iErr);
 
-    if (getPromptMode() != PROMPTMODE_SILENT && getSilentError() == VERBOSE_ERROR)
+    if (isPrintOutput() == 1 && isSilentError() == 0)
     {
         if (_iLastMsg)
         {
index 00792c2..9f93a38 100644 (file)
@@ -509,6 +509,7 @@ lib /DEF:"$(ProjectDir)coverage_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platfo
     <ClInclude Include="src\cpp\ast\run_CallExp.hpp" />
     <ClInclude Include="src\cpp\ast\run_MatrixExp.hpp" />
     <ClInclude Include="src\cpp\ast\run_OpExp.hpp" />
+    <ClInclude Include="src\cpp\ast\run_SeqExp.hpp" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\analysis\AnalysisVisitor.cpp" />
index 18c49b3..da50129 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Library Include="..\..\bin\blasplus.lib" />
     <ClInclude Include="includes\analysis\data\VarPromotion.hxx">
       <Filter>Header Files\analysis\data</Filter>
     </ClInclude>
+    <ClInclude Include="src\cpp\ast\run_SeqExp.hpp">
+      <Filter>Header Files\ast</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\ast\expHistory.cpp">
       <Filter>Source Files\analysis</Filter>
     </ClCompile>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index 10c5791..aa83075 100644 (file)
@@ -5,4 +5,5 @@ EXPORTS
 linesmore
 scilabRead
 SetTemporaryPrompt
-ClearTemporaryPrompt
\ No newline at end of file
+ClearTemporaryPrompt
+GetCurrentPrompt
index db7236d..6d6a085 100644 (file)
@@ -62,4 +62,8 @@ types::InternalType* insertionCall(const ast::Exp& e, types::typed_list* _pArgs,
 EXTERN_AST void callOnPrompt(void);
 EXTERN_AST ast::Exp* callTyper(ast::Exp* _tree, std::wstring _msg = std::wstring(L""));
 
+void printLine(const std::string& _stPrompt, const std::string& _stLine, bool _bLF);
+std::string printExp(std::ifstream& _File, ast::Exp* _pExp, const std::string& _stPrompt, int* _piLine /* in/out */, int* _piCol /* in/out */, std::string& _stPreviousBuffer);
+
+
 #endif //!AST_VISITOR_COMMON_HXX
index 441bc8e..3b74129 100644 (file)
@@ -28,16 +28,26 @@ namespace ast
 ** \b Example: (print_int(2097); print("WipeOut")) */
 class SeqExp : public Exp
 {
+public:
+
+    //enum on the orgin of execution
+    enum ExecFrom
+    {
+        SCRIPT,
+        EXEC,
+        EXECSTR
+    };
+
     /** \name Ctor & dtor.
     ** \{ */
-public:
+
     /** \brief Construct a Sequence Expression node.
     ** \param location scanner position informations
     ** \param body EXP LIST intruction
     */
     SeqExp (const Location& location,
-            exps_t& body)
-        : Exp (location)
+        exps_t& body)
+        : Exp(location), execfrom(SCRIPT)
     {
         for (auto it : body)
         {
@@ -130,6 +140,24 @@ public:
             exp->setBreakable();
         }
     }
+
+    void setExecFrom(ExecFrom from)
+    {
+        execfrom = from;
+    }
+
+    ExecFrom getExecFrom()
+    {
+        return execfrom;
+    }
+
+    ExecFrom getExecFrom() const
+    {
+        return execfrom;
+    }
+
+private :
+    ExecFrom execfrom;
 };
 
 } // namespace ast
index dcecc23..9392a36 100644 (file)
@@ -202,12 +202,28 @@ public :
     //Last Error Function
 private :
     static std::wstring m_wstErrorFunction;
-
-public :
+public:
     static void setLastErrorFunction(const std::wstring& _wstFunction);
     static std::wstring& getLastErrorFunction();
 
-    //Prompt Mode and Silent error
+    //verbose ";" after instruction
+    //set before function call to know status of e.isVerbose in functions
+private:
+    static bool m_bVerbose;
+
+public : 
+    static void setVerbose(bool _bVerbose);
+    static bool getVerbose(void);
+
+
+    //silent error ( try catch, errcatch, ... )
+private : 
+    static bool m_iSilentError;
+public:
+    static void setSilentError(bool _iSilentError);
+    static bool isSilentError(void);
+
+    //Prompt Mode
 public :
     /*
     Prompt mode
@@ -220,30 +236,35 @@ public :
     step7 = 7
     */
 
-    /*
-       show = 0
-       silent = 1
-    */
 private :
     static int m_iPromptMode;
-    static int m_iSilentError;
-
-    //set before function call to know status of e.isVerbose in functions
-    static bool m_bVerbose;
+    static bool m_printInput;
+    static bool m_printOutput;
+    static bool m_printCompact;
+    static bool m_printInteractive;
 
 public :
     static void setPromptMode(int _iPromptMode);
     static int getPromptMode(void);
-    static bool isPromptShow(void);
-    static bool isEmptyLineShow(void);
 
-    static void setSilentError(int _iSilentError);
-    static int getSilentError(void);
-    static void setVerbose(bool _bVerbose);
-    static bool getVerbose(void);
+    static void setPrintInput(bool val);
+    static bool isPrintInput(void);
+    static bool togglePrintInput(void);
 
-    //Thread List
+    static void setPrintOutput(bool val);
+    static bool isPrintOutput(void);
+    static bool togglePrintOutput(void);
+
+    static void setPrintInteractive(bool val);
+    static bool isPrintInteractive(void);
+    static bool togglePrintInteractive(void);
 
+    static void setPrintCompact(bool val);
+    static bool isPrintCompact(void);
+    static bool togglePrintCompact(void);
+
+
+    //Thread List
 private :
     static std::list<types::ThreadId*> m_threadList;
 public :
index 3bce55c..f44f6a0 100644 (file)
 #include <wchar.h>
 #include "dynlib_ast.h"
 
-#define PROMPTMODE_NORMAL   0   //show new values but not commands
-#define PROMPTMODE_SILENT   -1  //hide all
-#define PROMPTMODE_PROMPT   2   //show all
-#define PROMPTMODE_EXEC     1   //show all
-#define PROMPTMODE_EXEC3    3   //show all
-#define PROMPTMODE_STEP     4   //later ...
-#define PROMPTMODE_STEP7    7   //later ...
-
-#define SILENT_ERROR        1
 #define VERBOSE_ERROR       0
 
 typedef enum
@@ -52,9 +43,16 @@ EXTERN_AST int getConsoleLines(void);
 
 EXTERN_AST int getPromptMode(void);
 EXTERN_AST void setPromptMode(int _iMode);
-EXTERN_AST int isPromptShow(void);
-EXTERN_AST int getSilentError(void);
+EXTERN_AST int isSilentError(void);
 EXTERN_AST void setSilentError(int _iSilent);
+EXTERN_AST int isPrintInput();
+EXTERN_AST void setPrintInput(int);
+EXTERN_AST int isPrintOutput();
+EXTERN_AST void setPrintOutput(int);
+EXTERN_AST int isPrintCompact();
+EXTERN_AST void setPrintCompact(int);
+EXTERN_AST int isPrintInteractive();
+EXTERN_AST void setPrintInteractive(int);
 
 EXTERN_AST int getieee(void);
 EXTERN_AST void setieee(int);
index 538fced..b3b630d 100644 (file)
@@ -237,7 +237,7 @@ void DebuggerVisitor::visit(const SeqExp  &e)
                     //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
                     types::InternalType* pITAns = getResult();
                     symbol::Context::getInstance()->put(m_pAns, pITAns);
-                    if (exp->isVerbose() && ConfigVariable::isPromptShow())
+                    if (exp->isVerbose() && ConfigVariable::isPrintOutput())
                     {
                         //TODO manage multiple returns
                         scilabWriteW(L" ans  =\n\n");
index 58b5c41..7bace5f 100644 (file)
@@ -126,7 +126,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 }
             }
 
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
+            if (e.isVerbose() && ConfigVariable::isPrintOutput())
             {
                 std::wstring wstrName = pVar->getSymbol().getName();
                 std::wostringstream ostr;
@@ -208,7 +208,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
 
             if (pOut != NULL)
             {
-                if (e.isVerbose() && ConfigVariable::isPromptShow())
+                if (e.isVerbose() && ConfigVariable::isPrintOutput())
                 {
                     std::wostringstream ostr;
                     ostr << L" " << *getStructNameFromExp(pCell) << L"  = " << std::endl;
@@ -370,7 +370,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 }
             }
 
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
+            if (e.isVerbose() && ConfigVariable::isPrintOutput())
             {
                 std::wostringstream ostr;
                 ostr << L" " << *getStructNameFromExp(&pCall->getName()) << L"  = " << std::endl;
@@ -510,7 +510,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 delete i;
             }
 
-            if (e.isVerbose() && ConfigVariable::isPromptShow())
+            if (e.isVerbose() && ConfigVariable::isPrintOutput())
             {
                 const std::wstring *pstName = getStructNameFromExp(pField);
 
diff --git a/scilab/modules/ast/src/cpp/ast/run_SeqExp.hpp b/scilab/modules/ast/src/cpp/ast/run_SeqExp.hpp
new file mode 100644 (file)
index 0000000..0b73354
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#include <fstream>
+//file included in runvisitor.cpp
+namespace ast {
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const SeqExp  &e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    int lastLine = 0;
+    ast::exps_t exps = e.getExps();
+    ast::exps_t::const_iterator it = exps.begin();
+    ast::exps_t::const_iterator itEnd = exps.end();
+
+
+    /*stuff of printf input during execution*/
+    std::string str;
+    int iCurrentLine = -1; //no data in str
+
+    std::ifstream* file = nullptr;
+    if (e.getExecFrom() == SeqExp::EXEC)
+    {
+        //open input file to print exp from it
+        int iFileID = ConfigVariable::getExecutedFileID();
+        if (iFileID)
+        {
+            const wchar_t* filename = getfile_filename(iFileID);
+            if (filename)
+            {
+                char* cfilename = wide_string_to_UTF8(filename);
+                file = new std::ifstream(cfilename);
+                FREE(cfilename);
+            }
+        }
+    }
+
+    for (; it != itEnd; ++it)
+    {
+        if (ConfigVariable::isExecutionBreak())
+        {
+            ConfigVariable::resetExecutionBreak();
+            if (ConfigVariable::isPrintInteractive())
+            {
+                ClearTemporaryPrompt();
+            }
+
+            StorePrioritaryCommand("pause");
+            ThreadManagement::WaitForRunMeSignal();
+        }
+
+        // interrupt me to execute a prioritary command
+        while (StaticRunner_isInterruptibleCommand() == 1 && StaticRunner_isRunnerAvailable() == 1)
+        {
+            StaticRunner_launch();
+            StaticRunner_setInterruptibleCommand(1);
+        }
+
+        //printf input expression line following mode configuration
+        if (file && ConfigVariable::isPrintInput())
+        {
+            Location loc = (*it)->getLocation();
+            if (iCurrentLine + 1 < loc.first_line)
+            {
+                char pstPrompt[64];
+                //get prompt
+                GetCurrentPrompt(pstPrompt);
+                std::string stPrompt(pstPrompt);
+
+                if (ConfigVariable::isPrintInteractive())
+                {
+                    stPrompt = SCIPROMPT_PAUSE;
+                }
+
+                ast::exps_t::const_iterator k = it;
+                int iLastLine = loc.last_line;
+                int iCurrentCol = 0; //no data in str
+                do
+                {
+                    str = printExp(*file, *k, stPrompt, &iCurrentLine, &iCurrentCol, str);
+                    iLastLine = (*k)->getLocation().last_line;
+                    k++;
+                } while (k != exps.end() && (*k)->getLocation().first_line == iLastLine);
+            }
+        }
+
+        if ((*it)->isCommentExp())
+        {
+            continue;
+        }
+
+        try
+        {
+            //reset default values
+            setResult(NULL);
+            int iExpectedSize = getExpectedSize();
+            setExpectedSize(-1);
+            (*it)->accept(*this);
+            setExpectedSize(iExpectedSize);
+            types::InternalType * pIT = getResult();
+
+            // In case of exec file, set the file name in the Macro to store where it is defined.
+            int iFileID = ConfigVariable::getExecutedFileID();
+            if (iFileID && (*it)->isFunctionDec())
+            {
+                types::InternalType* pITMacro = symbol::Context::getInstance()->get((*it)->getAs<FunctionDec>()->getSymbol());
+                if (pITMacro)
+                {
+                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
+                    const wchar_t* filename = getfile_filename(iFileID);
+                    // scilab.quit is not open with mopen
+                    // in this case filename is NULL because FileManager have not been filled.
+                    if (filename)
+                    {
+                        pMacro->setFileName(filename);
+                    }
+                }
+            }
+
+            if (pIT != NULL)
+            {
+                bool bImplicitCall = false;
+                if (pIT->isCallable()) //to manage call without ()
+                {
+                    types::Callable *pCall = pIT->getAs<types::Callable>();
+                    types::typed_list out;
+                    types::typed_list in;
+                    types::optional_list opt;
+
+                    try
+                    {
+                        //in this case of calling, we can return only one values
+                        int iSaveExpectedSize = getExpectedSize();
+                        setExpectedSize(1);
+
+                        pCall->invoke(in, opt, getExpectedSize(), out, e);
+                        setExpectedSize(iSaveExpectedSize);
+
+                        if (out.size() == 0)
+                        {
+                            setResult(NULL);
+                        }
+                        else
+                        {
+                            setResult(out[0]);
+                        }
+
+                        bImplicitCall = true;
+                    }
+                    catch (const InternalError& ie)
+                    {
+                        if (ConfigVariable::getLastErrorFunction() == L"")
+                        {
+                            ConfigVariable::setLastErrorFunction(pCall->getName());
+                            ConfigVariable::setLastErrorLine(e.getLocation().first_line);
+                        }
+                        CoverageInstance::stopChrono((void*)&e);
+                        throw ie;
+                    }
+                }
+                else if (pIT->isImplicitList())
+                {
+                    //expand implicit when possible
+                    types::ImplicitList* pIL = pIT->getAs<types::ImplicitList>();
+                    if (pIL->isComputable())
+                    {
+                        types::InternalType* p = pIL->extractFullMatrix();
+                        if (p)
+                        {
+                            setResult(p);
+                        }
+                    }
+                }
+
+                //don't output Simplevar and empty result
+                if (getResult() != NULL && (!(*it)->isSimpleVar() || bImplicitCall))
+                {
+                    //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
+                    types::InternalType* pITAns = getResult();
+                    symbol::Context::getInstance()->put(m_pAns, pITAns);
+                    if ((*it)->isVerbose() && ConfigVariable::isPrintOutput())
+                    {
+                        //TODO manage multiple returns
+                        scilabWriteW(L" ans  =\n\n");
+                        std::wostringstream ostrName;
+                        ostrName << L"ans";
+                        VariableToString(pITAns, ostrName.str().c_str());
+                    }
+                }
+
+                pIT->killMe();
+            }
+
+            if (ConfigVariable::isPrintInteractive())
+            {
+                Location loc = (*it)->getLocation();
+                if (lastLine < loc.first_line)
+                {
+                    //break execution
+                    SetTemporaryPrompt(SCIPROMPT_PAUSE);
+                    ConfigVariable::setScilabCommand(0);
+                    char* pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
+                    if (pcConsoleReadStr) // exec is called from a callback
+                    {
+                        ThreadManagement::SendConsoleExecDoneSignal();
+                    }
+                    else // exec is called from the console
+                    {
+                        scilabRead();
+                        pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
+                    }
+
+                    if (pcConsoleReadStr && pcConsoleReadStr[0] == 'p' && pcConsoleReadStr[1] == '\0')
+                    {
+                        //mode pause
+                        ConfigVariable::setExecutionBreak();
+                    }
+                }
+
+                lastLine = loc.last_line;
+            }
+
+            if ((&e)->isBreakable() && (*it)->isBreak())
+            {
+                const_cast<SeqExp *>(&e)->setBreak();
+                (*it)->resetBreak();
+                break;
+            }
+
+            if ((&e)->isContinuable() && (*it)->isContinue())
+            {
+                const_cast<SeqExp *>(&e)->setContinue();
+                (*it)->resetContinue();
+                break;
+            }
+
+            if ((&e)->isReturnable() && (*it)->isReturn())
+            {
+                const_cast<SeqExp *>(&e)->setReturn();
+                (*it)->resetReturn();
+                break;
+            }
+        }
+        catch (const InternalError& ie)
+        {
+            ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
+            CoverageInstance::stopChrono((void*)&e);
+            throw ie;
+        }
+
+        // If something other than NULL is given to setResult, then that would imply
+        // to make a cleanup in visit(ForExp) for example (e.getBody().accept(*this);)
+        setResult(NULL);
+    }
+
+    if (file)
+    {
+        file->close();
+        delete file;
+    }
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+
+} /* namespace ast */
index 2ae8441..0dbbf78 100644 (file)
@@ -114,10 +114,10 @@ void RunVisitorT<T>::visitprivate(const SimpleVar & e)
     setResult(pI);
     if (pI != nullptr)
     {
-        if (e.isVerbose() && pI->isCallable() == false && ConfigVariable::isPromptShow())
+        if (e.isVerbose() && pI->isCallable() == false && ConfigVariable::isPrintOutput())
         {
             std::wostringstream ostr;
-            ostr << e.getSymbol().getName() << L"  = ";
+            ostr << L" " << e.getSymbol().getName() << L"  = ";
 #ifndef NDEBUG
             ostr << L"(" << pI->getRef() << L")";
 #endif
@@ -1264,204 +1264,6 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
 }
 
 template <class T>
-void RunVisitorT<T>::visitprivate(const SeqExp  &e)
-{
-    CoverageInstance::invokeAndStartChrono((void*)&e);
-    int lastLine = 0;
-    for (auto exp : e.getExps())
-    {
-        if (exp->isCommentExp())
-        {
-            continue;
-        }
-
-        if (ConfigVariable::isExecutionBreak())
-        {
-            ConfigVariable::resetExecutionBreak();
-            if (ConfigVariable::getPromptMode() == 7)
-            {
-                ClearTemporaryPrompt();
-            }
-
-            StorePrioritaryCommand("pause");
-            ThreadManagement::WaitForRunMeSignal();
-        }
-
-        // interrupt me to execute a prioritary command
-        while (StaticRunner_isInterruptibleCommand() == 1 && StaticRunner_isRunnerAvailable() == 1)
-        {
-            StaticRunner_launch();
-            StaticRunner_setInterruptibleCommand(1);
-        }
-
-        try
-        {
-            //reset default values
-            setResult(NULL);
-            int iExpectedSize = getExpectedSize();
-            setExpectedSize(-1);
-            exp->accept(*this);
-            setExpectedSize(iExpectedSize);
-            types::InternalType * pIT = getResult();
-
-            // In case of exec file, set the file name in the Macro to store where it is defined.
-            int iFileID = ConfigVariable::getExecutedFileID();
-            if (iFileID && exp->isFunctionDec())
-            {
-                types::InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<FunctionDec>()->getSymbol());
-                if (pITMacro)
-                {
-                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
-                    const wchar_t* filename = getfile_filename(iFileID);
-                    // scilab.quit is not open with mopen
-                    // in this case filename is NULL because FileManager have not been filled.
-                    if (filename)
-                    {
-                        pMacro->setFileName(filename);
-                    }
-                }
-            }
-
-            if (pIT != NULL)
-            {
-                bool bImplicitCall = false;
-                if (pIT->isCallable()) //to manage call without ()
-                {
-                    types::Callable *pCall = pIT->getAs<types::Callable>();
-                    types::typed_list out;
-                    types::typed_list in;
-                    types::optional_list opt;
-
-                    try
-                    {
-                        //in this case of calling, we can return only one values
-                        int iSaveExpectedSize = getExpectedSize();
-                        setExpectedSize(1);
-
-                        pCall->invoke(in, opt, getExpectedSize(), out, e);
-                        setExpectedSize(iSaveExpectedSize);
-
-                        if (out.size() == 0)
-                        {
-                            setResult(NULL);
-                        }
-                        else
-                        {
-                            setResult(out[0]);
-                        }
-
-                        bImplicitCall = true;
-                    }
-                    catch (const InternalError& ie)
-                    {
-                        if (ConfigVariable::getLastErrorFunction() == L"")
-                        {
-                            ConfigVariable::setLastErrorFunction(pCall->getName());
-                            ConfigVariable::setLastErrorLine(e.getLocation().first_line);
-                        }
-                        CoverageInstance::stopChrono((void*)&e);
-                        throw ie;
-                    }
-                }
-                else if (pIT->isImplicitList())
-                {
-                    //expand implicit when possible
-                    types::ImplicitList* pIL = pIT->getAs<types::ImplicitList>();
-                    if (pIL->isComputable())
-                    {
-                        types::InternalType* p = pIL->extractFullMatrix();
-                        if (p)
-                        {
-                            setResult(p);
-                        }
-                    }
-                }
-
-                //don't output Simplevar and empty result
-                if (getResult() != NULL && (!exp->isSimpleVar() || bImplicitCall))
-                {
-                    //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
-                    types::InternalType* pITAns = getResult();
-                    symbol::Context::getInstance()->put(m_pAns, pITAns);
-                    if (exp->isVerbose() && ConfigVariable::isPromptShow())
-                    {
-                        //TODO manage multiple returns
-                        scilabWriteW(L" ans  =\n\n");
-                        std::wostringstream ostrName;
-                        ostrName << L"ans";
-                        VariableToString(pITAns, ostrName.str().c_str());
-                    }
-                }
-
-                pIT->killMe();
-            }
-
-            if (ConfigVariable::getPromptMode() == 7)
-            {
-                Location loc = exp->getLocation();
-                if (lastLine < loc.first_line)
-                {
-                    //break execution
-                    SetTemporaryPrompt(SCIPROMPT_PAUSE);
-                    ConfigVariable::setScilabCommand(0);
-                    char* pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
-                    if (pcConsoleReadStr) // exec is called from a callback
-                    {
-                        ThreadManagement::SendConsoleExecDoneSignal();
-                    }
-                    else // exec is called from the console
-                    {
-                        scilabRead();
-                        pcConsoleReadStr = ConfigVariable::getConsoleReadStr();
-                    }
-
-                    if (pcConsoleReadStr && pcConsoleReadStr[0] == 'p' && pcConsoleReadStr[1] == '\0')
-                    {
-                        //mode pause
-                        ConfigVariable::setExecutionBreak();
-                    }
-                }
-
-                lastLine = loc.last_line;
-            }
-
-            if ((&e)->isBreakable() && exp->isBreak())
-            {
-                const_cast<SeqExp *>(&e)->setBreak();
-                exp->resetBreak();
-                break;
-            }
-
-            if ((&e)->isContinuable() && exp->isContinue())
-            {
-                const_cast<SeqExp *>(&e)->setContinue();
-                exp->resetContinue();
-                break;
-            }
-
-            if ((&e)->isReturnable() && exp->isReturn())
-            {
-                const_cast<SeqExp *>(&e)->setReturn();
-                exp->resetReturn();
-                break;
-            }
-        }
-        catch (const InternalError& ie)
-        {
-            ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
-            CoverageInstance::stopChrono((void*)&e);
-            throw ie;
-        }
-
-        // If something other than NULL is given to setResult, then that would imply
-        // to make a cleanup in visit(ForExp) for example (e.getBody().accept(*this);)
-        setResult(NULL);
-    }
-
-    CoverageInstance::stopChrono((void*)&e);
-}
-
-template <class T>
 void RunVisitorT<T>::visitprivate(const NotExp &e)
 {
     CoverageInstance::invokeAndStartChrono((void*)&e);
@@ -2120,10 +1922,10 @@ void RunVisitorT<T>::visitprivate(const TryCatchExp  &e)
 {
     CoverageInstance::invokeAndStartChrono((void*)&e);
     //save current prompt mode
-    int oldVal = ConfigVariable::getSilentError();
+    bool oldVal = ConfigVariable::isSilentError();
     int oldMode = ConfigVariable::getPromptMode();
     //set mode silent for errors
-    ConfigVariable::setSilentError(1);
+    ConfigVariable::setSilentError(true);
 
     symbol::Context* pCtx = symbol::Context::getInstance();
     try
@@ -2185,6 +1987,7 @@ void RunVisitorT<T>::visitprivate(const TryCatchExp  &e)
 
 } /* namespace ast */
 
+#include "run_SeqExp.hpp"
 #include "run_CallExp.hpp"
 #include "run_MatrixExp.hpp"
 #include "run_OpExp.hpp"
index 67886ce..07647e5 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <string>
 #include <numeric>
+#include <iostream>
+#include <fstream>
 #include "visitor_common.hxx"
 #include "exp.hxx"
 #include "fieldexp.hxx"
@@ -2331,3 +2333,147 @@ ast::Exp* callTyper(ast::Exp* _tree, std::wstring _msg)
     delete d;
     return newTree;
 }
+
+std::string printExp(std::ifstream& _File, ast::Exp* _pExp, const std::string& _stPrompt, int* _piLine /* in/out */, int* _piCol /* in/out */, std::string& _stPreviousBuffer)
+{
+    Location loc = _pExp->getLocation();
+
+    //get current line
+    //for multiple expression on same line
+    //_stPreviousBuffer will not be updated
+
+    //bypass previous lines
+    for (int i = *_piLine; i < loc.first_line - 1; i++)
+    {
+
+        (*_piLine)++;
+        if ((*_piLine) != (loc.first_line - 1))
+        {
+            //empty line
+            if (ConfigVariable::isPrintCompact() == false)
+            {
+                printLine("", "", true);
+            }
+        }
+        std::getline(_File, _stPreviousBuffer);
+    }
+
+    if (loc.first_line == loc.last_line)
+    {
+        //expression on 1-line
+        int iStart = loc.first_column - 1;
+        int iEnd = loc.last_column - 1;
+        int iLen = iEnd - iStart;
+
+        int iCopyLen = iEnd - *_piCol;
+        std::string strLastLine(_stPreviousBuffer.c_str() + *_piCol, iCopyLen);
+        int iExpLen = iLen;
+        int iLineLen = (int)_stPreviousBuffer.size();
+        bool bStart = iStart == 0 || *_piCol == 0;
+        bool bEnd = iStart + iExpLen == iLineLen;
+
+        //begin of line
+        if (bStart)
+        {
+            if (bEnd)
+            {
+                printLine(_stPrompt, strLastLine, true);
+                *_piCol = 0;
+            }
+            else
+            {
+                printLine(_stPrompt, strLastLine, false);
+                *_piCol = loc.last_column - 1;
+            }
+        }
+        else //middle of line
+        {
+            if (bEnd)
+            {
+                printLine("", strLastLine, true);
+                *_piCol = 0;
+            }
+            else
+            {
+                printLine("", strLastLine, false);
+                *_piCol = loc.last_column - 1;
+            }
+        }
+    }
+    else
+    {
+        //multiline
+        int iStart = loc.first_column - 1;
+        bool bStart = iStart == 0 || *_piCol == 0;
+
+        std::string strLastLine(_stPreviousBuffer.c_str() + *_piCol);
+
+        //begin of line
+        if (bStart)
+        {
+            printLine(_stPrompt, strLastLine, true);
+        }
+        else
+        {
+            printLine("", strLastLine, true);
+        }
+
+        bool isCompact = ConfigVariable::isPrintCompact();
+        ConfigVariable::setPrintCompact(true);
+
+        //full lines
+        for (int i = loc.first_line; i < (loc.last_line - 1); i++)
+        {
+            (*_piLine)++;
+            std::getline(_File, _stPreviousBuffer);
+            // dont print empty line of function body
+            if (_stPreviousBuffer.size() != 0)
+            {
+                printLine(_stPrompt, _stPreviousBuffer.c_str(), true);
+            }
+        }
+
+        //last line
+        std::getline(_File, _stPreviousBuffer);
+        (*_piLine)++;
+
+        int iSize = loc.last_column - 1;
+        std::string stLastLine(_stPreviousBuffer.c_str(), iSize);
+        int iLineLen = (int)_stPreviousBuffer.size();
+        if (iLineLen == iSize)
+        {
+            printLine(_stPrompt, stLastLine, true);
+            *_piCol = 0;
+        }
+        else
+        {
+            printLine(_stPrompt, stLastLine, false);
+            *_piCol = loc.last_column - 1;
+        }
+
+        ConfigVariable::setPrintCompact(isCompact);
+    }
+
+    return _stPreviousBuffer;
+}
+
+void printLine(const std::string& _stPrompt, const std::string& _stLine, bool _bLF)
+{
+    std::string st;
+    int size = _stPrompt.size();
+    if (size && ConfigVariable::isPrintCompact() == false)
+    {
+        st = "\n";
+    }
+
+    st += _stPrompt;
+
+    st += _stLine;
+    if (_bLF)
+    {
+        st += "\n";
+    }
+
+    scilabWrite(st.c_str());
+}
+/*--------------------------------------------------------------------------*/
index db52213..7b1e341 100644 (file)
@@ -424,85 +424,194 @@ std::wstring& ConfigVariable::getLastErrorFunction()
 ** \}
 */
 
-/*
-** Prompt Mode
-** \{
-*/
+/* verbose */
+bool ConfigVariable::m_bVerbose = true;
+
+void ConfigVariable::setVerbose(bool _bVerbose)
+{
+    m_bVerbose = _bVerbose;
+}
+
+bool ConfigVariable::getVerbose(void)
+{
+    return m_bVerbose;
+}
+
+/* silent error */
+
+bool ConfigVariable::m_iSilentError = false;
+
+void ConfigVariable::setSilentError(bool _iSilentError)
+{
+    m_iSilentError = _iSilentError;
+}
+
+bool ConfigVariable::isSilentError(void)
+{
+    return m_iSilentError;
+}
+
+
+/* Prompt Mode */
 
 int ConfigVariable::m_iPromptMode = 0;
-int ConfigVariable::m_iSilentError = 0;
-bool ConfigVariable::m_bVerbose = true;
+bool ConfigVariable::m_printInput = true;
+bool ConfigVariable::m_printOutput = true;
+bool ConfigVariable::m_printInteractive = false;
+bool ConfigVariable::m_printCompact = false;
+
+/*
+mode        input   output      compact     interactive
+-----------------------------------------------
+-1              0       0           0           0
+0               0       1           1           0
+1               1       1           1           0
+2               0       1           0           0
+3               1       1           0           0
+4               1       1           1           1
+7               1       1           0           1
+*/
 
 void ConfigVariable::setPromptMode(int _iPromptMode)
 {
     m_iPromptMode = _iPromptMode;
-    if (m_iPromptMode == 5)
+    switch (_iPromptMode)
     {
-        m_iPromptMode = 1;
-    }
-
-    if (m_iPromptMode == 6)
-    {
-        m_iPromptMode = 7;
+        default:
+        case -1:
+            ConfigVariable::setPrintInput(false);
+            ConfigVariable::setPrintOutput(false);
+            ConfigVariable::setPrintCompact(true);
+            ConfigVariable::setPrintInteractive(false);
+            break;
+        case 0:
+            ConfigVariable::setPrintInput(false);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(true);
+            ConfigVariable::setPrintInteractive(false);
+            break;
+        case 5:
+        case 1:
+            ConfigVariable::setPrintInput(true);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(true);
+            ConfigVariable::setPrintInteractive(false);
+            break;
+        case 2:
+            ConfigVariable::setPrintInput(false);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(false);
+            ConfigVariable::setPrintInteractive(false);
+            break;
+        case 3:
+            ConfigVariable::setPrintInput(true);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(false);
+            ConfigVariable::setPrintInteractive(false);
+            break;
+        case 4:
+            ConfigVariable::setPrintInput(true);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(true);
+            ConfigVariable::setPrintInteractive(true);
+            break;
+        case 6:
+        case 7:
+            ConfigVariable::setPrintInput(true);
+            ConfigVariable::setPrintOutput(true);
+            ConfigVariable::setPrintCompact(false);
+            ConfigVariable::setPrintInteractive(true);
+            break;
     }
 }
 
 int ConfigVariable::getPromptMode(void)
 {
+    //bool input = isPrintInput();
+    //bool output = isPrintOutput();
+    //bool compact = isPrintCompact();
+    //bool interactive = isPrintInteractive();
+
+    //return !interactive ?
+    //    (/*-1*/ !input && !output ? -1 :
+    //    /* 0*/ !input &&  output &&  compact ? 0 :
+    //    /* 1*/  input &&  output &&  compact ? 1 :
+    //    /* 2*/ !input &&  output && !compact ? 2 :
+    //    /* 3*/  input &&  output && !compact ? 3 : 2 /*default*/) :
+    //    (/* 4*/  compact ? 4 :
+    //    /* 7*/ 7);
+
     return m_iPromptMode;
 }
 
-bool ConfigVariable::isEmptyLineShow(void)
+void ConfigVariable::setPrintInput(bool val)
 {
-    if ( m_iPromptMode == 0    ||
-            m_iPromptMode == 2 ||
-            m_iPromptMode == 3 ||
-            m_iPromptMode == 7)
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
+    m_printInput = val;
 }
 
-bool ConfigVariable::isPromptShow(void)
+bool ConfigVariable::isPrintInput(void)
 {
-    if ( m_iPromptMode == 0    ||
-            m_iPromptMode == 1 ||
-            m_iPromptMode == 2 ||
-            m_iPromptMode == 3 ||
-            m_iPromptMode == 7)
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
+    return m_printInput;
 }
 
-void ConfigVariable::setSilentError(int _iSilentError)
+bool ConfigVariable::togglePrintInput(void)
 {
-    m_iSilentError = _iSilentError;
+    m_printInput = !m_printInput;
+    return m_printInput;
 }
 
-int ConfigVariable::getSilentError(void)
+
+void ConfigVariable::setPrintOutput(bool val)
 {
-    return m_iSilentError;
+    m_printOutput = val;
 }
 
-void ConfigVariable::setVerbose(bool _bVerbose)
+bool ConfigVariable::isPrintOutput(void)
 {
-    m_bVerbose = _bVerbose;
+    return m_printOutput;
 }
 
-bool ConfigVariable::getVerbose(void)
+bool ConfigVariable::togglePrintOutput(void)
 {
-    return m_bVerbose;
+    m_printOutput = !m_printOutput;
+    return m_printOutput;
 }
 
+
+void ConfigVariable::setPrintInteractive(bool val)
+{
+    m_printInteractive = val;
+}
+
+bool ConfigVariable::isPrintInteractive(void)
+{
+    return m_printInteractive;
+}
+
+bool ConfigVariable::togglePrintInteractive(void)
+{
+    m_printInteractive = !m_printInteractive;
+    return m_printInteractive;
+}
+
+
+void ConfigVariable::setPrintCompact(bool val)
+{
+    m_printCompact = val;
+}
+
+bool ConfigVariable::isPrintCompact(void)
+{
+    return m_printCompact;
+}
+
+bool ConfigVariable::togglePrintCompact(void)
+{
+    m_printCompact = !m_printCompact;
+    return m_printCompact;
+}
+
+
 /*
 ** ThreadList
 ** \{
index be4e7be..e8c0c91 100644 (file)
@@ -89,19 +89,54 @@ void setPromptMode(int _iMode)
     ConfigVariable::setPromptMode(_iMode);
 }
 
-int isPromptShow(void)
+int isPrintInput()
 {
-    return static_cast<int>(ConfigVariable::isPromptShow());
+    return ConfigVariable::isPrintInput() ? 1 : 0;
 }
 
-int getSilentError(void)
+void setPrintInput(int val)
 {
-    return static_cast<int>(ConfigVariable::getSilentError());
+    ConfigVariable::setPrintInput(val ? true : false);
+}
+
+int isPrintOutput()
+{
+    return ConfigVariable::isPrintOutput() ? 1 : 0;
+}
+
+void setPrintOutput(int val)
+{
+    ConfigVariable::setPrintOutput(val ? true : false);
+}
+
+int isPrintCompact()
+{
+    return ConfigVariable::isPrintCompact() ? 1 : 0;
+}
+
+void setPrintCompact(int val)
+{
+    ConfigVariable::setPrintCompact(val ? true : false);
+}
+
+int isPrintInteractive()
+{
+    return ConfigVariable::isPrintInteractive() ? 1 : 0;
+}
+
+void setPrintInteractive(int val)
+{
+    ConfigVariable::setPrintInteractive(val ? true : false);
+}
+
+int isSilentError(void)
+{
+    return ConfigVariable::isSilentError() ? 1 : 0;
 }
 
 void setSilentError(int _iSilent)
 {
-    ConfigVariable::setSilentError(_iSilent);
+    ConfigVariable::setSilentError(_iSilent ? true : false);
 }
 
 int getieee()
index ba1a516..296d195 100644 (file)
@@ -842,6 +842,11 @@ types::Function::ReturnValue VariableToString(types::InternalType* pIT, const wc
                 bFinish = linesmore() == 1;
             }
 
+            if (ConfigVariable::isPrintCompact() == false && ConfigVariable::isPrintInput() == false)
+            {
+                ostr << std::endl;
+            }
+
             scilabForcedWriteW(ostr.str().c_str());
             ostr.str(L"");
         }
index 74c8275..09614d9 100644 (file)
@@ -71,7 +71,7 @@ types::Function::ReturnValue sci_mode(types::typed_list &in, int _iRetCount, typ
 
         ConfigVariable::setPromptMode(iScilabMode);
 
-        if (iScilabMode == 4 || iScilabMode == 7)
+        if (ConfigVariable::isPrintInteractive())
         {
             sciprint(_("Pause mode: enter empty lines to continue.\n"));
         }
@@ -79,4 +79,3 @@ types::Function::ReturnValue sci_mode(types::typed_list &in, int _iRetCount, typ
 
     return types::Function::OK;
 }
-/*--------------------------------------------------------------------------*/
index f11a0d2..a085999 100644 (file)
@@ -618,7 +618,7 @@ void* scilabReadAndStore(void* param)
 
         Parser::ParserStatus exitStatus = Parser::Failed;
 
-        if (ConfigVariable::isEmptyLineShow())
+        if (ConfigVariable::isPrintCompact() == false)
         {
             scilabWriteW(L"\n");
         }
index 5f6e8d0..090808f 100644 (file)
@@ -4,6 +4,7 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
+// <-- CLI SHELL MODE -->
 function a = test_mode_foo(level_mode)
   mode(level_mode);
   a = mode();
@@ -27,4 +28,217 @@ r = test_mode_foo(ref);
 if r <> ref then bugmes();quit;end
 ref = 2;
 mode(ref);
+exec mode : -1
+exec mode : 0
+ a  = 
+    1.
+ b  = 
+    2.
+ c  = 
+    3.
+ d  = 
+    4.
+ e  = 
+    5.
+ f  = 
+    6.
+ g  = 
+    7.
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+printf("exec mode : %d\n", mode());
+exec mode : 1
+a = 1
+ a  = 
+    1.
+b = 2,c=3
+ b  = 
+    2.
+ c  = 
+    3.
+d = 4,if(1) e = 5
+end;
+ d  = 
+    4.
+ e  = 
+    5.
+f = 6,if(1)
+    g = 7
+end;
+ f  = 
+    6.
+ g  = 
+    7.
+h = 8,if(1)
+    i = 9
+end;j=10
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+exec mode : 2
+ a  = 
+    1.
+ b  = 
+    2.
+ c  = 
+    3.
+ d  = 
+    4.
+ e  = 
+    5.
+ f  = 
+    6.
+ g  = 
+    7.
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+printf("exec mode : %d\n", mode());
+exec mode : 3
+a = 1
+ a  = 
+    1.
+b = 2,c=3
+ b  = 
+    2.
+ c  = 
+    3.
+d = 4,if(1) e = 5
+end;
+ d  = 
+    4.
+ e  = 
+    5.
+f = 6,if(1)
+    g = 7
+end;
+ f  = 
+    6.
+ g  = 
+    7.
+h = 8,if(1)
+    i = 9
+end;j=10
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+script mode : -1
+script mode : 0
+ a  = 
+    1.
+ b  = 
+    2.
+ c  = 
+    3.
+ d  = 
+    4.
+ e  = 
+    5.
+ f  = 
+    6.
+ g  = 
+    7.
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+printf("script mode : %d\n", mode());
+script mode : 1
+a = 1
+ a  = 
+    1.
+b = 2,c=3
+ b  = 
+    2.
+ c  = 
+    3.
+d = 4,if(1) e = 5
+end;
+ d  = 
+    4.
+ e  = 
+    5.
+f = 6,if(1)
+    g = 7
+end;
+ f  = 
+    6.
+ g  = 
+    7.
+h = 8,if(1)
+    i = 9
+end;j=10
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+script mode : 2
+ a  = 
+    1.
+ b  = 
+    2.
+ c  = 
+    3.
+ d  = 
+    4.
+ e  = 
+    5.
+ f  = 
+    6.
+ g  = 
+    7.
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
+printf("script mode : %d\n", mode());
+script mode : 3
+a = 1
+ a  = 
+    1.
+b = 2,c=3
+ b  = 
+    2.
+ c  = 
+    3.
+d = 4,if(1) e = 5
+end;
+ d  = 
+    4.
+ e  = 
+    5.
+f = 6,if(1)
+    g = 7
+end;
+ f  = 
+    6.
+ g  = 
+    7.
+h = 8,if(1)
+    i = 9
+end;j=10
+ h  = 
+    8.
+ i  = 
+    9.
+ j  = 
+    10.
index ce6455e..0de6da7 100644 (file)
@@ -4,6 +4,8 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
+// <-- CLI SHELL MODE -->
+
 function a = test_mode_foo(level_mode)
   mode(level_mode);
   a = mode();
@@ -38,3 +40,14 @@ mode(ref);
 if ref <> mode() then pause,end
 
 
+exec("SCI/modules/core/tests/unit_tests/script_exec.sce", -1);
+exec("SCI/modules/core/tests/unit_tests/script_exec.sce", 0);
+exec("SCI/modules/core/tests/unit_tests/script_exec.sce", 1);
+exec("SCI/modules/core/tests/unit_tests/script_exec.sce", 2);
+exec("SCI/modules/core/tests/unit_tests/script_exec.sce", 3);
+
+m=-1;mode(2);exec("SCI/modules/core/tests/unit_tests/script_mode.sce");
+m=0;mode(2);exec("SCI/modules/core/tests/unit_tests/script_mode.sce");
+m=1;mode(2);exec("SCI/modules/core/tests/unit_tests/script_mode.sce");
+m=2;mode(2);exec("SCI/modules/core/tests/unit_tests/script_mode.sce");
+m=3;mode(2);exec("SCI/modules/core/tests/unit_tests/script_mode.sce");
diff --git a/scilab/modules/core/tests/unit_tests/script_exec.sce b/scilab/modules/core/tests/unit_tests/script_exec.sce
new file mode 100644 (file)
index 0000000..6a6df3c
--- /dev/null
@@ -0,0 +1,11 @@
+printf("exec mode : %d\n", mode());
+a = 1
+b = 2,c=3
+d = 4,if(1) e = 5
+end;
+f = 6,if(1)
+    g = 7
+end;
+h = 8,if(1)
+    i = 9
+end;j=10
diff --git a/scilab/modules/core/tests/unit_tests/script_mode.sce b/scilab/modules/core/tests/unit_tests/script_mode.sce
new file mode 100644 (file)
index 0000000..89e490a
--- /dev/null
@@ -0,0 +1,12 @@
+mode(m);
+printf("script mode : %d\n", mode());
+a = 1
+b = 2,c=3
+d = 4,if(1) e = 5
+end;
+f = 6,if(1)
+    g = 7
+end;
+h = 8,if(1)
+    i = 9
+end;j=10
index ab1a439..6be2a28 100644 (file)
@@ -45,10 +45,6 @@ extern "C"
 #include "PATH_MAX.h"
 }
 
-void printLine(const std::string& _stPrompt, const std::string& _stLine, bool _bLF);
-std::string printExp(std::ifstream& _File, ast::Exp* _pExp, const std::string& _stPrompt, int* _piLine /* in/out */, int* _piCol /* in/out */, std::string& _stPreviousBuffer);
-std::string getExpression(const std::string& _stFile, ast::Exp* _pExp);
-
 void closeFile(std::ifstream* file, int fileId, const std::wstring& wstFile, ast::Exp* pExp)
 {
     if (file)
@@ -290,208 +286,57 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
     int oldVal = ConfigVariable::getPromptMode();
     ConfigVariable::setPromptMode(promptMode);
 
-    // if not exp displaying, just execute the seqexp
-    if (file == NULL || promptMode == 0 || promptMode == 2)
-    {
-        ast::SeqExp* pSeqExp = pExp->getAs<ast::SeqExp>();
-        std::unique_ptr<ast::ConstVisitor> exec(ConfigVariable::getDefaultVisitor());
+    ast::SeqExp* pSeqExp = pExp->getAs<ast::SeqExp>();
+    pSeqExp->setExecFrom(ast::SeqExp::EXEC);
+    std::unique_ptr<ast::ConstVisitor> exec(ConfigVariable::getDefaultVisitor());
 
+    try
+    {
+        symbol::Context* pCtx = symbol::Context::getInstance();
+        int scope = pCtx->getScopeLevel();
+        int level = ConfigVariable::getRecursionLevel();
         try
         {
-            symbol::Context* pCtx = symbol::Context::getInstance();
-            int scope = pCtx->getScopeLevel();
-            int level = ConfigVariable::getRecursionLevel();
-            try
+            pSeqExp->accept(*exec);
+        }
+        catch (const ast::RecursionException& /* re */)
+        {
+            //close opened scope during try
+            while (pCtx->getScopeLevel() > scope)
             {
-                pSeqExp->accept(*exec);
+                pCtx->scope_end();
             }
-            catch (const ast::RecursionException& /* re */)
-            {
-                //close opened scope during try
-                while (pCtx->getScopeLevel() > scope)
-                {
-                    pCtx->scope_end();
-                }
-
-                //decrease recursion to init value
-                while (ConfigVariable::getRecursionLevel() > level)
-                {
-                    ConfigVariable::where_end();
-                    ConfigVariable::decreaseRecursion();
-                }
 
-                //print msg about recursion limit and trigger an error
-                wchar_t sz[1024];
-                os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
-                throw ast::InternalError(sz);
-            }
-        }
-        catch (const ast::InternalAbort& ia)
-        {
-            closeFile(file, iID, wstFile, pExp);
-            throw ia;
-        }
-        catch (const ast::InternalError& ie)
-        {
-            if (bErrCatch == false)
+            //decrease recursion to init value
+            while (ConfigVariable::getRecursionLevel() > level)
             {
-                closeFile(file, iID, wstFile, pExp);
-                ConfigVariable::setPromptMode(oldVal);
-                ConfigVariable::setExecutedFileID(0);
-                throw ie;
+                ConfigVariable::where_end();
+                ConfigVariable::decreaseRecursion();
             }
 
-            ConfigVariable::resetWhereError();
-            iErr = ConfigVariable::getLastErrorNumber();
+            //print msg about recursion limit and trigger an error
+            wchar_t sz[1024];
+            os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
+            throw ast::InternalError(sz);
         }
     }
-    else
+    catch (const ast::InternalAbort& ia)
     {
-        ast::exps_t& LExp = pExp->getAs<ast::SeqExp>()->getExps();
-
-        char pstPrompt[64];
-        //get prompt
-        GetCurrentPrompt(pstPrompt);
-        std::string stPrompt(pstPrompt);
-
-        std::string str;
-        int iCurrentLine = -1; //no data in str
-        int iCurrentCol = 0; //no data in str
-
-        for (ast::exps_t::iterator j = LExp.begin(), itEnd = LExp.end() ; j != itEnd; ++j)
+        closeFile(file, iID, wstFile, pExp);
+        throw ia;
+    }
+    catch (const ast::InternalError& ie)
+    {
+        if (bErrCatch == false)
         {
-            if (ConfigVariable::getPromptMode() == 7)
-            {
-                stPrompt = SCIPROMPT_PAUSE;
-            }
-            // printf some exp
-            ast::exps_t::iterator k = j;
-            int iLastLine = (*j)->getLocation().last_line;
-            do
-            {
-                str = printExp(*file, *k, stPrompt, &iCurrentLine, &iCurrentCol, str);
-                iLastLine = (*k)->getLocation().last_line;
-                k++;
-            }
-            while (k != LExp.end() && (*k)->getLocation().first_line == iLastLine);
-
-            // In case where the line ends by spaces, iCurrentCol is not reset
-            // by printExp because we don't know if that's the end of the expression
-            // before go out of the loop. So we have to reset column count
-            // and print a new line before manage the next line.
-            if (iCurrentCol != 0)
-            {
-                iCurrentCol = 0;
-                printLine("", "", true);
-            }
-
-            // create a seqexp with printed exp
-            ast::exps_t* someExps = new ast::exps_t();
-            someExps->assign(j, k);
-            k--;
-            ast::SeqExp seqExp(Location((*j)->getLocation().first_line,
-                                        (*k)->getLocation().last_line,
-                                        (*j)->getLocation().first_column,
-                                        (*k)->getLocation().last_column),
-                               *someExps);
-
-            j = k;
-
-            std::unique_ptr<ast::ConstVisitor> exec(ConfigVariable::getDefaultVisitor());
-
-            try
-            {
-                symbol::Context* pCtx = symbol::Context::getInstance();
-                int scope = pCtx->getScopeLevel();
-                int level = ConfigVariable::getRecursionLevel();
-                try
-                {
-                    // execute printed exp
-                    seqExp.accept(*exec);
-                }
-                catch (const ast::RecursionException& /* re */)
-                {
-                    //close opened scope during try
-                    while (pCtx->getScopeLevel() > scope)
-                    {
-                        pCtx->scope_end();
-                    }
-
-                    //decrease recursion to init value
-                    while (ConfigVariable::getRecursionLevel() > level)
-                    {
-                        ConfigVariable::where_end();
-                        ConfigVariable::decreaseRecursion();
-                    }
-
-                    //print msg about recursion limit and trigger an error
-                    wchar_t sz[1024];
-                    os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
-                    throw ast::InternalError(sz);
-                }
-            }
-            catch (const ast::InternalAbort& ia)
-            {
-                closeFile(file, iID, wstFile, pExp);
-
-                //restore previous prompt mode
-                ConfigVariable::setPromptMode(oldVal);
-
-                // avoid double delete on exps when "seqExp" is destryed and "LExp" too
-                ast::exps_t& protectExp = seqExp.getExps();
-                for (int i = 0; i < protectExp.size(); ++i)
-                {
-                    protectExp[i] = NULL;
-                }
-
-                throw ia;
-            }
-            catch (const ast::InternalError& ie)
-            {
-                ConfigVariable::setExecutedFileID(0);
-                ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
-                if (ConfigVariable::getLastErrorLine() == 0)
-                {
-                    ConfigVariable::setLastErrorLine(ie.GetErrorLocation().first_line);
-                }
-
-                // avoid double delete on exps when "seqExp" is destryed and "LExp" too
-                ast::exps_t& protectExp = seqExp.getExps();
-                for (int i = 0; i < protectExp.size(); ++i)
-                {
-                    protectExp[i] = NULL;
-                }
-
-                //store message
-                iErr = ConfigVariable::getLastErrorNumber();
-                if (bErrCatch == false)
-                {
-                    closeFile(file, iID, wstFile, pExp);
-
-                    //restore previous prompt mode
-                    ConfigVariable::setPromptMode(oldVal);
-                    throw ie;
-                }
-
-                if (pMacro)
-                {
-                    // reset last first line of macro called
-                    ConfigVariable::macroFirstLine_end();
-                }
-
-                ConfigVariable::resetWhereError();
-                break;
-            }
-
+            closeFile(file, iID, wstFile, pExp);
+            ConfigVariable::setPromptMode(oldVal);
             ConfigVariable::setExecutedFileID(0);
-
-            // avoid double delete on exps when "seqExp" is destryed and "LExp" too
-            ast::exps_t& protectExp = seqExp.getExps();
-            for (int i = 0; i < protectExp.size(); ++i)
-            {
-                protectExp[i] = NULL;
-            }
+            throw ie;
         }
+
+        ConfigVariable::resetWhereError();
+        iErr = ConfigVariable::getLastErrorNumber();
     }
 
     //restore previous prompt mode
@@ -506,231 +351,3 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
     closeFile(file, iID, wstFile, pExp);
     return types::Function::OK;
 }
-
-std::string getExpression(const std::string& _stFile, ast::Exp* _pExp)
-{
-    std::string out;
-    std::string stBuffer;
-    int iLine = 0;
-    Location loc = _pExp->getLocation();
-    std::ifstream file(_stFile.c_str());
-
-    //bypass previous lines
-    for (int i = 0 ; i < loc.first_line; i++)
-    {
-        std::getline(file, stBuffer);
-    }
-
-    if (loc.first_line == loc.last_line)
-    {
-        int iStart = loc.first_column - 1;
-        int iEnd = loc.last_column - 1;
-        int iLen = iEnd - iStart;
-        out += std::string(stBuffer.c_str() + iStart, iLen);
-    }
-    else
-    {
-        //
-
-        //first line, entire or not
-        out += std::string(stBuffer.c_str() + loc.first_column - 1);
-        out += "\n";
-
-        //print other full lines
-        for (int i = loc.first_line; i < (loc.last_line - 1) ; i++)
-        {
-            std::getline(file, stBuffer);
-            out += stBuffer;
-            out += "\n";
-        }
-
-
-        //last line, entire or not
-        getline(file, stBuffer);
-        out += std::string(stBuffer.c_str(), loc.last_column - 1);
-        out += "\n";
-    }
-    return out;
-}
-
-std::string printExp(std::ifstream& _File, ast::Exp* _pExp, const std::string& _stPrompt, int* _piLine /* in/out */, int* _piCol /* in/out */, std::string& _stPreviousBuffer)
-{
-    //case 1, exp is on 1 line and take the entire line
-
-    //case 2, exp is multiline
-
-    //case 3, exp is part of a line.
-    //ex : 3 exp on the same line a = 1; b = 2; c = 3;
-
-    //case 4, exp is multiline but start and/or finish in the middle of a line
-    //ex :
-    //a = 10;for i = 1 : a
-    // a
-    //end, b = 1;
-
-    Location loc = _pExp->getLocation();
-
-    //positionning file curser at loc.first_line
-    {
-        //strange case, current position is after the wanted position
-        if (*_piLine > loc.first_line)
-        {
-            //reset line counter and restart reading at the start of the file.
-            *_piLine = -1;
-            _File.seekg( 0, std::ios_base::beg );
-        }
-
-        //bypass previous lines
-        for (int i = *_piLine ; i < loc.first_line - 1; i++)
-        {
-
-            (*_piLine)++;
-            if ((*_piLine) != (loc.first_line - 1))
-            {
-                //empty line but not sequential lines
-                printLine("", "", true);
-            }
-            std::getline(_File, _stPreviousBuffer);
-        }
-    }
-
-    if (loc.first_line == loc.last_line)
-    {
-        //1 line
-        int iStart = loc.first_column - 1;
-        int iEnd = loc.last_column - 1;
-        int iLen = iEnd - iStart;
-        std::string strLastLine(_stPreviousBuffer.c_str() + iStart, iLen);
-        int iExpLen = iLen;
-        int iLineLen = (int)_stPreviousBuffer.size();
-        //printLine(_pstPrompt, strLastLine, true, false);
-
-        if (iStart == 0 && iExpLen == iLineLen)
-        {
-            //entire line
-            if (*_piCol)
-            {
-                //blank char at the end of previous line
-                printLine("", "", true);
-            }
-            printLine(_stPrompt, strLastLine, true);
-            *_piCol = 0;
-        }
-        else
-        {
-            if (iStart == 0)
-            {
-                //begin of line
-                if (*_piCol)
-                {
-                    //blank char at the end of previous line
-                    printLine("", "", true);
-                }
-                printLine(_stPrompt, strLastLine, false);
-                *_piCol = loc.last_column;
-            }
-            else
-            {
-                if (*_piCol == 0)
-                {
-                    printLine(_stPrompt, "", false);
-                    (*_piCol)++;
-                }
-
-                if (*_piCol < loc.first_column)
-                {
-                    //pickup separator between expressionsfrom file and add to output
-                    int iSize = loc.first_column - *_piCol;
-                    std::string stTemp(_stPreviousBuffer.c_str() +  (*_piCol - 1), iSize);
-                    printLine("", stTemp, false);
-                    *_piCol = loc.first_column;
-                }
-
-                if (iEnd == iLineLen)
-                {
-                    printLine("", strLastLine, true);
-                    *_piCol = 0;
-                }
-                else
-                {
-                    printLine("", strLastLine, false);
-                    *_piCol = loc.last_column;
-                }
-            }
-        }
-    }
-    else
-    {
-        //multiline
-
-        if (loc.first_column == 1)
-        {
-            if (*_piCol)
-            {
-                //blank char at the end of previous line
-                printLine("", "", true);
-            }
-            printLine(_stPrompt, _stPreviousBuffer.c_str() + (loc.first_column - 1), false);
-        }
-        else
-        {
-            if (*_piCol < loc.first_column)
-            {
-                //pickup separator between expressionsfrom file and add to output
-                printLine(_stPrompt, _stPreviousBuffer.c_str(), false);
-                *_piCol = loc.first_column;
-            }
-        }
-
-        //print other full lines
-        for (int i = loc.first_line; i < (loc.last_line - 1) ; i++)
-        {
-            (*_piLine)++;
-            std::getline(_File, _stPreviousBuffer);
-            // dont print empty line of function body
-            if (_stPreviousBuffer.size() != 0)
-            {
-                printLine(_stPrompt, _stPreviousBuffer.c_str(), false);
-            }
-        }
-
-        //last line
-        std::getline(_File, _stPreviousBuffer);
-        (*_piLine)++;
-
-        int iSize = loc.last_column - 1;
-        std::string stLastLine(_stPreviousBuffer.c_str(), iSize);
-        int iLineLen = (int)_stPreviousBuffer.size();
-        if (iLineLen == iSize)
-        {
-            printLine(_stPrompt, stLastLine, true);
-            *_piCol = 0;
-        }
-        else
-        {
-            printLine(_stPrompt, stLastLine, false);
-            *_piCol = loc.last_column;
-        }
-    }
-
-    return _stPreviousBuffer;
-}
-
-void printLine(const std::string& _stPrompt, const std::string& _stLine, bool _bLF)
-{
-    std::string st;
-
-    if (_stPrompt.size() != 0)
-    {
-        st = "\n" + _stPrompt;
-    }
-
-    st += _stLine;
-    if (_bLF && ConfigVariable::isEmptyLineShow())
-    {
-        st += "\n";
-    }
-
-    scilabWrite(st.c_str());
-}
-/*--------------------------------------------------------------------------*/
index 8bd8118..888c519 100644 (file)
@@ -3,8 +3,8 @@
 
 EXPORTS
 setLastError
-isPromptShow
-getSilentError
+isPrintOutput
+isSilentError
 getConsoleWidth
 getWarningMode
-getWarningStop
\ No newline at end of file
+getWarningStop
index 66ab6a3..09425d1 100644 (file)
@@ -39,7 +39,7 @@ static void scilabPrint(const char* _pstText)
 
 void scilabWrite(const char* _pstText)
 {
-    if (isPromptShow())
+    if (isPrintOutput())
     {
         scilabPrint(const_cast<char*>(_pstText));
     }
@@ -52,7 +52,7 @@ void scilabForcedWrite(const char* _pstText)
 
 void scilabWriteW(const wchar_t* _pwsText)
 {
-    if (isPromptShow())
+    if (isPrintOutput())
     {
         char* pstTemp = wide_string_to_UTF8(_pwsText);
         scilabWrite(pstTemp);
@@ -69,7 +69,7 @@ void scilabForcedWriteW(const wchar_t* _pwsText)
 
 void scilabError(const char* _pstText)
 {
-    if (getSilentError() == VERBOSE_ERROR)
+    if (isSilentError() == 0)
     {
         scilabPrint(const_cast<char*>(_pstText));
     }
@@ -77,7 +77,7 @@ void scilabError(const char* _pstText)
 
 void scilabErrorW(const wchar_t* _pwsText)
 {
-    if (getSilentError() == VERBOSE_ERROR)
+    if (isSilentError() == 0)
     {
         char* pstTemp = wide_string_to_UTF8(_pwsText);
         scilabPrint(pstTemp);