add library variables 54/14454/3
Antoine ELIAS [Thu, 24 Apr 2014 09:30:01 +0000 (11:30 +0200)]
Change-Id: I60c101d0c0afdfa85689003997f1ad2acf88bdf0

40 files changed:
scilab/etc/scilab.start
scilab/modules/ast/includes/runvisitor.hxx
scilab/modules/core/sci_gateway/cpp/sci_pause.cpp
scilab/modules/core/src/cpp/getfunctionsname.cpp
scilab/modules/core/src/cpp/getmacrosname.cpp
scilab/modules/core/src/cpp/getvariablesname.cpp
scilab/modules/functions/sci_gateway/cpp/sci_functionlist.cpp
scilab/modules/io/Makefile.am
scilab/modules/io/Makefile.in
scilab/modules/io/includes/io_gw.hxx
scilab/modules/io/sci_gateway/cpp/sci_genlib.cpp
scilab/modules/io/sci_gateway/cpp/sci_lib.cpp [new file with mode: 0644]
scilab/modules/io/sci_gateway/cpp/sci_load.cpp
scilab/modules/io/src/cpp/io_gw.cpp
scilab/modules/io/src/cpp/io_gw.vcxproj
scilab/modules/io/src/cpp/io_gw.vcxproj.filters
scilab/modules/io/src/cpp/loadlib.cpp [new file with mode: 0644]
scilab/modules/io/src/cpp/loadlib.hxx [new file with mode: 0644]
scilab/modules/symbol/Makefile.am
scilab/modules/symbol/Makefile.in
scilab/modules/symbol/includes/context.hxx
scilab/modules/symbol/includes/libraries.hxx [new file with mode: 0644]
scilab/modules/symbol/includes/scope.hxx
scilab/modules/symbol/includes/variables.hxx
scilab/modules/symbol/src/cpp/context.cpp
scilab/modules/symbol/src/cpp/libraries.cpp [new file with mode: 0644]
scilab/modules/symbol/src/cpp/scope.cpp
scilab/modules/symbol/src/cpp/variables.cpp
scilab/modules/symbol/symbol.vcxproj
scilab/modules/symbol/symbol.vcxproj.filters
scilab/modules/types/Makefile.am
scilab/modules/types/Makefile.in
scilab/modules/types/includes/internal.hxx
scilab/modules/types/includes/library.hxx [new file with mode: 0644]
scilab/modules/types/sci_gateway/cpp/sci_inspectorGetFunctionList.cpp
scilab/modules/types/src/cpp/library.cpp [new file with mode: 0644]
scilab/modules/types/tests/unit_tests/library.dia.ref [new file with mode: 0644]
scilab/modules/types/tests/unit_tests/library.tst [new file with mode: 0644]
scilab/modules/types/types.vcxproj
scilab/modules/types/types.vcxproj.filters

index 1594f8e..d922392 100644 (file)
@@ -14,7 +14,7 @@ mode(-1);  // silent execution mode
 
 // clean database when restarted ======================================
 //predef("clear"); //unprotect all variables
-clear  // erase all variables
+clear;  // erase all variables
 clearglobal();
 
 %tk = (with_module("tclsci") & getscilabmode() <> "NWNI");
index 30d20a6..c7e8857 100644 (file)
@@ -486,7 +486,14 @@ public :
             throw ScilabError(szError, 999, e.location_get());
         }
 
-        if (result_get() != NULL && result_get()->isStruct())
+        if (result_get() == NULL)
+        {
+            wchar_t szError[bsiz];
+            os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n"));
+            throw ScilabError(szError, 999, e.location_get());
+        }
+
+        if (result_get()->isStruct())
         {
             InternalType* pTemp = result_get();
             result_set(NULL);
@@ -514,7 +521,7 @@ public :
                 throw ScilabError(szError, 999, e.tail_get()->location_get());
             }
         }
-        else if (result_get() != NULL && (result_get()->isMList() || result_get()->isTList()))
+        else if (result_get()->isMList() || result_get()->isTList())
         {
             TList* psValue = ((InternalType*)result_get())->getAs<MList>();
 
@@ -569,13 +576,13 @@ public :
                 pS->DecreaseRef();
             }
         }
-        else if (result_get() != NULL && result_get()->isHandle())
+        else if (result_get()->isHandle())
         {
             typed_list in;
             typed_list out;
             optional_list opt;
 
-            String* pField = new String(psvRightMember->name_get().name_get().c_str());
+            String* pField = new String(wstField.c_str());
             in.push_back(pField);
             in.push_back(result_get());
 
@@ -586,6 +593,20 @@ public :
                 result_set(out[0]);
             }
         }
