exec and ecestr fixed about parsing error. 94/16694/3
Cedric Delamarre [Wed, 17 Jun 2015 09:42:51 +0000 (11:42 +0200)]
f=mopen(TMPDIR+"/test", "w");
mfprintf(1, "funtion test()\nend");
mclose(f);

exec(TMPDIR+"/test")
[err, num] = lasterror()
exec(TMPDIR+"/test", "errcatch")
[err, num] = lasterror()

execstr("funtion test(),end")
[err, num] = lasterror()
execstr("funtion test(),end", "errcatch")
[err, num] = lasterror()

Change-Id: Icba7c9df3738e030f6e30666a598ac9c534f6b54

scilab/modules/core/tests/nonreg_tests/bug_2072.dia.ref
scilab/modules/core/tests/nonreg_tests/bug_2072.tst
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/sci_gateway/cpp/sci_execstr.cpp

index c02fa63..7274d73 100644 (file)
 // <-- Short Description -->
 //   incorrect clause uncorrectly handled under errcatch
 // <-- CLI SHELL MODE -->
-mkdir(TMPDIR,'b2072');
-txt=['function test()'
-     'if 1 ~=1 then'
-     '   a=3;'
-     'end'
-     'else'
-     '   a=7;'
-     'end'
-     'endfunction']
- txt  =
-!function test()  !
-!                 !
-!if 1 ~=1 then    !
-!                 !
-!   a=3;          !
-!                 !
-!end              !
-!                 !
-!else             !
-!                 !
-!   a=7;          !
-!                 !
-!end              !
-!                 !
-!endfunction      !
-mputl(txt,TMPDIR+'/b2072/test.sci');
-txt=['function testOK()'
-     'a=3;'
-     '   end'
-     'endfunction   ']
- txt  =
-!function testOK()  !
-!                   !
-!a=3;               !
-!                   !
-!   end             !
-!                   !
-!endfunction        !
-mputl(txt,TMPDIR+'/b2072/testOK.sci');
-if execstr('exec(TMPDIR+''/b2072/test.sci'');','errcatch')<>34 then bugmes();quit;end
-if execstr('exec(TMPDIR+''/b2072/testOK.sci'');','errcatch')<>34 then bugmes();quit;end
+mkdir(TMPDIR,"b2072");
+txt=["function test()"
+"if 1 ~=1 then"
+"   a=3;"
+"end"
+"else"
+"   a=7;"
+"end"
+"endfunction"];
+mputl(txt,TMPDIR+"/b2072/test.sci");
+txt=["function testOK()"
+"a=3;"
+"   end"
+"endfunction   "];
+mputl(txt,TMPDIR+"/b2072/testOK.sci");
+if execstr("exec(TMPDIR+''/b2072/test.sci'');","errcatch")==0 then bugmes();quit;end
+if execstr("exec(TMPDIR+''/b2072/testOK.sci'');","errcatch")==0 then bugmes();quit;end
index 83fd7cf..6653104 100644 (file)
 
 // <-- CLI SHELL MODE -->
 
-mkdir(TMPDIR,'b2072');
+mkdir(TMPDIR,"b2072");
 
-txt=['function test()'
-     'if 1 ~=1 then'
-     '   a=3;'
-     'end'
-     'else'
-     '   a=7;'
-     'end'
-     'endfunction']
-mputl(txt,TMPDIR+'/b2072/test.sci');
-txt=['function testOK()'
-     'a=3;'
-     '   end'
-     'endfunction   ']
-mputl(txt,TMPDIR+'/b2072/testOK.sci');
+txt=["function test()"
+"if 1 ~=1 then"
+"   a=3;"
+"end"
+"else"
+"   a=7;"
+"end"
+"endfunction"];
+mputl(txt,TMPDIR+"/b2072/test.sci");
+txt=["function testOK()"
+"a=3;"
+"   end"
+"endfunction   "];
+mputl(txt,TMPDIR+"/b2072/testOK.sci");
+
+if execstr("exec(TMPDIR+''/b2072/test.sci'');","errcatch")==0 then pause,end
+if execstr("exec(TMPDIR+''/b2072/testOK.sci'');","errcatch")==0 then pause,end
 
-if execstr('exec(TMPDIR+''/b2072/test.sci'');','errcatch')<>34 then pause,end
-if execstr('exec(TMPDIR+''/b2072/testOK.sci'');','errcatch')<>34 then pause,end
-  
index 6a1d126..36a39b0 100644 (file)
@@ -87,6 +87,97 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         return Function::Error;
     }
 
