bug 4278
Allan CORNET [Tue, 26 May 2009 15:03:20 +0000 (17:03 +0200)]
18 files changed:
scilab/CHANGES_5.2.X
scilab/modules/core/Makefile.am
scilab/modules/core/help/en_US/typename.xml
scilab/modules/core/help/fr_FR/typename.xml
scilab/modules/core/help/pt_BR/typename.xml
scilab/modules/core/includes/stackinfo.h
scilab/modules/core/sci_gateway/c/sci_type.c
scilab/modules/core/sci_gateway/c/sci_typename.c
scilab/modules/core/sci_gateway/fortran/sci_type.f [deleted file]
scilab/modules/core/sci_gateway/fortran/sci_typnam.f [deleted file]
scilab/modules/core/src/c/core.vcproj
scilab/modules/core/src/c/stackinfo.c
scilab/modules/core/src/c/typename.c [new file with mode: 0644]
scilab/modules/core/src/c/typename.h [new file with mode: 0644]
scilab/modules/core/src/fortran/core_f.vfproj
scilab/modules/core/src/fortran/core_f2c.vcproj
scilab/modules/core/tests/nonreg_tests/bug_4278.dia.ref [new file with mode: 0644]
scilab/modules/core/tests/nonreg_tests/bug_4278.tst [new file with mode: 0644]

index 16e84f2..9aa46b9 100644 (file)
@@ -57,6 +57,8 @@ Core functions:
  - Rewrite :
      + mode
      + predef
+     + type
+     + typename
 
 fileio functions:
 =================
@@ -150,6 +152,8 @@ Bug fixes:
 
 * bug 4267 fixed - A non initilization of a lock under Netbsd was 
                    causing an error on startup
+                   
+* bug 4278 fixed - typename() called with a wrong number of input arguments  returns incoherent errors.
 
 * bug 4307 fixed - Desactivate (in modules.xml) modules if its functionnalities
                    are not available.
index 53dac38..a3f4286 100644 (file)
@@ -89,7 +89,8 @@ src/c/poly_api.c \
 src/c/sparse_api.c \
 src/c/boolean_sparse_api.c \
 src/c/string_api.c \
-src/c/list_api.c
+src/c/list_api.c \
+src/c/typename.c
 
 
 
@@ -261,7 +262,8 @@ sci_gateway/c/sci_libraryinfo.c \
 sci_gateway/c/sci_getvariablesonstack.c \
 sci_gateway/c/sci_readgateway.c \
 sci_gateway/c/sci_comp.c \
-sci_gateway/c/sci_exit.c
+sci_gateway/c/sci_exit.c \
+sci_gateway/c/sci_typename.c
 
 GATEWAY_FORTRAN_SOURCES =  sci_gateway/fortran/sci_errclear.f \
 sci_gateway/fortran/sci_funcprot.f \
@@ -280,12 +282,10 @@ sci_gateway/fortran/sci_errcatch.f \
 sci_gateway/fortran/sci_clear.f \
 sci_gateway/fortran/sci_argn.f \
 sci_gateway/fortran/sci_setbpt.f \
-sci_gateway/fortran/sci_typnam.f \
 sci_gateway/fortran/sci_clearglobal.f \
 sci_gateway/fortran/sci_delbpt.f \
 sci_gateway/fortran/where.f \
 sci_gateway/fortran/sci_iserror.f \
-sci_gateway/fortran/sci_type.f \
 sci_gateway/fortran/sci_debug.f \
 sci_gateway/fortran/sci_comp.f \
 sci_gateway/fortran/sci_isglobal.f
index be531c3..3b10aef 100644 (file)
@@ -57,6 +57,9 @@ typename(name,type)</synopsis>
     to a data type code.</para>
     <para><literal>typename('',type)</literal> suppress the data type given by its code
     <literal>type</literal> out of the table of known data types.</para>
+    
+    <para>Number max. of defined types is 50.</para>
+    
   </refsection>
   <refsection>
     <title>See Also</title>
