Rewrite validvar as gateway in scicos modules 20/15720/5
Antoine ELIAS [Thu, 18 Dec 2014 09:56:09 +0000 (10:56 +0100)]
Change-Id: I0e440bec40432aed165b03bd423abc21888e8723

14 files changed:
scilab/modules/api_scilab/src/cpp/api_common.cpp
scilab/modules/ast/includes/symbol/context.hxx
scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/core/sci_gateway/cpp/sci_global.cpp
scilab/modules/scicos/Makefile.am
scilab/modules/scicos/Makefile.in
scilab/modules/scicos/includes/gw_scicos.hxx
scilab/modules/scicos/macros/scicos_scicos/validvar.sci [deleted file]
scilab/modules/scicos/sci_gateway/cpp/sci_validvar.cpp [new file with mode: 0644]
scilab/modules/scicos/sci_gateway/scicos_gateway.xml
scilab/modules/scicos/src/c/scicos.vcxproj
scilab/modules/scicos/src/c/scicos.vcxproj.filters
scilab/modules/scicos/tests/unit_tests/validvar.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/validvar.tst [new file with mode: 0644]

index 81ce4e9..2868eed 100644 (file)
@@ -1502,8 +1502,6 @@ int isNamedVarExist(void *_pvCtx, const char *_pstName)
 /*--------------------------------------------------------------------------*/
 int checkNamedVarFormat(void* _pvCtx, const char *_pstName)
 {
-#define FORBIDDEN_CHARS " */\\.,;:^@><!=+-&|()~\n\t'\""
-
     // check pointer
     if (_pstName == NULL)
     {
@@ -1511,34 +1509,11 @@ int checkNamedVarFormat(void* _pvCtx, const char *_pstName)
     }
 
     // check length _pstName <> 0
-    if (strlen(_pstName) == 0)
-    {
-        return 0;
-    }
-
-    // forbidden characters
-    if (strpbrk(_pstName, FORBIDDEN_CHARS) != NULL)
+    if (symbol::Context::getInstance()->isValidVariableName(_pstName) == false)
     {
         return 0;
     }
 
-    // variable does not begin by a digit
-    if (isdigit(_pstName[0]))
-    {
-        return 0;
-    }
-
-    // check that we have only ascii characters
-    for (int i = 0; i < (int)strlen(_pstName); i++)
-    {
-        if (!isascii(_pstName[i]))
-        {
-            return 0;
-        }
-    }
-
-    // add here some others rules
-
     return 1;
 }
 /*--------------------------------------------------------------------------*/
index b328684..fdec3a6 100644 (file)
@@ -121,8 +121,9 @@ public :
     bool addMacroFile(types::MacroFile *_info);
     void print(std::wostream& ostr, bool bSorted = false) const;
     int getScopeLevel();
-
-private :
+    bool isValidVariableName(const wchar_t*);
+    bool isValidVariableName(const char*);
+private:
 
     types::InternalType* get(const Symbol& key, int _iLevel);
     bool clearCurrentScope(bool _bClose);
index cc704ad..e8dbf4c 100644 (file)
@@ -10,6 +10,7 @@
 *
 */
 #include <iomanip>
+#include <cctype>
 
 #include "context.hxx"
 #include "internal.hxx"
@@ -445,4 +446,27 @@ int Context::getScopeLevel()
 {
     return m_iLevel;
 }
+
+bool Context::isValidVariableName(const wchar_t* wcsVarName)
+{
+    static const wchar_t FORBIDDEN_CHARS[] = L" */\\.,;:^@><=+-&|()~\n\t'\"";
+    if (wcslen(wcsVarName) == 0 || wcspbrk(wcsVarName, FORBIDDEN_CHARS) || isdigit(wcsVarName[0]))
+    {
+        return false;
+    }
+    return true;
+}
+
+bool Context::isValidVariableName(const char* name)
+{
+    bool isValid = false;
+    wchar_t* wcsname = to_wide_string(name);
+    if (wcsname)
+    {
+        isValid = isValidVariableName(wcsname);
+        FREE(wcsname);
+    }
+
+    return isValid;
+}
 }