+    // get mode and errcatch
+    if (in.size() > 1)
+    {
+        //errcatch or mode
+        if (in[1]->isString() && in[1]->getAs<types::String>()->isScalar())
+        {
+            //errcatch
+            String* pS = in[1]->getAs<types::String>();
+            if (os_wcsicmp(pS->get(0), L"errcatch") == 0)
+            {
+                bErrCatch = true;
+            }
+            else
+            {
+                if (file)
+                {
+                    delete pExp;
+                    mclose(iID);
+                    file->close();
+                    delete file;
+                    FREE(pstFile);
+                    FREE(pwstFile);
+                }
+
+                Scierror(999, _("%s: Wrong value for input argument #%d: 'errcatch' expected.\n"), "exec", 2);
+                return Function::Error;
+            }
+
+            if (in.size() > 2)
+            {
+
+                if (in[2]->isDouble() == false || in[2]->getAs<Double>()->isScalar() == false)
+                {
+                    if (file)
+                    {
+                        delete pExp;
+                        mclose(iID);
+                        file->close();
+                        delete file;
+                        FREE(pstFile);
+                        FREE(pwstFile);
+                    }
+
+                    //mode
+                    Scierror(999, _("%s: Wrong type for input argument #%d: A integer expected.\n"), "exec", 3);
+                    return Function::Error;
+                }
+
+                promptMode = (int)in[2]->getAs<Double>()->getReal()[0];
+                bPromptMode = true;
+            }
+        }
+        else if (in[1]->isDouble() && in[1]->getAs<Double>()->isScalar())
+        {
+            if (in.size() > 2)
+            {
+                if (file)
+                {
+                    delete pExp;
+                    mclose(iID);
+                    file->close();
+                    delete file;
+                    FREE(pstFile);
+                    FREE(pwstFile);
+                }
+
+                Scierror(999, _("%s: Wrong value for input argument #%d: 'errcatch' expected.\n"), "exec", 2);
+                return Function::Error;
+            }
+            //mode
+            promptMode = (int)in[1]->getAs<Double>()->getReal()[0];
+            bPromptMode = true;
+        }
+        else
+        {
+            if (file)
+            {
+                delete pExp;
+                mclose(iID);
+                file->close();
+                delete file;
+                FREE(pstFile);
+                FREE(pwstFile);
+            }
+
+            //not managed
+            Scierror(999, _("%s: Wrong type for input argument #%d: A integer or string expected.\n"), "exec", 2);
+            return Function::Error;
+        }
+    }
+
     if (in[0]->isString() && in[0]->getAs<types::String>()->isScalar())
     {
         //1st argument is a path, parse file and execute it
@@ -113,7 +204,21 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         FREE(pwstTemp);
         if (parser.getExitStatus() !=  Parser::Succeded)
         {
-            scilabWriteW(parser.getErrorMessage());
+            if (bErrCatch)
+            {
+                out.push_back(new Double(999));
+                //to lock last error information
+                ConfigVariable::setLastErrorCall();
+                ConfigVariable::setLastErrorMessage(parser.getErrorMessage());
+                ConfigVariable::setLastErrorNumber(999);
+                delete parser.getTree();
+                mclose(iID);
+                return Function::OK;
+            }
+
+            char* pst = wide_string_to_UTF8(parser.getErrorMessage());
+            Scierror(999, "%s", pst);
+            FREE(pst);
             delete parser.getTree();
             mclose(iID);
             return Function::Error;
@@ -184,97 +289,6 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         return Function::Error;
     }
 
-    // get mode and errcatch
-    if (in.size() > 1)
-    {
-        //errcatch or mode
-        if (in[1]->isString() && in[1]->getAs<types::String>()->isScalar())
-        {
-            //errcatch
-            String* pS = in[1]->getAs<types::String>();
-            if (os_wcsicmp(pS->get(0), L"errcatch") == 0)
-            {
-                bErrCatch = true;
-            }
-            else
-            {
-                if (file)
-                {
-                    delete pExp;
-                    mclose(iID);
-                    file->close();
-                    delete file;
-                    FREE(pstFile);
-                    FREE(pwstFile);
-                }
-
-                Scierror(999, _("%s: Wrong value for input argument #%d: 'errcatch' expected.\n"), "exec", 2);
-                return Function::Error;
-            }
-
-            if (in.size() > 2)
-            {
-
-                if (in[2]->isDouble() == false || in[2]->getAs<Double>()->isScalar() == false)
-                {
-                    if (file)
-                    {
-                        delete pExp;
-                        mclose(iID);
-                        file->close();
-                        delete file;
-                        FREE(pstFile);
-                        FREE(pwstFile);
-                    }
-
-                    //mode
-                    Scierror(999, _("%s: Wrong type for input argument #%d: A integer expected.\n"), "exec", 3);
-                    return Function::Error;
-                }
-
-                promptMode = (int)in[2]->getAs<Double>()->getReal()[0];
-                bPromptMode = true;
-            }
-        }
-        else if (in[1]->isDouble() && in[1]->getAs<Double>()->isScalar())
-        {
-            if (in.size() > 2)
-            {
-                if (file)
-                {
-                    delete pExp;
-                    mclose(iID);
-                    file->close();
-                    delete file;
-                    FREE(pstFile);
-                    FREE(pwstFile);
-                }
-
-                Scierror(999, _("%s: Wrong value for input argument #%d: 'errcatch' expected.\n"), "exec", 2);
-                return Function::Error;
-            }
-            //mode
-            promptMode = (int)in[1]->getAs<Double>()->getReal()[0];
-            bPromptMode = true;
-        }
-        else
-        {
-            if (file)
-            {
-                delete pExp;
-                mclose(iID);
-                file->close();
-                delete file;
-                FREE(pstFile);
-                FREE(pwstFile);
-            }
-
-            //not managed
-            Scierror(999, _("%s: Wrong type for input argument #%d: A integer or string expected.\n"), "exec", 2);
-            return Function::Error;
-        }
-    }
-
     ast::exps_t& LExp = pExp->getAs<SeqExp>()->getExps();
 
     char pstPrompt[64];
index db3b5fc..67830c8 100644 (file)
@@ -152,6 +152,8 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
             out.push_back(new Double(999));
             //to lock last error information
             ConfigVariable::setLastErrorCall();
+            ConfigVariable::setLastErrorMessage(parser.getErrorMessage());
+            ConfigVariable::setLastErrorNumber(999);
             return Function::OK;
         }
         else