predef('names') returns names of predef variables 96/4796/4
Allan CORNET [Wed, 31 Aug 2011 12:56:34 +0000 (14:56 +0200)]
Change-Id: I8e13951b5f5617771835bc56b677bb208cf692f2

12 files changed:
SEP/INDEX
SEP/SEP_069_extends_predef_names.odt [new file with mode: 0644]
scilab/CHANGES_5.4.X
scilab/modules/core/help/en_US/predef.xml
scilab/modules/core/help/fr_FR/predef.xml
scilab/modules/core/help/ja_JP/predef.xml
scilab/modules/core/help/pt_BR/predef.xml
scilab/modules/core/sci_gateway/c/sci_predef.c
scilab/modules/core/src/c/predef.c
scilab/modules/core/src/c/predef.h
scilab/modules/core/tests/unit_tests/predef_names.dia.ref [new file with mode: 0644]
scilab/modules/core/tests/unit_tests/predef_names.tst [new file with mode: 0644]

index e2f3216..e1363fb 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -63,4 +63,6 @@ SEP #063: User block wizard
 SEP #064: HDF5 Scilab specification
 SEP #065: load and save based on HDF5
 SEP #066: Xcos compilation hooks
-SEP #067: lines() default value
\ No newline at end of file
+SEP #067: lines() default value
+SEP #068: Tempname
+SEP #069: Extend predef to get protected variable names
\ No newline at end of file
diff --git a/SEP/SEP_069_extends_predef_names.odt b/SEP/SEP_069_extends_predef_names.odt
new file mode 100644 (file)
index 0000000..db32e4d
Binary files /dev/null and b/SEP/SEP_069_extends_predef_names.odt differ
index bdd976a..ab8eeb8 100644 (file)
@@ -231,6 +231,7 @@ Documentation:
 
 * Bug 9790 fixed - windows_tools help were not available on all platforms.
 
+
 Removed functions (previously declared as obsolete):
 ====================================================
 
@@ -281,7 +282,6 @@ Compilation:
 Graphics:
 =========
 
-
 * bug 9330 fixed - delete() called overloading instead of deleting the current
                    graphic entity.
 
@@ -295,12 +295,13 @@ ATOMS:
 
 * bug 8664 fixed - Message error updated for non supported OS.
 
-* bug 9127 fixed - "Home" item renamed to "Installed Modules".
+* bug 8763 fixed - ATOMS installation path was shared on Windows 64 with 32 bits.
 
-* bug 9805 fixed - atomsSystemUpdate() failed on some Windows.
+* bug 9127 fixed - "Home" item renamed to "Installed Modules".
 
+* bug 9679 fixed - atomsSystemUpdate checks that Scilab is not in offLine mode, else writes a message.
 
-* bug 8763 fixed - ATOMS installation path was shared on Windows 64 with 32 bits.
+* bug 9805 fixed - atomsSystemUpdate() failed on some Windows.
 
 
 Javasci:
@@ -315,14 +316,12 @@ returns the value of the ScilabTypeEnum enum.
                    EDT was crashing the execution of a java program.
 
 
-* bug 9679 fixed - atomsSystemUpdate checks that Scilab is not in offLine mode, else writes a message.
-
 Misc:
 =====
 
 * Change the buffering display mode.
 
-* SEP 67: lines(0) by default at startup.
+* SEP #67: lines(0) by default at startup.
 
 * Options -disable-exception-catching added under GNU/Linux & Mac OS X.
   Disables the Scilab exception catching system.
@@ -330,6 +329,8 @@ Misc:
 * PVM module moved as ATOMS module.
   atomsInstall('PVM')
 
+* SEP #69: predef('names') returns names of protected variables by predef.
+
 
 Bug fixes:
 ==========
index 569f924..821688c 100644 (file)
@@ -9,10 +9,12 @@
   </refnamediv>
   <refsynopsisdiv>
     <title>Calling Sequence</title>
-    <synopsis>n=predef()
-oldnew=predef(n)
-oldnew=predef('all')
-oldnew=predef('clear')</synopsis>
+    <synopsis>n = predef()
+oldnew = predef(n)
+oldnew = predef('all')
+oldnew = predef('clear')
+variables_name = predef('names')
+</synopsis>
   </refsynopsisdiv>
   <refsection>
     <title>Description</title>