+        else if (result_get()->isLibrary())
+        {
+            Library* pLib = ((InternalType*)result_get())->getAs<Library>();
+
+            InternalType* pIT = pLib->get(wstField);
+            if (pIT == NULL)
+            {
+                wchar_t szError[bsiz];
+                os_swprintf(szError, bsiz, _W("Unknown macro %ls in library.\n"), wstField.c_str());
+                throw ScilabError(szError, 999, e.tail_get()->location_get());
+            }
+
+            result_set(pIT);
+        }
         else
         {
             wchar_t szError[bsiz];
index 5bd6699..2283fc5 100644 (file)
@@ -39,6 +39,10 @@ types::Function::ReturnValue sci_pause(types::typed_list &in, int _iRetCount, ty
     Runner::UnlockPrompt();
 
     ThreadId* pThread = ConfigVariable::getLastRunningThread();
+    if (pThread == NULL)
+    {
+        return types::Function::OK;
+    }
 
     //return to console so change mode to 2
     int iOldMode = ConfigVariable::getPromptMode();
index bece74d..cc11fb8 100644 (file)
@@ -19,18 +19,19 @@ extern "C" {
 /*----------------------------------------------------------------------------------*/
 char **getFunctionsName(int *sizearray)
 {
-    std::list<std::wstring> plMacrosList = symbol::Context::getInstance()->getFunctionsName();
+    std::list<std::wstring>* plMacrosList = symbol::Context::getInstance()->getFunctionsName();
     std::list<std::wstring>::iterator it;
-    *sizearray = (int)plMacrosList.size();
+    *sizearray = (int)plMacrosList->size();
     char** functions = (char**)MALLOC(*sizearray * sizeof(char*));
 
-    plMacrosList.sort();
+    plMacrosList->sort();
 
     int i = 0;
-    for (it = plMacrosList.begin(); it != plMacrosList.end(); it++, i++)
+    for (it = plMacrosList->begin(); it != plMacrosList->end(); ++it, i++)
     {
         functions[i] = wide_string_to_UTF8((*it).c_str());
     }
 
+    delete plMacrosList;
     return functions;
 }
index 11b1857..d2bbf99 100644 (file)
@@ -19,19 +19,25 @@ extern "C" {
 /*----------------------------------------------------------------------------------*/
 char **getMacrosName(int *sizearray)
 {
-    std::list<std::wstring> plMacrosList = symbol::Context::getInstance()->getMacrosName();
+    std::list<std::wstring>* plMacrosList = symbol::Context::getInstance()->getMacrosName();
     std::list<std::wstring>::iterator it;
-    *sizearray = (int)plMacrosList.size();
+
+    //sort list
+    plMacrosList->sort();
+    //same names could come from libraries AND context
+    plMacrosList->unique();
+
+    *sizearray = (int)plMacrosList->size();
     char** macros = (char**)MALLOC(*sizearray * sizeof(char*));
 
-    plMacrosList.sort();
 
     int i = 0;
-    for (it = plMacrosList.begin(); it != plMacrosList.end(); it++, i++)
+    for (it = plMacrosList->begin(); it != plMacrosList->end(); ++it, i++)
     {
         macros[i] = wide_string_to_UTF8((*it).c_str());
     }
 
+    delete plMacrosList;
     return macros;
 }
 /*----------------------------------------------------------------------------------*/
index 59bafc6..7289df3 100644 (file)
@@ -19,22 +19,23 @@ extern "C" {
 /*----------------------------------------------------------------------------------*/
 char **getVariablesName(int *sizearray, BOOL sorted)
 {
-    std::list<std::wstring> plVarNames = symbol::Context::getInstance()->getVarsName();
+    std::list<std::wstring>* plVarNames = symbol::Context::getInstance()->getVarsName();
     std::list<std::wstring>::iterator it;
-    *sizearray = (int)plVarNames.size();
+    *sizearray = (int)plVarNames->size();
     char** variables = (char**)MALLOC(*sizearray * sizeof(char*));
 
     if (sorted)
     {
-        plVarNames.sort();
+        plVarNames->sort();
     }
 
     int i = 0;
-    for (it = plVarNames.begin(); it != plVarNames.end(); it++, i++)
+    for (it = plVarNames->begin(); it != plVarNames->end(); ++it, i++)
     {
         variables[i] = wide_string_to_UTF8((*it).c_str());
     }
 
+    delete plVarNames;
     return variables;
 }
 
index e508927..a15db66 100644 (file)
@@ -52,17 +52,18 @@ Function::ReturnValue sci_funclist(types::typed_list &in, int _iRetCount, types:
     }
 
     wstring libName(pstLibName);
-    std::list<symbol::Symbol> FuncList = pContext->getFunctionList(libName, false);
+    std::list<symbol::Symbol>* FuncList = pContext->getFunctionList(libName, false);
 
-    String *pS = new String((int)FuncList.size(), 1);
+    String *pS = new String((int)FuncList->size(), 1);
 
     std::list<symbol::Symbol>::iterator it;
     int i = 0;
-    for (it = FuncList.begin() ; it != FuncList.end() ; it++)
+    for (it = FuncList->begin() ; it != FuncList->end() ; ++it)
     {
         pS->set(i++, 0, it->name_get().c_str());
     }
 
+    delete FuncList;
     out.push_back(pS);
     return Function::OK;
 }
index 50fb8a3..68c8617 100644 (file)
@@ -10,7 +10,10 @@ src/c/systemc.c \
 src/c/getenvc.c \
 src/c/v2cuniterror.c
 
-IO_CPP_SOURCES = src/cpp/io_gw.cpp
+IO_CPP_SOURCES = \
+src/cpp/io_gw.cpp \
+src/cpp/loadlib.cpp
+
 
 GATEWAY_C_SOURCES = sci_gateway/c/sci_read4b.c \
 sci_gateway/c/sci_getio.c \
@@ -26,15 +29,18 @@ sci_gateway/c/sci_write4b.c \
 sci_gateway/c/sci_save.c
 
 GATEWAY_CPP_SOURCES = \
-       sci_gateway/cpp/sci_genlib.cpp \
-       sci_gateway/cpp/sci_load.cpp \
-       sci_gateway/cpp/sci_file.cpp \
-       sci_gateway/cpp/sci_host.cpp \
-       sci_gateway/cpp/sci_unix.cpp
+sci_gateway/cpp/sci_genlib.cpp \
+sci_gateway/cpp/sci_load.cpp \
+sci_gateway/cpp/sci_file.cpp \
+sci_gateway/cpp/sci_host.cpp \
+sci_gateway/cpp/sci_unix.cpp \
+sci_gateway/cpp/sci_lib.cpp
+
 
 libsciio_la_CPPFLAGS = \
     -I$(srcdir)/includes/ \
     -I$(srcdir)/src/c/ \
+    -I$(srcdir)/src/cpp/ \
     -I$(top_srcdir)/modules/core/includes/ \
     -I$(top_srcdir)/modules/api_scilab/includes/ \
     -I$(top_srcdir)/modules/types/includes/ \
index f3998b0..ccb0c9e 100644 (file)
@@ -168,7 +168,8 @@ am__objects_1 = src/c/libsciio_algo_la-getpidc.lo \
        src/c/libsciio_algo_la-systemc.lo \
        src/c/libsciio_algo_la-getenvc.lo \
        src/c/libsciio_algo_la-v2cuniterror.lo
-am__objects_2 = src/cpp/libsciio_algo_la-io_gw.lo
+am__objects_2 = src/cpp/libsciio_algo_la-io_gw.lo \
+       src/cpp/libsciio_algo_la-loadlib.lo
 am_libsciio_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libsciio_algo_la_OBJECTS = $(am_libsciio_algo_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -194,7 +195,8 @@ am__objects_4 = sci_gateway/cpp/libsciio_la-sci_genlib.lo \
        sci_gateway/cpp/libsciio_la-sci_load.lo \
        sci_gateway/cpp/libsciio_la-sci_file.lo \
        sci_gateway/cpp/libsciio_la-sci_host.lo \
-       sci_gateway/cpp/libsciio_la-sci_unix.lo
+       sci_gateway/cpp/libsciio_la-sci_unix.lo \
+       sci_gateway/cpp/libsciio_la-sci_lib.lo
 am_libsciio_la_OBJECTS = $(am__objects_3) $(am__objects_4)
 libsciio_la_OBJECTS = $(am_libsciio_la_OBJECTS)
 @MAINTAINER_MODE_FALSE@am_libsciio_la_rpath =
@@ -569,7 +571,10 @@ src/c/systemc.c \
 src/c/getenvc.c \
 src/c/v2cuniterror.c
 
-IO_CPP_SOURCES = src/cpp/io_gw.cpp
+IO_CPP_SOURCES = \
+src/cpp/io_gw.cpp \
+src/cpp/loadlib.cpp
+
 GATEWAY_C_SOURCES = sci_gateway/c/sci_read4b.c \
 sci_gateway/c/sci_getio.c \
 sci_gateway/c/sci_readb.c \
@@ -584,15 +589,17 @@ sci_gateway/c/sci_write4b.c \
 sci_gateway/c/sci_save.c
 
 GATEWAY_CPP_SOURCES = \
-       sci_gateway/cpp/sci_genlib.cpp \
-       sci_gateway/cpp/sci_load.cpp \
-       sci_gateway/cpp/sci_file.cpp \
-       sci_gateway/cpp/sci_host.cpp \
-       sci_gateway/cpp/sci_unix.cpp
+sci_gateway/cpp/sci_genlib.cpp \
+sci_gateway/cpp/sci_load.cpp \
+sci_gateway/cpp/sci_file.cpp \
+sci_gateway/cpp/sci_host.cpp \
+sci_gateway/cpp/sci_unix.cpp \
+sci_gateway/cpp/sci_lib.cpp
 
 libsciio_la_CPPFLAGS = \
     -I$(srcdir)/includes/ \
     -I$(srcdir)/src/c/ \
+    -I$(srcdir)/src/cpp/ \
     -I$(top_srcdir)/modules/core/includes/ \
     -I$(top_srcdir)/modules/api_scilab/includes/ \
     -I$(top_srcdir)/modules/types/includes/ \
@@ -817,6 +824,8 @@ src/cpp/$(DEPDIR)/$(am__dirstamp):
        @: > src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libsciio_algo_la-io_gw.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libsciio_algo_la-loadlib.lo: src/cpp/$(am__dirstamp) \
+       src/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libsciio-algo.la: $(libsciio_algo_la_OBJECTS) $(libsciio_algo_la_DEPENDENCIES) $(EXTRA_libsciio_algo_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libsciio_algo_la_rpath) $(libsciio_algo_la_OBJECTS) $(libsciio_algo_la_LIBADD) $(LIBS)
@@ -877,6 +886,9 @@ sci_gateway/cpp/libsciio_la-sci_host.lo:  \
 sci_gateway/cpp/libsciio_la-sci_unix.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libsciio_la-sci_lib.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libsciio.la: $(libsciio_la_OBJECTS) $(libsciio_la_DEPENDENCIES) $(EXTRA_libsciio_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) $(am_libsciio_la_rpath) $(libsciio_la_OBJECTS) $(libsciio_la_LIBADD) $(LIBS)
@@ -910,6 +922,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_file.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_genlib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_host.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_load.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_unix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-getenvc.Plo@am__quote@
@@ -918,6 +931,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-systemc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libsciio_algo_la-v2cuniterror.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciio_algo_la-io_gw.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciio_algo_la-loadlib.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -1093,6 +1107,13 @@ src/cpp/libsciio_algo_la-io_gw.lo: src/cpp/io_gw.cpp
 @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) $(libsciio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciio_algo_la-io_gw.lo `test -f 'src/cpp/io_gw.cpp' || echo '$(srcdir)/'`src/cpp/io_gw.cpp
 
+src/cpp/libsciio_algo_la-loadlib.lo: src/cpp/loadlib.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libsciio_algo_la-loadlib.lo -MD -MP -MF src/cpp/$(DEPDIR)/libsciio_algo_la-loadlib.Tpo -c -o src/cpp/libsciio_algo_la-loadlib.lo `test -f 'src/cpp/loadlib.cpp' || echo '$(srcdir)/'`src/cpp/loadlib.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libsciio_algo_la-loadlib.Tpo src/cpp/$(DEPDIR)/libsciio_algo_la-loadlib.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/loadlib.cpp' object='src/cpp/libsciio_algo_la-loadlib.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) $(libsciio_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libsciio_algo_la-loadlib.lo `test -f 'src/cpp/loadlib.cpp' || echo '$(srcdir)/'`src/cpp/loadlib.cpp
+
 sci_gateway/cpp/libsciio_la-sci_genlib.lo: sci_gateway/cpp/sci_genlib.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciio_la-sci_genlib.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_genlib.Tpo -c -o sci_gateway/cpp/libsciio_la-sci_genlib.lo `test -f 'sci_gateway/cpp/sci_genlib.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_genlib.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_genlib.Tpo sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_genlib.Plo
@@ -1128,6 +1149,13 @@ sci_gateway/cpp/libsciio_la-sci_unix.lo: sci_gateway/cpp/sci_unix.cpp
 @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) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciio_la-sci_unix.lo `test -f 'sci_gateway/cpp/sci_unix.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_unix.cpp
 
+sci_gateway/cpp/libsciio_la-sci_lib.lo: sci_gateway/cpp/sci_lib.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libsciio_la-sci_lib.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Tpo -c -o sci_gateway/cpp/libsciio_la-sci_lib.lo `test -f 'sci_gateway/cpp/sci_lib.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_lib.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Tpo sci_gateway/cpp/$(DEPDIR)/libsciio_la-sci_lib.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_lib.cpp' object='sci_gateway/cpp/libsciio_la-sci_lib.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) $(libsciio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libsciio_la-sci_lib.lo `test -f 'sci_gateway/cpp/sci_lib.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_lib.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index d8e6b5f..3f8f7f0 100644 (file)
@@ -36,3 +36,4 @@ CPP_GATEWAY_PROTOTYPE(sci_genlib);
 CPP_GATEWAY_PROTOTYPE(sci_file);
 CPP_GATEWAY_PROTOTYPE(sci_host);
 CPP_GATEWAY_PROTOTYPE(sci_unix);
+CPP_GATEWAY_PROTOTYPE(sci_lib);
index 5732f55..4d275ca 100644 (file)
@@ -152,6 +152,7 @@ Function::ReturnValue sci_genlib(types::typed_list &in, int _iRetCount, types::t
 
     if (pstPath)
     {
+        types::Library* pLib = new types::Library(pstParsePath);
         for (int k = 0 ; k < iNbFile ; k++)
         {
             //version with direct parsing
@@ -182,15 +183,17 @@ Function::ReturnValue sci_genlib(types::typed_list &in, int _iRetCount, types::t
                         scilabWriteW(pstVerbose);
                     }
 
-                    symbol::Context::getInstance()->AddMacroFile(new MacroFile(pFD->name_get().name_get(), stFullPath, pstLibName));
-
+                    pLib->add(pFD->name_get().name_get(), new MacroFile(pFD->name_get().name_get(), stFullPath, pstLibName));
                 }
             }
 
             delete parser.getTree();
         }
+
+        symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), *pLib);
     }
 
+
     out.push_back(new Bool(1));
     FREE(pstParsePath);
     closeXMLFile(pWriter);
diff --git a/scilab/modules/io/sci_gateway/cpp/sci_lib.cpp b/scilab/modules/io/sci_gateway/cpp/sci_lib.cpp
new file mode 100644 (file)
index 0000000..bb7e8da
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+* 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.h>
+#include "function.hxx"
+#include "io_gw.hxx"
+#include "string.hxx"
+#include "library.hxx"
+#include "loadlib.hxx"
+
+extern "C"
+{
+#include "MALLOC.h"
+#include "expandPathVariable.h"
+}
+
+using namespace types;
+
+/*--------------------------------------------------------------------------*/
+Function::ReturnValue sci_lib(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    int iXMLFileLen = 0;
+    if (in.size() != 1)
+    {
+        return Function::Error;
+    }
+
+    InternalType* pIT = in[0];
+
+    if (pIT->isString() == false)
+    {
+        return Function::Error;
+    }
+
+    String *pS = pIT->getAs<types::String>();
+
+    if (pS->isScalar() == false)
+    {
+        return Function::Error;
+    }
+
+    wchar_t* pstPath = pS->get(0);
+    wchar_t* pwstPath = expandPathVariableW(pstPath);
+    Library* lib = loadlib(pwstPath, false, false);
+    FREE(pwstPath);
+
+    if (lib == NULL)
+    {
+        return Function::Error;
+    }
+
+
+    out.push_back(lib);
+    return Function::OK;
+}
+
+
+/*--------------------------------------------------------------------------*/
index 99bb780..a94e5fe 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2006 - INRIA - Allan CORNET
+* 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
 *
 */
 
-#ifdef _MSC_VER
-#pragma warning(disable : 4996) //It's not beautifull but that works !
-#endif
-
-#define DEFAULT_ENCODING "UTF-8"
-
-#define FILE_SEPARATOR "/"
-
 #include <string.h>
-#include "funcmanager.hxx"
-#include "context.hxx"
+#include "function.hxx"
 #include "io_gw.hxx"
-#include "setenvvar.hxx"
 #include "string.hxx"
+#include "library.hxx"
+#include "loadlib.hxx"
 
 extern "C"
 {
 #include "MALLOC.h"
-#include "os_strdup.h"
-#ifndef _MSC_VER
-#include "stricmp.h"
-#endif
 #include "expandPathVariable.h"
-#include "PATH_MAX.h"
 }
 
-//XML API
-#include <libxml/xpath.h>
-#include <libxml/xmlreader.h>
-
-char *GetXmlFileEncoding(string _filename);
-bool getMacros(wstring _stXMLFile);
-
 using namespace types;
+
 /*--------------------------------------------------------------------------*/
 Function::ReturnValue sci_load(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
     int iXMLFileLen = 0;
-    wchar_t* pstXMLFile = NULL;
-
     if (in.size() != 1)
     {
         return Function::Error;
@@ -69,168 +48,18 @@ Function::ReturnValue sci_load(types::typed_list &in, int _iRetCount, types::typ
         return Function::Error;
     }
 
-    wchar_t* pstFile = pS->get(0);
-    pstXMLFile = expandPathVariableW(pstFile);
+    wchar_t* pstPath = pS->get(0);
+    wchar_t* pwstPath = expandPathVariableW(pstPath);
+    Library* lib = loadlib(pwstPath);
+    FREE(pwstPath);
 
-    if (getMacros(pstXMLFile) == false)
+    if (lib == NULL)
     {
         return Function::Error;
     }
-    return Function::OK;
-}
-
-bool getMacros(wstring _stXMLFile)
-{
-    symbol::Context* pContext = symbol::Context::getInstance();
-
-    char* pstXMLFile = wide_string_to_UTF8(_stXMLFile.c_str());
-    char *encoding = GetXmlFileEncoding(pstXMLFile);
-
-    /* Don't care about line return / empty line */
-    xmlKeepBlanksDefault(0);
-    /* check if the XML file has been encoded with utf8 (unicode) or not */
-    if (stricmp("utf-8", encoding) == 0)
-    {
-        xmlDocPtr doc;
-        xmlXPathContextPtr xpathCtxt    = NULL;
-        xmlXPathObjectPtr xpathObj      = NULL;
-        wchar_t* pstName                = NULL;
-        wchar_t* pstLibName             = NULL;
-        wchar_t* pstFileName            = NULL;
-        wchar_t* pstLibNameW            = NULL;
-
-        int indice                      = 0;
-
-        doc = xmlParseFile(pstXMLFile);
-
-        if (doc == NULL)
-        {
-            std::cout << "Error: Could not parse file " << pstXMLFile << std::endl;
-            if (encoding)
-            {
-                free(encoding);
-                encoding = NULL;
-            }
-            return false;
-        }
-
-        xpathCtxt = xmlXPathNewContext(doc);
-        xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
-        if (xpathObj && xpathObj->nodesetval->nodeMax)
-        {
-            xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
-            if (xmlStrEqual (attrib->name, (const xmlChar*)"name"))
-            {
-                /* we found the tag name */
-                const char *str = (const char*)attrib->children->content;
-                pstLibName = to_wide_string(str);
-            }
-            else
-            {
-                return false;
-            }
-        }
-
-        xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
-        if (xpathObj && xpathObj->nodesetval->nodeMax)
-        {
-            /* the Xpath has been understood and there are node */
-            for (int   i = 0 ; i < xpathObj->nodesetval->nodeNr ; i++)
-            {
 
-                xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
-                /* Get the properties of <module>  */
-                while (attrib != NULL)
-                {
-                    /* loop until when have read all the attributes */
-                    if (xmlStrEqual (attrib->name, (const xmlChar*)"name"))
-                    {
-                        /* we found the tag name */
-                        const char *str = (const char*)attrib->children->content;
-                        pstName = to_wide_string(str);
-                    }
-                    else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
-                    {
-                        /* we found the tag activate */
-                        const char *str = (const char*)attrib->children->content;
-                        pstFileName = to_wide_string(str);
-                    }
-                    attrib = attrib->next;
-                }
-
-                if (pstName && pstFileName)
-                {
-                    size_t iPos = _stXMLFile.rfind(DIR_SEPARATORW);
-                    wstring stFilename = _stXMLFile.substr(0, iPos + 1) + pstFileName;
-                    pContext->AddMacroFile(new MacroFile(pstName, stFilename, pstLibName));
-                }
-                else
-                {
-                    std::cout << pstName << " module not found." << std::endl;
-                }
-
-                if (pstName)
-                {
-                    FREE(pstName);
-                    pstName = NULL;
-                }
-
-                if (pstFileName)
-                {
-                    FREE(pstFileName);
-                    pstFileName = NULL;
-                }
-            }
-        }
-
-        if (xpathObj)
-        {
-            xmlXPathFreeObject(xpathObj);
-        }
-        if (xpathCtxt)
-        {
-            xmlXPathFreeContext(xpathCtxt);
-        }
-        xmlFreeDoc (doc);
-    }
-    else
-    {
-        std::wcout << "Error: Not a valid module file " << pstXMLFile << " (encoding not 'utf-8') Encoding '" << encoding << "' found." << std::endl;
-    }
-    if (encoding)
-    {
-        free(encoding);
-        encoding = NULL;
-    }
-
-    FREE(pstXMLFile);
-    return true;
+    return Function::OK;
 }
 
-char *GetXmlFileEncoding(string _filename)
-{
-    char *encoding = NULL;
-    xmlDocPtr doc = NULL;
-
-    /* default */
-    encoding = os_strdup(DEFAULT_ENCODING);
-
-    doc = xmlParseFile(_filename.c_str());
-    if (doc)
-    {
-        if (doc->encoding)
-        {
-            if (encoding)
-            {
-                free(encoding);
-                encoding = NULL;
-            }
-            encoding = os_strdup((char*)doc->encoding);
-        }
-    }
-
-    xmlFreeDoc(doc);
-    return encoding;
-}
 
 /*--------------------------------------------------------------------------*/
index cc1f95a..ffb28f8 100644 (file)
@@ -31,5 +31,6 @@ int IoModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"unix", &sci_unix, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"getenv", &sci_getenv, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"setenv", &sci_setenv, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"lib", &sci_lib, MODULE_NAME));
     return 1;
 }
