save function can save environment in sod format 73/8573/6
Antoine ELIAS [Mon, 6 Aug 2012 15:55:59 +0000 (17:55 +0200)]
Change-Id: I31d54fdf00c6b69cf652638834546eb608624307

scilab/CHANGES_5.4.X
scilab/modules/core/help/en_US/variables/who_user.xml
scilab/modules/core/macros/who_user.sci
scilab/modules/hdf5/sci_gateway/cpp/sci_export_to_hdf5.cpp
scilab/modules/hdf5/src/c/core_Import.def
scilab/modules/io/macros/%_save.sci
scilab/modules/io/macros/%_sodload.sci
scilab/modules/io/sci_gateway/c/sci_save.c
scilab/modules/io/tests/unit_tests/saveload_v5.dia.ref
scilab/modules/io/tests/unit_tests/saveload_v5.tst

index 160af13..934a5f3 100644 (file)
@@ -32,6 +32,9 @@ Compilation
 Bug Fixes
 =========
 
+* Bug #4337 fixed - who_user did not return user's variable names, they were
+                    only displayed.
+
 * Bug #7674 fixed - In all demos Optimization and Simulation, the source
                     code was displayed by default.
                     A messagebox now lets the choice to the user to display the
index 52a4c4b..5685368 100644 (file)
@@ -1,28 +1,80 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="who_user">
-  <refnamediv>
-    <refname>who_user</refname>
-    <refpurpose> listing of user's variables</refpurpose>
-  </refnamediv>
-  <refsynopsisdiv>
-    <title>Calling Sequence</title>
-    <synopsis>who_user()</synopsis>
-  </refsynopsisdiv>
-  <refsection>
-    <title>Description</title>
-    <para>
-      <literal>who_user</literal> displays user's  variable names.
-    </para>
-  </refsection>
-  <refsection role="see also">
-    <title>See Also</title>
-    <simplelist type="inline">
-      <member>
-        <link linkend="whos">whos</link>
-      </member>
-      <member>
-        <link linkend="who">who</link>
-      </member>
-    </simplelist>
-  </refsection>
+    <refnamediv>
+        <refname>who_user</refname>
+        <refpurpose> listing of user's variables</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>varList = who_user([bPrint])</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>bPrint</term>
+                <listitem>
+                    <para>
+                        Enable or disable screen outputs (Default: %t).
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Return value</title>
+        <variablelist>
+            <varlistentry>
+                <term>varList</term>
+                <listitem>
+                    <para>
+                        Column vector of user's variables or [] if user does not have variable.
+                    </para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <literal>who_user</literal> displays and/or returns user's variable names.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="code_scilab">
+            <![CDATA[ 
+clear;
+who_user()
+who_user(%t)
+who_user(%f)
+a = 1;
+b = 2;
+who_user()
+who_user(%t)
+who_user(%f)
+clear;
+ ]]>
+        </programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="whos">whos</link>
+            </member>
+            <member>
+                <link linkend="who">who</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.4.0</revnumber>
+                <revremark>who_user can now return user's variable names in a column vector of character strings.</revremark>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index e332491..973d066 100644 (file)
@@ -1,5 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
+// Copyright (C) 2012 - 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
@@ -7,43 +8,61 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
-function who_user()
-//get user variables
-[nams,mem]=who('get'); //get all variables
-p=predef(); //number of system variable
-st=stacksize()
-nams=nams(1:$-p+1);mem=mem(1:$-p+1);
-//modifiable system variables
-excluded=['demolist','%helps','%helps_modules','who_user'];
-ke=grep(nams,excluded)
-nams(ke)=[];mem(ke)=[];
-
-n=size(nams,1);
-if n==0 then return,end
-
-//format names on n*10 characters
-ll=length(nams)+2;m=int((ll-1)/10)+1;
-for k=1:max(m)
-  ks=find(m==k);
-  if ks<>[] then nams(ks)=part(nams(ks),1:(k*10));end
-end
-
-
-
-nlc=lines(); nc=nlc(1)//window sizes
-
-txt=[]
-k=1
-while k<=n
-  m=find(cumsum(length(nams(k:$)))<nc);
-  m=m($)
-  txt=[txt;strcat(nams(k:k-1+m))];
-  k=k+m;
-end
-txt=[gettext("User variables are:");
-    '';
-    txt;
-    '';
-    msprintf(gettext("Using %s elements out of %s"),string(sum(mem)), string(st(1)-(st(2)-sum(mem))))]
-write(%io(2),txt,'(1x,a)')
+//2012/08/06 add return value with variable list.
+
+function ret = who_user(%__bPrint__)
+    //get user variables
+    [nams,mem]=who('get'); //get all variables
+    p=predef(); //number of system variable
+    st=stacksize()
+    nams=nams(1:$-p+1);mem=mem(1:$-p+1);
+    //modifiable system variables
+    excluded=['demolist','%helps','%helps_modules','home','who_user', "%__bPrint__"];
+    ke=grep(nams,excluded)
+    nams(ke)=[];mem(ke)=[];
+    ret = nams
+
+    [%_lhs, %_rhs] = argn();
+
+    if %_rhs == 0 then
+        %__bPrint__ = %t;
+    end
+
+    if %__bPrint__ == %f then
+        return;
+    end
+
+    n=size(nams,1);
+    
+    if n==0 then 
+        return
+    end
+
+    //format names on n*10 characters
+    ll=length(nams)+2;m=int((ll-1)/10)+1;
+    for k=1:max(m)
+        ks=find(m==k);
+        if ks<>[] then
+            nams(ks)=part(nams(ks),1:(k*10));
+        end
+    end
+
+    nlc=lines(); nc=nlc(1)//window sizes
+
+    txt=[]
+
+    k=1
+    while k<=n
+        m=find(cumsum(length(nams(k:$)))<nc);
+        m=m($)
+        txt=[txt;strcat(nams(k:k-1+m))];
+        k=k+m;
+    end
+
+    txt=[gettext("User variables are:");
+        '';
+        txt;
+        '';
+        msprintf(gettext("Using %s elements out of %s"),string(sum(mem)), string(st(1)-(st(2)-sum(mem))))]
+    write(%io(2),txt,'(1x,a)')
 endfunction