index 7336f18..ebd8ef5 100644 (file)
@@ -55,7 +55,7 @@ types::Function::ReturnValue sci_global(types::typed_list &in, int _iRetCount, t
     for (int i = 0 ; i < in.size() ; i++)
     {
         wchar_t* wcsVarName = in[i]->getAs<types::String>()->get(0);
-        if (wcslen(wcsVarName) == 0 || wcspbrk(wcsVarName, FORBIDDEN_CHARS) || isdigit(wcsVarName[0]))
+        if (symbol::Context::getInstance()->isValidVariableName(wcsVarName) == false)
         {
             char* pstrVarName = wide_string_to_UTF8(wcsVarName);
             Scierror(999, _("%s : Wrong value for argument #%d: %s\n"), "global", i + 1, pstrVarName);
index 7c7ea0b..c617b50 100644 (file)
@@ -72,7 +72,8 @@ NO_SCICOS_C_SOURCES = src/c/noscicos/noscicos.c
 GATEWAY_CXX_SOURCES = \
 sci_gateway/cpp/sci_scicos_log.cpp \
 sci_gateway/cpp/sci_scicos_new.cpp \
-sci_gateway/cpp/sci_scicos_setfield.cpp
+sci_gateway/cpp/sci_scicos_setfield.cpp \
+sci_gateway/cpp/sci_validvar.cpp
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_scicos.c \
 sci_gateway/c/sci_buildouttb.c \
@@ -135,29 +136,31 @@ libsciscicos_cli_la_LDFLAGS = $(AM_LDFLAGS)
 libsciscicos_la_LDFLAGS = $(AM_LDFLAGS)
 
 if XCOS
-libsciscicos_algo_la_CPPFLAGS= -I$(srcdir)/includes/ \
-                       -I$(srcdir)/src/c/ \
-                       -I$(srcdir)/src/cpp/ \
-                       -I$(srcdir)/src/scicos_sundials/include/ \
-                       -I$(srcdir)/src/scicos_sundials/include/sundials/ \
-                       -I$(srcdir)/src/scicos_sundials/src/ida/ \
-                       -I$(top_srcdir)/modules/output_stream/includes/ \
-                       -I$(top_srcdir)/modules/dynamic_link/includes/ \
-                       -I$(top_srcdir)/modules/string/includes/ \
-                       -I$(top_srcdir)/modules/localization/includes/ \
-                       -I$(top_srcdir)/modules/scicos_blocks/includes/ \
-                       -I$(top_srcdir)/modules/action_binding/includes/ \
-                       -I$(top_srcdir)/modules/time/includes/ \
-                       -I$(top_srcdir)/modules/api_scilab/includes/ \
-                       -I$(top_srcdir)/modules/ast/includes/ast/ \
-                       -I$(top_srcdir)/modules/ast/includes/exps/ \
-                       -I$(top_srcdir)/modules/ast/includes/operations/ \
-                       -I$(top_srcdir)/modules/ast/includes/system_env/ \
-                       -I$(top_srcdir)/modules/ast/includes/types/ \
-                       -I$(top_srcdir)/modules/ast/includes/analysis/ \
-                       -I$(top_srcdir)/modules/threads/includes/ \
-                       $(EIGEN_CPPFLAGS) \
-                       $(AM_CPPFLAGS)
+libsciscicos_algo_la_CPPFLAGS= \
+    -I$(srcdir)/includes/ \
+    -I$(srcdir)/src/c/ \
+    -I$(srcdir)/src/cpp/ \
+    -I$(srcdir)/src/scicos_sundials/include/ \
+    -I$(srcdir)/src/scicos_sundials/include/sundials/ \
+    -I$(srcdir)/src/scicos_sundials/src/ida/ \
+    -I$(top_srcdir)/modules/output_stream/includes/ \
+    -I$(top_srcdir)/modules/dynamic_link/includes/ \
+    -I$(top_srcdir)/modules/string/includes/ \
+    -I$(top_srcdir)/modules/localization/includes/ \
+    -I$(top_srcdir)/modules/scicos_blocks/includes/ \
+    -I$(top_srcdir)/modules/action_binding/includes/ \
+    -I$(top_srcdir)/modules/time/includes/ \
+    -I$(top_srcdir)/modules/api_scilab/includes/ \
+    -I$(top_srcdir)/modules/ast/includes/ast/ \
+    -I$(top_srcdir)/modules/ast/includes/exps/ \
+    -I$(top_srcdir)/modules/ast/includes/symbol/ \
+    -I$(top_srcdir)/modules/ast/includes/operations/ \
+    -I$(top_srcdir)/modules/ast/includes/system_env/ \
+    -I$(top_srcdir)/modules/ast/includes/types/ \
+    -I$(top_srcdir)/modules/ast/includes/analysis/ \
+    -I$(top_srcdir)/modules/threads/includes/ \
+    $(EIGEN_CPPFLAGS) \
+    $(AM_CPPFLAGS)
 else
 libsciscicos_algo_la_CPPFLAGS= -I$(top_srcdir)/modules/output_stream/includes/ \
                        -I$(top_srcdir)/modules/api_scilab/includes/ \
index 126172e..0ab613c 100644 (file)
@@ -292,15 +292,15 @@ am__libsciscicos_cli_la_SOURCES_DIST =  \
        sci_gateway/cpp/sci_scicos_log.cpp \
        sci_gateway/cpp/sci_scicos_new.cpp \
        sci_gateway/cpp/sci_scicos_setfield.cpp \
-       sci_gateway/c/gw_scicos.c sci_gateway/c/sci_buildouttb.c \
-       sci_gateway/c/sci_callblk.c sci_gateway/c/sci_coserror.c \
-       sci_gateway/c/sci_ctree2.c sci_gateway/c/sci_ctree3.c \
-       sci_gateway/c/sci_ctree4.c sci_gateway/c/sci_curblock.c \
-       sci_gateway/c/sci_curblockc.c sci_gateway/c/sci_data2sig.c \
-       sci_gateway/c/sci_diffobjs.c sci_gateway/c/sci_duplicate.c \
-       sci_gateway/c/sci_end_scicosim.c sci_gateway/c/sci_ftree2.c \
-       sci_gateway/c/sci_ftree3.c sci_gateway/c/sci_ftree4.c \
-       sci_gateway/c/sci_getblocklabel.c \
+       sci_gateway/cpp/sci_validvar.cpp sci_gateway/c/gw_scicos.c \
+       sci_gateway/c/sci_buildouttb.c sci_gateway/c/sci_callblk.c \
+       sci_gateway/c/sci_coserror.c sci_gateway/c/sci_ctree2.c \
+       sci_gateway/c/sci_ctree3.c sci_gateway/c/sci_ctree4.c \
+       sci_gateway/c/sci_curblock.c sci_gateway/c/sci_curblockc.c \
+       sci_gateway/c/sci_data2sig.c sci_gateway/c/sci_diffobjs.c \
+       sci_gateway/c/sci_duplicate.c sci_gateway/c/sci_end_scicosim.c \
+       sci_gateway/c/sci_ftree2.c sci_gateway/c/sci_ftree3.c \
+       sci_gateway/c/sci_ftree4.c sci_gateway/c/sci_getblocklabel.c \
        sci_gateway/c/sci_getscicosvars.c \
        sci_gateway/c/sci_haltscicos.c sci_gateway/c/sci_loadScicos.c \
        sci_gateway/c/sci_model2blk.c \
@@ -324,7 +324,8 @@ am__libsciscicos_cli_la_SOURCES_DIST =  \
        sci_gateway/fortran/sci_f_vec2var.f
 am__objects_5 = sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_log.lo \
        sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_new.lo \
-       sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_setfield.lo
+       sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_setfield.lo \
+       sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo
 am__objects_6 = sci_gateway/c/libsciscicos_cli_la-gw_scicos.lo \
        sci_gateway/c/libsciscicos_cli_la-sci_buildouttb.lo \
        sci_gateway/c/libsciscicos_cli_la-sci_callblk.lo \
@@ -381,15 +382,15 @@ libsciscicos_la_DEPENDENCIES = libsciscicos-algo.la $(am__append_3) \
 am__libsciscicos_la_SOURCES_DIST = sci_gateway/cpp/sci_scicos_log.cpp \
        sci_gateway/cpp/sci_scicos_new.cpp \
        sci_gateway/cpp/sci_scicos_setfield.cpp \
-       sci_gateway/c/gw_scicos.c sci_gateway/c/sci_buildouttb.c \
-       sci_gateway/c/sci_callblk.c sci_gateway/c/sci_coserror.c \
-       sci_gateway/c/sci_ctree2.c sci_gateway/c/sci_ctree3.c \
-       sci_gateway/c/sci_ctree4.c sci_gateway/c/sci_curblock.c \
-       sci_gateway/c/sci_curblockc.c sci_gateway/c/sci_data2sig.c \
-       sci_gateway/c/sci_diffobjs.c sci_gateway/c/sci_duplicate.c \
-       sci_gateway/c/sci_end_scicosim.c sci_gateway/c/sci_ftree2.c \
-       sci_gateway/c/sci_ftree3.c sci_gateway/c/sci_ftree4.c \
-       sci_gateway/c/sci_getblocklabel.c \
+       sci_gateway/cpp/sci_validvar.cpp sci_gateway/c/gw_scicos.c \
+       sci_gateway/c/sci_buildouttb.c sci_gateway/c/sci_callblk.c \
+       sci_gateway/c/sci_coserror.c sci_gateway/c/sci_ctree2.c \
+       sci_gateway/c/sci_ctree3.c sci_gateway/c/sci_ctree4.c \
+       sci_gateway/c/sci_curblock.c sci_gateway/c/sci_curblockc.c \
+       sci_gateway/c/sci_data2sig.c sci_gateway/c/sci_diffobjs.c \
+       sci_gateway/c/sci_duplicate.c sci_gateway/c/sci_end_scicosim.c \
+       sci_gateway/c/sci_ftree2.c sci_gateway/c/sci_ftree3.c \
+       sci_gateway/c/sci_ftree4.c sci_gateway/c/sci_getblocklabel.c \
        sci_gateway/c/sci_getscicosvars.c \
        sci_gateway/c/sci_haltscicos.c sci_gateway/c/sci_loadScicos.c \
        sci_gateway/c/sci_model2blk.c \
@@ -413,7 +414,8 @@ am__libsciscicos_la_SOURCES_DIST = sci_gateway/cpp/sci_scicos_log.cpp \
        sci_gateway/fortran/sci_f_vec2var.f
 am__objects_8 = sci_gateway/cpp/libsciscicos_la-sci_scicos_log.lo \
        sci_gateway/cpp/libsciscicos_la-sci_scicos_new.lo \
-       sci_gateway/cpp/libsciscicos_la-sci_scicos_setfield.lo
+       sci_gateway/cpp/libsciscicos_la-sci_scicos_setfield.lo \
+       sci_gateway/cpp/libsciscicos_la-sci_validvar.lo
 am__objects_9 = sci_gateway/c/libsciscicos_la-gw_scicos.lo \
        sci_gateway/c/libsciscicos_la-sci_buildouttb.lo \
        sci_gateway/c/libsciscicos_la-sci_callblk.lo \
@@ -992,7 +994,8 @@ NO_SCICOS_C_SOURCES = src/c/noscicos/noscicos.c
 GATEWAY_CXX_SOURCES = \
 sci_gateway/cpp/sci_scicos_log.cpp \
 sci_gateway/cpp/sci_scicos_new.cpp \
-sci_gateway/cpp/sci_scicos_setfield.cpp
+sci_gateway/cpp/sci_scicos_setfield.cpp \
+sci_gateway/cpp/sci_validvar.cpp
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_scicos.c \
 sci_gateway/c/sci_buildouttb.c \
@@ -1052,29 +1055,31 @@ libsciscicos_la_LDFLAGS = $(AM_LDFLAGS)
 @XCOS_FALSE@                   -I$(top_srcdir)/modules/scicos/includes/ \
 @XCOS_FALSE@                   $(AM_CPPFLAGS)
 
-@XCOS_TRUE@libsciscicos_algo_la_CPPFLAGS = -I$(srcdir)/includes/ \
-@XCOS_TRUE@                    -I$(srcdir)/src/c/ \
-@XCOS_TRUE@                    -I$(srcdir)/src/cpp/ \
-@XCOS_TRUE@                    -I$(srcdir)/src/scicos_sundials/include/ \
-@XCOS_TRUE@                    -I$(srcdir)/src/scicos_sundials/include/sundials/ \
-@XCOS_TRUE@                    -I$(srcdir)/src/scicos_sundials/src/ida/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/output_stream/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/dynamic_link/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/string/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/localization/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/scicos_blocks/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/action_binding/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/time/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/api_scilab/includes/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/ast/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/exps/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/operations/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/system_env/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/types/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/ast/includes/analysis/ \
-@XCOS_TRUE@                    -I$(top_srcdir)/modules/threads/includes/ \
-@XCOS_TRUE@                    $(EIGEN_CPPFLAGS) \
-@XCOS_TRUE@                    $(AM_CPPFLAGS)
+@XCOS_TRUE@libsciscicos_algo_la_CPPFLAGS = \
+@XCOS_TRUE@    -I$(srcdir)/includes/ \
+@XCOS_TRUE@    -I$(srcdir)/src/c/ \
+@XCOS_TRUE@    -I$(srcdir)/src/cpp/ \
+@XCOS_TRUE@    -I$(srcdir)/src/scicos_sundials/include/ \
+@XCOS_TRUE@    -I$(srcdir)/src/scicos_sundials/include/sundials/ \
+@XCOS_TRUE@    -I$(srcdir)/src/scicos_sundials/src/ida/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/output_stream/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/dynamic_link/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/string/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/localization/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/scicos_blocks/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/action_binding/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/time/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/api_scilab/includes/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/ast/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/exps/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/symbol/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/operations/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/system_env/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/types/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/ast/includes/analysis/ \
+@XCOS_TRUE@    -I$(top_srcdir)/modules/threads/includes/ \
+@XCOS_TRUE@    $(EIGEN_CPPFLAGS) \
+@XCOS_TRUE@    $(AM_CPPFLAGS)
 
 libsciscicos_cli_la_CPPFLAGS = $(libsciscicos_algo_la_CPPFLAGS)
 libsciscicos_la_CPPFLAGS = $(libsciscicos_algo_la_CPPFLAGS)
@@ -1599,6 +1604,9 @@ sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_new.lo:  \
 sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_setfield.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/$(am__dirstamp):
        @$(MKDIR_P) sci_gateway/c
        @: > sci_gateway/c/$(am__dirstamp)
@@ -1752,6 +1760,9 @@ sci_gateway/cpp/libsciscicos_la-sci_scicos_new.lo:  \
 sci_gateway/cpp/libsciscicos_la-sci_scicos_setfield.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciscicos_la-sci_validvar.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libsciscicos_la-gw_scicos.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -2119,9 +2130,11 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_scicos_log.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_scicos_new.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_scicos_setfield.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_validvar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_log.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_new.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_setfield.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_validvar.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_algo_la-MlistGetFieldNumber.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_algo_la-copyvarfromlistentry.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciscicos_algo_la-createblklist.Plo@am__quote@
@@ -3094,6 +3107,13 @@ sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_setfield.lo: sci_gateway/cpp/sci_
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_cli_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciscicos_cli_la-sci_scicos_setfield.lo `test -f 'sci_gateway/cpp/sci_scicos_setfield.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_scicos_setfield.cpp
 
+sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo: sci_gateway/cpp/sci_validvar.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_cli_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_validvar.Tpo -c -o sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo `test -f 'sci_gateway/cpp/sci_validvar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_validvar.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_validvar.Tpo sci_gateway/cpp/$(DEPDIR)/libsciscicos_cli_la-sci_validvar.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_validvar.cpp' object='sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_cli_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciscicos_cli_la-sci_validvar.lo `test -f 'sci_gateway/cpp/sci_validvar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_validvar.cpp
+
 sci_gateway/cpp/libsciscicos_la-sci_scicos_log.lo: sci_gateway/cpp/sci_scicos_log.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciscicos_la-sci_scicos_log.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_log.Tpo -c -o sci_gateway/cpp/libsciscicos_la-sci_scicos_log.lo `test -f 'sci_gateway/cpp/sci_scicos_log.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_scicos_log.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_log.Tpo sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_scicos_log.Plo
@@ -3115,6 +3135,13 @@ sci_gateway/cpp/libsciscicos_la-sci_scicos_setfield.lo: sci_gateway/cpp/sci_scic
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciscicos_la-sci_scicos_setfield.lo `test -f 'sci_gateway/cpp/sci_scicos_setfield.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_scicos_setfield.cpp
 
+sci_gateway/cpp/libsciscicos_la-sci_validvar.lo: sci_gateway/cpp/sci_validvar.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciscicos_la-sci_validvar.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_validvar.Tpo -c -o sci_gateway/cpp/libsciscicos_la-sci_validvar.lo `test -f 'sci_gateway/cpp/sci_validvar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_validvar.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_validvar.Tpo sci_gateway/cpp/$(DEPDIR)/libsciscicos_la-sci_validvar.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_validvar.cpp' object='sci_gateway/cpp/libsciscicos_la-sci_validvar.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciscicos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciscicos_la-sci_validvar.lo `test -f 'sci_gateway/cpp/sci_validvar.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_validvar.cpp
+
 .f.o:
        $(AM_V_F77)$(F77COMPILE) -c -o $@ $<
 
index 50e8090..4345ca3 100644 (file)
@@ -19,5 +19,6 @@
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_scicos_new, SCICOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_scicos_setfield, SCICOS_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_scicos_log, SCICOS_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_validvar, SCICOS_IMPEXP);
 
 #endif /* GW_SCICOS_HXX_ */
diff --git a/scilab/modules/scicos/macros/scicos_scicos/validvar.sci b/scilab/modules/scicos/macros/scicos_scicos/validvar.sci
deleted file mode 100644 (file)
index 6301dff..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-//  Scicos
-//
-//  Copyright (C) INRIA - Serge Steer <serge.steer@inria.fr>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See the file ../license.txt
-//
-
-function r=validvar(s)
-    //Serge Steer, 08/10/2007
-    //Alan restricted validvar for operation, 29/03/08
-
-    //check if the string s is a valid identifier
-    s=stripblanks(s)
-    r=%f
-    if size(s,"*")<>1 then return, end
-    if s=="" then return, end
-
-    //create a function with s as single statement
-    if execstr("deff(''foo'',s)","errcatch") then return, end
-    t=macr2tree(foo) //syntax tree
-    instr=t.statements(2) //ignore leading and trailing EOL
-
-    //lhs should be "ans"
-    if size(instr.lhs)<>1 then return,end
-    if instr.lhs(1).name<>"ans" then return,end
-
-    //expression should be just a reference to s
-    if typeof(instr.expression)<>"operation" then return, end
-    if instr.expression.operator<>"ext" then return,end
-    if size(instr.expression.operands)<>1 then return,end
-    if instr.expression.operands(1).name<>s  then return,end
-
-    r=%t
-endfunction
diff --git a/scilab/modules/scicos/sci_gateway/cpp/sci_validvar.cpp b/scilab/modules/scicos/sci_gateway/cpp/sci_validvar.cpp
new file mode 100644 (file)
index 0000000..0f6f4fa
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2014 - 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 <string>
+
+#include "gw_scicos.hxx"
+#include "context.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "bool.hxx"
+
+extern "C"
+{
+#include "Scierror.h"
+#include "localization.h"
+}
+
+types::Function::ReturnValue sci_validvar(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    int iValid = 0;
+    if (in.size() != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "validvar", 1);
+        return types::Function::Error;
+    }
+
+    if (_iRetCount != 1)
+    {
+        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "validvar", 1);
+        return types::Function::Error;
+    }
+
+    if (in[0]->isString() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "validvar", 1);
+        return types::Function::Error;
+    }
+
+    types::String* pS = in[0]->getAs<types::String>();
+
+    if (pS->isScalar() == false)
+    {
+        Scierror(202, _("%s: Wrong size for argument #%d: A string expected.\n"), "validvar", 1);
+        return types::Function::Error;
+    }
+
+
+    if (symbol::Context::getInstance()->isValidVariableName(pS->get(0)))
+    {
+        iValid = 1;
+    }
+
+    out.push_back(new types::Bool(iValid));
+    return types::Function::OK;
+}
\ No newline at end of file
index 56cc70b..4bac073 100644 (file)
@@ -55,4 +55,5 @@
     <gateway type="1" name="sci_scicos_log" function="scicos_log"/>
     <gateway type="1" name="sci_scicos_new" function="scicos_new"/>
     <gateway type="1" name="sci_scicos_setfield" function="scicos_setfield"/>