index 2e88778..5c3efca 100644 (file)
@@ -80,7 +80,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../includes;../../src/cpp;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;IO_GW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
     </Midl>
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../includes;../../src/cpp;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;IO_GW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../includes;../../src/cpp;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;IO_GW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>../../includes;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../includes;../../src/cpp;../../../functions_manager/includes;../../../types/includes;../../../symbol/includes;../../../ast/includes;../../../elementary_functions/includes;../../../core/includes;../../../operations/includes;../../../api_scilab/includes;../../../../libs/libxml2;../../../fileio/includes;../../../system_env/includes;../../../parse/includes;../../../output_stream/includes;../../../localization/includes;../../../../libs/intl;../../../string/includes;../../../threads/includes;../../src/c;../../../dynamic_link/includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;IO_GW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
     </PreLinkEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_lib.cpp" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getenv.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getio.c" />
     <ClCompile Include="..\..\sci_gateway\c\sci_getpid.c" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_host.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_load.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_unix.cpp" />
+    <ClCompile Include="loadlib.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_io_gw.h" />
     <ClInclude Include="..\..\includes\io_gw.hxx" />
+    <ClInclude Include="loadlib.hxx" />
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\..\..\bin\blasplus.lib" />
index 59bb100..c5c627d 100644 (file)
     <ClCompile Include="..\..\sci_gateway\c\sci_write4b.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_lib.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="loadlib.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_io_gw.h">