@@ -28,6 +30,7 @@ oldnew=predef('clear')</synopsis>
     the old and new value of protected variables number.</para>
     <para><literal>predef(n)</literal> sets the <literal>max(n,7)</literal> last defined variables as protected, it also return
     the old and new value of protected variables number.</para>
+    <para><literal>predef('names')</literal> returns a vector of strings with the name of protected variables.</para>
   </refsection>
   <refsection>
     <title>Remarks:</title>
index 005a55a..6062dd3 100644 (file)
@@ -9,10 +9,12 @@
   </refnamediv>
   <refsynopsisdiv>
     <title>Séquence d'appel</title>
-    <synopsis>n=predef()
-oldnew=predef(n)
-oldnew=predef('all')
-oldnew=predef('clear')</synopsis>
+    <synopsis>n = predef()
+oldnew = predef(n)
+oldnew = predef('all')
+oldnew = predef('clear')
+variables_name = predef('names')
+</synopsis>
   </refsynopsisdiv>
   <refsection>
     <title>Description</title>
@@ -37,6 +39,7 @@ oldnew=predef('clear')</synopsis>
       définies dernièrement. Renvoie l'ancien et le nouveau nombre de
       variables protégées.
     </para>
+    <para><literal>predef('names')</literal> retourne un vecteur de chaines de caracteres contenant les noms des variables protegées par predef.</para>
     <para>
     </para>
   </refsection>
index ffaca89..2151e62 100644 (file)
@@ -9,10 +9,12 @@
   </refnamediv>
   <refsynopsisdiv>
     <title>呼出し手順</title>
-    <synopsis>n=predef()
-oldnew=predef(n)
-oldnew=predef('all')
-oldnew=predef('clear')</synopsis>
+    <synopsis>n = predef()
+oldnew = predef(n)
+oldnew = predef('all')
+oldnew = predef('clear')
+variables_name = predef('names')
+</synopsis>
   </refsynopsisdiv>
   <refsection>
     <title>説明</title>
index 7152278..9dc71bd 100644 (file)
   <refsynopsisdiv>
     <title>Seqüência de Chamamento</title>
 
-    <synopsis>n=predef()
-oldnew=predef(n)
-oldnew=predef('all')
-oldnew=predef('clear')</synopsis>
+    <synopsis>n = predef()
+oldnew = predef(n)
+oldnew = predef('all')
+oldnew = predef('clear')
+variables_name = predef('names')</synopsis>
   </refsynopsisdiv>
 
   <refsection>
index 16cf8c1..4a54214 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2006 - INRIA - Allan Cornet
+ * Copyright (C) 2011 - DIGITEO - Allan CORNET
  * 
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
  */
 #include "gw_core.h"
 #include "stack-c.h"