index 7491fda..cacb9c2 100644 (file)
@@ -60,6 +60,7 @@ typename(name,type)</synopsis>
   </para>
     <para><literal>typename('',type)</literal> supprime le type de donnée défini par le code passé dans <literal>type</literal> dans la table des types de variables connus.
   </para>
+  <para>Nombre max de types defini est 50.</para>
   </refsection>
   <refsection>
     <title>Voir Aussi</title>
index bf66406..27049e9 100644 (file)
@@ -83,6 +83,8 @@ typename(name,type)</synopsis>
     <para><literal>typename('',type)</literal> suprime o tipo de dado
     fornecido pelo seu código <literal>type</literal> de tabelas de tipos de
     dados conhecidos.</para>
+    
+    <para>Number max. of defined types is 50.</para>
   </refsection>
 
   <refsection>
index 4c29021..959a8e9 100644 (file)
@@ -92,6 +92,28 @@ int getLocalSizefromId(int n);
 */
 int getGlobalSizefromId(int n);
 
+/**
+* check if a variable named exists on scilab stack (local & global)
+* @param[in] variable name
+* @return BOOL : TRUE if variable exists
+*/
+BOOL existVariableNamedOnStack(char *varname);
+
+/**
+* check if a variable named exists on scilab stack (local)
+* @param[in] variable name
+* @return BOOL : TRUE if variable exists
+*/
+BOOL existLocalVariableNamedOnStack(char *varname);
+
+/**
+* check if a variable named exists on scilab stack (global)
+* @param[in] variable name
+* @return BOOL : TRUE if variable exists
+*/
+BOOL existGlobalVariableNamedOnStack(char *varname);
+
+
 #endif /*__STACKINFO_H__*/
 /*--------------------------------------------------------------------------*/ 
 
index 11aa75a..bc08ba7 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) 2009 - 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"
 /*--------------------------------------------------------------------------*/
-extern int C2F(inttype)(void);
-/*--------------------------------------------------------------------------*/
 int C2F(sci_type)(char *fname,unsigned long fname_len)
 {
-       C2F(inttype)();
+       int iType = 0;
+       int l = 0, lc = 0;
+       int one = 1;
+       int zero = 0;
+
+       CheckRhs(1,1);
+       CheckLhs(1,2); 
+       
+       iType = GetType(1);
+       if (! C2F(cremat)(fname, &Top, &zero, &one, &one, &l, &lc, fname_len)) return 0;
+       *stk(l) = (double) iType;
+
        return 0;
 }
 /*--------------------------------------------------------------------------*/
index b40b35d..a7a568b 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) 2009 - 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
  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
  *
  */
+/*--------------------------------------------------------------------------*/
 #include "gw_core.h"
 #include "stack-c.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "typename.h"
+#include "MALLOC.h"
+#include "common_api.h"
+#include "string_api.h"
+#include "double_api.h"
+#include "int_api.h"
+#include "freeArrayOfString.h"
 /*--------------------------------------------------------------------------*/