@@ -77,6 +83,9 @@
     <ClInclude Include="..\..\includes\io_gw.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="loadlib.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\..\..\bin\blasplus.lib" />
diff --git a/scilab/modules/io/src/cpp/loadlib.cpp b/scilab/modules/io/src/cpp/loadlib.cpp
new file mode 100644 (file)
index 0000000..38596ee
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+* 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 "configvariable.hxx"
+#include "context.hxx"
+#include "loadlib.hxx"
+
+extern "C"
+{
+#include "MALLOC.h"
+#include "stricmp.h"
+#include "os_strdup.h"
+#include "expandPathVariable.h"
+#include "PATH_MAX.h"
+#include <libxml/xpath.h>
+#include <libxml/xmlreader.h>
+}
+
+#define DEFAULT_ENCODING "UTF-8"
+
+static char *GetXmlFileEncoding(string _filename);
+
+types::Library* loadlib(std::wstring _wstXML, bool _isFile, bool _bAddInContext)
+{
+    types::Library* lib = NULL;
+
+    wstring wstFile(_wstXML);
+    wstring wstPath(_wstXML);
+
+    if (_isFile)
+    {
+        size_t pos = wstPath.find_last_of(L"/\\");
+        wstPath = wstPath.substr(0, pos);
+    }
+    else
+    {
+        if (wstFile.empty() == false && *wstFile.rbegin() != DIR_SEPARATORW[0])
+        {
+            wstFile += DIR_SEPARATORW;
+        }
+
+        wstFile += L"lib";
+    }
+
+    char* pstFile = wide_string_to_UTF8(wstFile.c_str());
+    char *encoding = GetXmlFileEncoding(pstFile);
+
+    /* Don't care about line return / empty line */
+    xmlKeepBlanksDefault(0);
+    /* check if the XML file has been encoded with utf8 (unicode) or not */
+    if (stricmp("utf-8", encoding))
+    {
+        std::wcout << "Error: Not a valid module file " << pstFile << " (encoding not 'utf-8') Encoding '" << encoding << "' found." << std::endl;
+        FREE(pstFile);
+        free(encoding);
+        return NULL;
+    }
+
+    xmlDocPtr doc;
+    xmlXPathContextPtr xpathCtxt    = NULL;
+    xmlXPathObjectPtr xpathObj      = NULL;
+    wchar_t* pstName                = NULL;
+    wchar_t* pstLibName             = NULL;
+    wchar_t* pstFileName            = NULL;
+
+    free(encoding);
+
+    doc = xmlParseFile(pstFile);
+
+    if (doc == NULL)
+    {
+        std::cout << "Error: Could not parse file " << pstFile << std::endl;
+        FREE(pstFile);
+        return NULL;
+    }
+
+    FREE(pstFile);
+
+    lib = new types::Library(wstPath);
+
+    xpathCtxt = xmlXPathNewContext(doc);
+    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib", xpathCtxt);
+    if (xpathObj && xpathObj->nodesetval->nodeMax)
+    {
+        xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[0]->properties;
+        if (xmlStrEqual (attrib->name, (const xmlChar*)"name"))
+        {
+            /* we found the tag name */
+            const char *str = (const char*)attrib->children->content;
+            pstLibName = to_wide_string(str);
+        }
+        else
+        {
+            return NULL;
+        }
+    }
+
+    xpathObj = xmlXPathEval((const xmlChar*)"//scilablib/macro", xpathCtxt);
+    if (xpathObj && xpathObj->nodesetval->nodeMax)
+    {
+        /* the Xpath has been understood and there are node */
+        for (int i = 0 ; i < xpathObj->nodesetval->nodeNr ; i++)
+        {
+            xmlAttrPtr attrib = xpathObj->nodesetval->nodeTab[i]->properties;
+            /* Get the properties of <module>  */
+            while (attrib != NULL)
+            {
+                /* loop until when have read all the attributes */
+                if (xmlStrEqual (attrib->name, (const xmlChar*)"name"))
+                {
+                    /* we found the tag name */
+                    const char *str = (const char*)attrib->children->content;
+                    pstName = to_wide_string(str);
+                }
+                else if (xmlStrEqual(attrib->name, (const xmlChar*)"file"))
+                {
+                    /* we found the tag activate */
+                    const char *str = (const char*)attrib->children->content;
+                    pstFileName = to_wide_string(str);
+                }
+                attrib = attrib->next;
+            }
+
+            if (pstName && pstFileName)
+            {
+                wstring stFilename(wstPath);
+                if (stFilename.empty() == false && *stFilename.rbegin() != DIR_SEPARATORW[0])
+                {
+                    stFilename += DIR_SEPARATORW;
+                }
+
+                stFilename += pstFileName;
+                lib->add(pstName, new types::MacroFile(pstName, stFilename, pstLibName));
+            }
+            else
+            {
+                std::cout << pstName << " module not found." << std::endl;
+            }
+
+            if (pstName)
+            {
+                FREE(pstName);
+                pstName = NULL;
+            }
+
+            if (pstFileName)
+            {
+                FREE(pstFileName);
+                pstFileName = NULL;
+            }
+        }
+    }
+
+    if (xpathObj)
+    {
+        xmlXPathFreeObject(xpathObj);
+    }
+    if (xpathCtxt)
+    {
+        xmlXPathFreeContext(xpathCtxt);
+    }
+
+    if (_bAddInContext)
+    {
+        symbol::Context::getInstance()->put(symbol::Symbol(pstLibName), *lib);
+    }
+
+    xmlFreeDoc(doc);
+
+    return lib;
+}
+
+static char *GetXmlFileEncoding(string _filename)
+{
+    char *encoding = NULL;
+    xmlDocPtr doc = NULL;
+
+    /* default */
+    encoding = os_strdup(DEFAULT_ENCODING);
+
+    doc = xmlParseFile(_filename.c_str());
+    if (doc)
+    {
+        if (doc->encoding)
+        {
+            if (encoding)
+            {
+                free(encoding);
+                encoding = NULL;
+            }
+            encoding = os_strdup((char*)doc->encoding);
+        }
+    }
+
+    xmlFreeDoc(doc);
+    return encoding;
+}
diff --git a/scilab/modules/io/src/cpp/loadlib.hxx b/scilab/modules/io/src/cpp/loadlib.hxx
new file mode 100644 (file)
index 0000000..f4ce0f3
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+* 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
+*
+*/
+
+#ifndef __LOADLIB_H__
+#define __LOADLIB_H__
+
+#include "library.hxx"
+
+types::Library* loadlib(std::wstring _wstXML, bool _isFile = true, bool _bAddInContext = true);
+
+#endif /* !__LOADLIB_H__ */
\ No newline at end of file
index e7de995..c129f5d 100644 (file)
 ##
 
 SYMBOL_CXX_SOURCES = \
-    src/cpp/symbol.cpp \
-    src/cpp/context.cpp \
-    src/cpp/scope.cpp \
-    src/cpp/variables.cpp
+src/cpp/symbol.cpp \
+src/cpp/context.cpp \
+src/cpp/scope.cpp \
+src/cpp/variables.cpp \
+src/cpp/libraries.cpp
     
 
 pkglib_LTLIBRARIES             = libscisymbol.la
index 7bb067f..b60eb80 100644 (file)
@@ -160,7 +160,8 @@ am__dirstamp = $(am__leading_dot)dirstamp
 am__objects_1 = src/cpp/libscisymbol_la-symbol.lo \
        src/cpp/libscisymbol_la-context.lo \
        src/cpp/libscisymbol_la-scope.lo \