+#include "api_scilab.h"
 #include "localization.h"
 #include "Scierror.h"
 #include "predef.h"
 #include "MALLOC.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
 int C2F(sci_predef)(char *fname,unsigned long fname_len)
 {
-       int previous_n_var_protected = 0;
+    int previous_n_var_protected = 0;
 
-       Rhs = Max(0, Rhs);
+    Rhs = Max(0, Rhs);
 
-       CheckRhs(0,1);
-       CheckLhs(0,1);
+    CheckRhs(0,1);
+    CheckLhs(0,1);
 
-       previous_n_var_protected = getNumberPredefVariablesProtected();
+    previous_n_var_protected = getNumberPredefVariablesProtected();
 
-       if (Rhs == 0)
-       {
-               int one = 1 ,l = 0;
+    if (Rhs == 0)
+    {
+        int one = 1 ,l = 0;
 
-               CreateVar(Rhs+1, MATRIX_OF_INTEGER_DATATYPE, &one, &one,&l);
-               *istk(l) = (int) previous_n_var_protected;
+        CreateVar(Rhs+1, MATRIX_OF_INTEGER_DATATYPE, &one, &one,&l);
+        *istk(l) = (int) previous_n_var_protected;
 
-               LhsVar(1) = Rhs + 1;
-               PutLhsVar();
-       }
-       else /* Rhs == 1 */
-       {
-               int *out_values = NULL;
-               int nout = 0 , mout = 0;
-               int new_n_var_protected = 0;
+        LhsVar(1) = Rhs + 1;
+        PutLhsVar();
+    }
+    else /* Rhs == 1 */
+    {
+        int *out_values = NULL;
+        int nout = 0 , mout = 0;
+        int new_n_var_protected = 0;
 
-               if ( VarType(1) == sci_matrix )
-               {
-                       int m1 = 0, n1 = 0, l1 = 0;
-                       GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
-                       if ( (m1 == n1) && (n1 == 1) )
-                       {
-                               double dn_var = *stk(l1);
-                               int n_var = (int) dn_var;
+        if ( VarType(1) == sci_matrix )
+        {
+            int m1 = 0, n1 = 0, l1 = 0;
+            GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
+            if ( (m1 == n1) && (n1 == 1) )
+            {
+                double dn_var = *stk(l1);
+                int n_var = (int) dn_var;
 
-                               if (dn_var != (double)n_var)
-                               {
-                                       Scierror(999,_("%s: Wrong value for input argument #%d: A int expected.\n"),fname,1);
-                                       return 0;
-                               }
+                if (dn_var != (double)n_var)
+                {
+                    Scierror(999,_("%s: Wrong value for input argument #%d: A int expected.\n"),fname,1);
+                    return 0;
+                }
 
-                               setNumberPredefVariablesProtected(n_var);
-                       }
-                       else
-                       {
-                               Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
-                               return 0;
-                       }
-               }
-               else if ( VarType(1) == sci_strings )
-               {       
-                       int m1 = 0, n1 = 0, l1 = 0;
-                       char *protectMode = NULL;
+                setNumberPredefVariablesProtected(n_var);
+            }
+            else
+            {
+                Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
+                return 0;
+            }
+        }
+        else if ( VarType(1) == sci_strings )
+        {      
+            int m1 = 0, n1 = 0, l1 = 0;
+            char *protectMode = NULL;
 
-                       GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-                       protectMode = cstk(l1);
-                       if (protectMode)
-                       {
-                               if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'c')) ||
-                                       (strcmp(protectMode,"clear") == 0) )
-                               {
-                                       clearPredef();
-                               }
-                               else if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'a')) ||
-                                       (strcmp(protectMode,"all") == 0) )
-                               {
-                                       predefAll();
-                               }
-                               else
-                               {
-                                       Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname,1,"clear","all");
-                                       return 0;
-                               }
-                       }
-               }
-               else
-               {
-                       Scierror(999,_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),fname,1);
-                       return 0;
-               }
+            GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
+            protectMode = cstk(l1);
+            if (protectMode)
+            {
+                if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'c')) ||
+                    (strcmp(protectMode,"clear") == 0) )
+                {
+                    clearPredef();
+                }
+                else if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'a')) ||
+                    (strcmp(protectMode,"all") == 0) )
+                {
+                    predefAll();
+                }
+                else if (strcmp(protectMode,"names") == 0)
+                {
+                    int nbElements = 0;
+                    char **variablesPredef = getPredefinedVariablesName(&nbElements);
+                    if (variablesPredef && (nbElements > 0))
+                    {
+                        SciErr sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, nbElements, 1, variablesPredef);
+                        freeArrayOfString(variablesPredef, nbElements);
+                        variablesPredef = NULL;
+                        if(sciErr.iErr)
+                        {
+                            printError(&sciErr, 0);
+                        }
+                        else
+                        {
+                            LhsVar(1) = Rhs + 1;
+                            PutLhsVar();
+                        }
+                        return 0;
+                    }
+                    else
+                    {
+                        createEmptyMatrix(pvApiCtx, Rhs + 1);
+                        LhsVar(1) = Rhs + 1;
+                        PutLhsVar();
+                        return 0;
+                    }
+                }
+                else
+                {
+                    Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname,1,"clear","all");
+                    return 0;
+                }
+            }
+        }
+        else
+        {
+            Scierror(999,_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),fname,1);
+            return 0;
+        }
 
-               new_n_var_protected = getNumberPredefVariablesProtected();
+        new_n_var_protected = getNumberPredefVariablesProtected();
 
-               out_values = (int*)MALLOC(sizeof(int)*2);
-               out_values[0] = previous_n_var_protected;
-               out_values[1] = new_n_var_protected;
+        out_values = (int*)MALLOC(sizeof(int)*2);
+        out_values[0] = previous_n_var_protected;
+        out_values[1] = new_n_var_protected;
 