+    <gateway type="1" name="sci_validvar" function="validvar"/>
 </module>
index 7e2dfb9..c01dc90 100644 (file)
@@ -253,6 +253,7 @@ lib /DEF:"$(ProjectDir)differential_equations_f_Import.def" /SUBSYSTEM:WINDOWS /
     <ClCompile Include="..\..\sci_gateway\cpp\sci_scicos_log.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_scicos_new.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_scicos_setfield.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_validvar.cpp" />
     <ClCompile Include="..\cpp\Controller.cpp" />
     <ClCompile Include="..\cpp\LoggerView.cpp" />
     <ClCompile Include="..\cpp\Model.cpp" />
@@ -435,4 +436,4 @@ lib /DEF:"$(ProjectDir)differential_equations_f_Import.def" /SUBSYSTEM:WINDOWS /
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 822724f..7d86d71 100644 (file)
     <ClCompile Include="..\cpp\view_scilab\ParamsAdapter.cpp">
       <Filter>Source Files\MVC\view_scilab</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_validvar.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="copyvarfromlistentry.h">
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/scilab/modules/scicos/tests/unit_tests/validvar.dia.ref b/scilab/modules/scicos/tests/unit_tests/validvar.dia.ref
new file mode 100644 (file)
index 0000000..0279bf9
--- /dev/null
@@ -0,0 +1,17 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+loadXcosLibs();
+FORBIDDEN_CHARS = [" ","*","/","\",".",",",";",":","^","@",">","<","=","+","-","&","|","(",")","~","\n","\t","''",""""];
+for i = 1:size(FORBIDDEN_CHARS, "*")
+    assert_checkfalse(validvar("test" + FORBIDDEN_CHARS(i) + "test"));
+end
+FORBIDDEN_CHARS = ["0","1","2","3","4","5","6","7","8","9"];
+for i = 1:size(FORBIDDEN_CHARS, "*")
+    assert_checkfalse(validvar(FORBIDDEN_CHARS(i) + "test"));
+    assert_checktrue(validvar("test" + FORBIDDEN_CHARS(i)));
+end
diff --git a/scilab/modules/scicos/tests/unit_tests/validvar.tst b/scilab/modules/scicos/tests/unit_tests/validvar.tst
new file mode 100644 (file)
index 0000000..519d3ed
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+loadXcosLibs();
+
+FORBIDDEN_CHARS = [" ","*","/","\",".",",",";",":","^","@",">","<","=","+","-","&","|","(",")","~","\n","\t","''",""""];
+for i = 1:size(FORBIDDEN_CHARS, "*")
+    assert_checkfalse(validvar("test" + FORBIDDEN_CHARS(i) + "test"));
+end
+
+FORBIDDEN_CHARS = ["0","1","2","3","4","5","6","7","8","9"];
+
+for i = 1:size(FORBIDDEN_CHARS, "*")
+    assert_checkfalse(validvar(FORBIDDEN_CHARS(i) + "test"));
+    assert_checktrue(validvar("test" + FORBIDDEN_CHARS(i)));
+end