-       src/cpp/libscisymbol_la-variables.lo
+       src/cpp/libscisymbol_la-variables.lo \
+       src/cpp/libscisymbol_la-libraries.lo
 am_libscisymbol_la_OBJECTS = $(am__objects_1)
 libscisymbol_la_OBJECTS = $(am_libscisymbol_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -513,10 +514,11 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 yacc_present = @yacc_present@
 SYMBOL_CXX_SOURCES = \
-    src/cpp/symbol.cpp \
-    src/cpp/context.cpp \
-    src/cpp/scope.cpp \
-    src/cpp/variables.cpp
+src/cpp/symbol.cpp \
+src/cpp/context.cpp \
+src/cpp/scope.cpp \
+src/cpp/variables.cpp \
+src/cpp/libraries.cpp
 
 pkglib_LTLIBRARIES = libscisymbol.la
 libscisymbol_la_SOURCES = $(SYMBOL_CXX_SOURCES)
@@ -695,6 +697,8 @@ src/cpp/libscisymbol_la-scope.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscisymbol_la-variables.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libscisymbol_la-libraries.lo: src/cpp/$(am__dirstamp) \
+       src/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libscisymbol.la: $(libscisymbol_la_OBJECTS) $(libscisymbol_la_DEPENDENCIES) $(EXTRA_libscisymbol_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(CXXLINK) -rpath $(pkglibdir) $(libscisymbol_la_OBJECTS) $(libscisymbol_la_LIBADD) $(LIBS)
@@ -708,6 +712,7 @@ distclean-compile:
        -rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-context.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-scope.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-symbol.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscisymbol_la-variables.Plo@am__quote@
@@ -764,6 +769,13 @@ src/cpp/libscisymbol_la-variables.lo: src/cpp/variables.cpp
 @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) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-variables.lo `test -f 'src/cpp/variables.cpp' || echo '$(srcdir)/'`src/cpp/variables.cpp
 
+src/cpp/libscisymbol_la-libraries.lo: src/cpp/libraries.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscisymbol_la-libraries.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Tpo -c -o src/cpp/libscisymbol_la-libraries.lo `test -f 'src/cpp/libraries.cpp' || echo '$(srcdir)/'`src/cpp/libraries.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Tpo src/cpp/$(DEPDIR)/libscisymbol_la-libraries.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/libraries.cpp' object='src/cpp/libscisymbol_la-libraries.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) $(libscisymbol_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscisymbol_la-libraries.lo `test -f 'src/cpp/libraries.cpp' || echo '$(srcdir)/'`src/cpp/libraries.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 2dbdc65..4b7b65b 100644 (file)
@@ -64,11 +64,11 @@ public :
     types::InternalType* getFunction(const symbol::Symbol& key) const;
 
     /*return function list in the module _stModuleName*/
-    std::list<symbol::Symbol>& getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd = true);
+    std::list<symbol::Symbol>* getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd = true);
 
-    std::list<std::wstring>& getVarsName();
-    std::list<std::wstring>& getMacrosName();
-    std::list<std::wstring>& getFunctionsName();
+    std::list<std::wstring>* getVarsName();
+    std::list<std::wstring>* getMacrosName();
+    std::list<std::wstring>* getFunctionsName();
 
     /* global functions */
 
diff --git a/scilab/modules/symbol/includes/libraries.hxx b/scilab/modules/symbol/includes/libraries.hxx
new file mode 100644 (file)
index 0000000..5699649
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+*  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
+*
+*/
+
+#ifndef __LIBRARIES_HXX__
+#define __LIBRARIES_HXX__
+
+#include <map>
+#include <list>
+#include "types.hxx"
+#include "symbol.hxx"
+#include "function.hxx"
+#include "library.hxx"
+#include "variables.hxx"
+
+
+namespace symbol
+{
+class LibBox
+{
+public :
+    LibBox(int _iLevel, types::Library& _lib) : m_iLevel(_iLevel), m_pLib(&_lib) {};
+    virtual ~LibBox() {};
+
+    types::Library* getValue()
+    {
+        return m_pLib;
+    }
+    types::MacroFile* getMacroFile(const Symbol& _key);
+    void setValue(types::Library& _lib)
+    {
+        m_pLib = &_lib;
+    }
+    int getLevel()
+    {
+        return m_iLevel;
+    };
+    void setLevel(int _iLevel)
+    {
+        m_iLevel = _iLevel;
+    };
+private :
+    int m_iLevel;
+    types::Library* m_pLib;
+};
+
+class Libraries
+{
+private :
+    typedef std::list<LibBox* > LibBoxList;
+    typedef std::map<Symbol, LibBoxList*> LibMap;
+    typedef std::list<Symbol> LibList;
+    LibMap m_libmap;
+    LibList m_liblist;
+    int m_iLevel;
+
+public :
+    Libraries() : m_iLevel(-1) {}
+
+    virtual ~Libraries() {}
+
+    void IncreaseLevel()
+    {
+        m_iLevel++;
+    }
+    void DecreaseLevel()
+    {
+        m_iLevel--;
+    }
+
+    void put(const Symbol& _key, types::InternalType& _IT);
+    types::MacroFile* get(const Symbol& _key) const;
+    bool remove(const Symbol& _key);
+
+    std::list<std::wstring>* getMacrosName();
+
+};
+}
+#endif /* !__LIBRARIES_HXX__ */
index f995972..02f740d 100644 (file)
 #define __NEWSCOPE_HXX__
 
 #include "variables.hxx"
+#include "libraries.hxx"
 
 namespace symbol
 {
 class Scope
 {
 public :
-    Scope(Variables* _vars, int _iLevel) : m_vars(_vars), m_iLevel(_iLevel) {}
+    Scope(Variables* _vars, Libraries* _libs, int _iLevel) : m_vars(_vars), m_libs(_libs), m_iLevel(_iLevel) {}
     virtual ~Scope();
 
     void put(const Symbol& _key, types::InternalType& _iT);
@@ -38,6 +39,7 @@ private :
     SymbolMap m_symbol;
     int m_iLevel;
     Variables* m_vars;
+    Libraries* m_libs;
 };
 
 class Scopes
@@ -47,7 +49,7 @@ private :
     ScopesList m_scopes;
     int m_iLevel;
     Variables m_vars;
-
+    Libraries m_libs;
 public :
 
     Scopes() : m_iLevel(-1) {}
@@ -82,10 +84,10 @@ public :
     void createEmptyGlobalValue(const symbol::Symbol& _key);
 
     /*tools*/
-    std::list<symbol::Symbol>& getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd);
-    std::list<std::wstring>& getVarsName();
-    std::list<std::wstring>& getMacrosName();
-    std::list<std::wstring>& getFunctionsName();
+    std::list<symbol::Symbol>* getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd);
+    std::list<std::wstring>* getVarsName();
+    std::list<std::wstring>* getMacrosName();
+    std::list<std::wstring>* getFunctionsName();
     void print(std::wostream& ostr) const;
 };
 
index ad58868..1a14015 100644 (file)
@@ -57,10 +57,10 @@ public :
     types::InternalType* getAllButCurrentLevel(const Symbol& _key) const;
     types::InternalType* getInSpecificLevel(const Symbol& _key, int _iLevel) const;
 
-    std::list<symbol::Symbol>& getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const;
-    std::list<std::wstring>& getVarsName();
-    std::list<std::wstring>& getMacrosName();
-    std::list<std::wstring>& getFunctionsName();
+    std::list<symbol::Symbol>* getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const;
+    std::list<std::wstring>* getVarsName();
+    std::list<std::wstring>* getMacrosName();
+    std::list<std::wstring>* getFunctionsName();
 
     /*globals*/
     bool isGlobalVisible(const symbol::Symbol& _key) const;
index f7d49dc..270915a 100644 (file)
@@ -75,22 +75,22 @@ types::InternalType* Context::getFunction(const symbol::Symbol& _key) const
     return m_scopes->get(_key);
 }
 
-std::list<symbol::Symbol>& Context::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd)
+std::list<symbol::Symbol>* Context::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd)
 {
     return m_scopes->getFunctionList(_stModuleName, _bFromEnd);
 }
 
-std::list<std::wstring>& Context::getVarsName()
+std::list<std::wstring>* Context::getVarsName()
 {
     return m_scopes->getVarsName();
 }
 
-std::list<std::wstring>& Context::getMacrosName()
+std::list<std::wstring>* Context::getMacrosName()
 {
     return m_scopes->getMacrosName();
 }
 
-std::list<std::wstring>& Context::getFunctionsName()
+std::list<std::wstring>* Context::getFunctionsName()
 {
     return m_scopes->getFunctionsName();
 }