-               nout = 1 ; mout = 2;
-               CreateVarFromPtr(Rhs+1,MATRIX_OF_INTEGER_DATATYPE, &nout, &mout, &out_values);
-               if (out_values) {FREE(out_values); out_values = NULL;}
+        nout = 1 ; mout = 2;
+        CreateVarFromPtr(Rhs+1,MATRIX_OF_INTEGER_DATATYPE, &nout, &mout, &out_values);
+        if (out_values) {FREE(out_values); out_values = NULL;}
 
-               LhsVar(1) = Rhs + 1;
-               PutLhsVar();
-       }
-       return 0;
+        LhsVar(1) = Rhs + 1;
+        PutLhsVar();
+    }
+    return 0;
 }
 /*--------------------------------------------------------------------------*/
index 06ee584..7a5b77f 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2009 - DIGITEO - Allan CORNET
+* Copyright (C) 2009-2011 - DIGITEO - Allan CORNET
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 /*--------------------------------------------------------------------------*/
 #include <string.h>
 #include "predef.h"
+#include "api_scilab.h"
 #include "stackinfo.h"
 #include "stack-def.h"
 #include "core_math.h"
 #include "MALLOC.h"
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
 /*--------------------------------------------------------------------------*/
 int getNumberPredefVariablesProtected(void)
 {
-       return (C2F(vstk).isiz - C2F(vstk).bbot);
+    return (C2F(vstk).isiz - C2F(vstk).bbot);
 }
 /*--------------------------------------------------------------------------*/
 void setNumberPredefVariablesProtected(int nb)
 {
-       int new_value = Max( C2F(vstk).bot , Min( (C2F(vstk).isiz - nb), C2F(vstk).bot0 ) );
-       if ( C2F(vstk).bbot != new_value ) C2F(vstk).bbot = new_value;
+    int new_value = Max( C2F(vstk).bot , Min( (C2F(vstk).isiz - nb), C2F(vstk).bot0 ) );
+    if ( C2F(vstk).bbot != new_value ) C2F(vstk).bbot = new_value;
 }
 /*--------------------------------------------------------------------------*/
 void clearPredef(void)
 {
-       if ( C2F(vstk).bbot != C2F(vstk).bot0 ) C2F(vstk).bbot = C2F(vstk).bot0;
+    if ( C2F(vstk).bbot != C2F(vstk).bot0 ) C2F(vstk).bbot = C2F(vstk).bot0;
 }
 /*--------------------------------------------------------------------------*/
 void predefAll(void)
 {
-       if (C2F(vstk).bbot != C2F(vstk).bot)
-       {
-               /* bug 3773 */
-               /* "ans" must not be protected */
-               char *FirstNameVariableOnStack = getLocalNamefromId(1);
-
-               if (FirstNameVariableOnStack)
-               {
-                       if (strcmp(FirstNameVariableOnStack, "ans") == 0)
-                       {
-                               /* protect variable after "ans" */
-                               C2F(vstk).bbot = C2F(vstk).bot + 1;
-                       }
-                       else
-                       {
-                               C2F(vstk).bbot = C2F(vstk).bot;
-                       }
-                       FREE(FirstNameVariableOnStack);
-               }
-               else
-               {
-                       C2F(vstk).bbot = C2F(vstk).bot;
-               }
-       }
+    if (C2F(vstk).bbot != C2F(vstk).bot)
+    {
+        /* bug 3773 */
+        /* "ans" must not be protected */
+        char *FirstNameVariableOnStack = getLocalNamefromId(1);
+
+        if (FirstNameVariableOnStack)
+        {
+            if (strcmp(FirstNameVariableOnStack, "ans") == 0)
+            {
+                /* protect variable after "ans" */
+                C2F(vstk).bbot = C2F(vstk).bot + 1;
+            }
+            else
+            {
+                C2F(vstk).bbot = C2F(vstk).bot;
+            }
+            FREE(FirstNameVariableOnStack);
+        }
+        else
+        {
+            C2F(vstk).bbot = C2F(vstk).bot;
+        }
+    }
+}
+/*--------------------------------------------------------------------------*/
+BOOL isPredefinedVariable(const char *variablename)
+{
+    if (!isNamedVarExist(pvApiCtx, variablename))
+    {
+        int nbPredefined = getNumberPredefVariablesProtected() - 1; // remove ans
+        if (nbPredefined > 0)
+        {
+            int i = 0;
+            int Ltotal = 0;
+            int Lused = 0;
+
+            C2F(getvariablesinfo)(&Ltotal, &Lused);
+
+            for(i = 0; i < nbPredefined; i++)
+            {
+                char *varname = getLocalNamefromId(Lused - i - 1);
+                if (varname)
+                {
+                    if (strcmp(variablename, varname) == 0)
+                    {
+                        FREE(varname);
+                        varname = NULL;
+                        return TRUE;
+                    }
+                    FREE(varname);
+                    varname = NULL;
+                }
+            }
+        }
+    }
+    return FALSE;
+}
+/*--------------------------------------------------------------------------*/
+char **getPredefinedVariablesName(int *iReturnedSize)
+{
+    char **variablesName = NULL;
+    int nbPredefined = 0;
+
+    *iReturnedSize = 0;
+
+    nbPredefined = getNumberPredefVariablesProtected() - 1; // remove ans
+    if (nbPredefined > 0)
+    {
+        int Ltotal = 0;
+        int Lused = 0;
+
+        C2F(getvariablesinfo)(&Ltotal, &Lused);
+
+        variablesName = (char**)MALLOC(sizeof(char*) * nbPredefined);
+        if (variablesName)
+        {
+            int i = 0;
+
+            for(i = 0; i < nbPredefined; i++)
+            {
+                variablesName[i] = getLocalNamefromId(Lused - i - 1);
+            }
+            *iReturnedSize = nbPredefined;
+        }
+    }
+    return variablesName;
 }
 /*--------------------------------------------------------------------------*/