index 9554419..6ade5aa 100644 (file)
@@ -71,7 +71,7 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
 
     SciErr sciErr;
 
-    CheckInputArgumentAtLeast(pvApiCtx, 2);
+    CheckInputArgumentAtLeast(pvApiCtx, 1);
     CheckLhs(0, 1);
 
     pstNameList = (char**)MALLOC(sizeof(char*) * Rhs);
@@ -82,6 +82,29 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
         return 1;
     }
 
+    //if(Rhs == 1)
+    //{
+    //    pstFileName = expandPathVariable(pstNameList[0]);
+    //    int iH5File = createHDF5File(pstFileName);
+
+    //    if (iH5File < 0)
+    //    {
+    //        FREE(pstFileName);
+    //        if (iH5File == -2)
+    //        {
+    //            Scierror(999, _("%s: Wrong value for input argument #%d: \"%s\" is a directory"), fname, 1, pstNameList[0]);
+    //        }
+    //        else
+    //        {
+    //            Scierror(999, _("%s: Cannot open file %s.\n"), fname, pstNameList[0]);
+    //        }
+
+    //        return 1;
+    //    }
+
+    //}
+
+
     piAddrList = (int**)MALLOC(sizeof(int*) * (iNbVar));
     for (int i = 1 ; i < Rhs ; i++)
     {
@@ -191,7 +214,7 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
         }
     }
 