diff --git a/scilab/modules/symbol/src/cpp/libraries.cpp b/scilab/modules/symbol/src/cpp/libraries.cpp
new file mode 100644 (file)
index 0000000..edae211
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+*  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 "libraries.hxx"
+#include "context.hxx"
+
+namespace symbol
+{
+types::MacroFile* LibBox::getMacroFile(const Symbol& _key)
+{
+    return m_pLib->get(_key.name_get());
+}
+
+void Libraries::put(const Symbol& _key, types::InternalType& _iT)
+{
+    if (_iT.isLibrary() == false)
+    {
+        return;
+    }
+
+    types::Library* pLib = _iT.getAs<types::Library>();
+
+    LibMap::iterator itVar = m_libmap.find(_key);
+    LibBoxList* pL = NULL;
+    LibBox* pBox = NULL;
+
+    if (itVar != m_libmap.end())
+    {
+        //item alreay exists
+
+        //check scope level
+        LibBoxList::reverse_iterator itBox = itVar->second->rbegin();
+
+        bool bInserted = false;
+        for (; itBox != itVar->second->rend() ; itBox++)
+        {
+            pBox = *itBox;
+            if ((*itBox)->getValue() == pLib)
+            {
+                return;
+            }
+
+            //update value
+            (*itBox)->setValue(*pLib);
+            bInserted = true;
+            break;
+        }
+    }
+    else
+    {
+        //new var
+        pBox = new LibBox(m_iLevel, *pLib);
+        pL = new LibBoxList();
+        pL->push_back(pBox);
+        m_libmap[_key] = pL;
+        m_liblist.push_back(_key);
+    }
+
+    return;
+}
+
+types::MacroFile* Libraries::get(const Symbol& _key) const
+{
+    types::MacroFile* pIT = NULL;
+    LibList::const_reverse_iterator it = m_liblist.rbegin();
+    for (; it != m_liblist.rend() ; ++it)
+    {
+        LibBoxList* l = m_libmap.find(*it)->second;
+        LibBoxList::const_reverse_iterator itBox = l->rbegin();
+        for (; itBox != l->rend(); ++itBox)
+        {
+            pIT = (*itBox)->getMacroFile(_key);
+            if (pIT)
+            {
+                Context::getInstance()->AddMacroFile(pIT);
+                return pIT;
+            }
+        }
+    }
+
+    return pIT;
+}
+
+bool Libraries::remove(const Symbol& _key)
+{
+    LibMap::iterator itVar = m_libmap.find(_key);
+    if (itVar != m_libmap.end())
+    {
+        LibBox* pBox = itVar->second->back();
+        if (pBox->getLevel() != m_iLevel)
+        {
+            return false;
+        }
+
+        if (pBox->getValue())
+        {
+            delete pBox;
+        }
+
+        itVar->second->pop_back();
+
+        //remove empty entries from variable map
+        if (itVar->second->empty())
+        {
+            m_liblist.remove(itVar->first);
+            m_libmap.erase(itVar);
+        }
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+std::list<std::wstring>* Libraries::getMacrosName()
+{
+    std::list<std::wstring>* plOut = new std::list<std::wstring>();
+    types::Library* pLib = NULL;
+    LibMap::const_iterator it = m_libmap.begin();
+
+    for (; it != m_libmap.end(); it++)
+    {
+        pLib = it->second->back()->getValue();
+        std::list<std::wstring>* tmpList = pLib->getMacrosName();
+        plOut->insert(plOut->end(), tmpList->begin(), tmpList->end());
+        delete tmpList;
+    }
+
+    return plOut;
+}
+
+}
index e2889af..27dcccc 100644 (file)
@@ -22,6 +22,7 @@ Scope::~Scope()
     for (; it != m_symbol.end() ; it++)
     {
         m_vars->remove(it->first);
+        m_libs->remove(it->first);
     }
 }
 
@@ -29,12 +30,17 @@ void Scope::put(const Symbol& _key, types::InternalType& _iT)
 {
     m_symbol[_key] = 0;
     m_vars->put(_key, _iT, m_iLevel);
+    if (_iT.isLibrary())
+    {
+        m_libs->put(_key, _iT);
+    }
 }
 
 void Scope::remove(const Symbol& _key)
 {
     m_symbol.erase(_key);
     m_vars->remove(_key);
+    m_libs->remove(_key);
 }
 
 void Scope::print(std::wostream& ostr) const
@@ -73,8 +79,9 @@ void Scope::removeVar(const symbol::Symbol& _key)
 void Scopes::scope_begin()
 {
     m_iLevel++;
-    m_scopes.push_back(new Scope(&m_vars, m_iLevel));
+    m_scopes.push_back(new Scope(&m_vars, &m_libs, m_iLevel));
     m_vars.IncreaseLevel();
+    m_libs.IncreaseLevel();
 }
 
 void Scopes::scope_end()
@@ -84,6 +91,7 @@ void Scopes::scope_end()
     m_scopes.pop_back();
     m_iLevel--;
     m_vars.DecreaseLevel();
+    m_libs.DecreaseLevel();
 }
 
 void Scopes::put(const Symbol& _key, types::InternalType& _iT, int _iLevel)
@@ -112,7 +120,14 @@ void Scopes::putInPreviousScope(const Symbol& _key, types::InternalType& _iT)
 /* getters */
 types::InternalType* Scopes::get(const Symbol& _key) const
 {
-    return m_vars.get(_key);
+    types::InternalType* pIT = m_vars.get(_key);
+    if (pIT == NULL)
+    {
+        //check in macro lib
+        pIT = m_libs.get(_key);
+    }
+
+    return pIT;
 }
 
 types::InternalType* Scopes::getCurrentLevel(const Symbol& _key) const
@@ -184,22 +199,26 @@ void Scopes::createEmptyGlobalValue(const symbol::Symbol& _key)
 
 
 /*tools*/
-std::list<symbol::Symbol>& Scopes::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd)
+std::list<symbol::Symbol>* Scopes::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd)
 {
     return m_vars.getFunctionList(_stModuleName, _bFromEnd);
 }
 
-std::list<std::wstring>& Scopes::getVarsName()
+std::list<std::wstring>* Scopes::getVarsName()
 {
     return m_vars.getVarsName();
 }
 
-std::list<std::wstring>& Scopes::getMacrosName()
+std::list<std::wstring>* Scopes::getMacrosName()
 {
-    return m_vars.getMacrosName();
+    std::list<std::wstring>* vars = m_vars.getMacrosName();
+    std::list<std::wstring>* libs = m_libs.getMacrosName();
+    vars->insert(vars->end(), libs->begin(), libs->end());
+    delete libs;
+    return vars;
 }
 
-std::list<std::wstring>& Scopes::getFunctionsName()
+std::list<std::wstring>* Scopes::getFunctionsName()
 {
     return m_vars.getFunctionsName();
 }
index 8832aca..20d8673 100644 (file)
@@ -228,10 +228,9 @@ bool Variables::remove(const Symbol& _key)
     {
         return false;
     }
-
 }
 
-std::list<std::wstring>& Variables::getVarsName()
+std::list<std::wstring>* Variables::getVarsName()
 {
     std::list<std::wstring>* plOut = new std::list<std::wstring>();
     types::InternalType* pIT = NULL;
@@ -246,10 +245,10 @@ std::list<std::wstring>& Variables::getVarsName()
         }
     }
 
-    return *plOut;
+    return plOut;
 }
 
-std::list<std::wstring>& Variables::getMacrosName()
+std::list<std::wstring>* Variables::getMacrosName()
 {
     std::list<std::wstring>* plOut = new std::list<std::wstring>();
     types::InternalType* pIT = NULL;
@@ -264,10 +263,10 @@ std::list<std::wstring>& Variables::getMacrosName()
         }
     }
 
-    return *plOut;
+    return plOut;
 }
 
-std::list<std::wstring>& Variables::getFunctionsName()
+std::list<std::wstring>* Variables::getFunctionsName()
 {
     std::list<std::wstring>* plOut = new std::list<std::wstring>();
     types::InternalType* pIT = NULL;
@@ -282,10 +281,10 @@ std::list<std::wstring>& Variables::getFunctionsName()
         }
     }
 
-    return *plOut;
+    return plOut;
 }
 
-std::list<symbol::Symbol>& Variables::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const
+std::list<symbol::Symbol>* Variables::getFunctionList(const std::wstring& _stModuleName, bool _bFromEnd) const
 {
     bool bAll = _stModuleName == L"";
     std::list<symbol::Symbol>* lst = new std::list<symbol::Symbol>;
@@ -338,7 +337,7 @@ std::list<symbol::Symbol>& Variables::getFunctionList(const std::wstring& _stMod
         }
 
     }
-    return *lst;
+    return lst;
 }
 
 bool Variables::isGlobalVisible(const symbol::Symbol& _key) const
index 62aa51e..868ae1b 100644 (file)
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\context.cpp" />
+    <ClCompile Include="src\cpp\libraries.cpp" />
     <ClCompile Include="src\cpp\scope.cpp" />
     <ClCompile Include="src\cpp\symbol.cpp" />
     <ClCompile Include="src\cpp\variables.cpp" />
     <ClInclude Include="includes\addGatewayInContext.h" />
     <ClInclude Include="includes\context.hxx" />
     <ClInclude Include="includes\export_symbol.h" />
+    <ClInclude Include="includes\libraries.hxx" />
+    <ClInclude Include="includes\scope.hxx" />
     <ClInclude Include="includes\symbol.hxx" />
     <ClInclude Include="includes\variables.hxx" />
   </ItemGroup>
index 949c37b..4145e45 100644 (file)
@@ -27,6 +27,9 @@
     <ClCompile Include="src\cpp\scope.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\libraries.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\context.hxx">
     <ClInclude Include="includes\variables.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\scope.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="includes\libraries.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\bin\blasplus.lib" />