index f772116..3e4b055 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2009 - DIGITEO - Allan CORNET
+* Copyright (C) 2009-2011 - DIGITEO - Allan CORNET
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
@@ -15,6 +15,8 @@
 #ifndef __PREDEF_H__
 #define __PREDEF_H__
 
+#include "BOOL.h"
+
 /**
 * get the number of protected variables
 * @return number of protected variables
@@ -37,5 +39,19 @@ void clearPredef(void);
 */
 void predefAll(void);
 
+/**
+* check if variable name is a predefined variable
+* @param[in] variable name
+* @return TRUE (protected) or FALSE
+*/
+BOOL isPredefinedVariable(const char *variablename);
+
+/**
+* get variables name protected by predef
+* @param[out] size of returned array
+* @return array of strings predef variable
+*/
+char **getPredefinedVariablesName(int *iReturnedSize);
+
 #endif /* __PREDEF_H__ */
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/tests/unit_tests/predef_names.dia.ref b/scilab/modules/core/tests/unit_tests/predef_names.dia.ref
new file mode 100644 (file)
index 0000000..37d1bbb
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JVM NOT MANDATORY -->
+//
+variables_names_1 = predef('names');
+assert_checkequal(size(grep(variables_names_1,'SCI'), '*') <> [], %t);
+assert_checkequal(size(grep(variables_names_1,'corelib'), '*'), 1);
+clear
+// we add 3 variables
+toto_1 = 1;
+toto_2 = 1;
+toto_3 = 1;
+predef("all"); // and protect
+variables_names_2 = predef('names');
+ref = ["toto_1";
+       "toto_2";
+       "toto_3"];
+assert_checkequal(variables_names_2($-2:$), ref);
diff --git a/scilab/modules/core/tests/unit_tests/predef_names.tst b/scilab/modules/core/tests/unit_tests/predef_names.tst
new file mode 100644 (file)
index 0000000..c7335d3
--- /dev/null
@@ -0,0 +1,25 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JVM NOT MANDATORY -->
+//
+variables_names_1 = predef('names');
+assert_checkequal(size(grep(variables_names_1,'SCI'), '*') <> [], %t);
+assert_checkequal(size(grep(variables_names_1,'corelib'), '*'), 1);
+
+clear
+// we add 3 variables
+toto_1 = 1;
+toto_2 = 1;
+toto_3 = 1;
+
+predef("all"); // and protect
+variables_names_2 = predef('names');
+ref = ["toto_1";
+       "toto_2";
+       "toto_3"];
+assert_checkequal(variables_names_2($-2:$), ref);