-    if (bExport)
+    if (bExport && Rhs != 1)
     {
         //add or update scilab version and file version in hdf5 file
         if (updateScilabVersion(iH5File) < 0)
@@ -209,7 +232,7 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
 
     //close hdf5 file
     closeHDF5File(iH5File);
-    if (bExport == false)
+    if (bExport == false && Rhs != 1)
     {
         //remove file
         deleteafile(pstFileName);
@@ -225,7 +248,7 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
         return 1;
     }
 
-    if (bExport == true)
+    if (bExport == true || Rhs == 1)
     {
         piReturn[0] = 1;
     }
index a8a2fe5..ac88dd2 100644 (file)
@@ -8,4 +8,5 @@ EXPORTS
 getScilabMode
 callFunctionFromGateway
 com_
+vstk_
 freeArrayOfString
\ No newline at end of file
index 39f6211..7d649f4 100644 (file)
@@ -7,8 +7,10 @@
 // are also available at    
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
+//2012/08/06 transform macros to string to save it
+
 //called by save function, transform handle in tlist and save result
-function [] = %_save(filename, varargin)
+function [] = %_save(%__filename__, varargin)
 
     function result = isList(var)
 
@@ -22,16 +24,34 @@ function [] = %_save(filename, varargin)
         end
     endfunction
 
+    function result = isMacro(var)
+        //11 : sci_u_function
+        if or(type(var) == [11]) then
+            result  = %t;
+        else
+            result = %f;
+        end
+    endfunction
+
+    function result = isCompiledMacro(var)
+        //11 : sci_c_function
+        if or(type(var) == [13]) then
+            result  = %t;
+        else
+            result = %f;
+        end
+    endfunction
+
     function result = inspectList(l)
     if typeof(l)=="list" then
         result = list();
-        for i = definedfields(l)
-            if typeof(l(i)) == "handle" then
-                result(i) = extractMatrixHandle(l(i));
-            elseif isList(l(i)) then
-                result(i) = inspectList(l(i));
+        for %__i__ = definedfields(l)
+            if typeof(l(%__i__)) == "handle" then
+                result(%__i__) = extractMatrixHandle(l(%__i__));
+            elseif isList(l(%__i__)) then
+                result(%__i__) = inspectList(l(%__i__));
             else
-                result(i) = l(i);
+                result(%__i__) = l(%__i__);
             end
         end
     else
@@ -59,8 +79,8 @@ function [] = %_save(filename, varargin)
         matrixHandle = tlist(["ScilabMatrixHandle", "dims", "values"]);
         matrixHandle.dims = size(h);
         matrixHandle.values = list();
-        for i = 1:size(h, "*")
-            matrixHandle.values($+1) = extractSingleHandle(h(i));
+        for %__i__ = 1:size(h, "*")
+            matrixHandle.values($+1) = extractSingleHandle(h(%__i__));
             if or(fieldnames(matrixHandle.values($))=="user_data") then // TODO Remove after graphic branch merge
                 if isList(matrixHandle.values($).user_data) then
                     matrixHandle.values($).user_data = inspectList(matrixHandle.values($).user_data)
@@ -152,11 +172,11 @@ function [] = %_save(filename, varargin)
             
         fields = fieldnames(returnedFigure);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "children" then
-                returnedFigure(fields(i)) = extractMatrixHandle(h(fields(i)));
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "children" then
+                returnedFigure(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
             else
-                returnedFigure(fields(i)) = h(fields(i));
+                returnedFigure(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -184,8 +204,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedLabel);
 
-        for i = 1:size(fields, "*")
-            returnedLabel(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedLabel(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -200,8 +220,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedTicks);
 
-        for i = 1:size(fields, "*")
-            returnedTicks(fields(i)) = ticks(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedTicks(fields(%__i__)) = ticks(fields(%__i__));
         end
     endfunction
 
@@ -267,15 +287,15 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedAxes);
 
-        for i = 1:size(fields, "*")
-            if or(fields(i) == ["title","x_label","y_label","z_label"]) then
-                returnedAxes(fields(i)) = extractLabel(h(fields(i)));
-            elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then
-                returnedAxes(fields(i)) = extractTicks(h(fields(i)));
-            elseif fields(i) == "children" then
-                returnedAxes(fields(i)) = extractMatrixHandle(h(fields(i)));
+        for %__i__ = 1:size(fields, "*")
+            if or(fields(%__i__) == ["title","x_label","y_label","z_label"]) then
+                returnedAxes(fields(%__i__)) = extractLabel(h(fields(%__i__)));
+            elseif or(fields(%__i__) == ["x_ticks", "y_ticks", "z_ticks"]) then
+                returnedAxes(fields(%__i__)) = extractTicks(h(fields(%__i__)));
+            elseif fields(%__i__) == "children" then
+                returnedAxes(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
             else
-                returnedAxes(fields(i)) = h(fields(i));
+                returnedAxes(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -316,8 +336,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedPolyline);
 
-        for i = 1:size(fields, "*")
-            returnedPolyline(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedPolyline(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -364,13 +384,13 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedSurface);
 
-        for i = 1:size(fields, "*")
-            if fields(i)=="cdata_mapping" then
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__)=="cdata_mapping" then
                 if h.type=="Fac3d" then
-                    returnedSurface(fields(i)) = h(fields(i));
+                    returnedSurface(fields(%__i__)) = h(fields(%__i__));
                 end
             else
-                returnedSurface(fields(i)) = h(fields(i));
+                returnedSurface(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -388,11 +408,11 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedCompound);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "children" then
-                returnedCompound(fields(i)) = extractMatrixHandle(h(fields(i)));
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "children" then
+                returnedCompound(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
             else
-                returnedCompound(fields(i)) = h(fields(i));
+                returnedCompound(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -424,8 +444,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedRectangle);
 
-        for i = 1:size(fields, "*")
-            returnedRectangle(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedRectangle(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -451,8 +471,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedArc);
 
-        for i = 1:size(fields, "*")
-            returnedArc(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedArc(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -475,8 +495,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedChamp);
 
-        for i = 1:size(fields, "*")
-            returnedChamp(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedChamp(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -505,8 +525,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedSeg);
 
-        for i = 1:size(fields, "*")
-            returnedSeg(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedSeg(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -526,8 +546,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedGrayplot);
 
-        for i = 1:size(fields, "*")
-            returnedGrayplot(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedGrayplot(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -546,8 +566,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedMatplot);
 
-        for i = 1:size(fields, "*")
-            returnedMatplot(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedMatplot(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -572,8 +592,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedFec);
 
-        for i = 1:size(fields, "*")
-            returnedFec(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedFec(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -605,17 +625,17 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedLegend);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "links" then
-                returnedLegend(fields(i)) = extractMatrixHandle(h(fields(i)));
-            elseif fields(i) == "paths" then
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "links" then
+                returnedLegend(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
+            elseif fields(%__i__) == "paths" then
                 p = list();
                 for kl=1:size(h.links,'*');
                     p($+1) = get_entity_path(h.links(kl));
                 end
-                returnedLegend(fields(i)) = p;
+                returnedLegend(fields(%__i__)) = p;
             else
-                returnedLegend(fields(i)) = h(fields(i));
+                returnedLegend(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -649,8 +669,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedText);
 
-        for i = 1:size(fields, "*")
-            returnedText(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedText(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -679,8 +699,8 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returnedAxis);
 
-        for i = 1:size(fields, "*")
-            returnedAxis(fields(i)) = h(fields(i));
+        for %__i__ = 1:size(fields, "*")
+            returnedAxis(fields(%__i__)) = h(fields(%__i__));
         end
     endfunction
 
@@ -704,11 +724,11 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returneduimenu);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "children" then
-                returneduimenu(fields(i)) = extractMatrixHandle(h(fields(i))($:-1:1));
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "children" then
+                returneduimenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))($:-1:1));
             else
-                returneduimenu(fields(i)) = h(fields(i));
+                returneduimenu(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -724,11 +744,11 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returneduicontextmenu);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "children" then
-                returneduicontextmenu(fields(i)) = extractMatrixHandle(h(fields(i))($:-1:1));
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "children" then
+                returneduicontextmenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))($:-1:1));
             else
-                returneduicontextmenu(fields(i)) = h(fields(i));
+                returneduicontextmenu(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -770,11 +790,11 @@ function [] = %_save(filename, varargin)
 
         fields = fieldnames(returneduicontrol);
 
-        for i = 1:size(fields, "*")
-            if fields(i) == "children" then
-                returneduicontrol(fields(i)) = extractMatrixHandle(h(fields(i))($:-1:1));
+        for %__i__ = 1:size(fields, "*")
+            if fields(%__i__) == "children" then
+                returneduicontrol(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__))($:-1:1));
             else
-                returneduicontrol(fields(i)) = h(fields(i));
+                returneduicontrol(fields(%__i__)) = h(fields(%__i__));
             end
         end
     endfunction
@@ -800,29 +820,100 @@ function [] = %_save(filename, varargin)
         parent=e.parent;
     end
     endfunction
-    varList = list();
-    for i = 1:size(varargin)
 
-        if varargin(i) == "-append" then
+    function macro = extractMacro(macroPtr, macroName)
+        macroSt = fun2string(macroPtr, macroName);
+        oldMode = warning("query");
+        warning("off");
+        macro = tlist("ScilabMacro", isCompiledMacro(macroPtr), macroSt);
+        warning(oldMode);
+    endfunction
+
+    //main
+
+    //save environment
+    if size(varargin) == 0 then
+        %__excludeList__ = [
+            "%_save"
+            "isList"
+            "isMacro"
+            "isCompiledMacro"
+            "inspectList"
+            "extractMatrixHandle"
+            "extractSingleHandle"
+            "extractFigure"
+            "extractLabel"
+            "extractTicks"
+            "extractAxes"
+            "extractPolyline"
+            "extractPlot3d"
+            "extractFac3d"
+            "extractSurface"
+            "extractCompound"
+            "extractRectangle"
+            "extractArc"
+            "extractChamp"
+            "extractSegs"
+            "extractGrayplot"
+            "extractMatplot"
+            "extractFec"
+            "extractLegend"
+            "extractText"
+            "extractAxis"
+            "extractuimenu"
+            "extractuicontextmenu"
+            "extractuicontrol"
+            "get_entity_path"
+            "extractMacro"
+            "%__excludeList__"
+            "%__filename__"
+            "varargin"
+            "%__varList__"];
+
+        //get all user variables
+        %__varList__ = who_user(%f);
+        //remove exclude variables/functions
+        %__grepResult__ = grep(%__varList__, %__excludeList__);
+        %__varList__(%__grepResult__) = [];
+        for %__i__ = 1:size(%__varList__, "*")
+            //store them as input arguments
+            varargin(%__i__) = %__varList__(%__i__);
+        end
+    end
+
+    oldMode = warning("query");
+    warning("off");
+
+    if size(varargin) == 0 then
+    end
+
+    for %__i__ = 1:size(varargin)
+
+        if varargin(%__i__) == "-append" then
             continue;
         end
 
-        temp = evstr(varargin(i));
+        temp = evstr(varargin(%__i__));
 
         if isList(temp) then
             //list container
             value = inspectList(temp);
             //update 
-            execstr(varargin(i) + " = value");
+            execstr(varargin(%__i__) + " = value");
         elseif typeof(temp) == "handle" then
             //convert handle to tlist
             value = extractMatrixHandle(temp);
             //update 
-            execstr(varargin(i) + " = value");
+            execstr(varargin(%__i__) + " = value");
+        elseif isMacro(temp) | isCompiledMacro(temp) then
+            //convert macro to tlist
+            value = extractMacro(temp, varargin(%__i__));
+            //update 
+            execstr(varargin(%__i__) + " = value");
         end
     end
+    warning(oldMode);
 
-    result = export_to_hdf5(filename, varargin(:));
+    result = export_to_hdf5(%__filename__, varargin(:));
 
 endfunction
-
index a6b1fac..b2edf53 100644 (file)
 
 function %_sodload(%__filename__, varargin)
 
-function [varValues] = %__convertHandles__(varValues)
+    function [varValues] = %__convertVariable__(varValues, varNames)
         for i = 1:size(varValues)
             if typeof(varValues(i)) == "ScilabMatrixHandle" then
-                //convert handle to tlist
+                //convert tlist to handle
                 varValues(i) = createMatrixHandle(varValues(i));
+            elseif typeof(varValues(i)) == "ScilabMacro" then
+                //convert tlist to macro
+                varValues(i) = createMacro(varValues(i), varNames(i));
             elseif isList(varValues(i)) then
                 //list container
                 varValues(i) = parseList(varValues(i));
@@ -758,6 +761,21 @@ function [varValues] = %__convertHandles__(varValues)
         end
     endfunction
 
+    function macro = createMacro(macroStr, macroName)
+        macroSt = macroStr(3);
+        if macroStr(2) == %t then
+            flag = "c";
+        else
+            flag = "n";
+        end
+        header = strsubst(macroSt(1), "function ", "");
+        body = macroSt(2:$-1);
+        if body == [] then
+            body = "";
+        end
+        deff(header, body, flag);
+        execstr("macro = " + macroName);
+    endfunction
 
     [%__lhs__, %__rhs__] = argn();
     %__resumeList__ = list();
@@ -807,7 +825,7 @@ function [varValues] = %__convertHandles__(varValues)
     end
 
     if isfile(%__filename__) & is_hdf5_file(%__filename__) then
-        %__resumeList__ = %__convertHandles__(%__resumeList__);
+        %__resumeList__ = %__convertVariable__(%__resumeList__, %__resumeVarlist__);
     end
 
     execstr("[" + strcat(%__resumeVarlist__, ",") + "] = resume(%__resumeList__(:))");
index 9dd796e..894a514 100644 (file)
@@ -119,17 +119,10 @@ int sci_save(char *fname, unsigned long fname_len)
 
                 freeAllocatedSingleString(pstVarI);
             }
-
-            if(iOldSave == FALSE)
-            {
-                int lw = 0;
-                //call "overload" to prepare data to export_to_hdf5 function.
-                C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
-            }
         }
         else
         {
-            iOldSave = TRUE;
+            iOldSave = FALSE;
         }
     }
     else
@@ -137,6 +130,13 @@ int sci_save(char *fname, unsigned long fname_len)
         iOldSave = TRUE;
     }
 
+    //new save to sod format
+    if(iOldSave == FALSE)
+    {
+        int lw = 0;
+        //call "overload" to prepare data to export_to_hdf5 function.
+        C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
+    }
 
     //old save
 
index 9c58957..33abc2c 100644 (file)
@@ -119,3 +119,20 @@ deff('d()','x=n+1','n');
 if ~Check(a,b) then bugmes();quit;end
 if ~Check(a,b,c) then bugmes();quit;end
 if ~Check(a,b,c,d) then bugmes();quit;end
+//test save/load macro
+function a = toto(x,y)
+    a = x + y;
+endfunction
+ref = toto(3*5, 9*3);
+save(TMPDIR + "/savemacro.sod", "toto");
+clear toto;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(toto(3*5, 9*3), ref);
+assert_checkequal(type(toto), 13);
+clear toto;
+deff("a = toto(x,y)", "a = x + y;", "n");
+save(TMPDIR + "/savemacro.sod", "toto");
+clear toto;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(toto(3*5, 9*3), ref);
+assert_checkequal(type(toto), 11);
index da54d6f..5cbe1e2 100644 (file)
@@ -151,3 +151,26 @@ deff('d()','x=n+1','n');
 if ~Check(a,b) then pause,end
 if ~Check(a,b,c) then pause,end
 if ~Check(a,b,c,d) then pause,end
+
+//test save/load macro
+function a = toto(x,y)
+    a = x + y;
+endfunction
+
+ref = toto(3*5, 9*3);
+save(TMPDIR + "/savemacro.sod", "toto");
+clear toto;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(toto(3*5, 9*3), ref);
+assert_checkequal(type(toto), 13);
+
+clear toto;
+deff("a = toto(x,y)", "a = x + y;", "n");
+save(TMPDIR + "/savemacro.sod", "toto");
+clear toto;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(toto(3*5, 9*3), ref);
+assert_checkequal(type(toto), 11);
+
+
+