-extern int C2F(inttypnam)(char *fname,unsigned long fname_len);
+static int sci_typename_two_rhs(char *fname,unsigned long fname_len);
+static int sci_typename_no_rhs(char *fname,unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 int C2F(sci_typename)(char *fname,unsigned long fname_len)
 {
-       C2F(inttypnam)(fname,fname_len);
+       CheckLhs(1,2); 
+       switch (Rhs)
+       {
+       case 0:
+               sci_typename_no_rhs(fname,fname_len);
+               break;
+       case 2:
+               sci_typename_two_rhs(fname,fname_len);
+               break;
+       default:
+               Scierror(999,_("%s: Wrong number of input arguments: %d or %d expected.\n"),fname,0,2);
+               break;
+       }
+       return 0;
+}
+/*--------------------------------------------------------------------------*/
+int sci_typename_two_rhs(char *fname,unsigned long fname_len)
+{
+       int m1 = 0, n1 = 0;
+       int *piAddressVarOne = NULL;
+       char *pStVarOne = NULL;
+       int lenStVarOne = 0;
+
+       int m2 = 0, n2 = 0;
+       int *piAddressVarTwo = NULL;
+       double *pdVarTwo = NULL;
+
+       getVarAddressFromNumber(1, &piAddressVarOne);
+       getVarAddressFromNumber(2, &piAddressVarTwo);
+
+       if ( getVarType(piAddressVarOne) != sci_strings )
+       {
+               Scierror(999,"%s: Wrong type for input argument #%d: A string expected.\n",fname,1);
+               return 0;
+       }
+
+       if ( getVarType(piAddressVarTwo) != sci_matrix )
+       {
+               Scierror(999,"%s: Wrong type for input argument #%d: A scalar expected.\n",fname,2);
+               return 0;
+       }
+
+       getMatrixOfDouble(piAddressVarTwo,&m2,&n2,&pdVarTwo);
+       if ( (m2 != n2) && (n2 != 1) ) 
+       {
+               Scierror(999,"%s: Wrong size for input argument #%d: A scalar expected.\n",fname,2);
+               return 0;
+       }
+
+       getMatrixOfString(piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
+       if ( (m1 != n1) && (n1 != 1) ) 
+       {
+               Scierror(999,"%s: Wrong size for input argument #%d: A string expected.\n",fname,1);
+               return 0;
+       }
+       
+       pStVarOne = (char*)MALLOC(sizeof(char)*(lenStVarOne + 1));
+       getMatrixOfString(piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
+
+       if (pStVarOne)
+       {
+               int ierr = 0;
+               getMatrixOfString(piAddressVarOne,&m1,&n1,&lenStVarOne,&pStVarOne);
+               ierr = addNamedType(pStVarOne,(int)pdVarTwo[0]);
+
+               switch(ierr)
+               {
+               case -1 :
+                               Scierror(999,_("%s: '%s' already exists.\n"),fname,pStVarOne);
+                       break;
+               case 0:
+                               LhsVar(1) = 0; 
+                               C2F(putlhsvar)();
+                               break;
+                       break;
+
+               case 1: case 3:
+                               Error(224);
+                       break;
+
+               case 2:
+                               Error(225);
+                       break;
+
+               default:
+                       /* never here */
+                       Scierror(999,_("%s: Unknown Error.\n"),fname);
+                       break;
+               }
+
+               FREE(pStVarOne); pStVarOne = NULL;
+       }
+       else
+       {
+               Scierror(999,_("%s: No more memory.\n"),fname);
+       }
+       return 0;
+}
+/*--------------------------------------------------------------------------*/
+int sci_typename_no_rhs(char *fname,unsigned long fname_len)
+{
+       int numberOfTypes = 0;
+       int *TypesNumbers = NULL;
+       
+       int m_out1 = 0, n_out1 = 0;
+       int *piAddressOut1 = NULL;
+       
+       TypesNumbers = getAllTypesNumber(&numberOfTypes);
+       m_out1 = numberOfTypes;
+       n_out1 = 1;
+
+       createMatrixOfInteger32(Rhs + 1,m_out1,n_out1,TypesNumbers,&piAddressOut1);
+       if (TypesNumbers) { FREE(TypesNumbers);TypesNumbers = NULL;     }
+       LhsVar(1) = Rhs + 1; 
+
+       if (Lhs > 1)
+       {
+               int m_out2 = 0, n_out2 = 0;
+               int *piAddressOut2 = NULL;
+               char **TypesNames = NULL;
+
+               TypesNames = getAllTypesName(&numberOfTypes);
+               m_out2 = numberOfTypes;
+               n_out2 = 1;
+               
+               createMatrixOfString(Rhs + 2, m_out2, n_out2, TypesNames, &piAddressOut2);
+               if (TypesNames) freeArrayOfString(TypesNames,numberOfTypes);
+               LhsVar(2) = Rhs + 2; 
+       }
+       C2F(putlhsvar)();
+
        return 0;
 }
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/sci_gateway/fortran/sci_type.f b/scilab/modules/core/sci_gateway/fortran/sci_type.f
deleted file mode 100644 (file)
index 76a85cc..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-c Copyright (C) INRIA
-c 
-c This file must be used under the terms of the CeCILL.
-c This source file is licensed as described in the file COPYING, which
-c you should have received as part of this distribution.  The terms
-c are also available at    
-c http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-      subroutine inttype
-      include 'stack.h'
-      logical checkrhs,checklhs,cremat
-      integer iadr
-c    
-      iadr(l)=l+l-1
-c
-      if(.not.checklhs('type',1,1)) return
-      if(.not.checkrhs('type',1,1)) return
-
-
-      il=iadr(lstk(top))
-      if(istk(il).lt.0) il=iadr(istk(il+1))
-      k=istk(il)
-      if(.not.cremat('type',top,0,1,1,l,lc)) return
-      stk(l)=dble(k)
-      return
-      end
-      
diff --git a/scilab/modules/core/sci_gateway/fortran/sci_typnam.f b/scilab/modules/core/sci_gateway/fortran/sci_typnam.f
deleted file mode 100644 (file)
index ad69594..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-c Copyright (C) INRIA
-c 
-c This file must be used under the terms of the CeCILL.
-c This source file is licensed as described in the file COPYING, which
-c you should have received as part of this distribution.  The terms
-c are also available at    
-c http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-      subroutine inttypnam(fname)
-c     --------------------------
-      character*(*) fname
-      logical checkrhs,checklhs
-      include 'stack.h'
-      logical getscalar
-c     following common defines the initial database of type names
-      integer maxtyp,nmmax,ptmax
-      parameter (maxtyp=50,nmmax=200)
-      integer tp(maxtyp),ptr(maxtyp),ln(maxtyp),namrec(nmmax)
-      common /typnams/ tp,ptr,ln,namrec,ptmax
-C
-      integer iadr,sadr
-c
-      iadr(l)=l+l-1
-      sadr(l)=(l/2)+1
-C
-      nbvars = 0
-      rhs = max(0,rhs)
-      
-      if(rhs.eq.0) then
-         if(.not.checklhs(fname,1,2)) return
-c     compute number of defined types
-         nt=0
-         do 01 it=1,maxtyp
-            if(ln(it).ne.0) nt=nt+1
- 01      continue
-c     allocate results
-         top=top+1
-c     .  vector of type numbers
-         il=iadr(lstk(top))
-         l=sadr(il+4)
-         iln=iadr(l+nt)
-         lw1=sadr(iln+5+nt+ptmax)
-         err=lw1-lstk(bot)
-         if(err.gt.0) then
-            call error(17)
-            return
-         endif
-c
-         istk(il)=1
-         istk(il+1)=nt
-         istk(il+2)=1
-         istk(il+3)=0
-         lstk(top+1)=l+nt
-c
-         top=top+1
-c     .  vector of type names
-         iln=iadr(lstk(top))
-         istk(iln)=10
-         istk(iln+1)=nt
-         istk(iln+2)=1
-         istk(iln+3)=0
-         istk(iln+4)=1
-         ilc=iln+5+nt
-
-         i1=0
-
-         do 02 it=1,maxtyp
-            if(ln(it).ne.0) then
-               stk(l+i1)=tp(it)
-               istk(iln+5+i1)=istk(iln+4+i1)+ln(it)
-               call icopy(ln(it),namrec(ptr(it)),1,istk(ilc),1)
-               ilc=ilc+ln(it)
-               i1=i1+1
-            endif
- 02      continue
-         lstk(top+1)=sadr(ilc)
-         if(lhs.eq.1) top=top-1
-         return
-      endif
-c
-      if(.not.checkrhs(fname,0,2)) return
-      if(.not.checklhs(fname,0,1)) return
-      if(.not.getscalar(fname,top,top,lr)) return
-      itype=stk(lr)
-      if(itype.le.0) then
-         err=1
-         call error(116)
-         return
-      endif
-      top=top-1
-      il=iadr(lstk(top))
-      if(istk(il).ne.10) then
-         err=1
-         call error(55)
-         return
-      endif
-      if(istk(il+1).ne.1.or.istk(il+2).ne.1) then 
-         err=1
-         call error(60)
-         return
-      endif
-      n=istk(il+5)-1
-      call cvstr(n,istk(il+6),buf,1)
-
-      call addtypename(itype,buf(1:n),ierr)
-      if(ierr.eq.1) then
-         call error(224)
-         return
-      elseif(ierr.eq.2) then
-         call error(225)
-         return
-      elseif(ierr.eq.3) then
-         call error(224)
-         return
-      endif
-      istk(il)=0
-      return
-      end
index c683803..d790d9b 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\typename.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\version.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\typename.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\userf2.h"
                                >
                        </File>
index be5bb7f..5a47c8a 100644 (file)
@@ -202,3 +202,72 @@ static void cleanFortranString(char *fortanbuffer)
        }
 }
 /*--------------------------------------------------------------------------*/
+BOOL existVariableNamedOnStack(char *varname)
+{
+       if (existLocalVariableNamedOnStack(varname) || 
+               existGlobalVariableNamedOnStack(varname) )
+       {
+               return TRUE;
+       }
+       return FALSE;
+}
+/*--------------------------------------------------------------------------*/
+BOOL existLocalVariableNamedOnStack(char *varname)
+{
+       if (varname)
+       {
+               int LocalSize = 0;
+               int Lused = 0;
+               int Ltotal = 0;
+               int i = 0;
+
+               C2F(getvariablesinfo)(&Ltotal,&Lused);
+
+               for( i = 0; i < Lused; i++)
+               {
+                       char *varOnStack = getLocalNamefromId(i);
+                       if (varOnStack)
+                       {
+                               if (strcmp(varname, varOnStack) == 0)
+                               {
+                                       FREE(varOnStack);
+                                       varOnStack = NULL;
+                                       return TRUE;
+                               }
+                               FREE(varOnStack);
+                               varOnStack = NULL;
+                       }
+               }
+       }
+       return FALSE;
+}
+/*--------------------------------------------------------------------------*/
+BOOL existGlobalVariableNamedOnStack(char *varname)
+{
+       if (varname)
+       {
+               int GlobalSize = 0;
+               int Gused = 0;
+               int Gtotal = 0;
+               int i = 0;
+
+               C2F(getgvariablesinfo)(&Gtotal,&Gused);
+               for( i = 0; i < Gused; i++)
+               {
+                       char *varOnStack = getGlobalNamefromId(i);
+                       if (varOnStack)
+                       {
+                               if (strcmp(varname, varOnStack) == 0)
+                               {
+                                       FREE(varOnStack);
+                                       varOnStack = NULL;
+                                       return TRUE;
+                               }
+                               FREE(varOnStack);
+                               varOnStack = NULL;
+                       }
+               }
+       }
+       return FALSE;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/src/c/typename.c b/scilab/modules/core/src/c/typename.c
new file mode 100644 (file)
index 0000000..0fdcbd8
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - 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
+* 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 <stdio.h>
+#include "typename.h"
+#include "MALLOC.h"
+#include "freeArrayOfString.h"
+#include "cvstr.h"
+#include "BOOL.h"
+/*--------------------------------------------------------------------------*/
+extern TYPE_struct C2F(typnams);
+extern C2F(addtypename)(); /* fortran subroutine */
+/*--------------------------------------------------------------------------*/
+static BOOL isTypeNameAlreadyExist(char *name);
+/*--------------------------------------------------------------------------*/
+char **getAllTypesName(int *sizeArray)
+{
+       char **TypeNames = NULL;
+       int numberOfTypes = getNumberOfTypes();
+       *sizeArray = 0;
+
+       if (numberOfTypes > 0)
+       {
+               TypeNames = (char**)MALLOC(sizeof(char*) * numberOfTypes);
+               if (TypeNames)
+               {
+                       int i = 0;
+                       int j = 0;
+
+                       for(i = 0; i < numberOfTypes; i++)
+                       {
+                               TypeNames[i] = (char*)MALLOC(sizeof(char)*(MAX_LENGTH_NAME_DEFINED_TYPE + 1));
+                               if (TypeNames[i] == NULL)
+                               {
+                                       freeArrayOfString(TypeNames,i);
+                                       *sizeArray = 0;
+                                       return TypeNames;
+                               }
+                       }
+
+                       for(i = 0;i < MAX_SCILAB_DEFINED_TYPE; i++)
+                       {
+                               if ( C2F(typnams).ln[i] != 0) 
+                               {
+                                       int job = 1;
+                                       int lengthTypeName = C2F(typnams).ln[i];
+                                       C2F(cvstr)(&lengthTypeName,&C2F(typnams).namrec[C2F(typnams).ptr[i]-1],TypeNames[j],&job,lengthTypeName);
+                                       TypeNames[j][lengthTypeName] = '\0';
+                                       j++;
+                               }
+                       }
+                       *sizeArray = j;
+               }
+       }
+       return TypeNames;
+}
+/*--------------------------------------------------------------------------*/
+int *getAllTypesNumber(int *sizeArray)
+{
+       int *TypeNumbers = NULL;
+       int numberOfTypes = getNumberOfTypes();
+       *sizeArray = 0;
+
+       if (numberOfTypes > 0)
+       {
+               TypeNumbers = (int*)MALLOC(sizeof(int)*numberOfTypes);
+               if (TypeNumbers)
+               {
+                       int i = 0;
+                       int j = 0;
+                       for(i = 0;i < MAX_SCILAB_DEFINED_TYPE; i++)
+                       {
+                               if ( C2F(typnams).ln[i] != 0) 
+                               {
+                                       TypeNumbers[j] = C2F(typnams).tp[i];
+                                       j++;
+                               }
+                       }
+            *sizeArray = j;
+               }
+       }
+       return TypeNumbers;
+}
+/*--------------------------------------------------------------------------*/
+int getNumberOfTypes(void)
+{
+       int NumberOfTypes = 0;
+       int i = 0;
+       for(i = 0;i < MAX_SCILAB_DEFINED_TYPE; i++)
+       {
+               if ( C2F(typnams).ln[i] != 0) NumberOfTypes++;
+       }
+       return NumberOfTypes;
+}
+/*--------------------------------------------------------------------------*/
+int addNamedType(char *name,int val)
+{
+       int ierr = 0;
+       if (isTypeNameAlreadyExist(name)) ierr = -1;
+       else C2F(addtypename)(&val,name,&ierr,strlen(name));
+       return ierr;
+}
+/*--------------------------------------------------------------------------*/
+BOOL isTypeNameAlreadyExist(char *name)
+{
+       int sizeArray = 0;
+       char **TypeNames = getAllTypesName(&sizeArray);
+       int i = 0;
+
+       if (TypeNames)
+       {
+               for(i = 0;i < sizeArray; i++)
+               {
+                       if (strcmp(name,TypeNames[i]) == 0)
+                       {
+                               freeArrayOfString(TypeNames,sizeArray);
+                               return TRUE;
+                       }
+               }
+               freeArrayOfString(TypeNames,sizeArray);
+       }
+       return FALSE;
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/core/src/c/typename.h b/scilab/modules/core/src/c/typename.h
new file mode 100644 (file)
index 0000000..8b97b0b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - 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
+* 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 __TYPENAME_H__
+#define __TYPENAME_H__
+
+#include "machine.h" /* C2F */
+
+/* see FORTRAN COMMON in typ2code.f */
+
+#define MAX_SCILAB_DEFINED_TYPE  50
+#define MAX_LENGTH_NAME_DEFINED_TYPE  200
+
+typedef struct {
+       int tp[MAX_SCILAB_DEFINED_TYPE];
+       int ptr[MAX_SCILAB_DEFINED_TYPE];
+       int ln[MAX_SCILAB_DEFINED_TYPE];
+       int namrec[MAX_LENGTH_NAME_DEFINED_TYPE];
+       int  ptmax;
+} TYPE_struct;
+
+
+/**
+* get all names of types
+* @param[out] size of returned array
+* @return names of defined types
+*/
+char **getAllTypesName(int *sizeArray);
+
+/**
+* get all values of types
+* @param[out] size of returned array
+* @return values of defined types
+*/
+int *getAllTypesNumber(int *sizeArray);
+
+/**
+* Get numbers of defined type
+* @return numbers of defined type (18 at startup)
+*/
+int getNumberOfTypes(void);
+
+/**
+* add a named type defined by a value
+* @param[in] named type
+* @param[in] value of type
+*/
+int addNamedType(char *name,int val);
+
+#endif /* __TYPENAME_H__ */
+/*--------------------------------------------------------------------------*/
index 74ee043..5b55aac 100644 (file)
@@ -166,8 +166,6 @@ cd .."/></Configuration></Configurations>
                <File RelativePath="..\..\sci_gateway\fortran\sci_mtlb_mode.f"/>
                <File RelativePath="..\..\sci_gateway\fortran\sci_resume.f"/>
                <File RelativePath="..\..\sci_gateway\fortran\sci_setbpt.f"/>
-               <File RelativePath="..\..\sci_gateway\fortran\sci_type.f"/>
-               <File RelativePath="..\..\sci_gateway\fortran\sci_typnam.f"/>
                <File RelativePath="..\..\sci_gateway\fortran\sci_useascommand.f"/>
                <File RelativePath="..\..\sci_gateway\fortran\sci_whereis.f"/>
                <File RelativePath="seteol.f"/>
index 9a1587f..8154aa8 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath="..\..\sci_gateway\fortran\sci_type.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\sci_gateway\fortran\sci_typnam.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\fortran\sci_useascommand.c"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath="..\..\sci_gateway\fortran\sci_type.f"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\sci_gateway\fortran\sci_typnam.f"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\fortran\sci_useascommand.f"
                                >
                        </File>
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_4278.dia.ref b/scilab/modules/core/tests/nonreg_tests/bug_4278.dia.ref
new file mode 100644 (file)
index 0000000..7ed36fa
--- /dev/null
@@ -0,0 +1,20 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- Non-regression test for bug 4278 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=4278
+//
+// <-- Short Description -->
+// typename() called with a wrong number of input arguments  returns incoherent errors.
+ierr = execstr('typename(''hgh'')','errcatch');
+if ierr <> 999 then bugmes();quit;end
+ierr = execstr('typename([17])','errcatch');
+if ierr <> 999 then bugmes();quit;end
+typename('my type',100)
+ierr = execstr('typename(''my type'',110)','errcatch');
+if ierr <> 999 then bugmes();quit;end
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_4278.tst b/scilab/modules/core/tests/nonreg_tests/bug_4278.tst
new file mode 100644 (file)
index 0000000..c8ab9f5
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 4278 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=4278
+//
+// <-- Short Description -->
+// typename() called with a wrong number of input arguments  returns incoherent errors.
+
+
+ierr = execstr('typename(''hgh'')','errcatch');
+if ierr <> 999 then pause,end
+
+ierr = execstr('typename([17])','errcatch');
+if ierr <> 999 then pause,end
+
+typename('my type',100)
+ierr = execstr('typename(''my type'',110)','errcatch');
+if ierr <> 999 then pause,end
+