index de64345..4416ef9 100644 (file)
@@ -30,43 +30,44 @@ include $(top_srcdir)/Makefile.incl.am
 TYPES_JAVA_C_SOURCES = src/jni/getScilabVariable_wrap.c
 
 TYPES_CPP_SOURCES = \
-                       src/cpp/types.cpp \
-                       src/cpp/string.cpp \
-                       src/cpp/double.cpp \
-                       src/cpp/bool.cpp \
-                       src/cpp/float.cpp \
-                       src/cpp/implicitlist.cpp \
-                       src/cpp/polynom.cpp \
-                       src/cpp/singlepoly.cpp \
-                       src/cpp/tostring_common.cpp \
-                       src/cpp/function.cpp \
-                       src/cpp/macrofile.cpp \
-                       src/cpp/macro.cpp \
-                       src/cpp/list.cpp \
-                       src/cpp/listdelete.cpp \
-                       src/cpp/listinsert.cpp \
-                       src/cpp/listoperation.cpp \
-                       src/cpp/listundefined.cpp \
-                       src/cpp/struct.cpp \
-                       src/cpp/singlestruct.cpp \
-                       src/cpp/cell.cpp \
-                       src/cpp/tlist.cpp \
-                       src/cpp/file.cpp \
-                       src/cpp/mlist.cpp \
-                       src/cpp/threadId.cpp \
-                       src/cpp/arrayof.cpp \
-                       src/cpp/int8.cpp \
-                       src/cpp/uint8.cpp \
-                       src/cpp/int16.cpp \
-                       src/cpp/uint16.cpp \
-                       src/cpp/int32.cpp \
-                       src/cpp/uint32.cpp \
-                       src/cpp/int64.cpp \
-                       src/cpp/uint64.cpp \
-            src/cpp/sparse.cpp \
-                       src/cpp/graphichandle.cpp \
-            src/cpp/types_tools.cpp \
-            src/cpp/void.cpp
+src/cpp/types.cpp \
+src/cpp/string.cpp \
+src/cpp/double.cpp \
+src/cpp/bool.cpp \
+src/cpp/float.cpp \
+src/cpp/implicitlist.cpp \
+src/cpp/polynom.cpp \
+src/cpp/singlepoly.cpp \
+src/cpp/tostring_common.cpp \
+src/cpp/function.cpp \
+src/cpp/macrofile.cpp \
+src/cpp/macro.cpp \
+src/cpp/list.cpp \
+src/cpp/listdelete.cpp \
+src/cpp/listinsert.cpp \
+src/cpp/listoperation.cpp \
+src/cpp/listundefined.cpp \
+src/cpp/struct.cpp \
+src/cpp/singlestruct.cpp \
+src/cpp/cell.cpp \
+src/cpp/tlist.cpp \
+src/cpp/file.cpp \
+src/cpp/mlist.cpp \
+src/cpp/threadId.cpp \
+src/cpp/arrayof.cpp \
+src/cpp/int8.cpp \
+src/cpp/uint8.cpp \
+src/cpp/int16.cpp \
+src/cpp/uint16.cpp \
+src/cpp/int32.cpp \
+src/cpp/uint32.cpp \
+src/cpp/int64.cpp \
+src/cpp/uint64.cpp \
+src/cpp/sparse.cpp \
+src/cpp/graphichandle.cpp \
+src/cpp/types_tools.cpp \
+src/cpp/void.cpp \
+src/cpp/library.cpp
 
 TYPES_JAVA_CPP_SOURCES = src/cpp/ScilabToJava.cpp \
                    src/jni/ScilabVariables.cpp \
index 6d7c64c..80a7330 100644 (file)
@@ -198,7 +198,7 @@ am__libscitypes_algo_la_SOURCES_DIST = src/cpp/types.cpp \
        src/cpp/int32.cpp src/cpp/uint32.cpp src/cpp/int64.cpp \
        src/cpp/uint64.cpp src/cpp/sparse.cpp \
        src/cpp/graphichandle.cpp src/cpp/types_tools.cpp \
-       src/cpp/void.cpp src/cpp/inspector.cpp
+       src/cpp/void.cpp src/cpp/library.cpp src/cpp/inspector.cpp
 am__dirstamp = $(am__leading_dot)dirstamp
 @ENABLE_DEBUG_TRUE@am__objects_1 =  \
 @ENABLE_DEBUG_TRUE@    src/cpp/libscitypes_algo_la-inspector.lo
@@ -238,7 +238,8 @@ am__objects_2 = src/cpp/libscitypes_algo_la-types.lo \
        src/cpp/libscitypes_algo_la-sparse.lo \
        src/cpp/libscitypes_algo_la-graphichandle.lo \
        src/cpp/libscitypes_algo_la-types_tools.lo \
-       src/cpp/libscitypes_algo_la-void.lo $(am__objects_1)
+       src/cpp/libscitypes_algo_la-void.lo \
+       src/cpp/libscitypes_algo_la-library.lo $(am__objects_1)
 am_libscitypes_algo_la_OBJECTS = $(am__objects_2)
 libscitypes_algo_la_OBJECTS = $(am_libscitypes_algo_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -791,7 +792,7 @@ TYPES_CPP_SOURCES = src/cpp/types.cpp src/cpp/string.cpp \
        src/cpp/int32.cpp src/cpp/uint32.cpp src/cpp/int64.cpp \
        src/cpp/uint64.cpp src/cpp/sparse.cpp \
        src/cpp/graphichandle.cpp src/cpp/types_tools.cpp \
-       src/cpp/void.cpp $(am__append_2)
+       src/cpp/void.cpp src/cpp/library.cpp $(am__append_2)
 TYPES_JAVA_CPP_SOURCES = src/cpp/ScilabToJava.cpp \
                    src/jni/ScilabVariables.cpp \
                    src/jni/ScilabVariablesRefresh.cpp \
@@ -1042,6 +1043,8 @@ src/cpp/libscitypes_algo_la-types_tools.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscitypes_algo_la-void.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libscitypes_algo_la-library.lo: src/cpp/$(am__dirstamp) \
+       src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscitypes_algo_la-inspector.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
 
@@ -1197,6 +1200,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-int32.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-int64.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-int8.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-library.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-list.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-listdelete.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscitypes_algo_la-listinsert.Plo@am__quote@
@@ -1542,6 +1546,13 @@ src/cpp/libscitypes_algo_la-void.lo: src/cpp/void.cpp
 @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) $(libscitypes_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscitypes_algo_la-void.lo `test -f 'src/cpp/void.cpp' || echo '$(srcdir)/'`src/cpp/void.cpp
 
+src/cpp/libscitypes_algo_la-library.lo: src/cpp/library.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitypes_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscitypes_algo_la-library.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscitypes_algo_la-library.Tpo -c -o src/cpp/libscitypes_algo_la-library.lo `test -f 'src/cpp/library.cpp' || echo '$(srcdir)/'`src/cpp/library.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscitypes_algo_la-library.Tpo src/cpp/$(DEPDIR)/libscitypes_algo_la-library.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/library.cpp' object='src/cpp/libscitypes_algo_la-library.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) $(libscitypes_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscitypes_algo_la-library.lo `test -f 'src/cpp/library.cpp' || echo '$(srcdir)/'`src/cpp/library.cpp
+
 src/cpp/libscitypes_algo_la-inspector.lo: src/cpp/inspector.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitypes_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscitypes_algo_la-inspector.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscitypes_algo_la-inspector.Tpo -c -o src/cpp/libscitypes_algo_la-inspector.lo `test -f 'src/cpp/inspector.cpp' || echo '$(srcdir)/'`src/cpp/inspector.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscitypes_algo_la-inspector.Tpo src/cpp/$(DEPDIR)/libscitypes_algo_la-inspector.Plo
index 37d0572..ecf603f 100644 (file)
@@ -78,7 +78,8 @@ public :
         RealSparseBool,
         RealSingleHandle,
         RealHandle,
-        RealVoid
+        RealVoid,
+        RealLibrary
     };
 
 protected :
@@ -123,15 +124,15 @@ public :
         }
     }
 
-    bool                               isDeletable()
+    virtual bool isDeletable()
     {
         return m_iRef == 0;
     }
-    bool                               isRef(int _iRef = 0)
+    bool isRef(int _iRef = 0)
     {
         return m_iRef > _iRef;
     }
-    int                             getRef()
+    int getRef()
     {
         return m_iRef;
     }
@@ -322,6 +323,10 @@ public :
     {
         return false;
     }
+    virtual bool                    isLibrary(void)
+    {
+        return false;
+    }
 
     void clearPrintState()
     {
diff --git a/scilab/modules/types/includes/library.hxx b/scilab/modules/types/includes/library.hxx
new file mode 100644 (file)
index 0000000..e8566f6
--- /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
+ *
+ */
+
+#ifndef __LIBRARY_HXX__
+#define __LIBRARY_HXX__
+
+#include "macrofile.hxx"
+#include "dynlib_types.h"
+
+namespace types
+{
+class TYPES_IMPEXP Library : public InternalType
+{
+public :
+    Library(const std::wstring& _wstPath);
+    ~Library();
+
+    bool isLibrary(void)
+    {
+        return true;
+    }
+
+    /* return type as string ( double, int, cell, list, ... )*/
+    virtual std::wstring getTypeStr()
+    {
+        return L"library";
+    }
+    /* return type as short string ( s, i, ce, l, ... )*/
+    virtual std::wstring getShortTypeStr()
+    {
+        return L"f";
+    }
+
+    RealType getType(void)
+    {
+        return RealLibrary;
+    };
+    bool toString(std::wostringstream& ostr);
+    InternalType* clone();
+    bool isAssignable()
+    {
+        return true;
+    }
+
+    void add(const std::wstring& _wstName, MacroFile* _macro);
+    MacroFile* get(const std::wstring& _wstName);
+    std::list<std::wstring>* getMacrosName();
+private :
+    std::wstring m_wstPath;
+    typedef std::map<std::wstring, MacroFile*> MacroMap;
+    MacroMap m_macros;
+};
+}
+
+#endif /* __LIBRARY_HXX__ */
index 7bdb572..6ca847a 100644 (file)
@@ -34,12 +34,12 @@ Function::ReturnValue sci_inspectorGetFunctionList(typed_list &in, int _iRetCoun
 
     symbol::Context* pC = symbol::Context::getInstance();
 
-    std::list<symbol::Symbol> FuncName = pC->getFunctionList(L"");
+    std::list<symbol::Symbol>* FuncName = pC->getFunctionList(L"");
 
-    String* pOut = new String((int)FuncName.size(), 4);
+    String* pOut = new String((int)FuncName->size(), 4);
 
-    std::list<symbol::Symbol>::iterator it = FuncName.begin();
-    for (int i = 0; it != FuncName.end() ; it++, i++)
+    std::list<symbol::Symbol>::iterator it = FuncName->begin();
+    for (int i = 0; it != FuncName->end() ; ++it, i++)
     {
         Callable* pCall = pC->get(*it)->getAs<Callable>();
         //Function name
@@ -57,6 +57,7 @@ Function::ReturnValue sci_inspectorGetFunctionList(typed_list &in, int _iRetCoun
         }
     }
 
+    delete FuncName;
     out.push_back(pOut);
     return Function::OK;
 }
diff --git a/scilab/modules/types/src/cpp/library.cpp b/scilab/modules/types/src/cpp/library.cpp
new file mode 100644 (file)
index 0000000..9233567
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ *  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 "library.hxx"
+extern "C"
+{
+#include <wchar.h>
+#include "os_swprintf.h"
+#include "formatmode.h"
+}
+
+namespace types
+{
+Library::Library(const std::wstring& _wstPath) :
+    m_wstPath(_wstPath)
+{
+}
+
+Library::~Library()
+{
+    //delete all macrofile*
+    for (MacroMap::iterator it = m_macros.begin(); it != m_macros.end() ; ++it)
+    {
+        MacroFile* pMacro = it->second;
+        pMacro->DecreaseRef();
+        if (pMacro->isDeletable())
+        {
+            delete pMacro;
+        }
+    }
+
+    m_macros.clear();
+}
+
+bool Library::toString(std::wostringstream& ostr)
+{
+    wchar_t output[1024] = {0};
+    os_swprintf(output, 1024, _W("Functions files location : %s.\n"), m_wstPath.c_str());
+
+    ostr << output << std::endl;
+
+    int iLineLen = getConsoleWidth();
+
+    size_t iCurrentLen = 0;
+    MacroMap::iterator it = m_macros.begin();
+    for (int i = 0; it != m_macros.end() ; ++it, ++i)
+    {
+        if (iCurrentLen + it->first.length() + 2 > iLineLen)
+        {
+            ostr << std::endl;
+            iCurrentLen = 0;
+        }
+        ostr << it->first << "  ";
+        iCurrentLen += it->first.length() + 2;
+    }
+
+    ostr << std::endl;
+    return true;
+}
+
+InternalType* Library::clone()
+{
+    IncreaseRef();
+    return this;
+}
+
+void Library::add(const std::wstring& _wstName, MacroFile* _macro)
+{
+    _macro->IncreaseRef();
+    m_macros[_wstName] = _macro;
+}
+
+MacroFile* Library::get(const std::wstring& _wstName)
+{
+    MacroMap::iterator it = m_macros.find(_wstName);
+    if (it != m_macros.end())
+    {
+        return it->second;
+    }
+    return NULL;
+}
+
+std::list<std::wstring>* Library::getMacrosName()
+{
+    std::list<std::wstring>* pOut = new std::list<std::wstring>;
+    MacroMap::iterator it = m_macros.begin();
+    for (; it != m_macros.end() ; ++it)
+    {
+        pOut->push_back(it->first);
+    }
+
+    return pOut;
+}
+}
\ No newline at end of file
diff --git a/scilab/modules/types/tests/unit_tests/library.dia.ref b/scilab/modules/types/tests/unit_tests/library.dia.ref
new file mode 100644 (file)
index 0000000..ee6f7c4
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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
+//
+//
+cd TMPDIR;
+//create 2 lib with the same symbol ( "lib_test" for exemple )
+//create the "lib_test" macro file in TMPDIR/lib1
+mkdir("lib1");
+mputl(["function ret = lib_test";"  ret= ""lib1""";"endfunction"], "lib1/lib_test.sci");
+//generate lib ( aka "lib1lib" )
+genlib("lib1lib","lib1",%f,%t);
+-- Creation of [lib1lib] (Macros) --
+assert_checkequal(lib_test(), "lib1");
+clear lib1lib lib_test;
+//same things with TMPDIR/lib2
+mkdir("lib2");
+mputl(["function ret = lib_test";"  ret= ""lib2""";"endfunction"], "lib2/lib_test.sci");
+//generate lib ( aka "lib2lib" )
+genlib("lib2lib","lib2",%f,%t);
+-- Creation of [lib2lib] (Macros) --
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib lib_test;
+//now try to load lib1lib
+lib1lib = lib("lib1");
+//call macro
+assert_checkequal(lib_test(), "lib1");
+clear lib1lib lib_test;
+//now try to load lib2lib
+lib2lib = lib("lib2");
+//call macro
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib
+//load lib1 call function, load lib2 and call function again
+lib1lib = lib("lib1");
+//call macro
+assert_checkequal(lib_test(), "lib1");
+lib2lib = lib("lib2");
+assert_checkequal(lib_test(), "lib1");
+clear lib_test;
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib;
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib lib_test;
+assert_checkequal(lib_test(), "lib1");
diff --git a/scilab/modules/types/tests/unit_tests/library.tst b/scilab/modules/types/tests/unit_tests/library.tst
new file mode 100644 (file)
index 0000000..b5a14f4
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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
+//
+//
+
+cd TMPDIR;
+
+//create 2 lib with the same symbol ( "lib_test" for exemple )
+
+//create the "lib_test" macro file in TMPDIR/lib1
+mkdir("lib1");
+mputl(["function ret = lib_test";"  ret= ""lib1""";"endfunction"], "lib1/lib_test.sci");
+//generate lib ( aka "lib1lib" )
+genlib("lib1lib","lib1",%f,%t);
+assert_checkequal(lib_test(), "lib1");
+clear lib1lib lib_test;
+
+//same things with TMPDIR/lib2
+mkdir("lib2");
+mputl(["function ret = lib_test";"  ret= ""lib2""";"endfunction"], "lib2/lib_test.sci");
+//generate lib ( aka "lib2lib" )
+genlib("lib2lib","lib2",%f,%t);
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib lib_test;
+
+//now try to load lib1lib
+lib1lib = lib("lib1");
+//call macro
+assert_checkequal(lib_test(), "lib1");
+clear lib1lib lib_test;
+
+//now try to load lib2lib
+lib2lib = lib("lib2");
+//call macro
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib lib_test
+
+//load lib1 call function, load lib2 and call function again
+lib1lib = lib("lib1");
+//call macro
+assert_checkequal(lib_test(), "lib1");
+lib2lib = lib("lib2");
+assert_checkequal(lib_test(), "lib1");
+clear lib_test;
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib;
+assert_checkequal(lib_test(), "lib2");
+clear lib2lib lib_test;
+assert_checkequal(lib_test(), "lib1");
index a58e200..0f068fa 100644 (file)
@@ -206,6 +206,7 @@ lib /DEF:"$(ProjectDir)operations_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Plat
     <ClCompile Include="src\cpp\int32.cpp" />
     <ClCompile Include="src\cpp\int64.cpp" />
     <ClCompile Include="src\cpp\int8.cpp" />
+    <ClCompile Include="src\cpp\library.cpp" />
     <ClCompile Include="src\cpp\list.cpp" />
     <ClCompile Include="src\cpp\listdelete.cpp" />
     <ClCompile Include="src\cpp\listinsert.cpp" />
@@ -255,6 +256,7 @@ lib /DEF:"$(ProjectDir)operations_Import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Plat
     <ClInclude Include="includes\int64.hxx" />
     <ClInclude Include="includes\int8.hxx" />
     <ClInclude Include="includes\internal.hxx" />
+    <ClInclude Include="includes\library.hxx" />
     <ClInclude Include="includes\list.hxx" />
     <ClInclude Include="includes\listdelete.hxx" />
     <ClInclude Include="includes\listinsert.hxx" />
index fcc3ef2..88755d5 100644 (file)
     <ClCompile Include="src\cpp\void.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\library.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="Makefile.am" />
     <ClInclude Include="includes\void.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\library.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <Library Include="..\..\bin\blasplus.lib" />